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