]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/listbkg.cpp
Avoid an assert if no alignment style is specified
[wxWidgets.git] / src / generic / listbkg.cpp
index 1985558dfab29b3b799830fbfc1d3bff3f63e688..f096095e55bf12a50678e141068955c94ac1b8f5 100644 (file)
 
 #if wxUSE_LISTBOOK
 
+#include "wx/listbook.h"
+
+#ifndef WX_PRECOMP
+    #include "wx/settings.h"
+#endif
+
 #include "wx/listctrl.h"
 #include "wx/statline.h"
-#include "wx/listbook.h"
 #include "wx/imaglist.h"
-#include "wx/settings.h"
 
 // ----------------------------------------------------------------------------
 // various wxWidgets macros
 IMPLEMENT_DYNAMIC_CLASS(wxListbook, wxBookCtrlBase)
 IMPLEMENT_DYNAMIC_CLASS(wxListbookEvent, wxNotifyEvent)
 
+#if !WXWIN_COMPATIBILITY_EVENT_TYPES
 const wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING = wxNewEventType();
 const wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED = wxNewEventType();
+#endif
 const int wxID_LISTBOOKLISTVIEW = wxNewId();
 
 BEGIN_EVENT_TABLE(wxListbook, wxBookCtrlBase)
@@ -155,6 +161,26 @@ void wxListbook::OnSize(wxSizeEvent& event)
     wxBookCtrlBase::OnSize(event);
 }
 
+int wxListbook::HitTest(const wxPoint& pt, long * WXUNUSED(flags)) const
+{
+    int pagePos = wxNOT_FOUND;
+
+    const wxPoint clientPt = ClientToScreen(GetListView()->ScreenToClient(pt));
+
+    if ( wxRect(GetListView()->GetSize()).Inside(clientPt) )
+    {
+        int flagsList;
+        pagePos = GetListView()->HitTest(clientPt, flagsList);
+
+        if ( !(flagsList & wxLIST_HITTEST_ONITEM) )
+        {
+            pagePos = wxNOT_FOUND;
+        }
+    }
+
+    return pagePos;
+}
+
 wxSize wxListbook::CalcSizeFromPage(const wxSize& sizePage) const
 {
     // we need to add the size of the list control and the border between
@@ -299,7 +325,14 @@ wxListbook::InsertPage(size_t n,
         SetSelection(selNew);
 
     InvalidateBestSize();
+    // GetListView()->InvalidateBestSize();
     GetListView()->Arrange();
+
+    if (GetPageCount() == 1)
+    {
+        wxSizeEvent sz(GetSize(), GetId());
+        ProcessEvent(sz);
+    }
     return true;
 }
 
@@ -329,6 +362,11 @@ wxWindow *wxListbook::DoRemovePage(size_t page)
         }
 
         GetListView()->Arrange();
+        if (GetPageCount() == 0)
+        {
+            wxSizeEvent sz(GetSize(), GetId());
+            ProcessEvent(sz);
+        }
     }
 
     return win;
@@ -338,7 +376,15 @@ wxWindow *wxListbook::DoRemovePage(size_t page)
 bool wxListbook::DeleteAllPages()
 {
     GetListView()->DeleteAllItems();
-    return wxBookCtrlBase::DeleteAllPages();
+    if (!wxBookCtrlBase::DeleteAllPages())
+        return false;
+
+    m_selection = -1;
+
+    wxSizeEvent sz(GetSize(), GetId());
+    ProcessEvent(sz);
+
+    return true;
 }
 
 // ----------------------------------------------------------------------------