From 32816f9a683a67e61f3e527e9d149e86f364f127 Mon Sep 17 00:00:00 2001 From: =?utf8?q?W=C5=82odzimierz=20Skiba?= Date: Wed, 24 May 2006 14:56:15 +0000 Subject: [PATCH] wxToggleButton page added to widgets sample. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39317 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/widgets/Makefile.in | 4 + samples/widgets/icons/toggle.xpm | 54 ++++++++ samples/widgets/makefile.bcc | 4 + samples/widgets/makefile.gcc | 4 + samples/widgets/makefile.vc | 4 + samples/widgets/makefile.wat | 4 + samples/widgets/toggle.cpp | 207 +++++++++++++++++++++++++++++++ samples/widgets/widgets.bkl | 19 ++- samples/widgets/widgets.dsp | 4 + 9 files changed, 301 insertions(+), 3 deletions(-) create mode 100644 samples/widgets/icons/toggle.xpm create mode 100644 samples/widgets/toggle.cpp diff --git a/samples/widgets/Makefile.in b/samples/widgets/Makefile.in index 6398cbcb27..336f16422f 100644 --- a/samples/widgets/Makefile.in +++ b/samples/widgets/Makefile.in @@ -59,6 +59,7 @@ WIDGETS_OBJECTS = \ widgets_spinbtn.o \ widgets_static.o \ widgets_textctrl.o \ + widgets_toggle.o \ widgets_widgets.o \ $(__widgets___win32rc) @@ -235,6 +236,9 @@ widgets_static.o: $(srcdir)/static.cpp widgets_textctrl.o: $(srcdir)/textctrl.cpp $(CXXC) -c -o $@ $(WIDGETS_CXXFLAGS) $(srcdir)/textctrl.cpp +widgets_toggle.o: $(srcdir)/toggle.cpp + $(CXXC) -c -o $@ $(WIDGETS_CXXFLAGS) $(srcdir)/toggle.cpp + widgets_widgets.o: $(srcdir)/widgets.cpp $(CXXC) -c -o $@ $(WIDGETS_CXXFLAGS) $(srcdir)/widgets.cpp diff --git a/samples/widgets/icons/toggle.xpm b/samples/widgets/icons/toggle.xpm new file mode 100644 index 0000000000..4b9bcd3546 --- /dev/null +++ b/samples/widgets/icons/toggle.xpm @@ -0,0 +1,54 @@ +/* XPM */ +static char *toggle_xpm[] = { +/* columns rows colors chars-per-pixel */ +"32 32 16 1", +" c Gray0", +". c #808000", +"X c #000080", +"o c #c0c0c0", +"O c #000000", +"+ c #808000", +"@ c #000080", +"# c none", +"$ c #808080", +"% c Red", +"& c Green", +"* c Yellow", +"= c Blue", +"- c Magenta", +"; c Cyan", +": c Gray100", +/* pixels */ +"################################", +"#### ##############", +"### :::::::::::::: #############", +"## :::::::::::::::$ ############", +"# ::oooooooooooooo$$ ###########", +"# ::oooooooooooooo$$ ###########", +"# ::oooooooooooooo$$ ###########", +"# ::oooooooooooooo$$ ###########", +"# ::oooooooooooooo$$ ###########", +"# ::oooooooooooooo$$ ###########", +"# ::oooooooooooooo$$ ###########", +"# ::oooooooooooooo$$ ###########", +"## $$$$$$$$$$$$$$$$ ############", +"### $$$$$$$$$$$$$$ #############", +"#### ##############", +"################################", +"################################", +"############## ####", +"############# $$$$$$$$$$$$$$ ###", +"############ $$$$$$$$$$$$$$$: ##", +"########### $$:o:o:o:o:o:o:o:: #", +"########### $$o:o:o:o:o:o:o::: #", +"########### $$:o:o:o:o:o:o:o:: #", +"########### $$o:o:o:o:o:o:o::: #", +"########### $$:o:o:o:o:o:o:o:: #", +"########### $$o:o:o:o:o:o:o::: #", +"########### $$:o:o:o:o:o:o:o:: #", +"########### $$o:o:o:o:o:o:o::: #", +"############ :::::::::::::::: ##", +"############# :::::::::::::: ###", +"############## ####", +"################################" +}; diff --git a/samples/widgets/makefile.bcc b/samples/widgets/makefile.bcc index f8742ac09e..ccfc6c6643 100644 --- a/samples/widgets/makefile.bcc +++ b/samples/widgets/makefile.bcc @@ -46,6 +46,7 @@ WIDGETS_OBJECTS = \ $(OBJS)\widgets_spinbtn.obj \ $(OBJS)\widgets_static.obj \ $(OBJS)\widgets_textctrl.obj \ + $(OBJS)\widgets_toggle.obj \ $(OBJS)\widgets_widgets.obj ### Conditionally set variables: ### @@ -273,6 +274,9 @@ $(OBJS)\widgets_static.obj: .\static.cpp $(OBJS)\widgets_textctrl.obj: .\textctrl.cpp $(CXX) -q -c -P -o$@ $(WIDGETS_CXXFLAGS) $** +$(OBJS)\widgets_toggle.obj: .\toggle.cpp + $(CXX) -q -c -P -o$@ $(WIDGETS_CXXFLAGS) $** + $(OBJS)\widgets_widgets.obj: .\widgets.cpp $(CXX) -q -c -P -o$@ $(WIDGETS_CXXFLAGS) $** diff --git a/samples/widgets/makefile.gcc b/samples/widgets/makefile.gcc index 0b70216fa9..40e91ab6b2 100644 --- a/samples/widgets/makefile.gcc +++ b/samples/widgets/makefile.gcc @@ -39,6 +39,7 @@ WIDGETS_OBJECTS = \ $(OBJS)\widgets_spinbtn.o \ $(OBJS)\widgets_static.o \ $(OBJS)\widgets_textctrl.o \ + $(OBJS)\widgets_toggle.o \ $(OBJS)\widgets_widgets.o \ $(OBJS)\widgets_sample_rc.o @@ -266,6 +267,9 @@ $(OBJS)\widgets_static.o: ./static.cpp $(OBJS)\widgets_textctrl.o: ./textctrl.cpp $(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\widgets_toggle.o: ./toggle.cpp + $(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\widgets_widgets.o: ./widgets.cpp $(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $< diff --git a/samples/widgets/makefile.vc b/samples/widgets/makefile.vc index fb186dc7aa..421d7223ae 100644 --- a/samples/widgets/makefile.vc +++ b/samples/widgets/makefile.vc @@ -39,6 +39,7 @@ WIDGETS_OBJECTS = \ $(OBJS)\widgets_spinbtn.obj \ $(OBJS)\widgets_static.obj \ $(OBJS)\widgets_textctrl.obj \ + $(OBJS)\widgets_toggle.obj \ $(OBJS)\widgets_widgets.obj \ $(OBJS)\widgets_sample.res @@ -348,6 +349,9 @@ $(OBJS)\widgets_static.obj: .\static.cpp $(OBJS)\widgets_textctrl.obj: .\textctrl.cpp $(CXX) /c /nologo /TP /Fo$@ $(WIDGETS_CXXFLAGS) $** +$(OBJS)\widgets_toggle.obj: .\toggle.cpp + $(CXX) /c /nologo /TP /Fo$@ $(WIDGETS_CXXFLAGS) $** + $(OBJS)\widgets_widgets.obj: .\widgets.cpp $(CXX) /c /nologo /TP /Fo$@ $(WIDGETS_CXXFLAGS) $** diff --git a/samples/widgets/makefile.wat b/samples/widgets/makefile.wat index e346b7db87..20615ff4f1 100644 --- a/samples/widgets/makefile.wat +++ b/samples/widgets/makefile.wat @@ -236,6 +236,7 @@ WIDGETS_OBJECTS = & $(OBJS)\widgets_spinbtn.obj & $(OBJS)\widgets_static.obj & $(OBJS)\widgets_textctrl.obj & + $(OBJS)\widgets_toggle.obj & $(OBJS)\widgets_widgets.obj @@ -303,6 +304,9 @@ $(OBJS)\widgets_static.obj : .AUTODEPEND .\static.cpp $(OBJS)\widgets_textctrl.obj : .AUTODEPEND .\textctrl.cpp $(CXX) -bt=nt -zq -fo=$^@ $(WIDGETS_CXXFLAGS) $< +$(OBJS)\widgets_toggle.obj : .AUTODEPEND .\toggle.cpp + $(CXX) -bt=nt -zq -fo=$^@ $(WIDGETS_CXXFLAGS) $< + $(OBJS)\widgets_widgets.obj : .AUTODEPEND .\widgets.cpp $(CXX) -bt=nt -zq -fo=$^@ $(WIDGETS_CXXFLAGS) $< diff --git a/samples/widgets/toggle.cpp b/samples/widgets/toggle.cpp new file mode 100644 index 0000000000..626bc0c2bb --- /dev/null +++ b/samples/widgets/toggle.cpp @@ -0,0 +1,207 @@ +///////////////////////////////////////////////////////////////////////////// +// Program: wxWidgets Widgets Sample +// Name: toggle.cpp +// Purpose: Part of the widgets sample showing toggle control +// Author: Dimitri Schoolwerth, Vadim Zeitlin +// Created: 27 Sep 2003 +// Id: $Id$ +// Copyright: (c) 2006 Wlodzmierz Skiba +// License: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +// for compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#if wxUSE_TOGGLEBTN + +#include "wx/tglbtn.h" + +#include "widgets.h" + +// for all others, include the necessary headers +#ifndef WX_PRECOMP + #include "wx/sizer.h" + #include "wx/statbox.h" +#endif + +#include "icons/toggle.xpm" + +// ---------------------------------------------------------------------------- +// constants +// ---------------------------------------------------------------------------- + +// control ids +enum +{ + TogglePage_Reset = wxID_HIGHEST, + TogglePage_ChangeLabel, + TogglePage_Picker +}; + +// ---------------------------------------------------------------------------- +// CheckBoxWidgetsPage +// ---------------------------------------------------------------------------- + +class ToggleWidgetsPage : public WidgetsPage +{ +public: + ToggleWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist); + virtual ~ToggleWidgetsPage(){}; + + virtual wxControl *GetWidget() const { return m_toggle; } + virtual void RecreateWidget() { CreateToggle(); } + +protected: + // event handlers + void OnButtonReset(wxCommandEvent& event); + void OnButtonChangeLabel(wxCommandEvent& event); + + // reset the toggle parameters + void Reset(); + + // (re)create the toggle + void CreateToggle(); + + // the controls + // ------------ + + // the checkbox itself and the sizer it is in + wxToggleButton *m_toggle; + wxSizer *m_sizerToggle; + + // the text entries for command parameters + wxTextCtrl *m_textLabel; + +private: + DECLARE_EVENT_TABLE() + DECLARE_WIDGETS_PAGE(ToggleWidgetsPage) +}; + +// ---------------------------------------------------------------------------- +// event tables +// ---------------------------------------------------------------------------- + +BEGIN_EVENT_TABLE(ToggleWidgetsPage, WidgetsPage) + EVT_BUTTON(TogglePage_Reset, ToggleWidgetsPage::OnButtonReset) + EVT_BUTTON(TogglePage_ChangeLabel, ToggleWidgetsPage::OnButtonChangeLabel) +END_EVENT_TABLE() + +// ============================================================================ +// implementation +// ============================================================================ + +#if defined(__WXUNIVERSAL__) + #define FAMILY_CTRLS UNIVERSAL_CTRLS +#else + #define FAMILY_CTRLS NATIVE_CTRLS +#endif + +IMPLEMENT_WIDGETS_PAGE(ToggleWidgetsPage, wxT("ToggleButton"), + FAMILY_CTRLS + ); + +ToggleWidgetsPage::ToggleWidgetsPage(WidgetsBookCtrl *book, + wxImageList *imaglist) + :WidgetsPage(book) +{ + imaglist->Add(wxBitmap(toggle_xpm)); + + wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); + + // left pane +// wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("Styles")); + +// wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL); + + // middle pane + wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, _T("&Operations")); + wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL); + + wxSizer *sizerRow = CreateSizerWithTextAndButton(TogglePage_ChangeLabel, + _T("Change label"), + wxID_ANY, + &m_textLabel); + m_textLabel->SetValue(_T("&Toggle me!")); + + sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); + + // right pane + wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL); + + m_toggle = new wxToggleButton(this, TogglePage_Picker, wxT("Toggle Button")); + + sizerRight->Add(0, 0, 1, wxCENTRE); + sizerRight->Add(m_toggle, 1, wxCENTRE); + sizerRight->Add(0, 0, 1, wxCENTRE); + sizerRight->SetMinSize(150, 0); + m_sizerToggle = sizerRight; // save it to modify it later + + // the 3 panes panes compose the window +// sizerTop->Add(sizerLeft, 0, (wxALL & ~wxLEFT), 10); + sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10); + sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10); + + // final initializations + Reset(); + + SetSizer(sizerTop); + + sizerTop->Fit(this); +} + +void ToggleWidgetsPage::Reset() +{ + m_toggle->SetValue(false); +} + +void ToggleWidgetsPage::CreateToggle() +{ + const bool value = m_toggle->GetValue(); + + size_t count = m_sizerToggle->GetChildren().GetCount(); + for ( size_t n = 0; n < count; n++ ) + { + m_sizerToggle->Remove(0); + } + + delete m_toggle; + + m_toggle = new wxToggleButton(this, TogglePage_Picker, wxT("Toggle Button")); + + m_toggle->SetValue(value); + + m_sizerToggle->Add(0, 0, 1, wxCENTRE); + m_sizerToggle->Add(m_toggle, 1, wxCENTRE); + m_sizerToggle->Add(0, 0, 1, wxCENTRE); + m_sizerToggle->Layout(); +} + +// ---------------------------------------------------------------------------- +// event handlers +// ---------------------------------------------------------------------------- + +void ToggleWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event)) +{ + Reset(); + + CreateToggle(); +} + +void ToggleWidgetsPage::OnButtonChangeLabel(wxCommandEvent& WXUNUSED(event)) +{ + m_toggle->SetLabel(m_textLabel->GetValue()); +} + +#endif // wxUSE_TOGGLEBTN diff --git a/samples/widgets/widgets.bkl b/samples/widgets/widgets.bkl index 5c61f2efe7..1f57e7e8a3 100644 --- a/samples/widgets/widgets.bkl +++ b/samples/widgets/widgets.bkl @@ -4,9 +4,22 @@ - button.cpp checkbox.cpp combobox.cpp datepick.cpp gauge.cpp listbox.cpp - notebook.cpp radiobox.cpp slider.cpp spinbtn.cpp static.cpp - textctrl.cpp widgets.cpp + + button.cpp + checkbox.cpp + combobox.cpp + datepick.cpp + gauge.cpp + listbox.cpp + notebook.cpp + radiobox.cpp + slider.cpp + spinbtn.cpp + static.cpp + textctrl.cpp + toggle.cpp + widgets.cpp + adv html core diff --git a/samples/widgets/widgets.dsp b/samples/widgets/widgets.dsp index 45fb9399e9..9b7a89b875 100644 --- a/samples/widgets/widgets.dsp +++ b/samples/widgets/widgets.dsp @@ -520,6 +520,10 @@ SOURCE=.\textctrl.cpp # End Source File # Begin Source File +SOURCE=.\toggle.cpp +# End Source File +# Begin Source File + SOURCE=.\widgets.cpp # End Source File # End Group -- 2.47.2