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