]>
Commit | Line | Data |
---|---|---|
a6d70308 JS |
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 | |
65571936 | 12 | // Licence: wxWindows licence |
a6d70308 JS |
13 | ///////////////////////////////////////////////////////////////////////////// |
14 | ||
15 | #ifndef _WX_LAYWIN_H_G_ | |
16 | #define _WX_LAYWIN_H_G_ | |
17 | ||
88ac883a VZ |
18 | #if wxUSE_SASH |
19 | #include "wx/sashwin.h" | |
20 | #endif // wxUSE_SASH | |
a6d70308 | 21 | |
a6956d86 MR |
22 | #include "wx/event.h" |
23 | ||
c058cafa VZ |
24 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_QUERY_LAYOUT_INFO; |
25 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_CALCULATE_LAYOUT; | |
a6d70308 | 26 | |
88ac883a VZ |
27 | enum wxLayoutOrientation |
28 | { | |
a6d70308 JS |
29 | wxLAYOUT_HORIZONTAL, |
30 | wxLAYOUT_VERTICAL | |
31 | }; | |
32 | ||
88ac883a VZ |
33 | enum wxLayoutAlignment |
34 | { | |
a6d70308 JS |
35 | wxLAYOUT_NONE, |
36 | wxLAYOUT_TOP, | |
37 | wxLAYOUT_LEFT, | |
38 | wxLAYOUT_RIGHT, | |
afce4c03 | 39 | wxLAYOUT_BOTTOM |
a6d70308 JS |
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 | ||
12f190b0 | 58 | class WXDLLIMPEXP_ADV wxQueryLayoutInfoEvent: public wxEvent |
a6d70308 | 59 | { |
a6d70308 | 60 | public: |
a6d70308 JS |
61 | wxQueryLayoutInfoEvent(wxWindowID id = 0) |
62 | { | |
63 | SetEventType(wxEVT_QUERY_LAYOUT_INFO); | |
64 | m_requestedLength = 0; | |
65 | m_flags = 0; | |
8cb50e4b | 66 | m_id = id; |
a6d70308 JS |
67 | m_alignment = wxLAYOUT_TOP; |
68 | m_orientation = wxLAYOUT_HORIZONTAL; | |
69 | } | |
a6d70308 | 70 | |
bfc6fde4 VZ |
71 | // Read by the app |
72 | void SetRequestedLength(int length) { m_requestedLength = length; } | |
73 | int GetRequestedLength() const { return m_requestedLength; } | |
a6d70308 | 74 | |
bfc6fde4 VZ |
75 | void SetFlags(int flags) { m_flags = flags; } |
76 | int GetFlags() const { return m_flags; } | |
a6d70308 | 77 | |
bfc6fde4 VZ |
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; } | |
a6d70308 | 87 | |
acd15a3f VZ |
88 | virtual wxEvent *Clone() const { return new wxQueryLayoutInfoEvent(*this); } |
89 | ||
a6d70308 JS |
90 | protected: |
91 | int m_flags; | |
92 | int m_requestedLength; | |
93 | wxSize m_size; | |
94 | wxLayoutOrientation m_orientation; | |
95 | wxLayoutAlignment m_alignment; | |
ca65c044 | 96 | |
2b5f62a0 | 97 | private: |
a6cbc4db | 98 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxQueryLayoutInfoEvent) |
a6d70308 JS |
99 | }; |
100 | ||
101 | typedef void (wxEvtHandler::*wxQueryLayoutInfoEventFunction)(wxQueryLayoutInfoEvent&); | |
102 | ||
82a5f02c | 103 | #define EVT_QUERY_LAYOUT_INFO(func) \ |
ca65c044 | 104 | DECLARE_EVENT_TABLE_ENTRY( wxEVT_QUERY_LAYOUT_INFO, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxQueryLayoutInfoEventFunction, & func ), NULL ), |
a6d70308 JS |
105 | |
106 | /* | |
107 | * This event is used to take a bite out of the available client area. | |
108 | */ | |
109 | ||
12f190b0 | 110 | class WXDLLIMPEXP_ADV wxCalculateLayoutEvent: public wxEvent |
a6d70308 | 111 | { |
a6d70308 JS |
112 | public: |
113 | wxCalculateLayoutEvent(wxWindowID id = 0) | |
114 | { | |
115 | SetEventType(wxEVT_CALCULATE_LAYOUT); | |
116 | m_flags = 0; | |
afce4c03 | 117 | m_id = id; |
a6d70308 | 118 | } |
a6d70308 | 119 | |
acd15a3f VZ |
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 | ||
a6d70308 JS |
130 | protected: |
131 | int m_flags; | |
132 | wxRect m_rect; | |
ca65c044 | 133 | |
2b5f62a0 | 134 | private: |
a6cbc4db | 135 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxCalculateLayoutEvent) |
a6d70308 JS |
136 | }; |
137 | ||
138 | typedef void (wxEvtHandler::*wxCalculateLayoutEventFunction)(wxCalculateLayoutEvent&); | |
139 | ||
82a5f02c | 140 | #define EVT_CALCULATE_LAYOUT(func) \ |
ca65c044 | 141 | DECLARE_EVENT_TABLE_ENTRY( wxEVT_CALCULATE_LAYOUT, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxCalculateLayoutEventFunction, & func ), NULL ), |
a6d70308 | 142 | |
88ac883a VZ |
143 | #if wxUSE_SASH |
144 | ||
a6d70308 JS |
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. | |
12f190b0 | 148 | class WXDLLIMPEXP_ADV wxSashLayoutWindow: public wxSashWindow |
a6d70308 | 149 | { |
a6d70308 | 150 | public: |
f6bcfd97 BP |
151 | wxSashLayoutWindow() |
152 | { | |
153 | Init(); | |
154 | } | |
155 | ||
ca65c044 | 156 | wxSashLayoutWindow(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, |
2b5f62a0 | 157 | const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = wxT("layoutWindow")) |
f6bcfd97 BP |
158 | { |
159 | Create(parent, id, pos, size, style, name); | |
160 | } | |
161 | ||
ca65c044 | 162 | bool Create(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, |
2b5f62a0 | 163 | const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = wxT("layoutWindow")); |
a6d70308 JS |
164 | |
165 | // Accessors | |
47b378bd VS |
166 | inline wxLayoutAlignment GetAlignment() const { return m_alignment; } |
167 | inline wxLayoutOrientation GetOrientation() const { return m_orientation; } | |
a6d70308 | 168 | |
47b378bd VS |
169 | inline void SetAlignment(wxLayoutAlignment align) { m_alignment = align; } |
170 | inline void SetOrientation(wxLayoutOrientation orient) { m_orientation = orient; } | |
a6d70308 JS |
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); | |
f6bcfd97 BP |
182 | |
183 | private: | |
184 | void Init(); | |
185 | ||
a6d70308 JS |
186 | wxLayoutAlignment m_alignment; |
187 | wxLayoutOrientation m_orientation; | |
188 | wxSize m_defaultSize; | |
189 | ||
2b5f62a0 | 190 | private: |
2eb10e2a | 191 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxSashLayoutWindow) |
2b5f62a0 | 192 | DECLARE_EVENT_TABLE() |
a6d70308 JS |
193 | }; |
194 | ||
88ac883a VZ |
195 | #endif // wxUSE_SASH |
196 | ||
b5dbe15d VS |
197 | class WXDLLIMPEXP_FWD_CORE wxMDIParentFrame; |
198 | class WXDLLIMPEXP_FWD_CORE wxFrame; | |
a6d70308 JS |
199 | |
200 | // This class implements the layout algorithm | |
12f190b0 | 201 | class WXDLLIMPEXP_ADV wxLayoutAlgorithm: public wxObject |
a6d70308 JS |
202 | { |
203 | public: | |
204 | wxLayoutAlgorithm() {} | |
205 | ||
1e6feb95 | 206 | #if wxUSE_MDI_ARCHITECTURE |
a6d70308 | 207 | // The MDI client window is sized to whatever's left over. |
2243eed5 | 208 | bool LayoutMDIFrame(wxMDIParentFrame* frame, wxRect* rect = (wxRect*) NULL); |
1e6feb95 | 209 | #endif // wxUSE_MDI_ARCHITECTURE |
a6d70308 | 210 | |
f9b1708c JS |
211 | // mainWindow is sized to whatever's left over. This function for backward |
212 | // compatibility; use LayoutWindow. | |
04dbb646 | 213 | bool LayoutFrame(wxFrame* frame, wxWindow* mainWindow = (wxWindow*) NULL); |
f9b1708c | 214 | |
f6bcfd97 | 215 | // mainWindow is sized to whatever's left over. |
f9b1708c | 216 | bool LayoutWindow(wxWindow* frame, wxWindow* mainWindow = (wxWindow*) NULL); |
a6d70308 JS |
217 | }; |
218 | ||
219 | #endif | |
220 | // _WX_LAYWIN_H_G_ |