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
);
113 wxSize
wxStatusBarGeneric::DoGetBestSize() const
117 // best width is the width of the parent
118 GetParent()->GetClientSize(&width
, NULL
);
120 // best height is as calculated above in Create
121 wxClientDC
dc((wxWindow
*)this);
122 dc
.SetFont(GetFont());
124 dc
.GetTextExtent(_T("X"), NULL
, &y
);
125 height
= (int)( (11*y
)/10 + 2*GetBorderY());
127 return wxSize(width
, height
);
130 void wxStatusBarGeneric::SetFieldsCount(int number
, const int *widths
)
132 wxASSERT_MSG( number
>= 0, _T("negative number of fields in wxStatusBar?") );
135 for(i
= m_nFields
; i
< number
; ++i
)
136 m_statusStrings
.Add( wxEmptyString
);
138 for (i
= m_nFields
- 1; i
>= number
; --i
)
139 m_statusStrings
.RemoveAt(i
);
143 wxASSERT_MSG( m_nFields
== (int)m_statusStrings
.GetCount(),
144 _T("This really should never happen, can we do away with m_nFields here?") );
146 SetStatusWidths(number
, widths
);
149 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
151 wxCHECK_RET( (number
>= 0) && (number
< m_nFields
),
152 _T("invalid status bar field index") );
154 wxString oldText
= m_statusStrings
[number
];
157 m_statusStrings
[number
] = text
;
160 GetFieldRect(number
, rect
);
162 Refresh( TRUE
, &rect
);
166 wxString
wxStatusBarGeneric::GetStatusText(int n
) const
168 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), 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( n
== m_nFields
, _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
185 // forget the old cached pixel widths
190 // not an error, see the comment above
195 wxStatusBarBase::SetStatusWidths(n
, widths_field
);
198 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
204 if (HasFlag( wxST_SIZEGRIP
))
207 GetClientSize(&width
, &height
);
209 gtk_paint_resize_grip( m_widget
->style
,
210 GTK_PIZZA(m_wxwindow
)->bin_window
,
211 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
215 GDK_WINDOW_EDGE_SOUTH_EAST
,
216 width
-height
-2, 1, height
-2, height
-3 );
222 dc
.SetFont(GetFont());
224 dc
.SetBackgroundMode(wxTRANSPARENT
);
229 vColor
= wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
);
230 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
233 for (int i
= 0; i
< m_nFields
; i
++)
237 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
242 GetFieldRect(i
, rect
);
244 wxString
text(GetStatusText(i
));
248 dc
.GetTextExtent(text
, &x
, &y
);
250 int xpos
= rect
.x
+ leftMargin
;
251 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
253 #if defined( __WXGTK__ ) || defined(__WXMAC__)
258 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
260 dc
.DrawText(text
, xpos
, ypos
);
262 dc
.DestroyClippingRegion();
265 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
268 GetFieldRect(i
, rect
);
271 // Have grey background, plus 3-d border -
272 // One black rectangle.
273 // Inside this, left and top sides - dark grey. Bottom and right -
276 dc
.SetPen(m_hilightPen
);
280 // Right and bottom white lines
281 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
282 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
283 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
284 rect
.x
, rect
.y
+ rect
.height
);
286 dc
.SetPen(m_mediumShadowPen
);
288 // Left and top grey lines
289 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
291 dc
.DrawLine(rect
.x
, rect
.y
,
292 rect
.x
+ rect
.width
, rect
.y
);
295 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.height
+ 2,
296 rect
.x
, rect
.height
+ 2);
297 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
298 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
300 dc
.SetPen(m_mediumShadowPen
);
301 dc
.DrawLine(rect
.x
, rect
.y
,
302 rect
.x
+ rect
.width
, rect
.y
);
303 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
308 DrawFieldText(dc
, i
);
311 // Get the position and size of the field's internal bounding rectangle
312 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
314 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), FALSE
,
315 _T("invalid status bar field index") );
317 // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
320 GetSize(&width
, &height
);
322 GetClientSize(&width
, &height
);
325 // we cache m_widthsAbs between calls and recompute it if client
326 // width has changed (or when it is initially empty)
327 if ( m_widthsAbs
.IsEmpty() || (m_lastClientWidth
!= width
) )
329 wxConstCast(this, wxStatusBarGeneric
)->
330 m_widthsAbs
= CalculateAbsWidths(width
);
331 // remember last width for which we have recomputed the widths in pixels
332 wxConstCast(this, wxStatusBarGeneric
)->
333 m_lastClientWidth
= width
;
337 for ( int i
= 0; i
< n
; i
++ )
339 rect
.x
+= m_widthsAbs
[i
];
345 rect
.width
= m_widthsAbs
[n
] - 2*m_borderX
;
346 rect
.height
= height
- 2*m_borderY
;
351 // Initialize colours
352 void wxStatusBarGeneric::InitColours()
355 #if defined(__WIN95__) || defined(__WXMAC__)
356 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
357 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
359 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
360 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
361 #elif defined(__WXPM__)
362 m_mediumShadowPen
= wxPen(wxColour(127, 127, 127), 1, wxSOLID
);
363 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
367 vColour
.Set(wxString("LIGHT GREY"));
368 SetBackgroundColour(vColour
);
369 vColour
.Set(wxString("BLACK"));
370 SetForegroundColour(vColour
);
371 m_defaultStatusBarFont
= *wxSMALL_FONT
;
373 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
374 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
378 m_defaultStatusBarFont
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
379 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
383 // Responds to colour changes, and passes event on to children.
384 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
389 // Propagate the event to the non-top-level children
390 wxWindow::OnSysColourChanged(event
);
393 void wxStatusBarGeneric::SetMinHeight(int height
)
395 // check that this min height is not less than minimal height for the
399 dc
.GetTextExtent( wxT("X"), NULL
, &y
);
401 if ( height
> (11*y
)/10 )
403 SetSize(-1, -1, -1, height
+ 2*m_borderY
);
407 void wxStatusBarGeneric::OnLeftDown(wxMouseEvent
& event
)
411 GetClientSize(&width
, &height
);
413 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
415 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
417 if (!GTK_IS_WINDOW (ancestor
))
420 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
424 gdk_window_get_origin( source
, &org_x
, &org_y
);
426 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
427 GDK_WINDOW_EDGE_SOUTH_EAST
,
429 org_x
+ event
.GetX(),
430 org_y
+ event
.GetY(),
442 void wxStatusBarGeneric::OnRightDown(wxMouseEvent
& event
)
446 GetClientSize(&width
, &height
);
448 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
450 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
452 if (!GTK_IS_WINDOW (ancestor
))
455 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
459 gdk_window_get_origin( source
, &org_x
, &org_y
);
461 gtk_window_begin_move_drag (GTK_WINDOW (ancestor
),
463 org_x
+ event
.GetX(),
464 org_y
+ event
.GetY(),
476 #endif // wxUSE_STATUSBAR