1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/statusbr.cpp
3 // Purpose: wxStatusBarGeneric class implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
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
);
110 void wxStatusBarGeneric::SetFieldsCount(int number
, const int *widths
)
112 wxASSERT_MSG( number
>= 0, _T("negative number of fields in wxStatusBar?") );
115 for(i
= m_nFields
; i
< number
; ++i
)
116 m_statusStrings
.Add( wxEmptyString
);
118 for (i
= m_nFields
- 1; i
>= number
; --i
)
119 m_statusStrings
.RemoveAt(i
);
123 wxASSERT_MSG( m_nFields
== (int)m_statusStrings
.GetCount(),
124 _T("This really should never happen, can we do away with m_nFields here?") );
126 SetStatusWidths(number
, widths
);
129 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
131 wxCHECK_RET( (number
>= 0) && (number
< m_nFields
),
132 _T("invalid status bar field index") );
134 m_statusStrings
[number
] = text
;
137 GetFieldRect(number
, rect
);
139 Refresh( TRUE
, &rect
);
142 wxString
wxStatusBarGeneric::GetStatusText(int n
) const
144 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), wxEmptyString
,
145 _T("invalid status bar field index") );
147 return m_statusStrings
[n
];
150 void wxStatusBarGeneric::SetStatusWidths(int n
, const int widths_field
[])
152 // only set status widths, when n == number of statuswindows
153 wxCHECK_RET( n
== m_nFields
, _T("status bar field count mismatch") );
155 // delete the old widths in any case - this function may be used to reset
156 // the widths to the default (all equal)
157 // MBN: this is incompatible with at least wxMSW and wxMAC and not
158 // documented, but let's keep it for now
161 // forget the old cached pixel widths
166 // not an error, see the comment above
171 wxStatusBarBase::SetStatusWidths(n
, widths_field
);
174 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
180 if (HasFlag( wxST_SIZEGRIP
))
183 GetClientSize(&width
, &height
);
185 gtk_paint_resize_grip( m_widget
->style
,
186 GTK_PIZZA(m_wxwindow
)->bin_window
,
187 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
191 GDK_WINDOW_EDGE_SOUTH_EAST
,
192 width
-height
-2, 1, height
-2, height
-3 );
198 dc
.SetFont(GetFont());
200 dc
.SetBackgroundMode(wxTRANSPARENT
);
205 vColor
= wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
);
206 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
209 for (int i
= 0; i
< m_nFields
; i
++)
213 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
218 GetFieldRect(i
, rect
);
220 wxString
text(GetStatusText(i
));
224 dc
.GetTextExtent(text
, &x
, &y
);
226 int xpos
= rect
.x
+ leftMargin
;
227 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
229 #if defined( __WXGTK__ ) || defined(__WXMAC__)
234 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
236 dc
.DrawText(text
, xpos
, ypos
);
238 dc
.DestroyClippingRegion();
241 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
244 GetFieldRect(i
, rect
);
247 // Have grey background, plus 3-d border -
248 // One black rectangle.
249 // Inside this, left and top sides - dark grey. Bottom and right -
252 dc
.SetPen(m_hilightPen
);
256 // Right and bottom white lines
257 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
258 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
259 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
260 rect
.x
, rect
.y
+ rect
.height
);
262 dc
.SetPen(m_mediumShadowPen
);
264 // Left and top grey lines
265 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
267 dc
.DrawLine(rect
.x
, rect
.y
,
268 rect
.x
+ rect
.width
, rect
.y
);
271 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.height
+ 2,
272 rect
.x
, rect
.height
+ 2);
273 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
274 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
276 dc
.SetPen(m_mediumShadowPen
);
277 dc
.DrawLine(rect
.x
, rect
.y
,
278 rect
.x
+ rect
.width
, rect
.y
);
279 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
284 DrawFieldText(dc
, i
);
287 // Get the position and size of the field's internal bounding rectangle
288 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
290 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), FALSE
,
291 _T("invalid status bar field index") );
293 // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
296 GetSize(&width
, &height
);
298 GetClientSize(&width
, &height
);
301 // we cache m_widthsAbs between calls and recompute it if client
302 // width has changed (or when it is initially empty)
303 if ( m_widthsAbs
.IsEmpty() || (m_lastClientWidth
!= width
) )
305 wxConstCast(this, wxStatusBarGeneric
)->
306 m_widthsAbs
= CalculateAbsWidths(width
);
307 // remember last width for which we have recomputed the widths in pixels
308 wxConstCast(this, wxStatusBarGeneric
)->
309 m_lastClientWidth
= width
;
313 for ( int i
= 0; i
< n
; i
++ )
315 rect
.x
+= m_widthsAbs
[i
];
321 rect
.width
= m_widthsAbs
[n
] - 2*m_borderX
;
322 rect
.height
= height
- 2*m_borderY
;
327 // Initialize colours
328 void wxStatusBarGeneric::InitColours()
331 #if defined(__WIN95__)
332 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
333 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
335 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
336 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
337 #elif defined(__WXPM__)
338 m_mediumShadowPen
= wxPen(wxColour(127, 127, 127), 1, wxSOLID
);
339 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
343 vColour
.Set(wxString("LIGHT GREY"));
344 SetBackgroundColour(vColour
);
345 vColour
.Set(wxString("BLACK"));
346 SetForegroundColour(vColour
);
347 m_defaultStatusBarFont
= *wxSMALL_FONT
;
349 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
350 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
354 m_defaultStatusBarFont
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
355 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
359 // Responds to colour changes, and passes event on to children.
360 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
365 // Propagate the event to the non-top-level children
366 wxWindow::OnSysColourChanged(event
);
369 void wxStatusBarGeneric::SetMinHeight(int height
)
371 // check that this min height is not less than minimal height for the
375 dc
.GetTextExtent( wxT("X"), NULL
, &y
);
377 if ( height
> (11*y
)/10 )
379 SetSize(-1, -1, -1, height
+ 2*m_borderY
);
383 void wxStatusBarGeneric::OnLeftDown(wxMouseEvent
& event
)
387 GetClientSize(&width
, &height
);
389 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
391 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
393 if (!GTK_IS_WINDOW (ancestor
))
396 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
400 gdk_window_get_origin( source
, &org_x
, &org_y
);
402 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
403 GDK_WINDOW_EDGE_SOUTH_EAST
,
405 org_x
+ event
.GetX(),
406 org_y
+ event
.GetY(),
418 void wxStatusBarGeneric::OnRightDown(wxMouseEvent
& event
)
422 GetClientSize(&width
, &height
);
424 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
426 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
428 if (!GTK_IS_WINDOW (ancestor
))
431 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
435 gdk_window_get_origin( source
, &org_x
, &org_y
);
437 gtk_window_begin_move_drag (GTK_WINDOW (ancestor
),
439 org_x
+ event
.GetX(),
440 org_y
+ event
.GetY(),
452 #endif // wxUSE_STATUSBAR