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