// 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"
};
#endif
- // __PANELH_G__
+ // _WX_GENERIC_PANEL_H_
// 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,
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:
#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
#include "wx/statline.h"
#endif
+#include "wx/spinctrl.h"
+
// this is where wxGetNumberFromUser() is declared
#include "wx/generic/textdlgg.h"
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;
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
// 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
// 4) buttons
topsizer->Add( CreateButtonSizer( wxOK|wxCANCEL ), 0, wxCENTRE | wxALL, 10 );
-
+
SetSizer( topsizer );
SetAutoLayout( TRUE );
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;
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() ;
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 );
}
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;
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);
+}
wxAcceleratorEntry *accel = wxGetAccelFromString(pItem->GetText());
if ( accel ) {
m_accels.Add(accel);
+ accel->m_command = pItem->GetId();
}
#endif // wxUSE_ACCEL
#include <commctrl.h>
#endif
+#include <limits.h> // for INT_MIN
+
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
bool wxSpinCtrl::Create(wxWindow *parent,
wxWindowID id,
+ const wxString& value,
const wxPoint& pos,
const wxSize& size,
long style,
// 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
// ----------------------------------------------------------------------------