From 2209baaee3a8578450e204593b79ed155f340f68 Mon Sep 17 00:00:00 2001
From: Robert Roebling <robert@roebling.de>
Date: Mon, 24 Apr 2006 16:57:27 +0000
Subject: [PATCH]   Committed Jaako's renderer patch

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38891 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/renderer.tex | 23 ++++++++++-
 include/wx/renderer.h      | 19 ++++++++--
 src/generic/renderg.cpp    | 38 ++++++++++++-------
 src/gtk/renderer.cpp       | 65 ++++++++++++++++++-------------
 src/msw/renderer.cpp       | 78 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 179 insertions(+), 44 deletions(-)

diff --git a/docs/latex/wx/renderer.tex b/docs/latex/wx/renderer.tex
index ec48042f02..9678cb65ae 100644
--- a/docs/latex/wx/renderer.tex
+++ b/docs/latex/wx/renderer.tex
@@ -68,7 +68,8 @@ enum
     wxCONTROL_CURRENT    = 0x00000010,  // mouse is currently over the control
     wxCONTROL_SELECTED   = 0x00000020,  // selected item in e.g. listbox
     wxCONTROL_CHECKED    = 0x00000040,  // (check/radio button) is checked
-    wxCONTROL_CHECKABLE  = 0x00000080   // (menu) item can be checked
+    wxCONTROL_CHECKABLE  = 0x00000080,  // (menu) item can be checked
+    wxCONTROL_UNDETERMINED = wxCONTROL_CHECKABLE  // (check) undetermined state
 };
 \end{verbatim}
 
@@ -91,6 +92,16 @@ No base class
 Virtual destructor as for any base class.
 
 
+\membersection{wxRendererNative::DrawCheckButton}\label{wxrenderernativedrawcheckbutton}
+
+\func{void}{DrawCheckButton}{\param{wxWindow *}{win}, \param{wxDC\& }{dc}, \param{const wxRect\& }{rect}, \param{int }{flags}}
+
+Draw a check box (used by wxDataViewCtrl).
+
+\arg{flags} may have the \texttt{wxCONTROL\_CHECKED}, \texttt{wxCONTROL\_CURRENT} or
+\texttt{wxCONTROL\_UNDETERMINED} bit set.
+
+
 \membersection{wxRendererNative::DrawComboBoxDropButton}\label{wxrenderernativedrawcomboboxdropbutton}
 
 \func{void}{DrawComboBoxDropButton}{\param{wxWindow *}{win}, \param{wxDC\& }{dc}, \param{const wxRect\& }{rect}, \param{int }{flags}}
@@ -120,6 +131,16 @@ rectangle of a drop down button which arrow matches the size you need.
 Draw the header control button (used by \helpref{wxListCtrl}{wxlistctrl}).
 
 
+\membersection{wxRendererNative::DrawPushButton}\label{wxrenderernativedrawpushbutton}
+
+\func{void}{DrawPushButton}{\param{wxWindow *}{win}, \param{wxDC\& }{dc}, \param{const wxRect\& }{rect}, \param{int }{flags}}
+
+Draw a blank push button that looks very similar to \helpref{wxButton}{wxbutton}.
+
+\arg{flags} may have the \texttt{wxCONTROL\_PRESSED}, \texttt{wxCONTROL\_CURRENT} or
+\texttt{wxCONTROL\_ISDEFAULT} bit set.
+
+
 \membersection{wxRendererNative::DrawSplitterBorder}\label{wxrenderernativedrawsplitterborder}
 
 \func{void}{DrawSplitterBorder}{\param{wxWindow* }{win}, \param{wxDC\& }{dc}, \param{const wxRect\& }{rect}, \param{int }{flags = 0}}
diff --git a/include/wx/renderer.h b/include/wx/renderer.h
index 8a8076c484..9d21e8db1d 100644
--- a/include/wx/renderer.h
+++ b/include/wx/renderer.h
@@ -170,7 +170,6 @@ public:
                                const wxRect& rect,
                                int flags = 0) = 0;
 
-
     // draw check button
     //
     // flags may use wxCONTROL_CHECKED, wxCONTROL_UNDETERMINED and wxCONTROL_CURRENT
@@ -178,7 +177,15 @@ public:
                                  wxDC& dc,
                                  const wxRect& rect,
                                  int flags = 0) = 0;
-                                 
+
+    // draw blank button
+    //
+    // flags may use wxCONTROL_PRESSED, wxCONTROL_CURRENT and wxCONTROL_ISDEFAULT
+    virtual void DrawPushButton(wxWindow *win,
+                                wxDC& dc,
+                                const wxRect& rect,
+                                int flags = 0) = 0;
+
     // geometry functions
     // ------------------
 
@@ -286,7 +293,13 @@ public:
                                  const wxRect& rect,
                                  int flags = 0 )
         { m_rendererNative.DrawCheckButton( win, dc, rect, flags ); }
-        
+
+    virtual void DrawPushButton(wxWindow *win,
+                                wxDC& dc,
+                                const wxRect& rect,
+                                int flags = 0 )
+        { m_rendererNative.DrawPushButton( win, dc, rect, flags ); }
+
     virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win)
         { return m_rendererNative.GetSplitterParams(win); }
 
diff --git a/src/generic/renderg.cpp b/src/generic/renderg.cpp
index 53e31a830f..41a5bd65ff 100644
--- a/src/generic/renderg.cpp
+++ b/src/generic/renderg.cpp
@@ -82,7 +82,12 @@ public:
                                  wxDC& dc,
                                  const wxRect& rect,
                                  int flags = 0);
-                                 
+
+    virtual void DrawPushButton(wxWindow *win,
+                                wxDC& dc,
+                                const wxRect& rect,
+                                int flags = 0);
+
     virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
 
     virtual wxRendererVersion GetVersion() const
@@ -360,21 +365,12 @@ void
 wxRendererGeneric::DrawComboBoxDropButton(wxWindow *win,
                                           wxDC& dc,
                                           const wxRect& rect,
-                                          int WXUNUSED(flags))
+                                          int flags)
 {
-    // Creating a generic button background that would actually be
-    // useful is rather difficult to accomplish. Best compromise
-    // is to use window's background colour to achieve transparent'
-    // ish appearance that should look decent in combo box style
-    // controls.
-    wxColour col = win->GetBackgroundColour();
-    dc.SetBrush(wxBrush(col));
-    dc.SetPen(wxPen(col));
-    dc.DrawRectangle(rect);
-    DrawDropArrow(win,dc,rect);
+    DrawPushButton(win,dc,rect,flags);
+    DrawDropArrow(win,dc,rect,flags);
 }
 
-
 void
 wxRendererGeneric::DrawDropArrow(wxWindow *win,
                                  wxDC& dc,
@@ -416,6 +412,22 @@ wxRendererGeneric::DrawCheckButton(wxWindow *WXUNUSED(win),
     }
 }
 
+void
+wxRendererGeneric::DrawPushButton(wxWindow *win,
+                                  wxDC& dc,
+                                  const wxRect& rect,
+                                  int flags)
+{
+    // Don't try anything too fancy. It'll just turn out looking
+    // out-of-place on most platforms.
+    wxColour bgCol = flags & wxCONTROL_DISABLED ?
+                        wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE) :
+                        win->GetBackgroundColour();
+    dc.SetBrush(wxBrush(bgCol));
+    dc.SetPen(wxPen(bgCol));
+    dc.DrawRectangle(rect);
+}
+
 // ----------------------------------------------------------------------------
 // A module to allow cleanup of generic renderer.
 // ----------------------------------------------------------------------------
diff --git a/src/gtk/renderer.cpp b/src/gtk/renderer.cpp
index e4a3f236b7..53ab9e764b 100644
--- a/src/gtk/renderer.cpp
+++ b/src/gtk/renderer.cpp
@@ -82,13 +82,18 @@ public:
                                  wxDC& dc,
                                  const wxRect& rect,
                                  int flags = 0);
-                                 
+
+    virtual void DrawPushButton(wxWindow *win,
+                                wxDC& dc,
+                                const wxRect& rect,
+                                int flags = 0);
+
     virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
 
 private:
     // FIXME: shouldn't we destroy these windows somewhere?
 
-    // used by DrawHeaderButton and DrawComboBoxDropButton
+    // used by DrawHeaderButton and DrawPushButton
     static GtkWidget *GetButtonWidget();
 
     // used by DrawTreeItemButton()
@@ -185,7 +190,7 @@ wxRendererGTK::DrawHeaderButton(wxWindow *win,
     (
         button->style,
         // FIXME: I suppose GTK_PIZZA(win->m_wxwindow)->bin_window doesn't work with wxMemoryDC.
-        //   Maybe use code similar as in DrawComboBoxDropButton below?
+        //   Maybe use code similar as in DrawPushButton below?
         GTK_PIZZA(win->m_wxwindow)->bin_window,
         flags & wxCONTROL_DISABLED ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL,
         GTK_SHADOW_OUT,
@@ -422,13 +427,22 @@ wxRendererGTK::DrawComboBoxDropButton(wxWindow *win,
                                       const wxRect& rect,
                                       int flags)
 {
-    GtkWidget *button = GetButtonWidget();
+    DrawPushButton(win,dc,rect,flags);
+    DrawDropArrow(win,dc,rect);
+}
+
+void 
+wxRendererGTK::DrawCheckButton(wxWindow *win,
+                                 wxDC& dc,
+                                 const wxRect& rect,
+                                 int flags )
+{
+    GtkWidget *button = GetCheckButtonWidget();
 
     // for reason why we do this, see DrawDropArrow
     wxWindowDC& wdc = (wxWindowDC&)dc;
     wxASSERT ( wdc.IsKindOf(CLASSINFO(wxWindowDC)) );
-
-    // draw button
+    
     GtkStateType state;
 
     if ( flags & wxCONTROL_PRESSED )
@@ -439,36 +453,33 @@ wxRendererGTK::DrawComboBoxDropButton(wxWindow *win,
         state = GTK_STATE_PRELIGHT;
     else
         state = GTK_STATE_NORMAL;
-
-    gtk_paint_box
+    
+    gtk_paint_check
     (
         button->style,
         wdc.m_window,
         state,
-        flags & wxCONTROL_PRESSED ? GTK_SHADOW_IN : GTK_SHADOW_OUT,
+        flags & wxCONTROL_CHECKED ? GTK_SHADOW_IN : GTK_SHADOW_OUT,
         NULL,
         button,
-        "button",
-        rect.x, rect.y, rect.width, rect.height
+        "cellcheck",
+        rect.x, rect.y, 13, 13
     );
-
-    // draw arrow on button
-    DrawDropArrow(win,dc,rect,flags);
-
 }
 
-void 
-wxRendererGTK::DrawCheckButton(wxWindow *win,
-                                 wxDC& dc,
-                                 const wxRect& rect,
-                                 int flags )
+void
+wxRendererGTK::DrawPushButton(wxWindow *win,
+                              wxDC& dc,
+                              const wxRect& rect,
+                              int flags)
 {
-    GtkWidget *button = GetCheckButtonWidget();
+    GtkWidget *button = GetButtonWidget();
 
     // for reason why we do this, see DrawDropArrow
     wxWindowDC& wdc = (wxWindowDC&)dc;
     wxASSERT ( wdc.IsKindOf(CLASSINFO(wxWindowDC)) );
-    
+
+    // draw button
     GtkStateType state;
 
     if ( flags & wxCONTROL_PRESSED )
@@ -479,16 +490,16 @@ wxRendererGTK::DrawCheckButton(wxWindow *win,
         state = GTK_STATE_PRELIGHT;
     else
         state = GTK_STATE_NORMAL;
-    
-    gtk_paint_check
+
+    gtk_paint_box
     (
         button->style,
         wdc.m_window,
         state,
-        flags & wxCONTROL_CHECKED ? GTK_SHADOW_IN : GTK_SHADOW_OUT,
+        flags & wxCONTROL_PRESSED ? GTK_SHADOW_IN : GTK_SHADOW_OUT,
         NULL,
         button,
-        "cellcheck",
-        rect.x, rect.y, 13, 13
+        "button",
+        rect.x, rect.y, rect.width, rect.height
     );
 }
diff --git a/src/msw/renderer.cpp b/src/msw/renderer.cpp
index 4763dfe7bd..ca355bdf17 100644
--- a/src/msw/renderer.cpp
+++ b/src/msw/renderer.cpp
@@ -39,11 +39,18 @@
 // tmschema.h is in Win32 Platform SDK and might not be available with earlier
 // compilers
 #ifndef CP_DROPDOWNBUTTON
+    #define BP_PUSHBUTTON      1
     #define BP_CHECKBOX        3
     #define CBS_UNCHECKEDNORMAL 1
     #define CBS_CHECKEDNORMAL   (CBS_UNCHECKEDNORMAL + 4)
     #define CBS_MIXEDNORMAL     (CBS_CHECKEDNORMAL + 4)
 
+    #define PBS_NORMAL          1
+    #define PBS_HOT             2
+    #define PBS_PRESSED         3
+    #define PBS_DISABLED        4
+    #define PBS_DEFAULTED       5
+
     #define CP_DROPDOWNBUTTON  1
 
     #define CBXS_NORMAL        1
@@ -83,6 +90,11 @@ public:
                                         const wxRect& rect,
                                         int flags = 0);
 
+    virtual void DrawPushButton(wxWindow *win,
+                                wxDC& dc,
+                                const wxRect& rect,
+                                int flags = 0);
+
 private:
     DECLARE_NO_COPY_CLASS(wxRendererMSW)
 };
@@ -127,6 +139,11 @@ public:
                                  const wxRect& rect,
                                  int flags = 0);
 
+    virtual void DrawPushButton(wxWindow *win,
+                                wxDC& dc,
+                                const wxRect& rect,
+                                int flags = 0);
+
     virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
 private:
     DECLARE_NO_COPY_CLASS(wxRendererXP)
@@ -179,6 +196,27 @@ wxRendererMSW::DrawComboBoxDropButton(wxWindow * WXUNUSED(win),
     ::DrawFrameControl(GetHdcOf(dc), &r, DFC_SCROLL, style);
 }
 
+void
+wxRendererMSW::DrawPushButton(wxWindow * WXUNUSED(win),
+                              wxDC& dc,
+                              const wxRect& rect,
+                              int flags)
+{
+    RECT r;
+    r.left = rect.GetLeft();
+    r.top = rect.GetTop();
+    r.bottom = rect.y + rect.height;
+    r.right = rect.x + rect.width;
+
+    int style = DFCS_BUTTONPUSH;
+    if ( flags & wxCONTROL_DISABLED )
+        style |= DFCS_INACTIVE;
+    if ( flags & wxCONTROL_PRESSED )
+        style |= DFCS_PUSHED | DFCS_FLAT;
+
+    ::DrawFrameControl(GetHdcOf(dc), &r, DFC_BUTTON, style);
+}
+
 // ============================================================================
 // wxRendererXP implementation
 // ============================================================================
@@ -339,6 +377,46 @@ wxRendererXP::DrawCheckButton(wxWindow *win,
                             );
 }
 
+void
+wxRendererXP::DrawPushButton(wxWindow * win,
+                             wxDC& dc,
+                             const wxRect& rect,
+                             int flags)
+{
+    wxUxThemeHandle hTheme(win, L"BUTTON");
+    if ( !hTheme )
+    {
+        m_rendererNative.DrawPushButton(win, dc, rect, flags);
+        return;
+    }
+
+    RECT r;
+    wxCopyRectToRECT(rect, r);
+
+    int state;
+    if ( flags & wxCONTROL_PRESSED )
+        state = PBS_PRESSED;
+    else if ( flags & wxCONTROL_CURRENT )
+        state = PBS_HOT;
+    else if ( flags & wxCONTROL_DISABLED )
+        state = PBS_DISABLED;
+    else if ( flags & wxCONTROL_ISDEFAULT )
+        state = PBS_DEFAULTED;
+    else
+        state = PBS_NORMAL;
+
+    wxUxThemeEngine::Get()->DrawThemeBackground
+                            (
+                                hTheme,
+                                GetHdcOf(dc),
+                                BP_PUSHBUTTON,
+                                state,
+                                &r,
+                                NULL
+                            );
+
+}
+
 // ----------------------------------------------------------------------------
 // splitter drawing
 // ----------------------------------------------------------------------------
-- 
2.50.0

