]> git.saurik.com Git - wxWidgets.git/blob - include/wx/bookctrl.h
Added MSWPositionForWxMenu() method which is used to translate wxWindows
[wxWidgets.git] / include / wx / bookctrl.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/bookctrl.h
3 // Purpose: wxBookCtrl: common base class for wxList/Tree/Notebook
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 19.08.03
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_BOOKCTRL_H_
13 #define _WX_BOOKCTRL_H_
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "bookctrl.h"
17 #endif
18
19 // ----------------------------------------------------------------------------
20 // headers
21 // ----------------------------------------------------------------------------
22
23 #include "wx/defs.h"
24
25 #if wxUSE_BOOKCTRL
26
27 #include "wx/control.h"
28 #include "wx/dynarray.h"
29
30 WX_DEFINE_EXPORTED_ARRAY_PTR(wxWindow *, wxArrayPages);
31
32 class WXDLLEXPORT wxImageList;
33
34 // ----------------------------------------------------------------------------
35 // wxBookCtrl
36 // ----------------------------------------------------------------------------
37
38 class WXDLLEXPORT wxBookCtrl : public wxControl
39 {
40 public:
41 // construction
42 // ------------
43
44 wxBookCtrl();
45
46 wxBookCtrl(wxWindow *parent,
47 wxWindowID winid,
48 const wxPoint& pos = wxDefaultPosition,
49 const wxSize& size = wxDefaultSize,
50 long style = 0,
51 const wxString& name = wxEmptyString);
52
53 // quasi ctor
54 bool Create(wxWindow *parent,
55 wxWindowID winid,
56 const wxPoint& pos = wxDefaultPosition,
57 const wxSize& size = wxDefaultSize,
58 long style = 0,
59 const wxString& name = wxEmptyString);
60
61 // dtor
62 virtual ~wxBookCtrl();
63
64
65 // accessors
66 // ---------
67
68 // get number of pages in the dialog
69 virtual size_t GetPageCount() const { return m_pages.size(); }
70
71 // get the panel which represents the given page
72 virtual wxWindow *GetPage(size_t n) { return m_pages[n]; }
73
74 // get the currently selected page or wxNOT_FOUND if none
75 virtual int GetSelection() const = 0;
76
77 // set/get the title of a page
78 virtual bool SetPageText(size_t n, const wxString& strText) = 0;
79 virtual wxString GetPageText(size_t n) const = 0;
80
81
82 // image list stuff: each page may have an image associated with it (all
83 // images belong to the same image list)
84 // ---------------------------------------------------------------------
85
86 // sets the image list to use, it is *not* deleted by the control
87 virtual void SetImageList(wxImageList *imageList);
88
89 // as SetImageList() but we will delete the image list ourselves
90 void AssignImageList(wxImageList *imageList);
91
92 // get pointer (may be NULL) to the associated image list
93 wxImageList* GetImageList() const { return m_imageList; }
94
95 // sets/returns item's image index in the current image list
96 virtual int GetPageImage(size_t n) const = 0;
97 virtual bool SetPageImage(size_t n, int imageId) = 0;
98
99
100 // geometry
101 // --------
102
103 // resize the notebook so that all pages will have the specified size
104 virtual void SetPageSize(const wxSize& size);
105
106 // calculate the size of the control from the size of its page
107 virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const = 0;
108
109
110 // operations
111 // ----------
112
113 // remove one page from the control and delete it
114 virtual bool DeletePage(size_t n);
115
116 // remove one page from the notebook, without deleting it
117 virtual bool RemovePage(size_t n) { return DoRemovePage(n) != NULL; }
118
119 // remove all pages and delete them
120 virtual bool DeleteAllPages() { WX_CLEAR_ARRAY(m_pages); return true; }
121
122 // adds a new page to the control
123 virtual bool AddPage(wxWindow *page,
124 const wxString& text,
125 bool bSelect = false,
126 int imageId = -1)
127 {
128 return InsertPage(GetPageCount(), page, text, bSelect, imageId);
129 }
130
131 // the same as AddPage(), but adds the page at the specified position
132 virtual bool InsertPage(size_t n,
133 wxWindow *page,
134 const wxString& text,
135 bool bSelect = false,
136 int imageId = -1) = 0;
137
138 // set the currently selected page, return the index of the previously
139 // selected one (or -1 on error)
140 //
141 // NB: this function will _not_ generate PAGE_CHANGING/ED events
142 virtual int SetSelection(size_t n) = 0;
143
144
145 // cycle thru the pages
146 void AdvanceSelection(bool forward = true)
147 {
148 int nPage = GetNextPage(forward);
149 if ( nPage != -1 )
150 {
151 // cast is safe because of the check above
152 SetSelection((size_t)nPage);
153 }
154 }
155
156 protected:
157 // remove the page and return a pointer to it
158 virtual wxWindow *DoRemovePage(size_t page) = 0;
159
160 // our best size is the size which fits all our pages
161 virtual wxSize DoGetBestSize() const;
162
163 // helper: get the next page wrapping if we reached the end
164 int GetNextPage(bool forward) const;
165
166 // common part of all ctors
167 void Init();
168
169
170 // the array of all pages of this control
171 wxArrayPages m_pages;
172
173 // the associated image list or NULL
174 wxImageList *m_imageList;
175
176 // true if we must delete m_imageList
177 bool m_ownsImageList;
178
179
180 DECLARE_NO_COPY_CLASS(wxBookCtrl)
181 };
182
183 // ----------------------------------------------------------------------------
184 // wxBookCtrlEvent: page changing events generated by derived classes
185 // ----------------------------------------------------------------------------
186
187 class WXDLLEXPORT wxBookCtrlEvent : public wxNotifyEvent
188 {
189 public:
190 wxBookCtrlEvent(wxEventType commandType = wxEVT_NULL, int winid = 0,
191 int nSel = -1, int nOldSel = -1)
192 : wxNotifyEvent(commandType, winid)
193 {
194 m_nSel = nSel;
195 m_nOldSel = nOldSel;
196 }
197
198 // accessors
199 // the currently selected page (-1 if none)
200 int GetSelection() const { return m_nSel; }
201 void SetSelection(int nSel) { m_nSel = nSel; }
202 // the page that was selected before the change (-1 if none)
203 int GetOldSelection() const { return m_nOldSel; }
204 void SetOldSelection(int nOldSel) { m_nOldSel = nOldSel; }
205
206 private:
207 int m_nSel, // currently selected page
208 m_nOldSel; // previously selected page
209 };
210
211 #endif // wxUSE_BOOKCTRL
212
213 #endif // _WX_BOOKCTRL_H_