]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: msw/statbr95.cpp | |
3 | // Purpose: native implementation of wxStatusBar | |
4 | // Author: Vadim Zeitlin | |
ed791986 | 5 | // Modified by: |
2bda0e17 KB |
6 | // Created: 04.04.98 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
9 | // Licence: wxWindows license | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
cfe780fb JS |
12 | #ifdef __GNUG__ |
13 | #pragma implementation "statbr95.h" | |
14 | #endif | |
15 | ||
2bda0e17 KB |
16 | // for compilers that support precompilation, includes "wx.h". |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/setup.h" | |
25 | #include "wx/frame.h" | |
26 | #include "wx/settings.h" | |
27 | #include "wx/dcclient.h" | |
28 | #endif | |
29 | ||
ed791986 | 30 | #if defined(__WIN95__) && wxUSE_NATIVE_STATUSBAR |
2432b92d | 31 | |
608eeb0f | 32 | #include "wx/intl.h" |
2bda0e17 | 33 | #include "wx/log.h" |
ed791986 | 34 | #include "wx/statusbr.h" |
2bda0e17 | 35 | |
42e69d6b VZ |
36 | #include "wx/msw/private.h" |
37 | #include <windowsx.h> | |
2bda0e17 | 38 | |
c42404a5 VZ |
39 | #if !(defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) |
40 | #include <commctrl.h> | |
ce3ed50d JS |
41 | #endif |
42 | ||
ed791986 VZ |
43 | // ---------------------------------------------------------------------------- |
44 | // wxWindows macros | |
45 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 46 | |
ed791986 VZ |
47 | IMPLEMENT_DYNAMIC_CLASS(wxStatusBar95, wxWindow); |
48 | IMPLEMENT_DYNAMIC_CLASS(wxStatusBar, wxStatusBar95) | |
2bda0e17 | 49 | |
2bda0e17 KB |
50 | // ---------------------------------------------------------------------------- |
51 | // macros | |
52 | // ---------------------------------------------------------------------------- | |
53 | ||
54 | // windowsx.h and commctrl.h don't define those, so we do it here | |
55 | #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w) | |
837e5743 | 56 | #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t) |
2bda0e17 | 57 | #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0)) |
837e5743 | 58 | #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s)) |
2bda0e17 | 59 | |
ed791986 VZ |
60 | // ---------------------------------------------------------------------------- |
61 | // | |
62 | // ---------------------------------------------------------------------------- | |
63 | ||
457e6c54 JS |
64 | // static WNDPROC gs_wndprocStatBar = NULL; |
65 | static WXFARPROC gs_wndprocStatBar = (WXFARPROC) NULL; | |
ed791986 VZ |
66 | |
67 | LRESULT APIENTRY wxStatusBarProc(HWND hwnd, | |
68 | UINT message, | |
69 | WPARAM wParam, | |
70 | LPARAM lParam) | |
71 | { | |
72 | if ( message == WM_COMMAND ) | |
73 | { | |
74 | wxStatusBar95 *sb = (wxStatusBar95 *)GetWindowLong(hwnd, GWL_USERDATA); | |
75 | sb->MSWWindowProc(message, wParam, lParam); | |
76 | } | |
77 | ||
66e33344 | 78 | return ::CallWindowProc(CASTWNDPROC gs_wndprocStatBar, hwnd, message, wParam, lParam); |
ed791986 | 79 | } |
2bda0e17 KB |
80 | |
81 | // ============================================================================ | |
82 | // implementation | |
83 | // ============================================================================ | |
84 | ||
85 | // ---------------------------------------------------------------------------- | |
86 | // wxStatusBar95 class | |
87 | // ---------------------------------------------------------------------------- | |
88 | ||
89 | wxStatusBar95::wxStatusBar95() | |
90 | { | |
91 | SetParent(NULL); | |
92 | m_hWnd = 0; | |
93 | m_windowId = 0; | |
94 | } | |
95 | ||
ed791986 VZ |
96 | bool wxStatusBar95::Create(wxWindow *parent, |
97 | wxWindowID id, | |
98 | long style, | |
99 | const wxString& name) | |
2bda0e17 | 100 | { |
cbc66a27 VZ |
101 | wxCHECK_MSG( parent, FALSE, wxT("status bar must have a parent") ); |
102 | ||
ed791986 | 103 | SetName(name); |
cbc66a27 | 104 | SetWindowStyleFlag(style); |
ed791986 VZ |
105 | SetParent(parent); |
106 | ||
cbc66a27 VZ |
107 | parent->AddChild(this); |
108 | ||
109 | m_windowId = id == -1 ? NewControlId() : id; | |
ed791986 VZ |
110 | |
111 | DWORD wstyle = WS_CHILD | WS_VISIBLE; | |
43b5058d VZ |
112 | |
113 | // setting SBARS_SIZEGRIP is perfectly useless: it's always on by default | |
114 | // (at least in the version of comctl32.dll I'm using), and the only way to | |
115 | // turn it off is to use CCS_TOP style - as we position the status bar | |
116 | // manually anyhow (see DoMoveWindow), use CCS_TOP style if wxST_SIZEGRIP | |
117 | // is not given | |
118 | if ( !(style & wxST_SIZEGRIP) ) | |
119 | { | |
120 | wstyle |= CCS_TOP; | |
121 | } | |
122 | else | |
123 | { | |
124 | // may be some versions of comctl32.dll do need it - anyhow, it won't | |
125 | // do any harm | |
ed791986 | 126 | wstyle |= SBARS_SIZEGRIP; |
43b5058d | 127 | } |
ed791986 VZ |
128 | |
129 | m_hWnd = (WXHWND)CreateStatusWindow(wstyle, | |
130 | wxEmptyString, | |
131 | GetHwndOf(parent), | |
132 | m_windowId); | |
133 | if ( m_hWnd == 0 ) | |
134 | { | |
135 | wxLogSysError(_("Failed to create a status bar.")); | |
136 | ||
137 | return FALSE; | |
138 | } | |
2bda0e17 | 139 | |
c6e7d14f RD |
140 | SetFieldsCount(1); |
141 | ||
cbc66a27 VZ |
142 | // we can't subclass this window as usual because the status bar window |
143 | // proc processes WM_SIZE and WM_PAINT specially | |
ed791986 VZ |
144 | // SubclassWin(m_hWnd); |
145 | ||
cbc66a27 VZ |
146 | // but we want to process the messages from it still, so do custom |
147 | // subclassing here | |
457e6c54 | 148 | gs_wndprocStatBar = (WXFARPROC)GetWindowLong(GetHwnd(), GWL_WNDPROC); |
ed791986 VZ |
149 | SetWindowLong(GetHwnd(), GWL_WNDPROC, (LONG)wxStatusBarProc); |
150 | SetWindowLong(GetHwnd(), GWL_USERDATA, (LONG)this); | |
2bda0e17 | 151 | |
ed791986 VZ |
152 | return TRUE; |
153 | } | |
2bda0e17 | 154 | |
ed791986 VZ |
155 | wxStatusBar95::~wxStatusBar95() |
156 | { | |
157 | delete [] m_statusWidths; | |
2bda0e17 KB |
158 | } |
159 | ||
8b9518ee | 160 | void wxStatusBar95::CopyFieldsWidth(const int widths[]) |
2bda0e17 KB |
161 | { |
162 | if (widths && !m_statusWidths) | |
163 | m_statusWidths = new int[m_nFields]; | |
164 | ||
165 | if ( widths != NULL ) { | |
166 | for ( int i = 0; i < m_nFields; i++ ) | |
167 | m_statusWidths[i] = widths[i]; | |
168 | } | |
169 | else { | |
170 | delete [] m_statusWidths; | |
171 | m_statusWidths = NULL; | |
172 | } | |
173 | } | |
174 | ||
790ad94f | 175 | void wxStatusBar95::SetFieldsCount(int nFields, const int *widths) |
2bda0e17 | 176 | { |
ed791986 VZ |
177 | // this is Windows limitation |
178 | wxASSERT_MSG( (nFields > 0) && (nFields < 255), _T("too many fields") ); | |
2bda0e17 KB |
179 | |
180 | m_nFields = nFields; | |
181 | ||
182 | CopyFieldsWidth(widths); | |
183 | SetFieldsWidth(); | |
184 | } | |
185 | ||
8b9518ee | 186 | void wxStatusBar95::SetStatusWidths(int n, const int widths[]) |
2bda0e17 | 187 | { |
ed791986 | 188 | wxASSERT_MSG( n == m_nFields, _T("field number mismatch") ); |
2bda0e17 KB |
189 | |
190 | CopyFieldsWidth(widths); | |
191 | SetFieldsWidth(); | |
192 | } | |
193 | ||
194 | void wxStatusBar95::SetFieldsWidth() | |
195 | { | |
3175c712 VZ |
196 | if ( !m_nFields ) |
197 | return; | |
198 | ||
ed791986 VZ |
199 | int aBorders[3]; |
200 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
2bda0e17 | 201 | |
ed791986 | 202 | int extraWidth = aBorders[2]; // space between fields |
2bda0e17 | 203 | |
ed791986 | 204 | int *pWidths = new int[m_nFields]; |
2bda0e17 | 205 | |
ed791986 VZ |
206 | int nWindowWidth, y; |
207 | GetClientSize(&nWindowWidth, &y); | |
2bda0e17 | 208 | |
ed791986 VZ |
209 | if ( m_statusWidths == NULL ) { |
210 | // default: all fields have the same width | |
211 | int nWidth = nWindowWidth / m_nFields; | |
212 | for ( int i = 0; i < m_nFields; i++ ) | |
213 | pWidths[i] = (i + 1) * nWidth; | |
2bda0e17 | 214 | } |
ed791986 VZ |
215 | else { |
216 | // -1 doesn't mean the same thing for wxWindows and Win32, recalc | |
217 | int nTotalWidth = 0, | |
218 | nVarCount = 0, | |
219 | i; | |
220 | for ( i = 0; i < m_nFields; i++ ) { | |
221 | if ( m_statusWidths[i] == -1 ) | |
222 | nVarCount++; | |
223 | else | |
224 | nTotalWidth += m_statusWidths[i] + extraWidth; | |
225 | } | |
226 | ||
227 | if ( nVarCount == 0 ) { | |
228 | wxFAIL_MSG( _T("at least one field must be of variable width") ); | |
229 | ||
230 | nVarCount++; | |
231 | } | |
232 | ||
233 | int nVarWidth = (nWindowWidth - nTotalWidth) / nVarCount; | |
234 | ||
235 | // do fill the array | |
236 | int nCurPos = 0; | |
237 | for ( i = 0; i < m_nFields; i++ ) { | |
238 | if ( m_statusWidths[i] == -1 ) | |
239 | nCurPos += nVarWidth; | |
240 | else | |
241 | nCurPos += m_statusWidths[i] + extraWidth; | |
242 | pWidths[i] = nCurPos; | |
243 | } | |
2bda0e17 | 244 | } |
2bda0e17 | 245 | |
ed791986 VZ |
246 | if ( !StatusBar_SetParts(GetHwnd(), m_nFields, pWidths) ) { |
247 | wxLogLastError(wxT("StatusBar_SetParts")); | |
248 | } | |
2bda0e17 | 249 | |
ed791986 | 250 | delete [] pWidths; |
2bda0e17 KB |
251 | } |
252 | ||
debe6624 | 253 | void wxStatusBar95::SetStatusText(const wxString& strText, int nField) |
2bda0e17 | 254 | { |
ed791986 VZ |
255 | wxCHECK_RET( (nField >= 0) && (nField < m_nFields), |
256 | _T("invalid statusbar field index") ); | |
257 | ||
258 | if ( !StatusBar_SetText(GetHwnd(), nField, strText) ) { | |
223d09f6 | 259 | wxLogLastError(wxT("StatusBar_SetText")); |
2bda0e17 KB |
260 | } |
261 | } | |
262 | ||
263 | wxString wxStatusBar95::GetStatusText(int nField) const | |
264 | { | |
ed791986 VZ |
265 | wxCHECK_MSG( (nField >= 0) && (nField < m_nFields), wxEmptyString, |
266 | _T("invalid statusbar field index") ); | |
2bda0e17 | 267 | |
ed791986 VZ |
268 | wxString str; |
269 | int len = StatusBar_GetTextLen(GetHwnd(), nField); | |
b7346a70 JS |
270 | if (len > 0) |
271 | { | |
ed791986 VZ |
272 | StatusBar_GetText(GetHwnd(), nField, str.GetWriteBuf(len)); |
273 | str.UngetWriteBuf(); | |
b7346a70 | 274 | } |
2bda0e17 KB |
275 | return str; |
276 | } | |
277 | ||
ed791986 VZ |
278 | int wxStatusBar95::GetBorderX() const |
279 | { | |
280 | int aBorders[3]; | |
281 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
282 | ||
283 | return aBorders[0]; | |
284 | } | |
285 | ||
286 | int wxStatusBar95::GetBorderY() const | |
287 | { | |
288 | int aBorders[3]; | |
289 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
290 | ||
291 | return aBorders[1]; | |
292 | } | |
293 | ||
294 | void wxStatusBar95::SetMinHeight(int height) | |
295 | { | |
296 | SendMessage(GetHwnd(), SB_SETMINHEIGHT, height + 2*GetBorderY(), 0); | |
297 | ||
298 | // have to send a (dummy) WM_SIZE to redraw it now | |
299 | SendMessage(GetHwnd(), WM_SIZE, 0, 0); | |
300 | } | |
301 | ||
302 | bool wxStatusBar95::GetFieldRect(int i, wxRect& rect) const | |
303 | { | |
304 | wxCHECK_MSG( (i >= 0) && (i < m_nFields), FALSE, | |
305 | _T("invalid statusbar field index") ); | |
306 | ||
307 | RECT r; | |
308 | if ( !::SendMessage(GetHwnd(), SB_GETRECT, i, (LPARAM)&r) ) | |
309 | { | |
310 | wxLogLastError("SendMessage(SB_GETRECT)"); | |
311 | } | |
312 | ||
313 | wxCopyRECTToRect(r, rect); | |
314 | ||
315 | return TRUE; | |
316 | } | |
317 | ||
cbc66a27 | 318 | void wxStatusBar95::DoMoveWindow(int x, int y, int width, int height) |
2bda0e17 | 319 | { |
43b5058d VZ |
320 | // the status bar wnd proc must be forwarded the WM_SIZE message whenever |
321 | // the stat bar position/size is changed because it normally positions the | |
322 | // control itself along bottom or top side of the parent window - failing | |
323 | // to do so will result in nasty visual effects | |
324 | FORWARD_WM_SIZE(GetHwnd(), SIZE_RESTORED, x, y, SendMessage); | |
325 | ||
326 | // but now, when the standard status bar wnd proc did all it wanted to do, | |
327 | // move the status bar to its correct location - usually this call may be | |
328 | // omitted because for normal status bars (positioned along the bottom | |
329 | // edge) the position is already set correctly, but if the user wants to | |
330 | // position them in some exotic location, this is really needed | |
331 | wxWindow::DoMoveWindow(x, y, width, height); | |
332 | ||
333 | // adjust fields widths to the new size | |
334 | SetFieldsWidth(); | |
2bda0e17 KB |
335 | } |
336 | ||
ed791986 | 337 | #endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR |
ba681060 | 338 |