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 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
198 if (HasFlag( wxST_SIZEGRIP
))
201 GetClientSize(&width
, &height
);
203 if (GetLayoutDirection() == wxLayout_RightToLeft
)
205 gtk_paint_resize_grip( m_widget
->style
,
206 GTKGetDrawingWindow(),
207 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
211 GDK_WINDOW_EDGE_SOUTH_WEST
,
212 2, 2, height
-2, height
-4 );
216 gtk_paint_resize_grip( m_widget
->style
,
217 GTKGetDrawingWindow(),
218 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
222 GDK_WINDOW_EDGE_SOUTH_EAST
,
223 width
-height
-2, 2, height
-2, height
-4 );
229 dc
.SetFont(GetFont());
231 dc
.SetBackgroundMode(wxTRANSPARENT
);
236 vColor
= wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
);
237 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
240 for (int i
= 0; i
< m_nFields
; i
++)
244 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
249 GetFieldRect(i
, rect
);
251 wxString
text(GetStatusText(i
));
253 wxCoord x
= 0, y
= 0;
255 dc
.GetTextExtent(text
, &x
, &y
);
257 int xpos
= rect
.x
+ leftMargin
;
258 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
260 #if defined( __WXGTK__ ) || defined(__WXMAC__)
265 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
267 dc
.DrawText(text
, xpos
, ypos
);
269 dc
.DestroyClippingRegion();
272 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
275 GetFieldRect(i
, rect
);
277 int style
= wxSB_NORMAL
;
279 style
= m_statusStyles
[i
];
281 if (style
!= wxSB_FLAT
)
285 // Have grey background, plus 3-d border -
286 // One black rectangle.
287 // Inside this, left and top sides - dark grey. Bottom and right -
289 // Reverse it for wxSB_RAISED
291 dc
.SetPen((style
== wxSB_RAISED
) ? m_mediumShadowPen
: m_hilightPen
);
295 // Right and bottom lines
296 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
297 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
298 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
299 rect
.x
, rect
.y
+ rect
.height
);
301 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
303 // Left and top lines
304 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
306 dc
.DrawLine(rect
.x
, rect
.y
,
307 rect
.x
+ rect
.width
, rect
.y
);
310 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.height
+ 2,
311 rect
.x
, rect
.height
+ 2);
312 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
313 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
315 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
316 dc
.DrawLine(rect
.x
, rect
.y
,
317 rect
.x
+ rect
.width
, rect
.y
);
318 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
324 DrawFieldText(dc
, i
);
327 // Get the position and size of the field's internal bounding rectangle
328 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
330 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), false,
331 _T("invalid status bar field index") );
333 // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
336 GetSize(&width
, &height
);
338 GetClientSize(&width
, &height
);
341 // we cache m_widthsAbs between calls and recompute it if client
342 // width has changed (or when it is initially empty)
343 if ( m_widthsAbs
.IsEmpty() || (m_lastClientWidth
!= width
) )
345 wxConstCast(this, wxStatusBarGeneric
)->
346 m_widthsAbs
= CalculateAbsWidths(width
);
347 // remember last width for which we have recomputed the widths in pixels
348 wxConstCast(this, wxStatusBarGeneric
)->
349 m_lastClientWidth
= width
;
353 for ( int i
= 0; i
< n
; i
++ )
355 rect
.x
+= m_widthsAbs
[i
];
361 rect
.width
= m_widthsAbs
[n
] - 2*m_borderX
;
362 rect
.height
= height
- 2*m_borderY
;
367 // Initialize colours
368 void wxStatusBarGeneric::InitColours()
371 #if defined(__WXMSW__) || defined(__WXMAC__)
372 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
373 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
375 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
376 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
377 #elif defined(__WXPM__)
378 m_mediumShadowPen
= wxPen(wxColour(127, 127, 127), 1, wxSOLID
);
379 m_hilightPen
= *wxWHITE_PEN
;
381 SetBackgroundColour(*wxLIGHT_GREY
);
382 SetForegroundColour(*wxBLACK
);
384 m_mediumShadowPen
= *wxGREY_PEN
;
385 m_hilightPen
= *wxWHITE_PEN
;
389 // Responds to colour changes, and passes event on to children.
390 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
394 // Propagate the event to the non-top-level children
395 wxWindow::OnSysColourChanged(event
);
398 void wxStatusBarGeneric::SetMinHeight(int height
)
400 // check that this min height is not less than minimal height for the
404 dc
.GetTextExtent( wxT("X"), NULL
, &y
);
406 if ( height
> (11*y
)/10 )
408 SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, height
+ 2*m_borderY
);
412 void wxStatusBarGeneric::OnLeftDown(wxMouseEvent
& event
)
416 GetClientSize(&width
, &height
);
418 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
420 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
422 if (!GTK_IS_WINDOW (ancestor
))
425 GdkWindow
*source
= GTKGetDrawingWindow();
429 gdk_window_get_origin( source
, &org_x
, &org_y
);
431 if (GetLayoutDirection() == wxLayout_RightToLeft
)
433 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
434 GDK_WINDOW_EDGE_SOUTH_WEST
,
436 org_x
- event
.GetX() + GetSize().x
,
437 org_y
+ event
.GetY(),
442 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
443 GDK_WINDOW_EDGE_SOUTH_EAST
,
445 org_x
+ event
.GetX(),
446 org_y
+ event
.GetY(),
459 void wxStatusBarGeneric::OnRightDown(wxMouseEvent
& event
)
463 GetClientSize(&width
, &height
);
465 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
467 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
469 if (!GTK_IS_WINDOW (ancestor
))
472 GdkWindow
*source
= GTKGetDrawingWindow();
476 gdk_window_get_origin( source
, &org_x
, &org_y
);
478 gtk_window_begin_move_drag (GTK_WINDOW (ancestor
),
480 org_x
+ event
.GetX(),
481 org_y
+ event
.GetY(),
493 #endif // wxUSE_STATUSBAR