]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/laywin.h
Trying to hide evidence of my negative programming skills...
[wxWidgets.git] / include / wx / generic / laywin.h
CommitLineData
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
afce4c03 12// Licence: wxWindows licence
a6d70308
JS
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
88ac883a
VZ
22#if wxUSE_SASH
23 #include "wx/sashwin.h"
24#endif // wxUSE_SASH
a6d70308 25
2e4df4bf
VZ
26BEGIN_DECLARE_EVENT_TYPES()
27 DECLARE_EVENT_TYPE(wxEVT_QUERY_LAYOUT_INFO, 1500)
28 DECLARE_EVENT_TYPE(wxEVT_CALCULATE_LAYOUT, 1501)
29END_DECLARE_EVENT_TYPES()
a6d70308 30
88ac883a
VZ
31enum wxLayoutOrientation
32{
a6d70308
JS
33 wxLAYOUT_HORIZONTAL,
34 wxLAYOUT_VERTICAL
35};
36
88ac883a
VZ
37enum wxLayoutAlignment
38{
a6d70308
JS
39 wxLAYOUT_NONE,
40 wxLAYOUT_TOP,
41 wxLAYOUT_LEFT,
42 wxLAYOUT_RIGHT,
afce4c03 43 wxLAYOUT_BOTTOM
a6d70308
JS
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
937cf827 62class WXDLLEXPORT wxQueryLayoutInfoEvent: public wxEvent
a6d70308
JS
63{
64DECLARE_DYNAMIC_CLASS(wxQueryLayoutInfoEvent)
65public:
66
67 wxQueryLayoutInfoEvent(wxWindowID id = 0)
68 {
69 SetEventType(wxEVT_QUERY_LAYOUT_INFO);
70 m_requestedLength = 0;
71 m_flags = 0;
8cb50e4b 72 m_id = id;
a6d70308
JS
73 m_alignment = wxLAYOUT_TOP;
74 m_orientation = wxLAYOUT_HORIZONTAL;
75 }
a6d70308 76
bfc6fde4
VZ
77 // Read by the app
78 void SetRequestedLength(int length) { m_requestedLength = length; }
79 int GetRequestedLength() const { return m_requestedLength; }
a6d70308 80
bfc6fde4
VZ
81 void SetFlags(int flags) { m_flags = flags; }
82 int GetFlags() const { return m_flags; }
a6d70308 83
bfc6fde4
VZ
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; }
a6d70308 93
a6d70308
JS
94protected:
95 int m_flags;
96 int m_requestedLength;
97 wxSize m_size;
98 wxLayoutOrientation m_orientation;
99 wxLayoutAlignment m_alignment;
100
101};
102
103typedef void (wxEvtHandler::*wxQueryLayoutInfoEventFunction)(wxQueryLayoutInfoEvent&);
104
82a5f02c 105#define EVT_QUERY_LAYOUT_INFO(func) \
2e4df4bf 106 DECLARE_EVENT_TABLE_ENTRY( wxEVT_QUERY_LAYOUT_INFO, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxQueryLayoutInfoEventFunction) & func, NULL ),
a6d70308
JS
107
108/*
109 * This event is used to take a bite out of the available client area.
110 */
111
937cf827 112class WXDLLEXPORT wxCalculateLayoutEvent: public wxEvent
a6d70308
JS
113{
114DECLARE_DYNAMIC_CLASS(wxCalculateLayoutEvent)
115public:
116 wxCalculateLayoutEvent(wxWindowID id = 0)
117 {
118 SetEventType(wxEVT_CALCULATE_LAYOUT);
119 m_flags = 0;
afce4c03 120 m_id = id;
a6d70308
JS
121 }
122// Read by the app
123 inline void SetFlags(int flags) { m_flags = flags; }
124 inline int GetFlags() const { return m_flags; }
125
126// Set by the app
127 inline void SetRect(const wxRect& rect) { m_rect = rect; }
128 inline wxRect GetRect() const { return m_rect; }
129protected:
130 int m_flags;
131 wxRect m_rect;
132};
133
134typedef void (wxEvtHandler::*wxCalculateLayoutEventFunction)(wxCalculateLayoutEvent&);
135
82a5f02c 136#define EVT_CALCULATE_LAYOUT(func) \
2e4df4bf 137 DECLARE_EVENT_TABLE_ENTRY( wxEVT_CALCULATE_LAYOUT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCalculateLayoutEventFunction) & func, NULL ),
a6d70308 138
88ac883a
VZ
139#if wxUSE_SASH
140
a6d70308
JS
141// This is window that can remember alignment/orientation, does its own layout,
142// and can provide sashes too. Useful for implementing docked windows with sashes in
143// an IDE-style interface.
937cf827 144class WXDLLEXPORT wxSashLayoutWindow: public wxSashWindow
a6d70308
JS
145{
146 DECLARE_CLASS(wxSashLayoutWindow)
147public:
f6bcfd97
BP
148 wxSashLayoutWindow()
149 {
150 Init();
151 }
152
a6d70308 153 wxSashLayoutWindow(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
f6bcfd97
BP
154 const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = "layoutWindow")
155 {
156 Create(parent, id, pos, size, style, name);
157 }
158
159 bool Create(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
a6d70308
JS
160 const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = "layoutWindow");
161
162// Accessors
163 inline wxLayoutAlignment GetAlignment() const { return m_alignment; };
164 inline wxLayoutOrientation GetOrientation() const { return m_orientation; };
165
166 inline void SetAlignment(wxLayoutAlignment align) { m_alignment = align; };
167 inline void SetOrientation(wxLayoutOrientation orient) { m_orientation = orient; };
168
169 // Give the window default dimensions
170 inline void SetDefaultSize(const wxSize& size) { m_defaultSize = size; }
171
172// Event handlers
173 // Called by layout algorithm to allow window to take a bit out of the
174 // client rectangle, and size itself if not in wxLAYOUT_QUERY mode.
175 void OnCalculateLayout(wxCalculateLayoutEvent& event);
176
177 // Called by layout algorithm to retrieve information about the window.
178 void OnQueryLayoutInfo(wxQueryLayoutInfoEvent& event);
f6bcfd97
BP
179
180private:
181 void Init();
182
a6d70308
JS
183 wxLayoutAlignment m_alignment;
184 wxLayoutOrientation m_orientation;
185 wxSize m_defaultSize;
186
187DECLARE_EVENT_TABLE()
188};
189
88ac883a
VZ
190#endif // wxUSE_SASH
191
a6d70308
JS
192class WXDLLEXPORT wxMDIParentFrame;
193class WXDLLEXPORT wxFrame;
194
195// This class implements the layout algorithm
937cf827 196class WXDLLEXPORT wxLayoutAlgorithm: public wxObject
a6d70308
JS
197{
198public:
199 wxLayoutAlgorithm() {}
200
1e6feb95 201#if wxUSE_MDI_ARCHITECTURE
a6d70308 202 // The MDI client window is sized to whatever's left over.
2243eed5 203 bool LayoutMDIFrame(wxMDIParentFrame* frame, wxRect* rect = (wxRect*) NULL);
1e6feb95 204#endif // wxUSE_MDI_ARCHITECTURE
a6d70308 205
f9b1708c
JS
206 // mainWindow is sized to whatever's left over. This function for backward
207 // compatibility; use LayoutWindow.
04dbb646 208 bool LayoutFrame(wxFrame* frame, wxWindow* mainWindow = (wxWindow*) NULL);
f9b1708c 209
f6bcfd97 210 // mainWindow is sized to whatever's left over.
f9b1708c 211 bool LayoutWindow(wxWindow* frame, wxWindow* mainWindow = (wxWindow*) NULL);
a6d70308
JS
212};
213
214#endif
215 // _WX_LAYWIN_H_G_