]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/statbr95.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: 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 license
10 ///////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "statbr95.h"
16 // for compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/settings.h"
27 #include "wx/dcclient.h"
33 #include "wx/generic/statusbr.h"
34 #include "wx/msw/statbr95.h"
36 #include "wx/msw/private.h"
39 #if !defined(__GNUWIN32__) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
43 #if wxUSE_NATIVE_STATUSBAR
45 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar95
, wxStatusBar
);
47 BEGIN_EVENT_TABLE(wxStatusBar95
, wxStatusBar
)
48 EVT_SIZE(wxStatusBar95::OnSize
)
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 // windowsx.h and commctrl.h don't define those, so we do it here
57 #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w)
58 #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t)
59 #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
60 #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s))
62 #define hwnd ((HWND)m_hWnd)
64 // ============================================================================
66 // ============================================================================
68 // ----------------------------------------------------------------------------
69 // wxStatusBar95 class
70 // ----------------------------------------------------------------------------
72 wxStatusBar95::wxStatusBar95()
79 wxStatusBar95::wxStatusBar95(wxWindow
*parent
, wxWindowID id
, long style
)
81 Create(parent
, id
, style
);
84 bool wxStatusBar95::Create(wxWindow
*parent
, wxWindowID id
, long style
)
89 m_windowId
= NewControlId();
93 DWORD wstyle
= WS_CHILD
| WS_VISIBLE
;
94 if ( style
& wxST_SIZEGRIP
)
95 wstyle
|= SBARS_SIZEGRIP
;
97 m_hWnd
= (WXHWND
)CreateStatusWindow(wstyle
,
99 (HWND
)parent
->GetHWND(),
102 wxLogSysError(wxT("can't create status bar window"));
106 // this doesn't work: display problems (white 1-2 pixel borders...)
107 // SubclassWin(m_hWnd);
112 void wxStatusBar95::CopyFieldsWidth(const int widths
[])
114 if (widths
&& !m_statusWidths
)
115 m_statusWidths
= new int[m_nFields
];
117 if ( widths
!= NULL
) {
118 for ( int i
= 0; i
< m_nFields
; i
++ )
119 m_statusWidths
[i
] = widths
[i
];
122 delete [] m_statusWidths
;
123 m_statusWidths
= NULL
;
127 void wxStatusBar95::SetFieldsCount(int nFields
, const int widths
[])
129 wxASSERT( (nFields
> 0) && (nFields
< 255) );
133 CopyFieldsWidth(widths
);
137 void wxStatusBar95::SetStatusWidths(int n
, const int widths
[])
139 // @@ I don't understand what this function is for...
140 wxASSERT( n
== m_nFields
);
142 CopyFieldsWidth(widths
);
146 void wxStatusBar95::SetFieldsWidth()
151 int *pWidths
= new int[m_nFields
];
154 GetClientSize(&nWindowWidth
, &y
);
156 if ( m_statusWidths
== NULL
) {
157 // default: all fields have the same width
158 int nWidth
= nWindowWidth
/ m_nFields
;
159 for ( int i
= 0; i
< m_nFields
; i
++ )
160 pWidths
[i
] = (i
+ 1) * nWidth
;
163 // -1 doesn't mean the same thing for wxWindows and Win32, recalc
167 for ( i
= 0; i
< m_nFields
; i
++ ) {
168 if ( m_statusWidths
[i
] == -1 )
171 nTotalWidth
+= m_statusWidths
[i
];
174 if ( nVarCount
== 0 ) {
175 // wrong! at least one field must be of variable width
181 int nVarWidth
= (nWindowWidth
- nTotalWidth
) / nVarCount
;
185 for ( i
= 0; i
< m_nFields
; i
++ ) {
186 if ( m_statusWidths
[i
] == -1 )
187 nCurPos
+= nVarWidth
;
189 nCurPos
+= m_statusWidths
[i
];
190 pWidths
[i
] = nCurPos
;
194 if ( !StatusBar_SetParts(hwnd
, m_nFields
, pWidths
) ) {
195 wxLogLastError(wxT("StatusBar_SetParts"));
201 void wxStatusBar95::SetStatusText(const wxString
& strText
, int nField
)
203 if ( !StatusBar_SetText(hwnd
, nField
, strText
) ) {
204 wxLogLastError(wxT("StatusBar_SetText"));
208 wxString
wxStatusBar95::GetStatusText(int nField
) const
210 wxASSERT( (nField
> -1) && (nField
< m_nFields
) );
212 wxString
str(wxT(""));
213 int len
= StatusBar_GetTextLen(hwnd
, nField
);
216 StatusBar_GetText(hwnd
, nField
, str
.GetWriteBuf(len
));
222 void wxStatusBar95::OnSize(wxSizeEvent
& event
)
224 FORWARD_WM_SIZE(hwnd
, SIZE_RESTORED
, event
.GetSize().x
, event
.GetSize().y
,
227 // adjust fields widths to the new size
231 #endif // wxUSE_NATIVE_STATUSBAR
234 #error "wxStatusBar95 is only available under Windows 95 and later."