]>
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 | ||
2b5f62a0 | 164 | if ( style & wxNB_MULTILINE ) |
0df3fbd7 VZ |
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 | 207 | |
2b5f62a0 VZ |
208 | if ( nPage != m_nSelection ) |
209 | { | |
210 | wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId); | |
211 | event.SetSelection(nPage); | |
212 | event.SetOldSelection(m_nSelection); | |
213 | event.SetEventObject(this); | |
214 | if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() ) | |
215 | { | |
216 | // program allows the page change | |
217 | event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); | |
218 | (void)GetEventHandler()->ProcessEvent(event); | |
219 | ||
220 | TabCtrl_SetCurSel(m_hwnd, nPage); | |
221 | } | |
222 | } | |
88310e2e | 223 | |
2b5f62a0 | 224 | return m_nSelection; |
88310e2e VZ |
225 | } |
226 | ||
88310e2e VZ |
227 | bool wxNotebook::SetPageText(int nPage, const wxString& strText) |
228 | { | |
223d09f6 | 229 | wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") ); |
88310e2e VZ |
230 | |
231 | TC_ITEM tcItem; | |
232 | tcItem.mask = TCIF_TEXT; | |
837e5743 | 233 | tcItem.pszText = (wxChar *)strText.c_str(); |
88310e2e VZ |
234 | |
235 | return TabCtrl_SetItem(m_hwnd, nPage, &tcItem) != 0; | |
236 | } | |
237 | ||
238 | wxString wxNotebook::GetPageText(int nPage) const | |
239 | { | |
223d09f6 | 240 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxT(""), wxT("notebook page out of range") ); |
88310e2e | 241 | |
837e5743 | 242 | wxChar buf[256]; |
88310e2e VZ |
243 | TC_ITEM tcItem; |
244 | tcItem.mask = TCIF_TEXT; | |
245 | tcItem.pszText = buf; | |
246 | tcItem.cchTextMax = WXSIZEOF(buf); | |
247 | ||
248 | wxString str; | |
249 | if ( TabCtrl_GetItem(m_hwnd, nPage, &tcItem) ) | |
250 | str = tcItem.pszText; | |
251 | ||
252 | return str; | |
253 | } | |
254 | ||
255 | int wxNotebook::GetPageImage(int nPage) const | |
256 | { | |
223d09f6 | 257 | wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") ); |
88310e2e VZ |
258 | |
259 | TC_ITEM tcItem; | |
260 | tcItem.mask = TCIF_IMAGE; | |
261 | ||
262 | return TabCtrl_GetItem(m_hwnd, nPage, &tcItem) ? tcItem.iImage : -1; | |
263 | } | |
264 | ||
265 | bool wxNotebook::SetPageImage(int nPage, int nImage) | |
266 | { | |
223d09f6 | 267 | wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") ); |
88310e2e VZ |
268 | |
269 | TC_ITEM tcItem; | |
270 | tcItem.mask = TCIF_IMAGE; | |
271 | tcItem.iImage = nImage; | |
272 | ||
273 | return TabCtrl_SetItem(m_hwnd, nPage, &tcItem) != 0; | |
274 | } | |
275 | ||
276 | void wxNotebook::SetImageList(wxImageList* imageList) | |
907f37b3 | 277 | { |
07b8d7ec VZ |
278 | wxNotebookBase::SetImageList(imageList); |
279 | ||
280 | if ( imageList ) | |
1e6feb95 | 281 | { |
07b8d7ec | 282 | TabCtrl_SetImageList(m_hwnd, (HIMAGELIST)imageList->GetHIMAGELIST()); |
1e6feb95 | 283 | } |
b656febd VS |
284 | } |
285 | ||
d9506e77 VZ |
286 | // ---------------------------------------------------------------------------- |
287 | // wxNotebook size settings | |
288 | // ---------------------------------------------------------------------------- | |
289 | ||
290 | void wxNotebook::SetPageSize(const wxSize& size) | |
291 | { | |
292 | // transform the page size into the notebook size | |
293 | RECT rc; | |
294 | rc.left = | |
295 | rc.top = 0; | |
296 | rc.right = size.x; | |
297 | rc.bottom = size.y; | |
298 | ||
299 | TabCtrl_AdjustRect(GetHwnd(), TRUE, &rc); | |
300 | ||
301 | // and now set it | |
302 | SetSize(rc.right - rc.left, rc.bottom - rc.top); | |
303 | } | |
304 | ||
305 | void wxNotebook::SetPadding(const wxSize& padding) | |
306 | { | |
307 | TabCtrl_SetPadding(GetHwnd(), padding.x, padding.y); | |
308 | } | |
42e69d6b VZ |
309 | |
310 | // Windows-only at present. Also, you must use the wxNB_FIXEDWIDTH | |
311 | // style. | |
312 | void wxNotebook::SetTabSize(const wxSize& sz) | |
313 | { | |
314 | ::SendMessage(GetHwnd(), TCM_SETITEMSIZE, 0, MAKELPARAM(sz.x, sz.y)); | |
315 | } | |
316 | ||
88310e2e VZ |
317 | // ---------------------------------------------------------------------------- |
318 | // wxNotebook operations | |
319 | // ---------------------------------------------------------------------------- | |
320 | ||
621793f4 | 321 | // remove one page from the notebook, without deleting |
1e6feb95 | 322 | wxNotebookPage *wxNotebook::DoRemovePage(int nPage) |
621793f4 | 323 | { |
df7145da VZ |
324 | wxNotebookPage *pageRemoved = wxNotebookBase::DoRemovePage(nPage); |
325 | if ( !pageRemoved ) | |
326 | return NULL; | |
621793f4 | 327 | |
df7145da | 328 | TabCtrl_DeleteItem(m_hwnd, nPage); |
621793f4 | 329 | |
df7145da VZ |
330 | if ( m_pages.IsEmpty() ) |
331 | { | |
332 | // no selection any more, the notebook becamse empty | |
333 | m_nSelection = -1; | |
334 | } | |
335 | else // notebook still not empty | |
336 | { | |
43a997b6 VZ |
337 | // change the selected page if it was deleted or became invalid |
338 | int selNew; | |
df7145da VZ |
339 | if ( m_nSelection == GetPageCount() ) |
340 | { | |
43a997b6 VZ |
341 | // last page deleted, make the new last page the new selection |
342 | selNew = m_nSelection - 1; | |
df7145da | 343 | } |
43a997b6 VZ |
344 | else if ( nPage <= m_nSelection ) |
345 | { | |
346 | // we must show another page, even if it has the same index | |
347 | selNew = m_nSelection; | |
348 | } | |
349 | else // nothing changes for the currently selected page | |
350 | { | |
351 | selNew = -1; | |
df7145da | 352 | |
43a997b6 VZ |
353 | // we still must refresh the current page: this needs to be done |
354 | // for some unknown reason if the tab control shows the up-down | |
355 | // control (i.e. when there are too many pages) -- otherwise after | |
356 | // deleting a page nothing at all is shown | |
357 | m_pages[m_nSelection]->Refresh(); | |
358 | } | |
359 | ||
360 | if ( selNew != -1 ) | |
361 | { | |
362 | // m_nSelection must be always valid so reset it before calling | |
363 | // SetSelection() | |
364 | m_nSelection = -1; | |
365 | SetSelection(selNew); | |
366 | } | |
df7145da | 367 | } |
47f12f58 | 368 | |
df7145da | 369 | return pageRemoved; |
621793f4 JS |
370 | } |
371 | ||
88310e2e VZ |
372 | // remove all pages |
373 | bool wxNotebook::DeleteAllPages() | |
374 | { | |
88310e2e VZ |
375 | int nPageCount = GetPageCount(); |
376 | int nPage; | |
377 | for ( nPage = 0; nPage < nPageCount; nPage++ ) | |
1e6feb95 | 378 | delete m_pages[nPage]; |
88310e2e | 379 | |
1e6feb95 | 380 | m_pages.Clear(); |
88310e2e | 381 | |
907f37b3 VZ |
382 | TabCtrl_DeleteAllItems(m_hwnd); |
383 | ||
47f12f58 JS |
384 | m_nSelection = -1; |
385 | ||
88310e2e VZ |
386 | return TRUE; |
387 | } | |
388 | ||
389 | // add a page to the notebook | |
390 | bool wxNotebook::AddPage(wxNotebookPage *pPage, | |
391 | const wxString& strText, | |
392 | bool bSelect, | |
393 | int imageId) | |
394 | { | |
395 | return InsertPage(GetPageCount(), pPage, strText, bSelect, imageId); | |
396 | } | |
397 | ||
398 | // same as AddPage() but does it at given position | |
399 | bool wxNotebook::InsertPage(int nPage, | |
400 | wxNotebookPage *pPage, | |
401 | const wxString& strText, | |
402 | bool bSelect, | |
403 | int imageId) | |
404 | { | |
405 | wxASSERT( pPage != NULL ); | |
406 | wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), FALSE ); | |
407 | ||
43427087 VZ |
408 | // do add the tab to the control |
409 | ||
410 | // init all fields to 0 | |
88310e2e | 411 | TC_ITEM tcItem; |
43427087 | 412 | memset(&tcItem, 0, sizeof(tcItem)); |
58a8ab88 | 413 | |
43427087 | 414 | if ( imageId != -1 ) |
58a8ab88 JS |
415 | { |
416 | tcItem.mask |= TCIF_IMAGE; | |
417 | tcItem.iImage = imageId; | |
418 | } | |
58a8ab88 | 419 | |
43427087 | 420 | if ( !strText.IsEmpty() ) |
58a8ab88 | 421 | { |
43427087 VZ |
422 | tcItem.mask |= TCIF_TEXT; |
423 | tcItem.pszText = (wxChar *)strText.c_str(); // const_cast | |
58a8ab88 | 424 | } |
88310e2e VZ |
425 | |
426 | if ( TabCtrl_InsertItem(m_hwnd, nPage, &tcItem) == -1 ) { | |
223d09f6 | 427 | wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str()); |
43427087 | 428 | |
88310e2e VZ |
429 | return FALSE; |
430 | } | |
431 | ||
43427087 VZ |
432 | // if the inserted page is before the selected one, we must update the |
433 | // index of the selected page | |
434 | if ( nPage <= m_nSelection ) | |
435 | { | |
436 | // one extra page added | |
437 | m_nSelection++; | |
438 | } | |
439 | ||
88310e2e | 440 | // save the pointer to the page |
1e6feb95 | 441 | m_pages.Insert(pPage, nPage); |
88310e2e | 442 | |
88310e2e | 443 | // don't show pages by default (we'll need to adjust their size first) |
42e69d6b | 444 | HWND hwnd = GetWinHwnd(pPage); |
88310e2e VZ |
445 | SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE); |
446 | ||
42e69d6b VZ |
447 | // this updates internal flag too - otherwise it will get out of sync |
448 | pPage->Show(FALSE); | |
449 | ||
0398b1d6 RD |
450 | // fit the notebook page to the tab control's display area |
451 | RECT rc; | |
452 | rc.left = rc.top = 0; | |
453 | GetSize((int *)&rc.right, (int *)&rc.bottom); | |
454 | TabCtrl_AdjustRect(m_hwnd, FALSE, &rc); | |
455 | pPage->SetSize(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); | |
0398b1d6 | 456 | |
43427087 VZ |
457 | // some page should be selected: either this one or the first one if there is |
458 | // still no selection | |
459 | int selNew = -1; | |
460 | if ( bSelect ) | |
461 | selNew = nPage; | |
462 | else if ( m_nSelection == -1 ) | |
463 | selNew = 0; | |
464 | ||
465 | if ( selNew != -1 ) | |
466 | SetSelection(selNew); | |
96d37807 | 467 | |
88310e2e VZ |
468 | return TRUE; |
469 | } | |
470 | ||
471 | // ---------------------------------------------------------------------------- | |
472 | // wxNotebook callbacks | |
473 | // ---------------------------------------------------------------------------- | |
474 | ||
9026ad85 | 475 | void wxNotebook::OnSize(wxSizeEvent& event) |
88310e2e | 476 | { |
b5c3b538 VZ |
477 | // fit the notebook page to the tab control's display area |
478 | RECT rc; | |
479 | rc.left = rc.top = 0; | |
480 | GetSize((int *)&rc.right, (int *)&rc.bottom); | |
481 | ||
482 | TabCtrl_AdjustRect(m_hwnd, FALSE, &rc); | |
4b7f2165 VZ |
483 | |
484 | int width = rc.right - rc.left, | |
485 | height = rc.bottom - rc.top; | |
1e6feb95 | 486 | size_t nCount = m_pages.Count(); |
c86f1403 | 487 | for ( size_t nPage = 0; nPage < nCount; nPage++ ) { |
1e6feb95 | 488 | wxNotebookPage *pPage = m_pages[nPage]; |
4b7f2165 | 489 | pPage->SetSize(rc.left, rc.top, width, height); |
b5c3b538 VZ |
490 | } |
491 | ||
88310e2e VZ |
492 | event.Skip(); |
493 | } | |
494 | ||
495 | void wxNotebook::OnSelChange(wxNotebookEvent& event) | |
496 | { | |
497 | // is it our tab control? | |
498 | if ( event.GetEventObject() == this ) | |
5d1d2d46 | 499 | { |
5d1d2d46 VZ |
500 | int sel = event.GetOldSelection(); |
501 | if ( sel != -1 ) | |
1e6feb95 | 502 | m_pages[sel]->Show(FALSE); |
0398b1d6 | 503 | |
5d1d2d46 VZ |
504 | sel = event.GetSelection(); |
505 | if ( sel != -1 ) | |
506 | { | |
1e6feb95 | 507 | wxNotebookPage *pPage = m_pages[sel]; |
5d1d2d46 VZ |
508 | pPage->Show(TRUE); |
509 | pPage->SetFocus(); | |
510 | } | |
0398b1d6 | 511 | |
5d1d2d46 VZ |
512 | m_nSelection = sel; |
513 | } | |
88310e2e VZ |
514 | |
515 | // we want to give others a chance to process this message as well | |
516 | event.Skip(); | |
517 | } | |
518 | ||
519 | void wxNotebook::OnSetFocus(wxFocusEvent& event) | |
520 | { | |
d9506e77 VZ |
521 | // this function is only called when the focus is explicitly set (i.e. from |
522 | // the program) to the notebook - in this case we don't need the | |
523 | // complicated OnNavigationKey() logic because the programmer knows better | |
524 | // what [s]he wants | |
88310e2e | 525 | |
d9506e77 VZ |
526 | // set focus to the currently selected page if any |
527 | if ( m_nSelection != -1 ) | |
1e6feb95 | 528 | m_pages[m_nSelection]->SetFocus(); |
d9506e77 VZ |
529 | |
530 | event.Skip(); | |
88310e2e VZ |
531 | } |
532 | ||
533 | void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) | |
534 | { | |
d9506e77 VZ |
535 | if ( event.IsWindowChange() ) { |
536 | // change pages | |
537 | AdvanceSelection(event.GetDirection()); | |
538 | } | |
539 | else { | |
540 | // we get this event in 2 cases | |
541 | // | |
542 | // a) one of our pages might have generated it because the user TABbed | |
543 | // out from it in which case we should propagate the event upwards and | |
544 | // our parent will take care of setting the focus to prev/next sibling | |
545 | // | |
546 | // or | |
547 | // | |
548 | // b) the parent panel wants to give the focus to us so that we | |
549 | // forward it to our selected page. We can't deal with this in | |
550 | // OnSetFocus() because we don't know which direction the focus came | |
551 | // from in this case and so can't choose between setting the focus to | |
552 | // first or last panel child | |
553 | ||
554 | wxWindow *parent = GetParent(); | |
555 | if ( event.GetEventObject() == parent ) | |
556 | { | |
557 | // no, it doesn't come from child, case (b): forward to a page | |
558 | if ( m_nSelection != -1 ) | |
559 | { | |
560 | // so that the page knows that the event comes from it's parent | |
561 | // and is being propagated downwards | |
562 | event.SetEventObject(this); | |
563 | ||
1e6feb95 | 564 | wxWindow *page = m_pages[m_nSelection]; |
d9506e77 VZ |
565 | if ( !page->GetEventHandler()->ProcessEvent(event) ) |
566 | { | |
567 | page->SetFocus(); | |
568 | } | |
569 | //else: page manages focus inside it itself | |
570 | } | |
571 | else | |
572 | { | |
573 | // we have no pages - still have to give focus to _something_ | |
574 | SetFocus(); | |
575 | } | |
576 | } | |
577 | else | |
578 | { | |
579 | // it comes from our child, case (a), pass to the parent | |
580 | if ( parent ) { | |
581 | event.SetCurrentFocus(this); | |
582 | parent->GetEventHandler()->ProcessEvent(event); | |
583 | } | |
584 | } | |
88310e2e | 585 | } |
88310e2e VZ |
586 | } |
587 | ||
588 | // ---------------------------------------------------------------------------- | |
589 | // wxNotebook base class virtuals | |
590 | // ---------------------------------------------------------------------------- | |
b5c3b538 VZ |
591 | |
592 | // override these 2 functions to do nothing: everything is done in OnSize | |
593 | ||
4b7f2165 | 594 | void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse)) |
b5c3b538 VZ |
595 | { |
596 | // don't set the sizes of the pages - their correct size is not yet known | |
597 | wxControl::SetConstraintSizes(FALSE); | |
598 | } | |
599 | ||
4b7f2165 | 600 | bool wxNotebook::DoPhase(int WXUNUSED(nPhase)) |
b5c3b538 VZ |
601 | { |
602 | return TRUE; | |
603 | } | |
604 | ||
0df3fbd7 VZ |
605 | // ---------------------------------------------------------------------------- |
606 | // wxNotebook Windows message handlers | |
607 | // ---------------------------------------------------------------------------- | |
608 | ||
609 | bool wxNotebook::MSWOnScroll(int orientation, WXWORD nSBCode, | |
610 | WXWORD pos, WXHWND control) | |
611 | { | |
612 | // don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the | |
613 | // up-down control | |
614 | if ( control ) | |
615 | return FALSE; | |
616 | ||
617 | return wxNotebookBase::MSWOnScroll(orientation, nSBCode, pos, control); | |
618 | } | |
619 | ||
a23fd0e1 | 620 | bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result) |
88310e2e | 621 | { |
93a19f17 | 622 | wxNotebookEvent event(wxEVT_NULL, m_windowId); |
88310e2e VZ |
623 | |
624 | NMHDR* hdr = (NMHDR *)lParam; | |
625 | switch ( hdr->code ) { | |
626 | case TCN_SELCHANGE: | |
627 | event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); | |
628 | break; | |
629 | ||
630 | case TCN_SELCHANGING: | |
631 | event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING); | |
632 | break; | |
633 | ||
fd3f686c | 634 | default: |
a23fd0e1 | 635 | return wxControl::MSWOnNotify(idCtrl, lParam, result); |
88310e2e VZ |
636 | } |
637 | ||
93a19f17 VZ |
638 | event.SetSelection(TabCtrl_GetCurSel(m_hwnd)); |
639 | event.SetOldSelection(m_nSelection); | |
88310e2e | 640 | event.SetEventObject(this); |
a23fd0e1 | 641 | event.SetInt(idCtrl); |
88310e2e | 642 | |
fd3f686c VZ |
643 | bool processed = GetEventHandler()->ProcessEvent(event); |
644 | *result = !event.IsAllowed(); | |
645 | return processed; | |
88310e2e VZ |
646 | } |
647 | ||
1e6feb95 | 648 | #endif // wxUSE_NOTEBOOK |