]>
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_statusWidths
= (int *) NULL
;
57 m_statusStrings
= (wxString
*) NULL
;
59 m_borderX
= wxTHICK_LINE_BORDER
;
60 m_borderY
= wxTHICK_LINE_BORDER
;
63 wxStatusBarGeneric::~wxStatusBarGeneric()
69 if ( m_statusStrings
)
70 delete[] m_statusStrings
;
73 bool wxStatusBarGeneric::Create(wxWindow
*parent
,
78 m_statusWidths
= (int *) NULL
;
79 m_statusStrings
= (wxString
*) NULL
;
81 m_borderX
= wxTHICK_LINE_BORDER
;
82 m_borderY
= wxTHICK_LINE_BORDER
;
84 bool success
= wxWindow::Create(parent
, id
,
85 wxDefaultPosition
, wxDefaultSize
,
86 style
| wxTAB_TRAVERSAL
, name
);
88 // Don't wish this to be found as a child
90 parent
->GetChildren().DeleteObject(this);
94 SetFont(m_defaultStatusBarFont
);
96 // Set the height according to the font and the border size
98 dc
.SetFont(GetFont());
101 dc
.GetTextExtent(_T("X"), NULL
, &y
);
103 int height
= (int)( (11*y
)/10 + 2*GetBorderY());
105 SetSize(-1, -1, -1, height
);
110 void wxStatusBarGeneric::SetFieldsCount(int number
, const int *widths
)
112 if ( number
!= m_nFields
)
116 delete[] m_statusStrings
;
117 m_statusStrings
= new wxString
[number
];
120 SetStatusWidths(number
, widths
);
123 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
125 wxCHECK_RET( (number
>= 0) && (number
< m_nFields
),
126 _T("invalid status bar field index") );
128 m_statusStrings
[number
] = text
;
132 wxGetOsVersion( &major
, &minor
);
142 GetFieldRect(number
, rect
);
145 dc
.SetBackground( wxBrush(GetBackgroundColour(), wxSOLID
) );
146 dc
.SetClippingRegion( rect
.x
+1, rect
.y
+1, rect
.width
-1, rect
.height
-1 );
148 dc
.DestroyClippingRegion();
150 DrawFieldText( dc
, number
);
153 wxString
wxStatusBarGeneric::GetStatusText(int n
) const
155 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), wxEmptyString
,
156 _T("invalid status bar field index") );
158 return m_statusStrings
[n
];
161 void wxStatusBarGeneric::SetStatusWidths(int n
, const int widths_field
[])
163 // only set status widths, when n == number of statuswindows
164 wxCHECK_RET( n
== m_nFields
, _T("status bar field count mismatch") );
166 // delete the old widths in any case - this function may be used to reset
167 // the widths to the default (all equal)
168 delete [] m_statusWidths
;
172 // not an error, see the comment above
173 m_statusWidths
= (int *)NULL
;
180 // VZ: this doesn't do anything as is_variable is unused later
182 // when one window (minimum) is variable (width <= 0)
183 bool is_variable
= FALSE
;
184 for (i
= 0; i
< m_nFields
; i
++)
186 if (widths_field
[i
] <= 0)
192 m_statusWidths
= new int[n
];
193 for (i
= 0; i
< m_nFields
; i
++)
195 m_statusWidths
[i
] = widths_field
[i
];
200 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
206 if ( GetFont().Ok() )
207 dc
.SetFont(GetFont());
208 dc
.SetBackgroundMode(wxTRANSPARENT
);
213 vColor
.InitFromName("GREY");
214 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
217 for ( i
= 0; i
< m_nFields
; i
++ )
221 dc
.SetFont(wxNullFont
);
225 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
230 GetFieldRect(i
, rect
);
232 wxString
text(GetStatusText(i
));
236 dc
.GetTextExtent(text
, &x
, &y
);
238 int xpos
= rect
.x
+ leftMargin
;
239 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
241 #if defined( __WXGTK__ ) || defined(__WXMAC__)
246 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
248 dc
.DrawText(text
, xpos
, ypos
);
250 dc
.DestroyClippingRegion();
253 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
256 GetFieldRect(i
, rect
);
259 // Have grey background, plus 3-d border -
260 // One black rectangle.
261 // Inside this, left and top sides - dark grey. Bottom and right -
264 dc
.SetPen(m_hilightPen
);
268 // Right and bottom white lines
269 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
270 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
271 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
272 rect
.x
, rect
.y
+ rect
.height
);
274 dc
.SetPen(m_mediumShadowPen
);
276 // Left and top grey lines
277 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
279 dc
.DrawLine(rect
.x
, rect
.y
,
280 rect
.x
+ rect
.width
, rect
.y
);
283 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
284 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
+ 2);
285 dc
.SetPen(m_mediumShadowPen
);
286 dc
.DrawLine(rect
.x
+ rect
.width
+ 1, rect
.y
,
287 rect
.x
+ rect
.width
+ 1, rect
.y
+ rect
.height
+ 2);
288 dc
.DrawLine(rect
.x
+ rect
.width
+ 2, rect
.y
,
289 rect
.x
+ rect
.width
+ 2, rect
.y
+ rect
.height
+ 2);
291 dc
.DrawLine(rect
.x
+ rect
.width
+ 2, rect
.y
,
293 dc
.DrawLine(rect
.x
+ rect
.width
+ 1, rect
.y
- 1,
294 rect
.x
- 2, rect
.y
- 1);
295 dc
.SetPen(m_hilightPen
);
296 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
- 2,
297 rect
.x
- 2, rect
.y
- 2);
301 DrawFieldText(dc
, i
);
304 // Get the position and size of the field's internal bounding rectangle
305 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
307 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), FALSE
,
308 _T("invalid status bar field index") );
312 GetSize(&width
, &height
);
314 GetClientSize(&width
, &height
);
318 int sum_of_nonvar
= 0;
320 bool do_same_width
= FALSE
;
323 int fieldPosition
= 0;
327 // if sum(not variable Windows) > c_width - (20 points per variable_window)
328 // then do_same_width = TRUE;
329 for (i
= 0; i
< m_nFields
; i
++)
331 if (m_statusWidths
[i
] > 0) sum_of_nonvar
+= m_statusWidths
[i
];
334 if (sum_of_nonvar
> (width
- 20*num_of_var
)) do_same_width
= TRUE
;
336 else do_same_width
= TRUE
;
339 for (i
= 0; i
< m_nFields
; i
++)
341 fieldWidth
= (int)(width
/m_nFields
);
342 fieldPosition
= i
*fieldWidth
;
347 else // no_same_width
349 int *tempwidth
= new int[m_nFields
];
351 for (i
= 0; i
< m_nFields
; i
++)
353 if (m_statusWidths
[i
] > 0) tempwidth
[i
] = m_statusWidths
[i
];
354 else tempwidth
[i
] = (width
- sum_of_nonvar
) / num_of_var
;
356 for (i
= 0; i
< m_nFields
; i
++)
358 fieldWidth
= tempwidth
[i
];
359 fieldPosition
= temppos
;
361 temppos
+= tempwidth
[i
];
369 rect
.x
= fieldPosition
+ wxTHICK_LINE_BORDER
;
370 rect
.y
= wxTHICK_LINE_BORDER
;
372 rect
.width
= fieldWidth
- 2 * wxTHICK_LINE_BORDER
;
373 rect
.height
= height
- 2 * wxTHICK_LINE_BORDER
;
378 // Initialize colours
379 void wxStatusBarGeneric::InitColours()
382 #if defined(__WIN95__)
383 wxColour
mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW
));
384 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
386 wxColour
hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT
));
387 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
388 #elif defined(__WXPM__)
389 m_mediumShadowPen
= wxPen("LIGHT GREY", 1, wxSOLID
);
390 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
392 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
393 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
396 m_defaultStatusBarFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
397 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
400 // Responds to colour changes, and passes event on to children.
401 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
406 // Propagate the event to the non-top-level children
407 wxWindow::OnSysColourChanged(event
);
410 void wxStatusBarGeneric::SetMinHeight(int height
)
412 // check that this min height is not less than minimal height for the
416 dc
.GetTextExtent( _T("X"), NULL
, &y
);
418 if ( height
> (11*y
)/10 )
420 SetSize(-1, -1, -1, height
+ 2*m_borderY
);
424 #endif // wxUSE_STATUSBAR