Add presentation of text alignment in wxTextCtrl to widgets sample
Added an option to choose text alignment styles for wxTextCtrl presented in the sample.
This commit is contained in:
@@ -86,6 +86,14 @@ enum WrapStyle
|
|||||||
WrapStyle_Max
|
WrapStyle_Max
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Alignment style radio box
|
||||||
|
enum AlignmentStyle
|
||||||
|
{
|
||||||
|
Align_Left,
|
||||||
|
Align_Center,
|
||||||
|
Align_Right,
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
|
|
||||||
// textctrl kind values
|
// textctrl kind values
|
||||||
@@ -111,6 +119,7 @@ static const struct ControlValues
|
|||||||
bool noVertScrollbar;
|
bool noVertScrollbar;
|
||||||
|
|
||||||
WrapStyle wrapStyle;
|
WrapStyle wrapStyle;
|
||||||
|
AlignmentStyle alignmentStyle;
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
TextKind textKind;
|
TextKind textKind;
|
||||||
@@ -124,6 +133,7 @@ static const struct ControlValues
|
|||||||
false, // not filename
|
false, // not filename
|
||||||
false, // don't hide vertical scrollbar
|
false, // don't hide vertical scrollbar
|
||||||
WrapStyle_Word, // wrap on word boundaries
|
WrapStyle_Word, // wrap on word boundaries
|
||||||
|
Align_Left, // leading-alignment
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
TextKind_Plain // plain EDIT control
|
TextKind_Plain // plain EDIT control
|
||||||
#endif // __WXMSW__
|
#endif // __WXMSW__
|
||||||
@@ -208,6 +218,9 @@ protected:
|
|||||||
// and another one to choose the wrapping style
|
// and another one to choose the wrapping style
|
||||||
wxRadioBox *m_radioWrap;
|
wxRadioBox *m_radioWrap;
|
||||||
|
|
||||||
|
// and yet another one to choose the alignment style
|
||||||
|
wxRadioBox *m_radioAlign;
|
||||||
|
|
||||||
// the checkboxes controlling text ctrl styles
|
// the checkboxes controlling text ctrl styles
|
||||||
wxCheckBox *m_chkPassword,
|
wxCheckBox *m_chkPassword,
|
||||||
*m_chkReadonly,
|
*m_chkReadonly,
|
||||||
@@ -370,6 +383,7 @@ TextWidgetsPage::TextWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist)
|
|||||||
m_radioKind =
|
m_radioKind =
|
||||||
#endif // __WXMSW__
|
#endif // __WXMSW__
|
||||||
m_radioWrap =
|
m_radioWrap =
|
||||||
|
m_radioAlign =
|
||||||
m_radioTextLines = (wxRadioBox *)NULL;
|
m_radioTextLines = (wxRadioBox *)NULL;
|
||||||
|
|
||||||
m_chkPassword =
|
m_chkPassword =
|
||||||
@@ -449,6 +463,18 @@ void TextWidgetsPage::CreateContent()
|
|||||||
1, wxRA_SPECIFY_COLS);
|
1, wxRA_SPECIFY_COLS);
|
||||||
sizerLeft->Add(m_radioWrap, 0, wxGROW | wxALL, 5);
|
sizerLeft->Add(m_radioWrap, 0, wxGROW | wxALL, 5);
|
||||||
|
|
||||||
|
static const wxString halign[] =
|
||||||
|
{
|
||||||
|
wxS("left"),
|
||||||
|
wxS("centre"),
|
||||||
|
wxS("right"),
|
||||||
|
};
|
||||||
|
|
||||||
|
m_radioAlign = new wxRadioBox(this, wxID_ANY, wxS("&Text alignment"),
|
||||||
|
wxDefaultPosition, wxDefaultSize,
|
||||||
|
WXSIZEOF(halign), halign, 1);
|
||||||
|
sizerLeft->Add(m_radioAlign, 0, wxGROW | wxALL, 5);
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
static const wxString kinds[] =
|
static const wxString kinds[] =
|
||||||
{
|
{
|
||||||
@@ -635,6 +661,7 @@ void TextWidgetsPage::Reset()
|
|||||||
m_chkNoVertScrollbar->SetValue(DEFAULTS.noVertScrollbar);
|
m_chkNoVertScrollbar->SetValue(DEFAULTS.noVertScrollbar);
|
||||||
|
|
||||||
m_radioWrap->SetSelection(DEFAULTS.wrapStyle);
|
m_radioWrap->SetSelection(DEFAULTS.wrapStyle);
|
||||||
|
m_radioAlign->SetSelection(DEFAULTS.alignmentStyle);
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
m_radioKind->SetSelection(DEFAULTS.textKind);
|
m_radioKind->SetSelection(DEFAULTS.textKind);
|
||||||
@@ -690,6 +717,21 @@ void TextWidgetsPage::CreateText()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch ( m_radioAlign->GetSelection() )
|
||||||
|
{
|
||||||
|
case Align_Left:
|
||||||
|
flags |= wxTE_LEFT;
|
||||||
|
break;
|
||||||
|
case Align_Center:
|
||||||
|
flags |= wxTE_CENTER;
|
||||||
|
break;
|
||||||
|
case Align_Right:
|
||||||
|
flags |= wxTE_RIGHT;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
wxFAIL_MSG( wxS("unexpected alignment style radio box selection") );
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
switch ( m_radioKind->GetSelection() )
|
switch ( m_radioKind->GetSelection() )
|
||||||
{
|
{
|
||||||
@@ -949,9 +991,47 @@ void TextWidgetsPage::OnTextPasted(wxClipboardTextEvent& event)
|
|||||||
event.Skip();
|
event.Skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
|
void TextWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
|
#if defined(__WXMSW__) || defined(__WXGTK__)
|
||||||
|
// We should be able to change text alignment
|
||||||
|
// dynamically, without recreating the control.
|
||||||
|
if( event.GetEventObject() == m_radioAlign )
|
||||||
|
{
|
||||||
|
long flags = m_text->GetWindowStyle();
|
||||||
|
flags &= ~(wxTE_LEFT|wxTE_CENTER|wxTE_RIGHT);
|
||||||
|
|
||||||
|
switch ( event.GetSelection() )
|
||||||
|
{
|
||||||
|
case Align_Left:
|
||||||
|
flags |= wxTE_LEFT;
|
||||||
|
break;
|
||||||
|
case Align_Center:
|
||||||
|
flags |= wxTE_CENTER;
|
||||||
|
break;
|
||||||
|
case Align_Right:
|
||||||
|
flags |= wxTE_RIGHT;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
wxFAIL_MSG( wxS("unexpected alignment style radio box selection") );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_text->SetWindowStyle(flags);
|
||||||
|
m_text->Refresh();
|
||||||
|
|
||||||
|
flags = m_text->GetWindowStyle();
|
||||||
|
wxLogMessage(wxString::Format("Text alignment: %s",
|
||||||
|
(flags & wxTE_RIGHT) ? "Right" :
|
||||||
|
(flags & wxTE_CENTER) ? "Center" : "Left"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#else
|
||||||
|
wxUnusedVar(event);
|
||||||
|
#endif // WXMSW || WXGTK
|
||||||
|
{
|
||||||
CreateText();
|
CreateText();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextWidgetsPage::OnStreamRedirector(wxCommandEvent& WXUNUSED(event))
|
void TextWidgetsPage::OnStreamRedirector(wxCommandEvent& WXUNUSED(event))
|
||||||
|
Reference in New Issue
Block a user