]>
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_statusStrings
= (wxString
*) NULL
;
57 m_borderX
= wxTHICK_LINE_BORDER
;
58 m_borderY
= wxTHICK_LINE_BORDER
;
61 wxStatusBarGeneric::~wxStatusBarGeneric()
67 if ( m_statusStrings
)
68 delete[] m_statusStrings
;
71 bool wxStatusBarGeneric::Create(wxWindow
*parent
,
76 m_statusStrings
= (wxString
*) NULL
;
77 m_borderX
= wxTHICK_LINE_BORDER
;
78 m_borderY
= wxTHICK_LINE_BORDER
;
80 bool success
= wxWindow::Create(parent
, id
,
81 wxDefaultPosition
, wxDefaultSize
,
82 style
| wxTAB_TRAVERSAL
, name
);
84 // The status bar should have a themed background
85 SetThemeEnabled( TRUE
);
87 // Don't wish this to be found as a child
89 parent
->GetChildren().DeleteObject(this);
93 SetFont(m_defaultStatusBarFont
);
95 // Set the height according to the font and the border size
97 dc
.SetFont(GetFont());
100 dc
.GetTextExtent(_T("X"), NULL
, &y
);
102 int height
= (int)( (11*y
)/10 + 2*GetBorderY());
104 SetSize(-1, -1, -1, height
);
109 void wxStatusBarGeneric::SetFieldsCount(int number
, const int *widths
)
111 if ( number
!= m_nFields
)
115 delete[] m_statusStrings
;
116 m_statusStrings
= new wxString
[number
];
119 SetStatusWidths(number
, widths
);
122 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
124 wxCHECK_RET( (number
>= 0) && (number
< m_nFields
),
125 _T("invalid status bar field index") );
127 m_statusStrings
[number
] = text
;
130 GetFieldRect(number
, rect
);
132 Refresh( TRUE
, &rect
);
135 wxString
wxStatusBarGeneric::GetStatusText(int n
) const
137 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), wxEmptyString
,
138 _T("invalid status bar field index") );
140 return m_statusStrings
[n
];
143 void wxStatusBarGeneric::SetStatusWidths(int n
, const int widths_field
[])
145 // only set status widths, when n == number of statuswindows
146 wxCHECK_RET( n
== m_nFields
, _T("status bar field count mismatch") );
148 // delete the old widths in any case - this function may be used to reset
149 // the widths to the default (all equal)
150 // MBN: this is incompatible with at least wxMSW and wxMAC and not
151 // documented, but let's keep it for now
156 // not an error, see the comment above
161 wxStatusBarBase::SetStatusWidths(n
, widths_field
);
164 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
170 if ( GetFont().Ok() )
171 dc
.SetFont(GetFont());
172 dc
.SetBackgroundMode(wxTRANSPARENT
);
177 vColor
.InitFromName("LIGHT GREY");
178 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
181 for ( i
= 0; i
< m_nFields
; i
++ )
185 dc
.SetFont(wxNullFont
);
189 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
194 GetFieldRect(i
, rect
);
196 wxString
text(GetStatusText(i
));
200 dc
.GetTextExtent(text
, &x
, &y
);
202 int xpos
= rect
.x
+ leftMargin
;
203 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
205 #if defined( __WXGTK__ ) || defined(__WXMAC__)
210 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
212 dc
.DrawText(text
, xpos
, ypos
);
214 dc
.DestroyClippingRegion();
217 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
220 GetFieldRect(i
, rect
);
223 // Have grey background, plus 3-d border -
224 // One black rectangle.
225 // Inside this, left and top sides - dark grey. Bottom and right -
228 dc
.SetPen(m_hilightPen
);
232 // Right and bottom white lines
233 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
234 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
235 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
236 rect
.x
, rect
.y
+ rect
.height
);
238 dc
.SetPen(m_mediumShadowPen
);
240 // Left and top grey lines
241 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
243 dc
.DrawLine(rect
.x
, rect
.y
,
244 rect
.x
+ rect
.width
, rect
.y
);
247 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
248 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
+ 2);
249 dc
.SetPen(m_mediumShadowPen
);
250 dc
.DrawLine(rect
.x
+ rect
.width
+ 1, rect
.y
,
251 rect
.x
+ rect
.width
+ 1, rect
.y
+ rect
.height
+ 2);
252 dc
.DrawLine(rect
.x
+ rect
.width
+ 2, rect
.y
,
253 rect
.x
+ rect
.width
+ 2, rect
.y
+ rect
.height
+ 2);
255 dc
.DrawLine(rect
.x
+ rect
.width
+ 2, rect
.y
,
257 dc
.DrawLine(rect
.x
+ rect
.width
+ 1, rect
.y
- 1,
258 rect
.x
- 2, rect
.y
- 1);
259 dc
.SetPen(m_hilightPen
);
260 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
- 2,
261 rect
.x
- 2, rect
.y
- 2);
265 DrawFieldText(dc
, i
);
268 // Get the position and size of the field's internal bounding rectangle
269 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
271 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), FALSE
,
272 _T("invalid status bar field index") );
276 GetSize(&width
, &height
);
278 GetClientSize(&width
, &height
);
282 int sum_of_nonvar
= 0;
284 bool do_same_width
= FALSE
;
287 int fieldPosition
= 0;
291 // if sum(not variable Windows) > c_width - (20 points per variable_window)
292 // then do_same_width = TRUE;
293 for (i
= 0; i
< m_nFields
; i
++)
295 if (m_statusWidths
[i
] > 0) sum_of_nonvar
+= m_statusWidths
[i
];
298 if (sum_of_nonvar
> (width
- 20*num_of_var
)) do_same_width
= TRUE
;
300 else do_same_width
= TRUE
;
303 for (i
= 0; i
< m_nFields
; i
++)
305 fieldWidth
= (int)(width
/m_nFields
);
306 fieldPosition
= i
*fieldWidth
;
311 else // no_same_width
313 int *tempwidth
= new int[m_nFields
];
315 for (i
= 0; i
< m_nFields
; i
++)
317 if (m_statusWidths
[i
] > 0) tempwidth
[i
] = m_statusWidths
[i
];
318 else tempwidth
[i
] = (width
- sum_of_nonvar
) / num_of_var
;
320 for (i
= 0; i
< m_nFields
; i
++)
322 fieldWidth
= tempwidth
[i
];
323 fieldPosition
= temppos
;
325 temppos
+= tempwidth
[i
];
333 rect
.x
= fieldPosition
+ wxTHICK_LINE_BORDER
;
334 rect
.y
= wxTHICK_LINE_BORDER
;
336 rect
.width
= fieldWidth
- 2 * wxTHICK_LINE_BORDER
;
337 rect
.height
= height
- 2 * wxTHICK_LINE_BORDER
;
342 // Initialize colours
343 void wxStatusBarGeneric::InitColours()
346 #if defined(__WIN95__)
347 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
348 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
350 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
351 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
352 #elif defined(__WXPM__)
353 m_mediumShadowPen
= wxPen("DARK GREY", 1, wxSOLID
);
354 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
358 vColour
.Set(wxString("LIGHT GREY"));
359 SetBackgroundColour(vColour
);
360 vColour
.Set(wxString("BLACK"));
361 SetForegroundColour(vColour
);
362 m_defaultStatusBarFont
= *wxSMALL_FONT
;
364 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
365 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
369 m_defaultStatusBarFont
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
370 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
374 // Responds to colour changes, and passes event on to children.
375 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
380 // Propagate the event to the non-top-level children
381 wxWindow::OnSysColourChanged(event
);
384 void wxStatusBarGeneric::SetMinHeight(int height
)
386 // check that this min height is not less than minimal height for the
390 dc
.GetTextExtent( _T("X"), NULL
, &y
);
392 if ( height
> (11*y
)/10 )
394 SetSize(-1, -1, -1, height
+ 2*m_borderY
);
398 #endif // wxUSE_STATUSBAR