]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/notebmac.cpp
The Great wxRegion Refactoring:
[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
8f83dfee 163int wxNotebook::SetSelection(size_t nPage)
ee6b1d97 164{
5a7d70fe 165 wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("SetSelection: invalid notebook page") );
5aed9d50 166
461fe6e2
SC
167 if ( int(nPage) != m_nSelection )
168 {
169 wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId);
170 event.SetSelection(nPage);
171 event.SetOldSelection(m_nSelection);
172 event.SetEventObject(this);
173 if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() )
174 {
175 // program allows the page change
176 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED);
177 (void)GetEventHandler()->ProcessEvent(event);
178
179 ChangePage(m_nSelection, nPage);
180 }
181 }
5aed9d50 182
ee6b1d97
SC
183 return m_nSelection;
184}
185
8f83dfee 186bool wxNotebook::SetPageText(size_t nPage, const wxString& strText)
ee6b1d97 187{
5a7d70fe 188 wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("SetPageText: invalid notebook page") );
5aed9d50 189
90b959ae 190 wxNotebookPage *page = m_pages[nPage];
c854c7d9
GD
191 page->SetLabel(strText);
192 MacSetupTabs();
5aed9d50 193
c854c7d9 194 return true;
ee6b1d97
SC
195}
196
8f83dfee 197wxString wxNotebook::GetPageText(size_t nPage) const
ee6b1d97 198{
5a7d70fe 199 wxCHECK_MSG( IS_VALID_PAGE(nPage), wxEmptyString, wxT("GetPageText: invalid notebook page") );
5aed9d50 200
90b959ae 201 wxNotebookPage *page = m_pages[nPage];
5a7d70fe 202
c854c7d9 203 return page->GetLabel();
ee6b1d97
SC
204}
205
8f83dfee 206int wxNotebook::GetPageImage(size_t nPage) const
ee6b1d97 207{
5a7d70fe 208 wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("GetPageImage: invalid notebook page") );
5aed9d50 209
2b5f62a0 210 return m_images[nPage];
ee6b1d97
SC
211}
212
19c43a77 213bool wxNotebook::SetPageImage(size_t nPage, int nImage)
ee6b1d97 214{
5a7d70fe
DS
215 wxCHECK_MSG( IS_VALID_PAGE(nPage), false,
216 wxT("SetPageImage: invalid notebook page") );
90c0f5a9 217 wxCHECK_MSG( m_imageList && nImage < m_imageList->GetImageCount(), false,
5a7d70fe 218 wxT("SetPageImage: invalid image index") );
5aed9d50 219
2b5f62a0
VZ
220 if ( nImage != m_images[nPage] )
221 {
222 // if the item didn't have an icon before or, on the contrary, did have
223 // it but has lost it now, its size will change - but if the icon just
224 // changes, it won't
225 m_images[nPage] = nImage;
5aed9d50 226
e40298d5 227 MacSetupTabs() ;
2b5f62a0 228 }
5aed9d50 229
90c0f5a9 230 return true;
ee6b1d97
SC
231}
232
ee6b1d97
SC
233// ----------------------------------------------------------------------------
234// wxNotebook operations
235// ----------------------------------------------------------------------------
236
90b959ae 237// remove one page from the notebook, without deleting the window
8f83dfee 238wxNotebookPage* wxNotebook::DoRemovePage(size_t nPage)
ee6b1d97 239{
5a7d70fe
DS
240 wxCHECK_MSG( IS_VALID_PAGE(nPage), NULL,
241 wxT("DoRemovePage: invalid notebook page") );
242
90b959ae 243 wxNotebookPage* page = m_pages[nPage] ;
3ef585df 244 m_pages.RemoveAt(nPage);
5aed9d50 245
c854c7d9 246 MacSetupTabs();
5aed9d50 247
5a7d70fe 248 if (m_nSelection >= (int)GetPageCount())
c854c7d9 249 m_nSelection = GetPageCount() - 1;
5a7d70fe
DS
250
251 if (m_nSelection >= 0)
90b959ae 252 m_pages[m_nSelection]->Show(true);
5a7d70fe 253
37144cf0 254 InvalidateBestSize();
5a7d70fe 255
90b959ae 256 return page;
ee6b1d97
SC
257}
258
259// remove all pages
260bool wxNotebook::DeleteAllPages()
261{
90b959ae 262 WX_CLEAR_ARRAY(m_pages) ;
c854c7d9 263 MacSetupTabs();
061174e3 264 m_nSelection = -1 ;
37144cf0 265 InvalidateBestSize();
5a7d70fe 266
90c0f5a9 267 return true;
ee6b1d97
SC
268}
269
ee6b1d97 270// same as AddPage() but does it at given position
8f83dfee 271bool wxNotebook::InsertPage(size_t nPage,
5a7d70fe
DS
272 wxNotebookPage *pPage,
273 const wxString& strText,
274 bool bSelect,
275 int imageId )
ee6b1d97 276{
5a7d70fe 277 if ( !wxNotebookBase::InsertPage( nPage, pPage, strText, bSelect, imageId ) )
19c43a77 278 return false;
5aed9d50 279
5a7d70fe 280 wxASSERT_MSG( pPage->GetParent() == this, wxT("notebook pages must have notebook as parent") );
461fe6e2
SC
281
282 // don't show pages by default (we'll need to adjust their size first)
283 pPage->Show( false ) ;
284
5a7d70fe 285 pPage->SetLabel( strText );
5aed9d50 286
5a7d70fe 287 m_images.Insert( imageId, nPage );
5aed9d50 288
c854c7d9 289 MacSetupTabs();
5aed9d50 290
63ff6f53 291 wxRect rect = GetPageRect() ;
5a7d70fe
DS
292 pPage->SetSize( rect );
293 if ( pPage->GetAutoLayout() )
c854c7d9 294 pPage->Layout();
461fe6e2
SC
295
296 // now deal with the selection
297 // ---------------------------
298
299 // if the inserted page is before the selected one, we must update the
300 // index of the selected page
301
90c0f5a9 302 if ( int(nPage) <= m_nSelection )
461fe6e2
SC
303 {
304 m_nSelection++;
5a7d70fe 305
461fe6e2 306 // while this still is the same page showing, we need to update the tabs
5ca0d812 307 m_peer->SetValue( m_nSelection + 1 ) ;
461fe6e2 308 }
90c0f5a9 309
461fe6e2
SC
310 // some page should be selected: either this one or the first one if there
311 // is still no selection
312 int selNew = -1;
313 if ( bSelect )
314 selNew = nPage;
315 else if ( m_nSelection == -1 )
316 selNew = 0;
317
318 if ( selNew != -1 )
5a7d70fe 319 SetSelection( selNew );
461fe6e2 320
37144cf0 321 InvalidateBestSize();
5a7d70fe 322
c854c7d9
GD
323 return true;
324}
325
3c3e6970
SC
326int wxNotebook::HitTest(const wxPoint& pt, long * flags) const
327{
fe224552 328 int resultV = wxNOT_FOUND;
5a7d70fe 329
3c3e6970 330#if TARGET_API_MAC_OSX
5a7d70fe 331 const int countPages = GetPageCount();
fe224552 332
2fbfb7d6 333 // we have to convert from Client to Window relative coordinates
df91131c 334 wxPoint adjustedPt = pt + GetClientAreaOrigin();
2fbfb7d6
SC
335 // and now to HIView native ones
336 adjustedPt.x -= MacGetLeftBorderSize() ;
337 adjustedPt.y -= MacGetTopBorderSize() ;
df91131c 338
2fbfb7d6 339 HIPoint hipoint= { adjustedPt.x , adjustedPt.y } ;
3c3e6970 340 HIViewPartCode outPart = 0 ;
5a7d70fe 341 OSStatus err = HIViewGetPartHit( m_peer->GetControlRef(), &hipoint, &outPart );
fe224552 342
0df4335d 343 int max = m_peer->GetMaximum() ;
3c3e6970
SC
344 if ( outPart == 0 && max > 0 )
345 {
346 // this is a hack, as unfortunately a hit on an already selected tab returns 0,
fe224552 347 // so we have to go some extra miles to make sure we select something different
3c3e6970 348 // and try again ..
0df4335d 349 int val = m_peer->GetValue() ;
3c3e6970
SC
350 int maxval = max ;
351 if ( max == 1 )
352 {
0df4335d 353 m_peer->SetMaximum( 2 ) ;
3c3e6970
SC
354 maxval = 2 ;
355 }
356
357 if ( val == 1 )
0df4335d 358 m_peer->SetValue( maxval ) ;
3c3e6970 359 else
0df4335d 360 m_peer->SetValue( 1 ) ;
fe224552 361
5a7d70fe 362 err = HIViewGetPartHit( m_peer->GetControlRef(), &hipoint, &outPart );
fe224552 363
0df4335d 364 m_peer->SetValue( val ) ;
3c3e6970 365 if ( max == 1 )
0df4335d 366 m_peer->SetMaximum( 1 ) ;
3c3e6970 367 }
fe224552
VZ
368
369 if ( outPart >= 1 && outPart <= countPages )
eb5d9594 370 resultV = outPart - 1 ;
f885b815
VZ
371#endif // TARGET_API_MAC_OSX
372
3c3e6970
SC
373 if (flags != NULL)
374 {
375 *flags = 0;
fe224552 376
3c3e6970 377 // we cannot differentiate better
eb5d9594 378 if (resultV >= 0)
9804d540 379 *flags |= wxBK_HITTEST_ONLABEL;
3c3e6970 380 else
9804d540 381 *flags |= wxBK_HITTEST_NOWHERE;
3c3e6970 382 }
5a7d70fe 383
3c3e6970
SC
384 return resultV;
385}
386
5a7d70fe
DS
387// Added by Mark Newsam
388// When a page is added or deleted to the notebook this function updates
389// information held in the control so that it matches the order
390// the user would expect.
391//
c854c7d9
GD
392void wxNotebook::MacSetupTabs()
393{
5ca0d812 394 m_peer->SetMaximum( GetPageCount() ) ;
5aed9d50 395
c854c7d9 396 wxNotebookPage *page;
5324268e 397 ControlTabInfoRecV1 info;
5aed9d50 398
19c43a77 399 const size_t countPages = GetPageCount();
5a7d70fe 400 for (size_t ii = 0; ii < countPages; ii++)
c854c7d9 401 {
90b959ae 402 page = m_pages[ii];
5324268e 403 info.version = kControlTabInfoVersionOne;
c854c7d9 404 info.iconSuiteID = 0;
5a7d70fe 405 wxMacCFStringHolder cflabel( page->GetLabel(), m_font.GetEncoding() ) ;
5324268e 406 info.name = cflabel ;
5a7d70fe 407 m_peer->SetData<ControlTabInfoRecV1>( ii + 1, kControlTabInfoTag, &info ) ;
20b69855 408
2b5f62a0
VZ
409 if ( GetImageList() && GetPageImage(ii) >= 0 && UMAGetSystemVersion() >= 0x1020 )
410 {
5a7d70fe 411 const wxBitmap bmap = GetImageList()->GetBitmap( GetPageImage( ii ) ) ;
b337acd7 412 if ( bmap.Ok() )
061174e3 413 {
061174e3 414 ControlButtonContentInfo info ;
20b69855 415
5a7d70fe
DS
416 wxMacCreateBitmapButton( &info, bmap ) ;
417
418 OSStatus err = m_peer->SetData<ControlButtonContentInfo>( ii + 1, kControlTabImageContentTag, &info );
061174e3 419 wxASSERT_MSG( err == noErr , wxT("Error when setting icon on tab") ) ;
5a7d70fe 420
20b69855 421 wxMacReleaseBitmapButton( &info ) ;
061174e3 422 }
2b5f62a0 423 }
5a7d70fe
DS
424
425 m_peer->SetTabEnabled( ii + 1, true ) ;
c854c7d9 426 }
5a7d70fe 427
c854c7d9 428 Rect bounds;
5ca0d812 429 m_peer->GetRectInWindowCoords( &bounds ) ;
5a7d70fe 430 InvalWindowRect( (WindowRef)MacGetTopLevelWindowRef(), &bounds );
ee6b1d97
SC
431}
432
63ff6f53
SC
433wxRect wxNotebook::GetPageRect() const
434{
facd6764 435 wxSize size = GetClientSize() ;
5a7d70fe 436
facd6764 437 return wxRect( 0 , 0 , size.x , size.y ) ;
63ff6f53 438}
5a7d70fe 439
ee6b1d97
SC
440// ----------------------------------------------------------------------------
441// wxNotebook callbacks
442// ----------------------------------------------------------------------------
443
444// @@@ OnSize() is used for setting the font when it's called for the first
445// time because doing it in ::Create() doesn't work (for unknown reasons)
446void wxNotebook::OnSize(wxSizeEvent& event)
447{
90b959ae 448 unsigned int nCount = m_pages.Count();
63ff6f53 449 wxRect rect = GetPageRect() ;
5a7d70fe
DS
450
451 for ( unsigned int nPage = 0; nPage < nCount; nPage++ )
452 {
90b959ae 453 wxNotebookPage *pPage = m_pages[nPage];
63ff6f53 454 pPage->SetSize(rect);
5a7d70fe 455 if ( pPage->GetAutoLayout() )
ee6b1d97
SC
456 pPage->Layout();
457 }
5aed9d50 458
ee6b1d97
SC
459 // Processing continues to next OnSize
460 event.Skip();
461}
462
463void wxNotebook::OnSelChange(wxNotebookEvent& event)
464{
465 // is it our tab control?
466 if ( event.GetEventObject() == this )
467 ChangePage(event.GetOldSelection(), event.GetSelection());
5aed9d50 468
ee6b1d97
SC
469 // we want to give others a chance to process this message as well
470 event.Skip();
471}
472
473void wxNotebook::OnSetFocus(wxFocusEvent& event)
474{
475 // set focus to the currently selected page if any
476 if ( m_nSelection != -1 )
90b959ae 477 m_pages[m_nSelection]->SetFocus();
5aed9d50 478
ee6b1d97
SC
479 event.Skip();
480}
481
482void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
483{
5a7d70fe
DS
484 if ( event.IsWindowChange() )
485 {
ee6b1d97 486 // change pages
5a7d70fe 487 AdvanceSelection( event.GetDirection() );
ee6b1d97 488 }
5a7d70fe
DS
489 else
490 {
461fe6e2
SC
491 // we get this event in 2 cases
492 //
493 // a) one of our pages might have generated it because the user TABbed
494 // out from it in which case we should propagate the event upwards and
495 // our parent will take care of setting the focus to prev/next sibling
496 //
497 // or
498 //
499 // b) the parent panel wants to give the focus to us so that we
500 // forward it to our selected page. We can't deal with this in
501 // OnSetFocus() because we don't know which direction the focus came
502 // from in this case and so can't choose between setting the focus to
503 // first or last panel child
504 wxWindow *parent = GetParent();
5a7d70fe
DS
505
506 // the cast is here to fix a GCC ICE
461fe6e2
SC
507 if ( ((wxWindow*)event.GetEventObject()) == parent )
508 {
509 // no, it doesn't come from child, case (b): forward to a page
510 if ( m_nSelection != -1 )
511 {
512 // so that the page knows that the event comes from it's parent
513 // and is being propagated downwards
5a7d70fe 514 event.SetEventObject( this );
461fe6e2
SC
515
516 wxWindow *page = m_pages[m_nSelection];
5a7d70fe 517 if ( !page->GetEventHandler()->ProcessEvent( event ) )
461fe6e2
SC
518 {
519 page->SetFocus();
520 }
521 //else: page manages focus inside it itself
522 }
523 else
524 {
525 // we have no pages - still have to give focus to _something_
526 SetFocus();
527 }
528 }
529 else
530 {
531 // it comes from our child, case (a), pass to the parent
5a7d70fe
DS
532 if ( parent )
533 {
534 event.SetCurrentFocus( this );
535 parent->GetEventHandler()->ProcessEvent( event );
461fe6e2 536 }
ee6b1d97
SC
537 }
538 }
539}
540
541// ----------------------------------------------------------------------------
542// wxNotebook base class virtuals
543// ----------------------------------------------------------------------------
544
461fe6e2
SC
545#if wxUSE_CONSTRAINTS
546
ee6b1d97
SC
547// override these 2 functions to do nothing: everything is done in OnSize
548
461fe6e2 549void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse))
ee6b1d97 550{
90c0f5a9 551 // don't set the sizes of the pages - their correct size is not yet known
5a7d70fe 552 wxControl::SetConstraintSizes( false );
ee6b1d97
SC
553}
554
461fe6e2 555bool wxNotebook::DoPhase(int WXUNUSED(nPhase))
ee6b1d97 556{
90c0f5a9 557 return true;
ee6b1d97
SC
558}
559
461fe6e2
SC
560#endif // wxUSE_CONSTRAINTS
561
ee6b1d97
SC
562void wxNotebook::Command(wxCommandEvent& event)
563{
427ff662 564 wxFAIL_MSG(wxT("wxNotebook::Command not implemented"));
ee6b1d97
SC
565}
566
567// ----------------------------------------------------------------------------
568// wxNotebook helper functions
569// ----------------------------------------------------------------------------
570
571// hide the currently active panel and show the new one
572void wxNotebook::ChangePage(int nOldSel, int nSel)
573{
5a7d70fe
DS
574 if (nOldSel == nSel)
575 return;
576
90c0f5a9 577 if ( nOldSel != -1 )
5a7d70fe 578 m_pages[nOldSel]->Show( false );
461fe6e2
SC
579
580 if ( nSel != -1 )
c854c7d9 581 {
90b959ae 582 wxNotebookPage *pPage = m_pages[nSel];
5a7d70fe 583 pPage->Show( true );
c854c7d9 584 pPage->SetFocus();
c854c7d9 585 }
90c0f5a9 586
ee6b1d97 587 m_nSelection = nSel;
5ca0d812 588 m_peer->SetValue( m_nSelection + 1 ) ;
ee6b1d97
SC
589}
590
90c0f5a9 591wxInt32 wxNotebook::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
799690a0 592{
4c37f124 593 OSStatus status = eventNotHandledErr ;
90c0f5a9 594
5ca0d812 595 SInt32 newSel = m_peer->GetValue() - 1 ;
4c37f124 596 if ( newSel != m_nSelection )
e40298d5 597 {
5a7d70fe
DS
598 wxNotebookEvent changing(
599 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId,
600 newSel , m_nSelection );
601 changing.SetEventObject( this );
602 GetEventHandler()->ProcessEvent( changing );
5aed9d50 603
5a7d70fe 604 if ( changing.IsAllowed() )
e40298d5 605 {
5a7d70fe
DS
606 wxNotebookEvent event(
607 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId,
608 newSel, m_nSelection );
609 event.SetEventObject( this );
610 GetEventHandler()->ProcessEvent( event );
4c37f124
SC
611 }
612 else
613 {
5ca0d812 614 m_peer->SetValue( m_nSelection + 1 ) ;
e40298d5 615 }
5a7d70fe 616
4c37f124 617 status = noErr ;
e40298d5 618 }
5a7d70fe
DS
619
620 return (wxInt32)status ;
ee6b1d97
SC
621}
622
179e085f 623#endif