]> git.saurik.com Git - wxWidgets.git/commitdiff
added tests for setting fg/bg colours
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 19 Nov 2004 19:03:04 +0000 (19:03 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 19 Nov 2004 19:03:04 +0000 (19:03 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30634 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

13 files changed:
samples/widgets/button.cpp
samples/widgets/checkbox.cpp
samples/widgets/combobox.cpp
samples/widgets/gauge.cpp
samples/widgets/listbox.cpp
samples/widgets/notebook.cpp
samples/widgets/radiobox.cpp
samples/widgets/slider.cpp
samples/widgets/spinbtn.cpp
samples/widgets/static.cpp
samples/widgets/textctrl.cpp
samples/widgets/widgets.cpp
samples/widgets/widgets.h

index ebe6d458878e6053d6b75a84bd44eebfcf317907..a1f33a0eb9f86dbae20092144999862a5c0a9a4f 100644 (file)
@@ -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);
index e336b162213d6c5802faa4c6864e929fa2fbc4d4..250fb536149e37c09767db3d2148ac87f1d79b3b 100644 (file)
@@ -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);
index 6938293e618804fc62a50f89d2fd148c60e30a40..875d02296a51a440c638988f4272ab5d11a86b76 100644 (file)
@@ -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);
index f20aac08ef55b97e77199854fd7feac5cff58467..54610ac03ba2abd3e168b418acb2dc5320af6240 100644 (file)
@@ -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);
index 65ae57555e6953297a8a469e8a5aa1b43a98db16..a4416dcff1e17d8876fd92129a3f53c3969093db 100644 (file)
@@ -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);
index 68d6647d5d91b1ca32f308d1d9dc4a867ed0e85c..6e8c9b77099f5d70f71339d854326325e367f91e 100644 (file)
@@ -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);
index d2f710cab5ba354e1076accf35145082fd45bc44..b3af3419add576f015778b98cabf819e0c0616c9 100644 (file)
@@ -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);
index 87b03c1f9bf140a376a05bdb60a2b85c02d33008..2c5344eb03bff3e33ee400fd529d2c79a4ed4252 100644 (file)
@@ -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);
index 281fab9bd7eb6ede8cc26369ac455cebe42d669c..7b63513959a79a3424cdf10bf477e6669bb15b2f 100644 (file)
@@ -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);
index 8905378377e2c1462344d58af4eb3ff8c3936dc2..0b401aabbf8115bec835fbc6506ae61b4d663047 100644 (file)
@@ -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);
index 6ad3bb6a2c6976ba6cdde2a54a3c168b54dbc97e..0a278daed13d4434a6a5d01d3e3ccd34e5fe6675 100644 (file)
@@ -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();
index 35f939236d9fec7876718c74369b2799c8afa6a8..748d97c5da5c201742958c5e518cf04d33e62bf7 100644 (file)
@@ -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
 // ----------------------------------------------------------------------------
index f9e2e6d4325c167fae70e1419e7d923738aef86b..47ffc41c9b9065b262e72f218861aa4abcfcf12b 100644 (file)
@@ -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