author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 13 Oct 2010 14:23:59 +0300 | |
branch | RCL_3 |
changeset 83 | 26b2b12093af |
parent 66 | 2455ef1f5bbc |
permissions | -rw-r--r-- |
66 | 1 |
/******************************************************************************* |
2 |
* Copyright (c) 2005, 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
* All rights reserved. This program and the accompanying materials |
|
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
|
5 |
* which accompanies this distribution, and is available at |
|
6 |
* http://www.eclipse.org/legal/epl-v10.html |
|
7 |
* |
|
8 |
* Contributors: |
|
9 |
* Nokia Corporation - S60 implementation |
|
10 |
*******************************************************************************/ |
|
11 |
||
12 |
||
13 |
#include <gulicon.h> |
|
14 |
#include <AknsDrawUtils.h> |
|
15 |
#include <AknUtils.h> |
|
16 |
#include <swtlaffacade.h> |
|
17 |
#include <avkon.mbg> |
|
18 |
#ifdef RD_TACTILE_FEEDBACK |
|
19 |
#include <touchfeedback.h> |
|
20 |
#endif // RD_TACTILE_FEEDBACK |
|
21 |
#include "swtrotateimage.h" |
|
22 |
#include "swtslider.h" |
|
23 |
||
24 |
||
25 |
const TInt KSwtSliderDefaultThumb(1); |
|
26 |
||
27 |
#ifdef RD_TACTILE_FEEDBACK |
|
28 |
// Id for the only feedback area |
|
29 |
const TInt KTouchFeedbackRectId1(0); |
|
30 |
#endif // RD_TACTILE_FEEDBACK |
|
31 |
||
32 |
||
33 |
// ======== MEMBER FUNCTIONS ======== |
|
34 |
||
35 |
||
36 |
/** |
|
37 |
* 1st & 2nd phase constructors wrapper |
|
38 |
*/ |
|
39 |
CSwtSlider* CSwtSlider::NewL(MSwtDisplay& aDisplay, |
|
40 |
TSwtPeer aPeer, |
|
41 |
MSwtComposite& aParent, |
|
42 |
TInt aStyle) |
|
43 |
{ |
|
44 |
CSwtSlider* self = new(ELeave) CSwtSlider(aDisplay, aPeer, aParent, aStyle); |
|
45 |
CleanupStack::PushL(self); |
|
46 |
self->ConstructL(); |
|
47 |
self->InitControlBaseL(); |
|
48 |
CleanupStack::Pop(self); |
|
49 |
return self; |
|
50 |
} |
|
51 |
||
52 |
CSwtSlider::CSwtSlider(MSwtDisplay& aDisplay, TSwtPeer aPeer, |
|
53 |
MSwtComposite& aParent, TInt aStyle) |
|
54 |
: ASwtControlBase(aDisplay, aPeer, &aParent, aStyle) |
|
55 |
, iMaximum(10) |
|
56 |
, iIncrement(1) |
|
57 |
, iPageIncrement(5) |
|
58 |
{ |
|
59 |
SetComponentsToInheritVisibility(ETrue); |
|
60 |
} |
|
61 |
||
62 |
||
63 |
CSwtSlider::~CSwtSlider() |
|
64 |
{ |
|
65 |
#ifdef RD_TACTILE_FEEDBACK |
|
66 |
if (iFeedback) |
|
67 |
{ |
|
68 |
iFeedback->RemoveFeedbackForControl(this); |
|
69 |
} |
|
70 |
#endif // RD_TACTILE_FEEDBACK |
|
71 |
delete iImagesRotator; |
|
72 |
delete iSliderImageMask; |
|
73 |
delete iSliderImage; |
|
74 |
} |
|
75 |
||
76 |
/** |
|
77 |
* 2nd phase constructor |
|
78 |
*/ |
|
79 |
void CSwtSlider::ConstructL() |
|
80 |
{ |
|
81 |
// Get parent |
|
82 |
CCoeControl& coeParent = iParent->Control()->CoeControl(); |
|
83 |
SetContainerWindowL(coeParent); |
|
84 |
||
85 |
if (iStyle & KSwtStyleVertical) |
|
86 |
{ |
|
87 |
iImagesRotator = CAORotateImage::NewL(); |
|
88 |
||
89 |
iIncreaseKey = EKeyUpArrow; |
|
90 |
iDecreaseKey = EKeyDownArrow; |
|
91 |
} |
|
92 |
else if (iStyle & KSwtStyleHorizontal) |
|
93 |
{ |
|
94 |
if (AknLayoutUtils::LayoutMirrored()) |
|
95 |
{ |
|
96 |
iIncreaseKey = EKeyLeftArrow; |
|
97 |
iDecreaseKey = EKeyRightArrow; |
|
98 |
} |
|
99 |
else |
|
100 |
{ |
|
101 |
iIncreaseKey = EKeyRightArrow; |
|
102 |
iDecreaseKey = EKeyLeftArrow; |
|
103 |
} |
|
104 |
} |
|
105 |
||
106 |
SetPosition(TPoint(0, 0)); |
|
107 |
SetSize(TSize(0, 0)); |
|
108 |
||
109 |
// Synchronize with parent's state |
|
110 |
CAknControl::MakeVisible(coeParent.IsVisible()); |
|
111 |
CAknControl::SetDimmed(coeParent.IsDimmed()); |
|
112 |
||
113 |
SetBackground(this); // Back will be drawn by ASwtControlBase::Draw |
|
114 |
||
115 |
// Ready to be drawn |
|
116 |
ActivateL(); |
|
117 |
||
118 |
#ifdef RD_TACTILE_FEEDBACK |
|
119 |
iFeedback = MTouchFeedback::Instance(); |
|
120 |
#ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
121 |
// Disabling feedback for CSwtSlider. |
|
122 |
// When enabled - first tap on any slider position creates extra |
|
123 |
// feedback, that is not needed. |
|
124 |
{ |
|
125 |
iFeedback->EnableFeedbackForControl(this, EFalse); |
|
126 |
} |
|
127 |
#endif // RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
128 |
#endif // RD_TACTILE_FEEDBACK |
|
129 |
} |
|
130 |
||
131 |
||
132 |
/** |
|
133 |
* Slider image is composed manually here because we want to be able to |
|
134 |
* scale it to fit the control's size. |
|
135 |
*/ |
|
136 |
CGulIcon* CSwtSlider::CreateSliderIconL(TInt aValue, TInt aMinValue, TInt aMaxValue) |
|
137 |
{ |
|
138 |
CGulIcon* icon = CGulIcon::NewLC(); |
|
139 |
||
140 |
||
141 |
// The function used to get the layout data |
|
142 |
TAknLayoutRect(&Laf)(CSwtLafFacade::TSwtLafFacadeRectId, |
|
143 |
const TRect&, |
|
144 |
TInt, |
|
145 |
TInt, |
|
146 |
TInt) = CSwtLafFacade::GetLayoutRect; |
|
147 |
||
148 |
// Get slider pane layout |
|
149 |
TRect dummyParentRect(TPoint(0, 0), GetPreferredSliderSize()); |
|
150 |
// Scale the layout to the size of the control. |
|
151 |
// We refuse to make it smaller than the Min( layoutwidth, layoutheight ). |
|
152 |
TRect clientRect(ClientRect()); |
|
153 |
if (iStyle & KSwtStyleVertical) |
|
154 |
{ |
|
155 |
// We always build horizontal image, it will be rotated later. |
|
156 |
dummyParentRect.SetWidth(Max(clientRect.Height(), dummyParentRect.Height())); |
|
157 |
} |
|
158 |
else |
|
159 |
{ |
|
160 |
dummyParentRect.SetWidth(Max(clientRect.Width(), dummyParentRect.Height())); |
|
161 |
} |
|
162 |
TRect sliderPane(Laf(CSwtLafFacade::ESliderSetPaneCP3, dummyParentRect, 0, 0, 0).Rect()); |
|
163 |
||
164 |
// Get background graphic layout |
|
165 |
TRect topLeftRect(Laf(CSwtLafFacade::EBgSetOptPaneG2, sliderPane, 0, 0, 0).Rect()); |
|
166 |
TRect bottomRightRect(Laf(CSwtLafFacade::EBgSetOptPaneG5, sliderPane, 0, 0, 0).Rect()); |
|
167 |
TRect outerRect(dummyParentRect); |
|
168 |
TRect innerRect(topLeftRect.Width(), |
|
169 |
topLeftRect.Height(), |
|
170 |
outerRect.Width() - bottomRightRect.Width(), |
|
171 |
outerRect.Height() - bottomRightRect.Height()); |
|
172 |
||
173 |
// Get line graphic layout |
|
174 |
TRect lineRect(Laf(CSwtLafFacade::ESliderSetPaneG1, sliderPane, 0, 0, 0).Rect()); |
|
175 |
||
176 |
// Get marker graphic layout (size only actually) |
|
177 |
TRect markerRect(Laf(CSwtLafFacade::ESliderSetPaneG2, sliderPane, 0, 0, 0).Rect()); |
|
178 |
||
179 |
// Get marker graphic |
|
180 |
CFbsBitmap* marker = NULL; |
|
181 |
CFbsBitmap* markerMask = NULL; |
|
182 |
AknsUtils::CreateIconLC(AknsUtils::SkinInstance(), |
|
183 |
KAknsIIDQgnIndiSliderSet, |
|
184 |
marker, markerMask, |
|
185 |
AknIconUtils::AvkonIconFileName(), |
|
186 |
EMbmAvkonQgn_indi_slider_edit, |
|
187 |
EMbmAvkonQgn_indi_slider_edit_mask); |
|
188 |
AknIconUtils::SetSize(marker, markerRect.Size()); |
|
189 |
||
190 |
// Get line graphic |
|
191 |
CFbsBitmap* line = NULL; |
|
192 |
CFbsBitmap* lineMask = NULL; |
|
193 |
AknsUtils::CreateIconLC(AknsUtils::SkinInstance(), |
|
194 |
KAknsIIDQgnGrafLinePrimaryHorizontal, |
|
195 |
line, lineMask, |
|
196 |
AknIconUtils::AvkonIconFileName(), |
|
197 |
EMbmAvkonQgn_graf_line_primary_horizontal, |
|
198 |
EMbmAvkonQgn_graf_line_primary_horizontal_mask); |
|
199 |
AknIconUtils::SetSize(line, |
|
200 |
lineRect.Size(), |
|
201 |
EAspectRatioNotPreserved); |
|
202 |
||
203 |
// Create a bitmap to draw the slider components on to |
|
204 |
CFbsBitmap* bitmap = new(ELeave) CFbsBitmap; |
|
205 |
CleanupStack::PushL(bitmap); |
|
206 |
User::LeaveIfError(bitmap->Create( |
|
207 |
dummyParentRect.Size(), iDisplay.CoeEnv()->ScreenDevice()->DisplayMode())); |
|
208 |
||
209 |
// Create a gc for drawing to the bitmap |
|
210 |
CFbsBitGc* fbsBitGc = CFbsBitGc::NewL(); |
|
211 |
CleanupStack::PushL(fbsBitGc); |
|
212 |
CFbsBitmapDevice* bmpDevice = CFbsBitmapDevice::NewL(bitmap); |
|
213 |
CleanupStack::PushL(bmpDevice); |
|
214 |
fbsBitGc->Activate(bmpDevice); |
|
215 |
||
216 |
// The actual drawing: |
|
217 |
||
218 |
// Draw the background graphic |
|
219 |
const TAknsItemID *frameId = &KAknsIIDQsnFrSetOptFoc; |
|
220 |
CAknsFrameBackgroundControlContext* cc = |
|
221 |
CAknsFrameBackgroundControlContext::NewL(*frameId, outerRect, innerRect, EFalse); |
|
222 |
AknsDrawUtils::DrawBackground(AknsUtils::SkinInstance(), cc, NULL, *fbsBitGc, |
|
223 |
outerRect.iTl, outerRect, KAknsDrawParamDefault); |
|
224 |
delete cc; |
|
225 |
||
226 |
// Draw the line graphic |
|
227 |
fbsBitGc->BitBltMasked(lineRect.iTl, |
|
228 |
line, |
|
229 |
lineRect.Size(), |
|
230 |
lineMask, |
|
231 |
EFalse); |
|
232 |
||
233 |
// Draw the marker graphic |
|
234 |
TInt bitmapRun = lineRect.Width() - marker->SizeInPixels().iWidth; |
|
235 |
TInt range = aMaxValue - aMinValue; |
|
236 |
TInt pos = ((bitmapRun * (aValue - aMinValue)) / range); |
|
237 |
TPoint markerPos = TPoint(pos + markerRect.iTl.iX, markerRect.iTl.iY); |
|
238 |
TRect srcRect(0, 0, markerRect.Width(), markerRect.Height()); |
|
239 |
fbsBitGc->BitBltMasked(markerPos, marker, srcRect, |
|
240 |
markerMask, EFalse); |
|
241 |
||
242 |
CleanupStack::PopAndDestroy(bmpDevice); |
|
243 |
CleanupStack::PopAndDestroy(fbsBitGc); |
|
244 |
||
245 |
icon->SetBitmap(bitmap); |
|
246 |
||
247 |
// Then create the mask |
|
248 |
CFbsBitmap* mask = new(ELeave) CFbsBitmap; |
|
249 |
CleanupStack::PushL(mask); |
|
250 |
||
251 |
TDisplayMode mode = lineMask->DisplayMode(); |
|
252 |
if (mode == ENone) |
|
253 |
{ |
|
254 |
mode = EGray256; |
|
255 |
} |
|
256 |
User::LeaveIfError(mask->Create(bitmap->SizeInPixels(), mode)); |
|
257 |
||
258 |
// A gc for drawing the mask |
|
259 |
fbsBitGc = CFbsBitGc::NewL(); |
|
260 |
CleanupStack::PushL(fbsBitGc); |
|
261 |
bmpDevice = CFbsBitmapDevice::NewL(mask); |
|
262 |
fbsBitGc->Activate(bmpDevice); |
|
263 |
||
264 |
// Write mask data |
|
265 |
fbsBitGc->SetPenStyle(CGraphicsContext::ENullPen); |
|
266 |
fbsBitGc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
267 |
fbsBitGc->SetBrushColor(KRgbWhite); |
|
268 |
fbsBitGc->DrawRect(TRect(mask->SizeInPixels())); |
|
269 |
AknsDrawUtils::DrawFrame(AknsUtils::SkinInstance(), *fbsBitGc, |
|
270 |
outerRect, innerRect, |
|
271 |
KAknsIIDQsnFrSetOptFoc, |
|
272 |
KAknsIIDQsnFrSetOptFocCenter, |
|
273 |
KAknsSDMAlphaOnly); |
|
274 |
delete bmpDevice; |
|
275 |
CleanupStack::PopAndDestroy(fbsBitGc); |
|
276 |
||
277 |
icon->SetMask(mask); |
|
278 |
||
279 |
CleanupStack::Pop(mask); |
|
280 |
CleanupStack::Pop(bitmap); |
|
281 |
CleanupStack::PopAndDestroy(4); // line, lineMask, marker, markerMask |
|
282 |
CleanupStack::Pop(icon); |
|
283 |
||
284 |
return icon; |
|
285 |
} |
|
286 |
||
287 |
||
288 |
TSize CSwtSlider::GetPreferredSliderSize() const |
|
289 |
{ |
|
290 |
TRect rect; |
|
291 |
AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect); |
|
292 |
rect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::EListScrollGenPane, rect, 0).Rect(); |
|
293 |
rect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::EListGenPane, rect, 0).Rect(); |
|
294 |
rect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::EListSettingNumberPane, rect, 0).Rect(); |
|
295 |
rect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::ESetValuePane, rect, 0).Rect(); |
|
296 |
return rect.Size(); |
|
297 |
} |
|
298 |
||
299 |
void CSwtSlider::UpdateTouchFeedbackRect() const |
|
300 |
{ |
|
301 |
#ifdef RD_TACTILE_FEEDBACK |
|
302 |
if (iFeedback) |
|
303 |
{ |
|
304 |
iFeedback->SetFeedbackArea(this, KTouchFeedbackRectId1, Rect(), |
|
305 |
ETouchFeedbackBasic, ETouchEventStylusDown); |
|
306 |
} |
|
307 |
#endif //RD_TACTILE_FEEDBACK |
|
308 |
} |
|
309 |
||
310 |
void CSwtSlider::UpdateSliderImageL() |
|
311 |
{ |
|
312 |
if (iStyle & KSwtStyleVertical) |
|
313 |
{ |
|
314 |
iImagesRotator->RemoveAllImages(); |
|
315 |
} |
|
316 |
||
317 |
if (iSliderImage) |
|
318 |
{ |
|
319 |
delete iSliderImage; |
|
320 |
} |
|
321 |
||
322 |
if (iSliderImageMask) |
|
323 |
{ |
|
324 |
delete iSliderImageMask; |
|
325 |
} |
|
326 |
||
327 |
TInt nativeSliderMax = iMaximum - KSwtSliderDefaultThumb; |
|
328 |
||
329 |
// If native slider maximum value is the same as minimum value, increment the |
|
330 |
// value by one to prevent icon creation from failing. |
|
331 |
if (iMinimum == nativeSliderMax) |
|
332 |
{ |
|
333 |
nativeSliderMax++; |
|
334 |
} |
|
335 |
||
336 |
CGulIcon* icon = CreateSliderIconL(iSelection, iMinimum, nativeSliderMax); |
|
337 |
CleanupStack::PushL(icon); |
|
338 |
||
339 |
icon->SetBitmapsOwnedExternally(ETrue); |
|
340 |
iSliderImage = icon->Bitmap(); |
|
341 |
iSliderImageMask = icon->Mask(); |
|
342 |
||
343 |
CleanupStack::PopAndDestroy(); // icon |
|
344 |
||
345 |
iImageSize = iSliderImage->SizeInPixels(); |
|
346 |
||
347 |
if (iStyle & KSwtStyleVertical) |
|
348 |
{ |
|
349 |
// Update the image size before the rotation of the image. |
|
350 |
iImageSize.SetSize(iImageSize.iHeight, iImageSize.iWidth); |
|
351 |
||
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
352 |
iImagesRotator->AddImage(iSliderImage); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
353 |
iImagesRotator->AddImage(iSliderImageMask); |
66 | 354 |
|
355 |
iImagesRotator->Start(this); |
|
356 |
} |
|
357 |
else |
|
358 |
{ |
|
359 |
if (!(iCtrlFlags & MSwtControl::EFlagDoNotDraw)) |
|
360 |
{ |
|
361 |
if (IsPaintingUrgently()) |
|
362 |
{ |
|
363 |
PaintUrgently(Rect()) ; |
|
364 |
} |
|
365 |
else |
|
366 |
{ |
|
367 |
RWindow* window = static_cast<RWindow*>(DrawableWindow()); |
|
368 |
TRect dirtyRect(Rect()); |
|
369 |
dirtyRect.Move(window->Position()); |
|
370 |
Paint(dirtyRect); |
|
371 |
} |
|
372 |
} |
|
373 |
} |
|
374 |
} |
|
375 |
||
376 |
void CSwtSlider::AdjustSelectionValue() |
|
377 |
{ |
|
378 |
TInt value = iSelection; |
|
379 |
||
380 |
if (value > (iMaximum-KSwtSliderDefaultThumb)) |
|
381 |
{ |
|
382 |
value = iMaximum - KSwtSliderDefaultThumb; |
|
383 |
} |
|
384 |
else if (value < iMinimum) |
|
385 |
{ |
|
386 |
value = iMinimum; |
|
387 |
} |
|
388 |
||
389 |
iSelection = value; |
|
390 |
} |
|
391 |
||
392 |
void CSwtSlider::ClipAndDrawImage(CWindowGc& aGC, const TRect& /*aRect*/) const |
|
393 |
{ |
|
394 |
aGC.SetOpaque(EFalse); |
|
395 |
TRect clientRect(ClientRect()); |
|
396 |
TPoint imagePosition(clientRect.iTl); |
|
397 |
TRect rectImageSrc(0, 0, iImageSize.iWidth, iImageSize.iHeight); |
|
398 |
||
399 |
if (clientRect.Width() >= iImageSize.iWidth) |
|
400 |
{ |
|
401 |
imagePosition.iX += (clientRect.Width() - iImageSize.iWidth) / 2; |
|
402 |
} |
|
403 |
else |
|
404 |
{ |
|
405 |
rectImageSrc.iTl.iX = iImageSize.iWidth / 2 - clientRect.Width() / 2; |
|
406 |
rectImageSrc.SetWidth(clientRect.Width()); |
|
407 |
} |
|
408 |
||
409 |
if (clientRect.Height() >= iImageSize.iHeight) |
|
410 |
{ |
|
411 |
imagePosition.iY += (clientRect.Height() - iImageSize.iHeight) / 2; |
|
412 |
} |
|
413 |
else |
|
414 |
{ |
|
415 |
rectImageSrc.iTl.iY = iImageSize.iHeight / 2 - clientRect.Height() / 2; |
|
416 |
rectImageSrc.SetHeight(clientRect.Height()); |
|
417 |
} |
|
418 |
||
419 |
aGC.BitBltMasked(imagePosition, iSliderImage, rectImageSrc, iSliderImageMask, EFalse); |
|
420 |
} |
|
421 |
||
422 |
// |
|
423 |
// Virtual methods from CCoeControl |
|
424 |
// |
|
425 |
TSize CSwtSlider::MinimumSize() |
|
426 |
{ |
|
427 |
return BorderOuterRect(iImageSize).Size(); |
|
428 |
} |
|
429 |
||
430 |
void CSwtSlider::MakeVisible(TBool aVisible) |
|
431 |
{ |
|
432 |
#ifdef RD_TACTILE_FEEDBACK |
|
433 |
if (iFeedback) |
|
434 |
{ |
|
435 |
iFeedback->EnableFeedbackForControl(this, aVisible); |
|
436 |
} |
|
437 |
#endif // RD_TACTILE_FEEDBACK |
|
438 |
CAknControl::MakeVisible(aVisible); |
|
439 |
||
440 |
FocusabilityChanged(); |
|
441 |
} |
|
442 |
||
443 |
void CSwtSlider::SetDimmed(TBool aDimmed) |
|
444 |
{ |
|
445 |
#ifdef RD_TACTILE_FEEDBACK |
|
446 |
if (iFeedback) |
|
447 |
{ |
|
448 |
iFeedback->EnableFeedbackForControl(this, !aDimmed); |
|
449 |
} |
|
450 |
#endif // RD_TACTILE_FEEDBACK |
|
451 |
CAknControl::SetDimmed(aDimmed); |
|
452 |
||
453 |
FocusabilityChanged(); |
|
454 |
} |
|
455 |
||
456 |
TKeyResponse CSwtSlider::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) |
|
457 |
{ |
|
458 |
TKeyResponse keyReponse = EKeyWasNotConsumed; |
|
459 |
||
460 |
if (aType == EEventKey) |
|
461 |
{ |
|
462 |
if ((aKeyEvent.iCode == iIncreaseKey) || (aKeyEvent.iCode == iDecreaseKey)) |
|
463 |
keyReponse = EKeyWasConsumed; |
|
464 |
||
465 |
} |
|
466 |
||
467 |
if (keyReponse == EKeyWasNotConsumed) |
|
468 |
return HandleKeyL(aKeyEvent, aType, ETrue); |
|
469 |
else |
|
470 |
return HandleKeyL(aKeyEvent, aType, EFalse); |
|
471 |
} |
|
472 |
||
473 |
void CSwtSlider::HandleResourceChange(TInt aType) |
|
474 |
{ |
|
475 |
TRAP_IGNORE(SwtHandleResourceChangeL(aType)); |
|
476 |
} |
|
477 |
||
478 |
void CSwtSlider::SwtHandleResourceChangeL(TInt aType) |
|
479 |
{ |
|
480 |
CAknControl::HandleResourceChange(aType); |
|
481 |
// Check all type which can modify the Slider |
|
482 |
// |
|
483 |
if (aType == KAknsMessageSkinChange || aType == KEikDynamicLayoutVariantSwitch) |
|
484 |
{ |
|
485 |
UpdateSliderImageL(); |
|
486 |
} |
|
487 |
} |
|
488 |
||
489 |
void CSwtSlider::Draw(const TRect& aRect) const |
|
490 |
{ |
|
491 |
if (iStyle & KSwtStyleVertical) |
|
492 |
{ |
|
493 |
if (!iImagesRotator->IsFinish()) |
|
494 |
{ |
|
495 |
iImagesRotator->SetRedrawAfterRotation(ETrue); |
|
496 |
return; |
|
497 |
} |
|
498 |
} |
|
499 |
||
500 |
ClipAndDrawImage(SystemGc(), aRect); |
|
501 |
} |
|
502 |
||
503 |
void CSwtSlider::FocusChanged(TDrawNow aDrawNow) |
|
504 |
{ |
|
505 |
CAknControl::FocusChanged(ENoDrawNow); |
|
506 |
// Spread focus information |
|
507 |
HandleFocusChanged(aDrawNow); |
|
508 |
} |
|
509 |
||
510 |
void CSwtSlider::SizeChanged() |
|
511 |
{ |
|
512 |
CAknControl::SizeChanged(); |
|
513 |
UpdateTouchFeedbackRect(); |
|
514 |
TRAP_IGNORE(UpdateSliderImageL()); |
|
515 |
HandleSizeChanged(); |
|
516 |
} |
|
517 |
||
518 |
void CSwtSlider::PositionChanged() |
|
519 |
{ |
|
520 |
UpdateTouchFeedbackRect(); |
|
521 |
HandlePositionChanged(); |
|
522 |
} |
|
523 |
||
524 |
TTypeUid::Ptr CSwtSlider::MopSupplyObject(TTypeUid aId) |
|
525 |
{ |
|
526 |
TTypeUid::Ptr id = ASwtControlBase::SwtMopSupplyObject(aId); |
|
527 |
||
528 |
if (id.Pointer() == NULL) |
|
529 |
{ |
|
530 |
return CAknControl::MopSupplyObject(aId); |
|
531 |
} |
|
532 |
else |
|
533 |
{ |
|
534 |
return id; |
|
535 |
} |
|
536 |
} |
|
537 |
||
538 |
#ifdef RD_SCALABLE_UI_V2 |
|
539 |
||
540 |
void CSwtSlider::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
541 |
{ |
|
542 |
if ((aPointerEvent.iType == TPointerEvent::EButton1Down || |
|
543 |
aPointerEvent.iType == TPointerEvent::EDrag)) |
|
544 |
{ |
|
545 |
TInt betweenSteps; |
|
546 |
TInt value = CalcAlignedValue(aPointerEvent.iPosition - ClientRect().iTl); |
|
547 |
||
548 |
// Calculate if we have ended at a valid slider step |
|
549 |
betweenSteps = value % iIncrement; |
|
550 |
||
551 |
if (betweenSteps != 0) |
|
552 |
{ |
|
553 |
value = value - betweenSteps; |
|
554 |
||
555 |
// if click was nearer or middle of values, then move it to |
|
556 |
// next possible value |
|
557 |
if (betweenSteps > (iIncrement / 2)) |
|
558 |
{ |
|
559 |
value = value + iIncrement; |
|
560 |
} |
|
561 |
} |
|
562 |
||
563 |
#ifdef RD_TACTILE_FEEDBACK |
|
564 |
if (iFeedback && aPointerEvent.iType == TPointerEvent::EDrag && |
|
565 |
value != iSelection) |
|
566 |
{ |
|
567 |
#ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
568 |
iFeedback->InstantFeedback(ETouchFeedbackSlider); |
|
569 |
#else |
|
570 |
// Give sensitive feedback when selection changes by dragging. |
|
571 |
iFeedback->InstantFeedback(ETouchFeedbackSensitive); |
|
572 |
#endif //RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
573 |
} |
|
574 |
||
575 |
#ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
576 |
if (iFeedback && aPointerEvent.iType == TPointerEvent::EButton1Down) |
|
577 |
{ |
|
578 |
iFeedback->InstantFeedback(ETouchFeedbackSlider); |
|
579 |
} |
|
580 |
#endif //RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
581 |
||
582 |
#endif //RD_TACTILE_FEEDBACK |
|
583 |
SetSelection(value); |
|
584 |
} |
|
585 |
||
586 |
#ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
587 |
if (iFeedback && aPointerEvent.iType == TPointerEvent::EButton1Up) |
|
588 |
{ |
|
589 |
iFeedback->InstantFeedback(ETouchFeedbackSlider); |
|
590 |
} |
|
591 |
#endif //RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
592 |
||
593 |
PostMouseEventL(aPointerEvent); |
|
594 |
} |
|
595 |
||
596 |
TInt CSwtSlider::CalcAlignedValue(const TPoint& aPoint) |
|
597 |
{ |
|
598 |
TInt bitmapRun = 0; |
|
599 |
TInt returnValue = iMinimum; |
|
600 |
TInt sliderOrigin = 0; |
|
601 |
||
602 |
// Take into account the marker on the slider and extra space on the each side |
|
603 |
// of the slider |
|
604 |
TInt markerSize = CSwtLafFacade::GetLayoutRect( |
|
605 |
CSwtLafFacade::ESliderSetPaneG2, TRect()).Rect().Size().iWidth; |
|
606 |
||
607 |
TAknLayoutRect layoutRect = |
|
608 |
CSwtLafFacade::GetLayoutRect(CSwtLafFacade::ESliderSetPaneCP3, TRect()); |
|
609 |
TSize lineSize = CSwtLafFacade::GetLayoutRect( |
|
610 |
CSwtLafFacade::ESliderSetPaneG1, layoutRect.Rect()).Rect().Size(); |
|
611 |
||
612 |
if (lineSize.iWidth < 0) |
|
613 |
{ |
|
614 |
lineSize.iWidth = -lineSize.iWidth; |
|
615 |
} |
|
616 |
||
617 |
markerSize += lineSize.iWidth; |
|
618 |
||
619 |
if (iStyle & KSwtStyleHorizontal) |
|
620 |
{ |
|
621 |
// Calculate the start coordinate of the actual slider inside the |
|
622 |
// control |
|
623 |
sliderOrigin = (ClientRect().Size().iWidth - iImageSize.iWidth) / 2; |
|
624 |
||
625 |
// Size of the active part of the slider |
|
626 |
bitmapRun = iImageSize.iWidth - markerSize; |
|
627 |
||
628 |
if (bitmapRun == 0) |
|
629 |
{ |
|
630 |
bitmapRun = 1; |
|
631 |
} |
|
632 |
||
633 |
// Calculate which slider selection is the closest to the pointer location |
|
634 |
returnValue = (((iMaximum-iMinimum) * (aPoint.iX - sliderOrigin - |
|
635 |
markerSize / 2)) / bitmapRun) + iMinimum; |
|
636 |
} |
|
637 |
else |
|
638 |
{ |
|
639 |
sliderOrigin = (ClientRect().Size().iHeight - iImageSize.iHeight) / 2; |
|
640 |
||
641 |
bitmapRun = iImageSize.iHeight - markerSize; |
|
642 |
||
643 |
if (bitmapRun == 0) |
|
644 |
{ |
|
645 |
bitmapRun = 1; |
|
646 |
} |
|
647 |
||
648 |
returnValue = (((iMaximum-iMinimum) * (aPoint.iY - sliderOrigin - |
|
649 |
markerSize / 2)) / bitmapRun) + iMinimum; |
|
650 |
||
651 |
returnValue = iMaximum - returnValue - 1; |
|
652 |
} |
|
653 |
||
654 |
return returnValue; |
|
655 |
} |
|
656 |
||
657 |
#endif // RD_SCALABLE_UI_V2 |
|
658 |
||
659 |
// |
|
660 |
// Virtual methods from MSwtControl |
|
661 |
// |
|
662 |
||
663 |
CCoeControl& CSwtSlider::CoeControl() |
|
664 |
{ |
|
665 |
return *this; |
|
666 |
} |
|
667 |
||
668 |
const CCoeControl& CSwtSlider::CoeControl() const |
|
669 |
{ |
|
670 |
return *this; |
|
671 |
} |
|
672 |
||
673 |
void CSwtSlider::ProcessKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) |
|
674 |
{ |
|
675 |
if (aType != EEventKey) |
|
676 |
{ |
|
677 |
return; |
|
678 |
} |
|
679 |
||
680 |
TInt increment = (aKeyEvent.iRepeats == 1)?iPageIncrement : iIncrement; |
|
681 |
||
682 |
const TInt code(aKeyEvent.iCode); |
|
683 |
||
684 |
if (code == iDecreaseKey) |
|
685 |
{ |
|
686 |
SetSelection(iSelection - increment); |
|
687 |
} |
|
688 |
else if (code == iIncreaseKey) |
|
689 |
{ |
|
690 |
SetSelection(iSelection + increment); |
|
691 |
} |
|
692 |
} |
|
693 |
||
694 |
||
695 |
TSize CSwtSlider::ComputeSizeL(TInt aWHint, TInt aHHint) |
|
696 |
{ |
|
697 |
if (aWHint != KSwtDefault && aHHint != KSwtDefault) |
|
698 |
{ |
|
699 |
return TSize(aWHint, aHHint); |
|
700 |
} |
|
701 |
||
702 |
TSize preferredSize(GetPreferredSliderSize()); |
|
703 |
if (iStyle & KSwtStyleVertical) |
|
704 |
{ |
|
705 |
TInt tmp(preferredSize.iHeight); |
|
706 |
preferredSize.iHeight = preferredSize.iWidth; |
|
707 |
preferredSize.iWidth = tmp; |
|
708 |
} |
|
709 |
TSize borderDelta(BorderSizeDelta()); |
|
710 |
||
711 |
TInt preferredHeight = preferredSize.iHeight + borderDelta.iHeight; |
|
712 |
TInt preferredWidth = preferredSize.iWidth + borderDelta.iWidth; |
|
713 |
||
714 |
preferredSize.iWidth = (aWHint == KSwtDefault) ? preferredWidth : aWHint; |
|
715 |
preferredSize.iHeight = (aHHint == KSwtDefault) ? preferredHeight : aHHint; |
|
716 |
||
717 |
// Leave space around the slider so that control focus highlight can be |
|
718 |
// seen even when slider graphics are not transparent. |
|
719 |
TRect innerRect(CoeControl().Rect()); |
|
720 |
TRect outerRect(innerRect); |
|
721 |
TAknLayoutRect topLeft = CSwtLafFacade::GetLayoutRect( |
|
722 |
CSwtLafFacade::EInputFieldSkinPlacingGeneralLine2, CoeControl().Rect(), 0); |
|
723 |
TRect rectTopLeft(topLeft.Rect()); |
|
724 |
innerRect.iTl = rectTopLeft.iBr; |
|
725 |
TAknLayoutRect layoutRect = CSwtLafFacade::GetLayoutRect( |
|
726 |
CSwtLafFacade::EInputFieldSkinPlacingGeneralLine5, CoeControl().Rect(), 0); |
|
727 |
TRect rectLayout(layoutRect.Rect()); |
|
728 |
innerRect.iBr = rectLayout.iTl; |
|
729 |
if (iStyle & KSwtStyleVertical) |
|
730 |
{ |
|
731 |
preferredSize.iWidth += ((innerRect.iTl.iX - outerRect.iTl.iX) * 2); |
|
732 |
} |
|
733 |
else |
|
734 |
{ |
|
735 |
preferredSize.iHeight += ((innerRect.iTl.iY - outerRect.iTl.iY) * 2); |
|
736 |
} |
|
737 |
||
738 |
if (aWHint != KSwtDefault) |
|
739 |
{ |
|
740 |
preferredSize.iWidth = aWHint; |
|
741 |
} |
|
742 |
if (aHHint != KSwtDefault) |
|
743 |
{ |
|
744 |
preferredSize.iHeight = aHHint; |
|
745 |
} |
|
746 |
||
747 |
return preferredSize; |
|
748 |
} |
|
749 |
||
750 |
// |
|
751 |
// Virtual methods from MSwtSlider |
|
752 |
// |
|
753 |
||
754 |
MSwtControl* CSwtSlider::Control() |
|
755 |
{ |
|
756 |
return this; |
|
757 |
} |
|
758 |
||
759 |
TInt CSwtSlider::GetMaximum() const |
|
760 |
{ |
|
761 |
return iMaximum; |
|
762 |
} |
|
763 |
||
764 |
TInt CSwtSlider::GetMinimum() const |
|
765 |
{ |
|
766 |
return iMinimum; |
|
767 |
} |
|
768 |
||
769 |
TInt CSwtSlider::GetPageIncrement() const |
|
770 |
{ |
|
771 |
return iPageIncrement; |
|
772 |
} |
|
773 |
||
774 |
TInt CSwtSlider::GetIncrement() const |
|
775 |
{ |
|
776 |
return iIncrement; |
|
777 |
} |
|
778 |
||
779 |
TInt CSwtSlider::GetSelection() const |
|
780 |
{ |
|
781 |
return iSelection; |
|
782 |
} |
|
783 |
||
784 |
void CSwtSlider::SetMaximum(TInt aValue) |
|
785 |
{ |
|
786 |
if (aValue != iMaximum && aValue > iMinimum) |
|
787 |
{ |
|
788 |
iMaximum = aValue; |
|
789 |
||
790 |
AdjustSelectionValue(); |
|
791 |
TRAP_IGNORE(UpdateSliderImageL()); |
|
792 |
} |
|
793 |
} |
|
794 |
||
795 |
void CSwtSlider::SetPageIncrement(TInt aValue) |
|
796 |
{ |
|
797 |
if (aValue > 0) |
|
798 |
{ |
|
799 |
iPageIncrement = aValue; |
|
800 |
} |
|
801 |
} |
|
802 |
||
803 |
void CSwtSlider::SetMinimum(TInt aValue) |
|
804 |
{ |
|
805 |
if (aValue != iMinimum && aValue >= 0 && aValue < iMaximum) |
|
806 |
{ |
|
807 |
iMinimum = aValue; |
|
808 |
||
809 |
AdjustSelectionValue(); |
|
810 |
TRAP_IGNORE(UpdateSliderImageL()); |
|
811 |
} |
|
812 |
} |
|
813 |
||
814 |
void CSwtSlider::SetIncrement(TInt aValue) |
|
815 |
{ |
|
816 |
iIncrement = (aValue < 1) ? 1 : aValue; |
|
817 |
} |
|
818 |
||
819 |
void CSwtSlider::SetSelection(TInt aValue) |
|
820 |
{ |
|
821 |
TInt previousSelection = iSelection; |
|
822 |
iSelection = aValue; |
|
823 |
||
824 |
AdjustSelectionValue(); |
|
825 |
||
826 |
if (iSelection != previousSelection) |
|
827 |
{ |
|
828 |
TRAP_IGNORE(UpdateSliderImageL()); |
|
829 |
TRAP_IGNORE(iDisplay.PostSelectionEventL(iPeer)); |
|
830 |
} |
|
831 |
} |
|
832 |
||
833 |
void CSwtSlider::SetValues(TInt aSelection, |
|
834 |
TInt aMinimum, |
|
835 |
TInt aMaximum, |
|
836 |
TInt aIncrement, |
|
837 |
TInt aPageIncrement) |
|
838 |
{ |
|
839 |
if (aMinimum >= 0 && aMinimum < aMaximum) |
|
840 |
{ |
|
841 |
iMinimum = aMinimum; |
|
842 |
iMaximum = aMaximum; |
|
843 |
} |
|
844 |
||
845 |
SetIncrement(aIncrement); |
|
846 |
SetPageIncrement(aPageIncrement); |
|
847 |
||
848 |
SetSelection(aSelection); |
|
849 |
} |
|
850 |
||
851 |
TBool CSwtSlider::SetSwtFocus(TInt aReason /*= KSwtFocusByApi*/) |
|
852 |
{ |
|
853 |
TBool prevFocused = IsFocusControl(); |
|
854 |
TBool res = ASwtControlBase::SetSwtFocus(aReason); |
|
855 |
||
856 |
// Gaines focus by pointer |
|
857 |
if (IsFocusControl() && !prevFocused) |
|
858 |
{ |
|
859 |
iFocusChanged = ETrue; |
|
860 |
} |
|
861 |
||
862 |
return res; |
|
863 |
} |