X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5397911d6248a3bafe08233480ffb0c614b892e0..63ec176495f334a38767e670d9e033da4db8f2e2:/src/generic/spinctlg.cpp diff --git a/src/generic/spinctlg.cpp b/src/generic/spinctlg.cpp index f5019af63a..066e66f381 100644 --- a/src/generic/spinctlg.cpp +++ b/src/generic/spinctlg.cpp @@ -6,7 +6,7 @@ // Created: 29.01.01 // RCS-ID: $Id$ // Copyright: (c) 2001 Vadim Zeitlin -// License: wxWindows license +// License: wxWindows licence /////////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -17,7 +17,7 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "spinctlg.h" #endif @@ -28,8 +28,10 @@ #pragma hdrstop #endif -#if !(defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXPM__)) || defined(__WXMAC__) || \ - defined(__WXUNIVERSAL__) +// There are port-specific versions for MSW, GTK, OS/2 and Mac, so exclude the +// contents of this file in those cases +#if !(defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXPM__) || \ + defined(__WXMAC__)) || defined(__WXUNIVERSAL__) #ifndef WX_PRECOMP #include "wx/textctrl.h" @@ -55,9 +57,12 @@ class wxSpinCtrlText : public wxTextCtrl { public: wxSpinCtrlText(wxSpinCtrl *spin, const wxString& value) - : wxTextCtrl(spin->GetParent(), -1, value) + : wxTextCtrl(spin->GetParent(), wxID_ANY, value) { m_spin = spin; + + // remove the default minsize, the spinctrl will have one instead + SetSizeHints(wxDefaultCoord,wxDefaultCoord); } protected: @@ -76,7 +81,7 @@ protected: { // Hand button down events to wxSpinCtrl. Doesn't work. if (event.GetEventType() == wxEVT_LEFT_DOWN && m_spin->ProcessEvent( event )) - return TRUE; + return true; return wxTextCtrl::ProcessEvent( event ); } @@ -88,7 +93,7 @@ private: }; BEGIN_EVENT_TABLE(wxSpinCtrlText, wxTextCtrl) - EVT_TEXT(-1, wxSpinCtrlText::OnTextChange) + EVT_TEXT(wxID_ANY, wxSpinCtrlText::OnTextChange) END_EVENT_TABLE() // ---------------------------------------------------------------------------- @@ -104,23 +109,23 @@ public: m_spin = spin; SetWindowStyle(style | wxSP_VERTICAL); + + // remove the default minsize, the spinctrl will have one instead + SetSizeHints(wxDefaultCoord,wxDefaultCoord); } protected: void OnSpinButton(wxSpinEvent& eventSpin) { -#ifdef __WXMAC__ - m_spin->SetTextValue(eventSpin.GetPosition()); + m_spin->SetTextValue(eventSpin.GetPosition()); - wxCommandEvent event(wxEVT_COMMAND_SPINCTRL_UPDATED, m_spin->GetId()); - event.SetEventObject(m_spin); - event.SetInt(eventSpin.GetPosition()); + wxCommandEvent event(wxEVT_COMMAND_SPINCTRL_UPDATED, m_spin->GetId()); + event.SetEventObject(m_spin); + event.SetInt(eventSpin.GetPosition()); + + m_spin->GetEventHandler()->ProcessEvent(event); - m_spin->GetEventHandler()->ProcessEvent(event); -#else - m_spin->SetTextValue(eventSpin.GetPosition()); eventSpin.Skip(); -#endif } private: @@ -130,7 +135,7 @@ private: }; BEGIN_EVENT_TABLE(wxSpinCtrlButton, wxSpinButton) - EVT_SPIN(-1, wxSpinCtrlButton::OnSpinButton) + EVT_SPIN(wxID_ANY, wxSpinCtrlButton::OnSpinButton) END_EVENT_TABLE() IMPLEMENT_DYNAMIC_CLASS(wxSpinCtrl, wxControl) @@ -152,7 +157,7 @@ void wxSpinCtrl::Init() bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id, const wxString& value, - const wxPoint& pos, + const wxPoint& WXUNUSED(pos), const wxSize& size, long style, int min, @@ -160,10 +165,10 @@ bool wxSpinCtrl::Create(wxWindow *parent, int initial, const wxString& name) { - if ( !wxControl::Create(parent, id, pos, size, style, + if ( !wxControl::Create(parent, id, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, name) ) { - return FALSE; + return false; } // the string value overrides the numeric one (for backwards compatibility @@ -177,50 +182,42 @@ bool wxSpinCtrl::Create(wxWindow *parent, initial = l; } - SetBackgroundColour(*wxRED); m_text = new wxSpinCtrlText(this, value); m_btn = new wxSpinCtrlButton(this, style); m_btn->SetRange(min, max); m_btn->SetValue(initial); -#ifdef __WXMAC__ - wxSize csize = size ; - if ( size.y == -1 ) { - csize.y = m_text->GetSize().y ; - } - DoSetSize(pos.x, pos.y, csize.x, csize.y); -#else - DoSetSize(pos.x, pos.y, size.x, size.y); -#endif + SetBestSize(size); + // have to disable this window to avoid interfering it with message // processing to the text and the button... but pretend it is enabled to - // make IsEnabled() return TRUE - wxControl::Enable(FALSE); // don't use non virtual Disable() here! - m_isEnabled = TRUE; + // make IsEnabled() return true + wxControl::Enable(false); // don't use non virtual Disable() here! + m_isEnabled = true; // we don't even need to show this window itself - and not doing it avoids // that it overwrites the text control - wxControl::Show(FALSE); -#ifndef __WXMAC__ - m_isShown = TRUE; -#endif - return TRUE; + wxControl::Show(false); + m_isShown = true; + return true; } wxSpinCtrl::~wxSpinCtrl() { - // delete the controls now, don't leave them alive even though they woudl + // 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 delete m_text; + m_text = NULL ; delete m_btn; + m_btn = NULL ; } // ---------------------------------------------------------------------------- // geometry // ---------------------------------------------------------------------------- -wxSize wxSpinCtrl::DoGetBestClientSize() const +wxSize wxSpinCtrl::DoGetBestSize() const { wxSize sizeBtn = m_btn->GetBestSize(), sizeText = m_text->GetBestSize(); @@ -232,19 +229,12 @@ void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height) { wxControl::DoMoveWindow(x, y, width, height); - wxPoint p = GetParent() ? - GetParent()->GetClientAreaOrigin() : wxPoint(0,0); - // position the subcontrols inside the client area wxSize sizeBtn = m_btn->GetSize(); wxCoord wText = width - sizeBtn.x; - m_text->SetSize(x-p.x, y-p.y, wText, height); -#ifdef __WXMAC__ - m_btn->SetSize(x-p.x + wText + MARGIN, y-p.y, -1, -1); -#else - m_btn->SetSize(x-p.x + wText + MARGIN, y-p.y, -1, height); -#endif + m_text->SetSize(x, y, wText, height); + m_btn->SetSize(x + wText + MARGIN, y, wxDefaultCoord, height); } // ---------------------------------------------------------------------------- @@ -254,18 +244,18 @@ void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height) bool wxSpinCtrl::Enable(bool enable) { if ( !wxControl::Enable(enable) ) - return FALSE; + return false; m_btn->Enable(enable); m_text->Enable(enable); - return TRUE; + return true; } bool wxSpinCtrl::Show(bool show) { if ( !wxControl::Show(show) ) - return FALSE; + return false; // under GTK Show() is called the first time before we are fully // constructed @@ -275,7 +265,7 @@ bool wxSpinCtrl::Show(bool show) m_text->Show(show); } - return TRUE; + return true; } // ---------------------------------------------------------------------------- @@ -288,18 +278,18 @@ bool wxSpinCtrl::GetTextValue(int *val) const if ( !m_text->GetValue().ToLong(&l) ) { // not a number at all - return FALSE; + return false; } if ( l < GetMin() || l > GetMax() ) { // out of range - return FALSE; + return false; } *val = l; - return TRUE; + return true; } int wxSpinCtrl::GetValue() const @@ -331,7 +321,7 @@ void wxSpinCtrl::SetTextValue(int val) m_text->SetSelection(0, -1); // and give focus to the control! - m_text->SetFocus(); + // m_text->SetFocus(); Why???? TODO. } void wxSpinCtrl::SetValue(int val) @@ -366,5 +356,12 @@ void wxSpinCtrl::SetRange(int min, int max) m_btn->SetRange(min, max); } +void wxSpinCtrl::SetSelection(long from, long to) +{ + wxCHECK_RET( m_text, _T("invalid call to wxSpinCtrl::SetSelection") ); + + m_text->SetSelection(from, to); +} + #endif // wxUSE_SPINCTRL #endif // !wxPort-with-native-spinctrl