| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: 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 |
| 8 | // Modified by: |
| 9 | // Created: 04/01/98 |
| 10 | // RCS-ID: $Id$ |
| 11 | // Copyright: (c) Julian Smart |
| 12 | // Licence: wxWindows licence |
| 13 | ///////////////////////////////////////////////////////////////////////////// |
| 14 | |
| 15 | #ifndef _WX_LAYWIN_H_G_ |
| 16 | #define _WX_LAYWIN_H_G_ |
| 17 | |
| 18 | #ifdef __GNUG__ |
| 19 | #pragma interface "laywin.h" |
| 20 | #endif |
| 21 | |
| 22 | #if wxUSE_SASH |
| 23 | #include "wx/sashwin.h" |
| 24 | #endif // wxUSE_SASH |
| 25 | |
| 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() |
| 30 | |
| 31 | enum wxLayoutOrientation |
| 32 | { |
| 33 | wxLAYOUT_HORIZONTAL, |
| 34 | wxLAYOUT_VERTICAL |
| 35 | }; |
| 36 | |
| 37 | enum wxLayoutAlignment |
| 38 | { |
| 39 | wxLAYOUT_NONE, |
| 40 | wxLAYOUT_TOP, |
| 41 | wxLAYOUT_LEFT, |
| 42 | wxLAYOUT_RIGHT, |
| 43 | wxLAYOUT_BOTTOM |
| 44 | }; |
| 45 | |
| 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 |
| 50 | |
| 51 | // Use most recently used length |
| 52 | #define wxLAYOUT_MRU_LENGTH 0x0010 |
| 53 | |
| 54 | // Only a query, so don't actually move it. |
| 55 | #define wxLAYOUT_QUERY 0x0100 |
| 56 | |
| 57 | /* |
| 58 | * This event is used to get information about window alignment, |
| 59 | * orientation and size. |
| 60 | */ |
| 61 | |
| 62 | class WXDLLEXPORT wxQueryLayoutInfoEvent: public wxEvent |
| 63 | { |
| 64 | DECLARE_DYNAMIC_CLASS(wxQueryLayoutInfoEvent) |
| 65 | public: |
| 66 | |
| 67 | wxQueryLayoutInfoEvent(wxWindowID id = 0) |
| 68 | { |
| 69 | SetEventType(wxEVT_QUERY_LAYOUT_INFO); |
| 70 | m_requestedLength = 0; |
| 71 | m_flags = 0; |
| 72 | m_id = id; |
| 73 | m_alignment = wxLAYOUT_TOP; |
| 74 | m_orientation = wxLAYOUT_HORIZONTAL; |
| 75 | } |
| 76 | |
| 77 | // Read by the app |
| 78 | void SetRequestedLength(int length) { m_requestedLength = length; } |
| 79 | int GetRequestedLength() const { return m_requestedLength; } |
| 80 | |
| 81 | void SetFlags(int flags) { m_flags = flags; } |
| 82 | int GetFlags() const { return m_flags; } |
| 83 | |
| 84 | // Set by the app |
| 85 | void SetSize(const wxSize& size) { m_size = size; } |
| 86 | wxSize GetSize() const { return m_size; } |
| 87 | |
| 88 | void SetOrientation(wxLayoutOrientation orient) { m_orientation = orient; } |
| 89 | wxLayoutOrientation GetOrientation() const { return m_orientation; } |
| 90 | |
| 91 | void SetAlignment(wxLayoutAlignment align) { m_alignment = align; } |
| 92 | wxLayoutAlignment GetAlignment() const { return m_alignment; } |
| 93 | |
| 94 | protected: |
| 95 | int m_flags; |
| 96 | int m_requestedLength; |
| 97 | wxSize m_size; |
| 98 | wxLayoutOrientation m_orientation; |
| 99 | wxLayoutAlignment m_alignment; |
| 100 | |
| 101 | }; |
| 102 | |
| 103 | typedef void (wxEvtHandler::*wxQueryLayoutInfoEventFunction)(wxQueryLayoutInfoEvent&); |
| 104 | |
| 105 | #define EVT_QUERY_LAYOUT_INFO(func) \ |
| 106 | DECLARE_EVENT_TABLE_ENTRY( wxEVT_QUERY_LAYOUT_INFO, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxQueryLayoutInfoEventFunction) & func, NULL ), |
| 107 | |
| 108 | /* |
| 109 | * This event is used to take a bite out of the available client area. |
| 110 | */ |
| 111 | |
| 112 | class WXDLLEXPORT wxCalculateLayoutEvent: public wxEvent |
| 113 | { |
| 114 | DECLARE_DYNAMIC_CLASS(wxCalculateLayoutEvent) |
| 115 | public: |
| 116 | wxCalculateLayoutEvent(wxWindowID id = 0) |
| 117 | { |
| 118 | SetEventType(wxEVT_CALCULATE_LAYOUT); |
| 119 | m_flags = 0; |
| 120 | m_id = id; |
| 121 | } |
| 122 | // Read by the app |
| 123 | inline void SetFlags(int flags) { m_flags = flags; } |
| 124 | inline int GetFlags() const { return m_flags; } |
| 125 | |
| 126 | // Set by the app |
| 127 | inline void SetRect(const wxRect& rect) { m_rect = rect; } |
| 128 | inline wxRect GetRect() const { return m_rect; } |
| 129 | protected: |
| 130 | int m_flags; |
| 131 | wxRect m_rect; |
| 132 | }; |
| 133 | |
| 134 | typedef void (wxEvtHandler::*wxCalculateLayoutEventFunction)(wxCalculateLayoutEvent&); |
| 135 | |
| 136 | #define EVT_CALCULATE_LAYOUT(func) \ |
| 137 | DECLARE_EVENT_TABLE_ENTRY( wxEVT_CALCULATE_LAYOUT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCalculateLayoutEventFunction) & func, NULL ), |
| 138 | |
| 139 | #if wxUSE_SASH |
| 140 | |
| 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 |
| 145 | { |
| 146 | DECLARE_CLASS(wxSashLayoutWindow) |
| 147 | public: |
| 148 | wxSashLayoutWindow() |
| 149 | { |
| 150 | Init(); |
| 151 | } |
| 152 | |
| 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") |
| 155 | { |
| 156 | Create(parent, id, pos, size, style, name); |
| 157 | } |
| 158 | |
| 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"); |
| 161 | |
| 162 | // Accessors |
| 163 | inline wxLayoutAlignment GetAlignment() const { return m_alignment; }; |
| 164 | inline wxLayoutOrientation GetOrientation() const { return m_orientation; }; |
| 165 | |
| 166 | inline void SetAlignment(wxLayoutAlignment align) { m_alignment = align; }; |
| 167 | inline void SetOrientation(wxLayoutOrientation orient) { m_orientation = orient; }; |
| 168 | |
| 169 | // Give the window default dimensions |
| 170 | inline void SetDefaultSize(const wxSize& size) { m_defaultSize = size; } |
| 171 | |
| 172 | // Event handlers |
| 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); |
| 176 | |
| 177 | // Called by layout algorithm to retrieve information about the window. |
| 178 | void OnQueryLayoutInfo(wxQueryLayoutInfoEvent& event); |
| 179 | |
| 180 | private: |
| 181 | void Init(); |
| 182 | |
| 183 | wxLayoutAlignment m_alignment; |
| 184 | wxLayoutOrientation m_orientation; |
| 185 | wxSize m_defaultSize; |
| 186 | |
| 187 | DECLARE_EVENT_TABLE() |
| 188 | }; |
| 189 | |
| 190 | #endif // wxUSE_SASH |
| 191 | |
| 192 | class WXDLLEXPORT wxMDIParentFrame; |
| 193 | class WXDLLEXPORT wxFrame; |
| 194 | |
| 195 | // This class implements the layout algorithm |
| 196 | class WXDLLEXPORT wxLayoutAlgorithm: public wxObject |
| 197 | { |
| 198 | public: |
| 199 | wxLayoutAlgorithm() {} |
| 200 | |
| 201 | #if wxUSE_MDI_ARCHITECTURE |
| 202 | // The MDI client window is sized to whatever's left over. |
| 203 | bool LayoutMDIFrame(wxMDIParentFrame* frame, wxRect* rect = (wxRect*) NULL); |
| 204 | #endif // wxUSE_MDI_ARCHITECTURE |
| 205 | |
| 206 | // mainWindow is sized to whatever's left over. This function for backward |
| 207 | // compatibility; use LayoutWindow. |
| 208 | bool LayoutFrame(wxFrame* frame, wxWindow* mainWindow = (wxWindow*) NULL); |
| 209 | |
| 210 | // mainWindow is sized to whatever's left over. |
| 211 | bool LayoutWindow(wxWindow* frame, wxWindow* mainWindow = (wxWindow*) NULL); |
| 212 | }; |
| 213 | |
| 214 | #endif |
| 215 | // _WX_LAYWIN_H_G_ |