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(NO_GCC_PRAGMA)
19 #pragma interface "laywin.h"
23 #include "wx/sashwin.h"
26 BEGIN_DECLARE_EVENT_TYPES()
27 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_QUERY_LAYOUT_INFO
, 1500)
28 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, 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 WXDLLIMPEXP_ADV wxQueryLayoutInfoEvent
: public wxEvent
65 wxQueryLayoutInfoEvent(wxWindowID id
= 0)
67 SetEventType(wxEVT_QUERY_LAYOUT_INFO
);
68 m_requestedLength
= 0;
71 m_alignment
= wxLAYOUT_TOP
;
72 m_orientation
= wxLAYOUT_HORIZONTAL
;
76 void SetRequestedLength(int length
) { m_requestedLength
= length
; }
77 int GetRequestedLength() const { return m_requestedLength
; }
79 void SetFlags(int flags
) { m_flags
= flags
; }
80 int GetFlags() const { return m_flags
; }
83 void SetSize(const wxSize
& size
) { m_size
= size
; }
84 wxSize
GetSize() const { return m_size
; }
86 void SetOrientation(wxLayoutOrientation orient
) { m_orientation
= orient
; }
87 wxLayoutOrientation
GetOrientation() const { return m_orientation
; }
89 void SetAlignment(wxLayoutAlignment align
) { m_alignment
= align
; }
90 wxLayoutAlignment
GetAlignment() const { return m_alignment
; }
92 virtual wxEvent
*Clone() const { return new wxQueryLayoutInfoEvent(*this); }
96 int m_requestedLength
;
98 wxLayoutOrientation m_orientation
;
99 wxLayoutAlignment m_alignment
;
102 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxQueryLayoutInfoEvent
)
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 WXDLLIMPEXP_ADV wxCalculateLayoutEvent
: public wxEvent
117 wxCalculateLayoutEvent(wxWindowID id
= 0)
119 SetEventType(wxEVT_CALCULATE_LAYOUT
);
125 void SetFlags(int flags
) { m_flags
= flags
; }
126 int GetFlags() const { return m_flags
; }
129 void SetRect(const wxRect
& rect
) { m_rect
= rect
; }
130 wxRect
GetRect() const { return m_rect
; }
132 virtual wxEvent
*Clone() const { return new wxCalculateLayoutEvent(*this); }
139 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxCalculateLayoutEvent
)
142 typedef void (wxEvtHandler::*wxCalculateLayoutEventFunction
)(wxCalculateLayoutEvent
&);
144 #define EVT_CALCULATE_LAYOUT(func) \
145 DECLARE_EVENT_TABLE_ENTRY( wxEVT_CALCULATE_LAYOUT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCalculateLayoutEventFunction) & func, NULL ),
149 // This is window that can remember alignment/orientation, does its own layout,
150 // and can provide sashes too. Useful for implementing docked windows with sashes in
151 // an IDE-style interface.
152 class WXDLLIMPEXP_ADV wxSashLayoutWindow
: public wxSashWindow
160 wxSashLayoutWindow(wxWindow
*parent
, wxWindowID id
= -1, const wxPoint
& pos
= wxDefaultPosition
,
161 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= wxT("layoutWindow"))
163 Create(parent
, id
, pos
, size
, style
, name
);
166 bool Create(wxWindow
*parent
, wxWindowID id
= -1, const wxPoint
& pos
= wxDefaultPosition
,
167 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= wxT("layoutWindow"));
170 inline wxLayoutAlignment
GetAlignment() const { return m_alignment
; };
171 inline wxLayoutOrientation
GetOrientation() const { return m_orientation
; };
173 inline void SetAlignment(wxLayoutAlignment align
) { m_alignment
= align
; };
174 inline void SetOrientation(wxLayoutOrientation orient
) { m_orientation
= orient
; };
176 // Give the window default dimensions
177 inline void SetDefaultSize(const wxSize
& size
) { m_defaultSize
= size
; }
180 // Called by layout algorithm to allow window to take a bit out of the
181 // client rectangle, and size itself if not in wxLAYOUT_QUERY mode.
182 void OnCalculateLayout(wxCalculateLayoutEvent
& event
);
184 // Called by layout algorithm to retrieve information about the window.
185 void OnQueryLayoutInfo(wxQueryLayoutInfoEvent
& event
);
190 wxLayoutAlignment m_alignment
;
191 wxLayoutOrientation m_orientation
;
192 wxSize m_defaultSize
;
195 DECLARE_DYNAMIC_CLASS_NO_COPY(wxSashLayoutWindow
)
196 DECLARE_EVENT_TABLE()
201 class WXDLLEXPORT wxMDIParentFrame
;
202 class WXDLLEXPORT wxFrame
;
204 // This class implements the layout algorithm
205 class WXDLLIMPEXP_ADV wxLayoutAlgorithm
: public wxObject
208 wxLayoutAlgorithm() {}
210 #if wxUSE_MDI_ARCHITECTURE
211 // The MDI client window is sized to whatever's left over.
212 bool LayoutMDIFrame(wxMDIParentFrame
* frame
, wxRect
* rect
= (wxRect
*) NULL
);
213 #endif // wxUSE_MDI_ARCHITECTURE
215 // mainWindow is sized to whatever's left over. This function for backward
216 // compatibility; use LayoutWindow.
217 bool LayoutFrame(wxFrame
* frame
, wxWindow
* mainWindow
= (wxWindow
*) NULL
);
219 // mainWindow is sized to whatever's left over.
220 bool LayoutWindow(wxWindow
* frame
, wxWindow
* mainWindow
= (wxWindow
*) NULL
);