|
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: cuicscrollbar.cpp |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cuicscrollbar.h" |
|
19 #include "emailtrace.h" |
|
20 |
|
21 #include <alf/alfenv.h> |
|
22 #include <alf/alfevent.h> |
|
23 #include <alf/alfimagevisual.h> |
|
24 #include <alf/alftexture.h> |
|
25 #include <alf/alfanchorlayout.h> |
|
26 #include <alf/alfdecklayout.h> |
|
27 |
|
28 // Constants |
|
29 |
|
30 // Scroll bar opacity (visible) |
|
31 const TReal32 KVisibleOpacity = 1.0f; |
|
32 // Thumb opacity (visible) |
|
33 const TReal32 KVisibleOpacityThumb = 0.85f; |
|
34 // Background opacity (visible) |
|
35 const TReal32 KVisibleOpacityBackground = 0.65f; |
|
36 // How long scrollbar will be visible after change |
|
37 const TReal32 KVisibleTimeout = 500; |
|
38 // How long fading will take |
|
39 const TReal32 KFadeTimeout = 500; |
|
40 // Width of the scrollbar (this will be replaced with value from layout) |
|
41 const TInt KScrollBarWidth = 18; |
|
42 |
|
43 // CUiCCompositeImage |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // CUiCCompositeImage::NewL |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CUiCCompositeImage* CUiCCompositeImage::NewL( CAlfControl& aControl, |
|
50 CAlfLayout* aParentLayout, CAlfTexture& aTop, |
|
51 CAlfTexture& aMiddle, CAlfTexture& aBottom ) |
|
52 { |
|
53 FUNC_LOG; |
|
54 CUiCCompositeImage* self = new (ELeave) CUiCCompositeImage(); |
|
55 CleanupStack::PushL( self ); |
|
56 self->ConstructL( aControl, aParentLayout, aTop, aMiddle, aBottom ); |
|
57 CleanupStack::Pop(); // self |
|
58 return self; |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // CUiCCompositeImage::~CUiCCompositeImage |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 CUiCCompositeImage::~CUiCCompositeImage() |
|
66 { |
|
67 FUNC_LOG; |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // CUiCCompositeImage::Layout |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 CAlfLayout& CUiCCompositeImage::Layout() |
|
75 { |
|
76 FUNC_LOG; |
|
77 return *iLayout; |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------------------------- |
|
81 // CUiCCompositeImage::CUiCCompositeImage |
|
82 // --------------------------------------------------------------------------- |
|
83 // |
|
84 CUiCCompositeImage::CUiCCompositeImage() |
|
85 { |
|
86 FUNC_LOG; |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // CUiCCompositeImage::ConstructL |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 void CUiCCompositeImage::ConstructL( CAlfControl& aControl, CAlfLayout* aParentLayout, |
|
94 CAlfTexture& aTop, CAlfTexture& aMiddle, CAlfTexture& aBottom ) |
|
95 { |
|
96 FUNC_LOG; |
|
97 iLayout = CAlfAnchorLayout::AddNewL( aControl, aParentLayout ); |
|
98 iTop = CAlfImageVisual::AddNewL( aControl, iLayout ); |
|
99 iTop->SetImage( TAlfImage( aTop ) ); |
|
100 iMiddle = CAlfImageVisual::AddNewL( aControl, iLayout ); |
|
101 iMiddle->SetImage( TAlfImage( aMiddle ) ); |
|
102 iBottom = CAlfImageVisual::AddNewL( aControl, iLayout ); |
|
103 iBottom->SetImage( TAlfImage( aBottom ) ); |
|
104 SetAnchors(); |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // CUiCCompositeImage::SetAnchors |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 void CUiCCompositeImage::SetAnchors() |
|
112 { |
|
113 FUNC_LOG; |
|
114 // iTop |
|
115 iLayout->SetAnchor( |
|
116 EAlfAnchorTopLeft, 0, |
|
117 EAlfAnchorOriginLeft, EAlfAnchorOriginTop, |
|
118 EAlfAnchorMetricAbsolute, EAlfAnchorMetricAbsolute, |
|
119 TAlfTimedPoint( 0, 0 ) ); |
|
120 iLayout->SetAnchor( |
|
121 EAlfAnchorBottomRight, 0, |
|
122 EAlfAnchorOriginRight, EAlfAnchorOriginTop, |
|
123 EAlfAnchorMetricAbsolute, EAlfAnchorMetricAbsolute, |
|
124 TAlfTimedPoint( 0, KScrollBarWidth ) ); |
|
125 |
|
126 // iMiddle |
|
127 iLayout->SetAnchor( |
|
128 EAlfAnchorTopLeft, 1, |
|
129 EAlfAnchorOriginLeft, EAlfAnchorOriginTop, |
|
130 EAlfAnchorMetricAbsolute, EAlfAnchorMetricAbsolute, |
|
131 TAlfTimedPoint( 0, KScrollBarWidth ) ); |
|
132 iLayout->SetAnchor( |
|
133 EAlfAnchorBottomRight, 1, |
|
134 EAlfAnchorOriginRight, EAlfAnchorOriginBottom, |
|
135 EAlfAnchorMetricAbsolute, EAlfAnchorMetricAbsolute, |
|
136 TAlfTimedPoint( 0, -KScrollBarWidth ) ); |
|
137 |
|
138 // iBottom |
|
139 iLayout->SetAnchor( |
|
140 EAlfAnchorTopLeft, 2, |
|
141 EAlfAnchorOriginLeft, EAlfAnchorOriginBottom, |
|
142 EAlfAnchorMetricAbsolute, EAlfAnchorMetricAbsolute, |
|
143 TAlfTimedPoint( 0, -KScrollBarWidth ) ); |
|
144 iLayout->SetAnchor( |
|
145 EAlfAnchorBottomRight, 2, |
|
146 EAlfAnchorOriginRight, EAlfAnchorOriginBottom, |
|
147 EAlfAnchorMetricAbsolute, EAlfAnchorMetricAbsolute, |
|
148 TAlfTimedPoint( 0, 0 ) ); |
|
149 |
|
150 iLayout->UpdateChildrenLayout(); |
|
151 } |
|
152 |
|
153 // CUiCScrollBar |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // CUiCScrollBar::NewL |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 CUiCScrollBar* CUiCScrollBar::NewL( CAlfEnv& aEnv, CAlfLayout* aParentLayout ) |
|
160 { |
|
161 FUNC_LOG; |
|
162 CUiCScrollBar* self = new (ELeave) CUiCScrollBar(); |
|
163 CleanupStack::PushL( self ); |
|
164 self->ConstructL( aEnv, aParentLayout ); |
|
165 CleanupStack::Pop(); // self |
|
166 return self; |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // CUiCScrollBar::~CUiCScrollBar |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 void CUiCScrollBar::Destroy() |
|
174 { |
|
175 FUNC_LOG; |
|
176 delete this; |
|
177 } |
|
178 |
|
179 // --------------------------------------------------------------------------- |
|
180 // CUiCScrollBar::Show |
|
181 // --------------------------------------------------------------------------- |
|
182 // |
|
183 void CUiCScrollBar::Show( const TBool aShow ) |
|
184 { |
|
185 FUNC_LOG; |
|
186 Env().CancelCustomCommands( this ); |
|
187 TAlfTimedValue opacity( aShow ? KVisibleOpacity : 0 ); |
|
188 iDeck->SetOpacity( opacity ); |
|
189 if ( aShow ) |
|
190 { |
|
191 iThumbVisual->Layout().SetOpacity( KVisibleOpacityThumb ); |
|
192 iBackGroundVisual->Layout().SetOpacity( KVisibleOpacityBackground ); |
|
193 TAlfCustomEventCommand command( EFadeOut, this ); |
|
194 Env().Send( command, KVisibleTimeout ); |
|
195 } |
|
196 } |
|
197 |
|
198 // --------------------------------------------------------------------------- |
|
199 // CUiCScrollBar::UpdateModelL |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 void CUiCScrollBar::UpdateModelL( const TUiCScrollBarModel& aModel ) |
|
203 { |
|
204 FUNC_LOG; |
|
205 iModel = aModel; |
|
206 if ( iModel.ScrollBarNeeded() ) |
|
207 { |
|
208 SetThumbAnchors(); |
|
209 Show( ETrue ); |
|
210 } |
|
211 else |
|
212 { |
|
213 Show( EFalse ); |
|
214 } |
|
215 } |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // CUiCScrollBar::ThumbPosition |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 TInt CUiCScrollBar::ThumbPosition() const |
|
222 { |
|
223 FUNC_LOG; |
|
224 return iModel.ThumbPosition(); |
|
225 } |
|
226 |
|
227 // --------------------------------------------------------------------------- |
|
228 // CUiCScrollBar::SetRect |
|
229 // --------------------------------------------------------------------------- |
|
230 // |
|
231 void CUiCScrollBar::SetRect( const TRect& aRect ) |
|
232 { |
|
233 FUNC_LOG; |
|
234 TAlfRealRect realRect( aRect ); |
|
235 iDeck->SetRect( realRect ); |
|
236 iDeck->UpdateChildrenLayout(); |
|
237 } |
|
238 |
|
239 // --------------------------------------------------------------------------- |
|
240 // CUiCScrollBar::Redraw |
|
241 // --------------------------------------------------------------------------- |
|
242 // |
|
243 void CUiCScrollBar::Redraw() |
|
244 { |
|
245 FUNC_LOG; |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // CUiCScrollBar::NotifyThemeChanged |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 void CUiCScrollBar::NotifyThemeChanged() |
|
253 { |
|
254 FUNC_LOG; |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // CUiCScrollBar::LayoutHints |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 TInt CUiCScrollBar::LayoutHints() const |
|
262 { |
|
263 FUNC_LOG; |
|
264 return ELayoutOnTopOfList | ELayoutRelativeToList | |
|
265 ELayoutAutomaticMirroring; |
|
266 } |
|
267 |
|
268 // --------------------------------------------------------------------------- |
|
269 // CUiCScrollBar::OfferEventL |
|
270 // --------------------------------------------------------------------------- |
|
271 // |
|
272 TBool CUiCScrollBar::OfferEventL( const TAlfEvent& aEvent ) |
|
273 { |
|
274 FUNC_LOG; |
|
275 TBool handled( EFalse ); |
|
276 if ( aEvent.Type() == TAlfEvent::ETypeCustom ) |
|
277 { |
|
278 if ( aEvent.CustomParameter() == EFadeOut ) |
|
279 { |
|
280 handled = ETrue; |
|
281 TAlfTimedValue opacity( 0, KFadeTimeout ); |
|
282 iDeck->SetOpacity( opacity ); |
|
283 } |
|
284 } |
|
285 else |
|
286 { |
|
287 handled = CAlfControl::OfferEventL( aEvent ); |
|
288 } |
|
289 return handled; |
|
290 } |
|
291 |
|
292 // --------------------------------------------------------------------------- |
|
293 // CUiCScrollBar::ProvideBitmapL |
|
294 // --------------------------------------------------------------------------- |
|
295 // |
|
296 void CUiCScrollBar::ProvideBitmapL( TInt aId, CFbsBitmap*& aBitmap, CFbsBitmap*& aMaskBitmap ) |
|
297 { |
|
298 FUNC_LOG; |
|
299 TAknsItemID itemId; |
|
300 |
|
301 switch ( aId ) |
|
302 { |
|
303 case EThumbTop: |
|
304 itemId = KAknsIIDQsnCpScrollHandleTop; |
|
305 break; |
|
306 |
|
307 case EThumbMiddle: |
|
308 itemId = KAknsIIDQsnCpScrollHandleMiddle; |
|
309 break; |
|
310 |
|
311 case EThumbBottom: |
|
312 itemId = KAknsIIDQsnCpScrollHandleBottom; |
|
313 break; |
|
314 |
|
315 case EBackgroundTop: |
|
316 itemId = KAknsIIDQsnCpScrollBgTop; |
|
317 break; |
|
318 |
|
319 case EBackgroundMiddle: |
|
320 itemId = KAknsIIDQsnCpScrollBgMiddle; |
|
321 break; |
|
322 |
|
323 case EBackgroundBottom: |
|
324 itemId = KAknsIIDQsnCpScrollBgBottom; |
|
325 break; |
|
326 |
|
327 default: |
|
328 User::Leave( KErrNotFound ); |
|
329 } |
|
330 |
|
331 AknsUtils::CreateIconL( AknsUtils::SkinInstance(), itemId, aBitmap, aMaskBitmap, KNullDesC, -1, -1 ); |
|
332 |
|
333 if ( aBitmap ) |
|
334 { |
|
335 TAknContentDimensions origDim; |
|
336 AknIconUtils::GetContentDimensions( aBitmap, origDim ); |
|
337 TSize iconSize( origDim.iWidth, origDim.iHeight ); |
|
338 if (iconSize.iWidth != KScrollBarWidth && iconSize.iWidth > 0) |
|
339 { |
|
340 iconSize.iHeight = iconSize.iHeight * KScrollBarWidth / iconSize.iWidth; |
|
341 iconSize.iWidth = KScrollBarWidth; |
|
342 } |
|
343 AknIconUtils::DisableCompression( aBitmap ); |
|
344 AknIconUtils::SetSize( aBitmap, iconSize, EAspectRatioNotPreserved ); |
|
345 if ( aMaskBitmap ) |
|
346 { |
|
347 AknIconUtils::DisableCompression( aMaskBitmap ); |
|
348 AknIconUtils::SetSize( aMaskBitmap, iconSize, EAspectRatioNotPreserved ); |
|
349 } |
|
350 } |
|
351 } |
|
352 |
|
353 // --------------------------------------------------------------------------- |
|
354 // CUiCScrollBar::~CUiCScrollBar |
|
355 // --------------------------------------------------------------------------- |
|
356 // |
|
357 CUiCScrollBar::~CUiCScrollBar() |
|
358 { |
|
359 FUNC_LOG; |
|
360 Env().CancelCommands( this ); |
|
361 if ( iDeck ) |
|
362 { |
|
363 iDeck->RemoveAndDestroyAllD(); |
|
364 } |
|
365 delete iBackGroundVisual; |
|
366 delete iThumbVisual; |
|
367 } |
|
368 |
|
369 // --------------------------------------------------------------------------- |
|
370 // CUiCScrollBar::CUiCScrollBar |
|
371 // --------------------------------------------------------------------------- |
|
372 // |
|
373 CUiCScrollBar::CUiCScrollBar() |
|
374 { |
|
375 FUNC_LOG; |
|
376 } |
|
377 |
|
378 // --------------------------------------------------------------------------- |
|
379 // CUiCScrollBar::ConstructL |
|
380 // --------------------------------------------------------------------------- |
|
381 // |
|
382 void CUiCScrollBar::ConstructL( CAlfEnv& aEnv, CAlfLayout* aParentLayout ) |
|
383 { |
|
384 FUNC_LOG; |
|
385 CAlfControl::ConstructL( aEnv ); |
|
386 iDeck = CAlfDeckLayout::AddNewL( *this, aParentLayout ); |
|
387 iDeck->SetFlags( EAlfVisualFlagManualLayout | |
|
388 EAlfVisualFlagAutomaticLocaleMirroringEnabled ); |
|
389 iBgLayout = CAlfAnchorLayout::AddNewL( *this, iDeck ); |
|
390 iBgLayout->SetFlags( EAlfVisualFlagAutomaticLocaleMirroringEnabled ); |
|
391 iBackGroundVisual = CUiCCompositeImage::NewL( *this, iBgLayout, |
|
392 Env().TextureManager().CreateTextureL( EBackgroundTop, this, EAlfTextureFlagSkinContent ), |
|
393 Env().TextureManager().CreateTextureL( EBackgroundMiddle, this, EAlfTextureFlagSkinContent ), |
|
394 Env().TextureManager().CreateTextureL( EBackgroundBottom, this, EAlfTextureFlagSkinContent ) ); |
|
395 iThumbLayout = CAlfAnchorLayout::AddNewL( *this, iDeck ); |
|
396 iThumbLayout->SetFlags( EAlfVisualFlagAutomaticLocaleMirroringEnabled ); |
|
397 iThumbLayout->SetClipping( ETrue ); |
|
398 iThumbVisual = CUiCCompositeImage::NewL( *this, iThumbLayout, |
|
399 Env().TextureManager().CreateTextureL( EThumbTop, this, EAlfTextureFlagSkinContent ), |
|
400 Env().TextureManager().CreateTextureL( EThumbMiddle, this, EAlfTextureFlagSkinContent ), |
|
401 Env().TextureManager().CreateTextureL( EThumbBottom, this, EAlfTextureFlagSkinContent ) ); |
|
402 iThumbVisual->Layout().SetFlags( EAlfVisualFlagDrawAfterOthers ); |
|
403 SetAnchors(); |
|
404 } |
|
405 |
|
406 // --------------------------------------------------------------------------- |
|
407 // CUiCScrollBar::ConstructL |
|
408 // --------------------------------------------------------------------------- |
|
409 // |
|
410 void CUiCScrollBar::SetAnchors() |
|
411 { |
|
412 FUNC_LOG; |
|
413 SetBgAnchors(); |
|
414 SetThumbAnchors(); |
|
415 } |
|
416 |
|
417 // --------------------------------------------------------------------------- |
|
418 // CUiCScrollBar::SetBgAnchors |
|
419 // --------------------------------------------------------------------------- |
|
420 // |
|
421 void CUiCScrollBar::SetBgAnchors() |
|
422 { |
|
423 FUNC_LOG; |
|
424 iBgLayout->SetAnchor( |
|
425 EAlfAnchorTopLeft, 0, |
|
426 EAlfAnchorOriginRight, EAlfAnchorOriginTop, |
|
427 EAlfAnchorMetricAbsolute, EAlfAnchorMetricAbsolute, |
|
428 TAlfTimedPoint( -KScrollBarWidth, 0 ) ); |
|
429 iBgLayout->SetAnchor( |
|
430 EAlfAnchorBottomRight, 0, |
|
431 EAlfAnchorOriginRight, EAlfAnchorOriginBottom, |
|
432 EAlfAnchorMetricAbsolute, EAlfAnchorMetricAbsolute, |
|
433 TAlfTimedPoint( 0, 0 ) ); |
|
434 iBgLayout->UpdateChildrenLayout(); |
|
435 } |
|
436 |
|
437 // --------------------------------------------------------------------------- |
|
438 // CUiCScrollBar::SetThumbAnchors |
|
439 // --------------------------------------------------------------------------- |
|
440 // |
|
441 void CUiCScrollBar::SetThumbAnchors() |
|
442 { |
|
443 FUNC_LOG; |
|
444 iThumbLayout->SetAnchor( |
|
445 EAlfAnchorTopLeft, 0, |
|
446 EAlfAnchorOriginRight, EAlfAnchorOriginTop, |
|
447 EAlfAnchorMetricAbsolute, EAlfAnchorMetricAbsolute, |
|
448 TAlfTimedPoint( -KScrollBarWidth, iModel.ThumbPosition() ) ); |
|
449 iThumbLayout->SetAnchor( |
|
450 EAlfAnchorBottomRight, 0, |
|
451 EAlfAnchorOriginRight, EAlfAnchorOriginTop, |
|
452 EAlfAnchorMetricAbsolute, EAlfAnchorMetricAbsolute, |
|
453 TAlfTimedPoint( 0, iModel.ThumbPosition() + iModel.ThumbHeight() ) ); |
|
454 iThumbLayout->UpdateChildrenLayout(); |
|
455 } |
|
456 |
|
457 // end of file |