]>
Commit | Line | Data |
---|---|---|
a6d70308 | 1 | ///////////////////////////////////////////////////////////////////////////// |
80fdcdb9 | 2 | // Name: wx/generic/laywin.h |
a6d70308 JS |
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 | |
a6d70308 | 10 | // Copyright: (c) Julian Smart |
65571936 | 11 | // Licence: wxWindows licence |
a6d70308 JS |
12 | ///////////////////////////////////////////////////////////////////////////// |
13 | ||
14 | #ifndef _WX_LAYWIN_H_G_ | |
15 | #define _WX_LAYWIN_H_G_ | |
16 | ||
88ac883a VZ |
17 | #if wxUSE_SASH |
18 | #include "wx/sashwin.h" | |
19 | #endif // wxUSE_SASH | |
a6d70308 | 20 | |
a6956d86 MR |
21 | #include "wx/event.h" |
22 | ||
3c778901 VZ |
23 | class WXDLLIMPEXP_FWD_ADV wxQueryLayoutInfoEvent; |
24 | class WXDLLIMPEXP_FWD_ADV wxCalculateLayoutEvent; | |
25 | ||
9b11752c VZ |
26 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_QUERY_LAYOUT_INFO, wxQueryLayoutInfoEvent ); |
27 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_CALCULATE_LAYOUT, wxCalculateLayoutEvent ); | |
a6d70308 | 28 | |
88ac883a VZ |
29 | enum wxLayoutOrientation |
30 | { | |
a6d70308 JS |
31 | wxLAYOUT_HORIZONTAL, |
32 | wxLAYOUT_VERTICAL | |
33 | }; | |
34 | ||
88ac883a VZ |
35 | enum wxLayoutAlignment |
36 | { | |
a6d70308 JS |
37 | wxLAYOUT_NONE, |
38 | wxLAYOUT_TOP, | |
39 | wxLAYOUT_LEFT, | |
40 | wxLAYOUT_RIGHT, | |
afce4c03 | 41 | wxLAYOUT_BOTTOM |
a6d70308 JS |
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 | ||
12f190b0 | 60 | class WXDLLIMPEXP_ADV wxQueryLayoutInfoEvent: public wxEvent |
a6d70308 | 61 | { |
a6d70308 | 62 | public: |
a6d70308 JS |
63 | wxQueryLayoutInfoEvent(wxWindowID id = 0) |
64 | { | |
65 | SetEventType(wxEVT_QUERY_LAYOUT_INFO); | |
66 | m_requestedLength = 0; | |
67 | m_flags = 0; | |
8cb50e4b | 68 | m_id = id; |
a6d70308 JS |
69 | m_alignment = wxLAYOUT_TOP; |
70 | m_orientation = wxLAYOUT_HORIZONTAL; | |
71 | } | |
a6d70308 | 72 | |
bfc6fde4 VZ |
73 | // Read by the app |
74 | void SetRequestedLength(int length) { m_requestedLength = length; } | |
75 | int GetRequestedLength() const { return m_requestedLength; } | |
a6d70308 | 76 | |
bfc6fde4 VZ |
77 | void SetFlags(int flags) { m_flags = flags; } |
78 | int GetFlags() const { return m_flags; } | |
a6d70308 | 79 | |
bfc6fde4 VZ |
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; } | |
a6d70308 | 89 | |
acd15a3f VZ |
90 | virtual wxEvent *Clone() const { return new wxQueryLayoutInfoEvent(*this); } |
91 | ||
a6d70308 JS |
92 | protected: |
93 | int m_flags; | |
94 | int m_requestedLength; | |
95 | wxSize m_size; | |
96 | wxLayoutOrientation m_orientation; | |
97 | wxLayoutAlignment m_alignment; | |
ca65c044 | 98 | |
2b5f62a0 | 99 | private: |
a6cbc4db | 100 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxQueryLayoutInfoEvent) |
a6d70308 JS |
101 | }; |
102 | ||
103 | typedef void (wxEvtHandler::*wxQueryLayoutInfoEventFunction)(wxQueryLayoutInfoEvent&); | |
104 | ||
3c778901 VZ |
105 | #define wxQueryLayoutInfoEventHandler( func ) \ |
106 | wxEVENT_HANDLER_CAST( wxQueryLayoutInfoEventFunction, func ) | |
107 | ||
82a5f02c | 108 | #define EVT_QUERY_LAYOUT_INFO(func) \ |
a0e9a5df | 109 | wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_QUERY_LAYOUT_INFO, wxID_ANY, wxID_ANY, wxQueryLayoutInfoEventHandler( func ), NULL ), |
a6d70308 JS |
110 | |
111 | /* | |
112 | * This event is used to take a bite out of the available client area. | |
113 | */ | |
114 | ||
12f190b0 | 115 | class WXDLLIMPEXP_ADV wxCalculateLayoutEvent: public wxEvent |
a6d70308 | 116 | { |
a6d70308 JS |
117 | public: |
118 | wxCalculateLayoutEvent(wxWindowID id = 0) | |
119 | { | |
120 | SetEventType(wxEVT_CALCULATE_LAYOUT); | |
121 | m_flags = 0; | |
afce4c03 | 122 | m_id = id; |
a6d70308 | 123 | } |
a6d70308 | 124 | |
acd15a3f VZ |
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 | ||
a6d70308 JS |
135 | protected: |
136 | int m_flags; | |
137 | wxRect m_rect; | |
ca65c044 | 138 | |
2b5f62a0 | 139 | private: |
a6cbc4db | 140 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxCalculateLayoutEvent) |
a6d70308 JS |
141 | }; |
142 | ||
143 | typedef void (wxEvtHandler::*wxCalculateLayoutEventFunction)(wxCalculateLayoutEvent&); | |
144 | ||
3c778901 VZ |
145 | #define wxCalculateLayoutEventHandler( func ) wxEVENT_HANDLER_CAST(wxCalculateLayoutEventFunction, func) |
146 | ||
82a5f02c | 147 | #define EVT_CALCULATE_LAYOUT(func) \ |
a0e9a5df | 148 | wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_CALCULATE_LAYOUT, wxID_ANY, wxID_ANY, wxCalculateLayoutEventHandler( func ), NULL ), |
a6d70308 | 149 | |
88ac883a VZ |
150 | #if wxUSE_SASH |
151 | ||
a6d70308 JS |
152 | // This is window that can remember alignment/orientation, does its own layout, |
153 | // and can provide sashes too. Useful for implementing docked windows with sashes in | |
154 | // an IDE-style interface. | |
12f190b0 | 155 | class WXDLLIMPEXP_ADV wxSashLayoutWindow: public wxSashWindow |
a6d70308 | 156 | { |
a6d70308 | 157 | public: |
f6bcfd97 BP |
158 | wxSashLayoutWindow() |
159 | { | |
160 | Init(); | |
161 | } | |
162 | ||
ca65c044 | 163 | wxSashLayoutWindow(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, |
2b5f62a0 | 164 | const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = wxT("layoutWindow")) |
f6bcfd97 BP |
165 | { |
166 | Create(parent, id, pos, size, style, name); | |
167 | } | |
168 | ||
ca65c044 | 169 | bool Create(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, |
2b5f62a0 | 170 | const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = wxT("layoutWindow")); |
a6d70308 JS |
171 | |
172 | // Accessors | |
47b378bd VS |
173 | inline wxLayoutAlignment GetAlignment() const { return m_alignment; } |
174 | inline wxLayoutOrientation GetOrientation() const { return m_orientation; } | |
a6d70308 | 175 | |
47b378bd VS |
176 | inline void SetAlignment(wxLayoutAlignment align) { m_alignment = align; } |
177 | inline void SetOrientation(wxLayoutOrientation orient) { m_orientation = orient; } | |
a6d70308 JS |
178 | |
179 | // Give the window default dimensions | |
180 | inline void SetDefaultSize(const wxSize& size) { m_defaultSize = size; } | |
181 | ||
182 | // Event handlers | |
183 | // Called by layout algorithm to allow window to take a bit out of the | |
184 | // client rectangle, and size itself if not in wxLAYOUT_QUERY mode. | |
185 | void OnCalculateLayout(wxCalculateLayoutEvent& event); | |
186 | ||
187 | // Called by layout algorithm to retrieve information about the window. | |
188 | void OnQueryLayoutInfo(wxQueryLayoutInfoEvent& event); | |
f6bcfd97 BP |
189 | |
190 | private: | |
191 | void Init(); | |
192 | ||
a6d70308 JS |
193 | wxLayoutAlignment m_alignment; |
194 | wxLayoutOrientation m_orientation; | |
195 | wxSize m_defaultSize; | |
196 | ||
2b5f62a0 | 197 | private: |
2eb10e2a | 198 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxSashLayoutWindow) |
2b5f62a0 | 199 | DECLARE_EVENT_TABLE() |
a6d70308 JS |
200 | }; |
201 | ||
88ac883a VZ |
202 | #endif // wxUSE_SASH |
203 | ||
b5dbe15d VS |
204 | class WXDLLIMPEXP_FWD_CORE wxMDIParentFrame; |
205 | class WXDLLIMPEXP_FWD_CORE wxFrame; | |
a6d70308 JS |
206 | |
207 | // This class implements the layout algorithm | |
12f190b0 | 208 | class WXDLLIMPEXP_ADV wxLayoutAlgorithm: public wxObject |
a6d70308 JS |
209 | { |
210 | public: | |
211 | wxLayoutAlgorithm() {} | |
212 | ||
1e6feb95 | 213 | #if wxUSE_MDI_ARCHITECTURE |
a6d70308 | 214 | // The MDI client window is sized to whatever's left over. |
d3b9f782 | 215 | bool LayoutMDIFrame(wxMDIParentFrame* frame, wxRect* rect = NULL); |
1e6feb95 | 216 | #endif // wxUSE_MDI_ARCHITECTURE |
a6d70308 | 217 | |
f9b1708c JS |
218 | // mainWindow is sized to whatever's left over. This function for backward |
219 | // compatibility; use LayoutWindow. | |
d3b9f782 | 220 | bool LayoutFrame(wxFrame* frame, wxWindow* mainWindow = NULL); |
f9b1708c | 221 | |
f6bcfd97 | 222 | // mainWindow is sized to whatever's left over. |
d3b9f782 | 223 | bool LayoutWindow(wxWindow* frame, wxWindow* mainWindow = NULL); |
a6d70308 JS |
224 | }; |
225 | ||
226 | #endif | |
227 | // _WX_LAYWIN_H_G_ |