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"
21 #include "wx/statusbr.h"
24 #include "wx/settings.h"
25 #include "wx/dcclient.h"
30 #include "wx/gtk/win_gtk.h"
33 // we only have to do it here when we use wxStatusBarGeneric in addition to the
34 // standard wxStatusBar class, if wxStatusBarGeneric is the same as
35 // wxStatusBar, then the corresponding IMPLEMENT_DYNAMIC_CLASS is already in
37 #if defined(__WXMAC__) || \
38 (defined(wxUSE_NATIVE_STATUSBAR) && wxUSE_NATIVE_STATUSBAR)
39 #include "wx/generic/statusbr.h"
41 IMPLEMENT_DYNAMIC_CLASS(wxStatusBarGeneric
, wxWindow
)
42 #endif // wxUSE_NATIVE_STATUSBAR
44 BEGIN_EVENT_TABLE(wxStatusBarGeneric
, wxWindow
)
45 EVT_PAINT(wxStatusBarGeneric::OnPaint
)
46 EVT_LEFT_DOWN(wxStatusBarGeneric::OnLeftDown
)
47 EVT_RIGHT_DOWN(wxStatusBarGeneric::OnRightDown
)
48 EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged
)
51 // Default status border dimensions
52 #define wxTHICK_LINE_BORDER 2
54 void wxStatusBarGeneric::Init()
56 m_borderX
= wxTHICK_LINE_BORDER
;
57 m_borderY
= wxTHICK_LINE_BORDER
;
60 wxStatusBarGeneric::~wxStatusBarGeneric()
64 bool wxStatusBarGeneric::Create(wxWindow
*parent
,
69 style
|= wxTAB_TRAVERSAL
| wxFULL_REPAINT_ON_RESIZE
;
70 if ( !wxWindow::Create(parent
, id
,
71 wxDefaultPosition
, wxDefaultSize
,
75 // The status bar should have a themed background
76 SetThemeEnabled( true );
81 SetFont(*wxSMALL_FONT
);
86 // Set the height according to the font and the border size
88 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
);
154 // it's common to show some text in the status bar before starting a
155 // relatively lengthy operation, ensure that the text is shown to the
156 // user immediately and not after the lengthy operation end
161 wxString
wxStatusBarGeneric::GetStatusText(int n
) const
163 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), wxEmptyString
,
164 _T("invalid status bar field index") );
166 return m_statusStrings
[n
];
169 void wxStatusBarGeneric::SetStatusWidths(int n
, const int widths_field
[])
171 // only set status widths, when n == number of statuswindows
172 wxCHECK_RET( n
== m_nFields
, _T("status bar field count mismatch") );
174 // delete the old widths in any case - this function may be used to reset
175 // the widths to the default (all equal)
176 // MBN: this is incompatible with at least wxMSW and wxMAC and not
177 // documented, but let's keep it for now
180 // forget the old cached pixel widths
185 // not an error, see the comment above
190 wxStatusBarBase::SetStatusWidths(n
, widths_field
);
193 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
199 if (HasFlag( wxST_SIZEGRIP
))
202 GetClientSize(&width
, &height
);
204 if (GetLayoutDirection() == wxLayout_RightToLeft
)
206 gtk_paint_resize_grip( m_widget
->style
,
207 GTK_PIZZA(m_wxwindow
)->bin_window
,
208 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
212 GDK_WINDOW_EDGE_SOUTH_WEST
,
213 2, 2, height
-2, height
-4 );
217 gtk_paint_resize_grip( m_widget
->style
,
218 GTK_PIZZA(m_wxwindow
)->bin_window
,
219 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
223 GDK_WINDOW_EDGE_SOUTH_EAST
,
224 width
-height
-2, 2, height
-2, height
-4 );
230 dc
.SetFont(GetFont());
232 dc
.SetBackgroundMode(wxTRANSPARENT
);
237 vColor
= wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
);
238 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
241 for (int i
= 0; i
< m_nFields
; i
++)
245 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
250 GetFieldRect(i
, rect
);
252 wxString
text(GetStatusText(i
));
256 dc
.GetTextExtent(text
, &x
, &y
);
258 int xpos
= rect
.x
+ leftMargin
;
259 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
261 #if defined( __WXGTK__ ) || defined(__WXMAC__)
266 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
268 dc
.DrawText(text
, xpos
, ypos
);
270 dc
.DestroyClippingRegion();
273 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
276 GetFieldRect(i
, rect
);
278 int style
= wxSB_NORMAL
;
280 style
= m_statusStyles
[i
];
282 if (style
!= wxSB_FLAT
)
286 // Have grey background, plus 3-d border -
287 // One black rectangle.
288 // Inside this, left and top sides - dark grey. Bottom and right -
290 // Reverse it for wxSB_RAISED
292 dc
.SetPen((style
== wxSB_RAISED
) ? m_mediumShadowPen
: m_hilightPen
);
296 // Right and bottom lines
297 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
298 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
299 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
300 rect
.x
, rect
.y
+ rect
.height
);
302 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
304 // Left and top lines
305 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
307 dc
.DrawLine(rect
.x
, rect
.y
,
308 rect
.x
+ rect
.width
, rect
.y
);
311 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.height
+ 2,
312 rect
.x
, rect
.height
+ 2);
313 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
314 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
316 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
317 dc
.DrawLine(rect
.x
, rect
.y
,
318 rect
.x
+ rect
.width
, rect
.y
);
319 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
325 DrawFieldText(dc
, i
);
328 // Get the position and size of the field's internal bounding rectangle
329 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
331 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), false,
332 _T("invalid status bar field index") );
334 // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
337 GetSize(&width
, &height
);
339 GetClientSize(&width
, &height
);
342 // we cache m_widthsAbs between calls and recompute it if client
343 // width has changed (or when it is initially empty)
344 if ( m_widthsAbs
.IsEmpty() || (m_lastClientWidth
!= width
) )
346 wxConstCast(this, wxStatusBarGeneric
)->
347 m_widthsAbs
= CalculateAbsWidths(width
);
348 // remember last width for which we have recomputed the widths in pixels
349 wxConstCast(this, wxStatusBarGeneric
)->
350 m_lastClientWidth
= width
;
354 for ( int i
= 0; i
< n
; i
++ )
356 rect
.x
+= m_widthsAbs
[i
];
362 rect
.width
= m_widthsAbs
[n
] - 2*m_borderX
;
363 rect
.height
= height
- 2*m_borderY
;
368 // Initialize colours
369 void wxStatusBarGeneric::InitColours()
372 #if defined(__WXMSW__) || defined(__WXMAC__)
373 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
374 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
376 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
377 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
378 #elif defined(__WXPM__)
379 m_mediumShadowPen
= wxPen(wxColour(127, 127, 127), 1, wxSOLID
);
380 m_hilightPen
= *wxWHITE_PEN
;
382 SetBackgroundColour(*wxLIGHT_GREY
);
383 SetForegroundColour(*wxBLACK
);
385 m_mediumShadowPen
= *wxGREY_PEN
;
386 m_hilightPen
= *wxWHITE_PEN
;
390 // Responds to colour changes, and passes event on to children.
391 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
395 // Propagate the event to the non-top-level children
396 wxWindow::OnSysColourChanged(event
);
399 void wxStatusBarGeneric::SetMinHeight(int height
)
401 // check that this min height is not less than minimal height for the
405 dc
.GetTextExtent( wxT("X"), NULL
, &y
);
407 if ( height
> (11*y
)/10 )
409 SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, height
+ 2*m_borderY
);
413 void wxStatusBarGeneric::OnLeftDown(wxMouseEvent
& event
)
417 GetClientSize(&width
, &height
);
419 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
421 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
423 if (!GTK_IS_WINDOW (ancestor
))
426 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
430 gdk_window_get_origin( source
, &org_x
, &org_y
);
432 if (GetLayoutDirection() == wxLayout_RightToLeft
)
434 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
435 GDK_WINDOW_EDGE_SOUTH_WEST
,
437 org_x
- event
.GetX() + GetSize().x
,
438 org_y
+ event
.GetY(),
443 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
444 GDK_WINDOW_EDGE_SOUTH_EAST
,
446 org_x
+ event
.GetX(),
447 org_y
+ event
.GetY(),
460 void wxStatusBarGeneric::OnRightDown(wxMouseEvent
& event
)
464 GetClientSize(&width
, &height
);
466 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
468 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
470 if (!GTK_IS_WINDOW (ancestor
))
473 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
477 gdk_window_get_origin( source
, &org_x
, &org_y
);
479 gtk_window_begin_move_drag (GTK_WINDOW (ancestor
),
481 org_x
+ event
.GetX(),
482 org_y
+ event
.GetY(),
494 #endif // wxUSE_STATUSBAR