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
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 class WXDLLIMPEXP_FWD_ADV wxQueryLayoutInfoEvent
;
25 class WXDLLIMPEXP_FWD_ADV wxCalculateLayoutEvent
;
27 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_QUERY_LAYOUT_INFO
, wxQueryLayoutInfoEvent
);
28 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_CALCULATE_LAYOUT
, wxCalculateLayoutEvent
);
30 enum wxLayoutOrientation
36 enum wxLayoutAlignment
45 // Not sure this is necessary
46 // Tell window which dimension we're sizing on
47 #define wxLAYOUT_LENGTH_Y 0x0008
48 #define wxLAYOUT_LENGTH_X 0x0000
50 // Use most recently used length
51 #define wxLAYOUT_MRU_LENGTH 0x0010
53 // Only a query, so don't actually move it.
54 #define wxLAYOUT_QUERY 0x0100
57 * This event is used to get information about window alignment,
58 * orientation and size.
61 class WXDLLIMPEXP_ADV wxQueryLayoutInfoEvent
: public wxEvent
64 wxQueryLayoutInfoEvent(wxWindowID id
= 0)
66 SetEventType(wxEVT_QUERY_LAYOUT_INFO
);
67 m_requestedLength
= 0;
70 m_alignment
= wxLAYOUT_TOP
;
71 m_orientation
= wxLAYOUT_HORIZONTAL
;
75 void SetRequestedLength(int length
) { m_requestedLength
= length
; }
76 int GetRequestedLength() const { return m_requestedLength
; }
78 void SetFlags(int flags
) { m_flags
= flags
; }
79 int GetFlags() const { return m_flags
; }
82 void SetSize(const wxSize
& size
) { m_size
= size
; }
83 wxSize
GetSize() const { return m_size
; }
85 void SetOrientation(wxLayoutOrientation orient
) { m_orientation
= orient
; }
86 wxLayoutOrientation
GetOrientation() const { return m_orientation
; }
88 void SetAlignment(wxLayoutAlignment align
) { m_alignment
= align
; }
89 wxLayoutAlignment
GetAlignment() const { return m_alignment
; }
91 virtual wxEvent
*Clone() const { return new wxQueryLayoutInfoEvent(*this); }
95 int m_requestedLength
;
97 wxLayoutOrientation m_orientation
;
98 wxLayoutAlignment m_alignment
;
101 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxQueryLayoutInfoEvent
)
104 typedef void (wxEvtHandler::*wxQueryLayoutInfoEventFunction
)(wxQueryLayoutInfoEvent
&);
106 #define wxQueryLayoutInfoEventHandler( func ) \
107 wxEVENT_HANDLER_CAST( wxQueryLayoutInfoEventFunction, func )
109 #define EVT_QUERY_LAYOUT_INFO(func) \
110 wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_QUERY_LAYOUT_INFO, wxID_ANY, wxID_ANY, wxQueryLayoutInfoEventHandler( func ), NULL ),
113 * This event is used to take a bite out of the available client area.
116 class WXDLLIMPEXP_ADV wxCalculateLayoutEvent
: public wxEvent
119 wxCalculateLayoutEvent(wxWindowID id
= 0)
121 SetEventType(wxEVT_CALCULATE_LAYOUT
);
127 void SetFlags(int flags
) { m_flags
= flags
; }
128 int GetFlags() const { return m_flags
; }
131 void SetRect(const wxRect
& rect
) { m_rect
= rect
; }
132 wxRect
GetRect() const { return m_rect
; }
134 virtual wxEvent
*Clone() const { return new wxCalculateLayoutEvent(*this); }
141 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxCalculateLayoutEvent
)
144 typedef void (wxEvtHandler::*wxCalculateLayoutEventFunction
)(wxCalculateLayoutEvent
&);
146 #define wxCalculateLayoutEventHandler( func ) wxEVENT_HANDLER_CAST(wxCalculateLayoutEventFunction, func)
148 #define EVT_CALCULATE_LAYOUT(func) \
149 wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_CALCULATE_LAYOUT, wxID_ANY, wxID_ANY, wxCalculateLayoutEventHandler( func ), NULL ),
153 // This is window that can remember alignment/orientation, does its own layout,
154 // and can provide sashes too. Useful for implementing docked windows with sashes in
155 // an IDE-style interface.
156 class WXDLLIMPEXP_ADV wxSashLayoutWindow
: public wxSashWindow
164 wxSashLayoutWindow(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
165 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= wxT("layoutWindow"))
167 Create(parent
, id
, pos
, size
, style
, name
);
170 bool Create(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
171 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= wxT("layoutWindow"));
174 inline wxLayoutAlignment
GetAlignment() const { return m_alignment
; }
175 inline wxLayoutOrientation
GetOrientation() const { return m_orientation
; }
177 inline void SetAlignment(wxLayoutAlignment align
) { m_alignment
= align
; }
178 inline void SetOrientation(wxLayoutOrientation orient
) { m_orientation
= orient
; }
180 // Give the window default dimensions
181 inline void SetDefaultSize(const wxSize
& size
) { m_defaultSize
= size
; }
184 // Called by layout algorithm to allow window to take a bit out of the
185 // client rectangle, and size itself if not in wxLAYOUT_QUERY mode.
186 void OnCalculateLayout(wxCalculateLayoutEvent
& event
);
188 // Called by layout algorithm to retrieve information about the window.
189 void OnQueryLayoutInfo(wxQueryLayoutInfoEvent
& event
);
194 wxLayoutAlignment m_alignment
;
195 wxLayoutOrientation m_orientation
;
196 wxSize m_defaultSize
;
199 DECLARE_DYNAMIC_CLASS_NO_COPY(wxSashLayoutWindow
)
200 DECLARE_EVENT_TABLE()
205 class WXDLLIMPEXP_FWD_CORE wxMDIParentFrame
;
206 class WXDLLIMPEXP_FWD_CORE wxFrame
;
208 // This class implements the layout algorithm
209 class WXDLLIMPEXP_ADV wxLayoutAlgorithm
: public wxObject
212 wxLayoutAlgorithm() {}
214 #if wxUSE_MDI_ARCHITECTURE
215 // The MDI client window is sized to whatever's left over.
216 bool LayoutMDIFrame(wxMDIParentFrame
* frame
, wxRect
* rect
= NULL
);
217 #endif // wxUSE_MDI_ARCHITECTURE
219 // mainWindow is sized to whatever's left over. This function for backward
220 // compatibility; use LayoutWindow.
221 bool LayoutFrame(wxFrame
* frame
, wxWindow
* mainWindow
= NULL
);
223 // mainWindow is sized to whatever's left over.
224 bool LayoutWindow(wxWindow
* frame
, wxWindow
* mainWindow
= NULL
);