]>
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
;
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
)
103 if ( m_statusWidths
)
104 delete[] m_statusWidths
;
106 if ( m_statusStrings
)
107 delete[] m_statusStrings
;
109 m_statusStrings
= new wxString
[number
];
112 for (i
= 0; i
< number
; i
++)
113 m_statusStrings
[i
] = "";
116 SetStatusWidths(number
, widths
);
119 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
121 if ((number
< 0) || (number
>= m_nFields
))
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
142 // only set status widths,
143 // when one window (minimum) is variable (width <= 0)
144 bool is_variable
= FALSE
;
146 for (i
= 0; i
< m_nFields
; i
++)
148 if (widths_field
[i
] <= 0) is_variable
= TRUE
;
151 // if there are old widths, delete them
153 delete [] m_statusWidths
;
156 m_statusWidths
= new int[n
];
157 for (i
= 0; i
< m_nFields
; i
++)
159 m_statusWidths
[i
] = widths_field
[i
];
164 void wxStatusBarGeneric::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
169 if ( GetFont().Ok() )
170 dc
.SetFont(GetFont());
171 dc
.SetBackgroundMode(wxTRANSPARENT
);
173 for ( i
= 0; i
< m_nFields
; i
++ )
177 dc
.SetFont(wxNullFont
);
181 void wxStatusBarGeneric::DrawFieldText(wxDC
& dc
, int i
)
186 GetFieldRect(i
, rect
);
188 wxString
text(GetStatusText(i
));
192 dc
.GetTextExtent(text
, &x
, &y
);
194 int xpos
= rect
.x
+ leftMargin
;
195 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
197 #if defined( __WXGTK__ ) || defined(__WXMAC__)
202 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
204 dc
.DrawText(text
, xpos
, ypos
);
206 dc
.DestroyClippingRegion();
209 void wxStatusBarGeneric::DrawField(wxDC
& dc
, int i
)
212 GetFieldRect(i
, rect
);
215 // Have grey background, plus 3-d border -
216 // One black rectangle.
217 // Inside this, left and top sides - dark grey. Bottom and right -
220 dc
.SetPen(m_hilightPen
);
222 // Right and bottom white lines
223 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
224 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
225 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
226 rect
.x
, rect
.y
+ rect
.height
);
228 dc
.SetPen(m_mediumShadowPen
);
230 // Left and top grey lines
231 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
233 dc
.DrawLine(rect
.x
, rect
.y
,
234 rect
.x
+ rect
.width
, rect
.y
);
236 DrawFieldText(dc
, i
);
239 // Get the position and size of the field's internal bounding rectangle
240 bool wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
242 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), FALSE
,
243 _T("invalid status bar field index") );
246 GetClientSize(&width
, &height
);
249 int sum_of_nonvar
= 0;
251 bool do_same_width
= FALSE
;
254 int fieldPosition
= 0;
258 // if sum(not variable Windows) > c_width - (20 points per variable_window)
259 // then do_same_width = TRUE;
260 for (i
= 0; i
< m_nFields
; i
++)
262 if (m_statusWidths
[i
] > 0) sum_of_nonvar
+= m_statusWidths
[i
];
265 if (sum_of_nonvar
> (width
- 20*num_of_var
)) do_same_width
= TRUE
;
267 else do_same_width
= TRUE
;
270 for (i
= 0; i
< m_nFields
; i
++)
272 fieldWidth
= (int)(width
/m_nFields
);
273 fieldPosition
= i
*fieldWidth
;
278 else // no_same_width
280 int *tempwidth
= new int[m_nFields
];
282 for (i
= 0; i
< m_nFields
; i
++)
284 if (m_statusWidths
[i
] > 0) tempwidth
[i
] = m_statusWidths
[i
];
285 else tempwidth
[i
] = (width
- sum_of_nonvar
) / num_of_var
;
287 for (i
= 0; i
< m_nFields
; i
++)
289 fieldWidth
= tempwidth
[i
];
290 fieldPosition
= temppos
;
292 temppos
+= tempwidth
[i
];
300 rect
.x
= fieldPosition
+ wxTHICK_LINE_BORDER
;
301 rect
.y
= wxTHICK_LINE_BORDER
;
303 rect
.width
= fieldWidth
- 2 * wxTHICK_LINE_BORDER
;
304 rect
.height
= height
- 2 * wxTHICK_LINE_BORDER
;
309 // Initialize colours
310 void wxStatusBarGeneric::InitColours()
313 #if defined(__WIN95__)
314 wxColour
mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW
));
315 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
317 wxColour
hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT
));
318 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
320 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
321 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
324 m_defaultStatusBarFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
325 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
328 // Responds to colour changes, and passes event on to children.
329 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
334 // Propagate the event to the non-top-level children
335 wxWindow::OnSysColourChanged(event
);
338 void wxStatusBarGeneric::SetMinHeight(int height
)
340 // check that this min height is not less than minimal height for the
344 dc
.GetTextExtent( _T("X"), NULL
, &y
);
346 if ( height
> (11*y
)/10 )
348 SetSize(-1, -1, -1, height
+ 2*m_borderY
);
352 //#endif // Win32 && wxUSE_NATIVE_STATUSBAR