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