]> git.saurik.com Git - wxWidgets.git/blame - src/os2/notebook.cpp
placeholder
[wxWidgets.git] / src / os2 / notebook.cpp
CommitLineData
0e320a79
DW
1///////////////////////////////////////////////////////////////////////////////
2// Name: notebook.cpp
3// Purpose: implementation of wxNotebook
cdf1e714 4// Author: David Webster
fb46a9a6 5// Modified by:
cdf1e714 6// Created: 10/12/99
0e320a79 7// RCS-ID: $Id$
cdf1e714 8// Copyright: (c) David Webster
0e320a79
DW
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
cdf1e714
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
0e320a79 14
f289196b
DW
15#if wxUSE_NOTEBOOK
16
cdf1e714
DW
17// wxWindows
18#ifndef WX_PRECOMP
1a75e76f 19 #include "wx/app.h"
3979bf6b 20 #include "wx/dcclient.h"
1a75e76f
SN
21 #include "wx/string.h"
22 #include "wx/settings.h"
cdf1e714 23#endif // WX_PRECOMP
0e320a79 24
f289196b
DW
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"
cdf1e714 30
f289196b 31#include "wx/os2/private.h"
cdf1e714 32
0e320a79
DW
33// ----------------------------------------------------------------------------
34// macros
35// ----------------------------------------------------------------------------
f289196b 36
0e320a79
DW
37// check that the page index is valid
38#define IS_VALID_PAGE(nPage) (((nPage) >= 0) && ((nPage) < GetPageCount()))
39
cdf1e714 40// hide the ugly cast
f289196b 41#define m_hWnd (HWND)GetHWND()
cdf1e714
DW
42
43// ----------------------------------------------------------------------------
44// constants
45// ----------------------------------------------------------------------------
46
0e320a79
DW
47// ----------------------------------------------------------------------------
48// event table
49// ----------------------------------------------------------------------------
50
8546f11e
DW
51DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
52DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
53
54BEGIN_EVENT_TABLE(wxNotebook, wxControl)
0e320a79 55 EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange)
0e320a79
DW
56 EVT_SIZE(wxNotebook::OnSize)
57 EVT_SET_FOCUS(wxNotebook::OnSetFocus)
58 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
8546f11e 59END_EVENT_TABLE()
0e320a79 60
8546f11e
DW
61IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl)
62IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent)
0e320a79
DW
63
64// ============================================================================
65// implementation
66// ============================================================================
67
68// ----------------------------------------------------------------------------
69// wxNotebook construction
70// ----------------------------------------------------------------------------
71
f289196b
DW
72//
73// Common part of all ctors
74//
0e320a79
DW
75void wxNotebook::Init()
76{
f289196b 77 m_imageList = NULL;
0e320a79 78 m_nSelection = -1;
f289196b
DW
79 m_nTabSize = 0;
80} // end of wxNotebook::Init
0e320a79 81
f289196b
DW
82//
83// Default for dynamic class
84//
0e320a79
DW
85wxNotebook::wxNotebook()
86{
87 Init();
f289196b
DW
88} // end of wxNotebook::wxNotebook
89
90//
91// The same arguments as for wxControl
92//
93wxNotebook::wxNotebook(
94 wxWindow* pParent
95, wxWindowID vId
96, const wxPoint& rPos
97, const wxSize& rSize
98, long lStyle
99, const wxString& rsName
100)
0e320a79
DW
101{
102 Init();
f289196b
DW
103 Create( pParent
104 ,vId
105 ,rPos
106 ,rSize
107 ,lStyle
108 ,rsName
109 );
110} // end of wxNotebook::wxNotebook
111
112//
0e320a79 113// Create() function
f289196b
DW
114//
115bool wxNotebook::Create(
116 wxWindow* pParent
117, wxWindowID vId
118, const wxPoint& rPos
119, const wxSize& rSize
120, long lStyle
121, const wxString& rsName
122)
0e320a79 123{
f289196b
DW
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
152WXDWORD wxNotebook::OS2GetStyle (
153 long lStyle
154, WXDWORD* pdwExstyle
155) const
0e320a79 156{
f289196b
DW
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
0e320a79
DW
185
186// ----------------------------------------------------------------------------
187// wxNotebook accessors
188// ----------------------------------------------------------------------------
f289196b 189
21323df7 190size_t wxNotebook::GetPageCount() const
0e320a79 191{
f289196b
DW
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
0e320a79
DW
198
199int wxNotebook::GetRowCount() const
200{
f289196b
DW
201 return (int)::WinSendMsg( GetHWND()
202 ,BKM_QUERYPAGECOUNT
203 ,(MPARAM)0
204 ,(MPARAM)BKA_MAJOR
205 );
206} // end of wxNotebook::GetRowCount
207
208int wxNotebook::SetSelection(
3979bf6b 209 size_t nPage
f289196b 210)
0e320a79 211{
cdf1e714 212 wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") );
f289196b 213
9923c37d 214 if (nPage != (size_t)m_nSelection)
2b5f62a0
VZ
215 {
216 wxNotebookEvent vEvent( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
217 ,m_windowId
218 );
f289196b 219
2b5f62a0
VZ
220 vEvent.SetSelection(nPage);
221 vEvent.SetOldSelection(m_nSelection);
222 vEvent.SetEventObject(this);
223 if (!GetEventHandler()->ProcessEvent(vEvent) || vEvent.IsAllowed())
224 {
f289196b 225
2b5f62a0
VZ
226 //
227 // Program allows the page change
228 //
229 vEvent.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED);
230 GetEventHandler()->ProcessEvent(vEvent);
231
2b5f62a0
VZ
232 ::WinSendMsg( GetHWND()
233 ,BKM_TURNTOPAGE
234 ,MPFROMLONG((ULONG)m_alPageId[nPage])
235 ,(MPARAM)0
236 );
237 }
238 }
f289196b
DW
239 m_nSelection = nPage;
240 return nPage;
241} // end of wxNotebook::SetSelection
242
243bool wxNotebook::SetPageText(
3979bf6b 244 size_t nPage
f289196b
DW
245, const wxString& rsStrText
246)
247{
248 wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") );
f289196b
DW
249 return (bool)::WinSendMsg( m_hWnd
250 ,BKM_SETTABTEXT
251 ,MPFROMLONG((ULONG)m_alPageId[nPage])
252 ,MPFROMP((PSZ)rsStrText.c_str())
253 );
254} // end of wxNotebook::SetPageText
0e320a79 255
f289196b 256wxString wxNotebook::GetPageText (
3979bf6b 257 size_t nPage
f289196b 258) const
0e320a79 259{
f289196b
DW
260 BOOKTEXT vBookText;
261 wxChar zBuf[256];
262 wxString sStr;
263 ULONG ulRc;
0e320a79 264
cdf1e714 265 wxCHECK_MSG( IS_VALID_PAGE(nPage), wxT(""), wxT("notebook page out of range") );
0e320a79 266
f289196b
DW
267 memset(&vBookText, '\0', sizeof(BOOKTEXT));
268 vBookText.textLen = 0; // This will get the length
269 ulRc = LONGFROMMR(::WinSendMsg( m_hWnd
270 ,BKM_QUERYTABTEXT
271 ,MPFROMLONG((ULONG)m_alPageId[nPage])
272 ,MPFROMP(&vBookText)
273 ));
9923c37d 274 if (ulRc == (ULONG)BOOKERR_INVALID_PARAMETERS || ulRc == 0L)
f289196b 275 {
9923c37d 276 if (ulRc == (ULONG)BOOKERR_INVALID_PARAMETERS)
f289196b
DW
277 {
278 wxLogError(wxT("Invalid Page Id for page text querry."));
279 }
280 return wxEmptyString;
281 }
282 vBookText.textLen = ulRc + 1; // To get the null terminator
283 vBookText.pString = zBuf;
284
285 //
286 // Now get the actual text
287 //
288 ulRc = LONGFROMMR(::WinSendMsg( m_hWnd
289 ,BKM_QUERYTABTEXT
290 ,MPFROMLONG((ULONG)m_alPageId[nPage])
291 ,MPFROMP(&vBookText)
292 ));
9923c37d 293 if (ulRc == (ULONG)BOOKERR_INVALID_PARAMETERS || ulRc == 0L)
f289196b
DW
294 {
295 return wxEmptyString;
296 }
297 if (ulRc > 255L)
298 ulRc = 255L;
299
300 vBookText.pString[ulRc] = '\0';
301 sStr = vBookText.pString;
302 return sStr;
303} // end of wxNotebook::GetPageText
304
305int wxNotebook::GetPageImage (
3979bf6b 306 size_t nPage
f289196b 307) const
0e320a79 308{
cdf1e714 309 wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") );
0e320a79 310
f289196b
DW
311 //
312 // For OS/2 just return the page
313 //
314 return nPage;
315} // end of wxNotebook::GetPageImage
0e320a79 316
f289196b 317bool wxNotebook::SetPageImage (
3979bf6b 318 size_t nPage
f289196b
DW
319, int nImage
320)
0e320a79 321{
f289196b 322 wxBitmap* pBitmap = (wxBitmap*)m_imageList->GetBitmap(nImage);
0e320a79 323
f289196b
DW
324 return (bool)::WinSendMsg( GetHWND()
325 ,BKM_SETTABBITMAP
326 ,MPFROMLONG((ULONG)m_alPageId[nPage])
327 ,(MPARAM)pBitmap->GetHBITMAP()
328 );
329} // end of wxNotebook::SetPageImage
330
331void wxNotebook::SetImageList (
332 wxImageList* WXUNUSED(pImageList)
333)
cdf1e714 334{
f289196b
DW
335 //
336 // Does nothing under OS/2
337 //
338} // end of wxNotebook::SetImageList
cdf1e714 339
0e320a79 340// ----------------------------------------------------------------------------
f289196b 341// wxNotebook size settings
0e320a79 342// ----------------------------------------------------------------------------
f289196b
DW
343void wxNotebook::SetPageSize (
344 const wxSize& rSize
345)
0367c1c0 346{
f289196b
DW
347 RECTL vRect;
348
349 //
350 // Transform the page size into the notebook size
351 //
352 vRect.xLeft = vRect.yTop = 0;
353 vRect.xRight = rSize.x;
354 vRect.yBottom = rSize.y;
355
356
357 //
358 // And now set it
359 //
360 SetSize( vRect.xRight - vRect.xLeft
361 ,vRect.yBottom - vRect.yTop
362 );
363} // end of wxNotebook::SetPageSize
364
365void wxNotebook::SetPadding (
366 const wxSize& WXUNUSED(rPadding)
367)
0367c1c0 368{
f289196b
DW
369 //
370 // No padding in OS/2
371 //
372} // end of wxNotebook::SetPadding
373
374void wxNotebook::SetTabSize (
375 const wxSize& rSize
376)
377{
378 ::WinSendMsg( GetHWND()
379 ,BKM_SETDIMENSIONS
380 ,MPFROM2SHORT( (USHORT)rSize.x
381 ,(USHORT)rSize.y
382 )
383 ,(MPARAM)BKA_MAJORTAB
384 );
385} // end of wxNotebook::SetTabSize
386
387// ----------------------------------------------------------------------------
388// wxNotebook operations
389// ----------------------------------------------------------------------------
0367c1c0 390
f289196b
DW
391//
392// Remove one page from the notebook, without deleting
393//
394wxNotebookPage* wxNotebook::DoRemovePage (
3979bf6b 395 size_t nPage
f289196b 396)
0e320a79 397{
f289196b 398 wxNotebookPage* pPageRemoved = wxNotebookBase::DoRemovePage(nPage);
0e320a79 399
f289196b
DW
400 if (!pPageRemoved)
401 return NULL;
0e320a79 402
f289196b
DW
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;
0e320a79 421
9923c37d 422 if (m_nSelection == (int)GetPageCount())
f289196b
DW
423 {
424 //
425 // Last page deleted, make the new last page the new selection
426 //
427 nSelNew = m_nSelection - 1;
428 }
9923c37d 429 else if (nPage <= (size_t)m_nSelection)
f289196b
DW
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 }
0e320a79 448
f289196b
DW
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
0e320a79 461
f289196b
DW
462//
463// Remove all pages
464//
0e320a79
DW
465bool wxNotebook::DeleteAllPages()
466{
f289196b
DW
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;
0e320a79 479 return TRUE;
f289196b
DW
480} // end of wxNotebook::DeleteAllPages
481
482//
483// Add a page to the notebook
484//
485bool wxNotebook::AddPage (
486 wxNotebookPage* pPage
487, const wxString& rStrText
488, bool bSelect
489, int nImageId
490)
0e320a79 491{
f289196b
DW
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//
503bool wxNotebook::InsertPage (
3979bf6b 504 size_t nPage
f289196b
DW
505, wxNotebookPage* pPage
506, const wxString& rsStrText
507, bool bSelect
508, int nImageId
509)
0e320a79 510{
f289196b
DW
511 ULONG ulApiPage;
512
0e320a79
DW
513 wxASSERT( pPage != NULL );
514 wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), FALSE );
515
f289196b
DW
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;
0e320a79 537
f289196b
DW
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;
0e320a79 555
f289196b
DW
556 vError = ::WinGetLastError(vHabmain);
557 sError = wxPMErrorToStr(vError);
558 return FALSE;
559 }
560 m_alPageId.Insert((long)ulApiPage, nPage);
561 }
0e320a79 562
f289196b
DW
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 //
9923c37d 579 if (nPage <= (size_t)m_nSelection)
f289196b
DW
580 {
581 //
582 // One extra page added
583 //
584 m_nSelection++;
585 }
0e320a79 586
f289196b
DW
587 if (pPage)
588 {
589 //
590 // Save the pointer to the page
591 //
592 m_pages.Insert( pPage
593 ,nPage
594 );
0e320a79
DW
595 }
596
f289196b
DW
597 //
598 // Now set TAB dimenstions
599 //
0e320a79 600
f289196b
DW
601 wxWindowDC vDC(this);
602 wxCoord nTextX;
603 wxCoord nTextY;
0e320a79 604
f289196b
DW
605 vDC.GetTextExtent(rsStrText, &nTextX, &nTextY);
606 nTextY *= 2;
9923c37d 607 nTextX = (wxCoord)(nTextX * 1.3);
f289196b
DW
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 }
0e320a79 627
f289196b
DW
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 }
7e99520b 638
f289196b
DW
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);
0e320a79
DW
657 }
658
f289196b
DW
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;
0e320a79 669
f289196b
DW
670 if (nSelNew != -1)
671 SetSelection(nSelNew);
672 return TRUE;
673} // end of wxNotebook::InsertPage
674
675// ----------------------------------------------------------------------------
676// wxNotebook callbacks
677// ----------------------------------------------------------------------------
678void wxNotebook::OnSize(
679 wxSizeEvent& rEvent
680)
0e320a79 681{
1de4baa3
DW
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 }
f289196b
DW
696 rEvent.Skip();
697} // end of wxNotebook::OnSize
698
699void wxNotebook::OnSelChange (
700 wxNotebookEvent& rEvent
701)
702{
703 //
704 // Is it our tab control?
705 //
706 if (rEvent.GetEventObject() == this)
cdf1e714 707 {
1de4baa3
DW
708 int nPageCount = GetPageCount();
709 int nSel;
710 ULONG ulOS2Sel = (ULONG)rEvent.GetOldSelection();
711 bool bFound = FALSE;
fb46a9a6 712
1de4baa3 713 for (nSel = 0; nSel < nPageCount; nSel++)
f289196b 714 {
9923c37d 715 if (ulOS2Sel == (ULONG)m_alPageId[nSel])
1de4baa3
DW
716 {
717 bFound = TRUE;
718 break;
719 }
f289196b 720 }
f289196b 721
1de4baa3
DW
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 {
9923c37d 733 if (ulOS2Sel == (ULONG)m_alPageId[nSel])
1de4baa3
DW
734 {
735 bFound = TRUE;
736 break;
737 }
cdf1e714 738 }
1de4baa3
DW
739
740 if (!bFound)
741 return;
742
743 wxNotebookPage* pPage = m_pages[nSel];
744
745 pPage->Show(TRUE);
f289196b
DW
746 m_nSelection = nSel;
747 }
fb46a9a6 748
f289196b
DW
749 //
750 // We want to give others a chance to process this message as well
751 //
752 rEvent.Skip();
753} // end of wxNotebook::OnSelChange
0e320a79 754
f289196b
DW
755void wxNotebook::OnSetFocus (
756 wxFocusEvent& rEvent
757)
0e320a79 758{
f289196b
DW
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 //
0e320a79 765 // set focus to the currently selected page if any
f289196b
DW
766 //
767 if (m_nSelection != -1)
768 m_pages[m_nSelection]->SetFocus();
769 rEvent.Skip();
770} // end of wxNotebook::OnSetFocus
771
772void wxNotebook::OnNavigationKey (
773 wxNavigationKeyEvent& rEvent
774)
0e320a79 775{
f289196b
DW
776 if (rEvent.IsWindowChange())
777 {
778 //
779 // Change pages
780 //
781 AdvanceSelection(rEvent.GetDirection());
0e320a79 782 }
f289196b
DW
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 }
0e320a79
DW
841 }
842 }
f289196b 843} // end of wxNotebook::OnNavigationKey
0e320a79
DW
844
845// ----------------------------------------------------------------------------
846// wxNotebook base class virtuals
847// ----------------------------------------------------------------------------
848
f289196b
DW
849//
850// Override these 2 functions to do nothing: everything is done in OnSize
851//
852void wxNotebook::SetConstraintSizes(
853 bool WXUNUSED(bRecurse)
854)
0e320a79 855{
f289196b
DW
856 //
857 // Don't set the sizes of the pages - their correct size is not yet known
858 //
0e320a79 859 wxControl::SetConstraintSizes(FALSE);
f289196b 860} // end of wxNotebook::SetConstraintSizes
0e320a79 861
f289196b
DW
862bool wxNotebook::DoPhase (
863 int WXUNUSED(nPhase)
864)
0e320a79
DW
865{
866 return TRUE;
f289196b 867} // end of wxNotebook::DoPhase
0e320a79 868
f289196b
DW
869// ----------------------------------------------------------------------------
870// wxNotebook Windows message handlers
871// ----------------------------------------------------------------------------
872bool wxNotebook::OS2OnScroll (
873 int nOrientation
874, WXWORD wSBCode
875, WXWORD wPos
876, WXHWND wControl
877)
0e320a79 878{
f289196b
DW
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
0e320a79 891
f289196b 892#endif // wxUSE_NOTEBOOK
0e320a79 893