author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 15 Sep 2010 12:29:17 +0300 | |
branch | RCL_3 |
changeset 64 | 85902f042028 |
parent 56 | d48ab3b357f1 |
child 72 | a5e7a4f63858 |
permissions | -rw-r--r-- |
56 | 1 |
/* |
2 |
* Copyright (c) 2009 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: |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
#include "HgScrollbar.h" |
|
20 |
#include <ganes/HgScrollbarObserverIface.h> |
|
21 |
#include "HgConstants.h" |
|
22 |
||
23 |
#include <AknsUtils.h> |
|
24 |
#include <AknUtils.h> |
|
25 |
#include <AknsDrawUtils.h> |
|
26 |
||
27 |
#include <layoutmetadata.cdl.h> |
|
28 |
#include <aknlayoutscalable_avkon.cdl.h> |
|
29 |
#include <aknlayoutscalable_apps.cdl.h> |
|
30 |
||
31 |
#include <bitstd.h> |
|
32 |
#include <gulicon.h> |
|
33 |
||
34 |
#include <AknIconUtils.h> |
|
35 |
#include <AknsUtils.h> |
|
36 |
#include <AknsConstants.h> |
|
37 |
#include <w32std.h> |
|
38 |
||
39 |
// ----------------------------------------------------------------------------- |
|
40 |
// CHgScrollbar::NewL() |
|
41 |
// ----------------------------------------------------------------------------- |
|
42 |
// |
|
43 |
CHgScrollbar* CHgScrollbar::NewL( MHgScrollbarObserver& aObserver ) |
|
44 |
{ |
|
45 |
CHgScrollbar* self = new (ELeave) CHgScrollbar( aObserver ); |
|
46 |
CleanupStack::PushL( self ); |
|
47 |
self->ConstructL(); |
|
48 |
CleanupStack::Pop( self ); |
|
49 |
return self; |
|
50 |
} |
|
51 |
||
52 |
// ----------------------------------------------------------------------------- |
|
53 |
// CHgScrollbar::~CHgScrollbar() |
|
54 |
// ----------------------------------------------------------------------------- |
|
55 |
// |
|
56 |
CHgScrollbar::~CHgScrollbar() |
|
57 |
{ |
|
58 |
delete iScrollbarBg; |
|
59 |
delete iScrollbarHandle; |
|
60 |
delete iScrollbarHandleBg; |
|
61 |
delete iScrollbarBgSelected; |
|
62 |
delete iScrollbarHandleSelected; |
|
63 |
} |
|
64 |
||
65 |
// ----------------------------------------------------------------------------- |
|
66 |
// CHgScrollbar::CHgScrollbar() |
|
67 |
// ----------------------------------------------------------------------------- |
|
68 |
// |
|
69 |
CHgScrollbar::CHgScrollbar( MHgScrollbarObserver& aObserver ) |
|
70 |
: iObserver( aObserver ), |
|
71 |
iStatic( ETrue ) |
|
72 |
{ |
|
73 |
||
74 |
} |
|
75 |
||
76 |
// ----------------------------------------------------------------------------- |
|
77 |
// CHgScrollbar::ConstructL() |
|
78 |
// ----------------------------------------------------------------------------- |
|
79 |
// |
|
80 |
void CHgScrollbar::ConstructL() |
|
81 |
{ |
|
82 |
} |
|
83 |
||
84 |
// ----------------------------------------------------------------------------- |
|
85 |
// CHgScrollbar::SetScrollbarL() |
|
86 |
// ----------------------------------------------------------------------------- |
|
87 |
// |
|
88 |
void CHgScrollbar::InitScrollBarL( |
|
89 |
TRect aRect, |
|
90 |
TSize aTotalSize, |
|
91 |
TSize aViewSize, |
|
92 |
TBool aLandscapeScrolling ) |
|
93 |
{ |
|
94 |
if( iTotalSize == aTotalSize |
|
95 |
&& iViewSize == aViewSize |
|
96 |
&& iLandscapeScrolling == aLandscapeScrolling ) |
|
97 |
{ |
|
98 |
return; |
|
99 |
} |
|
100 |
||
101 |
TInt variety = aLandscapeScrolling ? 1 : 0; |
|
102 |
||
103 |
TAknLayoutRect layout; |
|
104 |
layout.LayoutRect(aRect, AknLayoutScalable_Avkon::scroll_pane( variety )); |
|
105 |
iScrollbarRect = layout.Rect(); |
|
106 |
||
107 |
TBool prevStatic = iStatic; |
|
108 |
||
109 |
if((aTotalSize.iHeight <= aViewSize.iHeight && !aLandscapeScrolling) |
|
110 |
|| (aTotalSize.iWidth <= aViewSize.iWidth && aLandscapeScrolling) ) |
|
111 |
{ |
|
112 |
iTotalSize = aViewSize; |
|
113 |
iStatic = ETrue; |
|
114 |
} |
|
115 |
else |
|
116 |
{ |
|
117 |
iTotalSize = aTotalSize; |
|
118 |
iStatic = EFalse; |
|
119 |
} |
|
120 |
||
121 |
// Do we need to init the bg graphics |
|
122 |
TBool initBg = (iViewSize != aViewSize) // view size has been changed |
|
123 |
|| (prevStatic != iStatic) // static value changed |
|
124 |
|| (iLandscapeScrolling != aLandscapeScrolling); // different scrolling direction |
|
125 |
||
126 |
iViewSize = aViewSize; |
|
127 |
iLandscapeScrolling = aLandscapeScrolling; |
|
128 |
iHandlePosition.SetXY(0,0); |
|
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
129 |
iHandlePos = 0.0; |
56 | 130 |
|
131 |
if(iLandscapeScrolling) |
|
132 |
{ |
|
133 |
iTotalLength = iTotalSize.iWidth - iViewSize.iWidth; |
|
134 |
} |
|
135 |
else |
|
136 |
{ |
|
137 |
iTotalLength = iTotalSize.iHeight - iViewSize.iHeight; |
|
138 |
} |
|
139 |
||
140 |
// Don't init icons in static mode since they are not drawn |
|
141 |
if(!iStatic) |
|
142 |
InitIconsL( initBg ); |
|
143 |
} |
|
144 |
||
145 |
// ----------------------------------------------------------------------------- |
|
146 |
// CHgScrollbar::SetViewPosition() |
|
147 |
// ----------------------------------------------------------------------------- |
|
148 |
// |
|
149 |
void CHgScrollbar::SetViewPosition( TPoint aPosition ) |
|
150 |
{ |
|
151 |
if(!iStatic) |
|
152 |
{ |
|
153 |
if(iLandscapeScrolling) |
|
154 |
{ |
|
155 |
if (AknLayoutUtils::LayoutMirrored()) |
|
156 |
{ |
|
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
157 |
iHandlePos = 1.0 - (TReal(aPosition.iX) / TReal(iTotalLength)); |
56 | 158 |
} |
159 |
else |
|
160 |
{ |
|
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
161 |
iHandlePos = TReal(aPosition.iX) / TReal(iTotalLength); |
56 | 162 |
} |
163 |
} |
|
164 |
else |
|
165 |
{ |
|
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
166 |
iHandlePos = TReal(aPosition.iY) / TReal(iTotalLength); |
56 | 167 |
} |
168 |
CheckHandlePosition( EFalse ); |
|
169 |
} |
|
170 |
} |
|
171 |
||
172 |
// ----------------------------------------------------------------------------- |
|
173 |
// CHgScrollbar::HandlePointerEventL() |
|
174 |
// ----------------------------------------------------------------------------- |
|
175 |
// |
|
176 |
TBool CHgScrollbar::HandlePointerEventL( const TPointerEvent& aEvent ) |
|
177 |
{ |
|
178 |
return HandleScrollBarPointerEvent( aEvent ); |
|
179 |
} |
|
180 |
||
181 |
// ----------------------------------------------------------------------------- |
|
182 |
// CHgScrollbar::HandleScrollBarPointerEvent() |
|
183 |
// ----------------------------------------------------------------------------- |
|
184 |
// |
|
185 |
TBool CHgScrollbar::HandleScrollBarPointerEvent( const TPointerEvent& aEvent ) |
|
186 |
{ |
|
187 |
TBool ret = EFalse; |
|
188 |
// Quick and dirty hack, remove when logic for fetching the correct drag rect is available |
|
189 |
TRect dragArea( iScrollbarRect ); |
|
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
190 |
if (iLandscapeScrolling) |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
191 |
{ |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
192 |
dragArea.iBr.iY += KScrollAreaOffset; |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
193 |
dragArea.iTl.iY -= KScrollAreaOffset; |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
194 |
} |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
195 |
else |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
196 |
{ |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
197 |
dragArea.iBr.iX += KScrollAreaOffset; |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
198 |
dragArea.iTl.iX -= KScrollAreaOffset; |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
199 |
} |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
200 |
|
56 | 201 |
// Start drag |
202 |
if( aEvent.iType == TPointerEvent::EButton1Down && dragArea.Contains(aEvent.iPosition)) |
|
203 |
{ |
|
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
204 |
TSize size = iHandleSize; |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
205 |
TRect handleRect; |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
206 |
if (iLandscapeScrolling) |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
207 |
{ |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
208 |
size.iHeight += KScrollAreaOffset*2; |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
209 |
handleRect = TRect( dragArea.iTl + TPoint(iHandlePos*iScrollLength, 0), size ); |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
210 |
} |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
211 |
else |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
212 |
{ |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
213 |
size.iWidth += KScrollAreaOffset*2; |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
214 |
handleRect = TRect( dragArea.iTl + TPoint(0, iHandlePos*iScrollLength), size ); |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
215 |
} |
56 | 216 |
iDragging = handleRect.Contains( aEvent.iPosition ); |
217 |
iPrevDrag = aEvent.iPosition; |
|
218 |
iHandler = ret = ETrue; |
|
219 |
CheckHandlePosition( !iStatic ); |
|
220 |
} |
|
221 |
||
222 |
// Drag |
|
223 |
if( aEvent.iType == TPointerEvent::EDrag && iHandler) |
|
224 |
{ |
|
225 |
if( iDragging ) |
|
226 |
{ |
|
227 |
if(iLandscapeScrolling) |
|
228 |
{ |
|
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
229 |
iHandlePos -= (iPrevDrag.iX - aEvent.iPosition.iX)/TReal(iScrollLength); |
56 | 230 |
} |
231 |
else |
|
232 |
{ |
|
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
233 |
iHandlePos -= (iPrevDrag.iY - aEvent.iPosition.iY)/TReal(iScrollLength); |
56 | 234 |
} |
235 |
CheckHandlePosition( !iStatic ); |
|
236 |
||
237 |
iPrevDrag = aEvent.iPosition; |
|
238 |
} |
|
239 |
ret = ETrue; |
|
240 |
} |
|
241 |
||
242 |
// End drag |
|
243 |
if( aEvent.iType == TPointerEvent::EButton1Up && iHandler) |
|
244 |
{ |
|
245 |
if(!iDragging) |
|
246 |
{ |
|
247 |
TBool below = iLandscapeScrolling ? |
|
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
248 |
aEvent.iPosition.iX > iHandlePos*iScrollLength |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
249 |
: aEvent.iPosition.iY > iHandlePos*iScrollLength; |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
250 |
if(below) |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
251 |
{ |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
252 |
iHandlePos += iPageSize; |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
253 |
} |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
254 |
else |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
255 |
{ |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
256 |
iHandlePos -= iPageSize; |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
257 |
} |
56 | 258 |
} |
259 |
CheckHandlePosition( !iStatic ); |
|
260 |
iHandler = iDragging = EFalse; |
|
261 |
ret = ETrue; |
|
262 |
} |
|
263 |
||
264 |
return ret; |
|
265 |
} |
|
266 |
||
267 |
||
268 |
// ----------------------------------------------------------------------------- |
|
269 |
// CHgScrollbar::Draw() |
|
270 |
// ----------------------------------------------------------------------------- |
|
271 |
// |
|
272 |
void CHgScrollbar::Draw( CWindowGc& aGc ) |
|
273 |
{ |
|
274 |
if(!iStatic) |
|
275 |
DrawScrollbar( aGc ); |
|
276 |
} |
|
277 |
||
278 |
// ----------------------------------------------------------------------------- |
|
279 |
// CHgScrollbar::DrawScrollbar() |
|
280 |
// ----------------------------------------------------------------------------- |
|
281 |
// |
|
282 |
void CHgScrollbar::DrawScrollbar( CWindowGc& aGc ) |
|
283 |
{ |
|
284 |
if(iScrollbarBg && iScrollbarHandle && iScrollbarHandleBg) |
|
285 |
{ |
|
286 |
if(iHandler) |
|
287 |
{ |
|
288 |
aGc.BitBltMasked(iScrollbarRect.iTl, |
|
289 |
iScrollbarHandleBg->Bitmap(), |
|
290 |
iScrollbarHandleBg->Bitmap()->SizeInPixels(), |
|
291 |
iScrollbarHandleBg->Mask(), |
|
292 |
EFalse); |
|
293 |
||
294 |
aGc.BitBltMasked(iScrollbarRect.iTl + iHandlePosition, |
|
295 |
iScrollbarHandleSelected->Bitmap(), |
|
296 |
iScrollbarHandleSelected->Bitmap()->SizeInPixels(), |
|
297 |
iScrollbarHandleSelected->Mask(), |
|
298 |
EFalse); |
|
299 |
} |
|
300 |
else |
|
301 |
{ |
|
302 |
aGc.BitBltMasked(iScrollbarRect.iTl, |
|
303 |
iScrollbarBg->Bitmap(), |
|
304 |
iScrollbarBg->Bitmap()->SizeInPixels(), |
|
305 |
iScrollbarBg->Mask(), |
|
306 |
EFalse); |
|
307 |
||
308 |
aGc.BitBltMasked(iScrollbarRect.iTl + iHandlePosition, |
|
309 |
iScrollbarHandle->Bitmap(), |
|
310 |
iScrollbarHandle->Bitmap()->SizeInPixels(), |
|
311 |
iScrollbarHandle->Mask(), |
|
312 |
EFalse); |
|
313 |
} |
|
314 |
} |
|
315 |
} |
|
316 |
||
317 |
// ----------------------------------------------------------------------------- |
|
318 |
// CHgScrollbar::CheckHandlePosition() |
|
319 |
// ----------------------------------------------------------------------------- |
|
320 |
// |
|
321 |
void CHgScrollbar::CheckHandlePosition( TBool aReportChange ) |
|
322 |
{ |
|
323 |
||
324 |
if(iLandscapeScrolling) |
|
325 |
{ |
|
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
326 |
if(iHandlePos < 0.0 ) |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
327 |
iHandlePos = 0.0; |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
328 |
if(iHandlePos > 1.0) |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
329 |
iHandlePos = 1; |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
330 |
|
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
331 |
iHandlePosition.SetXY(iHandlePos*iScrollLength, 0); |
56 | 332 |
} |
333 |
else |
|
334 |
{ |
|
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
335 |
if(iHandlePos < 0.0 ) |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
336 |
iHandlePos = 0.0; |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
337 |
if(iHandlePos > 1) |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
338 |
iHandlePos = 1.0; |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
339 |
|
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
340 |
iHandlePosition.SetXY(0, iHandlePos*iScrollLength); |
56 | 341 |
} |
342 |
if( aReportChange ) |
|
343 |
{ |
|
344 |
TPoint pos (iViewSize.iWidth/2, iViewSize.iHeight/2); |
|
345 |
if(iLandscapeScrolling) |
|
346 |
{ |
|
347 |
if (AknLayoutUtils::LayoutMirrored()) |
|
348 |
{ |
|
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
349 |
pos.iX += (1.0 - iHandlePos) * iTotalLength; |
56 | 350 |
} |
351 |
else |
|
352 |
{ |
|
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
353 |
pos.iX += iHandlePos * iTotalLength; |
56 | 354 |
} |
355 |
} |
|
356 |
else |
|
357 |
{ |
|
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
358 |
pos.iY += iHandlePos * iTotalLength; |
56 | 359 |
} |
360 |
||
361 |
iObserver.ScrollBarPositionChanged( pos ); |
|
362 |
} |
|
363 |
} |
|
364 |
||
365 |
// ----------------------------------------------------------------------------- |
|
366 |
// CHgScrollbar::InitIconsL() |
|
367 |
// ----------------------------------------------------------------------------- |
|
368 |
// |
|
369 |
void CHgScrollbar::InitIconsL( TBool aInitBgIcons ) |
|
370 |
{ |
|
371 |
if(aInitBgIcons) |
|
372 |
{ |
|
373 |
delete iScrollbarBg; iScrollbarBg = NULL; |
|
374 |
delete iScrollbarBgSelected; iScrollbarBgSelected = NULL; |
|
375 |
delete iScrollbarHandleBg; iScrollbarHandleBg = NULL; |
|
376 |
||
377 |
CreateIconL(iScrollbarBg, iScrollbarRect.Size()); |
|
378 |
CreateIconL(iScrollbarBgSelected, iScrollbarRect.Size()); |
|
379 |
CreateIconL(iScrollbarHandleBg, iScrollbarRect.Size()); |
|
380 |
} |
|
381 |
||
382 |
TReal xFactor = iScrollbarRect.Width()/TReal(iTotalSize.iWidth); |
|
383 |
TReal yFactor = iScrollbarRect.Height()/TReal(iTotalSize.iHeight); |
|
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
384 |
|
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
385 |
TReal handleSizeWidth = iViewSize.iWidth * xFactor; |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
386 |
TReal handleSizeHeight = iViewSize.iHeight * yFactor; |
56 | 387 |
|
388 |
if(iLandscapeScrolling) |
|
389 |
{ |
|
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
390 |
iPageSize = TReal(iViewSize.iWidth) / TReal(iTotalSize.iWidth - (iTotalSize.iWidth % iViewSize.iWidth) ); |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
391 |
TReal min = 2 * handleSizeHeight; |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
392 |
if( handleSizeWidth < min ) |
56 | 393 |
{ |
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
394 |
handleSizeWidth = min; |
56 | 395 |
} |
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
396 |
iScrollLength = TReal(iScrollbarRect.Width()) - handleSizeWidth; |
56 | 397 |
} |
398 |
else |
|
399 |
{ |
|
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
400 |
iPageSize = TReal(iViewSize.iHeight) / TReal(iTotalSize.iHeight - (iTotalSize.iHeight % iViewSize.iHeight) ); |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
401 |
TReal min = 2 * handleSizeWidth; |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
402 |
if( handleSizeHeight < min ) |
56 | 403 |
{ |
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
404 |
handleSizeHeight = min; |
56 | 405 |
} |
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
406 |
iScrollLength = TReal(iScrollbarRect.Height()) - handleSizeHeight; |
56 | 407 |
} |
408 |
||
64
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
409 |
iHandleSize = TSize(handleSizeWidth,handleSizeHeight); |
85902f042028
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
410 |
|
56 | 411 |
delete iScrollbarHandle; iScrollbarHandle = NULL; |
412 |
delete iScrollbarHandleSelected; iScrollbarHandleSelected = NULL; |
|
413 |
||
414 |
CreateIconL(iScrollbarHandle, iHandleSize ); |
|
415 |
CreateIconL(iScrollbarHandleSelected, iHandleSize ); |
|
416 |
||
417 |
if( iLandscapeScrolling ) |
|
418 |
{ |
|
419 |
if( aInitBgIcons ) |
|
420 |
{ |
|
421 |
DrawIconL( *iScrollbarBg, |
|
422 |
KAknsIIDQsnCpScrollHorizontalBgTop, |
|
423 |
KAknsIIDQsnCpScrollHorizontalBgMiddle, |
|
424 |
KAknsIIDQsnCpScrollHorizontalBgBottom ); |
|
425 |
||
426 |
// TODO, check if this is needed. |
|
427 |
// DrawIconL( *iScrollbarHandleBg, |
|
428 |
// KAknsIIDQsnCpScrollHorizontalHandleBgTop, |
|
429 |
// KAknsIIDQsnCpScrollHorizontalHandleBgMiddle, |
|
430 |
// KAknsIIDQsnCpScrollHorizontalHandleBgBottom ); |
|
431 |
||
432 |
DrawIconL( *iScrollbarBgSelected, |
|
433 |
KAknsIIDQsnCpScrollHorizontalBgTopPressed, |
|
434 |
KAknsIIDQsnCpScrollHorizontalBgMiddlePressed, |
|
435 |
KAknsIIDQsnCpScrollHorizontalBgBottomPressed ); |
|
436 |
} |
|
437 |
||
438 |
DrawIconL( *iScrollbarHandle, |
|
439 |
KAknsIIDQsnCpScrollHorizontalHandleTop, |
|
440 |
KAknsIIDQsnCpScrollHorizontalHandleMiddle, |
|
441 |
KAknsIIDQsnCpScrollHorizontalHandleBottom); |
|
442 |
||
443 |
DrawIconL( *iScrollbarHandleSelected, |
|
444 |
KAknsIIDQsnCpScrollHorizontalHandleTopPressed, |
|
445 |
KAknsIIDQsnCpScrollHorizontalHandleMiddlePressed, |
|
446 |
KAknsIIDQsnCpScrollHorizontalHandleBottomPressed ); |
|
447 |
} |
|
448 |
else |
|
449 |
{ |
|
450 |
if(aInitBgIcons) |
|
451 |
{ |
|
452 |
DrawIconL( *iScrollbarBg, |
|
453 |
KAknsIIDQsnCpScrollBgTop, |
|
454 |
KAknsIIDQsnCpScrollBgMiddle, |
|
455 |
KAknsIIDQsnCpScrollBgBottom ); |
|
456 |
||
457 |
DrawIconL( *iScrollbarHandleBg, |
|
458 |
KAknsIIDQsnCpScrollHandleBgTop, |
|
459 |
KAknsIIDQsnCpScrollHandleBgMiddle, |
|
460 |
KAknsIIDQsnCpScrollHandleBgBottom ); |
|
461 |
||
462 |
DrawIconL( *iScrollbarBgSelected, |
|
463 |
KAknsIIDQsnCpScrollBgTopPressed, |
|
464 |
KAknsIIDQsnCpScrollBgMiddlePressed, |
|
465 |
KAknsIIDQsnCpScrollBgBottomPressed ); |
|
466 |
} |
|
467 |
||
468 |
DrawIconL( *iScrollbarHandle, |
|
469 |
KAknsIIDQsnCpScrollHandleTop, |
|
470 |
KAknsIIDQsnCpScrollHandleMiddle, |
|
471 |
KAknsIIDQsnCpScrollHandleBottom); |
|
472 |
||
473 |
DrawIconL( *iScrollbarHandleSelected, |
|
474 |
KAknsIIDQsnCpScrollHandleTopPressed, |
|
475 |
KAknsIIDQsnCpScrollHandleMiddlePressed, |
|
476 |
KAknsIIDQsnCpScrollHandleBottomPressed ); |
|
477 |
} |
|
478 |
} |
|
479 |
||
480 |
// ----------------------------------------------------------------------------- |
|
481 |
// CHgScrollbar::CreateIconL() |
|
482 |
// ----------------------------------------------------------------------------- |
|
483 |
// |
|
484 |
void CHgScrollbar::CreateIconL( CGulIcon*& aIcon, TSize aSize) |
|
485 |
{ |
|
486 |
CFbsBitmap* bmap = new (ELeave) CFbsBitmap; |
|
487 |
CleanupStack::PushL( bmap ); |
|
488 |
User::LeaveIfError( bmap->Create( aSize , EColor64K)); |
|
489 |
||
490 |
CFbsBitmap* mask = new (ELeave) CFbsBitmap; |
|
491 |
CleanupStack::PushL( mask ); |
|
492 |
User::LeaveIfError( mask->Create( aSize , EGray256)); |
|
493 |
||
494 |
aIcon = CGulIcon::NewL( bmap, mask ); |
|
495 |
||
496 |
CleanupStack::Pop(2, bmap); |
|
497 |
} |
|
498 |
||
499 |
// ----------------------------------------------------------------------------- |
|
500 |
// CHgScrollbar::DrawIconL() |
|
501 |
// ----------------------------------------------------------------------------- |
|
502 |
// |
|
503 |
void CHgScrollbar::DrawIconL( CGulIcon& aIcon, |
|
504 |
const TAknsItemID& aTop, |
|
505 |
const TAknsItemID& aMiddle, |
|
506 |
const TAknsItemID& aBottom ) |
|
507 |
{ |
|
508 |
TRect rect; |
|
509 |
TSize iconSize(aIcon.Bitmap()->SizeInPixels()); |
|
510 |
TSize tSize; |
|
511 |
TPoint point(0,0); |
|
512 |
if(iLandscapeScrolling) |
|
513 |
{ |
|
514 |
tSize.SetSize(iconSize.iHeight, iconSize.iHeight); |
|
515 |
} |
|
516 |
else |
|
517 |
{ |
|
518 |
tSize.SetSize(iconSize.iWidth, iconSize.iWidth); |
|
519 |
} |
|
520 |
||
521 |
// TOP |
|
522 |
rect.SetRect(point, tSize); |
|
523 |
DrawBitmapL( aIcon, aTop, rect ); |
|
524 |
||
525 |
// MIDDLE |
|
526 |
TSize middlesize(iconSize); |
|
527 |
if(iLandscapeScrolling) |
|
528 |
{ |
|
529 |
point.iX = tSize.iWidth; |
|
530 |
middlesize.iWidth -= 2*tSize.iWidth; |
|
531 |
} |
|
532 |
else |
|
533 |
{ |
|
534 |
point.iY = tSize.iHeight; |
|
535 |
middlesize.iHeight -= 2*tSize.iHeight; |
|
536 |
} |
|
537 |
rect.SetRect(point, middlesize); |
|
538 |
DrawBitmapL( aIcon, aMiddle, rect); |
|
539 |
||
540 |
// BOTTOM |
|
541 |
point = iconSize.AsPoint()-tSize; |
|
542 |
rect.SetRect(point, tSize); |
|
543 |
DrawBitmapL( aIcon, aBottom, rect ); |
|
544 |
} |
|
545 |
||
546 |
// ----------------------------------------------------------------------------- |
|
547 |
// CHgScrollbar::DrawBitmapL() |
|
548 |
// ----------------------------------------------------------------------------- |
|
549 |
// |
|
550 |
void CHgScrollbar::DrawBitmapL( CGulIcon& aIcon, |
|
551 |
const TAknsItemID& aItem, |
|
552 |
const TRect& aDestRect ) |
|
553 |
{ |
|
554 |
CFbsBitmap* bitmap = NULL; |
|
555 |
CFbsBitmap* mask = NULL; |
|
556 |
TRAP_IGNORE( AknsUtils::CreateIconL(AknsUtils::SkinInstance(), aItem, bitmap, mask, KNullDesC, -1, -1); ) |
|
557 |
||
558 |
if(!bitmap) |
|
559 |
{ |
|
560 |
AknsUtils::CreateIconL(AknsUtils::SkinInstance(), aItem, bitmap, KNullDesC, -1); |
|
561 |
} |
|
562 |
||
563 |
AknIconUtils::SetSize(bitmap, aDestRect.Size(), EAspectRatioNotPreserved); |
|
564 |
ScaleBitmapL(aDestRect, aIcon.Bitmap(), bitmap); |
|
565 |
||
566 |
if(mask) |
|
567 |
{ |
|
568 |
AknIconUtils::SetSize(mask, aDestRect.Size(), EAspectRatioNotPreserved); |
|
569 |
ScaleBitmapL(aDestRect, aIcon.Mask(), mask); |
|
570 |
} |
|
571 |
||
572 |
delete bitmap; bitmap = NULL; |
|
573 |
delete mask; mask = NULL; |
|
574 |
} |
|
575 |
||
576 |
||
577 |
// ----------------------------------------------------------------------------- |
|
578 |
// CHgScrollbar::ScaleBitmapL() |
|
579 |
// ----------------------------------------------------------------------------- |
|
580 |
// |
|
581 |
void CHgScrollbar::ScaleBitmapL( const TRect& aDestRect, |
|
582 |
CFbsBitmap* aDest, |
|
583 |
const CFbsBitmap* aSrc) |
|
584 |
{ |
|
585 |
CFbsBitmapDevice* device = CFbsBitmapDevice::NewL(aDest); |
|
586 |
CleanupStack::PushL(device); |
|
587 |
||
588 |
CFbsBitGc* gc = NULL; |
|
589 |
User::LeaveIfError(device->CreateContext(gc)); |
|
590 |
CleanupStack::PushL(gc); |
|
591 |
||
592 |
gc->DrawBitmap(aDestRect, aSrc); |
|
593 |
||
594 |
CleanupStack::PopAndDestroy(2, device); |
|
595 |
} |
|
596 |
||
597 |
// ----------------------------------------------------------------------------- |
|
598 |
// CHgScrollbar::ScrollbarBg() |
|
599 |
// ----------------------------------------------------------------------------- |
|
600 |
// |
|
601 |
const CGulIcon* CHgScrollbar::ScrollbarBg() const |
|
602 |
{ |
|
603 |
return iScrollbarBg; |
|
604 |
} |
|
605 |
||
606 |
||
607 |
const CGulIcon* CHgScrollbar::ScrollbarHandleBg() const |
|
608 |
{ |
|
609 |
return iScrollbarHandleBg; |
|
610 |
} |
|
611 |
||
612 |
const CGulIcon* CHgScrollbar::ScrollbarHandle() const |
|
613 |
{ |
|
614 |
return iScrollbarHandle; |
|
615 |
} |
|
616 |
||
617 |
const CGulIcon* CHgScrollbar::ScrollbarBgSelected() const |
|
618 |
{ |
|
619 |
return iScrollbarBgSelected; |
|
620 |
} |
|
621 |
||
622 |
const CGulIcon* CHgScrollbar::ScrollbarHandleSelected() const |
|
623 |
{ |
|
624 |
return iScrollbarHandleSelected; |
|
625 |
} |
|
626 |
||
627 |
const TRect& CHgScrollbar::ScrollbarRect() const |
|
628 |
{ |
|
629 |
return iScrollbarRect; |
|
630 |
} |
|
631 |
||
632 |
const TPoint& CHgScrollbar::HandlePosition() const |
|
633 |
{ |
|
634 |
return iHandlePosition; |
|
635 |
} |
|
636 |
||
637 |
TBool CHgScrollbar::IsStatic() const |
|
638 |
{ |
|
639 |
return iStatic; |
|
640 |
} |
|
641 |
||
642 |
TBool CHgScrollbar::IsDragging() const |
|
643 |
{ |
|
644 |
return iDragging; |
|
645 |
} |
|
646 |
||
647 |
TBool CHgScrollbar::Handler() const |
|
648 |
{ |
|
649 |
return iHandler; |
|
650 |
} |
|
651 |
||
652 |
void CHgScrollbar::Reset() |
|
653 |
{ |
|
654 |
iHandler = iDragging = EFalse; |
|
655 |
} |
|
656 |
||
657 |
// End of file |