include/ax/ax_pagerctrl.h

Go to the documentation of this file.
00001 
00002 // Name:        ax_pagerctrl.h
00003 // Purpose:     AxPagerCtrl: a book with no controller
00004 // Author:      Julian Smart
00005 // Modified by:
00006 // Created:     2008-05-29
00007 // RCS-ID:      $Id$
00008 // Copyright:   (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
00009 //              (c) 2008 Julian Smart
00010 // Licence:     New BSD License
00012 
00013 #ifndef _AX_PAGERCTRL_H_
00014 #define _AX_PAGERCTRL_H_
00015 
00016 // ----------------------------------------------------------------------------
00017 // headers
00018 // ----------------------------------------------------------------------------
00019 
00020 #include "wx/defs.h"
00021 #include "wx/control.h"
00022 #include "wx/dynarray.h"
00023 #include "wx/notebook.h"
00024 
00033 class AxPagerCtrl: public wxControl
00034 {
00035 public:
00036     // construction
00037     // ------------
00038 
00039     AxPagerCtrl()
00040     {
00041         Init();
00042     }
00043 
00044     AxPagerCtrl(wxWindow *parent,
00045                    wxWindowID winid,
00046                    const wxPoint& pos = wxDefaultPosition,
00047                    const wxSize& size = wxDefaultSize,
00048                    long style = 0,
00049                    const wxString& name = wxEmptyString)
00050     {
00051         Init();
00052 
00053         (void) Create(parent, winid, pos, size, style, name);
00054     }
00055 
00056     // quasi ctor
00057     bool Create(wxWindow *parent,
00058                 wxWindowID winid,
00059                 const wxPoint& pos = wxDefaultPosition,
00060                 const wxSize& size = wxDefaultSize,
00061                 long style = 0,
00062                 const wxString& name = wxEmptyString);
00063 
00064     // dtor
00065     virtual ~AxPagerCtrl();
00066 
00067 
00068     // accessors
00069     // ---------
00070 
00071     // get number of pages in the dialog
00072     virtual size_t GetPageCount() const { return m_pages.size(); }
00073 
00074     // get the panel which represents the given page
00075     wxWindow *GetPage(size_t n) { return m_pages[n]; }
00076     wxWindow *GetPage(size_t n) const { return m_pages[n]; }
00077 
00078     // get the current page or NULL if none
00079     wxWindow *GetCurrentPage() const
00080     {
00081         const int n = GetSelection();
00082         return n == wxNOT_FOUND ? NULL : GetPage(n);
00083     }
00084 
00085     // Find the index for the given page (JACS)
00086     virtual int FindPage(wxWindow* window) const;
00087 
00088     // Find the index for the given page label (JACS)
00089     virtual int FindPage(const wxString& label) const;
00090 
00091     // Find the window for the given page label (JACS)
00092     virtual wxWindow* FindPageWindow(const wxString& label) const;
00093 
00094     // get the currently selected page or wxNOT_FOUND if none
00095     virtual int GetSelection() const;
00096 
00097     // set/get the title of a page
00098     virtual bool SetPageText(size_t n, const wxString& strText);
00099     virtual wxString GetPageText(size_t n);
00100 
00101     // geometry
00102     // --------
00103 
00104     // resize the notebook so that all pages will have the specified size
00105     virtual void SetPageSize(const wxSize& size);
00106 
00107     // calculate the size of the control from the size of its page
00108     virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const;
00109 
00110     // get/set size of area between book control area and page area
00111     unsigned int GetInternalBorder() const { return m_internalBorder; }
00112     void SetInternalBorder(unsigned int border) { m_internalBorder = border; }
00113 
00114     // Sets/gets the margin around the controller
00115     void SetControlMargin(int margin) { m_controlMargin = margin; }
00116     int GetControlMargin() const { return m_controlMargin; }
00117 
00118     // returns true if we have wxBK_TOP or wxBK_BOTTOM style
00119     bool IsVertical() const { return HasFlag(wxBK_BOTTOM | wxBK_TOP); }
00120 
00121     // set/get option to shrink to fit current page
00122     void SetFitToCurrentPage(bool fit) { m_fitToCurrentPage = fit; }
00123     bool GetFitToCurrentPage() const { return m_fitToCurrentPage; }
00124 
00125     // returns the sizer containing the control, if any
00126     wxSizer* GetControlSizer() const { return m_controlSizer; }
00127 
00128     // Sets/gets the top rule to be used if GetDrawTopRule is true.
00129     void SetTopRuleSize(int border) { m_topRuleSize = border; }
00130     int GetTopRuleSize() const { return m_topRuleSize; }
00131 
00132     // Sets/gets whether drawing a top rule
00133     void SetDrawTopRule(bool draw) { m_drawTopRule = draw; }
00134     bool GetDrawTopRule() const { return m_drawTopRule; }
00135 
00136     // operations
00137     // ----------
00138 
00139     // remove one page from the control and delete it
00140     virtual bool DeletePage(size_t n);
00141 
00142     // remove one page from the notebook, without deleting it
00143     virtual bool RemovePage(size_t n)
00144     {
00145         DoInvalidateBestSize();
00146         return DoRemovePage(n) != NULL;
00147     }
00148 
00149     // remove all pages and delete them
00150     virtual bool DeleteAllPages()
00151     {
00152         DoInvalidateBestSize();
00153         WX_CLEAR_ARRAY(m_pages);
00154         return true;
00155     }
00156 
00157     // adds a new page to the control
00158     virtual bool AddPage(wxWindow *page,
00159                          const wxString& text,
00160                          bool bSelect = false,
00161                          int imageId = -1)
00162     {
00163         DoInvalidateBestSize();
00164         return InsertPage(GetPageCount(), page, text, bSelect, imageId);
00165     }
00166 
00167     // the same as AddPage(), but adds the page at the specified position
00168     virtual bool InsertPage(size_t n,
00169                             wxWindow *page,
00170                             const wxString& text,
00171                             bool bSelect = false,
00172                             int imageId = -1);
00173 
00174     // set the currently selected page, return the index of the previously
00175     // selected one (or -1 on error)
00176     //
00177     // NB: this function will generate PAGE_CHANGING/ED events
00178     virtual int SetSelection(size_t n) { return DoSetSelection(n, SetSelection_SendEvent); }
00179 
00180     // acts as SetSelection but does not generate events
00181     virtual int ChangeSelection(size_t n) { return DoSetSelection(n); }
00182 
00183     // cycle thru the pages
00184     void AdvanceSelection(bool forward = true)
00185     {
00186         int nPage = GetNextPage(forward);
00187         if ( nPage != -1 )
00188         {
00189             // cast is safe because of the check above
00190             SetSelection((size_t)nPage);
00191         }
00192     }
00193 
00194     // hit test: returns which page is hit and, optionally, where (icon, label)
00195     virtual int HitTest(const wxPoint& WXUNUSED(pt),
00196                         long * WXUNUSED(flags) = NULL) const
00197     {
00198         return wxNOT_FOUND;
00199     }
00200 
00201 
00202     // we do have multiple pages
00203     virtual bool HasMultiplePages() const { return true; }
00204 
00205 
00206     // set the selection to the given page, sending the events (which can
00207     // possibly prevent the page change from taking place) if SendEvent flag is
00208     // included
00209     virtual int DoSetSelection(size_t nPage, int flags = 0);
00210 
00211     // if the derived class uses DoSetSelection() for implementing
00212     // [Set|Change]Selection, it must override UpdateSelectedPage(),
00213     // CreatePageChangingEvent() and MakeChangedEvent(), but as it might not
00214     // use it, these functions are not pure virtual
00215 
00216     // called to notify the control about a new current page
00217     virtual void UpdateSelectedPage(size_t newsel);
00218 
00219     // create a new "page changing" event
00220     virtual wxBookCtrlBaseEvent* CreatePageChangingEvent() const;
00221 
00222     // modify the event created by CreatePageChangingEvent() to "page changed"
00223     // event, usually by just calling SetEventType() on it
00224     virtual void MakeChangedEvent(wxBookCtrlBaseEvent& event);
00225 
00226     // Should we accept NULL page pointers in Add/InsertPage()?
00227     //
00228     // Default is no but derived classes may override it if they can treat NULL
00229     // pages in some sensible way (e.g. wxTreebook overrides this to allow
00230     // having nodes without any associated page)
00231     virtual bool AllowNullPage() const { return false; }
00232 
00233     // remove the page and return a pointer to it
00234     virtual wxWindow *DoRemovePage(size_t page);
00235 
00236     // our best size is the size which fits all our pages
00237     virtual wxSize DoGetBestSize() const;
00238 
00239     // helper: get the next page wrapping if we reached the end
00240     int GetNextPage(bool forward) const;
00241 
00242     // Lay out controls
00243     void DoSize();
00244 
00245     // This method also invalidates the size of the controller and should be
00246     // called instead of just InvalidateBestSize() whenever pages are added or
00247     // removed as this also affects the controller
00248     void DoInvalidateBestSize();
00249 
00250 #if wxUSE_HELP
00251     // Show the help for the corresponding page
00252     void OnHelp(wxHelpEvent& event);
00253 #endif // wxUSE_HELP
00254 
00255 protected:
00256     // flags for DoSetSelection()
00257     enum
00258     {
00259         SetSelection_SendEvent = 1
00260     };
00261 
00262     // the array of all pages of this control
00263     wxArrayPages m_pages;
00264 
00265     // the associated image list or NULL
00266     wxImageList *m_imageList;
00267 
00268     // true if we must delete m_imageList
00269     bool m_ownsImageList;
00270 
00271     // get the page area
00272     wxRect GetPageRect() const;
00273 
00274     // event handlers
00275     void OnSize(wxSizeEvent& event);
00276 
00277     void OnPaint(wxPaintEvent& event);
00278     void OnEraseBackground(wxEraseEvent& event);
00279 
00280     // Whether to shrink to fit current page
00281     bool m_fitToCurrentPage;
00282 
00283     // the sizer containing the choice control
00284     wxSizer *m_controlSizer;
00285 
00286     // the margin around the choice control
00287     int m_controlMargin;
00288 
00289     // the top border size if drawing a top border
00290     int m_topRuleSize;
00291 
00292     bool m_drawTopRule;
00293 
00294 private:
00295 
00296     // common part of all ctors
00297     void Init();
00298 
00299     // internal border
00300     unsigned int m_internalBorder;
00301 
00302     // the currently selected page or wxNOT_FOUND if none
00303     int m_selection;
00304 
00305     // the page text labels
00306     wxArrayString m_pageLabels;
00307 
00308     DECLARE_ABSTRACT_CLASS(AxPagerCtrl)
00309     DECLARE_NO_COPY_CLASS(AxPagerCtrl)
00310     DECLARE_EVENT_TABLE()
00311 };
00312 
00313 #endif
00314   // _AX_PAGERCTRL_H_

Generated on Wed May 6 19:20:18 2009 for AxTk by  doxygen 1.5.1