From 10ff9c616e00e4074dfdc2ac9e354605cc129c22 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sat, 8 Dec 2007 10:36:59 +0000 Subject: [PATCH] Document wxBitmapToggleButton, add update UI event in Base class for all toggle buttons git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50563 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/bitmaptglbutn.tex | 86 +++++++++++++++++++++++++++++++++ docs/latex/wx/category.tex | 1 + docs/latex/wx/classes.tex | 1 + docs/latex/wx/tglbtn.tex | 6 ++- include/wx/gtk/tglbtn.h | 12 ++--- include/wx/tglbtn.h | 47 ++++++++++++++++++ src/common/valgen.cpp | 12 +++++ src/gtk/tglbtn.cpp | 26 +++++----- src/mac/carbon/tglbtn.cpp | 16 +++--- 9 files changed, 179 insertions(+), 28 deletions(-) create mode 100644 docs/latex/wx/bitmaptglbutn.tex diff --git a/docs/latex/wx/bitmaptglbutn.tex b/docs/latex/wx/bitmaptglbutn.tex new file mode 100644 index 0000000000..27c1eed8a3 --- /dev/null +++ b/docs/latex/wx/bitmaptglbutn.tex @@ -0,0 +1,86 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Name: bitmaptglbtn.tex +%% Purpose: wxBitmapToggleButton documentation +%% Author: Robert Roebling +%% License: wxWindows license +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\section{\class{wxBitmapToggleButton}}\label{wxbitmaptogglebutton} + +wxBitmapToggleButton is a a \helpref{wxToggleButton}{wxtogglebutton} +that contains a bitmap instead of text. + +This control emits a update UI event. + +\wxheading{Derived from} + +\helpref{wxControl}{wxcontrol}\\ +\helpref{wxWindow}{wxwindow}\\ +\helpref{wxEvtHandler}{wxevthandler}\\ +\helpref{wxObject}{wxobject} + +\wxheading{Include files} + + + +\wxheading{Library} + +\helpref{wxCore}{librarieslist} + +\wxheading{Window styles} + +There are no special styles for wxBitmapToggleButton. + +\wxheading{Event handling} + +\twocolwidtha{7cm} +\begin{twocollist}\itemsep=0pt +\twocolitem{{\bf EVT\_TOGGLEBUTTON(id, func)}}{Handles a toggle button click event.} +\end{twocollist} + +\latexignore{\rtfignore{\wxheading{Members}}} + +\membersection{wxBitmapToggleButton::wxBitmapToggleButton}\label{wxbitmaptogglebuttonconstr} + +\func{}{wxBitmapToggleButton}{\void} + +Default constructor. + +\func{}{wxBitmapToggleButton}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp +\param{const wxBitmap\& }{label}, \param{const wxPoint\& }{pos = wxDefaultPosition},\rtfsp +\param{const wxSize\& }{size = wxDefaultSize}, \param{long}{ style = 0},\rtfsp +\param{const wxValidator\& }{val}, \param{const wxString\& }{name = ``checkBox"}} + +Constructor, creating and showing a toggle button with the bitmap {\it label}. +Internally calls Create(). + +\membersection{wxBitmapToggleButton::Create}\label{wxbitmaptogglebuttoncreate} + +\func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp +\param{const wxBitmap\& }{label}, \param{const wxPoint\& }{pos = wxDefaultPosition},\rtfsp +\param{const wxSize\& }{size = wxDefaultSize}, \param{long}{ style = 0},\rtfsp +\param{const wxValidator\& }{val}, \param{const wxString\& }{name = ``checkBox"}} + +Create method for two-step construction. + +\membersection{wxBitmapToggleButton::GetValue}\label{wxbitmaptogglebuttongetvalue} + +\constfunc{bool}{GetValue}{\void} + +Gets the state of the toggle button. + +\wxheading{Return value} + +Returns {\tt true} if it is pressed, {\tt false} otherwise. + +\membersection{wxBitmapToggleButton::SetValue}\label{wxbitmaptogglebuttonsetvalue} + +\func{void}{SetValue}{\param{bool}{ state}} + +Sets the toggle button to the given state. This does not cause a +{\tt EVT\_TOGGLEBUTTON} event to be emitted. + +\wxheading{Parameters} + +\docparam{state}{If {\tt true}, the button is pressed.} + diff --git a/docs/latex/wx/category.tex b/docs/latex/wx/category.tex index 17b1f7782c..1a18ca2aae 100644 --- a/docs/latex/wx/category.tex +++ b/docs/latex/wx/category.tex @@ -93,6 +93,7 @@ that are not static can have \helpref{validators}{wxvalidator} associated with t \twocolitem{\helpref{wxBitmapButton}{wxbitmapbutton}}{Push button control, displaying a bitmap} \twocolitem{\helpref{wxBitmapComboBox}{wxbitmapcombobox}}{A combobox with bitmaps next to text items} \twocolitem{\helpref{wxToggleButton}{wxtogglebutton}}{A button which stays pressed when clicked by user.} +\twocolitem{\helpref{wxBitmapToggleButton}{wxbitmaptogglebutton}}{A toggle button with bitmaps.} \twocolitem{\helpref{wxCalendarCtrl}{wxcalendarctrl}}{Control showing an entire calendar month} \twocolitem{\helpref{wxCheckBox}{wxcheckbox}}{Checkbox control} \twocolitem{\helpref{wxCheckListBox}{wxchecklistbox}}{A listbox with a checkbox to the left of each item} diff --git a/docs/latex/wx/classes.tex b/docs/latex/wx/classes.tex index bc5a406ec5..9754c13f47 100644 --- a/docs/latex/wx/classes.tex +++ b/docs/latex/wx/classes.tex @@ -27,6 +27,7 @@ \input autoobj.tex \input bitmap.tex \input bitmapcombobox.tex +\input bitmaptgnbtn.tex \input bbutton.tex \input bmpdatob.tex \input bmphand.tex diff --git a/docs/latex/wx/tglbtn.tex b/docs/latex/wx/tglbtn.tex index 9f82de7e08..0cd8afa5cf 100644 --- a/docs/latex/wx/tglbtn.tex +++ b/docs/latex/wx/tglbtn.tex @@ -15,6 +15,8 @@ wxToggleButton is a button that stays pressed when clicked by the user. In other words, it is similar to \helpref{wxCheckBox}{wxcheckbox} in functionality but looks like a \helpref{wxButton}{wxbutton}. +Since wxWidgets version 2.9.0 this control emits a update UI event. + You can see wxToggleButton in action in the sixth page of the \helpref{controls}{samplecontrols} sample. @@ -48,7 +50,8 @@ See also \helpref{window styles overview}{windowstyles}. \wxheading{See also} -\helpref{wxCheckBox}{wxcheckbox}, \helpref{wxButton}{wxbutton} +\helpref{wxCheckBox}{wxcheckbox}, \helpref{wxButton}{wxbutton}, +\helpref{wxToggleBitmapButton}{wxtogglebitmapbutton} \latexignore{\rtfignore{\wxheading{Members}}} @@ -123,3 +126,4 @@ Sets the toggle button to the given state. This does not cause a \wxheading{Parameters} \docparam{state}{If {\tt true}, the button is pressed.} + diff --git a/include/wx/gtk/tglbtn.h b/include/wx/gtk/tglbtn.h index 4c1f5f59b8..1a656e6c09 100644 --- a/include/wx/gtk/tglbtn.h +++ b/include/wx/gtk/tglbtn.h @@ -29,15 +29,15 @@ class WXDLLIMPEXP_FWD_CORE wxToggleBitmapButton; extern WXDLLIMPEXP_CORE const char wxCheckBoxNameStr[]; //----------------------------------------------------------------------------- -// wxToggleBitmapButton +// wxBitmapToggleButton //----------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxToggleBitmapButton: public wxControl +class WXDLLIMPEXP_CORE wxBitmapToggleButton: public wxToggleButtonBase { public: // construction/destruction - wxToggleBitmapButton() {} - wxToggleBitmapButton(wxWindow *parent, + wxBitmapToggleButton() {} + wxBitmapToggleButton(wxWindow *parent, wxWindowID id, const wxBitmap& label, const wxPoint& pos = wxDefaultPosition, @@ -82,14 +82,14 @@ protected: virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const; private: - DECLARE_DYNAMIC_CLASS(wxToggleBitmapButton) + DECLARE_DYNAMIC_CLASS(wxBitmapToggleButton) }; //----------------------------------------------------------------------------- // wxToggleButton //----------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxToggleButton: public wxControl +class WXDLLIMPEXP_CORE wxToggleButton: public wxToggleButtonBase { public: // construction/destruction diff --git a/include/wx/tglbtn.h b/include/wx/tglbtn.h index 7ac6ec9840..228cffdd31 100644 --- a/include/wx/tglbtn.h +++ b/include/wx/tglbtn.h @@ -24,6 +24,53 @@ BEGIN_DECLARE_EVENT_TYPES() DECLARE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, 19) END_DECLARE_EVENT_TYPES() +// ---------------------------------------------------------------------------- +// wxToggleButtonBase +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxToggleButtonBase : public wxControl +{ +public: + wxToggleButtonBase() { } + + // Get/set the value + virtual void SetValue(bool state) = 0; + virtual bool GetValue() const = 0; + + void UpdateWindowUI(long flags) + { + wxControl::UpdateWindowUI(flags); + + if ( !IsShown() ) + return; + + wxWindow *tlw = wxGetTopLevelParent( this ); + if (tlw && wxPendingDelete.Member( tlw )) + return; + + wxUpdateUIEvent event( GetId() ); + event.SetEventObject(this); + + if (GetEventHandler()->ProcessEvent(event) ) + { + if ( event.GetSetChecked() ) + SetValue( event.GetChecked() ); + } + } + + // Buttons on MSW can look bad if they are not native colours, because + // then they become owner-drawn and not theme-drawn. Disable it here + // in wxToggleButtonBase to make it consistent. + virtual bool ShouldInheritColours() const { return false; } + +protected: + // choose the default border for this window + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } + + DECLARE_NO_COPY_CLASS(wxToggleButtonBase) +}; + + #define EVT_TOGGLEBUTTON(id, fn) \ wx__DECLARE_EVT1(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, id, wxCommandEventHandler(fn)) diff --git a/src/common/valgen.cpp b/src/common/valgen.cpp index 4b05f6d4f2..d9de2dea7b 100644 --- a/src/common/valgen.cpp +++ b/src/common/valgen.cpp @@ -121,6 +121,7 @@ bool wxGenericValidator::TransferToWindow(void) } } else #endif + #if wxUSE_TOGGLEBTN if (m_validatorWindow->IsKindOf(CLASSINFO(wxToggleButton)) ) { @@ -131,6 +132,17 @@ bool wxGenericValidator::TransferToWindow(void) return true; } } else +#if defined(__WXMAC__) || defined(__WXGTK20__) + if (m_validatorWindow->IsKindOf(CLASSINFO(wxBitmapToggleButton)) ) + { + wxBitmapToggleButton * pControl = (wxBitmapToggleButton *) m_validatorWindow; + if (m_pBool) + { + pControl->SetValue(*m_pBool); + return true; + } + } else +#endif #endif // int controls diff --git a/src/gtk/tglbtn.cpp b/src/gtk/tglbtn.cpp index 120e9d75fa..50b319394f 100644 --- a/src/gtk/tglbtn.cpp +++ b/src/gtk/tglbtn.cpp @@ -44,12 +44,12 @@ static void gtk_togglebutton_clicked_callback(GtkWidget *WXUNUSED(widget), wxTog DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED) // ------------------------------------------------------------------------ -// wxToggleBitmapButton +// wxBitmapToggleButton // ------------------------------------------------------------------------ -IMPLEMENT_DYNAMIC_CLASS(wxToggleBitmapButton, wxControl) +IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton, wxControl) -bool wxToggleBitmapButton::Create(wxWindow *parent, wxWindowID id, +bool wxBitmapToggleButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap &label, const wxPoint &pos, const wxSize &size, long style, const wxValidator& validator, @@ -60,7 +60,7 @@ bool wxToggleBitmapButton::Create(wxWindow *parent, wxWindowID id, if (!PreCreation(parent, pos, size) || !CreateBase(parent, id, pos, size, style, validator, name )) { - wxFAIL_MSG(wxT("wxToggleBitmapButton creation failed")); + wxFAIL_MSG(wxT("wxBitmapToggleButton creation failed")); return false; } @@ -86,7 +86,7 @@ bool wxToggleBitmapButton::Create(wxWindow *parent, wxWindowID id, // void SetValue(bool state) // Set the value of the toggle button. -void wxToggleBitmapButton::SetValue(bool state) +void wxBitmapToggleButton::SetValue(bool state) { wxCHECK_RET(m_widget != NULL, wxT("invalid toggle button")); @@ -102,14 +102,14 @@ void wxToggleBitmapButton::SetValue(bool state) // bool GetValue() const // Get the value of the toggle button. -bool wxToggleBitmapButton::GetValue() const +bool wxBitmapToggleButton::GetValue() const { wxCHECK_MSG(m_widget != NULL, false, wxT("invalid toggle button")); return gtk_toggle_button_get_active((GtkToggleButton*)m_widget); } -void wxToggleBitmapButton::SetLabel(const wxBitmap& label) +void wxBitmapToggleButton::SetLabel(const wxBitmap& label) { wxCHECK_RET(m_widget != NULL, wxT("invalid toggle button")); @@ -119,7 +119,7 @@ void wxToggleBitmapButton::SetLabel(const wxBitmap& label) OnSetBitmap(); } -void wxToggleBitmapButton::OnSetBitmap() +void wxBitmapToggleButton::OnSetBitmap() { if (!m_bitmap.Ok()) return; @@ -137,7 +137,7 @@ void wxToggleBitmapButton::OnSetBitmap() } } -bool wxToggleBitmapButton::Enable(bool enable /*=true*/) +bool wxBitmapToggleButton::Enable(bool enable /*=true*/) { if (!wxControl::Enable(enable)) return false; @@ -147,20 +147,20 @@ bool wxToggleBitmapButton::Enable(bool enable /*=true*/) return true; } -void wxToggleBitmapButton::DoApplyWidgetStyle(GtkRcStyle *style) +void wxBitmapToggleButton::DoApplyWidgetStyle(GtkRcStyle *style) { gtk_widget_modify_style(m_widget, style); gtk_widget_modify_style(GTK_BIN(m_widget)->child, style); } GdkWindow * -wxToggleBitmapButton::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const +wxBitmapToggleButton::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const { return GTK_BUTTON(m_widget)->event_window; } // Get the "best" size for this control. -wxSize wxToggleBitmapButton::DoGetBestSize() const +wxSize wxBitmapToggleButton::DoGetBestSize() const { wxSize best; @@ -177,7 +177,7 @@ wxSize wxToggleBitmapButton::DoGetBestSize() const // static wxVisualAttributes -wxToggleBitmapButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +wxBitmapToggleButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) { return GetDefaultAttributesFromGTKWidget(gtk_toggle_button_new); } diff --git a/src/mac/carbon/tglbtn.cpp b/src/mac/carbon/tglbtn.cpp index f36eb04099..43904685f7 100644 --- a/src/mac/carbon/tglbtn.cpp +++ b/src/mac/carbon/tglbtn.cpp @@ -104,12 +104,12 @@ wxInt32 wxToggleButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEV } // ---------------------------------------------------------------------------- -// wxToggleBitmapButton +// wxBitmapToggleButton // ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxToggleBitmapButton, wxControl) +IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton, wxControl) -bool wxToggleBitmapButton::Create(wxWindow *parent, wxWindowID id, +bool wxBitmapToggleButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& label, const wxPoint& pos, const wxSize& size, long style, @@ -137,7 +137,7 @@ bool wxToggleBitmapButton::Create(wxWindow *parent, wxWindowID id, return TRUE; } -wxSize wxToggleBitmapButton::DoGetBestSize() const +wxSize wxBitmapToggleButton::DoGetBestSize() const { if (!m_bitmap.IsOk()) return wxSize(20,20); @@ -145,23 +145,23 @@ wxSize wxToggleBitmapButton::DoGetBestSize() const return wxSize ( m_bitmap.GetWidth()+6, m_bitmap.GetHeight()+6 ) ; } -void wxToggleBitmapButton::SetValue(bool val) +void wxBitmapToggleButton::SetValue(bool val) { m_peer->SetValue( val ) ; } -bool wxToggleBitmapButton::GetValue() const +bool wxBitmapToggleButton::GetValue() const { return m_peer->GetValue() ; } -void wxToggleBitmapButton::Command(wxCommandEvent & event) +void wxBitmapToggleButton::Command(wxCommandEvent & event) { SetValue((event.GetInt() != 0)); ProcessCommand(event); } -wxInt32 wxToggleBitmapButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) +wxInt32 wxBitmapToggleButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) { wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId); event.SetInt(GetValue()); -- 2.45.2