From 80752b57a9bbdfa7613a917d9ece00fc47677080 Mon Sep 17 00:00:00 2001
From: Robin Dunn <robin@alldunn.com>
Date: Thu, 14 Sep 2006 19:42:41 +0000
Subject: [PATCH] As per wx-dev, split the sort arrow options out to a separate
 parameter.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41230 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/renderer.tex                    | 16 +++++++++------
 include/wx/renderer.h                         | 20 ++++++++++++-------
 include/wx/univ/renderer.h                    |  3 ++-
 src/generic/renderg.cpp                       | 11 +++++++---
 src/gtk/renderer.cpp                          |  4 +++-
 src/mac/carbon/renderer.cpp                   | 13 +++++++-----
 src/msw/renderer.cpp                          |  6 ++++--
 .../gizmos/wxCode/src/treelistctrl.cpp        |  3 ++-
 wxPython/src/_renderer.i                      | 11 +++++++---
 9 files changed, 58 insertions(+), 29 deletions(-)

diff --git a/docs/latex/wx/renderer.tex b/docs/latex/wx/renderer.tex
index 7bb7e91223..3524cd8aee 100644
--- a/docs/latex/wx/renderer.tex
+++ b/docs/latex/wx/renderer.tex
@@ -19,7 +19,7 @@ However not all controls exist under all (or even any) platforms and in this
 case wxWidgets provides a default, generic, implementation of them written in
 wxWidgets itself.
 
-These controls don't have the native appearance if only the standard
+These controls don't have the native appearance if only the tandard
 line drawing and other graphics primitives are used, because the native
 appearance is different under different platforms while the lines are always
 drawn in the same way.
@@ -75,9 +75,6 @@ enum
     wxCONTROL_CHECKED    = 0x00000040,  // (check/radio button) is checked
     wxCONTROL_CHECKABLE  = 0x00000080,  // (menu) item can be checked
     wxCONTROL_UNDETERMINED = wxCONTROL_CHECKABLE  // (check) undetermined state
-    wxCONTROL_UPICON     = 0x00000100,  // header button has an up arrow icon
-    wxCONTROL_DOWNICON   = 0x00000200,  // header button has a down arrow icon
-
 };
 \end{verbatim}
 
@@ -134,9 +131,16 @@ rectangle of a drop down button which arrow matches the size you need.
 
 \membersection{wxRendererNative::DrawHeaderButton}\label{wxrenderernativedrawheaderbutton}
 
-\func{void}{DrawHeaderButton}{\param{wxWindow* }{win}, \param{wxDC\& }{dc}, \param{const wxRect\& }{rect}, \param{int }{flags = 0}, \param{wxHeaderButtonParams* }{params = NULL}}
+\func{void}{DrawHeaderButton}{\param{wxWindow* }{win}, \param{wxDC\& }{dc}, \param{const wxRect\& }{rect}, \param{int }{flags = 0}, \param{wxHeaderSortIconType }{sortArrow = wxHDR\_SORT\_ICON\_NONE}, \param{wxHeaderButtonParams* }{params = NULL}}
 
-Draw the header control button (used by \helpref{wxListCtrl}{wxlistctrl}).
+Draw the header control button (used, for example, by
+\helpref{wxListCtrl}{wxlistctrl}).  Depending on platforms the
+\arg{flags} parameter may support the \texttt{wxCONTROL\_SELECTED}
+\texttt{wxCONTROL\_DISABLED} and \texttt{wxCONTROL\_CURRENT} bits.
+The \arg{sortArrow} parameter can be one of
+\texttt{wxHDR\_SORT\_ICON\_NONE}, \texttt{wxHDR\_SORT\_ICON\_UP}, or 
+\texttt{wxHDR\_SORT\_ICON\_DOWN}.  Additional values controlling the
+drawing of a text or bitmap label can be passed in \arg{params}.
 
 
 \membersection{wxRendererNative::DrawPushButton}\label{wxrenderernativedrawpushbutton}
diff --git a/include/wx/renderer.h b/include/wx/renderer.h
index 4fbcf21b19..82ca8ce7ce 100644
--- a/include/wx/renderer.h
+++ b/include/wx/renderer.h
@@ -59,10 +59,8 @@ enum
     wxCONTROL_CHECKED    = 0x00000040,  // (check/radio button) is checked
     wxCONTROL_CHECKABLE  = 0x00000080,  // (menu) item can be checked
     wxCONTROL_UNDETERMINED = wxCONTROL_CHECKABLE, // (check) undetermined state
-    wxCONTROL_UPICON     = 0x00000100,  // header button has an up arrow icon
-    wxCONTROL_DOWNICON   = 0x00000200,  // header button has a down arrow icon
 
-    wxCONTROL_FLAGS_MASK = 0x000002ff,
+    wxCONTROL_FLAGS_MASK = 0x000000ff,
 
     // this is a pseudo flag not used directly by wxRenderer but rather by some
     // controls internally
@@ -109,6 +107,12 @@ struct WXDLLEXPORT wxHeaderButtonParams
     int         m_labelAlignment;
 };
 
+enum wxHeaderSortIconType {
+    wxHDR_SORT_ICON_NONE,        // Header button has no sort arrow
+    wxHDR_SORT_ICON_UP,          // Header button an an up sort arrow icon
+    wxHDR_SORT_ICON_DOWN         // Header button an a down sort arrow icon
+};
+
 
 // wxRendererNative interface version
 struct WXDLLEXPORT wxRendererVersion
@@ -156,6 +160,7 @@ public:
                                   wxDC& dc,
                                   const wxRect& rect,
                                   int flags = 0,
+                                  wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
                                   wxHeaderButtonParams* params=NULL) = 0;
 
 
@@ -165,6 +170,7 @@ public:
                                           wxDC& dc,
                                           const wxRect& rect,
                                           int flags = 0,
+                                          wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
                                           wxHeaderButtonParams* params=NULL) = 0;
 
     // Returns the default height of a header button, either a fixed platform
@@ -304,17 +310,17 @@ public:
                                   wxDC& dc,
                                   const wxRect& rect,
                                   int flags = 0,
+                                  wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
                                   wxHeaderButtonParams* params = NULL)
-        { m_rendererNative.DrawHeaderButton(win, dc, rect, flags, params); }
-
+        { m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params); }
 
     virtual void DrawHeaderButtonContents(wxWindow *win,
                                           wxDC& dc,
                                           const wxRect& rect,
                                           int flags = 0,
+                                          wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
                                           wxHeaderButtonParams* params = NULL)
-        { m_rendererNative.DrawHeaderButtonContents(win, dc, rect, flags, params); }
-
+        { m_rendererNative.DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params); }
 
     virtual int GetHeaderButtonHeight(wxWindow *win)
         { return m_rendererNative.GetHeaderButtonHeight(win); }
diff --git a/include/wx/univ/renderer.h b/include/wx/univ/renderer.h
index c2ba148e26..60ac8bb934 100644
--- a/include/wx/univ/renderer.h
+++ b/include/wx/univ/renderer.h
@@ -889,8 +889,9 @@ public:
                                   wxDC& dc,
                                   const wxRect& rect,
                                   int flags = 0,
+                                  wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
                                   wxHeaderButtonParams* params=NULL)
-        { m_renderer->DrawHeaderButton(win, dc, rect, flags, params); }
+        { m_renderer->DrawHeaderButton(win, dc, rect, flags, sortArrow, params); }
     virtual void DrawTreeItemButton(wxWindow *win,
                                     wxDC& dc,
                                     const wxRect& rect,
diff --git a/src/generic/renderg.cpp b/src/generic/renderg.cpp
index 6f84f6b904..758e36f472 100644
--- a/src/generic/renderg.cpp
+++ b/src/generic/renderg.cpp
@@ -50,12 +50,14 @@ public:
                                   wxDC& dc,
                                   const wxRect& rect,
                                   int flags = 0,
+                                  wxHBSortIconType sortArrow = wxHB_SORT_ICON_NONE,
                                   wxHeaderButtonParams* params = NULL);
 
     virtual void DrawHeaderButtonContents(wxWindow *win,
                                           wxDC& dc,
                                           const wxRect& rect,
                                           int flags = 0,
+                                          wxHBSortIconType sortArrow = wxHB_SORT_ICON_NONE,
                                           wxHeaderButtonParams* params = NULL);
 
     virtual int GetHeaderButtonHeight(wxWindow *win);
@@ -207,6 +209,7 @@ wxRendererGeneric::DrawHeaderButton(wxWindow* win,
                                     wxDC& dc,
                                     const wxRect& rect,
                                     int flags,
+                                    wxHeaderSortIconType sortArrow,
                                     wxHeaderButtonParams* params)
 {
     const int CORNER = 1;
@@ -236,14 +239,16 @@ wxRendererGeneric::DrawHeaderButton(wxWindow* win,
     dc.DrawLine( x, y+h-1, x+1, y+h-1 );
     dc.DrawLine( x+w-1, y, x+w-1, y+1 );
 
-    DrawHeaderButtonContents(win, dc, rect, flags, params);
+    DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params);
 }
 
+
 void
 wxRendererGeneric::DrawHeaderButtonContents(wxWindow *win,
                                             wxDC& dc,
                                             const wxRect& rect,
                                             int flags,
+                                            wxHeaderSortIconType sortArrow,
                                             wxHeaderButtonParams* params)
 {
     // Mark this item as selected.  For the generic version we'll just draw an
@@ -264,7 +269,7 @@ wxRendererGeneric::DrawHeaderButtonContents(wxWindow *win,
 
     // Draw an up or down arrow
     int arrowSpace = 0;
-    if (flags & (wxCONTROL_UPICON | wxCONTROL_DOWNICON) )
+    if (sortArrow != wxHDR_SORT_ICON_NONE )
     {
         wxRect ar = rect;
 
@@ -276,7 +281,7 @@ wxRendererGeneric::DrawHeaderButtonContents(wxWindow *win,
         arrowSpace = 3*ar.width/2; // space to preserve when drawing the label
         
         wxPoint triPt[3];
-        if ( flags & wxCONTROL_UPICON )
+        if ( sortArrow & wxHDR_SORT_ICON_UP )
         {
             triPt[0].x = ar.width / 2;
             triPt[0].y = 0;
diff --git a/src/gtk/renderer.cpp b/src/gtk/renderer.cpp
index 133f7af1cf..2c8c94ee1e 100644
--- a/src/gtk/renderer.cpp
+++ b/src/gtk/renderer.cpp
@@ -47,6 +47,7 @@ public:
                                   wxDC& dc,
                                   const wxRect& rect,
                                   int flags = 0,
+                                  wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
                                   wxHeaderButtonParams* params = NULL);
 
     // draw the expanded/collapsed icon for a tree control item
@@ -185,6 +186,7 @@ wxRendererGTK::DrawHeaderButton(wxWindow *win,
                                 wxDC& dc,
                                 const wxRect& rect,
                                 int flags,
+                                wxHeaderSortIconType sortArrow,
                                 wxHeaderButtonParams* params)
 {
 
@@ -208,7 +210,7 @@ wxRendererGTK::DrawHeaderButton(wxWindow *win,
         dc.LogicalToDeviceX(rect.x) - x_diff, rect.y, rect.width, rect.height
     );
 
-    DrawHeaderButtonContents(win, dc, rect, flags, params);
+    DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params);
 }
 
 // draw a ">" or "v" button
diff --git a/src/mac/carbon/renderer.cpp b/src/mac/carbon/renderer.cpp
index ee4ec9022d..802ff8a81e 100644
--- a/src/mac/carbon/renderer.cpp
+++ b/src/mac/carbon/renderer.cpp
@@ -37,6 +37,7 @@ public:
         wxDC& dc,
         const wxRect& rect,
         int flags = 0,
+        wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
         wxHeaderButtonParams* params = NULL );
 
     virtual int GetHeaderButtonHeight(wxWindow *win);
@@ -129,6 +130,7 @@ void wxRendererMac::DrawHeaderButton( wxWindow *win,
     wxDC& dc,
     const wxRect& rect,
     int flags,
+    wxHeaderSortIconType sortArrow,
     wxHeaderButtonParams* params )
 {
     const wxCoord x = dc.XLOG2DEV(rect.x /*- 1*/);
@@ -185,13 +187,13 @@ void wxRendererMac::DrawHeaderButton( wxWindow *win,
             drawInfo.adornment = kThemeAdornmentNone;
 
             // The down arrow is drawn automatically, change it to an up arrow if needed.
-            if ( flags & wxCONTROL_UPICON )
+            if ( sortArrow == wxHDR_SORT_ICON_UP )
                 drawInfo.adornment = kThemeAdornmentHeaderButtonSortUp;
                 
             HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect );
 
             // If we don't want any arrows we need to draw over the one already there
-            if ( (flags & wxCONTROL_SELECTED) && !(flags & (wxCONTROL_UPICON|wxCONTROL_DOWNICON)) )
+            if ( (flags & wxCONTROL_SELECTED) && (sortArrow == wxHDR_SORT_ICON_NONE) )
             {
                 // clip to the header rectangle
                 CGContextSaveGState( cgContext );
@@ -212,13 +214,14 @@ void wxRendererMac::DrawHeaderButton( wxWindow *win,
     // Reserve room for the arrows before writing the label, and turn off the
     // flags we've already handled
     wxRect newRect(rect);
-    if ( (flags & wxCONTROL_SELECTED) && (flags & (wxCONTROL_UPICON|wxCONTROL_DOWNICON)) )
+    if ( (flags & wxCONTROL_SELECTED) && (sortArrow != wxHDR_SORT_ICON_NONE) )
     {
         newRect.width -= 12;
+        sortArrow = wxHDR_SORT_ICON_NONE;
     }
-    flags &= ~(wxCONTROL_SELECTED | wxCONTROL_UPICON | wxCONTROL_DOWNICON);
+    flags &= ~wxCONTROL_SELECTED;
 
-    DrawHeaderButtonContents(win, dc, newRect, flags, params);
+    DrawHeaderButtonContents(win, dc, newRect, flags, sortArrow, params);
 }
 
 
diff --git a/src/msw/renderer.cpp b/src/msw/renderer.cpp
index 15f86caaa3..bba35b0154 100644
--- a/src/msw/renderer.cpp
+++ b/src/msw/renderer.cpp
@@ -122,6 +122,7 @@ public:
                                   wxDC& dc,
                                   const wxRect& rect,
                                   int flags = 0,
+                                  wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
                                   wxHeaderButtonParams* params = NULL);
     virtual int GetHeaderButtonHeight(wxWindow *win);
     
@@ -286,12 +287,13 @@ wxRendererXP::DrawHeaderButton(wxWindow *win,
                                wxDC& dc,
                                const wxRect& rect,
                                int flags,
+                               wxHeaderSortIconType sortArrow,
                                wxHeaderButtonParams* params)
 {
     wxUxThemeHandle hTheme(win, L"HEADER");
     if ( !hTheme )
     {
-        m_rendererNative.DrawHeaderButton(win, dc, rect, flags, params);
+        m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params);
         return;
     }
 
@@ -320,7 +322,7 @@ wxRendererXP::DrawHeaderButton(wxWindow *win,
     // and then clear those flags before calling DrawHeaderButtonContents.
     
     // Add any extras that are specified in flags and params
-    DrawHeaderButtonContents(win, dc, rect, flags, params);
+    DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params);
 }
 
 
diff --git a/wxPython/contrib/gizmos/wxCode/src/treelistctrl.cpp b/wxPython/contrib/gizmos/wxCode/src/treelistctrl.cpp
index f815aa8dab..5d97fe6f35 100644
--- a/wxPython/contrib/gizmos/wxCode/src/treelistctrl.cpp
+++ b/wxPython/contrib/gizmos/wxCode/src/treelistctrl.cpp
@@ -1194,7 +1194,8 @@ void wxTreeListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
         if ((image != -1) && imageList) 
             params.m_labelBitmap = imageList->GetBitmap(image);
                 
-        wxRendererNative::Get().DrawHeaderButton(this, dc, rect, flags, &params);
+        wxRendererNative::Get().DrawHeaderButton(this, dc, rect, flags,
+                                                 wxHDR_SORT_ICON_NONE, &params);
     }
 
     if (x < w) {
diff --git a/wxPython/src/_renderer.i b/wxPython/src/_renderer.i
index 705abbba80..07106059c8 100644
--- a/wxPython/src/_renderer.i
+++ b/wxPython/src/_renderer.i
@@ -34,10 +34,8 @@ enum
     wxCONTROL_CHECKED    = 0x00000040,  // (check/radio button) is checked
     wxCONTROL_CHECKABLE  = 0x00000080,  // (menu) item can be checked
     wxCONTROL_UNDETERMINED = wxCONTROL_CHECKABLE, // (check) undetermined state
-    wxCONTROL_UPICON     = 0x00000100,  // header button has an up arrow icon
-    wxCONTROL_DOWNICON   = 0x00000200,  // header button has a down arrow icon
 
-    wxCONTROL_FLAGS_MASK = 0x000002ff,
+    wxCONTROL_FLAGS_MASK = 0x000000ff,
 
     // this is a pseudo flag not used directly by wxRenderer but rather by some
     // controls internally
@@ -97,6 +95,11 @@ struct wxHeaderButtonParams
     int         m_labelAlignment;
 };
 
+enum wxHeaderSortIconType {
+    wxHDR_SORT_ICON_NONE,        // Header button has no sort arrow
+    wxHDR_SORT_ICON_UP,          // Header button an an up sort arrow icon
+    wxHDR_SORT_ICON_DOWN         // Header button an a down sort arrow icon
+};
 
 
 DocStr(wxRendererVersion,
@@ -155,6 +158,7 @@ public:
                                         wxDC& dc,
                                         const wxRect& rect,
                                         int flags = 0,
+                                        wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
                                         wxHeaderButtonParams* params=NULL),
         "Draw the header control button (such as what is used by `wx.ListCtrl`
 in report mode.)", "");
@@ -165,6 +169,7 @@ in report mode.)", "");
                                                 wxDC& dc,
                                                 const wxRect& rect,
                                                 int flags = 0,
+                                                wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
                                                 wxHeaderButtonParams* params=NULL),
         "Draw the contents of a header control button, (label, sort
 arrows, etc.)  Normally this is only called by `DrawHeaderButton`.", "");
-- 
2.50.0

