]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/statusbr.cpp
c42e2132091818f925c22431499b42035d7dad34
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
;
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
);
99 void wxStatusBarGeneric::SetFieldsCount(int number
, const int *widths
)
101 if ( number
!= m_nFields
)
105 delete[] m_statusStrings
;
106 m_statusStrings
= new wxString
[number
];
108 #if 0 // VZ: what is this for?
110 for (i
= 0; i
< number
; i
++)
111 m_statusStrings
[i
] = "";
115 SetStatusWidths(number
, widths
);
118 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
120 wxCHECK_RET( (number
>= 0) && (number
< m_nFields
),
121 _T("invalid status bar field index") );
123 m_statusStrings
[number
] = text
;
128 wxString
wxStatusBarGeneric::GetStatusText(int n
) const
130 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), wxEmptyString
,
131 _T("invalid status bar field index") );
133 return m_statusStrings
[n
];
136 void wxStatusBarGeneric::SetStatusWidths(int n
, const int widths_field
[])
138 // only set status widths, when n == number of statuswindows
139 wxCHECK_RET( n
== m_nFields
, _T("status bar field count mismatch") );
141 // delete the old widths in any case - this function may be used to reset
142 // the widths to the default (all equal)
143 delete [] m_statusWidths
;
147 // not an error, see the comment above
148 m_statusWidths
= (int *)NULL
;
155 // VZ: this doesn't do anything as is_variable is unused later
157 // when one window (minimum) is variable (width <= 0)
158 bool is_variable
= FALSE
;
159 for (i
= 0; i
< m_nFields
; i
++)
161 if (widths_field
[i
] <= 0)
167 m_statusWidths
= new int[n
];
168 for (i
= 0; i
< m_nFields
; i
++)
170 m_statusWidths
[i
] = widths_field
[i
];
174 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
180 if ( GetFont().Ok() )
181 dc
.SetFont(GetFont());
182 dc
.SetBackgroundMode(wxTRANSPARENT
);
187 vColor
.InitFromName("DIM GREY");
188 ::WinFillRect(dc
.m_hPS
, &dc
.m_vRclPaint
, vColor
.GetPixel());
191 for ( i
= 0; i
< m_nFields
; i
++ )
195 dc
.SetFont(wxNullFont
);
199 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
204 GetFieldRect(i
, rect
);
206 wxString
text(GetStatusText(i
));
210 #if defined(__WXPM__)
213 dc
.GetTextExtent(text
, &x
, &y
,&decsent
);
214 int xpos
= rect
.x
+ leftMargin
;
215 int ypos
= (int) (((rect
.height
- y
+ 1) / 2 ) + rect
.y
+ decsent
) ;
218 dc
.GetTextExtent(text
, &x
, &y
);
220 int xpos
= rect
.x
+ leftMargin
;
221 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
225 #if defined( __WXGTK__ ) || defined(__WXMAC__)
230 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
232 dc
.DrawText(text
, xpos
, ypos
);
234 dc
.DestroyClippingRegion();
237 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
240 GetFieldRect(i
, rect
);
243 // Have grey background, plus 3-d border -
244 // One black rectangle.
245 // Inside this, left and top sides - dark grey. Bottom and right -
248 dc
.SetPen(m_hilightPen
);
252 // Right and bottom white lines
253 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
254 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
255 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
256 rect
.x
, rect
.y
+ rect
.height
);
258 dc
.SetPen(m_mediumShadowPen
);
260 // Left and top grey lines
261 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
263 dc
.DrawLine(rect
.x
, rect
.y
,
264 rect
.x
+ rect
.width
, rect
.y
);
267 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
- 3,
268 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
269 dc
.SetPen(m_mediumShadowPen
);
270 dc
.DrawLine(rect
.x
+ rect
.width
+ 1, rect
.y
- 3,
271 rect
.x
+ rect
.width
+ 1, rect
.y
+ rect
.height
);
272 dc
.DrawLine(rect
.x
+ rect
.width
+ 2, rect
.y
- 3,
273 rect
.x
+ rect
.width
+ 2, rect
.y
+ rect
.height
);
275 dc
.DrawLine(rect
.x
+ rect
.width
+ 2, rect
.y
+ rect
.height
+ 2,
276 rect
.x
- 2, rect
.y
+ rect
.height
+ 2);
277 dc
.DrawLine(rect
.x
+ rect
.width
+ 1, rect
.y
+ rect
.height
+ 1,
278 rect
.x
- 2, rect
.y
+ rect
.height
+ 1);
279 dc
.SetPen(m_hilightPen
);
280 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
281 rect
.x
- 2, rect
.y
+ rect
.height
);
285 DrawFieldText(dc
, i
);
288 // Get the position and size of the field's internal bounding rectangle
289 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
291 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), FALSE
,
292 _T("invalid status bar field index") );
296 GetSize(&width
, &height
);
298 GetClientSize(&width
, &height
);
302 int sum_of_nonvar
= 0;
304 bool do_same_width
= FALSE
;
307 int fieldPosition
= 0;
311 // if sum(not variable Windows) > c_width - (20 points per variable_window)
312 // then do_same_width = TRUE;
313 for (i
= 0; i
< m_nFields
; i
++)
315 if (m_statusWidths
[i
] > 0) sum_of_nonvar
+= m_statusWidths
[i
];
318 if (sum_of_nonvar
> (width
- 20*num_of_var
)) do_same_width
= TRUE
;
320 else do_same_width
= TRUE
;
323 for (i
= 0; i
< m_nFields
; i
++)
325 fieldWidth
= (int)(width
/m_nFields
);
326 fieldPosition
= i
*fieldWidth
;
331 else // no_same_width
333 int *tempwidth
= new int[m_nFields
];
335 for (i
= 0; i
< m_nFields
; i
++)
337 if (m_statusWidths
[i
] > 0) tempwidth
[i
] = m_statusWidths
[i
];
338 else tempwidth
[i
] = (width
- sum_of_nonvar
) / num_of_var
;
340 for (i
= 0; i
< m_nFields
; i
++)
342 fieldWidth
= tempwidth
[i
];
343 fieldPosition
= temppos
;
345 temppos
+= tempwidth
[i
];
353 rect
.x
= fieldPosition
+ wxTHICK_LINE_BORDER
;
354 rect
.y
= wxTHICK_LINE_BORDER
;
356 rect
.width
= fieldWidth
- 2 * wxTHICK_LINE_BORDER
;
357 rect
.height
= height
- 2 * wxTHICK_LINE_BORDER
;
362 // Initialize colours
363 void wxStatusBarGeneric::InitColours()
366 #if defined(__WIN95__)
367 wxColour
mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW
));
368 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
370 wxColour
hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT
));
371 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
372 #elif defined(__WXPM__)
373 m_mediumShadowPen
= wxPen("LIGHT GREY", 1, wxSOLID
);
374 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
376 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
377 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
380 m_defaultStatusBarFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
381 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
384 // Responds to colour changes, and passes event on to children.
385 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
390 // Propagate the event to the non-top-level children
391 wxWindow::OnSysColourChanged(event
);
394 void wxStatusBarGeneric::SetMinHeight(int height
)
396 // check that this min height is not less than minimal height for the
400 dc
.GetTextExtent( _T("X"), NULL
, &y
);
402 if ( height
> (11*y
)/10 )
404 SetSize(-1, -1, -1, height
+ 2*m_borderY
);
408 //#endif // Win32 && wxUSE_NATIVE_STATUSBAR