]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/notebook.cpp
Blind fix for bug #1209944, wxFileConfig constructor corrupts the stack
[wxWidgets.git] / src / os2 / notebook.cpp
index 7cfd92ab124e2a409467f826e0a85a58047d7777..398290e166e4855d9a02f520d23b7a340997d88f 100644 (file)
 
 #if wxUSE_NOTEBOOK
 
-// wxWindows
+// wxWidgets
 #ifndef WX_PRECOMP
-  #include  "wx/string.h"
+  #include "wx/app.h"
+  #include "wx/dcclient.h"
+  #include "wx/string.h"
+  #include "wx/settings.h"
 #endif  // WX_PRECOMP
 
 #include  "wx/log.h"
@@ -134,8 +137,8 @@ bool wxNotebook::Create(
     //
     // Notebook, so explicitly specify 0 as last parameter
     //
-    if (!OS2CreateControl( "NOTEBOOK"
-                          ,_T("")
+    if (!OS2CreateControl( wxT("NOTEBOOK")
+                          ,wxEmptyString
                           ,rPos
                           ,rSize
                           ,lStyle | wxTAB_TRAVERSAL
@@ -155,7 +158,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;
@@ -184,11 +187,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
     //
@@ -206,37 +206,46 @@ int wxNotebook::GetRowCount() const
 } // end of wxNotebook::GetRowCount
 
 int wxNotebook::SetSelection(
-  int                               nPage
+  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
+  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])
@@ -245,7 +254,7 @@ bool wxNotebook::SetPageText(
 } // end of wxNotebook::SetPageText
 
 wxString wxNotebook::GetPageText (
-  int                               nPage
+  size_t                            nPage
 ) const
 {
     BOOKTEXT                        vBookText;
@@ -255,9 +264,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
@@ -265,16 +271,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
@@ -284,7 +290,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;
     }
@@ -292,12 +298,12 @@ 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
+  size_t                            nPage
 ) const
 {
     wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") );
@@ -309,29 +315,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
 
 // ----------------------------------------------------------------------------
@@ -341,22 +346,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 (
@@ -389,7 +379,7 @@ void wxNotebook::SetTabSize (
 // Remove one page from the notebook, without deleting
 //
 wxNotebookPage* wxNotebook::DoRemovePage (
-  int                               nPage
+  size_t                            nPage
 )
 {
     wxNotebookPage*                 pPageRemoved = wxNotebookBase::DoRemovePage(nPage);
@@ -397,9 +387,6 @@ wxNotebookPage* wxNotebook::DoRemovePage (
     if (!pPageRemoved)
         return NULL;
 
-
-    ULONG                           ulPageId = (ULONG)m_alPageId[nPage];
-
     ::WinSendMsg( GetHWND()
                  ,BKM_DELETEPAGE
                  ,MPFROMLONG((ULONG)m_alPageId[nPage])
@@ -419,14 +406,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
@@ -501,7 +488,7 @@ bool wxNotebook::AddPage (
 // Same as AddPage() but does it at given position
 //
 bool wxNotebook::InsertPage (
-  int                               nPage
+  size_t                            nPage
 , wxNotebookPage*                   pPage
 , const wxString&                   rsStrText
 , bool                              bSelect
@@ -576,7 +563,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
@@ -604,7 +591,7 @@ bool wxNotebook::InsertPage (
 
     vDC.GetTextExtent(rsStrText, &nTextX, &nTextY);
     nTextY *= 2;
-    nTextX *= 1.3;
+    nTextX  = (wxCoord)(nTextX * 1.3);
     if (nTextX > m_nTabSize)
     {
         m_nTabSize = nTextX;
@@ -669,6 +656,9 @@ bool wxNotebook::InsertPage (
 
     if (nSelNew != -1)
         SetSelection(nSelNew);
+
+    InvalidateBestSize();
+
     return TRUE;
 } // end of wxNotebook::InsertPage
 
@@ -679,8 +669,6 @@ void wxNotebook::OnSize(
   wxSizeEvent&                      rEvent
 )
 {
-    if (m_nSelection < m_pages.Count() && m_nSelection >= 0)
-        m_pages[m_nSelection]->Refresh();
     rEvent.Skip();
 } // end of wxNotebook::OnSize
 
@@ -693,22 +681,44 @@ void wxNotebook::OnSelChange (
     //
     if (rEvent.GetEventObject() == this)
     {
-        int                         nSel = rEvent.GetOldSelection();
+        int                         nPageCount = GetPageCount();
+        int                         nSel;
+        ULONG                       ulOS2Sel = (ULONG)rEvent.GetOldSelection();
+        bool                        bFound = FALSE;
 
-        if (nSel != -1)
+        for (nSel = 0; nSel < nPageCount; nSel++)
         {
-            m_pages[nSel]->Show(FALSE);
-            m_pages[nSel]->SetActivePage(FALSE);
+            if (ulOS2Sel == (ULONG)m_alPageId[nSel])
+            {
+                bFound = TRUE;
+                break;
+            }
         }
-        nSel = rEvent.GetSelection();
-        if (nSel != -1)
-        {
-            wxNotebookPage*         pPage = m_pages[nSel];
 
-            pPage->Show(TRUE);
-            pPage->SetFocus();
-            m_pages[nSel]->SetActivePage(TRUE);
+        if (!bFound)
+            return;
+
+        m_pages[nSel]->Show(FALSE);
+
+        ulOS2Sel = (ULONG)rEvent.GetSelection();
+
+        bFound = FALSE;
+
+        for (nSel = 0; nSel < nPageCount; nSel++)
+        {
+            if (ulOS2Sel == (ULONG)m_alPageId[nSel])
+            {
+                bFound = TRUE;
+                break;
+            }
         }
+
+        if (!bFound)
+            return;
+
+        wxNotebookPage*         pPage = m_pages[nSel];
+
+        pPage->Show(TRUE);
         m_nSelection = nSel;
     }
 
@@ -855,56 +865,5 @@ 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