×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    12

    HandleListBoxEventL not being called when enter key pressed

    I'm using the Carbide v1.3.1 wizard to generate a S60 3rd Edition Application with UI Designer. I've selected it to have a List Box with Double 2 style. I then added an event handler for enterKeyPressed and added some dummy list box items. When I run the application in the emulator, I can see that OfferKeyEventL is being called and that it's calling the List Box's OfferKeyEventL, but HandleListBoxEventL is not being called. Any help would be appreciated since I've run out of ideas on how to track this down. Thanks in advance.

    Here's the .H
    Code:
    #ifndef LISTBOXTESTLISTBOX_H
    #define LISTBOXTESTLISTBOX_H
    #include <coecntrl.h>		
    #include <akniconutils.h>
    #include <gulicon.h>
    #include <eiklbo.h>
    
    class MEikCommandObserver;		
    class CAknDoubleLargeStyleListBox;
    class CEikTextListBox;
    
    class CTestLB : public CCoeControl,MEikListBoxObserver	{
    public:
    	CTestLB() {iListBox = NULL;}
    	void ConstructL(const TRect& aRect, const CCoeControl* aParent, MEikCommandObserver* aCommandObserver);
    	virtual ~CTestLB() {delete iListBox; iListBox = NULL; iListBoxEventDispatch.Close();}
    	TInt CountComponentControls() const {return (int) ELastControl;}
    	CCoeControl* ComponentControl(TInt aIndex) const {switch (aIndex) { case EListBox: return iListBox; } return NULL; }
    	TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
    	void HandleResourceChange(TInt aType);
    	static void AddListBoxItemL(CEikTextListBox* aListBox, const TDesC& aString);
    	static RArray< TInt >* GetSelectedListBoxItemsLC(CEikTextListBox* aListBox);
    	static void DeleteSelectedListBoxItemsL(CEikTextListBox* aListBox);
    	CAknDoubleLargeStyleListBox* ListBox() {return iListBox;}
    	static void CreateListBoxItemL(TDes& aBuffer, TInt aIconIndex, const TDesC& aMainText, const TDesC& aSecondaryText);
    	void AddListBoxResourceArrayItemL(TInt aResourceId, TInt aIconIndex);
    	void SetupListBoxIconsL();
    	static CGulIcon* LoadAndScaleIconL(const TDesC& aFileName, TInt aBitmapId, TInt aMaskId, TSize* aSize, TScaleMode aScaleMode);
    	TBool HandleMarkableListCommandL(TInt aCommand) {return EFalse;}
    	enum TControls {EListBox, ELastControl};
    	enum TListBoxImages {EListBoxListboxtestList_iconIndex = 0, EListBoxFirstUserImageIndex};
    
    protected: 
    	void SizeChanged() {CCoeControl::SizeChanged();	LayoutControls(); }
    	void HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent anEventType);
    	void HandleListBoxEnterKeyPressedL(CEikListBox* aListBox, TListBoxEvent anEventType) {}
    
    private:
    	void Draw(const TRect& aRect) const;
    	void InitializeControlsL();
    	void LayoutControls();
    	CCoeControl* iFocusControl;
    	MEikCommandObserver* iCommandObserver;
    	CAknDoubleLargeStyleListBox* iListBox;
    	typedef void (CTestLB::*ListBoxEventHandler)(CEikListBox* aListBox, TListBoxEvent anEvent);
    	void AddListBoxEventHandlerL(CEikListBox* aListBox, TListBoxEvent anEvent, ListBoxEventHandler aHandler);
    	struct TListBoxEventDispatch { 
    	CEikListBox* src; 
    	TListBoxEvent event; 
    	ListBoxEventHandler handler;
    	};
    
    	RArray< TListBoxEventDispatch > iListBoxEventDispatch;
    };
    				
    #endif
    Here's the .CPP
    Code:
    #include <barsread.h>
    #include <stringloader.h>
    #include <aknlists.h>
    #include <eikenv.h>
    #include <akniconarray.h>
    #include <eikclbd.h>
    #include <aknviewappui.h>
    #include <eikappui.h>
    #include <ListboxTest.mbg>
    #include <ListboxTest.rsg>
    #include "TestLB.h"
    #include "TestLBView.h"
    #include "TestLB.hrh"
    _LIT(KListboxTestFile, "\\resource\\apps\\ListboxTest.mbm");
    
    void CTestLB::ConstructL(const TRect& aRect, const CCoeControl* aParent, MEikCommandObserver* aCommandObserver)
    {
    	if (aParent == NULL) CreateWindowL();
    	else SetContainerWindowL(*aParent);
    	iFocusControl = NULL;
    	iCommandObserver = aCommandObserver;
    	InitializeControlsL();
    	SetRect(aRect);
    	ActivateL();
    }
    void CTestLB::LayoutControls()
    {
    	iListBox->SetExtent(TPoint(0, 0), iListBox->MinimumSize());
    }
    TKeyResponse CTestLB::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
    {
    	if (aKeyEvent.iCode == EKeyLeftArrow || aKeyEvent.iCode == EKeyRightArrow)
    	{
    		return EKeyWasNotConsumed;
    	}
    	if (iFocusControl != NULL && iFocusControl->OfferKeyEventL(aKeyEvent, aType) == EKeyWasConsumed)
    	{
    		return EKeyWasConsumed;
    	}
    	return CCoeControl::OfferKeyEventL(aKeyEvent, aType);
    }
    void CTestLB::InitializeControlsL()
    {
    	iListBox = new (ELeave) CAknDoubleLargeStyleListBox;
    	iListBox->SetContainerWindowL(*this);
    	{
    		TResourceReader reader;
    		iEikonEnv->CreateResourceReaderLC(reader, R_LISTBOX_TEST_LIST_BOX_LIST_BOX);
    		iListBox->ConstructFromResourceL(reader);
    		CleanupStack::PopAndDestroy(); 
    	}
    	iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);
    
    	SetupListBoxIconsL();
    
    	iListBox->SetListBoxObserver(this);
    	AddListBoxEventHandlerL(iListBox, EEventEnterKeyPressed, &CTestLB::HandleListBoxEnterKeyPressedL);
    
    	AddListBoxResourceArrayItemL(R_LISTBOX_TEST_LIST_BOX_LISTBOX_ITEM1, EListBoxListboxtestList_iconIndex);
    	AddListBoxResourceArrayItemL(R_LISTBOX_TEST_LIST_BOX_LISTBOX_ITEM2, EListBoxListboxtestList_iconIndex);
    
    	iListBox->SetFocus(ETrue);
    	iFocusControl = iListBox;
    	
    }
    void CTestLB::HandleResourceChange(TInt aType)
    {
    	CCoeControl::HandleResourceChange(aType);
    	SetRect(iAvkonViewAppUi->View(TUid::Uid(EListboxTestListBoxViewId))->ClientRect());
    }
    void CTestLB::Draw(const TRect& aRect) const
    {
    	CWindowGc& gc = SystemGc();
    	gc.Clear(aRect);
    }
    void CTestLB::AddListBoxItemL(CEikTextListBox* aListBox, const TDesC& aString)
    {
    	CTextListBoxModel* model = aListBox->Model();
    	CDesCArray* itemArray = static_cast< CDesCArray* > (model->ItemTextArray());
    	itemArray->AppendL(aString);
    	aListBox->HandleItemAdditionL();
    }
    RArray< TInt >* CTestLB::GetSelectedListBoxItemsLC(CEikTextListBox* aListBox)
    {
    	CAknFilteredTextListBoxModel* model = static_cast< CAknFilteredTextListBoxModel *> (aListBox->Model());
    	if (model->NumberOfItems() == 0) return NULL;
    
    	const CListBoxView::CSelectionIndexArray* selectionIndexes = aListBox->SelectionIndexes();
    	TInt selectedIndexesCount = selectionIndexes->Count();
    	if (selectedIndexesCount == 0) return NULL;
    
    	RArray<TInt>* orderedSelectedIndices = new (ELeave) RArray< TInt >(selectedIndexesCount);
    
    	CleanupStack::PushL(orderedSelectedIndices);
    	CleanupClosePushL(*orderedSelectedIndices);
    
    	CAknListBoxFilterItems* filter = model->Filter();
    	if (filter != NULL)
    	{
    		for (TInt idx = 0; idx < selectedIndexesCount; idx++)
    		{
    			TInt filteredItem = (*selectionIndexes) [ idx ];
    			TInt actualItem = filter->FilteredItemIndex (filteredItem);
    			orderedSelectedIndices->InsertInOrder(actualItem);
    		}
    	}
    	else
    	{
    		for (TInt idx = 0; idx < selectedIndexesCount; idx++)
    			orderedSelectedIndices->InsertInOrder((*selectionIndexes) [ idx ]);
    	}	
    
    	return orderedSelectedIndices;
    }
    void CTestLB::DeleteSelectedListBoxItemsL(CEikTextListBox* aListBox)
    {
    	CAknFilteredTextListBoxModel* model = static_cast< CAknFilteredTextListBoxModel *> (aListBox->Model());
    	if (model->NumberOfItems() == 0) return;
    
    	RArray< TInt >* orderedSelectedIndices = GetSelectedListBoxItemsLC(aListBox);		
    	if (!orderedSelectedIndices) return;
    
    	CDesCArray* itemArray = static_cast< CDesCArray* > (model->ItemTextArray());
    	TInt currentItem = 0;
    
    	for (TInt idx = orderedSelectedIndices->Count(); idx-- > 0;) 
    	{
    		currentItem = (*orderedSelectedIndices)[ idx ];
    		itemArray->Delete (currentItem);
    	}
    
    	CleanupStack::PopAndDestroy();
    	CleanupStack::PopAndDestroy(orderedSelectedIndices);
    	AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(aListBox, currentItem, ETrue);
    }
    void CTestLB::CreateListBoxItemL(TDes& aBuffer, TInt aIconIndex, const TDesC& aMainText, const TDesC& aSecondaryText)
    {
    	_LIT (KStringHeader, "%d\t%S\t%S");
    	aBuffer.Format(KStringHeader(), aIconIndex, &aMainText, &aSecondaryText);
    } 
    void CTestLB::AddListBoxResourceArrayItemL(TInt aResourceId, TInt aIconIndex)
    {
    	CDesCArray* array = iCoeEnv->ReadDesCArrayResourceL(aResourceId);
    	CleanupStack::PushL(array);
    	TBuf<512> listString; 
    	CreateListBoxItemL(listString, aIconIndex, (*array) [ 0 ], (*array) [ 1 ]);
    	AddListBoxItemL(iListBox, listString);
    	CleanupStack::PopAndDestroy(array);
    } 
    void CTestLB::SetupListBoxIconsL()
    {
    	CArrayPtr< CGulIcon >* icons = NULL;		
    	icons = new (ELeave) CAknIconArray(1);
    	CleanupStack::PushL(icons);
    	icons->AppendL(LoadAndScaleIconL(KListboxTestFile, EMbmListboxtestList_icon, EMbmListboxtestList_icon_mask, NULL, EAspectRatioPreserved));
    	CleanupStack::Pop(icons);
    
    	if (icons != NULL)
    	{
    		iListBox->ItemDrawer()->ColumnData()->SetIconArray(icons);
    	}
    }
    void CTestLB::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent anEventType)
    {
    	for (int i = 0; i < iListBoxEventDispatch.Count(); i++)
    	{
    		const TListBoxEventDispatch& currEntry = iListBoxEventDispatch[i];
    		if (currEntry.src == aListBox && currEntry.event == anEventType)
    		{
    			(this->*currEntry.handler)(aListBox, anEventType);
    			break;
    		}
    	}
    }
    void CTestLB::AddListBoxEventHandlerL(CEikListBox* aListBox, TListBoxEvent anEvent, ListBoxEventHandler aHandler)
    {
    	TListBoxEventDispatch entry;
    	entry.src = aListBox;
    	entry.event = anEvent;
    	entry.handler = aHandler;
    	TInt err = iListBoxEventDispatch.Append(entry);
    	User::LeaveIfError(err);
    }
    CGulIcon* CTestLB::LoadAndScaleIconL(const TDesC& aFileName,TInt aBitmapId, TInt aMaskId, TSize* aSize, TScaleMode aScaleMode)
    {
    	CFbsBitmap* bitmap;
    	CFbsBitmap* mask;
    	AknIconUtils::CreateIconL(bitmap, mask, aFileName, aBitmapId, aMaskId);
    
    	TSize size;
    	if (aSize == NULL){ AknIconUtils::PreserveIconData(bitmap); AknIconUtils::GetContentDimensions(bitmap, size); }
    	else { size = *aSize; }
    
    	AknIconUtils::SetSize(bitmap, size, aScaleMode);
    	AknIconUtils::SetSize(mask, size, aScaleMode);
    	
    	if (aSize == NULL) AknIconUtils::DestroyIconData(bitmap);
    
    	return CGulIcon::NewL(bitmap, mask);
    }

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,175

    Re: HandleListBoxEventL not being called when enter key pressed

    have you checked if the OfferKeyEventL() gets called ?

  3. #3
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    131

    Re: HandleListBoxEventL not being called when enter key pressed

    u need to check your .rssi file as well

    the resource type of listbox may be causing it not being called

    check the "flags" property in ur resource

    for
    EAknListBoxSelectionList
    i think it doesn't call the event.

  4. #4
    Registered User
    Join Date
    Aug 2008
    Posts
    12

    Re: HandleListBoxEventL not being called when enter key pressed

    Quote Originally Posted by symbianyucca View Post
    have you checked if the OfferKeyEventL() gets called ?
    OfferKeyEventL() is being called and I can see that it's calling the List box's OfferKeyEventL, but HandleListBoxEventL is never being called.

  5. #5
    Registered User
    Join Date
    Aug 2008
    Posts
    12

    Re: HandleListBoxEventL not being called when enter key pressed

    Quote Originally Posted by raysky View Post
    u need to check your .rssi file as well

    the resource type of listbox may be causing it not being called

    check the "flags" property in ur resource

    for
    EAknListBoxSelectionList
    i think it doesn't call the event.
    Thanks for the reply raysky. The rssi file has the flags set as EAknListBoxSelectionList only.

  6. #6
    Registered User
    Join Date
    Aug 2008
    Posts
    12

    Re: HandleListBoxEventL not being called when enter key pressed

    One other strange thing that I just noticed. I added some options to the option menu and now when I use the center key to select an item in the listbox, instead of nothing happening, the options menu is now showing, but my listbox still doesn't receive the notification.

    Edit: One other data point. Hitting the enter key on my computer's keyboard causes the event to fire properly in the emulator, but clicking on the center button in the emulator does not.

    Any ideas? Thanks in advance.
    Last edited by TorrinLynn; 2008-09-11 at 19:33. Reason: Adding more data

  7. #7
    Registered User
    Join Date
    Aug 2008
    Posts
    12

    Re: HandleListBoxEventL not being called when enter key pressed

    I've found that the YahooImageSearch example doesn't have this problem. After looking at the differences between the projects, the YahooImageSearch control Pane doesn't list the middle Soft Key Menu in its properties, while the sample project that exhibits the problem does have this. Does anyone know how to turn off this menu through the UI editor or through code?

  8. #8
    Registered User
    Join Date
    Aug 2008
    Posts
    12

    Re: HandleListBoxEventL not being called when enter key pressed

    I just tried adding an event handler for middleSoftKeyPressed and that's not getting called either. Please help. Thanks.

  9. #9
    Registered User
    Join Date
    Aug 2008
    Posts
    12

    Re: HandleListBoxEventL not being called when enter key pressed

    Found the problem:

    BaseConstructL( EAknEnableSkin | EAknEnableMSK );

    Removing EAknEnableMSK now allows the center button to perform a select. Does anyone know how I can remove this value through the GUI so it doesn't get regenerated everytime I modify the UI? Thanks.

  10. #10
    Registered User
    Join Date
    Aug 2008
    Posts
    12

    Re: HandleListBoxEventL not being called when enter key pressed

    Found it. Go to the application.designer and select properties on the view. Set enable middle soft key to false. Hope this helps someone and saves them some time.

  11. #11
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    131

    Re: HandleListBoxEventL not being called when enter key pressed

    Quote Originally Posted by TorrinLynn View Post
    Found it. Go to the application.designer and select properties on the view. Set enable middle soft key to false. Hope this helps someone and saves them some time.
    hmm how come i dun have .designer extension?

    wat IDE are u using?

  12. #12
    Registered User
    Join Date
    Aug 2008
    Posts
    12

    Re: HandleListBoxEventL not being called when enter key pressed

    I'm using Carbide 1.3 developer edition which provides a UI Designer (the .uidesigner) file extensions.

  13. #13
    Registered User
    Join Date
    Feb 2006
    Posts
    36

    Re: HandleListBoxEventL not being called when enter key pressed

    Quote Originally Posted by TorrinLynn View Post
    Found it. Go to the application.designer and select properties on the view. Set enable middle soft key to false. Hope this helps someone and saves them some time.
    Thanks TorrinLynn !
    It really saved my time !

  14. #14
    Registered User
    Join Date
    Oct 2008
    Posts
    6

    Re: HandleListBoxEventL not being called when enter key pressed

    Quote Originally Posted by TorrinLynn View Post
    Found it. Go to the application.designer and select properties on the view. Set enable middle soft key to false. Hope this helps someone and saves them some time.
    Thx alot! I was searching for that for a whole day!

  15. #15
    Super Contributor
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: HandleListBoxEventL not being called when enter key pressed

    Quote Originally Posted by TorrinLynn View Post
    I'm using Carbide 1.3 developer edition which provides a UI Designer (the .uidesigner) file extensions.
    Carbide.c++ 2.0 is now available free of charge. You can try Carbide.c++ 2.0 from below link.
    http://www.forum.nokia.com/info/sw.n...119a2b4cb.html

Similar Threads

  1. Handling key pressed events
    By yuava in forum Mobile Java General
    Replies: 8
    Last Post: 2011-07-08, 08:35
  2. detect if key is pressed
    By south_guang in forum Mobile Java General
    Replies: 0
    Last Post: 2007-11-30, 11:50
  3. GameCanvas Middle Soft Key Problem
    By nnigel in forum Mobile Java General
    Replies: 5
    Last Post: 2006-06-27, 11:14
  4. hangup when any key pressed
    By diablos_2003 in forum Symbian
    Replies: 1
    Last Post: 2005-10-01, 16:43
  5. Simultaneous Key press handling not possible ??
    By sherissher in forum Symbian
    Replies: 2
    Last Post: 2003-12-08, 17:35

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×