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
59 #define wxTHICK_LINE_WIDTH 1
61 void wxStatusBarGeneric::Init()
63 m_borderX
= wxTHICK_LINE_BORDER
;
64 m_borderY
= wxTHICK_LINE_BORDER
;
67 wxStatusBarGeneric::~wxStatusBarGeneric()
69 // VZ: what is this for? please comment...
75 bool wxStatusBarGeneric::Create(wxWindow
*parent
,
80 if ( !wxWindow::Create(parent
, id
,
81 wxDefaultPosition
, wxDefaultSize
,
82 style
| wxTAB_TRAVERSAL
, name
) )
85 // The status bar should have a themed background
86 SetThemeEnabled( TRUE
);
88 // Don't wish this to be found as a child
90 parent
->GetChildren().DeleteObject(this);
94 SetFont(m_defaultStatusBarFont
);
96 // Set the height according to the font and the border size
98 dc
.SetFont(GetFont());
101 dc
.GetTextExtent(_T("X"), NULL
, &y
);
103 int height
= (int)( (11*y
)/10 + 2*GetBorderY());
105 SetSize(-1, -1, -1, height
);
112 void wxStatusBarGeneric::SetFieldsCount(int number
, const int *widths
)
114 wxASSERT_MSG( number
>= 0, _T("negative number of fields in wxStatusBar?") );
117 for(i
= m_nFields
; i
< number
; ++i
)
118 m_statusStrings
.Add( wxEmptyString
);
120 for (i
= m_nFields
- 1; i
>= number
; --i
)
121 m_statusStrings
.RemoveAt(i
);
125 wxASSERT_MSG( m_nFields
== (int)m_statusStrings
.GetCount(),
126 _T("This really should never happen, can we do away with m_nFields here?") );
128 SetStatusWidths(number
, widths
);
131 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
133 wxCHECK_RET( (number
>= 0) && (number
< m_nFields
),
134 _T("invalid status bar field index") );
136 wxString oldText
= m_statusStrings
[number
];
139 m_statusStrings
[number
] = text
;
142 GetFieldRect(number
, rect
);
144 Refresh( TRUE
, &rect
);
148 wxString
wxStatusBarGeneric::GetStatusText(int n
) const
150 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), wxEmptyString
,
151 _T("invalid status bar field index") );
153 return m_statusStrings
[n
];
156 void wxStatusBarGeneric::SetStatusWidths(int n
, const int widths_field
[])
158 // only set status widths, when n == number of statuswindows
159 wxCHECK_RET( n
== m_nFields
, _T("status bar field count mismatch") );
161 // delete the old widths in any case - this function may be used to reset
162 // the widths to the default (all equal)
163 // MBN: this is incompatible with at least wxMSW and wxMAC and not
164 // documented, but let's keep it for now
167 // forget the old cached pixel widths
172 // not an error, see the comment above
177 wxStatusBarBase::SetStatusWidths(n
, widths_field
);
180 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
186 if (HasFlag( wxST_SIZEGRIP
))
189 GetClientSize(&width
, &height
);
191 gtk_paint_resize_grip( m_widget
->style
,
192 GTK_PIZZA(m_wxwindow
)->bin_window
,
193 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
197 GDK_WINDOW_EDGE_SOUTH_EAST
,
198 width
-height
-2, 1, height
-2, height
-3 );
204 dc
.SetFont(GetFont());
206 dc
.SetBackgroundMode(wxTRANSPARENT
);
211 vColor
= wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
);
212 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
215 for (int i
= 0; i
< m_nFields
; i
++)
219 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
224 GetFieldRect(i
, rect
);
226 wxString
text(GetStatusText(i
));
230 dc
.GetTextExtent(text
, &x
, &y
);
232 int xpos
= rect
.x
+ leftMargin
;
233 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
235 #if defined( __WXGTK__ ) || defined(__WXMAC__)
240 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
242 dc
.DrawText(text
, xpos
, ypos
);
244 dc
.DestroyClippingRegion();
247 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
250 GetFieldRect(i
, rect
);
253 // Have grey background, plus 3-d border -
254 // One black rectangle.
255 // Inside this, left and top sides - dark grey. Bottom and right -
258 dc
.SetPen(m_hilightPen
);
262 // Right and bottom white lines
263 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
264 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
265 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
266 rect
.x
, rect
.y
+ rect
.height
);
268 dc
.SetPen(m_mediumShadowPen
);
270 // Left and top grey lines
271 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
273 dc
.DrawLine(rect
.x
, rect
.y
,
274 rect
.x
+ rect
.width
, rect
.y
);
277 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.height
+ 2,
278 rect
.x
, rect
.height
+ 2);
279 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
280 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
282 dc
.SetPen(m_mediumShadowPen
);
283 dc
.DrawLine(rect
.x
, rect
.y
,
284 rect
.x
+ rect
.width
, rect
.y
);
285 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
290 DrawFieldText(dc
, i
);
293 // Get the position and size of the field's internal bounding rectangle
294 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
296 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), FALSE
,
297 _T("invalid status bar field index") );
299 // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
302 GetSize(&width
, &height
);
304 GetClientSize(&width
, &height
);
307 // we cache m_widthsAbs between calls and recompute it if client
308 // width has changed (or when it is initially empty)
309 if ( m_widthsAbs
.IsEmpty() || (m_lastClientWidth
!= width
) )
311 wxConstCast(this, wxStatusBarGeneric
)->
312 m_widthsAbs
= CalculateAbsWidths(width
);
313 // remember last width for which we have recomputed the widths in pixels
314 wxConstCast(this, wxStatusBarGeneric
)->
315 m_lastClientWidth
= width
;
319 for ( int i
= 0; i
< n
; i
++ )
321 rect
.x
+= m_widthsAbs
[i
];
327 rect
.width
= m_widthsAbs
[n
] - 2*m_borderX
;
328 rect
.height
= height
- 2*m_borderY
;
333 // Initialize colours
334 void wxStatusBarGeneric::InitColours()
337 #if defined(__WIN95__) || defined(__WXMAC__)
338 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
339 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
341 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
342 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
343 #elif defined(__WXPM__)
344 m_mediumShadowPen
= wxPen(wxColour(127, 127, 127), 1, wxSOLID
);
345 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
349 vColour
.Set(wxString("LIGHT GREY"));
350 SetBackgroundColour(vColour
);
351 vColour
.Set(wxString("BLACK"));
352 SetForegroundColour(vColour
);
353 m_defaultStatusBarFont
= *wxSMALL_FONT
;
355 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
356 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
360 m_defaultStatusBarFont
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
361 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
365 // Responds to colour changes, and passes event on to children.
366 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
371 // Propagate the event to the non-top-level children
372 wxWindow::OnSysColourChanged(event
);
375 void wxStatusBarGeneric::SetMinHeight(int height
)
377 // check that this min height is not less than minimal height for the
381 dc
.GetTextExtent( wxT("X"), NULL
, &y
);
383 if ( height
> (11*y
)/10 )
385 SetSize(-1, -1, -1, height
+ 2*m_borderY
);
389 void wxStatusBarGeneric::OnLeftDown(wxMouseEvent
& event
)
393 GetClientSize(&width
, &height
);
395 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
397 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
399 if (!GTK_IS_WINDOW (ancestor
))
402 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
406 gdk_window_get_origin( source
, &org_x
, &org_y
);
408 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
409 GDK_WINDOW_EDGE_SOUTH_EAST
,
411 org_x
+ event
.GetX(),
412 org_y
+ event
.GetY(),
424 void wxStatusBarGeneric::OnRightDown(wxMouseEvent
& event
)
428 GetClientSize(&width
, &height
);
430 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
432 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
434 if (!GTK_IS_WINDOW (ancestor
))
437 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
441 gdk_window_get_origin( source
, &org_x
, &org_y
);
443 gtk_window_begin_move_drag (GTK_WINDOW (ancestor
),
445 org_x
+ event
.GetX(),
446 org_y
+ event
.GetY(),
458 #endif // wxUSE_STATUSBAR