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_
19 #include "wx/sashwin.h"
24 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_QUERY_LAYOUT_INFO
;
25 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_CALCULATE_LAYOUT
;
27 enum wxLayoutOrientation
33 enum wxLayoutAlignment
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
47 // Use most recently used length
48 #define wxLAYOUT_MRU_LENGTH 0x0010
50 // Only a query, so don't actually move it.
51 #define wxLAYOUT_QUERY 0x0100
54 * This event is used to get information about window alignment,
55 * orientation and size.
58 class WXDLLIMPEXP_ADV wxQueryLayoutInfoEvent
: public wxEvent
61 wxQueryLayoutInfoEvent(wxWindowID id
= 0)
63 SetEventType(wxEVT_QUERY_LAYOUT_INFO
);
64 m_requestedLength
= 0;
67 m_alignment
= wxLAYOUT_TOP
;
68 m_orientation
= wxLAYOUT_HORIZONTAL
;
72 void SetRequestedLength(int length
) { m_requestedLength
= length
; }
73 int GetRequestedLength() const { return m_requestedLength
; }
75 void SetFlags(int flags
) { m_flags
= flags
; }
76 int GetFlags() const { return m_flags
; }
79 void SetSize(const wxSize
& size
) { m_size
= size
; }
80 wxSize
GetSize() const { return m_size
; }
82 void SetOrientation(wxLayoutOrientation orient
) { m_orientation
= orient
; }
83 wxLayoutOrientation
GetOrientation() const { return m_orientation
; }
85 void SetAlignment(wxLayoutAlignment align
) { m_alignment
= align
; }
86 wxLayoutAlignment
GetAlignment() const { return m_alignment
; }
88 virtual wxEvent
*Clone() const { return new wxQueryLayoutInfoEvent(*this); }
92 int m_requestedLength
;
94 wxLayoutOrientation m_orientation
;
95 wxLayoutAlignment m_alignment
;
98 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxQueryLayoutInfoEvent
)
101 typedef void (wxEvtHandler::*wxQueryLayoutInfoEventFunction
)(wxQueryLayoutInfoEvent
&);
103 #define EVT_QUERY_LAYOUT_INFO(func) \
104 DECLARE_EVENT_TABLE_ENTRY( wxEVT_QUERY_LAYOUT_INFO, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxQueryLayoutInfoEventFunction, & func ), NULL ),
107 * This event is used to take a bite out of the available client area.
110 class WXDLLIMPEXP_ADV wxCalculateLayoutEvent
: public wxEvent
113 wxCalculateLayoutEvent(wxWindowID id
= 0)
115 SetEventType(wxEVT_CALCULATE_LAYOUT
);
121 void SetFlags(int flags
) { m_flags
= flags
; }
122 int GetFlags() const { return m_flags
; }
125 void SetRect(const wxRect
& rect
) { m_rect
= rect
; }
126 wxRect
GetRect() const { return m_rect
; }
128 virtual wxEvent
*Clone() const { return new wxCalculateLayoutEvent(*this); }
135 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxCalculateLayoutEvent
)
138 typedef void (wxEvtHandler::*wxCalculateLayoutEventFunction
)(wxCalculateLayoutEvent
&);
140 #define EVT_CALCULATE_LAYOUT(func) \
141 DECLARE_EVENT_TABLE_ENTRY( wxEVT_CALCULATE_LAYOUT, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxCalculateLayoutEventFunction, & func ), NULL ),
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.
148 class WXDLLIMPEXP_ADV wxSashLayoutWindow
: public wxSashWindow
156 wxSashLayoutWindow(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
157 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= wxT("layoutWindow"))
159 Create(parent
, id
, pos
, size
, style
, name
);
162 bool Create(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
163 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= wxT("layoutWindow"));
166 inline wxLayoutAlignment
GetAlignment() const { return m_alignment
; }
167 inline wxLayoutOrientation
GetOrientation() const { return m_orientation
; }
169 inline void SetAlignment(wxLayoutAlignment align
) { m_alignment
= align
; }
170 inline void SetOrientation(wxLayoutOrientation orient
) { m_orientation
= orient
; }
172 // Give the window default dimensions
173 inline void SetDefaultSize(const wxSize
& size
) { m_defaultSize
= size
; }
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
);
180 // Called by layout algorithm to retrieve information about the window.
181 void OnQueryLayoutInfo(wxQueryLayoutInfoEvent
& event
);
186 wxLayoutAlignment m_alignment
;
187 wxLayoutOrientation m_orientation
;
188 wxSize m_defaultSize
;
191 DECLARE_DYNAMIC_CLASS_NO_COPY(wxSashLayoutWindow
)
192 DECLARE_EVENT_TABLE()
197 class WXDLLIMPEXP_FWD_CORE wxMDIParentFrame
;
198 class WXDLLIMPEXP_FWD_CORE wxFrame
;
200 // This class implements the layout algorithm
201 class WXDLLIMPEXP_ADV wxLayoutAlgorithm
: public wxObject
204 wxLayoutAlgorithm() {}
206 #if wxUSE_MDI_ARCHITECTURE
207 // The MDI client window is sized to whatever's left over.
208 bool LayoutMDIFrame(wxMDIParentFrame
* frame
, wxRect
* rect
= (wxRect
*) NULL
);
209 #endif // wxUSE_MDI_ARCHITECTURE
211 // mainWindow is sized to whatever's left over. This function for backward
212 // compatibility; use LayoutWindow.
213 bool LayoutFrame(wxFrame
* frame
, wxWindow
* mainWindow
= (wxWindow
*) NULL
);
215 // mainWindow is sized to whatever's left over.
216 bool LayoutWindow(wxWindow
* frame
, wxWindow
* mainWindow
= (wxWindow
*) NULL
);