Skip to content

Commit

Permalink
Use border style consistently in the widgets sample
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
vadz committed Mar 17, 2018
1 parent 0acb119 commit 7e8fb1e
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 78 deletions.
16 changes: 4 additions & 12 deletions samples/widgets/clrpicker.cpp
Expand Up @@ -81,9 +81,6 @@ class ColourPickerWidgetsPage : public WidgetsPage
// restore the checkboxes state to the initial values
void Reset();

// get the initial style for the picker of the given kind
long GetPickerStyle();


void OnColourChange(wxColourPickerEvent &ev);
void OnCheckBox(wxCommandEvent &ev);
Expand Down Expand Up @@ -175,14 +172,7 @@ void ColourPickerWidgetsPage::CreatePicker()
{
delete m_clrPicker;

m_clrPicker = new wxColourPickerCtrl(this, PickerPage_Colour, *wxRED,
wxDefaultPosition, wxDefaultSize,
GetPickerStyle());
}

long ColourPickerWidgetsPage::GetPickerStyle()
{
long style = 0;
long style = GetAttrs().m_defaultFlags;

if ( m_chkColourTextCtrl->GetValue() )
style |= wxCLRP_USE_TEXTCTRL;
Expand All @@ -193,7 +183,9 @@ long ColourPickerWidgetsPage::GetPickerStyle()
if ( m_chkColourShowAlpha->GetValue() )
style |= wxCLRP_SHOW_ALPHA;

return style;
m_clrPicker = new wxColourPickerCtrl(this, PickerPage_Colour, *wxRED,
wxDefaultPosition, wxDefaultSize,
style);
}

void ColourPickerWidgetsPage::RecreatePicker()
Expand Down
2 changes: 1 addition & 1 deletion samples/widgets/datepick.cpp
Expand Up @@ -243,7 +243,7 @@ void DatePickerWidgetsPage::CreateDatePicker()

delete m_datePicker;

long style = 0;
long style = GetAttrs().m_defaultFlags;
switch ( m_radioKind->GetSelection() )
{
case 0:
Expand Down
21 changes: 15 additions & 6 deletions samples/widgets/dirctrl.cpp
Expand Up @@ -246,18 +246,27 @@ void DirCtrlWidgetsPage::CreateDirCtrl()
{
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(
this,
DirCtrlPage_Ctrl,
wxDirDialogDefaultFolderStr,
wxDefaultPosition,
wxDefaultSize,
( m_chkDirOnly->IsChecked() ? wxDIRCTRL_DIR_ONLY : 0 ) |
( 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)
style
);

wxString filter;
Expand Down
18 changes: 5 additions & 13 deletions samples/widgets/dirpicker.cpp
Expand Up @@ -83,9 +83,6 @@ class DirPickerWidgetsPage : public WidgetsPage
// restore the checkboxes state to the initial values
void Reset();

// get the initial style for the picker of the given kind
long GetPickerStyle();


void OnDirChange(wxFileDirPickerEvent &ev);
void OnCheckBox(wxCommandEvent &ev);
Expand Down Expand Up @@ -194,15 +191,7 @@ void DirPickerWidgetsPage::CreatePicker()
{
delete m_dirPicker;

m_dirPicker = new wxDirPickerCtrl(this, PickerPage_Dir,
wxGetHomeDir(), wxT("Hello!"),
wxDefaultPosition, wxDefaultSize,
GetPickerStyle());
}

long DirPickerWidgetsPage::GetPickerStyle()
{
long style = 0;
long style = GetAttrs().m_defaultFlags;

if ( m_chkDirTextCtrl->GetValue() )
style |= wxDIRP_USE_TEXTCTRL;
Expand All @@ -216,7 +205,10 @@ long DirPickerWidgetsPage::GetPickerStyle()
if ( m_chkSmall->GetValue() )
style |= wxDIRP_SMALL;

return style;
m_dirPicker = new wxDirPickerCtrl(this, PickerPage_Dir,
wxGetHomeDir(), wxT("Hello!"),
wxDefaultPosition, wxDefaultSize,
style);
}

void DirPickerWidgetsPage::RecreatePicker()
Expand Down
2 changes: 1 addition & 1 deletion samples/widgets/editlbox.cpp
Expand Up @@ -178,7 +178,7 @@ void EditableListboxWidgetsPage::Reset()

void EditableListboxWidgetsPage::CreateLbox()
{
int flags = 0;
long flags = GetAttrs().m_defaultFlags;

if ( m_chkAllowNew->GetValue() )
flags |= wxEL_ALLOW_NEW;
Expand Down
13 changes: 8 additions & 5 deletions samples/widgets/filectrl.cpp
Expand Up @@ -227,11 +227,14 @@ void FileCtrlWidgetsPage::CreateFileCtrl()
{
wxWindowUpdateLocker noUpdates( this );

const int style =
( m_radioFileCtrlMode->GetSelection() == FileCtrlMode_Open ?
wxFC_OPEN : wxFC_SAVE ) |
( m_chkMultiple->IsChecked() ? wxFC_MULTIPLE : 0 ) |
( m_chkNoShowHidden->IsChecked() ? wxFC_NOSHOWHIDDEN : 0 );
long style = GetAttrs().m_defaultFlags;
style |= m_radioFileCtrlMode->GetSelection() == FileCtrlMode_Open
? wxFC_OPEN
: wxFC_SAVE;
if ( m_chkMultiple->IsChecked() )
style |= wxFC_MULTIPLE;
if ( m_chkNoShowHidden->IsChecked() )
style |= wxFC_NOSHOWHIDDEN;

wxFileCtrl *fileCtrl = new wxFileCtrl(
this,
Expand Down
22 changes: 7 additions & 15 deletions samples/widgets/filepicker.cpp
Expand Up @@ -90,9 +90,6 @@ class FilePickerWidgetsPage : public WidgetsPage
// restore the checkboxes state to the initial values
void Reset();

// get the initial style for the picker of the given kind
long GetPickerStyle();

// update filepicker radiobox
void UpdateFilePickerMode();

Expand Down Expand Up @@ -223,17 +220,7 @@ void FilePickerWidgetsPage::CreatePicker()
{
delete m_filePicker;

// pass an empty string as initial file
m_filePicker = new wxFilePickerCtrl(this, PickerPage_File,
wxEmptyString,
wxT("Hello!"), wxT("*"),
wxDefaultPosition, wxDefaultSize,
GetPickerStyle());
}

long FilePickerWidgetsPage::GetPickerStyle()
{
long style = 0;
long style = GetAttrs().m_defaultFlags;

if ( m_chkFileTextCtrl->GetValue() )
style |= wxFLP_USE_TEXTCTRL;
Expand All @@ -255,7 +242,12 @@ long FilePickerWidgetsPage::GetPickerStyle()
else
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()
Expand Down
20 changes: 6 additions & 14 deletions samples/widgets/fontpicker.cpp
Expand Up @@ -81,9 +81,6 @@ class FontPickerWidgetsPage : public WidgetsPage
// restore the checkboxes state to the initial values
void Reset();

// get the initial style for the picker of the given kind
long GetPickerStyle();


void OnFontChange(wxFontPickerEvent &ev);
void OnCheckBox(wxCommandEvent &ev);
Expand Down Expand Up @@ -175,15 +172,7 @@ void FontPickerWidgetsPage::CreatePicker()
{
delete m_fontPicker;

m_fontPicker = new wxFontPickerCtrl(this, PickerPage_Font,
*wxSWISS_FONT,
wxDefaultPosition, wxDefaultSize,
GetPickerStyle());
}

long FontPickerWidgetsPage::GetPickerStyle()
{
long style = 0;
long style = GetAttrs().m_defaultFlags;

if ( m_chkFontTextCtrl->GetValue() )
style |= wxFNTP_USE_TEXTCTRL;
Expand All @@ -192,9 +181,12 @@ long FontPickerWidgetsPage::GetPickerStyle()
style |= wxFNTP_USEFONT_FOR_LABEL;

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()
Expand Down
21 changes: 16 additions & 5 deletions samples/widgets/hyperlnk.cpp
Expand Up @@ -99,7 +99,7 @@ class HyperlinkWidgetsPage : public WidgetsPage

// (re)create the hyperctrl
void CreateHyperlink();
void CreateHyperlinkLong(long);
void CreateHyperlinkLong(long align);

// the controls
// ------------
Expand Down Expand Up @@ -259,21 +259,30 @@ void HyperlinkWidgetsPage::CreateHyperlink()
{
const wxString label = m_hyperlink->GetLabel();
const wxString url = m_hyperlink->GetURL();
long style = GetAttrs().m_defaultFlags;

style |= wxHL_DEFAULT_STYLE & ~wxBORDER_MASK;

wxGenericHyperlinkCtrl *hyp;
if (m_checkGeneric->IsChecked())
{
hyp = new wxGenericHyperlinkCtrl(this,
HyperlinkPage_Ctrl,
label,
url);
url,
wxDefaultPosition,
wxDefaultSize,
style);
}
else
{
hyp = new wxHyperlinkCtrl(this,
HyperlinkPage_Ctrl,
label,
url);
url,
wxDefaultPosition,
wxDefaultSize,
style);
}

// update sizer's child window
Expand All @@ -287,9 +296,11 @@ void HyperlinkWidgetsPage::CreateHyperlink()
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;
if (m_checkGeneric->IsChecked())
Expand Down
3 changes: 1 addition & 2 deletions samples/widgets/searchctrl.cpp
Expand Up @@ -68,7 +68,6 @@ class SearchCtrlWidgetsPage : public WidgetsPage
{
public:
SearchCtrlWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist);
virtual ~SearchCtrlWidgetsPage(){};

virtual wxWindow *GetWidget() const wxOVERRIDE { return m_srchCtrl; }
virtual wxTextEntryBase *GetTextEntry() const wxOVERRIDE { return m_srchCtrl; }
Expand Down Expand Up @@ -176,7 +175,7 @@ void SearchCtrlWidgetsPage::CreateControl()
if (m_srchCtrl)
m_srchCtrl->Destroy();

int style = 0;
long style = GetAttrs().m_defaultFlags;

m_srchCtrl = new wxSearchCtrl(this, -1, wxEmptyString, wxDefaultPosition,
wxSize(150, -1), style);
Expand Down
15 changes: 13 additions & 2 deletions samples/widgets/statbmp.cpp
Expand Up @@ -132,10 +132,21 @@ void StatBmpWidgetsPage::RecreateWidget()
wxLogMessage("Reading image from file '%s' failed.", filepath.c_str());
return;
}

long style = GetAttrs().m_defaultFlags;

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
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();
m_statbmp->SetScaleMode(scaleMode);
Expand Down
6 changes: 5 additions & 1 deletion samples/widgets/timepick.cpp
Expand Up @@ -195,7 +195,11 @@ void TimePickerWidgetsPage::CreateTimePicker()

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(m_timePicker, 1, wxCENTRE);
Expand Down
2 changes: 1 addition & 1 deletion samples/widgets/widgets.h
Expand Up @@ -115,7 +115,7 @@ struct WidgetAttributes
wxWindowVariant m_variant;
wxCursor m_cursor;
// the default flags, currently only contains border flags
int m_defaultFlags;
long m_defaultFlags;
};

class WidgetsPage : public wxPanel
Expand Down

0 comments on commit 7e8fb1e

Please sign in to comment.