|
1 /* |
|
2 ============================================================================ |
|
3 Name : CImageLabel.cpp |
|
4 Author : |
|
5 Version : 1.0 |
|
6 Copyright : Your copyright notice |
|
7 Description : CCImageLabel implementation |
|
8 ============================================================================ |
|
9 */ |
|
10 #include "TimeAO.h" |
|
11 #include "CImageLabel.h" |
|
12 #include <W32STD.H> |
|
13 #include <akniconutils.h> |
|
14 #include <EIKENV.H> //For iEikonEnv |
|
15 #include <GDI.H> |
|
16 // --------------------------------------------------------------------------- |
|
17 // CImageLabel() |
|
18 // --------------------------------------------------------------------------- |
|
19 // |
|
20 CImageLabel::CImageLabel() |
|
21 { |
|
22 // No implementation required |
|
23 } |
|
24 // --------------------------------------------------------------------------- |
|
25 // ~CImageLabel() |
|
26 // --------------------------------------------------------------------------- |
|
27 // |
|
28 CImageLabel::~CImageLabel() |
|
29 { |
|
30 if (iBitmap != NULL) |
|
31 { |
|
32 delete iBitmap; |
|
33 iBitmap = NULL; |
|
34 } |
|
35 if (iBitmapMask != NULL) |
|
36 { |
|
37 delete iBitmapMask; |
|
38 iBitmap = NULL; |
|
39 } |
|
40 if (iTimeAO != NULL) |
|
41 { |
|
42 delete iTimeAO; |
|
43 iTimeAO = NULL; |
|
44 } |
|
45 } |
|
46 // --------------------------------------------------------------------------- |
|
47 // NewLC() |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 CImageLabel* CImageLabel::NewLC(CCoeControl *aParent, const TRect& aRect, |
|
51 TOOLTIP_LAYOUT aLabelLayout) |
|
52 { |
|
53 CImageLabel* self = new (ELeave) CImageLabel(); |
|
54 CleanupStack::PushL(self); |
|
55 self->ConstructL(aParent, aRect, aLabelLayout); |
|
56 return self; |
|
57 } |
|
58 // --------------------------------------------------------------------------- |
|
59 // NewL() |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 CImageLabel* CImageLabel::NewL(CCoeControl *aParent, const TRect& aRect, |
|
63 TOOLTIP_LAYOUT aLabelLayout) |
|
64 { |
|
65 CImageLabel* self = CImageLabel::NewLC(aParent, aRect, aLabelLayout); |
|
66 CleanupStack::Pop(); // self; |
|
67 return self; |
|
68 } |
|
69 // --------------------------------------------------------------------------- |
|
70 // ConstructL() |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 void CImageLabel::ConstructL(CCoeControl *aParent, const TRect& aRect, |
|
74 TOOLTIP_LAYOUT aLabelLayout) |
|
75 { |
|
76 SetContainerWindowL(*aParent); |
|
77 SetRect(aRect); |
|
78 |
|
79 iState = ENone; |
|
80 iLabelLayout = aLabelLayout; |
|
81 iBitmap = NULL; |
|
82 iBitmapMask = NULL; |
|
83 |
|
84 iTooltipStartPoint = TPoint(0, 0); |
|
85 CalculateImagePoint(); |
|
86 CalculateBoundingRectStartPoint(); |
|
87 CalculateZones(); |
|
88 |
|
89 iTimeAO = CTimeAO::NewL(); |
|
90 iTimeAO->SetObserver(this); |
|
91 |
|
92 iIsHandlePointerNotifyProcessing = EFalse; |
|
93 } |
|
94 // --------------------------------------------------------------------------- |
|
95 // HandlePointerEventL() |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void CImageLabel::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
99 { |
|
100 switch (aPointerEvent.iType) |
|
101 { |
|
102 case TPointerEvent::EButton1Down: |
|
103 { |
|
104 if(iIsHandlePointerNotifyProcessing) |
|
105 { |
|
106 //Ignore button down event when HandlePointerNotify is processing. |
|
107 break; |
|
108 } |
|
109 iState = ESelected; |
|
110 DrawNow(); |
|
111 iTimeAO->StartL(); |
|
112 |
|
113 break; |
|
114 } |
|
115 case TPointerEvent::EButton1Up: |
|
116 { |
|
117 iTimeAO->Cancel(); |
|
118 //If the statte is moveing or selected.change the state to ENone |
|
119 |
|
120 if (iState == EMoving || iState == ESelectedWithTooltip) |
|
121 { |
|
122 iState = ENone; |
|
123 DrawNow(); |
|
124 } |
|
125 else |
|
126 { |
|
127 iState = ENone; |
|
128 DrawNow(); |
|
129 //If not on process start it |
|
130 if(!iIsHandlePointerNotifyProcessing) |
|
131 { |
|
132 iIsHandlePointerNotifyProcessing = ETrue; |
|
133 //To avoid pop up dialog two times by quick double chick |
|
134 iHandlePointerObserver->HandlePointerNotify(this); |
|
135 iIsHandlePointerNotifyProcessing = EFalse; |
|
136 } |
|
137 } |
|
138 break; |
|
139 } |
|
140 default: |
|
141 break; |
|
142 } |
|
143 } |
|
144 // --------------------------------------------------------------------------- |
|
145 // SizeChanged() |
|
146 // --------------------------------------------------------------------------- |
|
147 // |
|
148 void CImageLabel::SizeChanged() |
|
149 { |
|
150 DrawNow(); |
|
151 } |
|
152 // --------------------------------------------------------------------------- |
|
153 // Draw() |
|
154 // --------------------------------------------------------------------------- |
|
155 // |
|
156 void CImageLabel::Draw(const TRect& aRect) const |
|
157 { |
|
158 // Get the standard graphics context |
|
159 CWindowGc& gc = SystemGc(); |
|
160 |
|
161 TRgb Rgb(KRgbGray); |
|
162 Rgb.SetAlpha(180); |
|
163 gc.SetBrushColor(Rgb); |
|
164 gc.SetBrushStyle(CWindowGc::ESolidBrush); |
|
165 gc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
166 gc.SetPenColor(KRgbDarkGray); |
|
167 gc.SetPenSize(TSize(2,2)); |
|
168 |
|
169 switch (iState) |
|
170 { |
|
171 case ENone: |
|
172 { |
|
173 //do nothing |
|
174 } |
|
175 break; |
|
176 case EMoving: |
|
177 { |
|
178 //Draw the bounding rect |
|
179 TSize cornorSize(8, 8); |
|
180 gc.DrawRoundRect(TRect(iBoundingRectStartPoint, iBoundingSize), |
|
181 cornorSize); |
|
182 break; |
|
183 } |
|
184 case ESelected: |
|
185 { |
|
186 //Draw the bouding rect |
|
187 TSize cornorSize(8, 8); |
|
188 gc.DrawRoundRect(TRect(iBoundingRectStartPoint, iBoundingSize), |
|
189 cornorSize); |
|
190 break; |
|
191 } |
|
192 case ESelectedWithTooltip: |
|
193 { |
|
194 //Draw the bounding rect |
|
195 TSize cornorSize(8, 8); |
|
196 gc.DrawRoundRect(TRect(iBoundingRectStartPoint, iBoundingSize), |
|
197 cornorSize); |
|
198 |
|
199 CFont* pFont = NULL; |
|
200 TFontSpec fontSpec = iEikonEnv->TitleFont()->FontSpecInTwips(); |
|
201 fontSpec.iHeight *= 0.535; |
|
202 iCoeEnv->ScreenDevice()->GetNearestFontInTwips(pFont, fontSpec); |
|
203 |
|
204 //Draw the tooltips |
|
205 gc.UseFont(pFont); |
|
206 gc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
207 gc.SetPenColor(KRgbGreen); |
|
208 gc.DrawText(iTooltip, iTooltipStartPoint); |
|
209 iCoeEnv->ScreenDevice()->ReleaseFont(pFont); |
|
210 gc.DiscardFont(); |
|
211 break; |
|
212 } |
|
213 default: |
|
214 break; |
|
215 } |
|
216 |
|
217 //Draw svg picture |
|
218 if (iBitmap != NULL) |
|
219 { |
|
220 gc.BitBltMasked(iImageStartPoint, iBitmap, TRect(TPoint(0, 0), TSize( |
|
221 iBoundingSize)), iBitmapMask, ETrue); |
|
222 } |
|
223 |
|
224 } |
|
225 // --------------------------------------------------------------------------- |
|
226 // Notify() |
|
227 // --------------------------------------------------------------------------- |
|
228 // |
|
229 void CImageLabel::Notify() |
|
230 { |
|
231 //if the state is not moving set selected with tooltips |
|
232 if (iState != EMoving) |
|
233 iState = ESelectedWithTooltip; |
|
234 DrawNow(); |
|
235 } |
|
236 // --------------------------------------------------------------------------- |
|
237 // SetImage() |
|
238 // --------------------------------------------------------------------------- |
|
239 // |
|
240 void CImageLabel::SetImage(const TDesC& aMbmPackage, TInt aIndex) |
|
241 { |
|
242 //Load pictures |
|
243 AknIconUtils::CreateIconL(iBitmap, iBitmapMask, aMbmPackage, aIndex, aIndex |
|
244 + 1); |
|
245 AknIconUtils::SetSize(iBitmap, iImageSize); |
|
246 AknIconUtils::SetSize(iBitmapMask, iImageSize); |
|
247 |
|
248 ActivateL(); |
|
249 } |
|
250 // --------------------------------------------------------------------------- |
|
251 // SetTooltip() |
|
252 // --------------------------------------------------------------------------- |
|
253 // |
|
254 void CImageLabel::SetTooltip(const TDesC& aTooltip) |
|
255 { |
|
256 iTooltip.Copy(aTooltip); |
|
257 CalculateTooltipPoint(); |
|
258 } |
|
259 // --------------------------------------------------------------------------- |
|
260 // ResetControl() |
|
261 // --------------------------------------------------------------------------- |
|
262 // |
|
263 void CImageLabel::ResetControl() |
|
264 { |
|
265 CalculateImagePoint(); |
|
266 CalculateBoundingRectStartPoint(); |
|
267 CalculateTooltipPoint(); |
|
268 CalculateZones(); |
|
269 } |
|
270 // --------------------------------------------------------------------------- |
|
271 // CalculateImagePoint() |
|
272 // --------------------------------------------------------------------------- |
|
273 // |
|
274 void CImageLabel::CalculateImagePoint() |
|
275 { |
|
276 // landscape |
|
277 if (iLabelLayout == ELabelHorizontal) |
|
278 { |
|
279 iImageStartPoint.iX = Rect().iTl.iX + 2; |
|
280 iImageStartPoint.iY = Rect().iBr.iY - (Rect().iBr.iX - Rect().iTl.iX) |
|
281 + 2; |
|
282 } |
|
283 //portrait |
|
284 else if (iLabelLayout == ELabelVertical) |
|
285 { |
|
286 iImageStartPoint.iX = Rect().iBr.iX - (Rect().iBr.iY - Rect().iTl.iY) |
|
287 + 2; |
|
288 iImageStartPoint.iY = Rect().iTl.iY + 2; |
|
289 } |
|
290 } |
|
291 // --------------------------------------------------------------------------- |
|
292 // CalculateBoundingRectStartPoint() |
|
293 // calcuate related start point |
|
294 // --------------------------------------------------------------------------- |
|
295 // |
|
296 void CImageLabel::CalculateBoundingRectStartPoint() |
|
297 { |
|
298 // landscape |
|
299 if (iLabelLayout == ELabelHorizontal) |
|
300 { |
|
301 iBoundingRectStartPoint.iX = Rect().iTl.iX + 1; |
|
302 iBoundingRectStartPoint.iY = Rect().iBr.iY - (Rect().iBr.iX |
|
303 - Rect().iTl.iX) + 1; |
|
304 } |
|
305 //portrait |
|
306 else if (iLabelLayout == ELabelVertical) |
|
307 { |
|
308 iBoundingRectStartPoint.iX = Rect().iBr.iX - (Rect().iBr.iY |
|
309 - Rect().iTl.iY) + 1; |
|
310 iBoundingRectStartPoint.iY = Rect().iTl.iY + 1; |
|
311 } |
|
312 |
|
313 } |
|
314 // --------------------------------------------------------------------------- |
|
315 // CalculateTooltipPoint() |
|
316 // Where show the tooltips. |
|
317 // --------------------------------------------------------------------------- |
|
318 // |
|
319 void CImageLabel::CalculateTooltipPoint() |
|
320 { |
|
321 // landscape |
|
322 if (iLabelLayout == ELabelHorizontal) |
|
323 { |
|
324 CFont* pFont = NULL; |
|
325 TFontSpec fontSpec = iEikonEnv->TitleFont()->FontSpecInTwips(); |
|
326 fontSpec.iHeight *= 0.535; |
|
327 iCoeEnv->ScreenDevice()->GetNearestFontInTwips(pFont, fontSpec); |
|
328 int tooltipLength = pFont->TextWidthInPixels(iTooltip); |
|
329 iCoeEnv->ScreenDevice()->ReleaseFont(pFont); |
|
330 |
|
331 iTooltipStartPoint.iX = Rect().iTl.iX |
|
332 + (Rect().Width() - tooltipLength) / 2; |
|
333 iTooltipStartPoint.iY = Rect().iBr.iY - (Rect().iBr.iX - Rect().iTl.iX); |
|
334 } |
|
335 //portrait |
|
336 else if (iLabelLayout == ELabelVertical) |
|
337 { |
|
338 CFont* pFont = NULL; |
|
339 TFontSpec fontSpec = iEikonEnv->TitleFont()->FontSpecInTwips(); |
|
340 fontSpec.iHeight *= 0.535; |
|
341 iCoeEnv->ScreenDevice()->GetNearestFontInTwips(pFont, fontSpec); |
|
342 int tooltipLength = pFont->TextWidthInPixels(iTooltip); |
|
343 int tooltipHeight = pFont->HeightInPixels(); |
|
344 iCoeEnv->ScreenDevice()->ReleaseFont(pFont); |
|
345 |
|
346 iTooltipStartPoint.iX = Rect().iTl.iX + (iBoundingRectStartPoint.iX |
|
347 - Rect().iTl.iX - tooltipLength) / 2; |
|
348 iTooltipStartPoint.iY = Rect().iBr.iY - (Rect().Height() |
|
349 - tooltipHeight) / 2; |
|
350 } |
|
351 } |
|
352 // --------------------------------------------------------------------------- |
|
353 // CalculateZones() |
|
354 // --------------------------------------------------------------------------- |
|
355 // |
|
356 |
|
357 void CImageLabel::CalculateZones() |
|
358 { |
|
359 // landscape |
|
360 if (iLabelLayout == ELabelHorizontal) |
|
361 { |
|
362 iBoundingSize.iHeight = Rect().iBr.iX - Rect().iTl.iX - 2; |
|
363 iBoundingSize.iWidth = iBoundingSize.iHeight - 2; |
|
364 |
|
365 iImageSize.iHeight = iBoundingSize.iHeight - 4; |
|
366 iImageSize.iWidth = iBoundingSize.iWidth - 4; |
|
367 } |
|
368 //portrait |
|
369 else if (iLabelLayout == ELabelVertical) |
|
370 { |
|
371 iBoundingSize.iHeight = Rect().iBr.iY - Rect().iTl.iY - 2; |
|
372 iBoundingSize.iWidth = iBoundingSize.iHeight - 2; |
|
373 |
|
374 iImageSize.iHeight = iBoundingSize.iHeight - 4; |
|
375 iImageSize.iWidth = iBoundingSize.iWidth - 4; |
|
376 } |
|
377 } |
|
378 // --------------------------------------------------------------------------- |
|
379 // LabelIsMoving() |
|
380 // --------------------------------------------------------------------------- |
|
381 // |
|
382 |
|
383 void CImageLabel::LabelIsMoving() |
|
384 { |
|
385 iState = EMoving; |
|
386 } |
|
387 // --------------------------------------------------------------------------- |
|
388 // SetHandlePointerObserver() |
|
389 // --------------------------------------------------------------------------- |
|
390 // |
|
391 void CImageLabel::SetHandlePointerObserver( |
|
392 MHandlePointerObserver* aHandlePointerObserver) |
|
393 { |
|
394 iHandlePointerObserver = aHandlePointerObserver; |
|
395 } |