]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/statbr95.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/statbr95.cpp
3 // Purpose: native implementation of wxStatusBar
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // for compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #if wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR
21 #include "wx/statusbr.h"
24 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
26 #include "wx/settings.h"
27 #include "wx/dcclient.h"
32 #include "wx/msw/private.h"
36 #include "wx/msw/uxtheme.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
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))
49 // ============================================================================
51 // ============================================================================
53 // ----------------------------------------------------------------------------
54 // wxStatusBar95 class
55 // ----------------------------------------------------------------------------
57 wxStatusBar95::wxStatusBar95()
64 bool wxStatusBar95::Create(wxWindow
*parent
,
69 wxCHECK_MSG( parent
, false, wxT("status bar must have a parent") );
72 SetWindowStyleFlag(style
);
75 parent
->AddChild(this);
77 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
79 DWORD wstyle
= WS_CHILD
| WS_VISIBLE
;
81 if ( style
& wxCLIP_SIBLINGS
)
82 wstyle
|= WS_CLIPSIBLINGS
;
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
89 if ( !(style
& wxST_SIZEGRIP
) )
96 // may be some versions of comctl32.dll do need it - anyhow, it won't
98 wstyle
|= SBARS_SIZEGRIP
;
102 m_hWnd
= (WXHWND
)CreateStatusWindow(wstyle
,
108 wxLogSysError(_("Failed to create a status bar."));
117 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
));
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
);
124 frame
->SendSizeEvent();
130 wxStatusBar95::~wxStatusBar95()
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
135 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
136 if ( frame
&& !frame
->IsBeingDeleted() )
138 frame
->SendSizeEvent();
142 void wxStatusBar95::SetFieldsCount(int nFields
, const int *widths
)
144 // this is a Windows limitation
145 wxASSERT_MSG( (nFields
> 0) && (nFields
< 255), _T("too many fields") );
147 wxStatusBarBase::SetFieldsCount(nFields
, widths
);
152 void wxStatusBar95::SetStatusWidths(int n
, const int widths
[])
154 wxStatusBarBase::SetStatusWidths(n
, widths
);
159 void wxStatusBar95::SetFieldsWidth()
165 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
167 int extraWidth
= aBorders
[2]; // space between fields
169 wxArrayInt widthsAbs
=
170 CalculateAbsWidths(GetClientSize().x
- extraWidth
*(m_nFields
- 1));
172 int *pWidths
= new int[m_nFields
];
175 for ( int i
= 0; i
< m_nFields
; i
++ ) {
176 nCurPos
+= widthsAbs
[i
] + extraWidth
;
177 pWidths
[i
] = nCurPos
;
180 if ( !StatusBar_SetParts(GetHwnd(), m_nFields
, pWidths
) ) {
181 wxLogLastError(wxT("StatusBar_SetParts"));
187 void wxStatusBar95::SetStatusText(const wxString
& strText
, int nField
)
189 wxCHECK_RET( (nField
>= 0) && (nField
< m_nFields
),
190 _T("invalid statusbar field index") );
192 if ( strText
== GetStatusText(nField
) )
194 // don't call StatusBar_SetText() to avoid flicker
198 // Get field style, if any
202 switch(m_statusStyles
[nField
])
208 style
= SBT_NOBORDERS
;
219 // Pass both field number and style. MSDN library doesn't mention
220 // that nField and style have to be 'ORed'
221 if ( !StatusBar_SetText(GetHwnd(), nField
| style
, strText
.wx_str()) )
223 wxLogLastError(wxT("StatusBar_SetText"));
227 wxString
wxStatusBar95::GetStatusText(int nField
) const
229 wxCHECK_MSG( (nField
>= 0) && (nField
< m_nFields
), wxEmptyString
,
230 _T("invalid statusbar field index") );
233 int len
= StatusBar_GetTextLen(GetHwnd(), nField
);
236 StatusBar_GetText(GetHwnd(), nField
, wxStringBuffer(str
, len
));
242 int wxStatusBar95::GetBorderX() const
245 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
250 int wxStatusBar95::GetBorderY() const
253 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
258 void wxStatusBar95::SetMinHeight(int height
)
260 SendMessage(GetHwnd(), SB_SETMINHEIGHT
, height
+ 2*GetBorderY(), 0);
262 // have to send a (dummy) WM_SIZE to redraw it now
263 SendMessage(GetHwnd(), WM_SIZE
, 0, 0);
266 bool wxStatusBar95::GetFieldRect(int i
, wxRect
& rect
) const
268 wxCHECK_MSG( (i
>= 0) && (i
< m_nFields
), false,
269 _T("invalid statusbar field index") );
272 if ( !::SendMessage(GetHwnd(), SB_GETRECT
, i
, (LPARAM
)&r
) )
274 wxLogLastError(wxT("SendMessage(SB_GETRECT)"));
278 wxUxThemeHandle
theme((wxStatusBar95
*)this, L
"Status"); // const_cast
281 // by default Windows has a 2 pixel border to the right of the left
282 // divider (or it could be a bug) but it looks wrong so remove it
288 wxUxThemeEngine::Get()->GetThemeBackgroundContentRect(theme
, NULL
,
294 wxCopyRECTToRect(r
, rect
);
299 // no idea for a default width, just choose something
300 #define DEFAULT_FIELD_WIDTH 25
302 wxSize
wxStatusBar95::DoGetBestSize() const
305 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)borders
);
309 for ( int i
= 0; i
< m_nFields
; ++i
)
311 int widthField
= m_statusWidths
? m_statusWidths
[i
]
312 : DEFAULT_FIELD_WIDTH
;
313 if ( widthField
>= 0 )
315 width
+= m_statusWidths
[i
];
319 // variable width field, its width is really a proportion
320 // related to the other fields
321 width
+= -widthField
*DEFAULT_FIELD_WIDTH
;
324 // add the space between fields
330 // still need something even for an empty status bar
331 width
= 2*DEFAULT_FIELD_WIDTH
;
337 wxGetCharSize(GetHWND(), NULL
, &height
, GetFont());
338 height
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(height
);
339 height
+= borders
[1];
341 wxSize
best(width
, height
);
346 void wxStatusBar95::DoMoveWindow(int x
, int y
, int width
, int height
)
348 if ( GetParent()->IsSizeDeferred() )
350 wxWindowMSW::DoMoveWindow(x
, y
, width
, height
);
354 // parent pos/size isn't deferred so do it now but don't send
355 // WM_WINDOWPOSCHANGING since we don't want to change pos/size later
356 // we must use SWP_NOCOPYBITS here otherwise it paints incorrectly
357 // if other windows are size deferred
358 ::SetWindowPos(GetHwnd(), NULL
, x
, y
, width
, height
,
359 SWP_NOZORDER
| SWP_NOOWNERZORDER
| SWP_NOACTIVATE
361 | SWP_NOCOPYBITS
| SWP_NOSENDCHANGING
366 // adjust fields widths to the new size
369 // we have to trigger wxSizeEvent if there are children window in status
370 // bar because GetFieldRect returned incorrect (not updated) values up to
371 // here, which almost certainly resulted in incorrectly redrawn statusbar
372 if ( m_children
.GetCount() > 0 )
374 wxSizeEvent
event(GetClientSize(), m_windowId
);
375 event
.SetEventObject(this);
376 GetEventHandler()->ProcessEvent(event
);
380 void wxStatusBar95::SetStatusStyles(int n
, const int styles
[])
382 wxStatusBarBase::SetStatusStyles(n
, styles
);
387 for (int i
= 0; i
< n
; i
++)
396 style
= SBT_NOBORDERS
;
403 // The SB_SETTEXT message is both used to set the field's text as well as
404 // the fields' styles. MSDN library doesn't mention
405 // that nField and style have to be 'ORed'
406 wxString text
= GetStatusText(i
);
407 if (!StatusBar_SetText(GetHwnd(), style
| i
, text
.wx_str()))
409 wxLogLastError(wxT("StatusBar_SetText"));
415 wxStatusBar95::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
418 if ( nMsg
== WM_WINDOWPOSCHANGING
)
420 WINDOWPOS
*lpPos
= (WINDOWPOS
*)lParam
;
425 // we need real window coords and not wx client coords
426 AdjustForParentClientOrigin(x
, y
);
436 if ( nMsg
== WM_NCLBUTTONDOWN
)
438 // if hit-test is on gripper then send message to TLW to begin
439 // resizing. It is possible to send this message to any window.
440 if ( wParam
== HTBOTTOMRIGHT
)
444 for ( win
= GetParent(); win
; win
= win
->GetParent() )
446 if ( win
->IsTopLevel() )
448 SendMessage(GetHwndOf(win
), WM_NCLBUTTONDOWN
,
458 return wxStatusBarBase::MSWWindowProc(nMsg
, wParam
, lParam
);
461 #endif // wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR