]>
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__)
43 #if wxUSE_NATIVE_STATUSBAR
45 #if !USE_SHARED_LIBRARY
46 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar95
, wxStatusBar
);
48 BEGIN_EVENT_TABLE(wxStatusBar95
, wxStatusBar
)
49 EVT_SIZE(wxStatusBar95::OnSize
)
51 #endif //USE_SHARED_LIBRARY
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 // windowsx.h and commctrl.h don't define those, so we do it here
59 #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w)
60 #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCSTR)t)
61 #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
62 #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPSTR)s))
64 #define hwnd ((HWND)m_hWnd)
66 // ============================================================================
68 // ============================================================================
70 // ----------------------------------------------------------------------------
71 // wxStatusBar95 class
72 // ----------------------------------------------------------------------------
74 wxStatusBar95::wxStatusBar95()
81 wxStatusBar95::wxStatusBar95(wxWindow
*parent
, wxWindowID id
, long style
)
83 Create(parent
, id
, style
);
86 bool wxStatusBar95::Create(wxWindow
*parent
, wxWindowID id
, long style
)
91 m_windowId
= NewControlId();
95 DWORD wstyle
= WS_CHILD
| WS_VISIBLE
;
96 if ( style
& wxST_SIZEGRIP
)
97 wstyle
|= SBARS_SIZEGRIP
;
99 m_hWnd
= (WXHWND
)CreateStatusWindow(wstyle
,
101 (HWND
)parent
->GetHWND(),
104 wxLogSysError("can't create status bar window");
108 // this doesn't work: display problems (white 1-2 pixel borders...)
109 // SubclassWin(m_hWnd);
114 void wxStatusBar95::CopyFieldsWidth(const int widths
[])
116 if (widths
&& !m_statusWidths
)
117 m_statusWidths
= new int[m_nFields
];
119 if ( widths
!= NULL
) {
120 for ( int i
= 0; i
< m_nFields
; i
++ )
121 m_statusWidths
[i
] = widths
[i
];
124 delete [] m_statusWidths
;
125 m_statusWidths
= NULL
;
129 void wxStatusBar95::SetFieldsCount(int nFields
, const int widths
[])
131 wxASSERT( (nFields
> 0) && (nFields
< 255) );
135 CopyFieldsWidth(widths
);
139 void wxStatusBar95::SetStatusWidths(int n
, const int widths
[])
141 // @@ I don't understand what this function is for...
142 wxASSERT( n
== m_nFields
);
144 CopyFieldsWidth(widths
);
148 void wxStatusBar95::SetFieldsWidth()
150 int *pWidths
= new int[m_nFields
];
153 GetClientSize(&nWindowWidth
, &y
);
155 if ( m_statusWidths
== NULL
) {
156 // default: all fields have the same width
157 int nWidth
= nWindowWidth
/ m_nFields
;
158 for ( int i
= 0; i
< m_nFields
; i
++ )
159 pWidths
[i
] = (i
+ 1) * nWidth
;
162 // -1 doesn't mean the same thing for wxWindows and Win32, recalc
166 for ( i
= 0; i
< m_nFields
; i
++ ) {
167 if ( m_statusWidths
[i
] == -1 )
170 nTotalWidth
+= m_statusWidths
[i
];
173 if ( nVarCount
== 0 ) {
174 // wrong! at least one field must be of variable width
180 int nVarWidth
= (nWindowWidth
- nTotalWidth
) / nVarCount
;
184 for ( i
= 0; i
< m_nFields
; i
++ ) {
185 if ( m_statusWidths
[i
] == -1 )
186 nCurPos
+= nVarWidth
;
188 nCurPos
+= m_statusWidths
[i
];
189 pWidths
[i
] = nCurPos
;
193 if ( !StatusBar_SetParts(hwnd
, m_nFields
, pWidths
) ) {
194 wxLogDebug("StatusBar_SetParts failed.");
200 void wxStatusBar95::SetStatusText(const wxString
& strText
, int nField
)
202 if ( !StatusBar_SetText(hwnd
, nField
, strText
) ) {
203 wxLogDebug("StatusBar_SetText failed");
207 wxString
wxStatusBar95::GetStatusText(int nField
) const
209 wxASSERT( (nField
> -1) && (nField
< m_nFields
) );
212 int len
= StatusBar_GetTextLen(hwnd
, nField
);
215 StatusBar_GetText(hwnd
, nField
, str
.GetWriteBuf(len
));
221 void wxStatusBar95::OnSize(wxSizeEvent
& event
)
223 FORWARD_WM_SIZE(hwnd
, SIZE_RESTORED
, event
.GetSize().x
, event
.GetSize().y
,
226 // adjust fields widths to the new size
230 #endif // wxUSE_NATIVE_STATUSBAR
233 #error "wxStatusBar95 is only available under Windows 95 and later."