1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBookCtrl: common base class for wxList/Tree/Notebook
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.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
)
127 InvalidateBestSize();
128 return DoRemovePage(n
) != NULL
;
131 // remove all pages and delete them
132 virtual bool DeleteAllPages()
134 InvalidateBestSize();
135 WX_CLEAR_ARRAY(m_pages
);
139 // adds a new page to the control
140 virtual bool AddPage(wxWindow
*page
,
141 const wxString
& text
,
142 bool bSelect
= false,
145 InvalidateBestSize();
146 return InsertPage(GetPageCount(), page
, text
, bSelect
, imageId
);
149 // the same as AddPage(), but adds the page at the specified position
150 virtual bool InsertPage(size_t n
,
152 const wxString
& text
,
153 bool bSelect
= false,
154 int imageId
= -1) = 0;
156 // set the currently selected page, return the index of the previously
157 // selected one (or -1 on error)
159 // NB: this function will _not_ generate PAGE_CHANGING/ED events
160 virtual int SetSelection(size_t n
) = 0;
163 // cycle thru the pages
164 void AdvanceSelection(bool forward
= true)
166 int nPage
= GetNextPage(forward
);
169 // cast is safe because of the check above
170 SetSelection((size_t)nPage
);
174 virtual void ApplyParentThemeBackground(const wxColour
& bg
)
175 { SetBackgroundColour(bg
); }
178 // remove the page and return a pointer to it
179 virtual wxWindow
*DoRemovePage(size_t page
) = 0;
181 // our best size is the size which fits all our pages
182 virtual wxSize
DoGetBestSize() const;
184 // helper: get the next page wrapping if we reached the end
185 int GetNextPage(bool forward
) const;
187 // common part of all ctors
190 // Always rely on GetBestSize, which will look at all the pages
191 virtual void SetInitialBestSize(const wxSize
& WXUNUSED(size
)) { }
193 // the array of all pages of this control
194 wxArrayPages m_pages
;
196 // the associated image list or NULL
197 wxImageList
*m_imageList
;
199 // true if we must delete m_imageList
200 bool m_ownsImageList
;
203 DECLARE_NO_COPY_CLASS(wxBookCtrl
)
206 // ----------------------------------------------------------------------------
207 // wxBookCtrlEvent: page changing events generated by derived classes
208 // ----------------------------------------------------------------------------
210 class WXDLLEXPORT wxBookCtrlEvent
: public wxNotifyEvent
213 wxBookCtrlEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0,
214 int nSel
= -1, int nOldSel
= -1)
215 : wxNotifyEvent(commandType
, winid
)
222 // the currently selected page (-1 if none)
223 int GetSelection() const { return m_nSel
; }
224 void SetSelection(int nSel
) { m_nSel
= nSel
; }
225 // the page that was selected before the change (-1 if none)
226 int GetOldSelection() const { return m_nOldSel
; }
227 void SetOldSelection(int nOldSel
) { m_nOldSel
= nOldSel
; }
230 int m_nSel
, // currently selected page
231 m_nOldSel
; // previously selected page
234 #endif // wxUSE_BOOKCTRL
236 #endif // _WX_BOOKCTRL_H_