00001
00002
00003
00004
00005
00006 #include "SMSExampleMarkableListContainer.h"
00007 #include "SmsExamplePanics.pan"
00008
00009 #include <akniconarray.h>
00010 #include <aknlists.h>
00011 #include <barsread.h>
00012 #include <e32def.h>
00013 #include <SMSExample.mbg>
00014 #include <smsexample.rsg>
00015 #include <stringloader.h>
00016 #include <uikon.hrh>
00017
00018 #ifdef __UI_FRAMEWORKS_V2__
00019 #include <GULICON.H>
00020 #include <AknIconUtils.h>
00021 #include <FBS.H>
00022 #endif
00023
00024 #define KListPosition TPoint(0,0)
00025
00026 const TInt KAknExListAddItemBufLength(512);
00027 const TInt KNumberOfIcons(2);
00028 const TInt KBeginIdx=0;
00029 const TInt KEndIdx=2;
00030
00031 _LIT(KIconSelectedText,"1\t");
00032 _LIT(KIconNotSelectedText,"0\t");
00033
00034
00035
00036
00037
00038
00039
00040 void CMarkableListContainer::ConstructL(const TRect& aRect)
00041 {
00042 CreateWindowL();
00043
00044
00045 CreateListL();
00046
00047 iAddress = 0;
00048 iMessage = 0;
00049
00050
00051 SetupListIconsL();
00052
00053
00054 SetupScrollBarsL();
00055
00056 iSelectedIds = new (ELeave) RArray<TMsvId>;
00057
00058 SetRect(aRect);
00059 ActivateL();
00060 }
00061
00062
00063
00064
00065
00066
00067 void CMarkableListContainer::CreateListL()
00068 {
00069
00070 iSmsListBox = new (ELeave) CAknDoubleGraphicStyleListBox();
00071 iSmsListBox->SetContainerWindowL(*this);
00072 iSmsListBox->SetListBoxObserver(this);
00073
00074
00075 TResourceReader reader;
00076 CEikonEnv::Static()->CreateResourceReaderLC(reader,
00077 R_SMSEXAMPLE_MARKABLE_LISTBOX);
00078 iSmsListBox->ConstructFromResourceL(reader);
00079 CleanupStack::PopAndDestroy();
00080 }
00081
00082
00083
00084
00085
00086
00087 void CMarkableListContainer::SetupScrollBarsL()
00088 {
00089 iSmsListBox->CreateScrollBarFrameL(ETrue);
00090 iSmsListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
00091 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
00092 }
00093
00094
00095
00096
00097
00098
00099
00100 void CMarkableListContainer::SetArraysL(CDesCArrayFlat* aAddress,
00101 CDesCArrayFlat* aMessage )
00102 {
00103 iAddress = aAddress;
00104 iMessage = aMessage;
00105
00106 for (TInt i = 0; i < aAddress->Count(); i++)
00107 {
00108 AddItemL( (*aAddress)[i], (*aMessage)[i] );
00109 }
00110 }
00111
00112
00113
00114
00115
00116
00117 void CMarkableListContainer::MarkAllL(TBool aSelectionMode)
00118 {
00119 if (iSmsListBox)
00120 {
00121
00122 CTextListBoxModel* model = iSmsListBox->Model();
00123 model->SetOwnershipType (ELbmOwnsItemArray);
00124 CDesCArray* smsArray = STATIC_CAST(CDesCArray*,model->ItemTextArray());
00125
00126
00127 for (TInt i = 0; i < smsArray->Count(); i++)
00128 {
00129 TBuf <KAknExListAddItemBufLength> changeItem( (*smsArray)[i] );
00130
00131
00132 if ( aSelectionMode )
00133 {
00134
00135 changeItem.Replace(KBeginIdx, KEndIdx, KIconSelectedText);
00136 }
00137 else
00138 {
00139
00140 changeItem.Replace(KBeginIdx, KEndIdx, KIconNotSelectedText);
00141 }
00142
00143
00144 smsArray->Delete(i);
00145
00146 smsArray->InsertL(i, changeItem);
00147 }
00148
00149
00150 if ( aSelectionMode )
00151 {
00152
00153 SelectItem( 0, ETrue );
00154 }
00155 else
00156 {
00157
00158 DeSelectItem( 0, ETrue );
00159 }
00160
00161 iSmsListBox->HandleItemAdditionL();
00162 }
00163 }
00164
00165
00166
00167
00168
00169
00170
00171 void CMarkableListContainer::MarkOrUnMarkL()
00172 {
00173 if (iSmsListBox)
00174 {
00175
00176 TInt itemIndex = iSmsListBox->CurrentItemIndex();
00177
00178 if (itemIndex >= 0)
00179 {
00180
00181 CTextListBoxModel* model = iSmsListBox->Model();
00182 model->SetOwnershipType (ELbmOwnsItemArray);
00183 CDesCArray* smsArray = STATIC_CAST(CDesCArray*,
00184 model->ItemTextArray());
00185
00186 if( smsArray->Count() <= itemIndex )
00187 {
00188 User::Leave(KErrTooBig);
00189 }
00190
00191 TBuf <KAknExListAddItemBufLength> changeItem(
00192 (*smsArray)[itemIndex]
00193 );
00194
00195
00196 if ( changeItem.Left(KEndIdx) == KIconNotSelectedText )
00197 {
00198 changeItem.Replace(KBeginIdx, KEndIdx, KIconSelectedText);
00199
00200 SelectItem( itemIndex, EFalse );
00201 }
00202 else if ( changeItem.Left(KEndIdx) == KIconSelectedText )
00203 {
00204 changeItem.Replace(KBeginIdx, KEndIdx, KIconNotSelectedText);
00205
00206 DeSelectItem( itemIndex, EFalse );
00207 }
00208
00209 smsArray->Delete(itemIndex);
00210 smsArray->InsertL(itemIndex, changeItem);
00211
00212 iSmsListBox->HandleItemAdditionL();
00213 }
00214 }
00215 }
00216
00217
00218
00219
00220
00221
00222 void CMarkableListContainer::SelectItem(TInt aIndex, TBool aSelectAll)
00223 {
00224
00225 if ( aSelectAll )
00226 {
00227 iSelectedIds->Reset();
00228 for (TInt i = 0; i < iIdArray->Count(); i++)
00229 {
00230 iSelectedIds->Append( (*iIdArray)[i] );
00231 }
00232 }
00233 else if( iIdArray->Count() > aIndex )
00234 {
00235 TMsvId id = (*iIdArray)[aIndex];
00236
00237 if ( KErrNotFound == iSelectedIds->Find( id ) )
00238 {
00239 iSelectedIds->Append( id );
00240 }
00241 }
00242 else
00243 {
00244 Panic(EGuiGeneral);
00245 }
00246
00247 }
00248
00249
00250
00251
00252
00253
00254 void CMarkableListContainer::DeSelectItem(TInt aIndex, TBool aDeselectAll)
00255 {
00256 if ( aDeselectAll )
00257 {
00258 iSelectedIds->Reset();
00259 }
00260 else if( iIdArray->Count() > aIndex )
00261 {
00262 TInt index = iSelectedIds->Find( (*iIdArray)[aIndex] );
00263
00264 if ( index != KErrNotFound )
00265 {
00266 iSelectedIds->Remove( index );
00267 }
00268 }
00269 else
00270 {
00271 Panic(EGuiGeneral);
00272 }
00273
00274 }
00275
00276
00277
00278
00279
00280
00281 void CMarkableListContainer::SetupListIconsL()
00282 {
00283
00284 HBufC* iconFilename = NULL;
00285 iconFilename = StringLoader::LoadLC(R_ICON_FILE_NAME);
00286
00287 CArrayPtr<CGulIcon>* icons = new(ELeave) CAknIconArray(KNumberOfIcons);
00288 CleanupStack::PushL(icons);
00289
00290 #ifdef __UI_FRAMEWORKS_V2__ // NOT IN FP3, should executed also there
00291
00292 CFbsBitmap* icon = NULL;
00293 CFbsBitmap* iconMask = NULL;
00294 CFbsBitmap* icon2 = NULL;
00295 CFbsBitmap* iconMask2 = NULL;
00296
00297 AknIconUtils::CreateIconLC(icon, iconMask, *iconFilename,
00298 EMbmSmsexampleTock,EMbmSmsexampleTock_mask);
00299
00300
00301 CGulIcon* guiIcon = CGulIcon::NewL( icon, iconMask );
00302 CleanupStack::PushL(guiIcon);
00303 icons->AppendL( guiIcon );
00304 CleanupStack::Pop(guiIcon);
00305 CleanupStack::Pop(2);
00306
00307 AknIconUtils::CreateIconLC(icon2, iconMask2, *iconFilename,
00308 EMbmSmsexampleTick,EMbmSmsexampleTick_mask);
00309
00310 CGulIcon* guiIcon2 = CGulIcon::NewL( icon2, iconMask2 );
00311 CleanupStack::PushL(guiIcon2);
00312 icons->AppendL( guiIcon2 );
00313 CleanupStack::Pop(guiIcon2);
00314 CleanupStack::Pop(2);
00315 #else
00316 CGulIcon* icon = iEikonEnv->CreateIconL(*iconFilename,
00317 EMbmSmsexampleTock,
00318 EMbmSmsexampleTock_mask);
00319 CleanupStack::PushL(icon);
00320 icons->AppendL(icon);
00321 CleanupStack::Pop(icon);
00322 icon =iEikonEnv->CreateIconL(*iconFilename, EMbmSmsexampleTick,
00323 EMbmSmsexampleTick_mask);
00324 CleanupStack::PushL(icon);
00325 icons->AppendL(icon);
00326 CleanupStack::Pop(icon);
00327 #endif
00328
00329 CleanupStack::Pop(icons);
00330
00331 CleanupStack::PopAndDestroy(iconFilename);
00332
00333
00334 iSmsListBox->ItemDrawer()->ColumnData()->SetIconArray(icons);
00335 }
00336
00337
00338
00339
00340
00341
00342 CMarkableListContainer* CMarkableListContainer::NewL(const TRect& aRect)
00343 {
00344 CMarkableListContainer* self = CMarkableListContainer::NewLC(aRect);
00345 CleanupStack::Pop(self);
00346 return self;
00347 }
00348
00349
00350
00351
00352
00353
00354 CMarkableListContainer* CMarkableListContainer::NewLC(const TRect& aRect)
00355 {
00356 CMarkableListContainer* self = new (ELeave) CMarkableListContainer;
00357 CleanupStack::PushL(self);
00358 self->ConstructL(aRect);
00359 return self;
00360 }
00361
00362
00363
00364
00365
00366
00367 CMarkableListContainer::~CMarkableListContainer()
00368 {
00369 Cleanup();
00370 }
00371
00372 void CMarkableListContainer::Cleanup()
00373 {
00374 iIdArray->Reset();
00375 delete iIdArray;
00376 iIdArray = 0;
00377
00378 iAddress->Reset();
00379 delete iAddress;
00380 iAddress = 0;
00381
00382 iMessage->Reset();
00383 delete iMessage;
00384 iMessage = 0;
00385
00386 delete iSmsListBox;
00387 iSmsListBox = 0;
00388 }
00389
00390
00391
00392
00393
00394 void CMarkableListContainer::SizeChanged()
00395 {
00396 iSmsListBox->SetExtent (KListPosition, iSmsListBox->MinimumSize());
00397 }
00398
00399
00400
00401
00402
00403
00404 TInt CMarkableListContainer::CountComponentControls() const
00405 {
00406 return 1;
00407 }
00408
00409
00410
00411
00412
00413
00414 CCoeControl* CMarkableListContainer::ComponentControl(TInt aIndex) const
00415 {
00416 switch (aIndex)
00417 {
00418 case 0:
00419 return iSmsListBox;
00420 default:
00421 return NULL;
00422 }
00423 }
00424
00425
00426
00427
00428
00429
00430 void CMarkableListContainer::Draw(const TRect& aRect) const
00431 {
00432 CWindowGc& gc = SystemGc();
00433 gc.Clear(aRect);
00434 }
00435
00436
00437
00438
00439
00440
00441
00442 TKeyResponse CMarkableListContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,
00443 TEventCode aType)
00444 {
00445 if (iSmsListBox)
00446 return iSmsListBox->OfferKeyEventL (aKeyEvent, aType);
00447 else
00448 return EKeyWasNotConsumed;
00449 }
00450
00451
00452
00453
00454 void CMarkableListContainer::SetIdArray(RArray<TMsvId>* aArray)
00455 {
00456 iIdArray = aArray;
00457 }
00458
00459
00460
00461
00462
00463
00464 RArray<TMsvId>* CMarkableListContainer::GetSelectedItems()
00465 {
00466 return iSelectedIds;
00467 }
00468
00469
00470
00471
00472
00473
00474
00475
00476 void CMarkableListContainer::HandleListBoxEventL(CEikListBox* ,
00477 TListBoxEvent aListBoxEvent)
00478 {
00479
00480 if ((aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed) ||
00481 (aListBoxEvent == MEikListBoxObserver::EEventItemDoubleClicked))
00482 {
00483 MarkOrUnMarkL();
00484 }
00485 }
00486
00487
00488
00489
00490
00491
00492 void CMarkableListContainer::AddItemL(const TDesC& aFirstLabel,
00493 const TDesC& aSecondLabel)
00494 {
00495 CTextListBoxModel* model = iSmsListBox->Model();
00496 model->SetOwnershipType (ELbmOwnsItemArray);
00497 CDesCArray* smsArray = static_cast <CDesCArray*> (model->ItemTextArray());
00498
00499 TBuf <KAknExListAddItemBufLength> addedItem( KBeginIdx );
00500
00501
00502
00503
00504
00505 _LIT( KBeginning, "0\t");
00506 addedItem.Append( KBeginning );
00507 addedItem.Append( aFirstLabel );
00508
00509
00510 _LIT( KEnd, "\t");
00511 addedItem.Append( KEnd );
00512 addedItem.Append( aSecondLabel );
00513 addedItem.Append( KEnd );
00514
00515
00516 smsArray->AppendL( addedItem );
00517
00518 iSmsListBox->HandleItemAdditionL();
00519 }
00520
00521