]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/laywin.h
oops, forgot to implement Home button
[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 #ifdef __GNUG__
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_EVENT_TYPE(wxEVT_QUERY_LAYOUT_INFO, 1500)
28 DECLARE_EVENT_TYPE(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 WXDLLEXPORT wxQueryLayoutInfoEvent: public wxEvent
63 {
64 DECLARE_DYNAMIC_CLASS(wxQueryLayoutInfoEvent)
65 public:
66
67 wxQueryLayoutInfoEvent(wxWindowID id = 0)
68 {
69 SetEventType(wxEVT_QUERY_LAYOUT_INFO);
70 m_requestedLength = 0;
71 m_flags = 0;
72 m_id = id;
73 m_alignment = wxLAYOUT_TOP;
74 m_orientation = wxLAYOUT_HORIZONTAL;
75 }
76
77 // Read by the app
78 void SetRequestedLength(int length) { m_requestedLength = length; }
79 int GetRequestedLength() const { return m_requestedLength; }
80
81 void SetFlags(int flags) { m_flags = flags; }
82 int GetFlags() const { return m_flags; }
83
84 // Set by the app
85 void SetSize(const wxSize& size) { m_size = size; }
86 wxSize GetSize() const { return m_size; }
87
88 void SetOrientation(wxLayoutOrientation orient) { m_orientation = orient; }
89 wxLayoutOrientation GetOrientation() const { return m_orientation; }
90
91 void SetAlignment(wxLayoutAlignment align) { m_alignment = align; }
92 wxLayoutAlignment GetAlignment() const { return m_alignment; }
93
94 virtual wxEvent *Clone() const { return new wxQueryLayoutInfoEvent(*this); }
95
96 protected:
97 int m_flags;
98 int m_requestedLength;
99 wxSize m_size;
100 wxLayoutOrientation m_orientation;
101 wxLayoutAlignment m_alignment;
102
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, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxQueryLayoutInfoEventFunction) & func, NULL ),
109
110 /*
111 * This event is used to take a bite out of the available client area.
112 */
113
114 class WXDLLEXPORT wxCalculateLayoutEvent: public wxEvent
115 {
116 DECLARE_DYNAMIC_CLASS(wxCalculateLayoutEvent)
117 public:
118 wxCalculateLayoutEvent(wxWindowID id = 0)
119 {
120 SetEventType(wxEVT_CALCULATE_LAYOUT);
121 m_flags = 0;
122 m_id = id;
123 }
124
125 // Read by the app
126 void SetFlags(int flags) { m_flags = flags; }
127 int GetFlags() const { return m_flags; }
128
129 // Set by the app
130 void SetRect(const wxRect& rect) { m_rect = rect; }
131 wxRect GetRect() const { return m_rect; }
132
133 virtual wxEvent *Clone() const { return new wxCalculateLayoutEvent(*this); }
134
135 protected:
136 int m_flags;
137 wxRect m_rect;
138 };
139
140 typedef void (wxEvtHandler::*wxCalculateLayoutEventFunction)(wxCalculateLayoutEvent&);
141
142 #define EVT_CALCULATE_LAYOUT(func) \
143 DECLARE_EVENT_TABLE_ENTRY( wxEVT_CALCULATE_LAYOUT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (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 WXDLLEXPORT wxSashLayoutWindow: public wxSashWindow
151 {
152 DECLARE_CLASS(wxSashLayoutWindow)
153 public:
154 wxSashLayoutWindow()
155 {
156 Init();
157 }
158
159 wxSashLayoutWindow(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
160 const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = "layoutWindow")
161 {
162 Create(parent, id, pos, size, style, name);
163 }
164
165 bool Create(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
166 const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = "layoutWindow");
167
168 // Accessors
169 inline wxLayoutAlignment GetAlignment() const { return m_alignment; };
170 inline wxLayoutOrientation GetOrientation() const { return m_orientation; };
171
172 inline void SetAlignment(wxLayoutAlignment align) { m_alignment = align; };
173 inline void SetOrientation(wxLayoutOrientation orient) { m_orientation = orient; };
174
175 // Give the window default dimensions
176 inline void SetDefaultSize(const wxSize& size) { m_defaultSize = size; }
177
178 // Event handlers
179 // Called by layout algorithm to allow window to take a bit out of the
180 // client rectangle, and size itself if not in wxLAYOUT_QUERY mode.
181 void OnCalculateLayout(wxCalculateLayoutEvent& event);
182
183 // Called by layout algorithm to retrieve information about the window.
184 void OnQueryLayoutInfo(wxQueryLayoutInfoEvent& event);
185
186 private:
187 void Init();
188
189 wxLayoutAlignment m_alignment;
190 wxLayoutOrientation m_orientation;
191 wxSize m_defaultSize;
192
193 DECLARE_EVENT_TABLE()
194 };
195
196 #endif // wxUSE_SASH
197
198 class WXDLLEXPORT wxMDIParentFrame;
199 class WXDLLEXPORT wxFrame;
200
201 // This class implements the layout algorithm
202 class WXDLLEXPORT wxLayoutAlgorithm: public wxObject
203 {
204 public:
205 wxLayoutAlgorithm() {}
206
207 #if wxUSE_MDI_ARCHITECTURE
208 // The MDI client window is sized to whatever's left over.
209 bool LayoutMDIFrame(wxMDIParentFrame* frame, wxRect* rect = (wxRect*) NULL);
210 #endif // wxUSE_MDI_ARCHITECTURE
211
212 // mainWindow is sized to whatever's left over. This function for backward
213 // compatibility; use LayoutWindow.
214 bool LayoutFrame(wxFrame* frame, wxWindow* mainWindow = (wxWindow*) NULL);
215
216 // mainWindow is sized to whatever's left over.
217 bool LayoutWindow(wxWindow* frame, wxWindow* mainWindow = (wxWindow*) NULL);
218 };
219
220 #endif
221 // _WX_LAYWIN_H_G_