]>
Commit | Line | Data |
---|---|---|
88310e2e | 1 | /////////////////////////////////////////////////////////////////////////////// |
2ddb4d13 | 2 | // Name: src/msw/notebook.cpp |
88310e2e VZ |
3 | // Purpose: implementation of wxNotebook |
4 | // Author: Vadim Zeitlin | |
907f37b3 | 5 | // Modified by: |
88310e2e VZ |
6 | // Created: 11.06.98 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
65571936 | 9 | // Licence: wxWindows licence |
88310e2e VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
88310e2e VZ |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
1e6feb95 | 16 | #pragma hdrstop |
88310e2e VZ |
17 | #endif |
18 | ||
1e6feb95 VZ |
19 | #if wxUSE_NOTEBOOK |
20 | ||
57bd4c60 | 21 | #include "wx/notebook.h" |
e4db172a | 22 | |
88310e2e | 23 | #ifndef WX_PRECOMP |
57bd4c60 WS |
24 | #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly" |
25 | #include "wx/string.h" | |
26 | #include "wx/dc.h" | |
27 | #include "wx/log.h" | |
28 | #include "wx/event.h" | |
29 | #include "wx/app.h" | |
30 | #include "wx/dcclient.h" | |
31 | #include "wx/dcmemory.h" | |
32 | #include "wx/control.h" | |
bb93b4a8 | 33 | #include "wx/panel.h" |
88310e2e VZ |
34 | #endif // WX_PRECOMP |
35 | ||
57bd4c60 WS |
36 | #include "wx/imaglist.h" |
37 | #include "wx/sysopt.h" | |
88310e2e | 38 | |
57bd4c60 | 39 | #include "wx/msw/private.h" |
74052fe8 | 40 | #include "wx/msw/dc.h" |
88310e2e | 41 | |
57bd4c60 | 42 | #include <windowsx.h> |
85b43fbf JS |
43 | #include "wx/msw/winundef.h" |
44 | ||
45 | #if wxUSE_UXTHEME | |
caf95d2a | 46 | #include "wx/msw/uxtheme.h" |
85b43fbf JS |
47 | #endif |
48 | ||
88310e2e VZ |
49 | // ---------------------------------------------------------------------------- |
50 | // macros | |
51 | // ---------------------------------------------------------------------------- | |
52 | ||
53 | // check that the page index is valid | |
8d34bf5c | 54 | #define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount()) |
88310e2e | 55 | |
014ee083 VZ |
56 | // you can set USE_NOTEBOOK_ANTIFLICKER to 0 for desktop Windows versions too |
57 | // to disable code whih results in flicker-less notebook redrawing at the | |
58 | // expense of some extra GDI resource consumption | |
254fbd14 | 59 | #ifdef __WXWINCE__ |
014ee083 VZ |
60 | // notebooks are never resized under CE anyhow |
61 | #define USE_NOTEBOOK_ANTIFLICKER 0 | |
254fbd14 | 62 | #else |
014ee083 | 63 | #define USE_NOTEBOOK_ANTIFLICKER 1 |
254fbd14 JS |
64 | #endif |
65 | ||
74b31181 VZ |
66 | // ---------------------------------------------------------------------------- |
67 | // constants | |
68 | // ---------------------------------------------------------------------------- | |
69 | ||
70 | // This is a work-around for missing defines in gcc-2.95 headers | |
71 | #ifndef TCS_RIGHT | |
72 | #define TCS_RIGHT 0x0002 | |
73 | #endif | |
74 | ||
75 | #ifndef TCS_VERTICAL | |
76 | #define TCS_VERTICAL 0x0080 | |
77 | #endif | |
78 | ||
79 | #ifndef TCS_BOTTOM | |
80 | #define TCS_BOTTOM TCS_RIGHT | |
81 | #endif | |
82 | ||
014ee083 VZ |
83 | // ---------------------------------------------------------------------------- |
84 | // global variables | |
85 | // ---------------------------------------------------------------------------- | |
86 | ||
87 | #if USE_NOTEBOOK_ANTIFLICKER | |
88 | ||
89 | // the pointer to standard spin button wnd proc | |
90 | static WXFARPROC gs_wndprocNotebookSpinBtn = (WXFARPROC)NULL; | |
91 | ||
6143d3b6 | 92 | // the pointer to standard tab control wnd proc |
e1cffcd6 | 93 | static WXFARPROC gs_wndprocNotebook = (WXFARPROC)NULL; |
6143d3b6 VZ |
94 | |
95 | LRESULT APIENTRY _EXPORT wxNotebookWndProc(HWND hwnd, | |
96 | UINT message, | |
97 | WPARAM wParam, | |
98 | LPARAM lParam); | |
99 | ||
014ee083 VZ |
100 | #endif // USE_NOTEBOOK_ANTIFLICKER |
101 | ||
b013c971 VZ |
102 | // ---------------------------------------------------------------------------- |
103 | // global functions | |
104 | // ---------------------------------------------------------------------------- | |
105 | ||
106 | static bool HasTroubleWithNonTopTabs() | |
107 | { | |
108 | const int verComCtl32 = wxApp::GetComCtl32Version(); | |
109 | ||
110 | // 600 is XP, 616 is Vista -- and both have a problem with tabs not on top | |
111 | // (but don't just test for >= 600 as Microsoft might decide to fix it in | |
112 | // later versions, who knows...) | |
113 | return verComCtl32 >= 600 && verComCtl32 <= 616; | |
114 | } | |
115 | ||
88310e2e VZ |
116 | // ---------------------------------------------------------------------------- |
117 | // event table | |
118 | // ---------------------------------------------------------------------------- | |
119 | ||
7ec69821 | 120 | #include "wx/listimpl.cpp" |
51741307 | 121 | |
259c43f6 | 122 | WX_DEFINE_LIST( wxNotebookPageInfoList ) |
51741307 | 123 | |
8dba4c72 | 124 | BEGIN_EVENT_TABLE(wxNotebook, wxBookCtrlBase) |
7ec69821 | 125 | EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, wxNotebook::OnSelChange) |
9026ad85 | 126 | EVT_SIZE(wxNotebook::OnSize) |
88310e2e | 127 | EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) |
014ee083 VZ |
128 | |
129 | #if USE_NOTEBOOK_ANTIFLICKER | |
130 | EVT_ERASE_BACKGROUND(wxNotebook::OnEraseBackground) | |
131 | EVT_PAINT(wxNotebook::OnPaint) | |
132 | #endif // USE_NOTEBOOK_ANTIFLICKER | |
d9317fd4 | 133 | END_EVENT_TABLE() |
88310e2e | 134 | |
51596bcb | 135 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
136 | WX_DEFINE_FLAGS( wxNotebookStyle ) |
137 | ||
3ff066a4 | 138 | wxBEGIN_FLAGS( wxNotebookStyle ) |
bc9fb572 JS |
139 | // new style border flags, we put them first to |
140 | // use them for streaming out | |
3ff066a4 SC |
141 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
142 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
143 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
144 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
145 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
146 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
078cf5cb | 147 | |
bc9fb572 | 148 | // old style border flags |
3ff066a4 SC |
149 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
150 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
151 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
152 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
153 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 154 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
155 | |
156 | // standard window styles | |
3ff066a4 SC |
157 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
158 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
159 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
160 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 161 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
162 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
163 | wxFLAGS_MEMBER(wxVSCROLL) | |
164 | wxFLAGS_MEMBER(wxHSCROLL) | |
165 | ||
166 | wxFLAGS_MEMBER(wxNB_FIXEDWIDTH) | |
2ddb4d13 WS |
167 | wxFLAGS_MEMBER(wxBK_DEFAULT) |
168 | wxFLAGS_MEMBER(wxBK_TOP) | |
169 | wxFLAGS_MEMBER(wxBK_LEFT) | |
170 | wxFLAGS_MEMBER(wxBK_RIGHT) | |
171 | wxFLAGS_MEMBER(wxBK_BOTTOM) | |
b554cf63 JS |
172 | wxFLAGS_MEMBER(wxNB_NOPAGETHEME) |
173 | wxFLAGS_MEMBER(wxNB_FLAT) | |
3ff066a4 SC |
174 | |
175 | wxEND_FLAGS( wxNotebookStyle ) | |
51741307 | 176 | |
8dba4c72 | 177 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebook, wxBookCtrlBase,"wx/notebook.h") |
51741307 SC |
178 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebookPageInfo, wxObject , "wx/notebook.h" ) |
179 | ||
3ff066a4 | 180 | wxCOLLECTION_TYPE_INFO( wxNotebookPageInfo * , wxNotebookPageInfoList ) ; |
51596bcb | 181 | |
f0a126fe SC |
182 | template<> void wxCollectionToVariantArray( wxNotebookPageInfoList const &theList, wxxVariantArray &value) |
183 | { | |
0c6b0084 | 184 | wxListCollectionToVariantArray<wxNotebookPageInfoList::compatibility_iterator>( theList , value ) ; |
f0a126fe SC |
185 | } |
186 | ||
3ff066a4 | 187 | wxBEGIN_PROPERTIES_TABLE(wxNotebook) |
3e97a905 VZ |
188 | wxEVENT_PROPERTY( PageChanging , wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING , wxBookCtrlEvent ) |
189 | wxEVENT_PROPERTY( PageChanged , wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED , wxBookCtrlEvent ) | |
c5ca409b | 190 | |
3ff066a4 | 191 | wxPROPERTY_COLLECTION( PageInfos , wxNotebookPageInfoList , wxNotebookPageInfo* , AddPageInfo , GetPageInfos , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
af498247 | 192 | wxPROPERTY_FLAGS( WindowStyle , wxNotebookStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
3ff066a4 | 193 | wxEND_PROPERTIES_TABLE() |
51596bcb | 194 | |
3ff066a4 SC |
195 | wxBEGIN_HANDLERS_TABLE(wxNotebook) |
196 | wxEND_HANDLERS_TABLE() | |
51596bcb | 197 | |
078cf5cb | 198 | wxCONSTRUCTOR_5( wxNotebook , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle) |
51596bcb | 199 | |
51741307 | 200 | |
3ff066a4 | 201 | wxBEGIN_PROPERTIES_TABLE(wxNotebookPageInfo) |
af498247 | 202 | wxREADONLY_PROPERTY( Page , wxNotebookPage* , GetPage , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
3ff066a4 SC |
203 | wxREADONLY_PROPERTY( Text , wxString , GetText , wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
204 | wxREADONLY_PROPERTY( Selected , bool , GetSelected , false, 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) | |
205 | wxREADONLY_PROPERTY( ImageId , int , GetImageId , -1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
206 | wxEND_PROPERTIES_TABLE() | |
51741307 | 207 | |
3ff066a4 SC |
208 | wxBEGIN_HANDLERS_TABLE(wxNotebookPageInfo) |
209 | wxEND_HANDLERS_TABLE() | |
51741307 | 210 | |
078cf5cb | 211 | wxCONSTRUCTOR_4( wxNotebookPageInfo , wxNotebookPage* , Page , wxString , Text , bool , Selected , int , ImageId ) |
51741307 | 212 | |
51596bcb | 213 | #else |
8dba4c72 | 214 | IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxBookCtrlBase) |
51741307 | 215 | IMPLEMENT_DYNAMIC_CLASS(wxNotebookPageInfo, wxObject ) |
51596bcb | 216 | #endif |
88310e2e VZ |
217 | |
218 | // ============================================================================ | |
219 | // implementation | |
220 | // ============================================================================ | |
221 | ||
222 | // ---------------------------------------------------------------------------- | |
223 | // wxNotebook construction | |
224 | // ---------------------------------------------------------------------------- | |
225 | ||
51741307 SC |
226 | const wxNotebookPageInfoList& wxNotebook::GetPageInfos() const |
227 | { | |
228 | wxNotebookPageInfoList* list = const_cast< wxNotebookPageInfoList* >( &m_pageInfos ) ; | |
229 | WX_CLEAR_LIST( wxNotebookPageInfoList , *list ) ; | |
34a0c9f4 | 230 | for( size_t i = 0 ; i < GetPageCount() ; ++i ) |
51741307 SC |
231 | { |
232 | wxNotebookPageInfo *info = new wxNotebookPageInfo() ; | |
34a0c9f4 | 233 | info->Create( const_cast<wxNotebook*>(this)->GetPage(i) , GetPageText(i) , GetSelection() == int(i) , GetPageImage(i) ) ; |
51741307 SC |
234 | list->Append( info ) ; |
235 | } | |
236 | return m_pageInfos ; | |
237 | } | |
238 | ||
88310e2e VZ |
239 | // common part of all ctors |
240 | void wxNotebook::Init() | |
241 | { | |
7ec69821 | 242 | m_imageList = NULL; |
caf95d2a VZ |
243 | |
244 | #if wxUSE_UXTHEME | |
7ec69821 | 245 | m_hbrBackground = NULL; |
caf95d2a | 246 | #endif // wxUSE_UXTHEME |
dfb47d83 VZ |
247 | |
248 | #if USE_NOTEBOOK_ANTIFLICKER | |
7ec69821 | 249 | m_hasSubclassedUpdown = false; |
dfb47d83 | 250 | #endif // USE_NOTEBOOK_ANTIFLICKER |
88310e2e VZ |
251 | } |
252 | ||
253 | // default for dynamic class | |
254 | wxNotebook::wxNotebook() | |
255 | { | |
256 | Init(); | |
257 | } | |
258 | ||
259 | // the same arguments as for wxControl | |
260 | wxNotebook::wxNotebook(wxWindow *parent, | |
8b9518ee | 261 | wxWindowID id, |
88310e2e VZ |
262 | const wxPoint& pos, |
263 | const wxSize& size, | |
8b9518ee | 264 | long style, |
88310e2e VZ |
265 | const wxString& name) |
266 | { | |
267 | Init(); | |
268 | ||
269 | Create(parent, id, pos, size, style, name); | |
270 | } | |
271 | ||
272 | // Create() function | |
273 | bool wxNotebook::Create(wxWindow *parent, | |
8b9518ee | 274 | wxWindowID id, |
88310e2e VZ |
275 | const wxPoint& pos, |
276 | const wxSize& size, | |
8b9518ee | 277 | long style, |
88310e2e VZ |
278 | const wxString& name) |
279 | { | |
895cc205 WS |
280 | if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT ) |
281 | { | |
282 | #if defined(__POCKETPC__) | |
283 | style |= wxBK_BOTTOM | wxNB_FLAT; | |
284 | #else | |
285 | style |= wxBK_TOP; | |
286 | #endif | |
287 | } | |
288 | ||
45418059 JS |
289 | #ifdef __WXWINCE__ |
290 | // Not sure why, but without this style, there is no border | |
291 | // around the notebook tabs. | |
292 | if (style & wxNB_FLAT) | |
293 | style |= wxBORDER_SUNKEN; | |
294 | #endif | |
c3732409 | 295 | |
e4db172a | 296 | #if !wxUSE_UXTHEME |
b013c971 VZ |
297 | // ComCtl32 notebook tabs simply don't work unless they're on top if we |
298 | // have uxtheme, we can work around it later (after control creation), but | |
299 | // if we have been compiled without uxtheme support, we have to clear those | |
300 | // styles | |
301 | if ( HasTroubleWithNonTopTabs() ) | |
04eb05b0 | 302 | { |
5483756f | 303 | style &= ~(wxBK_BOTTOM | wxBK_LEFT | wxBK_RIGHT); |
04eb05b0 | 304 | } |
7cc1ad29 | 305 | #endif //wxUSE_UXTHEME |
078cf5cb | 306 | |
82c51a8e JS |
307 | #if defined(__WINE__) && wxUSE_UNICODE |
308 | LPCTSTR className = L"SysTabControl32"; | |
309 | #else | |
c1637c89 | 310 | LPCTSTR className = WC_TABCONTROL; |
82c51a8e | 311 | #endif |
c1637c89 | 312 | |
6143d3b6 | 313 | #if USE_NOTEBOOK_ANTIFLICKER |
c1637c89 VZ |
314 | // SysTabCtl32 class has natively CS_HREDRAW and CS_VREDRAW enabled and it |
315 | // causes horrible flicker when resizing notebook, so get rid of it by | |
316 | // using a class without these styles (but otherwise identical to it) | |
317 | if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) ) | |
318 | { | |
319 | static ClassRegistrar s_clsNotebook; | |
320 | if ( !s_clsNotebook.IsInitialized() ) | |
321 | { | |
322 | // get a copy of standard class and modify it | |
323 | WNDCLASS wc; | |
324 | ||
6143d3b6 | 325 | if ( ::GetClassInfo(NULL, WC_TABCONTROL, &wc) ) |
c1637c89 | 326 | { |
6143d3b6 | 327 | gs_wndprocNotebook = |
5c33522f | 328 | reinterpret_cast<WXFARPROC>(wc.lpfnWndProc); |
c1637c89 VZ |
329 | wc.lpszClassName = wxT("_wx_SysTabCtl32"); |
330 | wc.style &= ~(CS_HREDRAW | CS_VREDRAW); | |
6143d3b6 VZ |
331 | wc.hInstance = wxGetInstance(); |
332 | wc.lpfnWndProc = wxNotebookWndProc; | |
c1637c89 VZ |
333 | s_clsNotebook.Register(wc); |
334 | } | |
335 | else | |
336 | { | |
9a83f860 | 337 | wxLogLastError(wxT("GetClassInfoEx(SysTabCtl32)")); |
c1637c89 VZ |
338 | } |
339 | } | |
340 | ||
341 | // use our custom class if available but fall back to the standard | |
342 | // notebook if we failed to register it | |
343 | if ( s_clsNotebook.IsRegistered() ) | |
344 | { | |
345 | // it's ok to use c_str() here as the static s_clsNotebook object | |
346 | // has sufficiently long lifetime | |
347 | className = s_clsNotebook.GetName().c_str(); | |
348 | } | |
349 | } | |
6143d3b6 | 350 | #endif // USE_NOTEBOOK_ANTIFLICKER |
c1637c89 | 351 | |
6dd16e4f VZ |
352 | if ( !CreateControl(parent, id, pos, size, style | wxTAB_TRAVERSAL, |
353 | wxDefaultValidator, name) ) | |
b8bdaa7c | 354 | return false; |
88310e2e | 355 | |
c1637c89 | 356 | if ( !MSWCreateControl(className, wxEmptyString, pos, size) ) |
b8bdaa7c | 357 | return false; |
907f37b3 | 358 | |
7dccdf81 VZ |
359 | #if wxUSE_UXTHEME |
360 | if ( HasFlag(wxNB_NOPAGETHEME) || | |
361 | wxSystemOptions::IsFalse(wxT("msw.notebook.themed-background")) ) | |
f2b7be7a | 362 | { |
7dccdf81 | 363 | SetBackgroundColour(GetThemeBackgroundColour()); |
f2b7be7a | 364 | } |
30556182 VZ |
365 | else // use themed background by default |
366 | { | |
367 | // create backing store | |
368 | UpdateBgBrush(); | |
369 | } | |
e4db172a | 370 | |
7cc1ad29 JS |
371 | // comctl32.dll 6.0 doesn't support non-top tabs with visual styles (the |
372 | // control is simply not rendered correctly), so we disable themes | |
373 | // if possible, otherwise we simply clear the styles. | |
b013c971 VZ |
374 | if ( HasTroubleWithNonTopTabs() && |
375 | (style & (wxBK_BOTTOM | wxBK_LEFT | wxBK_RIGHT)) ) | |
7cc1ad29 JS |
376 | { |
377 | // check if we use themes at all -- if we don't, we're still okay | |
b013c971 | 378 | if ( wxUxThemeEngine::GetIfActive() ) |
7cc1ad29 | 379 | { |
b013c971 VZ |
380 | wxUxThemeEngine::GetIfActive()->SetWindowTheme(GetHwnd(), L"", L""); |
381 | ||
382 | // correct the background color for the new non-themed control | |
8dba4c72 | 383 | SetBackgroundColour(GetThemeBackgroundColour()); |
7cc1ad29 JS |
384 | } |
385 | } | |
7dccdf81 | 386 | #endif // wxUSE_UXTHEME |
b554cf63 JS |
387 | |
388 | // Undocumented hack to get flat notebook style | |
389 | // In fact, we should probably only do this in some | |
390 | // curcumstances, i.e. if we know we will have a border | |
391 | // at the bottom (the tab control doesn't draw it itself) | |
392 | #if defined(__POCKETPC__) || defined(__SMARTPHONE__) | |
393 | if (HasFlag(wxNB_FLAT)) | |
394 | { | |
01c8cbf5 | 395 | SendMessage(GetHwnd(), CCM_SETVERSION, COMCTL32_VERSION, 0); |
b554cf63 JS |
396 | if (!m_hasBgCol) |
397 | SetBackgroundColour(*wxWHITE); | |
398 | } | |
399 | #endif | |
b8bdaa7c | 400 | return true; |
0df3fbd7 VZ |
401 | } |
402 | ||
403 | WXDWORD wxNotebook::MSWGetStyle(long style, WXDWORD *exstyle) const | |
404 | { | |
405 | WXDWORD tabStyle = wxControl::MSWGetStyle(style, exstyle); | |
406 | ||
407 | tabStyle |= WS_TABSTOP | TCS_TABS; | |
408 | ||
2b5f62a0 | 409 | if ( style & wxNB_MULTILINE ) |
0df3fbd7 VZ |
410 | tabStyle |= TCS_MULTILINE; |
411 | if ( style & wxNB_FIXEDWIDTH ) | |
412 | tabStyle |= TCS_FIXEDWIDTH; | |
413 | ||
2ddb4d13 | 414 | if ( style & wxBK_BOTTOM ) |
0df3fbd7 | 415 | tabStyle |= TCS_RIGHT; |
2ddb4d13 | 416 | else if ( style & wxBK_LEFT ) |
0df3fbd7 | 417 | tabStyle |= TCS_VERTICAL; |
2ddb4d13 | 418 | else if ( style & wxBK_RIGHT ) |
c3732409 | 419 | tabStyle |= TCS_VERTICAL | TCS_RIGHT; |
0df3fbd7 | 420 | |
0df3fbd7 | 421 | return tabStyle; |
88310e2e VZ |
422 | } |
423 | ||
caf95d2a VZ |
424 | wxNotebook::~wxNotebook() |
425 | { | |
426 | #if wxUSE_UXTHEME | |
427 | if ( m_hbrBackground ) | |
428 | ::DeleteObject((HBRUSH)m_hbrBackground); | |
429 | #endif // wxUSE_UXTHEME | |
430 | } | |
431 | ||
88310e2e VZ |
432 | // ---------------------------------------------------------------------------- |
433 | // wxNotebook accessors | |
434 | // ---------------------------------------------------------------------------- | |
07b8d7ec | 435 | |
8d34bf5c | 436 | size_t wxNotebook::GetPageCount() const |
88310e2e | 437 | { |
8ecd5de2 WS |
438 | // consistency check |
439 | wxASSERT( (int)m_pages.Count() == TabCtrl_GetItemCount(GetHwnd()) ); | |
88310e2e | 440 | |
8ecd5de2 | 441 | return m_pages.Count(); |
88310e2e VZ |
442 | } |
443 | ||
444 | int wxNotebook::GetRowCount() const | |
445 | { | |
8ecd5de2 | 446 | return TabCtrl_GetRowCount(GetHwnd()); |
88310e2e VZ |
447 | } |
448 | ||
8d34bf5c | 449 | int wxNotebook::SetSelection(size_t nPage) |
88310e2e | 450 | { |
8ecd5de2 WS |
451 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); |
452 | ||
681be2ef | 453 | if ( m_selection == wxNOT_FOUND || nPage != (size_t)m_selection ) |
2b5f62a0 | 454 | { |
a570e8f8 | 455 | if ( SendPageChangingEvent(nPage) ) |
8ecd5de2 WS |
456 | { |
457 | // program allows the page change | |
681be2ef | 458 | SendPageChangedEvent(m_selection, nPage); |
2b5f62a0 | 459 | |
a570e8f8 | 460 | TabCtrl_SetCurSel(GetHwnd(), nPage); |
8ecd5de2 | 461 | } |
2b5f62a0 | 462 | } |
88310e2e | 463 | |
681be2ef | 464 | return m_selection; |
88310e2e VZ |
465 | } |
466 | ||
5482ee07 | 467 | void wxNotebook::UpdateSelection(int selNew) |
1d6fcbcc | 468 | { |
681be2ef VZ |
469 | if ( m_selection != wxNOT_FOUND ) |
470 | m_pages[m_selection]->Show(false); | |
1d6fcbcc | 471 | |
5482ee07 | 472 | if ( selNew != wxNOT_FOUND ) |
1d6fcbcc | 473 | { |
5482ee07 | 474 | wxNotebookPage *pPage = m_pages[selNew]; |
1d6fcbcc VZ |
475 | pPage->Show(true); |
476 | } | |
477 | ||
478 | // Changing the page should give the focus to it but, as per bug report | |
479 | // http://sf.net/tracker/index.php?func=detail&aid=1150659&group_id=9863&atid=109863, | |
480 | // we should not set the focus to it directly since it erroneously | |
481 | // selects radio buttons and breaks keyboard handling for a notebook's | |
482 | // scroll buttons. So give focus to the notebook and not the page. | |
483 | ||
484 | // but don't do this is the notebook is hidden | |
485 | if ( ::IsWindowVisible(GetHwnd()) ) | |
486 | SetFocus(); | |
487 | ||
681be2ef | 488 | m_selection = selNew; |
1d6fcbcc VZ |
489 | } |
490 | ||
491 | int wxNotebook::ChangeSelection(size_t nPage) | |
492 | { | |
493 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); | |
494 | ||
681be2ef | 495 | const int selOld = m_selection; |
937d5b60 | 496 | |
681be2ef | 497 | if ( m_selection == wxNOT_FOUND || nPage != (size_t)m_selection ) |
1d6fcbcc VZ |
498 | { |
499 | TabCtrl_SetCurSel(GetHwnd(), nPage); | |
500 | ||
501 | UpdateSelection(nPage); | |
502 | } | |
503 | ||
937d5b60 | 504 | return selOld; |
1d6fcbcc VZ |
505 | } |
506 | ||
8d34bf5c | 507 | bool wxNotebook::SetPageText(size_t nPage, const wxString& strText) |
88310e2e | 508 | { |
8ecd5de2 | 509 | wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("notebook page out of range") ); |
88310e2e | 510 | |
8ecd5de2 WS |
511 | TC_ITEM tcItem; |
512 | tcItem.mask = TCIF_TEXT; | |
c9f78968 | 513 | tcItem.pszText = (wxChar *)strText.wx_str(); |
88310e2e | 514 | |
88a01064 JS |
515 | if ( !HasFlag(wxNB_MULTILINE) ) |
516 | return TabCtrl_SetItem(GetHwnd(), nPage, &tcItem) != 0; | |
517 | ||
518 | // multiline - we need to set new page size if a line is added or removed | |
519 | int rows = GetRowCount(); | |
520 | bool ret = TabCtrl_SetItem(GetHwnd(), nPage, &tcItem) != 0; | |
521 | ||
522 | if ( ret && rows != GetRowCount() ) | |
523 | { | |
524 | const wxRect r = GetPageSize(); | |
525 | const size_t count = m_pages.Count(); | |
526 | for ( size_t page = 0; page < count; page++ ) | |
527 | m_pages[page]->SetSize(r); | |
528 | } | |
529 | ||
530 | return ret; | |
88310e2e VZ |
531 | } |
532 | ||
8d34bf5c | 533 | wxString wxNotebook::GetPageText(size_t nPage) const |
88310e2e | 534 | { |
8ecd5de2 | 535 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxEmptyString, wxT("notebook page out of range") ); |
88310e2e | 536 | |
8ecd5de2 WS |
537 | wxChar buf[256]; |
538 | TC_ITEM tcItem; | |
539 | tcItem.mask = TCIF_TEXT; | |
540 | tcItem.pszText = buf; | |
541 | tcItem.cchTextMax = WXSIZEOF(buf); | |
88310e2e | 542 | |
8ecd5de2 WS |
543 | wxString str; |
544 | if ( TabCtrl_GetItem(GetHwnd(), nPage, &tcItem) ) | |
545 | str = tcItem.pszText; | |
88310e2e | 546 | |
8ecd5de2 | 547 | return str; |
88310e2e VZ |
548 | } |
549 | ||
8d34bf5c | 550 | int wxNotebook::GetPageImage(size_t nPage) const |
88310e2e | 551 | { |
8ecd5de2 | 552 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); |
88310e2e | 553 | |
8ecd5de2 WS |
554 | TC_ITEM tcItem; |
555 | tcItem.mask = TCIF_IMAGE; | |
88310e2e | 556 | |
5482ee07 VZ |
557 | return TabCtrl_GetItem(GetHwnd(), nPage, &tcItem) ? tcItem.iImage |
558 | : wxNOT_FOUND; | |
88310e2e VZ |
559 | } |
560 | ||
8d34bf5c | 561 | bool wxNotebook::SetPageImage(size_t nPage, int nImage) |
88310e2e | 562 | { |
8ecd5de2 | 563 | wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("notebook page out of range") ); |
88310e2e | 564 | |
8ecd5de2 WS |
565 | TC_ITEM tcItem; |
566 | tcItem.mask = TCIF_IMAGE; | |
567 | tcItem.iImage = nImage; | |
88310e2e | 568 | |
8ecd5de2 | 569 | return TabCtrl_SetItem(GetHwnd(), nPage, &tcItem) != 0; |
88310e2e VZ |
570 | } |
571 | ||
572 | void wxNotebook::SetImageList(wxImageList* imageList) | |
907f37b3 | 573 | { |
8ecd5de2 | 574 | wxNotebookBase::SetImageList(imageList); |
07b8d7ec | 575 | |
8ecd5de2 WS |
576 | if ( imageList ) |
577 | { | |
5482ee07 | 578 | (void) TabCtrl_SetImageList(GetHwnd(), GetHimagelistOf(imageList)); |
8ecd5de2 | 579 | } |
b656febd VS |
580 | } |
581 | ||
d9506e77 VZ |
582 | // ---------------------------------------------------------------------------- |
583 | // wxNotebook size settings | |
584 | // ---------------------------------------------------------------------------- | |
585 | ||
c3732409 VZ |
586 | wxRect wxNotebook::GetPageSize() const |
587 | { | |
588 | wxRect r; | |
589 | ||
590 | RECT rc; | |
591 | ::GetClientRect(GetHwnd(), &rc); | |
592 | ||
593 | // This check is to work around a bug in TabCtrl_AdjustRect which will | |
628eae0b VZ |
594 | // cause a crash on win2k or on XP with themes disabled if either |
595 | // wxNB_MULTILINE is used or tabs are placed on a side, if the rectangle | |
596 | // is too small. | |
597 | // | |
598 | // The value of 20 is chosen arbitrarily but seems to work | |
599 | if ( rc.right > 20 && rc.bottom > 20 ) | |
c3732409 | 600 | { |
01c8cbf5 | 601 | TabCtrl_AdjustRect(GetHwnd(), false, &rc); |
c3732409 VZ |
602 | |
603 | wxCopyRECTToRect(rc, r); | |
604 | } | |
605 | ||
606 | return r; | |
607 | } | |
608 | ||
d9506e77 VZ |
609 | void wxNotebook::SetPageSize(const wxSize& size) |
610 | { | |
611 | // transform the page size into the notebook size | |
612 | RECT rc; | |
613 | rc.left = | |
614 | rc.top = 0; | |
615 | rc.right = size.x; | |
616 | rc.bottom = size.y; | |
617 | ||
b8bdaa7c | 618 | TabCtrl_AdjustRect(GetHwnd(), true, &rc); |
d9506e77 VZ |
619 | |
620 | // and now set it | |
621 | SetSize(rc.right - rc.left, rc.bottom - rc.top); | |
622 | } | |
623 | ||
624 | void wxNotebook::SetPadding(const wxSize& padding) | |
625 | { | |
626 | TabCtrl_SetPadding(GetHwnd(), padding.x, padding.y); | |
627 | } | |
42e69d6b VZ |
628 | |
629 | // Windows-only at present. Also, you must use the wxNB_FIXEDWIDTH | |
630 | // style. | |
631 | void wxNotebook::SetTabSize(const wxSize& sz) | |
632 | { | |
633 | ::SendMessage(GetHwnd(), TCM_SETITEMSIZE, 0, MAKELPARAM(sz.x, sz.y)); | |
634 | } | |
635 | ||
2ce7af35 JS |
636 | wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const |
637 | { | |
669c595d | 638 | // we can't use TabCtrl_AdjustRect here because it only works for wxNB_TOP |
2ce7af35 | 639 | wxSize sizeTotal = sizePage; |
078cf5cb | 640 | |
8b5d5223 | 641 | wxSize tabSize; |
669c595d | 642 | if ( GetPageCount() > 0 ) |
2ce7af35 JS |
643 | { |
644 | RECT rect; | |
669c595d | 645 | TabCtrl_GetItemRect(GetHwnd(), 0, &rect); |
2ce7af35 JS |
646 | tabSize.x = rect.right - rect.left; |
647 | tabSize.y = rect.bottom - rect.top; | |
648 | } | |
669c595d | 649 | |
49ac39e3 VZ |
650 | const int rows = GetRowCount(); |
651 | ||
669c595d VZ |
652 | // add an extra margin in both directions |
653 | const int MARGIN = 8; | |
654 | if ( IsVertical() ) | |
2ce7af35 | 655 | { |
669c595d | 656 | sizeTotal.x += MARGIN; |
49ac39e3 | 657 | sizeTotal.y += tabSize.y * rows + MARGIN; |
2ce7af35 | 658 | } |
669c595d | 659 | else // horizontal layout |
2ce7af35 | 660 | { |
49ac39e3 | 661 | sizeTotal.x += tabSize.x * rows + MARGIN; |
669c595d | 662 | sizeTotal.y += MARGIN; |
2ce7af35 JS |
663 | } |
664 | ||
665 | return sizeTotal; | |
666 | } | |
667 | ||
2015f2b3 VZ |
668 | void wxNotebook::AdjustPageSize(wxNotebookPage *page) |
669 | { | |
9a83f860 | 670 | wxCHECK_RET( page, wxT("NULL page in wxNotebook::AdjustPageSize") ); |
2015f2b3 | 671 | |
c3732409 VZ |
672 | const wxRect r = GetPageSize(); |
673 | if ( !r.IsEmpty() ) | |
14a6b6e5 | 674 | { |
c3732409 | 675 | page->SetSize(r); |
14a6b6e5 | 676 | } |
2015f2b3 VZ |
677 | } |
678 | ||
88310e2e VZ |
679 | // ---------------------------------------------------------------------------- |
680 | // wxNotebook operations | |
681 | // ---------------------------------------------------------------------------- | |
682 | ||
621793f4 | 683 | // remove one page from the notebook, without deleting |
8d34bf5c | 684 | wxNotebookPage *wxNotebook::DoRemovePage(size_t nPage) |
621793f4 | 685 | { |
df7145da VZ |
686 | wxNotebookPage *pageRemoved = wxNotebookBase::DoRemovePage(nPage); |
687 | if ( !pageRemoved ) | |
688 | return NULL; | |
621793f4 | 689 | |
8138f406 VS |
690 | // hide the removed page to maintain the invariant that only the |
691 | // selected page is visible and others are hidden: | |
692 | pageRemoved->Show(false); | |
693 | ||
01c8cbf5 | 694 | TabCtrl_DeleteItem(GetHwnd(), nPage); |
621793f4 | 695 | |
df7145da VZ |
696 | if ( m_pages.IsEmpty() ) |
697 | { | |
698 | // no selection any more, the notebook becamse empty | |
681be2ef | 699 | m_selection = wxNOT_FOUND; |
df7145da VZ |
700 | } |
701 | else // notebook still not empty | |
702 | { | |
01c8cbf5 | 703 | int selNew = TabCtrl_GetCurSel(GetHwnd()); |
5482ee07 | 704 | if ( selNew != wxNOT_FOUND ) |
df7145da | 705 | { |
623f5f70 | 706 | // No selection change, just refresh the current selection. |
078cf5cb WS |
707 | // Because it could be that the slection index changed |
708 | // we need to update it. | |
623f5f70 | 709 | // Note: this does not mean the selection it self changed. |
681be2ef VZ |
710 | m_selection = selNew; |
711 | m_pages[m_selection]->Refresh(); | |
df7145da | 712 | } |
681be2ef | 713 | else if (int(nPage) == m_selection) |
43a997b6 | 714 | { |
623f5f70 | 715 | // The selection was deleted. |
078cf5cb | 716 | |
623f5f70 | 717 | // Determine new selection. |
681be2ef VZ |
718 | if (m_selection == int(GetPageCount())) |
719 | selNew = m_selection - 1; | |
623f5f70 | 720 | else |
681be2ef | 721 | selNew = m_selection; |
078cf5cb | 722 | |
681be2ef | 723 | // m_selection must be always valid so reset it before calling |
43a997b6 | 724 | // SetSelection() |
681be2ef | 725 | m_selection = wxNOT_FOUND; |
43a997b6 VZ |
726 | SetSelection(selNew); |
727 | } | |
623f5f70 JS |
728 | else |
729 | { | |
730 | wxFAIL; // Windows did not behave ok. | |
731 | } | |
df7145da | 732 | } |
47f12f58 | 733 | |
df7145da | 734 | return pageRemoved; |
621793f4 JS |
735 | } |
736 | ||
88310e2e VZ |
737 | // remove all pages |
738 | bool wxNotebook::DeleteAllPages() | |
739 | { | |
7ec69821 WS |
740 | size_t nPageCount = GetPageCount(); |
741 | size_t nPage; | |
742 | for ( nPage = 0; nPage < nPageCount; nPage++ ) | |
743 | delete m_pages[nPage]; | |
88310e2e | 744 | |
7ec69821 | 745 | m_pages.Clear(); |
88310e2e | 746 | |
7ec69821 | 747 | TabCtrl_DeleteAllItems(GetHwnd()); |
907f37b3 | 748 | |
681be2ef | 749 | m_selection = wxNOT_FOUND; |
47f12f58 | 750 | |
7ec69821 WS |
751 | InvalidateBestSize(); |
752 | return true; | |
88310e2e VZ |
753 | } |
754 | ||
88310e2e | 755 | // same as AddPage() but does it at given position |
8d34bf5c | 756 | bool wxNotebook::InsertPage(size_t nPage, |
88310e2e VZ |
757 | wxNotebookPage *pPage, |
758 | const wxString& strText, | |
759 | bool bSelect, | |
760 | int imageId) | |
761 | { | |
9a83f860 | 762 | wxCHECK_MSG( pPage != NULL, false, wxT("NULL page in wxNotebook::InsertPage") ); |
b8bdaa7c | 763 | wxCHECK_MSG( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), false, |
9a83f860 | 764 | wxT("invalid index in wxNotebook::InsertPage") ); |
88310e2e | 765 | |
efa14cf2 | 766 | wxASSERT_MSG( pPage->GetParent() == this, |
9a83f860 | 767 | wxT("notebook pages must have notebook as parent") ); |
43427087 | 768 | |
22f3361e VZ |
769 | // add a new tab to the control |
770 | // ---------------------------- | |
58a8ab88 | 771 | |
22f3361e VZ |
772 | // init all fields to 0 |
773 | TC_ITEM tcItem; | |
774 | wxZeroMemory(tcItem); | |
58a8ab88 | 775 | |
22f3361e VZ |
776 | // set the image, if any |
777 | if ( imageId != -1 ) | |
778 | { | |
779 | tcItem.mask |= TCIF_IMAGE; | |
780 | tcItem.iImage = imageId; | |
781 | } | |
88310e2e | 782 | |
22f3361e | 783 | // and the text |
8b5d5223 | 784 | if ( !strText.empty() ) |
22f3361e VZ |
785 | { |
786 | tcItem.mask |= TCIF_TEXT; | |
f48a1159 | 787 | tcItem.pszText = const_cast<wxChar *>(strText.wx_str()); |
22f3361e | 788 | } |
43427087 | 789 | |
e830a6a6 RD |
790 | // hide the page: unless it is selected, it shouldn't be shown (and if it |
791 | // is selected it will be shown later) | |
792 | HWND hwnd = GetWinHwnd(pPage); | |
793 | SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE); | |
794 | ||
795 | // this updates internal flag too -- otherwise it would get out of sync | |
796 | // with the real state | |
797 | pPage->Show(false); | |
798 | ||
799 | ||
22f3361e VZ |
800 | // fit the notebook page to the tab control's display area: this should be |
801 | // done before adding it to the notebook or TabCtrl_InsertItem() will | |
802 | // change the notebooks size itself! | |
2015f2b3 | 803 | AdjustPageSize(pPage); |
43427087 | 804 | |
22f3361e | 805 | // finally do insert it |
01c8cbf5 | 806 | if ( TabCtrl_InsertItem(GetHwnd(), nPage, &tcItem) == -1 ) |
2015f2b3 | 807 | { |
22f3361e | 808 | wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str()); |
88310e2e | 809 | |
b8bdaa7c | 810 | return false; |
22f3361e | 811 | } |
88310e2e | 812 | |
ebd9ec29 JG |
813 | // need to update the bg brush when the first page is added |
814 | // so the first panel gets the correct themed background | |
815 | if ( m_pages.empty() ) | |
816 | { | |
11e70ae6 | 817 | #if wxUSE_UXTHEME |
ebd9ec29 | 818 | UpdateBgBrush(); |
11e70ae6 | 819 | #endif // wxUSE_UXTHEME |
ebd9ec29 JG |
820 | } |
821 | ||
22f3361e VZ |
822 | // succeeded: save the pointer to the page |
823 | m_pages.Insert(pPage, nPage); | |
42e69d6b | 824 | |
56b9925b VZ |
825 | // we may need to adjust the size again if the notebook size changed: |
826 | // normally this only happens for the first page we add (the tabs which | |
827 | // hadn't been there before are now shown) but for a multiline notebook it | |
828 | // can happen for any page at all as a new row could have been started | |
829 | if ( m_pages.GetCount() == 1 || HasFlag(wxNB_MULTILINE) ) | |
2015f2b3 VZ |
830 | { |
831 | AdjustPageSize(pPage); | |
832 | } | |
833 | ||
22f3361e VZ |
834 | // now deal with the selection |
835 | // --------------------------- | |
836 | ||
837 | // if the inserted page is before the selected one, we must update the | |
838 | // index of the selected page | |
681be2ef | 839 | if ( int(nPage) <= m_selection ) |
22f3361e VZ |
840 | { |
841 | // one extra page added | |
681be2ef | 842 | m_selection++; |
22f3361e VZ |
843 | } |
844 | ||
60d5c563 | 845 | DoSetSelectionAfterInsertion(nPage, bSelect); |
22f3361e | 846 | |
37144cf0 | 847 | InvalidateBestSize(); |
25057aba | 848 | |
b8bdaa7c | 849 | return true; |
88310e2e VZ |
850 | } |
851 | ||
e450aa69 | 852 | int wxNotebook::HitTest(const wxPoint& pt, long *flags) const |
ef094fa0 JS |
853 | { |
854 | TC_HITTESTINFO hitTestInfo; | |
855 | hitTestInfo.pt.x = pt.x; | |
856 | hitTestInfo.pt.y = pt.y; | |
e450aa69 | 857 | int item = TabCtrl_HitTest(GetHwnd(), &hitTestInfo); |
ef094fa0 | 858 | |
e450aa69 VZ |
859 | if ( flags ) |
860 | { | |
861 | *flags = 0; | |
862 | ||
863 | if ((hitTestInfo.flags & TCHT_NOWHERE) == TCHT_NOWHERE) | |
9804d540 | 864 | *flags |= wxBK_HITTEST_NOWHERE; |
e450aa69 | 865 | if ((hitTestInfo.flags & TCHT_ONITEM) == TCHT_ONITEM) |
9804d540 | 866 | *flags |= wxBK_HITTEST_ONITEM; |
e450aa69 | 867 | if ((hitTestInfo.flags & TCHT_ONITEMICON) == TCHT_ONITEMICON) |
9804d540 | 868 | *flags |= wxBK_HITTEST_ONICON; |
e450aa69 | 869 | if ((hitTestInfo.flags & TCHT_ONITEMLABEL) == TCHT_ONITEMLABEL) |
9804d540 | 870 | *flags |= wxBK_HITTEST_ONLABEL; |
22a35096 | 871 | if ( item == wxNOT_FOUND && GetPageSize().Contains(pt) ) |
9804d540 | 872 | *flags |= wxBK_HITTEST_ONPAGE; |
e450aa69 | 873 | } |
ef094fa0 JS |
874 | |
875 | return item; | |
876 | } | |
877 | ||
014ee083 VZ |
878 | // ---------------------------------------------------------------------------- |
879 | // flicker-less notebook redraw | |
880 | // ---------------------------------------------------------------------------- | |
881 | ||
882 | #if USE_NOTEBOOK_ANTIFLICKER | |
883 | ||
884 | // wnd proc for the spin button | |
885 | LRESULT APIENTRY _EXPORT wxNotebookSpinBtnWndProc(HWND hwnd, | |
886 | UINT message, | |
887 | WPARAM wParam, | |
888 | LPARAM lParam) | |
889 | { | |
890 | if ( message == WM_ERASEBKGND ) | |
891 | return 0; | |
892 | ||
893 | return ::CallWindowProc(CASTWNDPROC gs_wndprocNotebookSpinBtn, | |
894 | hwnd, message, wParam, lParam); | |
895 | } | |
896 | ||
6143d3b6 VZ |
897 | LRESULT APIENTRY _EXPORT wxNotebookWndProc(HWND hwnd, |
898 | UINT message, | |
899 | WPARAM wParam, | |
900 | LPARAM lParam) | |
901 | { | |
902 | return ::CallWindowProc(CASTWNDPROC gs_wndprocNotebook, | |
903 | hwnd, message, wParam, lParam); | |
904 | } | |
905 | ||
014ee083 VZ |
906 | void wxNotebook::OnEraseBackground(wxEraseEvent& WXUNUSED(event)) |
907 | { | |
908 | // do nothing here | |
909 | } | |
910 | ||
911 | void wxNotebook::OnPaint(wxPaintEvent& WXUNUSED(event)) | |
912 | { | |
913 | wxPaintDC dc(this); | |
914 | wxMemoryDC memdc; | |
915 | RECT rc; | |
916 | ::GetClientRect(GetHwnd(), &rc); | |
917 | wxBitmap bmp(rc.right, rc.bottom); | |
918 | memdc.SelectObject(bmp); | |
919 | ||
6614aa49 VZ |
920 | const wxLayoutDirection dir = dc.GetLayoutDirection(); |
921 | memdc.SetLayoutDirection(dir); | |
922 | ||
014ee083 | 923 | // if there is no special brush just use the solid background colour |
64c288fa | 924 | #if wxUSE_UXTHEME |
014ee083 | 925 | HBRUSH hbr = (HBRUSH)m_hbrBackground; |
64c288fa JS |
926 | #else |
927 | HBRUSH hbr = 0; | |
e4db172a | 928 | #endif |
e32703a9 | 929 | wxBrush brush; |
014ee083 | 930 | if ( !hbr ) |
e32703a9 VZ |
931 | { |
932 | brush = wxBrush(GetBackgroundColour()); | |
933 | hbr = GetHbrushOf(brush); | |
934 | } | |
014ee083 | 935 | |
888dde65 | 936 | wxMSWDCImpl *impl = (wxMSWDCImpl*) memdc.GetImpl(); |
014ee083 | 937 | |
888dde65 RR |
938 | ::FillRect(GetHdcOf(*impl), &rc, hbr); |
939 | ||
940 | MSWDefWindowProc(WM_PAINT, (WPARAM)(impl->GetHDC()), 0); | |
014ee083 | 941 | |
f4322df6 | 942 | // For some reason in RTL mode, source offset has to be -1, otherwise the |
6614aa49 VZ |
943 | // right border (physical) remains unpainted. |
944 | const wxCoord ofs = dir == wxLayout_RightToLeft ? -1 : 0; | |
945 | dc.Blit(ofs, 0, rc.right, rc.bottom, &memdc, ofs, 0); | |
014ee083 VZ |
946 | } |
947 | ||
948 | #endif // USE_NOTEBOOK_ANTIFLICKER | |
e450aa69 | 949 | |
88310e2e VZ |
950 | // ---------------------------------------------------------------------------- |
951 | // wxNotebook callbacks | |
952 | // ---------------------------------------------------------------------------- | |
953 | ||
9026ad85 | 954 | void wxNotebook::OnSize(wxSizeEvent& event) |
88310e2e | 955 | { |
7dccdf81 | 956 | if ( GetPageCount() == 0 ) |
f7eaa62f JS |
957 | { |
958 | // Prevents droppings on resize, but does cause some flicker | |
959 | // when there are no pages. | |
2aa24b60 | 960 | Refresh(); |
f7eaa62f JS |
961 | event.Skip(); |
962 | return; | |
963 | } | |
254fbd14 JS |
964 | #ifndef __WXWINCE__ |
965 | else | |
966 | { | |
967 | // Without this, we can sometimes get droppings at the edges | |
968 | // of a notebook, for example a notebook in a splitter window. | |
969 | // This needs to be reconciled with the RefreshRect calls | |
970 | // at the end of this function, which weren't enough to prevent | |
971 | // the droppings. | |
01c8cbf5 | 972 | |
254fbd14 JS |
973 | wxSize sz = GetClientSize(); |
974 | ||
975 | // Refresh right side | |
976 | wxRect rect(sz.x-4, 0, 4, sz.y); | |
977 | RefreshRect(rect); | |
01c8cbf5 | 978 | |
254fbd14 JS |
979 | // Refresh bottom side |
980 | rect = wxRect(0, sz.y-4, sz.x, 4); | |
981 | RefreshRect(rect); | |
01c8cbf5 | 982 | |
254fbd14 JS |
983 | // Refresh left side |
984 | rect = wxRect(0, 0, 4, sz.y); | |
985 | RefreshRect(rect); | |
986 | } | |
014ee083 | 987 | #endif // !__WXWINCE__ |
f7eaa62f | 988 | |
c1637c89 | 989 | // fit all the notebook pages to the tab control's display area |
56b9925b | 990 | |
c1637c89 VZ |
991 | RECT rc; |
992 | rc.left = rc.top = 0; | |
993 | GetSize((int *)&rc.right, (int *)&rc.bottom); | |
56b9925b | 994 | |
c1637c89 VZ |
995 | // save the total size, we'll use it below |
996 | int widthNbook = rc.right - rc.left, | |
997 | heightNbook = rc.bottom - rc.top; | |
998 | ||
999 | // there seems to be a bug in the implementation of TabCtrl_AdjustRect(): it | |
1000 | // returns completely false values for multiline tab controls after the tabs | |
1001 | // are added but before getting the first WM_SIZE (off by ~50 pixels, see | |
1002 | // | |
1003 | // http://sf.net/tracker/index.php?func=detail&aid=645323&group_id=9863&atid=109863 | |
1004 | // | |
1005 | // and the only work around I could find was this ugly hack... without it | |
1006 | // simply toggling the "multiline" checkbox in the notebook sample resulted | |
1007 | // in a noticeable page displacement | |
1008 | if ( HasFlag(wxNB_MULTILINE) ) | |
1009 | { | |
1010 | // avoid an infinite recursion: we get another notification too! | |
1011 | static bool s_isInOnSize = false; | |
4b7f2165 | 1012 | |
c1637c89 VZ |
1013 | if ( !s_isInOnSize ) |
1014 | { | |
1015 | s_isInOnSize = true; | |
1016 | SendMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, | |
1017 | MAKELPARAM(rc.right, rc.bottom)); | |
1018 | s_isInOnSize = false; | |
1019 | } | |
49ac39e3 VZ |
1020 | |
1021 | // The best size depends on the number of rows of tabs, which can | |
1022 | // change when the notepad is resized. | |
1023 | InvalidateBestSize(); | |
c1637c89 | 1024 | } |
b5c3b538 | 1025 | |
e2f6f8da RD |
1026 | #if wxUSE_UXTHEME |
1027 | // background bitmap size has changed, update the brush using it too | |
1028 | UpdateBgBrush(); | |
1029 | #endif // wxUSE_UXTHEME | |
1030 | ||
01c8cbf5 | 1031 | TabCtrl_AdjustRect(GetHwnd(), false, &rc); |
c1637c89 VZ |
1032 | |
1033 | int width = rc.right - rc.left, | |
1034 | height = rc.bottom - rc.top; | |
1035 | size_t nCount = m_pages.Count(); | |
1036 | for ( size_t nPage = 0; nPage < nCount; nPage++ ) { | |
1037 | wxNotebookPage *pPage = m_pages[nPage]; | |
1038 | pPage->SetSize(rc.left, rc.top, width, height); | |
1039 | } | |
1040 | ||
1041 | ||
1042 | // unless we had already repainted everything, we now need to refresh | |
1043 | if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) ) | |
1044 | { | |
1045 | // invalidate areas not covered by pages | |
1046 | RefreshRect(wxRect(0, 0, widthNbook, rc.top), false); | |
1047 | RefreshRect(wxRect(0, rc.top, rc.left, height), false); | |
1048 | RefreshRect(wxRect(0, rc.bottom, widthNbook, heightNbook - rc.bottom), | |
1049 | false); | |
3550706d | 1050 | RefreshRect(wxRect(rc.right, rc.top, widthNbook - rc.right, height), |
c1637c89 VZ |
1051 | false); |
1052 | } | |
1053 | ||
014ee083 VZ |
1054 | #if USE_NOTEBOOK_ANTIFLICKER |
1055 | // subclass the spin control used by the notebook to scroll pages to | |
1056 | // prevent it from flickering on resize | |
dfb47d83 | 1057 | if ( !m_hasSubclassedUpdown ) |
014ee083 VZ |
1058 | { |
1059 | // iterate over all child windows to find spin button | |
1060 | for ( HWND child = ::GetWindow(GetHwnd(), GW_CHILD); | |
1061 | child; | |
1062 | child = ::GetWindow(child, GW_HWNDNEXT) ) | |
1063 | { | |
1064 | wxWindow *childWindow = wxFindWinFromHandle((WXHWND)child); | |
1065 | ||
1066 | // see if it exists, if no wxWindow found then assume it's the spin | |
1067 | // btn | |
1068 | if ( !childWindow ) | |
1069 | { | |
1070 | // subclass the spin button to override WM_ERASEBKGND | |
dfb47d83 VZ |
1071 | if ( !gs_wndprocNotebookSpinBtn ) |
1072 | gs_wndprocNotebookSpinBtn = (WXFARPROC)wxGetWindowProc(child); | |
014ee083 VZ |
1073 | |
1074 | wxSetWindowProc(child, wxNotebookSpinBtnWndProc); | |
dfb47d83 | 1075 | m_hasSubclassedUpdown = true; |
014ee083 VZ |
1076 | break; |
1077 | } | |
1078 | } | |
1079 | } | |
1080 | #endif // USE_NOTEBOOK_ANTIFLICKER | |
1081 | ||
c1637c89 | 1082 | event.Skip(); |
88310e2e VZ |
1083 | } |
1084 | ||
3e97a905 | 1085 | void wxNotebook::OnSelChange(wxBookCtrlEvent& event) |
88310e2e | 1086 | { |
1d6fcbcc VZ |
1087 | // is it our tab control? |
1088 | if ( event.GetEventObject() == this ) | |
1089 | { | |
1090 | UpdateSelection(event.GetSelection()); | |
1091 | } | |
88310e2e | 1092 | |
1d6fcbcc VZ |
1093 | // we want to give others a chance to process this message as well |
1094 | event.Skip(); | |
88310e2e VZ |
1095 | } |
1096 | ||
88310e2e VZ |
1097 | void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) |
1098 | { | |
d9506e77 VZ |
1099 | if ( event.IsWindowChange() ) { |
1100 | // change pages | |
1101 | AdvanceSelection(event.GetDirection()); | |
1102 | } | |
1103 | else { | |
b8bdaa7c | 1104 | // we get this event in 3 cases |
d9506e77 VZ |
1105 | // |
1106 | // a) one of our pages might have generated it because the user TABbed | |
1107 | // out from it in which case we should propagate the event upwards and | |
1108 | // our parent will take care of setting the focus to prev/next sibling | |
1109 | // | |
1110 | // or | |
1111 | // | |
1112 | // b) the parent panel wants to give the focus to us so that we | |
1113 | // forward it to our selected page. We can't deal with this in | |
1114 | // OnSetFocus() because we don't know which direction the focus came | |
1115 | // from in this case and so can't choose between setting the focus to | |
1116 | // first or last panel child | |
b8bdaa7c VZ |
1117 | // |
1118 | // or | |
1119 | // | |
1120 | // c) we ourselves (see MSWTranslateMessage) generated the event | |
1121 | // | |
1122 | wxWindow * const parent = GetParent(); | |
1123 | ||
3c99602b MB |
1124 | // the wxObject* casts are required to avoid MinGW GCC 2.95.3 ICE |
1125 | const bool isFromParent = event.GetEventObject() == (wxObject*) parent; | |
1126 | const bool isFromSelf = event.GetEventObject() == (wxObject*) this; | |
4a0dcc87 | 1127 | const bool isForward = event.GetDirection(); |
b8bdaa7c | 1128 | |
4a0dcc87 VS |
1129 | if ( isFromSelf && !isForward ) |
1130 | { | |
1131 | // focus is currently on notebook tab and should leave | |
1132 | // it backwards (Shift-TAB) | |
1133 | event.SetCurrentFocus(this); | |
1134 | parent->HandleWindowEvent(event); | |
1135 | } | |
1136 | else if ( isFromParent || isFromSelf ) | |
d9506e77 | 1137 | { |
b8bdaa7c | 1138 | // no, it doesn't come from child, case (b) or (c): forward to a |
4a0dcc87 VS |
1139 | // page but only if entering notebook page (i.e. direction is |
1140 | // backwards (Shift-TAB) comething from out-of-notebook, or | |
1141 | // direction is forward (TAB) from ourselves), | |
681be2ef | 1142 | if ( m_selection != wxNOT_FOUND && |
b8bdaa7c | 1143 | (!event.GetDirection() || isFromSelf) ) |
d9506e77 VZ |
1144 | { |
1145 | // so that the page knows that the event comes from it's parent | |
1146 | // and is being propagated downwards | |
1147 | event.SetEventObject(this); | |
1148 | ||
681be2ef | 1149 | wxWindow *page = m_pages[m_selection]; |
937013e0 | 1150 | if ( !page->HandleWindowEvent(event) ) |
d9506e77 VZ |
1151 | { |
1152 | page->SetFocus(); | |
1153 | } | |
1154 | //else: page manages focus inside it itself | |
1155 | } | |
b8bdaa7c | 1156 | else // otherwise set the focus to the notebook itself |
d9506e77 | 1157 | { |
d9506e77 VZ |
1158 | SetFocus(); |
1159 | } | |
1160 | } | |
1161 | else | |
1162 | { | |
b8bdaa7c VZ |
1163 | // it comes from our child, case (a), pass to the parent, but only |
1164 | // if the direction is forwards. Otherwise set the focus to the | |
1165 | // notebook itself. The notebook is always the 'first' control of a | |
1166 | // page. | |
4a0dcc87 | 1167 | if ( !isForward ) |
b8bdaa7c VZ |
1168 | { |
1169 | SetFocus(); | |
1170 | } | |
1171 | else if ( parent ) | |
1172 | { | |
d9506e77 | 1173 | event.SetCurrentFocus(this); |
937013e0 | 1174 | parent->HandleWindowEvent(event); |
d9506e77 VZ |
1175 | } |
1176 | } | |
88310e2e | 1177 | } |
88310e2e VZ |
1178 | } |
1179 | ||
caf95d2a VZ |
1180 | #if wxUSE_UXTHEME |
1181 | ||
c3732409 | 1182 | bool wxNotebook::DoDrawBackground(WXHDC hDC, wxWindow *child) |
caf95d2a | 1183 | { |
c3732409 VZ |
1184 | wxUxThemeHandle theme(child ? child : this, L"TAB"); |
1185 | if ( !theme ) | |
1186 | return false; | |
1187 | ||
1188 | // get the notebook client rect (we're not interested in drawing tabs | |
1189 | // themselves) | |
1190 | wxRect r = GetPageSize(); | |
1191 | if ( r.IsEmpty() ) | |
1192 | return false; | |
1193 | ||
c4a95f6f | 1194 | RECT rc; |
c3732409 VZ |
1195 | wxCopyRectToRECT(r, rc); |
1196 | ||
1197 | // map rect to the coords of the window we're drawing in | |
1198 | if ( child ) | |
1199 | ::MapWindowPoints(GetHwnd(), GetHwndOf(child), (POINT *)&rc, 2); | |
1200 | ||
2ff53fd3 JS |
1201 | // we have the content area (page size), but we need to draw all of the |
1202 | // background for it to be aligned correctly | |
1203 | wxUxThemeEngine::Get()->GetThemeBackgroundExtent | |
1204 | ( | |
1205 | theme, | |
1206 | (HDC) hDC, | |
1207 | 9 /* TABP_PANE */, | |
1208 | 0, | |
1209 | &rc, | |
1210 | &rc | |
1211 | ); | |
c3732409 VZ |
1212 | wxUxThemeEngine::Get()->DrawThemeBackground |
1213 | ( | |
1214 | theme, | |
92199f4c | 1215 | (HDC) hDC, |
c3732409 VZ |
1216 | 9 /* TABP_PANE */, |
1217 | 0, | |
1218 | &rc, | |
1219 | NULL | |
1220 | ); | |
1221 | ||
1222 | return true; | |
1223 | } | |
de359565 | 1224 | |
c3732409 VZ |
1225 | WXHBRUSH wxNotebook::QueryBgBitmap() |
1226 | { | |
1227 | wxRect r = GetPageSize(); | |
1228 | if ( r.IsEmpty() ) | |
1229 | return 0; | |
c4a95f6f VZ |
1230 | |
1231 | WindowHDC hDC(GetHwnd()); | |
1232 | MemoryHDC hDCMem(hDC); | |
c3732409 | 1233 | CompatibleBitmap hBmp(hDC, r.x + r.width, r.y + r.height); |
c4a95f6f VZ |
1234 | |
1235 | SelectInHDC selectBmp(hDCMem, hBmp); | |
caf95d2a | 1236 | |
c3732409 VZ |
1237 | if ( !DoDrawBackground((WXHDC)(HDC)hDCMem) ) |
1238 | return 0; | |
0f770734 | 1239 | |
de359565 | 1240 | return (WXHBRUSH)::CreatePatternBrush(hBmp); |
c4a95f6f | 1241 | } |
caf95d2a | 1242 | |
c4a95f6f VZ |
1243 | void wxNotebook::UpdateBgBrush() |
1244 | { | |
1245 | if ( m_hbrBackground ) | |
1246 | ::DeleteObject((HBRUSH)m_hbrBackground); | |
caf95d2a | 1247 | |
c4a95f6f VZ |
1248 | if ( !m_hasBgCol && wxUxThemeEngine::GetIfActive() ) |
1249 | { | |
de359565 | 1250 | m_hbrBackground = QueryBgBitmap(); |
caf95d2a | 1251 | } |
c3732409 | 1252 | else // no themes or we've got user-defined solid colour |
caf95d2a VZ |
1253 | { |
1254 | m_hbrBackground = NULL; | |
1255 | } | |
1256 | } | |
1257 | ||
b8797d96 | 1258 | WXHBRUSH wxNotebook::MSWGetBgBrushForChild(WXHDC hDC, wxWindow *child) |
caf95d2a | 1259 | { |
ebfee179 | 1260 | if ( m_hbrBackground ) |
caf95d2a VZ |
1261 | { |
1262 | // before drawing with the background brush, we need to position it | |
1263 | // correctly | |
caf95d2a | 1264 | RECT rc; |
b8797d96 | 1265 | ::GetWindowRect(GetHwndOf(child), &rc); |
caf95d2a VZ |
1266 | |
1267 | ::MapWindowPoints(NULL, GetHwnd(), (POINT *)&rc, 1); | |
1268 | ||
5c836c46 | 1269 | if ( !::SetBrushOrgEx((HDC)hDC, -rc.left, -rc.top, NULL) ) |
caf95d2a | 1270 | { |
9a83f860 | 1271 | wxLogLastError(wxT("SetBrushOrgEx(notebook bg brush)")); |
caf95d2a | 1272 | } |
c4a95f6f VZ |
1273 | |
1274 | return m_hbrBackground; | |
5c836c46 VZ |
1275 | } |
1276 | ||
b8797d96 | 1277 | return wxNotebookBase::MSWGetBgBrushForChild(hDC, child); |
5c836c46 | 1278 | } |
caf95d2a | 1279 | |
c3732409 | 1280 | bool wxNotebook::MSWPrintChild(WXHDC hDC, wxWindow *child) |
07c19327 | 1281 | { |
c3732409 VZ |
1282 | // solid background colour overrides themed background drawing |
1283 | if ( !UseBgCol() && DoDrawBackground(hDC, child) ) | |
1284 | return true; | |
de359565 | 1285 | |
4dab5279 JS |
1286 | // If we're using a solid colour (for example if we've switched off |
1287 | // theming for this notebook), paint it | |
1288 | if (UseBgCol()) | |
1289 | { | |
1290 | wxRect r = GetPageSize(); | |
1291 | if ( r.IsEmpty() ) | |
1292 | return false; | |
1293 | ||
1294 | RECT rc; | |
1295 | wxCopyRectToRECT(r, rc); | |
1296 | ||
1297 | // map rect to the coords of the window we're drawing in | |
1298 | if ( child ) | |
1299 | ::MapWindowPoints(GetHwnd(), GetHwndOf(child), (POINT *)&rc, 2); | |
1300 | ||
1301 | wxBrush brush(GetBackgroundColour()); | |
1302 | HBRUSH hbr = GetHbrushOf(brush); | |
01c8cbf5 | 1303 | |
4dab5279 JS |
1304 | ::FillRect((HDC) hDC, &rc, hbr); |
1305 | ||
1306 | return true; | |
1307 | } | |
1308 | ||
c3732409 | 1309 | return wxNotebookBase::MSWPrintChild(hDC, child); |
07c19327 VZ |
1310 | } |
1311 | ||
caf95d2a VZ |
1312 | #endif // wxUSE_UXTHEME |
1313 | ||
25057aba JS |
1314 | // Windows only: attempts to get colour for UX theme page background |
1315 | wxColour wxNotebook::GetThemeBackgroundColour() const | |
1316 | { | |
1317 | #if wxUSE_UXTHEME | |
1318 | if (wxUxThemeEngine::Get()) | |
1319 | { | |
1320 | wxUxThemeHandle hTheme((wxNotebook*) this, L"TAB"); | |
1321 | if (hTheme) | |
1322 | { | |
1323 | // This is total guesswork. | |
b380533c JS |
1324 | // See PlatformSDK\Include\Tmschema.h for values. |
1325 | // JACS: can also use 9 (TABP_PANE) | |
25057aba | 1326 | COLORREF themeColor; |
b380533c | 1327 | bool success = (S_OK == wxUxThemeEngine::Get()->GetThemeColor( |
25057aba JS |
1328 | hTheme, |
1329 | 10 /* TABP_BODY */, | |
1330 | 1 /* NORMAL */, | |
1331 | 3821 /* FILLCOLORHINT */, | |
b380533c JS |
1332 | &themeColor)); |
1333 | if (!success) | |
1334 | return GetBackgroundColour(); | |
25057aba JS |
1335 | |
1336 | /* | |
1337 | [DS] Workaround for WindowBlinds: | |
1338 | Some themes return a near black theme color using FILLCOLORHINT, | |
1339 | this makes notebook pages have an ugly black background and makes | |
1340 | text (usually black) unreadable. Retry again with FILLCOLOR. | |
1341 | ||
1342 | This workaround potentially breaks appearance of some themes, | |
1343 | but in practice it already fixes some themes. | |
1344 | */ | |
1345 | if (themeColor == 1) | |
1346 | { | |
1347 | wxUxThemeEngine::Get()->GetThemeColor( | |
1348 | hTheme, | |
1349 | 10 /* TABP_BODY */, | |
1350 | 1 /* NORMAL */, | |
1351 | 3802 /* FILLCOLOR */, | |
1352 | &themeColor); | |
1353 | } | |
1354 | ||
b380533c JS |
1355 | wxColour colour = wxRGBToColour(themeColor); |
1356 | ||
1357 | // Under Vista, the tab background colour is reported incorrectly. | |
1358 | // So for the default theme at least, hard-code the colour to something | |
1359 | // that will blend in. | |
1360 | ||
1361 | static int s_AeroStatus = -1; | |
1362 | if (s_AeroStatus == -1) | |
1363 | { | |
1364 | WCHAR szwThemeFile[1024]; | |
1365 | WCHAR szwThemeColor[256]; | |
1366 | if (S_OK == wxUxThemeEngine::Get()->GetCurrentThemeName(szwThemeFile, 1024, szwThemeColor, 256, NULL, 0)) | |
1367 | { | |
1368 | wxString themeFile(szwThemeFile), themeColor(szwThemeColor); | |
1369 | if (themeFile.Find(wxT("Aero")) != -1 && themeColor == wxT("NormalColor")) | |
1370 | s_AeroStatus = 1; | |
1371 | else | |
1372 | s_AeroStatus = 0; | |
1373 | } | |
1374 | else | |
1375 | s_AeroStatus = 0; | |
1376 | } | |
1377 | ||
1378 | if (s_AeroStatus == 1) | |
1379 | colour = wxColour(255, 255, 255); | |
1380 | ||
1381 | return colour; | |
25057aba JS |
1382 | } |
1383 | } | |
1384 | #endif // wxUSE_UXTHEME | |
1385 | ||
1386 | return GetBackgroundColour(); | |
1387 | } | |
1388 | ||
88310e2e VZ |
1389 | // ---------------------------------------------------------------------------- |
1390 | // wxNotebook base class virtuals | |
1391 | // ---------------------------------------------------------------------------- | |
b5c3b538 | 1392 | |
0b481c72 VZ |
1393 | #if wxUSE_CONSTRAINTS |
1394 | ||
b5c3b538 VZ |
1395 | // override these 2 functions to do nothing: everything is done in OnSize |
1396 | ||
4b7f2165 | 1397 | void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse)) |
b5c3b538 VZ |
1398 | { |
1399 | // don't set the sizes of the pages - their correct size is not yet known | |
b8bdaa7c | 1400 | wxControl::SetConstraintSizes(false); |
b5c3b538 VZ |
1401 | } |
1402 | ||
4b7f2165 | 1403 | bool wxNotebook::DoPhase(int WXUNUSED(nPhase)) |
b5c3b538 | 1404 | { |
b8bdaa7c | 1405 | return true; |
b5c3b538 VZ |
1406 | } |
1407 | ||
0b481c72 VZ |
1408 | #endif // wxUSE_CONSTRAINTS |
1409 | ||
0df3fbd7 VZ |
1410 | // ---------------------------------------------------------------------------- |
1411 | // wxNotebook Windows message handlers | |
1412 | // ---------------------------------------------------------------------------- | |
1413 | ||
1414 | bool wxNotebook::MSWOnScroll(int orientation, WXWORD nSBCode, | |
1415 | WXWORD pos, WXHWND control) | |
1416 | { | |
1417 | // don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the | |
1418 | // up-down control | |
1419 | if ( control ) | |
b8bdaa7c | 1420 | return false; |
0df3fbd7 VZ |
1421 | |
1422 | return wxNotebookBase::MSWOnScroll(orientation, nSBCode, pos, control); | |
1423 | } | |
1424 | ||
a23fd0e1 | 1425 | bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result) |
88310e2e | 1426 | { |
3e97a905 | 1427 | wxBookCtrlEvent event(wxEVT_NULL, m_windowId); |
88310e2e VZ |
1428 | |
1429 | NMHDR* hdr = (NMHDR *)lParam; | |
1430 | switch ( hdr->code ) { | |
1431 | case TCN_SELCHANGE: | |
1432 | event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); | |
1433 | break; | |
1434 | ||
1435 | case TCN_SELCHANGING: | |
1436 | event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING); | |
1437 | break; | |
1438 | ||
fd3f686c | 1439 | default: |
a23fd0e1 | 1440 | return wxControl::MSWOnNotify(idCtrl, lParam, result); |
88310e2e VZ |
1441 | } |
1442 | ||
01c8cbf5 | 1443 | event.SetSelection(TabCtrl_GetCurSel(GetHwnd())); |
681be2ef | 1444 | event.SetOldSelection(m_selection); |
88310e2e | 1445 | event.SetEventObject(this); |
a23fd0e1 | 1446 | event.SetInt(idCtrl); |
88310e2e | 1447 | |
937013e0 | 1448 | bool processed = HandleWindowEvent(event); |
fd3f686c VZ |
1449 | *result = !event.IsAllowed(); |
1450 | return processed; | |
88310e2e VZ |
1451 | } |
1452 | ||
1e6feb95 | 1453 | #endif // wxUSE_NOTEBOOK |