From 1301e2289f81208bdd2cb1ac92a0d13c3d0959c4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 16 Apr 2006 23:39:11 +0000 Subject: [PATCH] added a menu allowing to change the border style used by the widget git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38772 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/widgets/button.cpp | 3 +- samples/widgets/checkbox.cpp | 3 +- samples/widgets/combobox.cpp | 3 +- samples/widgets/gauge.cpp | 3 +- samples/widgets/listbox.cpp | 3 +- samples/widgets/notebook.cpp | 11 +++---- samples/widgets/radiobox.cpp | 3 ++ samples/widgets/slider.cpp | 3 +- samples/widgets/spinbtn.cpp | 3 +- samples/widgets/static.cpp | 3 +- samples/widgets/textctrl.cpp | 3 +- samples/widgets/widgets.cpp | 57 ++++++++++++++++++++++++++++++++++-- samples/widgets/widgets.h | 8 +++++ 13 files changed, 89 insertions(+), 17 deletions(-) diff --git a/samples/widgets/button.cpp b/samples/widgets/button.cpp index 4023441785..8e855553a3 100644 --- a/samples/widgets/button.cpp +++ b/samples/widgets/button.cpp @@ -83,6 +83,7 @@ public: virtual ~ButtonWidgetsPage(){}; virtual wxControl *GetWidget() const { return m_button; } + virtual void RecreateWidget() { CreateButton(); } protected: // event handlers @@ -311,7 +312,7 @@ void ButtonWidgetsPage::CreateButton() label = m_textLabel->GetValue(); } - int flags = 0; + int flags = ms_defaultFlags; switch ( m_radioHAlign->GetSelection() ) { case ButtonHAlign_Left: diff --git a/samples/widgets/checkbox.cpp b/samples/widgets/checkbox.cpp index aeaf200853..5b41e219f3 100644 --- a/samples/widgets/checkbox.cpp +++ b/samples/widgets/checkbox.cpp @@ -77,6 +77,7 @@ public: virtual ~CheckBoxWidgetsPage(){}; virtual wxControl *GetWidget() const { return m_checkbox; } + virtual void RecreateWidget() { CreateCheckbox(); } protected: // event handlers @@ -243,7 +244,7 @@ void CheckBoxWidgetsPage::CreateCheckbox() delete m_checkbox; - int flags = 0; + int flags = ms_defaultFlags; if ( m_chkRight->IsChecked() ) flags |= wxALIGN_RIGHT; diff --git a/samples/widgets/combobox.cpp b/samples/widgets/combobox.cpp index f973500bb2..d3e703bea4 100644 --- a/samples/widgets/combobox.cpp +++ b/samples/widgets/combobox.cpp @@ -88,6 +88,7 @@ public: ComboboxWidgetsPage(wxBookCtrlBase *book, wxImageList *imaglist); virtual wxControl *GetWidget() const { return m_combobox; } + virtual void RecreateWidget() { CreateCombo(); } protected: // event handlers @@ -334,7 +335,7 @@ void ComboboxWidgetsPage::Reset() void ComboboxWidgetsPage::CreateCombo() { - int flags = 0; + int flags = ms_defaultFlags; if ( m_chkSort->GetValue() ) flags |= wxCB_SORT; diff --git a/samples/widgets/gauge.cpp b/samples/widgets/gauge.cpp index 743592a7ba..5b950ee073 100644 --- a/samples/widgets/gauge.cpp +++ b/samples/widgets/gauge.cpp @@ -75,6 +75,7 @@ public: virtual ~GaugeWidgetsPage(); virtual wxControl *GetWidget() const { return m_gauge; } + virtual void RecreateWidget() { CreateGauge(); } protected: // event handlers @@ -259,7 +260,7 @@ void GaugeWidgetsPage::Reset() void GaugeWidgetsPage::CreateGauge() { - int flags = 0; + int flags = ms_defaultFlags; if ( m_chkVert->GetValue() ) flags |= wxGA_VERTICAL; diff --git a/samples/widgets/listbox.cpp b/samples/widgets/listbox.cpp index 24610b6f0c..713a117d74 100644 --- a/samples/widgets/listbox.cpp +++ b/samples/widgets/listbox.cpp @@ -79,6 +79,7 @@ public: ListboxWidgetsPage(wxBookCtrlBase *book, wxImageList *imaglist); virtual wxControl *GetWidget() const { return m_lbox; } + virtual void RecreateWidget() { CreateLbox(); } protected: // event handlers @@ -334,7 +335,7 @@ void ListboxWidgetsPage::Reset() void ListboxWidgetsPage::CreateLbox() { - int flags = 0; + int flags = ms_defaultFlags; switch ( m_radioSelMode->GetSelection() ) { default: diff --git a/samples/widgets/notebook.cpp b/samples/widgets/notebook.cpp index 0edbed19a6..0d15102e26 100644 --- a/samples/widgets/notebook.cpp +++ b/samples/widgets/notebook.cpp @@ -90,6 +90,7 @@ public: virtual ~NotebookWidgetsPage(); virtual wxControl *GetWidget() const { return m_notebook; } + virtual void RecreateWidget() { CreateNotebook(); } protected: // event handlers @@ -344,7 +345,7 @@ void NotebookWidgetsPage::CreateImageList() void NotebookWidgetsPage::CreateNotebook() { - int flags; + int flags = ms_defaultFlags; switch ( m_radioOrient->GetSelection() ) { default: @@ -352,19 +353,19 @@ void NotebookWidgetsPage::CreateNotebook() // fall through case Orient_Top: - flags = wxBK_TOP; + flags |= wxBK_TOP; break; case Orient_Bottom: - flags = wxBK_BOTTOM; + flags |= wxBK_BOTTOM; break; case Orient_Left: - flags = wxBK_LEFT; + flags |= wxBK_LEFT; break; case Orient_Right: - flags = wxBK_RIGHT; + flags |= wxBK_RIGHT; break; } diff --git a/samples/widgets/radiobox.cpp b/samples/widgets/radiobox.cpp index ddb8456084..91f5cc9fa9 100644 --- a/samples/widgets/radiobox.cpp +++ b/samples/widgets/radiobox.cpp @@ -87,6 +87,7 @@ public: virtual ~RadioWidgetsPage(){}; virtual wxControl *GetWidget() const { return m_radio; } + virtual void RecreateWidget() { CreateRadio(); } protected: // event handlers @@ -356,6 +357,8 @@ void RadioWidgetsPage::CreateRadio() int flags = m_chkVert->GetValue() ? wxRA_VERTICAL : wxRA_HORIZONTAL; + flags |= ms_defaultFlags; + #ifdef wxRA_LEFTTORIGHT switch ( m_radioDir->GetSelection() ) { diff --git a/samples/widgets/slider.cpp b/samples/widgets/slider.cpp index b23a4a7453..c70a794731 100644 --- a/samples/widgets/slider.cpp +++ b/samples/widgets/slider.cpp @@ -93,6 +93,7 @@ public: virtual ~SliderWidgetsPage(){}; virtual wxControl *GetWidget() const { return m_slider; } + virtual void RecreateWidget() { CreateSlider(); } protected: // event handlers @@ -333,7 +334,7 @@ void SliderWidgetsPage::Reset() void SliderWidgetsPage::CreateSlider() { - int flags = 0; + int flags = ms_defaultFlags; if ( m_chkInverse->GetValue() ) { diff --git a/samples/widgets/spinbtn.cpp b/samples/widgets/spinbtn.cpp index c0fd377581..cf8c255d4f 100644 --- a/samples/widgets/spinbtn.cpp +++ b/samples/widgets/spinbtn.cpp @@ -78,6 +78,7 @@ public: virtual wxControl *GetWidget() const { return m_spinbtn; } virtual wxControl *GetWidget2() const { return m_spinctrl; } + virtual void RecreateWidget() { CreateSpin(); } protected: // event handlers @@ -268,7 +269,7 @@ void SpinBtnWidgetsPage::Reset() void SpinBtnWidgetsPage::CreateSpin() { - int flags = 0; + int flags = ms_defaultFlags; bool isVert = m_chkVert->GetValue(); if ( isVert ) diff --git a/samples/widgets/static.cpp b/samples/widgets/static.cpp index 496284b85c..499a0037b6 100644 --- a/samples/widgets/static.cpp +++ b/samples/widgets/static.cpp @@ -143,6 +143,7 @@ public: virtual ~StaticWidgetsPage(){}; virtual wxControl *GetWidget() const { return m_statText; } + virtual void RecreateWidget() { CreateStatic(); } protected: // event handlers @@ -333,7 +334,7 @@ void StaticWidgetsPage::CreateStatic() } int flagsBox = 0, - flagsText = 0; + flagsText = ms_defaultFlags; if ( !m_chkAutoResize->GetValue() ) { diff --git a/samples/widgets/textctrl.cpp b/samples/widgets/textctrl.cpp index 3a6c35f698..6fd19a5497 100644 --- a/samples/widgets/textctrl.cpp +++ b/samples/widgets/textctrl.cpp @@ -136,6 +136,7 @@ public: virtual ~TextWidgetsPage(){}; virtual wxControl *GetWidget() const { return m_text; } + virtual void RecreateWidget() { CreateText(); } protected: // create an info text contorl @@ -599,7 +600,7 @@ void TextWidgetsPage::Reset() void TextWidgetsPage::CreateText() { - int flags = 0; + int flags = ms_defaultFlags; switch ( m_radioTextLines->GetSelection() ) { default: diff --git a/samples/widgets/widgets.cpp b/samples/widgets/widgets.cpp index 2b03a39c03..2378c6b78e 100644 --- a/samples/widgets/widgets.cpp +++ b/samples/widgets/widgets.cpp @@ -58,13 +58,22 @@ enum { Widgets_ClearLog = 100, Widgets_Quit, + #if wxUSE_TOOLTIPS Widgets_SetTooltip, #endif // wxUSE_TOOLTIPS Widgets_SetFgColour, Widgets_SetBgColour, Widgets_SetFont, - Widgets_Enable + Widgets_Enable, + + Widgets_BorderNone, + Widgets_BorderStatic, + Widgets_BorderSimple, + Widgets_BorderRaised, + Widgets_BorderSunken, + Widgets_BorderDouble, + Widgets_BorderDefault }; // ---------------------------------------------------------------------------- @@ -107,6 +116,7 @@ protected: void OnSetBgCol(wxCommandEvent& event); void OnSetFont(wxCommandEvent& event); void OnEnable(wxCommandEvent& event); + void OnSetBorder(wxCommandEvent& event); #endif // wxUSE_MENUS // initialize the book: add all pages to it @@ -228,6 +238,9 @@ BEGIN_EVENT_TABLE(WidgetsFrame, wxFrame) EVT_MENU(Widgets_SetFont, WidgetsFrame::OnSetFont) EVT_MENU(Widgets_Enable, WidgetsFrame::OnEnable) + EVT_MENU_RANGE(Widgets_BorderNone, Widgets_BorderDefault, + WidgetsFrame::OnSetBorder) + EVT_MENU(wxID_EXIT, WidgetsFrame::OnExit) END_EVENT_TABLE() @@ -305,6 +318,17 @@ WidgetsFrame::WidgetsFrame(const wxString& title) menuWidget->Append(Widgets_SetBgColour, _T("Set &background...\tCtrl-B")); menuWidget->Append(Widgets_SetFont, _T("Set f&ont...\tCtrl-O")); menuWidget->AppendCheckItem(Widgets_Enable, _T("&Enable/disable\tCtrl-E")); + + wxMenu *menuBorders = new wxMenu; + menuBorders->AppendRadioItem(Widgets_BorderDefault, _T("De&fault\tCtrl-Shift-9")); + menuBorders->AppendRadioItem(Widgets_BorderNone, _T("&None\tCtrl-Shift-0")); + menuBorders->AppendRadioItem(Widgets_BorderSimple, _T("&Simple\tCtrl-Shift-1")); + menuBorders->AppendRadioItem(Widgets_BorderDouble, _T("&Double\tCtrl-Shift-2")); + menuBorders->AppendRadioItem(Widgets_BorderStatic, _T("Stati&c\tCtrl-Shift-3")); + menuBorders->AppendRadioItem(Widgets_BorderRaised, _T("&Raised\tCtrl-Shift-4")); + menuBorders->AppendRadioItem(Widgets_BorderSunken, _T("S&unken\tCtrl-Shift-5")); + menuWidget->AppendSubMenu(menuBorders, _T("Set &border")); + menuWidget->AppendSeparator(); menuWidget->Append(wxID_EXIT, _T("&Quit\tCtrl-Q")); mbar->Append(menuWidget, _T("&Widget")); @@ -577,14 +601,38 @@ void WidgetsFrame::OnEnable(wxCommandEvent& event) page->GetWidget()->Enable(event.IsChecked()); } +void WidgetsFrame::OnSetBorder(wxCommandEvent& event) +{ + int border; + switch ( event.GetId() ) + { + case Widgets_BorderNone: border = wxBORDER_NONE; break; + case Widgets_BorderStatic: border = wxBORDER_STATIC; break; + case Widgets_BorderSimple: border = wxBORDER_SIMPLE; break; + case Widgets_BorderRaised: border = wxBORDER_RAISED; break; + case Widgets_BorderSunken: border = wxBORDER_SUNKEN; break; + case Widgets_BorderDouble: border = wxBORDER_DOUBLE; break; + + default: + wxFAIL_MSG( _T("unknown border style") ); + // fall through + + case Widgets_BorderDefault: border = wxBORDER_DEFAULT; break; + } + + WidgetsPage::ms_defaultFlags &= ~wxBORDER_MASK; + WidgetsPage::ms_defaultFlags |= border; + + WidgetsPage *page = wxStaticCast(m_book->GetCurrentPage(), WidgetsPage); + page->RecreateWidget(); +} + #endif // wxUSE_MENUS // ---------------------------------------------------------------------------- // WidgetsPageInfo // ---------------------------------------------------------------------------- -WidgetsPageInfo *WidgetsPage::ms_widgetPages = NULL; - WidgetsPageInfo::WidgetsPageInfo(Constructor ctor, const wxChar *label) : m_label(label) { @@ -644,6 +692,9 @@ WidgetsPageInfo::WidgetsPageInfo(Constructor ctor, const wxChar *label) // WidgetsPage // ---------------------------------------------------------------------------- +int WidgetsPage::ms_defaultFlags = wxBORDER_DEFAULT; +WidgetsPageInfo *WidgetsPage::ms_widgetPages = NULL; + WidgetsPage::WidgetsPage(wxBookCtrlBase *book) : wxPanel(book, wxID_ANY, wxDefaultPosition, wxDefaultSize, diff --git a/samples/widgets/widgets.h b/samples/widgets/widgets.h index 0fb6e05b58..d8e40df3ce 100644 --- a/samples/widgets/widgets.h +++ b/samples/widgets/widgets.h @@ -45,6 +45,14 @@ public: // some pages show 2 controls, in this case override this one as well virtual wxControl *GetWidget2() const { return NULL; } + // recreate the control shown by this page + // + // this is currently used only to take into account the border flags + virtual void RecreateWidget() = 0; + + // the default flags for the widget, currently only contains border flags + static int ms_defaultFlags; + protected: // several helper functions for page creation -- 2.45.2