]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: notebook.cpp | |
3 | // Purpose: implementation of wxNotebook | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "notebook.h" | |
14 | #endif | |
15 | ||
16 | // ============================================================================ | |
17 | // declarations | |
18 | // ============================================================================ | |
19 | ||
20 | // ---------------------------------------------------------------------------- | |
21 | // headers | |
22 | // ---------------------------------------------------------------------------- | |
23 | #include "wx/app.h" | |
24 | #include "wx/string.h" | |
25 | #include "wx/log.h" | |
26 | #include "wx/imaglist.h" | |
27 | #include "wx/image.h" | |
28 | #include "wx/notebook.h" | |
29 | #include "wx/mac/uma.h" | |
30 | // ---------------------------------------------------------------------------- | |
31 | // macros | |
32 | // ---------------------------------------------------------------------------- | |
33 | ||
34 | // check that the page index is valid | |
35 | #define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount()) | |
36 | ||
37 | ||
38 | // ---------------------------------------------------------------------------- | |
39 | // event table | |
40 | // ---------------------------------------------------------------------------- | |
41 | ||
42 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED) | |
43 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING) | |
44 | ||
45 | BEGIN_EVENT_TABLE(wxNotebook, wxControl) | |
46 | EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange) | |
47 | EVT_MOUSE_EVENTS(wxNotebook::OnMouse) | |
48 | ||
49 | EVT_SIZE(wxNotebook::OnSize) | |
50 | EVT_SET_FOCUS(wxNotebook::OnSetFocus) | |
51 | EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) | |
52 | END_EVENT_TABLE() | |
53 | ||
54 | IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl) | |
55 | IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent) | |
56 | ||
57 | // ============================================================================ | |
58 | // implementation | |
59 | // ============================================================================ | |
60 | ||
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 | |
66 | ||
67 | static inline int wxMacTabMargin(long nbStyle, long side) | |
68 | { | |
69 | static int tabMargin = -1; | |
70 | static int otherMargin = -1; | |
71 | ||
72 | if ( tabMargin == -1) | |
73 | { | |
74 | if ( UMAHasAquaLayout() ) | |
75 | { | |
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 | |
82 | } | |
83 | else | |
84 | { | |
85 | tabMargin = 30; | |
86 | #if wxMAC_EDGE_TO_EDGE | |
87 | otherMargin = 0; | |
88 | #else | |
89 | otherMargin = 16; | |
90 | #endif | |
91 | } | |
92 | } | |
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 | { | |
98 | if ( nbStyle != 0 && nbStyle & (wxNB_LEFT|wxNB_RIGHT|wxNB_BOTTOM)) | |
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 | ||
113 | static inline int wxMacTabLeftMargin(long style) | |
114 | { | |
115 | return wxMacTabMargin(style, wxNB_LEFT); | |
116 | } | |
117 | ||
118 | static inline int wxMacTabTopMargin(long style) | |
119 | { | |
120 | return wxMacTabMargin(style, wxNB_TOP); | |
121 | } | |
122 | ||
123 | static inline int wxMacTabRightMargin(long style) | |
124 | { | |
125 | return wxMacTabMargin(style, wxNB_RIGHT); | |
126 | } | |
127 | ||
128 | static 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 | |
138 | void wxNotebook::Init() | |
139 | { | |
140 | if ( UMAHasAquaLayout() ) | |
141 | { | |
142 | // Should these depend on wxMAC_EDGE_TO_EDGE too? | |
143 | m_macHorizontalBorder = 7; | |
144 | m_macVerticalBorder = 8; | |
145 | } | |
146 | ||
147 | m_nSelection = -1; | |
148 | } | |
149 | ||
150 | // default for dynamic class | |
151 | wxNotebook::wxNotebook() | |
152 | { | |
153 | Init(); | |
154 | } | |
155 | ||
156 | // the same arguments as for wxControl | |
157 | wxNotebook::wxNotebook(wxWindow *parent, | |
158 | wxWindowID id, | |
159 | const wxPoint& pos, | |
160 | const wxSize& size, | |
161 | long style, | |
162 | const wxString& name) | |
163 | { | |
164 | Init(); | |
165 | ||
166 | Create(parent, id, pos, size, style, name); | |
167 | } | |
168 | ||
169 | // Create() function | |
170 | bool wxNotebook::Create(wxWindow *parent, | |
171 | wxWindowID id, | |
172 | const wxPoint& pos, | |
173 | const wxSize& size, | |
174 | long style, | |
175 | const wxString& name) | |
176 | { | |
177 | if ( !wxNotebookBase::Create(parent, id, pos, size, style, name) ) | |
178 | return false; | |
179 | ||
180 | Rect bounds ; | |
181 | Str255 title ; | |
182 | ||
183 | MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ; | |
184 | ||
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 ; | |
192 | ||
193 | ||
194 | m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, | |
195 | tabstyle , (long) this ) ; | |
196 | ||
197 | MacPostControlCreate() ; | |
198 | return TRUE ; | |
199 | } | |
200 | ||
201 | // dtor | |
202 | wxNotebook::~wxNotebook() | |
203 | { | |
204 | } | |
205 | ||
206 | wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const | |
207 | { | |
208 | wxSize sizeTotal = sizePage; | |
209 | ||
210 | int major,minor; | |
211 | wxGetOsVersion( &major, &minor ); | |
212 | ||
213 | // Mac has large notebook borders. Aqua even more so. | |
214 | ||
215 | if ( HasFlag(wxNB_LEFT) || HasFlag(wxNB_RIGHT) ) | |
216 | { | |
217 | sizeTotal.x += 90; | |
218 | ||
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 | } | |
237 | ||
238 | return sizeTotal; | |
239 | } | |
240 | ||
241 | // ---------------------------------------------------------------------------- | |
242 | // wxNotebook accessors | |
243 | // ---------------------------------------------------------------------------- | |
244 | ||
245 | void wxNotebook::SetPadding(const wxSize& padding) | |
246 | { | |
247 | wxFAIL_MSG( wxT("wxNotebook::SetPadding not implemented") ); | |
248 | } | |
249 | ||
250 | void wxNotebook::SetTabSize(const wxSize& sz) | |
251 | { | |
252 | wxFAIL_MSG( wxT("wxNotebook::SetTabSize not implemented") ); | |
253 | } | |
254 | ||
255 | void wxNotebook::SetPageSize(const wxSize& size) | |
256 | { | |
257 | wxFAIL_MSG( wxT("wxNotebook::SetPageSize not implemented") ); | |
258 | } | |
259 | ||
260 | int wxNotebook::SetSelection(size_t nPage) | |
261 | { | |
262 | wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") ); | |
263 | ||
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 | } | |
279 | ||
280 | return m_nSelection; | |
281 | } | |
282 | ||
283 | bool wxNotebook::SetPageText(size_t nPage, const wxString& strText) | |
284 | { | |
285 | wxASSERT( IS_VALID_PAGE(nPage) ); | |
286 | ||
287 | wxNotebookPage *page = m_pages[nPage]; | |
288 | page->SetLabel(strText); | |
289 | MacSetupTabs(); | |
290 | ||
291 | return true; | |
292 | } | |
293 | ||
294 | wxString wxNotebook::GetPageText(size_t nPage) const | |
295 | { | |
296 | wxASSERT( IS_VALID_PAGE(nPage) ); | |
297 | ||
298 | wxNotebookPage *page = m_pages[nPage]; | |
299 | return page->GetLabel(); | |
300 | } | |
301 | ||
302 | int wxNotebook::GetPageImage(size_t nPage) const | |
303 | { | |
304 | wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, _T("invalid notebook page") ); | |
305 | ||
306 | return m_images[nPage]; | |
307 | } | |
308 | ||
309 | bool wxNotebook::SetPageImage(size_t nPage, int nImage) | |
310 | { | |
311 | wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, _T("invalid notebook page") ); | |
312 | ||
313 | wxCHECK_MSG( m_imageList && nImage < m_imageList->GetImageCount(), FALSE, | |
314 | _T("invalid image index in SetPageImage()") ); | |
315 | ||
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; | |
322 | ||
323 | MacSetupTabs() ; | |
324 | } | |
325 | ||
326 | return TRUE; | |
327 | } | |
328 | ||
329 | // ---------------------------------------------------------------------------- | |
330 | // wxNotebook operations | |
331 | // ---------------------------------------------------------------------------- | |
332 | ||
333 | // remove one page from the notebook, without deleting the window | |
334 | wxNotebookPage* wxNotebook::DoRemovePage(size_t nPage) | |
335 | { | |
336 | wxCHECK( IS_VALID_PAGE(nPage), NULL ); | |
337 | wxNotebookPage* page = m_pages[nPage] ; | |
338 | m_pages.RemoveAt(nPage); | |
339 | ||
340 | MacSetupTabs(); | |
341 | ||
342 | if(m_nSelection >= (int)GetPageCount()) { | |
343 | m_nSelection = GetPageCount() - 1; | |
344 | } | |
345 | if(m_nSelection >= 0) { | |
346 | m_pages[m_nSelection]->Show(true); | |
347 | } | |
348 | return page; | |
349 | } | |
350 | ||
351 | // remove all pages | |
352 | bool wxNotebook::DeleteAllPages() | |
353 | { | |
354 | WX_CLEAR_ARRAY(m_pages) ; | |
355 | MacSetupTabs(); | |
356 | m_nSelection = -1 ; | |
357 | return TRUE; | |
358 | } | |
359 | ||
360 | ||
361 | // same as AddPage() but does it at given position | |
362 | bool wxNotebook::InsertPage(size_t nPage, | |
363 | wxNotebookPage *pPage, | |
364 | const wxString& strText, | |
365 | bool bSelect, | |
366 | int imageId) | |
367 | { | |
368 | if ( !wxNotebookBase::InsertPage(nPage, pPage, strText, bSelect, imageId) ) | |
369 | return false; | |
370 | ||
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 | ||
377 | pPage->SetLabel(strText); | |
378 | ||
379 | m_images.Insert(imageId, nPage); | |
380 | ||
381 | MacSetupTabs(); | |
382 | ||
383 | int h, w; | |
384 | GetSize(&w, &h); | |
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); | |
389 | if ( pPage->GetAutoLayout() ) { | |
390 | pPage->Layout(); | |
391 | } | |
392 | ||
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 | ||
418 | return true; | |
419 | } | |
420 | ||
421 | /* Added by Mark Newsam | |
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 | */ | |
426 | void wxNotebook::MacSetupTabs() | |
427 | { | |
428 | SetControl32BitMaximum( (ControlHandle) m_macControl , GetPageCount() ) ; | |
429 | ||
430 | wxNotebookPage *page; | |
431 | ControlTabInfoRec info; | |
432 | ||
433 | const size_t countPages = GetPageCount(); | |
434 | for(size_t ii = 0; ii < countPages; ii++) | |
435 | { | |
436 | page = m_pages[ii]; | |
437 | info.version = 0; | |
438 | info.iconSuiteID = 0; | |
439 | wxMacStringToPascal( page->GetLabel() , info.name ) ; | |
440 | ||
441 | SetControlData( (ControlHandle) m_macControl, ii+1, kControlTabInfoTag, | |
442 | sizeof( ControlTabInfoRec) , (char*) &info ) ; | |
443 | SetTabEnabled( (ControlHandle) m_macControl , ii+1 , true ) ; | |
444 | #if TARGET_CARBON | |
445 | if ( GetImageList() && GetPageImage(ii) >= 0 && UMAGetSystemVersion() >= 0x1020 ) | |
446 | { | |
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 | |
450 | // afterwards Unregister it (IconRef is ref counted, so it will stay on the tab even if we | |
451 | // unregister it) in case this will ever lead to having the same icon everywhere add some kind | |
452 | // of static counter | |
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 | } | |
479 | } | |
480 | #endif | |
481 | } | |
482 | Rect bounds; | |
483 | GetControlBounds((ControlHandle)m_macControl, &bounds); | |
484 | InvalWindowRect((WindowRef)MacGetRootWindow(), &bounds); | |
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) | |
493 | void wxNotebook::OnSize(wxSizeEvent& event) | |
494 | { | |
495 | // emulate page change (it's esp. important to do it first time because | |
496 | // otherwise our page would stay invisible) | |
497 | /* | |
498 | int nSel = m_nSelection; | |
499 | m_nSelection = -1; | |
500 | SetSelection(nSel); | |
501 | */ | |
502 | ||
503 | // fit the notebook page to the tab control's display area | |
504 | int w, h; | |
505 | GetSize(&w, &h); | |
506 | ||
507 | unsigned int nCount = m_pages.Count(); | |
508 | for ( unsigned int nPage = 0; nPage < nCount; nPage++ ) { | |
509 | wxNotebookPage *pPage = m_pages[nPage]; | |
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); | |
514 | if ( pPage->GetAutoLayout() ) { | |
515 | pPage->Layout(); | |
516 | } | |
517 | } | |
518 | ||
519 | // Processing continues to next OnSize | |
520 | event.Skip(); | |
521 | } | |
522 | ||
523 | void wxNotebook::OnSelChange(wxNotebookEvent& event) | |
524 | { | |
525 | // is it our tab control? | |
526 | if ( event.GetEventObject() == this ) | |
527 | ChangePage(event.GetOldSelection(), event.GetSelection()); | |
528 | ||
529 | // we want to give others a chance to process this message as well | |
530 | event.Skip(); | |
531 | } | |
532 | ||
533 | void wxNotebook::OnSetFocus(wxFocusEvent& event) | |
534 | { | |
535 | // set focus to the currently selected page if any | |
536 | if ( m_nSelection != -1 ) | |
537 | m_pages[m_nSelection]->SetFocus(); | |
538 | ||
539 | event.Skip(); | |
540 | } | |
541 | ||
542 | void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) | |
543 | { | |
544 | if ( event.IsWindowChange() ) { | |
545 | // change pages | |
546 | AdvanceSelection(event.GetDirection()); | |
547 | } | |
548 | else { | |
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 | } | |
593 | } | |
594 | } | |
595 | } | |
596 | ||
597 | // ---------------------------------------------------------------------------- | |
598 | // wxNotebook base class virtuals | |
599 | // ---------------------------------------------------------------------------- | |
600 | ||
601 | #if wxUSE_CONSTRAINTS | |
602 | ||
603 | // override these 2 functions to do nothing: everything is done in OnSize | |
604 | ||
605 | void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse)) | |
606 | { | |
607 | // don't set the sizes of the pages - their correct size is not yet known | |
608 | wxControl::SetConstraintSizes(FALSE); | |
609 | } | |
610 | ||
611 | bool wxNotebook::DoPhase(int WXUNUSED(nPhase)) | |
612 | { | |
613 | return TRUE; | |
614 | } | |
615 | ||
616 | #endif // wxUSE_CONSTRAINTS | |
617 | ||
618 | void wxNotebook::Command(wxCommandEvent& event) | |
619 | { | |
620 | wxFAIL_MSG(wxT("wxNotebook::Command not implemented")); | |
621 | } | |
622 | ||
623 | // ---------------------------------------------------------------------------- | |
624 | // wxNotebook helper functions | |
625 | // ---------------------------------------------------------------------------- | |
626 | ||
627 | // hide the currently active panel and show the new one | |
628 | void wxNotebook::ChangePage(int nOldSel, int nSel) | |
629 | { | |
630 | if ( nOldSel != -1 ) | |
631 | { | |
632 | m_pages[nOldSel]->Show(FALSE); | |
633 | } | |
634 | ||
635 | if ( nSel != -1 ) | |
636 | { | |
637 | wxNotebookPage *pPage = m_pages[nSel]; | |
638 | pPage->Show(TRUE); | |
639 | pPage->SetFocus(); | |
640 | } | |
641 | ||
642 | m_nSelection = nSel; | |
643 | SetControl32BitValue( (ControlHandle) m_macControl , m_nSelection + 1 ) ; | |
644 | } | |
645 | ||
646 | ||
647 | void wxNotebook::OnMouse( wxMouseEvent &event ) | |
648 | { | |
649 | if ( (ControlHandle) m_macControl == NULL ) | |
650 | { | |
651 | event.Skip() ; | |
652 | return ; | |
653 | } | |
654 | ||
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 ; | |
659 | ||
660 | MacClientToRootWindow( &x , &y ) ; | |
661 | ||
662 | ControlHandle control ; | |
663 | Point localwhere ; | |
664 | SInt16 controlpart ; | |
665 | ||
666 | localwhere.h = x ; | |
667 | localwhere.v = y ; | |
668 | ||
669 | short modifiers = 0; | |
670 | ||
671 | if ( !event.m_leftDown && !event.m_rightDown ) | |
672 | modifiers |= btnState ; | |
673 | ||
674 | if ( event.m_shiftDown ) | |
675 | modifiers |= shiftKey ; | |
676 | ||
677 | if ( event.m_controlDown ) | |
678 | modifiers |= controlKey ; | |
679 | ||
680 | if ( event.m_altDown ) | |
681 | modifiers |= optionKey ; | |
682 | ||
683 | if ( event.m_metaDown ) | |
684 | modifiers |= cmdKey ; | |
685 | ||
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); | |
693 | GetEventHandler()->ProcessEvent(changing); | |
694 | ||
695 | if(changing.IsAllowed()) | |
696 | { | |
697 | controlpart = ::HandleControlClick(control, localwhere, modifiers, | |
698 | (ControlActionUPP) -1); | |
699 | wxTheApp->s_lastMouseDown = 0 ; | |
700 | ||
701 | wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId, | |
702 | ::GetControl32BitValue(control) - 1, m_nSelection); | |
703 | event.SetEventObject(this); | |
704 | ||
705 | GetEventHandler()->ProcessEvent(event); | |
706 | } | |
707 | } | |
708 | } | |
709 | } | |
710 | } | |
711 | ||
712 | ||
713 | void wxNotebook::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) ) | |
714 | { | |
715 | #if 0 | |
716 | wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId , ::GetControl32BitValue((ControlHandle)m_macControl) - 1, m_nSelection); | |
717 | event.SetEventObject(this); | |
718 | ||
719 | ProcessEvent(event); | |
720 | #endif | |
721 | } | |
722 |