X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/217099990c2665d18d352c60058106da9a014ab8..365796b153d710b08a03b92de241574d01c498d7:/src/generic/spinctlg.cpp?ds=sidebyside diff --git a/src/generic/spinctlg.cpp b/src/generic/spinctlg.cpp index 439e8987d2..91ae4c9f5f 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,14 +28,15 @@ #pragma hdrstop #endif -#if !wxUSE_SPINBTN - #error "This file can only be compiled if wxSpinButton is available" -#endif // !wxUSE_SPINBTN +#if !(defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXPM__)) || \ + defined(__WXMAC__) || defined(__WXUNIVERSAL__) #ifndef WX_PRECOMP #include "wx/textctrl.h" #endif //WX_PRECOMP +#if wxUSE_SPINCTRL + #include "wx/spinbutt.h" #include "wx/spinctrl.h" @@ -71,6 +72,15 @@ protected: event.Skip(); } + 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 ); + } + private: wxSpinCtrl *m_spin; @@ -93,15 +103,21 @@ public: { m_spin = spin; - SetWindowStyle(style); + SetWindowStyle(style | wxSP_VERTICAL); } protected: - void OnSpinButton(wxSpinEvent& event) + void OnSpinButton(wxSpinEvent& eventSpin) { - m_spin->SetTextValue(event.GetPosition()); + m_spin->SetTextValue(eventSpin.GetPosition()); - event.Skip(); + wxCommandEvent event(wxEVT_COMMAND_SPINCTRL_UPDATED, m_spin->GetId()); + event.SetEventObject(m_spin); + event.SetInt(eventSpin.GetPosition()); + + m_spin->GetEventHandler()->ProcessEvent(event); + + eventSpin.Skip(); } private: @@ -141,22 +157,41 @@ 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; } - SetBackgroundColour(*wxRED); + // 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; + } + SetBackgroundColour(*wxRED); m_text = new wxSpinCtrlText(this, value); m_btn = new wxSpinCtrlButton(this, style); m_btn->SetRange(min, max); m_btn->SetValue(initial); - - DoSetSize(pos.x, pos.y, size.x, size.y); - +#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 + wxSize best = GetBestSize(); + if ( size.x != -1 ) best.x = size.x; + if ( size.y != -1 ) best.y = size.y; + DoSetSize(pos.x, pos.y, best.x, best.y); +#endif // 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 @@ -166,8 +201,9 @@ bool wxSpinCtrl::Create(wxWindow *parent, // 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; } @@ -184,7 +220,7 @@ wxSpinCtrl::~wxSpinCtrl() // geometry // ---------------------------------------------------------------------------- -wxSize wxSpinCtrl::DoGetBestClientSize() const +wxSize wxSpinCtrl::DoGetBestSize() const { wxSize sizeBtn = m_btn->GetBestSize(), sizeText = m_text->GetBestSize(); @@ -197,12 +233,15 @@ void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height) wxControl::DoMoveWindow(x, y, width, height); // position the subcontrols inside the client area - wxSize sizeBtn = m_btn->GetSize(), - sizeText = m_text->GetSize(); + wxSize sizeBtn = m_btn->GetSize(); wxCoord wText = width - sizeBtn.x; m_text->SetSize(x, y, wText, height); +#ifdef __WXMAC__ + m_btn->SetSize(x + wText + MARGIN, y, -1, -1); +#else m_btn->SetSize(x + wText + MARGIN, y, -1, height); +#endif } // ---------------------------------------------------------------------------- @@ -225,8 +264,13 @@ bool wxSpinCtrl::Show(bool show) if ( !wxControl::Show(show) ) return FALSE; - m_btn->Show(show); - m_text->Show(show); + // under GTK Show() is called the first time before we are fully + // constructed + if ( m_btn ) + { + m_btn->Show(show); + m_text->Show(show); + } return TRUE; } @@ -284,7 +328,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) @@ -319,3 +363,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