]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/notebook.cpp
invalidate best size cache when GTK style changes
[wxWidgets.git] / src / msw / notebook.cpp
index e4cfd4c2a0b5c92b70e1da33b1d831ce29cf40d1..7057d019edc151c574535124f5bc41c790552c4b 100644 (file)
@@ -22,7 +22,7 @@
 
 #if wxUSE_NOTEBOOK
 
-// wxWindows
+// wxWidgets
 #ifndef WX_PRECOMP
   #include  "wx/string.h"
 #endif  // WX_PRECOMP
@@ -167,7 +167,7 @@ wxBEGIN_PROPERTIES_TABLE(wxNotebook)
     wxEVENT_PROPERTY( PageChanged , wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED , wxNotebookEvent )
 
     wxPROPERTY_COLLECTION( PageInfos , wxNotebookPageInfoList , wxNotebookPageInfo* , AddPageInfo , GetPageInfos , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
-    wxPROPERTY_FLAGS( WindowStyle , wxNotebookStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
+    wxPROPERTY_FLAGS( WindowStyle , wxNotebookStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
 wxEND_PROPERTIES_TABLE()
 
 wxBEGIN_HANDLERS_TABLE(wxNotebook)
@@ -177,7 +177,7 @@ wxCONSTRUCTOR_5( wxNotebook , wxWindow* , Parent , wxWindowID , Id , wxPoint , P
 
 
 wxBEGIN_PROPERTIES_TABLE(wxNotebookPageInfo)
-    wxREADONLY_PROPERTY( Page , wxNotebookPage* , GetPage , , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
+    wxREADONLY_PROPERTY( Page , wxNotebookPage* , GetPage , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
     wxREADONLY_PROPERTY( Text , wxString , GetText , wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
     wxREADONLY_PROPERTY( Selected , bool , GetSelected , false, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
     wxREADONLY_PROPERTY( ImageId , int , GetImageId , -1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
@@ -438,7 +438,7 @@ wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const
 {
     wxSize sizeTotal = sizePage;
     
-    // We need to make getting tab size part of the wxWindows API.
+    // We need to make getting tab size part of the wxWidgets API.
     wxSize tabSize(0, 0);
     if (GetPageCount() > 0)
     {
@@ -471,9 +471,18 @@ void wxNotebook::AdjustPageSize(wxNotebookPage *page)
 
     // get the page size from the notebook size
     GetSize((int *)&rc.right, (int *)&rc.bottom);
-    TabCtrl_AdjustRect(m_hwnd, false, &rc);
 
-    page->SetSize(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
+    // This check is to work around a bug in TabCtrl_AdjustRect which will
+    // cause a crash on win2k, or on XP with themes disabled, if the
+    // wxNB_MULTILINE style is used and the rectangle is very small, (such as
+    // when the notebook is first created.)  The value of 20 is just
+    // arbitrarily chosen, if there is a better way to determine this value
+    // then please do so.  --RD
+    if (rc.right > 20 && rc.bottom > 20)
+    {
+        TabCtrl_AdjustRect(m_hwnd, false, &rc);
+        page->SetSize(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
+    }
 }
 
 // ----------------------------------------------------------------------------
@@ -544,6 +553,7 @@ bool wxNotebook::DeleteAllPages()
 
   m_nSelection = -1;
 
+  InvalidateBestSize();
   return true;
 }
 
@@ -603,6 +613,16 @@ bool wxNotebook::InsertPage(size_t nPage,
         tcItem.pszText = (wxChar *)strText.c_str(); // const_cast
     }
 
+    // hide the page: unless it is selected, it shouldn't be shown (and if it
+    // is selected it will be shown later)
+    HWND hwnd = GetWinHwnd(pPage);
+    SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE);
+
+    // this updates internal flag too -- otherwise it would get out of sync
+    // with the real state
+    pPage->Show(false);
+
+
     // fit the notebook page to the tab control's display area: this should be
     // done before adding it to the notebook or TabCtrl_InsertItem() will
     // change the notebooks size itself!
@@ -628,16 +648,6 @@ bool wxNotebook::InsertPage(size_t nPage,
         AdjustPageSize(pPage);
     }
 
-    // hide the page: unless it is selected, it shouldn't be shown (and if it
-    // is selected it will be shown later)
-    HWND hwnd = GetWinHwnd(pPage);
-    SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE);
-
-    // this updates internal flag too -- otherwise it would get out of sync
-    // with the real state
-    pPage->Show(false);
-
-
     // now deal with the selection
     // ---------------------------
 
@@ -660,6 +670,7 @@ bool wxNotebook::InsertPage(size_t nPage,
     if ( selNew != -1 )
         SetSelection(selNew);
 
+    InvalidateBestSize();
     return true;
 }