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"
32 // we only have to do it here when we use wxStatusBarGeneric in addition to the
33 // standard wxStatusBar class, if wxStatusBarGeneric is the same as
34 // wxStatusBar, then the corresponding IMPLEMENT_DYNAMIC_CLASS is already in
36 #if defined(__WXMAC__) || \
37 (defined(wxUSE_NATIVE_STATUSBAR) && wxUSE_NATIVE_STATUSBAR)
38 #include "wx/generic/statusbr.h"
40 IMPLEMENT_DYNAMIC_CLASS(wxStatusBarGeneric
, wxWindow
)
41 #endif // wxUSE_NATIVE_STATUSBAR
43 BEGIN_EVENT_TABLE(wxStatusBarGeneric
, wxWindow
)
44 EVT_PAINT(wxStatusBarGeneric::OnPaint
)
45 EVT_LEFT_DOWN(wxStatusBarGeneric::OnLeftDown
)
46 EVT_RIGHT_DOWN(wxStatusBarGeneric::OnRightDown
)
47 EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged
)
50 // Default status border dimensions
51 #define wxTHICK_LINE_BORDER 2
53 void wxStatusBarGeneric::Init()
55 m_borderX
= wxTHICK_LINE_BORDER
;
56 m_borderY
= wxTHICK_LINE_BORDER
;
59 wxStatusBarGeneric::~wxStatusBarGeneric()
63 bool wxStatusBarGeneric::Create(wxWindow
*parent
,
68 style
|= wxTAB_TRAVERSAL
| wxFULL_REPAINT_ON_RESIZE
;
69 if ( !wxWindow::Create(parent
, id
,
70 wxDefaultPosition
, wxDefaultSize
,
74 // The status bar should have a themed background
75 SetThemeEnabled( true );
80 SetFont(*wxSMALL_FONT
);
85 // Set the height according to the font and the border size
87 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 bool wxStatusBarGeneric::ShowsSizeGrip() const
194 if ( !HasFlag(wxST_SIZEGRIP
) )
197 wxTopLevelWindow
* const
198 tlw
= wxDynamicCast(wxGetTopLevelParent(GetParent()), wxTopLevelWindow
);
199 return tlw
&& !tlw
->IsMaximized() && tlw
->HasFlag(wxRESIZE_BORDER
);
202 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
208 if ( ShowsSizeGrip() )
211 GetClientSize(&width
, &height
);
213 if (GetLayoutDirection() == wxLayout_RightToLeft
)
215 gtk_paint_resize_grip( m_widget
->style
,
216 GTKGetDrawingWindow(),
217 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
221 GDK_WINDOW_EDGE_SOUTH_WEST
,
222 2, 2, height
-2, height
-4 );
226 gtk_paint_resize_grip( m_widget
->style
,
227 GTKGetDrawingWindow(),
228 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
232 GDK_WINDOW_EDGE_SOUTH_EAST
,
233 width
-height
-2, 2, height
-2, height
-4 );
236 #endif // __WXGTK20__
239 dc
.SetFont(GetFont());
241 dc
.SetBackgroundMode(wxTRANSPARENT
);
246 vColor
= wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
);
247 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
250 for (int i
= 0; i
< m_nFields
; i
++)
254 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
259 GetFieldRect(i
, rect
);
261 wxString
text(GetStatusText(i
));
263 wxCoord x
= 0, y
= 0;
265 dc
.GetTextExtent(text
, &x
, &y
);
267 int xpos
= rect
.x
+ leftMargin
;
268 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
270 #if defined( __WXGTK__ ) || defined(__WXMAC__)
275 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
277 dc
.DrawText(text
, xpos
, ypos
);
279 dc
.DestroyClippingRegion();
282 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
285 GetFieldRect(i
, rect
);
287 int style
= wxSB_NORMAL
;
289 style
= m_statusStyles
[i
];
291 if (style
!= wxSB_FLAT
)
295 // Have grey background, plus 3-d border -
296 // One black rectangle.
297 // Inside this, left and top sides - dark grey. Bottom and right -
299 // Reverse it for wxSB_RAISED
301 dc
.SetPen((style
== wxSB_RAISED
) ? m_mediumShadowPen
: m_hilightPen
);
305 // Right and bottom lines
306 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
307 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
308 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
309 rect
.x
, rect
.y
+ rect
.height
);
311 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
313 // Left and top lines
314 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
316 dc
.DrawLine(rect
.x
, rect
.y
,
317 rect
.x
+ rect
.width
, rect
.y
);
320 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.height
+ 2,
321 rect
.x
, rect
.height
+ 2);
322 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
323 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
325 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
326 dc
.DrawLine(rect
.x
, rect
.y
,
327 rect
.x
+ rect
.width
, rect
.y
);
328 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
334 DrawFieldText(dc
, i
);
337 // Get the position and size of the field's internal bounding rectangle
338 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
340 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), false,
341 _T("invalid status bar field index") );
343 // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
346 GetSize(&width
, &height
);
348 GetClientSize(&width
, &height
);
351 // we cache m_widthsAbs between calls and recompute it if client
352 // width has changed (or when it is initially empty)
353 if ( m_widthsAbs
.IsEmpty() || (m_lastClientWidth
!= width
) )
355 wxConstCast(this, wxStatusBarGeneric
)->
356 m_widthsAbs
= CalculateAbsWidths(width
);
357 // remember last width for which we have recomputed the widths in pixels
358 wxConstCast(this, wxStatusBarGeneric
)->
359 m_lastClientWidth
= width
;
363 for ( int i
= 0; i
< n
; i
++ )
365 rect
.x
+= m_widthsAbs
[i
];
371 rect
.width
= m_widthsAbs
[n
] - 2*m_borderX
;
372 rect
.height
= height
- 2*m_borderY
;
377 // Initialize colours
378 void wxStatusBarGeneric::InitColours()
381 #if defined(__WXMSW__) || defined(__WXMAC__)
382 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
383 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
385 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
386 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
387 #elif defined(__WXPM__)
388 m_mediumShadowPen
= wxPen(wxColour(127, 127, 127), 1, wxSOLID
);
389 m_hilightPen
= *wxWHITE_PEN
;
391 SetBackgroundColour(*wxLIGHT_GREY
);
392 SetForegroundColour(*wxBLACK
);
394 m_mediumShadowPen
= *wxGREY_PEN
;
395 m_hilightPen
= *wxWHITE_PEN
;
399 // Responds to colour changes, and passes event on to children.
400 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
404 // Propagate the event to the non-top-level children
405 wxWindow::OnSysColourChanged(event
);
408 void wxStatusBarGeneric::SetMinHeight(int height
)
410 // check that this min height is not less than minimal height for the
414 dc
.GetTextExtent( wxT("X"), NULL
, &y
);
416 if ( height
> (11*y
)/10 )
418 SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, height
+ 2*m_borderY
);
422 void wxStatusBarGeneric::OnLeftDown(wxMouseEvent
& event
)
426 GetClientSize(&width
, &height
);
428 if ( ShowsSizeGrip() && (event
.GetX() > width
-height
) )
430 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
432 if (!GTK_IS_WINDOW (ancestor
))
435 GdkWindow
*source
= GTKGetDrawingWindow();
439 gdk_window_get_origin( source
, &org_x
, &org_y
);
441 if (GetLayoutDirection() == wxLayout_RightToLeft
)
443 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
444 GDK_WINDOW_EDGE_SOUTH_WEST
,
446 org_x
- event
.GetX() + GetSize().x
,
447 org_y
+ event
.GetY(),
452 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
453 GDK_WINDOW_EDGE_SOUTH_EAST
,
455 org_x
+ event
.GetX(),
456 org_y
+ event
.GetY(),
469 void wxStatusBarGeneric::OnRightDown(wxMouseEvent
& event
)
473 GetClientSize(&width
, &height
);
475 if ( ShowsSizeGrip() && (event
.GetX() > width
-height
) )
477 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
479 if (!GTK_IS_WINDOW (ancestor
))
482 GdkWindow
*source
= GTKGetDrawingWindow();
486 gdk_window_get_origin( source
, &org_x
, &org_y
);
488 gtk_window_begin_move_drag (GTK_WINDOW (ancestor
),
490 org_x
+ event
.GetX(),
491 org_y
+ event
.GetY(),
503 #endif // wxUSE_STATUSBAR