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"
22 #include "wx/sashwin.h"
24 const wxEventType wxEVT_QUERY_LAYOUT_INFO
= wxEVT_FIRST
+ 1500;
25 const wxEventType wxEVT_CALCULATE_LAYOUT
= wxEVT_FIRST
+ 1501;
27 enum wxLayoutOrientation
{
32 enum wxLayoutAlignment
{
40 // Not sure this is necessary
41 // Tell window which dimension we're sizing on
42 #define wxLAYOUT_LENGTH_Y 0x0008
43 #define wxLAYOUT_LENGTH_X 0x0000
45 // Use most recently used length
46 #define wxLAYOUT_MRU_LENGTH 0x0010
48 // Only a query, so don't actually move it.
49 #define wxLAYOUT_QUERY 0x0100
52 * This event is used to get information about window alignment,
53 * orientation and size.
56 class wxQueryLayoutInfoEvent
: public wxEvent
58 DECLARE_DYNAMIC_CLASS(wxQueryLayoutInfoEvent
)
61 wxQueryLayoutInfoEvent(wxWindowID id
= 0)
63 SetEventType(wxEVT_QUERY_LAYOUT_INFO
);
64 m_requestedLength
= 0;
67 m_alignment
= wxLAYOUT_TOP
;
68 m_orientation
= wxLAYOUT_HORIZONTAL
;
71 inline void SetRequestedLength(int length
) { m_requestedLength
= length
; }
72 inline int GetRequestedLength() const { return m_requestedLength
; }
74 inline void SetFlags(int flags
) { m_flags
= flags
; }
75 inline int GetFlags() const { return m_flags
; }
78 inline void SetSize(const wxSize
& size
) { m_size
= size
; }
79 inline wxSize
GetSize() const { return m_size
; }
81 inline void SetOrientation(wxLayoutOrientation orient
) { m_orientation
= orient
; }
82 inline wxLayoutOrientation
GetOrientation() const { return m_orientation
; }
84 inline void SetAlignment(wxLayoutAlignment align
) { m_alignment
= align
; }
85 inline wxLayoutAlignment
GetAlignment() const { return m_alignment
; }
88 int m_requestedLength
;
90 wxLayoutOrientation m_orientation
;
91 wxLayoutAlignment m_alignment
;
95 typedef void (wxEvtHandler::*wxQueryLayoutInfoEventFunction
)(wxQueryLayoutInfoEvent
&);
97 #define EVT_QUERY_LAYOUT_INFO(func) { wxEVT_QUERY_LAYOUT_INFO, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxQueryLayoutInfoEventFunction) & func, NULL },
100 * This event is used to take a bite out of the available client area.
103 class wxCalculateLayoutEvent
: public wxEvent
105 DECLARE_DYNAMIC_CLASS(wxCalculateLayoutEvent
)
107 wxCalculateLayoutEvent(wxWindowID id
= 0)
109 SetEventType(wxEVT_CALCULATE_LAYOUT
);
114 inline void SetFlags(int flags
) { m_flags
= flags
; }
115 inline int GetFlags() const { return m_flags
; }
118 inline void SetRect(const wxRect
& rect
) { m_rect
= rect
; }
119 inline wxRect
GetRect() const { return m_rect
; }
125 typedef void (wxEvtHandler::*wxCalculateLayoutEventFunction
)(wxCalculateLayoutEvent
&);
127 #define EVT_CALCULATE_LAYOUT(func) { wxEVT_CALCULATE_LAYOUT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCalculateLayoutEventFunction) & func, NULL },
129 // This is window that can remember alignment/orientation, does its own layout,
130 // and can provide sashes too. Useful for implementing docked windows with sashes in
131 // an IDE-style interface.
132 class wxSashLayoutWindow
: public wxSashWindow
134 DECLARE_CLASS(wxSashLayoutWindow
)
136 wxSashLayoutWindow(wxWindow
*parent
, wxWindowID id
= -1, const wxPoint
& pos
= wxDefaultPosition
,
137 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= "layoutWindow");
140 inline wxLayoutAlignment
GetAlignment() const { return m_alignment
; };
141 inline wxLayoutOrientation
GetOrientation() const { return m_orientation
; };
143 inline void SetAlignment(wxLayoutAlignment align
) { m_alignment
= align
; };
144 inline void SetOrientation(wxLayoutOrientation orient
) { m_orientation
= orient
; };
146 // Give the window default dimensions
147 inline void SetDefaultSize(const wxSize
& size
) { m_defaultSize
= size
; }
150 // Called by layout algorithm to allow window to take a bit out of the
151 // client rectangle, and size itself if not in wxLAYOUT_QUERY mode.
152 void OnCalculateLayout(wxCalculateLayoutEvent
& event
);
154 // Called by layout algorithm to retrieve information about the window.
155 void OnQueryLayoutInfo(wxQueryLayoutInfoEvent
& event
);
157 wxLayoutAlignment m_alignment
;
158 wxLayoutOrientation m_orientation
;
159 wxSize m_defaultSize
;
161 DECLARE_EVENT_TABLE()
164 class WXDLLEXPORT wxMDIParentFrame
;
165 class WXDLLEXPORT wxFrame
;
167 // This class implements the layout algorithm
168 class wxLayoutAlgorithm
: public wxObject
171 wxLayoutAlgorithm() {}
173 // The MDI client window is sized to whatever's left over.
174 bool LayoutMDIFrame(wxMDIParentFrame
* frame
, wxRect
* rect
= (wxRect
*) NULL
);
176 // mainWindow is sized to whatever's left over.
177 bool LayoutFrame(wxFrame
* frame
, wxWindow
* mainWindow
= (wxWindow
*) NULL
);