don't use DECLARE_EVENT_TYPE() to avoid confusing people about its unused value param...
[wxWidgets.git] / include / wx / generic / laywin.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: laywin.h
3 // Purpose: Implements a simple layout algorithm, plus
4 // wxSashLayoutWindow which is an example of a window with
5 // layout-awareness (via event handlers). This is suited to
6 // IDE-style window layout.
7 // Author: Julian Smart
8 // Modified by:
9 // Created: 04/01/98
10 // RCS-ID: $Id$
11 // Copyright: (c) Julian Smart
12 // Licence: wxWindows licence
13 /////////////////////////////////////////////////////////////////////////////
14
15 #ifndef _WX_LAYWIN_H_G_
16 #define _WX_LAYWIN_H_G_
17
18 #if wxUSE_SASH
19 #include "wx/sashwin.h"
20 #endif // wxUSE_SASH
21
22 #include "wx/event.h"
23
24 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_QUERY_LAYOUT_INFO;
25 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_CALCULATE_LAYOUT;
26
27 enum wxLayoutOrientation
28 {
29 wxLAYOUT_HORIZONTAL,
30 wxLAYOUT_VERTICAL
31 };
32
33 enum wxLayoutAlignment
34 {
35 wxLAYOUT_NONE,
36 wxLAYOUT_TOP,
37 wxLAYOUT_LEFT,
38 wxLAYOUT_RIGHT,
39 wxLAYOUT_BOTTOM
40 };
41
42 // Not sure this is necessary
43 // Tell window which dimension we're sizing on
44 #define wxLAYOUT_LENGTH_Y 0x0008
45 #define wxLAYOUT_LENGTH_X 0x0000
46
47 // Use most recently used length
48 #define wxLAYOUT_MRU_LENGTH 0x0010
49
50 // Only a query, so don't actually move it.
51 #define wxLAYOUT_QUERY 0x0100
52
53 /*
54 * This event is used to get information about window alignment,
55 * orientation and size.
56 */
57
58 class WXDLLIMPEXP_ADV wxQueryLayoutInfoEvent: public wxEvent
59 {
60 public:
61 wxQueryLayoutInfoEvent(wxWindowID id = 0)
62 {
63 SetEventType(wxEVT_QUERY_LAYOUT_INFO);
64 m_requestedLength = 0;
65 m_flags = 0;
66 m_id = id;
67 m_alignment = wxLAYOUT_TOP;
68 m_orientation = wxLAYOUT_HORIZONTAL;
69 }
70
71 // Read by the app
72 void SetRequestedLength(int length) { m_requestedLength = length; }
73 int GetRequestedLength() const { return m_requestedLength; }
74
75 void SetFlags(int flags) { m_flags = flags; }
76 int GetFlags() const { return m_flags; }
77
78 // Set by the app
79 void SetSize(const wxSize& size) { m_size = size; }
80 wxSize GetSize() const { return m_size; }
81
82 void SetOrientation(wxLayoutOrientation orient) { m_orientation = orient; }
83 wxLayoutOrientation GetOrientation() const { return m_orientation; }
84
85 void SetAlignment(wxLayoutAlignment align) { m_alignment = align; }
86 wxLayoutAlignment GetAlignment() const { return m_alignment; }
87
88 virtual wxEvent *Clone() const { return new wxQueryLayoutInfoEvent(*this); }
89
90 protected:
91 int m_flags;
92 int m_requestedLength;
93 wxSize m_size;
94 wxLayoutOrientation m_orientation;
95 wxLayoutAlignment m_alignment;
96
97 private:
98 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxQueryLayoutInfoEvent)
99 };
100
101 typedef void (wxEvtHandler::*wxQueryLayoutInfoEventFunction)(wxQueryLayoutInfoEvent&);
102
103 #define EVT_QUERY_LAYOUT_INFO(func) \
104 DECLARE_EVENT_TABLE_ENTRY( wxEVT_QUERY_LAYOUT_INFO, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxQueryLayoutInfoEventFunction, & func ), NULL ),
105
106 /*
107 * This event is used to take a bite out of the available client area.
108 */
109
110 class WXDLLIMPEXP_ADV wxCalculateLayoutEvent: public wxEvent
111 {
112 public:
113 wxCalculateLayoutEvent(wxWindowID id = 0)
114 {
115 SetEventType(wxEVT_CALCULATE_LAYOUT);
116 m_flags = 0;
117 m_id = id;
118 }
119
120 // Read by the app
121 void SetFlags(int flags) { m_flags = flags; }
122 int GetFlags() const { return m_flags; }
123
124 // Set by the app
125 void SetRect(const wxRect& rect) { m_rect = rect; }
126 wxRect GetRect() const { return m_rect; }
127
128 virtual wxEvent *Clone() const { return new wxCalculateLayoutEvent(*this); }
129
130 protected:
131 int m_flags;
132 wxRect m_rect;
133
134 private:
135 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxCalculateLayoutEvent)
136 };
137
138 typedef void (wxEvtHandler::*wxCalculateLayoutEventFunction)(wxCalculateLayoutEvent&);
139
140 #define EVT_CALCULATE_LAYOUT(func) \
141 DECLARE_EVENT_TABLE_ENTRY( wxEVT_CALCULATE_LAYOUT, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxCalculateLayoutEventFunction, & func ), NULL ),
142
143 #if wxUSE_SASH
144
145 // This is window that can remember alignment/orientation, does its own layout,
146 // and can provide sashes too. Useful for implementing docked windows with sashes in
147 // an IDE-style interface.
148 class WXDLLIMPEXP_ADV wxSashLayoutWindow: public wxSashWindow
149 {
150 public:
151 wxSashLayoutWindow()
152 {
153 Init();
154 }
155
156 wxSashLayoutWindow(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
157 const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = wxT("layoutWindow"))
158 {
159 Create(parent, id, pos, size, style, name);
160 }
161
162 bool Create(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
163 const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = wxT("layoutWindow"));
164
165 // Accessors
166 inline wxLayoutAlignment GetAlignment() const { return m_alignment; }
167 inline wxLayoutOrientation GetOrientation() const { return m_orientation; }
168
169 inline void SetAlignment(wxLayoutAlignment align) { m_alignment = align; }
170 inline void SetOrientation(wxLayoutOrientation orient) { m_orientation = orient; }
171
172 // Give the window default dimensions
173 inline void SetDefaultSize(const wxSize& size) { m_defaultSize = size; }
174
175 // Event handlers
176 // Called by layout algorithm to allow window to take a bit out of the
177 // client rectangle, and size itself if not in wxLAYOUT_QUERY mode.
178 void OnCalculateLayout(wxCalculateLayoutEvent& event);
179
180 // Called by layout algorithm to retrieve information about the window.
181 void OnQueryLayoutInfo(wxQueryLayoutInfoEvent& event);
182
183 private:
184 void Init();
185
186 wxLayoutAlignment m_alignment;
187 wxLayoutOrientation m_orientation;
188 wxSize m_defaultSize;
189
190 private:
191 DECLARE_DYNAMIC_CLASS_NO_COPY(wxSashLayoutWindow)
192 DECLARE_EVENT_TABLE()
193 };
194
195 #endif // wxUSE_SASH
196
197 class WXDLLIMPEXP_FWD_CORE wxMDIParentFrame;
198 class WXDLLIMPEXP_FWD_CORE wxFrame;
199
200 // This class implements the layout algorithm
201 class WXDLLIMPEXP_ADV wxLayoutAlgorithm: public wxObject
202 {
203 public:
204 wxLayoutAlgorithm() {}
205
206 #if wxUSE_MDI_ARCHITECTURE
207 // The MDI client window is sized to whatever's left over.
208 bool LayoutMDIFrame(wxMDIParentFrame* frame, wxRect* rect = (wxRect*) NULL);
209 #endif // wxUSE_MDI_ARCHITECTURE
210
211 // mainWindow is sized to whatever's left over. This function for backward
212 // compatibility; use LayoutWindow.
213 bool LayoutFrame(wxFrame* frame, wxWindow* mainWindow = (wxWindow*) NULL);
214
215 // mainWindow is sized to whatever's left over.
216 bool LayoutWindow(wxWindow* frame, wxWindow* mainWindow = (wxWindow*) NULL);
217 };
218
219 #endif
220 // _WX_LAYWIN_H_G_