add alignment flags support to wxSpinCtrl[Double] (closes #10621)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59719 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
0e5bf041b0
commit
7e4952db83
@ -50,7 +50,7 @@ public:
|
||||
const wxString& value = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxSP_ARROW_KEYS,
|
||||
long style = wxSP_ARROW_KEYS | wxTE_RIGHT,
|
||||
double min = 0, double max = 100, double initial = 0, double inc = 1,
|
||||
const wxString& name = _T("wxSpinCtrl"));
|
||||
|
||||
@ -157,7 +157,7 @@ public:
|
||||
const wxString& value = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxSP_ARROW_KEYS,
|
||||
long style = wxSP_ARROW_KEYS | wxTE_RIGHT,
|
||||
double min = 0, double max = 100, double initial = 0, double inc = 1,
|
||||
const wxString& name = _T("wxSpinCtrl"))
|
||||
{
|
||||
@ -232,7 +232,7 @@ public:
|
||||
const wxString& value = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxSP_ARROW_KEYS,
|
||||
long style = wxSP_ARROW_KEYS | wxTE_RIGHT,
|
||||
int min = 0, int max = 100, int initial = 0,
|
||||
const wxString& name = _T("wxSpinCtrl"))
|
||||
{
|
||||
@ -244,7 +244,7 @@ public:
|
||||
const wxString& value = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxSP_ARROW_KEYS,
|
||||
long style = wxSP_ARROW_KEYS | wxTE_RIGHT,
|
||||
int min = 0, int max = 100, int initial = 0,
|
||||
const wxString& name = _T("wxSpinCtrl"))
|
||||
{
|
||||
@ -285,7 +285,7 @@ public:
|
||||
const wxString& value = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxSP_ARROW_KEYS,
|
||||
long style = wxSP_ARROW_KEYS | wxTE_RIGHT,
|
||||
double min = 0, double max = 100, double initial = 0, double inc = 1,
|
||||
const wxString& name = _T("wxSpinCtrlDouble"))
|
||||
{
|
||||
@ -298,7 +298,7 @@ public:
|
||||
const wxString& value = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxSP_ARROW_KEYS,
|
||||
long style = wxSP_ARROW_KEYS | wxTE_RIGHT,
|
||||
double min = 0, double max = 100, double initial = 0, double inc = 1,
|
||||
const wxString& name = _T("wxSpinCtrlDouble"))
|
||||
{
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
const wxString& value = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxSP_ARROW_KEYS,
|
||||
long style = wxSP_ARROW_KEYS | wxTE_RIGHT,
|
||||
double min = 0, double max = 100, double initial = 0, double inc = 1,
|
||||
const wxString& name = _T("wxSpinCtrlGTKBase"));
|
||||
|
||||
@ -101,7 +101,7 @@ public:
|
||||
const wxString& value = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxSP_ARROW_KEYS,
|
||||
long style = wxSP_ARROW_KEYS | wxTE_RIGHT,
|
||||
int min = 0, int max = 100, int initial = 0,
|
||||
const wxString& name = _T("wxSpinCtrl"))
|
||||
{
|
||||
@ -113,7 +113,7 @@ public:
|
||||
const wxString& value = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxSP_ARROW_KEYS,
|
||||
long style = wxSP_ARROW_KEYS | wxTE_RIGHT,
|
||||
int min = 0, int max = 100, int initial = 0,
|
||||
const wxString& name = _T("wxSpinCtrl"))
|
||||
{
|
||||
@ -149,7 +149,7 @@ public:
|
||||
const wxString& value = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxSP_ARROW_KEYS,
|
||||
long style = wxSP_ARROW_KEYS | wxTE_RIGHT,
|
||||
double min = 0, double max = 100, double initial = 0, double inc = 1,
|
||||
const wxString& name = _T("wxSpinCtrlDouble"))
|
||||
{
|
||||
@ -161,7 +161,7 @@ public:
|
||||
const wxString& value = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxSP_ARROW_KEYS,
|
||||
long style = wxSP_ARROW_KEYS | wxTE_RIGHT,
|
||||
double min = 0, double max = 100, double initial = 0, double inc = 1,
|
||||
const wxString& name = _T("wxSpinCtrlDouble"))
|
||||
{
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
const wxString& value = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxSP_ARROW_KEYS,
|
||||
long style = wxSP_ARROW_KEYS | wxTE_RIGHT,
|
||||
int min = 0, int max = 100, int initial = 0,
|
||||
const wxString& name = _T("wxSpinCtrl"))
|
||||
{
|
||||
@ -49,7 +49,7 @@ public:
|
||||
const wxString& value = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxSP_ARROW_KEYS,
|
||||
long style = wxSP_ARROW_KEYS | wxTE_RIGHT,
|
||||
int min = 0, int max = 100, int initial = 0,
|
||||
const wxString& name = _T("wxSpinCtrl"));
|
||||
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
const wxString& value = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxSP_ARROW_KEYS,
|
||||
long style = wxSP_ARROW_KEYS | wxTE_RIGHT,
|
||||
int min = 0, int max = 100, int initial = 0,
|
||||
const wxString& name = _T("wxSpinCtrl"))
|
||||
{
|
||||
@ -56,7 +56,7 @@ public:
|
||||
const wxString& value = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxSP_ARROW_KEYS,
|
||||
long style = wxSP_ARROW_KEYS | wxTE_RIGHT,
|
||||
int min = 0, int max = 100, int initial = 0,
|
||||
const wxString& name = _T("wxSpinCtrl"));
|
||||
|
||||
@ -135,7 +135,7 @@ public:
|
||||
const wxString& value = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxSP_ARROW_KEYS,
|
||||
long style = wxSP_ARROW_KEYS | wxTE_RIGHT,
|
||||
int min = 0, int max = 100, int initial = 0,
|
||||
const wxString& name = _T("wxSpinCtrl"))
|
||||
{
|
||||
@ -147,7 +147,7 @@ public:
|
||||
const wxString& value = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxSP_ARROW_KEYS,
|
||||
long style = wxSP_ARROW_KEYS | wxTE_RIGHT,
|
||||
int min = 0, int max = 100, int initial = 0,
|
||||
const wxString& name = _T("wxSpinCtrl"))
|
||||
{
|
||||
|
@ -21,6 +21,13 @@
|
||||
events. Using this style will prevent the user from using the Enter key
|
||||
for dialog navigation (e.g. activating the default button in the
|
||||
dialog) under MSW.
|
||||
@style{wxTE_LEFT}
|
||||
Same as for wxTextCtrl: the text is left aligned.
|
||||
@style{wxTE_CENTER}
|
||||
Same as for wxTextCtrl: the text is centered.
|
||||
@style{wxTE_RIGHT}
|
||||
Same as for wxTextCtrl: the text is right aligned (this is the
|
||||
default).
|
||||
@endStyleTable
|
||||
|
||||
|
||||
|
@ -67,6 +67,14 @@ enum
|
||||
SpinBtnPage_SpinCtrlDouble
|
||||
};
|
||||
|
||||
// alignment radiobox values
|
||||
enum
|
||||
{
|
||||
Align_Left,
|
||||
Align_Centre,
|
||||
Align_Right
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SpinBtnWidgetsPage
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -130,6 +138,7 @@ protected:
|
||||
*m_chkArrowKeys,
|
||||
*m_chkWrap,
|
||||
*m_chkProcessEnter;
|
||||
wxRadioBox *m_radioAlign;
|
||||
|
||||
// the spinbtn and the spinctrl and the sizer containing them
|
||||
wxSpinButton *m_spinbtn;
|
||||
@ -199,6 +208,7 @@ SpinBtnWidgetsPage::SpinBtnWidgetsPage(WidgetsBookCtrl *book,
|
||||
m_chkArrowKeys = NULL;
|
||||
m_chkWrap = NULL;
|
||||
m_chkProcessEnter = NULL;
|
||||
m_radioAlign = NULL;
|
||||
m_spinbtn = NULL;
|
||||
m_spinctrl = NULL;
|
||||
m_spinctrldbl = NULL;
|
||||
@ -228,6 +238,21 @@ void SpinBtnWidgetsPage::CreateContent()
|
||||
|
||||
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
|
||||
|
||||
static const wxString halign[] =
|
||||
{
|
||||
_T("left"),
|
||||
_T("centre"),
|
||||
_T("right"),
|
||||
};
|
||||
|
||||
m_radioAlign = new wxRadioBox(this, wxID_ANY, _T("&Text alignment"),
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
WXSIZEOF(halign), halign, 1);
|
||||
|
||||
sizerLeft->Add(m_radioAlign, 0, wxGROW | wxALL, 5);
|
||||
|
||||
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
|
||||
|
||||
wxButton *btn = new wxButton(this, SpinBtnPage_Reset, _T("&Reset"));
|
||||
sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
|
||||
|
||||
@ -291,6 +316,7 @@ void SpinBtnWidgetsPage::Reset()
|
||||
m_chkArrowKeys->SetValue(true);
|
||||
m_chkWrap->SetValue(false);
|
||||
m_chkProcessEnter->SetValue(false);
|
||||
m_radioAlign->SetSelection(Align_Right);
|
||||
}
|
||||
|
||||
void SpinBtnWidgetsPage::CreateSpin()
|
||||
@ -312,6 +338,26 @@ void SpinBtnWidgetsPage::CreateSpin()
|
||||
if ( m_chkProcessEnter->GetValue() )
|
||||
flags |= wxTE_PROCESS_ENTER;
|
||||
|
||||
int textFlags = 0;
|
||||
switch ( m_radioAlign->GetSelection() )
|
||||
{
|
||||
default:
|
||||
wxFAIL_MSG(_T("unexpected radiobox selection"));
|
||||
// fall through
|
||||
|
||||
case Align_Left:
|
||||
textFlags |= wxALIGN_LEFT; // no-op
|
||||
break;
|
||||
|
||||
case Align_Centre:
|
||||
textFlags |= wxALIGN_CENTRE_HORIZONTAL;
|
||||
break;
|
||||
|
||||
case Align_Right:
|
||||
textFlags |= wxALIGN_RIGHT;
|
||||
break;
|
||||
}
|
||||
|
||||
int val = m_min;
|
||||
if ( m_spinbtn )
|
||||
{
|
||||
@ -334,13 +380,13 @@ void SpinBtnWidgetsPage::CreateSpin()
|
||||
m_spinctrl = new wxSpinCtrl(this, SpinBtnPage_SpinCtrl,
|
||||
wxString::Format(_T("%d"), val),
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
flags,
|
||||
flags | textFlags,
|
||||
m_min, m_max, val);
|
||||
|
||||
m_spinctrldbl = new wxSpinCtrlDouble(this, SpinBtnPage_SpinCtrlDouble,
|
||||
wxString::Format(_T("%d"), val),
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
flags,
|
||||
flags | textFlags,
|
||||
m_min, m_max, val, 0.1);
|
||||
|
||||
// Add spacers, labels and spin controls to the sizer.
|
||||
|
@ -58,9 +58,9 @@ static const wxCoord MARGIN = 2;
|
||||
class wxSpinCtrlTextGeneric : public wxTextCtrl
|
||||
{
|
||||
public:
|
||||
wxSpinCtrlTextGeneric(wxSpinCtrlGenericBase *spin, const wxString& value)
|
||||
: wxTextCtrl(spin->GetParent(), wxID_ANY, value, wxDefaultPosition,
|
||||
wxDefaultSize, wxTE_NOHIDESEL|wxTE_PROCESS_ENTER)
|
||||
wxSpinCtrlTextGeneric(wxSpinCtrlGenericBase *spin, const wxString& value, long style=0)
|
||||
: wxTextCtrl(spin->GetParent(), wxID_ANY, value, wxDefaultPosition, wxDefaultSize,
|
||||
( style & wxALIGN_MASK ) | wxTE_NOHIDESEL | wxTE_PROCESS_ENTER)
|
||||
{
|
||||
m_spin = spin;
|
||||
|
||||
@ -197,7 +197,7 @@ bool wxSpinCtrlGenericBase::Create(wxWindow *parent,
|
||||
m_max = max;
|
||||
m_increment = increment;
|
||||
|
||||
m_textCtrl = new wxSpinCtrlTextGeneric(this, value);
|
||||
m_textCtrl = new wxSpinCtrlTextGeneric(this, value, style);
|
||||
m_spinButton = new wxSpinCtrlButtonGeneric(this, style);
|
||||
|
||||
m_spin_value = m_spinButton->GetValue();
|
||||
|
@ -118,6 +118,16 @@ bool wxSpinCtrlGTKBase::Create(wxWindow *parent, wxWindowID id,
|
||||
gtk_spin_button_set_value( GTK_SPIN_BUTTON(m_widget), initial);
|
||||
m_value = gtk_spin_button_get_value( GTK_SPIN_BUTTON(m_widget));
|
||||
|
||||
gfloat align;
|
||||
if ( HasFlag(wxTE_RIGHT) )
|
||||
align = 1.0;
|
||||
else if ( HasFlag(wxTE_CENTRE) )
|
||||
align = 0.5;
|
||||
else
|
||||
align = 0.0;
|
||||
|
||||
gtk_entry_set_alignment(GTK_ENTRY(m_widget), align);
|
||||
|
||||
gtk_spin_button_set_wrap( GTK_SPIN_BUTTON(m_widget),
|
||||
(int)(m_windowStyle & wxSP_WRAP) );
|
||||
|
||||
|
@ -335,10 +335,16 @@ bool wxSpinCtrl::Create(wxWindow *parent,
|
||||
WXDWORD exStyle = 0;
|
||||
WXDWORD msStyle = MSWGetStyle(GetWindowStyle(), & exStyle) ;
|
||||
|
||||
// propagate text alignment style to text ctrl
|
||||
if ( style & wxTE_RIGHT )
|
||||
msStyle |= ES_RIGHT;
|
||||
else if ( style & wxTE_CENTER )
|
||||
msStyle |= ES_CENTER;
|
||||
|
||||
// this control is used for numeric entry so normally using these flags by
|
||||
// default shouldn't be a problem, if it is we can always add a style such
|
||||
// as wxSP_NON_NUMERIC later
|
||||
msStyle |= ES_RIGHT | ES_NUMBER;
|
||||
msStyle |= ES_NUMBER;
|
||||
|
||||
// calculate the sizes: the size given is the total size for both controls
|
||||
// and we need to fit them both in the given width (height is the same)
|
||||
|
@ -250,7 +250,7 @@ bool wxSpinCtrl::Create(wxWindow *parent,
|
||||
}
|
||||
|
||||
wxSize csize = size ;
|
||||
m_text = new wxSpinCtrlText(this, value, style & wxTE_PROCESS_ENTER ? wxTE_PROCESS_ENTER : 0 );
|
||||
m_text = new wxSpinCtrlText(this, value, style & ( wxTE_PROCESS_ENTER | wxALIGN_MASK ) );
|
||||
m_btn = new wxSpinCtrlButton(this, style);
|
||||
|
||||
m_btn->SetRange(min, max);
|
||||
|
@ -77,6 +77,9 @@ wxSpinCtrlXmlHandler::wxSpinCtrlXmlHandler()
|
||||
XRC_ADD_STYLE(wxSP_VERTICAL);
|
||||
XRC_ADD_STYLE(wxSP_ARROW_KEYS);
|
||||
XRC_ADD_STYLE(wxSP_WRAP);
|
||||
XRC_ADD_STYLE(wxTE_LEFT);
|
||||
XRC_ADD_STYLE(wxTE_CENTER);
|
||||
XRC_ADD_STYLE(wxTE_RIGHT);
|
||||
}
|
||||
|
||||
wxObject *wxSpinCtrlXmlHandler::DoCreateResource()
|
||||
@ -87,7 +90,7 @@ wxObject *wxSpinCtrlXmlHandler::DoCreateResource()
|
||||
GetID(),
|
||||
GetText(wxT("value")),
|
||||
GetPosition(), GetSize(),
|
||||
GetStyle(wxT("style"), wxSP_ARROW_KEYS),
|
||||
GetStyle(wxT("style"), wxSP_ARROW_KEYS | wxTE_RIGHT),
|
||||
GetLong(wxT("min"), DEFAULT_MIN),
|
||||
GetLong(wxT("max"), DEFAULT_MAX),
|
||||
GetLong(wxT("value"), DEFAULT_VALUE),
|
||||
|
Loading…
Reference in New Issue
Block a user