Notebook, Listbox, and Checklst updates
[wxWidgets.git] / src / os2 / notebook.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: notebook.cpp
3 // Purpose: implementation of wxNotebook
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/12/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #if wxUSE_NOTEBOOK
16
17 // wxWindows
18 #ifndef WX_PRECOMP
19 #include "wx/string.h"
20 #endif // WX_PRECOMP
21
22 #include "wx/log.h"
23 #include "wx/imaglist.h"
24 #include "wx/event.h"
25 #include "wx/control.h"
26 #include "wx/notebook.h"
27
28 #include "wx/os2/private.h"
29
30 // ----------------------------------------------------------------------------
31 // macros
32 // ----------------------------------------------------------------------------
33
34 // check that the page index is valid
35 #define IS_VALID_PAGE(nPage) (((nPage) >= 0) && ((nPage) < GetPageCount()))
36
37 // hide the ugly cast
38 #define m_hWnd (HWND)GetHWND()
39
40 // ----------------------------------------------------------------------------
41 // constants
42 // ----------------------------------------------------------------------------
43
44 // ----------------------------------------------------------------------------
45 // event table
46 // ----------------------------------------------------------------------------
47
48 DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
49 DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
50
51 BEGIN_EVENT_TABLE(wxNotebook, wxControl)
52 EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange)
53 EVT_SIZE(wxNotebook::OnSize)
54 EVT_SET_FOCUS(wxNotebook::OnSetFocus)
55 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
56 END_EVENT_TABLE()
57
58 IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl)
59 IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent)
60
61 // ============================================================================
62 // implementation
63 // ============================================================================
64
65 // ----------------------------------------------------------------------------
66 // wxNotebook construction
67 // ----------------------------------------------------------------------------
68
69 //
70 // Common part of all ctors
71 //
72 void wxNotebook::Init()
73 {
74 m_imageList = NULL;
75 m_nSelection = -1;
76 m_nTabSize = 0;
77 } // end of wxNotebook::Init
78
79 //
80 // Default for dynamic class
81 //
82 wxNotebook::wxNotebook()
83 {
84 Init();
85 } // end of wxNotebook::wxNotebook
86
87 //
88 // The same arguments as for wxControl
89 //
90 wxNotebook::wxNotebook(
91 wxWindow* pParent
92 , wxWindowID vId
93 , const wxPoint& rPos
94 , const wxSize& rSize
95 , long lStyle
96 , const wxString& rsName
97 )
98 {
99 Init();
100 Create( pParent
101 ,vId
102 ,rPos
103 ,rSize
104 ,lStyle
105 ,rsName
106 );
107 } // end of wxNotebook::wxNotebook
108
109 //
110 // Create() function
111 //
112 bool wxNotebook::Create(
113 wxWindow* pParent
114 , wxWindowID vId
115 , const wxPoint& rPos
116 , const wxSize& rSize
117 , long lStyle
118 , const wxString& rsName
119 )
120 {
121 //
122 // Base init
123 //
124 if (!CreateControl( pParent
125 ,vId
126 ,rPos
127 ,rSize
128 ,lStyle
129 ,wxDefaultValidator
130 ,rsName
131 ))
132 return FALSE;
133
134 //
135 // Notebook, so explicitly specify 0 as last parameter
136 //
137 if (!OS2CreateControl( "NOTEBOOK"
138 ,_T("")
139 ,rPos
140 ,rSize
141 ,lStyle | wxTAB_TRAVERSAL
142 ))
143 return FALSE;
144
145 SetBackgroundColour(wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)));
146 return TRUE;
147 } // end of wxNotebook::Create
148
149 WXDWORD wxNotebook::OS2GetStyle (
150 long lStyle
151 , WXDWORD* pdwExstyle
152 ) const
153 {
154 WXDWORD dwTabStyle = wxControl::OS2GetStyle( lStyle
155 ,pdwExstyle
156 );
157
158 dwTabStyle |= WS_TABSTOP | BKS_SOLIDBIND | BKS_ROUNDEDTABS | BKS_TABTEXTCENTER;
159
160 if (lStyle & wxNB_BOTTOM)
161 dwTabStyle |= BKS_MAJORTABBOTTOM | BKS_BACKPAGESBL;
162 else if (lStyle & wxNB_RIGHT)
163 dwTabStyle |= BKS_MAJORTABRIGHT | BKS_BACKPAGESBR;
164 else if (lStyle & wxNB_LEFT)
165 dwTabStyle |= BKS_MAJORTABLEFT | BKS_BACKPAGESTL;
166 else // default to top
167 dwTabStyle |= BKS_MAJORTABTOP | BKS_BACKPAGESTR;
168
169 //
170 // Ex style
171 //
172 if (pdwExstyle )
173 {
174 //
175 // Note that we never want to have the default WS_EX_CLIENTEDGE style
176 // as it looks too ugly for the notebooks
177 //
178 *pdwExstyle = 0;
179 }
180 return dwTabStyle;
181 } // end of wxNotebook::OS2GetStyle
182
183 // ----------------------------------------------------------------------------
184 // wxNotebook accessors
185 // ----------------------------------------------------------------------------
186
187 int wxNotebook::GetPageCount() const
188 {
189 int nPageInternal = m_pages.Count();
190 int nPageAPI = (int)::WinSendMsg(GetHWND(), BKM_QUERYPAGECOUNT, (MPARAM)0, (MPARAM)BKA_END);
191
192 //
193 // Consistency check
194 //
195 wxASSERT((int)m_pages.Count() == (int)::WinSendMsg(GetHWND(), BKM_QUERYPAGECOUNT, (MPARAM)0, (MPARAM)BKA_END));
196 return m_pages.Count();
197 } // end of wxNotebook::GetPageCount
198
199 int wxNotebook::GetRowCount() const
200 {
201 return (int)::WinSendMsg( GetHWND()
202 ,BKM_QUERYPAGECOUNT
203 ,(MPARAM)0
204 ,(MPARAM)BKA_MAJOR
205 );
206 } // end of wxNotebook::GetRowCount
207
208 int wxNotebook::SetSelection(
209 int nPage
210 )
211 {
212 wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") );
213 int nOldPage = GetSelection();
214
215 ChangePage( m_nSelection
216 ,nPage
217 );
218
219 ULONG ulPageId = (ULONG)m_alPageId[nPage];
220
221 ::WinSendMsg( GetHWND()
222 ,BKM_TURNTOPAGE
223 ,MPFROMLONG((ULONG)m_alPageId[nPage])
224 ,(MPARAM)0
225 );
226 m_nSelection = nPage;
227 return nPage;
228 } // end of wxNotebook::SetSelection
229
230 bool wxNotebook::SetPageText(
231 int nPage
232 , const wxString& rsStrText
233 )
234 {
235 wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") );
236
237
238 ULONG ulPageId = (ULONG)m_alPageId[nPage];
239
240 return (bool)::WinSendMsg( m_hWnd
241 ,BKM_SETTABTEXT
242 ,MPFROMLONG((ULONG)m_alPageId[nPage])
243 ,MPFROMP((PSZ)rsStrText.c_str())
244 );
245 } // end of wxNotebook::SetPageText
246
247 wxString wxNotebook::GetPageText (
248 int nPage
249 ) const
250 {
251 BOOKTEXT vBookText;
252 wxChar zBuf[256];
253 wxString sStr;
254 ULONG ulRc;
255
256 wxCHECK_MSG( IS_VALID_PAGE(nPage), wxT(""), wxT("notebook page out of range") );
257
258
259 ULONG ulPageId = (ULONG)m_alPageId[nPage];
260
261 memset(&vBookText, '\0', sizeof(BOOKTEXT));
262 vBookText.textLen = 0; // This will get the length
263 ulRc = LONGFROMMR(::WinSendMsg( m_hWnd
264 ,BKM_QUERYTABTEXT
265 ,MPFROMLONG((ULONG)m_alPageId[nPage])
266 ,MPFROMP(&vBookText)
267 ));
268 if (ulRc == BOOKERR_INVALID_PARAMETERS || ulRc == 0L)
269 {
270 if (ulRc == BOOKERR_INVALID_PARAMETERS)
271 {
272 wxLogError(wxT("Invalid Page Id for page text querry."));
273 }
274 return wxEmptyString;
275 }
276 vBookText.textLen = ulRc + 1; // To get the null terminator
277 vBookText.pString = zBuf;
278
279 //
280 // Now get the actual text
281 //
282 ulRc = LONGFROMMR(::WinSendMsg( m_hWnd
283 ,BKM_QUERYTABTEXT
284 ,MPFROMLONG((ULONG)m_alPageId[nPage])
285 ,MPFROMP(&vBookText)
286 ));
287 if (ulRc == BOOKERR_INVALID_PARAMETERS || ulRc == 0L)
288 {
289 return wxEmptyString;
290 }
291 if (ulRc > 255L)
292 ulRc = 255L;
293
294 vBookText.pString[ulRc] = '\0';
295 sStr = vBookText.pString;
296 return sStr;
297 } // end of wxNotebook::GetPageText
298
299 int wxNotebook::GetPageImage (
300 int nPage
301 ) const
302 {
303 wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") );
304
305 //
306 // For OS/2 just return the page
307 //
308 return nPage;
309 } // end of wxNotebook::GetPageImage
310
311 bool wxNotebook::SetPageImage (
312 int nPage
313 , int nImage
314 )
315 {
316 wxBitmap* pBitmap = (wxBitmap*)m_imageList->GetBitmap(nImage);
317
318
319 ULONG ulPageId = (ULONG)m_alPageId[nPage];
320
321 return (bool)::WinSendMsg( GetHWND()
322 ,BKM_SETTABBITMAP
323 ,MPFROMLONG((ULONG)m_alPageId[nPage])
324 ,(MPARAM)pBitmap->GetHBITMAP()
325 );
326 } // end of wxNotebook::SetPageImage
327
328 void wxNotebook::SetImageList (
329 wxImageList* WXUNUSED(pImageList)
330 )
331 {
332 //
333 // Does nothing under OS/2
334 //
335 } // end of wxNotebook::SetImageList
336
337 // ----------------------------------------------------------------------------
338 // wxNotebook size settings
339 // ----------------------------------------------------------------------------
340 void wxNotebook::SetPageSize (
341 const wxSize& rSize
342 )
343 {
344 RECTL vRect;
345
346 //
347 // Transform the page size into the notebook size
348 //
349 vRect.xLeft = vRect.yTop = 0;
350 vRect.xRight = rSize.x;
351 vRect.yBottom = rSize.y;
352
353
354 //
355 // And now set it
356 //
357 SetSize( vRect.xRight - vRect.xLeft
358 ,vRect.yBottom - vRect.yTop
359 );
360 } // end of wxNotebook::SetPageSize
361
362 void wxNotebook::SetPadding (
363 const wxSize& WXUNUSED(rPadding)
364 )
365 {
366 //
367 // No padding in OS/2
368 //
369 } // end of wxNotebook::SetPadding
370
371 void wxNotebook::SetTabSize (
372 const wxSize& rSize
373 )
374 {
375 ::WinSendMsg( GetHWND()
376 ,BKM_SETDIMENSIONS
377 ,MPFROM2SHORT( (USHORT)rSize.x
378 ,(USHORT)rSize.y
379 )
380 ,(MPARAM)BKA_MAJORTAB
381 );
382 } // end of wxNotebook::SetTabSize
383
384 // ----------------------------------------------------------------------------
385 // wxNotebook operations
386 // ----------------------------------------------------------------------------
387
388 //
389 // Remove one page from the notebook, without deleting
390 //
391 wxNotebookPage* wxNotebook::DoRemovePage (
392 int nPage
393 )
394 {
395 wxNotebookPage* pPageRemoved = wxNotebookBase::DoRemovePage(nPage);
396
397 if (!pPageRemoved)
398 return NULL;
399
400
401 ULONG ulPageId = (ULONG)m_alPageId[nPage];
402
403 ::WinSendMsg( GetHWND()
404 ,BKM_DELETEPAGE
405 ,MPFROMLONG((ULONG)m_alPageId[nPage])
406 ,(MPARAM)BKA_TAB
407 );
408 if (m_pages.IsEmpty())
409 {
410 //
411 // No selection any more, the notebook becamse empty
412 //
413 m_nSelection = -1;
414 }
415 else // notebook still not empty
416 {
417 //
418 // Change the selected page if it was deleted or became invalid
419 //
420 int nSelNew;
421
422 if (m_nSelection == GetPageCount())
423 {
424 //
425 // Last page deleted, make the new last page the new selection
426 //
427 nSelNew = m_nSelection - 1;
428 }
429 else if (nPage <= m_nSelection)
430 {
431 //
432 // We must show another page, even if it has the same index
433 //
434 nSelNew = m_nSelection;
435 }
436 else // nothing changes for the currently selected page
437 {
438 nSelNew = -1;
439
440 //
441 // We still must refresh the current page: this needs to be done
442 // for some unknown reason if the tab control shows the up-down
443 // control (i.e. when there are too many pages) -- otherwise after
444 // deleting a page nothing at all is shown
445 //
446 m_pages[m_nSelection]->Refresh();
447 }
448
449 if (nSelNew != -1)
450 {
451 //
452 // m_nSelection must be always valid so reset it before calling
453 // SetSelection()
454 //
455 m_nSelection = -1;
456 SetSelection(nSelNew);
457 }
458 }
459 return pPageRemoved;
460 } // end of wxNotebook::DoRemovePage
461
462 //
463 // Remove all pages
464 //
465 bool wxNotebook::DeleteAllPages()
466 {
467 int nPageCount = GetPageCount();
468 int nPage;
469
470 for (nPage = 0; nPage < nPageCount; nPage++)
471 delete m_pages[nPage];
472 m_pages.Clear();
473 ::WinSendMsg( GetHWND()
474 ,BKM_DELETEPAGE
475 ,(MPARAM)0
476 ,(MPARAM)BKA_ALL
477 );
478 m_nSelection = -1;
479 return TRUE;
480 } // end of wxNotebook::DeleteAllPages
481
482 //
483 // Add a page to the notebook
484 //
485 bool wxNotebook::AddPage (
486 wxNotebookPage* pPage
487 , const wxString& rStrText
488 , bool bSelect
489 , int nImageId
490 )
491 {
492 return InsertPage( GetPageCount()
493 ,pPage
494 ,rStrText
495 ,bSelect
496 ,nImageId
497 );
498 } // end of wxNotebook::AddPage
499
500 //
501 // Same as AddPage() but does it at given position
502 //
503 bool wxNotebook::InsertPage (
504 int nPage
505 , wxNotebookPage* pPage
506 , const wxString& rsStrText
507 , bool bSelect
508 , int nImageId
509 )
510 {
511 ULONG ulApiPage;
512
513 wxASSERT( pPage != NULL );
514 wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), FALSE );
515
516 //
517 // Under OS/2 we can only insert FIRST, LAST, NEXT or PREV. Requires
518 // two different calls to the API. Page 1 uses the BKA_FIRST. Subsequent
519 // pages use the previous page ID coupled with a BKA_NEXT call. Unlike
520 // Windows, OS/2 uses an internal Page ID to ID the pages.
521 //
522 // OS/2 also has a nice auto-size feature that automatically sizes the
523 // the attached window so we don't have to worry about the size of the
524 // window on the page.
525 //
526 if (nPage == 0)
527 {
528 ulApiPage = LONGFROMMR(::WinSendMsg( GetHWND()
529 ,BKM_INSERTPAGE
530 ,(MPARAM)0
531 ,MPFROM2SHORT(BKA_AUTOPAGESIZE | BKA_MAJOR, BKA_FIRST)
532 ));
533 if (ulApiPage == 0L)
534 {
535 ERRORID vError;
536 wxString sError;
537
538 vError = ::WinGetLastError(vHabmain);
539 sError = wxPMErrorToStr(vError);
540 return FALSE;
541 }
542 m_alPageId.Insert((long)ulApiPage, nPage);
543 }
544 else
545 {
546 ulApiPage = LONGFROMMR(::WinSendMsg( GetHWND()
547 ,BKM_INSERTPAGE
548 ,MPFROMLONG((ULONG)m_alPageId[nPage - 1])
549 ,MPFROM2SHORT(BKA_AUTOPAGESIZE | BKA_MAJOR, BKA_NEXT)
550 ));
551 if (ulApiPage == 0L)
552 {
553 ERRORID vError;
554 wxString sError;
555
556 vError = ::WinGetLastError(vHabmain);
557 sError = wxPMErrorToStr(vError);
558 return FALSE;
559 }
560 m_alPageId.Insert((long)ulApiPage, nPage);
561 }
562
563 //
564 // Associate a window handle with the page
565 //
566 if (pPage)
567 {
568 if (!::WinSendMsg( GetHWND()
569 ,BKM_SETPAGEWINDOWHWND
570 ,MPFROMLONG((ULONG)m_alPageId[nPage])
571 ,MPFROMHWND(pPage->GetHWND())
572 ))
573 return FALSE;
574 }
575 //
576 // If the inserted page is before the selected one, we must update the
577 // index of the selected page
578 //
579 if (nPage <= m_nSelection)
580 {
581 //
582 // One extra page added
583 //
584 m_nSelection++;
585 }
586
587 if (pPage)
588 {
589 //
590 // Save the pointer to the page
591 //
592 m_pages.Insert( pPage
593 ,nPage
594 );
595 }
596
597 //
598 // Now set TAB dimenstions
599 //
600
601 wxWindowDC vDC(this);
602 wxCoord nTextX;
603 wxCoord nTextY;
604
605 vDC.GetTextExtent(rsStrText, &nTextX, &nTextY);
606 nTextY *= 2;
607 nTextX *= 1.3;
608 if (nTextX > m_nTabSize)
609 {
610 m_nTabSize = nTextX;
611 ::WinSendMsg( GetHWND()
612 ,BKM_SETDIMENSIONS
613 ,MPFROM2SHORT((USHORT)m_nTabSize, (USHORT)nTextY)
614 ,(MPARAM)BKA_MAJORTAB
615 );
616 }
617 //
618 // Now set any TAB text
619 //
620 if (!rsStrText.IsEmpty())
621 {
622 if (!SetPageText( nPage
623 ,rsStrText
624 ))
625 return FALSE;
626 }
627
628 //
629 // Now set any TAB bitmap image
630 //
631 if (nImageId != -1)
632 {
633 if (!SetPageImage( nPage
634 ,nImageId
635 ))
636 return FALSE;
637 }
638
639 if (pPage)
640 {
641 //
642 // Don't show pages by default (we'll need to adjust their size first)
643 //
644 HWND hWnd = GetWinHwnd(pPage);
645
646 WinSetWindowULong( hWnd
647 ,QWL_STYLE
648 ,WinQueryWindowULong( hWnd
649 ,QWL_STYLE
650 ) & ~WS_VISIBLE
651 );
652
653 //
654 // This updates internal flag too - otherwise it will get out of sync
655 //
656 pPage->Show(FALSE);
657 }
658
659 //
660 // Some page should be selected: either this one or the first one if there is
661 // still no selection
662 //
663 int nSelNew = -1;
664
665 if (bSelect)
666 nSelNew = nPage;
667 else if ( m_nSelection == -1 )
668 nSelNew = 0;
669
670 if (nSelNew != -1)
671 SetSelection(nSelNew);
672 return TRUE;
673 } // end of wxNotebook::InsertPage
674
675 // ----------------------------------------------------------------------------
676 // wxNotebook callbacks
677 // ----------------------------------------------------------------------------
678 void wxNotebook::OnSize(
679 wxSizeEvent& rEvent
680 )
681 {
682 int nPage;
683 int nCount = (int)m_pages.Count();
684
685 for (nPage = 0; nPage < nCount; nPage++)
686 {
687 if (m_nSelection == nPage)
688 m_pages[nPage]->Refresh();
689 else
690 ::WinSetWindowPos(m_pages[nPage]->GetHWND()
691 ,NULLHANDLE
692 ,0,0,0,0
693 ,SWP_HIDE
694 );
695 }
696 rEvent.Skip();
697 } // end of wxNotebook::OnSize
698
699 void wxNotebook::OnSelChange (
700 wxNotebookEvent& rEvent
701 )
702 {
703 //
704 // Is it our tab control?
705 //
706 if (rEvent.GetEventObject() == this)
707 {
708 int nPageCount = GetPageCount();
709 int nSel;
710 ULONG ulOS2Sel = (ULONG)rEvent.GetOldSelection();
711 bool bFound = FALSE;
712
713 for (nSel = 0; nSel < nPageCount; nSel++)
714 {
715 if (ulOS2Sel == m_alPageId[nSel])
716 {
717 bFound = TRUE;
718 break;
719 }
720 }
721
722 if (!bFound)
723 return;
724
725 m_pages[nSel]->Show(FALSE);
726
727 ulOS2Sel = (ULONG)rEvent.GetSelection();
728
729 bFound = FALSE;
730
731 for (nSel = 0; nSel < nPageCount; nSel++)
732 {
733 if (ulOS2Sel == m_alPageId[nSel])
734 {
735 bFound = TRUE;
736 break;
737 }
738 }
739
740 if (!bFound)
741 return;
742
743 wxNotebookPage* pPage = m_pages[nSel];
744
745 pPage->Show(TRUE);
746 m_nSelection = nSel;
747 }
748
749 //
750 // We want to give others a chance to process this message as well
751 //
752 rEvent.Skip();
753 } // end of wxNotebook::OnSelChange
754
755 void wxNotebook::OnSetFocus (
756 wxFocusEvent& rEvent
757 )
758 {
759 //
760 // This function is only called when the focus is explicitly set (i.e. from
761 // the program) to the notebook - in this case we don't need the
762 // complicated OnNavigationKey() logic because the programmer knows better
763 // what [s]he wants
764 //
765 // set focus to the currently selected page if any
766 //
767 if (m_nSelection != -1)
768 m_pages[m_nSelection]->SetFocus();
769 rEvent.Skip();
770 } // end of wxNotebook::OnSetFocus
771
772 void wxNotebook::OnNavigationKey (
773 wxNavigationKeyEvent& rEvent
774 )
775 {
776 if (rEvent.IsWindowChange())
777 {
778 //
779 // Change pages
780 //
781 AdvanceSelection(rEvent.GetDirection());
782 }
783 else
784 {
785 //
786 // We get this event in 2 cases
787 //
788 // a) one of our pages might have generated it because the user TABbed
789 // out from it in which case we should propagate the event upwards and
790 // our parent will take care of setting the focus to prev/next sibling
791 //
792 // or
793 //
794 // b) the parent panel wants to give the focus to us so that we
795 // forward it to our selected page. We can't deal with this in
796 // OnSetFocus() because we don't know which direction the focus came
797 // from in this case and so can't choose between setting the focus to
798 // first or last panel child
799 //
800 wxWindow* pParent = GetParent();
801
802 if (rEvent.GetEventObject() == pParent)
803 {
804 //
805 // No, it doesn't come from child, case (b): forward to a page
806 //
807 if (m_nSelection != -1)
808 {
809 //
810 // So that the page knows that the event comes from it's parent
811 // and is being propagated downwards
812 //
813 rEvent.SetEventObject(this);
814
815 wxWindow* pPage = m_pages[m_nSelection];
816
817 if (!pPage->GetEventHandler()->ProcessEvent(rEvent))
818 {
819 pPage->SetFocus();
820 }
821 //else: page manages focus inside it itself
822 }
823 else
824 {
825 //
826 // We have no pages - still have to give focus to _something_
827 //
828 SetFocus();
829 }
830 }
831 else
832 {
833 //
834 // It comes from our child, case (a), pass to the parent
835 //
836 if (pParent)
837 {
838 rEvent.SetCurrentFocus(this);
839 pParent->GetEventHandler()->ProcessEvent(rEvent);
840 }
841 }
842 }
843 } // end of wxNotebook::OnNavigationKey
844
845 // ----------------------------------------------------------------------------
846 // wxNotebook base class virtuals
847 // ----------------------------------------------------------------------------
848
849 //
850 // Override these 2 functions to do nothing: everything is done in OnSize
851 //
852 void wxNotebook::SetConstraintSizes(
853 bool WXUNUSED(bRecurse)
854 )
855 {
856 //
857 // Don't set the sizes of the pages - their correct size is not yet known
858 //
859 wxControl::SetConstraintSizes(FALSE);
860 } // end of wxNotebook::SetConstraintSizes
861
862 bool wxNotebook::DoPhase (
863 int WXUNUSED(nPhase)
864 )
865 {
866 return TRUE;
867 } // end of wxNotebook::DoPhase
868
869 // ----------------------------------------------------------------------------
870 // wxNotebook Windows message handlers
871 // ----------------------------------------------------------------------------
872 bool wxNotebook::OS2OnScroll (
873 int nOrientation
874 , WXWORD wSBCode
875 , WXWORD wPos
876 , WXHWND wControl
877 )
878 {
879 //
880 // Don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the
881 // up-down control
882 //
883 if (wControl)
884 return FALSE;
885 return wxNotebookBase::OS2OnScroll( nOrientation
886 ,wSBCode
887 ,wPos
888 ,wControl
889 );
890 } // end of wxNotebook::OS2OnScroll
891
892 // ----------------------------------------------------------------------------
893 // wxNotebook helper functions
894 // ----------------------------------------------------------------------------
895
896 //
897 // Generate the page changing and changed events, hide the currently active
898 // panel and show the new one
899 //
900 void wxNotebook::ChangePage (
901 int nOldSel
902 , int nSel
903 )
904 {
905 static bool sbInsideChangePage = FALSE;
906
907 //
908 // When we call ProcessEvent(), our own OnSelChange() is called which calls
909 // this function - break the infinite loop
910 //
911 if (sbInsideChangePage)
912 return;
913
914 //
915 // It's not an error (the message may be generated by the tab control itself)
916 // and it may happen - just do nothing
917 //
918 if (nSel == nOldSel)
919 return;
920
921 sbInsideChangePage = TRUE;
922
923 wxNotebookEvent rEvent( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
924 ,m_windowId
925 );
926
927 rEvent.SetSelection(nSel);
928 rEvent.SetOldSelection(nOldSel);
929 rEvent.SetEventObject(this);
930 if (GetEventHandler()->ProcessEvent(rEvent) && !rEvent.IsAllowed())
931 {
932 //
933 // Program doesn't allow the page change
934 //
935 sbInsideChangePage = FALSE;
936 return;
937 }
938 rEvent.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED);
939 GetEventHandler()->ProcessEvent(rEvent);
940 sbInsideChangePage = FALSE;
941 } // end of wxNotebook::ChangePage
942
943 #endif // wxUSE_NOTEBOOK
944