]> git.saurik.com Git - wxWidgets.git/blobdiff - src/univ/notebook.cpp
no changes, just resolved conflicts (due to the fact that I had forgotten to commit...
[wxWidgets.git] / src / univ / notebook.cpp
index c90d042c3972158c88c8ae86860fdef175c5c3e5..cb5bfd045b5b20da06e16f255f439b5fa6650013 100644 (file)
@@ -17,7 +17,7 @@
 // headers
 // ----------------------------------------------------------------------------
 
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
     #pragma implementation "univnotebook.h"
 #endif
 
@@ -133,14 +133,14 @@ bool wxNotebook::Create(wxWindow *parent,
 // wxNotebook page titles and images
 // ----------------------------------------------------------------------------
 
-wxString wxNotebook::GetPageText(int nPage) const
+wxString wxNotebook::GetPageText(size_t nPage) const
 {
     wxCHECK_MSG( IS_VALID_PAGE(nPage), _T(""), _T("invalid notebook page") );
 
     return m_titles[nPage];
 }
 
-bool wxNotebook::SetPageText(int nPage, const wxString& strText)
+bool wxNotebook::SetPageText(size_t nPage, const wxString& strText)
 {
     wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, _T("invalid notebook page") );
 
@@ -163,14 +163,14 @@ bool wxNotebook::SetPageText(int nPage, const wxString& strText)
     return TRUE;
 }
 
-int wxNotebook::GetPageImage(int nPage) const
+int wxNotebook::GetPageImage(size_t nPage) const
 {
     wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, _T("invalid notebook page") );
 
     return m_images[nPage];
 }
 
-bool wxNotebook::SetPageImage(int nPage, int nImage)
+bool wxNotebook::SetPageImage(size_t nPage, int nImage)
 {
     wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, _T("invalid notebook page") );
 
@@ -202,7 +202,7 @@ wxNotebook::~wxNotebook()
 // wxNotebook page switching
 // ----------------------------------------------------------------------------
 
-int wxNotebook::SetSelection(int nPage)
+int wxNotebook::SetSelection(size_t nPage)
 {
     wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, _T("invalid notebook page") );
 
@@ -212,6 +212,17 @@ int wxNotebook::SetSelection(int nPage)
         return m_sel;
     }
 
+    // event handling
+    wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId);
+    event.SetSelection(nPage);
+    event.SetOldSelection(m_sel);
+    event.SetEventObject(this);
+    if ( GetEventHandler()->ProcessEvent(event) && !event.IsAllowed() )
+    {
+        // program doesn't allow the page change
+        return m_sel;
+    }
+
     // we need to change m_sel first, before calling RefreshTab() below as
     // otherwise the previously selected tab wouldn't be redrawn properly under
     // wxGTK which calls Refresh() immediately and not during the next event
@@ -255,46 +266,24 @@ int wxNotebook::SetSelection(int nPage)
         m_pages[m_sel]->Show();
     }
 
-    return m_sel;
-}
-
-void wxNotebook::ChangePage(int nPage)
-{
-    wxCHECK_RET( IS_VALID_PAGE(nPage), _T("invalid notebook page") );
-
-    if ( (size_t)nPage == m_sel )
-    {
-        // nothing to do
-        return;
-    }
-
-    wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId);
-    event.SetSelection(nPage);
-    event.SetOldSelection(m_sel);
-    event.SetEventObject(this);
-    if ( GetEventHandler()->ProcessEvent(event) && !event.IsAllowed() )
-    {
-        // program doesn't allow the page change
-        return;
-    }
-
-    SetSelection(nPage);
-
+    // event handling
     event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED);
     GetEventHandler()->ProcessEvent(event);
+
+    return selOld;
 }
 
 // ----------------------------------------------------------------------------
 // wxNotebook pages adding/deleting
 // ----------------------------------------------------------------------------
 
-bool wxNotebook::InsertPage(int nPage,
+bool wxNotebook::InsertPage(size_t nPage,
                             wxNotebookPage *pPage,
                             const wxString& strText,
                             bool bSelect,
                             int imageId)
 {
-    int nPages = GetPageCount();
+    size_t nPages = GetPageCount();
     wxCHECK_MSG( nPage == nPages || IS_VALID_PAGE(nPage), FALSE,
                  _T("invalid notebook page in InsertPage()") );
 
@@ -330,6 +319,7 @@ bool wxNotebook::InsertPage(int nPage,
         bSelect = TRUE;
 
         Relayout();
+        Refresh();
     }
     else // not the first tab
     {
@@ -370,7 +360,7 @@ bool wxNotebook::DeleteAllPages()
     return TRUE;
 }
 
-wxNotebookPage *wxNotebook::DoRemovePage(int nPage)
+wxNotebookPage *wxNotebook::DoRemovePage(size_t nPage)
 {
     wxCHECK_MSG( IS_VALID_PAGE(nPage), NULL, _T("invalid notebook page") );
 
@@ -382,7 +372,11 @@ wxNotebookPage *wxNotebook::DoRemovePage(int nPage)
     m_images.RemoveAt(nPage);
 
     // the spin button might not be needed any more
-    if ( HasSpinBtn() )
+    // 2002-08-12 'if' commented out by JACS on behalf
+    // of Hans Van Leemputten <Hansvl@softhome.net> who
+    // points out that UpdateSpinBtn should always be called,
+    // to ensure m_lastVisible is up to date.
+    // if ( HasSpinBtn() )
     {
         UpdateSpinBtn();
     }
@@ -458,7 +452,9 @@ void wxNotebook::DoDrawTab(wxDC& dc, const wxRect& rect, size_t n)
     {
         int image = m_images[n];
 
-#ifdef __WXMSW__    // FIXME
+        // Not needed now that wxGenericImageList is being
+        // used for wxUniversal under MSW
+#if 0 // def __WXMSW__    // FIXME
         int w, h;
         m_imageList->GetSize(n, w, h);
         bmp.Create(w, h);
@@ -512,10 +508,20 @@ void wxNotebook::DoDraw(wxControlRenderer *renderer)
         wxSize sizeSpinBtn = m_spinbtn->GetSize();
 
         if ( IsVertical() )
+        {
             rectTabs.height -= sizeSpinBtn.y;
+
+            // Allow for erasing the line under selected tab
+            rectTabs.width += 2;
+        }
         else
+        {
             rectTabs.width -= sizeSpinBtn.x;
 
+            // Allow for erasing the line under selected tab
+            rectTabs.height += 2;
+        }
+
         dc.SetClippingRegion(rectTabs);
     }
 
@@ -560,14 +566,19 @@ void wxNotebook::DoDraw(wxControlRenderer *renderer)
     {
         DoDrawTab(dc, rectSel, m_sel);
     }
+
+    dc.DestroyClippingRegion();
 }
 
 // ----------------------------------------------------------------------------
 // wxNotebook geometry
 // ----------------------------------------------------------------------------
 
-int wxNotebook::HitTest(const wxPoint& pt) const
+int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
 {
+    if ( flags )
+        *flags = wxNB_HITTEST_NOWHERE;
+
     // first check that it is in this window at all
     if ( !GetClientRect().Inside(pt) )
     {
@@ -608,7 +619,15 @@ int wxNotebook::HitTest(const wxPoint& pt) const
         GetTabSize(n, &rectTabs.width, &rectTabs.height);
 
         if ( rectTabs.Inside(pt) )
+        {
+            if ( flags )
+            {
+                // TODO: be more precise
+                *flags = wxNB_HITTEST_ONITEM;
+            }
+
             return n;
+        }
 
         // move the rectTabs to the next tab
         if ( IsVertical() )
@@ -943,7 +962,7 @@ void wxNotebook::SetPageSize(const wxSize& size)
     SetClientSize(GetSizeForPage(size));
 }
 
-wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage)
+wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const
 {
     return AdjustSize(GetSizeForPage(sizePage));
 }
@@ -1273,11 +1292,11 @@ bool wxNotebook::PerformAction(const wxControlAction& action,
                                const wxString& strArg)
 {
     if ( action == wxACTION_NOTEBOOK_NEXT )
-        ChangePage(GetNextPage(TRUE));
+        SetSelection(GetNextPage(TRUE));
     else if ( action == wxACTION_NOTEBOOK_PREV )
-        ChangePage(GetNextPage(FALSE));
+        SetSelection(GetNextPage(FALSE));
     else if ( action == wxACTION_NOTEBOOK_GOTO )
-        ChangePage((int)numArg);
+        SetSelection((int)numArg);
     else
         return wxControl::PerformAction(action, numArg, strArg);
 
@@ -1370,8 +1389,9 @@ bool wxStdNotebookInputHandler::HandleMouseMove(wxInputConsumer *consumer,
     return wxStdInputHandler::HandleMouseMove(consumer, event);
 }
 
-bool wxStdNotebookInputHandler::HandleFocus(wxInputConsumer *consumer,
-                                            const wxFocusEvent& event)
+bool
+wxStdNotebookInputHandler::HandleFocus(wxInputConsumer *consumer,
+                                       const wxFocusEvent& WXUNUSED(event))
 {
     HandleFocusChange(consumer);