]>
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_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged
)
50 // Default status border dimensions
51 #define wxTHICK_LINE_BORDER 2
52 #define wxTHICK_LINE_WIDTH 1
54 wxStatusBarGeneric::wxStatusBarGeneric()
56 m_borderX
= wxTHICK_LINE_BORDER
;
57 m_borderY
= wxTHICK_LINE_BORDER
;
60 wxStatusBarGeneric::~wxStatusBarGeneric()
67 bool wxStatusBarGeneric::Create(wxWindow
*parent
,
72 // If create is ever meant to be re-entrant over the life of
73 // an object we should:
74 // m_statusStrings.Empty();
76 m_borderX
= wxTHICK_LINE_BORDER
;
77 m_borderY
= wxTHICK_LINE_BORDER
;
79 bool success
= wxWindow::Create(parent
, id
,
80 wxDefaultPosition
, wxDefaultSize
,
81 style
| wxTAB_TRAVERSAL
, name
);
83 // The status bar should have a themed background
84 SetThemeEnabled( TRUE
);
86 // Don't wish this to be found as a child
88 parent
->GetChildren().DeleteObject(this);
92 SetFont(m_defaultStatusBarFont
);
94 // Set the height according to the font and the border size
96 dc
.SetFont(GetFont());
99 dc
.GetTextExtent(_T("X"), NULL
, &y
);
101 int height
= (int)( (11*y
)/10 + 2*GetBorderY());
103 SetSize(-1, -1, -1, height
);
108 void wxStatusBarGeneric::SetFieldsCount(int number
, const int *widths
)
110 wxASSERT_MSG( number
>= 0,
111 _T("Yes, number should be a size_t and less than no fields is silly.") );
113 // if( number > m_nFields )
116 for(i
= m_nFields
; i
< number
; ++i
)
117 m_statusStrings
.Add( wxEmptyString
);
119 // if( number < m_nFields )
121 for (i
= m_nFields
- 1; i
>= number
; --i
)
122 m_statusStrings
.Remove(i
);
126 wxASSERT_MSG( m_nFields
== (int)m_statusStrings
.GetCount(),
127 _T("This really should never happen, can we do away with m_nFields here?") );
129 SetStatusWidths(number
, widths
);
132 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
134 wxCHECK_RET( (number
>= 0) && (number
< m_nFields
),
135 _T("invalid status bar field index") );
137 m_statusStrings
[number
] = text
;
140 GetFieldRect(number
, rect
);
142 Refresh( TRUE
, &rect
);
145 wxString
wxStatusBarGeneric::GetStatusText(int n
) const
147 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), wxEmptyString
,
148 _T("invalid status bar field index") );
150 return m_statusStrings
[n
];
153 void wxStatusBarGeneric::SetStatusWidths(int n
, const int widths_field
[])
155 // only set status widths, when n == number of statuswindows
156 wxCHECK_RET( n
== m_nFields
, _T("status bar field count mismatch") );
158 // delete the old widths in any case - this function may be used to reset
159 // the widths to the default (all equal)
160 // MBN: this is incompatible with at least wxMSW and wxMAC and not
161 // documented, but let's keep it for now
166 // not an error, see the comment above
171 wxStatusBarBase::SetStatusWidths(n
, widths_field
);
174 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
180 if ( GetFont().Ok() )
181 dc
.SetFont(GetFont());
182 dc
.SetBackgroundMode(wxTRANSPARENT
);
187 vColor
= wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
);
188 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
191 for ( i
= 0; i
< m_nFields
; i
++ )
195 dc
.SetFont(wxNullFont
);
199 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
204 GetFieldRect(i
, rect
);
206 wxString
text(GetStatusText(i
));
210 dc
.GetTextExtent(text
, &x
, &y
);
212 int xpos
= rect
.x
+ leftMargin
;
213 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
215 #if defined( __WXGTK__ ) || defined(__WXMAC__)
220 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
222 dc
.DrawText(text
, xpos
, ypos
);
224 dc
.DestroyClippingRegion();
227 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
230 GetFieldRect(i
, rect
);
233 // Have grey background, plus 3-d border -
234 // One black rectangle.
235 // Inside this, left and top sides - dark grey. Bottom and right -
238 dc
.SetPen(m_hilightPen
);
242 // Right and bottom white lines
243 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
244 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
245 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
246 rect
.x
, rect
.y
+ rect
.height
);
248 dc
.SetPen(m_mediumShadowPen
);
250 // Left and top grey lines
251 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
253 dc
.DrawLine(rect
.x
, rect
.y
,
254 rect
.x
+ rect
.width
, rect
.y
);
257 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.height
+ 2,
258 rect
.x
, rect
.height
+ 2);
259 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
260 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
262 dc
.SetPen(m_mediumShadowPen
);
263 dc
.DrawLine(rect
.x
, rect
.y
,
264 rect
.x
+ rect
.width
, rect
.y
);
265 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
270 DrawFieldText(dc
, i
);
273 // Get the position and size of the field's internal bounding rectangle
274 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
276 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), FALSE
,
277 _T("invalid status bar field index") );
281 GetSize(&width
, &height
);
283 GetClientSize(&width
, &height
);
287 int sum_of_nonvar
= 0;
289 bool do_same_width
= FALSE
;
292 int fieldPosition
= 0;
296 // if sum(not variable Windows) > c_width - (20 points per variable_window)
297 // then do_same_width = TRUE;
298 for (i
= 0; i
< m_nFields
; i
++)
300 if (m_statusWidths
[i
] > 0) sum_of_nonvar
+= m_statusWidths
[i
];
303 if (sum_of_nonvar
> (width
- 20*num_of_var
)) do_same_width
= TRUE
;
305 else do_same_width
= TRUE
;
308 for (i
= 0; i
< m_nFields
; i
++)
310 fieldWidth
= (int)(width
/m_nFields
);
311 fieldPosition
= i
*fieldWidth
;
316 else // no_same_width
318 int *tempwidth
= new int[m_nFields
];
320 for (i
= 0; i
< m_nFields
; i
++)
322 if (m_statusWidths
[i
] > 0) tempwidth
[i
] = m_statusWidths
[i
];
323 else tempwidth
[i
] = (width
- sum_of_nonvar
) / num_of_var
;
325 for (i
= 0; i
< m_nFields
; i
++)
327 fieldWidth
= tempwidth
[i
];
328 fieldPosition
= temppos
;
330 temppos
+= tempwidth
[i
];
338 rect
.x
= fieldPosition
+ wxTHICK_LINE_BORDER
;
339 rect
.y
= wxTHICK_LINE_BORDER
;
341 rect
.width
= fieldWidth
- 2 * wxTHICK_LINE_BORDER
;
342 rect
.height
= height
- 2 * wxTHICK_LINE_BORDER
;
347 // Initialize colours
348 void wxStatusBarGeneric::InitColours()
351 #if defined(__WIN95__)
352 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
353 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
355 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
356 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
357 #elif defined(__WXPM__)
358 m_mediumShadowPen
= wxPen(wxColour(127, 127, 127), 1, wxSOLID
);
359 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
363 vColour
.Set(wxString("LIGHT GREY"));
364 SetBackgroundColour(vColour
);
365 vColour
.Set(wxString("BLACK"));
366 SetForegroundColour(vColour
);
367 m_defaultStatusBarFont
= *wxSMALL_FONT
;
369 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
370 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
374 m_defaultStatusBarFont
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
375 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
379 // Responds to colour changes, and passes event on to children.
380 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
385 // Propagate the event to the non-top-level children
386 wxWindow::OnSysColourChanged(event
);
389 void wxStatusBarGeneric::SetMinHeight(int height
)
391 // check that this min height is not less than minimal height for the
395 dc
.GetTextExtent( _T("X"), NULL
, &y
);
397 if ( height
> (11*y
)/10 )
399 SetSize(-1, -1, -1, height
+ 2*m_borderY
);
403 #endif // wxUSE_STATUSBAR