]>
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 | { | |
bae41109 RD |
72 | switch (message) { |
73 | case WM_COMMAND: | |
f6bcfd97 BP |
74 | case WM_DRAWITEM: |
75 | case WM_MEASUREITEM: | |
bae41109 RD |
76 | case WM_SIZE: |
77 | case WM_MOVE: | |
78 | case WM_MOUSEMOVE: | |
bae41109 RD |
79 | case WM_LBUTTONUP: |
80 | case WM_LBUTTONDBLCLK: | |
81 | case WM_RBUTTONDOWN: | |
82 | case WM_RBUTTONUP: | |
83 | case WM_RBUTTONDBLCLK: | |
84 | case WM_MBUTTONDOWN: | |
85 | case WM_MBUTTONUP: | |
86 | case WM_MBUTTONDBLCLK: | |
87 | wxStatusBar95 *sb = (wxStatusBar95 *)GetWindowLong(hwnd, GWL_USERDATA); | |
88 | sb->MSWWindowProc(message, wParam, lParam); | |
89 | break; | |
ed791986 VZ |
90 | } |
91 | ||
66e33344 | 92 | return ::CallWindowProc(CASTWNDPROC gs_wndprocStatBar, hwnd, message, wParam, lParam); |
ed791986 | 93 | } |
2bda0e17 KB |
94 | |
95 | // ============================================================================ | |
96 | // implementation | |
97 | // ============================================================================ | |
98 | ||
99 | // ---------------------------------------------------------------------------- | |
100 | // wxStatusBar95 class | |
101 | // ---------------------------------------------------------------------------- | |
102 | ||
103 | wxStatusBar95::wxStatusBar95() | |
104 | { | |
105 | SetParent(NULL); | |
106 | m_hWnd = 0; | |
107 | m_windowId = 0; | |
108 | } | |
109 | ||
ed791986 VZ |
110 | bool wxStatusBar95::Create(wxWindow *parent, |
111 | wxWindowID id, | |
112 | long style, | |
113 | const wxString& name) | |
2bda0e17 | 114 | { |
cbc66a27 VZ |
115 | wxCHECK_MSG( parent, FALSE, wxT("status bar must have a parent") ); |
116 | ||
ed791986 | 117 | SetName(name); |
cbc66a27 | 118 | SetWindowStyleFlag(style); |
ed791986 VZ |
119 | SetParent(parent); |
120 | ||
cbc66a27 VZ |
121 | parent->AddChild(this); |
122 | ||
123 | m_windowId = id == -1 ? NewControlId() : id; | |
ed791986 | 124 | |
b0766406 JS |
125 | DWORD wstyle = WS_CHILD | WS_VISIBLE; |
126 | ||
127 | if ( style & wxCLIP_SIBLINGS ) | |
128 | wstyle |= WS_CLIPSIBLINGS; | |
129 | ||
43b5058d VZ |
130 | |
131 | // setting SBARS_SIZEGRIP is perfectly useless: it's always on by default | |
132 | // (at least in the version of comctl32.dll I'm using), and the only way to | |
133 | // turn it off is to use CCS_TOP style - as we position the status bar | |
134 | // manually anyhow (see DoMoveWindow), use CCS_TOP style if wxST_SIZEGRIP | |
135 | // is not given | |
136 | if ( !(style & wxST_SIZEGRIP) ) | |
137 | { | |
138 | wstyle |= CCS_TOP; | |
139 | } | |
140 | else | |
141 | { | |
142 | // may be some versions of comctl32.dll do need it - anyhow, it won't | |
143 | // do any harm | |
ed791986 | 144 | wstyle |= SBARS_SIZEGRIP; |
43b5058d | 145 | } |
ed791986 VZ |
146 | |
147 | m_hWnd = (WXHWND)CreateStatusWindow(wstyle, | |
148 | wxEmptyString, | |
149 | GetHwndOf(parent), | |
150 | m_windowId); | |
151 | if ( m_hWnd == 0 ) | |
152 | { | |
153 | wxLogSysError(_("Failed to create a status bar.")); | |
154 | ||
155 | return FALSE; | |
156 | } | |
2bda0e17 | 157 | |
c6e7d14f RD |
158 | SetFieldsCount(1); |
159 | ||
cbc66a27 VZ |
160 | // we can't subclass this window as usual because the status bar window |
161 | // proc processes WM_SIZE and WM_PAINT specially | |
ed791986 VZ |
162 | // SubclassWin(m_hWnd); |
163 | ||
cbc66a27 VZ |
164 | // but we want to process the messages from it still, so do custom |
165 | // subclassing here | |
457e6c54 | 166 | gs_wndprocStatBar = (WXFARPROC)GetWindowLong(GetHwnd(), GWL_WNDPROC); |
ed791986 VZ |
167 | SetWindowLong(GetHwnd(), GWL_WNDPROC, (LONG)wxStatusBarProc); |
168 | SetWindowLong(GetHwnd(), GWL_USERDATA, (LONG)this); | |
2bda0e17 | 169 | |
ed791986 VZ |
170 | return TRUE; |
171 | } | |
2bda0e17 | 172 | |
ed791986 VZ |
173 | wxStatusBar95::~wxStatusBar95() |
174 | { | |
175 | delete [] m_statusWidths; | |
2bda0e17 KB |
176 | } |
177 | ||
8b9518ee | 178 | void wxStatusBar95::CopyFieldsWidth(const int widths[]) |
2bda0e17 KB |
179 | { |
180 | if (widths && !m_statusWidths) | |
181 | m_statusWidths = new int[m_nFields]; | |
182 | ||
183 | if ( widths != NULL ) { | |
184 | for ( int i = 0; i < m_nFields; i++ ) | |
185 | m_statusWidths[i] = widths[i]; | |
186 | } | |
187 | else { | |
188 | delete [] m_statusWidths; | |
189 | m_statusWidths = NULL; | |
190 | } | |
191 | } | |
192 | ||
790ad94f | 193 | void wxStatusBar95::SetFieldsCount(int nFields, const int *widths) |
2bda0e17 | 194 | { |
f6bcfd97 BP |
195 | // this is a Windows limitation |
196 | wxASSERT_MSG( (nFields > 0) && (nFields < 255), _T("too many fields") ); | |
2bda0e17 | 197 | |
f6bcfd97 | 198 | m_nFields = nFields; |
2bda0e17 | 199 | |
f6bcfd97 BP |
200 | CopyFieldsWidth(widths); |
201 | SetFieldsWidth(); | |
2bda0e17 KB |
202 | } |
203 | ||
3ba55e66 | 204 | void wxStatusBar95::SetStatusWidths(int WXUNUSED_UNLESS_DEBUG(n), const int widths[]) |
2bda0e17 | 205 | { |
f6bcfd97 | 206 | wxASSERT_MSG( n == m_nFields, _T("field number mismatch") ); |
2bda0e17 | 207 | |
f6bcfd97 BP |
208 | CopyFieldsWidth(widths); |
209 | SetFieldsWidth(); | |
2bda0e17 KB |
210 | } |
211 | ||
212 | void wxStatusBar95::SetFieldsWidth() | |
213 | { | |
3175c712 VZ |
214 | if ( !m_nFields ) |
215 | return; | |
216 | ||
ed791986 VZ |
217 | int aBorders[3]; |
218 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
2bda0e17 | 219 | |
ed791986 | 220 | int extraWidth = aBorders[2]; // space between fields |
2bda0e17 | 221 | |
ed791986 | 222 | int *pWidths = new int[m_nFields]; |
2bda0e17 | 223 | |
ed791986 VZ |
224 | int nWindowWidth, y; |
225 | GetClientSize(&nWindowWidth, &y); | |
2bda0e17 | 226 | |
ed791986 VZ |
227 | if ( m_statusWidths == NULL ) { |
228 | // default: all fields have the same width | |
229 | int nWidth = nWindowWidth / m_nFields; | |
230 | for ( int i = 0; i < m_nFields; i++ ) | |
231 | pWidths[i] = (i + 1) * nWidth; | |
2bda0e17 | 232 | } |
ed791986 VZ |
233 | else { |
234 | // -1 doesn't mean the same thing for wxWindows and Win32, recalc | |
235 | int nTotalWidth = 0, | |
236 | nVarCount = 0, | |
237 | i; | |
238 | for ( i = 0; i < m_nFields; i++ ) { | |
239 | if ( m_statusWidths[i] == -1 ) | |
240 | nVarCount++; | |
241 | else | |
242 | nTotalWidth += m_statusWidths[i] + extraWidth; | |
243 | } | |
244 | ||
245 | if ( nVarCount == 0 ) { | |
246 | wxFAIL_MSG( _T("at least one field must be of variable width") ); | |
247 | ||
248 | nVarCount++; | |
249 | } | |
250 | ||
251 | int nVarWidth = (nWindowWidth - nTotalWidth) / nVarCount; | |
252 | ||
253 | // do fill the array | |
254 | int nCurPos = 0; | |
255 | for ( i = 0; i < m_nFields; i++ ) { | |
256 | if ( m_statusWidths[i] == -1 ) | |
257 | nCurPos += nVarWidth; | |
258 | else | |
259 | nCurPos += m_statusWidths[i] + extraWidth; | |
260 | pWidths[i] = nCurPos; | |
261 | } | |
2bda0e17 | 262 | } |
2bda0e17 | 263 | |
ed791986 VZ |
264 | if ( !StatusBar_SetParts(GetHwnd(), m_nFields, pWidths) ) { |
265 | wxLogLastError(wxT("StatusBar_SetParts")); | |
266 | } | |
2bda0e17 | 267 | |
ed791986 | 268 | delete [] pWidths; |
2bda0e17 KB |
269 | } |
270 | ||
debe6624 | 271 | void wxStatusBar95::SetStatusText(const wxString& strText, int nField) |
2bda0e17 | 272 | { |
ed791986 VZ |
273 | wxCHECK_RET( (nField >= 0) && (nField < m_nFields), |
274 | _T("invalid statusbar field index") ); | |
275 | ||
276 | if ( !StatusBar_SetText(GetHwnd(), nField, strText) ) { | |
223d09f6 | 277 | wxLogLastError(wxT("StatusBar_SetText")); |
2bda0e17 KB |
278 | } |
279 | } | |
280 | ||
281 | wxString wxStatusBar95::GetStatusText(int nField) const | |
282 | { | |
ed791986 VZ |
283 | wxCHECK_MSG( (nField >= 0) && (nField < m_nFields), wxEmptyString, |
284 | _T("invalid statusbar field index") ); | |
2bda0e17 | 285 | |
ed791986 VZ |
286 | wxString str; |
287 | int len = StatusBar_GetTextLen(GetHwnd(), nField); | |
b7346a70 JS |
288 | if (len > 0) |
289 | { | |
ed791986 VZ |
290 | StatusBar_GetText(GetHwnd(), nField, str.GetWriteBuf(len)); |
291 | str.UngetWriteBuf(); | |
b7346a70 | 292 | } |
2bda0e17 KB |
293 | return str; |
294 | } | |
295 | ||
ed791986 VZ |
296 | int wxStatusBar95::GetBorderX() const |
297 | { | |
298 | int aBorders[3]; | |
299 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
300 | ||
301 | return aBorders[0]; | |
302 | } | |
303 | ||
304 | int wxStatusBar95::GetBorderY() const | |
305 | { | |
306 | int aBorders[3]; | |
307 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
308 | ||
309 | return aBorders[1]; | |
310 | } | |
311 | ||
312 | void wxStatusBar95::SetMinHeight(int height) | |
313 | { | |
314 | SendMessage(GetHwnd(), SB_SETMINHEIGHT, height + 2*GetBorderY(), 0); | |
315 | ||
316 | // have to send a (dummy) WM_SIZE to redraw it now | |
317 | SendMessage(GetHwnd(), WM_SIZE, 0, 0); | |
318 | } | |
319 | ||
320 | bool wxStatusBar95::GetFieldRect(int i, wxRect& rect) const | |
321 | { | |
322 | wxCHECK_MSG( (i >= 0) && (i < m_nFields), FALSE, | |
323 | _T("invalid statusbar field index") ); | |
324 | ||
325 | RECT r; | |
326 | if ( !::SendMessage(GetHwnd(), SB_GETRECT, i, (LPARAM)&r) ) | |
327 | { | |
f6bcfd97 | 328 | wxLogLastError(wxT("SendMessage(SB_GETRECT)")); |
ed791986 VZ |
329 | } |
330 | ||
331 | wxCopyRECTToRect(r, rect); | |
332 | ||
333 | return TRUE; | |
334 | } | |
335 | ||
cbc66a27 | 336 | void wxStatusBar95::DoMoveWindow(int x, int y, int width, int height) |
2bda0e17 | 337 | { |
43b5058d VZ |
338 | // the status bar wnd proc must be forwarded the WM_SIZE message whenever |
339 | // the stat bar position/size is changed because it normally positions the | |
340 | // control itself along bottom or top side of the parent window - failing | |
341 | // to do so will result in nasty visual effects | |
342 | FORWARD_WM_SIZE(GetHwnd(), SIZE_RESTORED, x, y, SendMessage); | |
343 | ||
344 | // but now, when the standard status bar wnd proc did all it wanted to do, | |
345 | // move the status bar to its correct location - usually this call may be | |
346 | // omitted because for normal status bars (positioned along the bottom | |
347 | // edge) the position is already set correctly, but if the user wants to | |
348 | // position them in some exotic location, this is really needed | |
349 | wxWindow::DoMoveWindow(x, y, width, height); | |
350 | ||
351 | // adjust fields widths to the new size | |
352 | SetFieldsWidth(); | |
2bda0e17 KB |
353 | } |
354 | ||
ed791986 | 355 | #endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR |
ba681060 | 356 |