Commit | Line | Data |
---|---|---|
8e08b761 JS |
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 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/wx.h" | |
25 | #endif | |
26 | ||
27 | #include "wx/fl/updatesmgr.h" | |
28 | ||
29 | // helper function | |
30 | ||
31 | static inline bool rect_hits_rect( const wxRect& r1, const wxRect& r2 ) | |
32 | { | |
33 | if ( ( r2.x >= r1.x && r2.x <= r1.x + r1.width ) || | |
34 | ( r1.x >= r2.x && r1.x <= r2.x + r2.width ) ) | |
35 | ||
36 | if ( ( r2.y >= r1.y && r2.y <= r1.y + r1.height ) || | |
37 | ( r1.y >= r2.y && r1.y <= r2.y + r2.height ) ) | |
38 | ||
39 | return 1; | |
40 | ||
41 | return 0; | |
42 | } | |
43 | ||
44 | /***** Implementation for class cbSimpleUpdatesMgr *****/ | |
45 | ||
46 | IMPLEMENT_DYNAMIC_CLASS( cbSimpleUpdatesMgr, cbUpdatesManagerBase ) | |
47 | ||
48 | cbSimpleUpdatesMgr::cbSimpleUpdatesMgr( wxFrameLayout* pPanel ) | |
49 | : cbUpdatesManagerBase( pPanel ) | |
50 | {} | |
51 | ||
52 | bool cbSimpleUpdatesMgr::WasChanged( cbUpdateMgrData& data, wxRect& currentBounds ) | |
53 | { | |
54 | return ( data.IsDirty() || | |
55 | ||
56 | ( data.mPrevBounds.x != currentBounds.x || | |
57 | data.mPrevBounds.y != currentBounds.y || | |
58 | data.mPrevBounds.width != currentBounds.width || | |
59 | data.mPrevBounds.height != currentBounds.height ) | |
60 | ); | |
61 | } | |
62 | ||
63 | void cbSimpleUpdatesMgr::OnStartChanges() | |
64 | { | |
65 | // memorize states of ALL items in the layout - | |
66 | // this is quite excessive, but OK for the simple | |
67 | // implementation of updates manager | |
68 | ||
69 | mpLayout->GetPrevClientRect() = mpLayout->GetClientRect(); | |
70 | ||
71 | cbDockPane** panes = mpLayout->GetPanesArray(); | |
72 | ||
73 | for( int n = 0; n != MAX_PANES; ++n ) | |
74 | { | |
75 | cbDockPane& pane = *panes[n]; | |
76 | // store pane state | |
77 | pane.mUMgrData.StoreItemState( pane.mBoundsInParent ); | |
78 | pane.mUMgrData.SetDirty( FALSE ); | |
79 | ||
80 | for( size_t i = 0; i != pane.GetRowList().Count(); ++i ) | |
81 | { | |
82 | cbRowInfo& row = *pane.GetRowList()[ i ]; | |
83 | ||
84 | // store row state | |
85 | row.mUMgrData.StoreItemState( row.mBoundsInParent ); | |
86 | row.mUMgrData.SetDirty( FALSE ); | |
87 | ||
88 | for( size_t k = 0; k != row.mBars.Count(); ++k ) | |
89 | { | |
90 | cbBarInfo& bar = *row.mBars[ k ]; | |
91 | ||
92 | // store bar state | |
93 | bar.mUMgrData.StoreItemState( bar.mBoundsInParent ); | |
94 | bar.mUMgrData.SetDirty( FALSE ); | |
95 | } | |
96 | } | |
97 | } | |
98 | } | |
99 | ||
100 | void cbSimpleUpdatesMgr::OnFinishChanges() | |
101 | { | |
102 | // nothing here, could be overriden by more sophisticated updates-managers | |
103 | } | |
104 | ||
105 | void cbSimpleUpdatesMgr::OnRowWillChange( cbRowInfo* pRow, cbDockPane* pInPane ) | |
106 | { | |
107 | // -/- | |
108 | } | |
109 | ||
110 | void cbSimpleUpdatesMgr::OnBarWillChange( cbBarInfo* pBar, | |
111 | cbRowInfo* pInRow, cbDockPane* pInPane ) | |
112 | { | |
113 | // -/- | |
114 | } | |
115 | ||
116 | void cbSimpleUpdatesMgr::OnPaneMarginsWillChange( cbDockPane* pPane ) | |
117 | { | |
118 | // -/- | |
119 | } | |
120 | ||
121 | void cbSimpleUpdatesMgr::OnPaneWillChange( cbDockPane* pPane ) | |
122 | { | |
123 | // -/- | |
124 | } | |
125 | ||
126 | void cbSimpleUpdatesMgr::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 mBarsToRefresh; | |
144 | wxList mPanesList; | |
145 | ||
146 | for( int n = 0; n != MAX_PANES; ++n ) | |
147 | { | |
148 | cbDockPane& pane = *(panes[n]); | |
149 | ||
150 | bool paneChanged = WasChanged( pane.mUMgrData, pane.mBoundsInParent ); | |
151 | ||
152 | if ( paneChanged ) | |
153 | { | |
154 | wxClientDC dc( &mpLayout->GetParentFrame() ); | |
155 | pane.PaintPaneBackground( dc ); | |
156 | } | |
157 | ||
158 | wxRect realBounds; | |
159 | ||
160 | for( size_t i = 0; i != pane.GetRowList().Count(); ++i ) | |
161 | { | |
162 | cbRowInfo& row = *pane.GetRowList()[ i ]; | |
163 | ||
164 | wxDC* pDc = NULL; | |
165 | ||
166 | bool rowChanged = FALSE; | |
167 | ||
168 | // FIXME:: the below should not be fixed | |
169 | cbBarInfo* barsToRepaint[256]; | |
170 | ||
171 | // number of bars, that were changed in the current row | |
172 | int nBars = 0; | |
173 | ||
174 | if ( WasChanged( row.mUMgrData, row.mBoundsInParent ) ) | |
175 | ||
176 | rowChanged = TRUE; | |
177 | else | |
178 | for( size_t k = 0; k != row.mBars.Count(); ++k ) | |
179 | ||
180 | if ( WasChanged( row.mBars[k]->mUMgrData, | |
181 | row.mBars[k]->mBoundsInParent ) | |
182 | ) | |
183 | ||
184 | barsToRepaint[nBars++] = row.mBars[k]; | |
185 | ||
186 | if ( nBars || rowChanged ) | |
187 | { | |
188 | realBounds = row.mBoundsInParent; | |
189 | ||
190 | // include 1-pixel thick shades around the row | |
191 | realBounds.x -= 1; | |
192 | realBounds.y -= 1; | |
193 | realBounds.width += 2; | |
194 | realBounds.height += 2; | |
195 | ||
196 | pDc = pane.StartDrawInArea( realBounds ); | |
197 | } | |
198 | ||
199 | if ( rowChanged ) | |
200 | { | |
201 | // postphone the resizing and refreshing the changed | |
202 | // bar windows | |
203 | ||
204 | for( size_t k = 0; k != row.mBars.Count(); ++k ) | |
205 | { | |
206 | mBarsToRefresh.Append( (wxObject*)row.mBars[k] ); | |
207 | mPanesList.Append( &pane ); | |
208 | } | |
209 | ||
210 | // draw only their decorations now | |
211 | ||
212 | pane.PaintRow( &row, *pDc ); | |
213 | } | |
214 | else | |
215 | if ( nBars != 0 ) | |
216 | { | |
217 | for( int i = 0; i != nBars; ++i ) | |
218 | { | |
219 | // postphone the resizement and refreshing the changed | |
220 | // bar windows | |
221 | ||
222 | mBarsToRefresh.Append( (wxObject*)barsToRepaint[i] ); | |
223 | mPanesList.Append( &pane ); | |
224 | } | |
225 | ||
226 | // redraw decorations of entire row, regardless of how much | |
227 | // of the bars were changed | |
228 | pane.PaintRow( &row, *pDc ); | |
229 | } | |
230 | ||
231 | if ( pDc ) | |
232 | ||
233 | pane.FinishDrawInArea( realBounds ); | |
234 | } // end of while | |
235 | ||
236 | if ( paneChanged ) | |
237 | { | |
238 | wxClientDC dc( &mpLayout->GetParentFrame() ); | |
239 | pane.PaintPaneDecorations( dc ); | |
240 | } | |
241 | ||
242 | } // end of for | |
243 | ||
244 | if ( clientWindowChanged ) | |
245 | { | |
246 | mpLayout->PositionClientWindow(); | |
247 | // ptr to client-window object is "marked" as 0 | |
248 | } | |
249 | ||
250 | // step #2 - do ordered refreshing and resizing of bar window objects now | |
251 | ||
252 | wxNode* pNode = mBarsToRefresh.First(); | |
253 | wxNode* pPaneNode = mPanesList.First(); | |
254 | ||
255 | while( pNode ) | |
256 | { | |
257 | cbBarInfo* pBar = (cbBarInfo*) pNode->Data(); | |
258 | cbDockPane* pPane = (cbDockPane*)pPaneNode->Data(); | |
259 | ||
260 | pPane->SizeBar( pBar ); | |
261 | ||
262 | pNode = pNode->Next(); | |
263 | pPaneNode = pPaneNode->Next(); | |
264 | } | |
265 | ||
266 | pNode = mBarsToRefresh.First(); | |
267 | ||
268 | while( pNode ) | |
269 | { | |
270 | cbBarInfo* pBar = (cbBarInfo*)pNode->Data(); | |
271 | ||
272 | if ( pBar->mpBarWnd ) | |
273 | { | |
274 | pBar->mpBarWnd->Refresh(); | |
275 | ||
276 | // FIXME:: | |
277 | //info.mpBarWnd->Show(FALSE); | |
278 | //info.mpBarWnd->Show(TRUE); | |
279 | } | |
280 | ||
281 | pNode = pNode->Next(); | |
282 | } | |
283 | ||
284 | if ( clientWindowChanged ) | |
285 | { | |
286 | // FIXME:: excessive? | |
287 | ||
288 | mpLayout->GetFrameClient()->Refresh(); | |
289 | } | |
290 | } | |
291 | ||
11a68fa3 | 292 |