]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/bookctrl.cpp
Added part of patch
[wxWidgets.git] / src / common / bookctrl.cpp
index d1e7bcbe019159228f25cc4b62627632e1312470..db698594dd209817e76bc5e971b181d7d354ee8c 100644 (file)
@@ -172,7 +172,7 @@ void wxBookCtrlBase::OnHelp(wxHelpEvent& event)
     // if the event object == this because the book control can have other
     // subcontrols inside it (e.g. wxSpinButton in case of a notebook in wxUniv)
     wxWindow *source = wxStaticCast(event.GetEventObject(), wxWindow);
-    while ( source && source->GetParent() != this )
+    while ( source && source != this && source->GetParent() != this )
     {
         source = source->GetParent();
     }
@@ -310,6 +310,8 @@ wxRect wxBookCtrlBase::GetPageRect() const
 
         case wxBK_BOTTOM:
             rectPage.height -= size.y + GetInternalBorder();
+            if (rectPage.height < 0)
+                rectPage.height = 0;
             break;
 
         case wxBK_LEFT:
@@ -318,6 +320,8 @@ wxRect wxBookCtrlBase::GetPageRect() const
 
         case wxBK_RIGHT:
             rectPage.width -= size.x + GetInternalBorder();
+            if (rectPage.width < 0)
+                rectPage.width = 0;
             break;
     }
 
@@ -419,4 +423,52 @@ wxSize wxBookCtrlBase::GetControllerSize() const
     return size;
 }
 
+int wxBookCtrlBase::DoSetSelection(size_t n, int flags)
+{
+    wxCHECK_MSG( n < GetPageCount(), wxNOT_FOUND,
+                 wxT("invalid page index in wxBookCtrlBase::DoSetSelection()") );
+
+    const int oldSel = GetSelection();
+
+    if ( oldSel != wxNOT_FOUND && n != (size_t)oldSel )
+    {
+        wxBookCtrlBaseEvent *event = CreatePageChangingEvent();
+        bool allowed = false;
+
+        if ( flags & SetSelection_SendEvent )
+        {
+            event->SetSelection(n);
+            event->SetOldSelection(oldSel);
+            event->SetEventObject(this);
+
+            allowed = !GetEventHandler()->ProcessEvent(*event) || event->IsAllowed();
+        }
+
+        if ( !(flags & SetSelection_SendEvent) || allowed)
+        {
+            if ( oldSel != wxNOT_FOUND )
+                m_pages[oldSel]->Hide();
+
+            wxWindow *page = m_pages[n];
+            page->SetSize(GetPageRect());
+            page->Show();
+
+            // change selection now to ignore the selection change event
+            UpdateSelectedPage(n);
+
+            if ( flags & SetSelection_SendEvent )
+            {
+                // program allows the page change
+                MakeChangedEvent(*event);
+                (void)GetEventHandler()->ProcessEvent(*event);
+            }
+        }
+
+        delete event;
+    }
+
+    return oldSel;
+}
+
+
 #endif // wxUSE_BOOKCTRL