/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/msw/statbr95.cpp
ViewVC logotype

Contents of /branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/msw/statbr95.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22