]>
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"
34 #include "wx/generic/statusbr.h"
35 #include "wx/msw/statbr95.h"
40 #if !defined(__GNUWIN32__)
44 #if wxUSE_NATIVE_STATUSBAR
46 #if !USE_SHARED_LIBRARY
47 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar95
, wxStatusBar
);
49 BEGIN_EVENT_TABLE(wxStatusBar95
, wxStatusBar
)
50 EVT_PAINT(wxWindow::OnPaint
)
51 EVT_SIZE(wxStatusBar95::OnSize
)
53 #endif //USE_SHARED_LIBRARY
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // windowsx.h and commctrl.h don't define those, so we do it here
61 #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w)
62 #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCSTR)t)
63 #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
64 #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPSTR)s))
66 #define hwnd ((HWND)m_hWnd)
68 // ============================================================================
70 // ============================================================================
72 // ----------------------------------------------------------------------------
73 // wxStatusBar95 class
74 // ----------------------------------------------------------------------------
76 wxStatusBar95::wxStatusBar95()
83 wxStatusBar95::wxStatusBar95(wxWindow
*parent
, wxWindowID id
, long style
)
85 Create(parent
, id
, style
);
88 bool wxStatusBar95::Create(wxWindow
*parent
, wxWindowID id
, long style
)
93 m_windowId
= NewControlId();
97 DWORD wstyle
= WS_CHILD
| WS_VISIBLE
;
98 if ( style
& wxST_SIZEGRIP
)
99 wstyle
|= SBARS_SIZEGRIP
;
101 m_hWnd
= (WXHWND
)CreateStatusWindow(wstyle
,
103 (HWND
)parent
->GetHWND(),
106 wxLogSysError("can't create status bar window");
110 // this doesn't work: display problems (white 1-2 pixel borders...)
111 // SubclassWin(m_hWnd);
116 void wxStatusBar95::CopyFieldsWidth(const int widths
[])
118 if (widths
&& !m_statusWidths
)
119 m_statusWidths
= new int[m_nFields
];
121 if ( widths
!= NULL
) {
122 for ( int i
= 0; i
< m_nFields
; i
++ )
123 m_statusWidths
[i
] = widths
[i
];
126 delete [] m_statusWidths
;
127 m_statusWidths
= NULL
;
131 void wxStatusBar95::SetFieldsCount(int nFields
, const int widths
[])
133 wxASSERT( (nFields
> 0) && (nFields
< 255) );
137 CopyFieldsWidth(widths
);
141 void wxStatusBar95::SetStatusWidths(int n
, const int widths
[])
143 // @@ I don't understand what this function is for...
144 wxASSERT( n
== m_nFields
);
146 CopyFieldsWidth(widths
);
150 void wxStatusBar95::SetFieldsWidth()
152 int *pWidths
= new int[m_nFields
];
155 GetClientSize(&nWindowWidth
, &y
);
157 if ( m_statusWidths
== NULL
) {
158 // default: all fields have the same width
159 int nWidth
= nWindowWidth
/ m_nFields
;
160 for ( int i
= 0; i
< m_nFields
; i
++ )
161 pWidths
[i
] = (i
+ 1) * nWidth
;
164 // -1 doesn't mean the same thing for wxWindows and Win32, recalc
168 for ( i
= 0; i
< m_nFields
; i
++ ) {
169 if ( m_statusWidths
[i
] == -1 )
172 nTotalWidth
+= m_statusWidths
[i
];
175 if ( nVarCount
== 0 ) {
176 // wrong! at least one field must be of variable width
182 int nVarWidth
= (nWindowWidth
- nTotalWidth
) / nVarCount
;
186 for ( i
= 0; i
< m_nFields
; i
++ ) {
187 if ( m_statusWidths
[i
] == -1 )
188 nCurPos
+= nVarWidth
;
190 nCurPos
+= m_statusWidths
[i
];
191 pWidths
[i
] = nCurPos
;
195 if ( !StatusBar_SetParts(hwnd
, m_nFields
, pWidths
) ) {
196 wxLogDebug("StatusBar_SetParts failed.");
202 void wxStatusBar95::SetStatusText(const wxString
& strText
, int nField
)
204 if ( !StatusBar_SetText(hwnd
, nField
, strText
) ) {
205 wxLogDebug("StatusBar_SetText failed");
209 wxString
wxStatusBar95::GetStatusText(int nField
) const
211 wxASSERT( (nField
> -1) && (nField
< m_nFields
) );
214 int len
= StatusBar_GetTextLen(hwnd
, nField
);
217 StatusBar_GetText(hwnd
, nField
, str
.GetWriteBuf(len
));
223 void wxStatusBar95::OnSize(wxSizeEvent
& event
)
225 FORWARD_WM_SIZE(hwnd
, SIZE_RESTORED
, event
.GetSize().x
, event
.GetSize().y
,
228 // adjust fields widths to the new size
235 // wxUSE_NATIVE_STATUSBAR