]> git.saurik.com Git - wxWidgets.git/blame - src/os2/notebook.cpp
wxGetenv was incorrectly implemented, caching prevented it from reflecting environmen...
[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
65571936 9// Licence: wxWindows licence
0e320a79
DW
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
77ffb593 17// wxWidgets
cdf1e714 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 (
ab5ebf52 332 wxImageList* pImageList
f289196b 333)
cdf1e714 334{
ab5ebf52
SN
335 //
336 // Does not really do anything yet, but at least we need to
337 // update the base class.
338 //
339 wxNotebookBase::SetImageList(pImageList);
f289196b 340} // end of wxNotebook::SetImageList
cdf1e714 341
0e320a79 342// ----------------------------------------------------------------------------
f289196b 343// wxNotebook size settings
0e320a79 344// ----------------------------------------------------------------------------
f289196b
DW
345void wxNotebook::SetPageSize (
346 const wxSize& rSize
347)
0367c1c0 348{
f289196b
DW
349 RECTL vRect;
350
351 //
352 // Transform the page size into the notebook size
353 //
354 vRect.xLeft = vRect.yTop = 0;
355 vRect.xRight = rSize.x;
356 vRect.yBottom = rSize.y;
357
358
359 //
360 // And now set it
361 //
362 SetSize( vRect.xRight - vRect.xLeft
363 ,vRect.yBottom - vRect.yTop
364 );
365} // end of wxNotebook::SetPageSize
366
367void wxNotebook::SetPadding (
368 const wxSize& WXUNUSED(rPadding)
369)
0367c1c0 370{
f289196b
DW
371 //
372 // No padding in OS/2
373 //
374} // end of wxNotebook::SetPadding
375
376void wxNotebook::SetTabSize (
377 const wxSize& rSize
378)
379{
380 ::WinSendMsg( GetHWND()
381 ,BKM_SETDIMENSIONS
382 ,MPFROM2SHORT( (USHORT)rSize.x
383 ,(USHORT)rSize.y
384 )
385 ,(MPARAM)BKA_MAJORTAB
386 );
387} // end of wxNotebook::SetTabSize
388
389// ----------------------------------------------------------------------------
390// wxNotebook operations
391// ----------------------------------------------------------------------------
0367c1c0 392
f289196b
DW
393//
394// Remove one page from the notebook, without deleting
395//
396wxNotebookPage* wxNotebook::DoRemovePage (
3979bf6b 397 size_t nPage
f289196b 398)
0e320a79 399{
f289196b 400 wxNotebookPage* pPageRemoved = wxNotebookBase::DoRemovePage(nPage);
0e320a79 401
f289196b
DW
402 if (!pPageRemoved)
403 return NULL;
0e320a79 404
f289196b
DW
405 ::WinSendMsg( GetHWND()
406 ,BKM_DELETEPAGE
407 ,MPFROMLONG((ULONG)m_alPageId[nPage])
408 ,(MPARAM)BKA_TAB
409 );
410 if (m_pages.IsEmpty())
411 {
412 //
413 // No selection any more, the notebook becamse empty
414 //
415 m_nSelection = -1;
416 }
417 else // notebook still not empty
418 {
419 //
420 // Change the selected page if it was deleted or became invalid
421 //
422 int nSelNew;
0e320a79 423
9923c37d 424 if (m_nSelection == (int)GetPageCount())
f289196b
DW
425 {
426 //
427 // Last page deleted, make the new last page the new selection
428 //
429 nSelNew = m_nSelection - 1;
430 }
9923c37d 431 else if (nPage <= (size_t)m_nSelection)
f289196b
DW
432 {
433 //
434 // We must show another page, even if it has the same index
435 //
436 nSelNew = m_nSelection;
437 }
438 else // nothing changes for the currently selected page
439 {
440 nSelNew = -1;
441
442 //
443 // We still must refresh the current page: this needs to be done
444 // for some unknown reason if the tab control shows the up-down
445 // control (i.e. when there are too many pages) -- otherwise after
446 // deleting a page nothing at all is shown
447 //
448 m_pages[m_nSelection]->Refresh();
449 }
0e320a79 450
f289196b
DW
451 if (nSelNew != -1)
452 {
453 //
454 // m_nSelection must be always valid so reset it before calling
455 // SetSelection()
456 //
457 m_nSelection = -1;
458 SetSelection(nSelNew);
459 }
460 }
461 return pPageRemoved;
462} // end of wxNotebook::DoRemovePage
0e320a79 463
f289196b
DW
464//
465// Remove all pages
466//
0e320a79
DW
467bool wxNotebook::DeleteAllPages()
468{
f289196b
DW
469 int nPageCount = GetPageCount();
470 int nPage;
471
472 for (nPage = 0; nPage < nPageCount; nPage++)
473 delete m_pages[nPage];
474 m_pages.Clear();
475 ::WinSendMsg( GetHWND()
476 ,BKM_DELETEPAGE
477 ,(MPARAM)0
478 ,(MPARAM)BKA_ALL
479 );
480 m_nSelection = -1;
0e320a79 481 return TRUE;
f289196b
DW
482} // end of wxNotebook::DeleteAllPages
483
484//
485// Add a page to the notebook
486//
487bool wxNotebook::AddPage (
488 wxNotebookPage* pPage
489, const wxString& rStrText
490, bool bSelect
491, int nImageId
492)
0e320a79 493{
f289196b
DW
494 return InsertPage( GetPageCount()
495 ,pPage
496 ,rStrText
497 ,bSelect
498 ,nImageId
499 );
500} // end of wxNotebook::AddPage
501
502//
503// Same as AddPage() but does it at given position
504//
505bool wxNotebook::InsertPage (
3979bf6b 506 size_t nPage
f289196b
DW
507, wxNotebookPage* pPage
508, const wxString& rsStrText
509, bool bSelect
510, int nImageId
511)
0e320a79 512{
f289196b
DW
513 ULONG ulApiPage;
514
0e320a79
DW
515 wxASSERT( pPage != NULL );
516 wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), FALSE );
517
f289196b
DW
518 //
519 // Under OS/2 we can only insert FIRST, LAST, NEXT or PREV. Requires
520 // two different calls to the API. Page 1 uses the BKA_FIRST. Subsequent
521 // pages use the previous page ID coupled with a BKA_NEXT call. Unlike
522 // Windows, OS/2 uses an internal Page ID to ID the pages.
523 //
524 // OS/2 also has a nice auto-size feature that automatically sizes the
525 // the attached window so we don't have to worry about the size of the
526 // window on the page.
527 //
528 if (nPage == 0)
529 {
530 ulApiPage = LONGFROMMR(::WinSendMsg( GetHWND()
531 ,BKM_INSERTPAGE
532 ,(MPARAM)0
533 ,MPFROM2SHORT(BKA_AUTOPAGESIZE | BKA_MAJOR, BKA_FIRST)
534 ));
535 if (ulApiPage == 0L)
536 {
537 ERRORID vError;
538 wxString sError;
0e320a79 539
f289196b
DW
540 vError = ::WinGetLastError(vHabmain);
541 sError = wxPMErrorToStr(vError);
542 return FALSE;
543 }
544 m_alPageId.Insert((long)ulApiPage, nPage);
545 }
546 else
547 {
548 ulApiPage = LONGFROMMR(::WinSendMsg( GetHWND()
549 ,BKM_INSERTPAGE
550 ,MPFROMLONG((ULONG)m_alPageId[nPage - 1])
551 ,MPFROM2SHORT(BKA_AUTOPAGESIZE | BKA_MAJOR, BKA_NEXT)
552 ));
553 if (ulApiPage == 0L)
554 {
555 ERRORID vError;
556 wxString sError;
0e320a79 557
f289196b
DW
558 vError = ::WinGetLastError(vHabmain);
559 sError = wxPMErrorToStr(vError);
560 return FALSE;
561 }
562 m_alPageId.Insert((long)ulApiPage, nPage);
563 }
0e320a79 564
f289196b
DW
565 //
566 // Associate a window handle with the page
567 //
568 if (pPage)
569 {
570 if (!::WinSendMsg( GetHWND()
571 ,BKM_SETPAGEWINDOWHWND
572 ,MPFROMLONG((ULONG)m_alPageId[nPage])
573 ,MPFROMHWND(pPage->GetHWND())
574 ))
575 return FALSE;
576 }
577 //
578 // If the inserted page is before the selected one, we must update the
579 // index of the selected page
580 //
9923c37d 581 if (nPage <= (size_t)m_nSelection)
f289196b
DW
582 {
583 //
584 // One extra page added
585 //
586 m_nSelection++;
587 }
0e320a79 588
f289196b
DW
589 if (pPage)
590 {
591 //
592 // Save the pointer to the page
593 //
594 m_pages.Insert( pPage
595 ,nPage
596 );
0e320a79
DW
597 }
598
f289196b
DW
599 //
600 // Now set TAB dimenstions
601 //
0e320a79 602
f289196b
DW
603 wxWindowDC vDC(this);
604 wxCoord nTextX;
605 wxCoord nTextY;
0e320a79 606
f289196b
DW
607 vDC.GetTextExtent(rsStrText, &nTextX, &nTextY);
608 nTextY *= 2;
9923c37d 609 nTextX = (wxCoord)(nTextX * 1.3);
f289196b
DW
610 if (nTextX > m_nTabSize)
611 {
612 m_nTabSize = nTextX;
613 ::WinSendMsg( GetHWND()
614 ,BKM_SETDIMENSIONS
615 ,MPFROM2SHORT((USHORT)m_nTabSize, (USHORT)nTextY)
616 ,(MPARAM)BKA_MAJORTAB
617 );
618 }
619 //
620 // Now set any TAB text
621 //
622 if (!rsStrText.IsEmpty())
623 {
624 if (!SetPageText( nPage
625 ,rsStrText
626 ))
627 return FALSE;
628 }
0e320a79 629
f289196b
DW
630 //
631 // Now set any TAB bitmap image
632 //
633 if (nImageId != -1)
634 {
635 if (!SetPageImage( nPage
636 ,nImageId
637 ))
638 return FALSE;
639 }
7e99520b 640
f289196b
DW
641 if (pPage)
642 {
643 //
644 // Don't show pages by default (we'll need to adjust their size first)
645 //
646 HWND hWnd = GetWinHwnd(pPage);
647
648 WinSetWindowULong( hWnd
649 ,QWL_STYLE
650 ,WinQueryWindowULong( hWnd
651 ,QWL_STYLE
652 ) & ~WS_VISIBLE
653 );
654
655 //
656 // This updates internal flag too - otherwise it will get out of sync
657 //
658 pPage->Show(FALSE);
0e320a79
DW
659 }
660
f289196b
DW
661 //
662 // Some page should be selected: either this one or the first one if there is
663 // still no selection
664 //
665 int nSelNew = -1;
666
667 if (bSelect)
668 nSelNew = nPage;
669 else if ( m_nSelection == -1 )
670 nSelNew = 0;
0e320a79 671
f289196b
DW
672 if (nSelNew != -1)
673 SetSelection(nSelNew);
674 return TRUE;
675} // end of wxNotebook::InsertPage
676
677// ----------------------------------------------------------------------------
678// wxNotebook callbacks
679// ----------------------------------------------------------------------------
680void wxNotebook::OnSize(
681 wxSizeEvent& rEvent
682)
0e320a79 683{
1de4baa3
DW
684 int nPage;
685 int nCount = (int)m_pages.Count();
686
687 for (nPage = 0; nPage < nCount; nPage++)
688 {
689 if (m_nSelection == nPage)
690 m_pages[nPage]->Refresh();
691 else
692 ::WinSetWindowPos(m_pages[nPage]->GetHWND()
693 ,NULLHANDLE
694 ,0,0,0,0
695 ,SWP_HIDE
696 );
697 }
f289196b
DW
698 rEvent.Skip();
699} // end of wxNotebook::OnSize
700
701void wxNotebook::OnSelChange (
702 wxNotebookEvent& rEvent
703)
704{
705 //
706 // Is it our tab control?
707 //
708 if (rEvent.GetEventObject() == this)
cdf1e714 709 {
1de4baa3
DW
710 int nPageCount = GetPageCount();
711 int nSel;
712 ULONG ulOS2Sel = (ULONG)rEvent.GetOldSelection();
713 bool bFound = FALSE;
fb46a9a6 714
1de4baa3 715 for (nSel = 0; nSel < nPageCount; nSel++)
f289196b 716 {
9923c37d 717 if (ulOS2Sel == (ULONG)m_alPageId[nSel])
1de4baa3
DW
718 {
719 bFound = TRUE;
720 break;
721 }
f289196b 722 }
f289196b 723
1de4baa3
DW
724 if (!bFound)
725 return;
726
727 m_pages[nSel]->Show(FALSE);
728
729 ulOS2Sel = (ULONG)rEvent.GetSelection();
730
731 bFound = FALSE;
732
733 for (nSel = 0; nSel < nPageCount; nSel++)
734 {
9923c37d 735 if (ulOS2Sel == (ULONG)m_alPageId[nSel])
1de4baa3
DW
736 {
737 bFound = TRUE;
738 break;
739 }
cdf1e714 740 }
1de4baa3
DW
741
742 if (!bFound)
743 return;
744
745 wxNotebookPage* pPage = m_pages[nSel];
746
747 pPage->Show(TRUE);
f289196b
DW
748 m_nSelection = nSel;
749 }
fb46a9a6 750
f289196b
DW
751 //
752 // We want to give others a chance to process this message as well
753 //
754 rEvent.Skip();
755} // end of wxNotebook::OnSelChange
0e320a79 756
f289196b
DW
757void wxNotebook::OnSetFocus (
758 wxFocusEvent& rEvent
759)
0e320a79 760{
f289196b
DW
761 //
762 // This function is only called when the focus is explicitly set (i.e. from
763 // the program) to the notebook - in this case we don't need the
764 // complicated OnNavigationKey() logic because the programmer knows better
765 // what [s]he wants
766 //
0e320a79 767 // set focus to the currently selected page if any
f289196b
DW
768 //
769 if (m_nSelection != -1)
770 m_pages[m_nSelection]->SetFocus();
771 rEvent.Skip();
772} // end of wxNotebook::OnSetFocus
773
774void wxNotebook::OnNavigationKey (
775 wxNavigationKeyEvent& rEvent
776)
0e320a79 777{
f289196b
DW
778 if (rEvent.IsWindowChange())
779 {
780 //
781 // Change pages
782 //
783 AdvanceSelection(rEvent.GetDirection());
0e320a79 784 }
f289196b
DW
785 else
786 {
787 //
788 // We get this event in 2 cases
789 //
790 // a) one of our pages might have generated it because the user TABbed
791 // out from it in which case we should propagate the event upwards and
792 // our parent will take care of setting the focus to prev/next sibling
793 //
794 // or
795 //
796 // b) the parent panel wants to give the focus to us so that we
797 // forward it to our selected page. We can't deal with this in
798 // OnSetFocus() because we don't know which direction the focus came
799 // from in this case and so can't choose between setting the focus to
800 // first or last panel child
801 //
802 wxWindow* pParent = GetParent();
803
804 if (rEvent.GetEventObject() == pParent)
805 {
806 //
807 // No, it doesn't come from child, case (b): forward to a page
808 //
809 if (m_nSelection != -1)
810 {
811 //
812 // So that the page knows that the event comes from it's parent
813 // and is being propagated downwards
814 //
815 rEvent.SetEventObject(this);
816
817 wxWindow* pPage = m_pages[m_nSelection];
818
819 if (!pPage->GetEventHandler()->ProcessEvent(rEvent))
820 {
821 pPage->SetFocus();
822 }
823 //else: page manages focus inside it itself
824 }
825 else
826 {
827 //
828 // We have no pages - still have to give focus to _something_
829 //
830 SetFocus();
831 }
832 }
833 else
834 {
835 //
836 // It comes from our child, case (a), pass to the parent
837 //
838 if (pParent)
839 {
840 rEvent.SetCurrentFocus(this);
841 pParent->GetEventHandler()->ProcessEvent(rEvent);
842 }
0e320a79
DW
843 }
844 }
f289196b 845} // end of wxNotebook::OnNavigationKey
0e320a79
DW
846
847// ----------------------------------------------------------------------------
848// wxNotebook base class virtuals
849// ----------------------------------------------------------------------------
850
f289196b
DW
851//
852// Override these 2 functions to do nothing: everything is done in OnSize
853//
854void wxNotebook::SetConstraintSizes(
855 bool WXUNUSED(bRecurse)
856)
0e320a79 857{
f289196b
DW
858 //
859 // Don't set the sizes of the pages - their correct size is not yet known
860 //
0e320a79 861 wxControl::SetConstraintSizes(FALSE);
f289196b 862} // end of wxNotebook::SetConstraintSizes
0e320a79 863
f289196b
DW
864bool wxNotebook::DoPhase (
865 int WXUNUSED(nPhase)
866)
0e320a79
DW
867{
868 return TRUE;
f289196b 869} // end of wxNotebook::DoPhase
0e320a79 870
f289196b
DW
871// ----------------------------------------------------------------------------
872// wxNotebook Windows message handlers
873// ----------------------------------------------------------------------------
874bool wxNotebook::OS2OnScroll (
875 int nOrientation
876, WXWORD wSBCode
877, WXWORD wPos
878, WXHWND wControl
879)
0e320a79 880{
f289196b
DW
881 //
882 // Don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the
883 // up-down control
884 //
885 if (wControl)
886 return FALSE;
887 return wxNotebookBase::OS2OnScroll( nOrientation
888 ,wSBCode
889 ,wPos
890 ,wControl
891 );
892} // end of wxNotebook::OS2OnScroll
0e320a79 893
f289196b 894#endif // wxUSE_NOTEBOOK
0e320a79 895