#endif
//-----------------------------------------------------------------------------
-// wxSpinButton
+// wxSpinCtrl
//-----------------------------------------------------------------------------
class wxSpinCtrl : public wxControl
wxSpinCtrl() {}
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"));
+ void SetValue(const wxString& text);
+
virtual int GetValue() const;
virtual void SetValue( int value );
virtual void SetRange( int minVal, int maxVal );
virtual int GetMin() const;
virtual int GetMax() const;
+ // implementation
bool IsOwnGtkWindow( GdkWindow *window );
void ApplyWidgetStyle();
#endif
//-----------------------------------------------------------------------------
-// wxSpinButton
+// wxSpinCtrl
//-----------------------------------------------------------------------------
class wxSpinCtrl : public wxControl
wxSpinCtrl() {}
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"));
+ void SetValue(const wxString& text);
+
virtual int GetValue() const;
virtual void SetValue( int value );
virtual void SetRange( int minVal, int maxVal );
virtual int GetMin() const;
virtual int GetMax() const;
+ // implementation
bool IsOwnGtkWindow( GdkWindow *window );
void ApplyWidgetStyle();
IMPLEMENT_DYNAMIC_CLASS(wxSpinCtrl,wxControl)
bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id,
- const wxPoint& pos, const wxSize& size,
- long style,
- int min, int max, int initial,
- const wxString& name)
+ const wxString& value,
+ const wxPoint& pos, const wxSize& size,
+ long style,
+ int min, int max, int initial,
+ const wxString& name)
{
m_needParent = TRUE;
SetBackgroundColour( parent->GetBackgroundColour() );
+ SetValue( value );
+
Show( TRUE );
return TRUE;
return (int)ceil(m_adjust->value);
}
+void wxSpinCtrl::SetValue( const wxString& value )
+{
+ wxCHECK_RET( (m_widget != NULL), wxT("invalid spin button") );
+
+ int n;
+ if ( (wxSscanf(value, wxT("%d"), &n) == 1) )
+ {
+ // a number - set it
+ SetValue(n);
+ }
+ else
+ {
+ // invalid number - set text as is (wxMSW compatible)
+ gtk_entry_set_text( GTK_ENTRY(m_widget), value.c_str() );
+ }
+}
+
void wxSpinCtrl::SetValue( int value )
{
wxCHECK_RET( (m_widget != NULL), wxT("invalid spin button") );
IMPLEMENT_DYNAMIC_CLASS(wxSpinCtrl,wxControl)
bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id,
- const wxPoint& pos, const wxSize& size,
- long style,
- int min, int max, int initial,
- const wxString& name)
+ const wxString& value,
+ const wxPoint& pos, const wxSize& size,
+ long style,
+ int min, int max, int initial,
+ const wxString& name)
{
m_needParent = TRUE;
SetBackgroundColour( parent->GetBackgroundColour() );
+ SetValue( value );
+
Show( TRUE );
return TRUE;
return (int)ceil(m_adjust->value);
}
+void wxSpinCtrl::SetValue( const wxString& value )
+{
+ wxCHECK_RET( (m_widget != NULL), wxT("invalid spin button") );
+
+ int n;
+ if ( (wxSscanf(value, wxT("%d"), &n) == 1) )
+ {
+ // a number - set it
+ SetValue(n);
+ }
+ else
+ {
+ // invalid number - set text as is (wxMSW compatible)
+ gtk_entry_set_text( GTK_ENTRY(m_widget), value.c_str() );
+ }
+}
+
void wxSpinCtrl::SetValue( int value )
{
wxCHECK_RET( (m_widget != NULL), wxT("invalid spin button") );