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...
71 // JACS: commenting out since it causes an assert
72 // and there seems no reason for it.
73 // SetFont(wxNullFont);
77 bool wxStatusBarGeneric::Create(wxWindow
*parent
,
82 if ( !wxWindow::Create(parent
, id
,
83 wxDefaultPosition
, wxDefaultSize
,
84 style
| wxTAB_TRAVERSAL
, name
) )
87 // The status bar should have a themed background
88 SetThemeEnabled( true );
90 // Don't wish this to be found as a child
92 parent
->GetChildren().DeleteObject(this);
97 SetFont(*wxSMALL_FONT
);
100 // Set the height according to the font and the border size
102 dc
.SetFont(GetFont());
105 dc
.GetTextExtent(_T("X"), NULL
, &y
);
107 int height
= (int)( (11*y
)/10 + 2*GetBorderY());
109 SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, height
);
117 wxSize
wxStatusBarGeneric::DoGetBestSize() const
121 // best width is the width of the parent
122 GetParent()->GetClientSize(&width
, NULL
);
124 // best height is as calculated above in Create
125 wxClientDC
dc((wxWindow
*)this);
126 dc
.SetFont(GetFont());
128 dc
.GetTextExtent(_T("X"), NULL
, &y
);
129 height
= (int)( (11*y
)/10 + 2*GetBorderY());
131 return wxSize(width
, height
);
134 void wxStatusBarGeneric::SetFieldsCount(int number
, const int *widths
)
136 wxASSERT_MSG( number
>= 0, _T("negative number of fields in wxStatusBar?") );
139 for(i
= m_nFields
; i
< number
; ++i
)
140 m_statusStrings
.Add( wxEmptyString
);
142 for (i
= m_nFields
- 1; i
>= number
; --i
)
143 m_statusStrings
.RemoveAt(i
);
145 // forget the old cached pixel widths
148 wxStatusBarBase::SetFieldsCount(number
, widths
);
150 wxASSERT_MSG( m_nFields
== (int)m_statusStrings
.GetCount(),
151 _T("This really should never happen, can we do away with m_nFields here?") );
154 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
156 wxCHECK_RET( (number
>= 0) && (number
< m_nFields
),
157 _T("invalid status bar field index") );
159 wxString oldText
= m_statusStrings
[number
];
162 m_statusStrings
[number
] = text
;
165 GetFieldRect(number
, rect
);
167 Refresh( true, &rect
);
171 wxString
wxStatusBarGeneric::GetStatusText(int n
) const
173 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), wxEmptyString
,
174 _T("invalid status bar field index") );
176 return m_statusStrings
[n
];
179 void wxStatusBarGeneric::SetStatusWidths(int n
, const int widths_field
[])
181 // only set status widths, when n == number of statuswindows
182 wxCHECK_RET( n
== m_nFields
, _T("status bar field count mismatch") );
184 // delete the old widths in any case - this function may be used to reset
185 // the widths to the default (all equal)
186 // MBN: this is incompatible with at least wxMSW and wxMAC and not
187 // documented, but let's keep it for now
190 // forget the old cached pixel widths
195 // not an error, see the comment above
200 wxStatusBarBase::SetStatusWidths(n
, widths_field
);
203 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
209 if (HasFlag( wxST_SIZEGRIP
))
212 GetClientSize(&width
, &height
);
214 gtk_paint_resize_grip( m_widget
->style
,
215 GTK_PIZZA(m_wxwindow
)->bin_window
,
216 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
220 GDK_WINDOW_EDGE_SOUTH_EAST
,
221 width
-height
-2, 1, height
-2, height
-3 );
227 dc
.SetFont(GetFont());
229 dc
.SetBackgroundMode(wxTRANSPARENT
);
234 vColor
= wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
);
235 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
238 for (int i
= 0; i
< m_nFields
; i
++)
242 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
247 GetFieldRect(i
, rect
);
249 wxString
text(GetStatusText(i
));
253 dc
.GetTextExtent(text
, &x
, &y
);
255 int xpos
= rect
.x
+ leftMargin
;
256 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
258 #if defined( __WXGTK__ ) || defined(__WXMAC__)
263 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
265 dc
.DrawText(text
, xpos
, ypos
);
267 dc
.DestroyClippingRegion();
270 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
273 GetFieldRect(i
, rect
);
275 int style
= wxSB_NORMAL
;
277 style
= m_statusStyles
[i
];
279 if (style
!= wxSB_FLAT
)
283 // Have grey background, plus 3-d border -
284 // One black rectangle.
285 // Inside this, left and top sides - dark grey. Bottom and right -
287 // Reverse it for wxSB_RAISED
289 dc
.SetPen((style
== wxSB_RAISED
) ? m_mediumShadowPen
: m_hilightPen
);
293 // Right and bottom lines
294 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
295 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
296 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
297 rect
.x
, rect
.y
+ rect
.height
);
299 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
301 // Left and top lines
302 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
304 dc
.DrawLine(rect
.x
, rect
.y
,
305 rect
.x
+ rect
.width
, rect
.y
);
308 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.height
+ 2,
309 rect
.x
, rect
.height
+ 2);
310 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
311 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
313 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
314 dc
.DrawLine(rect
.x
, rect
.y
,
315 rect
.x
+ rect
.width
, rect
.y
);
316 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
322 DrawFieldText(dc
, i
);
325 // Get the position and size of the field's internal bounding rectangle
326 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
328 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), false,
329 _T("invalid status bar field index") );
331 // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
334 GetSize(&width
, &height
);
336 GetClientSize(&width
, &height
);
339 // we cache m_widthsAbs between calls and recompute it if client
340 // width has changed (or when it is initially empty)
341 if ( m_widthsAbs
.IsEmpty() || (m_lastClientWidth
!= width
) )
343 wxConstCast(this, wxStatusBarGeneric
)->
344 m_widthsAbs
= CalculateAbsWidths(width
);
345 // remember last width for which we have recomputed the widths in pixels
346 wxConstCast(this, wxStatusBarGeneric
)->
347 m_lastClientWidth
= width
;
351 for ( int i
= 0; i
< n
; i
++ )
353 rect
.x
+= m_widthsAbs
[i
];
359 rect
.width
= m_widthsAbs
[n
] - 2*m_borderX
;
360 rect
.height
= height
- 2*m_borderY
;
365 // Initialize colours
366 void wxStatusBarGeneric::InitColours()
369 #if defined(__WIN95__) || defined(__WXMAC__)
370 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
371 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
373 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
374 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
375 #elif defined(__WXPM__)
376 m_mediumShadowPen
= wxPen(wxColour(127, 127, 127), 1, wxSOLID
);
377 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
381 vColour
.Set(wxString("LIGHT GREY"));
382 SetBackgroundColour(vColour
);
383 vColour
.Set(wxString("BLACK"));
384 SetForegroundColour(vColour
);
386 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
387 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
391 // Responds to colour changes, and passes event on to children.
392 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
396 // Propagate the event to the non-top-level children
397 wxWindow::OnSysColourChanged(event
);
400 void wxStatusBarGeneric::SetMinHeight(int height
)
402 // check that this min height is not less than minimal height for the
406 dc
.GetTextExtent( wxT("X"), NULL
, &y
);
408 if ( height
> (11*y
)/10 )
410 SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, height
+ 2*m_borderY
);
414 void wxStatusBarGeneric::OnLeftDown(wxMouseEvent
& event
)
418 GetClientSize(&width
, &height
);
420 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
422 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
424 if (!GTK_IS_WINDOW (ancestor
))
427 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
431 gdk_window_get_origin( source
, &org_x
, &org_y
);
433 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
434 GDK_WINDOW_EDGE_SOUTH_EAST
,
436 org_x
+ event
.GetX(),
437 org_y
+ event
.GetY(),
449 void wxStatusBarGeneric::OnRightDown(wxMouseEvent
& event
)
453 GetClientSize(&width
, &height
);
455 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
457 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
459 if (!GTK_IS_WINDOW (ancestor
))
462 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
466 gdk_window_get_origin( source
, &org_x
, &org_y
);
468 gtk_window_begin_move_drag (GTK_WINDOW (ancestor
),
470 org_x
+ event
.GetX(),
471 org_y
+ event
.GetY(),
483 #endif // wxUSE_STATUSBAR