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