]>
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"
39 #if !defined(__GNUWIN32__) || defined(__TWIN32__)
51 #if wxUSE_NATIVE_STATUSBAR
53 #if !USE_SHARED_LIBRARY
54 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar95
, wxStatusBar
);
56 BEGIN_EVENT_TABLE(wxStatusBar95
, wxStatusBar
)
57 EVT_PAINT(wxWindow::OnPaint
)
58 EVT_SIZE(wxStatusBar95::OnSize
)
60 #endif //USE_SHARED_LIBRARY
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 // windowsx.h and commctrl.h don't define those, so we do it here
68 #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w)
69 #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCSTR)t)
70 #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
71 #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPSTR)s))
73 #define hwnd ((HWND)m_hWnd)
75 // ============================================================================
77 // ============================================================================
79 // ----------------------------------------------------------------------------
80 // wxStatusBar95 class
81 // ----------------------------------------------------------------------------
83 wxStatusBar95::wxStatusBar95()
90 wxStatusBar95::wxStatusBar95(wxWindow
*parent
, wxWindowID id
, long style
)
92 Create(parent
, id
, style
);
95 bool wxStatusBar95::Create(wxWindow
*parent
, wxWindowID id
, long style
)
100 m_windowId
= NewControlId();
104 DWORD wstyle
= WS_CHILD
| WS_VISIBLE
;
105 if ( style
& wxST_SIZEGRIP
)
106 wstyle
|= SBARS_SIZEGRIP
;
108 m_hWnd
= (WXHWND
)CreateStatusWindow(wstyle
,
110 (HWND
)parent
->GetHWND(),
113 wxLogSysError("can't create status bar window");
117 // this doesn't work: display problems (white 1-2 pixel borders...)
118 // SubclassWin(m_hWnd);
123 void wxStatusBar95::CopyFieldsWidth(const int widths
[])
125 if (widths
&& !m_statusWidths
)
126 m_statusWidths
= new int[m_nFields
];
128 if ( widths
!= NULL
) {
129 for ( int i
= 0; i
< m_nFields
; i
++ )
130 m_statusWidths
[i
] = widths
[i
];
133 delete [] m_statusWidths
;
134 m_statusWidths
= NULL
;
138 void wxStatusBar95::SetFieldsCount(int nFields
, const int widths
[])
140 wxASSERT( (nFields
> 0) && (nFields
< 255) );
144 CopyFieldsWidth(widths
);
148 void wxStatusBar95::SetStatusWidths(int n
, const int widths
[])
150 // @@ I don't understand what this function is for...
151 wxASSERT( n
== m_nFields
);
153 CopyFieldsWidth(widths
);
157 void wxStatusBar95::SetFieldsWidth()
159 int *pWidths
= new int[m_nFields
];
162 GetClientSize(&nWindowWidth
, &y
);
164 if ( m_statusWidths
== NULL
) {
165 // default: all fields have the same width
166 int nWidth
= nWindowWidth
/ m_nFields
;
167 for ( int i
= 0; i
< m_nFields
; i
++ )
168 pWidths
[i
] = (i
+ 1) * nWidth
;
171 // -1 doesn't mean the same thing for wxWindows and Win32, recalc
175 for ( i
= 0; i
< m_nFields
; i
++ ) {
176 if ( m_statusWidths
[i
] == -1 )
179 nTotalWidth
+= m_statusWidths
[i
];
182 if ( nVarCount
== 0 ) {
183 // wrong! at least one field must be of variable width
189 int nVarWidth
= (nWindowWidth
- nTotalWidth
) / nVarCount
;
193 for ( i
= 0; i
< m_nFields
; i
++ ) {
194 if ( m_statusWidths
[i
] == -1 )
195 nCurPos
+= nVarWidth
;
197 nCurPos
+= m_statusWidths
[i
];
198 pWidths
[i
] = nCurPos
;
202 if ( !StatusBar_SetParts(hwnd
, m_nFields
, pWidths
) ) {
203 wxLogDebug("StatusBar_SetParts failed.");
209 void wxStatusBar95::SetStatusText(const wxString
& strText
, int nField
)
211 if ( !StatusBar_SetText(hwnd
, nField
, strText
) ) {
212 wxLogDebug("StatusBar_SetText failed");
216 wxString
wxStatusBar95::GetStatusText(int nField
) const
218 wxASSERT( (nField
> -1) && (nField
< m_nFields
) );
221 int len
= StatusBar_GetTextLen(hwnd
, nField
);
224 StatusBar_GetText(hwnd
, nField
, str
.GetWriteBuf(len
));
230 void wxStatusBar95::OnSize(wxSizeEvent
& event
)
232 FORWARD_WM_SIZE(hwnd
, SIZE_RESTORED
, event
.GetSize().x
, event
.GetSize().y
,
235 // adjust fields widths to the new size
239 #endif // wxUSE_NATIVE_STATUSBAR
242 #error "wxStatusBar95 is only available under Windows 95 and later."