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