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
This commit is contained in:
Vadim Zeitlin
1999-10-28 01:17:35 +00:00
parent baccb51431
commit 678cd6de66
8 changed files with 87 additions and 20 deletions

View File

@@ -9,8 +9,8 @@
// 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_

View File

@@ -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,

View File

@@ -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:

View File

@@ -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

View File

@@ -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;
@@ -121,7 +123,7 @@ 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
topsizer->Add( inputsizer, 1, wxEXPAND | wxLEFT|wxRIGHT, 5 );
@@ -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;

View File

@@ -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);
}

View File

@@ -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

View File

@@ -42,6 +42,8 @@
#include <commctrl.h>
#endif
#include <limits.h> // 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
// ----------------------------------------------------------------------------