]>
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"
23 //#if !defined(__WIN32__) || !wxUSE_NATIVE_STATUSBAR
28 #include "wx/settings.h"
29 #include "wx/dcclient.h"
32 #include "wx/statusbr.h"
34 // with wxUSE_NATIVE_STATUSBAR it is not included from wx/statusbr.h
35 #include "wx/generic/statusbr.h"
37 IMPLEMENT_DYNAMIC_CLASS(wxStatusBarGeneric
, wxWindow
)
39 #if !defined(__WIN32__) || !wxUSE_NATIVE_STATUSBAR
40 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar
, wxStatusBarGeneric
)
41 #endif // Win32 && wxUSE_NATIVE_STATUSBAR
43 BEGIN_EVENT_TABLE(wxStatusBarGeneric
, wxWindow
)
44 EVT_PAINT(wxStatusBarGeneric::OnPaint
)
45 EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged
)
48 // Default status border dimensions
49 #define wxTHICK_LINE_BORDER 2
50 #define wxTHICK_LINE_WIDTH 1
52 wxStatusBarGeneric::wxStatusBarGeneric()
54 m_statusWidths
= (int *) NULL
;
55 m_statusStrings
= (wxString
*) NULL
;
57 m_borderX
= wxTHICK_LINE_BORDER
;
58 m_borderY
= wxTHICK_LINE_BORDER
;
61 wxStatusBarGeneric::~wxStatusBarGeneric()
68 delete[] m_statusWidths
;
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
;
83 m_themeEnabled
= TRUE
;
85 bool success
= wxWindow::Create(parent
, id
,
86 wxDefaultPosition
, wxDefaultSize
,
87 style
| wxTAB_TRAVERSAL
, name
);
89 // Don't wish this to be found as a child
91 parent
->GetChildren().DeleteObject(this);
95 SetFont(m_defaultStatusBarFont
);
100 void wxStatusBarGeneric::SetFieldsCount(int number
, const int *widths
)
102 if ( number
!= m_nFields
)
106 delete[] m_statusStrings
;
107 m_statusStrings
= new wxString
[number
];
109 #if 0 // VZ: what is this for?
111 for (i
= 0; i
< number
; i
++)
112 m_statusStrings
[i
] = "";
116 SetStatusWidths(number
, widths
);
119 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
121 wxCHECK_RET( (number
>= 0) && (number
< m_nFields
),
122 _T("invalid status bar field index") );
124 m_statusStrings
[number
] = text
;
129 wxString
wxStatusBarGeneric::GetStatusText(int n
) const
131 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), wxEmptyString
,
132 _T("invalid status bar field index") );
134 return m_statusStrings
[n
];
137 void wxStatusBarGeneric::SetStatusWidths(int n
, const int widths_field
[])
139 // only set status widths, when n == number of statuswindows
140 wxCHECK_RET( n
== m_nFields
, _T("status bar field count mismatch") );
142 // delete the old widths in any case - this function may be used to reset
143 // the widths to the default (all equal)
144 delete [] m_statusWidths
;
148 // not an error, see the comment above
149 m_statusWidths
= (int *)NULL
;
156 // VZ: this doesn't do anything as is_variable is unused later
158 // when one window (minimum) is variable (width <= 0)
159 bool is_variable
= FALSE
;
160 for (i
= 0; i
< m_nFields
; i
++)
162 if (widths_field
[i
] <= 0)
168 m_statusWidths
= new int[n
];
169 for (i
= 0; i
< m_nFields
; i
++)
171 m_statusWidths
[i
] = widths_field
[i
];
175 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
180 if ( GetFont().Ok() )
181 dc
.SetFont(GetFont());
182 dc
.SetBackgroundMode(wxTRANSPARENT
);
183 dc
.SetTextForeground(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT
));
185 for ( i
= 0; i
< m_nFields
; i
++ )
189 dc
.SetFont(wxNullFont
);
193 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
198 GetFieldRect(i
, rect
);
200 wxString
text(GetStatusText(i
));
204 dc
.GetTextExtent(text
, &x
, &y
);
206 int xpos
= rect
.x
+ leftMargin
;
207 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
209 #if defined( __WXGTK__ ) || defined(__WXMAC__)
214 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
216 dc
.DrawText(text
, xpos
, ypos
);
218 dc
.DestroyClippingRegion();
221 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
224 GetFieldRect(i
, rect
);
227 // Have grey background, plus 3-d border -
228 // One black rectangle.
229 // Inside this, left and top sides - dark grey. Bottom and right -
232 dc
.SetPen(m_hilightPen
);
234 // Right and bottom white lines
235 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
236 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
237 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
238 rect
.x
, rect
.y
+ rect
.height
);
240 dc
.SetPen(m_mediumShadowPen
);
242 // Left and top grey lines
243 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
245 dc
.DrawLine(rect
.x
, rect
.y
,
246 rect
.x
+ rect
.width
, rect
.y
);
248 DrawFieldText(dc
, i
);
251 // Get the position and size of the field's internal bounding rectangle
252 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
254 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), FALSE
,
255 _T("invalid status bar field index") );
258 GetClientSize(&width
, &height
);
261 int sum_of_nonvar
= 0;
263 bool do_same_width
= FALSE
;
266 int fieldPosition
= 0;
270 // if sum(not variable Windows) > c_width - (20 points per variable_window)
271 // then do_same_width = TRUE;
272 for (i
= 0; i
< m_nFields
; i
++)
274 if (m_statusWidths
[i
] > 0) sum_of_nonvar
+= m_statusWidths
[i
];
277 if (sum_of_nonvar
> (width
- 20*num_of_var
)) do_same_width
= TRUE
;
279 else do_same_width
= TRUE
;
282 for (i
= 0; i
< m_nFields
; i
++)
284 fieldWidth
= (int)(width
/m_nFields
);
285 fieldPosition
= i
*fieldWidth
;
290 else // no_same_width
292 int *tempwidth
= new int[m_nFields
];
294 for (i
= 0; i
< m_nFields
; i
++)
296 if (m_statusWidths
[i
] > 0) tempwidth
[i
] = m_statusWidths
[i
];
297 else tempwidth
[i
] = (width
- sum_of_nonvar
) / num_of_var
;
299 for (i
= 0; i
< m_nFields
; i
++)
301 fieldWidth
= tempwidth
[i
];
302 fieldPosition
= temppos
;
304 temppos
+= tempwidth
[i
];
312 rect
.x
= fieldPosition
+ wxTHICK_LINE_BORDER
;
313 rect
.y
= wxTHICK_LINE_BORDER
;
315 rect
.width
= fieldWidth
- 2 * wxTHICK_LINE_BORDER
;
316 rect
.height
= height
- 2 * wxTHICK_LINE_BORDER
;
321 // Initialize colours
322 void wxStatusBarGeneric::InitColours()
326 wxColour
mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW
));
327 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
329 wxColour
hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT
));
330 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
332 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
333 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
336 m_defaultStatusBarFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
337 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
340 // Responds to colour changes, and passes event on to children.
341 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
346 // Propagate the event to the non-top-level children
347 wxWindow::OnSysColourChanged(event
);
350 void wxStatusBarGeneric::SetMinHeight(int height
)
352 // check that this min height is not less than minimal height for the
356 dc
.GetTextExtent( _T("X"), NULL
, &y
);
358 if ( height
> (11*y
)/10 )
360 SetSize(-1, -1, -1, height
+ 2*m_borderY
);
364 //#endif // Win32 && wxUSE_NATIVE_STATUSBAR