]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/listbkg.cpp
reminder added
[wxWidgets.git] / src / generic / listbkg.cpp
index c334b3d0120437f3bb48305098a5721a275b24e3..c4c83d0b9157463c49986f413feefae8d5f1429c 100644 (file)
@@ -34,6 +34,7 @@
 #include "wx/statline.h"
 #include "wx/listbook.h"
 #include "wx/imaglist.h"
+#include "wx/settings.h"
 
 // ----------------------------------------------------------------------------
 // constants
@@ -52,11 +53,12 @@ IMPLEMENT_DYNAMIC_CLASS(wxListbookEvent, wxNotifyEvent)
 
 const wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING = wxNewEventType();
 const wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED = wxNewEventType();
+const int wxID_LISTBOOKLISTVIEW = wxNewId();
 
 BEGIN_EVENT_TABLE(wxListbook, wxBookCtrl)
     EVT_SIZE(wxListbook::OnSize)
 
-    EVT_LIST_ITEM_SELECTED(wxID_ANY, wxListbook::OnListSelected)
+    EVT_LIST_ITEM_SELECTED(wxID_LISTBOOKLISTVIEW, wxListbook::OnListSelected)
 END_EVENT_TABLE()
 
 // ============================================================================
@@ -98,7 +100,7 @@ wxListbook::Create(wxWindow *parent,
     m_list = new wxListView
                  (
                     this,
-                    -1,
+                    wxID_LISTBOOKLISTVIEW,
                     wxDefaultPosition,
                     wxDefaultSize,
                     wxLC_ICON | wxLC_SINGLE_SEL
@@ -135,8 +137,8 @@ wxSize wxListbook::GetListSize() const
             wxRect r;
             m_list->GetItemRect(i, r);
 
-            wxCoord w = r.x + r.width,
-                    h = r.y + r.height;
+            wxCoord w = r.width,
+                    h = r.height;
 
             if ( w > widthMax )
                 widthMax = w;
@@ -150,11 +152,25 @@ wxSize wxListbook::GetListSize() const
     {
         size.x = sizeClient.x;
         size.y = heightMax;
+
+        if ( widthMax >= sizeClient.x )
+        {
+            // account for the scrollbar
+            size.y += wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
+        }
     }
     else // left/right aligned
     {
-        size.x = widthMax + 10;
+        // +20 is due to an apparent bug in wxListCtrl::GetItemRect() but I
+        // can't fix it there right now so just add a fudge here...
+        size.x = widthMax + 20;
         size.y = sizeClient.y;
+
+        if ( heightMax >= sizeClient.y )
+        {
+            // account for the scrollbar
+            size.x += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
+        }
     }
 
     return size;
@@ -193,6 +209,14 @@ wxRect wxListbook::GetPageRect() const
 
 void wxListbook::OnSize(wxSizeEvent& event)
 {
+    event.Skip();
+
+    if ( !m_list )
+    {
+        // we're not fully created yet
+        return;
+    }
+
     // resize the list control and the page area to fit inside our new size
     const wxSize sizeClient = GetClientSize(),
                  sizeList = GetListSize();
@@ -267,8 +291,6 @@ void wxListbook::OnSize(wxSizeEvent& event)
             page->Show();
         }
     }
-
-    event.Skip();
 }
 
 wxSize wxListbook::CalcSizeFromPage(const wxSize& sizePage) const