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