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 m_statusStrings
[number
] = text
;
139 GetFieldRect(number
, rect
);
141 Refresh( TRUE
, &rect
);
144 wxString
wxStatusBarGeneric::GetStatusText(int n
) const
146 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), wxEmptyString
,
147 _T("invalid status bar field index") );
149 return m_statusStrings
[n
];
152 void wxStatusBarGeneric::SetStatusWidths(int n
, const int widths_field
[])
154 // only set status widths, when n == number of statuswindows
155 wxCHECK_RET( n
== m_nFields
, _T("status bar field count mismatch") );
157 // delete the old widths in any case - this function may be used to reset
158 // the widths to the default (all equal)
159 // MBN: this is incompatible with at least wxMSW and wxMAC and not
160 // documented, but let's keep it for now
163 // forget the old cached pixel widths
168 // not an error, see the comment above
173 wxStatusBarBase::SetStatusWidths(n
, widths_field
);
176 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
182 if (HasFlag( wxST_SIZEGRIP
))
185 GetClientSize(&width
, &height
);
187 gtk_paint_resize_grip( m_widget
->style
,
188 GTK_PIZZA(m_wxwindow
)->bin_window
,
189 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
193 GDK_WINDOW_EDGE_SOUTH_EAST
,
194 width
-height
-2, 1, height
-2, height
-3 );
200 dc
.SetFont(GetFont());
202 dc
.SetBackgroundMode(wxTRANSPARENT
);
207 vColor
= wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
);
208 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
211 for (int i
= 0; i
< m_nFields
; i
++)
215 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
220 GetFieldRect(i
, rect
);
222 wxString
text(GetStatusText(i
));
226 dc
.GetTextExtent(text
, &x
, &y
);
228 int xpos
= rect
.x
+ leftMargin
;
229 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
231 #if defined( __WXGTK__ ) || defined(__WXMAC__)
236 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
238 dc
.DrawText(text
, xpos
, ypos
);
240 dc
.DestroyClippingRegion();
243 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
246 GetFieldRect(i
, rect
);
249 // Have grey background, plus 3-d border -
250 // One black rectangle.
251 // Inside this, left and top sides - dark grey. Bottom and right -
254 dc
.SetPen(m_hilightPen
);
258 // Right and bottom white lines
259 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
260 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
261 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
262 rect
.x
, rect
.y
+ rect
.height
);
264 dc
.SetPen(m_mediumShadowPen
);
266 // Left and top grey lines
267 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
269 dc
.DrawLine(rect
.x
, rect
.y
,
270 rect
.x
+ rect
.width
, rect
.y
);
273 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.height
+ 2,
274 rect
.x
, rect
.height
+ 2);
275 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
276 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
278 dc
.SetPen(m_mediumShadowPen
);
279 dc
.DrawLine(rect
.x
, rect
.y
,
280 rect
.x
+ rect
.width
, rect
.y
);
281 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
286 DrawFieldText(dc
, i
);
289 // Get the position and size of the field's internal bounding rectangle
290 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
292 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), FALSE
,
293 _T("invalid status bar field index") );
295 // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
298 GetSize(&width
, &height
);
300 GetClientSize(&width
, &height
);
303 // we cache m_widthsAbs between calls and recompute it if client
304 // width has changed (or when it is initially empty)
305 if ( m_widthsAbs
.IsEmpty() || (m_lastClientWidth
!= width
) )
307 wxConstCast(this, wxStatusBarGeneric
)->
308 m_widthsAbs
= CalculateAbsWidths(width
);
309 // remember last width for which we have recomputed the widths in pixels
310 wxConstCast(this, wxStatusBarGeneric
)->
311 m_lastClientWidth
= width
;
315 for ( int i
= 0; i
< n
; i
++ )
317 rect
.x
+= m_widthsAbs
[i
];
323 rect
.width
= m_widthsAbs
[n
] - 2*m_borderX
;
324 rect
.height
= height
- 2*m_borderY
;
329 // Initialize colours
330 void wxStatusBarGeneric::InitColours()
333 #if defined(__WIN95__) || defined(__WXMAC__)
334 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
335 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
337 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
338 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
339 #elif defined(__WXPM__)
340 m_mediumShadowPen
= wxPen(wxColour(127, 127, 127), 1, wxSOLID
);
341 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
345 vColour
.Set(wxString("LIGHT GREY"));
346 SetBackgroundColour(vColour
);
347 vColour
.Set(wxString("BLACK"));
348 SetForegroundColour(vColour
);
349 m_defaultStatusBarFont
= *wxSMALL_FONT
;
351 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
352 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
356 m_defaultStatusBarFont
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
357 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
361 // Responds to colour changes, and passes event on to children.
362 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
367 // Propagate the event to the non-top-level children
368 wxWindow::OnSysColourChanged(event
);
371 void wxStatusBarGeneric::SetMinHeight(int height
)
373 // check that this min height is not less than minimal height for the
377 dc
.GetTextExtent( wxT("X"), NULL
, &y
);
379 if ( height
> (11*y
)/10 )
381 SetSize(-1, -1, -1, height
+ 2*m_borderY
);
385 void wxStatusBarGeneric::OnLeftDown(wxMouseEvent
& event
)
389 GetClientSize(&width
, &height
);
391 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
393 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
395 if (!GTK_IS_WINDOW (ancestor
))
398 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
402 gdk_window_get_origin( source
, &org_x
, &org_y
);
404 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
405 GDK_WINDOW_EDGE_SOUTH_EAST
,
407 org_x
+ event
.GetX(),
408 org_y
+ event
.GetY(),
420 void wxStatusBarGeneric::OnRightDown(wxMouseEvent
& event
)
424 GetClientSize(&width
, &height
);
426 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
428 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
430 if (!GTK_IS_WINDOW (ancestor
))
433 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
437 gdk_window_get_origin( source
, &org_x
, &org_y
);
439 gtk_window_begin_move_drag (GTK_WINDOW (ancestor
),
441 org_x
+ event
.GetX(),
442 org_y
+ event
.GetY(),
454 #endif // wxUSE_STATUSBAR