]>
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" |
155ecd4c | 28 | #include "wx/image.h" |
df91131c WS |
29 | #endif |
30 | ||
2646f485 | 31 | #include "wx/imaglist.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 | ||
90f9b8ef JS |
190 | if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT ) |
191 | style |= wxBK_TOP; | |
155ecd4c | 192 | |
2646f485 SC |
193 | MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ; |
194 | ||
195 | int tabstyle = kControlTabSmallNorthProc ; | |
90c0f5a9 | 196 | if ( HasFlag(wxBK_LEFT) ) |
2646f485 | 197 | tabstyle = kControlTabSmallWestProc ; |
90c0f5a9 | 198 | else if ( HasFlag( wxBK_RIGHT ) ) |
2646f485 | 199 | tabstyle = kControlTabSmallEastProc ; |
90c0f5a9 | 200 | else if ( HasFlag( wxBK_BOTTOM ) ) |
2646f485 SC |
201 | tabstyle = kControlTabSmallSouthProc ; |
202 | ||
203 | ||
6bc3b8e9 | 204 | m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, |
2646f485 SC |
205 | tabstyle , (long) this ) ; |
206 | ||
207 | MacPostControlCreate() ; | |
90c0f5a9 | 208 | return true ; |
2646f485 SC |
209 | } |
210 | ||
211 | // dtor | |
212 | wxNotebook::~wxNotebook() | |
213 | { | |
214 | } | |
215 | ||
216 | // ---------------------------------------------------------------------------- | |
217 | // wxNotebook accessors | |
218 | // ---------------------------------------------------------------------------- | |
219 | ||
220 | void wxNotebook::SetPadding(const wxSize& padding) | |
221 | { | |
222 | // unsupported by OS | |
223 | } | |
224 | ||
225 | void wxNotebook::SetTabSize(const wxSize& sz) | |
226 | { | |
227 | // unsupported by OS | |
228 | } | |
229 | ||
230 | void wxNotebook::SetPageSize(const wxSize& size) | |
231 | { | |
232 | SetSize( CalcSizeFromPage( size ) ); | |
233 | } | |
234 | ||
235 | wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const | |
236 | { | |
237 | wxSize sizeTotal = sizePage; | |
90c0f5a9 | 238 | sizeTotal.x += 2 * m_macHorizontalBorder + wxMacTabLeftMargin(GetWindowStyle()) + |
2646f485 | 239 | wxMacTabRightMargin(GetWindowStyle()) ; |
90c0f5a9 | 240 | sizeTotal.y += 2 * m_macVerticalBorder + wxMacTabTopMargin(GetWindowStyle()) + |
2646f485 SC |
241 | wxMacTabBottomMargin(GetWindowStyle()) ; |
242 | ||
243 | return sizeTotal; | |
244 | } | |
245 | ||
246 | wxSize wxNotebook::DoGetBestSize() const | |
247 | { | |
248 | // calculate the max page size | |
249 | wxSize size(0, 0); | |
250 | ||
251 | size_t count = GetPageCount(); | |
252 | if ( count ) | |
253 | { | |
254 | for ( size_t n = 0; n < count; n++ ) | |
255 | { | |
256 | wxSize sizePage = m_pages[n]->GetSize(); | |
257 | ||
258 | if ( size.x < sizePage.x ) | |
259 | size.x = sizePage.x; | |
260 | if ( size.y < sizePage.y ) | |
261 | size.y = sizePage.y; | |
262 | } | |
263 | } | |
264 | else // no pages | |
265 | { | |
266 | // use some arbitrary default size | |
267 | size.x = | |
268 | size.y = 100; | |
269 | } | |
270 | ||
271 | return CalcSizeFromPage(size); | |
272 | } | |
273 | ||
274 | int wxNotebook::SetSelection(size_t nPage) | |
275 | { | |
90c0f5a9 | 276 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); |
2646f485 SC |
277 | |
278 | if ( int(nPage) != m_nSelection ) | |
279 | { | |
280 | wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId); | |
281 | event.SetSelection(nPage); | |
282 | event.SetOldSelection(m_nSelection); | |
283 | event.SetEventObject(this); | |
284 | if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() ) | |
285 | { | |
286 | // program allows the page change | |
287 | event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); | |
288 | (void)GetEventHandler()->ProcessEvent(event); | |
289 | ||
290 | ChangePage(m_nSelection, nPage); | |
291 | } | |
292 | } | |
293 | ||
294 | return m_nSelection; | |
295 | } | |
296 | ||
297 | bool wxNotebook::SetPageText(size_t nPage, const wxString& strText) | |
298 | { | |
299 | wxASSERT( IS_VALID_PAGE(nPage) ); | |
300 | ||
301 | wxNotebookPage *page = m_pages[nPage]; | |
302 | page->SetLabel(strText); | |
303 | MacSetupTabs(); | |
304 | ||
305 | return true; | |
306 | } | |
307 | ||
308 | wxString wxNotebook::GetPageText(size_t nPage) const | |
309 | { | |
310 | wxASSERT( IS_VALID_PAGE(nPage) ); | |
311 | ||
312 | wxNotebookPage *page = m_pages[nPage]; | |
313 | return page->GetLabel(); | |
314 | } | |
315 | ||
316 | int wxNotebook::GetPageImage(size_t nPage) const | |
317 | { | |
90c0f5a9 | 318 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, _T("invalid notebook page") ); |
2646f485 SC |
319 | |
320 | return m_images[nPage]; | |
321 | } | |
322 | ||
323 | bool wxNotebook::SetPageImage(size_t nPage, int nImage) | |
324 | { | |
90c0f5a9 | 325 | wxCHECK_MSG( IS_VALID_PAGE(nPage), false, _T("invalid notebook page") ); |
2646f485 | 326 | |
90c0f5a9 | 327 | wxCHECK_MSG( m_imageList && nImage < m_imageList->GetImageCount(), false, |
2646f485 SC |
328 | _T("invalid image index in SetPageImage()") ); |
329 | ||
330 | if ( nImage != m_images[nPage] ) | |
331 | { | |
332 | // if the item didn't have an icon before or, on the contrary, did have | |
333 | // it but has lost it now, its size will change - but if the icon just | |
334 | // changes, it won't | |
335 | m_images[nPage] = nImage; | |
336 | ||
337 | MacSetupTabs() ; | |
338 | } | |
339 | ||
90c0f5a9 | 340 | return true; |
2646f485 SC |
341 | } |
342 | ||
343 | // ---------------------------------------------------------------------------- | |
344 | // wxNotebook operations | |
345 | // ---------------------------------------------------------------------------- | |
346 | ||
347 | // remove one page from the notebook, without deleting the window | |
348 | wxNotebookPage* wxNotebook::DoRemovePage(size_t nPage) | |
349 | { | |
350 | wxCHECK( IS_VALID_PAGE(nPage), NULL ); | |
351 | wxNotebookPage* page = m_pages[nPage] ; | |
352 | m_pages.RemoveAt(nPage); | |
353 | ||
354 | MacSetupTabs(); | |
355 | ||
356 | if(m_nSelection >= (int)GetPageCount()) { | |
357 | m_nSelection = GetPageCount() - 1; | |
358 | } | |
359 | if(m_nSelection >= 0) { | |
360 | m_pages[m_nSelection]->Show(true); | |
361 | } | |
37144cf0 | 362 | InvalidateBestSize(); |
2646f485 SC |
363 | return page; |
364 | } | |
365 | ||
366 | // remove all pages | |
367 | bool wxNotebook::DeleteAllPages() | |
368 | { | |
369 | WX_CLEAR_ARRAY(m_pages) ; | |
370 | MacSetupTabs(); | |
371 | m_nSelection = -1 ; | |
37144cf0 | 372 | InvalidateBestSize(); |
90c0f5a9 | 373 | return true; |
2646f485 SC |
374 | } |
375 | ||
376 | ||
377 | // same as AddPage() but does it at given position | |
378 | bool wxNotebook::InsertPage(size_t nPage, | |
379 | wxNotebookPage *pPage, | |
380 | const wxString& strText, | |
381 | bool bSelect, | |
382 | int imageId) | |
383 | { | |
384 | if ( !wxNotebookBase::InsertPage(nPage, pPage, strText, bSelect, imageId) ) | |
385 | return false; | |
386 | ||
387 | wxASSERT_MSG( pPage->GetParent() == this, | |
388 | _T("notebook pages must have notebook as parent") ); | |
389 | ||
390 | // don't show pages by default (we'll need to adjust their size first) | |
391 | pPage->Show( false ) ; | |
392 | ||
393 | pPage->SetLabel(strText); | |
394 | ||
395 | m_images.Insert(imageId, nPage); | |
396 | ||
397 | MacSetupTabs(); | |
398 | ||
399 | wxRect rect = GetPageRect() ; | |
400 | pPage->SetSize(rect); | |
401 | if ( pPage->GetAutoLayout() ) { | |
402 | pPage->Layout(); | |
403 | } | |
404 | ||
405 | ||
406 | // now deal with the selection | |
407 | // --------------------------- | |
408 | ||
409 | // if the inserted page is before the selected one, we must update the | |
410 | // index of the selected page | |
411 | ||
90c0f5a9 | 412 | if ( int(nPage) <= m_nSelection ) |
2646f485 SC |
413 | { |
414 | m_nSelection++; | |
415 | // while this still is the same page showing, we need to update the tabs | |
416 | SetControl32BitValue( (ControlHandle) m_macControl , m_nSelection + 1 ) ; | |
417 | } | |
90c0f5a9 | 418 | |
2646f485 SC |
419 | // some page should be selected: either this one or the first one if there |
420 | // is still no selection | |
421 | int selNew = -1; | |
422 | if ( bSelect ) | |
423 | selNew = nPage; | |
424 | else if ( m_nSelection == -1 ) | |
425 | selNew = 0; | |
426 | ||
427 | if ( selNew != -1 ) | |
428 | SetSelection(selNew); | |
429 | ||
37144cf0 | 430 | InvalidateBestSize(); |
2646f485 SC |
431 | return true; |
432 | } | |
433 | ||
434 | /* Added by Mark Newsam | |
435 | * When a page is added or deleted to the notebook this function updates | |
436 | * information held in the m_macControl so that it matches the order | |
437 | * the user would expect. | |
438 | */ | |
439 | void wxNotebook::MacSetupTabs() | |
440 | { | |
441 | SetControl32BitMaximum( (ControlHandle) m_macControl , GetPageCount() ) ; | |
442 | ||
443 | wxNotebookPage *page; | |
444 | ControlTabInfoRec info; | |
445 | ||
446 | const size_t countPages = GetPageCount(); | |
447 | for(size_t ii = 0; ii < countPages; ii++) | |
448 | { | |
449 | page = m_pages[ii]; | |
450 | info.version = 0; | |
451 | info.iconSuiteID = 0; | |
452 | wxMacStringToPascal( page->GetLabel() , info.name ) ; | |
453 | ||
454 | SetControlData( (ControlHandle) m_macControl, ii+1, kControlTabInfoTag, | |
455 | sizeof( ControlTabInfoRec) , (char*) &info ) ; | |
456 | SetTabEnabled( (ControlHandle) m_macControl , ii+1 , true ) ; | |
457 | #if TARGET_CARBON | |
458 | if ( GetImageList() && GetPageImage(ii) >= 0 && UMAGetSystemVersion() >= 0x1020 ) | |
459 | { | |
460 | // tab controls only support very specific types of images, therefore we are doing an odyssee | |
461 | // accross the icon worlds (even Apple DTS did not find a shorter path) | |
462 | // in order not to pollute the icon registry we put every icon into (OSType) 1 and immediately | |
463 | // afterwards Unregister it (IconRef is ref counted, so it will stay on the tab even if we | |
464 | // unregister it) in case this will ever lead to having the same icon everywhere add some kind | |
465 | // of static counter | |
49bf4e3e | 466 | const wxBitmap* bmap = GetImageList()->GetBitmapPtr( GetPageImage(ii ) ) ; |
2646f485 SC |
467 | if ( bmap ) |
468 | { | |
469 | wxBitmap scaledBitmap ; | |
470 | if ( bmap->GetWidth() != 16 || bmap->GetHeight() != 16 ) | |
471 | { | |
472 | scaledBitmap = wxBitmap( bmap->ConvertToImage().Scale(16,16) ) ; | |
473 | bmap = &scaledBitmap ; | |
474 | } | |
475 | ControlButtonContentInfo info ; | |
476 | wxMacCreateBitmapButton( &info , *bmap , kControlContentPictHandle) ; | |
477 | IconFamilyHandle iconFamily = (IconFamilyHandle) NewHandle(0) ; | |
478 | OSErr err = SetIconFamilyData( iconFamily, 'PICT' , (Handle) info.u.picture ) ; | |
479 | wxASSERT_MSG( err == noErr , wxT("Error when adding bitmap") ) ; | |
480 | IconRef iconRef ; | |
481 | err = RegisterIconRefFromIconFamily( 'WXNG' , (OSType) 1, iconFamily, &iconRef ) ; | |
482 | wxASSERT_MSG( err == noErr , wxT("Error when adding bitmap") ) ; | |
483 | info.contentType = kControlContentIconRef ; | |
484 | info.u.iconRef = iconRef ; | |
485 | SetControlData( (ControlHandle) m_macControl, ii+1,kControlTabImageContentTag, | |
486 | sizeof( info ), (Ptr)&info ); | |
487 | wxASSERT_MSG( err == noErr , wxT("Error when setting icon on tab") ) ; | |
488 | if ( UMAGetSystemVersion() < 0x1030 ) | |
90c0f5a9 WS |
489 | { |
490 | UnregisterIconRef( 'WXNG' , (OSType) 1 ) ; | |
2646f485 | 491 | } |
90c0f5a9 | 492 | |
2646f485 SC |
493 | ReleaseIconRef( iconRef ) ; |
494 | DisposeHandle( (Handle) iconFamily ) ; | |
495 | } | |
496 | } | |
497 | #endif | |
498 | } | |
499 | Rect bounds; | |
500 | GetControlBounds((ControlHandle)m_macControl, &bounds); | |
501 | InvalWindowRect((WindowRef)MacGetRootWindow(), &bounds); | |
502 | } | |
503 | ||
504 | wxRect wxNotebook::GetPageRect() const | |
505 | { | |
506 | // fit the notebook page to the tab control's display area | |
507 | int w, h; | |
508 | GetSize(&w, &h); | |
90c0f5a9 WS |
509 | |
510 | return wxRect( | |
511 | wxMacTabLeftMargin(GetWindowStyle()) + m_macHorizontalBorder, | |
2646f485 SC |
512 | wxMacTabTopMargin(GetWindowStyle()) + m_macVerticalBorder, |
513 | w - wxMacTabLeftMargin(GetWindowStyle()) - wxMacTabRightMargin(GetWindowStyle()) - 2*m_macHorizontalBorder, | |
90c0f5a9 | 514 | h - wxMacTabTopMargin(GetWindowStyle()) - wxMacTabBottomMargin(GetWindowStyle()) - 2*m_macVerticalBorder); |
2646f485 SC |
515 | } |
516 | // ---------------------------------------------------------------------------- | |
517 | // wxNotebook callbacks | |
518 | // ---------------------------------------------------------------------------- | |
519 | ||
520 | // @@@ OnSize() is used for setting the font when it's called for the first | |
521 | // time because doing it in ::Create() doesn't work (for unknown reasons) | |
522 | void wxNotebook::OnSize(wxSizeEvent& event) | |
523 | { | |
524 | ||
525 | unsigned int nCount = m_pages.Count(); | |
526 | wxRect rect = GetPageRect() ; | |
527 | for ( unsigned int nPage = 0; nPage < nCount; nPage++ ) { | |
528 | wxNotebookPage *pPage = m_pages[nPage]; | |
529 | pPage->SetSize(rect); | |
530 | if ( pPage->GetAutoLayout() ) { | |
531 | pPage->Layout(); | |
532 | } | |
533 | } | |
534 | ||
535 | // Processing continues to next OnSize | |
536 | event.Skip(); | |
537 | } | |
538 | ||
539 | void wxNotebook::OnSelChange(wxNotebookEvent& event) | |
540 | { | |
541 | // is it our tab control? | |
542 | if ( event.GetEventObject() == this ) | |
543 | ChangePage(event.GetOldSelection(), event.GetSelection()); | |
544 | ||
545 | // we want to give others a chance to process this message as well | |
546 | event.Skip(); | |
547 | } | |
548 | ||
549 | void wxNotebook::OnSetFocus(wxFocusEvent& event) | |
550 | { | |
551 | // set focus to the currently selected page if any | |
552 | if ( m_nSelection != -1 ) | |
553 | m_pages[m_nSelection]->SetFocus(); | |
554 | ||
555 | event.Skip(); | |
556 | } | |
557 | ||
558 | void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) | |
559 | { | |
560 | if ( event.IsWindowChange() ) { | |
561 | // change pages | |
562 | AdvanceSelection(event.GetDirection()); | |
563 | } | |
564 | else { | |
565 | // we get this event in 2 cases | |
566 | // | |
567 | // a) one of our pages might have generated it because the user TABbed | |
568 | // out from it in which case we should propagate the event upwards and | |
569 | // our parent will take care of setting the focus to prev/next sibling | |
570 | // | |
571 | // or | |
572 | // | |
573 | // b) the parent panel wants to give the focus to us so that we | |
574 | // forward it to our selected page. We can't deal with this in | |
575 | // OnSetFocus() because we don't know which direction the focus came | |
576 | // from in this case and so can't choose between setting the focus to | |
577 | // first or last panel child | |
578 | wxWindow *parent = GetParent(); | |
579 | // the cast is here to fic a GCC ICE | |
580 | if ( ((wxWindow*)event.GetEventObject()) == parent ) | |
581 | { | |
582 | // no, it doesn't come from child, case (b): forward to a page | |
583 | if ( m_nSelection != -1 ) | |
584 | { | |
585 | // so that the page knows that the event comes from it's parent | |
586 | // and is being propagated downwards | |
587 | event.SetEventObject(this); | |
588 | ||
589 | wxWindow *page = m_pages[m_nSelection]; | |
590 | if ( !page->GetEventHandler()->ProcessEvent(event) ) | |
591 | { | |
592 | page->SetFocus(); | |
593 | } | |
594 | //else: page manages focus inside it itself | |
595 | } | |
596 | else | |
597 | { | |
598 | // we have no pages - still have to give focus to _something_ | |
599 | SetFocus(); | |
600 | } | |
601 | } | |
602 | else | |
603 | { | |
604 | // it comes from our child, case (a), pass to the parent | |
605 | if ( parent ) { | |
606 | event.SetCurrentFocus(this); | |
607 | parent->GetEventHandler()->ProcessEvent(event); | |
608 | } | |
609 | } | |
610 | } | |
611 | } | |
612 | ||
613 | // ---------------------------------------------------------------------------- | |
614 | // wxNotebook base class virtuals | |
615 | // ---------------------------------------------------------------------------- | |
616 | ||
617 | #if wxUSE_CONSTRAINTS | |
618 | ||
619 | // override these 2 functions to do nothing: everything is done in OnSize | |
620 | ||
621 | void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse)) | |
622 | { | |
90c0f5a9 WS |
623 | // don't set the sizes of the pages - their correct size is not yet known |
624 | wxControl::SetConstraintSizes(false); | |
2646f485 SC |
625 | } |
626 | ||
627 | bool wxNotebook::DoPhase(int WXUNUSED(nPhase)) | |
628 | { | |
90c0f5a9 | 629 | return true; |
2646f485 SC |
630 | } |
631 | ||
632 | #endif // wxUSE_CONSTRAINTS | |
633 | ||
634 | void wxNotebook::Command(wxCommandEvent& event) | |
635 | { | |
636 | wxFAIL_MSG(wxT("wxNotebook::Command not implemented")); | |
637 | } | |
638 | ||
639 | // ---------------------------------------------------------------------------- | |
640 | // wxNotebook helper functions | |
641 | // ---------------------------------------------------------------------------- | |
642 | ||
643 | // hide the currently active panel and show the new one | |
644 | void wxNotebook::ChangePage(int nOldSel, int nSel) | |
645 | { | |
90c0f5a9 | 646 | if ( nOldSel != -1 ) |
2646f485 | 647 | { |
90c0f5a9 | 648 | m_pages[nOldSel]->Show(false); |
2646f485 SC |
649 | } |
650 | ||
651 | if ( nSel != -1 ) | |
652 | { | |
653 | wxNotebookPage *pPage = m_pages[nSel]; | |
90c0f5a9 | 654 | pPage->Show(true); |
2646f485 SC |
655 | pPage->SetFocus(); |
656 | } | |
90c0f5a9 | 657 | |
2646f485 SC |
658 | m_nSelection = nSel; |
659 | SetControl32BitValue( (ControlHandle) m_macControl , m_nSelection + 1 ) ; | |
660 | } | |
661 | ||
662 | ||
663 | void wxNotebook::OnMouse( wxMouseEvent &event ) | |
664 | { | |
665 | if ( (ControlHandle) m_macControl == NULL ) | |
666 | { | |
667 | event.Skip() ; | |
668 | return ; | |
669 | } | |
670 | ||
671 | if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) | |
672 | { | |
673 | int x = event.m_x ; | |
674 | int y = event.m_y ; | |
675 | ||
676 | MacClientToRootWindow( &x , &y ) ; | |
677 | ||
678 | ControlHandle control ; | |
679 | Point localwhere ; | |
680 | SInt16 controlpart ; | |
681 | ||
682 | localwhere.h = x ; | |
683 | localwhere.v = y ; | |
684 | ||
685 | short modifiers = 0; | |
686 | ||
687 | if ( !event.m_leftDown && !event.m_rightDown ) | |
688 | modifiers |= btnState ; | |
689 | ||
690 | if ( event.m_shiftDown ) | |
691 | modifiers |= shiftKey ; | |
692 | ||
693 | if ( event.m_controlDown ) | |
694 | modifiers |= controlKey ; | |
695 | ||
696 | if ( event.m_altDown ) | |
697 | modifiers |= optionKey ; | |
698 | ||
699 | if ( event.m_metaDown ) | |
700 | modifiers |= cmdKey ; | |
701 | ||
702 | control = (ControlHandle) m_macControl ; | |
703 | if ( control && ::IsControlActive( control ) ) | |
704 | { | |
705 | { | |
706 | wxNotebookEvent changing(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId, | |
707 | ::GetControl32BitValue(control) - 1, m_nSelection); | |
708 | changing.SetEventObject(this); | |
709 | GetEventHandler()->ProcessEvent(changing); | |
710 | ||
711 | if(changing.IsAllowed()) | |
712 | { | |
713 | controlpart = ::HandleControlClick(control, localwhere, modifiers, | |
714 | (ControlActionUPP) -1); | |
715 | wxTheApp->s_lastMouseDown = 0 ; | |
716 | ||
717 | wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId, | |
718 | ::GetControl32BitValue(control) - 1, m_nSelection); | |
719 | event.SetEventObject(this); | |
720 | ||
721 | GetEventHandler()->ProcessEvent(event); | |
722 | } | |
723 | } | |
724 | } | |
725 | } | |
726 | } | |
727 | ||
728 | ||
729 | void wxNotebook::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) ) | |
730 | { | |
731 | #if 0 | |
732 | wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId , ::GetControl32BitValue((ControlHandle)m_macControl) - 1, m_nSelection); | |
733 | event.SetEventObject(this); | |
734 | ||
735 | ProcessEvent(event); | |
736 | #endif | |
737 | } |