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