]> git.saurik.com Git - wxWidgets.git/commitdiff
use Ellipsize() in wxStatusBarGeneric so that the text is correctly ellipsized when...
authorFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Sun, 8 Feb 2009 13:30:40 +0000 (13:30 +0000)
committerFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Sun, 8 Feb 2009 13:30:40 +0000 (13:30 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58760 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/generic/statusbr.h
src/generic/statusbr.cpp

index 785011cbeb24a5c6af19f526d683dd50b30a617d..4b195104f06782b014c8b3e52ebcb2e2c5a9f375 100644 (file)
@@ -64,8 +64,8 @@ public:
     virtual int GetBorderX() const { return m_borderX; }
     virtual int GetBorderY() const { return m_borderY; }
 
-    ////////////////////////////////////////////////////////////////////////
-    // Implementation
+
+protected:
 
     virtual void DrawFieldText(wxDC& dc, int i);
     virtual void DrawField(wxDC& dc, int i);
@@ -88,7 +88,9 @@ public:
     // and not maximized
     bool ShowsSizeGrip() const;
 
-protected:
+    // returns the position and the size of the size grip
+    wxRect GetSizeGripRect() const;
+
     // common part of all ctors
     void Init();
 
index bd1f7f50a88c76747626995bbb8d7d94b0a388f6..a7202cf210681f174b0aa7c8d17c1358f8d6a1fd 100644 (file)
@@ -44,6 +44,9 @@
 // Default status border dimensions
 #define wxTHICK_LINE_BORDER 2
 
+// Margin between the field text and the field rect
+#define wxFIELD_TEXT_MARGIN 2
+
 
 // ----------------------------------------------------------------------------
 // wxStatusBarGeneric
@@ -194,29 +197,56 @@ bool wxStatusBarGeneric::ShowsSizeGrip() const
 
 void wxStatusBarGeneric::DrawFieldText(wxDC& dc, int i)
 {
-    int leftMargin = 2;
-
     wxRect rect;
     GetFieldRect(i, rect);
 
+    if (rect.GetWidth() <= 0)
+        return;     // happens when the status bar is shrinked in a very small area!
+
+    if (ShowsSizeGrip())
+    {
+        // don't write text over the size grip:
+        // NOTE: overloading DoGetClientSize() and GetClientAreaOrigin() wouldn't
+        //       work because the adjustment needs to be done only when drawing
+        //       the field text and not also when drawing the background, the
+        //       size grip itself, etc
+        if (GetLayoutDirection() == wxLayout_RightToLeft && i == 0)
+        {
+            const wxRect& rc = GetSizeGripRect();
+
+            rect.x += rc.GetRight();
+            rect.width -= rc.GetRight();
+        }
+        else if (GetLayoutDirection() != wxLayout_RightToLeft && i == m_panes.GetCount()-1)
+        {
+            const wxRect& rc = GetSizeGripRect();
+
+            rect.width = rc.x - rect.x;
+        }
+    }
+
+    // eventually ellipsize the text so that it fits the field width
     wxString text(GetStatusText(i));
 
-    wxCoord x = 0, y = 0;
-    dc.GetTextExtent(text, &x, &y);
+    text = wxControl::Ellipsize(
+        text, dc,
+        GetLayoutDirection() == wxLayout_RightToLeft ? wxELLIPSIZE_START : wxELLIPSIZE_END,
+        rect.GetWidth() - 2*wxFIELD_TEXT_MARGIN,
+        wxELLIPSIZE_EXPAND_TAB);
+        // Ellipsize() will do something only if necessary
 
-    int xpos = rect.x + leftMargin;
-    int ypos = (int) (((rect.height - y) / 2 ) + rect.y + 0.5);
+    // center the text in its field
+    wxSize sz = dc.GetTextExtent(text);
+    int xpos = rect.x + wxFIELD_TEXT_MARGIN;
+    int ypos = (int) (((rect.height - sz.GetHeight()) / 2) + rect.y + 0.5);
 
 #if defined( __WXGTK__ ) || defined(__WXMAC__)
     xpos++;
     ypos++;
 #endif
 
-    dc.SetClippingRegion(rect.x, rect.y, rect.width, rect.height);
-
+    // draw the text
     dc.DrawText(text, xpos, ypos);
-
-    dc.DestroyClippingRegion();
 }
 
 void wxStatusBarGeneric::DrawField(wxDC& dc, int i)
@@ -289,6 +319,9 @@ bool wxStatusBarGeneric::GetFieldRect(int n, wxRect& rect) const
     // width has changed (or when it is initially empty)
     if ( m_widthsAbs.IsEmpty() || m_lastClientWidth != width )
     {
+        // FIXME: why don't we use an OnSize(wxSizeEvent&) event handler to
+        //        update the cache? (FM)
+
         wxConstCast(this, wxStatusBarGeneric)->m_widthsAbs = CalculateAbsWidths(width);
 
         // remember last width for which we have recomputed the widths in pixels
@@ -337,6 +370,16 @@ void wxStatusBarGeneric::SetMinHeight(int height)
     }
 }
 
+wxRect wxStatusBarGeneric::GetSizeGripRect() const
+{
+    int width, height;
+    wxWindow::DoGetClientSize(&width, &height);
+
+    if (GetLayoutDirection() == wxLayout_RightToLeft)
+        return wxRect(2, 2, height-2, height-4);
+    else
+        return wxRect(width-height-2, 2, height-2, height-4);
+}
 
 // ----------------------------------------------------------------------------
 // wxStatusBarGeneric - event handlers
@@ -350,31 +393,18 @@ void wxStatusBarGeneric::OnPaint(wxPaintEvent& WXUNUSED(event) )
     // Draw grip first
     if ( ShowsSizeGrip() )
     {
-        int width, height;
-        GetClientSize(&width, &height);
-
-        if (GetLayoutDirection() == wxLayout_RightToLeft)
-        {
-            gtk_paint_resize_grip( m_widget->style,
-                               GTKGetDrawingWindow(),
-                               (GtkStateType) GTK_WIDGET_STATE (m_widget),
-                               NULL,
-                               m_widget,
-                               "statusbar",
-                               GDK_WINDOW_EDGE_SOUTH_WEST,
-                               2, 2, height-2, height-4 );
-        }
-        else
-        {
-            gtk_paint_resize_grip( m_widget->style,
-                               GTKGetDrawingWindow(),
-                               (GtkStateType) GTK_WIDGET_STATE (m_widget),
-                               NULL,
-                               m_widget,
-                               "statusbar",
-                               GDK_WINDOW_EDGE_SOUTH_EAST,
-                               width-height-2, 2, height-2, height-4 );
-        }
+        const wxRect& rc = GetSizeGripRect();
+        GdkWindowEdge edge =
+            GetLayoutDirection() == wxLayout_RightToLeft ? GDK_WINDOW_EDGE_SOUTH_WEST :
+                                                           GDK_WINDOW_EDGE_SOUTH_EAST;
+        gtk_paint_resize_grip( m_widget->style,
+                            GTKGetDrawingWindow(),
+                            (GtkStateType) GTK_WIDGET_STATE (m_widget),
+                            NULL,
+                            m_widget,
+                            "statusbar",
+                            edge,
+                            rc.x, rc.y, rc.width, rc.height );
     }
 #endif // __WXGTK20__