]> git.saurik.com Git - wxWidgets.git/blob - src/msw/statbr95.cpp
starting blend modes for Core Graphics
[wxWidgets.git] / src / msw / statbr95.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/statbr95.cpp
3 // Purpose: native implementation of wxStatusBar
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 04.04.98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // for compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/setup.h"
21 #include "wx/frame.h"
22 #include "wx/settings.h"
23 #include "wx/dcclient.h"
24 #endif
25
26 #if wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR
27
28 #include "wx/intl.h"
29 #include "wx/log.h"
30 #include "wx/statusbr.h"
31
32 #include "wx/msw/private.h"
33 #include <windowsx.h>
34
35 // include <commctrl.h> "properly"
36 #include "wx/msw/wrapcctl.h"
37
38 // ----------------------------------------------------------------------------
39 // macros
40 // ----------------------------------------------------------------------------
41
42 // windowsx.h and commctrl.h don't define those, so we do it here
43 #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w)
44 #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t)
45 #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
46 #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s))
47
48 // ============================================================================
49 // implementation
50 // ============================================================================
51
52 // ----------------------------------------------------------------------------
53 // wxStatusBar95 class
54 // ----------------------------------------------------------------------------
55
56 wxStatusBar95::wxStatusBar95()
57 {
58 SetParent(NULL);
59 m_hWnd = 0;
60 m_windowId = 0;
61 }
62
63 bool wxStatusBar95::Create(wxWindow *parent,
64 wxWindowID id,
65 long style,
66 const wxString& name)
67 {
68 wxCHECK_MSG( parent, false, wxT("status bar must have a parent") );
69
70 SetName(name);
71 SetWindowStyleFlag(style);
72 SetParent(parent);
73
74 parent->AddChild(this);
75
76 m_windowId = id == wxID_ANY ? NewControlId() : id;
77
78 DWORD wstyle = WS_CHILD | WS_VISIBLE;
79
80 if ( style & wxCLIP_SIBLINGS )
81 wstyle |= WS_CLIPSIBLINGS;
82
83 // setting SBARS_SIZEGRIP is perfectly useless: it's always on by default
84 // (at least in the version of comctl32.dll I'm using), and the only way to
85 // turn it off is to use CCS_TOP style - as we position the status bar
86 // manually anyhow (see DoMoveWindow), use CCS_TOP style if wxST_SIZEGRIP
87 // is not given
88 if ( !(style & wxST_SIZEGRIP) )
89 {
90 wstyle |= CCS_TOP;
91 }
92 else
93 {
94 #ifndef __WXWINCE__
95 // may be some versions of comctl32.dll do need it - anyhow, it won't
96 // do any harm
97 wstyle |= SBARS_SIZEGRIP;
98 #endif
99 }
100
101 m_hWnd = (WXHWND)CreateStatusWindow(wstyle,
102 wxEmptyString,
103 GetHwndOf(parent),
104 m_windowId);
105 if ( m_hWnd == 0 )
106 {
107 wxLogSysError(_("Failed to create a status bar."));
108
109 return false;
110 }
111
112 SetFieldsCount(1);
113 SubclassWin(m_hWnd);
114 InheritAttributes();
115
116 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR));
117
118 // we must refresh the frame size when the statusbar is created, because
119 // its client area might change
120 wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
121 if ( frame )
122 {
123 frame->SendSizeEvent();
124 }
125
126 return true;
127 }
128
129 wxStatusBar95::~wxStatusBar95()
130 {
131 // we must refresh the frame size when the statusbar is deleted but the
132 // frame is not - otherwise statusbar leaves a hole in the place it used to
133 // occupy
134 wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
135 if ( frame && !frame->IsBeingDeleted() )
136 {
137 frame->SendSizeEvent();
138 }
139 }
140
141 void wxStatusBar95::SetFieldsCount(int nFields, const int *widths)
142 {
143 // this is a Windows limitation
144 wxASSERT_MSG( (nFields > 0) && (nFields < 255), _T("too many fields") );
145
146 wxStatusBarBase::SetFieldsCount(nFields, widths);
147
148 SetFieldsWidth();
149 }
150
151 void wxStatusBar95::SetStatusWidths(int n, const int widths[])
152 {
153 wxStatusBarBase::SetStatusWidths(n, widths);
154
155 SetFieldsWidth();
156 }
157
158 void wxStatusBar95::SetFieldsWidth()
159 {
160 if ( !m_nFields )
161 return;
162
163 int aBorders[3];
164 SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders);
165
166 int extraWidth = aBorders[2]; // space between fields
167
168 wxArrayInt widthsAbs =
169 CalculateAbsWidths(GetClientSize().x - extraWidth*(m_nFields - 1));
170
171 int *pWidths = new int[m_nFields];
172
173 int nCurPos = 0;
174 for ( int i = 0; i < m_nFields; i++ ) {
175 nCurPos += widthsAbs[i] + extraWidth;
176 pWidths[i] = nCurPos;
177 }
178
179 if ( !StatusBar_SetParts(GetHwnd(), m_nFields, pWidths) ) {
180 wxLogLastError(wxT("StatusBar_SetParts"));
181 }
182
183 delete [] pWidths;
184 }
185
186 void wxStatusBar95::SetStatusText(const wxString& strText, int nField)
187 {
188 wxCHECK_RET( (nField >= 0) && (nField < m_nFields),
189 _T("invalid statusbar field index") );
190
191 // Get field style, if any
192 int style;
193 if (m_statusStyles)
194 {
195 switch(m_statusStyles[nField])
196 {
197 case wxSB_RAISED:
198 style = SBT_POPOUT;
199 break;
200 case wxSB_FLAT:
201 style = SBT_NOBORDERS;
202 break;
203 case wxSB_NORMAL:
204 default:
205 style = 0;
206 break;
207 }
208 }
209 else
210 style = 0;
211
212 // Pass both field number and style. MSDN library doesn't mention
213 // that nField and style have to be 'ORed'
214 if ( !StatusBar_SetText(GetHwnd(), nField | style, strText) )
215 {
216 wxLogLastError(wxT("StatusBar_SetText"));
217 }
218 }
219
220 wxString wxStatusBar95::GetStatusText(int nField) const
221 {
222 wxCHECK_MSG( (nField >= 0) && (nField < m_nFields), wxEmptyString,
223 _T("invalid statusbar field index") );
224
225 wxString str;
226 int len = StatusBar_GetTextLen(GetHwnd(), nField);
227 if ( len > 0 )
228 {
229 StatusBar_GetText(GetHwnd(), nField, wxStringBuffer(str, len));
230 }
231
232 return str;
233 }
234
235 int wxStatusBar95::GetBorderX() const
236 {
237 int aBorders[3];
238 SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders);
239
240 return aBorders[0];
241 }
242
243 int wxStatusBar95::GetBorderY() const
244 {
245 int aBorders[3];
246 SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders);
247
248 return aBorders[1];
249 }
250
251 void wxStatusBar95::SetMinHeight(int height)
252 {
253 SendMessage(GetHwnd(), SB_SETMINHEIGHT, height + 2*GetBorderY(), 0);
254
255 // have to send a (dummy) WM_SIZE to redraw it now
256 SendMessage(GetHwnd(), WM_SIZE, 0, 0);
257 }
258
259 bool wxStatusBar95::GetFieldRect(int i, wxRect& rect) const
260 {
261 wxCHECK_MSG( (i >= 0) && (i < m_nFields), false,
262 _T("invalid statusbar field index") );
263
264 RECT r;
265 if ( !::SendMessage(GetHwnd(), SB_GETRECT, i, (LPARAM)&r) )
266 {
267 wxLogLastError(wxT("SendMessage(SB_GETRECT)"));
268 }
269
270 wxCopyRECTToRect(r, rect);
271
272 return true;
273 }
274
275 #ifndef SWP_NOSENDCHANGING
276 #define SWP_NOSENDCHANGING 0
277 #endif
278
279 void wxStatusBar95::DoMoveWindow(int x, int y, int width, int height)
280 {
281 if ( GetParent()->IsSizeDeferred() )
282 {
283 wxWindowMSW::DoMoveWindow(x, y, width, height);
284 }
285 else
286 {
287 // parent pos/size isn't deferred so do it now but don't send
288 // WM_WINDOWPOSCHANGING since we don't want to change pos/size later
289 ::SetWindowPos(GetHwnd(), NULL, x, y, width, height,
290 SWP_NOZORDER | SWP_NOSENDCHANGING);
291 }
292
293 // adjust fields widths to the new size
294 SetFieldsWidth();
295
296 // we have to trigger wxSizeEvent if there are children window in status
297 // bar because GetFieldRect returned incorrect (not updated) values up to
298 // here, which almost certainly resulted in incorrectly redrawn statusbar
299 if ( m_children.GetCount() > 0 )
300 {
301 wxSizeEvent event(GetClientSize(), m_windowId);
302 event.SetEventObject(this);
303 GetEventHandler()->ProcessEvent(event);
304 }
305 }
306
307 void wxStatusBar95::SetStatusStyles(int n, const int styles[])
308 {
309 wxStatusBarBase::SetStatusStyles(n, styles);
310
311 if (n != m_nFields)
312 return;
313
314 for (int i = 0; i < n; i++)
315 {
316 int style;
317 switch(styles[i])
318 {
319 case wxSB_RAISED:
320 style = SBT_POPOUT;
321 break;
322 case wxSB_FLAT:
323 style = SBT_NOBORDERS;
324 break;
325 case wxSB_NORMAL:
326 default:
327 style = 0;
328 break;
329 }
330 // The SB_SETTEXT message is both used to set the field's text as well as
331 // the fields' styles. MSDN library doesn't mention
332 // that nField and style have to be 'ORed'
333 wxString text = GetStatusText(i);
334 if (!StatusBar_SetText(GetHwnd(), style | i, text))
335 {
336 wxLogLastError(wxT("StatusBar_SetText"));
337 }
338 }
339 }
340
341 WXLRESULT
342 wxStatusBar95::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
343 {
344 #ifndef __WXWINCE__
345 if ( nMsg == WM_WINDOWPOSCHANGING )
346 {
347 WINDOWPOS *lpPos = (WINDOWPOS *)lParam;
348 int x, y, w, h;
349 GetPosition(&x, &y);
350 GetSize(&w, &h);
351
352 // we need real window coords and not wx client coords
353 AdjustForParentClientOrigin(x, y);
354
355 lpPos->x = x;
356 lpPos->y = y;
357 lpPos->cx = w;
358 lpPos->cy = h;
359
360 return 0;
361 }
362
363 if ( nMsg == WM_NCLBUTTONDOWN )
364 {
365 // if hit-test is on gripper then send message to TLW to begin
366 // resizing. It is possible to send this message to any window.
367 if ( wParam == HTBOTTOMRIGHT )
368 {
369 wxWindow *win;
370
371 for ( win = GetParent(); win; win = win->GetParent() )
372 {
373 if ( win->IsTopLevel() )
374 {
375 SendMessage(GetHwndOf(win), WM_NCLBUTTONDOWN,
376 wParam, lParam);
377
378 return 0;
379 }
380 }
381 }
382 }
383 #endif
384
385 return wxStatusBarBase::MSWWindowProc(nMsg, wParam, lParam);
386 }
387
388 #endif // wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR