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