]> git.saurik.com Git - wxWidgets.git/commitdiff
Return optimal label width from DrawHeaderButton
authorRobin Dunn <robin@alldunn.com>
Thu, 30 Nov 2006 23:44:55 +0000 (23:44 +0000)
committerRobin Dunn <robin@alldunn.com>
Thu, 30 Nov 2006 23:44:55 +0000 (23:44 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43726 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/renderer.tex
include/wx/renderer.h
include/wx/univ/renderer.h
src/generic/renderg.cpp
src/gtk/renderer.cpp
src/mac/carbon/renderer.cpp
src/msw/renderer.cpp
wxPython/src/_renderer.i

index 6b1f12b56d05e374c352dcb0df25a86fbebb5872..d0fa0b0ec99768f2212d85b86dc9a84f9c0d5cb8 100644 (file)
@@ -131,16 +131,19 @@ 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{wxHeaderSortIconType }{sortArrow = wxHDR\_SORT\_ICON\_NONE}, \param{wxHeaderButtonParams* }{params = NULL}}
+\func{int}{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, 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\_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}.
+drawing of a text or bitmap label can be passed in \arg{params}.  The
+value returned is the optimal width to contain the the unabreviated
+label text or bitmap, the sort arrow if present, and internal margins.
+
 
 
 \membersection{wxRendererNative::DrawItemSelectionRect}\label{wxrenderernativedrawitemselectionrect}
index 9345586fea78ef8dafc93467b9bf31b6c4558b85..a270f0848edb6e835ba98fd718a2b68d35137e3d 100644 (file)
@@ -157,8 +157,9 @@ public:
     // drawing functions
     // -----------------
 
-    // draw the header control button (used by wxListCtrl)
-    virtual void DrawHeaderButton(wxWindow *win,
+    // draw the header control button (used by wxListCtrl) Returns optimal
+    // width for the label contents.
+    virtual int  DrawHeaderButton(wxWindow *win,
                                   wxDC& dc,
                                   const wxRect& rect,
                                   int flags = 0,
@@ -168,7 +169,7 @@ public:
 
     // Draw the contents of a header control button (label, sort arrows, etc.)
     // Normally only called by DrawHeaderButton.
-    virtual void DrawHeaderButtonContents(wxWindow *win,
+    virtual int  DrawHeaderButtonContents(wxWindow *win,
                                           wxDC& dc,
                                           const wxRect& rect,
                                           int flags = 0,
@@ -308,21 +309,21 @@ public:
         : m_rendererNative(rendererNative) { }
 
 
-    virtual void DrawHeaderButton(wxWindow *win,
+    virtual int  DrawHeaderButton(wxWindow *win,
                                   wxDC& dc,
                                   const wxRect& rect,
                                   int flags = 0,
                                   wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
                                   wxHeaderButtonParams* params = NULL)
-        { m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params); }
+        { return m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params); }
 
-    virtual void DrawHeaderButtonContents(wxWindow *win,
+    virtual int  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, sortArrow, params); }
+        { return m_rendererNative.DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params); }
 
     virtual int GetHeaderButtonHeight(wxWindow *win)
         { return m_rendererNative.GetHeaderButtonHeight(win); }
index 446d11fd1edc182358808d2e017702f8ac23a305..9d66b616fed9038063fd26369e37bcfb477d409e 100644 (file)
@@ -847,13 +847,13 @@ public:
                              int flags) const
         { return m_renderer->HitTestFrame(rect, pt, flags); }
 
-    virtual void DrawHeaderButton(wxWindow *win,
+    virtual int  DrawHeaderButton(wxWindow *win,
                                   wxDC& dc,
                                   const wxRect& rect,
                                   int flags = 0,
                                   wxHeaderSortIconType sortIcon = wxHDR_SORT_ICON_NONE,
                                   wxHeaderButtonParams* params = NULL)
-        { m_renderer->DrawHeaderButton(win, dc, rect, flags, sortIcon, params); }
+        { return m_renderer->DrawHeaderButton(win, dc, rect, flags, sortIcon, params); }
     virtual void DrawTreeItemButton(wxWindow *win,
                                     wxDC& dc,
                                     const wxRect& rect,
index 38713efef077408414dac34156eb4a59ecb98a6f..2991a11d95433c51b46bbb8d0b224ddb472f009a 100644 (file)
@@ -46,14 +46,14 @@ class WXDLLEXPORT wxRendererGeneric : public wxRendererNative
 public:
     wxRendererGeneric();
 
-    virtual void DrawHeaderButton(wxWindow *win,
+    virtual int  DrawHeaderButton(wxWindow *win,
                                   wxDC& dc,
                                   const wxRect& rect,
                                   int flags = 0,
                                   wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
                                   wxHeaderButtonParams* params = NULL);
 
-    virtual void DrawHeaderButtonContents(wxWindow *win,
+    virtual int  DrawHeaderButtonContents(wxWindow *win,
                                           wxDC& dc,
                                           const wxRect& rect,
                                           int flags = 0,
@@ -204,7 +204,7 @@ wxRendererGeneric::DrawShadedRect(wxDC& dc,
 // tree/list ctrl drawing
 // ----------------------------------------------------------------------------
 
-void
+int
 wxRendererGeneric::DrawHeaderButton(wxWindow* win,
                                     wxDC& dc,
                                     const wxRect& rect,
@@ -239,11 +239,11 @@ 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, sortArrow, params);
+    return DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params);
 }
 
 
-void
+int
 wxRendererGeneric::DrawHeaderButtonContents(wxWindow *win,
                                             wxDC& dc,
                                             const wxRect& rect,
@@ -251,6 +251,8 @@ wxRendererGeneric::DrawHeaderButtonContents(wxWindow *win,
                                             wxHeaderSortIconType sortArrow,
                                             wxHeaderButtonParams* params)
 {
+    int labelWidth = 0;
+    
     // Mark this item as selected.  For the generic version we'll just draw an
     // underline
     if ( flags & wxCONTROL_SELECTED )
@@ -306,14 +308,17 @@ wxRendererGeneric::DrawHeaderButtonContents(wxWindow *win,
         dc.SetBrush(wxBrush(c));
         dc.DrawPolygon( 3, triPt, ar.x, ar.y);                  
     }
-
+    labelWidth += arrowSpace;
+    
     const int margin = 5;   // number of pixels to reserve on either side of the label
     int bmpWidth = 0;
     int txtEnd = 0;
     
     if ( params && params->m_labelBitmap.Ok() )
         bmpWidth = params->m_labelBitmap.GetWidth() + 2;
-        
+
+    labelWidth += bmpWidth + 2*margin;
+    
     // Draw a label if one is given
     if ( params && !params->m_labelText.empty() )
     {
@@ -330,8 +335,9 @@ wxRendererGeneric::DrawHeaderButtonContents(wxWindow *win,
 
         int tw, th, td, x, y;
         dc.GetTextExtent( label, &tw, &th, &td);
+        labelWidth += tw;
         y = rect.y + wxMax(0, (rect.height - (th+td)) / 2);
-
+        
         // truncate and add an ellipsis (...) if the text is too wide.
         int targetWidth = rect.width - arrowSpace - bmpWidth - 2*margin;
         if ( tw > targetWidth )        
@@ -397,6 +403,7 @@ wxRendererGeneric::DrawHeaderButtonContents(wxWindow *win,
         }
         dc.DrawBitmap(params->m_labelBitmap, x, y, true);
     }
+    return labelWidth;
 }
 
 
index e968ace5e13694db5613b17374603f3c856a3776..86ebfa8b4a95c3791b0afafdbd55cb756efb819a 100644 (file)
@@ -43,7 +43,7 @@ class WXDLLEXPORT wxRendererGTK : public wxDelegateRendererNative
 {
 public:
     // draw the header control button (used by wxListCtrl)
-    virtual void DrawHeaderButton(wxWindow *win,
+    virtual int  DrawHeaderButton(wxWindow *win,
                                   wxDC& dc,
                                   const wxRect& rect,
                                   int flags = 0,
@@ -181,7 +181,7 @@ wxRendererGTK::GetTreeWidget()
 // list/tree controls drawing
 // ----------------------------------------------------------------------------
 
-void
+int
 wxRendererGTK::DrawHeaderButton(wxWindow *win,
                                 wxDC& dc,
                                 const wxRect& rect,
@@ -212,7 +212,7 @@ wxRendererGTK::DrawHeaderButton(wxWindow *win,
         dc.LogicalToDeviceX(rect.x) - x_diff, rect.y, rect.width, rect.height
     );
 
-    DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params);
+    return DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params);
 }
 
 // draw a ">" or "v" button
index bf271a27bb19ec97a78ceb9bd718b7192faa09a6..15d9ef20b171e992a080215259e14d5f96342ccf 100644 (file)
@@ -34,7 +34,7 @@ class WXDLLEXPORT wxRendererMac : public wxDelegateRendererNative
 {
 public:
     // draw the header control button (used by wxListCtrl)
-    virtual void DrawHeaderButton( wxWindow *win,
+    virtual int DrawHeaderButton( wxWindow *win,
         wxDC& dc,
         const wxRect& rect,
         int flags = 0,
@@ -97,7 +97,7 @@ wxRendererNative& wxRendererNative::GetDefault()
     return s_rendererMac;
 }
 
-void wxRendererMac::DrawHeaderButton( wxWindow *win,
+int wxRendererMac::DrawHeaderButton( wxWindow *win,
     wxDC& dc,
     const wxRect& rect,
     int flags,
@@ -200,7 +200,7 @@ void wxRendererMac::DrawHeaderButton( wxWindow *win,
     }
     flags &= ~wxCONTROL_SELECTED;
 
-    DrawHeaderButtonContents(win, dc, newRect, flags, sortArrow, params);
+    return DrawHeaderButtonContents(win, dc, newRect, flags, sortArrow, params);
 }
 
 
index e63c25ad8de706f76345fea4974aea83aa9b60ef..27c7cb7e6cc1571abac9047aa28b3c72b9cac423 100644 (file)
@@ -118,7 +118,7 @@ public:
 
     static wxRendererNative& Get();
 
-    virtual void DrawHeaderButton(wxWindow *win,
+    virtual int DrawHeaderButton(wxWindow *win,
                                   wxDC& dc,
                                   const wxRect& rect,
                                   int flags = 0,
@@ -290,7 +290,7 @@ wxRendererXP::DrawComboBoxDropButton(wxWindow * win,
 
 }
 
-void
+int
 wxRendererXP::DrawHeaderButton(wxWindow *win,
                                wxDC& dc,
                                const wxRect& rect,
@@ -301,8 +301,7 @@ wxRendererXP::DrawHeaderButton(wxWindow *win,
     wxUxThemeHandle hTheme(win, L"HEADER");
     if ( !hTheme )
     {
-        m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params);
-        return;
+        return m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params);
     }
 
     RECT r;
@@ -330,7 +329,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, sortArrow, params);
+    return DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params);
 }
 
 
index 85c9e57361b35e1c87cfb5653160397fd00e16a0..c7f100b84fb71d534d07118853af2c860ca440e5 100644 (file)
@@ -156,23 +156,23 @@ public:
 
      
     DocDeclStr(
-        virtual void , DrawHeaderButton(wxWindow *win,
-                                        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.)", "");
+        virtual int , DrawHeaderButton(wxWindow *win,
+                                       wxDC& dc,
+                                       const wxRect& rect,
+                                       int flags = 0,
+                                       wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
+                                       wxHeaderButtonParams* params=NULL),
+        "Draw a header control button (such as what is used by `wx.ListCtrl` in report
+mode.)  The optimal size of the label (text and icons) is returned.", "");
     
 
     DocDeclStr(
-        virtual void , DrawHeaderButtonContents(wxWindow *win,
-                                                wxDC& dc,
-                                                const wxRect& rect,
-                                                int flags = 0,
-                                                wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
-                                                wxHeaderButtonParams* params=NULL),
+        virtual int , DrawHeaderButtonContents(wxWindow *win,
+                                               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`.", "");