1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBookCtrl: common base class for wxList/Tree/Notebook
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_BOOKCTRL_H_
13 #define _WX_BOOKCTRL_H_
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "bookctrl.h"
19 // ----------------------------------------------------------------------------
21 // ----------------------------------------------------------------------------
27 #include "wx/control.h"
28 #include "wx/dynarray.h"
30 WX_DEFINE_EXPORTED_ARRAY_PTR(wxWindow
*, wxArrayPages
);
32 class WXDLLEXPORT wxImageList
;
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
38 class WXDLLEXPORT wxBookCtrl
: public wxControl
49 wxBookCtrl(wxWindow
*parent
,
51 const wxPoint
& pos
= wxDefaultPosition
,
52 const wxSize
& size
= wxDefaultSize
,
54 const wxString
& name
= wxEmptyString
)
58 (void)Create(parent
, winid
, pos
, size
, style
, name
);
62 bool Create(wxWindow
*parent
,
64 const wxPoint
& pos
= wxDefaultPosition
,
65 const wxSize
& size
= wxDefaultSize
,
67 const wxString
& name
= wxEmptyString
);
70 virtual ~wxBookCtrl();
76 // get number of pages in the dialog
77 virtual size_t GetPageCount() const { return m_pages
.size(); }
79 // get the panel which represents the given page
80 virtual wxWindow
*GetPage(size_t n
) { return m_pages
[n
]; }
82 // get the currently selected page or wxNOT_FOUND if none
83 virtual int GetSelection() const = 0;
85 // set/get the title of a page
86 virtual bool SetPageText(size_t n
, const wxString
& strText
) = 0;
87 virtual wxString
GetPageText(size_t n
) const = 0;
90 // image list stuff: each page may have an image associated with it (all
91 // images belong to the same image list)
92 // ---------------------------------------------------------------------
94 // sets the image list to use, it is *not* deleted by the control
95 virtual void SetImageList(wxImageList
*imageList
);
97 // as SetImageList() but we will delete the image list ourselves
98 void AssignImageList(wxImageList
*imageList
);
100 // get pointer (may be NULL) to the associated image list
101 wxImageList
* GetImageList() const { return m_imageList
; }
103 // sets/returns item's image index in the current image list
104 virtual int GetPageImage(size_t n
) const = 0;
105 virtual bool SetPageImage(size_t n
, int imageId
) = 0;
111 // resize the notebook so that all pages will have the specified size
112 virtual void SetPageSize(const wxSize
& size
);
114 // calculate the size of the control from the size of its page
115 virtual wxSize
CalcSizeFromPage(const wxSize
& sizePage
) const = 0;
121 // remove one page from the control and delete it
122 virtual bool DeletePage(size_t n
);
124 // remove one page from the notebook, without deleting it
125 virtual bool RemovePage(size_t n
) { return DoRemovePage(n
) != NULL
; }
127 // remove all pages and delete them
128 virtual bool DeleteAllPages() { WX_CLEAR_ARRAY(m_pages
); return true; }
130 // adds a new page to the control
131 virtual bool AddPage(wxWindow
*page
,
132 const wxString
& text
,
133 bool bSelect
= false,
136 return InsertPage(GetPageCount(), page
, text
, bSelect
, imageId
);
139 // the same as AddPage(), but adds the page at the specified position
140 virtual bool InsertPage(size_t n
,
142 const wxString
& text
,
143 bool bSelect
= false,
144 int imageId
= -1) = 0;
146 // set the currently selected page, return the index of the previously
147 // selected one (or -1 on error)
149 // NB: this function will _not_ generate PAGE_CHANGING/ED events
150 virtual int SetSelection(size_t n
) = 0;
153 // cycle thru the pages
154 void AdvanceSelection(bool forward
= true)
156 int nPage
= GetNextPage(forward
);
159 // cast is safe because of the check above
160 SetSelection((size_t)nPage
);
164 virtual void ApplyParentThemeBackground(const wxColour
& bg
)
165 { SetBackgroundColour(bg
); }
168 // remove the page and return a pointer to it
169 virtual wxWindow
*DoRemovePage(size_t page
) = 0;
171 // our best size is the size which fits all our pages
172 virtual wxSize
DoGetBestSize() const;
174 // helper: get the next page wrapping if we reached the end
175 int GetNextPage(bool forward
) const;
177 // common part of all ctors
181 // the array of all pages of this control
182 wxArrayPages m_pages
;
184 // the associated image list or NULL
185 wxImageList
*m_imageList
;
187 // true if we must delete m_imageList
188 bool m_ownsImageList
;
191 DECLARE_NO_COPY_CLASS(wxBookCtrl
)
194 // ----------------------------------------------------------------------------
195 // wxBookCtrlEvent: page changing events generated by derived classes
196 // ----------------------------------------------------------------------------
198 class WXDLLEXPORT wxBookCtrlEvent
: public wxNotifyEvent
201 wxBookCtrlEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0,
202 int nSel
= -1, int nOldSel
= -1)
203 : wxNotifyEvent(commandType
, winid
)
210 // the currently selected page (-1 if none)
211 int GetSelection() const { return m_nSel
; }
212 void SetSelection(int nSel
) { m_nSel
= nSel
; }
213 // the page that was selected before the change (-1 if none)
214 int GetOldSelection() const { return m_nOldSel
; }
215 void SetOldSelection(int nOldSel
) { m_nOldSel
= nOldSel
; }
218 int m_nSel
, // currently selected page
219 m_nOldSel
; // previously selected page
222 #endif // wxUSE_BOOKCTRL
224 #endif // _WX_BOOKCTRL_H_