]> git.saurik.com Git - wxWidgets.git/commitdiff
Document wxBitmapToggleButton, add update UI event in Base class for all toggle buttons
authorRobert Roebling <robert@roebling.de>
Sat, 8 Dec 2007 10:36:59 +0000 (10:36 +0000)
committerRobert Roebling <robert@roebling.de>
Sat, 8 Dec 2007 10:36:59 +0000 (10:36 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50563 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/bitmaptglbutn.tex [new file with mode: 0644]
docs/latex/wx/category.tex
docs/latex/wx/classes.tex
docs/latex/wx/tglbtn.tex
include/wx/gtk/tglbtn.h
include/wx/tglbtn.h
src/common/valgen.cpp
src/gtk/tglbtn.cpp
src/mac/carbon/tglbtn.cpp

diff --git a/docs/latex/wx/bitmaptglbutn.tex b/docs/latex/wx/bitmaptglbutn.tex
new file mode 100644 (file)
index 0000000..27c1eed
--- /dev/null
@@ -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}
+
+<wx/tglbtn.h>
+
+\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.}
+
index 17b1f7782c4937f96999666e23916bad8bcff077..1a18ca2aaedce2cd39881a626a9b267426eadfe6 100644 (file)
@@ -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}
index bc5a406ec522c64ca7cb0ca0577ed0ec106cb078..9754c13f4702f33d87a290ec9d063f599349c36f 100644 (file)
@@ -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
index 9f82de7e08186553c37cfc628252933036b10429..0cd8afa5cf0f69e03a73bafabb882121d91b3ecf 100644 (file)
@@ -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.}
+
index 4c1f5f59b8808f17e9284251d8f8526fc7db3903..1a656e6c09c55c87893d21493522f89a7a641f1c 100644 (file)
@@ -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
index 7ac6ec9840207f307c3289042f7566c11f72df46..228cffdd31ca12659e0debfe2eff1763d2709980 100644 (file)
@@ -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))
 
index 4b05f6d4f29d1ea31c7dd7f1e0dd94122ea8a651..d9de2dea7b8579014bae031bdf8d893dca20968c 100644 (file)
@@ -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
index 120e9d75fad6cf455e5865b2bfc97113917ef232..50b319394fe82fe6247d269ab2acb3d3a42d2b8a 100644 (file)
@@ -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);
 }
index f36eb04099fc60dbeedf23f9af463d796c04602d..43904685f75eea567acda18bac18fb7c66d036eb 100644 (file)
@@ -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());