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