]>
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 // 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 BEGIN_EVENT_TABLE(wxStatusBarGeneric
, wxWindow
)
40 EVT_PAINT(wxStatusBarGeneric::OnPaint
)
41 EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged
)
44 // Default status border dimensions
45 #define wxTHICK_LINE_BORDER 2
46 #define wxTHICK_LINE_WIDTH 1
48 wxStatusBarGeneric::wxStatusBarGeneric()
50 m_statusWidths
= (int *) NULL
;
51 m_statusStrings
= (wxString
*) NULL
;
53 m_borderX
= wxTHICK_LINE_BORDER
;
54 m_borderY
= wxTHICK_LINE_BORDER
;
57 wxStatusBarGeneric::~wxStatusBarGeneric()
63 if ( m_statusStrings
)
64 delete[] m_statusStrings
;
67 bool wxStatusBarGeneric::Create(wxWindow
*parent
,
72 m_statusWidths
= (int *) NULL
;
73 m_statusStrings
= (wxString
*) NULL
;
75 m_borderX
= wxTHICK_LINE_BORDER
;
76 m_borderY
= wxTHICK_LINE_BORDER
;
78 bool success
= wxWindow::Create(parent
, id
,
79 wxDefaultPosition
, wxDefaultSize
,
80 style
| wxTAB_TRAVERSAL
, name
);
82 // Don't wish this to be found as a child
84 parent
->GetChildren().DeleteObject(this);
88 SetFont(m_defaultStatusBarFont
);
90 // Set the height according to the font and the border size
92 dc
.SetFont(GetFont());
95 dc
.GetTextExtent(_T("X"), NULL
, &y
);
97 int height
= (int)( (11*y
)/10 + 2*GetBorderY());
99 SetSize(-1, -1, -1, height
);
104 void wxStatusBarGeneric::SetFieldsCount(int number
, const int *widths
)
106 if ( number
!= m_nFields
)
110 delete[] m_statusStrings
;
111 m_statusStrings
= new wxString
[number
];
114 SetStatusWidths(number
, widths
);
117 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
119 wxCHECK_RET( (number
>= 0) && (number
< m_nFields
),
120 _T("invalid status bar field index") );
122 m_statusStrings
[number
] = text
;
127 wxString
wxStatusBarGeneric::GetStatusText(int n
) const
129 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), wxEmptyString
,
130 _T("invalid status bar field index") );
132 return m_statusStrings
[n
];
135 void wxStatusBarGeneric::SetStatusWidths(int n
, const int widths_field
[])
137 // only set status widths, when n == number of statuswindows
138 wxCHECK_RET( n
== m_nFields
, _T("status bar field count mismatch") );
140 // delete the old widths in any case - this function may be used to reset
141 // the widths to the default (all equal)
142 delete [] m_statusWidths
;
146 // not an error, see the comment above
147 m_statusWidths
= (int *)NULL
;
154 // VZ: this doesn't do anything as is_variable is unused later
156 // when one window (minimum) is variable (width <= 0)
157 bool is_variable
= FALSE
;
158 for (i
= 0; i
< m_nFields
; i
++)
160 if (widths_field
[i
] <= 0)
166 m_statusWidths
= new int[n
];
167 for (i
= 0; i
< m_nFields
; i
++)
169 m_statusWidths
[i
] = widths_field
[i
];
173 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
179 if ( GetFont().Ok() )
180 dc
.SetFont(GetFont());
181 dc
.SetBackgroundMode(wxTRANSPARENT
);
186 vColor
.InitFromName("GREY");
187 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
190 for ( i
= 0; i
< m_nFields
; i
++ )
194 dc
.SetFont(wxNullFont
);
198 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
203 GetFieldRect(i
, rect
);
205 wxString
text(GetStatusText(i
));
209 dc
.GetTextExtent(text
, &x
, &y
);
211 int xpos
= rect
.x
+ leftMargin
;
212 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
214 #if defined( __WXGTK__ ) || defined(__WXMAC__)
219 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
221 dc
.DrawText(text
, xpos
, ypos
);
223 dc
.DestroyClippingRegion();
226 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
229 GetFieldRect(i
, rect
);
232 // Have grey background, plus 3-d border -
233 // One black rectangle.
234 // Inside this, left and top sides - dark grey. Bottom and right -
237 dc
.SetPen(m_hilightPen
);
241 // Right and bottom white lines
242 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
243 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
244 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
245 rect
.x
, rect
.y
+ rect
.height
);
247 dc
.SetPen(m_mediumShadowPen
);
249 // Left and top grey lines
250 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
252 dc
.DrawLine(rect
.x
, rect
.y
,
253 rect
.x
+ rect
.width
, rect
.y
);
256 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
257 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
+ 2);
258 dc
.SetPen(m_mediumShadowPen
);
259 dc
.DrawLine(rect
.x
+ rect
.width
+ 1, rect
.y
,
260 rect
.x
+ rect
.width
+ 1, rect
.y
+ rect
.height
+ 2);
261 dc
.DrawLine(rect
.x
+ rect
.width
+ 2, rect
.y
,
262 rect
.x
+ rect
.width
+ 2, rect
.y
+ rect
.height
+ 2);
264 dc
.DrawLine(rect
.x
+ rect
.width
+ 2, rect
.y
,
266 dc
.DrawLine(rect
.x
+ rect
.width
+ 1, rect
.y
- 1,
267 rect
.x
- 2, rect
.y
- 1);
268 dc
.SetPen(m_hilightPen
);
269 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
- 2,
270 rect
.x
- 2, rect
.y
- 2);
274 DrawFieldText(dc
, i
);
277 // Get the position and size of the field's internal bounding rectangle
278 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
280 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), FALSE
,
281 _T("invalid status bar field index") );
285 GetSize(&width
, &height
);
287 GetClientSize(&width
, &height
);
291 int sum_of_nonvar
= 0;
293 bool do_same_width
= FALSE
;
296 int fieldPosition
= 0;
300 // if sum(not variable Windows) > c_width - (20 points per variable_window)
301 // then do_same_width = TRUE;
302 for (i
= 0; i
< m_nFields
; i
++)
304 if (m_statusWidths
[i
] > 0) sum_of_nonvar
+= m_statusWidths
[i
];
307 if (sum_of_nonvar
> (width
- 20*num_of_var
)) do_same_width
= TRUE
;
309 else do_same_width
= TRUE
;
312 for (i
= 0; i
< m_nFields
; i
++)
314 fieldWidth
= (int)(width
/m_nFields
);
315 fieldPosition
= i
*fieldWidth
;
320 else // no_same_width
322 int *tempwidth
= new int[m_nFields
];
324 for (i
= 0; i
< m_nFields
; i
++)
326 if (m_statusWidths
[i
] > 0) tempwidth
[i
] = m_statusWidths
[i
];
327 else tempwidth
[i
] = (width
- sum_of_nonvar
) / num_of_var
;
329 for (i
= 0; i
< m_nFields
; i
++)
331 fieldWidth
= tempwidth
[i
];
332 fieldPosition
= temppos
;
334 temppos
+= tempwidth
[i
];
342 rect
.x
= fieldPosition
+ wxTHICK_LINE_BORDER
;
343 rect
.y
= wxTHICK_LINE_BORDER
;
345 rect
.width
= fieldWidth
- 2 * wxTHICK_LINE_BORDER
;
346 rect
.height
= height
- 2 * wxTHICK_LINE_BORDER
;
351 // Initialize colours
352 void wxStatusBarGeneric::InitColours()
355 #if defined(__WIN95__)
356 wxColour
mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW
));
357 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
359 wxColour
hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT
));
360 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
361 #elif defined(__WXPM__)
362 m_mediumShadowPen
= wxPen("LIGHT GREY", 1, wxSOLID
);
363 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
365 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
366 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
369 m_defaultStatusBarFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
370 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
373 // Responds to colour changes, and passes event on to children.
374 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
379 // Propagate the event to the non-top-level children
380 wxWindow::OnSysColourChanged(event
);
383 void wxStatusBarGeneric::SetMinHeight(int height
)
385 // check that this min height is not less than minimal height for the
389 dc
.GetTextExtent( _T("X"), NULL
, &y
);
391 if ( height
> (11*y
)/10 )
393 SetSize(-1, -1, -1, height
+ 2*m_borderY
);
397 #endif // wxUSE_STATUSBAR