]>
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 // if !wxUSE_NATIVE_STATUSBAR, this is already done in common/statbar.cpp
35 #if defined(wxUSE_NATIVE_STATUSBAR) && wxUSE_NATIVE_STATUSBAR
36 #include "wx/generic/statusbr.h"
38 IMPLEMENT_DYNAMIC_CLASS(wxStatusBarGeneric
, wxWindow
)
39 #endif // wxUSE_NATIVE_STATUSBAR
41 BEGIN_EVENT_TABLE(wxStatusBarGeneric
, wxWindow
)
42 EVT_PAINT(wxStatusBarGeneric::OnPaint
)
43 EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged
)
46 // Default status border dimensions
47 #define wxTHICK_LINE_BORDER 2
48 #define wxTHICK_LINE_WIDTH 1
50 wxStatusBarGeneric::wxStatusBarGeneric()
52 m_statusWidths
= (int *) NULL
;
53 m_statusStrings
= (wxString
*) NULL
;
55 m_borderX
= wxTHICK_LINE_BORDER
;
56 m_borderY
= wxTHICK_LINE_BORDER
;
59 wxStatusBarGeneric::~wxStatusBarGeneric()
65 if ( m_statusStrings
)
66 delete[] m_statusStrings
;
69 bool wxStatusBarGeneric::Create(wxWindow
*parent
,
74 m_statusWidths
= (int *) NULL
;
75 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 // Don't wish this to be found as a child
86 parent
->GetChildren().DeleteObject(this);
90 SetFont(m_defaultStatusBarFont
);
92 // Set the height according to the font and the border size
94 dc
.SetFont(GetFont());
97 dc
.GetTextExtent(_T("X"), NULL
, &y
);
99 int height
= (int)( (11*y
)/10 + 2*GetBorderY());
101 SetSize(-1, -1, -1, height
);
106 void wxStatusBarGeneric::SetFieldsCount(int number
, const int *widths
)
108 if ( number
!= m_nFields
)
112 delete[] m_statusStrings
;
113 m_statusStrings
= new wxString
[number
];
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
) )
181 if ( GetFont().Ok() )
182 dc
.SetFont(GetFont());
183 dc
.SetBackgroundMode(wxTRANSPARENT
);
188 vColor
.InitFromName("GREY");
189 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
192 for ( i
= 0; i
< m_nFields
; i
++ )
196 dc
.SetFont(wxNullFont
);
200 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
205 GetFieldRect(i
, rect
);
207 wxString
text(GetStatusText(i
));
211 dc
.GetTextExtent(text
, &x
, &y
);
213 int xpos
= rect
.x
+ leftMargin
;
214 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
216 #if defined( __WXGTK__ ) || defined(__WXMAC__)
221 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
223 dc
.DrawText(text
, xpos
, ypos
);
225 dc
.DestroyClippingRegion();
228 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
231 GetFieldRect(i
, rect
);
234 // Have grey background, plus 3-d border -
235 // One black rectangle.
236 // Inside this, left and top sides - dark grey. Bottom and right -
239 dc
.SetPen(m_hilightPen
);
243 // Right and bottom white lines
244 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
245 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
246 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
247 rect
.x
, rect
.y
+ rect
.height
);
249 dc
.SetPen(m_mediumShadowPen
);
251 // Left and top grey lines
252 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
254 dc
.DrawLine(rect
.x
, rect
.y
,
255 rect
.x
+ rect
.width
, rect
.y
);
258 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
259 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
+ 2);
260 dc
.SetPen(m_mediumShadowPen
);
261 dc
.DrawLine(rect
.x
+ rect
.width
+ 1, rect
.y
,
262 rect
.x
+ rect
.width
+ 1, rect
.y
+ rect
.height
+ 2);
263 dc
.DrawLine(rect
.x
+ rect
.width
+ 2, rect
.y
,
264 rect
.x
+ rect
.width
+ 2, rect
.y
+ rect
.height
+ 2);
266 dc
.DrawLine(rect
.x
+ rect
.width
+ 2, rect
.y
,
268 dc
.DrawLine(rect
.x
+ rect
.width
+ 1, rect
.y
- 1,
269 rect
.x
- 2, rect
.y
- 1);
270 dc
.SetPen(m_hilightPen
);
271 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
- 2,
272 rect
.x
- 2, rect
.y
- 2);
276 DrawFieldText(dc
, i
);
279 // Get the position and size of the field's internal bounding rectangle
280 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
282 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), FALSE
,
283 _T("invalid status bar field index") );
287 GetSize(&width
, &height
);
289 GetClientSize(&width
, &height
);
293 int sum_of_nonvar
= 0;
295 bool do_same_width
= FALSE
;
298 int fieldPosition
= 0;
302 // if sum(not variable Windows) > c_width - (20 points per variable_window)
303 // then do_same_width = TRUE;
304 for (i
= 0; i
< m_nFields
; i
++)
306 if (m_statusWidths
[i
] > 0) sum_of_nonvar
+= m_statusWidths
[i
];
309 if (sum_of_nonvar
> (width
- 20*num_of_var
)) do_same_width
= TRUE
;
311 else do_same_width
= TRUE
;
314 for (i
= 0; i
< m_nFields
; i
++)
316 fieldWidth
= (int)(width
/m_nFields
);
317 fieldPosition
= i
*fieldWidth
;
322 else // no_same_width
324 int *tempwidth
= new int[m_nFields
];
326 for (i
= 0; i
< m_nFields
; i
++)
328 if (m_statusWidths
[i
] > 0) tempwidth
[i
] = m_statusWidths
[i
];
329 else tempwidth
[i
] = (width
- sum_of_nonvar
) / num_of_var
;
331 for (i
= 0; i
< m_nFields
; i
++)
333 fieldWidth
= tempwidth
[i
];
334 fieldPosition
= temppos
;
336 temppos
+= tempwidth
[i
];
344 rect
.x
= fieldPosition
+ wxTHICK_LINE_BORDER
;
345 rect
.y
= wxTHICK_LINE_BORDER
;
347 rect
.width
= fieldWidth
- 2 * wxTHICK_LINE_BORDER
;
348 rect
.height
= height
- 2 * wxTHICK_LINE_BORDER
;
353 // Initialize colours
354 void wxStatusBarGeneric::InitColours()
357 #if defined(__WIN95__)
358 wxColour
mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW
));
359 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
361 wxColour
hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT
));
362 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
363 #elif defined(__WXPM__)
364 m_mediumShadowPen
= wxPen("LIGHT GREY", 1, wxSOLID
);
365 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
367 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
368 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
371 m_defaultStatusBarFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
372 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
375 // Responds to colour changes, and passes event on to children.
376 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
381 // Propagate the event to the non-top-level children
382 wxWindow::OnSysColourChanged(event
);
385 void wxStatusBarGeneric::SetMinHeight(int height
)
387 // check that this min height is not less than minimal height for the
391 dc
.GetTextExtent( _T("X"), NULL
, &y
);
393 if ( height
> (11*y
)/10 )
395 SetSize(-1, -1, -1, height
+ 2*m_borderY
);
399 #endif // wxUSE_STATUSBAR