]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/widgets/widgets.cpp
reSWIGged
[wxWidgets.git] / samples / widgets / widgets.cpp
index f432060c34198ea2c80d2c29d1ce94d0445708a1..25d11d88b78c520ca9992691996f51edcdde8426 100644 (file)
@@ -47,6 +47,8 @@
 #include "wx/colordlg.h"
 #include "wx/fontdlg.h"
 #include "wx/textdlg.h"
+#include "wx/imaglist.h"
+#include "wx/wupdlock.h"
 
 #include "widgets.h"
 
@@ -85,7 +87,11 @@ enum
 };
 
 const wxChar *WidgetsCategories[MAX_PAGES] = {
+#if defined(__WXUNIVERSAL__)
+    wxT("Universal"),
+#else
     wxT("Native"),
+#endif
     wxT("Generic"),
     wxT("Pickers"),
     wxT("Comboboxes"),
@@ -320,7 +326,7 @@ bool WidgetsApp::OnInit()
 
 WidgetsFrame::WidgetsFrame(const wxString& title)
             : wxFrame(NULL, wxID_ANY, title,
-                      wxPoint(0, 50), wxDefaultSize,
+                      wxDefaultPosition, wxDefaultSize,
                       wxDEFAULT_FRAME_STYLE |
                       wxNO_FULL_REPAINT_ON_RESIZE |
                       wxCLIP_CHILDREN |
@@ -389,7 +395,7 @@ WidgetsFrame::WidgetsFrame(const wxString& title)
         style);
     InitBook();
 
-#ifndef __SMARTPHONE__
+#ifndef __WXHANDHELD__
     // the lower one only has the log listbox and a button to clear it
 #if USE_LOG
     wxSizer *sizerDown = new wxStaticBoxSizer(
@@ -419,11 +425,11 @@ WidgetsFrame::WidgetsFrame(const wxString& title)
     sizerTop->Add(0, 5, 0, wxGROW); // spacer in between
     sizerTop->Add(sizerDown, 0,  wxGROW | (wxALL & ~wxTOP), 10);
 
-#else // !__SMARTPHONE__/__SMARTPHONE__
+#else // !__WXHANDHELD__/__WXHANDHELD__
 
     sizerTop->Add(m_book, 1, wxGROW | wxALL );
 
-#endif // __SMARTPHONE__
+#endif // __WXHANDHELD__
 
     m_panel->SetSizer(sizerTop);
 
@@ -441,9 +447,13 @@ WidgetsFrame::WidgetsFrame(const wxString& title)
 
 void WidgetsFrame::InitBook()
 {
+#if USE_ICONS_IN_BOOK
     wxImageList *imageList = new wxImageList(32, 32);
 
     imageList->Add(wxBitmap(sample_xpm));
+#else
+    wxImageList *imageList = NULL;
+#endif
 
 #if !USE_TREEBOOK
     WidgetsBookCtrl *books[MAX_PAGES];
@@ -465,7 +475,11 @@ void WidgetsFrame::InitBook()
 #if USE_TREEBOOK
         nPage++; // increase for parent page
 #else
-        books[cat] = new WidgetsBookCtrl( m_book, wxID_ANY );
+        books[cat] = new WidgetsBookCtrl(m_book,
+                                         wxID_ANY,
+                                         wxDefaultPosition,
+                                         wxDefaultSize,
+                                         wxBK_DEFAULT);
 #endif
 
         for ( WidgetsPageInfo *info = WidgetsPage::ms_widgetPages;
@@ -513,7 +527,9 @@ void WidgetsFrame::InitBook()
 
     GetMenuBar()->Append(menuPages, _T("&Page"));
 
+#if USE_ICONS_IN_BOOK
     m_book->AssignImageList(imageList);
+#endif
 
     for ( cat = 0; cat < MAX_PAGES; cat++ )
     {
@@ -521,7 +537,9 @@ void WidgetsFrame::InitBook()
         m_book->AddPage(NULL,WidgetsCategories[cat],false,0);
 #else
         m_book->AddPage(books[cat],WidgetsCategories[cat],false,0);
+#if USE_ICONS_IN_BOOK
         books[cat]->SetImageList(imageList);
+#endif
 #endif
 
         // now do add them
@@ -544,17 +562,23 @@ void WidgetsFrame::InitBook()
 #if USE_TREEBOOK
     // for treebook page #0 is empty parent page only
     m_book->SetSelection(1);
+    m_book->SetSelection(0);
 #endif
 }
 
 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
 }
 
@@ -585,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();
 }
 
@@ -811,13 +856,21 @@ WidgetsPageInfo::WidgetsPageInfo(Constructor ctor, const wxChar *label, int cate
 int WidgetsPage::ms_defaultFlags = wxBORDER_DEFAULT;
 WidgetsPageInfo *WidgetsPage::ms_widgetPages = NULL;
 
-WidgetsPage::WidgetsPage(WidgetsBookCtrl *book)
+WidgetsPage::WidgetsPage(WidgetsBookCtrl *book,
+                         wxImageList *imaglist,
+                         char* icon[])
            : wxPanel(book, wxID_ANY,
                      wxDefaultPosition, wxDefaultSize,
                      wxNO_FULL_REPAINT_ON_RESIZE |
                      wxCLIP_CHILDREN |
                      wxTAB_TRAVERSAL)
 {
+#if USE_ICONS_IN_BOOK
+    imaglist->Add(wxBitmap(icon));
+#else
+    wxUnusedVar(imaglist);
+    wxUnusedVar(icon);
+#endif
 }
 
 wxSizer *WidgetsPage::CreateSizerWithText(wxControl *control,