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