]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/notebook.cpp
supporting promised file urls for transfer, see #14281
[wxWidgets.git] / src / os2 / notebook.cpp
index f518b1d11cf7161aad82c588639de6d85b116f41..f1c52e8ed43da48455f6a198320c3e83f5212a3a 100644 (file)
     #include "wx/settings.h"
     #include "wx/log.h"
     #include "wx/event.h"
+    #include  "wx/control.h"
 #endif  // WX_PRECOMP
 
 #include  "wx/imaglist.h"
-#include  "wx/control.h"
 
 #include  "wx/os2/private.h"
 
 // event table
 // ----------------------------------------------------------------------------
 
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
-
-BEGIN_EVENT_TABLE(wxNotebook, wxControl)
+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)
-
 // ============================================================================
 // implementation
 // ============================================================================
@@ -79,8 +73,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent)
 //
 void wxNotebook::Init()
 {
-    m_imageList  = NULL;
-    m_nSelection = -1;
     m_nTabSize   = 0;
 } // end of wxNotebook::Init
 
@@ -124,6 +116,8 @@ bool wxNotebook::Create( wxWindow*       pParent,
                          long            lStyle,
                          const wxString& rsName )
 {
+    if ( (lStyle & wxBK_ALIGN_MASK) == wxBK_DEFAULT )
+        lStyle |= wxBK_TOP;
     //
     // Base init
     //
@@ -212,23 +206,23 @@ int wxNotebook::SetSelection( size_t nPage )
 {
     wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") );
 
-    if (nPage != (size_t)m_nSelection)
+    if (nPage != (size_t)m_selection)
     {
-        wxNotebookEvent             vEvent( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
+        wxBookCtrlEvent             vEvent( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
                                            ,m_windowId
                                           );
 
         vEvent.SetSelection(nPage);
-        vEvent.SetOldSelection(m_nSelection);
+        vEvent.SetOldSelection(m_selection);
         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);
+            HandleWindowEvent(vEvent);
 
             ::WinSendMsg( GetHWND()
                          ,BKM_TURNTOPAGE
@@ -237,10 +231,26 @@ int wxNotebook::SetSelection( size_t nPage )
                         );
         }
     }
-    m_nSelection = nPage;
+    m_selection = nPage;
     return nPage;
 } // end of wxNotebook::SetSelection
 
+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_selection)
+    {
+        ::WinSendMsg( GetHWND()
+                ,BKM_TURNTOPAGE
+                ,MPFROMLONG((ULONG)m_alPageId[nPage])
+                        ,(MPARAM)0
+                    );
+    }
+    m_selection = nPage;
+    return nPage;
+}
+
 bool wxNotebook::SetPageText( size_t nPage,
                               const wxString& rsStrText )
 {
@@ -248,7 +258,7 @@ bool wxNotebook::SetPageText( size_t nPage,
     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
 
@@ -314,12 +324,12 @@ bool wxNotebook::SetPageImage (
 , int                               nImage
 )
 {
-    wxBitmap                        vBitmap = (wxBitmap)m_imageList->GetBitmap(nImage);
+    wxBitmap                        vBitmap = (wxBitmap)GetImageList()->GetBitmap(nImage);
 
     return (bool)::WinSendMsg( GetHWND()
                               ,BKM_SETTABBITMAP
                               ,MPFROMLONG((ULONG)m_alPageId[nPage])
-                              ,(MPARAM)wxFlipBmp(vBitmap.GetHBITMAP())
+                              ,(MPARAM)wxCopyBmp(vBitmap.GetHBITMAP(), true)
                              );
 } // end of wxNotebook::SetPageImage
 
@@ -390,7 +400,7 @@ wxNotebookPage* wxNotebook::DoRemovePage ( size_t nPage )
         //
         // No selection any more, the notebook becamse empty
         //
-        m_nSelection = -1;
+        m_selection = wxNOT_FOUND;
     }
     else // notebook still not empty
     {
@@ -399,23 +409,23 @@ wxNotebookPage* wxNotebook::DoRemovePage ( size_t nPage )
         //
         int                         nSelNew;
 
-        if (m_nSelection == (int)GetPageCount())
+        if (m_selection == (int)GetPageCount())
         {
             //
             // Last page deleted, make the new last page the new selection
             //
-            nSelNew = m_nSelection - 1;
+            nSelNew = m_selection - 1;
         }
-        else if (nPage <= (size_t)m_nSelection)
+        else if (nPage <= (size_t)m_selection)
         {
             //
             // We must show another page, even if it has the same index
             //
-            nSelNew = m_nSelection;
+            nSelNew = m_selection;
         }
         else // nothing changes for the currently selected page
         {
-            nSelNew = -1;
+            nSelNew = wxNOT_FOUND;
 
             //
             // We still must refresh the current page: this needs to be done
@@ -423,16 +433,16 @@ wxNotebookPage* wxNotebook::DoRemovePage ( size_t nPage )
             // control (i.e. when there are too many pages) -- otherwise after
             // deleting a page nothing at all is shown
             //
-            m_pages[m_nSelection]->Refresh();
+            m_pages[m_selection]->Refresh();
         }
 
-        if (nSelNew != -1)
+        if (nSelNew != wxNOT_FOUND)
         {
             //
-            // m_nSelection must be always valid so reset it before calling
+            // m_selection must be always valid so reset it before calling
             // SetSelection()
             //
-            m_nSelection = -1;
+            m_selection = wxNOT_FOUND;
             SetSelection(nSelNew);
         }
     }
@@ -455,7 +465,7 @@ bool wxNotebook::DeleteAllPages()
                  ,(MPARAM)0
                  ,(MPARAM)BKA_ALL
                 );
-    m_nSelection = -1;
+    m_selection = wxNOT_FOUND;
 
     return true;
 } // end of wxNotebook::DeleteAllPages
@@ -555,12 +565,12 @@ bool wxNotebook::InsertPage ( size_t          nPage,
     // If the inserted page is before the selected one, we must update the
     // index of the selected page
     //
-    if (nPage <= (size_t)m_nSelection)
+    if (nPage <= (size_t)m_selection)
     {
         //
         // One extra page added
         //
-        m_nSelection++;
+        m_selection++;
     }
 
     if (pPage)
@@ -635,19 +645,7 @@ bool wxNotebook::InsertPage ( size_t          nPage,
         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);
+    DoSetSelectionAfterInsertion(nPage, bSelect);
 
     InvalidateBestSize();
 
@@ -665,7 +663,7 @@ void wxNotebook::OnSize(
 } // end of wxNotebook::OnSize
 
 void wxNotebook::OnSelChange (
-  wxNotebookEvent&                  rEvent
+  wxBookCtrlEvent&                  rEvent
 )
 {
     //
@@ -711,7 +709,7 @@ void wxNotebook::OnSelChange (
         wxNotebookPage*         pPage = m_pages[nSel];
 
         pPage->Show(true);
-        m_nSelection = nSel;
+        m_selection = nSel;
     }
 
     //
@@ -732,8 +730,8 @@ void wxNotebook::OnSetFocus (
     //
     // set focus to the currently selected page if any
     //
-    if (m_nSelection != -1)
-        m_pages[m_nSelection]->SetFocus();
+    if (m_selection != wxNOT_FOUND)
+        m_pages[m_selection]->SetFocus();
     rEvent.Skip();
 } // end of wxNotebook::OnSetFocus
 
@@ -772,7 +770,7 @@ void wxNotebook::OnNavigationKey (
             //
             // No, it doesn't come from child, case (b): forward to a page
             //
-            if (m_nSelection != -1)
+            if (m_selection != wxNOT_FOUND)
             {
                 //
                 // So that the page knows that the event comes from it's parent
@@ -780,9 +778,9 @@ void wxNotebook::OnNavigationKey (
                 //
                 rEvent.SetEventObject(this);
 
-                wxWindow*           pPage = m_pages[m_nSelection];
+                wxWindow*           pPage = m_pages[m_selection];
 
-                if (!pPage->GetEventHandler()->ProcessEvent(rEvent))
+                if (!pPage->HandleWindowEvent(rEvent))
                 {
                     pPage->SetFocus();
                 }
@@ -804,7 +802,7 @@ void wxNotebook::OnNavigationKey (
             if (pParent)
             {
                 rEvent.SetCurrentFocus(this);
-                pParent->GetEventHandler()->ProcessEvent(rEvent);
+                pParent->HandleWindowEvent(rEvent);
             }
         }
     }