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