]>
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/generic/statusbr.h"
36 #include "wx/msw/winundef.h"
39 IMPLEMENT_DYNAMIC_CLASS(wxStatusBarGeneric
, wxWindow
)
41 #if !defined(__WIN32__) || !wxUSE_NATIVE_STATUSBAR
42 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar
, wxStatusBarGeneric
)
43 #endif // Win32 && wxUSE_NATIVE_STATUSBAR
45 BEGIN_EVENT_TABLE(wxStatusBarGeneric
, wxWindow
)
46 EVT_PAINT(wxStatusBarGeneric::OnPaint
)
47 EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged
)
50 // Default status border dimensions
51 #define wxTHICK_LINE_BORDER 2
52 #define wxTHICK_LINE_WIDTH 1
54 wxStatusBarGeneric::wxStatusBarGeneric()
56 m_statusWidths
= (int *) NULL
;
57 m_statusStrings
= (wxString
*) NULL
;
59 m_borderX
= wxTHICK_LINE_BORDER
;
60 m_borderY
= wxTHICK_LINE_BORDER
;
63 wxStatusBarGeneric::~wxStatusBarGeneric()
70 delete[] m_statusWidths
;
71 if ( m_statusStrings
)
72 delete[] m_statusStrings
;
75 bool wxStatusBarGeneric::Create(wxWindow
*parent
,
80 m_statusWidths
= (int *) NULL
;
81 m_statusStrings
= (wxString
*) NULL
;
83 m_borderX
= wxTHICK_LINE_BORDER
;
84 m_borderY
= wxTHICK_LINE_BORDER
;
86 bool success
= wxWindow::Create(parent
, id
,
87 wxDefaultPosition
, wxDefaultSize
,
88 style
| wxTAB_TRAVERSAL
, name
);
90 // Don't wish this to be found as a child
92 parent
->GetChildren().DeleteObject(this);
96 SetFont(m_defaultStatusBarFont
);
101 void wxStatusBarGeneric::SetFieldsCount(int number
, const int widths
[])
105 if ( m_statusWidths
)
106 delete[] m_statusWidths
;
108 if ( m_statusStrings
)
109 delete[] m_statusStrings
;
111 m_statusStrings
= new wxString
[number
];
114 for (i
= 0; i
< number
; i
++)
115 m_statusStrings
[i
] = "";
118 SetStatusWidths(number
, widths
);
121 void wxStatusBarGeneric::SetStatusText(const wxString
& text
, int number
)
123 if ((number
< 0) || (number
>= m_nFields
))
126 m_statusStrings
[number
] = text
;
131 wxString
wxStatusBarGeneric::GetStatusText(int n
) const
133 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), wxEmptyString
,
134 _T("invalid status bar field index") );
136 return m_statusStrings
[n
];
139 void wxStatusBarGeneric::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 wxStatusBarGeneric::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 wxStatusBarGeneric::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) ;
199 #if defined( __WXGTK__ ) || defined(__WXMAC__)
204 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
206 dc
.DrawText(text
, xpos
, ypos
);
208 dc
.DestroyClippingRegion();
211 void wxStatusBarGeneric::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 wxStatusBarGeneric::GetFieldRect(int n
, wxRect
& rect
) const
244 wxCHECK_MSG( (n
>= 0) && (n
< m_nFields
), FALSE
,
245 _T("invalid status bar field index") );
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 wxStatusBarGeneric::InitColours()
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 wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent
& event
)
336 // Propagate the event to the non-top-level children
337 wxWindow::OnSysColourChanged(event
);
340 void wxStatusBarGeneric::SetMinHeight(int height
)
342 // check that this min height is not less than minimal height for the
346 dc
.GetTextExtent( _T("X"), NULL
, &y
);
348 if ( height
> (11*y
)/10 )
350 SetSize(-1, -1, -1, height
+ 2*m_borderY
);
354 //#endif // Win32 && wxUSE_NATIVE_STATUSBAR