]>
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
= (int *) NULL
;
57 m_statusStrings
= (wxString
*) NULL
;
59 m_borderX
= wxTHICK_LINE_BORDER
;
60 m_borderY
= wxTHICK_LINE_BORDER
;
63 wxStatusBar::~wxStatusBar(void)
70 delete[] m_statusWidths
;
71 if ( m_statusStrings
)
72 delete[] m_statusStrings
;
75 bool wxStatusBar::Create(wxWindow
*parent
, wxWindowID id
,
81 m_statusWidths
= (int *) NULL
;
82 m_statusStrings
= (wxString
*) NULL
;
84 m_borderX
= wxTHICK_LINE_BORDER
;
85 m_borderY
= wxTHICK_LINE_BORDER
;
87 bool success
= wxWindow::Create(parent
, id
, pos
, size
, style
| wxTAB_TRAVERSAL
, name
);
89 // Don't wish this to be found as a child
90 parent
->GetChildren().DeleteObject(this);
94 SetFont(m_defaultStatusBarFont
);
99 void wxStatusBar::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 wxStatusBar::SetStatusText(const wxString
& text
, int number
)
121 if ((number
< 0) || (number
>= m_nFields
))
124 m_statusStrings
[number
] = text
;
129 // For some reason, this can cause major GDI problems - graphics
130 // all over the place. E.g. in print previewing.
131 // ::UpdateWindow((HWND) GetHWND());
135 wxString
wxStatusBar::GetStatusText(int n
) const
137 if ((n
< 0) || (n
>= m_nFields
))
140 return m_statusStrings
[n
];
143 void wxStatusBar::SetStatusWidths(int n
, const int widths_field
[])
145 // only set status widths, when n == number of statuswindows
148 // only set status widths,
149 // when one window (minimum) is variable (width <= 0)
150 bool is_variable
= FALSE
;
152 for (i
= 0; i
< m_nFields
; i
++)
154 if (widths_field
[i
] <= 0) is_variable
= TRUE
;
157 // if there are old widths, delete them
159 delete [] m_statusWidths
;
162 m_statusWidths
= new int[n
];
163 for (i
= 0; i
< m_nFields
; i
++)
165 m_statusWidths
[i
] = widths_field
[i
];
170 void wxStatusBar::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
175 if ( GetFont().Ok() )
176 dc
.SetFont(GetFont());
177 dc
.SetBackgroundMode(wxTRANSPARENT
);
179 for ( i
= 0; i
< m_nFields
; i
++ )
183 dc
.SetFont(wxNullFont
);
187 void wxStatusBar::DrawFieldText(wxDC
& dc
, int i
)
192 GetFieldRect(i
, rect
);
194 wxString
text(GetStatusText(i
));
198 dc
.GetTextExtent(text
, &x
, &y
);
200 int xpos
= rect
.x
+ leftMargin
;
201 int ypos
= (int) (((rect
.height
- y
) / 2 ) + rect
.y
+ 0.5) ;
208 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
210 dc
.DrawText(text
, xpos
, ypos
);
212 dc
.DestroyClippingRegion();
215 void wxStatusBar::DrawField(wxDC
& dc
, int i
)
218 GetFieldRect(i
, rect
);
221 // Have grey background, plus 3-d border -
222 // One black rectangle.
223 // Inside this, left and top sides - dark grey. Bottom and right -
226 dc
.SetPen(m_hilightPen
);
228 // Right and bottom white lines
229 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
,
230 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
231 dc
.DrawLine(rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
232 rect
.x
, rect
.y
+ rect
.height
);
234 dc
.SetPen(m_mediumShadowPen
);
236 // Left and top grey lines
237 dc
.DrawLine(rect
.x
, rect
.y
+ rect
.height
,
239 dc
.DrawLine(rect
.x
, rect
.y
,
240 rect
.x
+ rect
.width
, rect
.y
);
242 DrawFieldText(dc
, i
);
245 // Get the position and size of the field's internal bounding rectangle
246 bool wxStatusBar::GetFieldRect(int n
, wxRect
& rect
) const
248 if ((n
< 0) || (n
>= m_nFields
))
252 GetClientSize(&width
, &height
);
255 int sum_of_nonvar
= 0;
257 bool do_same_width
= FALSE
;
260 int fieldPosition
= 0;
264 // if sum(not variable Windows) > c_width - (20 points per variable_window)
265 // then do_same_width = TRUE;
266 for (i
= 0; i
< m_nFields
; i
++)
268 if (m_statusWidths
[i
] > 0) sum_of_nonvar
+= m_statusWidths
[i
];
271 if (sum_of_nonvar
> (width
- 20*num_of_var
)) do_same_width
= TRUE
;
273 else do_same_width
= TRUE
;
276 for (i
= 0; i
< m_nFields
; i
++)
278 fieldWidth
= (int)(width
/m_nFields
);
279 fieldPosition
= i
*fieldWidth
;
284 else // no_same_width
286 int *tempwidth
= new int[m_nFields
];
288 for (i
= 0; i
< m_nFields
; i
++)
290 if (m_statusWidths
[i
] > 0) tempwidth
[i
] = m_statusWidths
[i
];
291 else tempwidth
[i
] = (width
- sum_of_nonvar
) / num_of_var
;
293 for (i
= 0; i
< m_nFields
; i
++)
295 fieldWidth
= tempwidth
[i
];
296 fieldPosition
= temppos
;
298 temppos
+= tempwidth
[i
];
306 rect
.x
= fieldPosition
+ wxTHICK_LINE_BORDER
;
307 rect
.y
= wxTHICK_LINE_BORDER
;
309 rect
.width
= fieldWidth
- 2 * wxTHICK_LINE_BORDER
;
310 rect
.height
= height
- 2 * wxTHICK_LINE_BORDER
;
315 // Initialize colours
316 void wxStatusBar::InitColours(void)
319 #if defined(__WIN95__)
320 wxColour
mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW
));
321 m_mediumShadowPen
= wxPen(mediumShadowColour
, 1, wxSOLID
);
323 wxColour
hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT
));
324 m_hilightPen
= wxPen(hilightColour
, 1, wxSOLID
);
326 m_mediumShadowPen
= wxPen("GREY", 1, wxSOLID
);
327 m_hilightPen
= wxPen("WHITE", 1, wxSOLID
);
330 m_defaultStatusBarFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
331 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
334 // Responds to colour changes, and passes event on to children.
335 void wxStatusBar::OnSysColourChanged(wxSysColourChangedEvent
& event
)
340 // Propagate the event to the non-top-level children
341 wxWindow::OnSysColourChanged(event
);