1 /////////////////////////////////////////////////////////////////////////////
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
11 // Copyright: (c) Julian Smart
12 // Licence: wxWindows licence
13 /////////////////////////////////////////////////////////////////////////////
15 #ifndef _WX_LAYWIN_H_G_
16 #define _WX_LAYWIN_H_G_
18 #if defined(__GNUG__) && !defined(__APPLE__)
19 #pragma interface "laywin.h"
23 #include "wx/sashwin.h"
26 BEGIN_DECLARE_EVENT_TYPES()
27 DECLARE_EVENT_TYPE(wxEVT_QUERY_LAYOUT_INFO
, 1500)
28 DECLARE_EVENT_TYPE(wxEVT_CALCULATE_LAYOUT
, 1501)
29 END_DECLARE_EVENT_TYPES()
31 enum wxLayoutOrientation
37 enum wxLayoutAlignment
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
51 // Use most recently used length
52 #define wxLAYOUT_MRU_LENGTH 0x0010
54 // Only a query, so don't actually move it.
55 #define wxLAYOUT_QUERY 0x0100
58 * This event is used to get information about window alignment,
59 * orientation and size.
62 class WXDLLEXPORT wxQueryLayoutInfoEvent
: public wxEvent
64 DECLARE_DYNAMIC_CLASS(wxQueryLayoutInfoEvent
)
67 wxQueryLayoutInfoEvent(wxWindowID id
= 0)
69 SetEventType(wxEVT_QUERY_LAYOUT_INFO
);
70 m_requestedLength
= 0;
73 m_alignment
= wxLAYOUT_TOP
;
74 m_orientation
= wxLAYOUT_HORIZONTAL
;
78 void SetRequestedLength(int length
) { m_requestedLength
= length
; }
79 int GetRequestedLength() const { return m_requestedLength
; }
81 void SetFlags(int flags
) { m_flags
= flags
; }
82 int GetFlags() const { return m_flags
; }
85 void SetSize(const wxSize
& size
) { m_size
= size
; }
86 wxSize
GetSize() const { return m_size
; }
88 void SetOrientation(wxLayoutOrientation orient
) { m_orientation
= orient
; }
89 wxLayoutOrientation
GetOrientation() const { return m_orientation
; }
91 void SetAlignment(wxLayoutAlignment align
) { m_alignment
= align
; }
92 wxLayoutAlignment
GetAlignment() const { return m_alignment
; }
94 virtual wxEvent
*Clone() const { return new wxQueryLayoutInfoEvent(*this); }
98 int m_requestedLength
;
100 wxLayoutOrientation m_orientation
;
101 wxLayoutAlignment m_alignment
;
105 typedef void (wxEvtHandler::*wxQueryLayoutInfoEventFunction
)(wxQueryLayoutInfoEvent
&);
107 #define EVT_QUERY_LAYOUT_INFO(func) \
108 DECLARE_EVENT_TABLE_ENTRY( wxEVT_QUERY_LAYOUT_INFO, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxQueryLayoutInfoEventFunction) & func, NULL ),
111 * This event is used to take a bite out of the available client area.
114 class WXDLLEXPORT wxCalculateLayoutEvent
: public wxEvent
116 DECLARE_DYNAMIC_CLASS(wxCalculateLayoutEvent
)
118 wxCalculateLayoutEvent(wxWindowID id
= 0)
120 SetEventType(wxEVT_CALCULATE_LAYOUT
);
126 void SetFlags(int flags
) { m_flags
= flags
; }
127 int GetFlags() const { return m_flags
; }
130 void SetRect(const wxRect
& rect
) { m_rect
= rect
; }
131 wxRect
GetRect() const { return m_rect
; }
133 virtual wxEvent
*Clone() const { return new wxCalculateLayoutEvent(*this); }
140 typedef void (wxEvtHandler::*wxCalculateLayoutEventFunction
)(wxCalculateLayoutEvent
&);
142 #define EVT_CALCULATE_LAYOUT(func) \
143 DECLARE_EVENT_TABLE_ENTRY( wxEVT_CALCULATE_LAYOUT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCalculateLayoutEventFunction) & func, NULL ),
147 // This is window that can remember alignment/orientation, does its own layout,
148 // and can provide sashes too. Useful for implementing docked windows with sashes in
149 // an IDE-style interface.
150 class WXDLLEXPORT wxSashLayoutWindow
: public wxSashWindow
152 DECLARE_CLASS(wxSashLayoutWindow
)
159 wxSashLayoutWindow(wxWindow
*parent
, wxWindowID id
= -1, const wxPoint
& pos
= wxDefaultPosition
,
160 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= "layoutWindow")
162 Create(parent
, id
, pos
, size
, style
, name
);
165 bool Create(wxWindow
*parent
, wxWindowID id
= -1, const wxPoint
& pos
= wxDefaultPosition
,
166 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= "layoutWindow");
169 inline wxLayoutAlignment
GetAlignment() const { return m_alignment
; };
170 inline wxLayoutOrientation
GetOrientation() const { return m_orientation
; };
172 inline void SetAlignment(wxLayoutAlignment align
) { m_alignment
= align
; };
173 inline void SetOrientation(wxLayoutOrientation orient
) { m_orientation
= orient
; };
175 // Give the window default dimensions
176 inline void SetDefaultSize(const wxSize
& size
) { m_defaultSize
= size
; }
179 // Called by layout algorithm to allow window to take a bit out of the
180 // client rectangle, and size itself if not in wxLAYOUT_QUERY mode.
181 void OnCalculateLayout(wxCalculateLayoutEvent
& event
);
183 // Called by layout algorithm to retrieve information about the window.
184 void OnQueryLayoutInfo(wxQueryLayoutInfoEvent
& event
);
189 wxLayoutAlignment m_alignment
;
190 wxLayoutOrientation m_orientation
;
191 wxSize m_defaultSize
;
193 DECLARE_EVENT_TABLE()
198 class WXDLLEXPORT wxMDIParentFrame
;
199 class WXDLLEXPORT wxFrame
;
201 // This class implements the layout algorithm
202 class WXDLLEXPORT wxLayoutAlgorithm
: public wxObject
205 wxLayoutAlgorithm() {}
207 #if wxUSE_MDI_ARCHITECTURE
208 // The MDI client window is sized to whatever's left over.
209 bool LayoutMDIFrame(wxMDIParentFrame
* frame
, wxRect
* rect
= (wxRect
*) NULL
);
210 #endif // wxUSE_MDI_ARCHITECTURE
212 // mainWindow is sized to whatever's left over. This function for backward
213 // compatibility; use LayoutWindow.
214 bool LayoutFrame(wxFrame
* frame
, wxWindow
* mainWindow
= (wxWindow
*) NULL
);
216 // mainWindow is sized to whatever's left over.
217 bool LayoutWindow(wxWindow
* frame
, wxWindow
* mainWindow
= (wxWindow
*) NULL
);