]>
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"
34 #include "wx/msw/winundef.h"
37 #if !USE_SHARED_LIBRARY
38 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar
, wxWindow
)
40 BEGIN_EVENT_TABLE(wxStatusBar
, wxWindow
)
41 EVT_PAINT(wxStatusBar::OnPaint
)
42 EVT_SYS_COLOUR_CHANGED(wxStatusBar::OnSysColourChanged
)
46 // Default status border dimensions
47 #define wxTHICK_LINE_BORDER 2
48 #define wxTHICK_LINE_WIDTH 1
50 wxStatusBar::wxStatusBar(void)
52 m_statusWidths
= (int *) NULL
;
53 m_statusStrings
= (wxString
*) NULL
;
55 m_borderX
= wxTHICK_LINE_BORDER
;
56 m_borderY
= wxTHICK_LINE_BORDER
;
59 wxStatusBar::~wxStatusBar(void)
66 delete[] m_statusWidths
;
67 if ( m_statusStrings
)
68 delete[] m_statusStrings
;
71 bool wxStatusBar::Create(wxWindow
*parent
, wxWindowID id
,
77 m_statusWidths
= (int *) NULL
;
78 m_statusStrings
= (wxString
*) NULL
;
80 m_borderX
= wxTHICK_LINE_BORDER
;
81 m_borderY
= wxTHICK_LINE_BORDER
;
83 bool success
= wxWindow::Create(parent
, id
, pos
, size
, style
| wxTAB_TRAVERSAL
, name
);
85 // Don't wish this to be found as a child
86 parent
->GetChildren().DeleteObject(this);
90 SetFont(m_defaultStatusBarFont
);
95 void wxStatusBar::SetFieldsCount(int number
, const int widths
[])
100 delete[] m_statusWidths
;
102 if ( m_statusStrings
)
103 delete[] m_statusStrings
;
105 m_statusStrings
= new wxString
[number
];
108 for (i
= 0; i
< number
; i
++)
109 m_statusStrings
[i
] = "";
112 SetStatusWidths(number
, widths
);
115 void wxStatusBar::SetStatusText(const wxString
& text
, int number
)
117 if ((number
< 0) || (number
>= m_nFields
))
120 m_statusStrings
[number
] = text
;
125 // For some reason, this can cause major GDI problems - graphics
126 // all over the place. E.g. in print previewing.
127 // ::UpdateWindow((HWND) GetHWND());
131 wxString
wxStatusBar::GetStatusText(int n
) const
133 if ((n
< 0) || (n
>= m_nFields
))
136 return m_statusStrings
[n
];
139 void wxStatusBar::SetStatusWidths(int n
, const int widths_field
[])
141 // only set status widths, when n == number of statuswindows
144 // only set status widths,
145 // when one window (minimum) is variable (width <= 0)
146 bool is_variable
= FALSE
;
148 for (i
= 0; i
< m_nFields
; i
++)
150 if (widths_field
[i
] <= 0) is_variable
= TRUE
;
153 // if there are old widths, delete them
155 delete [] m_statusWidths
;
158 m_statusWidths
= new int[n
];
159 for (i
= 0; i
< m_nFields
; i
++)
161 m_statusWidths
[i
] = widths_field
[i
];
166 void wxStatusBar::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
171 if ( GetFont().Ok() )
172 dc
.SetFont(GetFont());
173 dc
.SetBackgroundMode(wxTRANSPARENT
);
175 for ( i
= 0; i
< m_nFields
; i
++ )
179 dc
.SetFont(wxNullFont
);
183 void wxStatusBar::DrawFieldText(wxDC
& dc
, int i
)
188 GetFieldRect(i
, rect
);
190 wxString
text(GetStatusText(i
));
194 dc
.GetTextExtent(text
, &x
, &y
);
196 int xpos
= rect
.x
+ leftMargin
;
197 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
204 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
206 dc
.DrawText(text
, xpos
, ypos
);
208 dc
.DestroyClippingRegion();
211 void wxStatusBar::DrawField(wxDC
& dc
, int i
)
214 GetFieldRect(i
, rect
);
217 // Have grey background, plus 3-d border -
218 // One black rectangle.
219 // Inside this, left and top sides - dark grey. Bottom and right -
222 dc
.SetPen(m_hilightPen
);
224 // Right and bottom white lines
225 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
226 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
227 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
228 rect
.x
, rect
.y
+ rect
.height
);
230 dc
.SetPen(m_mediumShadowPen
);
232 // Left and top grey lines
233 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
235 dc
.DrawLine(rect
.x
, rect
.y
,
236 rect
.x
+ rect
.width
, rect
.y
);
238 DrawFieldText(dc
, i
);
241 // Get the position and size of the field's internal bounding rectangle
242 bool wxStatusBar::GetFieldRect(int n
, wxRect
& rect
) const
244 if ((n
< 0) || (n
>= m_nFields
))
248 GetClientSize(&width
, &height
);
251 int sum_of_nonvar
= 0;
253 bool do_same_width
= FALSE
;
256 int fieldPosition
= 0;
260 // if sum(not variable Windows) > c_width - (20 points per variable_window)
261 // then do_same_width = TRUE;
262 for (i
= 0; i
< m_nFields
; i
++)
264 if (m_statusWidths
[i
] > 0) sum_of_nonvar
+= m_statusWidths
[i
];
267 if (sum_of_nonvar
> (width
- 20*num_of_var
)) do_same_width
= TRUE
;
269 else do_same_width
= TRUE
;
272 for (i
= 0; i
< m_nFields
; i
++)
274 fieldWidth
= (int)(width
/m_nFields
);
275 fieldPosition
= i
*fieldWidth
;
280 else // no_same_width
282 int *tempwidth
= new int[m_nFields
];
284 for (i
= 0; i
< m_nFields
; i
++)
286 if (m_statusWidths
[i
] > 0) tempwidth
[i
] = m_statusWidths
[i
];
287 else tempwidth
[i
] = (width
- sum_of_nonvar
) / num_of_var
;
289 for (i
= 0; i
< m_nFields
; i
++)
291 fieldWidth
= tempwidth
[i
];
292 fieldPosition
= temppos
;
294 temppos
+= tempwidth
[i
];
302 rect
.x
= fieldPosition
+ wxTHICK_LINE_BORDER
;
303 rect
.y
= wxTHICK_LINE_BORDER
;
305 rect
.width
= fieldWidth
- 2 * wxTHICK_LINE_BORDER
;
306 rect
.height
= height
- 2 * wxTHICK_LINE_BORDER
;
311 // Initialize colours
312 void wxStatusBar::InitColours(void)
315 #if defined(__WIN95__)
316 wxColour
mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW
));
317 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
319 wxColour
hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT
));
320 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
322 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
323 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
326 m_defaultStatusBarFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
327 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
330 // Responds to colour changes, and passes event on to children.
331 void wxStatusBar::OnSysColourChanged(wxSysColourChangedEvent
& event
)
336 // Propagate the event to the non-top-level children
337 wxWindow::OnSysColourChanged(event
);