]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/bookctrl.h
Don't send SELECTED events for an already selected item in wxGTK wxListBox.
[wxWidgets.git] / include / wx / bookctrl.h
index fbb493ebe5aa9fe6112819853bac4c98cbf35ad0..c7c7c27f9c81a71e35f298b05d566eaf7da92228 100644 (file)
@@ -106,7 +106,7 @@ public:
     }
 
     // get the currently selected page or wxNOT_FOUND if none
-    virtual int GetSelection() const = 0;
+    int GetSelection() const { return m_selection; }
 
     // set/get the title of a page
     virtual bool SetPageText(size_t n, const wxString& strText) = 0;
@@ -141,7 +141,10 @@ public:
     wxSize GetControllerSize() const;
 
     // calculate the size of the control from the size of its page
-    virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const = 0;
+    //
+    // by default this simply returns size enough to fit both the page and the
+    // controller
+    virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const;
 
     // get/set size of area between book control area and page area
     unsigned int GetInternalBorder() const { return m_internalBorder; }
@@ -178,6 +181,7 @@ public:
     // remove all pages and delete them
     virtual bool DeleteAllPages()
     {
+        m_selection = wxNOT_FOUND;
         DoInvalidateBestSize();
         WX_CLEAR_ARRAY(m_pages);
         return true;
@@ -201,7 +205,7 @@ public:
                             int imageId = -1) = 0;
 
     // set the currently selected page, return the index of the previously
-    // selected one (or -1 on error)
+    // selected one (or wxNOT_FOUND on error)
     //
     // NB: this function will generate PAGE_CHANGING/ED events
     virtual int SetSelection(size_t n) = 0;
@@ -214,7 +218,7 @@ public:
     void AdvanceSelection(bool forward = true)
     {
         int nPage = GetNextPage(forward);
-        if ( nPage != -1 )
+        if ( nPage != wxNOT_FOUND )
         {
             // cast is safe because of the check above
             SetSelection((size_t)nPage);
@@ -329,6 +333,11 @@ protected:
     // the margin around the choice control
     int m_controlMargin;
 
+    // The currently selected page (in range 0..m_pages.size()-1 inclusive) or
+    // wxNOT_FOUND if none (this can normally only be the case for an empty
+    // control without any pages).
+    int m_selection;
+
 private:
 
     // common part of all ctors
@@ -339,6 +348,7 @@ private:
 
     DECLARE_ABSTRACT_CLASS(wxBookCtrlBase)
     wxDECLARE_NO_COPY_CLASS(wxBookCtrlBase);
+
     DECLARE_EVENT_TABLE()
 };
 
@@ -350,7 +360,7 @@ class WXDLLIMPEXP_CORE wxBookCtrlEvent : public wxNotifyEvent
 {
 public:
     wxBookCtrlEvent(wxEventType commandType = wxEVT_NULL, int winid = 0,
-                        int nSel = -1, int nOldSel = -1)
+                        int nSel = wxNOT_FOUND, int nOldSel = wxNOT_FOUND)
         : wxNotifyEvent(commandType, winid)
     {
         m_nSel = nSel;
@@ -367,10 +377,10 @@ public:
     virtual wxEvent *Clone() const { return new wxBookCtrlEvent(*this); }
 
     // accessors
-        // the currently selected page (-1 if none)
+        // the currently selected page (wxNOT_FOUND if none)
     int GetSelection() const { return m_nSel; }
     void SetSelection(int nSel) { m_nSel = nSel; }
-        // the page that was selected before the change (-1 if none)
+        // the page that was selected before the change (wxNOT_FOUND if none)
     int GetOldSelection() const { return m_nOldSel; }
     void SetOldSelection(int nOldSel) { m_nOldSel = nOldSel; }