×

Discussion Board

Results 1 to 14 of 14
  1. #1
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,357

    How to put functionality on Selection Grid Icons.

    Hi,

    I am new to Symbian.
    I am trying to play with the Selection Grids.
    I could display the Grids with there Icons, using the Grid API from Nokia forum.


    But how to put functionality on the Grid Icons, so that where ever I press one Grid Icon it displays a Message on the screen.

    Please Help Me...
    thanks in advance.
    Last edited by somnathbanik; 2009-05-29 at 09:28. Reason: Added

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

    Re: How to put functionality on Selection Grid Icons.

    No need to ask twice, one post should be enough: http://discussion.forum.nokia.com/fo...d.php?t=169174

  3. #3
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,357

    Re: How to put functionality on Selection Grid Icons.

    HI,
    I tried this example http://wiki.forum.nokia.com/index.php/Grid_example.But it comes with a blank white screen with a scroll bar.

    Could any one please help me with some code, for handling the events.

  4. #4
    Super Contributor
    Join Date
    Mar 2004
    Location
    Bangalore,India
    Posts
    2,146

    Re: How to put functionality on Selection Grid Icons.

    Quote Originally Posted by somnathbanik View Post
    HI,
    I tried this example http://wiki.forum.nokia.com/index.php/Grid_example.But it comes with a blank white screen with a scroll bar.

    Could any one please help me with some code, for handling the events.
    I believe you are able to get the grid showing allright. If your grid is part of the container, you will have functions like HandlePointerEventL/OfferKeyEventL on the container which would be invoked everytime you do a key press/touch activity, you need to handle it in those functions with context to the grid, for instance you need to pass the offerkeyeventl to the grid when the container's offerkeyeventl gets called.

    Also make sure your view is aded to the control stack by doing AddToStackL to get key events. If you need to show your custom messages, then you can query the grid selected item
    Code:
    TInt currentIndex = iGrid->CurrentDataIndex();
    Cheers,
    Mayank

  5. #5
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,357

    Re: How to put functionality on Selection Grid Icons.

    Hi, here is my code in appview.cpp file..

    HTML Code:
    void CgridtestAppView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
    	{
    
    	TInt currentIndex = iMyGrid->CurrentDataIndex();
    	    if (currentIndex ==1)
    	    	    	 {
    	    	    	 _LIT(KMenuItem," is selected");
    	    	    	     							
    	    	    	 		iEikonEnv->AlertWin(KMenuItem);
    	    	    	 }
    	    
    	
    	
    	// Call base class HandlePointerEventL()
    	CCoeControl::HandlePointerEventL(aPointerEvent);
    	}
    but I am not getting an message displayed. Even I tried the same for for here also
    HTML Code:
    TKeyResponse CgridtestAppView::OfferKeyEventL( const TKeyEvent& aKeyEvent,
            TEventCode aType )
        {
        if ( iMyGrid )
            {
            return iMyGrid->OfferKeyEventL ( aKeyEvent, aType );
            }
        else
            {
            return EKeyWasNotConsumed;    
            }
        
        
        					
        TInt currentIndex = iMyGrid->CurrentDataIndex();
        	    if (currentIndex ==1)
        	    	    	 {
        	    	    	 _LIT(KMenuItem," is selected");
        	    	    	     							
        	    	    	 		iEikonEnv->AlertWin(KMenuItem);
        	    	    	 }						
        							
             
        }
    but nothing happens, please help me the code correction.

  6. #6
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,357

    Re: How to put functionality on Selection Grid Icons.

    Hi,

    Even I tried adding new function also. But no result. I am not able to display the message when I press on any of the Grid Icon.
    HTML Code:
    void CgridtestAppView::HandleControlEventL(CCoeControl *aControl, TCoeEvent aEventType)
    	{
    		if(iMyGrid == aControl)
    			{
    				switch(aEventType)
    				{
    					case EEventStateChanged:
    						{
    							TInt index = iMyGrid->CurrentDataIndex();
    							_LIT(KMenuItem,"%d is selected");
    							TBuf<20> buf;
    							buf.Format(KMenuItem(), index+1);							
    							CAknInformationNote* info = new (ELeave) CAknInformationNote;
    							info->ExecuteLD(buf);
    							iEikonEnv->AlertWin(KMenuItem);							
    										            
    						}
    						break;
    				}
    			}
    	}
    Please help me...

  7. #7
    Super Contributor
    Join Date
    Mar 2004
    Location
    Bangalore,India
    Posts
    2,146

    Re: How to put functionality on Selection Grid Icons.

    Did you debug and check if any of those functions i.e. offerkeyeventl and handlepointereventl are being called or not?
    Cheers,
    Mayank

  8. #8
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,357

    Re: How to put functionality on Selection Grid Icons.

    Hi,

    I have checked and found that the control is getting into the function OfferKeyEventL() when ever is change the grid controls on the icons (highlighted the icons) but not getting into the HandlePointerEventL() function.
    Here is the code
    HTML Code:
    KeyResponse CgridtestAppView::OfferKeyEventL( 
    		const TKeyEvent& aKeyEvent, 
    		TEventCode aType )
    	{
    	
    	TKeyResponse Ret = EKeyWasNotConsumed;
    	
    	if(iMyGrid)
    		{
    		Ret = iMyGrid->OfferKeyEventL(aKeyEvent,aType);
    		SelectedItem = iMyGrid->CurrentItemIndex();
    		
    		
    		
    		}
    	
    		
    	
    	switch(aType)
    		{
    		case EEventKeyDown:
    			_LIT(msg1," is selected");
    				iEikonEnv->AlertWin(msg1);
    			break;
    		
    			
    			
    		default:
    			break;
    			
    		}
    					
    	
    		
    		return Ret;
    	
    
    	}
    The above code pups up a message where ever the Grid control goes over the icons ( highlighted the icons), but I want that the message should pup up when the icons are pressed not when the icons are being highlighted .
    Please help me with some code.

  9. #9
    Super Contributor
    Join Date
    Mar 2004
    Location
    Bangalore,India
    Posts
    2,146

    Re: How to put functionality on Selection Grid Icons.

    Try inheriting your container from MEikListBoxObserver, while creating the grid do something like :- //iYourGrid->SetListBoxObserver(this); so that you get callbacks in the HandleListBoxEventL when there is any activity on the listbox, since the grid derives from the listbox this function would work. Then check for the aEventType in the callback function if you get 'EEventItemClicked' it means the item was clicked there you can do your processing.
    Cheers,
    Mayank

  10. #10
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,357

    Re: How to put functionality on Selection Grid Icons.

    Hi, tried this but those works only for listbox. Please suggest me something that works for Grids.

  11. #11
    Super Contributor
    Join Date
    Mar 2004
    Location
    Bangalore,India
    Posts
    2,146

    Re: How to put functionality on Selection Grid Icons.

    Absolutely does work :-

    Code:
    /*
     ============================================================================
     Name		: gridAppView.h
     ============================================================================
     */
    
    #ifndef __GRIDAPPVIEW_h__
    #define __GRIDAPPVIEW_h__
    
    // INCLUDES
    #include <coecntrl.h>
    #include <akngrid.h>
    #include <eiklbo.h>
    // CLASS DECLARATION
    class CgridAppView : public CCoeControl, public MEikListBoxObserver
    	{
    public:
    	// New methods
    
    	/**
    	 * NewL.
    	 * Two-phased constructor.
    	 * Create a CgridAppView object, which will draw itself to aRect.
    	 * @param aRect The rectangle this view will be drawn to.
    	 * @return a pointer to the created instance of CgridAppView.
    	 */
    	static CgridAppView* NewL(const TRect& aRect);
    
    	/**
    	 * NewLC.
    	 * Two-phased constructor.
    	 * Create a CgridAppView object, which will draw itself
    	 * to aRect.
    	 * @param aRect Rectangle this view will be drawn to.
    	 * @return A pointer to the created instance of CgridAppView.
    	 */
    	static CgridAppView* NewLC(const TRect& aRect);
    
    	/**
    	 * ~CgridAppView
    	 * Virtual Destructor.
    	 */
    	virtual ~CgridAppView();
    
    public:
    	// Functions from base classes
    
    	/**
    	 * From CCoeControl, Draw
    	 * Draw this CgridAppView to the screen.
    	 * @param aRect the rectangle of this view that needs updating
    	 */
    	void Draw(const TRect& aRect) const;
    
    	/**
    	 * From CoeControl, SizeChanged.
    	 * Called by framework when the view size is changed.
    	 */
    	virtual void SizeChanged();
    
    	/**
    	 * From CoeControl, HandlePointerEventL.
    	 * Called by framework when a pointer touch event occurs.
    	 * Note: although this method is compatible with earlier SDKs, 
    	 * it will not be called in SDKs without Touch support.
    	 * @param aPointerEvent the information about this event
    	 */
    	virtual void HandlePointerEventL(const TPointerEvent& aPointerEvent);
    
    	void LayoutControls();
    	TInt CountComponentControls() const;
    	CCoeControl* ComponentControl( TInt aIndex ) const;
    	void HandleListBoxEventL(CEikListBox* aListBox,TListBoxEvent aEventType);
    	TKeyResponse OfferKeyEventL( 
    				const TKeyEvent& aKeyEvent, 
    				TEventCode aType );
    private:
    	// Constructors
    
    	/**
    	 * ConstructL
    	 * 2nd phase constructor.
    	 * Perform the second phase construction of a
    	 * CgridAppView object.
    	 * @param aRect The rectangle this view will be drawn to.
    	 */
    	void ConstructL(const TRect& aRect);
    
    	/**
    	 * CgridAppView.
    	 * C++ default constructor.
    	 */
    	CgridAppView();
    	
    	 CAknGrid* iGrid;
    
    	 enum TControls
    	 		{
    	 		// [[[ begin generated region: do not modify [Generated Contents]
    	 		EGrid,
    	 		ELastControl
    	 		};
    	};
    
    #endif // __GRIDAPPVIEW_h__
    // End of File
    the .cpp file
    Code:
    /*
     ============================================================================
     Name		: gridAppView.cpp
     Author	  : mayank
     Copyright   : Your copyright notice
     Description : Application view implementation
     ============================================================================
     */
    
    // INCLUDE FILES
    #include <coemain.h>
    #include <BARSREAD.H>
    #include <aknlists.h>
    
    #include "gridAppView.h"
    #include <grid_0xE3C6070E.rsg>
    // ============================ MEMBER FUNCTIONS ===============================
    
    // -----------------------------------------------------------------------------
    // CgridAppView::NewL()
    // Two-phased constructor.
    // -----------------------------------------------------------------------------
    //
    CgridAppView* CgridAppView::NewL(const TRect& aRect)
    	{
    	CgridAppView* self = CgridAppView::NewLC(aRect);
    	CleanupStack::Pop(self);
    	return self;
    	}
    
    // -----------------------------------------------------------------------------
    // CgridAppView::NewLC()
    // Two-phased constructor.
    // -----------------------------------------------------------------------------
    //
    CgridAppView* CgridAppView::NewLC(const TRect& aRect)
    	{
    	CgridAppView* self = new (ELeave) CgridAppView;
    	CleanupStack::PushL(self);
    	self->ConstructL(aRect);
    	return self;
    	}
    
    // -----------------------------------------------------------------------------
    // CgridAppView::ConstructL()
    // Symbian 2nd phase constructor can leave.
    // -----------------------------------------------------------------------------
    //
    void CgridAppView::ConstructL(const TRect& aRect)
    	{
    	// Create a window for this application view
    	CreateWindowL();
    
    	   // Create grid
    	     iGrid = new( ELeave ) CAknGrid;    
    	     iGrid->SetContainerWindowL( *this );  
    	     iGrid->SetListBoxObserver( this );
    	     TResourceReader rr;  
    	     // initialize resource reader, passing resource id as parameter
    	     iEikonEnv->CreateResourceReaderLC( rr, R_SELECTIONGRID );
    	     // Construct grid from resource
    	     iGrid->ConstructFromResourceL( rr );    
    	     CleanupStack::PopAndDestroy();  // rr       
    
    	     // Setup the layout of the text in the cell.
    	     AknListBoxLayouts::SetupFormTextCell( *iGrid, iGrid->ItemDrawer(),
    	                                          0, LatinBold16(), 0, 0, 0, 30, 
    	                                          0, CGraphicsContext::ECenter, 
    	                                          TPoint(0,0), TPoint(0,0) ); 
    	     // Activate grid
    	     iGrid->SetRect( Rect() );	
    	     iGrid->ActivateL();
    	 	// Set the windows size
    	 	SetRect(aRect);
    
    	 	// Activate the window, which makes it ready to be drawn
    	 	ActivateL();
    	 	
         
    	}
    
    // -----------------------------------------------------------------------------
    // CgridAppView::CgridAppView()
    // C++ default constructor can NOT contain any code, that might leave.
    // -----------------------------------------------------------------------------
    //
    CgridAppView::CgridAppView()
    	{
    	// No implementation required
    	}
    
    // -----------------------------------------------------------------------------
    // CgridAppView::~CgridAppView()
    // Destructor.
    // -----------------------------------------------------------------------------
    //
    CgridAppView::~CgridAppView()
    	{
    	// No implementation required
    	}
    
    // -----------------------------------------------------------------------------
    // CgridAppView::Draw()
    // Draws the display.
    // -----------------------------------------------------------------------------
    //
    void CgridAppView::Draw(const TRect& /*aRect*/) const
    	{
    	// Get the standard graphics context
    	CWindowGc& gc = SystemGc();
    
    	// Gets the control's extent
    	TRect drawRect(Rect());
    
    	// Clears the screen
    	gc.Clear(drawRect);
    
    	}
    
    
    
    // -----------------------------------------------------------------------------
    // CgridAppView::HandlePointerEventL()
    // Called by framework to handle pointer touch events.
    // Note: although this method is compatible with earlier SDKs, 
    // it will not be called in SDKs without Touch support.
    // -----------------------------------------------------------------------------
    //
    void CgridAppView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
    	{
    
    	// Call base class HandlePointerEventL()
    	CCoeControl::HandlePointerEventL(aPointerEvent);
    	}
    
    /**
    * Return the number of controls in the container (override)
    * @return count
    */
    TInt CgridAppView::CountComponentControls() const
    	{
    	return ( int ) ELastControl;
    	}
    				
    /**
    * Get the control with the given index (override)
    * @param aIndex Control index [0...n) (limited by #CountComponentControls)
    * @return Pointer to control
    */
    CCoeControl* CgridAppView::ComponentControl( TInt aIndex ) const
    	{
    	// [[[ begin generated region: do not modify [Generated Contents]
    	switch ( aIndex )
    		{
    		case EGrid:
    			return iGrid;
    		}
    	// ]]] end generated region [Generated Contents]
    	
    	// handle any user controls here...
    	
    	return NULL;
    	}
    				
    /**
     *	Handle resizing of the container. This implementation will lay out
     *  full-sized controls like list boxes for any screen size, and will layout
     *  labels, editors, etc. to the size they were given in the UI designer.
     *  This code will need to be modified to adjust arbitrary controls to
     *  any screen size.
     */				
    void CgridAppView::SizeChanged()
    	{
    	CCoeControl::SizeChanged();
    	LayoutControls();
    	DrawNow();
    	// [[[ begin generated region: do not modify [Generated Contents]
    			
    	// ]]] end generated region [Generated Contents]
    	
    	}
    				
    // [[[ begin generated function: do not modify
    /**
     * Layout components as specified in the UI Designer
     */
    void CgridAppView::LayoutControls()
    	{
    	iGrid->SetExtent( TPoint( 10, 9 ), iGrid->MinimumSize()); //Set the extents for the controls
    	}
    
    void CgridAppView::HandleListBoxEventL(CEikListBox* aListBox,TListBoxEvent aEventType)
    	{
    	TInt currentIndex = -1;
    	if(aEventType == EEventItemClicked)
    		{
    		currentIndex = iGrid->CurrentDataIndex();
    		}
    	else if(aEventType == EEventEnterKeyPressed)
    		{
    		currentIndex = iGrid->CurrentDataIndex();
    		}
    	else if(aEventType == EEventItemDoubleClicked)
    		{
    		currentIndex = iGrid->CurrentDataIndex();
    		}
    	else if(aEventType == EEventPenDownOnItem)
    		{
    		currentIndex = iGrid->CurrentDataIndex();
    		}
    	TInt b = 2;
    	}
    
    TKeyResponse CgridAppView::OfferKeyEventL( 
    		const TKeyEvent& aKeyEvent, 
    		TEventCode aType )
    	{
    	if ( ( aKeyEvent.iCode == EKeyLeftArrow ) || ( aKeyEvent.iCode == EKeyRightArrow ) )
    			{
    	        // Listbox takes all events even if it doesn't use them
    	        return EKeyWasNotConsumed;
    			}	
    
    		if(iGrid)
    			{
    			return iGrid->OfferKeyEventL(aKeyEvent, aType);
    			}	
    		
    		//Other key events are passed on to the framework
    		return CCoeControl::OfferKeyEventL( aKeyEvent, aType );
    	}
    // End of File
    Creating the view from the appui like this :-
    Code:
    	// Create view object
    	iAppView = CgridAppView::NewL(ClientRect());
    
    	AddToStackL(iAppView);
    Cheers,
    Mayank

  12. #12
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,357

    Re: How to put functionality on Selection Grid Icons.

    I am working on the code, I don't mind if the code doesn't work, but I would be really great ful to you for this help.
    I would be more than glad if I could get your skype/gtalk or any other ID, so that in future I can contact you directly.

    Thank you
    Somnath

  13. #13
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,357

    Re: How to put functionality on Selection Grid Icons.

    Hi,
    I have tried the code and it worked. Thanks a lot. Now I am trying to put a background skin of an image. Could you please help me how to do that?

    I am trying to display a bmp or jpg image as a background skin. could you please help me how to do that?

  14. #14
    Super Contributor
    Join Date
    Mar 2004
    Location
    Bangalore,India
    Posts
    2,146

    Re: How to put functionality on Selection Grid Icons.

    M glad it works for you :-)

    For your other query wiki is your friend

    http://wiki.forum.nokia.com/index.ph...xt=Search+Wiki
    Cheers,
    Mayank

Similar Threads

  1. How to put functionality on Selection Grid Icons.
    By somnathbanik in forum Symbian
    Replies: 2
    Last Post: 2009-05-29, 09:25
  2. Grid selection problem
    By sriramadasu in forum Symbian
    Replies: 1
    Last Post: 2006-06-07, 06:50
  3. grid problem
    By ddhungry in forum Symbian
    Replies: 1
    Last Post: 2002-11-28, 05:15
  4. Grid Example
    By pappago in forum Symbian User Interface
    Replies: 1
    Last Post: 2002-11-05, 01:08
  5. Grid example
    By pappago in forum Symbian Tools & SDKs
    Replies: 0
    Last Post: 2002-10-24, 07: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
  •  
×