]>
Commit | Line | Data |
---|---|---|
ee6b1d97 | 1 | /////////////////////////////////////////////////////////////////////////////// |
90c0f5a9 | 2 | // Name: src/mac/carbon/notebmac.cpp |
ee6b1d97 | 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 |
65571936 | 9 | // Licence: wxWindows licence |
ee6b1d97 SC |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 SC |
12 | #include "wx/wxprec.h" |
13 | ||
179e085f RN |
14 | #if wxUSE_NOTEBOOK |
15 | ||
df91131c WS |
16 | #include "wx/notebook.h" |
17 | ||
18 | #ifndef WX_PRECOMP | |
19 | #include "wx/string.h" | |
e4db172a | 20 | #include "wx/log.h" |
670f9935 | 21 | #include "wx/app.h" |
155ecd4c | 22 | #include "wx/image.h" |
df91131c WS |
23 | #endif |
24 | ||
d497dca4 | 25 | #include "wx/string.h" |
d497dca4 | 26 | #include "wx/imaglist.h" |
d497dca4 | 27 | #include "wx/mac/uma.h" |
5a7d70fe | 28 | |
ee6b1d97 SC |
29 | |
30 | // check that the page index is valid | |
19c43a77 | 31 | #define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount()) |
ee6b1d97 | 32 | |
ee6b1d97 | 33 | |
5b781a67 SC |
34 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED) |
35 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING) | |
36 | ||
ee6b1d97 | 37 | BEGIN_EVENT_TABLE(wxNotebook, wxControl) |
90c0f5a9 | 38 | EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, wxNotebook::OnSelChange) |
e40298d5 | 39 | |
461fe6e2 SC |
40 | EVT_SIZE(wxNotebook::OnSize) |
41 | EVT_SET_FOCUS(wxNotebook::OnSetFocus) | |
42 | EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) | |
ee6b1d97 SC |
43 | END_EVENT_TABLE() |
44 | ||
45 | IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl) | |
46 | IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent) | |
ee6b1d97 | 47 | |
5aed9d50 RD |
48 | |
49 | // common part of all ctors | |
50 | void wxNotebook::Init() | |
51 | { | |
ee6b1d97 SC |
52 | m_nSelection = -1; |
53 | } | |
54 | ||
55 | // default for dynamic class | |
56 | wxNotebook::wxNotebook() | |
57 | { | |
58 | Init(); | |
59 | } | |
60 | ||
61 | // the same arguments as for wxControl | |
5a7d70fe DS |
62 | wxNotebook::wxNotebook( wxWindow *parent, |
63 | wxWindowID id, | |
64 | const wxPoint& pos, | |
65 | const wxSize& size, | |
66 | long style, | |
67 | const wxString& name ) | |
ee6b1d97 SC |
68 | { |
69 | Init(); | |
5aed9d50 | 70 | |
5a7d70fe | 71 | Create( parent, id, pos, size, style, name ); |
ee6b1d97 SC |
72 | } |
73 | ||
5a7d70fe DS |
74 | bool wxNotebook::Create( wxWindow *parent, |
75 | wxWindowID id, | |
76 | const wxPoint& pos, | |
77 | const wxSize& size, | |
78 | long style, | |
79 | const wxString& name ) | |
ee6b1d97 | 80 | { |
90c0f5a9 WS |
81 | m_macIsUserPane = false ; |
82 | ||
511bec96 RD |
83 | if (! (style & wxBK_ALIGN_MASK)) |
84 | style |= wxBK_TOP; | |
155ecd4c | 85 | |
5a7d70fe | 86 | if ( !wxNotebookBase::Create( parent, id, pos, size, style, name ) ) |
b45ed7a2 VZ |
87 | return false; |
88 | ||
5a7d70fe | 89 | Rect bounds = wxMacGetBoundsForControl( this, pos, size ); |
5aed9d50 | 90 | |
5a7d70fe DS |
91 | if ( bounds.right <= bounds.left ) |
92 | bounds.right = bounds.left + 100; | |
facd6764 | 93 | if ( bounds.bottom <= bounds.top ) |
5a7d70fe | 94 | bounds.bottom = bounds.top + 100; |
5aed9d50 | 95 | |
5a7d70fe | 96 | UInt16 tabstyle = kControlTabDirectionNorth; |
90c0f5a9 | 97 | if ( HasFlag(wxBK_LEFT) ) |
5a7d70fe | 98 | tabstyle = kControlTabDirectionWest; |
90c0f5a9 | 99 | else if ( HasFlag( wxBK_RIGHT ) ) |
5a7d70fe | 100 | tabstyle = kControlTabDirectionEast; |
90c0f5a9 | 101 | else if ( HasFlag( wxBK_BOTTOM ) ) |
5a7d70fe | 102 | tabstyle = kControlTabDirectionSouth; |
90c0f5a9 | 103 | |
5a7d70fe DS |
104 | ControlTabSize tabsize; |
105 | switch (GetWindowVariant()) | |
facd6764 | 106 | { |
df91131c | 107 | case wxWINDOW_VARIANT_MINI: |
5a7d70fe DS |
108 | if ( UMAGetSystemVersion() >= 0x1030 ) |
109 | tabsize = 3 ; | |
110 | else | |
111 | tabsize = kControlSizeSmall; | |
112 | break; | |
113 | ||
df91131c | 114 | case wxWINDOW_VARIANT_SMALL: |
5a7d70fe DS |
115 | tabsize = kControlTabSizeSmall; |
116 | break; | |
117 | ||
df91131c | 118 | default: |
5a7d70fe DS |
119 | tabsize = kControlTabSizeLarge; |
120 | break; | |
facd6764 | 121 | } |
5aed9d50 | 122 | |
5a7d70fe DS |
123 | m_peer = new wxMacControl( this ); |
124 | OSStatus err = CreateTabsControl( | |
125 | MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, | |
126 | tabsize, tabstyle, 0, NULL, m_peer->GetControlRefAddr() ); | |
127 | verify_noerr( err ); | |
90c0f5a9 | 128 | |
5a7d70fe | 129 | MacPostControlCreate( pos, size ); |
90c0f5a9 | 130 | |
90c0f5a9 | 131 | return true ; |
ee6b1d97 SC |
132 | } |
133 | ||
134 | // dtor | |
135 | wxNotebook::~wxNotebook() | |
136 | { | |
ee6b1d97 SC |
137 | } |
138 | ||
139 | // ---------------------------------------------------------------------------- | |
140 | // wxNotebook accessors | |
141 | // ---------------------------------------------------------------------------- | |
90b959ae SC |
142 | |
143 | void wxNotebook::SetPadding(const wxSize& padding) | |
144 | { | |
63ff6f53 | 145 | // unsupported by OS |
90b959ae SC |
146 | } |
147 | ||
148 | void wxNotebook::SetTabSize(const wxSize& sz) | |
ee6b1d97 | 149 | { |
63ff6f53 | 150 | // unsupported by OS |
ee6b1d97 SC |
151 | } |
152 | ||
90b959ae | 153 | void wxNotebook::SetPageSize(const wxSize& size) |
ee6b1d97 | 154 | { |
63ff6f53 SC |
155 | SetSize( CalcSizeFromPage( size ) ); |
156 | } | |
157 | ||
158 | wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const | |
159 | { | |
5a7d70fe | 160 | return DoGetSizeFromClientSize( sizePage ); |
63ff6f53 SC |
161 | } |
162 | ||
2da25e49 | 163 | int wxNotebook::DoSetSelection(size_t nPage, int flags) |
ee6b1d97 | 164 | { |
1d6fcbcc | 165 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("DoSetSelection: invalid notebook page") ); |
5aed9d50 | 166 | |
8e79a06b | 167 | if ( m_nSelection == wxNOT_FOUND || nPage != (size_t)m_nSelection ) |
461fe6e2 | 168 | { |
2da25e49 | 169 | if ( flags & SetSelection_SendEvent ) |
461fe6e2 | 170 | { |
a570e8f8 | 171 | if ( !SendPageChangingEvent(nPage) ) |
1d6fcbcc | 172 | { |
2da25e49 VZ |
173 | // vetoed by program |
174 | return m_nSelection; | |
1d6fcbcc | 175 | } |
2da25e49 VZ |
176 | //else: program allows the page change |
177 | ||
a570e8f8 | 178 | SendPageChangedEvent(m_nSelection, nPage); |
461fe6e2 | 179 | } |
5aed9d50 | 180 | |
2da25e49 VZ |
181 | ChangePage(m_nSelection, nPage); |
182 | } | |
8e79a06b | 183 | //else: no change |
2da25e49 | 184 | |
ee6b1d97 SC |
185 | return m_nSelection; |
186 | } | |
187 | ||
8f83dfee | 188 | bool wxNotebook::SetPageText(size_t nPage, const wxString& strText) |
ee6b1d97 | 189 | { |
5a7d70fe | 190 | wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("SetPageText: invalid notebook page") ); |
5aed9d50 | 191 | |
90b959ae | 192 | wxNotebookPage *page = m_pages[nPage]; |
c854c7d9 GD |
193 | page->SetLabel(strText); |
194 | MacSetupTabs(); | |
5aed9d50 | 195 | |
c854c7d9 | 196 | return true; |
ee6b1d97 SC |
197 | } |
198 | ||
8f83dfee | 199 | wxString wxNotebook::GetPageText(size_t nPage) const |
ee6b1d97 | 200 | { |
5a7d70fe | 201 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxEmptyString, wxT("GetPageText: invalid notebook page") ); |
5aed9d50 | 202 | |
90b959ae | 203 | wxNotebookPage *page = m_pages[nPage]; |
5a7d70fe | 204 | |
c854c7d9 | 205 | return page->GetLabel(); |
ee6b1d97 SC |
206 | } |
207 | ||
8f83dfee | 208 | int wxNotebook::GetPageImage(size_t nPage) const |
ee6b1d97 | 209 | { |
5a7d70fe | 210 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("GetPageImage: invalid notebook page") ); |
5aed9d50 | 211 | |
2b5f62a0 | 212 | return m_images[nPage]; |
ee6b1d97 SC |
213 | } |
214 | ||
19c43a77 | 215 | bool wxNotebook::SetPageImage(size_t nPage, int nImage) |
ee6b1d97 | 216 | { |
5a7d70fe DS |
217 | wxCHECK_MSG( IS_VALID_PAGE(nPage), false, |
218 | wxT("SetPageImage: invalid notebook page") ); | |
90c0f5a9 | 219 | wxCHECK_MSG( m_imageList && nImage < m_imageList->GetImageCount(), false, |
5a7d70fe | 220 | wxT("SetPageImage: invalid image index") ); |
5aed9d50 | 221 | |
2b5f62a0 VZ |
222 | if ( nImage != m_images[nPage] ) |
223 | { | |
224 | // if the item didn't have an icon before or, on the contrary, did have | |
225 | // it but has lost it now, its size will change - but if the icon just | |
226 | // changes, it won't | |
227 | m_images[nPage] = nImage; | |
5aed9d50 | 228 | |
e40298d5 | 229 | MacSetupTabs() ; |
2b5f62a0 | 230 | } |
5aed9d50 | 231 | |
90c0f5a9 | 232 | return true; |
ee6b1d97 SC |
233 | } |
234 | ||
ee6b1d97 SC |
235 | // ---------------------------------------------------------------------------- |
236 | // wxNotebook operations | |
237 | // ---------------------------------------------------------------------------- | |
238 | ||
90b959ae | 239 | // remove one page from the notebook, without deleting the window |
8f83dfee | 240 | wxNotebookPage* wxNotebook::DoRemovePage(size_t nPage) |
ee6b1d97 | 241 | { |
5a7d70fe DS |
242 | wxCHECK_MSG( IS_VALID_PAGE(nPage), NULL, |
243 | wxT("DoRemovePage: invalid notebook page") ); | |
244 | ||
90b959ae | 245 | wxNotebookPage* page = m_pages[nPage] ; |
3ef585df | 246 | m_pages.RemoveAt(nPage); |
5aed9d50 | 247 | |
c854c7d9 | 248 | MacSetupTabs(); |
5aed9d50 | 249 | |
5a7d70fe | 250 | if (m_nSelection >= (int)GetPageCount()) |
c854c7d9 | 251 | m_nSelection = GetPageCount() - 1; |
5a7d70fe DS |
252 | |
253 | if (m_nSelection >= 0) | |
90b959ae | 254 | m_pages[m_nSelection]->Show(true); |
5a7d70fe | 255 | |
37144cf0 | 256 | InvalidateBestSize(); |
5a7d70fe | 257 | |
90b959ae | 258 | return page; |
ee6b1d97 SC |
259 | } |
260 | ||
261 | // remove all pages | |
262 | bool wxNotebook::DeleteAllPages() | |
263 | { | |
90b959ae | 264 | WX_CLEAR_ARRAY(m_pages) ; |
c854c7d9 | 265 | MacSetupTabs(); |
061174e3 | 266 | m_nSelection = -1 ; |
37144cf0 | 267 | InvalidateBestSize(); |
5a7d70fe | 268 | |
90c0f5a9 | 269 | return true; |
ee6b1d97 SC |
270 | } |
271 | ||
ee6b1d97 | 272 | // same as AddPage() but does it at given position |
8f83dfee | 273 | bool wxNotebook::InsertPage(size_t nPage, |
5a7d70fe DS |
274 | wxNotebookPage *pPage, |
275 | const wxString& strText, | |
276 | bool bSelect, | |
277 | int imageId ) | |
ee6b1d97 | 278 | { |
5a7d70fe | 279 | if ( !wxNotebookBase::InsertPage( nPage, pPage, strText, bSelect, imageId ) ) |
19c43a77 | 280 | return false; |
5aed9d50 | 281 | |
5a7d70fe | 282 | wxASSERT_MSG( pPage->GetParent() == this, wxT("notebook pages must have notebook as parent") ); |
461fe6e2 SC |
283 | |
284 | // don't show pages by default (we'll need to adjust their size first) | |
285 | pPage->Show( false ) ; | |
286 | ||
5a7d70fe | 287 | pPage->SetLabel( strText ); |
5aed9d50 | 288 | |
5a7d70fe | 289 | m_images.Insert( imageId, nPage ); |
5aed9d50 | 290 | |
c854c7d9 | 291 | MacSetupTabs(); |
5aed9d50 | 292 | |
63ff6f53 | 293 | wxRect rect = GetPageRect() ; |
5a7d70fe DS |
294 | pPage->SetSize( rect ); |
295 | if ( pPage->GetAutoLayout() ) | |
c854c7d9 | 296 | pPage->Layout(); |
461fe6e2 SC |
297 | |
298 | // now deal with the selection | |
299 | // --------------------------- | |
300 | ||
301 | // if the inserted page is before the selected one, we must update the | |
302 | // index of the selected page | |
303 | ||
90c0f5a9 | 304 | if ( int(nPage) <= m_nSelection ) |
461fe6e2 SC |
305 | { |
306 | m_nSelection++; | |
5a7d70fe | 307 | |
461fe6e2 | 308 | // while this still is the same page showing, we need to update the tabs |
5ca0d812 | 309 | m_peer->SetValue( m_nSelection + 1 ) ; |
461fe6e2 | 310 | } |
90c0f5a9 | 311 | |
461fe6e2 SC |
312 | // some page should be selected: either this one or the first one if there |
313 | // is still no selection | |
314 | int selNew = -1; | |
315 | if ( bSelect ) | |
316 | selNew = nPage; | |
317 | else if ( m_nSelection == -1 ) | |
318 | selNew = 0; | |
319 | ||
320 | if ( selNew != -1 ) | |
5a7d70fe | 321 | SetSelection( selNew ); |
461fe6e2 | 322 | |
37144cf0 | 323 | InvalidateBestSize(); |
5a7d70fe | 324 | |
c854c7d9 GD |
325 | return true; |
326 | } | |
327 | ||
3c3e6970 SC |
328 | int wxNotebook::HitTest(const wxPoint& pt, long * flags) const |
329 | { | |
fe224552 | 330 | int resultV = wxNOT_FOUND; |
5a7d70fe | 331 | |
3c3e6970 | 332 | #if TARGET_API_MAC_OSX |
5a7d70fe | 333 | const int countPages = GetPageCount(); |
fe224552 | 334 | |
2fbfb7d6 | 335 | // we have to convert from Client to Window relative coordinates |
df91131c | 336 | wxPoint adjustedPt = pt + GetClientAreaOrigin(); |
2fbfb7d6 SC |
337 | // and now to HIView native ones |
338 | adjustedPt.x -= MacGetLeftBorderSize() ; | |
339 | adjustedPt.y -= MacGetTopBorderSize() ; | |
df91131c | 340 | |
2fbfb7d6 | 341 | HIPoint hipoint= { adjustedPt.x , adjustedPt.y } ; |
3c3e6970 | 342 | HIViewPartCode outPart = 0 ; |
5a7d70fe | 343 | OSStatus err = HIViewGetPartHit( m_peer->GetControlRef(), &hipoint, &outPart ); |
fe224552 | 344 | |
0df4335d | 345 | int max = m_peer->GetMaximum() ; |
3c3e6970 SC |
346 | if ( outPart == 0 && max > 0 ) |
347 | { | |
348 | // this is a hack, as unfortunately a hit on an already selected tab returns 0, | |
fe224552 | 349 | // so we have to go some extra miles to make sure we select something different |
3c3e6970 | 350 | // and try again .. |
0df4335d | 351 | int val = m_peer->GetValue() ; |
3c3e6970 SC |
352 | int maxval = max ; |
353 | if ( max == 1 ) | |
354 | { | |
0df4335d | 355 | m_peer->SetMaximum( 2 ) ; |
3c3e6970 SC |
356 | maxval = 2 ; |
357 | } | |
358 | ||
359 | if ( val == 1 ) | |
0df4335d | 360 | m_peer->SetValue( maxval ) ; |
3c3e6970 | 361 | else |
0df4335d | 362 | m_peer->SetValue( 1 ) ; |
fe224552 | 363 | |
5a7d70fe | 364 | err = HIViewGetPartHit( m_peer->GetControlRef(), &hipoint, &outPart ); |
fe224552 | 365 | |
0df4335d | 366 | m_peer->SetValue( val ) ; |
3c3e6970 | 367 | if ( max == 1 ) |
0df4335d | 368 | m_peer->SetMaximum( 1 ) ; |
3c3e6970 | 369 | } |
fe224552 VZ |
370 | |
371 | if ( outPart >= 1 && outPart <= countPages ) | |
eb5d9594 | 372 | resultV = outPart - 1 ; |
f885b815 VZ |
373 | #endif // TARGET_API_MAC_OSX |
374 | ||
3c3e6970 SC |
375 | if (flags != NULL) |
376 | { | |
377 | *flags = 0; | |
fe224552 | 378 | |
3c3e6970 | 379 | // we cannot differentiate better |
eb5d9594 | 380 | if (resultV >= 0) |
9804d540 | 381 | *flags |= wxBK_HITTEST_ONLABEL; |
3c3e6970 | 382 | else |
9804d540 | 383 | *flags |= wxBK_HITTEST_NOWHERE; |
3c3e6970 | 384 | } |
5a7d70fe | 385 | |
3c3e6970 SC |
386 | return resultV; |
387 | } | |
388 | ||
5a7d70fe DS |
389 | // Added by Mark Newsam |
390 | // When a page is added or deleted to the notebook this function updates | |
391 | // information held in the control so that it matches the order | |
392 | // the user would expect. | |
393 | // | |
c854c7d9 GD |
394 | void wxNotebook::MacSetupTabs() |
395 | { | |
5ca0d812 | 396 | m_peer->SetMaximum( GetPageCount() ) ; |
5aed9d50 | 397 | |
c854c7d9 | 398 | wxNotebookPage *page; |
5324268e | 399 | ControlTabInfoRecV1 info; |
5aed9d50 | 400 | |
19c43a77 | 401 | const size_t countPages = GetPageCount(); |
5a7d70fe | 402 | for (size_t ii = 0; ii < countPages; ii++) |
c854c7d9 | 403 | { |
90b959ae | 404 | page = m_pages[ii]; |
5324268e | 405 | info.version = kControlTabInfoVersionOne; |
c854c7d9 | 406 | info.iconSuiteID = 0; |
5a7d70fe | 407 | wxMacCFStringHolder cflabel( page->GetLabel(), m_font.GetEncoding() ) ; |
5324268e | 408 | info.name = cflabel ; |
5a7d70fe | 409 | m_peer->SetData<ControlTabInfoRecV1>( ii + 1, kControlTabInfoTag, &info ) ; |
20b69855 | 410 | |
2b5f62a0 VZ |
411 | if ( GetImageList() && GetPageImage(ii) >= 0 && UMAGetSystemVersion() >= 0x1020 ) |
412 | { | |
5a7d70fe | 413 | const wxBitmap bmap = GetImageList()->GetBitmap( GetPageImage( ii ) ) ; |
b337acd7 | 414 | if ( bmap.Ok() ) |
061174e3 | 415 | { |
061174e3 | 416 | ControlButtonContentInfo info ; |
20b69855 | 417 | |
5a7d70fe DS |
418 | wxMacCreateBitmapButton( &info, bmap ) ; |
419 | ||
420 | OSStatus err = m_peer->SetData<ControlButtonContentInfo>( ii + 1, kControlTabImageContentTag, &info ); | |
061174e3 | 421 | wxASSERT_MSG( err == noErr , wxT("Error when setting icon on tab") ) ; |
5a7d70fe | 422 | |
20b69855 | 423 | wxMacReleaseBitmapButton( &info ) ; |
061174e3 | 424 | } |
2b5f62a0 | 425 | } |
5a7d70fe DS |
426 | |
427 | m_peer->SetTabEnabled( ii + 1, true ) ; | |
c854c7d9 | 428 | } |
5a7d70fe | 429 | |
c854c7d9 | 430 | Rect bounds; |
5ca0d812 | 431 | m_peer->GetRectInWindowCoords( &bounds ) ; |
5a7d70fe | 432 | InvalWindowRect( (WindowRef)MacGetTopLevelWindowRef(), &bounds ); |
ee6b1d97 SC |
433 | } |
434 | ||
63ff6f53 SC |
435 | wxRect wxNotebook::GetPageRect() const |
436 | { | |
facd6764 | 437 | wxSize size = GetClientSize() ; |
5a7d70fe | 438 | |
facd6764 | 439 | return wxRect( 0 , 0 , size.x , size.y ) ; |
63ff6f53 | 440 | } |
5a7d70fe | 441 | |
ee6b1d97 SC |
442 | // ---------------------------------------------------------------------------- |
443 | // wxNotebook callbacks | |
444 | // ---------------------------------------------------------------------------- | |
445 | ||
446 | // @@@ OnSize() is used for setting the font when it's called for the first | |
447 | // time because doing it in ::Create() doesn't work (for unknown reasons) | |
448 | void wxNotebook::OnSize(wxSizeEvent& event) | |
449 | { | |
90b959ae | 450 | unsigned int nCount = m_pages.Count(); |
63ff6f53 | 451 | wxRect rect = GetPageRect() ; |
5a7d70fe DS |
452 | |
453 | for ( unsigned int nPage = 0; nPage < nCount; nPage++ ) | |
454 | { | |
90b959ae | 455 | wxNotebookPage *pPage = m_pages[nPage]; |
63ff6f53 | 456 | pPage->SetSize(rect); |
5a7d70fe | 457 | if ( pPage->GetAutoLayout() ) |
ee6b1d97 SC |
458 | pPage->Layout(); |
459 | } | |
5aed9d50 | 460 | |
ee6b1d97 SC |
461 | // Processing continues to next OnSize |
462 | event.Skip(); | |
463 | } | |
464 | ||
465 | void wxNotebook::OnSelChange(wxNotebookEvent& event) | |
466 | { | |
467 | // is it our tab control? | |
468 | if ( event.GetEventObject() == this ) | |
469 | ChangePage(event.GetOldSelection(), event.GetSelection()); | |
5aed9d50 | 470 | |
ee6b1d97 SC |
471 | // we want to give others a chance to process this message as well |
472 | event.Skip(); | |
473 | } | |
474 | ||
475 | void wxNotebook::OnSetFocus(wxFocusEvent& event) | |
476 | { | |
477 | // set focus to the currently selected page if any | |
478 | if ( m_nSelection != -1 ) | |
90b959ae | 479 | m_pages[m_nSelection]->SetFocus(); |
5aed9d50 | 480 | |
ee6b1d97 SC |
481 | event.Skip(); |
482 | } | |
483 | ||
484 | void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) | |
485 | { | |
5a7d70fe DS |
486 | if ( event.IsWindowChange() ) |
487 | { | |
ee6b1d97 | 488 | // change pages |
5a7d70fe | 489 | AdvanceSelection( event.GetDirection() ); |
ee6b1d97 | 490 | } |
5a7d70fe DS |
491 | else |
492 | { | |
461fe6e2 SC |
493 | // we get this event in 2 cases |
494 | // | |
495 | // a) one of our pages might have generated it because the user TABbed | |
496 | // out from it in which case we should propagate the event upwards and | |
497 | // our parent will take care of setting the focus to prev/next sibling | |
498 | // | |
499 | // or | |
500 | // | |
501 | // b) the parent panel wants to give the focus to us so that we | |
502 | // forward it to our selected page. We can't deal with this in | |
503 | // OnSetFocus() because we don't know which direction the focus came | |
504 | // from in this case and so can't choose between setting the focus to | |
505 | // first or last panel child | |
506 | wxWindow *parent = GetParent(); | |
5a7d70fe DS |
507 | |
508 | // the cast is here to fix a GCC ICE | |
461fe6e2 SC |
509 | if ( ((wxWindow*)event.GetEventObject()) == parent ) |
510 | { | |
511 | // no, it doesn't come from child, case (b): forward to a page | |
512 | if ( m_nSelection != -1 ) | |
513 | { | |
514 | // so that the page knows that the event comes from it's parent | |
515 | // and is being propagated downwards | |
5a7d70fe | 516 | event.SetEventObject( this ); |
461fe6e2 SC |
517 | |
518 | wxWindow *page = m_pages[m_nSelection]; | |
5a7d70fe | 519 | if ( !page->GetEventHandler()->ProcessEvent( event ) ) |
461fe6e2 SC |
520 | { |
521 | page->SetFocus(); | |
522 | } | |
523 | //else: page manages focus inside it itself | |
524 | } | |
525 | else | |
526 | { | |
527 | // we have no pages - still have to give focus to _something_ | |
528 | SetFocus(); | |
529 | } | |
530 | } | |
531 | else | |
532 | { | |
533 | // it comes from our child, case (a), pass to the parent | |
5a7d70fe DS |
534 | if ( parent ) |
535 | { | |
536 | event.SetCurrentFocus( this ); | |
537 | parent->GetEventHandler()->ProcessEvent( event ); | |
461fe6e2 | 538 | } |
ee6b1d97 SC |
539 | } |
540 | } | |
541 | } | |
542 | ||
543 | // ---------------------------------------------------------------------------- | |
544 | // wxNotebook base class virtuals | |
545 | // ---------------------------------------------------------------------------- | |
546 | ||
461fe6e2 SC |
547 | #if wxUSE_CONSTRAINTS |
548 | ||
ee6b1d97 SC |
549 | // override these 2 functions to do nothing: everything is done in OnSize |
550 | ||
461fe6e2 | 551 | void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse)) |
ee6b1d97 | 552 | { |
90c0f5a9 | 553 | // don't set the sizes of the pages - their correct size is not yet known |
5a7d70fe | 554 | wxControl::SetConstraintSizes( false ); |
ee6b1d97 SC |
555 | } |
556 | ||
461fe6e2 | 557 | bool wxNotebook::DoPhase(int WXUNUSED(nPhase)) |
ee6b1d97 | 558 | { |
90c0f5a9 | 559 | return true; |
ee6b1d97 SC |
560 | } |
561 | ||
461fe6e2 SC |
562 | #endif // wxUSE_CONSTRAINTS |
563 | ||
ee6b1d97 SC |
564 | void wxNotebook::Command(wxCommandEvent& event) |
565 | { | |
427ff662 | 566 | wxFAIL_MSG(wxT("wxNotebook::Command not implemented")); |
ee6b1d97 SC |
567 | } |
568 | ||
569 | // ---------------------------------------------------------------------------- | |
570 | // wxNotebook helper functions | |
571 | // ---------------------------------------------------------------------------- | |
572 | ||
573 | // hide the currently active panel and show the new one | |
574 | void wxNotebook::ChangePage(int nOldSel, int nSel) | |
575 | { | |
5a7d70fe DS |
576 | if (nOldSel == nSel) |
577 | return; | |
578 | ||
90c0f5a9 | 579 | if ( nOldSel != -1 ) |
5a7d70fe | 580 | m_pages[nOldSel]->Show( false ); |
461fe6e2 SC |
581 | |
582 | if ( nSel != -1 ) | |
c854c7d9 | 583 | { |
90b959ae | 584 | wxNotebookPage *pPage = m_pages[nSel]; |
5a7d70fe | 585 | pPage->Show( true ); |
c854c7d9 | 586 | pPage->SetFocus(); |
c854c7d9 | 587 | } |
90c0f5a9 | 588 | |
ee6b1d97 | 589 | m_nSelection = nSel; |
5ca0d812 | 590 | m_peer->SetValue( m_nSelection + 1 ) ; |
ee6b1d97 SC |
591 | } |
592 | ||
90c0f5a9 | 593 | wxInt32 wxNotebook::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) |
799690a0 | 594 | { |
4c37f124 | 595 | OSStatus status = eventNotHandledErr ; |
90c0f5a9 | 596 | |
5ca0d812 | 597 | SInt32 newSel = m_peer->GetValue() - 1 ; |
4c37f124 | 598 | if ( newSel != m_nSelection ) |
e40298d5 | 599 | { |
5a7d70fe DS |
600 | wxNotebookEvent changing( |
601 | wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId, | |
602 | newSel , m_nSelection ); | |
603 | changing.SetEventObject( this ); | |
604 | GetEventHandler()->ProcessEvent( changing ); | |
5aed9d50 | 605 | |
5a7d70fe | 606 | if ( changing.IsAllowed() ) |
e40298d5 | 607 | { |
5a7d70fe DS |
608 | wxNotebookEvent event( |
609 | wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId, | |
610 | newSel, m_nSelection ); | |
611 | event.SetEventObject( this ); | |
612 | GetEventHandler()->ProcessEvent( event ); | |
4c37f124 SC |
613 | } |
614 | else | |
615 | { | |
5ca0d812 | 616 | m_peer->SetValue( m_nSelection + 1 ) ; |
e40298d5 | 617 | } |
5a7d70fe | 618 | |
4c37f124 | 619 | status = noErr ; |
e40298d5 | 620 | } |
5a7d70fe DS |
621 | |
622 | return (wxInt32)status ; | |
ee6b1d97 SC |
623 | } |
624 | ||
179e085f | 625 | #endif |