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 // forget the old cached pixel widths
182 wxStatusBarBase::SetStatusWidths(n
, widths_field
);
185 bool wxStatusBarGeneric::ShowsSizeGrip() const
187 if ( !HasFlag(wxST_SIZEGRIP
) )
190 wxTopLevelWindow
* const
191 tlw
= wxDynamicCast(wxGetTopLevelParent(GetParent()), wxTopLevelWindow
);
192 return tlw
&& !tlw
->IsMaximized() && tlw
->HasFlag(wxRESIZE_BORDER
);
195 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
201 if ( ShowsSizeGrip() )
204 GetClientSize(&width
, &height
);
206 if (GetLayoutDirection() == wxLayout_RightToLeft
)
208 gtk_paint_resize_grip( m_widget
->style
,
209 GTKGetDrawingWindow(),
210 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
214 GDK_WINDOW_EDGE_SOUTH_WEST
,
215 2, 2, height
-2, height
-4 );
219 gtk_paint_resize_grip( m_widget
->style
,
220 GTKGetDrawingWindow(),
221 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
225 GDK_WINDOW_EDGE_SOUTH_EAST
,
226 width
-height
-2, 2, height
-2, height
-4 );
229 #endif // __WXGTK20__
232 dc
.SetFont(GetFont());
234 dc
.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
236 for (size_t i
= 0; i
< m_panes
.GetCount(); i
++)
240 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
245 GetFieldRect(i
, rect
);
247 wxString
text(GetStatusText(i
));
249 wxCoord x
= 0, y
= 0;
251 dc
.GetTextExtent(text
, &x
, &y
);
253 int xpos
= rect
.x
+ leftMargin
;
254 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
256 #if defined( __WXGTK__ ) || defined(__WXMAC__)
261 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
263 dc
.DrawText(text
, xpos
, ypos
);
265 dc
.DestroyClippingRegion();
268 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
271 GetFieldRect(i
, rect
);
273 int style
= m_panes
[i
].nStyle
;
274 if (style
!= wxSB_FLAT
)
278 // Have grey background, plus 3-d border -
279 // One black rectangle.
280 // Inside this, left and top sides - dark grey. Bottom and right -
282 // Reverse it for wxSB_RAISED
284 dc
.SetPen((style
== wxSB_RAISED
) ? m_mediumShadowPen
: m_hilightPen
);
288 // Right and bottom lines
289 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
290 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
291 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
292 rect
.x
, rect
.y
+ rect
.height
);
294 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
296 // Left and top lines
297 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
299 dc
.DrawLine(rect
.x
, rect
.y
,
300 rect
.x
+ rect
.width
, rect
.y
);
303 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.height
+ 2,
304 rect
.x
, rect
.height
+ 2);
305 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
306 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
308 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
309 dc
.DrawLine(rect
.x
, rect
.y
,
310 rect
.x
+ rect
.width
, rect
.y
);
311 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
317 DrawFieldText(dc
, i
);
320 // Get the position and size of the field's internal bounding rectangle
321 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
323 wxCHECK_MSG( (n
>= 0) && ((size_t)n
< m_panes
.GetCount()), false,
324 _T("invalid status bar field index") );
326 // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
329 GetSize(&width
, &height
);
331 GetClientSize(&width
, &height
);
334 // we cache m_widthsAbs between calls and recompute it if client
335 // width has changed (or when it is initially empty)
336 if ( m_widthsAbs
.IsEmpty() || (m_lastClientWidth
!= width
) )
338 wxConstCast(this, wxStatusBarGeneric
)->
339 m_widthsAbs
= CalculateAbsWidths(width
);
340 // remember last width for which we have recomputed the widths in pixels
341 wxConstCast(this, wxStatusBarGeneric
)->
342 m_lastClientWidth
= width
;
346 for ( int i
= 0; i
< n
; i
++ )
348 rect
.x
+= m_widthsAbs
[i
];
354 rect
.width
= m_widthsAbs
[n
] - 2*m_borderX
;
355 rect
.height
= height
- 2*m_borderY
;
360 // Initialize colours
361 void wxStatusBarGeneric::InitColours()
363 #if defined(__WXPM__)
364 m_mediumShadowPen
= wxPen(wxColour(127, 127, 127), 1, wxSOLID
);
365 m_hilightPen
= *wxWHITE_PEN
;
367 SetBackgroundColour(*wxLIGHT_GREY
);
368 SetForegroundColour(*wxBLACK
);
370 m_mediumShadowPen
= wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
371 m_hilightPen
= wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
372 #endif // __WXPM__/!__WXPM__
375 // Responds to colour changes, and passes event on to children.
376 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
380 // Propagate the event to the non-top-level children
381 wxWindow::OnSysColourChanged(event
);
384 void wxStatusBarGeneric::SetMinHeight(int height
)
386 // check that this min height is not less than minimal height for the
390 dc
.GetTextExtent( wxT("X"), NULL
, &y
);
392 if ( height
> (11*y
)/10 )
394 SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, height
+ 2*m_borderY
);
398 void wxStatusBarGeneric::OnLeftDown(wxMouseEvent
& event
)
402 GetClientSize(&width
, &height
);
404 if ( ShowsSizeGrip() && (event
.GetX() > width
-height
) )
406 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
408 if (!GTK_IS_WINDOW (ancestor
))
411 GdkWindow
*source
= GTKGetDrawingWindow();
415 gdk_window_get_origin( source
, &org_x
, &org_y
);
417 if (GetLayoutDirection() == wxLayout_RightToLeft
)
419 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
420 GDK_WINDOW_EDGE_SOUTH_WEST
,
422 org_x
- event
.GetX() + GetSize().x
,
423 org_y
+ event
.GetY(),
428 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
429 GDK_WINDOW_EDGE_SOUTH_EAST
,
431 org_x
+ event
.GetX(),
432 org_y
+ event
.GetY(),
445 void wxStatusBarGeneric::OnRightDown(wxMouseEvent
& event
)
449 GetClientSize(&width
, &height
);
451 if ( ShowsSizeGrip() && (event
.GetX() > width
-height
) )
453 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
455 if (!GTK_IS_WINDOW (ancestor
))
458 GdkWindow
*source
= GTKGetDrawingWindow();
462 gdk_window_get_origin( source
, &org_x
, &org_y
);
464 gtk_window_begin_move_drag (GTK_WINDOW (ancestor
),
466 org_x
+ event
.GetX(),
467 org_y
+ event
.GetY(),
479 #endif // wxUSE_STATUSBAR