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 extern const int wxEVT_QUERY_LAYOUT_INFO
;
27 extern const int wxEVT_CALCULATE_LAYOUT
;
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 WXDLLEXPORT wxQueryLayoutInfoEvent
: public wxEvent
62 DECLARE_DYNAMIC_CLASS(wxQueryLayoutInfoEvent
)
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
; }
94 int m_requestedLength
;
96 wxLayoutOrientation m_orientation
;
97 wxLayoutAlignment m_alignment
;
101 typedef void (wxEvtHandler::*wxQueryLayoutInfoEventFunction
)(wxQueryLayoutInfoEvent
&);
103 #define EVT_QUERY_LAYOUT_INFO(func) \
104 wxEventTableEntry( wxEVT_QUERY_LAYOUT_INFO, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxQueryLayoutInfoEventFunction) & func, NULL ),
107 * This event is used to take a bite out of the available client area.
110 class WXDLLEXPORT wxCalculateLayoutEvent
: public wxEvent
112 DECLARE_DYNAMIC_CLASS(wxCalculateLayoutEvent
)
114 wxCalculateLayoutEvent(wxWindowID id
= 0)
116 SetEventType(wxEVT_CALCULATE_LAYOUT
);
121 inline void SetFlags(int flags
) { m_flags
= flags
; }
122 inline int GetFlags() const { return m_flags
; }
125 inline void SetRect(const wxRect
& rect
) { m_rect
= rect
; }
126 inline wxRect
GetRect() const { return m_rect
; }
132 typedef void (wxEvtHandler::*wxCalculateLayoutEventFunction
)(wxCalculateLayoutEvent
&);
134 #define EVT_CALCULATE_LAYOUT(func) \
135 wxEventTableEntry( wxEVT_CALCULATE_LAYOUT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCalculateLayoutEventFunction) & func, NULL ),
139 // This is window that can remember alignment/orientation, does its own layout,
140 // and can provide sashes too. Useful for implementing docked windows with sashes in
141 // an IDE-style interface.
142 class WXDLLEXPORT wxSashLayoutWindow
: public wxSashWindow
144 DECLARE_CLASS(wxSashLayoutWindow
)
151 wxSashLayoutWindow(wxWindow
*parent
, wxWindowID id
= -1, const wxPoint
& pos
= wxDefaultPosition
,
152 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= "layoutWindow")
154 Create(parent
, id
, pos
, size
, style
, name
);
157 bool Create(wxWindow
*parent
, wxWindowID id
= -1, const wxPoint
& pos
= wxDefaultPosition
,
158 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= "layoutWindow");
161 inline wxLayoutAlignment
GetAlignment() const { return m_alignment
; };
162 inline wxLayoutOrientation
GetOrientation() const { return m_orientation
; };
164 inline void SetAlignment(wxLayoutAlignment align
) { m_alignment
= align
; };
165 inline void SetOrientation(wxLayoutOrientation orient
) { m_orientation
= orient
; };
167 // Give the window default dimensions
168 inline void SetDefaultSize(const wxSize
& size
) { m_defaultSize
= size
; }
171 // Called by layout algorithm to allow window to take a bit out of the
172 // client rectangle, and size itself if not in wxLAYOUT_QUERY mode.
173 void OnCalculateLayout(wxCalculateLayoutEvent
& event
);
175 // Called by layout algorithm to retrieve information about the window.
176 void OnQueryLayoutInfo(wxQueryLayoutInfoEvent
& event
);
181 wxLayoutAlignment m_alignment
;
182 wxLayoutOrientation m_orientation
;
183 wxSize m_defaultSize
;
185 DECLARE_EVENT_TABLE()
190 class WXDLLEXPORT wxMDIParentFrame
;
191 class WXDLLEXPORT wxFrame
;
193 // This class implements the layout algorithm
194 class WXDLLEXPORT wxLayoutAlgorithm
: public wxObject
197 wxLayoutAlgorithm() {}
199 // The MDI client window is sized to whatever's left over.
200 bool LayoutMDIFrame(wxMDIParentFrame
* frame
, wxRect
* rect
= (wxRect
*) NULL
);
202 // mainWindow is sized to whatever's left over. This function for backward
203 // compatibility; use LayoutWindow.
204 bool LayoutFrame(wxFrame
* frame
, wxWindow
* mainWindow
= (wxWindow
*) NULL
)
206 return LayoutWindow(frame
, mainWindow
);
209 // mainWindow is sized to whatever's left over.
210 bool LayoutWindow(wxWindow
* frame
, wxWindow
* mainWindow
= (wxWindow
*) NULL
);