From: Vadim Zeitlin Date: Thu, 30 Aug 2012 20:24:12 +0000 (+0000) Subject: Remove wxOSX implementation of wxSpinCtrl and use the generic one. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/36090ae57eff3e53cd74f504aaaa727b3bdb6ac8 Remove wxOSX implementation of wxSpinCtrl and use the generic one. wxOSX doesn't provide a native spinner+text control so it used a generic implementation of wxSpinCtrl but a different one to the version found in src/generic/spinctlg.cpp. Just use the real generic version instead, it doesn't make sense to have two different versions of the same generic control. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72413 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/Makefile.in b/Makefile.in index c42923b822..dab1a63fbe 100644 --- a/Makefile.in +++ b/Makefile.in @@ -3274,7 +3274,6 @@ COND_TOOLKIT_OSX_CARBON_GUI_HDR = \ wx/osx/scrolbar.h \ wx/osx/slider.h \ wx/osx/spinbutt.h \ - wx/osx/spinctrl.h \ wx/osx/srchctrl.h \ wx/osx/statbmp.h \ wx/osx/statbox.h \ @@ -3377,7 +3376,6 @@ COND_TOOLKIT_OSX_COCOA_GUI_HDR = \ wx/osx/scrolbar.h \ wx/osx/slider.h \ wx/osx/spinbutt.h \ - wx/osx/spinctrl.h \ wx/osx/srchctrl.h \ wx/osx/statbmp.h \ wx/osx/statbox.h \ @@ -3484,7 +3482,6 @@ COND_TOOLKIT_OSX_IPHONE_GUI_HDR = \ wx/osx/scrolbar.h \ wx/osx/slider.h \ wx/osx/spinbutt.h \ - wx/osx/spinctrl.h \ wx/osx/srchctrl.h \ wx/osx/statbmp.h \ wx/osx/statbox.h \ @@ -14349,7 +14346,6 @@ COND_PLATFORM_MACOSX_1___OSX_CARBON_COCOA_SRC_OBJECTS = \ monodll_scrolbar_osx.o \ monodll_slider_osx.o \ monodll_spinbutt_osx.o \ - monodll_spinctrl_osx.o \ monodll_srchctrl_osx.o \ monodll_statbox_osx.o \ monodll_statline_osx.o \ @@ -14479,7 +14475,6 @@ COND_PLATFORM_MACOSX_1___OSX_CARBON_COCOA_SRC_OBJECTS_12 = \ monolib_scrolbar_osx.o \ monolib_slider_osx.o \ monolib_spinbutt_osx.o \ - monolib_spinctrl_osx.o \ monolib_srchctrl_osx.o \ monolib_statbox_osx.o \ monolib_statline_osx.o \ @@ -14609,7 +14604,6 @@ COND_PLATFORM_MACOSX_1___OSX_CARBON_COCOA_SRC_OBJECTS_14 = \ coredll_scrolbar_osx.o \ coredll_slider_osx.o \ coredll_spinbutt_osx.o \ - coredll_spinctrl_osx.o \ coredll_srchctrl_osx.o \ coredll_statbox_osx.o \ coredll_statline_osx.o \ @@ -14727,7 +14721,6 @@ COND_PLATFORM_MACOSX_1___OSX_CARBON_COCOA_SRC_OBJECTS_1_0 = \ corelib_scrolbar_osx.o \ corelib_slider_osx.o \ corelib_spinbutt_osx.o \ - corelib_spinctrl_osx.o \ corelib_srchctrl_osx.o \ corelib_statbox_osx.o \ corelib_statline_osx.o \ @@ -20970,15 +20963,6 @@ monodll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONODLL_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@monodll_spinbutt_osx.o: $(srcdir)/src/osx/spinbutt_osx.cpp $(MONODLL_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/osx/spinbutt_osx.cpp -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_CARBON_USE_GUI_1_WXUNIV_0@monodll_spinctrl_osx.o: $(srcdir)/src/osx/spinctrl_osx.cpp $(MONODLL_ODEP) -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_CARBON_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/osx/spinctrl_osx.cpp - -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@monodll_spinctrl_osx.o: $(srcdir)/src/osx/spinctrl_osx.cpp $(MONODLL_ODEP) -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/osx/spinctrl_osx.cpp - -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@monodll_spinctrl_osx.o: $(srcdir)/src/osx/spinctrl_osx.cpp $(MONODLL_ODEP) -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/osx/spinctrl_osx.cpp - @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_CARBON_USE_GUI_1_WXUNIV_0@monodll_srchctrl_osx.o: $(srcdir)/src/osx/srchctrl_osx.cpp $(MONODLL_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_CARBON_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/osx/srchctrl_osx.cpp @@ -26673,15 +26657,6 @@ monolib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONOLIB_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@monolib_spinbutt_osx.o: $(srcdir)/src/osx/spinbutt_osx.cpp $(MONOLIB_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/osx/spinbutt_osx.cpp -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_CARBON_USE_GUI_1_WXUNIV_0@monolib_spinctrl_osx.o: $(srcdir)/src/osx/spinctrl_osx.cpp $(MONOLIB_ODEP) -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_CARBON_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/osx/spinctrl_osx.cpp - -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@monolib_spinctrl_osx.o: $(srcdir)/src/osx/spinctrl_osx.cpp $(MONOLIB_ODEP) -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/osx/spinctrl_osx.cpp - -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@monolib_spinctrl_osx.o: $(srcdir)/src/osx/spinctrl_osx.cpp $(MONOLIB_ODEP) -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/osx/spinctrl_osx.cpp - @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_CARBON_USE_GUI_1_WXUNIV_0@monolib_srchctrl_osx.o: $(srcdir)/src/osx/srchctrl_osx.cpp $(MONOLIB_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_CARBON_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/osx/srchctrl_osx.cpp @@ -32544,15 +32519,6 @@ coredll_win32.o: $(srcdir)/src/univ/themes/win32.cpp $(COREDLL_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@coredll_spinbutt_osx.o: $(srcdir)/src/osx/spinbutt_osx.cpp $(COREDLL_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/osx/spinbutt_osx.cpp -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_CARBON_USE_GUI_1_WXUNIV_0@coredll_spinctrl_osx.o: $(srcdir)/src/osx/spinctrl_osx.cpp $(COREDLL_ODEP) -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_CARBON_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/osx/spinctrl_osx.cpp - -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@coredll_spinctrl_osx.o: $(srcdir)/src/osx/spinctrl_osx.cpp $(COREDLL_ODEP) -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/osx/spinctrl_osx.cpp - -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@coredll_spinctrl_osx.o: $(srcdir)/src/osx/spinctrl_osx.cpp $(COREDLL_ODEP) -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/osx/spinctrl_osx.cpp - @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_CARBON_USE_GUI_1_WXUNIV_0@coredll_srchctrl_osx.o: $(srcdir)/src/osx/srchctrl_osx.cpp $(COREDLL_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_CARBON_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/osx/srchctrl_osx.cpp @@ -36798,15 +36764,6 @@ corelib_win32.o: $(srcdir)/src/univ/themes/win32.cpp $(CORELIB_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@corelib_spinbutt_osx.o: $(srcdir)/src/osx/spinbutt_osx.cpp $(CORELIB_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/osx/spinbutt_osx.cpp -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_CARBON_USE_GUI_1_WXUNIV_0@corelib_spinctrl_osx.o: $(srcdir)/src/osx/spinctrl_osx.cpp $(CORELIB_ODEP) -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_CARBON_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/osx/spinctrl_osx.cpp - -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@corelib_spinctrl_osx.o: $(srcdir)/src/osx/spinctrl_osx.cpp $(CORELIB_ODEP) -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/osx/spinctrl_osx.cpp - -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@corelib_spinctrl_osx.o: $(srcdir)/src/osx/spinctrl_osx.cpp $(CORELIB_ODEP) -@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/osx/spinctrl_osx.cpp - @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_CARBON_USE_GUI_1_WXUNIV_0@corelib_srchctrl_osx.o: $(srcdir)/src/osx/srchctrl_osx.cpp $(CORELIB_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_CARBON_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/osx/srchctrl_osx.cpp diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index 68b17dfa2f..8c7ada93a1 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -2259,7 +2259,6 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! src/osx/scrolbar_osx.cpp src/osx/slider_osx.cpp src/osx/spinbutt_osx.cpp - src/osx/spinctrl_osx.cpp src/osx/srchctrl_osx.cpp src/osx/statbox_osx.cpp src/osx/statline_osx.cpp @@ -2386,7 +2385,6 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! wx/osx/scrolbar.h wx/osx/slider.h wx/osx/spinbutt.h - wx/osx/spinctrl.h wx/osx/srchctrl.h wx/osx/statbmp.h wx/osx/statbox.h diff --git a/include/wx/osx/spinctrl.h b/include/wx/osx/spinctrl.h deleted file mode 100644 index f8a7ab2057..0000000000 --- a/include/wx/osx/spinctrl.h +++ /dev/null @@ -1,192 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/osx/spinctrl.h -// Purpose: generic wxSpinCtrl class -// Author: Vadim Zeitlin -// Modified by: -// Created: 28.10.99 -// RCS-ID: $Id$ -// Copyright: (c) Vadim Zeitlin -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_MAC_SPINCTRL_H_ -#define _WX_MAC_SPINCTRL_H_ - -// ---------------------------------------------------------------------------- -// wxSpinCtrl is a combination of wxSpinButton and wxTextCtrl, so if -// wxSpinButton is available, this is what we do - but if it isn't, we still -// define wxSpinCtrl class which then has the same appearance as wxTextCtrl but -// the different interface. This allows to write programs using wxSpinCtrl -// without tons of #ifdefs. -// ---------------------------------------------------------------------------- - -#if wxUSE_SPINBTN - -#include "wx/containr.h" - -class WXDLLIMPEXP_FWD_CORE wxSpinButton; -class WXDLLIMPEXP_FWD_CORE wxTextCtrl; -class WXDLLIMPEXP_FWD_CORE wxSpinCtrlText; -class WXDLLIMPEXP_FWD_CORE wxSpinCtrlButton; - -// ---------------------------------------------------------------------------- -// wxSpinCtrl is a combination of wxTextCtrl and wxSpinButton -// ---------------------------------------------------------------------------- - -class WXDLLIMPEXP_CORE wxSpinCtrl : public wxNavigationEnabled -{ -public: - wxSpinCtrl() { Init(); } - - wxSpinCtrl(wxWindow *parent, - wxWindowID id = -1, - const wxString& value = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT, - int min = 0, int max = 100, int initial = 0, - const wxString& name = wxT("wxSpinCtrl")) - { - Init(); - Create(parent, id, value, pos, size, style, min, max, initial, name); - } - - bool Create(wxWindow *parent, - wxWindowID id = -1, - const wxString& value = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT, - int min = 0, int max = 100, int initial = 0, - const wxString& name = wxT("wxSpinCtrl")); - - // wxTextCtrl-like method - void SetSelection(long from, long to); - - virtual ~wxSpinCtrl(); - - // operations - void SetValue(int val); - void SetValue(const wxString& text); - void SetRange(int min, int max); - - // accessors - int GetValue() const; - int GetMin() const; - int GetMax() const; - - // implementation from now on - - // forward these functions to all subcontrols - virtual bool Enable(bool enable = true); - virtual bool Show(bool show = true); - - // get the subcontrols - wxTextCtrl *GetText() const { return m_text; } - wxSpinButton *GetSpinButton() const { return m_btn; } - - // set the value of the text (only) - void SetTextValue(int val); - - // put the numeric value of the string in the text ctrl into val and return - // TRUE or return FALSE if the text ctrl doesn't contain a number or if the - // number is out of range - bool GetTextValue(int *val) const; - -protected: - // override the base class virtuals involved into geometry calculations - virtual wxSize DoGetBestSize() const; - virtual void DoMoveWindow(int x, int y, int width, int height); - - // common part of all ctors - void Init(); - -private: - // the subcontrols - wxTextCtrl *m_text; - wxSpinButton *m_btn; - - friend class wxSpinCtrlText; - friend class wxSpinCtrlButton; - - int m_oldValue; -private: - DECLARE_DYNAMIC_CLASS(wxSpinCtrl) -}; - -#else // !wxUSE_SPINBTN - -// ---------------------------------------------------------------------------- -// wxSpinCtrl is just a text control -// ---------------------------------------------------------------------------- - -#include "wx/textctrl.h" - -class WXDLLIMPEXP_CORE wxSpinCtrl : public wxTextCtrl -{ -public: - wxSpinCtrl() { Init(); } - - wxSpinCtrl(wxWindow *parent, - wxWindowID id = -1, - const wxString& value = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT, - int min = 0, int max = 100, int initial = 0, - const wxString& name = wxT("wxSpinCtrl")) - { - Create(parent, id, value, pos, size, style, min, max, initial, name); - } - - bool Create(wxWindow *parent, - wxWindowID id = -1, - const wxString& value = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT, - int min = 0, int max = 100, int initial = 0, - const wxString& name = wxT("wxSpinCtrl")) - { - SetRange(min, max); - - bool ok = wxTextCtrl::Create(parent, id, value, pos, size, style, - wxDefaultValidator, name); - SetValue(initial); - - return ok; - } - - // accessors - int GetValue(int WXUNUSED(dummy) = 1) const - { - int n; - if ( (wxSscanf(wxTextCtrl::GetValue(), wxT("%d"), &n) != 1) ) - n = INT_MIN; - - return n; - } - - int GetMin() const { return m_min; } - int GetMax() const { return m_max; } - - // operations - void SetValue(const wxString& value) { wxTextCtrl::SetValue(value); } - void SetValue(int val) { wxString s; s << val; wxTextCtrl::SetValue(s); } - void SetRange(int min, int max) { m_min = min; m_max = max; } - -protected: - // initialize m_min/max with the default values - void Init() { SetRange(0, 100); } - - int m_min; - int m_max; - -private: - DECLARE_DYNAMIC_CLASS(wxSpinCtrl) -}; - -#endif // wxUSE_SPINBTN/!wxUSE_SPINBTN - -#endif // _WX_MAC_SPINCTRL_H_ - diff --git a/include/wx/spinctrl.h b/include/wx/spinctrl.h index 91e9a39a05..8a2ef4d90b 100644 --- a/include/wx/spinctrl.h +++ b/include/wx/spinctrl.h @@ -113,9 +113,7 @@ typedef void (wxEvtHandler::*wxSpinDoubleEventFunction)(wxSpinDoubleEvent&); // wxSpinCtrlDouble implementations or neither, define the appropriate symbols // and include the generic version if necessary to provide the missing class(es) -#if defined(__WXUNIVERSAL__) || \ - defined(__WXMOTIF__) || \ - defined(__WXCOCOA__) +#if defined(__WXUNIVERSAL__) // nothing, use generic controls #elif defined(__WXMSW__) #define wxHAS_NATIVE_SPINCTRL @@ -130,9 +128,6 @@ typedef void (wxEvtHandler::*wxSpinDoubleEventFunction)(wxSpinDoubleEvent&); #elif defined(__WXGTK__) #define wxHAS_NATIVE_SPINCTRL #include "wx/gtk1/spinctrl.h" -#elif defined(__WXMAC__) - #define wxHAS_NATIVE_SPINCTRL - #include "wx/osx/spinctrl.h" #endif // platform #if !defined(wxHAS_NATIVE_SPINCTRL) || !defined(wxHAS_NATIVE_SPINCTRLDOUBLE) diff --git a/src/osx/spinctrl_osx.cpp b/src/osx/spinctrl_osx.cpp deleted file mode 100644 index acd16fac55..0000000000 --- a/src/osx/spinctrl_osx.cpp +++ /dev/null @@ -1,437 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/osx/spinctrl_osx.cpp -// Purpose: wxSpinCtrl -// Author: Robert -// Modified by: Mark Newsam (Based on GTK file) -// RCS-ID: $Id$ -// Copyright: (c) Robert Roebling -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#if wxUSE_SPINCTRL - -#include "wx/spinctrl.h" - -#ifndef WX_PRECOMP - #include "wx/textctrl.h" - #include "wx/containr.h" -#endif - -#include "wx/spinbutt.h" - -// ---------------------------------------------------------------------------- -// constants -// ---------------------------------------------------------------------------- - -// the focus rect around a text may have 4 pixels in each direction -// we handle these problems right now in an extended vis region of a window -static const wxCoord TEXTBORDER = 4 ; -// the margin between the text control and the spin -// HIG says 2px between text and stepper control, -// but a value of 3 leads to the same look as the -// spin controls in Apple's apps -static const wxCoord MARGIN = 3; - -// ---------------------------------------------------------------------------- -// wxSpinCtrlText: text control used by spin control -// ---------------------------------------------------------------------------- - -class wxSpinCtrlText : public wxTextCtrl -{ -public: - wxSpinCtrlText(wxSpinCtrl *spin, const wxString& value, int style) - : wxTextCtrl(spin , wxID_ANY, value, wxDefaultPosition, wxSize(40, wxDefaultCoord), style ) - { - m_spin = spin; - - // remove the default minsize, the spinctrl will have one instead - SetMinSize(wxDefaultSize); - } - - bool ProcessEvent(wxEvent &event) - { - // Hand button down events to wxSpinCtrl. Doesn't work. - if (event.GetEventType() == wxEVT_LEFT_DOWN && m_spin->ProcessEvent( event )) - return true; - - return wxTextCtrl::ProcessEvent( event ); - } - -protected: - void OnSetFocus(wxFocusEvent& event) - { - // delegate to parent control - event.SetEventObject( GetParent() ); - GetParent()->HandleWindowEvent(event); - } - - void OnKillFocus(wxFocusEvent& event) - { - long l; - if ( !GetValue().ToLong(&l) ) - { - // not a number at all - return; - } - - // is within range - if (l < m_spin->GetMin()) - l = m_spin->GetMin(); - if (l > m_spin->GetMax()) - l = m_spin->GetMax(); - - // Update text control - wxString str; - str.Printf( wxT("%d"), (int)l ); - if (str != GetValue()) - SetValue( str ); - - if (l != m_spin->m_oldValue) - { - // set value in spin button - // does that trigger an event? - m_spin->m_btn->SetValue( l ); - - // if not - wxCommandEvent cevent(wxEVT_COMMAND_SPINCTRL_UPDATED, m_spin->GetId()); - cevent.SetEventObject(m_spin); - cevent.SetInt(l); - m_spin->HandleWindowEvent(cevent); - - m_spin->m_oldValue = l; - } - - // delegate to parent control - event.SetEventObject( GetParent() ); - GetParent()->HandleWindowEvent(event); - } - - void OnTextChange(wxCommandEvent& event) - { - int val; - if ( m_spin->GetTextValue(&val) ) - { - m_spin->GetSpinButton()->SetValue(val); - - // If we're already processing a text update from m_spin, - // don't send it again, since we could end up recursing - // infinitely. - if (event.GetId() == m_spin->GetId()) - { - event.Skip(); - return; - } - - // Send event that the text was manually changed - wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_spin->GetId()); - event.SetEventObject(m_spin); - event.SetString(m_spin->GetText()->GetValue()); - event.SetInt(val); - - m_spin->HandleWindowEvent(event); - } - - event.Skip(); - } - -private: - wxSpinCtrl *m_spin; - - DECLARE_EVENT_TABLE() -}; - -BEGIN_EVENT_TABLE(wxSpinCtrlText, wxTextCtrl) - EVT_TEXT(wxID_ANY, wxSpinCtrlText::OnTextChange) - EVT_SET_FOCUS(wxSpinCtrlText::OnSetFocus) - EVT_KILL_FOCUS(wxSpinCtrlText::OnKillFocus) -END_EVENT_TABLE() - -// ---------------------------------------------------------------------------- -// wxSpinCtrlButton: spin button used by spin control -// ---------------------------------------------------------------------------- - -class wxSpinCtrlButton : public wxSpinButton -{ -public: - wxSpinCtrlButton(wxSpinCtrl *spin, int style) - : wxSpinButton(spin ) - { - m_spin = spin; - SetWindowStyle(style | wxSP_VERTICAL); - - // TODO: The spin button gets truncated a little bit due to size - // differences so change it's default size a bit. SMALL still gets a - // bit truncated, but MINI seems to be too small... Readdress this - // when the textctrl issues are all sorted out. - //SetWindowVariant(wxWINDOW_VARIANT_SMALL); - - // remove the default minsize, the spinctrl will have one instead - SetMinSize(wxDefaultSize); - } - -protected: - void OnSpinButton(wxSpinEvent& eventSpin) - { - int pos = eventSpin.GetPosition(); - m_spin->SetTextValue(pos); - - wxCommandEvent event(wxEVT_COMMAND_SPINCTRL_UPDATED, m_spin->GetId()); - event.SetEventObject(m_spin); - event.SetInt(pos); - - m_spin->HandleWindowEvent(event); - - m_spin->m_oldValue = pos; - } - -private: - wxSpinCtrl *m_spin; - - DECLARE_EVENT_TABLE() -}; - -BEGIN_EVENT_TABLE(wxSpinCtrlButton, wxSpinButton) - EVT_SPIN(wxID_ANY, wxSpinCtrlButton::OnSpinButton) -END_EVENT_TABLE() - -// ============================================================================ -// implementation -// ============================================================================ - -// ---------------------------------------------------------------------------- -// wxSpinCtrl creation -// ---------------------------------------------------------------------------- - -void wxSpinCtrl::Init() -{ - m_text = NULL; - m_btn = NULL; -} - -bool wxSpinCtrl::Create(wxWindow *parent, - wxWindowID id, - const wxString& value, - const wxPoint& pos, - const wxSize& size, - long style, - int min, - int max, - int initial, - const wxString& name) -{ - if ( !wxControl::Create(parent, id, pos, size, style, - wxDefaultValidator, name) ) - { - return false; - } - - // the string value overrides the numeric one (for backwards compatibility - // reasons and also because it is simpler to satisfy the string value which - // comes much sooner in the list of arguments and leave the initial - // parameter unspecified) - if ( !value.empty() ) - { - long l; - if ( value.ToLong(&l) ) - initial = l; - } - - wxSize csize = size ; - m_text = new wxSpinCtrlText(this, value, style & ( wxTE_PROCESS_ENTER | wxALIGN_MASK ) ); - m_btn = new wxSpinCtrlButton(this, style); - - m_btn->SetRange(min, max); - m_btn->SetValue(initial); - // make it different - m_oldValue = GetMin()-1; - - if ( size.x == wxDefaultCoord ){ - csize.x = m_text->GetSize().x + MARGIN + m_btn->GetSize().x ; - } - - if ( size.y == wxDefaultCoord ) { - csize.y = m_text->GetSize().y + 2 * TEXTBORDER ; //allow for text border highlights - if ( m_btn->GetSize().y > csize.y ) - csize.y = m_btn->GetSize().y ; - } - - //SetSize(csize); - - //MacPostControlCreate(pos, csize); - SetInitialSize(csize); - - return true; -} - -wxSpinCtrl::~wxSpinCtrl() -{ - // delete the controls now, don't leave them alive even though they would - // still be eventually deleted by our parent - but it will be too late, the - // user code expects them to be gone now - wxDELETE(m_text); - wxDELETE(m_btn); -} - -// ---------------------------------------------------------------------------- -// geometry -// ---------------------------------------------------------------------------- - -wxSize wxSpinCtrl::DoGetBestSize() const -{ - if (!m_btn || !m_text) - return GetSize(); - - wxSize sizeBtn = m_btn->GetBestSize(), - sizeText = m_text->GetBestSize(); - - sizeText.y += 2 * TEXTBORDER ; - sizeText.x += 2 * TEXTBORDER ; - - int height; - if (sizeText.y > sizeBtn.y) - height = sizeText.y; - else - height = sizeBtn.y; - - return wxSize(sizeBtn.x + sizeText.x + MARGIN, height ); -} - -void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height) -{ - // position the subcontrols inside the client area - wxSize sizeBtn = m_btn->GetSize(); - wxSize sizeText = m_text->GetSize(); - - wxControl::DoMoveWindow(x, y, width, height); - - wxCoord wText = width - sizeBtn.x - MARGIN - 2 * TEXTBORDER; - - m_text->SetSize(TEXTBORDER, (height - sizeText.y) / 2, wText, -1); - m_btn->SetSize(0 + wText + MARGIN + TEXTBORDER , (height - sizeBtn.y) / 2 , -1, -1 ); -} - -// ---------------------------------------------------------------------------- -// operations forwarded to the subcontrols -// ---------------------------------------------------------------------------- - -bool wxSpinCtrl::Enable(bool enable) -{ - if ( !wxControl::Enable(enable) ) - return false; - m_text->Enable(enable); - m_btn->Enable(enable); - return true; -} - -bool wxSpinCtrl::Show(bool show) -{ - if ( !wxControl::Show(show) ) - return false; - return true; -} - -// ---------------------------------------------------------------------------- -// value and range access -// ---------------------------------------------------------------------------- - -bool wxSpinCtrl::GetTextValue(int *val) const -{ - long l; - if ( !m_text->GetValue().ToLong(&l) ) - { - // not a number at all - return false; - } - - if ( l < GetMin() || l > GetMax() ) - { - // out of range - return false; - } - - *val = l; - - return true; -} - -int wxSpinCtrl::GetValue() const -{ - return m_btn ? m_btn->GetValue() : 0; -} - -int wxSpinCtrl::GetMin() const -{ - return m_btn ? m_btn->GetMin() : 0; -} - -int wxSpinCtrl::GetMax() const -{ - return m_btn ? m_btn->GetMax() : 0; -} - -// ---------------------------------------------------------------------------- -// changing value and range -// ---------------------------------------------------------------------------- - -void wxSpinCtrl::SetTextValue(int val) -{ - wxCHECK_RET( m_text, wxT("invalid call to wxSpinCtrl::SetTextValue") ); - - m_text->SetValue(wxString::Format(wxT("%d"), val)); - - // select all text - m_text->SetSelection(0, -1); - - m_text->SetInsertionPointEnd(); - - // and give focus to the control! - // m_text->SetFocus(); Why???? TODO. -} - -void wxSpinCtrl::SetValue(int val) -{ - wxCHECK_RET( m_btn, wxT("invalid call to wxSpinCtrl::SetValue") ); - - SetTextValue(val); - - m_btn->SetValue(val); - m_oldValue = val; -} - -void wxSpinCtrl::SetValue(const wxString& text) -{ - wxCHECK_RET( m_text, wxT("invalid call to wxSpinCtrl::SetValue") ); - - long val; - if ( text.ToLong(&val) && ((val > INT_MIN) && (val < INT_MAX)) ) - { - SetValue((int)val); - } - else // not a number at all or out of range - { - m_text->SetValue(text); - m_text->SetSelection(0, -1); - } -} - -void wxSpinCtrl::SetRange(int min, int max) -{ - wxCHECK_RET( m_btn, wxT("invalid call to wxSpinCtrl::SetRange") ); - - m_btn->SetRange(min, max); -} - -void wxSpinCtrl::SetSelection(long from, long to) -{ - // if from and to are both -1, it means (in wxWidgets) that all text should - // be selected - if ( (from == -1) && (to == -1) ) - { - from = 0; - } - m_text->SetSelection(from, to); -} - -#endif // wxUSE_SPINCTRL