1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/generic/statusbr.cpp 
   3 // Purpose:     wxStatusBarGeneric class implementation 
   4 // Author:      Julian Smart 
   8 // Copyright:   (c) Julian Smart 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  21 #include "wx/statusbr.h" 
  24     #include "wx/settings.h" 
  25     #include "wx/dcclient.h" 
  30     #include "wx/gtk/win_gtk.h" 
  33 // we only have to do it here when we use wxStatusBarGeneric in addition to the 
  34 // standard wxStatusBar class, if wxStatusBarGeneric is the same as 
  35 // wxStatusBar, then the corresponding IMPLEMENT_DYNAMIC_CLASS is already in 
  37 #if defined(__WXMAC__) || \ 
  38     (defined(wxUSE_NATIVE_STATUSBAR) && wxUSE_NATIVE_STATUSBAR) 
  39     #include "wx/generic/statusbr.h" 
  41     IMPLEMENT_DYNAMIC_CLASS(wxStatusBarGeneric
, wxWindow
) 
  42 #endif // wxUSE_NATIVE_STATUSBAR 
  44 BEGIN_EVENT_TABLE(wxStatusBarGeneric
, wxWindow
) 
  45     EVT_PAINT(wxStatusBarGeneric::OnPaint
) 
  46     EVT_LEFT_DOWN(wxStatusBarGeneric::OnLeftDown
) 
  47     EVT_RIGHT_DOWN(wxStatusBarGeneric::OnRightDown
) 
  48     EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged
) 
  51 // Default status border dimensions 
  52 #define         wxTHICK_LINE_BORDER 2 
  54 void wxStatusBarGeneric::Init() 
  56     m_borderX 
= wxTHICK_LINE_BORDER
; 
  57     m_borderY 
= wxTHICK_LINE_BORDER
; 
  60 wxStatusBarGeneric::~wxStatusBarGeneric() 
  64 bool wxStatusBarGeneric::Create(wxWindow 
*parent
, 
  69     style 
|= wxTAB_TRAVERSAL 
| wxFULL_REPAINT_ON_RESIZE
; 
  70     if ( !wxWindow::Create(parent
, id
, 
  71                            wxDefaultPosition
, wxDefaultSize
, 
  75     // The status bar should have a themed background 
  76     SetThemeEnabled( true ); 
  81     SetFont(*wxSMALL_FONT
); 
  84     // Set the height according to the font and the border size 
  86     dc
.SetFont(GetFont()); 
  89     dc
.GetTextExtent(_T("X"), NULL
, &y 
); 
  91     int height 
= (int)( (11*y
)/10 + 2*GetBorderY()); 
  93     SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, height
); 
 101 wxSize 
wxStatusBarGeneric::DoGetBestSize() const 
 105     // best width is the width of the parent 
 106     GetParent()->GetClientSize(&width
, NULL
); 
 108     // best height is as calculated above in Create 
 109     wxClientDC 
dc((wxWindow
*)this); 
 110     dc
.SetFont(GetFont()); 
 112     dc
.GetTextExtent(_T("X"), NULL
, &y 
); 
 113     height 
= (int)( (11*y
)/10 + 2*GetBorderY()); 
 115     return wxSize(width
, height
); 
 118 void wxStatusBarGeneric::SetFieldsCount(int number
, const int *widths
) 
 120     wxASSERT_MSG( number 
>= 0, _T("negative number of fields in wxStatusBar?") ); 
 123     for(i 
= m_nFields
; i 
< number
; ++i
) 
 124         m_statusStrings
.Add( wxEmptyString 
); 
 126     for (i 
= m_nFields 
- 1; i 
>= number
; --i
) 
 127         m_statusStrings
.RemoveAt(i
); 
 129     // forget the old cached pixel widths 
 132     wxStatusBarBase::SetFieldsCount(number
, widths
); 
 134     wxASSERT_MSG( m_nFields 
== (int)m_statusStrings
.GetCount(), 
 135                   _T("This really should never happen, can we do away with m_nFields here?") ); 
 138 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
) 
 140     wxCHECK_RET( (number 
>= 0) && (number 
< m_nFields
), 
 141                  _T("invalid status bar field index") ); 
 143     wxString oldText 
= m_statusStrings
[number
]; 
 146         m_statusStrings
[number
] = text
; 
 149         GetFieldRect(number
, rect
); 
 151         Refresh(true, &rect
); 
 153         // it's common to show some text in the status bar before starting a 
 154         // relatively lengthy operation, ensure that the text is shown to the 
 155         // user immediately and not after the lengthy operation end 
 160 wxString 
wxStatusBarGeneric::GetStatusText(int n
) const 
 162     wxCHECK_MSG( (n 
>= 0) && (n 
< m_nFields
), wxEmptyString
, 
 163                  _T("invalid status bar field index") ); 
 165     return m_statusStrings
[n
]; 
 168 void wxStatusBarGeneric::SetStatusWidths(int n
, const int widths_field
[]) 
 170     // only set status widths, when n == number of statuswindows 
 171     wxCHECK_RET( n 
== m_nFields
, _T("status bar field count mismatch") ); 
 173     // delete the old widths in any case - this function may be used to reset 
 174     // the widths to the default (all equal) 
 175     // MBN: this is incompatible with at least wxMSW and wxMAC and not 
 176     //      documented, but let's keep it for now 
 179     // forget the old cached pixel widths 
 184         // not an error, see the comment above 
 189     wxStatusBarBase::SetStatusWidths(n
, widths_field
); 
 192 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) ) 
 198     if (HasFlag( wxST_SIZEGRIP 
)) 
 201         GetClientSize(&width
, &height
); 
 203         gtk_paint_resize_grip( m_widget
->style
, 
 204                                GTK_PIZZA(m_wxwindow
)->bin_window
, 
 205                                (GtkStateType
) GTK_WIDGET_STATE (m_widget
), 
 209                                GDK_WINDOW_EDGE_SOUTH_EAST
, 
 210                                width
-height
-2, 1, height
-2, height
-3 ); 
 216         dc
.SetFont(GetFont()); 
 218     dc
.SetBackgroundMode(wxTRANSPARENT
); 
 223     vColor 
= wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
); 
 224     ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel()); 
 227     for (int i 
= 0; i 
< m_nFields
; i 
++) 
 231 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
) 
 236     GetFieldRect(i
, rect
); 
 238     wxString 
text(GetStatusText(i
)); 
 242     dc
.GetTextExtent(text
, &x
, &y
); 
 244     int xpos 
= rect
.x 
+ leftMargin
; 
 245     int ypos 
= (int) (((rect
.height 
- y
) / 2 ) + rect
.y 
+ 0.5) ; 
 247 #if defined( __WXGTK__ ) || defined(__WXMAC__) 
 252     dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
); 
 254     dc
.DrawText(text
, xpos
, ypos
); 
 256     dc
.DestroyClippingRegion(); 
 259 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
) 
 262     GetFieldRect(i
, rect
); 
 264     int style 
= wxSB_NORMAL
; 
 266         style 
= m_statusStyles
[i
]; 
 268     if (style 
!= wxSB_FLAT
) 
 272         // Have grey background, plus 3-d border - 
 273         // One black rectangle. 
 274         // Inside this, left and top sides - dark grey. Bottom and right - 
 276         // Reverse it for wxSB_RAISED 
 278         dc
.SetPen((style 
== wxSB_RAISED
) ? m_mediumShadowPen 
: m_hilightPen
); 
 282         // Right and bottom lines 
 283         dc
.DrawLine(rect
.x 
+ rect
.width
, rect
.y
, 
 284                     rect
.x 
+ rect
.width
, rect
.y 
+ rect
.height
); 
 285         dc
.DrawLine(rect
.x 
+ rect
.width
, rect
.y 
+ rect
.height
, 
 286                     rect
.x
, rect
.y 
+ rect
.height
); 
 288         dc
.SetPen((style 
== wxSB_RAISED
) ? m_hilightPen 
: m_mediumShadowPen
); 
 290         // Left and top lines 
 291         dc
.DrawLine(rect
.x
, rect
.y 
+ rect
.height
, 
 293         dc
.DrawLine(rect
.x
, rect
.y
, 
 294             rect
.x 
+ rect
.width
, rect
.y
); 
 297         dc
.DrawLine(rect
.x 
+ rect
.width
, rect
.height 
+ 2, 
 298                     rect
.x
, rect
.height 
+ 2); 
 299         dc
.DrawLine(rect
.x 
+ rect
.width
, rect
.y
, 
 300                     rect
.x 
+ rect
.width
, rect
.y 
+ rect
.height
); 
 302         dc
.SetPen((style 
== wxSB_RAISED
) ? m_hilightPen 
: m_mediumShadowPen
); 
 303         dc
.DrawLine(rect
.x
, rect
.y
, 
 304                     rect
.x 
+ rect
.width
, rect
.y
); 
 305         dc
.DrawLine(rect
.x
, rect
.y 
+ rect
.height
, 
 311     DrawFieldText(dc
, i
); 
 314   // Get the position and size of the field's internal bounding rectangle 
 315 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const 
 317     wxCHECK_MSG( (n 
>= 0) && (n 
< m_nFields
), false, 
 318                  _T("invalid status bar field index") ); 
 320     // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ) 
 323     GetSize(&width
, &height
); 
 325     GetClientSize(&width
, &height
); 
 328     // we cache m_widthsAbs between calls and recompute it if client 
 329     // width has changed (or when it is initially empty) 
 330     if ( m_widthsAbs
.IsEmpty() || (m_lastClientWidth 
!= width
) ) 
 332         wxConstCast(this, wxStatusBarGeneric
)-> 
 333             m_widthsAbs 
= CalculateAbsWidths(width
); 
 334         // remember last width for which we have recomputed the widths in pixels 
 335         wxConstCast(this, wxStatusBarGeneric
)-> 
 336             m_lastClientWidth 
= width
; 
 340     for ( int i 
= 0; i 
< n
; i
++ ) 
 342         rect
.x 
+= m_widthsAbs
[i
]; 
 348     rect
.width 
= m_widthsAbs
[n
] - 2*m_borderX
; 
 349     rect
.height 
= height 
- 2*m_borderY
; 
 354 // Initialize colours 
 355 void wxStatusBarGeneric::InitColours() 
 358 #if defined(__WXMSW__) || defined(__WXMAC__) 
 359     wxColour 
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
)); 
 360     m_mediumShadowPen 
= wxPen(mediumShadowColour
, 1, wxSOLID
); 
 362     wxColour 
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
)); 
 363     m_hilightPen 
= wxPen(hilightColour
, 1, wxSOLID
); 
 364 #elif defined(__WXPM__) 
 365     m_mediumShadowPen 
= wxPen(wxColour(127, 127, 127), 1, wxSOLID
); 
 366     m_hilightPen 
= *wxWHITE_PEN
; 
 368     SetBackgroundColour(*wxLIGHT_GREY
); 
 369     SetForegroundColour(*wxBLACK
); 
 371     m_mediumShadowPen 
= *wxGREY_PEN
; 
 372     m_hilightPen 
= *wxWHITE_PEN
; 
 376 // Responds to colour changes, and passes event on to children. 
 377 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
) 
 381     // Propagate the event to the non-top-level children 
 382     wxWindow::OnSysColourChanged(event
); 
 385 void wxStatusBarGeneric::SetMinHeight(int height
) 
 387     // check that this min height is not less than minimal height for the 
 391     dc
.GetTextExtent( wxT("X"), NULL
, &y 
); 
 393     if ( height 
> (11*y
)/10 ) 
 395         SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, height 
+ 2*m_borderY
); 
 399 void wxStatusBarGeneric::OnLeftDown(wxMouseEvent
& event
) 
 403     GetClientSize(&width
, &height
); 
 405     if (HasFlag( wxST_SIZEGRIP 
) && (event
.GetX() > width
-height
)) 
 407         GtkWidget 
*ancestor 
= gtk_widget_get_toplevel( m_widget 
); 
 409         if (!GTK_IS_WINDOW (ancestor
)) 
 412         GdkWindow 
*source 
= GTK_PIZZA(m_wxwindow
)->bin_window
; 
 416         gdk_window_get_origin( source
, &org_x
, &org_y 
); 
 418         gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
), 
 419                                   GDK_WINDOW_EDGE_SOUTH_EAST
, 
 421                                   org_x 
+ event
.GetX(), 
 422                                   org_y 
+ event
.GetY(), 
 434 void wxStatusBarGeneric::OnRightDown(wxMouseEvent
& event
) 
 438     GetClientSize(&width
, &height
); 
 440     if (HasFlag( wxST_SIZEGRIP 
) && (event
.GetX() > width
-height
)) 
 442         GtkWidget 
*ancestor 
= gtk_widget_get_toplevel( m_widget 
); 
 444         if (!GTK_IS_WINDOW (ancestor
)) 
 447         GdkWindow 
*source 
= GTK_PIZZA(m_wxwindow
)->bin_window
; 
 451         gdk_window_get_origin( source
, &org_x
, &org_y 
); 
 453         gtk_window_begin_move_drag (GTK_WINDOW (ancestor
), 
 455                                 org_x 
+ event
.GetX(), 
 456                                 org_y 
+ event
.GetY(), 
 468 #endif // wxUSE_STATUSBAR