]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/statusbr.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/statusbr.cpp
3 // Purpose: wxStatusBarGeneric class implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
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"
32 #include "wx/statusbr.h"
34 // we only have to do it here when we use wxStatusBarGeneric in addition to the
35 // standard wxStatusBar class, if wxStatusBarGeneric is the same as
36 // wxStatusBar, then the corresponding IMPLEMENT_DYNAMIC_CLASS is already in
38 #if defined(__WXMAC__) || \
39 (defined(wxUSE_NATIVE_STATUSBAR) && wxUSE_NATIVE_STATUSBAR)
40 #include "wx/generic/statusbr.h"
42 IMPLEMENT_DYNAMIC_CLASS(wxStatusBarGeneric
, wxWindow
)
43 #endif // wxUSE_NATIVE_STATUSBAR
45 BEGIN_EVENT_TABLE(wxStatusBarGeneric
, wxWindow
)
46 EVT_PAINT(wxStatusBarGeneric::OnPaint
)
47 EVT_SIZE(wxStatusBarGeneric::OnSize
)
49 EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged
)
52 // Default status border dimensions
53 #define wxTHICK_LINE_BORDER 2
54 #define wxTHICK_LINE_WIDTH 1
56 void wxStatusBarGeneric::Init()
58 m_borderX
= wxTHICK_LINE_BORDER
;
59 m_borderY
= wxTHICK_LINE_BORDER
;
62 wxStatusBarGeneric::~wxStatusBarGeneric()
64 // VZ: what is this for? please comment...
70 bool wxStatusBarGeneric::Create(wxWindow
*parent
,
75 if ( !wxWindow::Create(parent
, id
,
76 wxDefaultPosition
, wxDefaultSize
,
77 style
| wxTAB_TRAVERSAL
, name
) )
80 // The status bar should have a themed background
81 SetThemeEnabled( TRUE
);
83 // Don't wish this to be found as a child
85 parent
->GetChildren().DeleteObject(this);
89 SetFont(m_defaultStatusBarFont
);
91 // Set the height according to the font and the border size
93 dc
.SetFont(GetFont());
96 dc
.GetTextExtent(_T("X"), NULL
, &y
);
98 int height
= (int)( (11*y
)/10 + 2*GetBorderY());
100 SetSize(-1, -1, -1, height
);
105 void wxStatusBarGeneric::SetFieldsCount(int number
, const int *widths
)
107 wxASSERT_MSG( number
>= 0, _T("negative number of fields in wxStatusBar?") );
110 for(i
= m_nFields
; i
< number
; ++i
)
111 m_statusStrings
.Add( wxEmptyString
);
113 for (i
= m_nFields
- 1; i
>= number
; --i
)
114 m_statusStrings
.RemoveAt(i
);
118 wxASSERT_MSG( m_nFields
== (int)m_statusStrings
.GetCount(),
119 _T("This really should never happen, can we do away with m_nFields here?") );
121 SetStatusWidths(number
, widths
);
124 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
126 wxCHECK_RET( (number
>= 0) && (number
< m_nFields
),
127 _T("invalid status bar field index") );
129 m_statusStrings
[number
] = text
;
132 GetFieldRect(number
, rect
);
134 Refresh( TRUE
, &rect
);
137 wxString
wxStatusBarGeneric::GetStatusText(int n
) const
139 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), wxEmptyString
,
140 _T("invalid status bar field index") );
142 return m_statusStrings
[n
];
145 void wxStatusBarGeneric::SetStatusWidths(int n
, const int widths_field
[])
147 // only set status widths, when n == number of statuswindows
148 wxCHECK_RET( n
== m_nFields
, _T("status bar field count mismatch") );
150 // delete the old widths in any case - this function may be used to reset
151 // the widths to the default (all equal)
152 // MBN: this is incompatible with at least wxMSW and wxMAC and not
153 // documented, but let's keep it for now
156 // forget the old cached pixel widths
161 // not an error, see the comment above
166 wxStatusBarBase::SetStatusWidths(n
, widths_field
);
169 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
175 if ( GetFont().Ok() )
176 dc
.SetFont(GetFont());
177 dc
.SetBackgroundMode(wxTRANSPARENT
);
182 vColor
= wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
);
183 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
186 for ( i
= 0; i
< m_nFields
; i
++ )
189 // VZ: again, what is this for?
191 dc
.SetFont(wxNullFont
);
195 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
200 GetFieldRect(i
, rect
);
202 wxString
text(GetStatusText(i
));
206 dc
.GetTextExtent(text
, &x
, &y
);
208 int xpos
= rect
.x
+ leftMargin
;
209 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
211 #if defined( __WXGTK__ ) || defined(__WXMAC__)
216 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
218 dc
.DrawText(text
, xpos
, ypos
);
220 dc
.DestroyClippingRegion();
223 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
226 GetFieldRect(i
, rect
);
229 // Have grey background, plus 3-d border -
230 // One black rectangle.
231 // Inside this, left and top sides - dark grey. Bottom and right -
234 dc
.SetPen(m_hilightPen
);
238 // Right and bottom white lines
239 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
240 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
241 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
242 rect
.x
, rect
.y
+ rect
.height
);
244 dc
.SetPen(m_mediumShadowPen
);
246 // Left and top grey lines
247 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
249 dc
.DrawLine(rect
.x
, rect
.y
,
250 rect
.x
+ rect
.width
, rect
.y
);
253 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.height
+ 2,
254 rect
.x
, rect
.height
+ 2);
255 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
256 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
258 dc
.SetPen(m_mediumShadowPen
);
259 dc
.DrawLine(rect
.x
, rect
.y
,
260 rect
.x
+ rect
.width
, rect
.y
);
261 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
266 DrawFieldText(dc
, i
);
269 // Get the position and size of the field's internal bounding rectangle
270 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
272 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), FALSE
,
273 _T("invalid status bar field index") );
275 // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
278 GetSize(&width
, &height
);
280 GetClientSize(&width
, &height
);
283 // we cache m_widthsAbs between calls normally but it's cleared when the
284 // status widths change so recompute it if needed
285 if ( m_widthsAbs
.IsEmpty() )
287 wxConstCast(this, wxStatusBarGeneric
)->
288 m_widthsAbs
= CalculateAbsWidths(width
);
292 for ( int i
= 0; i
< n
; i
++ )
294 rect
.x
+= m_widthsAbs
[i
];
300 rect
.width
= m_widthsAbs
[n
] - 2*m_borderX
;
301 rect
.height
= height
- 2*m_borderY
;
306 // Initialize colours
307 void wxStatusBarGeneric::InitColours()
310 #if defined(__WIN95__)
311 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
312 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
314 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
315 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
316 #elif defined(__WXPM__)
317 m_mediumShadowPen
= wxPen(wxColour(127, 127, 127), 1, wxSOLID
);
318 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
322 vColour
.Set(wxString("LIGHT GREY"));
323 SetBackgroundColour(vColour
);
324 vColour
.Set(wxString("BLACK"));
325 SetForegroundColour(vColour
);
326 m_defaultStatusBarFont
= *wxSMALL_FONT
;
328 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
329 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
333 m_defaultStatusBarFont
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
334 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
338 // Responds to colour changes, and passes event on to children.
339 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
344 // Propagate the event to the non-top-level children
345 wxWindow::OnSysColourChanged(event
);
348 void wxStatusBarGeneric::SetMinHeight(int height
)
350 // check that this min height is not less than minimal height for the
354 dc
.GetTextExtent( _T("X"), NULL
, &y
);
356 if ( height
> (11*y
)/10 )
358 SetSize(-1, -1, -1, height
+ 2*m_borderY
);
362 void wxStatusBarGeneric::OnSize(wxSizeEvent
& event
)
364 // have to recompute the widths in pixels
370 #endif // wxUSE_STATUSBAR