]> git.saurik.com Git - wxWidgets.git/blame - utils/framelayout/src/gcupdatesmgr.cpp
bump date on 'easter egg' dialog.
[wxWidgets.git] / utils / framelayout / src / gcupdatesmgr.cpp
CommitLineData
bd9396d5
HH
1/////////////////////////////////////////////////////////////////////////////
2// Name: No names yet.
3// Purpose: Contrib. demo
4// Author: Aleksandras Gluchovas
5// Modified by:
6// Created: 19/10/98
7// RCS-ID: $Id$
8// Copyright: (c) Aleksandras Gluchovas
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "updatesmgr.h"
14// #pragma interface
15#endif
16
17// For compilers that support precompilation, includes "wx.h".
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
21#pragma hdrstop
22#endif
23
24#ifndef WX_PRECOMP
25#include "wx/wx.h"
26#endif
27
28#include "gcupdatesmgr.h"
29
30// helper function
31
32static inline bool rect_hits_rect( const wxRect& r1, const wxRect& r2 )
33{
34 if ( ( r2.x >= r1.x && r2.x <= r1.x + r1.width ) ||
35 ( r1.x >= r2.x && r1.x <= r2.x + r2.width ) )
36
37 if ( ( r2.y >= r1.y && r2.y <= r1.y + r1.height ) ||
38 ( r1.y >= r2.y && r1.y <= r2.y + r2.height ) )
39
40 return 1;
41
42 return 0;
43}
44
45// helper structure
46
47struct cbRectInfo
48{
49 cbBarInfo* mpBar;
50 cbDockPane* mpPane;
51 wxRect* mpCurBounds;
52 wxRect* mpPrevBounds;
53};
54
55static inline cbRectInfo& node_to_rect_info( wxNode* pNode )
56{
57 return *( (cbRectInfo*) (pNode->Data()) );
58}
59
60/***** Implementation for class cbSimpleUpdatesMgr *****/
61
62IMPLEMENT_DYNAMIC_CLASS( cbGCUpdatesMgr, cbSimpleUpdatesMgr )
63
64cbGCUpdatesMgr::cbGCUpdatesMgr( wxFrameLayout* pPanel )
65 : cbSimpleUpdatesMgr( pPanel )
66{}
67
68void cbGCUpdatesMgr::AddItem( wxList& itemList,
69 cbBarInfo* pBar,
70 cbDockPane* pPane,
71 wxRect& curBounds,
72 wxRect& prevBounds )
73{
74 cbRectInfo* pInfo = new cbRectInfo();
75
76 pInfo->mpBar = pBar;
77 pInfo->mpPane = pPane;
78 pInfo->mpCurBounds = &curBounds;
79 pInfo->mpPrevBounds = &prevBounds;
80
81 itemList.Append( (wxObject*) pInfo );
82}
83
84void cbGCUpdatesMgr::OnStartChanges()
85{
86 // memorize states of ALL items in the layout -
87 // this is quite excessive, but OK for the decent
88 // implementation of updates manager
89
90 mpLayout->GetPrevClientRect() = mpLayout->GetClientRect();
91
92 cbDockPane** panes = mpLayout->GetPanesArray();
93
94 for( int n = 0; n != MAX_PANES; ++n )
95 {
96 cbDockPane& pane = *(panes[n]);
97
98 // store pane state
99 pane.mUMgrData.StoreItemState( pane.mBoundsInParent );
100 pane.mUMgrData.SetDirty( FALSE );
101
102 cbRowInfo* pRow = pane.GetFirstRow();
103
104 while ( pRow )
105 {
106 cbBarInfo* pBar = pRow->GetFirstBar();
107
108 // store row state
109 pRow->mUMgrData.StoreItemState( pRow->mBoundsInParent );
110 pRow->mUMgrData.SetDirty( FALSE );
111
112 while( pBar )
113 {
114 // store bar state
115 pBar->mUMgrData.StoreItemState( pBar->mBoundsInParent );
116 pBar->mUMgrData.SetDirty( FALSE );
117
118 pBar = pBar->mpNext;
119 }
120
121 pRow = pRow->mpNext;
122 }
123 }
124}
125
126void cbGCUpdatesMgr::UpdateNow()
127{
128 cbDockPane** panes = mpLayout->GetPanesArray();
129
130 wxRect& r1 = mpLayout->GetClientRect();
131 wxRect& r2 = mpLayout->GetPrevClientRect();
132
133 // detect changes in client window's area
134
135 bool clientWindowChanged = ( r1.x != r2.x ||
136 r1.y != r2.y ||
137 r1.width != r2.width ||
138 r1.height != r2.height );
139
140 // step #1 - detect changes in each row of each pane,
141 // and repaint decorations around changed windows
142
143 wxList mBarsToResize;
144
145 for( int n = 0; n != MAX_PANES; ++n )
146 {
147 cbDockPane& pane = *(panes[n]);
148
149 bool paneChanged = WasChanged( pane.mUMgrData, pane.mBoundsInParent );
150
151 if ( paneChanged )
152 {
153 wxClientDC dc( &mpLayout->GetParentFrame() );
154 pane.PaintPaneBackground( dc );
155 }
156
157 wxRect realBounds;
158
159 cbRowInfo* pRow = pane.GetFirstRow();
160
161 while ( pRow )
162 {
163 wxDC* pDc = 0;
164
165 cbBarInfo* pBar = pRow->GetFirstBar();
166
167 bool rowChanged = FALSE;
168 bool rowBkPainted = FALSE;
169
170 // FIXME:: the below should not be fixed
171 cbBarInfo* barsToRepaint[128];
172 // number of bars, that were changed in the current row
173 int nBars = 0;
174
175 wxRect r1 = pRow->mUMgrData.mPrevBounds;
176 wxRect r2 = pRow->mBoundsInParent;
177
178 if ( WasChanged( pRow->mUMgrData, pRow->mBoundsInParent ) )
179
180 rowChanged = TRUE;
181 else
182 while( pBar )
183 {
184 if ( WasChanged( pBar->mUMgrData, pBar->mBoundsInParent ) )
185
186 barsToRepaint[nBars++] = pBar;
187
188 pBar = pBar->mpNext;
189 }
190
191 if ( nBars || rowChanged )
192 {
193 realBounds = pRow->mBoundsInParent;
194
195 // include 1-pixel thick shades around the row
196 realBounds.x -= 1;
197 realBounds.y -= 1;
198 realBounds.width += 2;
199 realBounds.height += 2;
200
201 pDc = pane.StartDrawInArea( realBounds );
202 }
203
204 if ( rowChanged )
205 {
206 // postphone the resizement and refreshing the changed
207 // bar windows
208
209 cbBarInfo* pCurBar = pRow->GetFirstBar();
210
211 while( pCurBar )
212 {
213 if ( WasChanged( pCurBar->mUMgrData,
214 pCurBar->mBoundsInParent ) )
215
216 AddItem( mBarsToResize, pCurBar, &pane,
217 pCurBar->mBoundsInParent,
218 pCurBar->mUMgrData.mPrevBounds );
219
220 pCurBar = pCurBar->mpNext;
221 }
222
223 // draw only their decorations now
224
225 pane.PaintRow( pRow, *pDc );
226 }
227 else
228 if ( nBars != 0 )
229 {
230 for( int i = 0; i != nBars; ++i )
231
232 // postphone the resizement and refreshing the changed
233 // bar windows
234
235 AddItem( mBarsToResize,
236 barsToRepaint[i],
237 &pane,
238 barsToRepaint[i]->mBoundsInParent,
239 barsToRepaint[i]->mUMgrData.mPrevBounds );
240
241 // redraw decorations of entire row, regardless of how much
242 // of the bars were changed
243
244 pane.PaintRow( pRow, *pDc );
245 }
246
247 if ( pDc )
248
249 pane.FinishDrawInArea( realBounds );
250
251 pRow = pRow->mpNext;
252
253 } // end of while
254
255 if ( paneChanged )
256 {
257 wxClientDC dc( &mpLayout->GetParentFrame() );
258 pane.PaintPaneDecorations( dc );
259 }
260
261 } // end of for
262
263 if ( clientWindowChanged && !mpLayout->mClientWndRefreshPending )
264 {
265 // ptr to client-window object is "marked" as NULL
266
267 AddItem( mBarsToResize, NULL, NULL,
268 mpLayout->GetClientRect(),
269 mpLayout->GetPrevClientRect() );
270 }
271
272 // step #2 - do ordered refreshing and resizing of bar window objects now
273
274 DoRepositionItems( mBarsToResize );
275}
276
277void cbGCUpdatesMgr::DoRepositionItems( wxList& items )
278{
279 wxNode* pNode1 = items.First();
280
281 while( pNode1 )
282 {
283 cbRectInfo& info = node_to_rect_info( pNode1 );
284
285 wxNode* pNode2 = items.First();
286
287 // and node itself
288
289 mGC.AddObject( &info );
290
291 while( pNode2 )
292 {
293 if ( pNode2 != pNode1 ) // node should not depend on itself
294 {
295 // add references to objects, on which this object
296 // depends. Dependecy here indicates intersection of current
297 // bounds of this object with the initial bounds of the
298 // other object
299
300 cbRectInfo& otherInfo = node_to_rect_info( pNode2 );
301
302 if ( rect_hits_rect( *info.mpCurBounds, *otherInfo.mpPrevBounds ) )
303
304 // the node depends on node
305 mGC.AddDependency( &info, &otherInfo );
306 }
307
308 pNode2 = pNode2->Next();
309 }
310
311 pNode1 = pNode1->Next();
312 }
313
314 mGC.ArrangeCollection(); // order nodes according "least-dependency" rule,
315 // and find out cycled chains
316
317 // regular item nodes need to be resized, but not repainted (since
318 // they stand in linear (not cyclic) dependency with other
319 // regular nodes)
320
321 wxNode* pNode = mGC.GetRegularObjects().First();
322
323 while ( pNode )
324 {
325 cbRectInfo& info = *((cbRectInfo*)gc_node_to_obj(pNode));
326
327 if ( info.mpBar == NULL )
328
329 mpLayout->PositionClientWindow();
330 else
331 info.mpPane->SizeBar( info.mpBar );
332
333 pNode = pNode->Next();
334 }
335
336 // cycled item nodes, need to be both resized and repainted
337
338 pNode = mGC.GetCycledObjects().First();
339
340 while ( pNode )
341 {
342 cbRectInfo& info = *((cbRectInfo*)gc_node_to_obj(pNode));
343
344 if ( info.mpBar == NULL )
345 {
346 wxWindow* pClntWnd = mpLayout->GetFrameClient();
347
348 mpLayout->PositionClientWindow();
349
350 // FIXME FIXME:: excessive!
351
352 pClntWnd->Show( FALSE );
353 pClntWnd->Show( TRUE );
354
355 // OLD STUFF:: mpLayout->PositionClientWindow();
356 }
357 else
358 if ( info.mpBar->mpBarWnd )
359 {
360 wxWindow* pWnd = info.mpBar->mpBarWnd;
361
362 // resize
363 info.mpPane->SizeBar( info.mpBar );
364
365 // repaint
366
367 /* OLD STUFF:: bool isChoice = info.mpBar->IsKindOf( CLASSINFO( wxChoice ) );
368
369 //#ifdef __WINDOWS__
370 //int result = ::SendMessage( (HWND)pWnd->m_hWnd, WM_NCPAINT, 0, 0 );
371 //#endif
372 */
373
374 // FIXME FIXME:: there's no other way to repaint non-client area of the wxWindow!!
375 // so we do *excessive* "hide 'n show"
376
377 pWnd->Show(FALSE);
378 pWnd->Show(TRUE);
379
380 pWnd->Refresh();
381 }
382
383 pNode = pNode->Next();
384 }
385
386 // release data prepared for GC alg.
387
388 pNode = items.First();
389
390 while( pNode )
391 {
392 cbRectInfo* pInfo = (cbRectInfo*)(pNode->Data());
393
394 delete pInfo;
395
396 pNode = pNode->Next();
397 }
398
399 mGC.Reset(); // reinit GC
400
401 // FIXME:: this is a dirty-workaround for messy client-area,
402 // as a result of docking bar out of floated-container window
403
404 if ( mpLayout->mClientWndRefreshPending )
405 {
406 mpLayout->PositionClientWindow();
407 mpLayout->GetFrameClient()->Refresh();
408 }
409}