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"
26 #include "wx/toplevel.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
);
86 // Set the height according to the font and the border size
88 dc
.SetFont(GetFont());
90 dc
.GetTextExtent(_T("X"), NULL
, &y
);
92 int height
= (int)( (11*y
)/10 + 2*GetBorderY());
94 SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, height
);
102 wxSize
wxStatusBarGeneric::DoGetBestSize() const
106 // best width is the width of the parent
107 GetParent()->GetClientSize(&width
, NULL
);
109 // best height is as calculated above in Create
110 wxClientDC
dc((wxWindow
*)this);
111 dc
.SetFont(GetFont());
113 dc
.GetTextExtent(_T("X"), NULL
, &y
);
114 height
= (int)( (11*y
)/10 + 2*GetBorderY());
116 return wxSize(width
, height
);
119 void wxStatusBarGeneric::SetFieldsCount(int number
, const int *widths
)
121 wxASSERT_MSG( number
>= 0, _T("negative number of fields in wxStatusBar?") );
124 for(i
= m_nFields
; i
< number
; ++i
)
125 m_statusStrings
.Add( wxEmptyString
);
127 for (i
= m_nFields
- 1; i
>= number
; --i
)
128 m_statusStrings
.RemoveAt(i
);
130 // forget the old cached pixel widths
133 wxStatusBarBase::SetFieldsCount(number
, widths
);
135 wxASSERT_MSG( m_nFields
== (int)m_statusStrings
.GetCount(),
136 _T("This really should never happen, can we do away with m_nFields here?") );
139 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
141 wxCHECK_RET( (number
>= 0) && (number
< m_nFields
),
142 _T("invalid status bar field index") );
144 wxString oldText
= m_statusStrings
[number
];
147 m_statusStrings
[number
] = text
;
150 GetFieldRect(number
, rect
);
152 Refresh(true, &rect
);
154 // it's common to show some text in the status bar before starting a
155 // relatively lengthy operation, ensure that the text is shown to the
156 // user immediately and not after the lengthy operation end
161 wxString
wxStatusBarGeneric::GetStatusText(int n
) const
163 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), wxEmptyString
,
164 _T("invalid status bar field index") );
166 return m_statusStrings
[n
];
169 void wxStatusBarGeneric::SetStatusWidths(int n
, const int widths_field
[])
171 // only set status widths, when n == number of statuswindows
172 wxCHECK_RET( n
== m_nFields
, _T("status bar field count mismatch") );
174 // delete the old widths in any case - this function may be used to reset
175 // the widths to the default (all equal)
176 // MBN: this is incompatible with at least wxMSW and wxMAC and not
177 // documented, but let's keep it for now
180 // forget the old cached pixel widths
185 // not an error, see the comment above
190 wxStatusBarBase::SetStatusWidths(n
, widths_field
);
193 bool wxStatusBarGeneric::ShowsSizeGrip() const
195 if ( !HasFlag(wxST_SIZEGRIP
) )
198 wxTopLevelWindow
* const
199 tlw
= wxDynamicCast(wxGetTopLevelParent(GetParent()), wxTopLevelWindow
);
200 return tlw
&& !tlw
->IsMaximized() && tlw
->HasFlag(wxRESIZE_BORDER
);
203 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
209 if ( ShowsSizeGrip() )
212 GetClientSize(&width
, &height
);
214 if (GetLayoutDirection() == wxLayout_RightToLeft
)
216 gtk_paint_resize_grip( m_widget
->style
,
217 GTKGetDrawingWindow(),
218 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
222 GDK_WINDOW_EDGE_SOUTH_WEST
,
223 2, 2, height
-2, height
-4 );
227 gtk_paint_resize_grip( m_widget
->style
,
228 GTKGetDrawingWindow(),
229 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
233 GDK_WINDOW_EDGE_SOUTH_EAST
,
234 width
-height
-2, 2, height
-2, height
-4 );
237 #endif // __WXGTK20__
240 dc
.SetFont(GetFont());
242 dc
.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
244 for (int i
= 0; i
< m_nFields
; i
++)
248 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
253 GetFieldRect(i
, rect
);
255 wxString
text(GetStatusText(i
));
257 wxCoord x
= 0, y
= 0;
259 dc
.GetTextExtent(text
, &x
, &y
);
261 int xpos
= rect
.x
+ leftMargin
;
262 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
264 #if defined( __WXGTK__ ) || defined(__WXMAC__)
269 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
271 dc
.DrawText(text
, xpos
, ypos
);
273 dc
.DestroyClippingRegion();
276 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
279 GetFieldRect(i
, rect
);
281 int style
= wxSB_NORMAL
;
283 style
= m_statusStyles
[i
];
285 if (style
!= wxSB_FLAT
)
289 // Have grey background, plus 3-d border -
290 // One black rectangle.
291 // Inside this, left and top sides - dark grey. Bottom and right -
293 // Reverse it for wxSB_RAISED
295 dc
.SetPen((style
== wxSB_RAISED
) ? m_mediumShadowPen
: m_hilightPen
);
299 // Right and bottom lines
300 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
301 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
302 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
303 rect
.x
, rect
.y
+ rect
.height
);
305 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
307 // Left and top lines
308 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
310 dc
.DrawLine(rect
.x
, rect
.y
,
311 rect
.x
+ rect
.width
, rect
.y
);
314 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.height
+ 2,
315 rect
.x
, rect
.height
+ 2);
316 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
317 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
319 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
320 dc
.DrawLine(rect
.x
, rect
.y
,
321 rect
.x
+ rect
.width
, rect
.y
);
322 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
328 DrawFieldText(dc
, i
);
331 // Get the position and size of the field's internal bounding rectangle
332 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
334 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), false,
335 _T("invalid status bar field index") );
337 // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
340 GetSize(&width
, &height
);
342 GetClientSize(&width
, &height
);
345 // we cache m_widthsAbs between calls and recompute it if client
346 // width has changed (or when it is initially empty)
347 if ( m_widthsAbs
.IsEmpty() || (m_lastClientWidth
!= width
) )
349 wxConstCast(this, wxStatusBarGeneric
)->
350 m_widthsAbs
= CalculateAbsWidths(width
);
351 // remember last width for which we have recomputed the widths in pixels
352 wxConstCast(this, wxStatusBarGeneric
)->
353 m_lastClientWidth
= width
;
357 for ( int i
= 0; i
< n
; i
++ )
359 rect
.x
+= m_widthsAbs
[i
];
365 rect
.width
= m_widthsAbs
[n
] - 2*m_borderX
;
366 rect
.height
= height
- 2*m_borderY
;
371 // Initialize colours
372 void wxStatusBarGeneric::InitColours()
374 #if defined(__WXPM__)
375 m_mediumShadowPen
= wxPen(wxColour(127, 127, 127), 1, wxSOLID
);
376 m_hilightPen
= *wxWHITE_PEN
;
378 SetBackgroundColour(*wxLIGHT_GREY
);
379 SetForegroundColour(*wxBLACK
);
381 m_mediumShadowPen
= wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
382 m_hilightPen
= wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
383 #endif // __WXPM__/!__WXPM__
386 // Responds to colour changes, and passes event on to children.
387 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
391 // Propagate the event to the non-top-level children
392 wxWindow::OnSysColourChanged(event
);
395 void wxStatusBarGeneric::SetMinHeight(int height
)
397 // check that this min height is not less than minimal height for the
401 dc
.GetTextExtent( wxT("X"), NULL
, &y
);
403 if ( height
> (11*y
)/10 )
405 SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, height
+ 2*m_borderY
);
409 void wxStatusBarGeneric::OnLeftDown(wxMouseEvent
& event
)
413 GetClientSize(&width
, &height
);
415 if ( ShowsSizeGrip() && (event
.GetX() > width
-height
) )
417 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
419 if (!GTK_IS_WINDOW (ancestor
))
422 GdkWindow
*source
= GTKGetDrawingWindow();
426 gdk_window_get_origin( source
, &org_x
, &org_y
);
428 if (GetLayoutDirection() == wxLayout_RightToLeft
)
430 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
431 GDK_WINDOW_EDGE_SOUTH_WEST
,
433 org_x
- event
.GetX() + GetSize().x
,
434 org_y
+ event
.GetY(),
439 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
440 GDK_WINDOW_EDGE_SOUTH_EAST
,
442 org_x
+ event
.GetX(),
443 org_y
+ event
.GetY(),
456 void wxStatusBarGeneric::OnRightDown(wxMouseEvent
& event
)
460 GetClientSize(&width
, &height
);
462 if ( ShowsSizeGrip() && (event
.GetX() > width
-height
) )
464 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
466 if (!GTK_IS_WINDOW (ancestor
))
469 GdkWindow
*source
= GTKGetDrawingWindow();
473 gdk_window_get_origin( source
, &org_x
, &org_y
);
475 gtk_window_begin_move_drag (GTK_WINDOW (ancestor
),
477 org_x
+ event
.GetX(),
478 org_y
+ event
.GetY(),
490 #endif // wxUSE_STATUSBAR