]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/widgets/widgets.cpp
Changes needed for scanning the aui header files with SWIG for
[wxWidgets.git] / samples / widgets / widgets.cpp
index 8287db11ae9477f4fd231528b1fd263457111b78..25d11d88b78c520ca9992691996f51edcdde8426 100644 (file)
@@ -48,6 +48,7 @@
 #include "wx/fontdlg.h"
 #include "wx/textdlg.h"
 #include "wx/imaglist.h"
+#include "wx/wupdlock.h"
 
 #include "widgets.h"
 
@@ -381,7 +382,7 @@ WidgetsFrame::WidgetsFrame(const wxString& title)
     // we have 2 panes: book with pages demonstrating the controls in the
     // upper one and the log window with some buttons in the lower
 
-    int style = wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN|WidgetBookStyle;
+    int style = wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN|wxBK_DEFAULT;
     // Uncomment to suppress page theme (draw in solid colour)
     //style |= wxNB_NOPAGETHEME;
 
@@ -478,7 +479,7 @@ void WidgetsFrame::InitBook()
                                          wxID_ANY,
                                          wxDefaultPosition,
                                          wxDefaultSize,
-                                         WidgetBookStyle);
+                                         wxBK_DEFAULT);
 #endif
 
         for ( WidgetsPageInfo *info = WidgetsPage::ms_widgetPages;
@@ -567,12 +568,17 @@ void WidgetsFrame::InitBook()
 
 WidgetsPage *WidgetsFrame::CurrentPage()
 {
+    wxWindow *page = m_book->GetCurrentPage();
+    if(!page) return NULL;
+
 #if USE_TREEBOOK
-    return wxStaticCast(m_book->GetCurrentPage(), WidgetsPage);
+    return wxStaticCast(page, WidgetsPage);
 #else
-    WidgetsBookCtrl *book = wxStaticCast(m_book->GetCurrentPage(), WidgetsBookCtrl);
-    if (!book) return NULL;
-    return wxStaticCast(book->GetCurrentPage(), WidgetsPage);
+    WidgetsBookCtrl *subBook = wxStaticCast(page, WidgetsBookCtrl);
+    if (!subBook) return NULL;
+    page = subBook->GetCurrentPage();
+    if(!page) return NULL;
+    return wxStaticCast(page, WidgetsPage);
 #endif
 }
 
@@ -603,8 +609,29 @@ void WidgetsFrame::OnButtonClearLog(wxCommandEvent& WXUNUSED(event))
 
 void WidgetsFrame::OnPageChanged(WidgetsBookCtrlEvent& event)
 {
+    // adjust "Page" menu selection
     wxMenuItem *item = GetMenuBar()->FindItem(Widgets_GoToPage + event.GetSelection());
     if (item) item->Check();
+
+    // lazy creation of the pages
+    WidgetsPage* page = CurrentPage();
+    if (page && (page->GetChildren().GetCount()==0))
+    {
+        wxWindowUpdateLocker noUpdates(page);
+        page->CreateContent();
+        WidgetsBookCtrl *book = wxStaticCast(page->GetParent(), WidgetsBookCtrl);
+        wxSize size;
+        for ( size_t i = 0; i < book->GetPageCount(); ++i )
+        {
+            wxWindow *page = book->GetPage(i);
+            if (page)
+            {
+                size.IncTo(page->GetSize());
+            }
+        }
+        page->SetSize(size);
+    }
+
     event.Skip();
 }