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:
@@ -6,11 +6,11 @@
|
|||||||
// Created: 01/02/97
|
// Created: 01/02/97
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c)
|
// Copyright: (c)
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef __PANELH_G__
|
#ifndef _WX_GENERIC_PANEL_H_
|
||||||
#define __PANELH_G__
|
#define _WX_GENERIC_PANEL_H_
|
||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
#pragma interface "panelg.h"
|
#pragma interface "panelg.h"
|
||||||
@@ -100,4 +100,4 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
// __PANELH_G__
|
// _WX_GENERIC_PANEL_H_
|
||||||
|
@@ -53,6 +53,7 @@ public:
|
|||||||
|
|
||||||
// implementation from now on
|
// implementation from now on
|
||||||
virtual void Command(wxCommandEvent& event);
|
virtual void Command(wxCommandEvent& event);
|
||||||
|
virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
|
||||||
virtual bool MSWCommand(WXUINT param, WXWORD id);
|
virtual bool MSWCommand(WXUINT param, WXWORD id);
|
||||||
virtual WXHBRUSH OnCtlColor(WXHDC pDC,
|
virtual WXHBRUSH OnCtlColor(WXHDC pDC,
|
||||||
WXHWND pWnd,
|
WXHWND pWnd,
|
||||||
|
@@ -31,24 +31,32 @@ public:
|
|||||||
|
|
||||||
wxSpinCtrl(wxWindow *parent,
|
wxSpinCtrl(wxWindow *parent,
|
||||||
wxWindowID id = -1,
|
wxWindowID id = -1,
|
||||||
|
const wxString& value = wxEmptyString,
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
const wxSize& size = wxDefaultSize,
|
const wxSize& size = wxDefaultSize,
|
||||||
long style = wxSP_ARROW_KEYS,
|
long style = wxSP_ARROW_KEYS,
|
||||||
int min = 0, int max = 100, int initial = 0,
|
int min = 0, int max = 100, int initial = 0,
|
||||||
const wxString& name = _T("wxSpinCtrl"))
|
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,
|
bool Create(wxWindow *parent,
|
||||||
wxWindowID id = -1,
|
wxWindowID id = -1,
|
||||||
|
const wxString& value = wxEmptyString,
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
const wxSize& size = wxDefaultSize,
|
const wxSize& size = wxDefaultSize,
|
||||||
long style = wxSP_ARROW_KEYS,
|
long style = wxSP_ARROW_KEYS,
|
||||||
int min = 0, int max = 100, int initial = 0,
|
int min = 0, int max = 100, int initial = 0,
|
||||||
const wxString& name = _T("wxSpinCtrl"));
|
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
|
// 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);
|
virtual bool SetFont(const wxFont &font);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@@ -527,7 +527,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
|
|||||||
#endif // wxUSE_SPINBUTTON
|
#endif // wxUSE_SPINBUTTON
|
||||||
|
|
||||||
#if wxUSE_SPINCTRL
|
#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->SetRange(10,30);
|
||||||
m_spinctrl->SetValue(15);
|
m_spinctrl->SetValue(15);
|
||||||
#endif // wxUSE_SPINCTRL
|
#endif // wxUSE_SPINCTRL
|
||||||
|
@@ -45,6 +45,8 @@
|
|||||||
#include "wx/statline.h"
|
#include "wx/statline.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "wx/spinctrl.h"
|
||||||
|
|
||||||
// this is where wxGetNumberFromUser() is declared
|
// this is where wxGetNumberFromUser() is declared
|
||||||
#include "wx/generic/textdlgg.h"
|
#include "wx/generic/textdlgg.h"
|
||||||
|
|
||||||
@@ -69,7 +71,7 @@ public:
|
|||||||
void OnCancel(wxCommandEvent& event);
|
void OnCancel(wxCommandEvent& event);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxTextCtrl *m_spinctrl; // TODO replace it with wxSpinCtrl once it's done
|
wxSpinCtrl *m_spinctrl;
|
||||||
|
|
||||||
long m_value, m_min, m_max;
|
long m_value, m_min, m_max;
|
||||||
|
|
||||||
@@ -107,12 +109,12 @@ wxNumberEntryDialog::wxNumberEntryDialog(wxWindow *parent,
|
|||||||
m_min = min;
|
m_min = min;
|
||||||
|
|
||||||
wxBeginBusyCursor();
|
wxBeginBusyCursor();
|
||||||
|
|
||||||
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
|
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
|
||||||
|
|
||||||
// 1) text message
|
// 1) text message
|
||||||
topsizer->Add( CreateTextSizer( message ), 0, wxALL, 10 );
|
topsizer->Add( CreateTextSizer( message ), 0, wxALL, 10 );
|
||||||
|
|
||||||
// 2) prompt and text ctrl
|
// 2) prompt and text ctrl
|
||||||
wxBoxSizer *inputsizer = new wxBoxSizer( wxHORIZONTAL );
|
wxBoxSizer *inputsizer = new wxBoxSizer( wxHORIZONTAL );
|
||||||
// prompt if any
|
// prompt if any
|
||||||
@@ -121,9 +123,9 @@ wxNumberEntryDialog::wxNumberEntryDialog(wxWindow *parent,
|
|||||||
// spin ctrl
|
// spin ctrl
|
||||||
wxString valStr;
|
wxString valStr;
|
||||||
valStr.Printf(wxT("%lu"), m_value);
|
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 );
|
inputsizer->Add( m_spinctrl, 1, wxCENTER | wxLEFT | wxRIGHT, 10 );
|
||||||
// add both
|
// add both
|
||||||
topsizer->Add( inputsizer, 1, wxEXPAND | wxLEFT|wxRIGHT, 5 );
|
topsizer->Add( inputsizer, 1, wxEXPAND | wxLEFT|wxRIGHT, 5 );
|
||||||
|
|
||||||
#if wxUSE_STATLINE
|
#if wxUSE_STATLINE
|
||||||
@@ -133,7 +135,7 @@ wxNumberEntryDialog::wxNumberEntryDialog(wxWindow *parent,
|
|||||||
|
|
||||||
// 4) buttons
|
// 4) buttons
|
||||||
topsizer->Add( CreateButtonSizer( wxOK|wxCANCEL ), 0, wxCENTRE | wxALL, 10 );
|
topsizer->Add( CreateButtonSizer( wxOK|wxCANCEL ), 0, wxCENTRE | wxALL, 10 );
|
||||||
|
|
||||||
SetSizer( topsizer );
|
SetSizer( topsizer );
|
||||||
SetAutoLayout( TRUE );
|
SetAutoLayout( TRUE );
|
||||||
|
|
||||||
@@ -149,8 +151,8 @@ wxNumberEntryDialog::wxNumberEntryDialog(wxWindow *parent,
|
|||||||
|
|
||||||
void wxNumberEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event))
|
void wxNumberEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
if ( (wxSscanf(m_spinctrl->GetValue(), wxT("%lu"), &m_value) != 1) ||
|
m_value = m_spinctrl->GetValue();
|
||||||
(m_value < m_min) || (m_value > m_max) )
|
if ( m_value < m_min || m_value > m_max )
|
||||||
{
|
{
|
||||||
// not a number or out of range
|
// not a number or out of range
|
||||||
m_value = -1;
|
m_value = -1;
|
||||||
|
@@ -70,9 +70,6 @@ bool wxButton::Create(wxWindow *parent,
|
|||||||
if ( !CreateBase(parent, id, pos, size, style, validator, name) )
|
if ( !CreateBase(parent, id, pos, size, style, validator, name) )
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
// Validator was set in CreateBase
|
|
||||||
//SetValidator(validator);
|
|
||||||
|
|
||||||
parent->AddChild((wxButton *)this);
|
parent->AddChild((wxButton *)this);
|
||||||
|
|
||||||
m_backgroundColour = parent->GetBackgroundColour() ;
|
m_backgroundColour = parent->GetBackgroundColour() ;
|
||||||
@@ -104,8 +101,10 @@ bool wxButton::Create(wxWindow *parent,
|
|||||||
wxSize nsize( GetSize() );
|
wxSize nsize( GetSize() );
|
||||||
if ((nsize.x < 80) || (nsize.y < 23))
|
if ((nsize.x < 80) || (nsize.y < 23))
|
||||||
{
|
{
|
||||||
if ((size.x == -1) && (nsize.x < 80)) nsize.x = 80;
|
if ((size.x == -1) && (nsize.x < 80))
|
||||||
if ((size.y == -1) && (nsize.y < 23)) nsize.y = 23;
|
nsize.x = 80;
|
||||||
|
if ((size.y == -1) && (nsize.y < 23))
|
||||||
|
nsize.y = 23;
|
||||||
SetSize( nsize );
|
SetSize( nsize );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +233,7 @@ bool wxButton::MSWCommand(WXUINT param, WXWORD id)
|
|||||||
bool processed = FALSE;
|
bool processed = FALSE;
|
||||||
switch ( param )
|
switch ( param )
|
||||||
{
|
{
|
||||||
case 1: // 1 for accelerator
|
case 1: // means that the message came from an accelerator
|
||||||
case BN_CLICKED:
|
case BN_CLICKED:
|
||||||
processed = SendClickEvent();
|
processed = SendClickEvent();
|
||||||
break;
|
break;
|
||||||
@@ -255,3 +254,28 @@ WXHBRUSH wxButton::OnCtlColor(WXHDC pDC,
|
|||||||
return (WXHBRUSH) backgroundBrush->GetResourceHandle();
|
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);
|
||||||
|
}
|
||||||
|
@@ -150,6 +150,7 @@ void wxMenu::Append(wxMenuItem *pItem)
|
|||||||
wxAcceleratorEntry *accel = wxGetAccelFromString(pItem->GetText());
|
wxAcceleratorEntry *accel = wxGetAccelFromString(pItem->GetText());
|
||||||
if ( accel ) {
|
if ( accel ) {
|
||||||
m_accels.Add(accel);
|
m_accels.Add(accel);
|
||||||
|
accel->m_command = pItem->GetId();
|
||||||
}
|
}
|
||||||
#endif // wxUSE_ACCEL
|
#endif // wxUSE_ACCEL
|
||||||
|
|
||||||
|
@@ -42,6 +42,8 @@
|
|||||||
#include <commctrl.h>
|
#include <commctrl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <limits.h> // for INT_MIN
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// macros
|
// macros
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -69,6 +71,7 @@ static const int MARGIN_BETWEEN = 1;
|
|||||||
|
|
||||||
bool wxSpinCtrl::Create(wxWindow *parent,
|
bool wxSpinCtrl::Create(wxWindow *parent,
|
||||||
wxWindowID id,
|
wxWindowID id,
|
||||||
|
const wxString& value,
|
||||||
const wxPoint& pos,
|
const wxPoint& pos,
|
||||||
const wxSize& size,
|
const wxSize& size,
|
||||||
long style,
|
long style,
|
||||||
@@ -149,9 +152,37 @@ bool wxSpinCtrl::Create(wxWindow *parent,
|
|||||||
// associate the text window with the spin button
|
// associate the text window with the spin button
|
||||||
(void)::SendMessage(GetHwnd(), UDM_SETBUDDY, (WPARAM)m_hwndBuddy, 0);
|
(void)::SendMessage(GetHwnd(), UDM_SETBUDDY, (WPARAM)m_hwndBuddy, 0);
|
||||||
|
|
||||||
|
if ( !value.IsEmpty() )
|
||||||
|
{
|
||||||
|
SetValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
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
|
// when setting font, we need to do it for both controls
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user