]>
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 | |
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 | #include "wx/sashwin.h" | |
23 | ||
24 | const wxEventType wxEVT_QUERY_LAYOUT_INFO = wxEVT_FIRST + 1500; | |
25 | const wxEventType wxEVT_CALCULATE_LAYOUT = wxEVT_FIRST + 1501; | |
26 | ||
27 | enum wxLayoutOrientation { | |
28 | wxLAYOUT_HORIZONTAL, | |
29 | wxLAYOUT_VERTICAL | |
30 | }; | |
31 | ||
32 | enum wxLayoutAlignment { | |
33 | wxLAYOUT_NONE, | |
34 | wxLAYOUT_TOP, | |
35 | wxLAYOUT_LEFT, | |
36 | wxLAYOUT_RIGHT, | |
37 | wxLAYOUT_BOTTOM, | |
38 | }; | |
39 | ||
40 | // Not sure this is necessary | |
41 | // Tell window which dimension we're sizing on | |
42 | #define wxLAYOUT_LENGTH_Y 0x0008 | |
43 | #define wxLAYOUT_LENGTH_X 0x0000 | |
44 | ||
45 | // Use most recently used length | |
46 | #define wxLAYOUT_MRU_LENGTH 0x0010 | |
47 | ||
48 | // Only a query, so don't actually move it. | |
49 | #define wxLAYOUT_QUERY 0x0100 | |
50 | ||
51 | /* | |
52 | * This event is used to get information about window alignment, | |
53 | * orientation and size. | |
54 | */ | |
55 | ||
937cf827 | 56 | class WXDLLEXPORT wxQueryLayoutInfoEvent: public wxEvent |
a6d70308 JS |
57 | { |
58 | DECLARE_DYNAMIC_CLASS(wxQueryLayoutInfoEvent) | |
59 | public: | |
60 | ||
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 | |
a6d70308 JS |
88 | protected: |
89 | int m_flags; | |
90 | int m_requestedLength; | |
91 | wxSize m_size; | |
92 | wxLayoutOrientation m_orientation; | |
93 | wxLayoutAlignment m_alignment; | |
94 | ||
95 | }; | |
96 | ||
97 | typedef void (wxEvtHandler::*wxQueryLayoutInfoEventFunction)(wxQueryLayoutInfoEvent&); | |
98 | ||
99 | #define EVT_QUERY_LAYOUT_INFO(func) { wxEVT_QUERY_LAYOUT_INFO, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxQueryLayoutInfoEventFunction) & func, NULL }, | |
100 | ||
101 | /* | |
102 | * This event is used to take a bite out of the available client area. | |
103 | */ | |
104 | ||
937cf827 | 105 | class WXDLLEXPORT wxCalculateLayoutEvent: public wxEvent |
a6d70308 JS |
106 | { |
107 | DECLARE_DYNAMIC_CLASS(wxCalculateLayoutEvent) | |
108 | public: | |
109 | wxCalculateLayoutEvent(wxWindowID id = 0) | |
110 | { | |
111 | SetEventType(wxEVT_CALCULATE_LAYOUT); | |
112 | m_flags = 0; | |
8cb50e4b | 113 | m_id = id; |
a6d70308 JS |
114 | } |
115 | // Read by the app | |
116 | inline void SetFlags(int flags) { m_flags = flags; } | |
117 | inline int GetFlags() const { return m_flags; } | |
118 | ||
119 | // Set by the app | |
120 | inline void SetRect(const wxRect& rect) { m_rect = rect; } | |
121 | inline wxRect GetRect() const { return m_rect; } | |
122 | protected: | |
123 | int m_flags; | |
124 | wxRect m_rect; | |
125 | }; | |
126 | ||
127 | typedef void (wxEvtHandler::*wxCalculateLayoutEventFunction)(wxCalculateLayoutEvent&); | |
128 | ||
129 | #define EVT_CALCULATE_LAYOUT(func) { wxEVT_CALCULATE_LAYOUT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCalculateLayoutEventFunction) & func, NULL }, | |
130 | ||
131 | // This is window that can remember alignment/orientation, does its own layout, | |
132 | // and can provide sashes too. Useful for implementing docked windows with sashes in | |
133 | // an IDE-style interface. | |
937cf827 | 134 | class WXDLLEXPORT wxSashLayoutWindow: public wxSashWindow |
a6d70308 JS |
135 | { |
136 | DECLARE_CLASS(wxSashLayoutWindow) | |
137 | public: | |
138 | wxSashLayoutWindow(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, | |
139 | const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = "layoutWindow"); | |
140 | ||
141 | // Accessors | |
142 | inline wxLayoutAlignment GetAlignment() const { return m_alignment; }; | |
143 | inline wxLayoutOrientation GetOrientation() const { return m_orientation; }; | |
144 | ||
145 | inline void SetAlignment(wxLayoutAlignment align) { m_alignment = align; }; | |
146 | inline void SetOrientation(wxLayoutOrientation orient) { m_orientation = orient; }; | |
147 | ||
148 | // Give the window default dimensions | |
149 | inline void SetDefaultSize(const wxSize& size) { m_defaultSize = size; } | |
150 | ||
151 | // Event handlers | |
152 | // Called by layout algorithm to allow window to take a bit out of the | |
153 | // client rectangle, and size itself if not in wxLAYOUT_QUERY mode. | |
154 | void OnCalculateLayout(wxCalculateLayoutEvent& event); | |
155 | ||
156 | // Called by layout algorithm to retrieve information about the window. | |
157 | void OnQueryLayoutInfo(wxQueryLayoutInfoEvent& event); | |
158 | protected: | |
159 | wxLayoutAlignment m_alignment; | |
160 | wxLayoutOrientation m_orientation; | |
161 | wxSize m_defaultSize; | |
162 | ||
163 | DECLARE_EVENT_TABLE() | |
164 | }; | |
165 | ||
166 | class WXDLLEXPORT wxMDIParentFrame; | |
167 | class WXDLLEXPORT wxFrame; | |
168 | ||
169 | // This class implements the layout algorithm | |
937cf827 | 170 | class WXDLLEXPORT wxLayoutAlgorithm: public wxObject |
a6d70308 JS |
171 | { |
172 | public: | |
173 | wxLayoutAlgorithm() {} | |
174 | ||
175 | // The MDI client window is sized to whatever's left over. | |
2243eed5 | 176 | bool LayoutMDIFrame(wxMDIParentFrame* frame, wxRect* rect = (wxRect*) NULL); |
a6d70308 | 177 | |
f9b1708c JS |
178 | // mainWindow is sized to whatever's left over. This function for backward |
179 | // compatibility; use LayoutWindow. | |
180 | bool LayoutFrame(wxFrame* frame, wxWindow* mainWindow = (wxWindow*) NULL) | |
181 | { | |
182 | return LayoutWindow(frame, mainWindow); | |
183 | } | |
184 | ||
185 | // mainWindow is sized to whatever's left over. This function for backward | |
186 | bool LayoutWindow(wxWindow* frame, wxWindow* mainWindow = (wxWindow*) NULL); | |
a6d70308 JS |
187 | }; |
188 | ||
189 | #endif | |
190 | // _WX_LAYWIN_H_G_ |