]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: msw/notebook.cpp | |
3 | // Purpose: implementation of wxNotebook | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 11.06.98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "notebook.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #if wxUSE_NOTEBOOK | |
24 | ||
25 | // wxWindows | |
26 | #ifndef WX_PRECOMP | |
27 | #include "wx/string.h" | |
28 | #endif // WX_PRECOMP | |
29 | ||
30 | #include "wx/log.h" | |
31 | #include "wx/imaglist.h" | |
32 | #include "wx/event.h" | |
33 | #include "wx/control.h" | |
34 | #include "wx/notebook.h" | |
35 | #include "wx/app.h" | |
36 | ||
37 | #include "wx/msw/private.h" | |
38 | ||
39 | // Windows standard headers | |
40 | #ifndef __WIN95__ | |
41 | #error "wxNotebook is only supported Windows 95 and above" | |
42 | #endif //Win95 | |
43 | ||
44 | #include <windowsx.h> // for SetWindowFont | |
45 | ||
46 | #ifdef __GNUWIN32_OLD__ | |
47 | #include "wx/msw/gnuwin32/extra.h" | |
48 | #endif | |
49 | ||
50 | #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__)) | |
51 | #include <commctrl.h> | |
52 | #endif | |
53 | ||
54 | #include "wx/msw/winundef.h" | |
55 | ||
56 | #if wxUSE_UXTHEME | |
57 | #include "wx/msw/uxtheme.h" | |
58 | ||
59 | #include "wx/radiobut.h" | |
60 | #include "wx/radiobox.h" | |
61 | #include "wx/checkbox.h" | |
62 | #include "wx/bmpbuttn.h" | |
63 | #include "wx/statline.h" | |
64 | #include "wx/statbox.h" | |
65 | #include "wx/stattext.h" | |
66 | #include "wx/slider.h" | |
67 | #include "wx/scrolwin.h" | |
68 | #include "wx/panel.h" | |
69 | #endif | |
70 | ||
71 | // ---------------------------------------------------------------------------- | |
72 | // macros | |
73 | // ---------------------------------------------------------------------------- | |
74 | ||
75 | // check that the page index is valid | |
76 | #define IS_VALID_PAGE(nPage) (((nPage) >= 0) && ((nPage) < GetPageCount())) | |
77 | ||
78 | // hide the ugly cast | |
79 | #define m_hwnd (HWND)GetHWND() | |
80 | ||
81 | // ---------------------------------------------------------------------------- | |
82 | // constants | |
83 | // ---------------------------------------------------------------------------- | |
84 | ||
85 | // This is a work-around for missing defines in gcc-2.95 headers | |
86 | #ifndef TCS_RIGHT | |
87 | #define TCS_RIGHT 0x0002 | |
88 | #endif | |
89 | ||
90 | #ifndef TCS_VERTICAL | |
91 | #define TCS_VERTICAL 0x0080 | |
92 | #endif | |
93 | ||
94 | #ifndef TCS_BOTTOM | |
95 | #define TCS_BOTTOM TCS_RIGHT | |
96 | #endif | |
97 | ||
98 | // ---------------------------------------------------------------------------- | |
99 | // event table | |
100 | // ---------------------------------------------------------------------------- | |
101 | ||
102 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED) | |
103 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING) | |
104 | ||
105 | BEGIN_EVENT_TABLE(wxNotebook, wxControl) | |
106 | EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange) | |
107 | ||
108 | EVT_SIZE(wxNotebook::OnSize) | |
109 | ||
110 | EVT_SET_FOCUS(wxNotebook::OnSetFocus) | |
111 | ||
112 | EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) | |
113 | END_EVENT_TABLE() | |
114 | ||
115 | IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl) | |
116 | IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent) | |
117 | ||
118 | // ============================================================================ | |
119 | // implementation | |
120 | // ============================================================================ | |
121 | ||
122 | // ---------------------------------------------------------------------------- | |
123 | // wxNotebook construction | |
124 | // ---------------------------------------------------------------------------- | |
125 | ||
126 | // common part of all ctors | |
127 | void wxNotebook::Init() | |
128 | { | |
129 | m_imageList = NULL; | |
130 | m_nSelection = -1; | |
131 | } | |
132 | ||
133 | // default for dynamic class | |
134 | wxNotebook::wxNotebook() | |
135 | { | |
136 | Init(); | |
137 | } | |
138 | ||
139 | // the same arguments as for wxControl | |
140 | wxNotebook::wxNotebook(wxWindow *parent, | |
141 | wxWindowID id, | |
142 | const wxPoint& pos, | |
143 | const wxSize& size, | |
144 | long style, | |
145 | const wxString& name) | |
146 | { | |
147 | Init(); | |
148 | ||
149 | Create(parent, id, pos, size, style, name); | |
150 | } | |
151 | ||
152 | // Create() function | |
153 | bool wxNotebook::Create(wxWindow *parent, | |
154 | wxWindowID id, | |
155 | const wxPoint& pos, | |
156 | const wxSize& size, | |
157 | long style, | |
158 | const wxString& name) | |
159 | { | |
160 | // Does ComCtl32 support non-top tabs? | |
161 | int verComCtl32 = wxApp::GetComCtl32Version(); | |
162 | if ( verComCtl32 < 470 || verComCtl32 >= 600 ) | |
163 | { | |
164 | if (style & wxNB_BOTTOM) | |
165 | style &= ~wxNB_BOTTOM; | |
166 | ||
167 | if (style & wxNB_LEFT) | |
168 | style &= ~wxNB_LEFT; | |
169 | ||
170 | if (style & wxNB_RIGHT) | |
171 | style &= ~wxNB_RIGHT; | |
172 | } | |
173 | ||
174 | if ( !CreateControl(parent, id, pos, size, style | wxTAB_TRAVERSAL, | |
175 | wxDefaultValidator, name) ) | |
176 | return FALSE; | |
177 | ||
178 | if ( !MSWCreateControl(WC_TABCONTROL, _T(""), pos, size) ) | |
179 | return FALSE; | |
180 | ||
181 | SetBackgroundColour(wxColour(::GetSysColor(COLOR_BTNFACE))); | |
182 | ||
183 | return TRUE; | |
184 | } | |
185 | ||
186 | WXDWORD wxNotebook::MSWGetStyle(long style, WXDWORD *exstyle) const | |
187 | { | |
188 | WXDWORD tabStyle = wxControl::MSWGetStyle(style, exstyle); | |
189 | ||
190 | tabStyle |= WS_TABSTOP | TCS_TABS; | |
191 | ||
192 | if ( style & wxNB_MULTILINE ) | |
193 | tabStyle |= TCS_MULTILINE; | |
194 | if ( style & wxNB_FIXEDWIDTH ) | |
195 | tabStyle |= TCS_FIXEDWIDTH; | |
196 | ||
197 | if ( style & wxNB_BOTTOM ) | |
198 | tabStyle |= TCS_RIGHT; | |
199 | else if ( style & wxNB_LEFT ) | |
200 | tabStyle |= TCS_VERTICAL; | |
201 | else if ( style & wxNB_RIGHT ) | |
202 | tabStyle |= TCS_VERTICAL | TCS_RIGHT; | |
203 | ||
204 | // ex style | |
205 | if ( exstyle ) | |
206 | { | |
207 | // note that we never want to have the default WS_EX_CLIENTEDGE style | |
208 | // as it looks too ugly for the notebooks | |
209 | *exstyle = 0; | |
210 | } | |
211 | ||
212 | return tabStyle; | |
213 | } | |
214 | ||
215 | // ---------------------------------------------------------------------------- | |
216 | // wxNotebook accessors | |
217 | // ---------------------------------------------------------------------------- | |
218 | ||
219 | int wxNotebook::GetPageCount() const | |
220 | { | |
221 | // consistency check | |
222 | wxASSERT( (int)m_pages.Count() == TabCtrl_GetItemCount(m_hwnd) ); | |
223 | ||
224 | return m_pages.Count(); | |
225 | } | |
226 | ||
227 | int wxNotebook::GetRowCount() const | |
228 | { | |
229 | return TabCtrl_GetRowCount(m_hwnd); | |
230 | } | |
231 | ||
232 | int wxNotebook::SetSelection(int nPage) | |
233 | { | |
234 | wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") ); | |
235 | ||
236 | if ( nPage != m_nSelection ) | |
237 | { | |
238 | wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId); | |
239 | event.SetSelection(nPage); | |
240 | event.SetOldSelection(m_nSelection); | |
241 | event.SetEventObject(this); | |
242 | if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() ) | |
243 | { | |
244 | // program allows the page change | |
245 | event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); | |
246 | (void)GetEventHandler()->ProcessEvent(event); | |
247 | ||
248 | TabCtrl_SetCurSel(m_hwnd, nPage); | |
249 | } | |
250 | } | |
251 | ||
252 | return m_nSelection; | |
253 | } | |
254 | ||
255 | bool wxNotebook::SetPageText(int nPage, const wxString& strText) | |
256 | { | |
257 | wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") ); | |
258 | ||
259 | TC_ITEM tcItem; | |
260 | tcItem.mask = TCIF_TEXT; | |
261 | tcItem.pszText = (wxChar *)strText.c_str(); | |
262 | ||
263 | return TabCtrl_SetItem(m_hwnd, nPage, &tcItem) != 0; | |
264 | } | |
265 | ||
266 | wxString wxNotebook::GetPageText(int nPage) const | |
267 | { | |
268 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxT(""), wxT("notebook page out of range") ); | |
269 | ||
270 | wxChar buf[256]; | |
271 | TC_ITEM tcItem; | |
272 | tcItem.mask = TCIF_TEXT; | |
273 | tcItem.pszText = buf; | |
274 | tcItem.cchTextMax = WXSIZEOF(buf); | |
275 | ||
276 | wxString str; | |
277 | if ( TabCtrl_GetItem(m_hwnd, nPage, &tcItem) ) | |
278 | str = tcItem.pszText; | |
279 | ||
280 | return str; | |
281 | } | |
282 | ||
283 | int wxNotebook::GetPageImage(int nPage) const | |
284 | { | |
285 | wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") ); | |
286 | ||
287 | TC_ITEM tcItem; | |
288 | tcItem.mask = TCIF_IMAGE; | |
289 | ||
290 | return TabCtrl_GetItem(m_hwnd, nPage, &tcItem) ? tcItem.iImage : -1; | |
291 | } | |
292 | ||
293 | bool wxNotebook::SetPageImage(int nPage, int nImage) | |
294 | { | |
295 | wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") ); | |
296 | ||
297 | TC_ITEM tcItem; | |
298 | tcItem.mask = TCIF_IMAGE; | |
299 | tcItem.iImage = nImage; | |
300 | ||
301 | return TabCtrl_SetItem(m_hwnd, nPage, &tcItem) != 0; | |
302 | } | |
303 | ||
304 | void wxNotebook::SetImageList(wxImageList* imageList) | |
305 | { | |
306 | wxNotebookBase::SetImageList(imageList); | |
307 | ||
308 | if ( imageList ) | |
309 | { | |
310 | TabCtrl_SetImageList(m_hwnd, (HIMAGELIST)imageList->GetHIMAGELIST()); | |
311 | } | |
312 | } | |
313 | ||
314 | // ---------------------------------------------------------------------------- | |
315 | // wxNotebook size settings | |
316 | // ---------------------------------------------------------------------------- | |
317 | ||
318 | void wxNotebook::SetPageSize(const wxSize& size) | |
319 | { | |
320 | // transform the page size into the notebook size | |
321 | RECT rc; | |
322 | rc.left = | |
323 | rc.top = 0; | |
324 | rc.right = size.x; | |
325 | rc.bottom = size.y; | |
326 | ||
327 | TabCtrl_AdjustRect(GetHwnd(), TRUE, &rc); | |
328 | ||
329 | // and now set it | |
330 | SetSize(rc.right - rc.left, rc.bottom - rc.top); | |
331 | } | |
332 | ||
333 | void wxNotebook::SetPadding(const wxSize& padding) | |
334 | { | |
335 | TabCtrl_SetPadding(GetHwnd(), padding.x, padding.y); | |
336 | } | |
337 | ||
338 | // Windows-only at present. Also, you must use the wxNB_FIXEDWIDTH | |
339 | // style. | |
340 | void wxNotebook::SetTabSize(const wxSize& sz) | |
341 | { | |
342 | ::SendMessage(GetHwnd(), TCM_SETITEMSIZE, 0, MAKELPARAM(sz.x, sz.y)); | |
343 | } | |
344 | ||
345 | wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const | |
346 | { | |
347 | wxSize sizeTotal = sizePage; | |
348 | ||
349 | // We need to make getting tab size part of the wxWindows API. | |
350 | wxSize tabSize(0, 0); | |
351 | if (GetPageCount() > 0) | |
352 | { | |
353 | RECT rect; | |
354 | TabCtrl_GetItemRect((HWND) GetHWND(), 0, & rect); | |
355 | tabSize.x = rect.right - rect.left; | |
356 | tabSize.y = rect.bottom - rect.top; | |
357 | } | |
358 | if ( HasFlag(wxNB_LEFT) || HasFlag(wxNB_RIGHT) ) | |
359 | { | |
360 | sizeTotal.x += tabSize.x + 7; | |
361 | sizeTotal.y += 7; | |
362 | } | |
363 | else | |
364 | { | |
365 | sizeTotal.x += 7; | |
366 | sizeTotal.y += tabSize.y + 7; | |
367 | } | |
368 | ||
369 | return sizeTotal; | |
370 | } | |
371 | ||
372 | void wxNotebook::AdjustPageSize(wxNotebookPage *page) | |
373 | { | |
374 | wxCHECK_RET( page, _T("NULL page in wxNotebook::AdjustPageSize") ); | |
375 | ||
376 | RECT rc; | |
377 | rc.left = | |
378 | rc.top = 0; | |
379 | ||
380 | // get the page size from the notebook size | |
381 | GetSize((int *)&rc.right, (int *)&rc.bottom); | |
382 | TabCtrl_AdjustRect(m_hwnd, FALSE, &rc); | |
383 | ||
384 | page->SetSize(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); | |
385 | } | |
386 | ||
387 | // ---------------------------------------------------------------------------- | |
388 | // wxNotebook operations | |
389 | // ---------------------------------------------------------------------------- | |
390 | ||
391 | // remove one page from the notebook, without deleting | |
392 | wxNotebookPage *wxNotebook::DoRemovePage(int nPage) | |
393 | { | |
394 | wxNotebookPage *pageRemoved = wxNotebookBase::DoRemovePage(nPage); | |
395 | if ( !pageRemoved ) | |
396 | return NULL; | |
397 | ||
398 | TabCtrl_DeleteItem(m_hwnd, nPage); | |
399 | ||
400 | if ( m_pages.IsEmpty() ) | |
401 | { | |
402 | // no selection any more, the notebook becamse empty | |
403 | m_nSelection = -1; | |
404 | } | |
405 | else // notebook still not empty | |
406 | { | |
407 | // change the selected page if it was deleted or became invalid | |
408 | int selNew; | |
409 | if ( m_nSelection == GetPageCount() ) | |
410 | { | |
411 | // last page deleted, make the new last page the new selection | |
412 | selNew = m_nSelection - 1; | |
413 | } | |
414 | else if ( nPage <= m_nSelection ) | |
415 | { | |
416 | // we must show another page, even if it has the same index | |
417 | selNew = m_nSelection; | |
418 | } | |
419 | else // nothing changes for the currently selected page | |
420 | { | |
421 | selNew = -1; | |
422 | ||
423 | // we still must refresh the current page: this needs to be done | |
424 | // for some unknown reason if the tab control shows the up-down | |
425 | // control (i.e. when there are too many pages) -- otherwise after | |
426 | // deleting a page nothing at all is shown | |
427 | m_pages[m_nSelection]->Refresh(); | |
428 | } | |
429 | ||
430 | if ( selNew != -1 ) | |
431 | { | |
432 | // m_nSelection must be always valid so reset it before calling | |
433 | // SetSelection() | |
434 | m_nSelection = -1; | |
435 | SetSelection(selNew); | |
436 | } | |
437 | } | |
438 | ||
439 | return pageRemoved; | |
440 | } | |
441 | ||
442 | // remove all pages | |
443 | bool wxNotebook::DeleteAllPages() | |
444 | { | |
445 | int nPageCount = GetPageCount(); | |
446 | int nPage; | |
447 | for ( nPage = 0; nPage < nPageCount; nPage++ ) | |
448 | delete m_pages[nPage]; | |
449 | ||
450 | m_pages.Clear(); | |
451 | ||
452 | TabCtrl_DeleteAllItems(m_hwnd); | |
453 | ||
454 | m_nSelection = -1; | |
455 | ||
456 | return TRUE; | |
457 | } | |
458 | ||
459 | // same as AddPage() but does it at given position | |
460 | bool wxNotebook::InsertPage(int nPage, | |
461 | wxNotebookPage *pPage, | |
462 | const wxString& strText, | |
463 | bool bSelect, | |
464 | int imageId) | |
465 | { | |
466 | wxCHECK_MSG( pPage != NULL, FALSE, _T("NULL page in wxNotebook::InsertPage") ); | |
467 | wxCHECK_MSG( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), FALSE, | |
468 | _T("invalid index in wxNotebook::InsertPage") ); | |
469 | ||
470 | wxASSERT_MSG( pPage->GetParent() == this, | |
471 | _T("notebook pages must have notebook as parent") ); | |
472 | ||
473 | #if wxUSE_UXTHEME && wxUSE_UXTHEME_AUTO | |
474 | // Automatically apply the theme background, | |
475 | // changing the colour of the panel to match the | |
476 | // tab page colour. This won't work well with all | |
477 | // themes but it's a start. | |
478 | if (wxUxThemeEngine::Get() && pPage->IsKindOf(CLASSINFO(wxPanel))) | |
479 | { | |
480 | ApplyThemeBackground(pPage, GetThemeBackgroundColour()); | |
481 | } | |
482 | #endif | |
483 | ||
484 | // add a new tab to the control | |
485 | // ---------------------------- | |
486 | ||
487 | // init all fields to 0 | |
488 | TC_ITEM tcItem; | |
489 | wxZeroMemory(tcItem); | |
490 | ||
491 | // set the image, if any | |
492 | if ( imageId != -1 ) | |
493 | { | |
494 | tcItem.mask |= TCIF_IMAGE; | |
495 | tcItem.iImage = imageId; | |
496 | } | |
497 | ||
498 | // and the text | |
499 | if ( !strText.IsEmpty() ) | |
500 | { | |
501 | tcItem.mask |= TCIF_TEXT; | |
502 | tcItem.pszText = (wxChar *)strText.c_str(); // const_cast | |
503 | } | |
504 | ||
505 | // fit the notebook page to the tab control's display area: this should be | |
506 | // done before adding it to the notebook or TabCtrl_InsertItem() will | |
507 | // change the notebooks size itself! | |
508 | AdjustPageSize(pPage); | |
509 | ||
510 | // finally do insert it | |
511 | if ( TabCtrl_InsertItem(m_hwnd, nPage, &tcItem) == -1 ) | |
512 | { | |
513 | wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str()); | |
514 | ||
515 | return FALSE; | |
516 | } | |
517 | ||
518 | // succeeded: save the pointer to the page | |
519 | m_pages.Insert(pPage, nPage); | |
520 | ||
521 | // for the first page (only) we need to adjust the size again because the | |
522 | // notebook size changed: the tabs which hadn't been there before are now | |
523 | // shown | |
524 | if ( m_pages.GetCount() == 1 ) | |
525 | { | |
526 | AdjustPageSize(pPage); | |
527 | } | |
528 | ||
529 | // hide the page: unless it is selected, it shouldn't be shown (and if it | |
530 | // is selected it will be shown later) | |
531 | HWND hwnd = GetWinHwnd(pPage); | |
532 | SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE); | |
533 | ||
534 | // this updates internal flag too -- otherwise it would get out of sync | |
535 | // with the real state | |
536 | pPage->Show(FALSE); | |
537 | ||
538 | ||
539 | // now deal with the selection | |
540 | // --------------------------- | |
541 | ||
542 | // if the inserted page is before the selected one, we must update the | |
543 | // index of the selected page | |
544 | if ( nPage <= m_nSelection ) | |
545 | { | |
546 | // one extra page added | |
547 | m_nSelection++; | |
548 | } | |
549 | ||
550 | // some page should be selected: either this one or the first one if there | |
551 | // is still no selection | |
552 | int selNew = -1; | |
553 | if ( bSelect ) | |
554 | selNew = nPage; | |
555 | else if ( m_nSelection == -1 ) | |
556 | selNew = 0; | |
557 | ||
558 | if ( selNew != -1 ) | |
559 | SetSelection(selNew); | |
560 | ||
561 | return TRUE; | |
562 | } | |
563 | ||
564 | // Hit test | |
565 | int wxNotebook::HitTest(const wxPoint& pt, long& flags) | |
566 | { | |
567 | TC_HITTESTINFO hitTestInfo; | |
568 | hitTestInfo.pt.x = pt.x; | |
569 | hitTestInfo.pt.y = pt.y; | |
570 | int item = TabCtrl_HitTest( (HWND) GetHWND(), & hitTestInfo ) ; | |
571 | flags = 0; | |
572 | ||
573 | if ((hitTestInfo.flags & TCHT_NOWHERE) == TCHT_NOWHERE) | |
574 | flags |= wxNB_HITTEST_NOWHERE; | |
575 | if ((hitTestInfo.flags & TCHT_ONITEMICON) == TCHT_ONITEMICON) | |
576 | flags |= wxNB_HITTEST_ONICON; | |
577 | if ((hitTestInfo.flags & TCHT_ONITEMLABEL) == TCHT_ONITEMLABEL) | |
578 | flags |= wxNB_HITTEST_ONLABEL; | |
579 | ||
580 | return item; | |
581 | } | |
582 | ||
583 | // ---------------------------------------------------------------------------- | |
584 | // wxNotebook callbacks | |
585 | // ---------------------------------------------------------------------------- | |
586 | ||
587 | void wxNotebook::OnSize(wxSizeEvent& event) | |
588 | { | |
589 | // fit the notebook page to the tab control's display area | |
590 | RECT rc; | |
591 | rc.left = rc.top = 0; | |
592 | GetSize((int *)&rc.right, (int *)&rc.bottom); | |
593 | ||
594 | TabCtrl_AdjustRect(m_hwnd, FALSE, &rc); | |
595 | ||
596 | int width = rc.right - rc.left, | |
597 | height = rc.bottom - rc.top; | |
598 | size_t nCount = m_pages.Count(); | |
599 | for ( size_t nPage = 0; nPage < nCount; nPage++ ) { | |
600 | wxNotebookPage *pPage = m_pages[nPage]; | |
601 | pPage->SetSize(rc.left, rc.top, width, height); | |
602 | } | |
603 | ||
604 | event.Skip(); | |
605 | } | |
606 | ||
607 | void wxNotebook::OnSelChange(wxNotebookEvent& event) | |
608 | { | |
609 | // is it our tab control? | |
610 | if ( event.GetEventObject() == this ) | |
611 | { | |
612 | int sel = event.GetOldSelection(); | |
613 | if ( sel != -1 ) | |
614 | m_pages[sel]->Show(FALSE); | |
615 | ||
616 | sel = event.GetSelection(); | |
617 | if ( sel != -1 ) | |
618 | { | |
619 | wxNotebookPage *pPage = m_pages[sel]; | |
620 | pPage->Show(TRUE); | |
621 | pPage->SetFocus(); | |
622 | } | |
623 | ||
624 | m_nSelection = sel; | |
625 | } | |
626 | ||
627 | // we want to give others a chance to process this message as well | |
628 | event.Skip(); | |
629 | } | |
630 | ||
631 | void wxNotebook::OnSetFocus(wxFocusEvent& event) | |
632 | { | |
633 | // this function is only called when the focus is explicitly set (i.e. from | |
634 | // the program) to the notebook - in this case we don't need the | |
635 | // complicated OnNavigationKey() logic because the programmer knows better | |
636 | // what [s]he wants | |
637 | ||
638 | // set focus to the currently selected page if any | |
639 | if ( m_nSelection != -1 ) | |
640 | m_pages[m_nSelection]->SetFocus(); | |
641 | ||
642 | event.Skip(); | |
643 | } | |
644 | ||
645 | void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) | |
646 | { | |
647 | if ( event.IsWindowChange() ) { | |
648 | // change pages | |
649 | AdvanceSelection(event.GetDirection()); | |
650 | } | |
651 | else { | |
652 | // we get this event in 2 cases | |
653 | // | |
654 | // a) one of our pages might have generated it because the user TABbed | |
655 | // out from it in which case we should propagate the event upwards and | |
656 | // our parent will take care of setting the focus to prev/next sibling | |
657 | // | |
658 | // or | |
659 | // | |
660 | // b) the parent panel wants to give the focus to us so that we | |
661 | // forward it to our selected page. We can't deal with this in | |
662 | // OnSetFocus() because we don't know which direction the focus came | |
663 | // from in this case and so can't choose between setting the focus to | |
664 | // first or last panel child | |
665 | ||
666 | wxWindow *parent = GetParent(); | |
667 | if ( event.GetEventObject() == parent ) | |
668 | { | |
669 | // no, it doesn't come from child, case (b): forward to a page | |
670 | if ( m_nSelection != -1 ) | |
671 | { | |
672 | // so that the page knows that the event comes from it's parent | |
673 | // and is being propagated downwards | |
674 | event.SetEventObject(this); | |
675 | ||
676 | wxWindow *page = m_pages[m_nSelection]; | |
677 | if ( !page->GetEventHandler()->ProcessEvent(event) ) | |
678 | { | |
679 | page->SetFocus(); | |
680 | } | |
681 | //else: page manages focus inside it itself | |
682 | } | |
683 | else | |
684 | { | |
685 | // we have no pages - still have to give focus to _something_ | |
686 | SetFocus(); | |
687 | } | |
688 | } | |
689 | else | |
690 | { | |
691 | // it comes from our child, case (a), pass to the parent | |
692 | if ( parent ) { | |
693 | event.SetCurrentFocus(this); | |
694 | parent->GetEventHandler()->ProcessEvent(event); | |
695 | } | |
696 | } | |
697 | } | |
698 | } | |
699 | ||
700 | // ---------------------------------------------------------------------------- | |
701 | // wxNotebook base class virtuals | |
702 | // ---------------------------------------------------------------------------- | |
703 | ||
704 | #if wxUSE_CONSTRAINTS | |
705 | ||
706 | // override these 2 functions to do nothing: everything is done in OnSize | |
707 | ||
708 | void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse)) | |
709 | { | |
710 | // don't set the sizes of the pages - their correct size is not yet known | |
711 | wxControl::SetConstraintSizes(FALSE); | |
712 | } | |
713 | ||
714 | bool wxNotebook::DoPhase(int WXUNUSED(nPhase)) | |
715 | { | |
716 | return TRUE; | |
717 | } | |
718 | ||
719 | #endif // wxUSE_CONSTRAINTS | |
720 | ||
721 | // ---------------------------------------------------------------------------- | |
722 | // wxNotebook Windows message handlers | |
723 | // ---------------------------------------------------------------------------- | |
724 | ||
725 | bool wxNotebook::MSWOnScroll(int orientation, WXWORD nSBCode, | |
726 | WXWORD pos, WXHWND control) | |
727 | { | |
728 | // don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the | |
729 | // up-down control | |
730 | if ( control ) | |
731 | return FALSE; | |
732 | ||
733 | return wxNotebookBase::MSWOnScroll(orientation, nSBCode, pos, control); | |
734 | } | |
735 | ||
736 | bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result) | |
737 | { | |
738 | wxNotebookEvent event(wxEVT_NULL, m_windowId); | |
739 | ||
740 | NMHDR* hdr = (NMHDR *)lParam; | |
741 | switch ( hdr->code ) { | |
742 | case TCN_SELCHANGE: | |
743 | event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); | |
744 | break; | |
745 | ||
746 | case TCN_SELCHANGING: | |
747 | event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING); | |
748 | break; | |
749 | ||
750 | default: | |
751 | return wxControl::MSWOnNotify(idCtrl, lParam, result); | |
752 | } | |
753 | ||
754 | event.SetSelection(TabCtrl_GetCurSel(m_hwnd)); | |
755 | event.SetOldSelection(m_nSelection); | |
756 | event.SetEventObject(this); | |
757 | event.SetInt(idCtrl); | |
758 | ||
759 | bool processed = GetEventHandler()->ProcessEvent(event); | |
760 | *result = !event.IsAllowed(); | |
761 | return processed; | |
762 | } | |
763 | ||
764 | // Windows only: attempts to get colour for UX theme page background | |
765 | wxColour wxNotebook::GetThemeBackgroundColour() | |
766 | { | |
767 | #if wxUSE_UXTHEME | |
768 | if (wxUxThemeEngine::Get()) | |
769 | { | |
770 | WXHTHEME hTheme = wxUxThemeEngine::Get()->m_pfnOpenThemeData(GetHWND(), L"TAB"); | |
771 | if (hTheme) | |
772 | { | |
773 | // This is total guesswork. | |
774 | // See PlatformSDK\Include\Tmschema.h for values | |
775 | COLORREF themeColor; | |
776 | wxUxThemeEngine::Get()-> | |
777 | m_pfnGetThemeColor(hTheme, | |
778 | 10 /* TABP_BODY */, | |
779 | 1 /* NORMAL */, | |
780 | 3821, /* FILLCOLORHINT */ | |
781 | & themeColor); | |
782 | ||
783 | wxUxThemeEngine::Get()->m_pfnCloseThemeData(hTheme); | |
784 | ||
785 | wxColour colour(GetRValue(themeColor), GetGValue(themeColor), GetBValue(themeColor)); | |
786 | return colour; | |
787 | } | |
788 | } | |
789 | #endif | |
790 | return GetBackgroundColour(); | |
791 | } | |
792 | ||
793 | // Windows only: attempts to apply the UX theme page background to this page | |
794 | void wxNotebook::ApplyThemeBackground(wxWindow* window, const wxColour& colour) | |
795 | { | |
796 | #if wxUSE_UXTHEME | |
797 | // Don't set the background for buttons since this will | |
798 | // switch it into ownerdraw mode | |
799 | if (window->IsKindOf(CLASSINFO(wxButton)) && !window->IsKindOf(CLASSINFO(wxBitmapButton))) | |
800 | // This is essential, otherwise you'll see dark grey | |
801 | // corners in the buttons. | |
802 | ((wxButton*)window)->wxControl::SetBackgroundColour(colour); | |
803 | else if (window->IsKindOf(CLASSINFO(wxStaticText)) || | |
804 | window->IsKindOf(CLASSINFO(wxStaticBox)) || | |
805 | window->IsKindOf(CLASSINFO(wxStaticLine)) || | |
806 | window->IsKindOf(CLASSINFO(wxRadioButton)) || | |
807 | window->IsKindOf(CLASSINFO(wxRadioBox)) || | |
808 | window->IsKindOf(CLASSINFO(wxCheckBox)) || | |
809 | window->IsKindOf(CLASSINFO(wxBitmapButton)) || | |
810 | window->IsKindOf(CLASSINFO(wxSlider)) || | |
811 | window->IsKindOf(CLASSINFO(wxPanel)) || | |
812 | (window->IsKindOf(CLASSINFO(wxNotebook)) && (window != this)) || | |
813 | window->IsKindOf(CLASSINFO(wxScrolledWindow)) | |
814 | ) | |
815 | { | |
816 | window->SetBackgroundColour(colour); | |
817 | } | |
818 | ||
819 | for ( wxWindowList::Node *node = window->GetChildren().GetFirst(); node; node = node->GetNext() ) | |
820 | { | |
821 | wxWindow *child = node->GetData(); | |
822 | ApplyThemeBackground(child, colour); | |
823 | } | |
824 | #endif | |
825 | } | |
826 | ||
827 | #endif // wxUSE_NOTEBOOK |