UIQ Technology
Symbian OS Library

UIQ 3.1 SDK        UIQ developer portal

[Index] [Spacer] [Previous] [Next]



UIQ Controls - IP Editor


1. Introduction

This guide explains the UIQ control IP Editor (CQikIpEditor). The IP Editor allows the user to edit IP addresses. The IP address can be an IPv4 address, IPv6 address, IPv4-mapped IPv6 address or an IPv4-compatible IPv6 address. This control is normally used in a Container Pop-out.

The following functionality can be used by the application developer:

By default, the following configuration applies:

IPv4 Editor with first section highlight...

IPv4 Editor with first section highlighted

IPv6 Editor with first section highlight...

IPv6 Editor with first section highlighted

Dimmed IPv6 Editor

Dimmed IPv6 Editor

[Top]


2. Architecture

IP Editor inherits from Bordered Control (CEikBorderedControl).

High-level architecture of IP Editor

High-level architecture of IP Editor

[Top]


3. Using the Control

This section explains how the control is constructed, used and destroyed. Source code examples are used and explained to illustrate how the IP Editor control is used.


3.1 Includes and Identifications

Use the following #include directive:

#include <QikIpEditor.h>

Use the following LIBRARY directive in the project's mmp-file:

LIBRARY qikctl.lib

Use the following control identifier when specifying the control in resource data files. It is used by the framework when constructing the control from resource data:

EQikCtIpEditor


3.2 Resource Structure

Resource files can be used to construct the IP Editor. The resource to use is defined by the QIK_IP_EDITOR struct, defined in Qikon.rh. The struct looks like this:

STRUCT QIK_IP_EDITOR
    {
    }

The resource is empty; no elements are defined.


3.3 Construction

A common way to construct controls is to specify them in the resource files and let the framework construct them from there. Specifying the controls in resource files is the preferred way of constructing controls, since it allows for easier modifications compared to creating them entirely from source code.

This section covers different ways of constructing an IP Editor.

3.3.1 Construction with View Framework Using Data from a Resource File

The example below describes how to construct an IP Editor using the view framework.

The reason the example seems to be rather complex is because it demonstrates how to construct a complete view containing a Scrollable Container and a Layout Manager. It also encapsulates the IP Editor in a Building Block. The view supports both pen and softkey styles; support of both styles in a view is optional.

1) Declare an enumeration for the controls to be used in the view in a *.hrh file. Hrh files are files to be included both in resource files (*.rss) and C++ files:

/* Declare the controls' ID in a *.hrh file for use both in resource and cpp */
enum TMyViewControls
    {
    EMyViewScrollableContainer,
    EMyViewBuildingBlock,
    EMyViewIPEditor,
    EMyViewNumberOfControls
    };

2) Declare the controls to be used in the view in your resource (*.rss) file:

/* Declare the set of controls to be used in the view */
RESOURCE QIK_CONTROL_COLLECTION r_my_ip_editor_view_controls
    {
    items =
        {
        QIK_CONTROL
            {
            unique_handle = EMyViewScrollableContainer;
            type = EQikCtScrollableContainer;
            control = r_my_ip_editor_scroll_pane;
            },
        QIK_CONTROL
            {
            unique_handle = EMyViewIPEditor;
            type = EQikCtIpEditor;
            control = r_my_ip_editor;
            },
        QIK_CONTROL
            {
            unique_handle = EMyViewBuildingBlock;
            type = EQikCtCaptionedTwolineBuildingBlock;
            control = r_my_ip_editor_building_block;
            }
        };
    }

3) Define the view and its contents in your resource file:

/* The view */
RESOURCE QIK_VIEW r_my_ip_editor_view
    {
    pages = r_my_ip_editor_viewpages;
    }
                
/* The view page */
RESOURCE QIK_VIEW_PAGES r_my_ip_editor_viewpages
    {
    pages =
        {
        QIK_VIEW_PAGE
            {
            container_unique_handle = EMyViewScrollableContainer;
            page_content = r_my_ip_editor_view_container_details;
            }
        };
    }

4) Define the resource for the Scrollable Container used in the view:

/* The scrollable container used in the view */
RESOURCE QIK_SCROLLABLE_CONTAINER r_my_ip_editor_scroll_pane
    {
    }

5) Declare the contents and properties for the Scrollable Container used in the view:

/* Contents of the Scrollable Container used in the view */
RESOURCE QIK_SCROLLABLE_CONTAINER_SETTINGS r_my_ip_editor_view_container_details
    {
    controls =
        {
        QIK_CONTAINER_ITEM
            {
            unique_handle = EMyViewBuildingBlock;
            }
        };
    }

6) Define the control resource struct used in the view:

/* The control used in the view */
RESOURCE QIK_IP_EDITOR r_my_ip_editor
    {
    }

7) Define the settings for the Building Block containing the control:

/* Settings for the EQikCtCaptionedTwolineBuildingBlock containing the control */
RESOURCE QIK_SYSTEM_BUILDING_BLOCK r_my_ip_editor_building_block
    {
    content =
        {
        QIK_SLOT_CONTENT
            {
            slot_id = EQikItemSlot1;
            caption = "Choose:";
            },
        QIK_SLOT_CONTENT
            {
            slot_id = EQikItemSlot2;
            unique_handle = EMyViewIPEditor;
            }
        };
    }

8) The configurations of the view:

RESOURCE QIK_VIEW_CONFIGURATIONS r_my_ip_editor_ui_configurations
    {
    configurations=
        {
        QIK_VIEW_CONFIGURATION
            {
            ui_config_mode = KQikSoftkeyStylePortrait;
            view = r_my_ip_editor_view;
            command_list = r_my_ip_editor_commands;
            },
        QIK_VIEW_CONFIGURATION
            {
            ui_config_mode = KQikPenStyleTouchPortrait;
            view = r_my_ip_editor_view;
            command_list = r_my_ip_editor_commands;
            }                       
        };
    }

9) The command list for the view:

RESOURCE QIK_COMMAND_LIST r_my_ip_editor_commands
    {
    items =
        {
        // This command shall only be visible in debug mode because it is only
        // used to find memory leaks during development of the application.
        QIK_COMMAND
            {
            id = EEikCmdExit;
            type = EQikCommandTypeScreen;
            // Indicate that this command will only be visible in debug
            stateFlags = EQikCmdFlagDebugOnly;
            text = "Close (debug)";
            }
        };
    }

10) The view framework constructs the view described in this example with this code:

void CMySinglePageView::ViewConstructL()
    {
    ViewConstructFromResourceL(R_MY_IP_EDITOR_UI_CONFIGURATIONS, R_MY_IP_EDITOR_VIEW_CONTROLS);
    }

11) The result should look something like this:

IP editor placed in a Building Block slo...

IP editor placed in a Building Block slot

3.3.2 Construction with Your Own C++ Code Using Data from a Resource File

The example below describes how to construct an IP editor from resource with your own C++ code.

The reason the example seems to be rather complex is because it demonstrates how to construct a complete view containing a Scrollable Container and a Layout Manager. It also encapsulates the IP editor in a Building Block.

This example uses the resource structs from the previous example. The following code creates the IP editor:

#include <qikipeditor.h>
#include <QikRowLayoutManager.h>
#include <QikGridLayoutManager.h>
#include <QikBuildingBlock.h>
                    
void CMySinglePageView::ViewConstructL()
    {
    // Create and designate a layout manager for the view
    CQikGridLayoutManager* gl = CQikGridLayoutManager::NewLC();
    SetLayoutManagerL(gl);
    CleanupStack::Pop(gl);
                        
    // Load the control collection, create a container and designate it to the view
    ControlProvider()->ControlInfos().AddFromResourceL(R_MY_IP_EDITOR_VIEW_CONTROLS);
    CQikContainerBase* container = static_cast<CQikContainerBase*>(ControlProvider()->ControlConstructIfNeededL(EMyViewScrollableContainer, *this));
    ASSERT(container);
    Controls().AppendLC(container);
    CleanupStack::Pop(container);
                    
    // Create a layout manager to be used inside the container
    CQikRowLayoutManager* rowlayout = CQikRowLayoutManager::NewLC();
    container->SetLayoutManagerL(rowlayout);
    CleanupStack::Pop(rowlayout);
                    
    // Create the building block (containing an IP editor) and
    // add it to the container
    CQikBuildingBlock* block = CQikBuildingBlock::CreateSystemBuildingBlockL(EQikCtCaptionedTwolineBuildingBlock);
    container->AddControlLC(block, EMyViewBuildingBlock);
    TResourceReader blockReader;
    iCoeEnv->CreateResourceReaderLC(blockReader,R_MY_IP_EDITOR_BUILDING_BLOCK);
    block->ConstructFromResourceL(blockReader, *ControlProvider());
    CleanupStack::PopAndDestroy(); //blockReader
    CleanupStack::Pop(block);
    }

What the code does

1) Initializes the Command Manager with an empty Command List. The controls placed in the view add their commands to the Command List when they receive focus.

2) Creates a Layout Manager for the view. The Grid Layout Manager fills the view with its only control in this example, the Scrollable Container.

3) Loads the control collection R_MY_VIEW_CONTROLS into the Control Provider. Then the Control Provider is asked to create the Scrollable Container.

4) Uses the MopGetObjectNoChaining function to determine whether the control that was created really is a class of the type CQikContainerBase before it is added to the view.

5) Creates a Layout Manager to control the layout inside the container. Adds the Layout Manager to the container.

6) Constructs the Building Block containing the IP editor from the resource R_MY_BUILDING_BLOCK. Adds the Building Block to the container.

7) The result should look something like this:

IP editor placed in a Building Block slo...

IP editor placed in a Building Block slot

The IP editor can also be created without a Building Block. In that case, replace the last section in the code above, from the "Create building block..." comment, with the following code.

Since a pointer to the control is declared here, QikIpEditor.h needs to be included in the cpp-file and QikCtl.lib in the mmp-file.

// Create the IP Editor and add it into the container
TResourceReader reader;
iEikonEnv->CreateResourceReaderLC(reader, R_MY_IP_EDITOR);
CQikIpEditor* ipEditor = new (ELeave) CQikIpEditor();
container->AddControlLC(ipEditor, EMyViewIPEditor);
ipEditor->ConstructFromResourceL(reader);
ipEditor->SetObserver(this);
ipEditor->SetUniqueHandle(EMyViewIPEditor);
CleanupStack::Pop(ipEditor);
CleanupStack::PopAndDestroy(); //reader

Use AddControlLC to add controls to a Scrollable Container. Add the controls as soon as they are created. Do not push them onto the Cleanup Stack before they are added. Do not pop them from the Cleanup Stack until they are fully constructed. A TCleanupItem created in AddControlLC will make sure that the control is both cleaned up and removed from the Components Array if a leave occurs before the control is fully constructed.

8) The result should look something like this:

IP editor placed directly in a Scrollabl...

IP editor placed directly in a Scrollable Container without using a Building Block

3.3.3 Construction Solely from C++ Code

The example below describes how to construct an IP editor solely from C++ code.

The reason the example seems to be rather complex is because it demonstrates how to construct a complete view containing a Scrollable Container and a Layout Manager.

The following source code constructs an IP editor:

#include <QikIpEditor.h>
#include <QikScrollableContainer.h>
#include <QikRowLayoutManager.h>
#include <QikGridLayoutManager.h>
#include <QikBuildingBlock.h>
                    
void CMySinglePageView::ViewConstructL()
    {
    // Create and designate a layout manager for the view
    CQikGridLayoutManager* gridlayout = CQikGridLayoutManager::NewLC();
    SetLayoutManagerL(gridlayout);
    CleanupStack::Pop(gridlayout);
                        
    // Create a container and add it to the view
    CQikScrollableContainer* container = new (ELeave) CQikScrollableContainer();
    Controls().AppendLC(container);
    container->ConstructL(EFalse);
    CleanupStack::Pop(container);
                        
    // Create a layout manager to be used inside the container
    CQikRowLayoutManager* rowlayout = CQikRowLayoutManager::NewLC();
    container->SetLayoutManagerL(rowlayout);
    CleanupStack::Pop(rowlayout);
                    
    // Create the IP editor and add it to the container
    CQikIpEditor* ipEditor = new (ELeave) CQikIpEditor();
    container->AddControlLC(ipEditor, EMyViewIPEditor);
    ipEditor->ConstructL();

    // IP ver 6 code
    ipEditor->SetMode(EIpv6Address);
    _LIT(KTestIp, "111a:222b:333c:444d:555e:666f:777a:888b");

    ipEditor->SetIpAddress(KTestIp);
    ipEditor->SetUniqueHandle(EMyViewIPEditor);
    ipEditor->SetObserver(this);
    CleanupStack::Pop(ipEditor);
    }

What the code does

1) Initializes the Command Manager with an empty Command List. The controls placed in the view add their commands to the Command List when they receive focus.

2) Creates a Layout Manager for the view. The Grid Layout Manager fills the view with its only control in this example, the Scrollable Container.

3) Creates a container and adds it to the view.

4) Creates a Layout Manager and adds it to the container.

5) Creates the IP editor from C++ code. Sets the view, this, to be an observer of the IP editor. The view's base class, CQikViewBase, handles focus changes in its method HandleControlEventL. For more details see the section below on how to be notified with Control Events.

6) The result should look something like this:

IP editor placed directly in a Scrollabl...

IP editor placed directly in a Scrollable Container

3.3.4 Construction with the Dialog Framework Using Data from a Resource File

The IP editor can be constructed from resource files in dialogs as well. To construct a dialog from resource a valid resource definition of that dialog must be in one of the project's resource files.

An example of a dialog resource containing the control is given below. For more information about the dialog class and its resource struct see CEikDialog and DIALOG in the API documentation.

1) Declare a dialog resource containing the IP editor:

RESOURCE DIALOG r_my_ip_editor_dialog
    {
    title = "Test of control in dialog";
    flags = EEikDialogFlagWait;
    items =
        {
        DLG_LINE
            {
            prompt = "IP editor:";
            type = EQikCtIpEditor;
            itemflags = EQikDlgItemCtlIsEditInPlace; // No Pop-out container will be used.
            control = QIK_IP_EDITOR
                {
                };
            }
        };
    }

The resource properties inside the Control Block are the same as the ones described in the previous section.

2) Launch the dialog using the following source code. The dialog resource ID is passed as an argument:

CEikDialog* dlg = new (ELeave) CEikDialog();
dlg->ExecuteLD(R_MY_IP_EDITOR_DIALOG);

The function returns immediately if EEikDialogFlagWait has not been specified in the dialog resource. If EEikDialogFlagWait is specified, it returns when the dialog exits. The dialog framework will, in both situations, delete the dialog appropriately as indicated by the D suffix of the ExcecuteLD function name.

3) The result should look something like this:

Result of creating the IP Editor from a...

Result of creating the IP Editor from a dialog resource


3.4 Using the IP Editor

This section covers the most common functions used for interacting with the control.

When constructing the control with resource data, no reference to the control is available in the view class. When constructing the control with code, the preferred way might be to not save a reference to the control. In both these cases, the LocateControlByUniqueHandle function is used to get a pointer to the control by supplying the control's unique handle. When constructing the view and the control from code, you must explicitly set this unique handle by calling the method SetUniqueHandle. See the code examples below.

Note that the function will return NULL if the control could not be found. Always check the pointer before using it!

// Set the unique handle
ipEditor->SetUniqueHandle(EMyViewIPEditor);
            
// Get a pointer to the control
CQikIpEditor* ipEditor = LocateControlByUniqueHandle<CQikIpEditor>(EMyViewIPEditor);

3.4.1 How to Set the IP Address Mode

The IP mode is determined automatically by the address passed to the editor. But the mode can be set explicitly using one of the address modes listed in the table below. The enum TIpType specifies the available modes.

Address mode Description

EIpv4Address

IPv4 addresses are specified as n.n.n.n, where n is a decimal 0-255.

EIpv6Address

IPv6 addresses are specified as n:n:n:n:n:n:n:n, where n is a hexadecimal 0-ffff.

EIpv4CompatibleAddress

IPv4 compatible addresses are specified as 0:0:0:0:0:0:n.n.n.n, where n is a decimal 0-255.

EIpv4MappedAddress

IPv4 mapped addresses are specified as 0:0:0:0:0:ffff:n.n.n.n, where n is a decimal 0-255.

EIpUnknownAddress

When the address mode cannot be determined from the address provided, it is set to EIpUnknownAddress. This could indicate an error in the address. This is also the initial mode for the IP editor. However, the initial mode should be overridden by the default mode during construction of the IP editor.

The following lines of code set the address mode:

// Set the address mode to IP version 6.
ipEditor->SetMode(EIpv6Address);

// Set the address mode to IP version 4.
ipEditor->SetMode(EIpv4Address);

3.4.2 How to Get the IP Address Mode

The enum TIpType specifies the available modes; see the table above.

The following lines of code get the address mode:

// Get the address current mode.
TIpType addressMode;
addressMode = ipEditor->Mode();

3.4.3 How to Set the IP Address

The address formats that are supported are specified by the TIpType; see above. All types of short versions for IPv6 addresses are also supported. See RFC2373 for more information on address formats. The link address is http://www.scit.wlv.ac.uk/rfc/rfc23xx/RFC2373.html.

The following lines of code set the address:

// Set address to an IP version 6 address.
_LIT(KTestIp, "111a:222b:333c:444d:555e:666f:777a:888b");
ipEditor->SetIpAddress(KTestIp);

// Set address to an IP version 4 address.
_LIT(KTestIp, "1.2.3.4");
ipEditor->SetIpAddress(KTestIp);

3.4.4 How to Get the IP Address

The following lines of code get the address:

// Get the IP address.
TBuf<50> address;
ipEditor->IpAddress(address);

3.4.5 How to be Notified with Control Events

In order to be notified when the IP Editor changes state you must add an observer to the IP Editor. An observer is an object of the type MCoeControlObserver. The observer receives a function call to its function HandleControlEventL(CCoeControl* aControl, TCoeEvent aEventType) when the IP Editor changes state.

The view base class, CQikViewBase, implements the MCoeControlObserver. The HandleControlEventL function must be overloaded in the view class because the view inherits from CQikViewBase.

The following source code example shows how to add an object as an observer and how to receive events from the IP Editor:

void CMySinglePageView::ViewConstructL()
    {
    // Construction code
    …
    // Adding this object as an observer
    ipEditor->SetObserver(this);
    }

void CMySinglePageView::HandleControlEventL(CCoeControl* aControl, TCoeEvent aEventType)
    {
    // Call base class to handle focus management
    CQikViewBase::HandleControlEventL(aControl, aEventType);
                        
    CQikIpEditor* ipEditor = LocateControlByUniqueHandle<CQikIpEditor>(EMyViewIPEditor);
                        
    if(aControl == ipEditor)
        {
        switch(aEventType)
            {
            case EEventStateChanged:
                // The internal state of the IP Editor was changed,
                // for example, due to another item being selected.
                break;
                                    
            case EEventRequestExit:
                break;
                                    
            case EEventRequestCancel:
                break;
                                    
            case EEventRequestFocus:
                // The control received a pointer down event
                break;
                                    
            case EEventPrepareFocusTransition:
                // A focus change is about to appear
                break;
                                
            case EEventInteractionRefused:
                // The control is dimmed and received a
                // pointer down event.
                break;
                                
            default:
                break;
            }
        }
    }

The reason for calling the base class's HandleControlEventL function is that the view base class, CQikViewBase, handles focus management between controls in the view. If the control's observer is not a class which derives from CQikViewBase, focus management must be resolved by the observer itself. If a control requests focus and does not get it from the observer, it will generate a panic in some cases if the observer does not leave.

For more details on the TCoeEvent type, see class MCoeControlObserver in the API documentation.


3.5 Destruction

Destroying the control is just a matter of invoking operator delete on the IP Editor object.

[Top]


4. Subclassing

Subclassing IP Editor is not recommended.

[Top]


5. Glossary

This is an explanation of some of the expressions used in this guide.

Expression/Abbreviation Description

IP

Internet Protocol

IPv6

IP version 6 addresses

IPv4

IP version 4 addresses