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 #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
; }
96 int m_requestedLength
;
98 wxLayoutOrientation m_orientation
;
99 wxLayoutAlignment m_alignment
;
103 typedef void (wxEvtHandler::*wxQueryLayoutInfoEventFunction
)(wxQueryLayoutInfoEvent
&);
105 #define EVT_QUERY_LAYOUT_INFO(func) \
106 DECLARE_EVENT_TABLE_ENTRY( wxEVT_QUERY_LAYOUT_INFO, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxQueryLayoutInfoEventFunction) & func, NULL ),
109 * This event is used to take a bite out of the available client area.
112 class WXDLLEXPORT wxCalculateLayoutEvent
: public wxEvent
114 DECLARE_DYNAMIC_CLASS(wxCalculateLayoutEvent
)
116 wxCalculateLayoutEvent(wxWindowID id
= 0)
118 SetEventType(wxEVT_CALCULATE_LAYOUT
);
123 inline void SetFlags(int flags
) { m_flags
= flags
; }
124 inline int GetFlags() const { return m_flags
; }
127 inline void SetRect(const wxRect
& rect
) { m_rect
= rect
; }
128 inline wxRect
GetRect() const { return m_rect
; }
134 typedef void (wxEvtHandler::*wxCalculateLayoutEventFunction
)(wxCalculateLayoutEvent
&);
136 #define EVT_CALCULATE_LAYOUT(func) \
137 DECLARE_EVENT_TABLE_ENTRY( wxEVT_CALCULATE_LAYOUT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCalculateLayoutEventFunction) & func, NULL ),
141 // This is window that can remember alignment/orientation, does its own layout,
142 // and can provide sashes too. Useful for implementing docked windows with sashes in
143 // an IDE-style interface.
144 class WXDLLEXPORT wxSashLayoutWindow
: public wxSashWindow
146 DECLARE_CLASS(wxSashLayoutWindow
)
153 wxSashLayoutWindow(wxWindow
*parent
, wxWindowID id
= -1, const wxPoint
& pos
= wxDefaultPosition
,
154 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= "layoutWindow")
156 Create(parent
, id
, pos
, size
, style
, name
);
159 bool Create(wxWindow
*parent
, wxWindowID id
= -1, const wxPoint
& pos
= wxDefaultPosition
,
160 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= "layoutWindow");
163 inline wxLayoutAlignment
GetAlignment() const { return m_alignment
; };
164 inline wxLayoutOrientation
GetOrientation() const { return m_orientation
; };
166 inline void SetAlignment(wxLayoutAlignment align
) { m_alignment
= align
; };
167 inline void SetOrientation(wxLayoutOrientation orient
) { m_orientation
= orient
; };
169 // Give the window default dimensions
170 inline void SetDefaultSize(const wxSize
& size
) { m_defaultSize
= size
; }
173 // Called by layout algorithm to allow window to take a bit out of the
174 // client rectangle, and size itself if not in wxLAYOUT_QUERY mode.
175 void OnCalculateLayout(wxCalculateLayoutEvent
& event
);
177 // Called by layout algorithm to retrieve information about the window.
178 void OnQueryLayoutInfo(wxQueryLayoutInfoEvent
& event
);
183 wxLayoutAlignment m_alignment
;
184 wxLayoutOrientation m_orientation
;
185 wxSize m_defaultSize
;
187 DECLARE_EVENT_TABLE()
192 class WXDLLEXPORT wxMDIParentFrame
;
193 class WXDLLEXPORT wxFrame
;
195 // This class implements the layout algorithm
196 class WXDLLEXPORT wxLayoutAlgorithm
: public wxObject
199 wxLayoutAlgorithm() {}
201 // The MDI client window is sized to whatever's left over.
202 bool LayoutMDIFrame(wxMDIParentFrame
* frame
, wxRect
* rect
= (wxRect
*) NULL
);
204 // mainWindow is sized to whatever's left over. This function for backward
205 // compatibility; use LayoutWindow.
206 bool LayoutFrame(wxFrame
* frame
, wxWindow
* mainWindow
= (wxWindow
*) NULL
)
208 return LayoutWindow(frame
, mainWindow
);
211 // mainWindow is sized to whatever's left over.
212 bool LayoutWindow(wxWindow
* frame
, wxWindow
* mainWindow
= (wxWindow
*) NULL
);