listbox problem

Login to reply to this topic.
Tue, 2005-11-22 01:26
Joined: 2005-02-16
Forum posts: 70
Hi,
I have a strange problem with my listbox... I have a function createList which does everything for the creation of the list. If I call this function in the ConstructL function of my container class, it works fine. But if I call it anywhere else it doesn't work, it compiles, but then exits at run time (breaks in debug mode of visual studio).

I want to call this function from the AppUi class as I want the list to be displayed after a key press. Is this possible?

Thanks,
Miranda

Tue, 2005-11-22 08:52
Joined: 2005-11-20
Forum posts: 1242
Re: listbox problem
With "creation of the list" you mean filling the listbox i.e. populating it with items? If yes: A listbox is very dynamic and allows filling and/or changing of items at almost any time. (If it were not, the usefulness of the listbox would be severely restricted.) Therefore your problem really sounds strange to me.

Maybe you show the relevant parts of the code here so it will be possible to see more details? Do you know *where* it leaves?

René Brunner

Wed, 2005-11-23 00:12
Joined: 2005-02-16
Forum posts: 70
Re: listbox problem
Hi,
The list box I am creating is a list of the images or sounds in the users gallery.

here is the code that works:

ConstructL
Code:
void CsmilContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();

     phase = 0;
     iSplashImage = iEikonEnv->CreateBitmapL(KMultiBitmapFilename, EMbmSmilimagesSplash);

     createList();

    SetRect(aRect);
    ActivateL();
    }

createList
Code:
void CsmilContainer::createList()
{
RDebug::Print(_L("createList"));
User::LeaveIfError(aFs.Connect());
User::LeaveIfError(aFs.GetDir(KDirSounds, KEntryAttNormal, ESortByName, dir));

if ( iList )
{
delete iList;
iList = NULL;
}

// listbox instance
iList = new (ELeave) CAknSingleStyleListBox();

iList->SetContainerWindowL(*this);
iList->ConstructL(this,EAknListBoxSelectionList);

//iList->CreateScrollBarFrameL(ETrue);
//iList->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto);

iList->CreateScrollBarFrameL(ETrue);
iList->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);

iList->Model()->SetOwnershipType(ELbmOwnsItemArray);
iList->ActivateL();

//Fill list box with the data
CDesCArray *itemList = new (ELeave) CDesCArrayFlat(8);

if(!dir)
        return;
                       
    for (TInt i=0;i<dir->Count();i++)
        {
        TFileName filename = NULL;
        if(iSizeDate==1)
            {
            // Show file size
            filename.Format(KStringSize,i+1,&(*dir)[i].iName,(*dir)[i].iSize);
            }

        else
            {
            // Fix the date and time string of last modification
            TBuf<30> dateString;
            _LIT(KDateString,"%D%M%Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B");
            (*dir)[i].iModified.FormatL(dateString,KDateString);

            // Show date modified
            filename.Format(KStringDate,i+1,&(*dir)[i].iName,&dateString);
            }

        itemList->AppendL(filename);
        }

// set items and ownership
iList->Model()->SetItemTextArray(itemList);
iList->Model()->SetOwnershipType(ELbmOwnsItemArray);

iList->CreateScrollBarFrameL(ETrue);
iList->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto);

iList->HandleItemAdditionL();

    iList->SetCurrentItemIndex(0);
iList->SetFocus(ETrue);

iCtrlArray.Append( iList );

iList->DrawNow();

iList->SetListBoxObserver(this);
iList->SetObserver(this);

aFs.Close();
}
* I usually have this divided into a number of smaller functions but for testing I just lumped it all together

So what I want to do is call createList from AppUi like this:

Code:
TKeyResponse CsmilAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
    {

if (aType == EEventKey) {
switch (aKeyEvent.iScanCode)
{
case (57):
{
Exit();
break;
}
case EStdKeyDevice3:
{
RDebug::Print(_L("ok key pressed"));
iAppContainer->phase = 1;
iAppContainer->DrawNow();
iAppContainer->createList();

return EKeyWasConsumed;
}
}
}

    return EKeyWasNotConsumed;
    }

it appears to leave at the sizeChanged function, but I recall when I was first having listbox problems I got a similar leave that had nothing to do with setExtent...

Any ideas?
Wed, 2005-11-23 09:06
Joined: 2005-11-20
Forum posts: 1242
Re: listbox problem
I have only one idea what could be tried: I would try to separate more clearly code that "builds" and "configures" the listbox from code that "uses" it.

Concretely: Move the following lines that configure the listbox:
Code:
iList->SetListBoxObserver(this);
iList->SetObserver(this);
further up and place them before
Code:
iList->ActivateL();

Delete the line
Code:
iList->Model()->SetOwnershipType(ELbmOwnsItemArray);
just before the call to ActivateL which is a duplicate (you do this again later) and maybe also "too early" (the "ownItemArray" is not yet set when you call it first).

Likewise, in HandleKeyEventL, call createList first, only then call the DrawNow method.

The general idea behind my proposals is the following: Maybe Symbian internally gets confused if one starts to "use" a listbox, e.g. set items and asks them to be drawn, when the listbox is only partially configured or if certain aspects (like observers) of the listbox are changed while some background task is still busy drawing the new items.

But anyway, just my guesses  Smiley

René Brunner

Thu, 2005-11-24 00:54
Joined: 2005-02-16
Forum posts: 70
Re: listbox problem
Thanks for the reply, but unfortunately that didn't help  Sad

Any other ideas?
Thu, 2005-11-24 07:34
Joined: 2005-11-20
Forum posts: 1242
Re: listbox problem
Unfortunately not, except to experiment with the position of this line in the code:
Code:
iCtrlArray.Append( iList );

E.g. move it up in the procedure together with two lines that set the observers. Who knows how early there will be calls to the procedures of your container handling the different objects, and maybe a chance for confusion if the listbox appears too late in the list.

But if that does not help either, I have to capitulate...

René Brunner

Thu, 2005-11-24 08:08
Joined: 2005-11-20
Forum posts: 1242
Re: listbox problem
Thinking again about the whole thing: Maybe the framework is not flexible enough to allow creation of controls later on, "on the fly". Maybe all controls have to be created in the ConstructL method, if you try to create and add them later maybe things get wrong indeed.

Maybe you will have to separate creating the listbox and filling it. Create it in the ConstructL method, what will work according to your report, but leave it empty. Later on, after the keypress, fill it.

Isn't there a way to make (existing) controls visible and invisible so that you could create the listbox, but leave it invisible until the keypress and make it visible only after it is filled? Check the method CCoeControl::MakeVisible!

René Brunner

  • Login to reply to this topic.