Constructing the toolbar

Construct the toolbar either for your entire application or for an application view. If a view has no toolbar specified, the application specific toolbar is used for the view.

The UI framework creates the toolbar automatically during application initialization when it is properly defined in the resource files. After the toolbar has been created, you can receive a pointer to it using CAknAppUi, CEikAppUiFactory or CAknView methods. The method to use depends on whether the application specific or view specific toolbar pointer should be received. For more information, see Accessing the toolbar from applications or application views.

The toolbar destruction is also handled by the framework when the application execution ends.

The EIK_APP_INFO structure’s custom_app_info_extension refers to the EIK_APP_INFO_EXT element. The element contains links to the resource structure of the toolbar. The contents of the application-specific toolbar can be defined in the AVKON_TOOLBAR resource definition. The toolbar can also be specified to be view-specific by linking to its resource structure from the AVKON_VIEW resource structure. If a view has no toolbar specified, the application-specific toolbar is used for the view.

Use the AVKON_TOOLBAR resource definition to define the toolbar contents.

If the toolbar is application specific, refer to the toolbar definition from the EIK_APP_INFO_EXT resource structure. In case of a view specific toolbar, refer to the toolbar definition from the AVKON_VIEW structure.

The AVKON_TOOLBAR resource definition contains a list of toolbar items. Each item is defined as TBAR_CTRL structure.

The example below shows how to define an application toolbar in resources.

RESOURCE EIK_APP_INFO
    {
    cba = r_softkeys_options_next;
    menubar = r_myapp_menubar;
    custom_app_info_extension = r_myapp_info_extension;
    }

RESOURCE EIK_APP_INFO_EXT r_myapp_info_extension
    {
    popup_toolbar = r_myapp_fixed_toolbar;
    }

The example below shows how to define a toolbar for an application view in resources.

RESOURCE AVKON_VIEW r_myapp_fixed_view
    {
    menubar = r_myapp_menubar;
    toolbar = r_myapp_fixed_toolbar;
    cba = r_softkeys_options_next;
    }

Use the TBAR_CTRL resource definition to define toolbar controls. You can also add controls later dynamically in your application code.

The example below shows how to define a fixed toolbar with three buttons in resources.

RESOURCE AVKON_TOOLBAR r_myapp_fixed_toolbar
    {
    flags = KAknToolbarFixed;
    items =
        {
        TBAR_CTRL
            {
            type = EAknCtButton;
            id = ECmdFirst;
            control = AVKON_BUTTON
                {
                flags = 0;
                states =
                    {
                    AVKON_BUTTON_STATE
                        {
                        txt = "First";
                        helptxt = "First help";
                        }  
                    };
                };
            },
        TBAR_CTRL
            {
            type = EAknCtButton;
            id = ECmdSecond;
            control = AVKON_BUTTON
                {
                flags = 0;
                states =
                    {
                    AVKON_BUTTON_STATE
                        {
                        txt = "Second";
                        helptxt = "Second help";
                        }  
                    };
                };
            },
        TBAR_CTRL
            {
            type = EAknCtButton;
            id = ECmdThird;
            control = AVKON_BUTTON
                {
                flags = 0;
                states =
                    {
                    AVKON_BUTTON_STATE
                        {
                        txt = "Third";
                        helptxt = "Third help";
                        }  
                    };
                };
            }
        };
    }

The example below shows how to define a floating toolbar with items to be added dynamically at runtime.

RESOURCE AVKON_TOOLBAR r_myapp_floating_toolbar
    {
    flags = KAknToolbarWithoutCba;
    items =
        {
        // Created dynamically
        };
    }