added wxTBK_HORZ_LAYOUT (heavily modified patch 1855678)
[wxWidgets.git] / include / wx / toolbook.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/toolbook.h
3 // Purpose: wxToolbook: wxToolBar and wxNotebook combination
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2006-01-29
7 // RCS-ID: $Id$
8 // Copyright: (c) 2006 Julian Smart
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_TOOLBOOK_H_
13 #define _WX_TOOLBOOK_H_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_TOOLBOOK
18
19 #include "wx/bookctrl.h"
20
21 class WXDLLIMPEXP_FWD_CORE wxToolBarBase;
22 class WXDLLIMPEXP_FWD_CORE wxCommandEvent;
23
24 extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGED;
25 extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING;
26
27
28 // Use wxButtonToolBar
29 #define wxBK_BUTTONBAR 0x0100
30
31 // Use wxTB_HORZ_LAYOUT style for the controlling toolbar
32 #define wxTBK_HORZ_LAYOUT 0x8000
33
34 // ----------------------------------------------------------------------------
35 // wxToolbook
36 // ----------------------------------------------------------------------------
37
38 class WXDLLEXPORT wxToolbook : public wxBookCtrlBase
39 {
40 public:
41 wxToolbook()
42 {
43 Init();
44 }
45
46 wxToolbook(wxWindow *parent,
47 wxWindowID id,
48 const wxPoint& pos = wxDefaultPosition,
49 const wxSize& size = wxDefaultSize,
50 long style = 0,
51 const wxString& name = wxEmptyString)
52 {
53 Init();
54
55 (void)Create(parent, id, pos, size, style, name);
56 }
57
58 // quasi ctor
59 bool Create(wxWindow *parent,
60 wxWindowID id,
61 const wxPoint& pos = wxDefaultPosition,
62 const wxSize& size = wxDefaultSize,
63 long style = 0,
64 const wxString& name = wxEmptyString);
65
66
67 // implement base class virtuals
68 virtual int GetSelection() const;
69 virtual bool SetPageText(size_t n, const wxString& strText);
70 virtual wxString GetPageText(size_t n) const;
71 virtual int GetPageImage(size_t n) const;
72 virtual bool SetPageImage(size_t n, int imageId);
73 virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const;
74 virtual bool InsertPage(size_t n,
75 wxWindow *page,
76 const wxString& text,
77 bool bSelect = false,
78 int imageId = -1);
79 virtual int SetSelection(size_t n) { return DoSetSelection(n, SetSelection_SendEvent); }
80 virtual int ChangeSelection(size_t n) { return DoSetSelection(n); }
81 virtual void SetImageList(wxImageList *imageList);
82
83 virtual bool DeleteAllPages();
84 virtual int HitTest(const wxPoint& pt, long *flags = NULL) const;
85
86
87 // methods which are not part of base wxBookctrl API
88
89 // get the underlying toolbar
90 wxToolBarBase* GetToolBar() const { return (wxToolBarBase*)m_bookctrl; }
91
92 // must be called in OnIdle or by application to realize the toolbar and
93 // select the initial page.
94 void Realize();
95
96 protected:
97 virtual wxWindow *DoRemovePage(size_t page);
98
99 // get the size which the list control should have
100 virtual wxSize GetControllerSize() const;
101
102 // event handlers
103 void OnToolSelected(wxCommandEvent& event);
104 void OnSize(wxSizeEvent& event);
105 void OnIdle(wxIdleEvent& event);
106
107 void UpdateSelectedPage(size_t newsel);
108
109 wxBookCtrlBaseEvent* CreatePageChangingEvent() const;
110 void MakeChangedEvent(wxBookCtrlBaseEvent &event);
111
112 // the currently selected page or wxNOT_FOUND if none
113 int m_selection;
114
115 // whether the toolbar needs to be realized
116 bool m_needsRealizing;
117
118 // maximum bitmap size
119 wxSize m_maxBitmapSize;
120
121 private:
122 // common part of all constructors
123 void Init();
124
125 DECLARE_EVENT_TABLE()
126 DECLARE_DYNAMIC_CLASS_NO_COPY(wxToolbook)
127 };
128
129 // ----------------------------------------------------------------------------
130 // listbook event class and related stuff
131 // ----------------------------------------------------------------------------
132
133 class WXDLLEXPORT wxToolbookEvent : public wxBookCtrlBaseEvent
134 {
135 public:
136 wxToolbookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
137 int nSel = wxNOT_FOUND, int nOldSel = wxNOT_FOUND)
138 : wxBookCtrlBaseEvent(commandType, id, nSel, nOldSel)
139 {
140 }
141
142 wxToolbookEvent(const wxToolbookEvent& event)
143 : wxBookCtrlBaseEvent(event)
144 {
145 }
146
147 virtual wxEvent *Clone() const { return new wxToolbookEvent(*this); }
148
149 private:
150 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxToolbookEvent)
151 };
152
153 typedef void (wxEvtHandler::*wxToolbookEventFunction)(wxToolbookEvent&);
154
155 #define wxToolbookEventHandler(func) \
156 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxToolbookEventFunction, &func)
157
158 #define EVT_TOOLBOOK_PAGE_CHANGED(winid, fn) \
159 wx__DECLARE_EVT1(wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGED, winid, wxToolbookEventHandler(fn))
160
161 #define EVT_TOOLBOOK_PAGE_CHANGING(winid, fn) \
162 wx__DECLARE_EVT1(wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING, winid, wxToolbookEventHandler(fn))
163
164 #endif // wxUSE_TOOLBOOK
165
166 #endif // _WX_TOOLBOOK_H_