|
1 /* |
|
2 * Copyright (c) 2006 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: Draws recurrence/alarm icons |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 //debug |
|
21 #include "calendarui_debug.h" |
|
22 |
|
23 // User includes |
|
24 #include "calenicondrawer.h" |
|
25 |
|
26 #include <calenservices.h> |
|
27 |
|
28 // System includes |
|
29 #include <fbs.h> |
|
30 #include <eikapp.h> |
|
31 |
|
32 // Layout includes |
|
33 #include <aknlayoutscalable_apps.cdl.h> |
|
34 |
|
35 #include <AknsConstants.h> |
|
36 #include <AknsUtils.h> |
|
37 #include <gulicon.h> |
|
38 #include <avkon.mbg> |
|
39 #include <gdi.h> |
|
40 #include <fbs.h> |
|
41 |
|
42 #include <AknIconArray.h> |
|
43 |
|
44 // ============================ MEMBER FUNCTIONS =============================== |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CCalenIconDrawer::NewL |
|
48 // Two-phased constructor. |
|
49 // (other items were commented in a header). |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CCalenIconDrawer* CCalenIconDrawer::NewL( MCalenServices& aServices ) |
|
53 { |
|
54 TRACE_ENTRY_POINT; |
|
55 |
|
56 CCalenIconDrawer* self = new (ELeave) CCalenIconDrawer( aServices ); |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(); |
|
59 CleanupStack::Pop( self ); |
|
60 |
|
61 TRACE_EXIT_POINT; |
|
62 return self; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CCalenIconDrawer::ConstructL |
|
67 // Second phase construction. |
|
68 // (other items were commented in a header). |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 void CCalenIconDrawer::ConstructL() |
|
72 { |
|
73 TRACE_ENTRY_POINT; |
|
74 |
|
75 // Create icons used by the viewer |
|
76 iIconIndices.AppendL( MCalenServices::ECalenAlarmIcon ); |
|
77 iIconIndices.AppendL( MCalenServices::ECalenRepeatIcon ); |
|
78 iIconIndices.AppendL( MCalenServices::ECalenRepeatExceptionIcon ); |
|
79 iIconIndices.AppendL( MCalenServices::ECalenNotePriorityLow ); |
|
80 iIconIndices.AppendL( MCalenServices::ECalenNotePriorityHigh ); |
|
81 iIconIndices.AppendL( MCalenServices::ECalenMapIcon ); |
|
82 |
|
83 iIconArray = CreateIconsL( iIconIndices ); |
|
84 isMapIconAdded = EFalse; |
|
85 //SetIconSizesFromLayout(); |
|
86 |
|
87 TRACE_EXIT_POINT; |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // CCalenIconDrawer::SetIconSizesFromLayout |
|
92 // Calculate icon size from layout |
|
93 // (other items were commented in a header). |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 void CCalenIconDrawer::SetIconSizesFromLayout(TInt aNumOfLinesBefLocField) |
|
97 { |
|
98 TRACE_ENTRY_POINT; |
|
99 |
|
100 TSize main_pane_size; |
|
101 AknLayoutUtils::LayoutMetricsSize (AknLayoutUtils::EMainPane, main_pane_size); |
|
102 TRect main_pane(main_pane_size); |
|
103 |
|
104 TAknLayoutRect main_cale_event_viewer_pane; |
|
105 main_cale_event_viewer_pane.LayoutRect(main_pane, AknLayoutScalable_Apps::main_cale_event_viewer_pane().LayoutLine() ); |
|
106 |
|
107 TAknLayoutRect listscroll_cale_event_viewer_pane; |
|
108 listscroll_cale_event_viewer_pane.LayoutRect(main_cale_event_viewer_pane.Rect(), AknLayoutScalable_Apps::listscroll_cale_event_viewer_pane().LayoutLine() ); |
|
109 |
|
110 TAknLayoutRect list_cale_ev2_pane; |
|
111 list_cale_ev2_pane.LayoutRect(listscroll_cale_event_viewer_pane.Rect(), AknLayoutScalable_Apps::list_cale_ev2_pane().LayoutLine() ); |
|
112 |
|
113 TAknLayoutRect icon_layout_rect; |
|
114 icon_layout_rect.LayoutRect( list_cale_ev2_pane.Rect(), AknLayoutScalable_Apps::field_cale_ev2_pane_g1(1).LayoutLine() ); |
|
115 iFirstIconRect = icon_layout_rect.Rect(); |
|
116 |
|
117 icon_layout_rect.LayoutRect( list_cale_ev2_pane.Rect(), AknLayoutScalable_Apps::field_cale_ev2_pane_g2(1).LayoutLine() ); |
|
118 iSecondIconRect = icon_layout_rect.Rect(); |
|
119 |
|
120 icon_layout_rect.LayoutRect( list_cale_ev2_pane.Rect(), AknLayoutScalable_Apps::field_cale_ev2_pane_g3(2).LayoutLine() ); |
|
121 iThirdIconRect = icon_layout_rect.Rect(); |
|
122 |
|
123 // Adjust the map icon size |
|
124 if(isMapIconAdded) |
|
125 { |
|
126 TInt mapIconIndex = IconIndex(MCalenServices::ECalenMapIcon); |
|
127 TAknLayoutRect field_cale_ev2_pane; |
|
128 field_cale_ev2_pane.LayoutRect(list_cale_ev2_pane.Rect(), AknLayoutScalable_Apps::field_cale_ev2_pane(aNumOfLinesBefLocField, 0, 0).LayoutLine() ); |
|
129 |
|
130 icon_layout_rect.LayoutRect( field_cale_ev2_pane.Rect(), AknLayoutScalable_Apps::field_cale_ev2_pane_g4(0).LayoutLine() ); |
|
131 SetMapIconSize(icon_layout_rect.Rect()); |
|
132 } |
|
133 AknIconUtils::SetSize( iIconArray->At(iFirstIconIndex)->Bitmap(), iFirstIconRect.Size() ); |
|
134 AknIconUtils::SetSize( iIconArray->At(iSecondIconIndex)->Bitmap(), iSecondIconRect.Size() ); |
|
135 AknIconUtils::SetSize( iIconArray->At(iThirdIconIndex)->Bitmap(), iThirdIconRect.Size() ); |
|
136 |
|
137 TRACE_EXIT_POINT; |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // CCalenIconDrawer::SetMapIconSize |
|
142 // Fuction to set map icon size |
|
143 // (other items were commented in a header). |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 void CCalenIconDrawer::SetMapIconSize(TRect aIconRect) |
|
147 { |
|
148 TRACE_ENTRY_POINT; |
|
149 |
|
150 if(iIconIndices[iFirstIconIndex] == MCalenServices::ECalenMapIcon) |
|
151 { |
|
152 iFirstIconRect = aIconRect; |
|
153 iFirstIconRect.iBr.iX = iFirstIconRect.iTl.iX + 30; |
|
154 iFirstIconRect.iBr.iY = iFirstIconRect.iTl.iY + 30; |
|
155 } |
|
156 else if(iIconIndices[iSecondIconIndex] == MCalenServices::ECalenMapIcon) |
|
157 { |
|
158 iSecondIconRect = aIconRect; |
|
159 iSecondIconRect.iBr.iX = iSecondIconRect.iTl.iX + 30; |
|
160 iSecondIconRect.iBr.iY = iSecondIconRect.iTl.iY + 30; |
|
161 } |
|
162 else if(iIconIndices[iThirdIconIndex] == MCalenServices::ECalenMapIcon) |
|
163 { |
|
164 iThirdIconRect = aIconRect; |
|
165 iThirdIconRect.iBr.iX = iThirdIconRect.iTl.iX + 30; |
|
166 iThirdIconRect.iBr.iY = iThirdIconRect.iTl.iY + 30; |
|
167 } |
|
168 |
|
169 TRACE_EXIT_POINT; |
|
170 } |
|
171 // --------------------------------------------------------------------------- |
|
172 // CCalenIconDrawer::CCalenIconDrawer |
|
173 // C++ constructor can NOT contain any code, that might leave. |
|
174 // (other items were commented in a header). |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 CCalenIconDrawer::CCalenIconDrawer( MCalenServices& aServices ) |
|
178 : iServices( aServices ) |
|
179 { |
|
180 TRACE_ENTRY_POINT; |
|
181 TRACE_EXIT_POINT; |
|
182 } |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // CCalenIconDrawer::~CCalenIconDrawer |
|
186 // Destructor. |
|
187 // (other items were commented in a header). |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 CCalenIconDrawer::~CCalenIconDrawer() |
|
191 { |
|
192 TRACE_ENTRY_POINT; |
|
193 |
|
194 delete iIconArray; |
|
195 iIconIndices.Close(); |
|
196 |
|
197 TRACE_EXIT_POINT; |
|
198 } |
|
199 |
|
200 // ----------------------------------------------------------------------------- |
|
201 // CCalenIconDrawer::Draw |
|
202 // Draw icon function |
|
203 // (other items were commented in a header). |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 void CCalenIconDrawer::Draw(CGraphicsContext& aGc, const TPoint& /*aTopLeft*/, |
|
207 const TRect& /*aClipRect*/, MGraphicsDeviceMap* /*aMap*/) const |
|
208 { |
|
209 TRACE_ENTRY_POINT; |
|
210 |
|
211 aGc.Reset(); |
|
212 switch (iIconCount) |
|
213 { |
|
214 case EThreeIcons: |
|
215 aGc.DrawBitmapMasked(iThirdIconRect, iIconArray->At(iThirdIconIndex)->Bitmap(), iThirdIconRect.Size(), iIconArray->At(iThirdIconIndex)->Mask(), ETrue); |
|
216 //lint -fallthrough |
|
217 case ETwoIcons: /* fall through... */ |
|
218 aGc.DrawBitmapMasked(iSecondIconRect, iIconArray->At(iSecondIconIndex)->Bitmap(), iSecondIconRect.Size(), iIconArray->At(iSecondIconIndex)->Mask(), ETrue); |
|
219 //lint -fallthrough |
|
220 case EOneIcon: /* fall through... */ |
|
221 aGc.DrawBitmapMasked(iFirstIconRect, iIconArray->At(iFirstIconIndex)->Bitmap(), iFirstIconRect.Size(), iIconArray->At(iFirstIconIndex)->Mask(), ETrue); |
|
222 //lint -fallthrough |
|
223 case ENoIcons: /* fall through... */ |
|
224 default: |
|
225 break; |
|
226 } |
|
227 |
|
228 TRACE_EXIT_POINT; |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // CCalenIconDrawer::ExternalizeL |
|
233 // Pure virtual from CPicture, intentionally empty. |
|
234 // (other items were commented in a header). |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 void CCalenIconDrawer::ExternalizeL(RWriteStream& /*aStream*/) const |
|
238 { |
|
239 TRACE_ENTRY_POINT; |
|
240 TRACE_EXIT_POINT; |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CCalenIconDrawer::GetOriginalSizeInTwips |
|
245 // Convert size to twips |
|
246 // (other items were commented in a header). |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 void CCalenIconDrawer::GetOriginalSizeInTwips( TSize& /*aSize*/ ) const |
|
250 { |
|
251 TRACE_ENTRY_POINT; |
|
252 TRACE_EXIT_POINT; |
|
253 } |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CCalenIconDrawer::HandleResourceChange |
|
257 // Handle resource change. e.g. screen resolution change |
|
258 // (other items were commented in a header). |
|
259 // ----------------------------------------------------------------------------- |
|
260 // |
|
261 void CCalenIconDrawer::HandleResourceChange() |
|
262 { |
|
263 TRACE_ENTRY_POINT; |
|
264 |
|
265 SetIconSizesFromLayout(); |
|
266 |
|
267 TRACE_EXIT_POINT; |
|
268 } |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CCalenIconDrawer::AddIconL |
|
272 // Store icon index for reserved icon position |
|
273 // (other items were commented in a header). |
|
274 // ----------------------------------------------------------------------------- |
|
275 // |
|
276 void CCalenIconDrawer::AddIconL( MCalenServices::TCalenIcons aIconIndex) |
|
277 { |
|
278 TRACE_ENTRY_POINT; |
|
279 if(aIconIndex == MCalenServices::ECalenMapIcon) |
|
280 { |
|
281 isMapIconAdded = ETrue; |
|
282 } |
|
283 switch (iIconCount) |
|
284 { |
|
285 case ENoIcons: |
|
286 iFirstIconIndex = IconIndex( aIconIndex ); |
|
287 User::LeaveIfError( iFirstIconIndex == KErrNotFound ); |
|
288 iIconCount = EOneIcon; |
|
289 break; |
|
290 |
|
291 case EOneIcon: |
|
292 iSecondIconIndex = IconIndex( aIconIndex ); |
|
293 User::LeaveIfError( iSecondIconIndex == KErrNotFound ); |
|
294 iIconCount = ETwoIcons; |
|
295 break; |
|
296 |
|
297 case ETwoIcons: |
|
298 iThirdIconIndex = IconIndex( aIconIndex ); |
|
299 User::LeaveIfError( iThirdIconIndex == KErrNotFound ); |
|
300 iIconCount = EThreeIcons; |
|
301 break; |
|
302 |
|
303 case EThreeIcons: |
|
304 /* fall through... */ |
|
305 User::Leave(KErrNotSupported); |
|
306 break; |
|
307 } |
|
308 |
|
309 TRACE_EXIT_POINT; |
|
310 } |
|
311 |
|
312 // --------------------------------------------------------- |
|
313 // CCalenIconDrawer::WidthInPixels |
|
314 // Count width of all icons in pixel |
|
315 // (other items were commented in a header). |
|
316 // --------------------------------------------------------- |
|
317 // |
|
318 TInt CCalenIconDrawer::WidthInPixels() |
|
319 { |
|
320 TRACE_ENTRY_POINT; |
|
321 |
|
322 TInt widthInPixels = 0; |
|
323 if (iIconCount) |
|
324 { |
|
325 // All icons are the same size |
|
326 widthInPixels = iIconCount * iFirstIconRect.Size().iWidth; |
|
327 } |
|
328 |
|
329 TRACE_EXIT_POINT; |
|
330 return widthInPixels; |
|
331 } |
|
332 |
|
333 // ---------------------------------------------------------------------------- |
|
334 // CCalenIconDrawer::CreateIconsL |
|
335 // Create array of icons according to icon indices array given |
|
336 // (other items were commented in a header). |
|
337 // ---------------------------------------------------------------------------- |
|
338 // |
|
339 CAknIconArray* CCalenIconDrawer::CreateIconsL( const RArray<MCalenServices::TCalenIcons>& aIndexArray ) |
|
340 { |
|
341 TRACE_ENTRY_POINT; |
|
342 |
|
343 const TInt iconCount( aIndexArray.Count() ); |
|
344 CAknIconArray* icons = new(ELeave) CAknIconArray( iconCount ); |
|
345 CleanupStack::PushL( icons ); |
|
346 icons->SetReserveL( iconCount ); |
|
347 |
|
348 for( TInt i=0; i<iconCount; ++i ) |
|
349 { |
|
350 icons->AppendL( iServices.GetIconL( static_cast<MCalenServices::TCalenIcons>(aIndexArray[i] ) )); |
|
351 } |
|
352 CleanupStack::Pop( icons ); |
|
353 |
|
354 TRACE_EXIT_POINT; |
|
355 return icons; |
|
356 } |
|
357 |
|
358 // ---------------------------------------------------------------------------- |
|
359 // CCalenContainer::IconIndex |
|
360 // Get icon index of the icon array |
|
361 // (other items were commented in a header). |
|
362 // ---------------------------------------------------------------------------- |
|
363 // |
|
364 TInt CCalenIconDrawer::IconIndex( MCalenServices::TCalenIcons aType ) const |
|
365 { |
|
366 TRACE_ENTRY_POINT; |
|
367 |
|
368 TInt index( iIconIndices.Find( aType ) ); |
|
369 // User::LeaveIfError( index == KErrNotFound ); |
|
370 |
|
371 TRACE_EXIT_POINT; |
|
372 return index; |
|
373 } |
|
374 |
|
375 // End of File |