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