1 /* |
|
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of Data window |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //Includes |
|
20 #include "mulpagedatawindow.h" |
|
21 |
|
22 #include <stdexcept> |
|
23 |
|
24 //Internal includes |
|
25 #include "mulassert.h" |
|
26 #include "mulmodelimpl.h" |
|
27 #include "mullog.h" |
|
28 |
|
29 using namespace std; |
|
30 |
|
31 namespace Alf |
|
32 { |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // MulPageDataWindow |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 MulPageDataWindow::MulPageDataWindow( MulModelImpl& aMulModel ) |
|
39 :mMulModel( aMulModel ), |
|
40 mHighlight(KNotInitialized), |
|
41 mPageTopIndex(KNotInitialized), |
|
42 mOldPageTopIndex(KNotInitialized), |
|
43 mBufferSize(KNotInitialized), |
|
44 mWindowSize(KNotInitialized), |
|
45 mWindowTop(KNotInitialized), |
|
46 mWindowBottom(KNotInitialized), |
|
47 mBufferTop(0), |
|
48 mBufferBottom(0), |
|
49 mOldBufferTop(KNotInitialized), |
|
50 mOldBufferBottom(KNotInitialized), |
|
51 mRearBufferTop(0), |
|
52 mRearBufferBottom(0), |
|
53 mOldRearBufferTop(KNotInitialized), |
|
54 mOldRearBufferBottom(KNotInitialized) |
|
55 { |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // SetWindowSize |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 void MulPageDataWindow::SetWindowSize( int aWindowSize, int aPageTopIndex ) |
|
63 { |
|
64 MUL_LOG_ENTRY_EXIT("MUL::MulDataWindow::SetWindowSize()"); |
|
65 |
|
66 __MUL_ASSERT( aWindowSize > 0, KLInvalidArgument ); |
|
67 |
|
68 if( mWindowSize != aWindowSize || mWindowTop != aPageTopIndex) |
|
69 { |
|
70 if( KNotInitialized == mBufferSize ) |
|
71 { |
|
72 mBufferSize = aWindowSize; |
|
73 } |
|
74 |
|
75 mWindowSize = aWindowSize; |
|
76 mOldPageTopIndex = mPageTopIndex; |
|
77 mPageTopIndex = aPageTopIndex; |
|
78 |
|
79 |
|
80 /*adjusting window offset |
|
81 //if window size changes then the top and bottom offset should be |
|
82 //adjusted such that highlight remains at the centre |
|
83 //window top and bottom are inclusive*/ |
|
84 |
|
85 //assing page top index to window top by default aPageTopIndex is KNotInitialized |
|
86 mWindowTop = aPageTopIndex ; |
|
87 mWindowTop = ( mWindowTop == KNotInitialized ) ? 0 : mWindowTop; |
|
88 mWindowBottom = mWindowTop + mWindowSize - 1; |
|
89 //make sure that window bottom is not more than model count |
|
90 mWindowBottom = mWindowBottom >= mMulModel.CurrentItemCount() ? ( mMulModel.CurrentItemCount() -1) : mWindowBottom; |
|
91 |
|
92 MUL_LOG_INFO2("MUL::MulDataWindow::SetWindowSize() mWindowTop:%d,mWindowBottom:%d",mWindowTop,mWindowBottom); |
|
93 |
|
94 AdjustBuffer(); |
|
95 mMulModel.DataWindowUpdated(); |
|
96 } |
|
97 //else nothing needed |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // SetBufferSize |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 void MulPageDataWindow::SetBufferSize( int aBufferSize ) |
|
105 { |
|
106 MUL_LOG_ENTRY_EXIT("MUL::MulDataWindow::SetBufferSize()"); |
|
107 |
|
108 __MUL_ASSERT( aBufferSize > 0, KLInvalidArgument ); |
|
109 |
|
110 if( mBufferSize != aBufferSize ) |
|
111 { |
|
112 mBufferSize = aBufferSize; |
|
113 |
|
114 if(mMulModel.CurrentItemCount() > 0) |
|
115 { |
|
116 AdjustBuffer(); |
|
117 mMulModel.DataWindowUpdated(); |
|
118 } |
|
119 } |
|
120 //else nothing needed |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // ~MulDataWindow |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 MulPageDataWindow::~MulPageDataWindow() |
|
128 { |
|
129 // do nothing |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // SetHighlight |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 void MulPageDataWindow::SetHighlight( int aHighlightIndex ) |
|
137 { |
|
138 MUL_LOG_INFO2("MUL::MulDataWindow::SetHighlight() mHighlight:%d,modelCount:%d",aHighlightIndex,mMulModel.CurrentItemCount()); |
|
139 |
|
140 __MUL_ASSERT( aHighlightIndex >= 0 && aHighlightIndex <= mMulModel.CurrentItemCount()-1, KLInvalidArgument ); |
|
141 |
|
142 mHighlight = aHighlightIndex; |
|
143 } |
|
144 |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 // UpdateHighlight |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 void MulPageDataWindow::UpdateHighlight( int aHighlightIndex ) |
|
151 { |
|
152 // No need to assert. We should send highlight -1 when all the items are removed. |
|
153 // Widget should handle. to show emty text visualization |
|
154 mHighlight = aHighlightIndex; |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // AdjustOffset |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 void MulPageDataWindow::AdjustOffset() |
|
162 { |
|
163 if( BottomWindowOffset() >= mMulModel.CurrentItemCount() ) |
|
164 { |
|
165 mWindowBottom = mMulModel.CurrentItemCount() -1; |
|
166 mWindowTop = mWindowBottom - WindowSize() + 1; |
|
167 mWindowTop = mWindowTop < 0 ? 0 : mWindowTop; |
|
168 |
|
169 MUL_LOG_INFO2("MUL::MulPageDataWindow::AdjustOffset() : windowTop:%d::windowBottom%d",mWindowTop,mWindowBottom); |
|
170 } |
|
171 else if( (BottomWindowOffset() - TopWindowOffset() +1 ) < WindowSize() ) |
|
172 { |
|
173 mWindowTop = 0; |
|
174 mWindowBottom = mWindowTop + WindowSize() -1; |
|
175 int modelCount = mMulModel.CurrentItemCount(); |
|
176 mWindowBottom = mWindowBottom >= modelCount ? (modelCount - 1) : mWindowBottom; |
|
177 |
|
178 MUL_LOG_INFO2("MUL::MulPageDataWindow::AdjustOffset() :: windowTop:%d::windowBottom%d",mWindowTop,mWindowBottom); |
|
179 } |
|
180 |
|
181 // save old values to check if teh buffer offsets are modified. If the buffer offsets are |
|
182 // modified then should inform the widget to update the visualization |
|
183 SaveOldValues(); |
|
184 AdjustBuffer(); |
|
185 } |
|
186 |
|
187 |
|
188 // --------------------------------------------------------------------------- |
|
189 // ScrollWindow |
|
190 // --------------------------------------------------------------------------- |
|
191 // |
|
192 void MulPageDataWindow::ScrollWindow( int aPageTopIndex ) |
|
193 { |
|
194 MUL_LOG_INFO2("MUL::MulDataWindow::ScrollWindow() aPageTopIndex:%d,modelCount:%d",aPageTopIndex,mMulModel.CurrentItemCount()); |
|
195 |
|
196 __MUL_ASSERT( aPageTopIndex >= 0 && aPageTopIndex <= mMulModel.CurrentItemCount()-1, KLInvalidArgument ); |
|
197 |
|
198 if( mPageTopIndex != aPageTopIndex ) |
|
199 { |
|
200 mOldPageTopIndex = mPageTopIndex; |
|
201 mPageTopIndex = aPageTopIndex; |
|
202 |
|
203 UpdateDataWindow(); |
|
204 } |
|
205 //else same highlight |
|
206 } |
|
207 |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // UpdateDataWindow |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 void MulPageDataWindow::UpdateDataWindow() |
|
214 { |
|
215 MUL_LOG_INFO1("MUL::MulPageDataWindow::UpdateDataWindow() diff:%d ", mPageTopIndex - mOldPageTopIndex ); |
|
216 |
|
217 //If diffrence is negative than highlight is moved up else down |
|
218 //(( mPageTopIndex - mOldPageTopIndex ) < 0 ) ? ShiftWindowUp() : ShiftWindowDown() ; |
|
219 |
|
220 MUL_LOG_ENTRY_EXIT("MUL::MulPageDataWindow::ShiftWindowDown()"); |
|
221 MUL_LOG_INFO2("MUL::MulPageDataWindow::ShiftWindowDown() mPageTopIndex:%d,mWindowBottom:%d",mPageTopIndex,mWindowBottom); |
|
222 |
|
223 mWindowTop = mPageTopIndex; |
|
224 mWindowBottom = mWindowTop + mWindowSize -1; |
|
225 //bottom can't exceeding model count |
|
226 mWindowBottom = mWindowBottom >= mMulModel.CurrentItemCount() ? |
|
227 mWindowBottom = mMulModel.CurrentItemCount() - 1 : mWindowBottom; |
|
228 |
|
229 MUL_LOG_INFO2("MUL::MulDataWindow::ShiftWindowDown() mWindowTop:%d,mWindowBottom:%d",mWindowTop,mWindowBottom); |
|
230 |
|
231 SaveOldValues(); |
|
232 AdjustBuffer(); |
|
233 mMulModel.DataWindowUpdated(); |
|
234 } |
|
235 |
|
236 // --------------------------------------------------------------------------- |
|
237 // AdjustBuffer |
|
238 // --------------------------------------------------------------------------- |
|
239 // |
|
240 void MulPageDataWindow::AdjustBuffer() |
|
241 { |
|
242 MUL_LOG_ENTRY_EXIT("MUL::MulPageDataWindow::AdjustBuffer()"); |
|
243 |
|
244 int modelCount = mMulModel.CurrentItemCount() -1; |
|
245 |
|
246 //remove data is new window is smaller/add is new window is bigger |
|
247 //create rear buffer only if model has more data |
|
248 if( mWindowTop == 0 && ActualBufferSize() <= modelCount ) |
|
249 { |
|
250 MUL_LOG_INFO("MUL::MulPageDataWindow::AdjustBuffer() mWindowTop == 0 "); |
|
251 |
|
252 mBufferTop = mWindowTop; |
|
253 mBufferBottom = mBufferTop + mWindowSize + mBufferSize - 1; |
|
254 |
|
255 //Create rear top and rear bottom only in looping case |
|
256 //window top is zero so data at other end should be buffered |
|
257 mRearBufferBottom = modelCount; |
|
258 mRearBufferTop = mRearBufferBottom - mBufferSize +1; |
|
259 } |
|
260 else if( mWindowBottom == modelCount && ActualBufferSize() <= modelCount ) |
|
261 { |
|
262 MUL_LOG_INFO("MUL::MulPageDataWindow::AdjustBuffer() mWindowBottom == modelCount "); |
|
263 |
|
264 mBufferBottom = mWindowBottom ; |
|
265 mBufferTop = mBufferBottom - (mWindowSize + mBufferSize) + 1; |
|
266 |
|
267 //Create rear top and rear bottom only in looping case |
|
268 //window bottom is equal to model count so data at other end should be buffered |
|
269 mRearBufferTop = 0; |
|
270 mRearBufferBottom = mRearBufferTop + mBufferSize -1 ; |
|
271 } |
|
272 else |
|
273 { |
|
274 MUL_LOG_INFO("MUL::MulPageDataWindow::AdjustBuffer() else "); |
|
275 |
|
276 mBufferTop = mWindowTop - mBufferSize; |
|
277 mBufferBottom = mWindowBottom + mBufferSize; |
|
278 |
|
279 //check if top or bottom is out of bound and update offset accordingly |
|
280 if( mBufferTop < 0 ) |
|
281 { |
|
282 MUL_LOG_INFO("MUL::MulPageDataWindow::AdjustBuffer() mBufferTop < 0 "); |
|
283 |
|
284 mBufferTop = 0; |
|
285 mBufferBottom = mBufferTop + ActualBufferSize() - 1; |
|
286 //buffer bottom cant be larger then model count |
|
287 mBufferBottom = mBufferBottom > modelCount ? modelCount : mBufferBottom; |
|
288 } |
|
289 else if( mBufferBottom > modelCount ) |
|
290 { |
|
291 MUL_LOG_INFO("MUL::MulPageDataWindow::AdjustBuffer() mBufferBottom > modelCount"); |
|
292 |
|
293 mBufferBottom = modelCount ; |
|
294 mBufferTop = mBufferBottom - ActualBufferSize() + 1; |
|
295 //buffer top cant be less then 0 |
|
296 mBufferTop = mBufferTop < 0 ? 0 : mBufferTop; |
|
297 } |
|
298 |
|
299 //in other case rear top and rear bottom is not use set to -1 |
|
300 mRearBufferTop = KNotInitialized; |
|
301 mRearBufferBottom = KNotInitialized; |
|
302 } |
|
303 |
|
304 MUL_LOG_INFO2("MUL::MulPageDataWindow::AdjustBuffer() mOldBufferTop:%d,mOldBufferBottom:%d",mOldBufferTop,mOldBufferBottom); |
|
305 MUL_LOG_INFO2("MUL::MulPageDataWindow::AdjustBuffer() mOldRearBufferBottom:%d,mOldRearBufferTop:%d",mOldRearBufferBottom,mOldRearBufferTop); |
|
306 |
|
307 MUL_LOG_INFO2("MUL::MulPageDataWindow::AdjustBuffer() mBufferTop:%d,mBufferBottom:%d",mBufferTop,mBufferBottom); |
|
308 MUL_LOG_INFO2("MUL::MulPageDataWindow::AdjustBuffer() mRearBufferBottom:%d,mRearBufferTop:%d",mRearBufferBottom,mRearBufferTop); |
|
309 |
|
310 __MUL_ASSERT_DEBUG( mWindowTop >= 0 && mWindowBottom < mMulModel.CurrentItemCount(), _L("Invlid Window")); |
|
311 __MUL_ASSERT_DEBUG( mBufferTop >= 0 && mBufferBottom < mMulModel.CurrentItemCount(), _L("Invlid Buffer")); |
|
312 } |
|
313 |
|
314 // --------------------------------------------------------------------------- |
|
315 // IsItemInDataWindow |
|
316 // --------------------------------------------------------------------------- |
|
317 // |
|
318 bool MulPageDataWindow::IsItemInDataWindow(int aItemIndex ) const |
|
319 { |
|
320 //__MUL_ASSERT_DEBUG( aItemIndex >= 0 && aItemIndex <= mMulModel.CurrentItemCount()-1, KLInvalidArgument ); |
|
321 |
|
322 bool result( false ); |
|
323 |
|
324 if(mWindowSize == KNotInitialized ) |
|
325 { |
|
326 result = false; |
|
327 } |
|
328 //check that rear buffer is on or not in looping case |
|
329 else if( mRearBufferTop != KNotInitialized && mRearBufferBottom != KNotInitialized ) |
|
330 { |
|
331 if( ( aItemIndex >= mBufferTop && aItemIndex <= mBufferBottom ) || |
|
332 ( aItemIndex >= mRearBufferTop && aItemIndex <= mRearBufferBottom ) ) |
|
333 { |
|
334 result = true; |
|
335 } |
|
336 } |
|
337 else if( aItemIndex >= mBufferTop && aItemIndex <= mBufferBottom ) |
|
338 { |
|
339 result = true; |
|
340 } |
|
341 return result; |
|
342 } |
|
343 |
|
344 // --------------------------------------------------------------------------- |
|
345 // IsItemInDataWindow |
|
346 // --------------------------------------------------------------------------- |
|
347 // |
|
348 bool MulPageDataWindow::IsItemInVisibleWindow(int aItemIndex ) const |
|
349 { |
|
350 //__MUL_ASSERT_DEBUG( aItemIndex >= 0 && aItemIndex <= mMulModel.CurrentItemCount()-1, KLInvalidArgument ); |
|
351 |
|
352 if(mWindowSize == KNotInitialized ) |
|
353 { |
|
354 return false; |
|
355 } |
|
356 else if( aItemIndex >= mWindowTop && aItemIndex <= mWindowBottom ) |
|
357 { |
|
358 return true; |
|
359 } |
|
360 return false; |
|
361 } |
|
362 |
|
363 // --------------------------------------------------------------------------- |
|
364 // RelativeIndex |
|
365 // --------------------------------------------------------------------------- |
|
366 // |
|
367 int MulPageDataWindow::RelativeIndex( int aAbsoluteIndex ) const |
|
368 { |
|
369 __MUL_ASSERT_DEBUG( aAbsoluteIndex >= 0 && aAbsoluteIndex <= mMulModel.CurrentItemCount()-1, KLInvalidArgument ); |
|
370 |
|
371 if( !IsItemInDataWindow(aAbsoluteIndex) ) |
|
372 { |
|
373 return -1; |
|
374 } |
|
375 |
|
376 if( mRearBufferTop != KNotInitialized && mRearBufferBottom != KNotInitialized ) |
|
377 { |
|
378 if( mRearBufferBottom == mMulModel.CurrentItemCount() - 1 ) |
|
379 { |
|
380 if( aAbsoluteIndex >= mRearBufferTop && aAbsoluteIndex <= mRearBufferBottom ) |
|
381 { |
|
382 int bufferSize = BottomOffset() - TopOffset() + 1; |
|
383 int rearDiff = aAbsoluteIndex - mRearBufferTop; |
|
384 int relativeIndex = bufferSize + rearDiff; |
|
385 return relativeIndex; |
|
386 } |
|
387 else |
|
388 { |
|
389 int relativeIndex = aAbsoluteIndex < TopOffset() ? |
|
390 aAbsoluteIndex : aAbsoluteIndex - TopOffset() ; |
|
391 return relativeIndex; |
|
392 } |
|
393 } |
|
394 else |
|
395 { |
|
396 if( aAbsoluteIndex >= mRearBufferTop && aAbsoluteIndex <= mRearBufferBottom ) |
|
397 { |
|
398 int relativeIndex = aAbsoluteIndex < TopOffset() ? |
|
399 aAbsoluteIndex : aAbsoluteIndex - TopOffset() ; |
|
400 return relativeIndex; |
|
401 } |
|
402 else |
|
403 { |
|
404 int bufferSize = mRearBufferBottom - mRearBufferTop + 1; |
|
405 int diff = aAbsoluteIndex - TopOffset(); |
|
406 int relativeIndex = bufferSize + diff; |
|
407 return relativeIndex; |
|
408 } |
|
409 } |
|
410 } |
|
411 else |
|
412 { |
|
413 int relativeIndex = aAbsoluteIndex < TopOffset() ? |
|
414 aAbsoluteIndex : aAbsoluteIndex - TopOffset() ; |
|
415 return relativeIndex; |
|
416 } |
|
417 } |
|
418 |
|
419 // --------------------------------------------------------------------------- |
|
420 // AbsoluteIndex |
|
421 // --------------------------------------------------------------------------- |
|
422 // |
|
423 int MulPageDataWindow::AbsoluteIndex( int aRelativeIndex ) const |
|
424 { |
|
425 __MUL_ASSERT_DEBUG( aRelativeIndex >= 0 && aRelativeIndex <= ActualBufferSize(), _L("Invalid Relative Index")); |
|
426 |
|
427 if( mRearBufferTop != KNotInitialized && mRearBufferBottom != KNotInitialized ) |
|
428 { |
|
429 if( mRearBufferBottom == mMulModel.CurrentItemCount() - 1 ) |
|
430 { |
|
431 if( aRelativeIndex > BottomOffset() ) |
|
432 { |
|
433 //relative index is in loop buffer |
|
434 int diff = aRelativeIndex - BottomOffset() - 1; |
|
435 int absoluteIndex = RearTopOffset() + diff; |
|
436 return absoluteIndex; |
|
437 } |
|
438 else |
|
439 { |
|
440 int absoluteIndex = TopOffset() + aRelativeIndex; |
|
441 return absoluteIndex; |
|
442 } |
|
443 } |
|
444 else |
|
445 { |
|
446 if( aRelativeIndex <= RearBottomOffset() ) |
|
447 { |
|
448 //relative index is in loop buffer |
|
449 int absoluteIndex = RearTopOffset() + aRelativeIndex; |
|
450 return absoluteIndex; |
|
451 } |
|
452 else |
|
453 { |
|
454 int diff = aRelativeIndex - RearBottomOffset() - 1; |
|
455 int absoluteIndex = TopOffset() + diff; |
|
456 return absoluteIndex; |
|
457 } |
|
458 } |
|
459 } |
|
460 else |
|
461 { |
|
462 int absoluteIndex = TopOffset() + aRelativeIndex; |
|
463 return absoluteIndex; |
|
464 } |
|
465 } |
|
466 |
|
467 // --------------------------------------------------------------------------- |
|
468 // IsBufferOffsetChanged |
|
469 // --------------------------------------------------------------------------- |
|
470 // |
|
471 bool MulPageDataWindow::IsBufferOffsetChanged() |
|
472 { |
|
473 if(mRearBufferBottom != mOldRearBufferBottom || |
|
474 mRearBufferTop != mOldRearBufferTop || |
|
475 mBufferTop != mOldBufferTop || |
|
476 mBufferBottom != mOldBufferBottom ) |
|
477 { |
|
478 return true; |
|
479 } |
|
480 return false; |
|
481 } |
|
482 |
|
483 } // namespace Alf |
|
484 |
|
485 //End of file |
|