From 195df7a7672277af495a4ecf9bf6eee2a7517069 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 19 Nov 2004 19:03:04 +0000 Subject: [PATCH] added tests for setting fg/bg colours git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30634 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/widgets/button.cpp | 2 ++ samples/widgets/checkbox.cpp | 2 ++ samples/widgets/combobox.cpp | 2 ++ samples/widgets/gauge.cpp | 2 ++ samples/widgets/listbox.cpp | 2 ++ samples/widgets/notebook.cpp | 2 ++ samples/widgets/radiobox.cpp | 2 ++ samples/widgets/slider.cpp | 2 ++ samples/widgets/spinbtn.cpp | 2 ++ samples/widgets/static.cpp | 2 ++ samples/widgets/textctrl.cpp | 2 ++ samples/widgets/widgets.cpp | 65 +++++++++++++++++++++++++++++++++--- samples/widgets/widgets.h | 3 ++ 13 files changed, 86 insertions(+), 4 deletions(-) diff --git a/samples/widgets/button.cpp b/samples/widgets/button.cpp index ebe6d45887..a1f33a0eb9 100644 --- a/samples/widgets/button.cpp +++ b/samples/widgets/button.cpp @@ -80,6 +80,8 @@ public: ButtonWidgetsPage(wxNotebook *notebook, wxImageList *imaglist); virtual ~ButtonWidgetsPage(){}; + virtual wxControl *GetWidget() const { return m_button; } + protected: // event handlers void OnCheckOrRadioBox(wxCommandEvent& event); diff --git a/samples/widgets/checkbox.cpp b/samples/widgets/checkbox.cpp index e336b16221..250fb53614 100644 --- a/samples/widgets/checkbox.cpp +++ b/samples/widgets/checkbox.cpp @@ -76,6 +76,8 @@ public: CheckBoxWidgetsPage(wxNotebook *notebook, wxImageList *imaglist); virtual ~CheckBoxWidgetsPage(){}; + virtual wxControl *GetWidget() const { return m_checkbox; } + protected: // event handlers void OnCheckBox(wxCommandEvent& event); diff --git a/samples/widgets/combobox.cpp b/samples/widgets/combobox.cpp index 6938293e61..875d02296a 100644 --- a/samples/widgets/combobox.cpp +++ b/samples/widgets/combobox.cpp @@ -86,6 +86,8 @@ class ComboboxWidgetsPage : public WidgetsPage public: ComboboxWidgetsPage(wxNotebook *notebook, wxImageList *imaglist); + virtual wxControl *GetWidget() const { return m_combobox; } + protected: // event handlers void OnButtonReset(wxCommandEvent& event); diff --git a/samples/widgets/gauge.cpp b/samples/widgets/gauge.cpp index f20aac08ef..54610ac03b 100644 --- a/samples/widgets/gauge.cpp +++ b/samples/widgets/gauge.cpp @@ -74,6 +74,8 @@ public: GaugeWidgetsPage(wxNotebook *notebook, wxImageList *imaglist); virtual ~GaugeWidgetsPage(); + virtual wxControl *GetWidget() const { return m_gauge; } + protected: // event handlers void OnButtonReset(wxCommandEvent& event); diff --git a/samples/widgets/listbox.cpp b/samples/widgets/listbox.cpp index 65ae57555e..a4416dcff1 100644 --- a/samples/widgets/listbox.cpp +++ b/samples/widgets/listbox.cpp @@ -78,6 +78,8 @@ class ListboxWidgetsPage : public WidgetsPage public: ListboxWidgetsPage(wxNotebook *notebook, wxImageList *imaglist); + virtual wxControl *GetWidget() const { return m_lbox; } + protected: // event handlers void OnButtonReset(wxCommandEvent& event); diff --git a/samples/widgets/notebook.cpp b/samples/widgets/notebook.cpp index 68d6647d5d..6e8c9b7709 100644 --- a/samples/widgets/notebook.cpp +++ b/samples/widgets/notebook.cpp @@ -93,6 +93,8 @@ public: NotebookWidgetsPage(wxNotebook *notebook, wxImageList *imaglist); virtual ~NotebookWidgetsPage(); + virtual wxControl *GetWidget() const { return m_notebook; } + protected: // event handlers void OnPageChanging(wxNotebookEvent& event); diff --git a/samples/widgets/radiobox.cpp b/samples/widgets/radiobox.cpp index d2f710cab5..b3af3419ad 100644 --- a/samples/widgets/radiobox.cpp +++ b/samples/widgets/radiobox.cpp @@ -79,6 +79,8 @@ public: RadioWidgetsPage(wxNotebook *notebook, wxImageList *imaglist); virtual ~RadioWidgetsPage(){}; + virtual wxControl *GetWidget() const { return m_radio; } + protected: // event handlers void OnCheckOrRadioBox(wxCommandEvent& event); diff --git a/samples/widgets/slider.cpp b/samples/widgets/slider.cpp index 87b03c1f9b..2c5344eb03 100644 --- a/samples/widgets/slider.cpp +++ b/samples/widgets/slider.cpp @@ -90,6 +90,8 @@ public: SliderWidgetsPage(wxNotebook *notebook, wxImageList *imaglist); virtual ~SliderWidgetsPage(){}; + virtual wxControl *GetWidget() const { return m_slider; } + protected: // event handlers void OnButtonReset(wxCommandEvent& event); diff --git a/samples/widgets/spinbtn.cpp b/samples/widgets/spinbtn.cpp index 281fab9bd7..7b63513959 100644 --- a/samples/widgets/spinbtn.cpp +++ b/samples/widgets/spinbtn.cpp @@ -74,6 +74,8 @@ public: SpinBtnWidgetsPage(wxNotebook *notebook, wxImageList *imaglist); virtual ~SpinBtnWidgetsPage(){}; + virtual wxControl *GetWidget() const { return m_spinbtn; } + protected: // event handlers void OnButtonReset(wxCommandEvent& event); diff --git a/samples/widgets/static.cpp b/samples/widgets/static.cpp index 8905378377..0b401aabbf 100644 --- a/samples/widgets/static.cpp +++ b/samples/widgets/static.cpp @@ -142,6 +142,8 @@ public: StaticWidgetsPage(wxNotebook *notebook, wxImageList *imaglist); virtual ~StaticWidgetsPage(){}; + virtual wxControl *GetWidget() const { return m_statText; } + protected: // event handlers void OnCheckOrRadioBox(wxCommandEvent& event); diff --git a/samples/widgets/textctrl.cpp b/samples/widgets/textctrl.cpp index 6ad3bb6a2c..0a278daed1 100644 --- a/samples/widgets/textctrl.cpp +++ b/samples/widgets/textctrl.cpp @@ -116,6 +116,8 @@ public: TextWidgetsPage(wxNotebook *notebook, wxImageList *imaglist); virtual ~TextWidgetsPage(){}; + virtual wxControl *GetWidget() const { return m_text; } + protected: // create an info text contorl wxTextCtrl *CreateInfoText(); diff --git a/samples/widgets/widgets.cpp b/samples/widgets/widgets.cpp index 35f939236d..748d97c5da 100644 --- a/samples/widgets/widgets.cpp +++ b/samples/widgets/widgets.cpp @@ -39,6 +39,7 @@ #include "wx/notebook.h" #include "wx/sizer.h" +#include "wx/colordlg.h" #include "widgets.h" @@ -50,7 +51,9 @@ enum { Widgets_ClearLog = 100, - Widgets_Quit + Widgets_Quit, + Widgets_SetFgColour, + Widgets_SetBgColour }; // ---------------------------------------------------------------------------- @@ -83,7 +86,11 @@ protected: #if wxUSE_LOG void OnButtonClearLog(wxCommandEvent& event); #endif // wxUSE_LOG - void OnButtonQuit(wxCommandEvent& event); + void OnExit(wxCommandEvent& event); +#if wxUSE_MENUS + void OnSetFgCol(wxCommandEvent& event); + void OnSetBgCol(wxCommandEvent& event); +#endif // wxUSE_MENUS // initialize the notebook: add all pages to it void InitNotebook(); @@ -106,6 +113,12 @@ private: // and the image list for it wxImageList *m_imaglist; +#if wxUSE_MENUS + // last chosen fg/bg colours + wxColour m_colFg, + m_colBg; +#endif // wxUSE_MENUS + // any class wishing to process wxWidgets events must use this macro DECLARE_EVENT_TABLE() }; @@ -186,7 +199,11 @@ BEGIN_EVENT_TABLE(WidgetsFrame, wxFrame) #if wxUSE_LOG EVT_BUTTON(Widgets_ClearLog, WidgetsFrame::OnButtonClearLog) #endif // wxUSE_LOG - EVT_BUTTON(Widgets_Quit, WidgetsFrame::OnButtonQuit) + EVT_BUTTON(Widgets_Quit, WidgetsFrame::OnExit) + + EVT_MENU(wxID_EXIT, WidgetsFrame::OnExit) + EVT_MENU(Widgets_SetFgColour, WidgetsFrame::OnSetFgCol) + EVT_MENU(Widgets_SetBgColour, WidgetsFrame::OnSetBgCol) END_EVENT_TABLE() // ============================================================================ @@ -251,6 +268,18 @@ WidgetsFrame::WidgetsFrame(const wxString& title) m_notebook = (wxNotebook *)NULL; m_imaglist = (wxImageList *)NULL; +#if wxUSE_MENUS + // create the menubar + wxMenuBar *mbar = new wxMenuBar; + wxMenu *menuWidget = new wxMenu; + menuWidget->Append(Widgets_SetFgColour, _T("Set &foreground...\tCtrl-F")); + menuWidget->Append(Widgets_SetBgColour, _T("Set &background...\tCtrl-B")); + menuWidget->AppendSeparator(); + menuWidget->Append(wxID_EXIT, _T("&Quit\tCtrl-Q")); + mbar->Append(menuWidget, _T("&Widget")); + SetMenuBar(mbar); +#endif // wxUSE_MENUS + // create controls m_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxCLIP_CHILDREN); @@ -354,7 +383,7 @@ WidgetsFrame::~WidgetsFrame() // WidgetsFrame event handlers // ---------------------------------------------------------------------------- -void WidgetsFrame::OnButtonQuit(wxCommandEvent& WXUNUSED(event)) +void WidgetsFrame::OnExit(wxCommandEvent& WXUNUSED(event)) { Close(); } @@ -366,6 +395,34 @@ void WidgetsFrame::OnButtonClearLog(wxCommandEvent& WXUNUSED(event)) } #endif // wxUSE_LOG +#if wxUSE_MENUS + +void WidgetsFrame::OnSetFgCol(wxCommandEvent& WXUNUSED(event)) +{ + wxColour col = wxGetColourFromUser(this, m_colFg); + if ( !col.Ok() ) + return; + + m_colFg = col; + + WidgetsPage *page = wxStaticCast(m_notebook->GetCurrentPage(), WidgetsPage); + page->GetWidget()->SetForegroundColour(m_colFg); +} + +void WidgetsFrame::OnSetBgCol(wxCommandEvent& WXUNUSED(event)) +{ + wxColour col = wxGetColourFromUser(this, m_colBg); + if ( !col.Ok() ) + return; + + m_colBg = col; + + WidgetsPage *page = wxStaticCast(m_notebook->GetCurrentPage(), WidgetsPage); + page->GetWidget()->SetBackgroundColour(m_colBg); +} + +#endif // wxUSE_MENUS + // ---------------------------------------------------------------------------- // WidgetsPageInfo // ---------------------------------------------------------------------------- diff --git a/samples/widgets/widgets.h b/samples/widgets/widgets.h index f9e2e6d432..47ffc41c9b 100644 --- a/samples/widgets/widgets.h +++ b/samples/widgets/widgets.h @@ -33,6 +33,9 @@ class WidgetsPage : public wxPanel public: WidgetsPage(wxNotebook *notebook); + // return the control shown by this page + virtual wxControl *GetWidget() const = 0; + protected: // several helper functions for page creation -- 2.47.2