X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1a75e76f399bc91b3f841e7f77140e83f9bd5958..4948c2b6c8936ee1d0b9c5e3b3594b046fc77020:/src/os2/notebook.cpp diff --git a/src/os2/notebook.cpp b/src/os2/notebook.cpp index dbf582f6d4..89f0f9d6fd 100644 --- a/src/os2/notebook.cpp +++ b/src/os2/notebook.cpp @@ -14,9 +14,10 @@ #if wxUSE_NOTEBOOK -// wxWindows +// wxWidgets #ifndef WX_PRECOMP #include "wx/app.h" + #include "wx/dcclient.h" #include "wx/string.h" #include "wx/settings.h" #endif // WX_PRECOMP @@ -34,7 +35,11 @@ // ---------------------------------------------------------------------------- // check that the page index is valid -#define IS_VALID_PAGE(nPage) (((nPage) >= 0) && ((nPage) < GetPageCount())) +#define IS_VALID_PAGE(nPage) ( \ + /* size_t is _always_ >= 0 */ \ + /* ((nPage) >= 0) && */ \ + ((nPage) < GetPageCount()) \ + ) // hide the ugly cast #define m_hWnd (HWND)GetHWND() @@ -111,14 +116,12 @@ wxNotebook::wxNotebook( // // Create() function // -bool wxNotebook::Create( - wxWindow* pParent -, wxWindowID vId -, const wxPoint& rPos -, const wxSize& rSize -, long lStyle -, const wxString& rsName -) +bool wxNotebook::Create( wxWindow* pParent, + wxWindowID vId, + const wxPoint& rPos, + const wxSize& rSize, + long lStyle, + const wxString& rsName ) { // // Base init @@ -131,21 +134,21 @@ bool wxNotebook::Create( ,wxDefaultValidator ,rsName )) - return FALSE; + return false; // // Notebook, so explicitly specify 0 as last parameter // - if (!OS2CreateControl( "NOTEBOOK" - ,_T("") + if (!OS2CreateControl( wxT("NOTEBOOK") + ,wxEmptyString ,rPos ,rSize ,lStyle | wxTAB_TRAVERSAL )) - return FALSE; + return false; SetBackgroundColour(wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE))); - return TRUE; + return true; } // end of wxNotebook::Create WXDWORD wxNotebook::OS2GetStyle ( @@ -157,7 +160,7 @@ WXDWORD wxNotebook::OS2GetStyle ( ,pdwExstyle ); - dwTabStyle |= WS_TABSTOP | BKS_SOLIDBIND | BKS_ROUNDEDTABS | BKS_TABTEXTCENTER; + dwTabStyle |= WS_TABSTOP | BKS_SOLIDBIND | BKS_ROUNDEDTABS | BKS_TABTEXTCENTER | BKS_TABBEDDIALOG; if (lStyle & wxNB_BOTTOM) dwTabStyle |= BKS_MAJORTABBOTTOM | BKS_BACKPAGESBL; @@ -186,11 +189,8 @@ WXDWORD wxNotebook::OS2GetStyle ( // wxNotebook accessors // ---------------------------------------------------------------------------- -int wxNotebook::GetPageCount() const +size_t wxNotebook::GetPageCount() const { - int nPageInternal = m_pages.Count(); - int nPageAPI = (int)::WinSendMsg(GetHWND(), BKM_QUERYPAGECOUNT, (MPARAM)0, (MPARAM)BKA_END); - // // Consistency check // @@ -207,38 +207,43 @@ int wxNotebook::GetRowCount() const ); } // end of wxNotebook::GetRowCount -int wxNotebook::SetSelection( - int nPage -) +int wxNotebook::SetSelection( size_t nPage ) { wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") ); - int nOldPage = GetSelection(); - ChangePage( m_nSelection - ,nPage - ); + if (nPage != (size_t)m_nSelection) + { + wxNotebookEvent vEvent( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING + ,m_windowId + ); - ULONG ulPageId = (ULONG)m_alPageId[nPage]; + vEvent.SetSelection(nPage); + vEvent.SetOldSelection(m_nSelection); + vEvent.SetEventObject(this); + if (!GetEventHandler()->ProcessEvent(vEvent) || vEvent.IsAllowed()) + { - ::WinSendMsg( GetHWND() - ,BKM_TURNTOPAGE - ,MPFROMLONG((ULONG)m_alPageId[nPage]) - ,(MPARAM)0 - ); + // + // Program allows the page change + // + vEvent.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); + GetEventHandler()->ProcessEvent(vEvent); + + ::WinSendMsg( GetHWND() + ,BKM_TURNTOPAGE + ,MPFROMLONG((ULONG)m_alPageId[nPage]) + ,(MPARAM)0 + ); + } + } m_nSelection = nPage; return nPage; } // end of wxNotebook::SetSelection -bool wxNotebook::SetPageText( - int nPage -, const wxString& rsStrText -) +bool wxNotebook::SetPageText( size_t nPage, + const wxString& rsStrText ) { wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") ); - - - ULONG ulPageId = (ULONG)m_alPageId[nPage]; - return (bool)::WinSendMsg( m_hWnd ,BKM_SETTABTEXT ,MPFROMLONG((ULONG)m_alPageId[nPage]) @@ -246,9 +251,7 @@ bool wxNotebook::SetPageText( ); } // end of wxNotebook::SetPageText -wxString wxNotebook::GetPageText ( - int nPage -) const +wxString wxNotebook::GetPageText ( size_t nPage ) const { BOOKTEXT vBookText; wxChar zBuf[256]; @@ -257,9 +260,6 @@ wxString wxNotebook::GetPageText ( wxCHECK_MSG( IS_VALID_PAGE(nPage), wxT(""), wxT("notebook page out of range") ); - - ULONG ulPageId = (ULONG)m_alPageId[nPage]; - memset(&vBookText, '\0', sizeof(BOOKTEXT)); vBookText.textLen = 0; // This will get the length ulRc = LONGFROMMR(::WinSendMsg( m_hWnd @@ -267,16 +267,16 @@ wxString wxNotebook::GetPageText ( ,MPFROMLONG((ULONG)m_alPageId[nPage]) ,MPFROMP(&vBookText) )); - if (ulRc == BOOKERR_INVALID_PARAMETERS || ulRc == 0L) + if (ulRc == (ULONG)BOOKERR_INVALID_PARAMETERS || ulRc == 0L) { - if (ulRc == BOOKERR_INVALID_PARAMETERS) + 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 = zBuf; + vBookText.pString = (char*)zBuf; // // Now get the actual text @@ -286,7 +286,7 @@ wxString wxNotebook::GetPageText ( ,MPFROMLONG((ULONG)m_alPageId[nPage]) ,MPFROMP(&vBookText) )); - if (ulRc == BOOKERR_INVALID_PARAMETERS || ulRc == 0L) + if (ulRc == (ULONG)BOOKERR_INVALID_PARAMETERS || ulRc == 0L) { return wxEmptyString; } @@ -294,13 +294,11 @@ wxString wxNotebook::GetPageText ( ulRc = 255L; vBookText.pString[ulRc] = '\0'; - sStr = vBookText.pString; + sStr = (wxChar*)vBookText.pString; return sStr; } // end of wxNotebook::GetPageText -int wxNotebook::GetPageImage ( - int nPage -) const +int wxNotebook::GetPageImage ( size_t nPage ) const { wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") ); @@ -311,29 +309,28 @@ int wxNotebook::GetPageImage ( } // end of wxNotebook::GetPageImage bool wxNotebook::SetPageImage ( - int nPage + size_t nPage , int nImage ) { - wxBitmap* pBitmap = (wxBitmap*)m_imageList->GetBitmap(nImage); - - - ULONG ulPageId = (ULONG)m_alPageId[nPage]; + wxBitmap vBitmap = (wxBitmap)m_imageList->GetBitmap(nImage); return (bool)::WinSendMsg( GetHWND() ,BKM_SETTABBITMAP ,MPFROMLONG((ULONG)m_alPageId[nPage]) - ,(MPARAM)pBitmap->GetHBITMAP() + ,(MPARAM)vBitmap.GetHBITMAP() ); } // end of wxNotebook::SetPageImage void wxNotebook::SetImageList ( - wxImageList* WXUNUSED(pImageList) + wxImageList* pImageList ) { // - // Does nothing under OS/2 + // Does not really do anything yet, but at least we need to + // update the base class. // + wxNotebookBase::SetImageList(pImageList); } // end of wxNotebook::SetImageList // ---------------------------------------------------------------------------- @@ -343,22 +340,7 @@ void wxNotebook::SetPageSize ( const wxSize& rSize ) { - RECTL vRect; - - // - // Transform the page size into the notebook size - // - vRect.xLeft = vRect.yTop = 0; - vRect.xRight = rSize.x; - vRect.yBottom = rSize.y; - - - // - // And now set it - // - SetSize( vRect.xRight - vRect.xLeft - ,vRect.yBottom - vRect.yTop - ); + SetSize(rSize); } // end of wxNotebook::SetPageSize void wxNotebook::SetPadding ( @@ -390,18 +372,13 @@ void wxNotebook::SetTabSize ( // // Remove one page from the notebook, without deleting // -wxNotebookPage* wxNotebook::DoRemovePage ( - int nPage -) +wxNotebookPage* wxNotebook::DoRemovePage ( size_t nPage ) { - wxNotebookPage* pPageRemoved = wxNotebookBase::DoRemovePage(nPage); + wxNotebookPage* pPageRemoved = wxNotebookBase::DoRemovePage(nPage); if (!pPageRemoved) return NULL; - - ULONG ulPageId = (ULONG)m_alPageId[nPage]; - ::WinSendMsg( GetHWND() ,BKM_DELETEPAGE ,MPFROMLONG((ULONG)m_alPageId[nPage]) @@ -421,14 +398,14 @@ wxNotebookPage* wxNotebook::DoRemovePage ( // int nSelNew; - if (m_nSelection == GetPageCount()) + if (m_nSelection == (int)GetPageCount()) { // // Last page deleted, make the new last page the new selection // nSelNew = m_nSelection - 1; } - else if (nPage <= m_nSelection) + else if (nPage <= (size_t)m_nSelection) { // // We must show another page, even if it has the same index @@ -478,7 +455,8 @@ bool wxNotebook::DeleteAllPages() ,(MPARAM)BKA_ALL ); m_nSelection = -1; - return TRUE; + + return true; } // end of wxNotebook::DeleteAllPages // @@ -502,13 +480,11 @@ bool wxNotebook::AddPage ( // // Same as AddPage() but does it at given position // -bool wxNotebook::InsertPage ( - int nPage -, wxNotebookPage* pPage -, const wxString& rsStrText -, bool bSelect -, int nImageId -) +bool wxNotebook::InsertPage ( size_t nPage, + wxNotebookPage* pPage, + const wxString& rsStrText, + bool bSelect, + int nImageId ) { ULONG ulApiPage; @@ -578,7 +554,7 @@ bool wxNotebook::InsertPage ( // If the inserted page is before the selected one, we must update the // index of the selected page // - if (nPage <= m_nSelection) + if (nPage <= (size_t)m_nSelection) { // // One extra page added @@ -600,13 +576,13 @@ bool wxNotebook::InsertPage ( // Now set TAB dimenstions // - wxWindowDC vDC(this); - wxCoord nTextX; - wxCoord nTextY; + wxWindowDC vDC(this); + wxCoord nTextX; + wxCoord nTextY; vDC.GetTextExtent(rsStrText, &nTextX, &nTextY); nTextY *= 2; - nTextX *= 1.3; + nTextX = (wxCoord)(nTextX * 1.3); if (nTextX > m_nTabSize) { m_nTabSize = nTextX; @@ -619,7 +595,7 @@ bool wxNotebook::InsertPage ( // // Now set any TAB text // - if (!rsStrText.IsEmpty()) + if (!rsStrText.empty()) { if (!SetPageText( nPage ,rsStrText @@ -671,6 +647,9 @@ bool wxNotebook::InsertPage ( if (nSelNew != -1) SetSelection(nSelNew); + + InvalidateBestSize(); + return TRUE; } // end of wxNotebook::InsertPage @@ -681,20 +660,6 @@ void wxNotebook::OnSize( wxSizeEvent& rEvent ) { - int nPage; - int nCount = (int)m_pages.Count(); - - for (nPage = 0; nPage < nCount; nPage++) - { - if (m_nSelection == nPage) - m_pages[nPage]->Refresh(); - else - ::WinSetWindowPos(m_pages[nPage]->GetHWND() - ,NULLHANDLE - ,0,0,0,0 - ,SWP_HIDE - ); - } rEvent.Skip(); } // end of wxNotebook::OnSize @@ -714,7 +679,7 @@ void wxNotebook::OnSelChange ( for (nSel = 0; nSel < nPageCount; nSel++) { - if (ulOS2Sel == m_alPageId[nSel]) + if (ulOS2Sel == (ULONG)m_alPageId[nSel]) { bFound = TRUE; break; @@ -732,7 +697,7 @@ void wxNotebook::OnSelChange ( for (nSel = 0; nSel < nPageCount; nSel++) { - if (ulOS2Sel == m_alPageId[nSel]) + if (ulOS2Sel == (ULONG)m_alPageId[nSel]) { bFound = TRUE; break; @@ -871,12 +836,10 @@ bool wxNotebook::DoPhase ( // ---------------------------------------------------------------------------- // wxNotebook Windows message handlers // ---------------------------------------------------------------------------- -bool wxNotebook::OS2OnScroll ( - int nOrientation -, WXWORD wSBCode -, WXWORD wPos -, WXHWND wControl -) +bool wxNotebook::OS2OnScroll ( int nOrientation, + WXWORD wSBCode, + WXWORD wPos, + WXHWND wControl ) { // // Don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the @@ -891,56 +854,4 @@ bool wxNotebook::OS2OnScroll ( ); } // end of wxNotebook::OS2OnScroll -// ---------------------------------------------------------------------------- -// wxNotebook helper functions -// ---------------------------------------------------------------------------- - -// -// Generate the page changing and changed events, hide the currently active -// panel and show the new one -// -void wxNotebook::ChangePage ( - int nOldSel -, int nSel -) -{ - static bool sbInsideChangePage = FALSE; - - // - // When we call ProcessEvent(), our own OnSelChange() is called which calls - // this function - break the infinite loop - // - if (sbInsideChangePage) - return; - - // - // It's not an error (the message may be generated by the tab control itself) - // and it may happen - just do nothing - // - if (nSel == nOldSel) - return; - - sbInsideChangePage = TRUE; - - wxNotebookEvent rEvent( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING - ,m_windowId - ); - - rEvent.SetSelection(nSel); - rEvent.SetOldSelection(nOldSel); - rEvent.SetEventObject(this); - if (GetEventHandler()->ProcessEvent(rEvent) && !rEvent.IsAllowed()) - { - // - // Program doesn't allow the page change - // - sbInsideChangePage = FALSE; - return; - } - rEvent.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); - GetEventHandler()->ProcessEvent(rEvent); - sbInsideChangePage = FALSE; -} // end of wxNotebook::ChangePage - #endif // wxUSE_NOTEBOOK -