1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/statusbr.cpp
3 // Purpose: wxStatusBarGeneric class implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
24 #include "wx/settings.h"
25 #include "wx/dcclient.h"
29 #include "wx/gtk/private.h"
30 #include "wx/gtk/win_gtk.h"
33 #include "wx/statusbr.h"
35 // we only have to do it here when we use wxStatusBarGeneric in addition to the
36 // standard wxStatusBar class, if wxStatusBarGeneric is the same as
37 // wxStatusBar, then the corresponding IMPLEMENT_DYNAMIC_CLASS is already in
39 #if defined(__WXMAC__) || \
40 (defined(wxUSE_NATIVE_STATUSBAR) && wxUSE_NATIVE_STATUSBAR)
41 #include "wx/generic/statusbr.h"
43 IMPLEMENT_DYNAMIC_CLASS(wxStatusBarGeneric
, wxWindow
)
44 #endif // wxUSE_NATIVE_STATUSBAR
46 BEGIN_EVENT_TABLE(wxStatusBarGeneric
, wxWindow
)
47 EVT_PAINT(wxStatusBarGeneric::OnPaint
)
48 EVT_LEFT_DOWN(wxStatusBarGeneric::OnLeftDown
)
49 EVT_RIGHT_DOWN(wxStatusBarGeneric::OnRightDown
)
50 EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged
)
53 // Default status border dimensions
54 #define wxTHICK_LINE_BORDER 2
56 void wxStatusBarGeneric::Init()
58 m_borderX
= wxTHICK_LINE_BORDER
;
59 m_borderY
= wxTHICK_LINE_BORDER
;
62 wxStatusBarGeneric::~wxStatusBarGeneric()
66 bool wxStatusBarGeneric::Create(wxWindow
*parent
,
71 if ( !wxWindow::Create(parent
, id
,
72 wxDefaultPosition
, wxDefaultSize
,
73 style
| wxTAB_TRAVERSAL
, name
) )
76 // The status bar should have a themed background
77 SetThemeEnabled( true );
82 SetFont(*wxSMALL_FONT
);
85 // Set the height according to the font and the border size
87 dc
.SetFont(GetFont());
90 dc
.GetTextExtent(_T("X"), NULL
, &y
);
92 int height
= (int)( (11*y
)/10 + 2*GetBorderY());
94 SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, height
);
102 wxSize
wxStatusBarGeneric::DoGetBestSize() const
106 // best width is the width of the parent
107 GetParent()->GetClientSize(&width
, NULL
);
109 // best height is as calculated above in Create
110 wxClientDC
dc((wxWindow
*)this);
111 dc
.SetFont(GetFont());
113 dc
.GetTextExtent(_T("X"), NULL
, &y
);
114 height
= (int)( (11*y
)/10 + 2*GetBorderY());
116 return wxSize(width
, height
);
119 void wxStatusBarGeneric::SetFieldsCount(int number
, const int *widths
)
121 wxASSERT_MSG( number
>= 0, _T("negative number of fields in wxStatusBar?") );
124 for(i
= m_nFields
; i
< number
; ++i
)
125 m_statusStrings
.Add( wxEmptyString
);
127 for (i
= m_nFields
- 1; i
>= number
; --i
)
128 m_statusStrings
.RemoveAt(i
);
130 // forget the old cached pixel widths
133 wxStatusBarBase::SetFieldsCount(number
, widths
);
135 wxASSERT_MSG( m_nFields
== (int)m_statusStrings
.GetCount(),
136 _T("This really should never happen, can we do away with m_nFields here?") );
139 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
141 wxCHECK_RET( (number
>= 0) && (number
< m_nFields
),
142 _T("invalid status bar field index") );
144 wxString oldText
= m_statusStrings
[number
];
147 m_statusStrings
[number
] = text
;
150 GetFieldRect(number
, rect
);
152 Refresh( true, &rect
);
156 wxString
wxStatusBarGeneric::GetStatusText(int n
) const
158 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), wxEmptyString
,
159 _T("invalid status bar field index") );
161 return m_statusStrings
[n
];
164 void wxStatusBarGeneric::SetStatusWidths(int n
, const int widths_field
[])
166 // only set status widths, when n == number of statuswindows
167 wxCHECK_RET( n
== m_nFields
, _T("status bar field count mismatch") );
169 // delete the old widths in any case - this function may be used to reset
170 // the widths to the default (all equal)
171 // MBN: this is incompatible with at least wxMSW and wxMAC and not
172 // documented, but let's keep it for now
175 // forget the old cached pixel widths
180 // not an error, see the comment above
185 wxStatusBarBase::SetStatusWidths(n
, widths_field
);
188 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
194 if (HasFlag( wxST_SIZEGRIP
))
197 GetClientSize(&width
, &height
);
199 gtk_paint_resize_grip( m_widget
->style
,
200 GTK_PIZZA(m_wxwindow
)->bin_window
,
201 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
205 GDK_WINDOW_EDGE_SOUTH_EAST
,
206 width
-height
-2, 1, height
-2, height
-3 );
212 dc
.SetFont(GetFont());
214 dc
.SetBackgroundMode(wxTRANSPARENT
);
219 vColor
= wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
);
220 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
223 for (int i
= 0; i
< m_nFields
; i
++)
227 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
232 GetFieldRect(i
, rect
);
234 wxString
text(GetStatusText(i
));
238 dc
.GetTextExtent(text
, &x
, &y
);
240 int xpos
= rect
.x
+ leftMargin
;
241 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
243 #if defined( __WXGTK__ ) || defined(__WXMAC__)
248 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
250 dc
.DrawText(text
, xpos
, ypos
);
252 dc
.DestroyClippingRegion();
255 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
258 GetFieldRect(i
, rect
);
260 int style
= wxSB_NORMAL
;
262 style
= m_statusStyles
[i
];
264 if (style
!= wxSB_FLAT
)
268 // Have grey background, plus 3-d border -
269 // One black rectangle.
270 // Inside this, left and top sides - dark grey. Bottom and right -
272 // Reverse it for wxSB_RAISED
274 dc
.SetPen((style
== wxSB_RAISED
) ? m_mediumShadowPen
: m_hilightPen
);
278 // Right and bottom lines
279 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
280 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
281 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
282 rect
.x
, rect
.y
+ rect
.height
);
284 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
286 // Left and top lines
287 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
289 dc
.DrawLine(rect
.x
, rect
.y
,
290 rect
.x
+ rect
.width
, rect
.y
);
293 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.height
+ 2,
294 rect
.x
, rect
.height
+ 2);
295 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
296 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
298 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
299 dc
.DrawLine(rect
.x
, rect
.y
,
300 rect
.x
+ rect
.width
, rect
.y
);
301 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
307 DrawFieldText(dc
, i
);
310 // Get the position and size of the field's internal bounding rectangle
311 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
313 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), false,
314 _T("invalid status bar field index") );
316 // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
319 GetSize(&width
, &height
);
321 GetClientSize(&width
, &height
);
324 // we cache m_widthsAbs between calls and recompute it if client
325 // width has changed (or when it is initially empty)
326 if ( m_widthsAbs
.IsEmpty() || (m_lastClientWidth
!= width
) )
328 wxConstCast(this, wxStatusBarGeneric
)->
329 m_widthsAbs
= CalculateAbsWidths(width
);
330 // remember last width for which we have recomputed the widths in pixels
331 wxConstCast(this, wxStatusBarGeneric
)->
332 m_lastClientWidth
= width
;
336 for ( int i
= 0; i
< n
; i
++ )
338 rect
.x
+= m_widthsAbs
[i
];
344 rect
.width
= m_widthsAbs
[n
] - 2*m_borderX
;
345 rect
.height
= height
- 2*m_borderY
;
350 // Initialize colours
351 void wxStatusBarGeneric::InitColours()
354 #if defined(__WXMSW__) || defined(__WXMAC__)
355 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
356 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
358 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
359 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
360 #elif defined(__WXPM__)
361 m_mediumShadowPen
= wxPen(wxColour(127, 127, 127), 1, wxSOLID
);
362 m_hilightPen
= wxPen(_T("WHITE"), 1, wxSOLID
);
366 vColour
.Set(wxString(_T("LIGHT GREY")));
367 SetBackgroundColour(vColour
);
368 vColour
.Set(wxString(_T("BLACK")));
369 SetForegroundColour(vColour
);
371 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
372 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
376 // Responds to colour changes, and passes event on to children.
377 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
381 // Propagate the event to the non-top-level children
382 wxWindow::OnSysColourChanged(event
);
385 void wxStatusBarGeneric::SetMinHeight(int height
)
387 // check that this min height is not less than minimal height for the
391 dc
.GetTextExtent( wxT("X"), NULL
, &y
);
393 if ( height
> (11*y
)/10 )
395 SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, height
+ 2*m_borderY
);
399 void wxStatusBarGeneric::OnLeftDown(wxMouseEvent
& event
)
403 GetClientSize(&width
, &height
);
405 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
407 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
409 if (!GTK_IS_WINDOW (ancestor
))
412 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
416 gdk_window_get_origin( source
, &org_x
, &org_y
);
418 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
419 GDK_WINDOW_EDGE_SOUTH_EAST
,
421 org_x
+ event
.GetX(),
422 org_y
+ event
.GetY(),
434 void wxStatusBarGeneric::OnRightDown(wxMouseEvent
& event
)
438 GetClientSize(&width
, &height
);
440 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
442 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
444 if (!GTK_IS_WINDOW (ancestor
))
447 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
451 gdk_window_get_origin( source
, &org_x
, &org_y
);
453 gtk_window_begin_move_drag (GTK_WINDOW (ancestor
),
455 org_x
+ event
.GetX(),
456 org_y
+ event
.GetY(),
468 #endif // wxUSE_STATUSBAR