]>
Commit | Line | Data |
---|---|---|
88310e2e VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: msw/notebook.cpp | |
3 | // Purpose: implementation of wxNotebook | |
4 | // Author: Vadim Zeitlin | |
907f37b3 | 5 | // Modified by: |
88310e2e VZ |
6 | // Created: 11.06.98 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
9 | // Licence: wxWindows license | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
88310e2e | 12 | #ifdef __GNUG__ |
a3b46648 | 13 | #pragma implementation "notebook.h" |
88310e2e VZ |
14 | #endif |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
1e6feb95 | 20 | #pragma hdrstop |
88310e2e VZ |
21 | #endif |
22 | ||
1e6feb95 VZ |
23 | #if wxUSE_NOTEBOOK |
24 | ||
88310e2e VZ |
25 | // wxWindows |
26 | #ifndef WX_PRECOMP | |
3096bd2f | 27 | #include "wx/string.h" |
88310e2e VZ |
28 | #endif // WX_PRECOMP |
29 | ||
3096bd2f VZ |
30 | #include "wx/log.h" |
31 | #include "wx/imaglist.h" | |
32 | #include "wx/event.h" | |
33 | #include "wx/control.h" | |
34 | #include "wx/notebook.h" | |
88310e2e | 35 | |
3096bd2f | 36 | #include "wx/msw/private.h" |
88310e2e VZ |
37 | |
38 | // Windows standard headers | |
39 | #ifndef __WIN95__ | |
2432b92d | 40 | #error "wxNotebook is only supported Windows 95 and above" |
88310e2e VZ |
41 | #endif //Win95 |
42 | ||
aaab7c01 VZ |
43 | #include <windowsx.h> // for SetWindowFont |
44 | ||
57c208c5 | 45 | #ifndef __TWIN32__ |
c42404a5 VZ |
46 | #ifdef __GNUWIN32_OLD__ |
47 | #include "wx/msw/gnuwin32/extra.h" | |
48 | #endif | |
65fd5cb0 | 49 | #endif |
57c208c5 | 50 | |
ae090fdb | 51 | #if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__)) |
c42404a5 | 52 | #include <commctrl.h> |
88310e2e VZ |
53 | #endif |
54 | ||
55 | // ---------------------------------------------------------------------------- | |
56 | // macros | |
57 | // ---------------------------------------------------------------------------- | |
58 | ||
59 | // check that the page index is valid | |
60 | #define IS_VALID_PAGE(nPage) (((nPage) >= 0) && ((nPage) < GetPageCount())) | |
61 | ||
62 | // hide the ugly cast | |
63 | #define m_hwnd (HWND)GetHWND() | |
64 | ||
74b31181 VZ |
65 | // ---------------------------------------------------------------------------- |
66 | // constants | |
67 | // ---------------------------------------------------------------------------- | |
68 | ||
69 | // This is a work-around for missing defines in gcc-2.95 headers | |
70 | #ifndef TCS_RIGHT | |
71 | #define TCS_RIGHT 0x0002 | |
72 | #endif | |
73 | ||
74 | #ifndef TCS_VERTICAL | |
75 | #define TCS_VERTICAL 0x0080 | |
76 | #endif | |
77 | ||
78 | #ifndef TCS_BOTTOM | |
79 | #define TCS_BOTTOM TCS_RIGHT | |
80 | #endif | |
81 | ||
88310e2e VZ |
82 | // ---------------------------------------------------------------------------- |
83 | // event table | |
84 | // ---------------------------------------------------------------------------- | |
85 | ||
2e4df4bf VZ |
86 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED) |
87 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING) | |
88 | ||
d9317fd4 | 89 | BEGIN_EVENT_TABLE(wxNotebook, wxControl) |
88310e2e VZ |
90 | EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange) |
91 | ||
9026ad85 | 92 | EVT_SIZE(wxNotebook::OnSize) |
42e69d6b | 93 | |
88310e2e | 94 | EVT_SET_FOCUS(wxNotebook::OnSetFocus) |
42e69d6b | 95 | |
88310e2e | 96 | EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) |
d9317fd4 | 97 | END_EVENT_TABLE() |
88310e2e | 98 | |
d9317fd4 VZ |
99 | IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl) |
100 | IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent) | |
88310e2e VZ |
101 | |
102 | // ============================================================================ | |
103 | // implementation | |
104 | // ============================================================================ | |
105 | ||
106 | // ---------------------------------------------------------------------------- | |
107 | // wxNotebook construction | |
108 | // ---------------------------------------------------------------------------- | |
109 | ||
110 | // common part of all ctors | |
111 | void wxNotebook::Init() | |
112 | { | |
1e6feb95 | 113 | m_imageList = NULL; |
88310e2e VZ |
114 | m_nSelection = -1; |
115 | } | |
116 | ||
117 | // default for dynamic class | |
118 | wxNotebook::wxNotebook() | |
119 | { | |
120 | Init(); | |
121 | } | |
122 | ||
123 | // the same arguments as for wxControl | |
124 | wxNotebook::wxNotebook(wxWindow *parent, | |
8b9518ee | 125 | wxWindowID id, |
88310e2e VZ |
126 | const wxPoint& pos, |
127 | const wxSize& size, | |
8b9518ee | 128 | long style, |
88310e2e VZ |
129 | const wxString& name) |
130 | { | |
131 | Init(); | |
132 | ||
133 | Create(parent, id, pos, size, style, name); | |
134 | } | |
135 | ||
136 | // Create() function | |
137 | bool wxNotebook::Create(wxWindow *parent, | |
8b9518ee | 138 | wxWindowID id, |
88310e2e VZ |
139 | const wxPoint& pos, |
140 | const wxSize& size, | |
8b9518ee | 141 | long style, |
88310e2e VZ |
142 | const wxString& name) |
143 | { | |
0df3fbd7 VZ |
144 | // base init |
145 | if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) ) | |
146 | return FALSE; | |
88310e2e | 147 | |
0df3fbd7 VZ |
148 | // notebook, so explicitly specify 0 as last parameter |
149 | if ( !MSWCreateControl(WC_TABCONTROL, _T(""), pos, size, | |
150 | style | wxTAB_TRAVERSAL) ) | |
151 | return FALSE; | |
907f37b3 | 152 | |
0df3fbd7 VZ |
153 | SetBackgroundColour(wxColour(::GetSysColor(COLOR_BTNFACE))); |
154 | ||
155 | return TRUE; | |
156 | } | |
157 | ||
158 | WXDWORD wxNotebook::MSWGetStyle(long style, WXDWORD *exstyle) const | |
159 | { | |
160 | WXDWORD tabStyle = wxControl::MSWGetStyle(style, exstyle); | |
161 | ||
162 | tabStyle |= WS_TABSTOP | TCS_TABS; | |
163 | ||
164 | if ( style & wxTC_MULTILINE ) | |
165 | tabStyle |= TCS_MULTILINE; | |
166 | if ( style & wxNB_FIXEDWIDTH ) | |
167 | tabStyle |= TCS_FIXEDWIDTH; | |
168 | ||
169 | if ( style & wxNB_BOTTOM ) | |
170 | tabStyle |= TCS_RIGHT; | |
171 | else if ( style & wxNB_LEFT ) | |
172 | tabStyle |= TCS_VERTICAL; | |
173 | else if ( style & wxNB_RIGHT ) | |
174 | tabStyle |= TCS_VERTICAL | TCS_RIGHT; | |
175 | ||
176 | // ex style | |
177 | if ( exstyle ) | |
178 | { | |
179 | // note that we never want to have the default WS_EX_CLIENTEDGE style | |
180 | // as it looks too ugly for the notebooks | |
181 | *exstyle = 0; | |
182 | } | |
183 | ||
184 | return tabStyle; | |
88310e2e VZ |
185 | } |
186 | ||
88310e2e VZ |
187 | // ---------------------------------------------------------------------------- |
188 | // wxNotebook accessors | |
189 | // ---------------------------------------------------------------------------- | |
07b8d7ec | 190 | |
88310e2e VZ |
191 | int wxNotebook::GetPageCount() const |
192 | { | |
193 | // consistency check | |
1e6feb95 | 194 | wxASSERT( (int)m_pages.Count() == TabCtrl_GetItemCount(m_hwnd) ); |
88310e2e | 195 | |
1e6feb95 | 196 | return m_pages.Count(); |
88310e2e VZ |
197 | } |
198 | ||
199 | int wxNotebook::GetRowCount() const | |
200 | { | |
201 | return TabCtrl_GetRowCount(m_hwnd); | |
202 | } | |
203 | ||
204 | int wxNotebook::SetSelection(int nPage) | |
205 | { | |
223d09f6 | 206 | wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") ); |
88310e2e VZ |
207 | |
208 | ChangePage(m_nSelection, nPage); | |
209 | ||
210 | return TabCtrl_SetCurSel(m_hwnd, nPage); | |
211 | } | |
212 | ||
88310e2e VZ |
213 | bool wxNotebook::SetPageText(int nPage, const wxString& strText) |
214 | { | |
223d09f6 | 215 | wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") ); |
88310e2e VZ |
216 | |
217 | TC_ITEM tcItem; | |
218 | tcItem.mask = TCIF_TEXT; | |
837e5743 | 219 | tcItem.pszText = (wxChar *)strText.c_str(); |
88310e2e VZ |
220 | |
221 | return TabCtrl_SetItem(m_hwnd, nPage, &tcItem) != 0; | |
222 | } | |
223 | ||
224 | wxString wxNotebook::GetPageText(int nPage) const | |
225 | { | |
223d09f6 | 226 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxT(""), wxT("notebook page out of range") ); |
88310e2e | 227 | |
837e5743 | 228 | wxChar buf[256]; |
88310e2e VZ |
229 | TC_ITEM tcItem; |
230 | tcItem.mask = TCIF_TEXT; | |
231 | tcItem.pszText = buf; | |
232 | tcItem.cchTextMax = WXSIZEOF(buf); | |
233 | ||
234 | wxString str; | |
235 | if ( TabCtrl_GetItem(m_hwnd, nPage, &tcItem) ) | |
236 | str = tcItem.pszText; | |
237 | ||
238 | return str; | |
239 | } | |
240 | ||
241 | int wxNotebook::GetPageImage(int nPage) const | |
242 | { | |
223d09f6 | 243 | wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") ); |
88310e2e VZ |
244 | |
245 | TC_ITEM tcItem; | |
246 | tcItem.mask = TCIF_IMAGE; | |
247 | ||
248 | return TabCtrl_GetItem(m_hwnd, nPage, &tcItem) ? tcItem.iImage : -1; | |
249 | } | |
250 | ||
251 | bool wxNotebook::SetPageImage(int nPage, int nImage) | |
252 | { | |
223d09f6 | 253 | wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") ); |
88310e2e VZ |
254 | |
255 | TC_ITEM tcItem; | |
256 | tcItem.mask = TCIF_IMAGE; | |
257 | tcItem.iImage = nImage; | |
258 | ||
259 | return TabCtrl_SetItem(m_hwnd, nPage, &tcItem) != 0; | |
260 | } | |
261 | ||
262 | void wxNotebook::SetImageList(wxImageList* imageList) | |
907f37b3 | 263 | { |
07b8d7ec VZ |
264 | wxNotebookBase::SetImageList(imageList); |
265 | ||
266 | if ( imageList ) | |
1e6feb95 | 267 | { |
07b8d7ec | 268 | TabCtrl_SetImageList(m_hwnd, (HIMAGELIST)imageList->GetHIMAGELIST()); |
1e6feb95 | 269 | } |
b656febd VS |
270 | } |
271 | ||
d9506e77 VZ |
272 | // ---------------------------------------------------------------------------- |
273 | // wxNotebook size settings | |
274 | // ---------------------------------------------------------------------------- | |
275 | ||
276 | void wxNotebook::SetPageSize(const wxSize& size) | |
277 | { | |
278 | // transform the page size into the notebook size | |
279 | RECT rc; | |
280 | rc.left = | |
281 | rc.top = 0; | |
282 | rc.right = size.x; | |
283 | rc.bottom = size.y; | |
284 | ||
285 | TabCtrl_AdjustRect(GetHwnd(), TRUE, &rc); | |
286 | ||
287 | // and now set it | |
288 | SetSize(rc.right - rc.left, rc.bottom - rc.top); | |
289 | } | |
290 | ||
291 | void wxNotebook::SetPadding(const wxSize& padding) | |
292 | { | |
293 | TabCtrl_SetPadding(GetHwnd(), padding.x, padding.y); | |
294 | } | |
42e69d6b VZ |
295 | |
296 | // Windows-only at present. Also, you must use the wxNB_FIXEDWIDTH | |
297 | // style. | |
298 | void wxNotebook::SetTabSize(const wxSize& sz) | |
299 | { | |
300 | ::SendMessage(GetHwnd(), TCM_SETITEMSIZE, 0, MAKELPARAM(sz.x, sz.y)); | |
301 | } | |
302 | ||
88310e2e VZ |
303 | // ---------------------------------------------------------------------------- |
304 | // wxNotebook operations | |
305 | // ---------------------------------------------------------------------------- | |
306 | ||
621793f4 | 307 | // remove one page from the notebook, without deleting |
1e6feb95 | 308 | wxNotebookPage *wxNotebook::DoRemovePage(int nPage) |
621793f4 | 309 | { |
df7145da VZ |
310 | wxNotebookPage *pageRemoved = wxNotebookBase::DoRemovePage(nPage); |
311 | if ( !pageRemoved ) | |
312 | return NULL; | |
621793f4 | 313 | |
df7145da | 314 | TabCtrl_DeleteItem(m_hwnd, nPage); |
621793f4 | 315 | |
df7145da VZ |
316 | if ( m_pages.IsEmpty() ) |
317 | { | |
318 | // no selection any more, the notebook becamse empty | |
319 | m_nSelection = -1; | |
320 | } | |
321 | else // notebook still not empty | |
322 | { | |
43a997b6 VZ |
323 | // change the selected page if it was deleted or became invalid |
324 | int selNew; | |
df7145da VZ |
325 | if ( m_nSelection == GetPageCount() ) |
326 | { | |
43a997b6 VZ |
327 | // last page deleted, make the new last page the new selection |
328 | selNew = m_nSelection - 1; | |
df7145da | 329 | } |
43a997b6 VZ |
330 | else if ( nPage <= m_nSelection ) |
331 | { | |
332 | // we must show another page, even if it has the same index | |
333 | selNew = m_nSelection; | |
334 | } | |
335 | else // nothing changes for the currently selected page | |
336 | { | |
337 | selNew = -1; | |
df7145da | 338 | |
43a997b6 VZ |
339 | // we still must refresh the current page: this needs to be done |
340 | // for some unknown reason if the tab control shows the up-down | |
341 | // control (i.e. when there are too many pages) -- otherwise after | |
342 | // deleting a page nothing at all is shown | |
343 | m_pages[m_nSelection]->Refresh(); | |
344 | } | |
345 | ||
346 | if ( selNew != -1 ) | |
347 | { | |
348 | // m_nSelection must be always valid so reset it before calling | |
349 | // SetSelection() | |
350 | m_nSelection = -1; | |
351 | SetSelection(selNew); | |
352 | } | |
df7145da | 353 | } |
47f12f58 | 354 | |
df7145da | 355 | return pageRemoved; |
621793f4 JS |
356 | } |
357 | ||
88310e2e VZ |
358 | // remove all pages |
359 | bool wxNotebook::DeleteAllPages() | |
360 | { | |
88310e2e VZ |
361 | int nPageCount = GetPageCount(); |
362 | int nPage; | |
363 | for ( nPage = 0; nPage < nPageCount; nPage++ ) | |
1e6feb95 | 364 | delete m_pages[nPage]; |
88310e2e | 365 | |
1e6feb95 | 366 | m_pages.Clear(); |
88310e2e | 367 | |
907f37b3 VZ |
368 | TabCtrl_DeleteAllItems(m_hwnd); |
369 | ||
47f12f58 JS |
370 | m_nSelection = -1; |
371 | ||
88310e2e VZ |
372 | return TRUE; |
373 | } | |
374 | ||
375 | // add a page to the notebook | |
376 | bool wxNotebook::AddPage(wxNotebookPage *pPage, | |
377 | const wxString& strText, | |
378 | bool bSelect, | |
379 | int imageId) | |
380 | { | |
381 | return InsertPage(GetPageCount(), pPage, strText, bSelect, imageId); | |
382 | } | |
383 | ||
384 | // same as AddPage() but does it at given position | |
385 | bool wxNotebook::InsertPage(int nPage, | |
386 | wxNotebookPage *pPage, | |
387 | const wxString& strText, | |
388 | bool bSelect, | |
389 | int imageId) | |
390 | { | |
391 | wxASSERT( pPage != NULL ); | |
392 | wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), FALSE ); | |
393 | ||
43427087 VZ |
394 | // do add the tab to the control |
395 | ||
396 | // init all fields to 0 | |
88310e2e | 397 | TC_ITEM tcItem; |
43427087 | 398 | memset(&tcItem, 0, sizeof(tcItem)); |
58a8ab88 | 399 | |
43427087 | 400 | if ( imageId != -1 ) |
58a8ab88 JS |
401 | { |
402 | tcItem.mask |= TCIF_IMAGE; | |
403 | tcItem.iImage = imageId; | |
404 | } | |
58a8ab88 | 405 | |
43427087 | 406 | if ( !strText.IsEmpty() ) |
58a8ab88 | 407 | { |
43427087 VZ |
408 | tcItem.mask |= TCIF_TEXT; |
409 | tcItem.pszText = (wxChar *)strText.c_str(); // const_cast | |
58a8ab88 | 410 | } |
88310e2e VZ |
411 | |
412 | if ( TabCtrl_InsertItem(m_hwnd, nPage, &tcItem) == -1 ) { | |
223d09f6 | 413 | wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str()); |
43427087 | 414 | |
88310e2e VZ |
415 | return FALSE; |
416 | } | |
417 | ||
43427087 VZ |
418 | // if the inserted page is before the selected one, we must update the |
419 | // index of the selected page | |
420 | if ( nPage <= m_nSelection ) | |
421 | { | |
422 | // one extra page added | |
423 | m_nSelection++; | |
424 | } | |
425 | ||
88310e2e | 426 | // save the pointer to the page |
1e6feb95 | 427 | m_pages.Insert(pPage, nPage); |
88310e2e | 428 | |
88310e2e | 429 | // don't show pages by default (we'll need to adjust their size first) |
42e69d6b | 430 | HWND hwnd = GetWinHwnd(pPage); |
88310e2e VZ |
431 | SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE); |
432 | ||
42e69d6b VZ |
433 | // this updates internal flag too - otherwise it will get out of sync |
434 | pPage->Show(FALSE); | |
435 | ||
0398b1d6 RD |
436 | // fit the notebook page to the tab control's display area |
437 | RECT rc; | |
438 | rc.left = rc.top = 0; | |
439 | GetSize((int *)&rc.right, (int *)&rc.bottom); | |
440 | TabCtrl_AdjustRect(m_hwnd, FALSE, &rc); | |
441 | pPage->SetSize(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); | |
0398b1d6 | 442 | |
43427087 VZ |
443 | // some page should be selected: either this one or the first one if there is |
444 | // still no selection | |
445 | int selNew = -1; | |
446 | if ( bSelect ) | |
447 | selNew = nPage; | |
448 | else if ( m_nSelection == -1 ) | |
449 | selNew = 0; | |
450 | ||
451 | if ( selNew != -1 ) | |
452 | SetSelection(selNew); | |
96d37807 | 453 | |
88310e2e VZ |
454 | return TRUE; |
455 | } | |
456 | ||
457 | // ---------------------------------------------------------------------------- | |
458 | // wxNotebook callbacks | |
459 | // ---------------------------------------------------------------------------- | |
460 | ||
9026ad85 | 461 | void wxNotebook::OnSize(wxSizeEvent& event) |
88310e2e | 462 | { |
b5c3b538 VZ |
463 | // fit the notebook page to the tab control's display area |
464 | RECT rc; | |
465 | rc.left = rc.top = 0; | |
466 | GetSize((int *)&rc.right, (int *)&rc.bottom); | |
467 | ||
468 | TabCtrl_AdjustRect(m_hwnd, FALSE, &rc); | |
4b7f2165 VZ |
469 | |
470 | int width = rc.right - rc.left, | |
471 | height = rc.bottom - rc.top; | |
1e6feb95 | 472 | size_t nCount = m_pages.Count(); |
c86f1403 | 473 | for ( size_t nPage = 0; nPage < nCount; nPage++ ) { |
1e6feb95 | 474 | wxNotebookPage *pPage = m_pages[nPage]; |
4b7f2165 | 475 | pPage->SetSize(rc.left, rc.top, width, height); |
b5c3b538 VZ |
476 | } |
477 | ||
88310e2e VZ |
478 | event.Skip(); |
479 | } | |
480 | ||
481 | void wxNotebook::OnSelChange(wxNotebookEvent& event) | |
482 | { | |
483 | // is it our tab control? | |
484 | if ( event.GetEventObject() == this ) | |
5d1d2d46 | 485 | { |
5d1d2d46 VZ |
486 | int sel = event.GetOldSelection(); |
487 | if ( sel != -1 ) | |
1e6feb95 | 488 | m_pages[sel]->Show(FALSE); |
0398b1d6 | 489 | |
5d1d2d46 VZ |
490 | sel = event.GetSelection(); |
491 | if ( sel != -1 ) | |
492 | { | |
1e6feb95 | 493 | wxNotebookPage *pPage = m_pages[sel]; |
5d1d2d46 VZ |
494 | pPage->Show(TRUE); |
495 | pPage->SetFocus(); | |
496 | } | |
0398b1d6 | 497 | |
5d1d2d46 VZ |
498 | m_nSelection = sel; |
499 | } | |
88310e2e VZ |
500 | |
501 | // we want to give others a chance to process this message as well | |
502 | event.Skip(); | |
503 | } | |
504 | ||
505 | void wxNotebook::OnSetFocus(wxFocusEvent& event) | |
506 | { | |
d9506e77 VZ |
507 | // this function is only called when the focus is explicitly set (i.e. from |
508 | // the program) to the notebook - in this case we don't need the | |
509 | // complicated OnNavigationKey() logic because the programmer knows better | |
510 | // what [s]he wants | |
88310e2e | 511 | |
d9506e77 VZ |
512 | // set focus to the currently selected page if any |
513 | if ( m_nSelection != -1 ) | |
1e6feb95 | 514 | m_pages[m_nSelection]->SetFocus(); |
d9506e77 VZ |
515 | |
516 | event.Skip(); | |
88310e2e VZ |
517 | } |
518 | ||
519 | void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) | |
520 | { | |
d9506e77 VZ |
521 | if ( event.IsWindowChange() ) { |
522 | // change pages | |
523 | AdvanceSelection(event.GetDirection()); | |
524 | } | |
525 | else { | |
526 | // we get this event in 2 cases | |
527 | // | |
528 | // a) one of our pages might have generated it because the user TABbed | |
529 | // out from it in which case we should propagate the event upwards and | |
530 | // our parent will take care of setting the focus to prev/next sibling | |
531 | // | |
532 | // or | |
533 | // | |
534 | // b) the parent panel wants to give the focus to us so that we | |
535 | // forward it to our selected page. We can't deal with this in | |
536 | // OnSetFocus() because we don't know which direction the focus came | |
537 | // from in this case and so can't choose between setting the focus to | |
538 | // first or last panel child | |
539 | ||
540 | wxWindow *parent = GetParent(); | |
541 | if ( event.GetEventObject() == parent ) | |
542 | { | |
543 | // no, it doesn't come from child, case (b): forward to a page | |
544 | if ( m_nSelection != -1 ) | |
545 | { | |
546 | // so that the page knows that the event comes from it's parent | |
547 | // and is being propagated downwards | |
548 | event.SetEventObject(this); | |
549 | ||
1e6feb95 | 550 | wxWindow *page = m_pages[m_nSelection]; |
d9506e77 VZ |
551 | if ( !page->GetEventHandler()->ProcessEvent(event) ) |
552 | { | |
553 | page->SetFocus(); | |
554 | } | |
555 | //else: page manages focus inside it itself | |
556 | } | |
557 | else | |
558 | { | |
559 | // we have no pages - still have to give focus to _something_ | |
560 | SetFocus(); | |
561 | } | |
562 | } | |
563 | else | |
564 | { | |
565 | // it comes from our child, case (a), pass to the parent | |
566 | if ( parent ) { | |
567 | event.SetCurrentFocus(this); | |
568 | parent->GetEventHandler()->ProcessEvent(event); | |
569 | } | |
570 | } | |
88310e2e | 571 | } |
88310e2e VZ |
572 | } |
573 | ||
574 | // ---------------------------------------------------------------------------- | |
575 | // wxNotebook base class virtuals | |
576 | // ---------------------------------------------------------------------------- | |
b5c3b538 VZ |
577 | |
578 | // override these 2 functions to do nothing: everything is done in OnSize | |
579 | ||
4b7f2165 | 580 | void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse)) |
b5c3b538 VZ |
581 | { |
582 | // don't set the sizes of the pages - their correct size is not yet known | |
583 | wxControl::SetConstraintSizes(FALSE); | |
584 | } | |
585 | ||
4b7f2165 | 586 | bool wxNotebook::DoPhase(int WXUNUSED(nPhase)) |
b5c3b538 VZ |
587 | { |
588 | return TRUE; | |
589 | } | |
590 | ||
0df3fbd7 VZ |
591 | // ---------------------------------------------------------------------------- |
592 | // wxNotebook Windows message handlers | |
593 | // ---------------------------------------------------------------------------- | |
594 | ||
595 | bool wxNotebook::MSWOnScroll(int orientation, WXWORD nSBCode, | |
596 | WXWORD pos, WXHWND control) | |
597 | { | |
598 | // don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the | |
599 | // up-down control | |
600 | if ( control ) | |
601 | return FALSE; | |
602 | ||
603 | return wxNotebookBase::MSWOnScroll(orientation, nSBCode, pos, control); | |
604 | } | |
605 | ||
a23fd0e1 | 606 | bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result) |
88310e2e | 607 | { |
93a19f17 | 608 | wxNotebookEvent event(wxEVT_NULL, m_windowId); |
88310e2e VZ |
609 | |
610 | NMHDR* hdr = (NMHDR *)lParam; | |
611 | switch ( hdr->code ) { | |
612 | case TCN_SELCHANGE: | |
613 | event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); | |
614 | break; | |
615 | ||
616 | case TCN_SELCHANGING: | |
617 | event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING); | |
618 | break; | |
619 | ||
fd3f686c | 620 | default: |
a23fd0e1 | 621 | return wxControl::MSWOnNotify(idCtrl, lParam, result); |
88310e2e VZ |
622 | } |
623 | ||
93a19f17 VZ |
624 | event.SetSelection(TabCtrl_GetCurSel(m_hwnd)); |
625 | event.SetOldSelection(m_nSelection); | |
88310e2e | 626 | event.SetEventObject(this); |
a23fd0e1 | 627 | event.SetInt(idCtrl); |
88310e2e | 628 | |
fd3f686c VZ |
629 | bool processed = GetEventHandler()->ProcessEvent(event); |
630 | *result = !event.IsAllowed(); | |
631 | return processed; | |
88310e2e VZ |
632 | } |
633 | ||
634 | // ---------------------------------------------------------------------------- | |
635 | // wxNotebook helper functions | |
636 | // ---------------------------------------------------------------------------- | |
637 | ||
43427087 VZ |
638 | // generate the page changing and changed events, hide the currently active |
639 | // panel and show the new one | |
88310e2e VZ |
640 | void wxNotebook::ChangePage(int nOldSel, int nSel) |
641 | { | |
fd3f686c VZ |
642 | // MT-FIXME should use a real semaphore |
643 | static bool s_bInsideChangePage = FALSE; | |
644 | ||
645 | // when we call ProcessEvent(), our own OnSelChange() is called which calls | |
646 | // this function - break the infinite loop | |
647 | if ( s_bInsideChangePage ) | |
648 | return; | |
649 | ||
aaab7c01 VZ |
650 | // it's not an error (the message may be generated by the tab control itself) |
651 | // and it may happen - just do nothing | |
652 | if ( nSel == nOldSel ) | |
653 | return; | |
88310e2e | 654 | |
fd3f686c VZ |
655 | s_bInsideChangePage = TRUE; |
656 | ||
657 | wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId); | |
658 | event.SetSelection(nSel); | |
659 | event.SetOldSelection(nOldSel); | |
660 | event.SetEventObject(this); | |
1e6feb95 | 661 | if ( GetEventHandler()->ProcessEvent(event) && !event.IsAllowed() ) |
fd3f686c VZ |
662 | { |
663 | // program doesn't allow the page change | |
664 | s_bInsideChangePage = FALSE; | |
665 | return; | |
666 | } | |
667 | ||
fd3f686c | 668 | event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); |
1e6feb95 | 669 | GetEventHandler()->ProcessEvent(event); |
fd3f686c | 670 | |
fd3f686c | 671 | s_bInsideChangePage = FALSE; |
88310e2e | 672 | } |
1e6feb95 VZ |
673 | |
674 | #endif // wxUSE_NOTEBOOK |