]>
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 // ============================================================================
18 // ============================================================================
20 // ----------------------------------------------------------------------------
22 // ----------------------------------------------------------------------------
24 // for compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
34 #include "wx/settings.h"
35 #include "wx/dcclient.h"
40 #include "wx/generic/statusbr.h"
41 #include "wx/msw/statbr95.h"
50 #if wxUSE_NATIVE_STATUSBAR
52 #if !USE_SHARED_LIBRARY
53 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar95
, wxStatusBar
);
55 BEGIN_EVENT_TABLE(wxStatusBar95
, wxStatusBar
)
56 EVT_PAINT(wxWindow::OnPaint
)
57 EVT_SIZE(wxStatusBar95::OnSize
)
59 #endif //USE_SHARED_LIBRARY
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 // windowsx.h and commctrl.h don't define those, so we do it here
67 #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w)
68 #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCSTR)t)
69 #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
70 #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPSTR)s))
72 #define hwnd ((HWND)m_hWnd)
74 // ============================================================================
76 // ============================================================================
78 // ----------------------------------------------------------------------------
79 // wxStatusBar95 class
80 // ----------------------------------------------------------------------------
82 wxStatusBar95::wxStatusBar95()
89 wxStatusBar95::wxStatusBar95(wxWindow
*parent
, wxWindowID id
, long style
)
91 Create(parent
, id
, style
);
94 bool wxStatusBar95::Create(wxWindow
*parent
, wxWindowID id
, long style
)
99 m_windowId
= NewControlId();
103 DWORD wstyle
= WS_CHILD
| WS_VISIBLE
;
104 if ( style
& wxST_SIZEGRIP
)
105 wstyle
|= SBARS_SIZEGRIP
;
107 m_hWnd
= (WXHWND
)CreateStatusWindow(wstyle
,
109 (HWND
)parent
->GetHWND(),
112 wxLogSysError("can't create status bar window");
116 // this doesn't work: display problems (white 1-2 pixel borders...)
117 // SubclassWin(m_hWnd);
122 void wxStatusBar95::CopyFieldsWidth(const int widths
[])
124 if (widths
&& !m_statusWidths
)
125 m_statusWidths
= new int[m_nFields
];
127 if ( widths
!= NULL
) {
128 for ( int i
= 0; i
< m_nFields
; i
++ )
129 m_statusWidths
[i
] = widths
[i
];
132 delete [] m_statusWidths
;
133 m_statusWidths
= NULL
;
137 void wxStatusBar95::SetFieldsCount(int nFields
, const int widths
[])
139 wxASSERT( (nFields
> 0) && (nFields
< 255) );
143 CopyFieldsWidth(widths
);
147 void wxStatusBar95::SetStatusWidths(int n
, const int widths
[])
149 // @@ I don't understand what this function is for...
150 wxASSERT( n
== m_nFields
);
152 CopyFieldsWidth(widths
);
156 void wxStatusBar95::SetFieldsWidth()
158 int *pWidths
= new int[m_nFields
];
161 GetClientSize(&nWindowWidth
, &y
);
163 if ( m_statusWidths
== NULL
) {
164 // default: all fields have the same width
165 int nWidth
= nWindowWidth
/ m_nFields
;
166 for ( int i
= 0; i
< m_nFields
; i
++ )
167 pWidths
[i
] = (i
+ 1) * nWidth
;
170 // -1 doesn't mean the same thing for wxWindows and Win32, recalc
174 for ( i
= 0; i
< m_nFields
; i
++ ) {
175 if ( m_statusWidths
[i
] == -1 )
178 nTotalWidth
+= m_statusWidths
[i
];
181 if ( nVarCount
== 0 ) {
182 // wrong! at least one field must be of variable width
188 int nVarWidth
= (nWindowWidth
- nTotalWidth
) / nVarCount
;
192 for ( i
= 0; i
< m_nFields
; i
++ ) {
193 if ( m_statusWidths
[i
] == -1 )
194 nCurPos
+= nVarWidth
;
196 nCurPos
+= m_statusWidths
[i
];
197 pWidths
[i
] = nCurPos
;
201 if ( !StatusBar_SetParts(hwnd
, m_nFields
, pWidths
) ) {
202 wxLogDebug("StatusBar_SetParts failed.");
208 void wxStatusBar95::SetStatusText(const wxString
& strText
, int nField
)
210 if ( !StatusBar_SetText(hwnd
, nField
, strText
) ) {
211 wxLogDebug("StatusBar_SetText failed");
215 wxString
wxStatusBar95::GetStatusText(int nField
) const
217 wxASSERT( (nField
> -1) && (nField
< m_nFields
) );
220 int len
= StatusBar_GetTextLen(hwnd
, nField
);
223 StatusBar_GetText(hwnd
, nField
, str
.GetWriteBuf(len
));
229 void wxStatusBar95::OnSize(wxSizeEvent
& event
)
231 FORWARD_WM_SIZE(hwnd
, SIZE_RESTORED
, event
.GetSize().x
, event
.GetSize().y
,
234 // adjust fields widths to the new size
238 #endif //USE_NATIVE_STATUSBAR