]> git.saurik.com Git - wxWidgets.git/commitdiff
refactored common parts of DrawItem() in the base class; implemented GetTextTotal...
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 20 Sep 2006 14:51:14 +0000 (14:51 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 20 Sep 2006 14:51:14 +0000 (14:51 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41318 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/univ/stdrend.h
src/univ/stdrend.cpp
src/univ/themes/gtk.cpp
src/univ/themes/win32.cpp

index 91c57a3961752a88f843e18eda240199ef7464d3..5248bfb5f9390baaf83f779a1d17dda4cf400397 100644 (file)
@@ -83,6 +83,11 @@ public:
                           const wxString& label,
                           const wxRect& rect,
                           int flags = 0);
+    virtual void DrawCheckItem(wxDC& dc,
+                               const wxString& label,
+                               const wxBitmap& bitmap,
+                               const wxRect& rect,
+                               int flags = 0);
 
     virtual void DrawCheckButton(wxDC& dc,
                                  const wxString& label,
@@ -108,6 +113,12 @@ public:
                               int flags = 0);
 
     virtual void DrawLineWrapMark(wxDC& dc, const wxRect& rect);
+
+    virtual wxRect GetTextTotalArea(const wxTextCtrl *text,
+                                    const wxRect& rect) const;
+    virtual wxRect GetTextClientArea(const wxTextCtrl *text,
+                                     const wxRect& rect,
+                                     wxCoord *extraSpaceBeyond) const;
 #endif // wxUSE_TEXTCTRL
 
     virtual wxRect GetBorderDimensions(wxBorder border) const;
@@ -135,7 +146,8 @@ protected:
     {
         IndicatorType_Check,
         IndicatorType_Radio,
-        IndicatorType_Menu,
+        IndicatorType_MaxCtrl,
+        IndicatorType_Menu = IndicatorType_MaxCtrl,
         IndicatorType_Max
     };
 
@@ -184,6 +196,7 @@ protected:
     virtual void DrawRaisedBorder(wxDC& dc, wxRect *rect);
     virtual void DrawSunkenBorder(wxDC& dc, wxRect *rect);
     virtual void DrawAntiSunkenBorder(wxDC& dc, wxRect *rect);
+    virtual void DrawFrameBorder(wxDC& dc, wxRect *rect);
 
 
     // draw the frame with non-empty label inside the given rectText
@@ -201,6 +214,13 @@ protected:
                                const wxRect& rectLabel);
 
 
+    // draw the bitmap for a check item (which is by default the same as check
+    // box one but may be different)
+    virtual void DrawCheckItemBitmap(wxDC& dc,
+                                     const wxBitmap& bitmap,
+                                     const wxRect& rect,
+                                     int flags);
+
     // common routine for drawing check and radio buttons
     void DrawCheckOrRadioButton(wxDC& dc,
                                 const wxString& label,
@@ -214,6 +234,10 @@ protected:
     virtual wxBitmap GetRadioBitmap(int flags) = 0;
     virtual wxBitmap GetCheckBitmap(int flags) = 0;
 
+#if wxUSE_TEXTCTRL
+    // return the width of the border around the text area in the text control
+    virtual int GetTextBorderWidth(const wxTextCtrl *text) const;
+#endif // wxUSE_TEXTCTRL
 
     // return the starting and ending positions, in pixels, of the thumb of a
     // scrollbar with the given logical position, thumb size and range and the
index fa8b77dfe03ee1a48b755f15502d13fb1a6970fb..771b3a9052b42d9a1e1d4858506ef9602583fa55 100644 (file)
@@ -304,6 +304,12 @@ void wxStdRenderer::DrawAntiSunkenBorder(wxDC& dc, wxRect *rect)
     DrawShadedRect(dc, rect, m_penHighlight, m_penDarkGrey);
 }
 
+void wxStdRenderer::DrawFrameBorder(wxDC& dc, wxRect *rect)
+{
+    DrawShadedRect(dc, rect, m_penDarkGrey, m_penHighlight);
+    DrawShadedRect(dc, rect, m_penHighlight, m_penDarkGrey);
+}
+
 void wxStdRenderer::DrawBorder(wxDC& dc,
                                wxBorder border,
                                const wxRect& rectTotal,
@@ -493,9 +499,7 @@ void wxStdRenderer::DrawFrame(wxDC& dc,
     }
     else // no label
     {
-        // just draw the complete frame
-        DrawShadedRect(dc, &rectFrame, m_penDarkGrey, m_penHighlight);
-        DrawShadedRect(dc, &rectFrame, m_penHighlight, m_penDarkGrey);
+        DrawFrameBorder(dc, &rectFrame);
     }
 }
 
@@ -527,6 +531,31 @@ void wxStdRenderer::DrawItem(wxDC& dc,
     }
 }
 
+void wxStdRenderer::DrawCheckItemBitmap(wxDC& dc,
+                                        const wxBitmap& bitmap,
+                                        const wxRect& rect,
+                                        int flags)
+{
+    DrawCheckButton(dc, wxEmptyString, bitmap, rect, flags);
+}
+
+void wxStdRenderer::DrawCheckItem(wxDC& dc,
+                                  const wxString& label,
+                                  const wxBitmap& bitmap,
+                                  const wxRect& rect,
+                                  int flags)
+{
+    wxRect rectBitmap = rect;
+    rectBitmap.width = GetCheckBitmapSize().x;
+    DrawCheckItemBitmap(dc, bitmap, rectBitmap, flags);
+
+    wxRect rectLabel = rect;
+    wxCoord shift = rectBitmap.width + 2*GetCheckItemMargin();
+    rectLabel.x += shift;
+    rectLabel.width -= shift;
+    DrawItem(dc, label, rectLabel, flags);
+}
+
 // ----------------------------------------------------------------------------
 // check and radio bitmaps
 // ----------------------------------------------------------------------------
@@ -681,6 +710,32 @@ void wxStdRenderer::DrawLineWrapMark(wxDC& WXUNUSED(dc),
     // nothing by default
 }
 
+int wxStdRenderer::GetTextBorderWidth(const wxTextCtrl * WXUNUSED(text)) const
+{
+    return 1;
+}
+
+wxRect
+wxStdRenderer::GetTextTotalArea(const wxTextCtrl *text, const wxRect& rect) const
+{
+    wxRect rectTotal = rect;
+    rectTotal.Inflate(GetTextBorderWidth(text));
+    return rectTotal;
+}
+
+wxRect wxStdRenderer::GetTextClientArea(const wxTextCtrl *text,
+                                        const wxRect& rect,
+                                        wxCoord *extraSpaceBeyond) const
+{
+    wxRect rectText = rect;
+    rectText.Deflate(GetTextBorderWidth(text));
+
+    if ( extraSpaceBeyond )
+        *extraSpaceBeyond = 0;
+
+    return rectText;
+}
+
 #endif // wxUSE_TEXTCTRL
 
 // ----------------------------------------------------------------------------
index e44cdbb599df573dd038159bb181a11e86f33313..382823ee0403853b2e15849611b3532ab64a901f 100644 (file)
@@ -117,11 +117,6 @@ public:
                                     int flags = 0);
     virtual void DrawScrollCorner(wxDC& dc,
                                   const wxRect& rect);
-    virtual void DrawCheckItem(wxDC& dc,
-                               const wxString& label,
-                               const wxBitmap& bitmap,
-                               const wxRect& rect,
-                               int flags = 0);
 
 #if wxUSE_TOOLBAR
     virtual void DrawToolBarButton(wxDC& dc,
@@ -264,8 +259,6 @@ public:
         { return wxSize(6, 6); }
 
 #if wxUSE_TEXTCTRL
-    virtual wxRect GetTextTotalArea(const wxTextCtrl *text,
-                                    const wxRect& rect) const;
     virtual wxRect GetTextClientArea(const wxTextCtrl *text,
                                      const wxRect& rect,
                                      wxCoord *extraSpaceBeyond) const;
@@ -306,6 +299,7 @@ public:
     void DrawUndeterminedBitmap(wxDC& dc, const wxRect& rect, bool isPressed);
 
 protected:
+    // overridden wxStdRenderer methods
     virtual void DrawSunkenBorder(wxDC& dc, wxRect *rect);
 
     virtual void DrawFrameWithLabel(wxDC& dc,
@@ -316,6 +310,11 @@ protected:
                                     int alignment,
                                     int indexAccel);
 
+    virtual void DrawCheckItemBitmap(wxDC& dc,
+                                     const wxBitmap& bitmap,
+                                     const wxRect& rect,
+                                     int flags);
+
     // get the colour to use for background
     wxColour GetBackgroundColour(int flags) const
     {
@@ -396,15 +395,6 @@ protected:
     // draw the radio button bitmap for the given state
     void DrawRadioBitmap(wxDC& dc, const wxRect& rect, int flags);
 
-    // draw check/radio - the bitmap must be a valid one by now
-    void DoDrawCheckOrRadioBitmap(wxDC& dc,
-                                  const wxString& label,
-                                  const wxBitmap& bitmap,
-                                  const wxRect& rectTotal,
-                                  int flags,
-                                  wxAlignment align,
-                                  int indexAccel);
-
     // common part of DrawMenuItem() and DrawMenuBarItem()
     void DoDrawMenuItem(wxDC& dc,
                         const wxRect& rect,
@@ -995,33 +985,18 @@ void wxGTKRenderer::DrawFrameWithLabel(wxDC& dc,
 }
 
 // ----------------------------------------------------------------------------
-// label
+// check/radion buttons
 // ----------------------------------------------------------------------------
 
-void wxGTKRenderer::DrawCheckItem(wxDC& dc,
-                                  const wxString& label,
-                                  const wxBitmap& bitmap,
-                                  const wxRect& rect,
-                                  int flags)
+void wxGTKRenderer::DrawCheckItemBitmap(wxDC& dc,
+                                        const wxBitmap& bitmap,
+                                        const wxRect& rect,
+                                        int flags)
 {
-    wxRect rectBitmap = rect;
-    rectBitmap.x -= 1;
-    rectBitmap.width = GetCheckBitmapSize().x;
-
     // never draw the focus rect around the check indicators here
-    DrawCheckButton(dc, wxEmptyString, bitmap, rectBitmap, flags & ~wxCONTROL_FOCUSED);
-
-    wxRect rectLabel = rect;
-    wxCoord shift = rectBitmap.width + 2*GetCheckItemMargin();
-    rectLabel.x += shift;
-    rectLabel.width -= shift;
-    DrawItem(dc, label, rectLabel, flags);
+    DrawCheckButton(dc, wxEmptyString, bitmap, rect, flags & ~wxCONTROL_FOCUSED);
 }
 
-// ----------------------------------------------------------------------------
-// check/radion buttons
-// ----------------------------------------------------------------------------
-
 void wxGTKRenderer::DrawUndeterminedBitmap(wxDC& dc,
                                            const wxRect& rectTotal,
                                            bool isPressed)
@@ -1306,20 +1281,12 @@ void wxGTKRenderer::DrawToolBarButton(wxDC& dc,
 
 #if wxUSE_TEXTCTRL
 
-wxRect wxGTKRenderer::GetTextTotalArea(const wxTextCtrl * WXUNUSED(text),
-                                       const wxRect& rect) const
-{
-    wxRect rectTotal = rect;
-    rectTotal.Inflate(2*BORDER_THICKNESS);
-    return rectTotal;
-}
-
 wxRect wxGTKRenderer::GetTextClientArea(const wxTextCtrl *text,
                                         const wxRect& rect,
                                         wxCoord *extraSpaceBeyond) const
 {
-    wxRect rectText = rect;
-    rectText.Deflate(2*BORDER_THICKNESS);
+    wxRect
+      rectText = wxStdRenderer::GetTextClientArea(text, rect, extraSpaceBeyond);
 
     if ( text->WrapLines() )
     {
@@ -1335,8 +1302,6 @@ wxRect wxGTKRenderer::GetTextClientArea(const wxTextCtrl *text,
     return rectText;
 }
 
-#endif // wxUSE_TEXTCTRL
-
 void wxGTKRenderer::DrawLineWrapMark(wxDC& dc, const wxRect& rect)
 {
     wxBitmap bmpLineWrap = GetLineWrapBitmap();
@@ -1362,6 +1327,8 @@ void wxGTKRenderer::DrawLineWrapMark(wxDC& dc, const wxRect& rect)
     }
 }
 
+#endif // wxUSE_TEXTCTRL
+
 // ----------------------------------------------------------------------------
 // notebook
 // ----------------------------------------------------------------------------
index 083ae06c36582120da1e2884d508fa4787cdb2cb..99919f87d1aa7d01dd79f3743316cca2155df77d 100644 (file)
@@ -170,11 +170,6 @@ public:
                                     int flags = 0);
     virtual void DrawScrollCorner(wxDC& dc,
                                   const wxRect& rect);
-    virtual void DrawCheckItem(wxDC& dc,
-                               const wxString& label,
-                               const wxBitmap& bitmap,
-                               const wxRect& rect,
-                               int flags = 0);
 
 #if wxUSE_TOOLBAR
     virtual void DrawToolBarButton(wxDC& dc,
@@ -342,6 +337,7 @@ public:
 #endif // wxUSE_STATUSBAR
 
 protected:
+    // overridden wxStdRenderer methods
     virtual void DrawFrameWithLabel(wxDC& dc,
                                     const wxString& label,
                                     const wxRect& rectFrame,
@@ -350,6 +346,11 @@ protected:
                                     int alignment,
                                     int indexAccel);
 
+    virtual void DrawCheckItemBitmap(wxDC& dc,
+                                     const wxBitmap& bitmap,
+                                     const wxRect& rect,
+                                     int flags);
+
 
     // draw the border used for scrollbar arrows
     void DrawArrowBorder(wxDC& dc, wxRect *rect, bool isPressed = false);
@@ -363,16 +364,6 @@ protected:
                          wxArrowDirection arrowDir,
                          wxArrowStyle arrowStyle);
 
-    // DrawCheckButton helper
-    void DrawCheckOrRadioButton(wxDC& dc,
-                                const wxString& label,
-                                const wxBitmap& bitmap,
-                                const wxRect& rect,
-                                int flags,
-                                wxAlignment align,
-                                int indexAccel,
-                                wxCoord focusOffsetY);
-
     // draw a normal or transposed line (useful for using the same code fo both
     // horizontal and vertical widgets)
     void DrawLine(wxDC& dc,
@@ -388,9 +379,9 @@ protected:
 
     // get the standard check/radio button bitmap
     wxBitmap GetIndicator(IndicatorType indType, int flags);
-    wxBitmap GetCheckBitmap(int flags)
+    virtual wxBitmap GetCheckBitmap(int flags)
         { return GetIndicator(IndicatorType_Check, flags); }
-    wxBitmap GetRadioBitmap(int flags)
+    virtual wxBitmap GetRadioBitmap(int flags)
         { return GetIndicator(IndicatorType_Radio, flags); }
 
 private:
@@ -399,7 +390,7 @@ private:
 
     wxFont m_titlebarFont;
 
-    // the checked and unchecked bitmaps for DrawCheckItem()
+    // the checked and unchecked bitmaps for DrawCheckItemBitmap()
     wxBitmap m_bmpCheckBitmaps[IndicatorStatus_Max];
 
     // the bitmaps returned by GetIndicator()
@@ -1715,11 +1706,10 @@ void wxWin32Renderer::DrawButtonBorder(wxDC& dc,
 // (check)listbox items
 // ----------------------------------------------------------------------------
 
-void wxWin32Renderer::DrawCheckItem(wxDC& dc,
-                                    const wxString& label,
-                                    const wxBitmap& bitmap,
-                                    const wxRect& rect,
-                                    int flags)
+void wxWin32Renderer::DrawCheckItemBitmap(wxDC& dc,
+                                          const wxBitmap& bitmap,
+                                          const wxRect& rect,
+                                          int flags)
 {
     wxBitmap bmp;
     if ( bitmap.Ok() )
@@ -1742,13 +1732,6 @@ void wxWin32Renderer::DrawCheckItem(wxDC& dc,
 
     dc.DrawBitmap(bmp, rect.x, rect.y + (rect.height - bmp.GetHeight()) / 2 - 1,
                   true /* use mask */);
-
-    wxRect rectLabel = rect;
-    int bmpWidth = bmp.GetWidth();
-    rectLabel.x += bmpWidth;
-    rectLabel.width -= bmpWidth;
-
-    DrawItem(dc, label, rectLabel, flags);
 }
 
 // ----------------------------------------------------------------------------
@@ -1776,6 +1759,10 @@ wxBitmap wxWin32Renderer::GetIndicator(IndicatorType indType, int flags)
     return bmp;
 }
 
+// ----------------------------------------------------------------------------
+// toolbar stuff
+// ----------------------------------------------------------------------------
+
 #if wxUSE_TOOLBAR
 void wxWin32Renderer::DrawToolBarButton(wxDC& dc,
                                         const wxString& label,
@@ -3564,28 +3551,20 @@ wxBitmap wxWin32ArtProvider::CreateBitmap(const wxArtID& id,
 // text control geometry
 // ----------------------------------------------------------------------------
 
-static inline int GetTextBorderWidth()
-{
-    return 1;
-}
-
 wxRect
-wxWin32Renderer::GetTextTotalArea(const wxTextCtrl * WXUNUSED(text),
+wxWin32Renderer::GetTextTotalArea(const wxTextCtrl *text,
                                   const wxRect& rect) const
 {
-    wxRect rectTotal = rect;
+    wxRect rectTotal = wxStdRenderer::GetTextTotalArea(text, rect);
 
-    wxCoord widthBorder = GetTextBorderWidth();
-    rectTotal.Inflate(widthBorder);
-
-    // this is what Windows does
+    // this is strange but it's what Windows does
     rectTotal.height++;
 
     return rectTotal;
 }
 
 wxRect
-wxWin32Renderer::GetTextClientArea(const wxTextCtrl * WXUNUSED(text),
+wxWin32Renderer::GetTextClientArea(const wxTextCtrl *text,
                                    const wxRect& rect,
                                    wxCoord *extraSpaceBeyond) const
 {
@@ -3595,13 +3574,7 @@ wxWin32Renderer::GetTextClientArea(const wxTextCtrl * WXUNUSED(text),
     if ( rectText.height > 0 )
         rectText.height--;
 
-    wxCoord widthBorder = GetTextBorderWidth();
-    rectText.Inflate(-widthBorder);
-
-    if ( extraSpaceBeyond )
-        *extraSpaceBeyond = 0;
-
-    return rectText;
+    return wxStdRenderer::GetTextClientArea(text, rect, extraSpaceBeyond);
 }
 
 #endif // wxUSE_TEXTCTRL