1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/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
10 // Copyright: (c) Julian Smart
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
14 #ifndef _WX_LAYWIN_H_G_
15 #define _WX_LAYWIN_H_G_
18 #include "wx/sashwin.h"
23 class WXDLLIMPEXP_FWD_ADV wxQueryLayoutInfoEvent
;
24 class WXDLLIMPEXP_FWD_ADV wxCalculateLayoutEvent
;
26 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_QUERY_LAYOUT_INFO
, wxQueryLayoutInfoEvent
);
27 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_CALCULATE_LAYOUT
, wxCalculateLayoutEvent
);
29 enum wxLayoutOrientation
35 enum wxLayoutAlignment
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
49 // Use most recently used length
50 #define wxLAYOUT_MRU_LENGTH 0x0010
52 // Only a query, so don't actually move it.
53 #define wxLAYOUT_QUERY 0x0100
56 * This event is used to get information about window alignment,
57 * orientation and size.
60 class WXDLLIMPEXP_ADV wxQueryLayoutInfoEvent
: public wxEvent
63 wxQueryLayoutInfoEvent(wxWindowID id
= 0)
65 SetEventType(wxEVT_QUERY_LAYOUT_INFO
);
66 m_requestedLength
= 0;
69 m_alignment
= wxLAYOUT_TOP
;
70 m_orientation
= wxLAYOUT_HORIZONTAL
;
74 void SetRequestedLength(int length
) { m_requestedLength
= length
; }
75 int GetRequestedLength() const { return m_requestedLength
; }
77 void SetFlags(int flags
) { m_flags
= flags
; }
78 int GetFlags() const { return m_flags
; }
81 void SetSize(const wxSize
& size
) { m_size
= size
; }
82 wxSize
GetSize() const { return m_size
; }
84 void SetOrientation(wxLayoutOrientation orient
) { m_orientation
= orient
; }
85 wxLayoutOrientation
GetOrientation() const { return m_orientation
; }
87 void SetAlignment(wxLayoutAlignment align
) { m_alignment
= align
; }
88 wxLayoutAlignment
GetAlignment() const { return m_alignment
; }
90 virtual wxEvent
*Clone() const { return new wxQueryLayoutInfoEvent(*this); }
94 int m_requestedLength
;
96 wxLayoutOrientation m_orientation
;
97 wxLayoutAlignment m_alignment
;
100 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxQueryLayoutInfoEvent
)
103 typedef void (wxEvtHandler::*wxQueryLayoutInfoEventFunction
)(wxQueryLayoutInfoEvent
&);
105 #define wxQueryLayoutInfoEventHandler( func ) \
106 wxEVENT_HANDLER_CAST( wxQueryLayoutInfoEventFunction, func )
108 #define EVT_QUERY_LAYOUT_INFO(func) \
109 wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_QUERY_LAYOUT_INFO, wxID_ANY, wxID_ANY, wxQueryLayoutInfoEventHandler( func ), NULL ),
112 * This event is used to take a bite out of the available client area.
115 class WXDLLIMPEXP_ADV wxCalculateLayoutEvent
: public wxEvent
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 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxCalculateLayoutEvent
)
143 typedef void (wxEvtHandler::*wxCalculateLayoutEventFunction
)(wxCalculateLayoutEvent
&);
145 #define wxCalculateLayoutEventHandler( func ) wxEVENT_HANDLER_CAST(wxCalculateLayoutEventFunction, func)
147 #define EVT_CALCULATE_LAYOUT(func) \
148 wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_CALCULATE_LAYOUT, wxID_ANY, wxID_ANY, wxCalculateLayoutEventHandler( func ), NULL ),
152 // This is window that can remember alignment/orientation, does its own layout,
153 // and can provide sashes too. Useful for implementing docked windows with sashes in
154 // an IDE-style interface.
155 class WXDLLIMPEXP_ADV wxSashLayoutWindow
: public wxSashWindow
163 wxSashLayoutWindow(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
164 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= wxT("layoutWindow"))
166 Create(parent
, id
, pos
, size
, style
, name
);
169 bool Create(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
170 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= wxT("layoutWindow"));
173 inline wxLayoutAlignment
GetAlignment() const { return m_alignment
; }
174 inline wxLayoutOrientation
GetOrientation() const { return m_orientation
; }
176 inline void SetAlignment(wxLayoutAlignment align
) { m_alignment
= align
; }
177 inline void SetOrientation(wxLayoutOrientation orient
) { m_orientation
= orient
; }
179 // Give the window default dimensions
180 inline void SetDefaultSize(const wxSize
& size
) { m_defaultSize
= size
; }
183 // Called by layout algorithm to allow window to take a bit out of the
184 // client rectangle, and size itself if not in wxLAYOUT_QUERY mode.
185 void OnCalculateLayout(wxCalculateLayoutEvent
& event
);
187 // Called by layout algorithm to retrieve information about the window.
188 void OnQueryLayoutInfo(wxQueryLayoutInfoEvent
& event
);
193 wxLayoutAlignment m_alignment
;
194 wxLayoutOrientation m_orientation
;
195 wxSize m_defaultSize
;
198 DECLARE_DYNAMIC_CLASS_NO_COPY(wxSashLayoutWindow
)
199 DECLARE_EVENT_TABLE()
204 class WXDLLIMPEXP_FWD_CORE wxMDIParentFrame
;
205 class WXDLLIMPEXP_FWD_CORE wxFrame
;
207 // This class implements the layout algorithm
208 class WXDLLIMPEXP_ADV wxLayoutAlgorithm
: public wxObject
211 wxLayoutAlgorithm() {}
213 #if wxUSE_MDI_ARCHITECTURE
214 // The MDI client window is sized to whatever's left over.
215 bool LayoutMDIFrame(wxMDIParentFrame
* frame
, wxRect
* rect
= NULL
);
216 #endif // wxUSE_MDI_ARCHITECTURE
218 // mainWindow is sized to whatever's left over. This function for backward
219 // compatibility; use LayoutWindow.
220 bool LayoutFrame(wxFrame
* frame
, wxWindow
* mainWindow
= NULL
);
222 // mainWindow is sized to whatever's left over.
223 bool LayoutWindow(wxWindow
* frame
, wxWindow
* mainWindow
= NULL
);