]>
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 USE_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
)
98 m_windowId
= id
== -1 ? NewControlId() : id
;
100 DWORD wstyle
= WS_CHILD
| WS_VISIBLE
;
101 if ( style
& wxST_SIZEGRIP
)
102 wstyle
|= SBARS_SIZEGRIP
;
104 m_hWnd
= (WXHWND
)CreateStatusWindow(wstyle
,
106 (HWND
)parent
->GetHWND(),
109 wxLogSysError("can't create status bar window");
113 // this doesn't work: display problems (white 1-2 pixel borders...)
114 // SubclassWin(m_hWnd);
119 void wxStatusBar95::CopyFieldsWidth(int *widths
)
121 if (widths
&& !m_statusWidths
)
122 m_statusWidths
= new int[m_nFields
];
124 if ( widths
!= NULL
) {
125 for ( int i
= 0; i
< m_nFields
; i
++ )
126 m_statusWidths
[i
] = widths
[i
];
129 delete [] m_statusWidths
;
130 m_statusWidths
= NULL
;
134 void wxStatusBar95::SetFieldsCount(int nFields
, int *widths
)
136 wxASSERT( (nFields
> 0) && (nFields
< 255) );
140 CopyFieldsWidth(widths
);
144 void wxStatusBar95::SetStatusWidths(int n
, int *widths
)
146 // @@ I don't understand what this function is for...
147 wxASSERT( n
== m_nFields
);
149 CopyFieldsWidth(widths
);
153 void wxStatusBar95::SetFieldsWidth()
155 int *pWidths
= new int[m_nFields
];
158 GetClientSize(&nWindowWidth
, &y
);
160 if ( m_statusWidths
== NULL
) {
161 // default: all fields have the same width
162 int nWidth
= nWindowWidth
/ m_nFields
;
163 for ( int i
= 0; i
< m_nFields
; i
++ )
164 pWidths
[i
] = (i
+ 1) * nWidth
;
167 // -1 doesn't mean the same thing for wxWindows and Win32, recalc
171 for ( i
= 0; i
< m_nFields
; i
++ ) {
172 if ( m_statusWidths
[i
] == -1 )
175 nTotalWidth
+= m_statusWidths
[i
];
178 if ( nVarCount
== 0 ) {
179 // wrong! at least one field must be of variable width
185 int nVarWidth
= (nWindowWidth
- nTotalWidth
) / nVarCount
;
189 for ( i
= 0; i
< m_nFields
; i
++ ) {
190 if ( m_statusWidths
[i
] == -1 )
191 nCurPos
+= nVarWidth
;
193 nCurPos
+= m_statusWidths
[i
];
194 pWidths
[i
] = nCurPos
;
198 if ( !StatusBar_SetParts(hwnd
, m_nFields
, pWidths
) ) {
199 wxLogDebug("StatusBar_SetParts failed.");
205 void wxStatusBar95::SetStatusText(const wxString
& strText
, int nField
)
207 if ( !StatusBar_SetText(hwnd
, nField
, strText
) ) {
208 wxLogDebug("StatusBar_SetText failed");
212 wxString
wxStatusBar95::GetStatusText(int nField
) const
214 wxASSERT( (nField
> -1) && (nField
< m_nFields
) );
217 int len
= StatusBar_GetTextLen(hwnd
, nField
);
220 StatusBar_GetText(hwnd
, nField
, str
.GetWriteBuf(len
));
225 void wxStatusBar95::OnSize(wxSizeEvent
& event
)
227 FORWARD_WM_SIZE(hwnd
, SIZE_RESTORED
, event
.GetSize().x
, event
.GetSize().y
,
230 // adjust fields widths to the new size
234 #endif //USE_NATIVE_STATUSBAR