From: Vadim Zeitlin Date: Thu, 28 Oct 1999 01:17:35 +0000 (+0000) Subject: 1. corrected (but the fix is ugly) the multiple def button problem X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/678cd6de66095373ebaed01d8d013f256cac326b 1. corrected (but the fix is ugly) the multiple def button problem 2. corrected a bug which disabled all accels for MSW (sic) 3. added SetValue/GetValue to wxSpinCtrl 4. modified wxGetNumberFromUser to use wxSpinCtrl git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4234 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/generic/panelg.h b/include/wx/generic/panelg.h index c5442a15e0..b6c550a860 100644 --- a/include/wx/generic/panelg.h +++ b/include/wx/generic/panelg.h @@ -6,11 +6,11 @@ // Created: 01/02/97 // RCS-ID: $Id$ // Copyright: (c) -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef __PANELH_G__ -#define __PANELH_G__ +#ifndef _WX_GENERIC_PANEL_H_ +#define _WX_GENERIC_PANEL_H_ #ifdef __GNUG__ #pragma interface "panelg.h" @@ -100,4 +100,4 @@ private: }; #endif - // __PANELH_G__ + // _WX_GENERIC_PANEL_H_ diff --git a/include/wx/msw/button.h b/include/wx/msw/button.h index 6888ee443a..794d9f9337 100644 --- a/include/wx/msw/button.h +++ b/include/wx/msw/button.h @@ -53,6 +53,7 @@ public: // implementation from now on virtual void Command(wxCommandEvent& event); + virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); virtual bool MSWCommand(WXUINT param, WXWORD id); virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, diff --git a/include/wx/msw/spinctrl.h b/include/wx/msw/spinctrl.h index 4471ccd5dc..7babcf4e74 100644 --- a/include/wx/msw/spinctrl.h +++ b/include/wx/msw/spinctrl.h @@ -31,24 +31,32 @@ public: wxSpinCtrl(wxWindow *parent, wxWindowID id = -1, + const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxSP_ARROW_KEYS, int min = 0, int max = 100, int initial = 0, const wxString& name = _T("wxSpinCtrl")) { - Create(parent, id, pos, size, style, min, max, initial, name); + 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, int min = 0, int max = 100, int initial = 0, const wxString& name = _T("wxSpinCtrl")); + // a wxTextCtrl-like method (but we can't have GetValue returning wxString + // because the base class already has one returning int!) + void SetValue(const wxString& text); + // override some of the base class virtuals + virtual void SetValue(int val) { wxSpinButton::SetValue(val); } + virtual int GetValue() const; virtual bool SetFont(const wxFont &font); protected: diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index f4719a7b86..4b6f62cee1 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -527,7 +527,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) #endif // wxUSE_SPINBUTTON #if wxUSE_SPINCTRL - m_spinctrl = new wxSpinCtrl( panel, ID_SPINCTRL, wxPoint(200, 160), wxSize(80, -1) ); + m_spinctrl = new wxSpinCtrl( panel, ID_SPINCTRL, "", wxPoint(200, 160), wxSize(80, -1) ); m_spinctrl->SetRange(10,30); m_spinctrl->SetValue(15); #endif // wxUSE_SPINCTRL diff --git a/src/generic/numdlgg.cpp b/src/generic/numdlgg.cpp index c88afa638c..0bcafcdc60 100644 --- a/src/generic/numdlgg.cpp +++ b/src/generic/numdlgg.cpp @@ -45,6 +45,8 @@ #include "wx/statline.h" #endif +#include "wx/spinctrl.h" + // this is where wxGetNumberFromUser() is declared #include "wx/generic/textdlgg.h" @@ -69,7 +71,7 @@ public: void OnCancel(wxCommandEvent& event); protected: - wxTextCtrl *m_spinctrl; // TODO replace it with wxSpinCtrl once it's done + wxSpinCtrl *m_spinctrl; long m_value, m_min, m_max; @@ -107,12 +109,12 @@ wxNumberEntryDialog::wxNumberEntryDialog(wxWindow *parent, m_min = min; wxBeginBusyCursor(); - + wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); // 1) text message topsizer->Add( CreateTextSizer( message ), 0, wxALL, 10 ); - + // 2) prompt and text ctrl wxBoxSizer *inputsizer = new wxBoxSizer( wxHORIZONTAL ); // prompt if any @@ -121,9 +123,9 @@ wxNumberEntryDialog::wxNumberEntryDialog(wxWindow *parent, // spin ctrl wxString valStr; valStr.Printf(wxT("%lu"), m_value); - m_spinctrl = new wxTextCtrl(this, -1, valStr, wxDefaultPosition, wxSize( 140, -1 ) ); + m_spinctrl = new wxSpinCtrl(this, -1, valStr, wxDefaultPosition, wxSize( 140, -1 ) ); inputsizer->Add( m_spinctrl, 1, wxCENTER | wxLEFT | wxRIGHT, 10 ); - // add both + // add both topsizer->Add( inputsizer, 1, wxEXPAND | wxLEFT|wxRIGHT, 5 ); #if wxUSE_STATLINE @@ -133,7 +135,7 @@ wxNumberEntryDialog::wxNumberEntryDialog(wxWindow *parent, // 4) buttons topsizer->Add( CreateButtonSizer( wxOK|wxCANCEL ), 0, wxCENTRE | wxALL, 10 ); - + SetSizer( topsizer ); SetAutoLayout( TRUE ); @@ -149,8 +151,8 @@ wxNumberEntryDialog::wxNumberEntryDialog(wxWindow *parent, void wxNumberEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event)) { - if ( (wxSscanf(m_spinctrl->GetValue(), wxT("%lu"), &m_value) != 1) || - (m_value < m_min) || (m_value > m_max) ) + m_value = m_spinctrl->GetValue(); + if ( m_value < m_min || m_value > m_max ) { // not a number or out of range m_value = -1; diff --git a/src/msw/button.cpp b/src/msw/button.cpp index 18a3cc42e6..b1001d5930 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -70,9 +70,6 @@ bool wxButton::Create(wxWindow *parent, if ( !CreateBase(parent, id, pos, size, style, validator, name) ) return FALSE; - // Validator was set in CreateBase - //SetValidator(validator); - parent->AddChild((wxButton *)this); m_backgroundColour = parent->GetBackgroundColour() ; @@ -104,8 +101,10 @@ bool wxButton::Create(wxWindow *parent, wxSize nsize( GetSize() ); if ((nsize.x < 80) || (nsize.y < 23)) { - if ((size.x == -1) && (nsize.x < 80)) nsize.x = 80; - if ((size.y == -1) && (nsize.y < 23)) nsize.y = 23; + if ((size.x == -1) && (nsize.x < 80)) + nsize.x = 80; + if ((size.y == -1) && (nsize.y < 23)) + nsize.y = 23; SetSize( nsize ); } @@ -234,7 +233,7 @@ bool wxButton::MSWCommand(WXUINT param, WXWORD id) bool processed = FALSE; switch ( param ) { - case 1: // 1 for accelerator + case 1: // means that the message came from an accelerator case BN_CLICKED: processed = SendClickEvent(); break; @@ -255,3 +254,28 @@ WXHBRUSH wxButton::OnCtlColor(WXHDC pDC, return (WXHBRUSH) backgroundBrush->GetResourceHandle(); } +long wxButton::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) +{ + // make sure that we won't have BS_DEFPUSHBUTTON style any more if the + // focus is being transfered to another button with the same parent - + // otherwise, we could finish with 2 default buttons inside one panel + if ( (nMsg == WM_KILLFOCUS) && + (GetWindowLong(GetHwnd(), GWL_STYLE) & BS_DEFPUSHBUTTON) ) + { + wxWindow *parent = GetParent(); + wxWindow *win = wxFindWinFromHandle((WXHWND)wParam); + if ( win && win->GetParent() == parent ) + { + wxPanel *panel = wxDynamicCast(parent, wxPanel); + if ( panel ) + { + panel->SetDefaultItem(this); + } + // else: I don't know what to do - we'll still have the problem + // with multiple default buttons in a dialog... + } + } + + // let the base class do all real processing + return wxControl::MSWWindowProc(nMsg, wParam, lParam); +} diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp index 1fb674564e..22b89e7b4e 100644 --- a/src/msw/menu.cpp +++ b/src/msw/menu.cpp @@ -150,6 +150,7 @@ void wxMenu::Append(wxMenuItem *pItem) wxAcceleratorEntry *accel = wxGetAccelFromString(pItem->GetText()); if ( accel ) { m_accels.Add(accel); + accel->m_command = pItem->GetId(); } #endif // wxUSE_ACCEL diff --git a/src/msw/spinctrl.cpp b/src/msw/spinctrl.cpp index 983181c466..1e5ed52266 100644 --- a/src/msw/spinctrl.cpp +++ b/src/msw/spinctrl.cpp @@ -42,6 +42,8 @@ #include #endif +#include // for INT_MIN + // ---------------------------------------------------------------------------- // macros // ---------------------------------------------------------------------------- @@ -69,6 +71,7 @@ static const int MARGIN_BETWEEN = 1; bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id, + const wxString& value, const wxPoint& pos, const wxSize& size, long style, @@ -149,9 +152,37 @@ bool wxSpinCtrl::Create(wxWindow *parent, // associate the text window with the spin button (void)::SendMessage(GetHwnd(), UDM_SETBUDDY, (WPARAM)m_hwndBuddy, 0); + if ( !value.IsEmpty() ) + { + SetValue(value); + } + return TRUE; } +// ---------------------------------------------------------------------------- +// wxTextCtrl-like methods +// ---------------------------------------------------------------------------- + +void wxSpinCtrl::SetValue(const wxString& text) +{ + if ( ::SetWindowText((HWND)m_hwndBuddy, text.c_str()) ) + { + wxLogLastError("SetWindowText(buddy)"); + } +} + +int wxSpinCtrl::GetValue() const +{ + wxString val = wxGetWindowText(m_hwndBuddy); + + long n; + if ( (wxSscanf(val, wxT("%lu"), &n) != 1) ) + n = INT_MIN; + + return n; +} + // ---------------------------------------------------------------------------- // when setting font, we need to do it for both controls // ----------------------------------------------------------------------------