]>
Commit | Line | Data |
---|---|---|
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 |
42 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED) |
43 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING) | |
44 | ||
ee6b1d97 | 45 | BEGIN_EVENT_TABLE(wxNotebook, wxControl) |
461fe6e2 | 46 | EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange) |
e40298d5 | 47 | |
461fe6e2 SC |
48 | EVT_SIZE(wxNotebook::OnSize) |
49 | EVT_SET_FOCUS(wxNotebook::OnSetFocus) | |
50 | EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) | |
ee6b1d97 SC |
51 | END_EVENT_TABLE() |
52 | ||
53 | IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl) | |
54 | IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent) | |
ee6b1d97 SC |
55 | |
56 | // ============================================================================ | |
57 | // implementation | |
58 | // ============================================================================ | |
59 | ||
5aed9d50 RD |
60 | // ---------------------------------------------------------------------------- |
61 | // wxNotebook construction | |
62 | // ---------------------------------------------------------------------------- | |
63 | ||
64 | // common part of all ctors | |
65 | void wxNotebook::Init() | |
66 | { | |
ee6b1d97 SC |
67 | m_nSelection = -1; |
68 | } | |
69 | ||
70 | // default for dynamic class | |
71 | wxNotebook::wxNotebook() | |
72 | { | |
73 | Init(); | |
74 | } | |
75 | ||
76 | // the same arguments as for wxControl | |
77 | wxNotebook::wxNotebook(wxWindow *parent, | |
78 | wxWindowID id, | |
79 | const wxPoint& pos, | |
80 | const wxSize& size, | |
81 | long style, | |
82 | const wxString& name) | |
83 | { | |
84 | Init(); | |
5aed9d50 | 85 | |
ee6b1d97 SC |
86 | Create(parent, id, pos, size, style, name); |
87 | } | |
88 | ||
89 | // Create() function | |
90 | bool wxNotebook::Create(wxWindow *parent, | |
91 | wxWindowID id, | |
92 | const wxPoint& pos, | |
93 | const wxSize& size, | |
94 | long style, | |
95 | const wxString& name) | |
96 | { | |
facd6764 SC |
97 | m_macIsUserPane = FALSE ; |
98 | ||
b45ed7a2 VZ |
99 | if ( !wxNotebookBase::Create(parent, id, pos, size, style, name) ) |
100 | return false; | |
101 | ||
facd6764 | 102 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; |
5aed9d50 | 103 | |
facd6764 SC |
104 | if( bounds.right <= bounds.left ) |
105 | bounds.right = bounds.left + 100 ; | |
106 | if ( bounds.bottom <= bounds.top ) | |
107 | bounds.bottom = bounds.top + 100 ; | |
5aed9d50 | 108 | |
facd6764 | 109 | UInt16 tabstyle = kControlTabDirectionNorth ; |
e40298d5 | 110 | if ( HasFlag(wxNB_LEFT) ) |
facd6764 | 111 | tabstyle = kControlTabDirectionWest ; |
e40298d5 | 112 | else if ( HasFlag( wxNB_RIGHT ) ) |
facd6764 | 113 | tabstyle = kControlTabDirectionEast ; |
e40298d5 | 114 | else if ( HasFlag( wxNB_BOTTOM ) ) |
facd6764 SC |
115 | tabstyle = kControlTabDirectionSouth ; |
116 | ||
117 | ControlTabSize tabsize = kControlTabSizeLarge ; | |
118 | if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL ) | |
119 | tabsize = kControlTabSizeSmall ; | |
120 | else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI ) | |
121 | { | |
122 | if (UMAGetSystemVersion() >= 0x1030 ) | |
123 | tabsize = 3 ; | |
124 | else | |
125 | tabsize = kControlSizeSmall; | |
126 | } | |
5aed9d50 | 127 | |
4c37f124 SC |
128 | verify_noerr ( CreateTabsControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , |
129 | tabsize , tabstyle, 0, NULL, (ControlRef*) &m_macControl) ); | |
facd6764 SC |
130 | |
131 | MacPostControlCreate(pos,size) ; | |
e40298d5 | 132 | return TRUE ; |
ee6b1d97 SC |
133 | } |
134 | ||
135 | // dtor | |
136 | wxNotebook::~wxNotebook() | |
137 | { | |
ee6b1d97 SC |
138 | } |
139 | ||
140 | // ---------------------------------------------------------------------------- | |
141 | // wxNotebook accessors | |
142 | // ---------------------------------------------------------------------------- | |
90b959ae SC |
143 | |
144 | void wxNotebook::SetPadding(const wxSize& padding) | |
145 | { | |
63ff6f53 | 146 | // unsupported by OS |
90b959ae SC |
147 | } |
148 | ||
149 | void wxNotebook::SetTabSize(const wxSize& sz) | |
ee6b1d97 | 150 | { |
63ff6f53 | 151 | // unsupported by OS |
ee6b1d97 SC |
152 | } |
153 | ||
90b959ae | 154 | void wxNotebook::SetPageSize(const wxSize& size) |
ee6b1d97 | 155 | { |
63ff6f53 SC |
156 | SetSize( CalcSizeFromPage( size ) ); |
157 | } | |
158 | ||
159 | wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const | |
160 | { | |
facd6764 | 161 | return DoGetSizeFromClientSize( sizePage ) ; |
63ff6f53 SC |
162 | } |
163 | ||
164 | wxSize wxNotebook::DoGetBestSize() const | |
165 | { | |
166 | // calculate the max page size | |
167 | wxSize size(0, 0); | |
168 | ||
169 | size_t count = GetPageCount(); | |
170 | if ( count ) | |
171 | { | |
172 | for ( size_t n = 0; n < count; n++ ) | |
173 | { | |
174 | wxSize sizePage = m_pages[n]->GetSize(); | |
175 | ||
176 | if ( size.x < sizePage.x ) | |
177 | size.x = sizePage.x; | |
178 | if ( size.y < sizePage.y ) | |
179 | size.y = sizePage.y; | |
180 | } | |
181 | } | |
182 | else // no pages | |
183 | { | |
184 | // use some arbitrary default size | |
185 | size.x = | |
186 | size.y = 100; | |
187 | } | |
188 | ||
189 | return CalcSizeFromPage(size); | |
ee6b1d97 SC |
190 | } |
191 | ||
8f83dfee | 192 | int wxNotebook::SetSelection(size_t nPage) |
ee6b1d97 | 193 | { |
461fe6e2 | 194 | wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") ); |
5aed9d50 | 195 | |
461fe6e2 SC |
196 | if ( int(nPage) != m_nSelection ) |
197 | { | |
198 | wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId); | |
199 | event.SetSelection(nPage); | |
200 | event.SetOldSelection(m_nSelection); | |
201 | event.SetEventObject(this); | |
202 | if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() ) | |
203 | { | |
204 | // program allows the page change | |
205 | event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); | |
206 | (void)GetEventHandler()->ProcessEvent(event); | |
207 | ||
208 | ChangePage(m_nSelection, nPage); | |
209 | } | |
210 | } | |
5aed9d50 | 211 | |
ee6b1d97 SC |
212 | return m_nSelection; |
213 | } | |
214 | ||
8f83dfee | 215 | bool wxNotebook::SetPageText(size_t nPage, const wxString& strText) |
ee6b1d97 SC |
216 | { |
217 | wxASSERT( IS_VALID_PAGE(nPage) ); | |
5aed9d50 | 218 | |
90b959ae | 219 | wxNotebookPage *page = m_pages[nPage]; |
c854c7d9 GD |
220 | page->SetLabel(strText); |
221 | MacSetupTabs(); | |
5aed9d50 | 222 | |
c854c7d9 | 223 | return true; |
ee6b1d97 SC |
224 | } |
225 | ||
8f83dfee | 226 | wxString wxNotebook::GetPageText(size_t nPage) const |
ee6b1d97 SC |
227 | { |
228 | wxASSERT( IS_VALID_PAGE(nPage) ); | |
5aed9d50 | 229 | |
90b959ae | 230 | wxNotebookPage *page = m_pages[nPage]; |
c854c7d9 | 231 | return page->GetLabel(); |
ee6b1d97 SC |
232 | } |
233 | ||
8f83dfee | 234 | int wxNotebook::GetPageImage(size_t nPage) const |
ee6b1d97 | 235 | { |
fc0daf84 | 236 | wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, _T("invalid notebook page") ); |
5aed9d50 | 237 | |
2b5f62a0 | 238 | return m_images[nPage]; |
ee6b1d97 SC |
239 | } |
240 | ||
19c43a77 | 241 | bool wxNotebook::SetPageImage(size_t nPage, int nImage) |
ee6b1d97 | 242 | { |
fc0daf84 | 243 | wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, _T("invalid notebook page") ); |
5aed9d50 | 244 | |
fc0daf84 | 245 | wxCHECK_MSG( m_imageList && nImage < m_imageList->GetImageCount(), FALSE, |
e40298d5 | 246 | _T("invalid image index in SetPageImage()") ); |
5aed9d50 | 247 | |
2b5f62a0 VZ |
248 | if ( nImage != m_images[nPage] ) |
249 | { | |
250 | // if the item didn't have an icon before or, on the contrary, did have | |
251 | // it but has lost it now, its size will change - but if the icon just | |
252 | // changes, it won't | |
253 | m_images[nPage] = nImage; | |
5aed9d50 | 254 | |
e40298d5 | 255 | MacSetupTabs() ; |
2b5f62a0 | 256 | } |
5aed9d50 | 257 | |
2b5f62a0 | 258 | return TRUE; |
ee6b1d97 SC |
259 | } |
260 | ||
ee6b1d97 SC |
261 | // ---------------------------------------------------------------------------- |
262 | // wxNotebook operations | |
263 | // ---------------------------------------------------------------------------- | |
264 | ||
90b959ae | 265 | // remove one page from the notebook, without deleting the window |
8f83dfee | 266 | wxNotebookPage* wxNotebook::DoRemovePage(size_t nPage) |
ee6b1d97 | 267 | { |
90b959ae SC |
268 | wxCHECK( IS_VALID_PAGE(nPage), NULL ); |
269 | wxNotebookPage* page = m_pages[nPage] ; | |
3ef585df | 270 | m_pages.RemoveAt(nPage); |
5aed9d50 | 271 | |
c854c7d9 | 272 | MacSetupTabs(); |
5aed9d50 | 273 | |
19c43a77 | 274 | if(m_nSelection >= (int)GetPageCount()) { |
c854c7d9 GD |
275 | m_nSelection = GetPageCount() - 1; |
276 | } | |
277 | if(m_nSelection >= 0) { | |
90b959ae | 278 | m_pages[m_nSelection]->Show(true); |
c854c7d9 | 279 | } |
90b959ae | 280 | return page; |
ee6b1d97 SC |
281 | } |
282 | ||
283 | // remove all pages | |
284 | bool wxNotebook::DeleteAllPages() | |
285 | { | |
90b959ae | 286 | WX_CLEAR_ARRAY(m_pages) ; |
c854c7d9 | 287 | MacSetupTabs(); |
061174e3 | 288 | m_nSelection = -1 ; |
ee6b1d97 SC |
289 | return TRUE; |
290 | } | |
291 | ||
ee6b1d97 SC |
292 | |
293 | // same as AddPage() but does it at given position | |
8f83dfee | 294 | bool wxNotebook::InsertPage(size_t nPage, |
ee6b1d97 SC |
295 | wxNotebookPage *pPage, |
296 | const wxString& strText, | |
297 | bool bSelect, | |
298 | int imageId) | |
299 | { | |
19c43a77 VZ |
300 | if ( !wxNotebookBase::InsertPage(nPage, pPage, strText, bSelect, imageId) ) |
301 | return false; | |
5aed9d50 | 302 | |
461fe6e2 SC |
303 | wxASSERT_MSG( pPage->GetParent() == this, |
304 | _T("notebook pages must have notebook as parent") ); | |
305 | ||
306 | // don't show pages by default (we'll need to adjust their size first) | |
307 | pPage->Show( false ) ; | |
308 | ||
c854c7d9 | 309 | pPage->SetLabel(strText); |
5aed9d50 | 310 | |
2b5f62a0 | 311 | m_images.Insert(imageId, nPage); |
5aed9d50 | 312 | |
c854c7d9 | 313 | MacSetupTabs(); |
5aed9d50 | 314 | |
63ff6f53 SC |
315 | wxRect rect = GetPageRect() ; |
316 | pPage->SetSize(rect); | |
c854c7d9 GD |
317 | if ( pPage->GetAutoLayout() ) { |
318 | pPage->Layout(); | |
319 | } | |
5aed9d50 | 320 | |
461fe6e2 SC |
321 | |
322 | // now deal with the selection | |
323 | // --------------------------- | |
324 | ||
325 | // if the inserted page is before the selected one, we must update the | |
326 | // index of the selected page | |
327 | ||
328 | if ( int(nPage) <= m_nSelection ) | |
329 | { | |
330 | m_nSelection++; | |
331 | // while this still is the same page showing, we need to update the tabs | |
facd6764 | 332 | SetControl32BitValue( (ControlRef) m_macControl , m_nSelection + 1 ) ; |
461fe6e2 SC |
333 | } |
334 | ||
335 | // some page should be selected: either this one or the first one if there | |
336 | // is still no selection | |
337 | int selNew = -1; | |
338 | if ( bSelect ) | |
339 | selNew = nPage; | |
340 | else if ( m_nSelection == -1 ) | |
341 | selNew = 0; | |
342 | ||
343 | if ( selNew != -1 ) | |
344 | SetSelection(selNew); | |
345 | ||
c854c7d9 GD |
346 | return true; |
347 | } | |
348 | ||
349 | /* Added by Mark Newsam | |
e40298d5 JS |
350 | * When a page is added or deleted to the notebook this function updates |
351 | * information held in the m_macControl so that it matches the order | |
352 | * the user would expect. | |
353 | */ | |
c854c7d9 GD |
354 | void wxNotebook::MacSetupTabs() |
355 | { | |
facd6764 | 356 | SetControl32BitMaximum( (ControlRef) m_macControl , GetPageCount() ) ; |
5aed9d50 | 357 | |
c854c7d9 GD |
358 | wxNotebookPage *page; |
359 | ControlTabInfoRec info; | |
5aed9d50 | 360 | |
19c43a77 VZ |
361 | const size_t countPages = GetPageCount(); |
362 | for(size_t ii = 0; ii < countPages; ii++) | |
c854c7d9 | 363 | { |
90b959ae | 364 | page = m_pages[ii]; |
c854c7d9 GD |
365 | info.version = 0; |
366 | info.iconSuiteID = 0; | |
427ff662 SC |
367 | wxMacStringToPascal( page->GetLabel() , info.name ) ; |
368 | ||
facd6764 | 369 | SetControlData( (ControlRef) m_macControl, ii+1, kControlTabInfoTag, |
e40298d5 | 370 | sizeof( ControlTabInfoRec) , (char*) &info ) ; |
facd6764 | 371 | SetTabEnabled( (ControlRef) m_macControl , ii+1 , true ) ; |
22026088 | 372 | #if TARGET_CARBON |
2b5f62a0 VZ |
373 | if ( GetImageList() && GetPageImage(ii) >= 0 && UMAGetSystemVersion() >= 0x1020 ) |
374 | { | |
e40298d5 JS |
375 | // tab controls only support very specific types of images, therefore we are doing an odyssee |
376 | // accross the icon worlds (even Apple DTS did not find a shorter path) | |
377 | // in order not to pollute the icon registry we put every icon into (OSType) 1 and immediately | |
5aed9d50 | 378 | // afterwards Unregister it (IconRef is ref counted, so it will stay on the tab even if we |
e40298d5 | 379 | // unregister it) in case this will ever lead to having the same icon everywhere add some kind |
5aed9d50 | 380 | // of static counter |
69efd83d | 381 | const wxBitmap* bmap = GetImageList()->GetBitmap( GetPageImage(ii ) ) ; |
061174e3 SC |
382 | if ( bmap ) |
383 | { | |
384 | wxBitmap scaledBitmap ; | |
385 | if ( bmap->GetWidth() != 16 || bmap->GetHeight() != 16 ) | |
386 | { | |
387 | scaledBitmap = wxBitmap( bmap->ConvertToImage().Scale(16,16) ) ; | |
388 | bmap = &scaledBitmap ; | |
389 | } | |
390 | ControlButtonContentInfo info ; | |
391 | wxMacCreateBitmapButton( &info , *bmap , kControlContentPictHandle) ; | |
392 | IconFamilyHandle iconFamily = (IconFamilyHandle) NewHandle(0) ; | |
393 | OSErr err = SetIconFamilyData( iconFamily, 'PICT' , (Handle) info.u.picture ) ; | |
394 | wxASSERT_MSG( err == noErr , wxT("Error when adding bitmap") ) ; | |
395 | IconRef iconRef ; | |
d5f7923b | 396 | err = RegisterIconRefFromIconFamily( 'WXNG' , (OSType) 1, iconFamily, &iconRef ) ; |
061174e3 SC |
397 | wxASSERT_MSG( err == noErr , wxT("Error when adding bitmap") ) ; |
398 | info.contentType = kControlContentIconRef ; | |
399 | info.u.iconRef = iconRef ; | |
facd6764 | 400 | SetControlData( (ControlRef) m_macControl, ii+1,kControlTabImageContentTag, |
061174e3 SC |
401 | sizeof( info ), (Ptr)&info ); |
402 | wxASSERT_MSG( err == noErr , wxT("Error when setting icon on tab") ) ; | |
d8c59747 | 403 | if ( UMAGetSystemVersion() < 0x1030 ) |
d5f7923b SC |
404 | { |
405 | UnregisterIconRef( 'WXNG' , (OSType) 1 ) ; | |
406 | } | |
407 | ||
061174e3 SC |
408 | ReleaseIconRef( iconRef ) ; |
409 | DisposeHandle( (Handle) iconFamily ) ; | |
410 | } | |
2b5f62a0 VZ |
411 | } |
412 | #endif | |
c854c7d9 GD |
413 | } |
414 | Rect bounds; | |
facd6764 SC |
415 | UMAGetControlBoundsInWindowCoords((ControlRef)m_macControl, &bounds); |
416 | InvalWindowRect((WindowRef)MacGetTopLevelWindowRef(), &bounds); | |
ee6b1d97 SC |
417 | } |
418 | ||
63ff6f53 SC |
419 | wxRect wxNotebook::GetPageRect() const |
420 | { | |
facd6764 SC |
421 | wxSize size = GetClientSize() ; |
422 | return wxRect( 0 , 0 , size.x , size.y ) ; | |
63ff6f53 | 423 | } |
ee6b1d97 SC |
424 | // ---------------------------------------------------------------------------- |
425 | // wxNotebook callbacks | |
426 | // ---------------------------------------------------------------------------- | |
427 | ||
428 | // @@@ OnSize() is used for setting the font when it's called for the first | |
429 | // time because doing it in ::Create() doesn't work (for unknown reasons) | |
430 | void wxNotebook::OnSize(wxSizeEvent& event) | |
431 | { | |
5aed9d50 | 432 | |
90b959ae | 433 | unsigned int nCount = m_pages.Count(); |
63ff6f53 | 434 | wxRect rect = GetPageRect() ; |
ee6b1d97 | 435 | for ( unsigned int nPage = 0; nPage < nCount; nPage++ ) { |
90b959ae | 436 | wxNotebookPage *pPage = m_pages[nPage]; |
63ff6f53 | 437 | pPage->SetSize(rect); |
c854c7d9 | 438 | if ( pPage->GetAutoLayout() ) { |
ee6b1d97 | 439 | pPage->Layout(); |
c854c7d9 | 440 | } |
ee6b1d97 | 441 | } |
5aed9d50 | 442 | |
ee6b1d97 SC |
443 | // Processing continues to next OnSize |
444 | event.Skip(); | |
445 | } | |
446 | ||
447 | void wxNotebook::OnSelChange(wxNotebookEvent& event) | |
448 | { | |
449 | // is it our tab control? | |
450 | if ( event.GetEventObject() == this ) | |
451 | ChangePage(event.GetOldSelection(), event.GetSelection()); | |
5aed9d50 | 452 | |
ee6b1d97 SC |
453 | // we want to give others a chance to process this message as well |
454 | event.Skip(); | |
455 | } | |
456 | ||
457 | void wxNotebook::OnSetFocus(wxFocusEvent& event) | |
458 | { | |
459 | // set focus to the currently selected page if any | |
460 | if ( m_nSelection != -1 ) | |
90b959ae | 461 | m_pages[m_nSelection]->SetFocus(); |
5aed9d50 | 462 | |
ee6b1d97 SC |
463 | event.Skip(); |
464 | } | |
465 | ||
466 | void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) | |
467 | { | |
468 | if ( event.IsWindowChange() ) { | |
469 | // change pages | |
470 | AdvanceSelection(event.GetDirection()); | |
471 | } | |
472 | else { | |
461fe6e2 SC |
473 | // we get this event in 2 cases |
474 | // | |
475 | // a) one of our pages might have generated it because the user TABbed | |
476 | // out from it in which case we should propagate the event upwards and | |
477 | // our parent will take care of setting the focus to prev/next sibling | |
478 | // | |
479 | // or | |
480 | // | |
481 | // b) the parent panel wants to give the focus to us so that we | |
482 | // forward it to our selected page. We can't deal with this in | |
483 | // OnSetFocus() because we don't know which direction the focus came | |
484 | // from in this case and so can't choose between setting the focus to | |
485 | // first or last panel child | |
486 | wxWindow *parent = GetParent(); | |
487 | // the cast is here to fic a GCC ICE | |
488 | if ( ((wxWindow*)event.GetEventObject()) == parent ) | |
489 | { | |
490 | // no, it doesn't come from child, case (b): forward to a page | |
491 | if ( m_nSelection != -1 ) | |
492 | { | |
493 | // so that the page knows that the event comes from it's parent | |
494 | // and is being propagated downwards | |
495 | event.SetEventObject(this); | |
496 | ||
497 | wxWindow *page = m_pages[m_nSelection]; | |
498 | if ( !page->GetEventHandler()->ProcessEvent(event) ) | |
499 | { | |
500 | page->SetFocus(); | |
501 | } | |
502 | //else: page manages focus inside it itself | |
503 | } | |
504 | else | |
505 | { | |
506 | // we have no pages - still have to give focus to _something_ | |
507 | SetFocus(); | |
508 | } | |
509 | } | |
510 | else | |
511 | { | |
512 | // it comes from our child, case (a), pass to the parent | |
513 | if ( parent ) { | |
514 | event.SetCurrentFocus(this); | |
515 | parent->GetEventHandler()->ProcessEvent(event); | |
516 | } | |
ee6b1d97 SC |
517 | } |
518 | } | |
519 | } | |
520 | ||
521 | // ---------------------------------------------------------------------------- | |
522 | // wxNotebook base class virtuals | |
523 | // ---------------------------------------------------------------------------- | |
524 | ||
461fe6e2 SC |
525 | #if wxUSE_CONSTRAINTS |
526 | ||
ee6b1d97 SC |
527 | // override these 2 functions to do nothing: everything is done in OnSize |
528 | ||
461fe6e2 | 529 | void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse)) |
ee6b1d97 | 530 | { |
461fe6e2 SC |
531 | // don't set the sizes of the pages - their correct size is not yet known |
532 | wxControl::SetConstraintSizes(FALSE); | |
ee6b1d97 SC |
533 | } |
534 | ||
461fe6e2 | 535 | bool wxNotebook::DoPhase(int WXUNUSED(nPhase)) |
ee6b1d97 | 536 | { |
461fe6e2 | 537 | return TRUE; |
ee6b1d97 SC |
538 | } |
539 | ||
461fe6e2 SC |
540 | #endif // wxUSE_CONSTRAINTS |
541 | ||
ee6b1d97 SC |
542 | void wxNotebook::Command(wxCommandEvent& event) |
543 | { | |
427ff662 | 544 | wxFAIL_MSG(wxT("wxNotebook::Command not implemented")); |
ee6b1d97 SC |
545 | } |
546 | ||
547 | // ---------------------------------------------------------------------------- | |
548 | // wxNotebook helper functions | |
549 | // ---------------------------------------------------------------------------- | |
550 | ||
551 | // hide the currently active panel and show the new one | |
552 | void wxNotebook::ChangePage(int nOldSel, int nSel) | |
553 | { | |
461fe6e2 SC |
554 | if ( nOldSel != -1 ) |
555 | { | |
556 | m_pages[nOldSel]->Show(FALSE); | |
557 | } | |
558 | ||
559 | if ( nSel != -1 ) | |
c854c7d9 | 560 | { |
90b959ae | 561 | wxNotebookPage *pPage = m_pages[nSel]; |
c854c7d9 GD |
562 | pPage->Show(TRUE); |
563 | pPage->SetFocus(); | |
c854c7d9 | 564 | } |
461fe6e2 | 565 | |
ee6b1d97 | 566 | m_nSelection = nSel; |
facd6764 | 567 | SetControl32BitValue( (ControlRef) m_macControl , m_nSelection + 1 ) ; |
ee6b1d97 SC |
568 | } |
569 | ||
4c37f124 | 570 | wxInt32 wxNotebook::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) |
799690a0 | 571 | { |
4c37f124 SC |
572 | OSStatus status = eventNotHandledErr ; |
573 | ||
574 | SInt32 newSel = GetControl32BitValue( (ControlRef) m_macControl ) - 1 ; | |
575 | if ( newSel != m_nSelection ) | |
e40298d5 | 576 | { |
4c37f124 SC |
577 | wxNotebookEvent changing(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId, |
578 | newSel , m_nSelection); | |
579 | changing.SetEventObject(this); | |
580 | GetEventHandler()->ProcessEvent(changing); | |
5aed9d50 | 581 | |
4c37f124 | 582 | if(changing.IsAllowed()) |
e40298d5 | 583 | { |
4c37f124 SC |
584 | wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId, |
585 | newSel, m_nSelection); | |
586 | event.SetEventObject(this); | |
5aed9d50 | 587 | |
4c37f124 SC |
588 | GetEventHandler()->ProcessEvent(event); |
589 | } | |
590 | else | |
591 | { | |
592 | SetControl32BitValue( (ControlRef) m_macControl , m_nSelection + 1 ) ; | |
e40298d5 | 593 | } |
4c37f124 | 594 | status = noErr ; |
e40298d5 | 595 | } |
4c37f124 | 596 | return status ; |
ee6b1d97 SC |
597 | } |
598 |