]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/os2/notebook.cpp | |
3 | // Purpose: implementation of wxNotebook | |
4 | // Author: David Webster | |
5 | // Modified by: | |
6 | // Created: 10/12/99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) David Webster | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // For compilers that support precompilation, includes "wx.h". | |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #if wxUSE_NOTEBOOK | |
16 | ||
17 | #include "wx/notebook.h" | |
18 | ||
19 | // wxWidgets | |
20 | #ifndef WX_PRECOMP | |
21 | #include "wx/app.h" | |
22 | #include "wx/dcclient.h" | |
23 | #include "wx/string.h" | |
24 | #include "wx/settings.h" | |
25 | #include "wx/log.h" | |
26 | #include "wx/event.h" | |
27 | #include "wx/control.h" | |
28 | #endif // WX_PRECOMP | |
29 | ||
30 | #include "wx/imaglist.h" | |
31 | ||
32 | #include "wx/os2/private.h" | |
33 | ||
34 | // ---------------------------------------------------------------------------- | |
35 | // macros | |
36 | // ---------------------------------------------------------------------------- | |
37 | ||
38 | // check that the page index is valid | |
39 | #define IS_VALID_PAGE(nPage) ( \ | |
40 | /* size_t is _always_ >= 0 */ \ | |
41 | /* ((nPage) >= 0) && */ \ | |
42 | ((nPage) < GetPageCount()) \ | |
43 | ) | |
44 | ||
45 | // hide the ugly cast | |
46 | #define m_hWnd (HWND)GetHWND() | |
47 | ||
48 | // ---------------------------------------------------------------------------- | |
49 | // constants | |
50 | // ---------------------------------------------------------------------------- | |
51 | ||
52 | // ---------------------------------------------------------------------------- | |
53 | // event table | |
54 | // ---------------------------------------------------------------------------- | |
55 | ||
56 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED) | |
57 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING) | |
58 | ||
59 | BEGIN_EVENT_TABLE(wxNotebook, wxBookCtrlBase) | |
60 | EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, wxNotebook::OnSelChange) | |
61 | EVT_SIZE(wxNotebook::OnSize) | |
62 | EVT_SET_FOCUS(wxNotebook::OnSetFocus) | |
63 | EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) | |
64 | END_EVENT_TABLE() | |
65 | ||
66 | IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxBookCtrlBase) | |
67 | ||
68 | // ============================================================================ | |
69 | // implementation | |
70 | // ============================================================================ | |
71 | ||
72 | // ---------------------------------------------------------------------------- | |
73 | // wxNotebook construction | |
74 | // ---------------------------------------------------------------------------- | |
75 | ||
76 | // | |
77 | // Common part of all ctors | |
78 | // | |
79 | void wxNotebook::Init() | |
80 | { | |
81 | m_imageList = NULL; | |
82 | m_nSelection = -1; | |
83 | m_nTabSize = 0; | |
84 | } // end of wxNotebook::Init | |
85 | ||
86 | // | |
87 | // Default for dynamic class | |
88 | // | |
89 | wxNotebook::wxNotebook() | |
90 | { | |
91 | Init(); | |
92 | } // end of wxNotebook::wxNotebook | |
93 | ||
94 | // | |
95 | // The same arguments as for wxControl | |
96 | // | |
97 | wxNotebook::wxNotebook( | |
98 | wxWindow* pParent | |
99 | , wxWindowID vId | |
100 | , const wxPoint& rPos | |
101 | , const wxSize& rSize | |
102 | , long lStyle | |
103 | , const wxString& rsName | |
104 | ) | |
105 | { | |
106 | Init(); | |
107 | Create( pParent | |
108 | ,vId | |
109 | ,rPos | |
110 | ,rSize | |
111 | ,lStyle | |
112 | ,rsName | |
113 | ); | |
114 | } // end of wxNotebook::wxNotebook | |
115 | ||
116 | // | |
117 | // Create() function | |
118 | // | |
119 | bool wxNotebook::Create( wxWindow* pParent, | |
120 | wxWindowID vId, | |
121 | const wxPoint& rPos, | |
122 | const wxSize& rSize, | |
123 | long lStyle, | |
124 | const wxString& rsName ) | |
125 | { | |
126 | if ( (lStyle & wxBK_ALIGN_MASK) == wxBK_DEFAULT ) | |
127 | lStyle |= wxBK_TOP; | |
128 | // | |
129 | // Base init | |
130 | // | |
131 | if (!CreateControl( pParent | |
132 | ,vId | |
133 | ,rPos | |
134 | ,rSize | |
135 | ,lStyle | |
136 | ,wxDefaultValidator | |
137 | ,rsName | |
138 | )) | |
139 | return false; | |
140 | ||
141 | // | |
142 | // Notebook, so explicitly specify 0 as last parameter | |
143 | // | |
144 | if (!OS2CreateControl( wxT("NOTEBOOK") | |
145 | ,wxEmptyString | |
146 | ,rPos | |
147 | ,rSize | |
148 | ,lStyle | wxTAB_TRAVERSAL | |
149 | )) | |
150 | return false; | |
151 | ||
152 | SetBackgroundColour(wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE))); | |
153 | return true; | |
154 | } // end of wxNotebook::Create | |
155 | ||
156 | WXDWORD wxNotebook::OS2GetStyle ( | |
157 | long lStyle | |
158 | , WXDWORD* pdwExstyle | |
159 | ) const | |
160 | { | |
161 | WXDWORD dwTabStyle = wxControl::OS2GetStyle( lStyle | |
162 | ,pdwExstyle | |
163 | ); | |
164 | ||
165 | dwTabStyle |= WS_TABSTOP | BKS_SOLIDBIND | BKS_ROUNDEDTABS | BKS_TABTEXTCENTER | BKS_TABBEDDIALOG; | |
166 | ||
167 | if (lStyle & wxBK_BOTTOM) | |
168 | dwTabStyle |= BKS_MAJORTABBOTTOM | BKS_BACKPAGESBL; | |
169 | else if (lStyle & wxBK_RIGHT) | |
170 | dwTabStyle |= BKS_MAJORTABRIGHT | BKS_BACKPAGESBR; | |
171 | else if (lStyle & wxBK_LEFT) | |
172 | dwTabStyle |= BKS_MAJORTABLEFT | BKS_BACKPAGESTL; | |
173 | else // default to top | |
174 | dwTabStyle |= BKS_MAJORTABTOP | BKS_BACKPAGESTR; | |
175 | ||
176 | // | |
177 | // Ex style | |
178 | // | |
179 | if (pdwExstyle ) | |
180 | { | |
181 | // | |
182 | // Note that we never want to have the default WS_EX_CLIENTEDGE style | |
183 | // as it looks too ugly for the notebooks | |
184 | // | |
185 | *pdwExstyle = 0; | |
186 | } | |
187 | return dwTabStyle; | |
188 | } // end of wxNotebook::OS2GetStyle | |
189 | ||
190 | // ---------------------------------------------------------------------------- | |
191 | // wxNotebook accessors | |
192 | // ---------------------------------------------------------------------------- | |
193 | ||
194 | size_t wxNotebook::GetPageCount() const | |
195 | { | |
196 | // | |
197 | // Consistency check | |
198 | // | |
199 | wxASSERT((int)m_pages.Count() == (int)::WinSendMsg(GetHWND(), BKM_QUERYPAGECOUNT, (MPARAM)0, (MPARAM)BKA_END)); | |
200 | return m_pages.Count(); | |
201 | } // end of wxNotebook::GetPageCount | |
202 | ||
203 | int wxNotebook::GetRowCount() const | |
204 | { | |
205 | return (int)::WinSendMsg( GetHWND() | |
206 | ,BKM_QUERYPAGECOUNT | |
207 | ,(MPARAM)0 | |
208 | ,(MPARAM)BKA_MAJOR | |
209 | ); | |
210 | } // end of wxNotebook::GetRowCount | |
211 | ||
212 | int wxNotebook::SetSelection( size_t nPage ) | |
213 | { | |
214 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); | |
215 | ||
216 | if (nPage != (size_t)m_nSelection) | |
217 | { | |
218 | wxBookCtrlEvent vEvent( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING | |
219 | ,m_windowId | |
220 | ); | |
221 | ||
222 | vEvent.SetSelection(nPage); | |
223 | vEvent.SetOldSelection(m_nSelection); | |
224 | vEvent.SetEventObject(this); | |
225 | if (!HandleWindowEvent(vEvent) || vEvent.IsAllowed()) | |
226 | { | |
227 | ||
228 | // | |
229 | // Program allows the page change | |
230 | // | |
231 | vEvent.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); | |
232 | HandleWindowEvent(vEvent); | |
233 | ||
234 | ::WinSendMsg( GetHWND() | |
235 | ,BKM_TURNTOPAGE | |
236 | ,MPFROMLONG((ULONG)m_alPageId[nPage]) | |
237 | ,(MPARAM)0 | |
238 | ); | |
239 | } | |
240 | } | |
241 | m_nSelection = nPage; | |
242 | return nPage; | |
243 | } // end of wxNotebook::SetSelection | |
244 | ||
245 | int wxNotebook::ChangeSelection( size_t nPage ) | |
246 | { | |
247 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); | |
248 | ||
249 | if (nPage != (size_t)m_nSelection) | |
250 | { | |
251 | ::WinSendMsg( GetHWND() | |
252 | ,BKM_TURNTOPAGE | |
253 | ,MPFROMLONG((ULONG)m_alPageId[nPage]) | |
254 | ,(MPARAM)0 | |
255 | ); | |
256 | } | |
257 | m_nSelection = nPage; | |
258 | return nPage; | |
259 | } | |
260 | ||
261 | bool wxNotebook::SetPageText( size_t nPage, | |
262 | const wxString& rsStrText ) | |
263 | { | |
264 | wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("notebook page out of range") ); | |
265 | return (bool)::WinSendMsg( m_hWnd | |
266 | ,BKM_SETTABTEXT | |
267 | ,MPFROMLONG((ULONG)m_alPageId[nPage]) | |
268 | ,MPFROMP((const char*)rsStrText.c_str()) | |
269 | ); | |
270 | } // end of wxNotebook::SetPageText | |
271 | ||
272 | wxString wxNotebook::GetPageText ( size_t nPage ) const | |
273 | { | |
274 | BOOKTEXT vBookText; | |
275 | wxChar zBuf[256]; | |
276 | wxString sStr; | |
277 | ULONG ulRc; | |
278 | ||
279 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxEmptyString, wxT("notebook page out of range") ); | |
280 | ||
281 | memset(&vBookText, '\0', sizeof(BOOKTEXT)); | |
282 | vBookText.textLen = 0; // This will get the length | |
283 | ulRc = LONGFROMMR(::WinSendMsg( m_hWnd | |
284 | ,BKM_QUERYTABTEXT | |
285 | ,MPFROMLONG((ULONG)m_alPageId[nPage]) | |
286 | ,MPFROMP(&vBookText) | |
287 | )); | |
288 | if (ulRc == (ULONG)BOOKERR_INVALID_PARAMETERS || ulRc == 0L) | |
289 | { | |
290 | if (ulRc == (ULONG)BOOKERR_INVALID_PARAMETERS) | |
291 | { | |
292 | wxLogError(wxT("Invalid Page Id for page text querry.")); | |
293 | } | |
294 | return wxEmptyString; | |
295 | } | |
296 | vBookText.textLen = ulRc + 1; // To get the null terminator | |
297 | vBookText.pString = (char*)zBuf; | |
298 | ||
299 | // | |
300 | // Now get the actual text | |
301 | // | |
302 | ulRc = LONGFROMMR(::WinSendMsg( m_hWnd | |
303 | ,BKM_QUERYTABTEXT | |
304 | ,MPFROMLONG((ULONG)m_alPageId[nPage]) | |
305 | ,MPFROMP(&vBookText) | |
306 | )); | |
307 | if (ulRc == (ULONG)BOOKERR_INVALID_PARAMETERS || ulRc == 0L) | |
308 | { | |
309 | return wxEmptyString; | |
310 | } | |
311 | if (ulRc > 255L) | |
312 | ulRc = 255L; | |
313 | ||
314 | vBookText.pString[ulRc] = '\0'; | |
315 | sStr = (wxChar*)vBookText.pString; | |
316 | return sStr; | |
317 | } // end of wxNotebook::GetPageText | |
318 | ||
319 | int wxNotebook::GetPageImage ( size_t nPage ) const | |
320 | { | |
321 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); | |
322 | ||
323 | // | |
324 | // For OS/2 just return the page | |
325 | // | |
326 | return nPage; | |
327 | } // end of wxNotebook::GetPageImage | |
328 | ||
329 | bool wxNotebook::SetPageImage ( | |
330 | size_t nPage | |
331 | , int nImage | |
332 | ) | |
333 | { | |
334 | wxBitmap vBitmap = (wxBitmap)m_imageList->GetBitmap(nImage); | |
335 | ||
336 | return (bool)::WinSendMsg( GetHWND() | |
337 | ,BKM_SETTABBITMAP | |
338 | ,MPFROMLONG((ULONG)m_alPageId[nPage]) | |
339 | ,(MPARAM)wxCopyBmp(vBitmap.GetHBITMAP(), true) | |
340 | ); | |
341 | } // end of wxNotebook::SetPageImage | |
342 | ||
343 | void wxNotebook::SetImageList ( | |
344 | wxImageList* pImageList | |
345 | ) | |
346 | { | |
347 | // | |
348 | // Does not really do anything yet, but at least we need to | |
349 | // update the base class. | |
350 | // | |
351 | wxNotebookBase::SetImageList(pImageList); | |
352 | } // end of wxNotebook::SetImageList | |
353 | ||
354 | // ---------------------------------------------------------------------------- | |
355 | // wxNotebook size settings | |
356 | // ---------------------------------------------------------------------------- | |
357 | void wxNotebook::SetPageSize ( | |
358 | const wxSize& rSize | |
359 | ) | |
360 | { | |
361 | SetSize(rSize); | |
362 | } // end of wxNotebook::SetPageSize | |
363 | ||
364 | void wxNotebook::SetPadding ( | |
365 | const wxSize& WXUNUSED(rPadding) | |
366 | ) | |
367 | { | |
368 | // | |
369 | // No padding in OS/2 | |
370 | // | |
371 | } // end of wxNotebook::SetPadding | |
372 | ||
373 | void wxNotebook::SetTabSize ( | |
374 | const wxSize& rSize | |
375 | ) | |
376 | { | |
377 | ::WinSendMsg( GetHWND() | |
378 | ,BKM_SETDIMENSIONS | |
379 | ,MPFROM2SHORT( (USHORT)rSize.x | |
380 | ,(USHORT)rSize.y | |
381 | ) | |
382 | ,(MPARAM)BKA_MAJORTAB | |
383 | ); | |
384 | } // end of wxNotebook::SetTabSize | |
385 | ||
386 | // ---------------------------------------------------------------------------- | |
387 | // wxNotebook operations | |
388 | // ---------------------------------------------------------------------------- | |
389 | ||
390 | // | |
391 | // Remove one page from the notebook, without deleting | |
392 | // | |
393 | wxNotebookPage* wxNotebook::DoRemovePage ( size_t nPage ) | |
394 | { | |
395 | wxNotebookPage* pPageRemoved = wxNotebookBase::DoRemovePage(nPage); | |
396 | ||
397 | if (!pPageRemoved) | |
398 | return NULL; | |
399 | ||
400 | ::WinSendMsg( GetHWND() | |
401 | ,BKM_DELETEPAGE | |
402 | ,MPFROMLONG((ULONG)m_alPageId[nPage]) | |
403 | ,(MPARAM)BKA_TAB | |
404 | ); | |
405 | if (m_pages.IsEmpty()) | |
406 | { | |
407 | // | |
408 | // No selection any more, the notebook becamse empty | |
409 | // | |
410 | m_nSelection = -1; | |
411 | } | |
412 | else // notebook still not empty | |
413 | { | |
414 | // | |
415 | // Change the selected page if it was deleted or became invalid | |
416 | // | |
417 | int nSelNew; | |
418 | ||
419 | if (m_nSelection == (int)GetPageCount()) | |
420 | { | |
421 | // | |
422 | // Last page deleted, make the new last page the new selection | |
423 | // | |
424 | nSelNew = m_nSelection - 1; | |
425 | } | |
426 | else if (nPage <= (size_t)m_nSelection) | |
427 | { | |
428 | // | |
429 | // We must show another page, even if it has the same index | |
430 | // | |
431 | nSelNew = m_nSelection; | |
432 | } | |
433 | else // nothing changes for the currently selected page | |
434 | { | |
435 | nSelNew = -1; | |
436 | ||
437 | // | |
438 | // We still must refresh the current page: this needs to be done | |
439 | // for some unknown reason if the tab control shows the up-down | |
440 | // control (i.e. when there are too many pages) -- otherwise after | |
441 | // deleting a page nothing at all is shown | |
442 | // | |
443 | m_pages[m_nSelection]->Refresh(); | |
444 | } | |
445 | ||
446 | if (nSelNew != -1) | |
447 | { | |
448 | // | |
449 | // m_nSelection must be always valid so reset it before calling | |
450 | // SetSelection() | |
451 | // | |
452 | m_nSelection = -1; | |
453 | SetSelection(nSelNew); | |
454 | } | |
455 | } | |
456 | return pPageRemoved; | |
457 | } // end of wxNotebook::DoRemovePage | |
458 | ||
459 | // | |
460 | // Remove all pages | |
461 | // | |
462 | bool wxNotebook::DeleteAllPages() | |
463 | { | |
464 | int nPageCount = GetPageCount(); | |
465 | int nPage; | |
466 | ||
467 | for (nPage = 0; nPage < nPageCount; nPage++) | |
468 | delete m_pages[nPage]; | |
469 | m_pages.Clear(); | |
470 | ::WinSendMsg( GetHWND() | |
471 | ,BKM_DELETEPAGE | |
472 | ,(MPARAM)0 | |
473 | ,(MPARAM)BKA_ALL | |
474 | ); | |
475 | m_nSelection = -1; | |
476 | ||
477 | return true; | |
478 | } // end of wxNotebook::DeleteAllPages | |
479 | ||
480 | // | |
481 | // Add a page to the notebook | |
482 | // | |
483 | bool wxNotebook::AddPage ( | |
484 | wxNotebookPage* pPage | |
485 | , const wxString& rStrText | |
486 | , bool bSelect | |
487 | , int nImageId | |
488 | ) | |
489 | { | |
490 | return InsertPage( GetPageCount() | |
491 | ,pPage | |
492 | ,rStrText | |
493 | ,bSelect | |
494 | ,nImageId | |
495 | ); | |
496 | } // end of wxNotebook::AddPage | |
497 | ||
498 | // | |
499 | // Same as AddPage() but does it at given position | |
500 | // | |
501 | bool wxNotebook::InsertPage ( size_t nPage, | |
502 | wxNotebookPage* pPage, | |
503 | const wxString& rsStrText, | |
504 | bool bSelect, | |
505 | int nImageId ) | |
506 | { | |
507 | ULONG ulApiPage; | |
508 | ||
509 | wxASSERT( pPage != NULL ); | |
510 | wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), false ); | |
511 | ||
512 | // | |
513 | // Under OS/2 we can only insert FIRST, LAST, NEXT or PREV. Requires | |
514 | // two different calls to the API. Page 1 uses the BKA_FIRST. Subsequent | |
515 | // pages use the previous page ID coupled with a BKA_NEXT call. Unlike | |
516 | // Windows, OS/2 uses an internal Page ID to ID the pages. | |
517 | // | |
518 | // OS/2 also has a nice auto-size feature that automatically sizes the | |
519 | // the attached window so we don't have to worry about the size of the | |
520 | // window on the page. | |
521 | // | |
522 | if (nPage == 0) | |
523 | { | |
524 | ulApiPage = LONGFROMMR(::WinSendMsg( GetHWND() | |
525 | ,BKM_INSERTPAGE | |
526 | ,(MPARAM)0 | |
527 | ,MPFROM2SHORT(BKA_AUTOPAGESIZE | BKA_MAJOR, BKA_FIRST) | |
528 | )); | |
529 | if (ulApiPage == 0L) | |
530 | { | |
531 | ERRORID vError; | |
532 | wxString sError; | |
533 | ||
534 | vError = ::WinGetLastError(vHabmain); | |
535 | sError = wxPMErrorToStr(vError); | |
536 | return false; | |
537 | } | |
538 | m_alPageId.Insert((long)ulApiPage, nPage); | |
539 | } | |
540 | else | |
541 | { | |
542 | ulApiPage = LONGFROMMR(::WinSendMsg( GetHWND() | |
543 | ,BKM_INSERTPAGE | |
544 | ,MPFROMLONG((ULONG)m_alPageId[nPage - 1]) | |
545 | ,MPFROM2SHORT(BKA_AUTOPAGESIZE | BKA_MAJOR, BKA_NEXT) | |
546 | )); | |
547 | if (ulApiPage == 0L) | |
548 | { | |
549 | ERRORID vError; | |
550 | wxString sError; | |
551 | ||
552 | vError = ::WinGetLastError(vHabmain); | |
553 | sError = wxPMErrorToStr(vError); | |
554 | return false; | |
555 | } | |
556 | m_alPageId.Insert((long)ulApiPage, nPage); | |
557 | } | |
558 | ||
559 | // | |
560 | // Associate a window handle with the page | |
561 | // | |
562 | if (pPage) | |
563 | { | |
564 | if (!::WinSendMsg( GetHWND() | |
565 | ,BKM_SETPAGEWINDOWHWND | |
566 | ,MPFROMLONG((ULONG)m_alPageId[nPage]) | |
567 | ,MPFROMHWND(pPage->GetHWND()) | |
568 | )) | |
569 | return false; | |
570 | } | |
571 | // | |
572 | // If the inserted page is before the selected one, we must update the | |
573 | // index of the selected page | |
574 | // | |
575 | if (nPage <= (size_t)m_nSelection) | |
576 | { | |
577 | // | |
578 | // One extra page added | |
579 | // | |
580 | m_nSelection++; | |
581 | } | |
582 | ||
583 | if (pPage) | |
584 | { | |
585 | // | |
586 | // Save the pointer to the page | |
587 | // | |
588 | m_pages.Insert( pPage | |
589 | ,nPage | |
590 | ); | |
591 | } | |
592 | ||
593 | // | |
594 | // Now set TAB dimenstions | |
595 | // | |
596 | ||
597 | wxWindowDC vDC(this); | |
598 | wxCoord nTextX; | |
599 | wxCoord nTextY; | |
600 | ||
601 | vDC.GetTextExtent(rsStrText, &nTextX, &nTextY); | |
602 | nTextY *= 2; | |
603 | nTextX = (wxCoord)(nTextX * 1.3); | |
604 | if (nTextX > m_nTabSize) | |
605 | { | |
606 | m_nTabSize = nTextX; | |
607 | ::WinSendMsg( GetHWND() | |
608 | ,BKM_SETDIMENSIONS | |
609 | ,MPFROM2SHORT((USHORT)m_nTabSize, (USHORT)nTextY) | |
610 | ,(MPARAM)BKA_MAJORTAB | |
611 | ); | |
612 | } | |
613 | // | |
614 | // Now set any TAB text | |
615 | // | |
616 | if (!rsStrText.empty()) | |
617 | { | |
618 | if (!SetPageText( nPage | |
619 | ,rsStrText | |
620 | )) | |
621 | return false; | |
622 | } | |
623 | ||
624 | // | |
625 | // Now set any TAB bitmap image | |
626 | // | |
627 | if (nImageId != -1) | |
628 | { | |
629 | if (!SetPageImage( nPage | |
630 | ,nImageId | |
631 | )) | |
632 | return false; | |
633 | } | |
634 | ||
635 | if (pPage) | |
636 | { | |
637 | // | |
638 | // Don't show pages by default (we'll need to adjust their size first) | |
639 | // | |
640 | HWND hWnd = GetWinHwnd(pPage); | |
641 | ||
642 | WinSetWindowULong( hWnd | |
643 | ,QWL_STYLE | |
644 | ,WinQueryWindowULong( hWnd | |
645 | ,QWL_STYLE | |
646 | ) & ~WS_VISIBLE | |
647 | ); | |
648 | ||
649 | // | |
650 | // This updates internal flag too - otherwise it will get out of sync | |
651 | // | |
652 | pPage->Show(false); | |
653 | } | |
654 | ||
655 | // | |
656 | // Some page should be selected: either this one or the first one if there is | |
657 | // still no selection | |
658 | // | |
659 | int nSelNew = -1; | |
660 | ||
661 | if (bSelect) | |
662 | nSelNew = nPage; | |
663 | else if ( m_nSelection == -1 ) | |
664 | nSelNew = 0; | |
665 | ||
666 | if (nSelNew != -1) | |
667 | SetSelection(nSelNew); | |
668 | ||
669 | InvalidateBestSize(); | |
670 | ||
671 | return true; | |
672 | } // end of wxNotebook::InsertPage | |
673 | ||
674 | // ---------------------------------------------------------------------------- | |
675 | // wxNotebook callbacks | |
676 | // ---------------------------------------------------------------------------- | |
677 | void wxNotebook::OnSize( | |
678 | wxSizeEvent& rEvent | |
679 | ) | |
680 | { | |
681 | rEvent.Skip(); | |
682 | } // end of wxNotebook::OnSize | |
683 | ||
684 | void wxNotebook::OnSelChange ( | |
685 | wxBookCtrlEvent& rEvent | |
686 | ) | |
687 | { | |
688 | // | |
689 | // Is it our tab control? | |
690 | // | |
691 | if (rEvent.GetEventObject() == this) | |
692 | { | |
693 | int nPageCount = GetPageCount(); | |
694 | int nSel; | |
695 | ULONG ulOS2Sel = (ULONG)rEvent.GetOldSelection(); | |
696 | bool bFound = false; | |
697 | ||
698 | for (nSel = 0; nSel < nPageCount; nSel++) | |
699 | { | |
700 | if (ulOS2Sel == (ULONG)m_alPageId[nSel]) | |
701 | { | |
702 | bFound = true; | |
703 | break; | |
704 | } | |
705 | } | |
706 | ||
707 | if (!bFound) | |
708 | return; | |
709 | ||
710 | m_pages[nSel]->Show(false); | |
711 | ||
712 | ulOS2Sel = (ULONG)rEvent.GetSelection(); | |
713 | ||
714 | bFound = false; | |
715 | ||
716 | for (nSel = 0; nSel < nPageCount; nSel++) | |
717 | { | |
718 | if (ulOS2Sel == (ULONG)m_alPageId[nSel]) | |
719 | { | |
720 | bFound = true; | |
721 | break; | |
722 | } | |
723 | } | |
724 | ||
725 | if (!bFound) | |
726 | return; | |
727 | ||
728 | wxNotebookPage* pPage = m_pages[nSel]; | |
729 | ||
730 | pPage->Show(true); | |
731 | m_nSelection = nSel; | |
732 | } | |
733 | ||
734 | // | |
735 | // We want to give others a chance to process this message as well | |
736 | // | |
737 | rEvent.Skip(); | |
738 | } // end of wxNotebook::OnSelChange | |
739 | ||
740 | void wxNotebook::OnSetFocus ( | |
741 | wxFocusEvent& rEvent | |
742 | ) | |
743 | { | |
744 | // | |
745 | // This function is only called when the focus is explicitly set (i.e. from | |
746 | // the program) to the notebook - in this case we don't need the | |
747 | // complicated OnNavigationKey() logic because the programmer knows better | |
748 | // what [s]he wants | |
749 | // | |
750 | // set focus to the currently selected page if any | |
751 | // | |
752 | if (m_nSelection != -1) | |
753 | m_pages[m_nSelection]->SetFocus(); | |
754 | rEvent.Skip(); | |
755 | } // end of wxNotebook::OnSetFocus | |
756 | ||
757 | void wxNotebook::OnNavigationKey ( | |
758 | wxNavigationKeyEvent& rEvent | |
759 | ) | |
760 | { | |
761 | if (rEvent.IsWindowChange()) | |
762 | { | |
763 | // | |
764 | // Change pages | |
765 | // | |
766 | AdvanceSelection(rEvent.GetDirection()); | |
767 | } | |
768 | else | |
769 | { | |
770 | // | |
771 | // We get this event in 2 cases | |
772 | // | |
773 | // a) one of our pages might have generated it because the user TABbed | |
774 | // out from it in which case we should propagate the event upwards and | |
775 | // our parent will take care of setting the focus to prev/next sibling | |
776 | // | |
777 | // or | |
778 | // | |
779 | // b) the parent panel wants to give the focus to us so that we | |
780 | // forward it to our selected page. We can't deal with this in | |
781 | // OnSetFocus() because we don't know which direction the focus came | |
782 | // from in this case and so can't choose between setting the focus to | |
783 | // first or last panel child | |
784 | // | |
785 | wxWindow* pParent = GetParent(); | |
786 | ||
787 | if (rEvent.GetEventObject() == pParent) | |
788 | { | |
789 | // | |
790 | // No, it doesn't come from child, case (b): forward to a page | |
791 | // | |
792 | if (m_nSelection != -1) | |
793 | { | |
794 | // | |
795 | // So that the page knows that the event comes from it's parent | |
796 | // and is being propagated downwards | |
797 | // | |
798 | rEvent.SetEventObject(this); | |
799 | ||
800 | wxWindow* pPage = m_pages[m_nSelection]; | |
801 | ||
802 | if (!pPage->HandleWindowEvent(rEvent)) | |
803 | { | |
804 | pPage->SetFocus(); | |
805 | } | |
806 | //else: page manages focus inside it itself | |
807 | } | |
808 | else | |
809 | { | |
810 | // | |
811 | // We have no pages - still have to give focus to _something_ | |
812 | // | |
813 | SetFocus(); | |
814 | } | |
815 | } | |
816 | else | |
817 | { | |
818 | // | |
819 | // It comes from our child, case (a), pass to the parent | |
820 | // | |
821 | if (pParent) | |
822 | { | |
823 | rEvent.SetCurrentFocus(this); | |
824 | pParent->HandleWindowEvent(rEvent); | |
825 | } | |
826 | } | |
827 | } | |
828 | } // end of wxNotebook::OnNavigationKey | |
829 | ||
830 | // ---------------------------------------------------------------------------- | |
831 | // wxNotebook base class virtuals | |
832 | // ---------------------------------------------------------------------------- | |
833 | ||
834 | // | |
835 | // Override these 2 functions to do nothing: everything is done in OnSize | |
836 | // | |
837 | void wxNotebook::SetConstraintSizes( bool WXUNUSED(bRecurse) ) | |
838 | { | |
839 | // | |
840 | // Don't set the sizes of the pages - their correct size is not yet known | |
841 | // | |
842 | wxControl::SetConstraintSizes(false); | |
843 | } // end of wxNotebook::SetConstraintSizes | |
844 | ||
845 | bool wxNotebook::DoPhase ( int WXUNUSED(nPhase) ) | |
846 | { | |
847 | return true; | |
848 | } // end of wxNotebook::DoPhase | |
849 | ||
850 | // ---------------------------------------------------------------------------- | |
851 | // wxNotebook Windows message handlers | |
852 | // ---------------------------------------------------------------------------- | |
853 | bool wxNotebook::OS2OnScroll ( int nOrientation, | |
854 | WXWORD wSBCode, | |
855 | WXWORD wPos, | |
856 | WXHWND wControl ) | |
857 | { | |
858 | // | |
859 | // Don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the | |
860 | // up-down control | |
861 | // | |
862 | if (wControl) | |
863 | return false; | |
864 | return wxNotebookBase::OS2OnScroll( nOrientation | |
865 | ,wSBCode | |
866 | ,wPos | |
867 | ,wControl | |
868 | ); | |
869 | } // end of wxNotebook::OS2OnScroll | |
870 | ||
871 | #endif // wxUSE_NOTEBOOK |