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);
95 SetFont(*wxSMALL_FONT
);
98 // Set the height according to the font and the border size
100 dc
.SetFont(GetFont());
103 dc
.GetTextExtent(_T("X"), NULL
, &y
);
105 int height
= (int)( (11*y
)/10 + 2*GetBorderY());
107 SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, height
);
115 wxSize
wxStatusBarGeneric::DoGetBestSize() const
119 // best width is the width of the parent
120 GetParent()->GetClientSize(&width
, NULL
);
122 // best height is as calculated above in Create
123 wxClientDC
dc((wxWindow
*)this);
124 dc
.SetFont(GetFont());
126 dc
.GetTextExtent(_T("X"), NULL
, &y
);
127 height
= (int)( (11*y
)/10 + 2*GetBorderY());
129 return wxSize(width
, height
);
132 void wxStatusBarGeneric::SetFieldsCount(int number
, const int *widths
)
134 wxASSERT_MSG( number
>= 0, _T("negative number of fields in wxStatusBar?") );
137 for(i
= m_nFields
; i
< number
; ++i
)
138 m_statusStrings
.Add( wxEmptyString
);
140 for (i
= m_nFields
- 1; i
>= number
; --i
)
141 m_statusStrings
.RemoveAt(i
);
143 // forget the old cached pixel widths
146 wxStatusBarBase::SetFieldsCount(number
, widths
);
148 wxASSERT_MSG( m_nFields
== (int)m_statusStrings
.GetCount(),
149 _T("This really should never happen, can we do away with m_nFields here?") );
152 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
154 wxCHECK_RET( (number
>= 0) && (number
< m_nFields
),
155 _T("invalid status bar field index") );
157 wxString oldText
= m_statusStrings
[number
];
160 m_statusStrings
[number
] = text
;
163 GetFieldRect(number
, rect
);
165 Refresh( true, &rect
);
169 wxString
wxStatusBarGeneric::GetStatusText(int n
) const
171 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), wxEmptyString
,
172 _T("invalid status bar field index") );
174 return m_statusStrings
[n
];
177 void wxStatusBarGeneric::SetStatusWidths(int n
, const int widths_field
[])
179 // only set status widths, when n == number of statuswindows
180 wxCHECK_RET( n
== m_nFields
, _T("status bar field count mismatch") );
182 // delete the old widths in any case - this function may be used to reset
183 // the widths to the default (all equal)
184 // MBN: this is incompatible with at least wxMSW and wxMAC and not
185 // documented, but let's keep it for now
188 // forget the old cached pixel widths
193 // not an error, see the comment above
198 wxStatusBarBase::SetStatusWidths(n
, widths_field
);
201 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
207 if (HasFlag( wxST_SIZEGRIP
))
210 GetClientSize(&width
, &height
);
212 gtk_paint_resize_grip( m_widget
->style
,
213 GTK_PIZZA(m_wxwindow
)->bin_window
,
214 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
218 GDK_WINDOW_EDGE_SOUTH_EAST
,
219 width
-height
-2, 1, height
-2, height
-3 );
225 dc
.SetFont(GetFont());
227 dc
.SetBackgroundMode(wxTRANSPARENT
);
232 vColor
= wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
);
233 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
236 for (int i
= 0; i
< m_nFields
; i
++)
240 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
245 GetFieldRect(i
, rect
);
247 wxString
text(GetStatusText(i
));
251 dc
.GetTextExtent(text
, &x
, &y
);
253 int xpos
= rect
.x
+ leftMargin
;
254 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
256 #if defined( __WXGTK__ ) || defined(__WXMAC__)
261 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
263 dc
.DrawText(text
, xpos
, ypos
);
265 dc
.DestroyClippingRegion();
268 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
271 GetFieldRect(i
, rect
);
273 int style
= wxSB_NORMAL
;
275 style
= m_statusStyles
[i
];
277 if (style
!= wxSB_FLAT
)
281 // Have grey background, plus 3-d border -
282 // One black rectangle.
283 // Inside this, left and top sides - dark grey. Bottom and right -
285 // Reverse it for wxSB_RAISED
287 dc
.SetPen((style
== wxSB_RAISED
) ? m_mediumShadowPen
: m_hilightPen
);
291 // Right and bottom lines
292 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
293 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
294 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
295 rect
.x
, rect
.y
+ rect
.height
);
297 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
299 // Left and top lines
300 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
302 dc
.DrawLine(rect
.x
, rect
.y
,
303 rect
.x
+ rect
.width
, rect
.y
);
306 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.height
+ 2,
307 rect
.x
, rect
.height
+ 2);
308 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
309 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
311 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
312 dc
.DrawLine(rect
.x
, rect
.y
,
313 rect
.x
+ rect
.width
, rect
.y
);
314 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
320 DrawFieldText(dc
, i
);
323 // Get the position and size of the field's internal bounding rectangle
324 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
326 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), false,
327 _T("invalid status bar field index") );
329 // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
332 GetSize(&width
, &height
);
334 GetClientSize(&width
, &height
);
337 // we cache m_widthsAbs between calls and recompute it if client
338 // width has changed (or when it is initially empty)
339 if ( m_widthsAbs
.IsEmpty() || (m_lastClientWidth
!= width
) )
341 wxConstCast(this, wxStatusBarGeneric
)->
342 m_widthsAbs
= CalculateAbsWidths(width
);
343 // remember last width for which we have recomputed the widths in pixels
344 wxConstCast(this, wxStatusBarGeneric
)->
345 m_lastClientWidth
= width
;
349 for ( int i
= 0; i
< n
; i
++ )
351 rect
.x
+= m_widthsAbs
[i
];
357 rect
.width
= m_widthsAbs
[n
] - 2*m_borderX
;
358 rect
.height
= height
- 2*m_borderY
;
363 // Initialize colours
364 void wxStatusBarGeneric::InitColours()
367 #if defined(__WIN95__) || defined(__WXMAC__)
368 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
369 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
371 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
372 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
373 #elif defined(__WXPM__)
374 m_mediumShadowPen
= wxPen(wxColour(127, 127, 127), 1, wxSOLID
);
375 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
379 vColour
.Set(wxString("LIGHT GREY"));
380 SetBackgroundColour(vColour
);
381 vColour
.Set(wxString("BLACK"));
382 SetForegroundColour(vColour
);
384 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
385 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
389 // Responds to colour changes, and passes event on to children.
390 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
394 // Propagate the event to the non-top-level children
395 wxWindow::OnSysColourChanged(event
);
398 void wxStatusBarGeneric::SetMinHeight(int height
)
400 // check that this min height is not less than minimal height for the
404 dc
.GetTextExtent( wxT("X"), NULL
, &y
);
406 if ( height
> (11*y
)/10 )
408 SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, height
+ 2*m_borderY
);
412 void wxStatusBarGeneric::OnLeftDown(wxMouseEvent
& event
)
416 GetClientSize(&width
, &height
);
418 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
420 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
422 if (!GTK_IS_WINDOW (ancestor
))
425 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
429 gdk_window_get_origin( source
, &org_x
, &org_y
);
431 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
432 GDK_WINDOW_EDGE_SOUTH_EAST
,
434 org_x
+ event
.GetX(),
435 org_y
+ event
.GetY(),
447 void wxStatusBarGeneric::OnRightDown(wxMouseEvent
& event
)
451 GetClientSize(&width
, &height
);
453 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
455 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
457 if (!GTK_IS_WINDOW (ancestor
))
460 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
464 gdk_window_get_origin( source
, &org_x
, &org_y
);
466 gtk_window_begin_move_drag (GTK_WINDOW (ancestor
),
468 org_x
+ event
.GetX(),
469 org_y
+ event
.GetY(),
481 #endif // wxUSE_STATUSBAR