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 // Default status border dimensions
45 #define wxTHICK_LINE_BORDER 2
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 BEGIN_EVENT_TABLE(wxStatusBarGeneric
, wxWindow
)
53 EVT_PAINT(wxStatusBarGeneric::OnPaint
)
54 EVT_LEFT_DOWN(wxStatusBarGeneric::OnLeftDown
)
55 EVT_RIGHT_DOWN(wxStatusBarGeneric::OnRightDown
)
56 EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged
)
59 void wxStatusBarGeneric::Init()
61 m_borderX
= wxTHICK_LINE_BORDER
;
62 m_borderY
= wxTHICK_LINE_BORDER
;
65 wxStatusBarGeneric::~wxStatusBarGeneric()
69 bool wxStatusBarGeneric::Create(wxWindow
*parent
,
74 style
|= wxTAB_TRAVERSAL
| wxFULL_REPAINT_ON_RESIZE
;
75 if ( !wxWindow::Create(parent
, id
,
76 wxDefaultPosition
, wxDefaultSize
,
80 // The status bar should have a themed background
81 SetThemeEnabled( true );
86 SetFont(*wxSMALL_FONT
);
91 // Set the height according to the font and the border size
93 dc
.SetFont(GetFont());
95 dc
.GetTextExtent(_T("X"), NULL
, &y
);
97 int height
= (int)( (11*y
)/10 + 2*GetBorderY());
99 SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, height
);
106 wxSize
wxStatusBarGeneric::DoGetBestSize() const
110 // best width is the width of the parent
111 GetParent()->GetClientSize(&width
, NULL
);
113 // best height is as calculated above in Create
114 wxClientDC
dc((wxWindow
*)this);
115 dc
.SetFont(GetFont());
117 dc
.GetTextExtent(_T("X"), NULL
, &y
);
118 height
= (int)( (11*y
)/10 + 2*GetBorderY());
120 return wxSize(width
, height
);
123 void wxStatusBarGeneric::SetFieldsCount(int number
, const int *widths
)
125 wxASSERT_MSG( number
>= 0, _T("negative number of fields in wxStatusBar?") );
127 // enlarge the m_statusStrings array if needed:
128 for (size_t i
= m_panes
.GetCount(); i
< (size_t)number
; ++i
)
129 m_statusStrings
.Add( wxEmptyString
);
131 // shrink the m_statusStrings array if needed:
132 for (int j
= (int)m_panes
.GetCount() - 1; j
>= number
; --j
)
133 m_statusStrings
.RemoveAt(j
);
135 // forget the old cached pixel widths
138 wxStatusBarBase::SetFieldsCount(number
, widths
);
140 wxASSERT_MSG( m_panes
.GetCount() == m_statusStrings
.GetCount(),
141 _T("This really should never happen, can we do away with m_panes.GetCount() here?") );
144 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
146 wxCHECK_RET( (number
>= 0) && ((size_t)number
< m_panes
.GetCount()),
147 _T("invalid status bar field index") );
149 wxString oldText
= m_statusStrings
[number
];
152 m_statusStrings
[number
] = text
;
155 GetFieldRect(number
, rect
);
157 Refresh(true, &rect
);
159 // it's common to show some text in the status bar before starting a
160 // relatively lengthy operation, ensure that the text is shown to the
161 // user immediately and not after the lengthy operation end
166 wxString
wxStatusBarGeneric::GetStatusText(int n
) const
168 wxCHECK_MSG( (n
>= 0) && ((size_t)n
< m_panes
.GetCount()), wxEmptyString
,
169 _T("invalid status bar field index") );
171 return m_statusStrings
[n
];
174 void wxStatusBarGeneric::SetStatusWidths(int n
, const int widths_field
[])
176 // only set status widths when n == number of statuswindows
177 wxCHECK_RET( (size_t)n
== m_panes
.GetCount(), _T("status bar field count mismatch") );
179 // delete the old widths in any case - this function may be used to reset
180 // the widths to the default (all equal)
181 // MBN: this is incompatible with at least wxMSW and wxMAC and not
182 // documented, but let's keep it for now
183 m_bSameWidthForAllPanes
= true;
184 // FM: what MBN's comment is saying is that allowing widths_field = NULL
185 // only for wxStatusBarGeneric is not documented...
187 // forget the old cached pixel widths
192 // not an error, see the comment above
197 wxStatusBarBase::SetStatusWidths(n
, widths_field
);
200 bool wxStatusBarGeneric::ShowsSizeGrip() const
202 if ( !HasFlag(wxST_SIZEGRIP
) )
205 wxTopLevelWindow
* const
206 tlw
= wxDynamicCast(wxGetTopLevelParent(GetParent()), wxTopLevelWindow
);
207 return tlw
&& !tlw
->IsMaximized() && tlw
->HasFlag(wxRESIZE_BORDER
);
210 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
216 if ( ShowsSizeGrip() )
219 GetClientSize(&width
, &height
);
221 if (GetLayoutDirection() == wxLayout_RightToLeft
)
223 gtk_paint_resize_grip( m_widget
->style
,
224 GTKGetDrawingWindow(),
225 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
229 GDK_WINDOW_EDGE_SOUTH_WEST
,
230 2, 2, height
-2, height
-4 );
234 gtk_paint_resize_grip( m_widget
->style
,
235 GTKGetDrawingWindow(),
236 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
240 GDK_WINDOW_EDGE_SOUTH_EAST
,
241 width
-height
-2, 2, height
-2, height
-4 );
244 #endif // __WXGTK20__
247 dc
.SetFont(GetFont());
249 dc
.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
251 for (size_t i
= 0; i
< m_panes
.GetCount(); i
++)
255 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
260 GetFieldRect(i
, rect
);
262 wxString
text(GetStatusText(i
));
264 wxCoord x
= 0, y
= 0;
266 dc
.GetTextExtent(text
, &x
, &y
);
268 int xpos
= rect
.x
+ leftMargin
;
269 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
271 #if defined( __WXGTK__ ) || defined(__WXMAC__)
276 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
278 dc
.DrawText(text
, xpos
, ypos
);
280 dc
.DestroyClippingRegion();
283 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
286 GetFieldRect(i
, rect
);
288 int style
= m_panes
[i
].nStyle
;
289 if (style
!= wxSB_FLAT
)
293 // Have grey background, plus 3-d border -
294 // One black rectangle.
295 // Inside this, left and top sides - dark grey. Bottom and right -
297 // Reverse it for wxSB_RAISED
299 dc
.SetPen((style
== wxSB_RAISED
) ? m_mediumShadowPen
: m_hilightPen
);
303 // Right and bottom lines
304 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
305 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
306 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
307 rect
.x
, rect
.y
+ rect
.height
);
309 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
311 // Left and top lines
312 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
314 dc
.DrawLine(rect
.x
, rect
.y
,
315 rect
.x
+ rect
.width
, rect
.y
);
318 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.height
+ 2,
319 rect
.x
, rect
.height
+ 2);
320 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
321 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
323 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
324 dc
.DrawLine(rect
.x
, rect
.y
,
325 rect
.x
+ rect
.width
, rect
.y
);
326 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
332 DrawFieldText(dc
, i
);
335 // Get the position and size of the field's internal bounding rectangle
336 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
338 wxCHECK_MSG( (n
>= 0) && ((size_t)n
< m_panes
.GetCount()), false,
339 _T("invalid status bar field index") );
341 // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
344 GetSize(&width
, &height
);
346 GetClientSize(&width
, &height
);
349 // we cache m_widthsAbs between calls and recompute it if client
350 // width has changed (or when it is initially empty)
351 if ( m_widthsAbs
.IsEmpty() || (m_lastClientWidth
!= width
) )
353 wxConstCast(this, wxStatusBarGeneric
)->
354 m_widthsAbs
= CalculateAbsWidths(width
);
355 // remember last width for which we have recomputed the widths in pixels
356 wxConstCast(this, wxStatusBarGeneric
)->
357 m_lastClientWidth
= width
;
361 for ( int i
= 0; i
< n
; i
++ )
363 rect
.x
+= m_widthsAbs
[i
];
369 rect
.width
= m_widthsAbs
[n
] - 2*m_borderX
;
370 rect
.height
= height
- 2*m_borderY
;
375 // Initialize colours
376 void wxStatusBarGeneric::InitColours()
378 #if defined(__WXPM__)
379 m_mediumShadowPen
= wxPen(wxColour(127, 127, 127), 1, wxSOLID
);
380 m_hilightPen
= *wxWHITE_PEN
;
382 SetBackgroundColour(*wxLIGHT_GREY
);
383 SetForegroundColour(*wxBLACK
);
385 m_mediumShadowPen
= wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
386 m_hilightPen
= wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
387 #endif // __WXPM__/!__WXPM__
390 // Responds to colour changes, and passes event on to children.
391 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
395 // Propagate the event to the non-top-level children
396 wxWindow::OnSysColourChanged(event
);
399 void wxStatusBarGeneric::SetMinHeight(int height
)
401 // check that this min height is not less than minimal height for the
405 dc
.GetTextExtent( wxT("X"), NULL
, &y
);
407 if ( height
> (11*y
)/10 )
409 SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, height
+ 2*m_borderY
);
413 void wxStatusBarGeneric::OnLeftDown(wxMouseEvent
& event
)
417 GetClientSize(&width
, &height
);
419 if ( ShowsSizeGrip() && (event
.GetX() > width
-height
) )
421 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
423 if (!GTK_IS_WINDOW (ancestor
))
426 GdkWindow
*source
= GTKGetDrawingWindow();
430 gdk_window_get_origin( source
, &org_x
, &org_y
);
432 if (GetLayoutDirection() == wxLayout_RightToLeft
)
434 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
435 GDK_WINDOW_EDGE_SOUTH_WEST
,
437 org_x
- event
.GetX() + GetSize().x
,
438 org_y
+ event
.GetY(),
443 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
444 GDK_WINDOW_EDGE_SOUTH_EAST
,
446 org_x
+ event
.GetX(),
447 org_y
+ event
.GetY(),
460 void wxStatusBarGeneric::OnRightDown(wxMouseEvent
& event
)
464 GetClientSize(&width
, &height
);
466 if ( ShowsSizeGrip() && (event
.GetX() > width
-height
) )
468 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
470 if (!GTK_IS_WINDOW (ancestor
))
473 GdkWindow
*source
= GTKGetDrawingWindow();
477 gdk_window_get_origin( source
, &org_x
, &org_y
);
479 gtk_window_begin_move_drag (GTK_WINDOW (ancestor
),
481 org_x
+ event
.GetX(),
482 org_y
+ event
.GetY(),
494 #endif // wxUSE_STATUSBAR