]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/statusbr.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxStatusBar 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"
26 #include "wx/settings.h"
27 #include "wx/dcclient.h"
30 #include "wx/generic/statusbr.h"
41 #if !USE_SHARED_LIBRARY
42 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar
, wxWindow
)
44 BEGIN_EVENT_TABLE(wxStatusBar
, wxWindow
)
45 EVT_PAINT(wxStatusBar::OnPaint
)
46 EVT_SYS_COLOUR_CHANGED(wxStatusBar::OnSysColourChanged
)
50 // Default status border dimensions
51 #define wxTHICK_LINE_BORDER 2
52 #define wxTHICK_LINE_WIDTH 1
54 wxStatusBar::wxStatusBar(void)
56 m_statusWidths
= NULL
;
57 m_statusStrings
= NULL
;
59 m_borderX
= wxTHICK_LINE_BORDER
;
60 m_borderY
= wxTHICK_LINE_BORDER
;
63 wxStatusBar::~wxStatusBar(void)
68 delete[] m_statusWidths
;
69 if ( m_statusStrings
)
70 delete[] m_statusStrings
;
73 bool wxStatusBar::Create(wxWindow
*parent
, const wxWindowID id
,
79 m_statusWidths
= NULL
;
80 m_statusStrings
= NULL
;
82 m_borderX
= wxTHICK_LINE_BORDER
;
83 m_borderY
= wxTHICK_LINE_BORDER
;
85 bool success
= wxWindow::Create(parent
, id
, pos
, size
, style
, name
);
87 // Don't wish this to be found as a child
88 parent
->GetChildren()->DeleteObject(this);
92 SetFont(m_defaultStatusBarFont
);
97 void wxStatusBar::SetFieldsCount(const int number
, const int *widths
)
101 if ( m_statusWidths
)
102 delete[] m_statusWidths
;
104 if ( m_statusStrings
)
105 delete[] m_statusStrings
;
107 m_statusStrings
= new wxString
[number
];
110 for (i
= 0; i
< number
; i
++)
111 m_statusStrings
[i
] = "";
114 SetStatusWidths(number
, widths
);
117 void wxStatusBar::SetStatusText(const wxString
& text
, const int number
)
119 if ((number
< 0) || (number
>= m_nFields
))
122 m_statusStrings
[number
] = text
;
127 // For some reason, this can cause major GDI problems - graphics
128 // all over the place. E.g. in print previewing.
129 // ::UpdateWindow((HWND) GetHWND());
133 wxString
wxStatusBar::GetStatusText(const int n
) const
135 if ((n
< 0) || (n
>= m_nFields
))
138 return m_statusStrings
[n
];
141 void wxStatusBar::SetStatusWidths(const int n
, const int *widths_field
)
143 // only set status widths, when n == number of statuswindows
146 // only set status widths,
147 // when one window (minimum) is variable (width <= 0)
148 bool is_variable
= FALSE
;
150 for (i
= 0; i
< m_nFields
; i
++)
152 if (widths_field
[i
] <= 0) is_variable
= TRUE
;
155 // if there are old widths, delete them
157 delete [] m_statusWidths
;
160 m_statusWidths
= new int[n
];
161 for (i
= 0; i
< m_nFields
; i
++)
163 m_statusWidths
[i
] = widths_field
[i
];
168 void wxStatusBar::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
174 dc
.SetFont(*GetFont());
175 dc
.SetBackgroundMode(wxTRANSPARENT
);
177 for ( i
= 0; i
< m_nFields
; i
++ )
181 void wxStatusBar::DrawFieldText(wxDC
& dc
, const 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 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
199 dc
.DrawText(text
, xpos
, ypos
);
201 dc
.DestroyClippingRegion();
204 void wxStatusBar::DrawField(wxDC
& dc
, const int i
)
207 GetFieldRect(i
, rect
);
210 // Have grey background, plus 3-d border -
211 // One black rectangle.
212 // Inside this, left and top sides - dark grey. Bottom and right -
215 dc
.SetPen(m_hilightPen
);
217 // Right and bottom white lines
218 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
219 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
220 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
221 rect
.x
, rect
.y
+ rect
.height
);
223 dc
.SetPen(m_mediumShadowPen
);
225 // Left and top grey lines
226 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
228 dc
.DrawLine(rect
.x
, rect
.y
,
229 rect
.x
+ rect
.width
, rect
.y
);
231 DrawFieldText(dc
, i
);
234 // Get the position and size of the field's internal bounding rectangle
235 bool wxStatusBar::GetFieldRect(const int n
, wxRectangle
& rect
) const
237 if ((n
< 0) || (n
>= m_nFields
))
241 GetClientSize(&width
, &height
);
244 int sum_of_nonvar
= 0;
246 bool do_same_width
= FALSE
;
249 int fieldPosition
= 0;
253 // if sum(not variable Windows) > c_width - (20 points per variable_window)
254 // then do_same_width = TRUE;
255 for (i
= 0; i
< m_nFields
; i
++)
257 if (m_statusWidths
[i
] > 0) sum_of_nonvar
+= m_statusWidths
[i
];
260 if (sum_of_nonvar
> (width
- 20*num_of_var
)) do_same_width
= TRUE
;
262 else do_same_width
= TRUE
;
265 for (i
= 0; i
< m_nFields
; i
++)
267 fieldWidth
= (int)(width
/m_nFields
);
268 fieldPosition
= i
*fieldWidth
;
273 else // no_same_width
275 int *tempwidth
= new int[m_nFields
];
277 for (i
= 0; i
< m_nFields
; i
++)
279 if (m_statusWidths
[i
] > 0) tempwidth
[i
] = m_statusWidths
[i
];
280 else tempwidth
[i
] = (width
- sum_of_nonvar
) / num_of_var
;
282 for (i
= 0; i
< m_nFields
; i
++)
284 fieldWidth
= tempwidth
[i
];
285 fieldPosition
= temppos
;
287 temppos
+= tempwidth
[i
];
295 rect
.x
= fieldPosition
+ wxTHICK_LINE_BORDER
;
296 rect
.y
= wxTHICK_LINE_BORDER
;
298 rect
.width
= fieldWidth
- 2 * wxTHICK_LINE_BORDER
;
299 rect
.height
= height
- 2 * wxTHICK_LINE_BORDER
;
304 // Initialize colours
305 void wxStatusBar::InitColours(void)
308 #if defined(__WIN95__)
309 wxColour
mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW
));
310 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
312 wxColour
hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT
));
313 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
315 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
316 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
319 m_defaultStatusBarFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
320 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
323 // Responds to colour changes, and passes event on to children.
324 void wxStatusBar::OnSysColourChanged(wxSysColourChangedEvent
& event
)
329 // Propagate the event to the non-top-level children
330 wxWindow::OnSysColourChanged(event
);