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