]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/laywin.h
Fixed some broken things related to context help, fixed memory leak
[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 const wxEventType wxEVT_QUERY_LAYOUT_INFO = wxEVT_FIRST + 1500;
27 const wxEventType wxEVT_CALCULATE_LAYOUT = wxEVT_FIRST + 1501;
28
29 enum wxLayoutOrientation
30 {
31 wxLAYOUT_HORIZONTAL,
32 wxLAYOUT_VERTICAL
33 };
34
35 enum wxLayoutAlignment
36 {
37 wxLAYOUT_NONE,
38 wxLAYOUT_TOP,
39 wxLAYOUT_LEFT,
40 wxLAYOUT_RIGHT,
41 wxLAYOUT_BOTTOM
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
60 class WXDLLEXPORT wxQueryLayoutInfoEvent: public wxEvent
61 {
62 DECLARE_DYNAMIC_CLASS(wxQueryLayoutInfoEvent)
63 public:
64
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 protected:
93 int m_flags;
94 int m_requestedLength;
95 wxSize m_size;
96 wxLayoutOrientation m_orientation;
97 wxLayoutAlignment m_alignment;
98
99 };
100
101 typedef void (wxEvtHandler::*wxQueryLayoutInfoEventFunction)(wxQueryLayoutInfoEvent&);
102
103 #define EVT_QUERY_LAYOUT_INFO(func) { wxEVT_QUERY_LAYOUT_INFO, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxQueryLayoutInfoEventFunction) & func, NULL },
104
105 /*
106 * This event is used to take a bite out of the available client area.
107 */
108
109 class WXDLLEXPORT wxCalculateLayoutEvent: public wxEvent
110 {
111 DECLARE_DYNAMIC_CLASS(wxCalculateLayoutEvent)
112 public:
113 wxCalculateLayoutEvent(wxWindowID id = 0)
114 {
115 SetEventType(wxEVT_CALCULATE_LAYOUT);
116 m_flags = 0;
117 m_id = id;
118 }
119 // Read by the app
120 inline void SetFlags(int flags) { m_flags = flags; }
121 inline int GetFlags() const { return m_flags; }
122
123 // Set by the app
124 inline void SetRect(const wxRect& rect) { m_rect = rect; }
125 inline wxRect GetRect() const { return m_rect; }
126 protected:
127 int m_flags;
128 wxRect m_rect;
129 };
130
131 typedef void (wxEvtHandler::*wxCalculateLayoutEventFunction)(wxCalculateLayoutEvent&);
132
133 #define EVT_CALCULATE_LAYOUT(func) { wxEVT_CALCULATE_LAYOUT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCalculateLayoutEventFunction) & func, NULL },
134
135 #if wxUSE_SASH
136
137 // This is window that can remember alignment/orientation, does its own layout,
138 // and can provide sashes too. Useful for implementing docked windows with sashes in
139 // an IDE-style interface.
140 class WXDLLEXPORT wxSashLayoutWindow: public wxSashWindow
141 {
142 DECLARE_CLASS(wxSashLayoutWindow)
143 public:
144 wxSashLayoutWindow()
145 {
146 Init();
147 }
148
149 wxSashLayoutWindow(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
150 const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = "layoutWindow")
151 {
152 Create(parent, id, pos, size, style, name);
153 }
154
155 bool Create(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
156 const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = "layoutWindow");
157
158 // Accessors
159 inline wxLayoutAlignment GetAlignment() const { return m_alignment; };
160 inline wxLayoutOrientation GetOrientation() const { return m_orientation; };
161
162 inline void SetAlignment(wxLayoutAlignment align) { m_alignment = align; };
163 inline void SetOrientation(wxLayoutOrientation orient) { m_orientation = orient; };
164
165 // Give the window default dimensions
166 inline void SetDefaultSize(const wxSize& size) { m_defaultSize = size; }
167
168 // Event handlers
169 // Called by layout algorithm to allow window to take a bit out of the
170 // client rectangle, and size itself if not in wxLAYOUT_QUERY mode.
171 void OnCalculateLayout(wxCalculateLayoutEvent& event);
172
173 // Called by layout algorithm to retrieve information about the window.
174 void OnQueryLayoutInfo(wxQueryLayoutInfoEvent& event);
175
176 private:
177 void Init();
178
179 wxLayoutAlignment m_alignment;
180 wxLayoutOrientation m_orientation;
181 wxSize m_defaultSize;
182
183 DECLARE_EVENT_TABLE()
184 };
185
186 #endif // wxUSE_SASH
187
188 class WXDLLEXPORT wxMDIParentFrame;
189 class WXDLLEXPORT wxFrame;
190
191 // This class implements the layout algorithm
192 class WXDLLEXPORT wxLayoutAlgorithm: public wxObject
193 {
194 public:
195 wxLayoutAlgorithm() {}
196
197 // The MDI client window is sized to whatever's left over.
198 bool LayoutMDIFrame(wxMDIParentFrame* frame, wxRect* rect = (wxRect*) NULL);
199
200 // mainWindow is sized to whatever's left over. This function for backward
201 // compatibility; use LayoutWindow.
202 bool LayoutFrame(wxFrame* frame, wxWindow* mainWindow = (wxWindow*) NULL)
203 {
204 return LayoutWindow(frame, mainWindow);
205 }
206
207 // mainWindow is sized to whatever's left over.
208 bool LayoutWindow(wxWindow* frame, wxWindow* mainWindow = (wxWindow*) NULL);
209 };
210
211 #endif
212 // _WX_LAYWIN_H_G_