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