]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/generic/laywin.cpp
Added distribution script
[wxWidgets.git] / src / generic / laywin.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: laywin.cpp
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#ifdef __GNUG__
16#pragma implementation "laywin.h"
17#endif
18
19// For compilers that support precompilation, includes "wx/wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23#pragma hdrstop
24#endif
25
26#ifndef WX_PRECOMP
27#include "wx/wx.h"
28#include "wx/mdi.h"
29#endif
30
31#include "wx/laywin.h"
32
33IMPLEMENT_DYNAMIC_CLASS(wxQueryLayoutInfoEvent, wxEvent)
34IMPLEMENT_DYNAMIC_CLASS(wxCalculateLayoutEvent, wxEvent)
35
36IMPLEMENT_CLASS(wxSashLayoutWindow, wxSashWindow)
37
38BEGIN_EVENT_TABLE(wxSashLayoutWindow, wxSashWindow)
39 EVT_CALCULATE_LAYOUT(wxSashLayoutWindow::OnCalculateLayout)
40 EVT_QUERY_LAYOUT_INFO(wxSashLayoutWindow::OnQueryLayoutInfo)
41END_EVENT_TABLE()
42
43wxSashLayoutWindow::wxSashLayoutWindow(wxWindow *parent, wxWindowID id, const wxPoint& pos,
44 const wxSize& size, long style, const wxString& name):
45 wxSashWindow(parent, id, pos, size, style, name)
46{
47 m_orientation = wxLAYOUT_HORIZONTAL;
48 m_alignment = wxLAYOUT_TOP;
49}
50
51// This is the function that wxLayoutAlgorithm calls to ascertain the window
52// dimensions.
53void wxSashLayoutWindow::OnQueryLayoutInfo(wxQueryLayoutInfoEvent& event)
54{
55 // int flags = event.GetFlags();
56 int requestedLength = event.GetRequestedLength();
57
58 event.SetOrientation(m_orientation);
59 event.SetAlignment(m_alignment);
60
61 if (m_orientation == wxLAYOUT_HORIZONTAL)
62 event.SetSize(wxSize(requestedLength, m_defaultSize.y));
63 else
64 event.SetSize(wxSize(m_defaultSize.x, requestedLength));
65}
66
67// Called by parent to allow window to take a bit out of the
68// client rectangle, and size itself if not in wxLAYOUT_QUERY mode.
69
70void wxSashLayoutWindow::OnCalculateLayout(wxCalculateLayoutEvent& event)
71{
72 wxRect clientSize(event.GetRect());
73
74 int flags = event.GetFlags();
75
76 if (!IsShown())
77 return;
78
79 // Let's assume that all windows stretch the full extent of the window in
80 // the direction of that window orientation. This will work for non-docking toolbars,
81 // and the status bar. Note that the windows have to have been created in a certain
82 // order to work, else you might get a left-aligned window going to the bottom
83 // of the window, and the status bar appearing to the right of it. The
84 // status bar would have to be created after or before the toolbar(s).
85
86 wxRect thisRect;
87
88 // Try to stretch
89 int length = (GetOrientation() == wxLAYOUT_HORIZONTAL) ? clientSize.width : clientSize.height;
90 wxLayoutOrientation orient = GetOrientation();
91
92 // We assume that a window that says it's horizontal, wants to be stretched in that
93 // direction. Is this distinction too fine? Do we assume that any horizontal
94 // window needs to be stretched in that direction? Possibly.
95 int whichDimension = (GetOrientation() == wxLAYOUT_HORIZONTAL) ? wxLAYOUT_LENGTH_X : wxLAYOUT_LENGTH_Y;
96
97 wxQueryLayoutInfoEvent infoEvent(GetId());
98 infoEvent.SetEventObject(this);
99 infoEvent.SetRequestedLength(length);
100 infoEvent.SetFlags(orient | whichDimension);
101
102 if (!GetEventHandler()->ProcessEvent(infoEvent))
103 return;
104
105 wxSize sz = infoEvent.GetSize();
106
107 if (sz.x == 0 && sz.y == 0) // Assume it's invisible
108 return;
109
110 // Now we know the size it wants to be. We wish to decide where to place it, i.e.
111 // how it's aligned.
112 switch (GetAlignment())
113 {
114 case wxLAYOUT_TOP:
115 {
116 thisRect.x = clientSize.x; thisRect.y = clientSize.y;
117 thisRect.width = sz.x; thisRect.height = sz.y;
118 clientSize.y += thisRect.height;
119 clientSize.height -= thisRect.height;
120 break;
121 }
122 case wxLAYOUT_LEFT:
123 {
124 thisRect.x = clientSize.x; thisRect.y = clientSize.y;
125 thisRect.width = sz.x; thisRect.height = sz.y;
126 clientSize.x += thisRect.width;
127 clientSize.width -= thisRect.width;
128 break;
129 }
130 case wxLAYOUT_RIGHT:
131 {
132 thisRect.x = clientSize.x + (clientSize.width - sz.x); thisRect.y = clientSize.y;
133 thisRect.width = sz.x; thisRect.height = sz.y;
134 clientSize.width -= thisRect.width;
135 break;
136 }
137 case wxLAYOUT_BOTTOM:
138 {
139 thisRect.x = clientSize.x; thisRect.y = clientSize.y + (clientSize.height - sz.y);
140 thisRect.width = sz.x; thisRect.height = sz.y;
141 clientSize.height -= thisRect.height;
142 break;
143 }
144 case wxLAYOUT_NONE:
145 {
146 break;
147 }
148
149 }
150
151 if ((flags & wxLAYOUT_QUERY) == 0)
152 {
153 // If not in query mode, resize the window.
154 // TODO: add wxRect& form to wxWindow::SetSize
155 SetSize(thisRect.x, thisRect.y, thisRect.width, thisRect.height);
156 }
157
158 event.SetRect(clientSize);
159}
160
161/*
162 * wxLayoutAlgorithm
163 */
164
165// Lays out windows for an MDI frame. The MDI client area gets what's left
166// over.
167bool wxLayoutAlgorithm::LayoutMDIFrame(wxMDIParentFrame* frame, wxRect* r)
168{
169 int cw, ch;
170 frame->GetClientSize(& cw, & ch);
171
172 wxRect rect(0, 0, cw, ch);
173 if (r)
174 rect = * r;
175
176 wxCalculateLayoutEvent event;
177 event.SetRect(rect);
178
179 wxNode* node = frame->GetChildren().First();
180 while (node)
181 {
182 wxWindow* win = (wxWindow*) node->Data();
183
184 event.SetId(win->GetId());
185 event.SetEventObject(win);
186 event.SetFlags(0); // ??
187
188 win->GetEventHandler()->ProcessEvent(event);
189
190 node = node->Next();
191 }
192
193 wxWindow* clientWindow = frame->GetClientWindow();
194
195 rect = event.GetRect();
196
197 clientWindow->SetSize(rect.x, rect.y, rect.width, rect.height);
198
199 return TRUE;
200}
201
202// Layout algorithm for normal frame. mainWindow gets what's left over.
203bool wxLayoutAlgorithm::LayoutFrame(wxFrame* frame, wxWindow* mainWindow)
204{
205 int cw, ch;
206 frame->GetClientSize(& cw, & ch);
207
208 wxRect rect(0, 0, cw, ch);
209
210 wxCalculateLayoutEvent event;
211 event.SetRect(rect);
212
213 wxNode* node = frame->GetChildren().First();
214 while (node)
215 {
216 wxWindow* win = (wxWindow*) node->Data();
217
218 event.SetId(win->GetId());
219 event.SetEventObject(win);
220 event.SetFlags(0); // ??
221
222 win->GetEventHandler()->ProcessEvent(event);
223
224 node = node->Next();
225 }
226
227 rect = event.GetRect();
228
229 if (mainWindow)
230 mainWindow->SetSize(rect.x, rect.y, rect.width, rect.height);
231
232 return TRUE;
233}
234