wxToggleButton page added to widgets sample.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39317 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
dd5e86874e
commit
32816f9a68
@ -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
|
||||
|
||||
|
54
samples/widgets/icons/toggle.xpm
Normal file
54
samples/widgets/icons/toggle.xpm
Normal file
@ -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::: #",
|
||||
"############ :::::::::::::::: ##",
|
||||
"############# :::::::::::::: ###",
|
||||
"############## ####",
|
||||
"################################"
|
||||
};
|
@ -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) $**
|
||||
|
||||
|
@ -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) $<
|
||||
|
||||
|
@ -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) $**
|
||||
|
||||
|
@ -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) $<
|
||||
|
||||
|
207
samples/widgets/toggle.cpp
Normal file
207
samples/widgets/toggle.cpp
Normal file
@ -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
|
@ -4,9 +4,22 @@
|
||||
<include file="../../build/bakefiles/common_samples.bkl"/>
|
||||
|
||||
<exe id="widgets" template="wx_sample" template_append="wx_append">
|
||||
<sources>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</sources>
|
||||
<sources>
|
||||
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
|
||||
</sources>
|
||||
<wx-lib>adv</wx-lib>
|
||||
<wx-lib>html</wx-lib>
|
||||
<wx-lib>core</wx-lib>
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user