]>
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 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
30 #include "wx/settings.h"
31 #include "wx/dcclient.h"
36 #include "wx/generic/statusbr.h"
37 #include "wx/msw/statbr95.h"
46 #if USE_NATIVE_STATUSBAR
48 #if !USE_SHARED_LIBRARY
49 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar95
, wxStatusBar
);
51 BEGIN_EVENT_TABLE(wxStatusBar95
, wxStatusBar
)
52 EVT_PAINT(wxWindow::OnPaint
)
53 EVT_SIZE(wxStatusBar95::OnSize
)
55 #endif //USE_SHARED_LIBRARY
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 // windowsx.h and commctrl.h don't define those, so we do it here
63 #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w)
64 #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCSTR)t)
65 #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
66 #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPSTR)s))
68 #define hwnd ((HWND)m_hWnd)
70 // ============================================================================
72 // ============================================================================
74 // ----------------------------------------------------------------------------
75 // wxStatusBar95 class
76 // ----------------------------------------------------------------------------
78 wxStatusBar95::wxStatusBar95()
85 wxStatusBar95::wxStatusBar95(wxWindow
*parent
, wxWindowID id
, long style
)
87 Create(parent
, id
, style
);
90 bool wxStatusBar95::Create(wxWindow
*parent
, wxWindowID id
, long style
)
94 m_windowId
= id
== -1 ? NewControlId() : id
;
96 DWORD wstyle
= WS_CHILD
| WS_VISIBLE
;
97 if ( style
& wxSB_SIZEGRIP
)
98 wstyle
|= SBARS_SIZEGRIP
;
100 m_hWnd
= (WXHWND
)CreateStatusWindow(wstyle
,
102 (HWND
)parent
->GetHWND(),
105 wxLogSysError("can't create status bar window");
109 // this doesn't work: display problems (white 1-2 pixel borders...)
110 // SubclassWin(m_hWnd);
115 void wxStatusBar95::CopyFieldsWidth(const int *widths
)
117 if (widths
&& !m_statusWidths
)
118 m_statusWidths
= new int[m_nFields
];
120 if ( widths
!= NULL
) {
121 for ( int i
= 0; i
< m_nFields
; i
++ )
122 m_statusWidths
[i
] = widths
[i
];
125 delete [] m_statusWidths
;
126 m_statusWidths
= NULL
;
130 void wxStatusBar95::SetFieldsCount(int nFields
, const int *widths
)
132 wxASSERT( (nFields
> 0) && (nFields
< 255) );
136 CopyFieldsWidth(widths
);
140 void wxStatusBar95::SetStatusWidths(int n
, const int *widths
)
142 // @@ I don't understand what this function is for...
143 wxASSERT( n
== m_nFields
);
145 CopyFieldsWidth(widths
);
149 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) * nWindowWidth
;
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 wxLogDebug("StatusBar_SetParts failed.");
201 void wxStatusBar95::SetStatusText(const wxString
& strText
, const int nField
)
203 if ( !StatusBar_SetText(hwnd
, nField
, strText
) ) {
204 wxLogDebug("StatusBar_SetText failed");
208 wxString
wxStatusBar95::GetStatusText(int nField
) const
210 wxASSERT( (nField
> 0) && (nField
< m_nFields
) );
213 StatusBar_GetText(hwnd
, nField
,
214 str
.GetWriteBuf(StatusBar_GetTextLen(hwnd
, nField
)));
218 void wxStatusBar95::OnSize(wxSizeEvent
& event
)
220 FORWARD_WM_SIZE(hwnd
, SIZE_RESTORED
, event
.GetSize().x
, event
.GetSize().y
,
223 // adjust fields widths to the new size
227 #endif //USE_NATIVE_STATUSBAR