1 /* |
|
2 * Copyright (c) 2010 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 // INCLUDE FILES |
|
19 #include <coemain.h> |
|
20 #include <mcsmenuitem.h> |
|
21 #include <mcsmenuiconutility.h> |
|
22 #include <mcsdef.h> |
|
23 #include <akniconarray.h> |
|
24 #include <eikclbd.h> |
|
25 #include <eikedwin.h> |
|
26 |
|
27 #include <aknsconstants.h> |
|
28 #include <aknsconstants.hrh> |
|
29 |
|
30 #include <MCSExample_0xEB753B18.rsg> |
|
31 #include "MCSExampleAppView.h" |
|
32 #include "mcspluginwatcher.h" |
|
33 #include "MCSExample.hrh" |
|
34 |
|
35 _LIT( KMenuData, "matrixmenudata" ); |
|
36 |
|
37 CMyForm::CMyForm( TMyData& aData ) : iData( aData ) |
|
38 { |
|
39 } |
|
40 |
|
41 CMyForm::~CMyForm() |
|
42 { |
|
43 } |
|
44 |
|
45 void CMyForm::PreLayoutDynInitL() |
|
46 { |
|
47 CAknForm::PreLayoutDynInitL(); |
|
48 LoadFormDataL(); |
|
49 } |
|
50 |
|
51 void CMyForm::LoadFormDataL() |
|
52 { |
|
53 CEikEdwin* textEd1 = |
|
54 (CEikEdwin*)Control( EMyFirstLine ); |
|
55 textEd1->SetTextL( &iData.majorID ); |
|
56 |
|
57 CEikEdwin* textEd2 = |
|
58 (CEikEdwin*)Control( EMySecondLine ); |
|
59 textEd2->SetTextL( &iData.minorID ); |
|
60 |
|
61 CEikEdwin* textEd3 = |
|
62 (CEikEdwin*)Control( EMyThirdLine ); |
|
63 textEd3->SetTextL( &iData.iconFile ); |
|
64 |
|
65 CEikEdwin* textEd4 = |
|
66 (CEikEdwin*)Control( EMyFourthLine ); |
|
67 textEd4->SetTextL( &iData.iconID ); |
|
68 |
|
69 CEikEdwin* textEd5 = |
|
70 (CEikEdwin*)Control( EMyFifthLine ); |
|
71 textEd5->SetTextL( &iData.maskID ); |
|
72 |
|
73 CEikEdwin* textEd6 = |
|
74 (CEikEdwin*)Control( EMySixthLine ); |
|
75 textEd6->SetTextL( &iData.statusIcon ); |
|
76 } |
|
77 |
|
78 TBool CMyForm::SaveFormDataL() |
|
79 { |
|
80 CEikEdwin* textEd1 = |
|
81 (CEikEdwin*)Control( EMyFirstLine ); |
|
82 textEd1->GetText( iData.majorID ); |
|
83 |
|
84 CEikEdwin* textEd2 = |
|
85 (CEikEdwin*)Control( EMySecondLine ); |
|
86 textEd2->GetText( iData.minorID ); |
|
87 |
|
88 CEikEdwin* textEd3 = |
|
89 (CEikEdwin*)Control( EMyThirdLine ); |
|
90 textEd3->GetText( iData.iconFile ); |
|
91 |
|
92 CEikEdwin* textEd4 = |
|
93 (CEikEdwin*)Control( EMyFourthLine ); |
|
94 textEd4->GetText( iData.iconID ); |
|
95 |
|
96 CEikEdwin* textEd5 = |
|
97 (CEikEdwin*)Control( EMyFifthLine ); |
|
98 textEd5->GetText( iData.maskID ); |
|
99 |
|
100 CEikEdwin* textEd6 = |
|
101 (CEikEdwin*)Control( EMySixthLine ); |
|
102 textEd6->GetText( iData.statusIcon ); |
|
103 return ETrue; |
|
104 } |
|
105 |
|
106 void CMyForm::DoNotSaveFormDataL() |
|
107 { |
|
108 LoadFormDataL(); |
|
109 } |
|
110 |
|
111 TBool CMyForm::OkToExitL( TInt aButtonId ) |
|
112 { |
|
113 if ( aButtonId == EAknSoftkeyOk) |
|
114 { |
|
115 SaveFormDataL(); |
|
116 iData.updated = ETrue; |
|
117 } |
|
118 else if( aButtonId == EAknSoftkeyCancel ) |
|
119 { |
|
120 iData.updated = EFalse; |
|
121 } |
|
122 return ETrue; |
|
123 } |
|
124 |
|
125 CGulIcon* ConvertToGulIconLC( CAknIcon* aIcon ) |
|
126 { |
|
127 CGulIcon* icon = CGulIcon::NewL( aIcon->Bitmap(), aIcon->Mask() ); |
|
128 CleanupStack::PushL( icon ); |
|
129 // Detach bitmap and mask |
|
130 aIcon->SetBitmap( NULL ); |
|
131 aIcon->SetMask( NULL ); |
|
132 return icon; |
|
133 } |
|
134 |
|
135 |
|
136 // ============================ MEMBER FUNCTIONS =============================== |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // CMCSExampleAppView::NewL() |
|
140 // Two-phased constructor. |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 CMCSExampleAppView* CMCSExampleAppView::NewL(const TRect& aRect) |
|
144 { |
|
145 CMCSExampleAppView* self = CMCSExampleAppView::NewLC(aRect); |
|
146 CleanupStack::Pop(self); |
|
147 return self; |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CMCSExampleAppView::NewLC() |
|
152 // Two-phased constructor. |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 CMCSExampleAppView* CMCSExampleAppView::NewLC(const TRect& aRect) |
|
156 { |
|
157 CMCSExampleAppView* self = new (ELeave) CMCSExampleAppView; |
|
158 CleanupStack::PushL(self); |
|
159 self->ConstructL(aRect); |
|
160 return self; |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CMCSExampleAppView::ConstructL() |
|
165 // Symbian 2nd phase constructor can leave. |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 void CMCSExampleAppView::ConstructL(const TRect& aRect) |
|
169 { |
|
170 // Create a window for this application view |
|
171 CreateWindowL(); |
|
172 |
|
173 // Set the windows size |
|
174 SetRect(aRect); |
|
175 |
|
176 // Activate the window, which makes it ready to be drawn |
|
177 ActivateL(); |
|
178 |
|
179 iMCSMenu.OpenL( KMenuData ); |
|
180 iWatcher = CMCSExampleWatcher::NewL(); |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CMCSExampleAppView::CMCSExampleAppView() |
|
185 // C++ default constructor can NOT contain any code, that might leave. |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 CMCSExampleAppView::CMCSExampleAppView() |
|
189 { |
|
190 // No implementation required |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CMCSExampleAppView::~CMCSExampleAppView() |
|
195 // Destructor. |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 CMCSExampleAppView::~CMCSExampleAppView() |
|
199 { |
|
200 iMCSMenu.Close(); |
|
201 delete iListBox; |
|
202 iItemArray.Close(); |
|
203 delete iWatcher; |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 void CMCSExampleAppView::ListAllItemsL() |
|
211 { |
|
212 |
|
213 |
|
214 CArrayPtr<CGulIcon>* icons =new( ELeave ) CAknIconArray(1); |
|
215 CleanupStack::PushL(icons); |
|
216 |
|
217 iListBox->Model()->SetItemTextArray(GetArrayL(icons)); |
|
218 iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray); |
|
219 // |
|
220 // Inform the listbox of item additions. |
|
221 // This should be done if you want your items displayed correctly |
|
222 iListBox ->HandleItemAdditionL(); |
|
223 |
|
224 CleanupStack::Pop(icons); |
|
225 CArrayPtr<CGulIcon>* oldArray = iListBox->ItemDrawer()->ColumnData()->IconArray(); |
|
226 delete oldArray; |
|
227 iListBox->ItemDrawer()->ColumnData()->SetIconArray(icons); |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 void CMCSExampleAppView::MakeListBoxL() |
|
235 { |
|
236 TInt MySetIndex(0); |
|
237 |
|
238 if(iListBox) |
|
239 { |
|
240 MySetIndex = iListBox->CurrentItemIndex(); |
|
241 } |
|
242 |
|
243 delete iListBox; |
|
244 iListBox = NULL; |
|
245 |
|
246 iListBox = new( ELeave ) CAknSingleLargeStyleListBox(); |
|
247 iListBox->ConstructL(this,EAknListBoxSelectionList); |
|
248 iListBox->SetListBoxObserver( this ); |
|
249 |
|
250 iListBox->CreateScrollBarFrameL( ETrue ); |
|
251 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
252 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
253 |
|
254 iListBox->SetRect(Rect()); |
|
255 |
|
256 iListBox->View()->SetListEmptyTextL(_L("No data")); |
|
257 |
|
258 iListBox->ActivateL(); |
|
259 |
|
260 TInt ItemsCount = iListBox->Model()->ItemTextArray()->MdcaCount(); |
|
261 |
|
262 if(ItemsCount > MySetIndex && MySetIndex >= 0) |
|
263 iListBox->SetCurrentItemIndex(MySetIndex); |
|
264 else if(ItemsCount > 0) |
|
265 iListBox->SetCurrentItemIndex(0); |
|
266 |
|
267 UpdateScrollBar(iListBox); |
|
268 iListBox->DrawNow(); |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 CDesCArray* CMCSExampleAppView::GetArrayL(CArrayPtr<CGulIcon>* aIcons) |
|
276 { |
|
277 TBuf<256> listString; |
|
278 CDesCArrayFlat* myArray = new(ELeave)CDesCArrayFlat(1); |
|
279 CleanupStack::PushL(myArray); |
|
280 |
|
281 const TInt rootId = iMCSMenu. RootFolderL(); |
|
282 iItemArray.Reset(); |
|
283 //CleanupClosePushL( itemArray ); |
|
284 // Get all the items from MCS |
|
285 iMCSMenu.GetItemsL( iItemArray, rootId, NULL, ETrue ); |
|
286 |
|
287 for( TInt i = 0; i < iItemArray.Count(); i++ ) |
|
288 { |
|
289 // Open the actual item |
|
290 CMenuItem* menuItem = CMenuItem::OpenL( iMCSMenu, iItemArray[i] ); |
|
291 CleanupStack::PushL( menuItem ); |
|
292 |
|
293 // Get the name of the item |
|
294 TBool attrExists( EFalse ); |
|
295 TPtrC attr = menuItem->GetAttributeL(_L("short_name" ), attrExists ); |
|
296 |
|
297 //Create listbox string |
|
298 listString.Delete(0, 256); |
|
299 listString.AppendNum( i ); |
|
300 listString.Append( _L("\t")); |
|
301 listString.Append( attr ); |
|
302 myArray->AppendL( listString ); |
|
303 |
|
304 //Fetch the item icon from MCS |
|
305 CAknIcon* icon = MenuIconUtility::GetItemIconL( *menuItem ); |
|
306 CleanupStack::PushL( icon ); |
|
307 if ( icon ) |
|
308 { |
|
309 CGulIcon* gIcon = ConvertToGulIconLC( icon ); |
|
310 aIcons->AppendL( gIcon ); |
|
311 CleanupStack::Pop( gIcon ); |
|
312 } |
|
313 CleanupStack::PopAndDestroy( icon ); |
|
314 CleanupStack::PopAndDestroy( menuItem ); |
|
315 } |
|
316 CleanupStack::Pop(myArray); |
|
317 return myArray; |
|
318 } |
|
319 |
|
320 // ----------------------------------------------------------------------------- |
|
321 // |
|
322 // ----------------------------------------------------------------------------- |
|
323 // |
|
324 void CMCSExampleAppView::UpdateScrollBar(CEikListBox* aListBox) |
|
325 { |
|
326 if (aListBox) |
|
327 { |
|
328 TInt pos(aListBox->View()->CurrentItemIndex()); |
|
329 if (aListBox->ScrollBarFrame()) |
|
330 { |
|
331 aListBox->ScrollBarFrame()->MoveVertThumbTo(pos); |
|
332 } |
|
333 } |
|
334 } |
|
335 |
|
336 // ----------------------------------------------------------------------------- |
|
337 // CMCSExampleAppView::Draw() |
|
338 // Draws the display. |
|
339 // ----------------------------------------------------------------------------- |
|
340 // |
|
341 void CMCSExampleAppView::Draw(const TRect& /*aRect*/) const |
|
342 { |
|
343 // Get the standard graphics context |
|
344 CWindowGc& gc = SystemGc(); |
|
345 |
|
346 // Gets the control's extent |
|
347 TRect drawRect(Rect()); |
|
348 |
|
349 // Clears the screen |
|
350 gc.Clear(drawRect); |
|
351 |
|
352 } |
|
353 |
|
354 // ----------------------------------------------------------------------------- |
|
355 // CMCSExampleAppView::SizeChanged() |
|
356 // Called by framework when the view size is changed. |
|
357 // ----------------------------------------------------------------------------- |
|
358 // |
|
359 void CMCSExampleAppView::SizeChanged() |
|
360 { |
|
361 TRAP_IGNORE( MakeListBoxL() ); |
|
362 DrawNow(); |
|
363 } |
|
364 |
|
365 // ----------------------------------------------------------------------------- |
|
366 // CMCSExampleAppView::HandlePointerEventL() |
|
367 // Called by framework to handle pointer touch events. |
|
368 // Note: although this method is compatible with earlier SDKs, |
|
369 // it will not be called in SDKs without Touch support. |
|
370 // ----------------------------------------------------------------------------- |
|
371 // |
|
372 void CMCSExampleAppView::HandlePointerEventL( |
|
373 const TPointerEvent& aPointerEvent) |
|
374 { |
|
375 |
|
376 // Call base class HandlePointerEventL() |
|
377 CCoeControl::HandlePointerEventL(aPointerEvent); |
|
378 } |
|
379 |
|
380 // ----------------------------------------------------------------------------- |
|
381 // ----------------------------------------------------------------------------- |
|
382 // |
|
383 void CMCSExampleAppView::HandleListBoxEventL( CEikListBox* /*aListBox*/, TListBoxEvent aEventType ) |
|
384 { |
|
385 if( iListBox && aEventType == EEventItemSingleClicked ) |
|
386 { |
|
387 TInt index = iListBox->CurrentItemIndex(); |
|
388 if( index < iItemArray.Count()) |
|
389 { |
|
390 ShowFormL( index ); |
|
391 } |
|
392 } |
|
393 } |
|
394 |
|
395 // ----------------------------------------------------------------------------- |
|
396 // ----------------------------------------------------------------------------- |
|
397 // |
|
398 void CMCSExampleAppView::ShowFormL( TInt aItemIndex) |
|
399 { |
|
400 CMenuItem* menuItem = CMenuItem::OpenL( iMCSMenu, iItemArray[aItemIndex] ); |
|
401 CleanupStack::PushL( menuItem ); |
|
402 TBool attrExists( EFalse ); |
|
403 TPtrC attr = menuItem->GetAttributeL(_L("short_name" ), attrExists ); |
|
404 // Initialize form data. |
|
405 TBool exists( EFalse );; |
|
406 TMyData myData; |
|
407 myData.majorID = menuItem->GetAttributeL( KMenuAttrIconSkinMajorId, exists ); |
|
408 myData.minorID = menuItem->GetAttributeL( KMenuAttrIconSkinMinorId, exists ); |
|
409 myData.iconFile = menuItem->GetAttributeL( KMenuAttrIconFile, exists ); |
|
410 myData.iconID = menuItem->GetAttributeL( KMenuAttrIconId, exists ); |
|
411 myData.maskID = menuItem->GetAttributeL( KMenuAttrMaskId, exists ); |
|
412 // e.g. skin(0x101F86E3 0x1ee2) |
|
413 myData.statusIcon = menuItem->GetAttributeL( _L("presenceicon"), exists ); |
|
414 myData.updated = EFalse; |
|
415 |
|
416 // Launch the dialog to view/edit data |
|
417 CAknForm* dlg = new ( ELeave ) CMyForm( myData ); |
|
418 CleanupStack::PushL( dlg ); |
|
419 dlg->ConstructL( 0 ); // default menu items only |
|
420 CleanupStack::Pop( dlg ); |
|
421 dlg->ExecuteLD( R_ICON_QUERY_DIALOG ); |
|
422 // myData now contains the edited values. |
|
423 |
|
424 if( myData.updated ) |
|
425 { |
|
426 // Changes the main icon, if all values are empty then application icon is used. |
|
427 // Piority 0 |
|
428 menuItem->SetAttributeL(KMenuAttrIconSkinMajorId, myData.majorID ); |
|
429 menuItem->SetAttributeL(KMenuAttrIconSkinMinorId, myData.minorID ); |
|
430 // Pririty 1 |
|
431 menuItem->SetAttributeL(KMenuAttrIconFile, myData.iconFile ); |
|
432 menuItem->SetAttributeL(KMenuAttrIconId, myData.iconID ); |
|
433 menuItem->SetAttributeL(KMenuAttrMaskId, myData.maskID ); |
|
434 //Changes the presence icon |
|
435 menuItem->SetAttributeL( _L("presenceicon"), myData.statusIcon ); |
|
436 |
|
437 CMenuOperation* operation = menuItem->SaveL( iWatcher->iStatus ); |
|
438 // Deletes the operation after its completion |
|
439 iWatcher->Watch( operation, this ); |
|
440 } |
|
441 CleanupStack::PopAndDestroy( menuItem ); |
|
442 } |
|
443 |
|
444 // ----------------------------------------------------------------------------- |
|
445 // ----------------------------------------------------------------------------- |
|
446 // |
|
447 CCoeControl* CMCSExampleAppView::ComponentControl( TInt /*aIndex*/) const |
|
448 { |
|
449 return iListBox; |
|
450 } |
|
451 |
|
452 // ----------------------------------------------------------------------------- |
|
453 // ----------------------------------------------------------------------------- |
|
454 // |
|
455 TInt CMCSExampleAppView::CountComponentControls() const |
|
456 { |
|
457 if(iListBox) |
|
458 return 1; |
|
459 else |
|
460 return 0; |
|
461 } |
|
462 // End of File |
|