]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/bookctrl.cpp
Don't crash when waiting for thread termination in wxMSW.
[wxWidgets.git] / src / common / bookctrl.cpp
index da06cdafeba1ce300f7bc3f26a1ccdde4ffda51b..cd3baf71e67401c2b87b3bf59f14f674f6af0b2d 100644 (file)
@@ -53,6 +53,7 @@ END_EVENT_TABLE()
 
 void wxBookCtrlBase::Init()
 {
+    m_selection = wxNOT_FOUND;
     m_bookctrl = NULL;
     m_imageList = NULL;
     m_ownsImageList = false;
@@ -137,6 +138,28 @@ void wxBookCtrlBase::DoInvalidateBestSize()
         wxControl::InvalidateBestSize();
 }
 
+wxSize wxBookCtrlBase::CalcSizeFromPage(const wxSize& sizePage) const
+{
+    // we need to add the size of the choice control and the border between
+    const wxSize sizeController = GetControllerSize();
+
+    wxSize size = sizePage;
+    if ( IsVertical() )
+    {
+        if ( sizeController.x > sizePage.x )
+            size.x = sizeController.x;
+        size.y += sizeController.y + GetInternalBorder();
+    }
+    else // left/right aligned
+    {
+        size.x += sizeController.x + GetInternalBorder();
+        if ( sizeController.y > sizePage.y )
+            size.y = sizeController.y;
+    }
+
+    return size;
+}
+
 void wxBookCtrlBase::SetPageSize(const wxSize& size)
 {
     SetClientSize(CalcSizeFromPage(size));
@@ -289,7 +312,10 @@ void wxBookCtrlBase::OnSize(wxSizeEvent& event)
 
 wxSize wxBookCtrlBase::GetControllerSize() const
 {
-    if ( !m_bookctrl )
+    // For at least some book controls (e.g. wxChoicebook) it may make sense to
+    // (temporarily?) hide the controller and we shouldn't leave extra space
+    // for the hidden control in this case.
+    if ( !m_bookctrl || !m_bookctrl->IsShown() )
         return wxSize(0, 0);
 
     const wxSize sizeClient = GetClientSize(),