int wxNotebook::GetPageImage(size_t nPage) const { wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); TC_ITEM tcItem; tcItem.mask = TCIF_IMAGE; return TabCtrl_GetItem(GetHwnd(), nPage, &tcItem) ? tcItem.iImage : wxNOT_FOUND; }
bool wxNotebook::SetPageText(size_t nPage, const wxString& strText) { wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("SetPageText: invalid notebook page") ); wxNotebookPage *page = m_pages[nPage]; page->SetLabel(wxStripMenuCodes(strText)); MacSetupTabs(); return true; }
bool wxNotebook::SetPageImage(size_t nPage, int nImage) { wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("notebook page out of range") ); TC_ITEM tcItem; tcItem.mask = TCIF_IMAGE; tcItem.iImage = nImage; return TabCtrl_SetItem(GetHwnd(), nPage, &tcItem) != 0; }
bool wxTreebook::DeletePage(size_t pagePos) { wxCHECK_MSG( IS_VALID_PAGE(pagePos), false, wxT("Invalid tree index") ); wxTreebookPage *oldPage = DoRemovePage(pagePos); if ( !oldPage ) return false; delete oldPage; return true; }
int wxNotebook::ChangeSelection(size_t nPage) { wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); const int selOld = m_selection; if ( m_selection == wxNOT_FOUND || nPage != (size_t)m_selection ) { TabCtrl_SetCurSel(GetHwnd(), nPage); UpdateSelection(nPage); } return selOld; }
int wxNotebook::ChangeSelection( size_t nPage ) { wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); if (nPage != (size_t)m_nSelection) { ::WinSendMsg( GetHWND() ,BKM_TURNTOPAGE ,MPFROMLONG((ULONG)m_alPageId[nPage]) ,(MPARAM)0 ); } m_nSelection = nPage; return nPage; }
wxString wxNotebook::GetPageText(size_t nPage) const { wxCHECK_MSG( IS_VALID_PAGE(nPage), wxEmptyString, wxT("notebook page out of range") ); wxChar buf[256]; TC_ITEM tcItem; tcItem.mask = TCIF_TEXT; tcItem.pszText = buf; tcItem.cchTextMax = WXSIZEOF(buf); wxString str; if ( TabCtrl_GetItem(GetHwnd(), nPage, &tcItem) ) str = tcItem.pszText; return str; }
wxString wxNotebook::GetPageText ( size_t nPage ) const { BOOKTEXT vBookText; wxChar zBuf[256]; wxString sStr; ULONG ulRc; wxCHECK_MSG( IS_VALID_PAGE(nPage), wxEmptyString, wxT("notebook page out of range") ); memset(&vBookText, '\0', sizeof(BOOKTEXT)); vBookText.textLen = 0; // This will get the length ulRc = LONGFROMMR(::WinSendMsg( m_hWnd ,BKM_QUERYTABTEXT ,MPFROMLONG((ULONG)m_alPageId[nPage]) ,MPFROMP(&vBookText) )); if (ulRc == (ULONG)BOOKERR_INVALID_PARAMETERS || ulRc == 0L) { if (ulRc == (ULONG)BOOKERR_INVALID_PARAMETERS) { wxLogError(wxT("Invalid Page Id for page text querry.")); } return wxEmptyString; } vBookText.textLen = ulRc + 1; // To get the null terminator vBookText.pString = (char*)zBuf; // // Now get the actual text // ulRc = LONGFROMMR(::WinSendMsg( m_hWnd ,BKM_QUERYTABTEXT ,MPFROMLONG((ULONG)m_alPageId[nPage]) ,MPFROMP(&vBookText) )); if (ulRc == (ULONG)BOOKERR_INVALID_PARAMETERS || ulRc == 0L) { return wxEmptyString; } if (ulRc > 255L) ulRc = 255L; vBookText.pString[ulRc] = '\0'; sStr = (wxChar*)vBookText.pString; return sStr; } // end of wxNotebook::GetPageText
int wxNotebook::SetSelection(size_t nPage) { wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); if ( m_nSelection == wxNOT_FOUND || nPage != (size_t)m_nSelection ) { if ( SendPageChangingEvent(nPage) ) { // program allows the page change SendPageChangedEvent(m_nSelection, nPage); TabCtrl_SetCurSel(GetHwnd(), nPage); } } return m_nSelection; }
wxTreebookPage *wxTreebook::DoRemovePage(size_t pagePos) { wxTreeItemId pageId = DoInternalGetPage(pagePos); wxCHECK_MSG( pageId.IsOk(), NULL, wxT("Invalid tree index") ); wxTreebookPage * oldPage = GetPage(pagePos); wxTreeCtrl *tree = GetTreeCtrl(); size_t subCount = tree->GetChildrenCount(pageId, true); wxASSERT_MSG ( IS_VALID_PAGE(pagePos + subCount), wxT("Internal error in wxTreebook::DoRemovePage") ); // here we are going to delete ALL the pages in the range // [pagePos, pagePos + subCount] -- the page and its children // deleting all the pages from the base class #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for ( size_t i = 0; i <= subCount; ++i ) { wxTreebookPage *page = wxBookCtrlBase::DoRemovePage(pagePos); // don't delete the page itself though -- it will be deleted in // DeletePage() when we return if ( i ) { delete page; } } DoInternalRemovePageRange(pagePos, subCount); tree->DeleteChildren( pageId ); tree->Delete( pageId ); return oldPage; }
bool wxNotebook::SetPageImage(size_t nPage, int nImage) { wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("SetPageImage: invalid notebook page") ); wxCHECK_MSG( HasImageList() && nImage < GetImageList()->GetImageCount(), false, wxT("SetPageImage: invalid image index") ); if ( nImage != m_images[nPage] ) { // if the item didn't have an icon before or, on the contrary, did have // it but has lost it now, its size will change - but if the icon just // changes, it won't m_images[nPage] = nImage; MacSetupTabs() ; } return true; }
// remove one page from the notebook, without deleting the window wxNotebookPage* wxNotebook::DoRemovePage(size_t nPage) { wxCHECK_MSG( IS_VALID_PAGE(nPage), NULL, wxT("DoRemovePage: invalid notebook page") ); wxNotebookPage* page = m_pages[nPage] ; m_pages.RemoveAt(nPage); MacSetupTabs(); if (m_selection >= (int)GetPageCount()) m_selection = GetPageCount() - 1; if (m_selection >= 0) m_pages[m_selection]->Show(true); InvalidateBestSize(); return page; }
int wxNotebook::DoSetSelection(size_t nPage, int flags) { wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("DoSetSelection: invalid notebook page") ); if ( m_selection == wxNOT_FOUND || nPage != (size_t)m_selection ) { if ( flags & SetSelection_SendEvent ) { if ( !SendPageChangingEvent(nPage) ) { // vetoed by program return m_selection; } //else: program allows the page change SendPageChangedEvent(m_selection, nPage); } ChangePage(m_selection, nPage); } //else: no change return m_selection; }
int wxNotebook::GetPageImage(size_t nPage) const { wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("GetPageImage: invalid notebook page") ); return m_images[nPage]; }
int wxTreebook::DoSetSelection(size_t pagePos, int flags) { wxCHECK_MSG( IS_VALID_PAGE(pagePos), wxNOT_FOUND, wxT("invalid page index in wxListbook::DoSetSelection()") ); wxASSERT_MSG( GetPageCount() == DoInternalGetPageCount(), wxT("wxTreebook logic error: m_treeIds and m_pages not in sync!")); wxBookCtrlEvent event(wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING, m_windowId); const int oldSel = m_selection; wxTreeCtrl *tree = GetTreeCtrl(); bool allowed = false; if (flags & SetSelection_SendEvent) { event.SetEventObject(this); event.SetSelection(pagePos); event.SetOldSelection(m_selection); // don't send the event if the old and new pages are the same; do send it // otherwise and be prepared for it to be vetoed allowed = (int)pagePos == m_selection || !GetEventHandler()->ProcessEvent(event) || event.IsAllowed(); } if ( !(flags & SetSelection_SendEvent) || allowed ) { // hide the previously shown page wxTreebookPage * const oldPage = DoGetCurrentPage(); if ( oldPage ) oldPage->Hide(); // then show the new one m_selection = pagePos; wxTreebookPage *page = wxBookCtrlBase::GetPage(m_selection); if ( !page ) { // find the next page suitable to be shown: the first (grand)child // of this one with a non-NULL associated page wxTreeItemId childId = m_treeIds[pagePos]; int actualPagePos = pagePos; while ( !page && childId.IsOk() ) { wxTreeItemIdValue cookie; childId = tree->GetFirstChild( childId, cookie ); if ( childId.IsOk() ) { page = wxBookCtrlBase::GetPage(++actualPagePos); } } m_actualSelection = page ? actualPagePos : m_selection; } if ( page ) page->Show(); tree->SelectItem(DoInternalGetPage(pagePos)); if (flags & SetSelection_SendEvent) { // notify about the (now completed) page change event.SetEventType(wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED); (void)GetEventHandler()->ProcessEvent(event); } } else if ( (flags & SetSelection_SendEvent) && !allowed) // page change vetoed { // tree selection might have already had changed if ( oldSel != wxNOT_FOUND ) tree->SelectItem(DoInternalGetPage(oldSel)); } return oldSel; }
// same as AddPage() but does it at given position bool wxNotebook::InsertPage(size_t nPage, wxNotebookPage *pPage, const wxString& strText, bool bSelect, int imageId) { wxCHECK_MSG( pPage != NULL, false, wxT("NULL page in wxNotebook::InsertPage") ); wxCHECK_MSG( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), false, wxT("invalid index in wxNotebook::InsertPage") ); wxASSERT_MSG( pPage->GetParent() == this, wxT("notebook pages must have notebook as parent") ); // add a new tab to the control // ---------------------------- // init all fields to 0 TC_ITEM tcItem; wxZeroMemory(tcItem); // set the image, if any if ( imageId != -1 ) { tcItem.mask |= TCIF_IMAGE; tcItem.iImage = imageId; } // and the text if ( !strText.empty() ) { tcItem.mask |= TCIF_TEXT; tcItem.pszText = (wxChar *)strText.wx_str(); // const_cast } // hide the page: unless it is selected, it shouldn't be shown (and if it // is selected it will be shown later) HWND hwnd = GetWinHwnd(pPage); SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE); // this updates internal flag too -- otherwise it would get out of sync // with the real state pPage->Show(false); // fit the notebook page to the tab control's display area: this should be // done before adding it to the notebook or TabCtrl_InsertItem() will // change the notebooks size itself! AdjustPageSize(pPage); // finally do insert it if ( TabCtrl_InsertItem(GetHwnd(), nPage, &tcItem) == -1 ) { wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str()); return false; } // need to update the bg brush when the first page is added // so the first panel gets the correct themed background if ( m_pages.empty() ) { #if wxUSE_UXTHEME UpdateBgBrush(); #endif // wxUSE_UXTHEME } // succeeded: save the pointer to the page m_pages.Insert(pPage, nPage); // also ensure that the notebook background is used for its pages by making // them transparent: this ensures that MSWGetBgBrush() queries the notebook // for the background brush to be used for erasing them if ( wxPanel *panel = wxDynamicCast(pPage, wxPanel) ) { panel->MSWSetTransparentBackground(); } // we may need to adjust the size again if the notebook size changed: // normally this only happens for the first page we add (the tabs which // hadn't been there before are now shown) but for a multiline notebook it // can happen for any page at all as a new row could have been started if ( m_pages.GetCount() == 1 || HasFlag(wxNB_MULTILINE) ) { AdjustPageSize(pPage); } // now deal with the selection // --------------------------- // if the inserted page is before the selected one, we must update the // index of the selected page if ( int(nPage) <= m_nSelection ) { // one extra page added m_nSelection++; } // some page should be selected: either this one or the first one if there // is still no selection int selNew = wxNOT_FOUND; if ( bSelect ) selNew = nPage; else if ( m_nSelection == wxNOT_FOUND ) selNew = 0; if ( selNew != wxNOT_FOUND ) SetSelection(selNew); InvalidateBestSize(); return true; }
// same as AddPage() but does it at given position bool wxNotebook::InsertPage(size_t nPage, wxNotebookPage *pPage, const wxString& strText, bool bSelect, int imageId) { wxCHECK_MSG( pPage != NULL, false, wxT("NULL page in wxNotebook::InsertPage") ); wxCHECK_MSG( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), false, wxT("invalid index in wxNotebook::InsertPage") ); wxASSERT_MSG( pPage->GetParent() == this, wxT("notebook pages must have notebook as parent") ); // add a new tab to the control // ---------------------------- // init all fields to 0 TC_ITEM tcItem; wxZeroMemory(tcItem); // set the image, if any if ( imageId != -1 ) { tcItem.mask |= TCIF_IMAGE; tcItem.iImage = imageId; } // and the text if ( !strText.empty() ) { tcItem.mask |= TCIF_TEXT; tcItem.pszText = wxMSW_CONV_LPTSTR(strText); } // hide the page: unless it is selected, it shouldn't be shown (and if it // is selected it will be shown later) HWND hwnd = GetWinHwnd(pPage); SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE); // this updates internal flag too -- otherwise it would get out of sync // with the real state pPage->Show(false); // fit the notebook page to the tab control's display area: this should be // done before adding it to the notebook or TabCtrl_InsertItem() will // change the notebooks size itself! AdjustPageSize(pPage); // finally do insert it if ( TabCtrl_InsertItem(GetHwnd(), nPage, &tcItem) == -1 ) { wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str()); return false; } // need to update the bg brush when the first page is added // so the first panel gets the correct themed background if ( m_pages.empty() ) { #if wxUSE_UXTHEME UpdateBgBrush(); #endif // wxUSE_UXTHEME } // succeeded: save the pointer to the page m_pages.Insert(pPage, nPage); // we may need to adjust the size again if the notebook size changed: // normally this only happens for the first page we add (the tabs which // hadn't been there before are now shown) but for a multiline notebook it // can happen for any page at all as a new row could have been started if ( m_pages.GetCount() == 1 || HasFlag(wxNB_MULTILINE) ) { AdjustPageSize(pPage); // Additionally, force the layout of the notebook itself by posting a // size event to it. If we don't do it, notebooks with pages on the // left or the right side may fail to account for the fact that they // are now big enough to fit all all of their pages on one row and // still reserve space for the second row of tabs, see #1792. const wxSize s = GetSize(); ::PostMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(s.x, s.y)); } // now deal with the selection // --------------------------- // if the inserted page is before the selected one, we must update the // index of the selected page if ( int(nPage) <= m_selection ) { // one extra page added m_selection++; } DoSetSelectionAfterInsertion(nPage, bSelect); InvalidateBestSize(); return true; }
// // Same as AddPage() but does it at given position // bool wxNotebook::InsertPage ( size_t nPage, wxNotebookPage* pPage, const wxString& rsStrText, bool bSelect, int nImageId ) { ULONG ulApiPage; wxASSERT( pPage != NULL ); wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), false ); // // Under OS/2 we can only insert FIRST, LAST, NEXT or PREV. Requires // two different calls to the API. Page 1 uses the BKA_FIRST. Subsequent // pages use the previous page ID coupled with a BKA_NEXT call. Unlike // Windows, OS/2 uses an internal Page ID to ID the pages. // // OS/2 also has a nice auto-size feature that automatically sizes the // the attached window so we don't have to worry about the size of the // window on the page. // if (nPage == 0) { ulApiPage = LONGFROMMR(::WinSendMsg( GetHWND() ,BKM_INSERTPAGE ,(MPARAM)0 ,MPFROM2SHORT(BKA_AUTOPAGESIZE | BKA_MAJOR, BKA_FIRST) )); if (ulApiPage == 0L) { ERRORID vError; wxString sError; vError = ::WinGetLastError(vHabmain); sError = wxPMErrorToStr(vError); return false; } m_alPageId.Insert((long)ulApiPage, nPage); } else { ulApiPage = LONGFROMMR(::WinSendMsg( GetHWND() ,BKM_INSERTPAGE ,MPFROMLONG((ULONG)m_alPageId[nPage - 1]) ,MPFROM2SHORT(BKA_AUTOPAGESIZE | BKA_MAJOR, BKA_NEXT) )); if (ulApiPage == 0L) { ERRORID vError; wxString sError; vError = ::WinGetLastError(vHabmain); sError = wxPMErrorToStr(vError); return false; } m_alPageId.Insert((long)ulApiPage, nPage); } // // Associate a window handle with the page // if (pPage) { if (!::WinSendMsg( GetHWND() ,BKM_SETPAGEWINDOWHWND ,MPFROMLONG((ULONG)m_alPageId[nPage]) ,MPFROMHWND(pPage->GetHWND()) )) return false; } // // If the inserted page is before the selected one, we must update the // index of the selected page // if (nPage <= (size_t)m_nSelection) { // // One extra page added // m_nSelection++; } if (pPage) { // // Save the pointer to the page // m_pages.Insert( pPage ,nPage ); } // // Now set TAB dimenstions // wxWindowDC vDC(this); wxCoord nTextX; wxCoord nTextY; vDC.GetTextExtent(rsStrText, &nTextX, &nTextY); nTextY *= 2; nTextX = (wxCoord)(nTextX * 1.3); if (nTextX > m_nTabSize) { m_nTabSize = nTextX; ::WinSendMsg( GetHWND() ,BKM_SETDIMENSIONS ,MPFROM2SHORT((USHORT)m_nTabSize, (USHORT)nTextY) ,(MPARAM)BKA_MAJORTAB ); } // // Now set any TAB text // if (!rsStrText.empty()) { if (!SetPageText( nPage ,rsStrText )) return false; } // // Now set any TAB bitmap image // if (nImageId != -1) { if (!SetPageImage( nPage ,nImageId )) return false; } if (pPage) { // // Don't show pages by default (we'll need to adjust their size first) // HWND hWnd = GetWinHwnd(pPage); WinSetWindowULong( hWnd ,QWL_STYLE ,WinQueryWindowULong( hWnd ,QWL_STYLE ) & ~WS_VISIBLE ); // // This updates internal flag too - otherwise it will get out of sync // pPage->Show(false); } // // Some page should be selected: either this one or the first one if there is // still no selection // int nSelNew = -1; if (bSelect) nSelNew = nPage; else if ( m_nSelection == -1 ) nSelNew = 0; if (nSelNew != -1) SetSelection(nSelNew); InvalidateBestSize(); return true; } // end of wxNotebook::InsertPage