]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/bookctrl.h
Unrevert Cygwin changes after discussion. Cygwin will be unix with the new
[wxWidgets.git] / include / wx / bookctrl.h
index 51761208cb28f60c73e98023040c5e6106efd110..82f956d58e49106283073f5e049091a8f63f2a09 100644 (file)
@@ -1,11 +1,11 @@
 ///////////////////////////////////////////////////////////////////////////////
 // Name:        wx/bookctrl.h
-// Purpose:     wxBookCtrl: common base class for wxList/Tree/Notebook
+// Purpose:     wxBookCtrlBase: common base class for wxList/Tree/Notebook
 // Author:      Vadim Zeitlin
 // Modified by:
 // Created:     19.08.03
 // RCS-ID:      $Id$
-// Copyright:   (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
+// Copyright:   (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
 // Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 
@@ -32,23 +32,31 @@ WX_DEFINE_EXPORTED_ARRAY_PTR(wxWindow *, wxArrayPages);
 class WXDLLEXPORT wxImageList;
 
 // ----------------------------------------------------------------------------
-// wxBookCtrl
+// wxBookCtrlBase
 // ----------------------------------------------------------------------------
 
-class WXDLLEXPORT wxBookCtrl : public wxControl
+class WXDLLEXPORT wxBookCtrlBase : public wxControl
 {
 public:
     // construction
     // ------------
 
-    wxBookCtrl();
+    wxBookCtrlBase()
+    {
+        Init();
+    }
 
-    wxBookCtrl(wxWindow *parent,
-               wxWindowID winid,
-               const wxPoint& pos = wxDefaultPosition,
-               const wxSize& size = wxDefaultSize,
-               long style = 0,
-               const wxString& name = wxEmptyString);
+    wxBookCtrlBase(wxWindow *parent,
+                   wxWindowID winid,
+                   const wxPoint& pos = wxDefaultPosition,
+                   const wxSize& size = wxDefaultSize,
+                   long style = 0,
+                   const wxString& name = wxEmptyString)
+    {
+        Init();
+
+        (void)Create(parent, winid, pos, size, style, name);
+    }
 
     // quasi ctor
     bool Create(wxWindow *parent,
@@ -59,7 +67,7 @@ public:
                 const wxString& name = wxEmptyString);
 
     // dtor
-    virtual ~wxBookCtrl();
+    virtual ~wxBookCtrlBase();
 
 
     // accessors
@@ -71,6 +79,14 @@ public:
     // get the panel which represents the given page
     virtual wxWindow *GetPage(size_t n) { return m_pages[n]; }
 
+    // get the current page or NULL if none
+    wxWindow *GetCurrentPage() const
+    {
+        int n = GetSelection();
+        return n == wxNOT_FOUND ? NULL
+                                : wx_const_cast(wxBookCtrlBase *, this)->GetPage(n);
+    }
+
     // get the currently selected page or wxNOT_FOUND if none
     virtual int GetSelection() const = 0;
 
@@ -114,10 +130,19 @@ public:
     virtual bool DeletePage(size_t n);
 
     // remove one page from the notebook, without deleting it
-    virtual bool RemovePage(size_t n) { return DoRemovePage(n) != NULL; }
+    virtual bool RemovePage(size_t n)
+    {
+        InvalidateBestSize();
+        return DoRemovePage(n) != NULL;
+    }
 
     // remove all pages and delete them
-    virtual bool DeleteAllPages() { WX_CLEAR_ARRAY(m_pages); return true; }
+    virtual bool DeleteAllPages()
+    {
+        InvalidateBestSize();
+        WX_CLEAR_ARRAY(m_pages);
+        return true;
+    }
 
     // adds a new page to the control
     virtual bool AddPage(wxWindow *page,
@@ -125,6 +150,7 @@ public:
                          bool bSelect = false,
                          int imageId = -1)
     {
+        InvalidateBestSize();
         return InsertPage(GetPageCount(), page, text, bSelect, imageId);
     }
 
@@ -138,7 +164,7 @@ public:
     // set the currently selected page, return the index of the previously
     // selected one (or -1 on error)
     //
-    // NB: this function will _not_ generate PAGE_CHANGING/ED events
+    // NB: this function will generate PAGE_CHANGING/ED events
     virtual int SetSelection(size_t n) = 0;
 
 
@@ -166,6 +192,8 @@ protected:
     // common part of all ctors
     void Init();
 
+    // Always rely on GetBestSize, which will look at all the pages
+    virtual void SetInitialBestSize(const wxSize& WXUNUSED(size)) { }
 
     // the array of all pages of this control
     wxArrayPages m_pages;
@@ -177,18 +205,18 @@ protected:
     bool m_ownsImageList;
 
 
-    DECLARE_NO_COPY_CLASS(wxBookCtrl)
+    DECLARE_NO_COPY_CLASS(wxBookCtrlBase)
 };
 
 // ----------------------------------------------------------------------------
-// wxBookCtrlEvent: page changing events generated by derived classes
+// wxBookCtrlBaseEvent: page changing events generated by derived classes
 // ----------------------------------------------------------------------------
 
-class WXDLLEXPORT wxBookCtrlEvent : public wxNotifyEvent
+class WXDLLEXPORT wxBookCtrlBaseEvent : public wxNotifyEvent
 {
 public:
-    wxBookCtrlEvent(wxEventType commandType = wxEVT_NULL, int winid = 0,
-                    int nSel = -1, int nOldSel = -1)
+    wxBookCtrlBaseEvent(wxEventType commandType = wxEVT_NULL, int winid = 0,
+                        int nSel = -1, int nOldSel = -1)
         : wxNotifyEvent(commandType, winid)
         {
             m_nSel = nSel;
@@ -208,6 +236,37 @@ private:
         m_nOldSel;  // previously selected page
 };
 
+// make a default book control for given platform
+#if wxUSE_NOTEBOOK
+    // dedicated to majority of desktops
+    #include "wx/notebook.h"
+    #define wxBookCtrl                             wxNotebook
+    #define wxBookCtrlEvent                        wxNotebookEvent
+    #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED    wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
+    #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING   wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
+    #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn)      EVT_NOTEBOOK_PAGE_CHANGED(id, fn)
+    #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn)     EVT_NOTEBOOK_PAGE_CHANGING(id, fn)
+    #define wxBC_TOP                               wxNB_TOP
+    #define wxBC_BOTTOM                            wxNB_BOTTOM
+    #define wxBC_LEFT                              wxNB_LEFT
+    #define wxBC_RIGHT                             wxNB_RIGHT
+    #define wxBC_DEFAULT                           wxNB_DEFAULT
+#else
+    // dedicated to Smartphones
+    #include "wx/choicebk.h"
+    #define wxBookCtrl                             wxChoicebook
+    #define wxBookCtrlEvent                        wxChoicebookEvent
+    #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED    wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED
+    #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING   wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING
+    #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn)      EVT_CHOICEBOOK_PAGE_CHANGED(id, fn)
+    #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn)     EVT_CHOICEBOOK_PAGE_CHANGING(id, fn)
+    #define wxBC_TOP                               wxCHB_TOP
+    #define wxBC_BOTTOM                            wxCHB_BOTTOM
+    #define wxBC_LEFT                              wxCHB_LEFT
+    #define wxBC_RIGHT                             wxCHB_RIGHT
+    #define wxBC_DEFAULT                           wxCHB_DEFAULT
+#endif
+
 #endif // wxUSE_BOOKCTRL
 
 #endif // _WX_BOOKCTRL_H_