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