From: Vadim Zeitlin Date: Tue, 20 Dec 2011 21:27:06 +0000 (+0000) Subject: Added wxTimePickerCtrl page to the widgets sample. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/59a2c19914f02be7eae4ec8b7c58b06c19995146 Added wxTimePickerCtrl page to the widgets sample. Even if this page is pretty trivial, add it for consistency with wxDatePickerCtrl. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70069 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/samples/widgets/Makefile.in b/samples/widgets/Makefile.in index 49c80dba3e..dce91f6350 100644 --- a/samples/widgets/Makefile.in +++ b/samples/widgets/Makefile.in @@ -75,6 +75,7 @@ WIDGETS_OBJECTS = \ widgets_static.o \ widgets_statbmp.o \ widgets_textctrl.o \ + widgets_timepick.o \ widgets_toggle.o \ widgets_widgets.o \ $(__widgets___win32rc) @@ -284,6 +285,9 @@ widgets_statbmp.o: $(srcdir)/statbmp.cpp widgets_textctrl.o: $(srcdir)/textctrl.cpp $(CXXC) -c -o $@ $(WIDGETS_CXXFLAGS) $(srcdir)/textctrl.cpp +widgets_timepick.o: $(srcdir)/timepick.cpp + $(CXXC) -c -o $@ $(WIDGETS_CXXFLAGS) $(srcdir)/timepick.cpp + widgets_toggle.o: $(srcdir)/toggle.cpp $(CXXC) -c -o $@ $(WIDGETS_CXXFLAGS) $(srcdir)/toggle.cpp diff --git a/samples/widgets/datepick.cpp b/samples/widgets/datepick.cpp index 160a85a144..f9cdbced62 100644 --- a/samples/widgets/datepick.cpp +++ b/samples/widgets/datepick.cpp @@ -211,7 +211,6 @@ void DatePickerWidgetsPage::CreateContent() sizerRight->Add(0, 0, 1, wxCENTRE); sizerRight->Add(m_datePicker, 1, wxCENTRE); sizerRight->Add(0, 0, 1, wxCENTRE); - sizerRight->SetMinSize(150, 0); m_sizerDatePicker = sizerRight; // save it to modify it later // the 3 panes panes compose the window diff --git a/samples/widgets/icons/timepick.xpm b/samples/widgets/icons/timepick.xpm new file mode 100644 index 0000000000..d6bbd9720d --- /dev/null +++ b/samples/widgets/icons/timepick.xpm @@ -0,0 +1,207 @@ +/* XPM */ +static const char *timepick_xpm[] = { +/* columns rows colors chars-per-pixel */ +"32 32 169 2", +" c None", +". c #067706", +"X c #0F750E", +"o c #0D7E09", +"O c #117611", +"+ c #167616", +"@ c #1A7A16", +"# c #1A7A19", +"$ c #217D1F", +"% c #267C23", +"& c #2B712A", +"* c #5E795F", +"= c #69696A", +"- c #6E6E6F", +"; c #6E6E70", +": c #6F6F70", +"> c #717172", +", c #727273", +"< c #737373", +"1 c #737374", +"2 c #747475", +"3 c #797979", +"4 c #FF0000", +"5 c #FF4800", +"6 c #FF7400", +"7 c #FF0048", +"8 c #FF0074", +"9 c #018700", +"0 c #018901", +"q c #018D00", +"w c #0D8109", +"e c #029902", +"r c #029B02", +"t c #069905", +"y c #059A05", +"u c #198219", +"i c #1F821A", +"p c #1A8719", +"a c #179716", +"s c #00A900", +"d c #01A901", +"f c #00AA01", +"g c #00AB01", +"h c #03AB03", +"j c #00AC01", +"k c #00AD01", +"l c #06AB06", +"z c #16B116", +"x c #278427", +"c c #218B20", +"v c #288428", +"b c #2A8E29", +"n c #319231", +"m c #349632", +"M c #389635", +"N c #3F923C", +"B c #22B422", +"V c #31A130", +"C c #32BC32", +"Z c #37BB37", +"A c #3EBD3E", +"S c #40AB40", +"D c #5FA25F", +"F c #639064", +"G c #659A65", +"H c #68A868", +"J c #70AB70", +"K c #77A876", +"L c #75BC74", +"P c #52C152", +"I c #52C353", +"U c #5CC15C", +"Y c #6BCB6C", +"T c #7ECE7E", +"R c #7FD27F", +"E c #FF9C48", +"W c #FF9C74", +"Q c #FFBF74", +"! c #FF489C", +"~ c #FF749C", +"^ c #FF74BF", +"/ c #808080", +"( c #818181", +") c #838384", +"_ c #878788", +"` c #8E8E90", +"' c #8F8F90", +"] c #909091", +"[ c #909092", +"{ c #919192", +"} c #939395", +"| c #989899", +" . c #80B080", +".. c #8AB88A", +"X. c #8DBC8D", +"o. c #95B795", +"O. c #92BD92", +"+. c #9ABC9A", +"@. c #AFAFAF", +"#. c #B0B0B0", +"$. c #B1B1B1", +"%. c #B0B0B2", +"&. c #BABABC", +"*. c #BCBCBC", +"=. c #BDBDBD", +"-. c #BEBEBE", +";. c #BFBFBF", +":. c #FF9C9C", +">. c #FF9CBF", +",. c #9ECB9E", +"<. c #93D893", +"1. c #A5C8A5", +"2. c #ACCAAB", +"3. c #A5DAA5", +"4. c #AAD4A9", +"5. c #ABDDAB", +"6. c #BBC9BC", +"7. c #B7D1B7", +"8. c #BFD2BF", +"9. c #A9E0A9", +"0. c #B4E3B4", +"q. c #FFDF9C", +"w. c #FFFFBF", +"e. c #FF9CDF", +"r. c #FFBFFF", +"t. c #C0C0C0", +"y. c #C1C1C1", +"u. c #C0C0C3", +"i. c #C5C5C8", +"p. c #C8C8C8", +"a. c #C8C8CB", +"s. c #CBCBCB", +"d. c #CCCCCC", +"f. c #CECECF", +"g. c #C8D8C8", +"h. c #CBDCCB", +"j. c #CFCFD1", +"k. c #D0D0D2", +"l. c #D1D1D2", +"z. c #D0D0D3", +"x. c #D1D1D3", +"c. c #D2D2D3", +"v. c #D2D2D4", +"b. c #D3D3D4", +"n. c #D3D3D5", +"m. c #D3D3D6", +"M. c #D4D4D5", +"N. c #D4D4D6", +"B. c #D4D4D7", +"V. c #D5D5D8", +"C. c #D8D8DA", +"Z. c #D9D9DB", +"A. c #DADADA", +"S. c #DADADB", +"D. c #DADEDA", +"F. c #D9D9DC", +"G. c #DADADC", +"H. c #DBDBDD", +"J. c #DDDDDF", +"K. c #DDF3DD", +"L. c #FFFFDF", +"P. c #FFDFFF", +"I. c #E2E2E3", +"U. c #E3E3E3", +"Y. c #E3E3E4", +"T. c #E4E4E4", +"R. c #E5E5E5", +"E. c #E3E8E3", +"W. c #FFFFFF", +/* pixels */ +" h.D u x .. ", +" 1.c 5.K.P 9 .", +" 7.n 0.9.A f j v ", +" O.. U Y B f j z # ", +" H 0 y h h j j Z S K ", +" J q C <.r f f P T X E.", +" p o m y y a R 3.O 8. ", +" ;.F b N @ V L ,.+ g. ", +" *.] m.6.M 2.i 4.$ +. ", +" ;.] z.H.b.D.X.w % G ", +" ;.] m.G.b.U.b.* & o. ", +" / ;.' m.G.b.I.B.2 @. ", +" ;.' m.G.m.U.b.1 #. ", +" y.' m.C.z.U.b.1 #. ", +" y.{ m.C.b.T.z.< #. ", +" y.{ B.C.b.T.z.< #. ", +" d.' B.C.b.T.z.- #. ", +" | B.z.b.T.z.- #. ", +" d._ J.p.C.z.- #. ", +" / i.s.u.&.- #. ", +" ) } #.= 3 C. ", +" W.W.W.W.W.W.W.W.W.;.: < p.W.W.W.W.W.W.W.W.W.W.W.W.W. ", +" W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W. ", +" W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W. ", +" W.W.W.W.6 e.W.E 4 7 P.W.W.Q 4 7 P.W.q.8 W.W.W.W.W.W. ", +" W.W.W.Q :.e.W.W.W.Q r.Q e.W.W.Q r.L.~ :.W.W.W.W.W.W. ", +" W.W.W.W.q.e.W.W.w.! W.W.W.w.4 ! W.W P.:.W.W.W.W.W.W. ", +" W.W.W.W.q.e.W.w.8 W.W.W.W.W.W.q.>.5 4 4 ! W.W.W.W.W. ", +" W.W.W.Q 4 4 e.E 4 4 ^ Q e.E 4 7 P.W.W.:.W.W.W.W.W.W. ", +" W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W. ", +" W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W. ", +" " +}; diff --git a/samples/widgets/makefile.bcc b/samples/widgets/makefile.bcc index c15e9ac13a..202be001f0 100644 --- a/samples/widgets/makefile.bcc +++ b/samples/widgets/makefile.bcc @@ -62,6 +62,7 @@ WIDGETS_OBJECTS = \ $(OBJS)\widgets_static.obj \ $(OBJS)\widgets_statbmp.obj \ $(OBJS)\widgets_textctrl.obj \ + $(OBJS)\widgets_timepick.obj \ $(OBJS)\widgets_toggle.obj \ $(OBJS)\widgets_widgets.obj @@ -343,6 +344,9 @@ $(OBJS)\widgets_statbmp.obj: .\statbmp.cpp $(OBJS)\widgets_textctrl.obj: .\textctrl.cpp $(CXX) -q -c -P -o$@ $(WIDGETS_CXXFLAGS) .\textctrl.cpp +$(OBJS)\widgets_timepick.obj: .\timepick.cpp + $(CXX) -q -c -P -o$@ $(WIDGETS_CXXFLAGS) .\timepick.cpp + $(OBJS)\widgets_toggle.obj: .\toggle.cpp $(CXX) -q -c -P -o$@ $(WIDGETS_CXXFLAGS) .\toggle.cpp diff --git a/samples/widgets/makefile.gcc b/samples/widgets/makefile.gcc index e138d1be65..7297d8afe2 100644 --- a/samples/widgets/makefile.gcc +++ b/samples/widgets/makefile.gcc @@ -55,6 +55,7 @@ WIDGETS_OBJECTS = \ $(OBJS)\widgets_static.o \ $(OBJS)\widgets_statbmp.o \ $(OBJS)\widgets_textctrl.o \ + $(OBJS)\widgets_timepick.o \ $(OBJS)\widgets_toggle.o \ $(OBJS)\widgets_widgets.o \ $(OBJS)\widgets_sample_rc.o @@ -330,6 +331,9 @@ $(OBJS)\widgets_statbmp.o: ./statbmp.cpp $(OBJS)\widgets_textctrl.o: ./textctrl.cpp $(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\widgets_timepick.o: ./timepick.cpp + $(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\widgets_toggle.o: ./toggle.cpp $(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $< diff --git a/samples/widgets/makefile.unx b/samples/widgets/makefile.unx index eaf97a9d47..14ca7b5ad5 100644 --- a/samples/widgets/makefile.unx +++ b/samples/widgets/makefile.unx @@ -79,6 +79,7 @@ WIDGETS_OBJECTS = \ widgets_static.o \ widgets_statbmp.o \ widgets_textctrl.o \ + widgets_timepick.o \ widgets_toggle.o \ widgets_widgets.o @@ -195,6 +196,9 @@ widgets_statbmp.o: ./statbmp.cpp widgets_textctrl.o: ./textctrl.cpp $(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $< +widgets_timepick.o: ./timepick.cpp + $(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $< + widgets_toggle.o: ./toggle.cpp $(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $< diff --git a/samples/widgets/makefile.vc b/samples/widgets/makefile.vc index 850b365882..c3a34e3594 100644 --- a/samples/widgets/makefile.vc +++ b/samples/widgets/makefile.vc @@ -56,6 +56,7 @@ WIDGETS_OBJECTS = \ $(OBJS)\widgets_static.obj \ $(OBJS)\widgets_statbmp.obj \ $(OBJS)\widgets_textctrl.obj \ + $(OBJS)\widgets_timepick.obj \ $(OBJS)\widgets_toggle.obj \ $(OBJS)\widgets_widgets.obj WIDGETS_RESOURCES = \ @@ -453,6 +454,9 @@ $(OBJS)\widgets_statbmp.obj: .\statbmp.cpp $(OBJS)\widgets_textctrl.obj: .\textctrl.cpp $(CXX) /c /nologo /TP /Fo$@ $(WIDGETS_CXXFLAGS) .\textctrl.cpp +$(OBJS)\widgets_timepick.obj: .\timepick.cpp + $(CXX) /c /nologo /TP /Fo$@ $(WIDGETS_CXXFLAGS) .\timepick.cpp + $(OBJS)\widgets_toggle.obj: .\toggle.cpp $(CXX) /c /nologo /TP /Fo$@ $(WIDGETS_CXXFLAGS) .\toggle.cpp diff --git a/samples/widgets/makefile.wat b/samples/widgets/makefile.wat index 9874c74496..8aa77c8620 100644 --- a/samples/widgets/makefile.wat +++ b/samples/widgets/makefile.wat @@ -260,6 +260,7 @@ WIDGETS_OBJECTS = & $(OBJS)\widgets_static.obj & $(OBJS)\widgets_statbmp.obj & $(OBJS)\widgets_textctrl.obj & + $(OBJS)\widgets_timepick.obj & $(OBJS)\widgets_toggle.obj & $(OBJS)\widgets_widgets.obj @@ -370,6 +371,9 @@ $(OBJS)\widgets_statbmp.obj : .AUTODEPEND .\statbmp.cpp $(OBJS)\widgets_textctrl.obj : .AUTODEPEND .\textctrl.cpp $(CXX) -bt=nt -zq -fo=$^@ $(WIDGETS_CXXFLAGS) $< +$(OBJS)\widgets_timepick.obj : .AUTODEPEND .\timepick.cpp + $(CXX) -bt=nt -zq -fo=$^@ $(WIDGETS_CXXFLAGS) $< + $(OBJS)\widgets_toggle.obj : .AUTODEPEND .\toggle.cpp $(CXX) -bt=nt -zq -fo=$^@ $(WIDGETS_CXXFLAGS) $< diff --git a/samples/widgets/timepick.cpp b/samples/widgets/timepick.cpp new file mode 100644 index 0000000000..9100980e35 --- /dev/null +++ b/samples/widgets/timepick.cpp @@ -0,0 +1,237 @@ +///////////////////////////////////////////////////////////////////////////// +// Program: wxWidgets Widgets Sample +// Name: timepick.cpp +// Purpose: Part of the widgets sample showing time picker +// Author: Vadim Zeitlin +// Created: 2011-12-20 +// Id: $Id$ +// Copyright: (c) 2011 wxWindows team +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +// for compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#if wxUSE_TIMEPICKCTRL + +// for all others, include the necessary headers +#ifndef WX_PRECOMP + #include "wx/app.h" + #include "wx/log.h" + + #include "wx/button.h" + #include "wx/textctrl.h" + + #include "wx/sizer.h" +#endif + +#include "wx/timectrl.h" +#include "wx/dateevt.h" + +#include "widgets.h" + +#include "icons/timepick.xpm" + +// ---------------------------------------------------------------------------- +// constants +// ---------------------------------------------------------------------------- + +// control ids +enum +{ + TimePickerPage_Reset = wxID_HIGHEST, + TimePickerPage_Set, + TimePickerPage_Picker +}; + +// ---------------------------------------------------------------------------- +// CheckBoxWidgetsPage +// ---------------------------------------------------------------------------- + +class TimePickerWidgetsPage : public WidgetsPage +{ +public: + TimePickerWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist); + virtual ~TimePickerWidgetsPage(){}; + + virtual wxControl *GetWidget() const { return m_timePicker; } + virtual void RecreateWidget() { CreateTimePicker(); } + + // lazy creation of the content + virtual void CreateContent(); + +protected: + // event handlers + void OnTimeChanged(wxDateEvent& event); + + void OnButtonSet(wxCommandEvent& event); + void OnButtonReset(wxCommandEvent& event); + + // reset the time picker parameters + void Reset(); + + // (re)create the time picker + void CreateTimePicker(); + + // the controls + // ------------ + + // the checkbox itself and the sizer it is in + wxTimePickerCtrl *m_timePicker; + wxSizer *m_sizerTimePicker; + + wxTextCtrl *m_textCur; + +private: + DECLARE_EVENT_TABLE() + DECLARE_WIDGETS_PAGE(TimePickerWidgetsPage) +}; + +// ---------------------------------------------------------------------------- +// event tables +// ---------------------------------------------------------------------------- + +BEGIN_EVENT_TABLE(TimePickerWidgetsPage, WidgetsPage) + EVT_BUTTON(TimePickerPage_Reset, TimePickerWidgetsPage::OnButtonReset) + EVT_BUTTON(TimePickerPage_Set, TimePickerWidgetsPage::OnButtonSet) + + EVT_TIME_CHANGED(wxID_ANY, TimePickerWidgetsPage::OnTimeChanged) +END_EVENT_TABLE() + +// ============================================================================ +// implementation +// ============================================================================ + +#if defined(__WXMSW__) + #define FAMILY_CTRLS NATIVE_CTRLS +#else + #define FAMILY_CTRLS GENERIC_CTRLS +#endif + +IMPLEMENT_WIDGETS_PAGE(TimePickerWidgetsPage, wxT("TimePicker"), + FAMILY_CTRLS | PICKER_CTRLS + ); + +TimePickerWidgetsPage::TimePickerWidgetsPage(WidgetsBookCtrl *book, + wxImageList *imaglist) + : WidgetsPage(book, imaglist, timepick_xpm) +{ +} + +void TimePickerWidgetsPage::CreateContent() +{ + wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); + + // left pane + wxSizer* const sizerLeft = new wxBoxSizer(wxVERTICAL); + + sizerLeft->Add(new wxButton(this, TimePickerPage_Reset, "&Reset"), + wxSizerFlags().Centre().Border()); + + + // middle pane: operations + wxSizer* const sizerMiddle = new wxBoxSizer(wxVERTICAL); + sizerMiddle->Add(CreateSizerWithTextAndButton + ( + TimePickerPage_Set, + "&Set time", + wxID_ANY, + &m_textCur + ), + wxSizerFlags().Expand().Border()); + + m_textCur->SetMinSize(wxSize(GetTextExtent(" 99:99:99 ").x, -1)); + + + // right pane: control itself + wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL); + + m_timePicker = new wxTimePickerCtrl(this, TimePickerPage_Picker); + + sizerRight->Add(0, 0, 1, wxCENTRE); + sizerRight->Add(m_timePicker, 1, wxCENTRE); + sizerRight->Add(0, 0, 1, wxCENTRE); + m_sizerTimePicker = sizerRight; // save it to modify it later + + // the 3 panes panes compose the window + sizerTop->Add(sizerLeft, 0, (wxALL & ~wxLEFT), 10); + sizerTop->Add(sizerMiddle, 0, (wxTOP | wxBOTTOM), 10); + sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10); + + // final initializations + Reset(); + + SetSizer(sizerTop); +} + +void TimePickerWidgetsPage::Reset() +{ + const wxDateTime today = wxDateTime::Today(); + + m_timePicker->SetValue(today); + m_textCur->SetValue(today.FormatISOTime()); +} + +void TimePickerWidgetsPage::CreateTimePicker() +{ + const wxDateTime value = m_timePicker->GetValue(); + + size_t count = m_sizerTimePicker->GetChildren().GetCount(); + for ( size_t n = 0; n < count; n++ ) + { + m_sizerTimePicker->Remove(0); + } + + delete m_timePicker; + + m_timePicker = new wxTimePickerCtrl(this, TimePickerPage_Picker, value); + + m_sizerTimePicker->Add(0, 0, 1, wxCENTRE); + m_sizerTimePicker->Add(m_timePicker, 1, wxCENTRE); + m_sizerTimePicker->Add(0, 0, 1, wxCENTRE); + m_sizerTimePicker->Layout(); +} + +// ---------------------------------------------------------------------------- +// event handlers +// ---------------------------------------------------------------------------- + +void TimePickerWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event)) +{ + Reset(); + + CreateTimePicker(); +} + +void TimePickerWidgetsPage::OnButtonSet(wxCommandEvent& WXUNUSED(event)) +{ + wxDateTime dt; + if ( !dt.ParseISOTime(m_textCur->GetValue()) ) + { + wxLogError("Invalid time, please use HH:MM:SS format."); + return; + } + + m_timePicker->SetValue(dt); +} + +void TimePickerWidgetsPage::OnTimeChanged(wxDateEvent& event) +{ + wxLogMessage("Time changed, now is %s (control value is %s).", + event.GetDate().FormatISOTime(), + m_timePicker->GetValue().FormatISOTime()); +} + +#endif // wxUSE_TIMEPICKCTRL diff --git a/samples/widgets/widgets.bkl b/samples/widgets/widgets.bkl index 9227075d1a..c4f6dfe025 100644 --- a/samples/widgets/widgets.bkl +++ b/samples/widgets/widgets.bkl @@ -32,6 +32,7 @@ static.cpp statbmp.cpp textctrl.cpp + timepick.cpp toggle.cpp widgets.cpp diff --git a/samples/widgets/widgets.dsp b/samples/widgets/widgets.dsp index 1b1165f0ad..787aee7fd6 100644 --- a/samples/widgets/widgets.dsp +++ b/samples/widgets/widgets.dsp @@ -360,6 +360,10 @@ SOURCE=.\textctrl.cpp # End Source File # Begin Source File +SOURCE=.\timepick.cpp +# End Source File +# Begin Source File + SOURCE=.\toggle.cpp # End Source File # Begin Source File diff --git a/samples/widgets/widgets_vc7.vcproj b/samples/widgets/widgets_vc7.vcproj index 624b3b90f3..9e44ec27d0 100644 --- a/samples/widgets/widgets_vc7.vcproj +++ b/samples/widgets/widgets_vc7.vcproj @@ -620,6 +620,9 @@ RelativePath=".\textctrl.cpp"> + + + + diff --git a/samples/widgets/widgets_vc9.vcproj b/samples/widgets/widgets_vc9.vcproj index a143c3683a..04c9a22fbe 100644 --- a/samples/widgets/widgets_vc9.vcproj +++ b/samples/widgets/widgets_vc9.vcproj @@ -880,6 +880,10 @@ > + +