]>
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 // The status bar should have a themed background
89 SetThemeEnabled( TRUE
);
91 // Don't wish this to be found as a child
93 parent
->GetChildren().DeleteObject(this);
97 SetFont(m_defaultStatusBarFont
);
99 // Set the height according to the font and the border size
101 dc
.SetFont(GetFont());
104 dc
.GetTextExtent(_T("X"), NULL
, &y
);
106 int height
= (int)( (11*y
)/10 + 2*GetBorderY());
108 SetSize(-1, -1, -1, height
);
113 void wxStatusBarGeneric::SetFieldsCount(int number
, const int *widths
)
115 if ( number
!= m_nFields
)
119 delete[] m_statusStrings
;
120 m_statusStrings
= new wxString
[number
];
123 SetStatusWidths(number
, widths
);
126 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
128 wxCHECK_RET( (number
>= 0) && (number
< m_nFields
),
129 _T("invalid status bar field index") );
131 m_statusStrings
[number
] = text
;
134 GetFieldRect(number
, rect
);
136 Refresh( TRUE
, &rect
);
139 wxString
wxStatusBarGeneric::GetStatusText(int n
) const
141 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), wxEmptyString
,
142 _T("invalid status bar field index") );
144 return m_statusStrings
[n
];
147 void wxStatusBarGeneric::SetStatusWidths(int n
, const int widths_field
[])
149 // only set status widths, when n == number of statuswindows
150 wxCHECK_RET( n
== m_nFields
, _T("status bar field count mismatch") );
152 // delete the old widths in any case - this function may be used to reset
153 // the widths to the default (all equal)
154 delete [] m_statusWidths
;
158 // not an error, see the comment above
159 m_statusWidths
= (int *)NULL
;
166 // VZ: this doesn't do anything as is_variable is unused later
168 // when one window (minimum) is variable (width <= 0)
169 bool is_variable
= FALSE
;
170 for (i
= 0; i
< m_nFields
; i
++)
172 if (widths_field
[i
] <= 0)
178 m_statusWidths
= new int[n
];
179 for (i
= 0; i
< m_nFields
; i
++)
181 m_statusWidths
[i
] = widths_field
[i
];
186 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
192 if ( GetFont().Ok() )
193 dc
.SetFont(GetFont());
194 dc
.SetBackgroundMode(wxTRANSPARENT
);
199 vColor
.InitFromName("LIGHT GREY");
200 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
203 for ( i
= 0; i
< m_nFields
; i
++ )
207 dc
.SetFont(wxNullFont
);
211 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
216 GetFieldRect(i
, rect
);
218 wxString
text(GetStatusText(i
));
222 dc
.GetTextExtent(text
, &x
, &y
);
224 int xpos
= rect
.x
+ leftMargin
;
225 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
227 #if defined( __WXGTK__ ) || defined(__WXMAC__)
232 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
234 dc
.DrawText(text
, xpos
, ypos
);
236 dc
.DestroyClippingRegion();
239 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
242 GetFieldRect(i
, rect
);
245 // Have grey background, plus 3-d border -
246 // One black rectangle.
247 // Inside this, left and top sides - dark grey. Bottom and right -
250 dc
.SetPen(m_hilightPen
);
254 // Right and bottom white lines
255 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
256 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
257 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
258 rect
.x
, rect
.y
+ rect
.height
);
260 dc
.SetPen(m_mediumShadowPen
);
262 // Left and top grey lines
263 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
265 dc
.DrawLine(rect
.x
, rect
.y
,
266 rect
.x
+ rect
.width
, rect
.y
);
269 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
270 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
+ 2);
271 dc
.SetPen(m_mediumShadowPen
);
272 dc
.DrawLine(rect
.x
+ rect
.width
+ 1, rect
.y
,
273 rect
.x
+ rect
.width
+ 1, rect
.y
+ rect
.height
+ 2);
274 dc
.DrawLine(rect
.x
+ rect
.width
+ 2, rect
.y
,
275 rect
.x
+ rect
.width
+ 2, rect
.y
+ rect
.height
+ 2);
277 dc
.DrawLine(rect
.x
+ rect
.width
+ 2, rect
.y
,
279 dc
.DrawLine(rect
.x
+ rect
.width
+ 1, rect
.y
- 1,
280 rect
.x
- 2, rect
.y
- 1);
281 dc
.SetPen(m_hilightPen
);
282 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
- 2,
283 rect
.x
- 2, rect
.y
- 2);
287 DrawFieldText(dc
, i
);
290 // Get the position and size of the field's internal bounding rectangle
291 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
293 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), FALSE
,
294 _T("invalid status bar field index") );
298 GetSize(&width
, &height
);
300 GetClientSize(&width
, &height
);
304 int sum_of_nonvar
= 0;
306 bool do_same_width
= FALSE
;
309 int fieldPosition
= 0;
313 // if sum(not variable Windows) > c_width - (20 points per variable_window)
314 // then do_same_width = TRUE;
315 for (i
= 0; i
< m_nFields
; i
++)
317 if (m_statusWidths
[i
] > 0) sum_of_nonvar
+= m_statusWidths
[i
];
320 if (sum_of_nonvar
> (width
- 20*num_of_var
)) do_same_width
= TRUE
;
322 else do_same_width
= TRUE
;
325 for (i
= 0; i
< m_nFields
; i
++)
327 fieldWidth
= (int)(width
/m_nFields
);
328 fieldPosition
= i
*fieldWidth
;
333 else // no_same_width
335 int *tempwidth
= new int[m_nFields
];
337 for (i
= 0; i
< m_nFields
; i
++)
339 if (m_statusWidths
[i
] > 0) tempwidth
[i
] = m_statusWidths
[i
];
340 else tempwidth
[i
] = (width
- sum_of_nonvar
) / num_of_var
;
342 for (i
= 0; i
< m_nFields
; i
++)
344 fieldWidth
= tempwidth
[i
];
345 fieldPosition
= temppos
;
347 temppos
+= tempwidth
[i
];
355 rect
.x
= fieldPosition
+ wxTHICK_LINE_BORDER
;
356 rect
.y
= wxTHICK_LINE_BORDER
;
358 rect
.width
= fieldWidth
- 2 * wxTHICK_LINE_BORDER
;
359 rect
.height
= height
- 2 * wxTHICK_LINE_BORDER
;
364 // Initialize colours
365 void wxStatusBarGeneric::InitColours()
368 #if defined(__WIN95__)
369 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
370 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
372 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
373 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
374 #elif defined(__WXPM__)
375 m_mediumShadowPen
= wxPen("DARK GREY", 1, wxSOLID
);
376 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
380 vColour
.Set(wxString("LIGHT GREY"));
381 SetBackgroundColour(vColour
);
382 vColour
.Set(wxString("BLACK"));
383 SetForegroundColour(vColour
);
384 m_defaultStatusBarFont
= *wxSMALL_FONT
;
386 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
387 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
391 m_defaultStatusBarFont
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
392 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
396 // Responds to colour changes, and passes event on to children.
397 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
402 // Propagate the event to the non-top-level children
403 wxWindow::OnSysColourChanged(event
);
406 void wxStatusBarGeneric::SetMinHeight(int height
)
408 // check that this min height is not less than minimal height for the
412 dc
.GetTextExtent( _T("X"), NULL
, &y
);
414 if ( height
> (11*y
)/10 )
416 SetSize(-1, -1, -1, height
+ 2*m_borderY
);
420 #endif // wxUSE_STATUSBAR