|
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 FILES |
|
20 #include "loadgen_maincontainer.h" |
|
21 #include "loadgen.hrh" |
|
22 #include "loadgen_document.h" |
|
23 #include "loadgen_appui.h" |
|
24 #include "loadgen_model.h" |
|
25 #include <loadgen_extraicons.mbg> |
|
26 |
|
27 #include <aknlists.h> |
|
28 #include <eikclb.h> |
|
29 #include <eikclbd.h> |
|
30 #include <aknconsts.h> |
|
31 #include <AknUtils.h> |
|
32 #include <aknnotewrappers.h> |
|
33 #include <AknIconArray.h> |
|
34 #include <f32file.h> |
|
35 #include <AknIconUtils.h> |
|
36 #include <AknDef.h> |
|
37 #include <akntitle.h> |
|
38 #include <eikspane.h> |
|
39 |
|
40 _LIT(KExtraIconsPath, "\\resource\\apps\\loadgen_extraicons.mif"); |
|
41 |
|
42 // ===================================== MEMBER FUNCTIONS ===================================== |
|
43 |
|
44 void CLoadGenMainContainer::ConstructL(const TRect& aRect) |
|
45 { |
|
46 iModel = static_cast<CLoadGenDocument*>(reinterpret_cast<CEikAppUi*>(iEikonEnv->AppUi())->Document())->Model(); |
|
47 iModel->SetMainContainer(this); |
|
48 |
|
49 CreateWindowL(); |
|
50 SetRect(aRect); |
|
51 SetBlank(); |
|
52 |
|
53 // init listbox |
|
54 iListBox = new(ELeave) CLoadGenCAknSingleGraphicStyleListBox; |
|
55 iListBox->SetContainerWindowL(*this); |
|
56 iListBox->ConstructL(this, EAknListBoxMarkableList); |
|
57 iListBox->View()->SetListEmptyTextL(_L("No loads activated\n(Select new load from Options to generate new load)")); |
|
58 |
|
59 // create icon array and add marking indicator to it |
|
60 CAknIconArray* iconArray = new(ELeave) CAknIconArray(1); |
|
61 CleanupStack::PushL(iconArray); |
|
62 CFbsBitmap* markBitmap = NULL; |
|
63 CFbsBitmap* markBitmapMask = NULL; |
|
64 |
|
65 TRgb defaultColor; |
|
66 defaultColor = iEikonEnv->Color(EColorControlText); |
|
67 |
|
68 AknsUtils::CreateColorIconL(AknsUtils::SkinInstance(), |
|
69 KAknsIIDQgnIndiMarkedAdd, |
|
70 KAknsIIDQsnIconColors, |
|
71 EAknsCIQsnIconColorsCG13, |
|
72 markBitmap, |
|
73 markBitmapMask, |
|
74 AknIconUtils::AvkonIconFileName(), |
|
75 EMbmAvkonQgn_indi_marked_add, |
|
76 EMbmAvkonQgn_indi_marked_add_mask, |
|
77 defaultColor |
|
78 ); |
|
79 |
|
80 CGulIcon* markIcon = CGulIcon::NewL(markBitmap, markBitmapMask); |
|
81 iconArray->AppendL(markIcon); |
|
82 |
|
83 // append icons from loadgen_extraicons.mif |
|
84 TFileName extraIconsPath; |
|
85 extraIconsPath.Copy(KExtraIconsPath); |
|
86 TParsePtrC parse((CEikonEnv::Static()->EikAppUi()->Application())->AppFullName()); // get path where this app is installed |
|
87 extraIconsPath.Insert(0, parse.Drive()); // drive letter |
|
88 |
|
89 CFbsBitmap* redBitmap = NULL; |
|
90 CFbsBitmap* redBitmapMask = NULL; |
|
91 CFbsBitmap* greenBitmap = NULL; |
|
92 CFbsBitmap* greenBitmapMask = NULL; |
|
93 |
|
94 AknIconUtils::CreateIconL(redBitmap, redBitmapMask, extraIconsPath, EMbmLoadgen_extraiconsQgn_prob_status_red, EMbmLoadgen_extraiconsQgn_prob_status_red_mask); |
|
95 AknIconUtils::CreateIconL(greenBitmap, greenBitmapMask, extraIconsPath, EMbmLoadgen_extraiconsQgn_prob_status_green, EMbmLoadgen_extraiconsQgn_prob_status_green_mask); |
|
96 |
|
97 CGulIcon* redIcon = CGulIcon::NewL(redBitmap, redBitmapMask); |
|
98 iconArray->AppendL(redIcon); |
|
99 |
|
100 CGulIcon* greenIcon = CGulIcon::NewL(greenBitmap, greenBitmapMask); |
|
101 iconArray->AppendL(greenIcon); |
|
102 |
|
103 // set icon array |
|
104 CleanupStack::Pop(); // iconArray |
|
105 iListBox->ItemDrawer()->ColumnData()->SetIconArray(iconArray); |
|
106 |
|
107 iListBox->CreateScrollBarFrameL(ETrue); |
|
108 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
109 iListBox->SetListBoxObserver(this); |
|
110 |
|
111 // set size of the listbox |
|
112 TSize outputRectSize; |
|
113 AknLayoutUtils::LayoutMetricsSize(AknLayoutUtils::EMainPane, outputRectSize); |
|
114 TRect outputRect(outputRectSize); |
|
115 iListBox->SetRect(outputRect); |
|
116 |
|
117 iListBox->ActivateL(); |
|
118 |
|
119 ActivateL(); |
|
120 } |
|
121 |
|
122 // -------------------------------------------------------------------------------------------- |
|
123 |
|
124 CLoadGenMainContainer::~CLoadGenMainContainer() |
|
125 { |
|
126 if (iListBox) |
|
127 delete iListBox; |
|
128 } |
|
129 |
|
130 // -------------------------------------------------------------------------------------------- |
|
131 |
|
132 void CLoadGenMainContainer::SizeChanged() |
|
133 { |
|
134 TSize outputRectSize; |
|
135 AknLayoutUtils::LayoutMetricsSize(AknLayoutUtils::EMainPane, outputRectSize); |
|
136 TRect outputRect(outputRectSize); |
|
137 |
|
138 if (iListBox) |
|
139 iListBox->SetRect(outputRect); |
|
140 } |
|
141 |
|
142 // -------------------------------------------------------------------------------------------- |
|
143 |
|
144 TInt CLoadGenMainContainer::CountComponentControls() const |
|
145 { |
|
146 if (iListBox) |
|
147 return 1; |
|
148 else |
|
149 return 0; |
|
150 } |
|
151 |
|
152 // -------------------------------------------------------------------------------------------- |
|
153 |
|
154 CCoeControl* CLoadGenMainContainer::ComponentControl(TInt /*aIndex*/) const |
|
155 { |
|
156 if (iListBox) |
|
157 return iListBox; |
|
158 else |
|
159 return NULL; |
|
160 } |
|
161 |
|
162 // -------------------------------------------------------------------------------------------- |
|
163 |
|
164 TInt CLoadGenMainContainer::CurrentListBoxItemIndex() |
|
165 { |
|
166 if (iListBox) |
|
167 { |
|
168 return iListBox->CurrentItemIndex(); |
|
169 } |
|
170 else |
|
171 return KErrNotFound; |
|
172 } |
|
173 |
|
174 // -------------------------------------------------------------------------------------------- |
|
175 |
|
176 void CLoadGenMainContainer::SetListBoxTextArrayL(CDesCArray* aTextArray) |
|
177 { |
|
178 if (iListBox) |
|
179 { |
|
180 iListBox->Model()->SetItemTextArray(aTextArray); |
|
181 iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray); |
|
182 iListBox->HandleItemAdditionL(); |
|
183 iListBox->UpdateScrollBarsL(); |
|
184 } |
|
185 } |
|
186 |
|
187 // -------------------------------------------------------------------------------------------- |
|
188 |
|
189 const CArrayFix<TInt>* CLoadGenMainContainer::ListBoxSelectionIndexes() |
|
190 { |
|
191 if (iListBox) |
|
192 { |
|
193 const CListBoxView::CSelectionIndexArray* indices = iListBox->SelectionIndexes(); |
|
194 return static_cast<const CArrayFix<TInt>*>(indices); |
|
195 } |
|
196 else |
|
197 return NULL; |
|
198 } |
|
199 |
|
200 // -------------------------------------------------------------------------------------------- |
|
201 |
|
202 TInt CLoadGenMainContainer::ListBoxSelectionIndexesCount() |
|
203 { |
|
204 if (iListBox) |
|
205 { |
|
206 return iListBox->SelectionIndexes()->Count(); |
|
207 } |
|
208 else |
|
209 return KErrNotFound; |
|
210 } |
|
211 |
|
212 // -------------------------------------------------------------------------------------------- |
|
213 |
|
214 void CLoadGenMainContainer::Draw(const TRect& aRect) const |
|
215 { |
|
216 CWindowGc& gc = SystemGc(); |
|
217 gc.Clear(aRect); |
|
218 } |
|
219 |
|
220 // -------------------------------------------------------------------------------------------- |
|
221 |
|
222 void CLoadGenMainContainer::HandleControlEventL(CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/) |
|
223 { |
|
224 } |
|
225 |
|
226 // -------------------------------------------------------------------------------------------- |
|
227 |
|
228 void CLoadGenMainContainer::SetDefaultTitlePaneTextL() |
|
229 { |
|
230 _LIT(KTitleText, "Load Gener."); |
|
231 |
|
232 CEikStatusPane* sp = iEikonEnv->AppUiFactory()->StatusPane(); |
|
233 CAknTitlePane* tp = static_cast<CAknTitlePane*>( sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) ); |
|
234 tp->SetTextL( KTitleText ); |
|
235 } |
|
236 |
|
237 // -------------------------------------------------------------------------------------------- |
|
238 |
|
239 TKeyResponse CLoadGenMainContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) |
|
240 { |
|
241 if(aType != EEventKey) |
|
242 return EKeyWasNotConsumed; |
|
243 |
|
244 if (iListBox && iListBox->Model()->NumberOfItems() > 0) |
|
245 { |
|
246 /* |
|
247 if (aKeyEvent.iCode == EKeyBackspace || aKeyEvent.iCode == EKeyDelete) |
|
248 { |
|
249 iModel->StopSelectedOrHighlightedItemsL(); |
|
250 return EKeyWasConsumed; |
|
251 } |
|
252 else |
|
253 { |
|
254 return iListBox->OfferKeyEventL(aKeyEvent, aType); |
|
255 } |
|
256 */ |
|
257 TBool shiftKeyPressed = (aKeyEvent.iModifiers & EModifierShift) || |
|
258 (aKeyEvent.iModifiers & EModifierLeftShift) || |
|
259 (aKeyEvent.iModifiers & EModifierRightShift); |
|
260 TBool controlKeyPressed = (aKeyEvent.iModifiers & EModifierCtrl) || |
|
261 (aKeyEvent.iModifiers & EModifierRightCtrl); |
|
262 |
|
263 |
|
264 // handle OK/Enter keys |
|
265 if ((aKeyEvent.iCode == EKeyOK || aKeyEvent.iCode == EKeyEnter) && (shiftKeyPressed || controlKeyPressed)) |
|
266 { |
|
267 return iListBox->OfferKeyEventL(aKeyEvent, aType); //send to listbox if modifiers |
|
268 } |
|
269 |
|
270 // handle OK/Enter keys |
|
271 else if (aKeyEvent.iCode == EKeyOK || aKeyEvent.iCode == EKeyEnter) |
|
272 { |
|
273 iModel->ShowItemActionMenuL(); |
|
274 } |
|
275 |
|
276 // handle delete key |
|
277 else if (aKeyEvent.iCode == EKeyBackspace || aKeyEvent.iCode == EKeyDelete) |
|
278 { |
|
279 iModel->StopSelectedOrHighlightedItemsL(); |
|
280 } |
|
281 |
|
282 else |
|
283 return iListBox->OfferKeyEventL(aKeyEvent, aType); |
|
284 } |
|
285 |
|
286 return EKeyWasNotConsumed; |
|
287 } |
|
288 |
|
289 // -------------------------------------------------------------------------------------------- |
|
290 |
|
291 void CLoadGenMainContainer::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aEventType) |
|
292 { |
|
293 switch (aEventType) |
|
294 { |
|
295 case EEventEnterKeyPressed: |
|
296 case EEventItemDoubleClicked: |
|
297 { |
|
298 iModel->ShowItemActionMenuL(); |
|
299 } |
|
300 break; |
|
301 default: |
|
302 break; |
|
303 } |
|
304 } |
|
305 |
|
306 // -------------------------------------------------------------------------------------------- |
|
307 |
|
308 void CLoadGenMainContainer::HandleResourceChange(TInt aType) |
|
309 { |
|
310 if ( aType == KEikDynamicLayoutVariantSwitch ) |
|
311 { |
|
312 TRect mainPaneRect; |
|
313 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect); |
|
314 SetRect(mainPaneRect); |
|
315 |
|
316 TSize outputRectSize; |
|
317 AknLayoutUtils::LayoutMetricsSize(AknLayoutUtils::EMainPane, outputRectSize); |
|
318 TRect outputRect(outputRectSize); |
|
319 iListBox->SetRect(outputRect); |
|
320 } |
|
321 else |
|
322 { |
|
323 CCoeControl::HandleResourceChange(aType); |
|
324 } |
|
325 } |
|
326 |
|
327 // -------------------------------------------------------------------------------------------- |
|
328 // -------------------------------------------------------------------------------------------- |
|
329 |
|
330 void CLoadGenCAknSingleGraphicStyleListBox::SizeChanged() |
|
331 { |
|
332 // call the base class function first |
|
333 CAknSingleGraphicStyleListBox::SizeChanged(); |
|
334 |
|
335 // customize the list box |
|
336 TRAP_IGNORE(SizeChangedL()); |
|
337 } |
|
338 |
|
339 // -------------------------------------------------------------------------------------------- |
|
340 |
|
341 void CLoadGenCAknSingleGraphicStyleListBox::SizeChangedL() |
|
342 { |
|
343 const TInt KEmptySize = 2; |
|
344 |
|
345 // disable separator line |
|
346 ItemDrawer()->ColumnData()->SetSeparatorLinePosition(ENoLine); |
|
347 |
|
348 // enable marquee |
|
349 ItemDrawer()->ColumnData()->EnableMarqueeL(ETrue); |
|
350 |
|
351 // set fonts |
|
352 const CFont* font = AknLayoutUtils::FontFromId(EAknLogicalFontPrimarySmallFont); |
|
353 ItemDrawer()->ColumnData()->SetColumnFontL(0, font); |
|
354 ItemDrawer()->ColumnData()->SetColumnFontL(1, font); |
|
355 ItemDrawer()->ColumnData()->SetColumnFontL(2, font); |
|
356 ItemDrawer()->ColumnData()->SetColumnFontL(3, font); |
|
357 |
|
358 // set row height |
|
359 TInt rowHeight = font->HeightInPixels()+5; |
|
360 TSize itemCellSize = View()->ItemDrawer()->ItemCellSize(); |
|
361 itemCellSize.iHeight = rowHeight; |
|
362 SetItemHeightL(rowHeight); |
|
363 View()->ItemDrawer()->SetItemCellSize(itemCellSize); |
|
364 |
|
365 // set icon sizes |
|
366 TInt normalIconSize = rowHeight * 0.7; |
|
367 TInt markingIconSize = rowHeight * 0.8; |
|
368 ItemDrawer()->ColumnData()->SetSubCellIconSize(0, TSize(normalIconSize,normalIconSize)); |
|
369 ItemDrawer()->ColumnData()->SetSubCellIconSize(2, TSize(markingIconSize,markingIconSize)); |
|
370 ItemDrawer()->ColumnData()->SetSubCellIconSize(3, TSize(KEmptySize,KEmptySize)); |
|
371 |
|
372 // set column widths |
|
373 ItemDrawer()->ColumnData()->SetColumnWidthPixelL(0, normalIconSize + 2*normalIconSize * 0.15); |
|
374 ItemDrawer()->ColumnData()->SetColumnWidthPixelL(1, itemCellSize.iWidth-KEmptySize-markingIconSize); |
|
375 ItemDrawer()->ColumnData()->SetColumnWidthPixelL(2, markingIconSize); |
|
376 ItemDrawer()->ColumnData()->SetColumnWidthPixelL(3, KEmptySize); |
|
377 |
|
378 // set baseline for the text |
|
379 ItemDrawer()->ColumnData()->SetColumnBaselinePosL(1, font->HeightInPixels()-font->BaselineOffsetInPixels()); |
|
380 |
|
381 // set margins |
|
382 TMargins iconMargins; |
|
383 iconMargins.iBottom = 0; |
|
384 iconMargins.iLeft = normalIconSize * 0.15; |
|
385 iconMargins.iRight = normalIconSize * 0.15; |
|
386 iconMargins.iTop = 0; |
|
387 |
|
388 TMargins textMargins; |
|
389 textMargins.iBottom = 0; |
|
390 textMargins.iLeft = markingIconSize * 0.15; |
|
391 textMargins.iRight = markingIconSize * 0.15; |
|
392 textMargins.iTop = 0; |
|
393 |
|
394 ItemDrawer()->ColumnData()->SetColumnMarginsL(0, iconMargins); |
|
395 ItemDrawer()->ColumnData()->SetColumnMarginsL(1, textMargins); |
|
396 ItemDrawer()->ColumnData()->SetColumnMarginsL(2, iconMargins); |
|
397 ItemDrawer()->ColumnData()->SetColumnMarginsL(3, iconMargins); |
|
398 |
|
399 /* |
|
400 const TInt KEmptySize = 2; |
|
401 |
|
402 // enable marquee |
|
403 ItemDrawer()->ColumnData()->EnableMarqueeL(ETrue); |
|
404 |
|
405 // set fonts |
|
406 const CFont* font = AknLayoutUtils::FontFromId(EAknLogicalFontPrimarySmallFont); |
|
407 ItemDrawer()->ColumnData()->SetColumnFontL(0, font); |
|
408 ItemDrawer()->ColumnData()->SetColumnFontL(1, font); |
|
409 ItemDrawer()->ColumnData()->SetColumnFontL(2, font); |
|
410 ItemDrawer()->ColumnData()->SetColumnFontL(3, font); |
|
411 |
|
412 // set row height |
|
413 TInt rowHeight = font->HeightInPixels()+7; |
|
414 TSize itemCellSize = View()->ItemDrawer()->ItemCellSize(); |
|
415 itemCellSize.iHeight = rowHeight; |
|
416 SetItemHeightL(rowHeight); |
|
417 View()->ItemDrawer()->SetItemCellSize(itemCellSize); |
|
418 |
|
419 // set icon sizes |
|
420 TInt normalIconSize = rowHeight * 0.6; |
|
421 TInt markingIconSize = rowHeight * 0.8; |
|
422 ItemDrawer()->ColumnData()->SetSubCellIconSize(0, TSize(normalIconSize,normalIconSize)); |
|
423 ItemDrawer()->ColumnData()->SetSubCellIconSize(2, TSize(markingIconSize,markingIconSize)); |
|
424 ItemDrawer()->ColumnData()->SetSubCellIconSize(3, TSize(KEmptySize,KEmptySize)); |
|
425 |
|
426 // set column widths |
|
427 ItemDrawer()->ColumnData()->SetColumnWidthPixelL(0, normalIconSize); |
|
428 ItemDrawer()->ColumnData()->SetColumnWidthPixelL(1, itemCellSize.iWidth-KEmptySize-markingIconSize); |
|
429 ItemDrawer()->ColumnData()->SetColumnWidthPixelL(2, markingIconSize); |
|
430 ItemDrawer()->ColumnData()->SetColumnWidthPixelL(3, KEmptySize); |
|
431 |
|
432 // set baseline for the text |
|
433 ItemDrawer()->ColumnData()->SetColumnBaselinePosL(1, font->HeightInPixels()-font->BaselineOffsetInPixels()); |
|
434 |
|
435 // set margins |
|
436 TMargins iconMargins; |
|
437 iconMargins.iBottom = 0; |
|
438 iconMargins.iLeft = 0; |
|
439 iconMargins.iRight = 0; |
|
440 iconMargins.iTop = 0; |
|
441 |
|
442 TMargins textMargins; |
|
443 textMargins.iBottom = 0; |
|
444 textMargins.iLeft = markingIconSize * 0.15; |
|
445 textMargins.iRight = markingIconSize * 0.15; |
|
446 textMargins.iTop = 0; |
|
447 |
|
448 ItemDrawer()->ColumnData()->SetColumnMarginsL(0, iconMargins); |
|
449 ItemDrawer()->ColumnData()->SetColumnMarginsL(1, textMargins); |
|
450 ItemDrawer()->ColumnData()->SetColumnMarginsL(2, iconMargins); |
|
451 ItemDrawer()->ColumnData()->SetColumnMarginsL(3, iconMargins); |
|
452 */ |
|
453 } |
|
454 |
|
455 // -------------------------------------------------------------------------------------------- |
|
456 |
|
457 // End of File |