Getting images from different MBM file in ListBox
hi all,
I am building a new application with listbox loading images from different mbm files. ie; each image in listbox item should be obtained from different mbm files. We tried loading image from two mbm files , but each time any one of the mbm files will be loaded. Is it practically possible??..If yes please guide us...The part where we tried doing this is pasted below.
CDesCArrayFlat* strings = new (ELeave) CDesCArrayFlat(8);
strings->AppendL(_L("c:\\System\\Apps\\Demo1\\test.mbm"));
strings->AppendL(_L("c:\\System\\Apps\\ChristmasSongs\\test.mbm"));
// Creates gul icon.
CArrayPtr<CGulIcon>* icons = new( ELeave ) CAknIconArray(5 );
icons->AppendL( iEikonEnv->CreateIconL((*strings)[1] ,0,1));
//CleanupStack::PushL( icons );
iListBox->ItemDrawer()->ColumnData()->SetIconArray( icons);
// CleanupStack::Pop(icons);
icons->AppendL( iEikonEnv->CreateIconL((*strings)[0] ,0,1));
//CleanupStack::PushL( icons );
iListBox->ItemDrawer()->ColumnData()->SetIconArray( icons );
icons = NULL;
delete icons;
Now we get only the first mbm file. We expect a speedy reply...
Thanks in advance ...
Re: Getting images from different MBM file in ListBox
what happens with the second one ? any errors shown ?
Basically there should not be any problems on loading icons from multiple MBM files.
yucca
Re: Getting images from different MBM file in ListBox
Hi yucca,,
Thanks for the speedy reply. We still culdn't figure out the problem . Is there any problm related with cleanupstack ?? No errors are shown .But we r getting image from a single mbm file for the entire listbox items. Image from the second mbm file is not displayed. Is there any issue in calling iListBox->ItemDrawer()->ColumnData()->SetIconArray( icons );
twice. Any kind of reply from ur part will be appreciated.
Thanks,
AnoopD.
Re: Getting images from different MBM file in ListBox
ok, didn't look the code too closely. You could just try to use one PushL, right after constructing the icons array, then just pop it (without destroying it) when you set it to your listbox.
also have you tried using 0 index for first icon and 1 for the second..
yucca
Re: Getting images from different MBM file in ListBox
Yucca,,
We made the modifications as per ur suggestion. But still the code is not working .Can u give us a sample code or can u go through this code and give necessary suggestions.
void CList4Container::ConstructL(const TRect& aRect)
{
CreateWindowL();
iListBox = new( ELeave ) CAknSingleLargeStyleListBox();//CAknDoubleStyle2ListBox()
iListBox->SetContainerWindowL( *this );
TResourceReader reader;
iEikonEnv->CreateResourceReaderLC(reader, R_LIST_LISTBOX);
iListBox->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy();
PopulateListBox();
// Creates scrollbar.
iListBox->CreateScrollBarFrameL( ETrue );
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
j=0;
CDesCArrayFlat* strings = new (ELeave) CDesCArrayFlat(8);
strings->AppendL(_L("c:\\System\\Apps\\Demo1\\test.mbm"));
strings->AppendL(_L("c:\\System\\Apps\\ChristmasSongs\\test.mbm"));
// Creates gul icon.
CArrayPtr<CGulIcon>* icons = new( ELeave ) CAknIconArray(5 );
CleanupStack::PushL(icons);
icons->AppendL( iEikonEnv->CreateIconL((*strings)[0] ,0,1));
icons->AppendL( iEikonEnv->CreateIconL((*strings)[1] ,0,1));
iListBox->ItemDrawer()->ColumnData()->SetIconArray( icons );
// SetGraphicIconL(iListBox);
CleanupStack::Pop();
iListBox->ActivateL();
DrawNow();
iListBox->SetFocus(ETrue, EDrawNow);
SetRect(aRect);
//SetSize(iListBox->MinimumSize());
ActivateL();
}
Thanks,
AnoopD
Re: Getting images from different MBM file in ListBox
how does your item (text) array look like ?
yucca
Re: Getting images from different MBM file in ListBox
Our Listbox is dynamically created by first reading the item text into a buffer and arranging it in order by appending the image number to it [0\t buffer \t1]. The code looks like this.
void CList4Container::PopulateListBox()
{
TBuf<256> KString1;
TBuf<256> KString2;
TBuf<256> readBuf1;
TBuf<256> readBuf2;
TBuf<256> mbmpath;
KString1 = _L("\t");
KString2 = _L("0");
RFs fileSession;
RFile file;
// TInt start=1;
TInt ret;
TInt len;
TInt len1;
// TBuf8<256> readBuf1;
iListItems = new (ELeave) CDesCArrayFlat(10);
int i=0;
_LIT(KMyfile,"pkglist.txt");
// _LIT(KFileSpec,"c:\\System\\Apps\\config.txt");
TFileName myfile;
myfile.Format(KMyfile,10);
CompleteWithAppPath(myfile);
/* Commented by <SWT2007> Aswathy on 2/15/2006 11:40:16 AM */
/* TParse parse;
parse.Set(CEikonEnv::Static()->EikAppUi()->Application()->AppFullName(), NULL, NULL);
TFileName myfile = parse.DriveAndPath();
myfile.Append(KMyfile);
*/
//_L("c:\\System\\Apps\\pkglist.txt")
fileSession.Connect();
TInt err=file.Open(fileSession,_L("c:\\System\\Apps\\pkglist.txt"),EFileStreamText|EFileRead|EFileShareAny);
if(err==KErrNone)
{
//pkg = new (ELeave) CDesCArrayFlat(10);
// strings = new (ELeave) CArrayFixFlat<TDesC>(8);
// strings = new (ELeave) CDesCArrayFlat(8);
TFileText tfile;
tfile.Set(file);
tfile.Seek(ESeekStart);//Seek to beginning
readBuf2.Append(KString2);//0
readBuf2.Append(KString1);//0\t
ret=tfile.Read(readBuf1);//data
// if mbm file in the name of readbuf1
_LIT(MbmPath,"c:\\System\\Apps\\");
mbmpath=MbmPath;
mbmpath.Append(readBuf1);
mbmpath.Append(_L("\\test.mbm"));
//TPtr16 ptr((TUint16)readBuf1.Ptr(), readBuf1.Size());
// TPtr8 ptr((TUint8*)readBuf1.Ptr(),readBuf1.Size());
readBuf2.Append(readBuf1);//readbuf1 0\t\label
readBuf2.Append(KString1);//0\t\label\t
//readBuf2.Append(KString2);
//readBuf2.Append(KString1);
//readBuf2.Append(KString2);
len=readBuf1.Length();
len1=readBuf2.Length();
// iListItems->AppendL(readBuf2);
while((ret!=KErrEof)&&(len!=0))
{
//ret=tfile.Read(readBuf1);
//len=readBuf1.Length();
TPtrC16 ptr=readBuf2.Right(len1);
iListItems->AppendL(readBuf2);
readBuf2.Delete(0,len1);
// strings->AppendL(mbmpath);
// pkg->InsertL(i,mbmpath);
readBuf2.Append(KString2);
readBuf2.Append(KString1);
ret=tfile.Read(readBuf1);
//TPtrC16 ptr1((TUint16)readBuf1.Ptr(), readBuf1.Size());
readBuf2.Append(readBuf1);
readBuf2.Append(KString1);
// readBuf2.Append(KString2);
//readBuf2.Append(KString1);
// readBuf2.Append(KString2);
len=readBuf1.Length();
len1=readBuf2.Length();
i++;
}
}
file.Close();
fileSession.Close();
iListBox->Model()->SetItemTextArray(iListItems);
// SetGraphicIconL(iListBox);
}
Hope u got an idea behind this scenario...
Waiting for u r replay
Re: Getting images from different MBM file in ListBox
I don't see where you set any other value than 0 for the icon index.
Just for the debug purposes could you just try setting two different strings there, for example
_LIT(KtxtFirstString ,"0\tfirst string");
_LIT(KtxtSecondString ,"1\tsecond string");
iListItems->Append(KtxtFirstString);
iListItems->Append(KtxtSecondString);
before the SetItemTextArray line.
yucca
Re: Getting images from different MBM file in ListBox
hi yucca..
Now its working fine ..Thanks for the help in time...am whole heartedly thanfull to you...Will look forward for u r help in future..
Byeee...