|
1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * Dialog for Bubble plugin. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include <AknsDrawUtils.h> |
|
23 #include <eikmover.h> |
|
24 #include <aknview.h> |
|
25 #include <aknlists.h> |
|
26 #include <barsread.h> |
|
27 #include <akniconarray.h> |
|
28 #include <gulicon.h> |
|
29 #include <bautils.h> |
|
30 #include <coecobs.h> |
|
31 #include <uikon.hrh> |
|
32 #include <ConeResLoader.h> |
|
33 #include <BitmapTransforms.h> |
|
34 #include <eikprogi.h> |
|
35 #include <s32file.h> |
|
36 #include <aknslistboxbackgroundcontrolcontext.h> |
|
37 #include <AknLayoutScalable_Apps.cdl.h> |
|
38 #include <layoutmetadata.cdl.h> |
|
39 |
|
40 #include "BubbleSelectionGrid.h" |
|
41 #include "BubbleScaler.h" |
|
42 #include "Callback.h" |
|
43 #include "Bubble.hrh" |
|
44 #include "BubbleSelectionDialog.h" |
|
45 #include "ResolutionUtil.h" |
|
46 #include "ImageEditorUI.hrh" |
|
47 #include "iepb.h" |
|
48 #include "ImageEditorError.h" |
|
49 #include <Bubble.rsg> |
|
50 |
|
51 // debug log |
|
52 #include "imageeditordebugutils.h" |
|
53 |
|
54 _LIT(KBubblePluginLogFile,"BubblePlugin.log"); |
|
55 |
|
56 // Constants |
|
57 const TInt KDefaultNumberOfBubbles = 51; |
|
58 |
|
59 const TInt KStandardBubbleGridCellWidth = 40; |
|
60 const TInt KStandardBubbleGridCellHeight = 30; |
|
61 |
|
62 const TInt KQVGABubbleGridCellWidth = 56; |
|
63 const TInt KQVGABubbleGridCellHeight = 46; |
|
64 |
|
65 const TInt KDoubleBubbleGridCellWidth = 80; |
|
66 const TInt KDoubleBubbleGridCellHeight = 60; |
|
67 |
|
68 const TInt KVGABubbleGridCellWidth = 95; |
|
69 const TInt KVGABubbleGridCellHeight = 60; |
|
70 |
|
71 const TInt KQHDBubbleGridCellWidth = 80; |
|
72 const TInt KQHDBubbleGridCellHeight = 60; |
|
73 |
|
74 const TInt KBubbleGridCellGap = 0; |
|
75 |
|
76 const TInt KScrollBarWidth = 3; |
|
77 |
|
78 const TInt KProgressInterval = 5; |
|
79 |
|
80 _LIT (KBubbleResourceFile, "Bubble.rsc"); |
|
81 _LIT (KBubbleFileWild, "*.mbm"); |
|
82 _LIT( KBubbleExternalizeFile, "c:\\private\\101FFA91\\BubbleStorage.ini"); |
|
83 |
|
84 |
|
85 //============================================================================= |
|
86 CBubbleSelectionDialog::CBubbleSelectionDialog(TFileName& aBubbleFileName, TInt& aBubbleFileNameIndex) |
|
87 : CEikDialog() |
|
88 , iGrid(NULL) |
|
89 , iBubbleFileName(aBubbleFileName) |
|
90 , iBubbleFileNameIndex(aBubbleFileNameIndex) |
|
91 , iIconArray(NULL) |
|
92 , iTextArray(NULL) |
|
93 , iProgressDialog(NULL) |
|
94 , iBubbleScaler(NULL) |
|
95 , iCallback(NULL) |
|
96 , iCurrentBitmap(NULL) |
|
97 , iCurrentMask(NULL) |
|
98 , iCurrentIcon(0) |
|
99 , iState(EIdle) |
|
100 , iBusy(ETrue) |
|
101 , iDoubleClick(EFalse) |
|
102 , iClick(EFalse) |
|
103 { |
|
104 |
|
105 } |
|
106 //============================================================================= |
|
107 CBubbleSelectionDialog::~CBubbleSelectionDialog() |
|
108 { |
|
109 if (iCallback) |
|
110 { |
|
111 iCallback->Cancel(); |
|
112 } |
|
113 delete iCallback; |
|
114 |
|
115 if (iBubbleScaler) |
|
116 { |
|
117 iBubbleScaler->Cancel(); |
|
118 } |
|
119 delete iBubbleScaler; |
|
120 |
|
121 if (iIconArray) |
|
122 { |
|
123 delete iIconArray; |
|
124 iIconArray = NULL; |
|
125 } |
|
126 if (iTextArray) |
|
127 { |
|
128 delete iTextArray; |
|
129 iTextArray = NULL; |
|
130 } |
|
131 |
|
132 iBubbleList.Close(); |
|
133 delete iCurrentBitmap; |
|
134 delete iCurrentMask; |
|
135 delete iProgressDialog; |
|
136 |
|
137 delete iGrid; |
|
138 } |
|
139 |
|
140 |
|
141 //============================================================================= |
|
142 void CBubbleSelectionDialog::ConstructL(MCoeControlObserver* aParent) |
|
143 { |
|
144 |
|
145 SetObserver(aParent); |
|
146 |
|
147 iBubbleScaler = new (ELeave) CBubbleScaler(this); |
|
148 iBubbleScaler->ConstructL(); |
|
149 |
|
150 // Callback |
|
151 iCallback = CObCallback::NewL(this); |
|
152 |
|
153 // Create icon and text arrays |
|
154 iIconArray = new(ELeave) CAknIconArray(KDefaultNumberOfBubbles); |
|
155 iTextArray = new(ELeave) CDesC16ArrayFlat(KDefaultNumberOfBubbles); |
|
156 |
|
157 TInt screenMode = CResolutionUtil::Self()->GetScreenMode(); |
|
158 |
|
159 switch (screenMode) |
|
160 { |
|
161 |
|
162 case CResolutionUtil::EDouble: |
|
163 case CResolutionUtil::EDoubleFullScreen: |
|
164 case CResolutionUtil::EDoubleLandscape: |
|
165 case CResolutionUtil::EDoubleLandscapeFullScreen: |
|
166 { |
|
167 iBubbleGridCellWidth = KDoubleBubbleGridCellWidth; |
|
168 iBubbleGridCellHeight = KDoubleBubbleGridCellHeight; |
|
169 break; |
|
170 } |
|
171 |
|
172 case CResolutionUtil::EQVGA: |
|
173 case CResolutionUtil::EQVGAFullScreen: |
|
174 case CResolutionUtil::EQVGALandscape: |
|
175 case CResolutionUtil::EQVGALandscapeFullScreen: |
|
176 { |
|
177 iBubbleGridCellWidth = KQVGABubbleGridCellWidth; |
|
178 iBubbleGridCellHeight = KQVGABubbleGridCellHeight; |
|
179 break; |
|
180 } |
|
181 |
|
182 case CResolutionUtil::EVGA: |
|
183 case CResolutionUtil::EVGAFullScreen: |
|
184 case CResolutionUtil::EVGALandscape: |
|
185 case CResolutionUtil::EVGALandscapeFullScreen: |
|
186 { |
|
187 iBubbleGridCellWidth = KVGABubbleGridCellWidth; |
|
188 iBubbleGridCellHeight = KVGABubbleGridCellHeight; |
|
189 break; |
|
190 } |
|
191 |
|
192 case CResolutionUtil::EQHD: |
|
193 case CResolutionUtil::EQHDFullScreen: |
|
194 case CResolutionUtil::EQHDLandscape: |
|
195 case CResolutionUtil::EQHDLandscapeFullScreen: |
|
196 { |
|
197 iBubbleGridCellWidth = KQHDBubbleGridCellWidth; |
|
198 iBubbleGridCellHeight = KQHDBubbleGridCellHeight; |
|
199 break; |
|
200 } |
|
201 default: |
|
202 { |
|
203 iBubbleGridCellWidth = KStandardBubbleGridCellWidth; |
|
204 iBubbleGridCellHeight = KStandardBubbleGridCellHeight; |
|
205 break; |
|
206 } |
|
207 } |
|
208 |
|
209 // Check that if externalize file exists |
|
210 RFs& fs = ControlEnv()->FsSession(); |
|
211 BaflUtils::EnsurePathExistsL( fs, KBubbleExternalizeFile() ); |
|
212 |
|
213 if( BaflUtils::FileExists(fs, KBubbleExternalizeFile()) ) |
|
214 { |
|
215 FindBubblesL(); |
|
216 |
|
217 // Internalize icons if externalize file exists |
|
218 TRAPD(err, |
|
219 InternalizeIconArrayL(); |
|
220 ); |
|
221 |
|
222 if (err) |
|
223 { |
|
224 // if error delete externalization file |
|
225 BaflUtils::DeleteFile( |
|
226 ControlEnv()->FsSession(), |
|
227 KBubbleExternalizeFile() |
|
228 ); |
|
229 |
|
230 User::Leave(err); |
|
231 } |
|
232 |
|
233 iCallback->DoCallback(0); |
|
234 } |
|
235 else |
|
236 { |
|
237 |
|
238 // Find Bubbles |
|
239 FindBubblesL(); |
|
240 |
|
241 // Create progress note dialog |
|
242 iProgressDialog = new ( ELeave ) CAknProgressDialog( reinterpret_cast<CEikDialog**>(&iProgressDialog) ); |
|
243 iProgressDialog->PrepareLC(R_BUBBLE_PROGRESS_NOTE); |
|
244 iProgressDialog->GetProgressInfoL()->SetFinalValue( iBubbleList.Count() ); |
|
245 iProgressDialog->SetCallback ( (MProgressDialogCallback *) this); |
|
246 iProgressDialog->RunLD(); |
|
247 |
|
248 // Load Bubble bitmaps for the grid - asynchronous method |
|
249 LoadBitmapsL(); |
|
250 |
|
251 } |
|
252 |
|
253 |
|
254 } |
|
255 |
|
256 //============================================================================= |
|
257 void CBubbleSelectionDialog::PreLayoutDynInitL () |
|
258 { |
|
259 |
|
260 CAknGrid* grid = (CAknGrid*)ControlOrNull(EBubbleSelectionGrid); |
|
261 |
|
262 // Set icon array to grid |
|
263 grid->ItemDrawer()->FormattedCellData()->SetIconArray(iIconArray); |
|
264 iIconArray = NULL; // ownership moved |
|
265 |
|
266 grid->Model()->SetItemTextArray(iTextArray); |
|
267 iTextArray = NULL; // ownership moved |
|
268 |
|
269 TRect clientRect; |
|
270 CResolutionUtil::Self()->GetClientRect(clientRect); |
|
271 |
|
272 TInt rows = clientRect.Height() / iBubbleGridCellHeight; |
|
273 TInt columns = (clientRect.Width() - KScrollBarWidth) / iBubbleGridCellWidth; |
|
274 |
|
275 grid->SetRect(clientRect); |
|
276 |
|
277 // Set grid layout |
|
278 grid->SetLayoutL ( |
|
279 EFalse, |
|
280 ETrue, |
|
281 ETrue, |
|
282 columns, |
|
283 rows, |
|
284 TSize(iBubbleGridCellWidth, iBubbleGridCellHeight) |
|
285 ); |
|
286 |
|
287 grid->SetPrimaryScrollingType (CAknGridView::EScrollIncrementLineAndLoops); |
|
288 grid->SetSecondaryScrollingType (CAknGridView::EScrollIncrementLineAndLoops); |
|
289 |
|
290 // Set gaps between items |
|
291 ((CAknGridView*)grid->View())-> |
|
292 SetSpacesBetweenItems(TSize(KBubbleGridCellGap,KBubbleGridCellGap)); |
|
293 |
|
294 grid->SetCurrentDataIndex (0); |
|
295 |
|
296 SetupGrid(); |
|
297 |
|
298 // Set scroll bar |
|
299 grid->CreateScrollBarFrameL(ETrue, EFalse); |
|
300 // Hide scroll bar as there are only so few bubbles at the moment available |
|
301 grid->ScrollBarFrame()-> |
|
302 SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOff); |
|
303 |
|
304 // Inform list box about new icons |
|
305 grid->HandleItemAdditionL(); |
|
306 |
|
307 grid->SetListBoxObserver(this); |
|
308 |
|
309 TBool iLandscape = CResolutionUtil::Self()->GetLandscape(); |
|
310 if (iLandscape) |
|
311 { |
|
312 grid->ItemDrawer()->ColumnData()->SetSkinEnabledL(ETrue); |
|
313 CAknsListBoxBackgroundControlContext* context = static_cast<CAknsListBoxBackgroundControlContext*>(grid->ItemDrawer()->ColumnData()->SkinBackgroundContext()); |
|
314 TRect bgRect = clientRect; |
|
315 |
|
316 TRect spRect; |
|
317 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EBatteryPane, spRect); |
|
318 |
|
319 |
|
320 bgRect.iTl.iY-=spRect.Height(); |
|
321 context->SetRect(bgRect); |
|
322 context->SetBitmap( KAknsIIDQsnBgAreaMainFlat ); |
|
323 } |
|
324 // Reset busy flag |
|
325 SetBusy(EFalse); |
|
326 |
|
327 } |
|
328 |
|
329 //============================================================================= |
|
330 void CBubbleSelectionDialog::SetSizeAndPosition( const TSize& aSize) |
|
331 { |
|
332 CEikDialog::SetSizeAndPosition(aSize); |
|
333 |
|
334 } |
|
335 |
|
336 //============================================================================= |
|
337 TBool CBubbleSelectionDialog::OkToExitL( TInt aButtonId ) |
|
338 { |
|
339 if ( aButtonId == EAknSoftkeyOk || aButtonId == EAknSoftkeySelect) |
|
340 { |
|
341 BubbleFilenameL(iBubbleFileName, iBubbleFileNameIndex); |
|
342 return ETrue; |
|
343 } |
|
344 else |
|
345 { |
|
346 return EFalse; |
|
347 } |
|
348 } |
|
349 |
|
350 //============================================================================= |
|
351 |
|
352 TBool CBubbleSelectionDialog::CallbackMethodL ( TInt /*aParam*/ ) |
|
353 { |
|
354 LOG(KBubblePluginLogFile, "CBubbleSelectionDialog::CallbackMethodL()"); |
|
355 |
|
356 // Report that the grid is ready |
|
357 ReportEventL(MCoeControlObserver::EEventStateChanged); |
|
358 |
|
359 return EFalse; |
|
360 } |
|
361 |
|
362 //============================================================================= |
|
363 TKeyResponse CBubbleSelectionDialog::OfferKeyEventL ( |
|
364 const TKeyEvent & aKeyEvent, |
|
365 TEventCode aType |
|
366 ) |
|
367 { |
|
368 TKeyResponse result = EKeyWasNotConsumed; |
|
369 if ( |
|
370 ( aKeyEvent.iCode == EKeyEnter ) |
|
371 ) |
|
372 { |
|
373 TryExitL( EAknSoftkeyOk ); |
|
374 result = EKeyWasConsumed; |
|
375 } |
|
376 else |
|
377 { |
|
378 result = CEikDialog::OfferKeyEventL( aKeyEvent, aType ); |
|
379 } |
|
380 return result; |
|
381 |
|
382 } |
|
383 |
|
384 //============================================================================= |
|
385 void CBubbleSelectionDialog::FindBubblesL() |
|
386 { |
|
387 LOG(KBubblePluginLogFile, "CBubbleSelectionGrid::FindBubblesL()"); |
|
388 |
|
389 // Read resource |
|
390 TFileName resourcefile; |
|
391 resourcefile.Append(KPgnResourcePath); |
|
392 resourcefile.Append(KBubbleResourceFile); |
|
393 User::LeaveIfError( CompleteWithAppPath( resourcefile ) ); |
|
394 |
|
395 // Get reference to application file session |
|
396 RFs & fs = ControlEnv()->FsSession(); |
|
397 |
|
398 // Implementation of RConeResourceLoader uses BaflUtils::NearestLanguageFile |
|
399 // to search for a localised resource in proper search order |
|
400 RConeResourceLoader resLoader( *ControlEnv() ); |
|
401 resLoader.OpenL ( resourcefile ); |
|
402 CleanupClosePushL(resLoader); |
|
403 |
|
404 CDesCArrayFlat* array = |
|
405 ControlEnv()->ReadDesCArrayResourceL(R_BUBBLE_DIRS); |
|
406 CleanupStack::PushL(array); |
|
407 |
|
408 TBuf<256> pathList; |
|
409 _LIT(KPathSeparator, ";"); |
|
410 |
|
411 for (TInt i = 0; i < array->Count(); ++i) |
|
412 { |
|
413 pathList.Append((*array)[i]); |
|
414 pathList.Append(KPathSeparator); |
|
415 } |
|
416 CleanupStack::PopAndDestroy(2); // resLoader, array |
|
417 |
|
418 // Create a file finder |
|
419 TFindFile fileFinder (fs); |
|
420 CDir * fileList = NULL; |
|
421 |
|
422 // Find files by wild card and directory |
|
423 TInt err = fileFinder.FindWildByPath ( |
|
424 KBubbleFileWild, |
|
425 &pathList, |
|
426 fileList |
|
427 ); |
|
428 |
|
429 LOGFMT(KBubblePluginLogFile, "CBubbleSelectionGrid::FindBubblesL: found %d Bubbles", fileList->Count()); |
|
430 |
|
431 // Trace leave |
|
432 if (err) |
|
433 { |
|
434 LOGFMT(KBubblePluginLogFile, "CBubbleSelectionGrid::FindBubblesL: FindWildByPath returned %d. Leaving...", err); |
|
435 User::LeaveIfError(KSIEEInternal); |
|
436 } |
|
437 |
|
438 // Go through files |
|
439 while (err == KErrNone) |
|
440 { |
|
441 CleanupStack::PushL (fileList); |
|
442 |
|
443 // Check all plug-in candidates |
|
444 for (TInt i = 0; i < fileList->Count(); ++i) |
|
445 { |
|
446 |
|
447 // Create a full file name for a MBM file |
|
448 TParse fullentry; |
|
449 fullentry.Set ( |
|
450 (*fileList)[i].iName,& |
|
451 fileFinder.File(), |
|
452 0 |
|
453 ); |
|
454 TPtrC fullname (fullentry.FullName()); |
|
455 |
|
456 // Check the amount of frames |
|
457 TInt err_bmp = KErrNone; |
|
458 TInt j = 0; |
|
459 |
|
460 while (err_bmp == KErrNone) |
|
461 { |
|
462 // Try to load next bitmap. |
|
463 // KErrNotFound if no more bitmaps |
|
464 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap; |
|
465 CleanupStack::PushL (bitmap); |
|
466 err_bmp = bitmap->Load (fullname, j); |
|
467 |
|
468 CFbsBitmap* bitmapMask = new (ELeave) CFbsBitmap; |
|
469 CleanupStack::PushL (bitmapMask); |
|
470 TInt err_mask = bitmapMask->Load (fullname, j + 1); |
|
471 |
|
472 if (err_bmp == KErrNone && err_mask != KErrNone) |
|
473 { |
|
474 User::Leave(KSIEEInternal); |
|
475 } |
|
476 |
|
477 if (err_bmp == KErrNone) |
|
478 { |
|
479 |
|
480 // Add filename-index pair to the Bubble list |
|
481 TBubbleListItem item; |
|
482 item.iFilename = fullname; |
|
483 item.iIndex = j; |
|
484 iBubbleList.Append(item); |
|
485 |
|
486 } |
|
487 CleanupStack::PopAndDestroy(2); // bitmap, mask |
|
488 |
|
489 j += 2; |
|
490 } |
|
491 } |
|
492 |
|
493 CleanupStack::PopAndDestroy(); /// fileList |
|
494 |
|
495 // Try once again |
|
496 err = fileFinder.FindWild (fileList); |
|
497 |
|
498 } |
|
499 |
|
500 } |
|
501 |
|
502 |
|
503 //============================================================================= |
|
504 void CBubbleSelectionDialog::LoadBitmapsL() |
|
505 { |
|
506 LOG(KBubblePluginLogFile, "CBubbleSelectionGrid::LoadBitmapsL()"); |
|
507 |
|
508 // Create and load new one |
|
509 iCurrentBitmap = new (ELeave) CFbsBitmap; |
|
510 User::LeaveIfError(iCurrentBitmap->Load( |
|
511 iBubbleList[iCurrentIcon].iFilename, |
|
512 iBubbleList[iCurrentIcon].iIndex)); |
|
513 |
|
514 // Create and load new one |
|
515 iCurrentMask = new (ELeave) CFbsBitmap; |
|
516 User::LeaveIfError(iCurrentMask->Load( |
|
517 iBubbleList[iCurrentIcon].iFilename, |
|
518 iBubbleList[iCurrentIcon].iIndex + 1)); |
|
519 |
|
520 // Scale bitmap to grid size |
|
521 iState = EScalingBitmap; |
|
522 iBubbleScaler->ScaleBitmapL( |
|
523 iCurrentBitmap, |
|
524 TSize(iBubbleGridCellWidth, iBubbleGridCellHeight)); |
|
525 } |
|
526 |
|
527 //============================================================================= |
|
528 void CBubbleSelectionDialog::AddIconL() |
|
529 { |
|
530 LOG(KBubblePluginLogFile, "CBubbleSelectionGrid::AddIconL()"); |
|
531 // Create icon |
|
532 CGulIcon* icon = NULL; |
|
533 icon = CGulIcon::NewLC(); |
|
534 icon->SetBitmapsOwnedExternally (EFalse); |
|
535 |
|
536 // Set bitmap to icon and append icon to icon array |
|
537 icon->SetBitmap (iCurrentBitmap); |
|
538 iCurrentBitmap = NULL; |
|
539 icon->SetMask(iCurrentMask); |
|
540 iCurrentMask = NULL; |
|
541 iIconArray->AppendL(icon); |
|
542 |
|
543 CleanupStack::Pop(); // icon |
|
544 |
|
545 // Create grid item text |
|
546 TBuf<8> buf; |
|
547 buf.AppendNum (iCurrentIcon); |
|
548 buf.Append(_L("\t1")); |
|
549 iTextArray->AppendL (buf); |
|
550 |
|
551 // Increase current icon index |
|
552 iCurrentIcon++; |
|
553 |
|
554 // Load next icon |
|
555 // one step begins. |
|
556 if (iProgressDialog && (iCurrentIcon % KProgressInterval) == 0) |
|
557 { |
|
558 iProgressDialog->GetProgressInfoL()->IncrementAndDraw (KProgressInterval); |
|
559 } |
|
560 if (iCurrentIcon < iBubbleList.Count()) |
|
561 { |
|
562 |
|
563 LoadBitmapsL(); |
|
564 } |
|
565 else |
|
566 { |
|
567 |
|
568 // Externalize loaded icons |
|
569 TRAPD(err, |
|
570 ExternalizeIconArrayL(); |
|
571 ); |
|
572 if (err) |
|
573 { |
|
574 // if error delete externalization file |
|
575 BaflUtils::DeleteFile( |
|
576 ControlEnv()->FsSession(), |
|
577 KBubbleExternalizeFile() |
|
578 ); |
|
579 } |
|
580 // dismiss progress dialog |
|
581 if (iProgressDialog) |
|
582 { |
|
583 iProgressDialog->ProcessFinishedL(); |
|
584 } |
|
585 |
|
586 SetBusy(EFalse); |
|
587 |
|
588 // Report that the grid is ready |
|
589 ReportEventL(MCoeControlObserver::EEventStateChanged); |
|
590 } |
|
591 } |
|
592 |
|
593 |
|
594 //============================================================================= |
|
595 void CBubbleSelectionDialog::BubbleScalerOperationReadyL(TInt aError) |
|
596 { |
|
597 if (aError == KErrNone) |
|
598 { |
|
599 |
|
600 switch (iState) |
|
601 { |
|
602 case EScalingBitmap: |
|
603 { |
|
604 // Scale the mask bitmap |
|
605 iState = EScalingMask; |
|
606 iBubbleScaler->ScaleBitmapL( |
|
607 iCurrentMask, |
|
608 TSize(iBubbleGridCellWidth, iBubbleGridCellHeight)); |
|
609 break; |
|
610 } |
|
611 case EScalingMask: |
|
612 { |
|
613 iState = EIdle; |
|
614 // Add icon to grid |
|
615 AddIconL(); |
|
616 break; |
|
617 } |
|
618 default: |
|
619 { |
|
620 break; |
|
621 } |
|
622 } |
|
623 } |
|
624 else |
|
625 { |
|
626 User::Leave(KSIEEInternal); |
|
627 } |
|
628 } |
|
629 |
|
630 //============================================================================= |
|
631 void CBubbleSelectionDialog::DialogDismissedL( TInt aButtonId ) |
|
632 { |
|
633 LOGFMT(KBubblePluginLogFile, "CBubbleSelectionGrid::DialogDismissedL(%d)", aButtonId); |
|
634 |
|
635 CAknGrid* grid = (CAknGrid*)ControlOrNull(EBubbleSelectionGrid); |
|
636 |
|
637 if( aButtonId == EAknSoftkeyCancel ) |
|
638 { |
|
639 // Cancel the on-going image decoding |
|
640 iBubbleScaler->Cancel(); |
|
641 |
|
642 // grid->HandleItemAdditionL(); |
|
643 |
|
644 // Report cancel request |
|
645 ReportEventL(MCoeControlObserver::EEventRequestCancel); |
|
646 } |
|
647 |
|
648 } |
|
649 |
|
650 //============================================================================= |
|
651 void CBubbleSelectionDialog::BubbleFilenameL(TDes& aFilename, TInt& aIndex) |
|
652 { |
|
653 CAknGrid* grid = (CAknGrid*)ControlOrNull(EBubbleSelectionGrid); |
|
654 |
|
655 // Get MBM file and icon index of the selected clip-art |
|
656 aFilename = iBubbleList[grid->CurrentItemIndex()].iFilename; |
|
657 aIndex = iBubbleList[grid->CurrentItemIndex()].iIndex; |
|
658 } |
|
659 |
|
660 //============================================================================= |
|
661 void CBubbleSelectionDialog::SetupGrid () |
|
662 { |
|
663 |
|
664 CAknGrid* grid = (CAknGrid*)ControlOrNull(EBubbleSelectionGrid); |
|
665 |
|
666 LOG(KBubblePluginLogFile, "CBubbleSelectionGrid::SetupGrid()"); |
|
667 |
|
668 // Setup text foreground and background colors to default |
|
669 AknListBoxLayouts::SetupStandardGrid (*grid); |
|
670 |
|
671 // Get local copies of data we will need |
|
672 CFormattedCellListBoxItemDrawer * itemDrawer = grid->ItemDrawer(); |
|
673 |
|
674 TInt cell_w = grid->ColumnWidth(); |
|
675 TInt cell_h = grid->ItemHeight(); |
|
676 |
|
677 // Set up graphics sub-cells |
|
678 AknListBoxLayouts::SetupGridFormGfxCell ( |
|
679 *grid, // the grid |
|
680 itemDrawer, // the grid's drawer |
|
681 0, // index of the graphic within item strings |
|
682 0, // left position |
|
683 0, // top position |
|
684 0, // right - unused |
|
685 0, // bottom - unused |
|
686 cell_w, // width of graphic |
|
687 cell_h, // height of graphic |
|
688 TPoint (0, 0), // start position |
|
689 TPoint (cell_w, cell_h) // end position |
|
690 ); |
|
691 |
|
692 } |
|
693 |
|
694 //============================================================================= |
|
695 void CBubbleSelectionDialog::InternalizeIconArrayL() |
|
696 { |
|
697 LOG(KBubblePluginLogFile, "CBubbleSelectionGrid::InternalizeIconArrayL()"); |
|
698 |
|
699 // Internalize Bubble icons |
|
700 RFileReadStream stream; |
|
701 |
|
702 User::LeaveIfError ( |
|
703 stream.Open ( |
|
704 ControlEnv()->FsSession(), |
|
705 KBubbleExternalizeFile(), |
|
706 EFileRead | EFileShareReadersOnly |
|
707 )); |
|
708 stream.PushL(); |
|
709 |
|
710 CGulIcon* icon = NULL; |
|
711 CFbsBitmap* bitmap = NULL; |
|
712 |
|
713 TInt count = stream.ReadInt32L(); |
|
714 for ( TInt i=0; i < count; i++ ) |
|
715 { |
|
716 icon = CGulIcon::NewLC(); |
|
717 icon->SetBitmapsOwnedExternally (EFalse); |
|
718 |
|
719 // Text index |
|
720 TInt len = stream.ReadInt32L(); |
|
721 HBufC* iconText = HBufC::NewLC(len); |
|
722 TPtr iconTextPtr = iconText->Des(); |
|
723 stream >> iconTextPtr; |
|
724 |
|
725 iTextArray->AppendL(iconTextPtr); |
|
726 |
|
727 CleanupStack::PopAndDestroy(); // iconText |
|
728 |
|
729 // Bitmap Data |
|
730 |
|
731 bitmap = new(ELeave) CFbsBitmap; |
|
732 CleanupStack::PushL(bitmap); |
|
733 |
|
734 stream >> *bitmap; |
|
735 |
|
736 // Save data |
|
737 //TBuf<20> name; |
|
738 //name.Format(_L("bitmap%d.mbm"), i); |
|
739 //bitmap->Save(name); |
|
740 |
|
741 // Set bitmap to icon - Ownership is transfered |
|
742 icon->SetBitmap (bitmap); |
|
743 |
|
744 CleanupStack::Pop(); |
|
745 |
|
746 bitmap = new(ELeave) CFbsBitmap; |
|
747 CleanupStack::PushL(bitmap); |
|
748 |
|
749 stream >> *bitmap; |
|
750 |
|
751 //TBuf<20> name2; |
|
752 //name2.Format(_L("mask%d.mbm"), i); |
|
753 //bitmap->Save(name2); |
|
754 |
|
755 // Set bitmap to icon - Ownership transfers |
|
756 icon->SetMask(bitmap); |
|
757 |
|
758 CleanupStack::Pop(); |
|
759 bitmap = NULL; |
|
760 |
|
761 // Set icon to icon array |
|
762 iIconArray->AppendL(icon); |
|
763 |
|
764 CleanupStack::Pop(); // icon |
|
765 icon = NULL; |
|
766 |
|
767 } |
|
768 |
|
769 CleanupStack::PopAndDestroy(); // stream |
|
770 |
|
771 } |
|
772 |
|
773 |
|
774 //============================================================================= |
|
775 void CBubbleSelectionDialog::ExternalizeIconArrayL() |
|
776 { |
|
777 LOG(KBubblePluginLogFile, "CBubbleSelectionGrid::ExternalizeIconArrayL()"); |
|
778 |
|
779 RFileWriteStream stream; |
|
780 |
|
781 User::LeaveIfError ( |
|
782 stream.Replace ( |
|
783 ControlEnv()->FsSession(), |
|
784 KBubbleExternalizeFile(), |
|
785 EFileWrite |
|
786 )); |
|
787 stream.PushL(); |
|
788 |
|
789 // Externalize the contents of Bubble |
|
790 stream.WriteInt32L( iTextArray->Count() ); |
|
791 |
|
792 for ( TInt i=0; i< iTextArray->Count(); i++ ) |
|
793 { |
|
794 // Text index |
|
795 TPtrC text = (*iTextArray)[i]; |
|
796 stream.WriteInt32L(text.Length()); |
|
797 stream << text; |
|
798 |
|
799 // Bitmap |
|
800 CFbsBitmap* bitmap = (*iIconArray)[i]->Bitmap(); |
|
801 stream << *bitmap; |
|
802 bitmap = NULL; |
|
803 |
|
804 // Mask |
|
805 bitmap = (*iIconArray)[i]->Mask(); |
|
806 stream << *bitmap; |
|
807 bitmap = NULL; |
|
808 |
|
809 } |
|
810 |
|
811 // Write extra before commiting |
|
812 stream.WriteInt32L( 0 ); |
|
813 |
|
814 stream.CommitL(); |
|
815 |
|
816 CleanupStack::PopAndDestroy(); // stream |
|
817 |
|
818 } |
|
819 |
|
820 //============================================================================= |
|
821 void CBubbleSelectionDialog::SetBusy(TBool aBusy) |
|
822 { |
|
823 iBusy = aBusy; |
|
824 } |
|
825 |
|
826 //============================================================================= |
|
827 SEikControlInfo CBubbleSelectionDialog::CreateCustomControlL(TInt aControlType) |
|
828 { |
|
829 |
|
830 SEikControlInfo controlInfo; |
|
831 controlInfo.iControl = NULL; |
|
832 controlInfo.iTrailerTextId = 0; |
|
833 controlInfo.iFlags = 0; |
|
834 |
|
835 switch (aControlType) |
|
836 { |
|
837 |
|
838 case EBubbleCustomControlType: |
|
839 { |
|
840 controlInfo.iControl = new(ELeave) CBubbleSelectionGrid; |
|
841 break; |
|
842 } |
|
843 |
|
844 default: |
|
845 { |
|
846 break; |
|
847 } |
|
848 |
|
849 } |
|
850 |
|
851 return controlInfo; |
|
852 } |
|
853 |
|
854 void CBubbleSelectionDialog::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aEventType) |
|
855 { |
|
856 if ( aEventType == EEventItemDoubleClicked ) |
|
857 { |
|
858 iDoubleClick = ETrue; |
|
859 } |
|
860 // also single click is enough for selecting item |
|
861 else if ( aEventType == EEventItemClicked ) |
|
862 { |
|
863 iClick = ETrue; |
|
864 } |
|
865 } |
|
866 |
|
867 void CBubbleSelectionDialog::HandleDialogPageEventL(TInt /*aEventId*/) |
|
868 { |
|
869 if( iDoubleClick || iClick ) |
|
870 { |
|
871 TryExitL( EAknSoftkeyOk ); |
|
872 } |
|
873 } |
|
874 |
|
875 //-------------------------- Handle resource change |
|
876 void CBubbleSelectionDialog::HandleResourceChange(TInt aType) |
|
877 { |
|
878 CEikDialog::HandleResourceChange(aType); |
|
879 if( aType == KEikDynamicLayoutVariantSwitch ) |
|
880 { |
|
881 CAknGrid* grid = (CAknGrid*)ControlOrNull(EBubbleSelectionGrid); |
|
882 if ( grid ) |
|
883 { |
|
884 TRect clientRect = Rect(); |
|
885 grid->SetRect(clientRect); |
|
886 TInt xOffset( 0 ); |
|
887 TAknWindowLineLayout lineLayout; |
|
888 TAknLayoutRect layoutRect; |
|
889 TInt variety( 0 ); |
|
890 TRect scrollPaneRect; |
|
891 if( Layout_Meta_Data::IsLandscapeOrientation() ) |
|
892 { |
|
893 variety = 1; |
|
894 } |
|
895 |
|
896 if( AknLayoutUtils::LayoutMirrored() ) |
|
897 { |
|
898 // scroll_pane_cp029 |
|
899 lineLayout = AknLayoutScalable_Apps::scroll_pane_cp029( variety ).LayoutLine(); |
|
900 layoutRect.LayoutRect( Rect(), lineLayout ); |
|
901 scrollPaneRect = layoutRect.Rect(); |
|
902 xOffset = scrollPaneRect.Width() + 5; |
|
903 } |
|
904 TInt rows = clientRect.Height() / iBubbleGridCellHeight; |
|
905 TInt columns = (clientRect.Width() - scrollPaneRect.Width()) / iBubbleGridCellWidth; |
|
906 |
|
907 // Set grid layout |
|
908 |
|
909 grid->SetLayoutL ( |
|
910 EFalse, |
|
911 ETrue, |
|
912 ETrue, |
|
913 columns, |
|
914 rows, |
|
915 TSize(iBubbleGridCellWidth, iBubbleGridCellHeight) |
|
916 ); |
|
917 |
|
918 } |
|
919 } |
|
920 } |
|
921 |
|
922 // End of File |
|
923 |