×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:Applying actions on list box items using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search
Forum Nokia KB (Talk | contribs)
m (Protected "TSS000647 - Applying actions on list box items": KB [edit=sysop:move=sysop])
extkbeditor1 (Talk | contribs)
m
Line 5: Line 5:
 
[[Category:Technical Solution]]
 
[[Category:Technical Solution]]
  
{|border="2" cellspacing="0" cellpadding="4" width="100%"
+
{{KnowledgeBase
|
+
|id=TSS000647
====Subject:====
+
|platform=S60 1st Edition<br>S60 2nd Edition and FP1, FP2, FP3<br>S60 3rd Edition and FP1
|colspan = "2"|
+
|devices=
====Applying actions on list box items====
+
|category=Symbian C<nowiki>++</nowiki>
|TSS000647
+
|subcategory=UI, UI components
 +
|creationdate=May 10, 2007
 +
|keywords=
 +
}}
  
|-
+
== Overview ==
|rowspan = "2"|
+
Applying actions on list box items
====&nbsp;====
+
|Platform(s):
+
|colspan = "2"|Device(s), SW version(s):
+
  
|-
+
== Description ==
|S60 1st Edition<br>S60 2nd Edition and FP1, FP2, FP3<br>S60 3rd Edition and FP1
+
Below is a code snippet demonstrating how to apply actions on a list box item selected by the user.<br>The code to create a simple list box can be obtained from the link below:<br>http://wiki.forum.nokia.com/index.php/How_to_create_a_simple_listbox<br>It is possible to apply any actions (e.g., displaying a popup or a dialog) by catching key events for a list box that currently has keyboard focus. This is done in the OfferKeyEventL() function of the container class that owns the list box.
|colspan = "2"|&nbsp;
+
  
|-
+
== Solution ==
|
+
&nbsp;&nbsp;&nbsp;&nbsp;TKeyResponse CMyExampleAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(aType != EEventKey)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return EKeyWasNotConsumed;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch(aKeyEvent.iCode)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case EKeyUpArrow:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case EKeyDownArrow:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Forward up and down key press events to the list box<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return iListBox-<nowiki>></nowiki>OfferKeyEventL( aKeyEvent, aType );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case EKeyOK: // display an information note when item is selected<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_LIT(KFormatMessage, "Selected item: %d");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TInt idx = iListBox-<nowiki>></nowiki>CurrentItemIndex();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TBuf<nowiki><</nowiki>32<nowiki>></nowiki> message;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;message.Format(KFormatMessage, idx);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CAknInformationNote* Note = new (ELeave) CAknInformationNote;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Note-<nowiki>></nowiki>ExecuteLD(message);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return EKeyWasConsumed;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return EKeyWasNotConsumed;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>Also make sure to add this line<br>&nbsp;&nbsp;&nbsp;&nbsp;AddToStackL( iAppView ); <br>in AppUi<nowiki>’</nowiki>s ConstructL() to add the view/container to the control stack and receive OfferKeyEventL() calls.
====Category:====
+
|colspan = "3"|Symbian C<nowiki>++</nowiki>
+
  
|-
 
|
 
====Subcategory:====
 
|colspan = "3"|UI, UI components
 
 
|-
 
|
 
====Description:====
 
|colspan = "3"|'''Description:'''<br>Below is a code snippet demonstrating how to apply actions on a list box item selected by the user.<br>The code to create a simple list box can be obtained from the link below:<br>http://wiki.forum.nokia.com/index.php/How_to_create_a_simple_listbox<br>It is possible to apply any actions (e.g., displaying a popup or a dialog) by catching key events for a list box that currently has keyboard focus. This is done in the OfferKeyEventL() function of the container class that owns the list box.<br>'''Solution:'''<br>&nbsp;&nbsp;&nbsp;&nbsp;TKeyResponse CMyExampleAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(aType != EEventKey)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return EKeyWasNotConsumed;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch(aKeyEvent.iCode)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case EKeyUpArrow:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case EKeyDownArrow:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Forward up and down key press events to the list box<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return iListBox-<nowiki>></nowiki>OfferKeyEventL( aKeyEvent, aType );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case EKeyOK: // display an information note when item is selected<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_LIT(KFormatMessage, "Selected item: %d");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TInt idx = iListBox-<nowiki>></nowiki>CurrentItemIndex();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TBuf<nowiki><</nowiki>32<nowiki>></nowiki> message;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;message.Format(KFormatMessage, idx);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CAknInformationNote* Note = new (ELeave) CAknInformationNote;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Note-<nowiki>></nowiki>ExecuteLD(message);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return EKeyWasConsumed;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return EKeyWasNotConsumed;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>Also make sure to add this line<br>&nbsp;&nbsp;&nbsp;&nbsp;AddToStackL( iAppView ); <br>in AppUi<nowiki>’</nowiki>s ConstructL() to add the view/container to the control stack and receive OfferKeyEventL() calls.
 
 
|-
 
|
 
====Creation date:====
 
|colspan = "3"|May 10, 2007
 
 
|-
 
|
 
====Last modified:====
 
|colspan = "3"|-
 
 
|-
 
 
[[Category:Symbian C++]][[Category:UI]][[Category:S60 1st Edition]] [[Category:S60 2nd Edition]] [[Category:S60 3rd Edition]] [[Category:S60 3rd Edition, Feature Pack 1]]
 
[[Category:Symbian C++]][[Category:UI]][[Category:S60 1st Edition]] [[Category:S60 2nd Edition]] [[Category:S60 3rd Edition]] [[Category:S60 3rd Edition, Feature Pack 1]]

Revision as of 17:08, 4 November 2008

Template:KBTS

Article Metadata
Compatibility
Platform(s): S60 1st Edition
S60 2nd Edition and FP1, FP2, FP3
S60 3rd Edition and FP1
S60 3rd Edition FP1
S60 3rd Edition (initial release)
S60 2nd Edition (initial release)
S60 1st Edition
Article
Created: (10 May 2007)
Last edited: extkbeditor1 (04 Nov 2008)

Overview

Applying actions on list box items

Description

Below is a code snippet demonstrating how to apply actions on a list box item selected by the user.
The code to create a simple list box can be obtained from the link below:
http://wiki.forum.nokia.com/index.php/How_to_create_a_simple_listbox
It is possible to apply any actions (e.g., displaying a popup or a dialog) by catching key events for a list box that currently has keyboard focus. This is done in the OfferKeyEventL() function of the container class that owns the list box.

Solution

    TKeyResponse CMyExampleAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
        {
        if(aType != EEventKey)
            {
            return EKeyWasNotConsumed;
            }
        switch(aKeyEvent.iCode)
            {
            case EKeyUpArrow:
            case EKeyDownArrow:
                {
                // Forward up and down key press events to the list box
                return iListBox->OfferKeyEventL( aKeyEvent, aType );
                }
            case EKeyOK: // display an information note when item is selected
                {
                _LIT(KFormatMessage, "Selected item: %d");
                TInt idx = iListBox->CurrentItemIndex();
                TBuf<32> message;
                message.Format(KFormatMessage, idx);
                CAknInformationNote* Note = new (ELeave) CAknInformationNote;
                Note->ExecuteLD(message);
                return EKeyWasConsumed;
                }
            default:
                break;
            }
       
        return EKeyWasNotConsumed;
        }
Also make sure to add this line
    AddToStackL( iAppView );
in AppUi’s ConstructL() to add the view/container to the control stack and receive OfferKeyEventL() calls.

118 page views in the last 30 days.
×