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()
71 bool wxStatusBarGeneric::Create(wxWindow
*parent
,
76 if ( !wxWindow::Create(parent
, id
,
77 wxDefaultPosition
, wxDefaultSize
,
78 style
| wxTAB_TRAVERSAL
, name
) )
81 // The status bar should have a themed background
82 SetThemeEnabled( true );
87 SetFont(*wxSMALL_FONT
);
90 // Set the height according to the font and the border size
92 dc
.SetFont(GetFont());
95 dc
.GetTextExtent(_T("X"), NULL
, &y
);
97 int height
= (int)( (11*y
)/10 + 2*GetBorderY());
99 SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, height
);
107 wxSize
wxStatusBarGeneric::DoGetBestSize() const
111 // best width is the width of the parent
112 GetParent()->GetClientSize(&width
, NULL
);
114 // best height is as calculated above in Create
115 wxClientDC
dc((wxWindow
*)this);
116 dc
.SetFont(GetFont());
118 dc
.GetTextExtent(_T("X"), NULL
, &y
);
119 height
= (int)( (11*y
)/10 + 2*GetBorderY());
121 return wxSize(width
, height
);
124 void wxStatusBarGeneric::SetFieldsCount(int number
, const int *widths
)
126 wxASSERT_MSG( number
>= 0, _T("negative number of fields in wxStatusBar?") );
129 for(i
= m_nFields
; i
< number
; ++i
)
130 m_statusStrings
.Add( wxEmptyString
);
132 for (i
= m_nFields
- 1; i
>= number
; --i
)
133 m_statusStrings
.RemoveAt(i
);
135 // forget the old cached pixel widths
138 wxStatusBarBase::SetFieldsCount(number
, widths
);
140 wxASSERT_MSG( m_nFields
== (int)m_statusStrings
.GetCount(),
141 _T("This really should never happen, can we do away with m_nFields here?") );
144 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
146 wxCHECK_RET( (number
>= 0) && (number
< m_nFields
),
147 _T("invalid status bar field index") );
149 wxString oldText
= m_statusStrings
[number
];
152 m_statusStrings
[number
] = text
;
155 GetFieldRect(number
, rect
);
157 Refresh( true, &rect
);
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 gtk_paint_resize_grip( m_widget
->style
,
205 GTK_PIZZA(m_wxwindow
)->bin_window
,
206 (GtkStateType
) GTK_WIDGET_STATE (m_widget
),
210 GDK_WINDOW_EDGE_SOUTH_EAST
,
211 width
-height
-2, 1, height
-2, height
-3 );
217 dc
.SetFont(GetFont());
219 dc
.SetBackgroundMode(wxTRANSPARENT
);
224 vColor
= wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
);
225 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
228 for (int i
= 0; i
< m_nFields
; i
++)
232 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
237 GetFieldRect(i
, rect
);
239 wxString
text(GetStatusText(i
));
243 dc
.GetTextExtent(text
, &x
, &y
);
245 int xpos
= rect
.x
+ leftMargin
;
246 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
248 #if defined( __WXGTK__ ) || defined(__WXMAC__)
253 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
255 dc
.DrawText(text
, xpos
, ypos
);
257 dc
.DestroyClippingRegion();
260 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
263 GetFieldRect(i
, rect
);
265 int style
= wxSB_NORMAL
;
267 style
= m_statusStyles
[i
];
269 if (style
!= wxSB_FLAT
)
273 // Have grey background, plus 3-d border -
274 // One black rectangle.
275 // Inside this, left and top sides - dark grey. Bottom and right -
277 // Reverse it for wxSB_RAISED
279 dc
.SetPen((style
== wxSB_RAISED
) ? m_mediumShadowPen
: m_hilightPen
);
283 // Right and bottom lines
284 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
285 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
286 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
287 rect
.x
, rect
.y
+ rect
.height
);
289 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
291 // Left and top lines
292 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
294 dc
.DrawLine(rect
.x
, rect
.y
,
295 rect
.x
+ rect
.width
, rect
.y
);
298 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.height
+ 2,
299 rect
.x
, rect
.height
+ 2);
300 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
301 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
303 dc
.SetPen((style
== wxSB_RAISED
) ? m_hilightPen
: m_mediumShadowPen
);
304 dc
.DrawLine(rect
.x
, rect
.y
,
305 rect
.x
+ rect
.width
, rect
.y
);
306 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
312 DrawFieldText(dc
, i
);
315 // Get the position and size of the field's internal bounding rectangle
316 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
318 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), false,
319 _T("invalid status bar field index") );
321 // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
324 GetSize(&width
, &height
);
326 GetClientSize(&width
, &height
);
329 // we cache m_widthsAbs between calls and recompute it if client
330 // width has changed (or when it is initially empty)
331 if ( m_widthsAbs
.IsEmpty() || (m_lastClientWidth
!= width
) )
333 wxConstCast(this, wxStatusBarGeneric
)->
334 m_widthsAbs
= CalculateAbsWidths(width
);
335 // remember last width for which we have recomputed the widths in pixels
336 wxConstCast(this, wxStatusBarGeneric
)->
337 m_lastClientWidth
= width
;
341 for ( int i
= 0; i
< n
; i
++ )
343 rect
.x
+= m_widthsAbs
[i
];
349 rect
.width
= m_widthsAbs
[n
] - 2*m_borderX
;
350 rect
.height
= height
- 2*m_borderY
;
355 // Initialize colours
356 void wxStatusBarGeneric::InitColours()
359 #if defined(__WIN95__) || defined(__WXMAC__)
360 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
361 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
363 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
364 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
365 #elif defined(__WXPM__)
366 m_mediumShadowPen
= wxPen(wxColour(127, 127, 127), 1, wxSOLID
);
367 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
371 vColour
.Set(wxString("LIGHT GREY"));
372 SetBackgroundColour(vColour
);
373 vColour
.Set(wxString("BLACK"));
374 SetForegroundColour(vColour
);
376 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
377 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
381 // Responds to colour changes, and passes event on to children.
382 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
386 // Propagate the event to the non-top-level children
387 wxWindow::OnSysColourChanged(event
);
390 void wxStatusBarGeneric::SetMinHeight(int height
)
392 // check that this min height is not less than minimal height for the
396 dc
.GetTextExtent( wxT("X"), NULL
, &y
);
398 if ( height
> (11*y
)/10 )
400 SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, height
+ 2*m_borderY
);
404 void wxStatusBarGeneric::OnLeftDown(wxMouseEvent
& event
)
408 GetClientSize(&width
, &height
);
410 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
412 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
414 if (!GTK_IS_WINDOW (ancestor
))
417 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
421 gdk_window_get_origin( source
, &org_x
, &org_y
);
423 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor
),
424 GDK_WINDOW_EDGE_SOUTH_EAST
,
426 org_x
+ event
.GetX(),
427 org_y
+ event
.GetY(),
439 void wxStatusBarGeneric::OnRightDown(wxMouseEvent
& event
)
443 GetClientSize(&width
, &height
);
445 if (HasFlag( wxST_SIZEGRIP
) && (event
.GetX() > width
-height
))
447 GtkWidget
*ancestor
= gtk_widget_get_toplevel( m_widget
);
449 if (!GTK_IS_WINDOW (ancestor
))
452 GdkWindow
*source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
456 gdk_window_get_origin( source
, &org_x
, &org_y
);
458 gtk_window_begin_move_drag (GTK_WINDOW (ancestor
),
460 org_x
+ event
.GetX(),
461 org_y
+ event
.GetY(),
473 #endif // wxUSE_STATUSBAR