]> git.saurik.com Git - wxWidgets.git/blame - src/mac/notebmac.cpp
Some doc corrections
[wxWidgets.git] / src / mac / notebmac.cpp
CommitLineData
ee6b1d97
SC
1///////////////////////////////////////////////////////////////////////////////
2// Name: notebook.cpp
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
ee6b1d97
SC
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
eb22f2a6 12#ifdef __GNUG__
e40298d5 13#pragma implementation "notebook.h"
eb22f2a6
GD
14#endif
15
ee6b1d97
SC
16// ============================================================================
17// declarations
18// ============================================================================
19
20// ----------------------------------------------------------------------------
21// headers
22// ----------------------------------------------------------------------------
799690a0 23#include "wx/app.h"
d497dca4
GD
24#include "wx/string.h"
25#include "wx/log.h"
26#include "wx/imaglist.h"
061174e3 27#include "wx/image.h"
d497dca4
GD
28#include "wx/notebook.h"
29#include "wx/mac/uma.h"
ee6b1d97
SC
30// ----------------------------------------------------------------------------
31// macros
32// ----------------------------------------------------------------------------
33
34// check that the page index is valid
19c43a77 35#define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount())
ee6b1d97 36
ee6b1d97
SC
37
38// ----------------------------------------------------------------------------
39// event table
40// ----------------------------------------------------------------------------
41
5b781a67
SC
42DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
43DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
44
ee6b1d97 45BEGIN_EVENT_TABLE(wxNotebook, wxControl)
461fe6e2
SC
46 EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange)
47 EVT_MOUSE_EVENTS(wxNotebook::OnMouse)
e40298d5 48
461fe6e2
SC
49 EVT_SIZE(wxNotebook::OnSize)
50 EVT_SET_FOCUS(wxNotebook::OnSetFocus)
51 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
ee6b1d97
SC
52END_EVENT_TABLE()
53
54IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl)
55IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent)
ee6b1d97
SC
56
57// ============================================================================
58// implementation
59// ============================================================================
60
5aed9d50
RD
61// The Appearance Manager docs show using tab controls in either edge to edge
62// mode, or inset. I think edge to edge conforms better to the other ports,
63// and inset mode is better accomplished with space around the wxNotebook rather
64// than within it. --Robin
5d3a3a5c
SC
65
66// CS : had to switch off tight spacing due to 10.3 problems
67#define wxMAC_EDGE_TO_EDGE 0
ee6b1d97 68
5aed9d50 69static inline int wxMacTabMargin(long nbStyle, long side)
ee6b1d97 70{
5aed9d50
RD
71 static int tabMargin = -1;
72 static int otherMargin = -1;
73
74 if ( tabMargin == -1)
dd47b3d3
SC
75 {
76 if ( UMAHasAquaLayout() )
77 {
5aed9d50
RD
78 tabMargin = 26; // From Appearance Manager docs for small tab control dimensions
79#if wxMAC_EDGE_TO_EDGE
80 otherMargin = 0;
81#else
82 otherMargin = 20;
83#endif
dd47b3d3
SC
84 }
85 else
86 {
5aed9d50
RD
87 tabMargin = 30;
88#if wxMAC_EDGE_TO_EDGE
89 otherMargin = 0;
90#else
91 otherMargin = 16;
92#endif
dd47b3d3 93 }
dd47b3d3 94 }
5aed9d50
RD
95
96 // If the style matches the side asked for then return the tab margin,
97 // but we have to special case wxNB_TOP since it is zero...
98 if ( side == wxNB_TOP)
99 {
feddd867 100 if ( nbStyle != 0 && nbStyle & (wxNB_LEFT|wxNB_RIGHT|wxNB_BOTTOM))
5aed9d50
RD
101 {
102 return otherMargin;
103 }
104 else
105 {
106 return tabMargin;
107 }
108 }
109 else if ( nbStyle & side)
110 return tabMargin;
111 else
112 return otherMargin;
113}
114
115static inline int wxMacTabLeftMargin(long style)
116{
117 return wxMacTabMargin(style, wxNB_LEFT);
118}
119
120static inline int wxMacTabTopMargin(long style)
121{
122 return wxMacTabMargin(style, wxNB_TOP);
123}
124
125static inline int wxMacTabRightMargin(long style)
126{
127 return wxMacTabMargin(style, wxNB_RIGHT);
128}
129
130static inline int wxMacTabBottomMargin(long style)
131{
132 return wxMacTabMargin(style, wxNB_BOTTOM);
133}
134
135// ----------------------------------------------------------------------------
136// wxNotebook construction
137// ----------------------------------------------------------------------------
138
139// common part of all ctors
140void wxNotebook::Init()
141{
dd47b3d3
SC
142 if ( UMAHasAquaLayout() )
143 {
5aed9d50 144 // Should these depend on wxMAC_EDGE_TO_EDGE too?
dd47b3d3
SC
145 m_macHorizontalBorder = 7;
146 m_macVerticalBorder = 8;
147 }
5aed9d50 148
ee6b1d97
SC
149 m_nSelection = -1;
150}
151
152// default for dynamic class
153wxNotebook::wxNotebook()
154{
155 Init();
156}
157
158// the same arguments as for wxControl
159wxNotebook::wxNotebook(wxWindow *parent,
160 wxWindowID id,
161 const wxPoint& pos,
162 const wxSize& size,
163 long style,
164 const wxString& name)
165{
166 Init();
5aed9d50 167
ee6b1d97
SC
168 Create(parent, id, pos, size, style, name);
169}
170
171// Create() function
172bool wxNotebook::Create(wxWindow *parent,
173 wxWindowID id,
174 const wxPoint& pos,
175 const wxSize& size,
176 long style,
177 const wxString& name)
178{
b45ed7a2
VZ
179 if ( !wxNotebookBase::Create(parent, id, pos, size, style, name) )
180 return false;
181
e40298d5
JS
182 Rect bounds ;
183 Str255 title ;
5aed9d50 184
427ff662 185 MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ;
5aed9d50 186
e40298d5
JS
187 int tabstyle = kControlTabSmallNorthProc ;
188 if ( HasFlag(wxNB_LEFT) )
189 tabstyle = kControlTabSmallWestProc ;
190 else if ( HasFlag( wxNB_RIGHT ) )
191 tabstyle = kControlTabSmallEastProc ;
192 else if ( HasFlag( wxNB_BOTTOM ) )
193 tabstyle = kControlTabSmallSouthProc ;
5aed9d50
RD
194
195
196 m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1,
e40298d5 197 tabstyle , (long) this ) ;
5aed9d50 198
e40298d5
JS
199 MacPostControlCreate() ;
200 return TRUE ;
ee6b1d97
SC
201}
202
203// dtor
204wxNotebook::~wxNotebook()
205{
ee6b1d97
SC
206}
207
208// ----------------------------------------------------------------------------
209// wxNotebook accessors
210// ----------------------------------------------------------------------------
90b959ae
SC
211
212void wxNotebook::SetPadding(const wxSize& padding)
213{
63ff6f53 214 // unsupported by OS
90b959ae
SC
215}
216
217void wxNotebook::SetTabSize(const wxSize& sz)
ee6b1d97 218{
63ff6f53 219 // unsupported by OS
ee6b1d97
SC
220}
221
90b959ae 222void wxNotebook::SetPageSize(const wxSize& size)
ee6b1d97 223{
63ff6f53
SC
224 SetSize( CalcSizeFromPage( size ) );
225}
226
227wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const
228{
229 wxSize sizeTotal = sizePage;
230 sizeTotal.x += 2 * m_macHorizontalBorder + wxMacTabLeftMargin(GetWindowStyle()) +
231 wxMacTabRightMargin(GetWindowStyle()) ;
232 sizeTotal.y += 2 * m_macVerticalBorder + wxMacTabTopMargin(GetWindowStyle()) +
233 wxMacTabBottomMargin(GetWindowStyle()) ;
234
235 return sizeTotal;
236}
237
238wxSize wxNotebook::DoGetBestSize() const
239{
240 // calculate the max page size
241 wxSize size(0, 0);
242
243 size_t count = GetPageCount();
244 if ( count )
245 {
246 for ( size_t n = 0; n < count; n++ )
247 {
248 wxSize sizePage = m_pages[n]->GetSize();
249
250 if ( size.x < sizePage.x )
251 size.x = sizePage.x;
252 if ( size.y < sizePage.y )
253 size.y = sizePage.y;
254 }
255 }
256 else // no pages
257 {
258 // use some arbitrary default size
259 size.x =
260 size.y = 100;
261 }
262
263 return CalcSizeFromPage(size);
ee6b1d97
SC
264}
265
8f83dfee 266int wxNotebook::SetSelection(size_t nPage)
ee6b1d97 267{
461fe6e2 268 wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") );
5aed9d50 269
461fe6e2
SC
270 if ( int(nPage) != m_nSelection )
271 {
272 wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId);
273 event.SetSelection(nPage);
274 event.SetOldSelection(m_nSelection);
275 event.SetEventObject(this);
276 if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() )
277 {
278 // program allows the page change
279 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED);
280 (void)GetEventHandler()->ProcessEvent(event);
281
282 ChangePage(m_nSelection, nPage);
283 }
284 }
5aed9d50 285
ee6b1d97
SC
286 return m_nSelection;
287}
288
8f83dfee 289bool wxNotebook::SetPageText(size_t nPage, const wxString& strText)
ee6b1d97
SC
290{
291 wxASSERT( IS_VALID_PAGE(nPage) );
5aed9d50 292
90b959ae 293 wxNotebookPage *page = m_pages[nPage];
c854c7d9
GD
294 page->SetLabel(strText);
295 MacSetupTabs();
5aed9d50 296
c854c7d9 297 return true;
ee6b1d97
SC
298}
299
8f83dfee 300wxString wxNotebook::GetPageText(size_t nPage) const
ee6b1d97
SC
301{
302 wxASSERT( IS_VALID_PAGE(nPage) );
5aed9d50 303
90b959ae 304 wxNotebookPage *page = m_pages[nPage];
c854c7d9 305 return page->GetLabel();
ee6b1d97
SC
306}
307
8f83dfee 308int wxNotebook::GetPageImage(size_t nPage) const
ee6b1d97 309{
fc0daf84 310 wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, _T("invalid notebook page") );
5aed9d50 311
2b5f62a0 312 return m_images[nPage];
ee6b1d97
SC
313}
314
19c43a77 315bool wxNotebook::SetPageImage(size_t nPage, int nImage)
ee6b1d97 316{
fc0daf84 317 wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, _T("invalid notebook page") );
5aed9d50 318
fc0daf84 319 wxCHECK_MSG( m_imageList && nImage < m_imageList->GetImageCount(), FALSE,
e40298d5 320 _T("invalid image index in SetPageImage()") );
5aed9d50 321
2b5f62a0
VZ
322 if ( nImage != m_images[nPage] )
323 {
324 // if the item didn't have an icon before or, on the contrary, did have
325 // it but has lost it now, its size will change - but if the icon just
326 // changes, it won't
327 m_images[nPage] = nImage;
5aed9d50 328
e40298d5 329 MacSetupTabs() ;
2b5f62a0 330 }
5aed9d50 331
2b5f62a0 332 return TRUE;
ee6b1d97
SC
333}
334
ee6b1d97
SC
335// ----------------------------------------------------------------------------
336// wxNotebook operations
337// ----------------------------------------------------------------------------
338
90b959ae 339// remove one page from the notebook, without deleting the window
8f83dfee 340wxNotebookPage* wxNotebook::DoRemovePage(size_t nPage)
ee6b1d97 341{
90b959ae
SC
342 wxCHECK( IS_VALID_PAGE(nPage), NULL );
343 wxNotebookPage* page = m_pages[nPage] ;
3ef585df 344 m_pages.RemoveAt(nPage);
5aed9d50 345
c854c7d9 346 MacSetupTabs();
5aed9d50 347
19c43a77 348 if(m_nSelection >= (int)GetPageCount()) {
c854c7d9
GD
349 m_nSelection = GetPageCount() - 1;
350 }
351 if(m_nSelection >= 0) {
90b959ae 352 m_pages[m_nSelection]->Show(true);
c854c7d9 353 }
90b959ae 354 return page;
ee6b1d97
SC
355}
356
357// remove all pages
358bool wxNotebook::DeleteAllPages()
359{
90b959ae 360 WX_CLEAR_ARRAY(m_pages) ;
c854c7d9 361 MacSetupTabs();
061174e3 362 m_nSelection = -1 ;
ee6b1d97
SC
363 return TRUE;
364}
365
ee6b1d97
SC
366
367// same as AddPage() but does it at given position
8f83dfee 368bool wxNotebook::InsertPage(size_t nPage,
ee6b1d97
SC
369 wxNotebookPage *pPage,
370 const wxString& strText,
371 bool bSelect,
372 int imageId)
373{
19c43a77
VZ
374 if ( !wxNotebookBase::InsertPage(nPage, pPage, strText, bSelect, imageId) )
375 return false;
5aed9d50 376
461fe6e2
SC
377 wxASSERT_MSG( pPage->GetParent() == this,
378 _T("notebook pages must have notebook as parent") );
379
380 // don't show pages by default (we'll need to adjust their size first)
381 pPage->Show( false ) ;
382
c854c7d9 383 pPage->SetLabel(strText);
5aed9d50 384
2b5f62a0 385 m_images.Insert(imageId, nPage);
5aed9d50 386
c854c7d9 387 MacSetupTabs();
5aed9d50 388
63ff6f53
SC
389 wxRect rect = GetPageRect() ;
390 pPage->SetSize(rect);
c854c7d9
GD
391 if ( pPage->GetAutoLayout() ) {
392 pPage->Layout();
393 }
5aed9d50 394
461fe6e2
SC
395
396 // now deal with the selection
397 // ---------------------------
398
399 // if the inserted page is before the selected one, we must update the
400 // index of the selected page
401
402 if ( int(nPage) <= m_nSelection )
403 {
404 m_nSelection++;
405 // while this still is the same page showing, we need to update the tabs
406 SetControl32BitValue( (ControlHandle) m_macControl , m_nSelection + 1 ) ;
407 }
408
409 // some page should be selected: either this one or the first one if there
410 // is still no selection
411 int selNew = -1;
412 if ( bSelect )
413 selNew = nPage;
414 else if ( m_nSelection == -1 )
415 selNew = 0;
416
417 if ( selNew != -1 )
418 SetSelection(selNew);
419
c854c7d9
GD
420 return true;
421}
422
423/* Added by Mark Newsam
e40298d5
JS
424* When a page is added or deleted to the notebook this function updates
425* information held in the m_macControl so that it matches the order
426* the user would expect.
427*/
c854c7d9
GD
428void wxNotebook::MacSetupTabs()
429{
467e3168 430 SetControl32BitMaximum( (ControlHandle) m_macControl , GetPageCount() ) ;
5aed9d50 431
c854c7d9
GD
432 wxNotebookPage *page;
433 ControlTabInfoRec info;
5aed9d50 434
19c43a77
VZ
435 const size_t countPages = GetPageCount();
436 for(size_t ii = 0; ii < countPages; ii++)
c854c7d9 437 {
90b959ae 438 page = m_pages[ii];
c854c7d9
GD
439 info.version = 0;
440 info.iconSuiteID = 0;
427ff662
SC
441 wxMacStringToPascal( page->GetLabel() , info.name ) ;
442
76a5e5d2 443 SetControlData( (ControlHandle) m_macControl, ii+1, kControlTabInfoTag,
e40298d5 444 sizeof( ControlTabInfoRec) , (char*) &info ) ;
2b5f62a0 445 SetTabEnabled( (ControlHandle) m_macControl , ii+1 , true ) ;
22026088 446#if TARGET_CARBON
2b5f62a0
VZ
447 if ( GetImageList() && GetPageImage(ii) >= 0 && UMAGetSystemVersion() >= 0x1020 )
448 {
e40298d5
JS
449 // tab controls only support very specific types of images, therefore we are doing an odyssee
450 // accross the icon worlds (even Apple DTS did not find a shorter path)
451 // in order not to pollute the icon registry we put every icon into (OSType) 1 and immediately
5aed9d50 452 // afterwards Unregister it (IconRef is ref counted, so it will stay on the tab even if we
e40298d5 453 // unregister it) in case this will ever lead to having the same icon everywhere add some kind
5aed9d50 454 // of static counter
69efd83d 455 const wxBitmap* bmap = GetImageList()->GetBitmap( GetPageImage(ii ) ) ;
061174e3
SC
456 if ( bmap )
457 {
458 wxBitmap scaledBitmap ;
459 if ( bmap->GetWidth() != 16 || bmap->GetHeight() != 16 )
460 {
461 scaledBitmap = wxBitmap( bmap->ConvertToImage().Scale(16,16) ) ;
462 bmap = &scaledBitmap ;
463 }
464 ControlButtonContentInfo info ;
465 wxMacCreateBitmapButton( &info , *bmap , kControlContentPictHandle) ;
466 IconFamilyHandle iconFamily = (IconFamilyHandle) NewHandle(0) ;
467 OSErr err = SetIconFamilyData( iconFamily, 'PICT' , (Handle) info.u.picture ) ;
468 wxASSERT_MSG( err == noErr , wxT("Error when adding bitmap") ) ;
469 IconRef iconRef ;
d5f7923b 470 err = RegisterIconRefFromIconFamily( 'WXNG' , (OSType) 1, iconFamily, &iconRef ) ;
061174e3
SC
471 wxASSERT_MSG( err == noErr , wxT("Error when adding bitmap") ) ;
472 info.contentType = kControlContentIconRef ;
473 info.u.iconRef = iconRef ;
474 SetControlData( (ControlHandle) m_macControl, ii+1,kControlTabImageContentTag,
475 sizeof( info ), (Ptr)&info );
476 wxASSERT_MSG( err == noErr , wxT("Error when setting icon on tab") ) ;
d8c59747 477 if ( UMAGetSystemVersion() < 0x1030 )
d5f7923b
SC
478 {
479 UnregisterIconRef( 'WXNG' , (OSType) 1 ) ;
480 }
481
061174e3
SC
482 ReleaseIconRef( iconRef ) ;
483 DisposeHandle( (Handle) iconFamily ) ;
484 }
2b5f62a0
VZ
485 }
486#endif
c854c7d9
GD
487 }
488 Rect bounds;
76a5e5d2
SC
489 GetControlBounds((ControlHandle)m_macControl, &bounds);
490 InvalWindowRect((WindowRef)MacGetRootWindow(), &bounds);
ee6b1d97
SC
491}
492
63ff6f53
SC
493wxRect wxNotebook::GetPageRect() const
494{
495 // fit the notebook page to the tab control's display area
496 int w, h;
497 GetSize(&w, &h);
498
499 return wxRect(
500 wxMacTabLeftMargin(GetWindowStyle()) + m_macHorizontalBorder,
501 wxMacTabTopMargin(GetWindowStyle()) + m_macVerticalBorder,
502 w - wxMacTabLeftMargin(GetWindowStyle()) - wxMacTabRightMargin(GetWindowStyle()) - 2*m_macHorizontalBorder,
503 h - wxMacTabTopMargin(GetWindowStyle()) - wxMacTabBottomMargin(GetWindowStyle()) - 2*m_macVerticalBorder);
504}
ee6b1d97
SC
505// ----------------------------------------------------------------------------
506// wxNotebook callbacks
507// ----------------------------------------------------------------------------
508
509// @@@ OnSize() is used for setting the font when it's called for the first
510// time because doing it in ::Create() doesn't work (for unknown reasons)
511void wxNotebook::OnSize(wxSizeEvent& event)
512{
5aed9d50 513
90b959ae 514 unsigned int nCount = m_pages.Count();
63ff6f53 515 wxRect rect = GetPageRect() ;
ee6b1d97 516 for ( unsigned int nPage = 0; nPage < nCount; nPage++ ) {
90b959ae 517 wxNotebookPage *pPage = m_pages[nPage];
63ff6f53 518 pPage->SetSize(rect);
c854c7d9 519 if ( pPage->GetAutoLayout() ) {
ee6b1d97 520 pPage->Layout();
c854c7d9 521 }
ee6b1d97 522 }
5aed9d50 523
ee6b1d97
SC
524 // Processing continues to next OnSize
525 event.Skip();
526}
527
528void wxNotebook::OnSelChange(wxNotebookEvent& event)
529{
530 // is it our tab control?
531 if ( event.GetEventObject() == this )
532 ChangePage(event.GetOldSelection(), event.GetSelection());
5aed9d50 533
ee6b1d97
SC
534 // we want to give others a chance to process this message as well
535 event.Skip();
536}
537
538void wxNotebook::OnSetFocus(wxFocusEvent& event)
539{
540 // set focus to the currently selected page if any
541 if ( m_nSelection != -1 )
90b959ae 542 m_pages[m_nSelection]->SetFocus();
5aed9d50 543
ee6b1d97
SC
544 event.Skip();
545}
546
547void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
548{
549 if ( event.IsWindowChange() ) {
550 // change pages
551 AdvanceSelection(event.GetDirection());
552 }
553 else {
461fe6e2
SC
554 // we get this event in 2 cases
555 //
556 // a) one of our pages might have generated it because the user TABbed
557 // out from it in which case we should propagate the event upwards and
558 // our parent will take care of setting the focus to prev/next sibling
559 //
560 // or
561 //
562 // b) the parent panel wants to give the focus to us so that we
563 // forward it to our selected page. We can't deal with this in
564 // OnSetFocus() because we don't know which direction the focus came
565 // from in this case and so can't choose between setting the focus to
566 // first or last panel child
567 wxWindow *parent = GetParent();
568 // the cast is here to fic a GCC ICE
569 if ( ((wxWindow*)event.GetEventObject()) == parent )
570 {
571 // no, it doesn't come from child, case (b): forward to a page
572 if ( m_nSelection != -1 )
573 {
574 // so that the page knows that the event comes from it's parent
575 // and is being propagated downwards
576 event.SetEventObject(this);
577
578 wxWindow *page = m_pages[m_nSelection];
579 if ( !page->GetEventHandler()->ProcessEvent(event) )
580 {
581 page->SetFocus();
582 }
583 //else: page manages focus inside it itself
584 }
585 else
586 {
587 // we have no pages - still have to give focus to _something_
588 SetFocus();
589 }
590 }
591 else
592 {
593 // it comes from our child, case (a), pass to the parent
594 if ( parent ) {
595 event.SetCurrentFocus(this);
596 parent->GetEventHandler()->ProcessEvent(event);
597 }
ee6b1d97
SC
598 }
599 }
600}
601
602// ----------------------------------------------------------------------------
603// wxNotebook base class virtuals
604// ----------------------------------------------------------------------------
605
461fe6e2
SC
606#if wxUSE_CONSTRAINTS
607
ee6b1d97
SC
608// override these 2 functions to do nothing: everything is done in OnSize
609
461fe6e2 610void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse))
ee6b1d97 611{
461fe6e2
SC
612 // don't set the sizes of the pages - their correct size is not yet known
613 wxControl::SetConstraintSizes(FALSE);
ee6b1d97
SC
614}
615
461fe6e2 616bool wxNotebook::DoPhase(int WXUNUSED(nPhase))
ee6b1d97 617{
461fe6e2 618 return TRUE;
ee6b1d97
SC
619}
620
461fe6e2
SC
621#endif // wxUSE_CONSTRAINTS
622
ee6b1d97
SC
623void wxNotebook::Command(wxCommandEvent& event)
624{
427ff662 625 wxFAIL_MSG(wxT("wxNotebook::Command not implemented"));
ee6b1d97
SC
626}
627
628// ----------------------------------------------------------------------------
629// wxNotebook helper functions
630// ----------------------------------------------------------------------------
631
632// hide the currently active panel and show the new one
633void wxNotebook::ChangePage(int nOldSel, int nSel)
634{
461fe6e2
SC
635 if ( nOldSel != -1 )
636 {
637 m_pages[nOldSel]->Show(FALSE);
638 }
639
640 if ( nSel != -1 )
c854c7d9 641 {
90b959ae 642 wxNotebookPage *pPage = m_pages[nSel];
c854c7d9
GD
643 pPage->Show(TRUE);
644 pPage->SetFocus();
c854c7d9 645 }
461fe6e2 646
ee6b1d97 647 m_nSelection = nSel;
461fe6e2 648 SetControl32BitValue( (ControlHandle) m_macControl , m_nSelection + 1 ) ;
ee6b1d97
SC
649}
650
799690a0
SC
651
652void wxNotebook::OnMouse( wxMouseEvent &event )
653{
e40298d5
JS
654 if ( (ControlHandle) m_macControl == NULL )
655 {
656 event.Skip() ;
657 return ;
658 }
5aed9d50 659
e40298d5
JS
660 if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
661 {
662 int x = event.m_x ;
663 int y = event.m_y ;
5aed9d50 664
e40298d5 665 MacClientToRootWindow( &x , &y ) ;
5aed9d50 666
e40298d5
JS
667 ControlHandle control ;
668 Point localwhere ;
669 SInt16 controlpart ;
5aed9d50 670
e40298d5
JS
671 localwhere.h = x ;
672 localwhere.v = y ;
5aed9d50 673
e40298d5 674 short modifiers = 0;
5aed9d50 675
e40298d5
JS
676 if ( !event.m_leftDown && !event.m_rightDown )
677 modifiers |= btnState ;
5aed9d50 678
e40298d5
JS
679 if ( event.m_shiftDown )
680 modifiers |= shiftKey ;
5aed9d50 681
e40298d5
JS
682 if ( event.m_controlDown )
683 modifiers |= controlKey ;
5aed9d50 684
e40298d5
JS
685 if ( event.m_altDown )
686 modifiers |= optionKey ;
5aed9d50 687
e40298d5
JS
688 if ( event.m_metaDown )
689 modifiers |= cmdKey ;
5aed9d50 690
e40298d5
JS
691 control = (ControlHandle) m_macControl ;
692 if ( control && ::IsControlActive( control ) )
693 {
694 {
695 wxNotebookEvent changing(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId,
696 ::GetControl32BitValue(control) - 1, m_nSelection);
697 changing.SetEventObject(this);
55da8bd1 698 GetEventHandler()->ProcessEvent(changing);
5aed9d50 699
e40298d5
JS
700 if(changing.IsAllowed())
701 {
702 controlpart = ::HandleControlClick(control, localwhere, modifiers,
703 (ControlActionUPP) -1);
704 wxTheApp->s_lastMouseDown = 0 ;
5aed9d50 705
e40298d5
JS
706 wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId,
707 ::GetControl32BitValue(control) - 1, m_nSelection);
708 event.SetEventObject(this);
5aed9d50 709
55da8bd1 710 GetEventHandler()->ProcessEvent(event);
e40298d5
JS
711 }
712 }
713 }
714 }
799690a0 715}
e40298d5 716
799690a0 717
4b26b60f 718void wxNotebook::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
ee6b1d97 719{
799690a0 720#if 0
e40298d5
JS
721 wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId , ::GetControl32BitValue((ControlHandle)m_macControl) - 1, m_nSelection);
722 event.SetEventObject(this);
5aed9d50 723
e40298d5 724 ProcessEvent(event);
799690a0 725#endif
ee6b1d97
SC
726}
727