]>
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 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar
, wxWindow
)
39 BEGIN_EVENT_TABLE(wxStatusBar
, wxWindow
)
40 EVT_PAINT(wxStatusBar::OnPaint
)
41 EVT_SYS_COLOUR_CHANGED(wxStatusBar::OnSysColourChanged
)
44 // Default status border dimensions
45 #define wxTHICK_LINE_BORDER 2
46 #define wxTHICK_LINE_WIDTH 1
48 wxStatusBar::wxStatusBar(void)
50 m_statusWidths
= (int *) NULL
;
51 m_statusStrings
= (wxString
*) NULL
;
53 m_borderX
= wxTHICK_LINE_BORDER
;
54 m_borderY
= wxTHICK_LINE_BORDER
;
57 wxStatusBar::~wxStatusBar(void)
64 delete[] m_statusWidths
;
65 if ( m_statusStrings
)
66 delete[] m_statusStrings
;
69 bool wxStatusBar::Create(wxWindow
*parent
, wxWindowID id
,
75 m_statusWidths
= (int *) NULL
;
76 m_statusStrings
= (wxString
*) NULL
;
78 m_borderX
= wxTHICK_LINE_BORDER
;
79 m_borderY
= wxTHICK_LINE_BORDER
;
81 bool success
= wxWindow::Create(parent
, id
, pos
, size
, style
| wxTAB_TRAVERSAL
, name
);
83 // Don't wish this to be found as a child
85 parent
->GetChildren().DeleteObject(this);
89 SetFont(m_defaultStatusBarFont
);
94 void wxStatusBar::SetFieldsCount(int number
, const int widths
[])
99 delete[] m_statusWidths
;
101 if ( m_statusStrings
)
102 delete[] m_statusStrings
;
104 m_statusStrings
= new wxString
[number
];
107 for (i
= 0; i
< number
; i
++)
108 m_statusStrings
[i
] = "";
111 SetStatusWidths(number
, widths
);
114 void wxStatusBar::SetStatusText(const wxString
& text
, int number
)
116 if ((number
< 0) || (number
>= m_nFields
))
119 m_statusStrings
[number
] = text
;
124 // For some reason, this can cause major GDI problems - graphics
125 // all over the place. E.g. in print previewing.
126 // ::UpdateWindow((HWND) GetHWND());
130 wxString
wxStatusBar::GetStatusText(int n
) const
132 if ((n
< 0) || (n
>= m_nFields
))
135 return m_statusStrings
[n
];
138 void wxStatusBar::SetStatusWidths(int n
, const int widths_field
[])
140 // only set status widths, when n == number of statuswindows
143 // only set status widths,
144 // when one window (minimum) is variable (width <= 0)
145 bool is_variable
= FALSE
;
147 for (i
= 0; i
< m_nFields
; i
++)
149 if (widths_field
[i
] <= 0) is_variable
= TRUE
;
152 // if there are old widths, delete them
154 delete [] m_statusWidths
;
157 m_statusWidths
= new int[n
];
158 for (i
= 0; i
< m_nFields
; i
++)
160 m_statusWidths
[i
] = widths_field
[i
];
165 void wxStatusBar::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
170 if ( GetFont().Ok() )
171 dc
.SetFont(GetFont());
172 dc
.SetBackgroundMode(wxTRANSPARENT
);
174 for ( i
= 0; i
< m_nFields
; i
++ )
178 dc
.SetFont(wxNullFont
);
182 void wxStatusBar::DrawFieldText(wxDC
& dc
, int i
)
187 GetFieldRect(i
, rect
);
189 wxString
text(GetStatusText(i
));
193 dc
.GetTextExtent(text
, &x
, &y
);
195 int xpos
= rect
.x
+ leftMargin
;
196 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
198 #if defined( __WXGTK__ ) || defined(__WXMAC__)
203 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
205 dc
.DrawText(text
, xpos
, ypos
);
207 dc
.DestroyClippingRegion();
210 void wxStatusBar::DrawField(wxDC
& dc
, int i
)
213 GetFieldRect(i
, rect
);
216 // Have grey background, plus 3-d border -
217 // One black rectangle.
218 // Inside this, left and top sides - dark grey. Bottom and right -
221 dc
.SetPen(m_hilightPen
);
223 // Right and bottom white lines
224 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
225 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
226 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
227 rect
.x
, rect
.y
+ rect
.height
);
229 dc
.SetPen(m_mediumShadowPen
);
231 // Left and top grey lines
232 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
234 dc
.DrawLine(rect
.x
, rect
.y
,
235 rect
.x
+ rect
.width
, rect
.y
);
237 DrawFieldText(dc
, i
);
240 // Get the position and size of the field's internal bounding rectangle
241 bool wxStatusBar::GetFieldRect(int n
, wxRect
& rect
) const
243 if ((n
< 0) || (n
>= m_nFields
))
247 GetClientSize(&width
, &height
);
250 int sum_of_nonvar
= 0;
252 bool do_same_width
= FALSE
;
255 int fieldPosition
= 0;
259 // if sum(not variable Windows) > c_width - (20 points per variable_window)
260 // then do_same_width = TRUE;
261 for (i
= 0; i
< m_nFields
; i
++)
263 if (m_statusWidths
[i
] > 0) sum_of_nonvar
+= m_statusWidths
[i
];
266 if (sum_of_nonvar
> (width
- 20*num_of_var
)) do_same_width
= TRUE
;
268 else do_same_width
= TRUE
;
271 for (i
= 0; i
< m_nFields
; i
++)
273 fieldWidth
= (int)(width
/m_nFields
);
274 fieldPosition
= i
*fieldWidth
;
279 else // no_same_width
281 int *tempwidth
= new int[m_nFields
];
283 for (i
= 0; i
< m_nFields
; i
++)
285 if (m_statusWidths
[i
] > 0) tempwidth
[i
] = m_statusWidths
[i
];
286 else tempwidth
[i
] = (width
- sum_of_nonvar
) / num_of_var
;
288 for (i
= 0; i
< m_nFields
; i
++)
290 fieldWidth
= tempwidth
[i
];
291 fieldPosition
= temppos
;
293 temppos
+= tempwidth
[i
];
301 rect
.x
= fieldPosition
+ wxTHICK_LINE_BORDER
;
302 rect
.y
= wxTHICK_LINE_BORDER
;
304 rect
.width
= fieldWidth
- 2 * wxTHICK_LINE_BORDER
;
305 rect
.height
= height
- 2 * wxTHICK_LINE_BORDER
;
310 // Initialize colours
311 void wxStatusBar::InitColours(void)
314 #if defined(__WIN95__)
315 wxColour
mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW
));
316 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
318 wxColour
hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT
));
319 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
321 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
322 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
325 m_defaultStatusBarFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
326 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
329 // Responds to colour changes, and passes event on to children.
330 void wxStatusBar::OnSysColourChanged(wxSysColourChangedEvent
& event
)
335 // Propagate the event to the non-top-level children
336 wxWindow::OnSysColourChanged(event
);