use Ellipsize() in wxStatusBarGeneric so that the text is correctly ellipsized when exceeding field width; avoid that text overlaps the size grip

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58760 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Francesco Montorsi
2009-02-08 13:30:40 +00:00
parent a78618b062
commit 78612fa68f
2 changed files with 70 additions and 38 deletions

View File

@@ -64,8 +64,8 @@ public:
virtual int GetBorderX() const { return m_borderX; } virtual int GetBorderX() const { return m_borderX; }
virtual int GetBorderY() const { return m_borderY; } virtual int GetBorderY() const { return m_borderY; }
////////////////////////////////////////////////////////////////////////
// Implementation protected:
virtual void DrawFieldText(wxDC& dc, int i); virtual void DrawFieldText(wxDC& dc, int i);
virtual void DrawField(wxDC& dc, int i); virtual void DrawField(wxDC& dc, int i);
@@ -88,7 +88,9 @@ public:
// and not maximized // and not maximized
bool ShowsSizeGrip() const; bool ShowsSizeGrip() const;
protected: // returns the position and the size of the size grip
wxRect GetSizeGripRect() const;
// common part of all ctors // common part of all ctors
void Init(); void Init();

View File

@@ -44,6 +44,9 @@
// Default status border dimensions // Default status border dimensions
#define wxTHICK_LINE_BORDER 2 #define wxTHICK_LINE_BORDER 2
// Margin between the field text and the field rect
#define wxFIELD_TEXT_MARGIN 2
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxStatusBarGeneric // wxStatusBarGeneric
@@ -194,29 +197,56 @@ bool wxStatusBarGeneric::ShowsSizeGrip() const
void wxStatusBarGeneric::DrawFieldText(wxDC& dc, int i) void wxStatusBarGeneric::DrawFieldText(wxDC& dc, int i)
{ {
int leftMargin = 2;
wxRect rect; wxRect rect;
GetFieldRect(i, 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)); wxString text(GetStatusText(i));
wxCoord x = 0, y = 0; text = wxControl::Ellipsize(
dc.GetTextExtent(text, &x, &y); 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; // center the text in its field
int ypos = (int) (((rect.height - y) / 2 ) + rect.y + 0.5); 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__) #if defined( __WXGTK__ ) || defined(__WXMAC__)
xpos++; xpos++;
ypos++; ypos++;
#endif #endif
dc.SetClippingRegion(rect.x, rect.y, rect.width, rect.height); // draw the text
dc.DrawText(text, xpos, ypos); dc.DrawText(text, xpos, ypos);
dc.DestroyClippingRegion();
} }
void wxStatusBarGeneric::DrawField(wxDC& dc, int i) 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) // width has changed (or when it is initially empty)
if ( m_widthsAbs.IsEmpty() || m_lastClientWidth != width ) 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); wxConstCast(this, wxStatusBarGeneric)->m_widthsAbs = CalculateAbsWidths(width);
// remember last width for which we have recomputed the widths in pixels // 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 // wxStatusBarGeneric - event handlers
@@ -350,31 +393,18 @@ void wxStatusBarGeneric::OnPaint(wxPaintEvent& WXUNUSED(event) )
// Draw grip first // Draw grip first
if ( ShowsSizeGrip() ) if ( ShowsSizeGrip() )
{ {
int width, height; const wxRect& rc = GetSizeGripRect();
GetClientSize(&width, &height); GdkWindowEdge edge =
GetLayoutDirection() == wxLayout_RightToLeft ? GDK_WINDOW_EDGE_SOUTH_WEST :
if (GetLayoutDirection() == wxLayout_RightToLeft) GDK_WINDOW_EDGE_SOUTH_EAST;
{
gtk_paint_resize_grip( m_widget->style, gtk_paint_resize_grip( m_widget->style,
GTKGetDrawingWindow(), GTKGetDrawingWindow(),
(GtkStateType) GTK_WIDGET_STATE (m_widget), (GtkStateType) GTK_WIDGET_STATE (m_widget),
NULL, NULL,
m_widget, m_widget,
"statusbar", "statusbar",
GDK_WINDOW_EDGE_SOUTH_WEST, edge,
2, 2, height-2, height-4 ); rc.x, rc.y, rc.width, rc.height );
}
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 );
}
} }
#endif // __WXGTK20__ #endif // __WXGTK20__