Use border style consistently in the widgets sample

Use GetAttrs().m_defaultFlags everywhere when creating the widgets, it
was done for some but not all of them before, without any apparent
reason.

This should make setting various border styles work (for the widgets
supporting them).
This commit is contained in:
Vadim Zeitlin 2018-03-17 17:50:56 +01:00
parent 0acb119ccb
commit 7e8fb1e294
13 changed files with 83 additions and 78 deletions

View File

@ -81,9 +81,6 @@ protected:
// restore the checkboxes state to the initial values // restore the checkboxes state to the initial values
void Reset(); void Reset();
// get the initial style for the picker of the given kind
long GetPickerStyle();
void OnColourChange(wxColourPickerEvent &ev); void OnColourChange(wxColourPickerEvent &ev);
void OnCheckBox(wxCommandEvent &ev); void OnCheckBox(wxCommandEvent &ev);
@ -175,14 +172,7 @@ void ColourPickerWidgetsPage::CreatePicker()
{ {
delete m_clrPicker; delete m_clrPicker;
m_clrPicker = new wxColourPickerCtrl(this, PickerPage_Colour, *wxRED, long style = GetAttrs().m_defaultFlags;
wxDefaultPosition, wxDefaultSize,
GetPickerStyle());
}
long ColourPickerWidgetsPage::GetPickerStyle()
{
long style = 0;
if ( m_chkColourTextCtrl->GetValue() ) if ( m_chkColourTextCtrl->GetValue() )
style |= wxCLRP_USE_TEXTCTRL; style |= wxCLRP_USE_TEXTCTRL;
@ -193,7 +183,9 @@ long ColourPickerWidgetsPage::GetPickerStyle()
if ( m_chkColourShowAlpha->GetValue() ) if ( m_chkColourShowAlpha->GetValue() )
style |= wxCLRP_SHOW_ALPHA; style |= wxCLRP_SHOW_ALPHA;
return style; m_clrPicker = new wxColourPickerCtrl(this, PickerPage_Colour, *wxRED,
wxDefaultPosition, wxDefaultSize,
style);
} }
void ColourPickerWidgetsPage::RecreatePicker() void ColourPickerWidgetsPage::RecreatePicker()

View File

@ -243,7 +243,7 @@ void DatePickerWidgetsPage::CreateDatePicker()
delete m_datePicker; delete m_datePicker;
long style = 0; long style = GetAttrs().m_defaultFlags;
switch ( m_radioKind->GetSelection() ) switch ( m_radioKind->GetSelection() )
{ {
case 0: case 0:

View File

@ -246,18 +246,27 @@ void DirCtrlWidgetsPage::CreateDirCtrl()
{ {
wxWindowUpdateLocker noUpdates(this); wxWindowUpdateLocker noUpdates(this);
long style = GetAttrs().m_defaultFlags;
if ( m_chkDirOnly->IsChecked() )
style |= wxDIRCTRL_DIR_ONLY;
if ( m_chk3D->IsChecked() )
style |= wxDIRCTRL_3D_INTERNAL;
if ( m_chkFirst->IsChecked() )
style |= wxDIRCTRL_SELECT_FIRST;
if ( m_chkFilters->IsChecked() )
style |= wxDIRCTRL_SHOW_FILTERS;
if ( m_chkLabels->IsChecked() )
style |= wxDIRCTRL_EDIT_LABELS;
if ( m_chkMulti->IsChecked() )
style |= wxDIRCTRL_MULTIPLE;
wxGenericDirCtrl *dirCtrl = new wxGenericDirCtrl( wxGenericDirCtrl *dirCtrl = new wxGenericDirCtrl(
this, this,
DirCtrlPage_Ctrl, DirCtrlPage_Ctrl,
wxDirDialogDefaultFolderStr, wxDirDialogDefaultFolderStr,
wxDefaultPosition, wxDefaultPosition,
wxDefaultSize, wxDefaultSize,
( m_chkDirOnly->IsChecked() ? wxDIRCTRL_DIR_ONLY : 0 ) | style
( m_chk3D->IsChecked() ? wxDIRCTRL_3D_INTERNAL : 0 ) |
( m_chkFirst->IsChecked() ? wxDIRCTRL_SELECT_FIRST : 0 ) |
( m_chkFilters->IsChecked() ? wxDIRCTRL_SHOW_FILTERS : 0 ) |
( m_chkLabels->IsChecked() ? wxDIRCTRL_EDIT_LABELS : 0 ) |
( m_chkMulti->IsChecked() ? wxDIRCTRL_MULTIPLE : 0)
); );
wxString filter; wxString filter;

View File

@ -83,9 +83,6 @@ protected:
// restore the checkboxes state to the initial values // restore the checkboxes state to the initial values
void Reset(); void Reset();
// get the initial style for the picker of the given kind
long GetPickerStyle();
void OnDirChange(wxFileDirPickerEvent &ev); void OnDirChange(wxFileDirPickerEvent &ev);
void OnCheckBox(wxCommandEvent &ev); void OnCheckBox(wxCommandEvent &ev);
@ -194,15 +191,7 @@ void DirPickerWidgetsPage::CreatePicker()
{ {
delete m_dirPicker; delete m_dirPicker;
m_dirPicker = new wxDirPickerCtrl(this, PickerPage_Dir, long style = GetAttrs().m_defaultFlags;
wxGetHomeDir(), wxT("Hello!"),
wxDefaultPosition, wxDefaultSize,
GetPickerStyle());
}
long DirPickerWidgetsPage::GetPickerStyle()
{
long style = 0;
if ( m_chkDirTextCtrl->GetValue() ) if ( m_chkDirTextCtrl->GetValue() )
style |= wxDIRP_USE_TEXTCTRL; style |= wxDIRP_USE_TEXTCTRL;
@ -216,7 +205,10 @@ long DirPickerWidgetsPage::GetPickerStyle()
if ( m_chkSmall->GetValue() ) if ( m_chkSmall->GetValue() )
style |= wxDIRP_SMALL; style |= wxDIRP_SMALL;
return style; m_dirPicker = new wxDirPickerCtrl(this, PickerPage_Dir,
wxGetHomeDir(), wxT("Hello!"),
wxDefaultPosition, wxDefaultSize,
style);
} }
void DirPickerWidgetsPage::RecreatePicker() void DirPickerWidgetsPage::RecreatePicker()

View File

@ -178,7 +178,7 @@ void EditableListboxWidgetsPage::Reset()
void EditableListboxWidgetsPage::CreateLbox() void EditableListboxWidgetsPage::CreateLbox()
{ {
int flags = 0; long flags = GetAttrs().m_defaultFlags;
if ( m_chkAllowNew->GetValue() ) if ( m_chkAllowNew->GetValue() )
flags |= wxEL_ALLOW_NEW; flags |= wxEL_ALLOW_NEW;

View File

@ -227,11 +227,14 @@ void FileCtrlWidgetsPage::CreateFileCtrl()
{ {
wxWindowUpdateLocker noUpdates( this ); wxWindowUpdateLocker noUpdates( this );
const int style = long style = GetAttrs().m_defaultFlags;
( m_radioFileCtrlMode->GetSelection() == FileCtrlMode_Open ? style |= m_radioFileCtrlMode->GetSelection() == FileCtrlMode_Open
wxFC_OPEN : wxFC_SAVE ) | ? wxFC_OPEN
( m_chkMultiple->IsChecked() ? wxFC_MULTIPLE : 0 ) | : wxFC_SAVE;
( m_chkNoShowHidden->IsChecked() ? wxFC_NOSHOWHIDDEN : 0 ); if ( m_chkMultiple->IsChecked() )
style |= wxFC_MULTIPLE;
if ( m_chkNoShowHidden->IsChecked() )
style |= wxFC_NOSHOWHIDDEN;
wxFileCtrl *fileCtrl = new wxFileCtrl( wxFileCtrl *fileCtrl = new wxFileCtrl(
this, this,

View File

@ -90,9 +90,6 @@ protected:
// restore the checkboxes state to the initial values // restore the checkboxes state to the initial values
void Reset(); void Reset();
// get the initial style for the picker of the given kind
long GetPickerStyle();
// update filepicker radiobox // update filepicker radiobox
void UpdateFilePickerMode(); void UpdateFilePickerMode();
@ -223,17 +220,7 @@ void FilePickerWidgetsPage::CreatePicker()
{ {
delete m_filePicker; delete m_filePicker;
// pass an empty string as initial file long style = GetAttrs().m_defaultFlags;
m_filePicker = new wxFilePickerCtrl(this, PickerPage_File,
wxEmptyString,
wxT("Hello!"), wxT("*"),
wxDefaultPosition, wxDefaultSize,
GetPickerStyle());
}
long FilePickerWidgetsPage::GetPickerStyle()
{
long style = 0;
if ( m_chkFileTextCtrl->GetValue() ) if ( m_chkFileTextCtrl->GetValue() )
style |= wxFLP_USE_TEXTCTRL; style |= wxFLP_USE_TEXTCTRL;
@ -255,7 +242,12 @@ long FilePickerWidgetsPage::GetPickerStyle()
else else
style |= wxFLP_SAVE; style |= wxFLP_SAVE;
return style; // pass an empty string as initial file
m_filePicker = new wxFilePickerCtrl(this, PickerPage_File,
wxEmptyString,
wxT("Hello!"), wxT("*"),
wxDefaultPosition, wxDefaultSize,
style);
} }
void FilePickerWidgetsPage::RecreatePicker() void FilePickerWidgetsPage::RecreatePicker()

View File

@ -81,9 +81,6 @@ protected:
// restore the checkboxes state to the initial values // restore the checkboxes state to the initial values
void Reset(); void Reset();
// get the initial style for the picker of the given kind
long GetPickerStyle();
void OnFontChange(wxFontPickerEvent &ev); void OnFontChange(wxFontPickerEvent &ev);
void OnCheckBox(wxCommandEvent &ev); void OnCheckBox(wxCommandEvent &ev);
@ -175,15 +172,7 @@ void FontPickerWidgetsPage::CreatePicker()
{ {
delete m_fontPicker; delete m_fontPicker;
m_fontPicker = new wxFontPickerCtrl(this, PickerPage_Font, long style = GetAttrs().m_defaultFlags;
*wxSWISS_FONT,
wxDefaultPosition, wxDefaultSize,
GetPickerStyle());
}
long FontPickerWidgetsPage::GetPickerStyle()
{
long style = 0;
if ( m_chkFontTextCtrl->GetValue() ) if ( m_chkFontTextCtrl->GetValue() )
style |= wxFNTP_USE_TEXTCTRL; style |= wxFNTP_USE_TEXTCTRL;
@ -192,9 +181,12 @@ long FontPickerWidgetsPage::GetPickerStyle()
style |= wxFNTP_USEFONT_FOR_LABEL; style |= wxFNTP_USEFONT_FOR_LABEL;
if ( m_chkFontDescAsLabel->GetValue() ) if ( m_chkFontDescAsLabel->GetValue() )
style |= wxFNTP_FONTDESC_AS_LABEL; style |= wxFNTP_FONTDESC_AS_LABEL;
return style; m_fontPicker = new wxFontPickerCtrl(this, PickerPage_Font,
*wxSWISS_FONT,
wxDefaultPosition, wxDefaultSize,
style);
} }
void FontPickerWidgetsPage::RecreatePicker() void FontPickerWidgetsPage::RecreatePicker()

View File

@ -99,7 +99,7 @@ protected:
// (re)create the hyperctrl // (re)create the hyperctrl
void CreateHyperlink(); void CreateHyperlink();
void CreateHyperlinkLong(long); void CreateHyperlinkLong(long align);
// the controls // the controls
// ------------ // ------------
@ -259,6 +259,9 @@ void HyperlinkWidgetsPage::CreateHyperlink()
{ {
const wxString label = m_hyperlink->GetLabel(); const wxString label = m_hyperlink->GetLabel();
const wxString url = m_hyperlink->GetURL(); const wxString url = m_hyperlink->GetURL();
long style = GetAttrs().m_defaultFlags;
style |= wxHL_DEFAULT_STYLE & ~wxBORDER_MASK;
wxGenericHyperlinkCtrl *hyp; wxGenericHyperlinkCtrl *hyp;
if (m_checkGeneric->IsChecked()) if (m_checkGeneric->IsChecked())
@ -266,14 +269,20 @@ void HyperlinkWidgetsPage::CreateHyperlink()
hyp = new wxGenericHyperlinkCtrl(this, hyp = new wxGenericHyperlinkCtrl(this,
HyperlinkPage_Ctrl, HyperlinkPage_Ctrl,
label, label,
url); url,
wxDefaultPosition,
wxDefaultSize,
style);
} }
else else
{ {
hyp = new wxHyperlinkCtrl(this, hyp = new wxHyperlinkCtrl(this,
HyperlinkPage_Ctrl, HyperlinkPage_Ctrl,
label, label,
url); url,
wxDefaultPosition,
wxDefaultSize,
style);
} }
// update sizer's child window // update sizer's child window
@ -287,9 +296,11 @@ void HyperlinkWidgetsPage::CreateHyperlink()
GetSizer()->Layout(); GetSizer()->Layout();
} }
void HyperlinkWidgetsPage::CreateHyperlinkLong(long style) void HyperlinkWidgetsPage::CreateHyperlinkLong(long align)
{ {
style = (wxHL_DEFAULT_STYLE & ~wxHL_ALIGN_CENTRE)|style; long style = GetAttrs().m_defaultFlags;
style |= align;
style |= wxHL_DEFAULT_STYLE & ~(wxHL_ALIGN_CENTRE | wxBORDER_MASK);
wxGenericHyperlinkCtrl *hyp; wxGenericHyperlinkCtrl *hyp;
if (m_checkGeneric->IsChecked()) if (m_checkGeneric->IsChecked())

View File

@ -68,7 +68,6 @@ class SearchCtrlWidgetsPage : public WidgetsPage
{ {
public: public:
SearchCtrlWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist); SearchCtrlWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist);
virtual ~SearchCtrlWidgetsPage(){};
virtual wxWindow *GetWidget() const wxOVERRIDE { return m_srchCtrl; } virtual wxWindow *GetWidget() const wxOVERRIDE { return m_srchCtrl; }
virtual wxTextEntryBase *GetTextEntry() const wxOVERRIDE { return m_srchCtrl; } virtual wxTextEntryBase *GetTextEntry() const wxOVERRIDE { return m_srchCtrl; }
@ -176,7 +175,7 @@ void SearchCtrlWidgetsPage::CreateControl()
if (m_srchCtrl) if (m_srchCtrl)
m_srchCtrl->Destroy(); m_srchCtrl->Destroy();
int style = 0; long style = GetAttrs().m_defaultFlags;
m_srchCtrl = new wxSearchCtrl(this, -1, wxEmptyString, wxDefaultPosition, m_srchCtrl = new wxSearchCtrl(this, -1, wxEmptyString, wxDefaultPosition,
wxSize(150, -1), style); wxSize(150, -1), style);

View File

@ -132,10 +132,21 @@ void StatBmpWidgetsPage::RecreateWidget()
wxLogMessage("Reading image from file '%s' failed.", filepath.c_str()); wxLogMessage("Reading image from file '%s' failed.", filepath.c_str());
return; return;
} }
long style = GetAttrs().m_defaultFlags;
if (m_radio->GetSelection() == 0) if (m_radio->GetSelection() == 0)
m_statbmp = new wxStaticBitmap(this, wxID_ANY, wxBitmap(image)); {
m_statbmp = new wxStaticBitmap(this, wxID_ANY, wxBitmap(image),
wxDefaultPosition, wxDefaultSize,
style);
}
else else
m_statbmp = new wxGenericStaticBitmap(this, wxID_ANY, wxBitmap(image)); {
m_statbmp = new wxGenericStaticBitmap(this, wxID_ANY, wxBitmap(image),
wxDefaultPosition, wxDefaultSize,
style);
}
wxStaticBitmapBase::ScaleMode scaleMode = (wxStaticBitmapBase::ScaleMode) m_scaleRadio->GetSelection(); wxStaticBitmapBase::ScaleMode scaleMode = (wxStaticBitmapBase::ScaleMode) m_scaleRadio->GetSelection();
m_statbmp->SetScaleMode(scaleMode); m_statbmp->SetScaleMode(scaleMode);

View File

@ -195,7 +195,11 @@ void TimePickerWidgetsPage::CreateTimePicker()
delete m_timePicker; delete m_timePicker;
m_timePicker = new wxTimePickerCtrl(this, TimePickerPage_Picker, value); long style = GetAttrs().m_defaultFlags;
m_timePicker = new wxTimePickerCtrl(this, TimePickerPage_Picker, value,
wxDefaultPosition, wxDefaultSize,
style);
m_sizerTimePicker->Add(0, 0, 1, wxCENTRE); m_sizerTimePicker->Add(0, 0, 1, wxCENTRE);
m_sizerTimePicker->Add(m_timePicker, 1, wxCENTRE); m_sizerTimePicker->Add(m_timePicker, 1, wxCENTRE);

View File

@ -115,7 +115,7 @@ struct WidgetAttributes
wxWindowVariant m_variant; wxWindowVariant m_variant;
wxCursor m_cursor; wxCursor m_cursor;
// the default flags, currently only contains border flags // the default flags, currently only contains border flags
int m_defaultFlags; long m_defaultFlags;
}; };
class WidgetsPage : public wxPanel class WidgetsPage : public wxPanel