1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/statusbr.cpp
3 // Purpose: wxStatusBarGeneric class implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "statusbr.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
28 #include "wx/settings.h"
29 #include "wx/dcclient.h"
33 #include "wx/gtk/private.h"
34 #include "wx/gtk/win_gtk.h"
37 #include "wx/statusbr.h"
39 // we only have to do it here when we use wxStatusBarGeneric in addition to the
40 // standard wxStatusBar class, if wxStatusBarGeneric is the same as
41 // wxStatusBar, then the corresponding IMPLEMENT_DYNAMIC_CLASS is already in
43 #if defined(__WXMAC__) || \
44 (defined(wxUSE_NATIVE_STATUSBAR) && wxUSE_NATIVE_STATUSBAR)
45 #include "wx/generic/statusbr.h"
47 IMPLEMENT_DYNAMIC_CLASS(wxStatusBarGeneric
, wxWindow
)
48 #endif // wxUSE_NATIVE_STATUSBAR
50 BEGIN_EVENT_TABLE(wxStatusBarGeneric
, wxWindow
)
51 EVT_PAINT(wxStatusBarGeneric::OnPaint
)
52 EVT_LEFT_DOWN(wxStatusBarGeneric::OnLeftDown
)
53 EVT_RIGHT_DOWN(wxStatusBarGeneric::OnRightDown
)
54 EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged
)
57 // Default status border dimensions
58 #define wxTHICK_LINE_BORDER 2
60 void wxStatusBarGeneric::Init()
62 m_borderX
= wxTHICK_LINE_BORDER
;
63 m_borderY
= wxTHICK_LINE_BORDER
;
66 wxStatusBarGeneric::~wxStatusBarGeneric()
70 bool wxStatusBarGeneric::Create(wxWindow
*parent
,
75 if ( !wxWindow::Create(parent
, id
,
76 wxDefaultPosition
, wxDefaultSize
,
77 style
| wxTAB_TRAVERSAL
, name
) )
80 // The status bar should have a themed background
81 SetThemeEnabled( true );
86 SetFont(*wxSMALL_FONT
);
89 // Set the height according to the font and the border size
91 dc
.SetFont(GetFont());
94 dc
.GetTextExtent(_T("X"), NULL
, &y
);
96 int height
= (int)( (11*y
)/10 + 2*GetBorderY());
98 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?") );
128 for(i
= m_nFields
; i
< number
; ++i
)
129 m_statusStrings
.Add( wxEmptyString
);
131 for (i
= m_nFields
- 1; i
>= number
; --i
)
132 m_statusStrings
.RemoveAt(i
);
134 // forget the old cached pixel widths
137 wxStatusBarBase::SetFieldsCount(number
, widths
);
139 wxASSERT_MSG( m_nFields
== (int)m_statusStrings
.GetCount(),
140 _T("This really should never happen, can we do away with m_nFields here?") );
143 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
145 wxCHECK_RET( (number
>= 0) && (number
< m_nFields
),
146 _T("invalid status bar field index") );
148 wxString oldText
= m_statusStrings
[number
];
151 m_statusStrings
[number
] = text
;
154 GetFieldRect(number
, rect
);
156 Refresh( true, &rect
);
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 gtk_paint_resize_grip( m_widget
->style
,
204 GTK_PIZZA(m_wxwindow
)->bin_window
,
205 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
209 GDK_WINDOW_EDGE_SOUTH_EAST
,
210 width
-height
-2, 1, height
-2, height
-3 );
216 dc
.SetFont(GetFont());
218 dc
.SetBackgroundMode(wxTRANSPARENT
);
223 vColor
= wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
);
224 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
227 for (int i
= 0; i
< m_nFields
; i
++)
231 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
236 GetFieldRect(i
, rect
);
238 wxString
text(GetStatusText(i
));
242 dc
.GetTextExtent(text
, &x
, &y
);
244 int xpos
= rect
.x
+ leftMargin
;
245 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
247 #if defined( __WXGTK__ ) || defined(__WXMAC__)
252 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
254 dc
.DrawText(text
, xpos
, ypos
);
256 dc
.DestroyClippingRegion();
259 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
262 GetFieldRect(i
, rect
);
264 int style
= wxSB_NORMAL
;
266 style
= m_statusStyles
[i
];
268 if (style
!= wxSB_FLAT
)
272 // Have grey background, plus 3-d border -
273 // One black rectangle.
274 // Inside this, left and top sides - dark grey. Bottom and right -
276 // Reverse it for wxSB_RAISED
278 dc
.SetPen((style
== wxSB_RAISED
) ? m_mediumShadowPen
: m_hilightPen
);
282 // Right and bottom lines
283 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
284 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
285 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
286 rect
.x
, rect
.y
+ rect
.height
);
288 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
290 // Left and top lines
291 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
293 dc
.DrawLine(rect
.x
, rect
.y
,
294 rect
.x
+ rect
.width
, rect
.y
);
297 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.height
+ 2,
298 rect
.x
, rect
.height
+ 2);
299 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
300 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
302 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
303 dc
.DrawLine(rect
.x
, rect
.y
,
304 rect
.x
+ rect
.width
, rect
.y
);
305 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
311 DrawFieldText(dc
, i
);
314 // Get the position and size of the field's internal bounding rectangle
315 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
317 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), false,
318 _T("invalid status bar field index") );
320 // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
323 GetSize(&width
, &height
);
325 GetClientSize(&width
, &height
);
328 // we cache m_widthsAbs between calls and recompute it if client
329 // width has changed (or when it is initially empty)
330 if ( m_widthsAbs
.IsEmpty() || (m_lastClientWidth
!= width
) )
332 wxConstCast(this, wxStatusBarGeneric
)->
333 m_widthsAbs
= CalculateAbsWidths(width
);
334 // remember last width for which we have recomputed the widths in pixels
335 wxConstCast(this, wxStatusBarGeneric
)->
336 m_lastClientWidth
= width
;
340 for ( int i
= 0; i
< n
; i
++ )
342 rect
.x
+= m_widthsAbs
[i
];
348 rect
.width
= m_widthsAbs
[n
] - 2*m_borderX
;
349 rect
.height
= height
- 2*m_borderY
;
354 // Initialize colours
355 void wxStatusBarGeneric::InitColours()
358 #if defined(__WIN95__) || defined(__WXMAC__)
359 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
360 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
362 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
363 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
364 #elif defined(__WXPM__)
365 m_mediumShadowPen
= wxPen(wxColour(127, 127, 127), 1, wxSOLID
);
366 m_hilightPen
= wxPen(_T("WHITE"), 1, wxSOLID
);
370 vColour
.Set(wxString(_T("LIGHT GREY")));
371 SetBackgroundColour(vColour
);
372 vColour
.Set(wxString(_T("BLACK")));
373 SetForegroundColour(vColour
);
375 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
376 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
380 // Responds to colour changes, and passes event on to children.
381 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
385 // Propagate the event to the non-top-level children
386 wxWindow::OnSysColourChanged(event
);
389 void wxStatusBarGeneric::SetMinHeight(int height
)
391 // check that this min height is not less than minimal height for the
395 dc
.GetTextExtent( wxT("X"), NULL
, &y
);
397 if ( height
> (11*y
)/10 )
399 SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, height
+ 2*m_borderY
);
403 void wxStatusBarGeneric::OnLeftDown(wxMouseEvent
& event
)
407 GetClientSize(&width
, &height
);
409 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
411 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
413 if (!GTK_IS_WINDOW (ancestor
))
416 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
420 gdk_window_get_origin( source
, &org_x
, &org_y
);
422 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
423 GDK_WINDOW_EDGE_SOUTH_EAST
,
425 org_x
+ event
.GetX(),
426 org_y
+ event
.GetY(),
438 void wxStatusBarGeneric::OnRightDown(wxMouseEvent
& event
)
442 GetClientSize(&width
, &height
);
444 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
446 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
448 if (!GTK_IS_WINDOW (ancestor
))
451 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
455 gdk_window_get_origin( source
, &org_x
, &org_y
);
457 gtk_window_begin_move_drag (GTK_WINDOW (ancestor
),
459 org_x
+ event
.GetX(),
460 org_y
+ event
.GetY(),
472 #endif // wxUSE_STATUSBAR