X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/21323df7fe84193504be91f0ee20a869707e8412..079f4130b861d094c79e0952966caad8b85dab67:/src/os2/notebook.cpp diff --git a/src/os2/notebook.cpp b/src/os2/notebook.cpp index af5ac8b27e..9f7df8f3f9 100644 --- a/src/os2/notebook.cpp +++ b/src/os2/notebook.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: notebook.cpp +// Name: src/os2/notebook.cpp // Purpose: implementation of wxNotebook // Author: David Webster // Modified by: @@ -14,18 +14,20 @@ #if wxUSE_NOTEBOOK -// wxWindows +#include "wx/notebook.h" + +// wxWidgets #ifndef WX_PRECOMP - #include "wx/app.h" - #include "wx/string.h" - #include "wx/settings.h" + #include "wx/app.h" + #include "wx/dcclient.h" + #include "wx/string.h" + #include "wx/settings.h" + #include "wx/log.h" + #include "wx/event.h" + #include "wx/control.h" #endif // WX_PRECOMP -#include "wx/log.h" #include "wx/imaglist.h" -#include "wx/event.h" -#include "wx/control.h" -#include "wx/notebook.h" #include "wx/os2/private.h" @@ -34,7 +36,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() @@ -47,18 +53,14 @@ // event table // ---------------------------------------------------------------------------- -DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED) -DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING) - -BEGIN_EVENT_TABLE(wxNotebook, wxControl) - EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange) +BEGIN_EVENT_TABLE(wxNotebook, wxBookCtrlBase) + EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, wxNotebook::OnSelChange) EVT_SIZE(wxNotebook::OnSize) EVT_SET_FOCUS(wxNotebook::OnSetFocus) EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) END_EVENT_TABLE() -IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl) -IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent) +IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxBookCtrlBase) // ============================================================================ // implementation @@ -111,15 +113,15 @@ 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 ) { + if ( (lStyle & wxBK_ALIGN_MASK) == wxBK_DEFAULT ) + lStyle |= wxBK_TOP; // // Base init // @@ -131,21 +133,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,13 +159,13 @@ 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) + if (lStyle & wxBK_BOTTOM) dwTabStyle |= BKS_MAJORTABBOTTOM | BKS_BACKPAGESBL; - else if (lStyle & wxNB_RIGHT) + else if (lStyle & wxBK_RIGHT) dwTabStyle |= BKS_MAJORTABRIGHT | BKS_BACKPAGESBR; - else if (lStyle & wxNB_LEFT) + else if (lStyle & wxBK_LEFT) dwTabStyle |= BKS_MAJORTABLEFT | BKS_BACKPAGESTL; else // default to top dwTabStyle |= BKS_MAJORTABTOP | BKS_BACKPAGESTR; @@ -188,9 +190,6 @@ WXDWORD wxNotebook::OS2GetStyle ( 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,31 +206,27 @@ 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") ); + wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); - if (nPage != m_nSelection) + if (nPage != (size_t)m_nSelection) { - wxNotebookEvent vEvent( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING + wxBookCtrlEvent vEvent( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING ,m_windowId ); vEvent.SetSelection(nPage); vEvent.SetOldSelection(m_nSelection); vEvent.SetEventObject(this); - if (!GetEventHandler()->ProcessEvent(vEvent) || vEvent.IsAllowed()) + if (!HandleWindowEvent(vEvent) || vEvent.IsAllowed()) { // // Program allows the page change // vEvent.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); - GetEventHandler()->ProcessEvent(vEvent); - - ULONG ulPageId = (ULONG)m_alPageId[nPage]; + HandleWindowEvent(vEvent); ::WinSendMsg( GetHWND() ,BKM_TURNTOPAGE @@ -244,36 +239,41 @@ int wxNotebook::SetSelection( return nPage; } // end of wxNotebook::SetSelection -bool wxNotebook::SetPageText( - int nPage -, const wxString& rsStrText -) +int wxNotebook::ChangeSelection( size_t nPage ) { - wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") ); - + wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); - ULONG ulPageId = (ULONG)m_alPageId[nPage]; + if (nPage != (size_t)m_nSelection) + { + ::WinSendMsg( GetHWND() + ,BKM_TURNTOPAGE + ,MPFROMLONG((ULONG)m_alPageId[nPage]) + ,(MPARAM)0 + ); + } + m_nSelection = nPage; + return nPage; +} +bool wxNotebook::SetPageText( size_t nPage, + const wxString& rsStrText ) +{ + wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("notebook page out of range") ); return (bool)::WinSendMsg( m_hWnd ,BKM_SETTABTEXT ,MPFROMLONG((ULONG)m_alPageId[nPage]) - ,MPFROMP((PSZ)rsStrText.c_str()) + ,MPFROMP((const char*)rsStrText.c_str()) ); } // end of wxNotebook::SetPageText -wxString wxNotebook::GetPageText ( - int nPage -) const +wxString wxNotebook::GetPageText ( size_t nPage ) const { BOOKTEXT vBookText; wxChar zBuf[256]; wxString sStr; ULONG ulRc; - wxCHECK_MSG( IS_VALID_PAGE(nPage), wxT(""), wxT("notebook page out of range") ); - - - ULONG ulPageId = (ULONG)m_alPageId[nPage]; + 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 @@ -282,16 +282,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 @@ -301,7 +301,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; } @@ -309,15 +309,13 @@ 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") ); + wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); // // For OS/2 just return the page @@ -326,29 +324,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)wxCopyBmp(vBitmap.GetHBITMAP(), true) ); } // 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 // ---------------------------------------------------------------------------- @@ -358,22 +355,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 ( @@ -405,18 +387,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]) @@ -436,14 +413,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 @@ -493,7 +470,8 @@ bool wxNotebook::DeleteAllPages() ,(MPARAM)BKA_ALL ); m_nSelection = -1; - return TRUE; + + return true; } // end of wxNotebook::DeleteAllPages // @@ -517,18 +495,16 @@ 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; wxASSERT( pPage != NULL ); - wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), FALSE ); + wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), false ); // // Under OS/2 we can only insert FIRST, LAST, NEXT or PREV. Requires @@ -554,7 +530,7 @@ bool wxNotebook::InsertPage ( vError = ::WinGetLastError(vHabmain); sError = wxPMErrorToStr(vError); - return FALSE; + return false; } m_alPageId.Insert((long)ulApiPage, nPage); } @@ -572,7 +548,7 @@ bool wxNotebook::InsertPage ( vError = ::WinGetLastError(vHabmain); sError = wxPMErrorToStr(vError); - return FALSE; + return false; } m_alPageId.Insert((long)ulApiPage, nPage); } @@ -587,13 +563,13 @@ bool wxNotebook::InsertPage ( ,MPFROMLONG((ULONG)m_alPageId[nPage]) ,MPFROMHWND(pPage->GetHWND()) )) - return FALSE; + return false; } // // 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 @@ -615,13 +591,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; @@ -634,12 +610,12 @@ bool wxNotebook::InsertPage ( // // Now set any TAB text // - if (!rsStrText.IsEmpty()) + if (!rsStrText.empty()) { if (!SetPageText( nPage ,rsStrText )) - return FALSE; + return false; } // @@ -650,7 +626,7 @@ bool wxNotebook::InsertPage ( if (!SetPageImage( nPage ,nImageId )) - return FALSE; + return false; } if (pPage) @@ -658,7 +634,7 @@ bool wxNotebook::InsertPage ( // // Don't show pages by default (we'll need to adjust their size first) // - HWND hWnd = GetWinHwnd(pPage); + HWND hWnd = GetWinHwnd(pPage); WinSetWindowULong( hWnd ,QWL_STYLE @@ -670,14 +646,14 @@ bool wxNotebook::InsertPage ( // // This updates internal flag too - otherwise it will get out of sync // - pPage->Show(FALSE); + pPage->Show(false); } // // Some page should be selected: either this one or the first one if there is // still no selection // - int nSelNew = -1; + int nSelNew = -1; if (bSelect) nSelNew = nPage; @@ -686,7 +662,10 @@ bool wxNotebook::InsertPage ( if (nSelNew != -1) SetSelection(nSelNew); - return TRUE; + + InvalidateBestSize(); + + return true; } // end of wxNotebook::InsertPage // ---------------------------------------------------------------------------- @@ -696,25 +675,11 @@ 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 void wxNotebook::OnSelChange ( - wxNotebookEvent& rEvent + wxBookCtrlEvent& rEvent ) { // @@ -722,16 +687,16 @@ void wxNotebook::OnSelChange ( // if (rEvent.GetEventObject() == this) { - int nPageCount = GetPageCount(); - int nSel; - ULONG ulOS2Sel = (ULONG)rEvent.GetOldSelection(); - bool bFound = FALSE; + int nPageCount = GetPageCount(); + int nSel; + ULONG ulOS2Sel = (ULONG)rEvent.GetOldSelection(); + bool bFound = false; for (nSel = 0; nSel < nPageCount; nSel++) { - if (ulOS2Sel == m_alPageId[nSel]) + if (ulOS2Sel == (ULONG)m_alPageId[nSel]) { - bFound = TRUE; + bFound = true; break; } } @@ -739,17 +704,17 @@ void wxNotebook::OnSelChange ( if (!bFound) return; - m_pages[nSel]->Show(FALSE); + m_pages[nSel]->Show(false); ulOS2Sel = (ULONG)rEvent.GetSelection(); - bFound = FALSE; + bFound = false; for (nSel = 0; nSel < nPageCount; nSel++) { - if (ulOS2Sel == m_alPageId[nSel]) + if (ulOS2Sel == (ULONG)m_alPageId[nSel]) { - bFound = TRUE; + bFound = true; break; } } @@ -759,7 +724,7 @@ void wxNotebook::OnSelChange ( wxNotebookPage* pPage = m_pages[nSel]; - pPage->Show(TRUE); + pPage->Show(true); m_nSelection = nSel; } @@ -831,7 +796,7 @@ void wxNotebook::OnNavigationKey ( wxWindow* pPage = m_pages[m_nSelection]; - if (!pPage->GetEventHandler()->ProcessEvent(rEvent)) + if (!pPage->HandleWindowEvent(rEvent)) { pPage->SetFocus(); } @@ -853,7 +818,7 @@ void wxNotebook::OnNavigationKey ( if (pParent) { rEvent.SetCurrentFocus(this); - pParent->GetEventHandler()->ProcessEvent(rEvent); + pParent->HandleWindowEvent(rEvent); } } } @@ -866,39 +831,33 @@ void wxNotebook::OnNavigationKey ( // // Override these 2 functions to do nothing: everything is done in OnSize // -void wxNotebook::SetConstraintSizes( - bool WXUNUSED(bRecurse) -) +void wxNotebook::SetConstraintSizes( bool WXUNUSED(bRecurse) ) { // // Don't set the sizes of the pages - their correct size is not yet known // - wxControl::SetConstraintSizes(FALSE); + wxControl::SetConstraintSizes(false); } // end of wxNotebook::SetConstraintSizes -bool wxNotebook::DoPhase ( - int WXUNUSED(nPhase) -) +bool wxNotebook::DoPhase ( int WXUNUSED(nPhase) ) { - return TRUE; + return true; } // end of 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 // up-down control // if (wControl) - return FALSE; + return false; return wxNotebookBase::OS2OnScroll( nOrientation ,wSBCode ,wPos @@ -907,4 +866,3 @@ bool wxNotebook::OS2OnScroll ( } // end of wxNotebook::OS2OnScroll #endif // wxUSE_NOTEBOOK -