]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/notebmac.cpp
Updated list of subprojects.
[wxWidgets.git] / src / mac / carbon / notebmac.cpp
CommitLineData
ee6b1d97 1///////////////////////////////////////////////////////////////////////////////
90c0f5a9 2// Name: src/mac/carbon/notebmac.cpp
ee6b1d97 3// Purpose: implementation of wxNotebook
a31a5f85 4// Author: Stefan Csomor
5aed9d50 5// Modified by:
a31a5f85 6// Created: 1998-01-01
ee6b1d97 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
ee6b1d97
SC
10///////////////////////////////////////////////////////////////////////////////
11
3d1a4878
SC
12#include "wx/wxprec.h"
13
179e085f
RN
14#if wxUSE_NOTEBOOK
15
df91131c
WS
16#include "wx/notebook.h"
17
18#ifndef WX_PRECOMP
19 #include "wx/string.h"
e4db172a 20 #include "wx/log.h"
670f9935 21 #include "wx/app.h"
155ecd4c 22 #include "wx/image.h"
df91131c
WS
23#endif
24
d497dca4 25#include "wx/string.h"
d497dca4 26#include "wx/imaglist.h"
d497dca4 27#include "wx/mac/uma.h"
5a7d70fe 28
ee6b1d97
SC
29
30// check that the page index is valid
19c43a77 31#define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount())
ee6b1d97 32
ee6b1d97 33
5b781a67
SC
34DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
35DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
36
ee6b1d97 37BEGIN_EVENT_TABLE(wxNotebook, wxControl)
90c0f5a9 38 EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, wxNotebook::OnSelChange)
e40298d5 39
461fe6e2
SC
40 EVT_SIZE(wxNotebook::OnSize)
41 EVT_SET_FOCUS(wxNotebook::OnSetFocus)
42 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
ee6b1d97
SC
43END_EVENT_TABLE()
44
45IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl)
46IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent)
ee6b1d97 47
5aed9d50
RD
48
49// common part of all ctors
50void wxNotebook::Init()
51{
ee6b1d97
SC
52 m_nSelection = -1;
53}
54
55// default for dynamic class
56wxNotebook::wxNotebook()
57{
58 Init();
59}
60
61// the same arguments as for wxControl
5a7d70fe
DS
62wxNotebook::wxNotebook( wxWindow *parent,
63 wxWindowID id,
64 const wxPoint& pos,
65 const wxSize& size,
66 long style,
67 const wxString& name )
ee6b1d97
SC
68{
69 Init();
5aed9d50 70
5a7d70fe 71 Create( parent, id, pos, size, style, name );
ee6b1d97
SC
72}
73
5a7d70fe
DS
74bool wxNotebook::Create( wxWindow *parent,
75 wxWindowID id,
76 const wxPoint& pos,
77 const wxSize& size,
78 long style,
79 const wxString& name )
ee6b1d97 80{
90c0f5a9
WS
81 m_macIsUserPane = false ;
82
511bec96
RD
83 if (! (style & wxBK_ALIGN_MASK))
84 style |= wxBK_TOP;
155ecd4c 85
5a7d70fe 86 if ( !wxNotebookBase::Create( parent, id, pos, size, style, name ) )
b45ed7a2
VZ
87 return false;
88
5a7d70fe 89 Rect bounds = wxMacGetBoundsForControl( this, pos, size );
5aed9d50 90
5a7d70fe
DS
91 if ( bounds.right <= bounds.left )
92 bounds.right = bounds.left + 100;
facd6764 93 if ( bounds.bottom <= bounds.top )
5a7d70fe 94 bounds.bottom = bounds.top + 100;
5aed9d50 95
5a7d70fe 96 UInt16 tabstyle = kControlTabDirectionNorth;
90c0f5a9 97 if ( HasFlag(wxBK_LEFT) )
5a7d70fe 98 tabstyle = kControlTabDirectionWest;
90c0f5a9 99 else if ( HasFlag( wxBK_RIGHT ) )
5a7d70fe 100 tabstyle = kControlTabDirectionEast;
90c0f5a9 101 else if ( HasFlag( wxBK_BOTTOM ) )
5a7d70fe 102 tabstyle = kControlTabDirectionSouth;
90c0f5a9 103
5a7d70fe
DS
104 ControlTabSize tabsize;
105 switch (GetWindowVariant())
facd6764 106 {
df91131c 107 case wxWINDOW_VARIANT_MINI:
5a7d70fe
DS
108 if ( UMAGetSystemVersion() >= 0x1030 )
109 tabsize = 3 ;
110 else
111 tabsize = kControlSizeSmall;
112 break;
113
df91131c 114 case wxWINDOW_VARIANT_SMALL:
5a7d70fe
DS
115 tabsize = kControlTabSizeSmall;
116 break;
117
df91131c 118 default:
5a7d70fe
DS
119 tabsize = kControlTabSizeLarge;
120 break;
facd6764 121 }
5aed9d50 122
5a7d70fe
DS
123 m_peer = new wxMacControl( this );
124 OSStatus err = CreateTabsControl(
125 MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds,
126 tabsize, tabstyle, 0, NULL, m_peer->GetControlRefAddr() );
127 verify_noerr( err );
90c0f5a9 128
5a7d70fe 129 MacPostControlCreate( pos, size );
90c0f5a9 130
90c0f5a9 131 return true ;
ee6b1d97
SC
132}
133
134// dtor
135wxNotebook::~wxNotebook()
136{
ee6b1d97
SC
137}
138
139// ----------------------------------------------------------------------------
140// wxNotebook accessors
141// ----------------------------------------------------------------------------
90b959ae
SC
142
143void wxNotebook::SetPadding(const wxSize& padding)
144{
63ff6f53 145 // unsupported by OS
90b959ae
SC
146}
147
148void wxNotebook::SetTabSize(const wxSize& sz)
ee6b1d97 149{
63ff6f53 150 // unsupported by OS
ee6b1d97
SC
151}
152
90b959ae 153void wxNotebook::SetPageSize(const wxSize& size)
ee6b1d97 154{
63ff6f53
SC
155 SetSize( CalcSizeFromPage( size ) );
156}
157
158wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const
159{
5a7d70fe 160 return DoGetSizeFromClientSize( sizePage );
63ff6f53
SC
161}
162
2da25e49 163int wxNotebook::DoSetSelection(size_t nPage, int flags)
ee6b1d97 164{
1d6fcbcc 165 wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("DoSetSelection: invalid notebook page") );
5aed9d50 166
8e79a06b 167 if ( m_nSelection == wxNOT_FOUND || nPage != (size_t)m_nSelection )
461fe6e2 168 {
2da25e49 169 if ( flags & SetSelection_SendEvent )
461fe6e2 170 {
a570e8f8 171 if ( !SendPageChangingEvent(nPage) )
1d6fcbcc 172 {
2da25e49
VZ
173 // vetoed by program
174 return m_nSelection;
1d6fcbcc 175 }
2da25e49
VZ
176 //else: program allows the page change
177
a570e8f8 178 SendPageChangedEvent(m_nSelection, nPage);
461fe6e2 179 }
5aed9d50 180
2da25e49
VZ
181 ChangePage(m_nSelection, nPage);
182 }
8e79a06b 183 //else: no change
2da25e49 184
ee6b1d97
SC
185 return m_nSelection;
186}
187
8f83dfee 188bool wxNotebook::SetPageText(size_t nPage, const wxString& strText)
ee6b1d97 189{
5a7d70fe 190 wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("SetPageText: invalid notebook page") );
5aed9d50 191
90b959ae 192 wxNotebookPage *page = m_pages[nPage];
c854c7d9
GD
193 page->SetLabel(strText);
194 MacSetupTabs();
5aed9d50 195
c854c7d9 196 return true;
ee6b1d97
SC
197}
198
8f83dfee 199wxString wxNotebook::GetPageText(size_t nPage) const
ee6b1d97 200{
5a7d70fe 201 wxCHECK_MSG( IS_VALID_PAGE(nPage), wxEmptyString, wxT("GetPageText: invalid notebook page") );
5aed9d50 202
90b959ae 203 wxNotebookPage *page = m_pages[nPage];
5a7d70fe 204
c854c7d9 205 return page->GetLabel();
ee6b1d97
SC
206}
207
8f83dfee 208int wxNotebook::GetPageImage(size_t nPage) const
ee6b1d97 209{
5a7d70fe 210 wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("GetPageImage: invalid notebook page") );
5aed9d50 211
2b5f62a0 212 return m_images[nPage];
ee6b1d97
SC
213}
214
19c43a77 215bool wxNotebook::SetPageImage(size_t nPage, int nImage)
ee6b1d97 216{
5a7d70fe
DS
217 wxCHECK_MSG( IS_VALID_PAGE(nPage), false,
218 wxT("SetPageImage: invalid notebook page") );
90c0f5a9 219 wxCHECK_MSG( m_imageList && nImage < m_imageList->GetImageCount(), false,
5a7d70fe 220 wxT("SetPageImage: invalid image index") );
5aed9d50 221
2b5f62a0
VZ
222 if ( nImage != m_images[nPage] )
223 {
224 // if the item didn't have an icon before or, on the contrary, did have
225 // it but has lost it now, its size will change - but if the icon just
226 // changes, it won't
227 m_images[nPage] = nImage;
5aed9d50 228
e40298d5 229 MacSetupTabs() ;
2b5f62a0 230 }
5aed9d50 231
90c0f5a9 232 return true;
ee6b1d97
SC
233}
234
ee6b1d97
SC
235// ----------------------------------------------------------------------------
236// wxNotebook operations
237// ----------------------------------------------------------------------------
238
90b959ae 239// remove one page from the notebook, without deleting the window
8f83dfee 240wxNotebookPage* wxNotebook::DoRemovePage(size_t nPage)
ee6b1d97 241{
5a7d70fe
DS
242 wxCHECK_MSG( IS_VALID_PAGE(nPage), NULL,
243 wxT("DoRemovePage: invalid notebook page") );
244
90b959ae 245 wxNotebookPage* page = m_pages[nPage] ;
3ef585df 246 m_pages.RemoveAt(nPage);
5aed9d50 247
c854c7d9 248 MacSetupTabs();
5aed9d50 249
5a7d70fe 250 if (m_nSelection >= (int)GetPageCount())
c854c7d9 251 m_nSelection = GetPageCount() - 1;
5a7d70fe
DS
252
253 if (m_nSelection >= 0)
90b959ae 254 m_pages[m_nSelection]->Show(true);
5a7d70fe 255
37144cf0 256 InvalidateBestSize();
5a7d70fe 257
90b959ae 258 return page;
ee6b1d97
SC
259}
260
261// remove all pages
262bool wxNotebook::DeleteAllPages()
263{
90b959ae 264 WX_CLEAR_ARRAY(m_pages) ;
c854c7d9 265 MacSetupTabs();
061174e3 266 m_nSelection = -1 ;
37144cf0 267 InvalidateBestSize();
5a7d70fe 268
90c0f5a9 269 return true;
ee6b1d97
SC
270}
271
ee6b1d97 272// same as AddPage() but does it at given position
8f83dfee 273bool wxNotebook::InsertPage(size_t nPage,
5a7d70fe
DS
274 wxNotebookPage *pPage,
275 const wxString& strText,
276 bool bSelect,
277 int imageId )
ee6b1d97 278{
5a7d70fe 279 if ( !wxNotebookBase::InsertPage( nPage, pPage, strText, bSelect, imageId ) )
19c43a77 280 return false;
5aed9d50 281
5a7d70fe 282 wxASSERT_MSG( pPage->GetParent() == this, wxT("notebook pages must have notebook as parent") );
461fe6e2
SC
283
284 // don't show pages by default (we'll need to adjust their size first)
285 pPage->Show( false ) ;
286
5a7d70fe 287 pPage->SetLabel( strText );
5aed9d50 288
5a7d70fe 289 m_images.Insert( imageId, nPage );
5aed9d50 290
c854c7d9 291 MacSetupTabs();
5aed9d50 292
63ff6f53 293 wxRect rect = GetPageRect() ;
5a7d70fe
DS
294 pPage->SetSize( rect );
295 if ( pPage->GetAutoLayout() )
c854c7d9 296 pPage->Layout();
461fe6e2
SC
297
298 // now deal with the selection
299 // ---------------------------
300
301 // if the inserted page is before the selected one, we must update the
302 // index of the selected page
303
90c0f5a9 304 if ( int(nPage) <= m_nSelection )
461fe6e2
SC
305 {
306 m_nSelection++;
5a7d70fe 307
461fe6e2 308 // while this still is the same page showing, we need to update the tabs
5ca0d812 309 m_peer->SetValue( m_nSelection + 1 ) ;
461fe6e2 310 }
90c0f5a9 311
461fe6e2
SC
312 // some page should be selected: either this one or the first one if there
313 // is still no selection
314 int selNew = -1;
315 if ( bSelect )
316 selNew = nPage;
317 else if ( m_nSelection == -1 )
318 selNew = 0;
319
320 if ( selNew != -1 )
5a7d70fe 321 SetSelection( selNew );
461fe6e2 322
37144cf0 323 InvalidateBestSize();
5a7d70fe 324
c854c7d9
GD
325 return true;
326}
327
3c3e6970
SC
328int wxNotebook::HitTest(const wxPoint& pt, long * flags) const
329{
fe224552 330 int resultV = wxNOT_FOUND;
5a7d70fe 331
3c3e6970 332#if TARGET_API_MAC_OSX
5a7d70fe 333 const int countPages = GetPageCount();
fe224552 334
2fbfb7d6 335 // we have to convert from Client to Window relative coordinates
df91131c 336 wxPoint adjustedPt = pt + GetClientAreaOrigin();
2fbfb7d6
SC
337 // and now to HIView native ones
338 adjustedPt.x -= MacGetLeftBorderSize() ;
339 adjustedPt.y -= MacGetTopBorderSize() ;
df91131c 340
2fbfb7d6 341 HIPoint hipoint= { adjustedPt.x , adjustedPt.y } ;
3c3e6970 342 HIViewPartCode outPart = 0 ;
5a7d70fe 343 OSStatus err = HIViewGetPartHit( m_peer->GetControlRef(), &hipoint, &outPart );
fe224552 344
0df4335d 345 int max = m_peer->GetMaximum() ;
3c3e6970
SC
346 if ( outPart == 0 && max > 0 )
347 {
348 // this is a hack, as unfortunately a hit on an already selected tab returns 0,
fe224552 349 // so we have to go some extra miles to make sure we select something different
3c3e6970 350 // and try again ..
0df4335d 351 int val = m_peer->GetValue() ;
3c3e6970
SC
352 int maxval = max ;
353 if ( max == 1 )
354 {
0df4335d 355 m_peer->SetMaximum( 2 ) ;
3c3e6970
SC
356 maxval = 2 ;
357 }
358
359 if ( val == 1 )
0df4335d 360 m_peer->SetValue( maxval ) ;
3c3e6970 361 else
0df4335d 362 m_peer->SetValue( 1 ) ;
fe224552 363
5a7d70fe 364 err = HIViewGetPartHit( m_peer->GetControlRef(), &hipoint, &outPart );
fe224552 365
0df4335d 366 m_peer->SetValue( val ) ;
3c3e6970 367 if ( max == 1 )
0df4335d 368 m_peer->SetMaximum( 1 ) ;
3c3e6970 369 }
fe224552
VZ
370
371 if ( outPart >= 1 && outPart <= countPages )
eb5d9594 372 resultV = outPart - 1 ;
f885b815
VZ
373#endif // TARGET_API_MAC_OSX
374
3c3e6970
SC
375 if (flags != NULL)
376 {
377 *flags = 0;
fe224552 378
3c3e6970 379 // we cannot differentiate better
eb5d9594 380 if (resultV >= 0)
9804d540 381 *flags |= wxBK_HITTEST_ONLABEL;
3c3e6970 382 else
9804d540 383 *flags |= wxBK_HITTEST_NOWHERE;
3c3e6970 384 }
5a7d70fe 385
3c3e6970
SC
386 return resultV;
387}
388
5a7d70fe
DS
389// Added by Mark Newsam
390// When a page is added or deleted to the notebook this function updates
391// information held in the control so that it matches the order
392// the user would expect.
393//
c854c7d9
GD
394void wxNotebook::MacSetupTabs()
395{
5ca0d812 396 m_peer->SetMaximum( GetPageCount() ) ;
5aed9d50 397
c854c7d9 398 wxNotebookPage *page;
5324268e 399 ControlTabInfoRecV1 info;
5aed9d50 400
19c43a77 401 const size_t countPages = GetPageCount();
5a7d70fe 402 for (size_t ii = 0; ii < countPages; ii++)
c854c7d9 403 {
90b959ae 404 page = m_pages[ii];
5324268e 405 info.version = kControlTabInfoVersionOne;
c854c7d9 406 info.iconSuiteID = 0;
5a7d70fe 407 wxMacCFStringHolder cflabel( page->GetLabel(), m_font.GetEncoding() ) ;
5324268e 408 info.name = cflabel ;
5a7d70fe 409 m_peer->SetData<ControlTabInfoRecV1>( ii + 1, kControlTabInfoTag, &info ) ;
20b69855 410
2b5f62a0
VZ
411 if ( GetImageList() && GetPageImage(ii) >= 0 && UMAGetSystemVersion() >= 0x1020 )
412 {
5a7d70fe 413 const wxBitmap bmap = GetImageList()->GetBitmap( GetPageImage( ii ) ) ;
b337acd7 414 if ( bmap.Ok() )
061174e3 415 {
061174e3 416 ControlButtonContentInfo info ;
20b69855 417
5a7d70fe
DS
418 wxMacCreateBitmapButton( &info, bmap ) ;
419
420 OSStatus err = m_peer->SetData<ControlButtonContentInfo>( ii + 1, kControlTabImageContentTag, &info );
061174e3 421 wxASSERT_MSG( err == noErr , wxT("Error when setting icon on tab") ) ;
5a7d70fe 422
20b69855 423 wxMacReleaseBitmapButton( &info ) ;
061174e3 424 }
2b5f62a0 425 }
5a7d70fe
DS
426
427 m_peer->SetTabEnabled( ii + 1, true ) ;
c854c7d9 428 }
5a7d70fe 429
4f74e0d1
SC
430#if wxMAC_USE_CORE_GRAPHICS
431 Refresh();
432#else
c854c7d9 433 Rect bounds;
5ca0d812 434 m_peer->GetRectInWindowCoords( &bounds ) ;
5a7d70fe 435 InvalWindowRect( (WindowRef)MacGetTopLevelWindowRef(), &bounds );
4f74e0d1 436#endif
ee6b1d97
SC
437}
438
63ff6f53
SC
439wxRect wxNotebook::GetPageRect() const
440{
facd6764 441 wxSize size = GetClientSize() ;
5a7d70fe 442
facd6764 443 return wxRect( 0 , 0 , size.x , size.y ) ;
63ff6f53 444}
5a7d70fe 445
ee6b1d97
SC
446// ----------------------------------------------------------------------------
447// wxNotebook callbacks
448// ----------------------------------------------------------------------------
449
450// @@@ OnSize() is used for setting the font when it's called for the first
451// time because doing it in ::Create() doesn't work (for unknown reasons)
452void wxNotebook::OnSize(wxSizeEvent& event)
453{
90b959ae 454 unsigned int nCount = m_pages.Count();
63ff6f53 455 wxRect rect = GetPageRect() ;
5a7d70fe
DS
456
457 for ( unsigned int nPage = 0; nPage < nCount; nPage++ )
458 {
90b959ae 459 wxNotebookPage *pPage = m_pages[nPage];
63ff6f53 460 pPage->SetSize(rect);
5a7d70fe 461 if ( pPage->GetAutoLayout() )
ee6b1d97
SC
462 pPage->Layout();
463 }
5aed9d50 464
ee6b1d97
SC
465 // Processing continues to next OnSize
466 event.Skip();
467}
468
469void wxNotebook::OnSelChange(wxNotebookEvent& event)
470{
471 // is it our tab control?
472 if ( event.GetEventObject() == this )
473 ChangePage(event.GetOldSelection(), event.GetSelection());
5aed9d50 474
ee6b1d97
SC
475 // we want to give others a chance to process this message as well
476 event.Skip();
477}
478
479void wxNotebook::OnSetFocus(wxFocusEvent& event)
480{
481 // set focus to the currently selected page if any
482 if ( m_nSelection != -1 )
90b959ae 483 m_pages[m_nSelection]->SetFocus();
5aed9d50 484
ee6b1d97
SC
485 event.Skip();
486}
487
488void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
489{
5a7d70fe
DS
490 if ( event.IsWindowChange() )
491 {
ee6b1d97 492 // change pages
5a7d70fe 493 AdvanceSelection( event.GetDirection() );
ee6b1d97 494 }
5a7d70fe
DS
495 else
496 {
461fe6e2
SC
497 // we get this event in 2 cases
498 //
499 // a) one of our pages might have generated it because the user TABbed
500 // out from it in which case we should propagate the event upwards and
501 // our parent will take care of setting the focus to prev/next sibling
502 //
503 // or
504 //
505 // b) the parent panel wants to give the focus to us so that we
506 // forward it to our selected page. We can't deal with this in
507 // OnSetFocus() because we don't know which direction the focus came
508 // from in this case and so can't choose between setting the focus to
509 // first or last panel child
510 wxWindow *parent = GetParent();
5a7d70fe
DS
511
512 // the cast is here to fix a GCC ICE
461fe6e2
SC
513 if ( ((wxWindow*)event.GetEventObject()) == parent )
514 {
515 // no, it doesn't come from child, case (b): forward to a page
516 if ( m_nSelection != -1 )
517 {
518 // so that the page knows that the event comes from it's parent
519 // and is being propagated downwards
5a7d70fe 520 event.SetEventObject( this );
461fe6e2
SC
521
522 wxWindow *page = m_pages[m_nSelection];
5a7d70fe 523 if ( !page->GetEventHandler()->ProcessEvent( event ) )
461fe6e2
SC
524 {
525 page->SetFocus();
526 }
527 //else: page manages focus inside it itself
528 }
529 else
530 {
531 // we have no pages - still have to give focus to _something_
532 SetFocus();
533 }
534 }
535 else
536 {
537 // it comes from our child, case (a), pass to the parent
5a7d70fe
DS
538 if ( parent )
539 {
540 event.SetCurrentFocus( this );
541 parent->GetEventHandler()->ProcessEvent( event );
461fe6e2 542 }
ee6b1d97
SC
543 }
544 }
545}
546
547// ----------------------------------------------------------------------------
548// wxNotebook base class virtuals
549// ----------------------------------------------------------------------------
550
461fe6e2
SC
551#if wxUSE_CONSTRAINTS
552
ee6b1d97
SC
553// override these 2 functions to do nothing: everything is done in OnSize
554
461fe6e2 555void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse))
ee6b1d97 556{
90c0f5a9 557 // don't set the sizes of the pages - their correct size is not yet known
5a7d70fe 558 wxControl::SetConstraintSizes( false );
ee6b1d97
SC
559}
560
461fe6e2 561bool wxNotebook::DoPhase(int WXUNUSED(nPhase))
ee6b1d97 562{
90c0f5a9 563 return true;
ee6b1d97
SC
564}
565
461fe6e2
SC
566#endif // wxUSE_CONSTRAINTS
567
ee6b1d97
SC
568void wxNotebook::Command(wxCommandEvent& event)
569{
427ff662 570 wxFAIL_MSG(wxT("wxNotebook::Command not implemented"));
ee6b1d97
SC
571}
572
573// ----------------------------------------------------------------------------
574// wxNotebook helper functions
575// ----------------------------------------------------------------------------
576
577// hide the currently active panel and show the new one
578void wxNotebook::ChangePage(int nOldSel, int nSel)
579{
5a7d70fe
DS
580 if (nOldSel == nSel)
581 return;
582
90c0f5a9 583 if ( nOldSel != -1 )
5a7d70fe 584 m_pages[nOldSel]->Show( false );
461fe6e2
SC
585
586 if ( nSel != -1 )
c854c7d9 587 {
90b959ae 588 wxNotebookPage *pPage = m_pages[nSel];
5a7d70fe 589 pPage->Show( true );
c854c7d9 590 pPage->SetFocus();
c854c7d9 591 }
90c0f5a9 592
ee6b1d97 593 m_nSelection = nSel;
5ca0d812 594 m_peer->SetValue( m_nSelection + 1 ) ;
ee6b1d97
SC
595}
596
90c0f5a9 597wxInt32 wxNotebook::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
799690a0 598{
4c37f124 599 OSStatus status = eventNotHandledErr ;
90c0f5a9 600
5ca0d812 601 SInt32 newSel = m_peer->GetValue() - 1 ;
4c37f124 602 if ( newSel != m_nSelection )
e40298d5 603 {
5a7d70fe
DS
604 wxNotebookEvent changing(
605 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId,
606 newSel , m_nSelection );
607 changing.SetEventObject( this );
608 GetEventHandler()->ProcessEvent( changing );
5aed9d50 609
5a7d70fe 610 if ( changing.IsAllowed() )
e40298d5 611 {
5a7d70fe
DS
612 wxNotebookEvent event(
613 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId,
614 newSel, m_nSelection );
615 event.SetEventObject( this );
616 GetEventHandler()->ProcessEvent( event );
4c37f124
SC
617 }
618 else
619 {
5ca0d812 620 m_peer->SetValue( m_nSelection + 1 ) ;
e40298d5 621 }
5a7d70fe 622
4c37f124 623 status = noErr ;
e40298d5 624 }
5a7d70fe
DS
625
626 return (wxInt32)status ;
ee6b1d97
SC
627}
628
179e085f 629#endif