Dialog box for Symbian OS control development

Source: Internet
Author: User
Dialog box for Symbian OS control development
New article: Understanding the Symbian Control Architecture

The dialog box of Symbian OS is divided into the mode dialog box and the non-mode dialog box. The dialog box must be defined in the resource file (the control contained in the dialog box must also be defined in the resource file). Then, create a dialog box object in the program and use the dialog box ID in the resource file for initialization, finally, execute the dialog box and display the relevant content.
There are many types of dialogs. Apart from standard dialogs, there are also forms, notification dialogs, query dialogs, list dialogs, and other types.
* Form: similar to the list control, each data item in the form can be edited.
* Notification dialog box: displays user prompts.
* Query dialog box: contains an editing box. You can input data to the text editor for program query, which is mainly used for data query.
* List dialog box: contains a list control that displays multiple data items. Query dialog box:

Data Query dialog box

In the program, you must first define the query dialog box in the resource file:
Resource dialog r_data_query_dialog
{
Flags = egeneralqueryflags;
Buttons = r_avkon_softkeys_ OK _cancel;
Items =
{
Dlg_line
{
Type = eaknctquery;
Id = edataqueryid;
Control = avkon_data_query
{
Layout = edatalayout;
Control = Edwin
{
Width = 20;
Lines = 1;
Maxlength = 20;
};
};
}
};
}
In the query dialog box, an editor control is also defined as Edwin in the resource file, and its width, number of rows, and maximum length attributes are specified.
List query dialog box
It displays various options in the form of a list. You can select any of them.

Common Symbian dialog box

1. Text inquiry dialog box
Resource definition (note the semicolon)

Resource dialog r_text_query
{
Flags = egeneralqueryflags;
Buttons = r_avkon_softkeys_ OK _cancel;
Items =
{
Dlg_line
{
Type = eaknctquery;
Id = egeneralquery;
Control = avkon_data_query
{
Layout = edatalayout;
Label = "";
Control = Edwin
{
Width = 5;
Lines = 1;
Maxlength = 15;
};
};
}
};
}

Code for calling this class

Tbuf <128> text; // save user input information
Tbuf <128> prompt (_ L ("Enter text:"); // prompt

Cakntextquerydialog * DLG = new (eleave) cakntextquerydialog (text, prompt );

DLG-> setmaxlength (20 );
If (DLG-> executeld (r_text_query ))
{// OK is pressed
}

2. List inquiry dialog box
Resource avkon_list_query r_demo_list_query
{
Flags = egeneralqueryflags;
Softkeys = r_avkon_softkeys_ OK _cancel;
Items =
{
Avkon_list_query_dlg_line
{
Control = avkon_list_query_control
{
Listtype = eaknctsinglepopupmenulistbox;
ListBox = avkon_list_query_list
{
Array_id = r_demo_list_query_item;
};
Heading = "select one item :";
};
}
};
}

Resource array r_demo_list_query_item
{
Items =
{
Lbuf {TXT = "first item ";},
Lbuf {TXT = "second item ";},
Lbuf {TXT = "third item ";}
};
}

Called code
Tint index (0 );
Caknlistquerydialog * DLG = new (eleave) caknlistquerydialog (& Index );
If (DLG-> executeld (r_demo_list_query ))
{
// OK pressed, index is the selected item index.
}

Example of dynamically setting list items in a program
Tint index (0 );
Caknlistquerydialog * DLG = new (eleave) caknlistquerydialog (& Index );
Cdescarrayflat * aarray = new (eleave) cdescarrayflat (3 );
Tbuf <16> astring;

Astring. Format (_ L ("item % d"), 1 );
Aarray-> appendl (astring );
Astring. Format (_ L ("item % d"), 2 );
Aarray-> appendl (astring );
Astring. Format (_ L ("item % d"), 3 );
Aarray-> appendl (astring );

DLG-> preparelc (r_demo_list_query );
DLG-> setitemtextarray (aarray );
DLG-> setownershiptype (elbmownsitemarray );

If (DLG-> runld ()){}

3. In addition, the quick method for setting up simple and commonly used dialog boxes in Symbian does not need to use resources.

Static tbool ceikonenv: querywinl (const tdesc & afirstline, const tdesc & asecondline );
A dialog box with a specified text line is displayed. YES/NO is provided. If yes is selected, etrue is returned.

Static void ceikonenv: infowinl (const tdesc & afirstline, const tdesc & asecondline );
Display a dialog box with specified text lines

Static void ceikonenv: alertwinl (const tdesc & afirstline, const tdesc & asecondline );
Displays an alarm dialog box with specified text lines

1. Non-blocking prompt box
Symbian defines several prompt classes:
Confirm class: caknconfirmationnote
Info class: cakninformationnote
Warning class: caknwarningnote
Error class: caknerrornote
Header file: aknnotewrappers. h
Lib: avkon. Lib eikcdlg. Lib eikctl. Lib

Usage:

Code:
Tbuf <32> Buf;
Buf. Copy (_ L ("info note "));
Cakninformationnote * iinfonote = new (eleave) cakninformationnote;
Iinfonote-> executeld (BUF );

2. Blocking prompt box
Void ceikonenv: alertwin (const tdesc & amsg );
Void ceikonenv: alertwin (const tdesc & amsg1, const tdesc & amsg2 );
Static void ceikonenv: infowinl (const tdesc & afirstline, const tdesc & asecondline );

Alertwin is a non-static member function of the ceikonenv class, And infowinl is a static member function of the ceikonenv class.
Alertwin can only be used in the UI, view, and container. The usage is as follows:

Code:
Ieikonenv-> alertwin (_ L ("text "));

Infowinl can be used in any class as follows:
Code:
Ceikonenv: static ()-> infowinl (_ L ("Note:"), _ L ("text "));

For ease of use, macros are often defined to use such prompt boxes, such:

Code:
# Define debug_dialog (x) ieikonenv-> alertwin (# X );
# Define debug_dialog1 (x) ceikonenv: static ()-> infowinl (_ L ("Note:"), # X );
# Define debug_dialog2 (x, y) ceikonenv: static ()-> infowinl (##x, ## y );

This can be used as follows:
Tbuf <32> Buf;
Buf. Copy (_ L ("test "));
Debug_dialog (BUF );
Debug_dialog1 (BUF );
Debug_dialog2 (BUF, _ L ("text "));

This type of prompt box blocks the thread. Only after you press the button to exit the prompt box can subsequent programs run.

3. Progress bar dialog box
The progress bar dialog box is as follows:
Caknprogressdialog
Header file: aknprogressdialog. h
Lib: avkon. Lib eikcdlg. Lib eikctl. Lib

Usage:

Code:
// Initialization progress bar
Caknprogressdialog * iprogressdialog;
Ceikprogressinfo * iprogressinfo;
Iprogressdialog = new (eleave) caknprogressdialog (reinterpret_cast
<Ceikdialog **>
(& Iprogressdialog ));
Iprogressdialog-> setcallback (this );
Iprogressdialog-> preparelc (r_resource_progress_note); // create a dialog box from the resource file. for resources, see the definition below.
Iprogressinfo = iprogressdialog-> getprogressinfol ();
Iprogressinfo-> setfinalvalue (amaxvalue); // sets the maximum value of the progress bar (end value)
Iprogressdialog-> runld ();

// Update the progress bar
Iprogressinfo-> incrementanddraw (astep );

// End progress bar
Iprogressdialog-> processfinishedl ();
Delete iprogressdialog;

Resource dialog r_resource_progress_note // resource in the progress bar dialog box
{
Flags = eaknprogressnoteflags;
Buttons = r_avkon_softkeys_cancel;
Items =
{
Dlg_line
{
Type = eaknctnote;
Id = emagicboxctr1_progressnote;
Control = avkon_note
{
Layout = eprogresslayout;
Singular_label = "text displayed in the dialog box ";
Plural_label = "Download ";
Imagefile = avkon_bmp file_name; // in version 2, the icon file is # define avkon_bmp file_name.

"Z: // system // data // avkon. MBM"
Imageid = embmavkonqgn_note_sml; // you can change the two items to display different icons.
Imagemask = embmavkonqgn_note_sml_mask;
};
}
};
}

4. waiting dialog box
Classes to be used in the wait dialog box:
Caknglobalnote
Header file: aknglobalnote. h
Lib: aknnotify. Lib eiksrv. Lib

Usage:

Code:
// Display the waiting dialog box
Caknglobalnote * globalnote = caknglobalnote: newl ();
Cleanupstack: pushl (globalnote );
Tint iwaitnoteid = globalnote-> shownotel (eaknglobalwaitnote, _ L ("text displayed in the dialog box "));
Cleanupstack: popanddestroy ();

// End wait dialog box
Caknglobalnote * Note = caknglobalnote: newl ();
Cleanupstack: pushl (note );
Note-> cancelnotel (iwaitnoteid );
Cleanupstack: popanddestroy ();

Note:
In addition to the waiting dialog box, the caknglobalnote class can also display multiple types of global dialogs. The specific types can be specified by the first parameter of shownotel. The possible types are as follows:

Code:
Enum taknglobalnotetype
{
Eaknglobalinformationnote = 1,
Eaknglobalwarningnote,
Eaknglobalconfirmationnote,
Eaknglobalerrornote,
Eaknglobalchargingnote,
Eaknglobalwaitnote,
Eaknglobalpermanentnote,
Eaknglobalnotchargingnote,
Eaknglobalbatteryfullnote,
Eaknglobalbatterylownote,
Eaknglobalrechargebatterynote,
Eakncancelglobalnote,
Eaknglobaltextnote
};

5. Dialog Box
Classes used in the query dialog box:
Caknquerydialog
Header file: aknquerydialog. h
Lib: avkon. Lib

Usage:

Code:
Caknquerydialog * DLG;
DLG = caknquerydialog: newl (caknquerydialog: enotone );
DLG-> preparelc (r_resource_query_dialog); // create a dialog box from the resource file. for resources, see the definition below.
Tint ret = DLG-> runld (); // If "yes" is selected, non-0 is returned. If "no" is selected, 0 is returned.

Resource dialog r_resource_query_dialog // query Resources in the dialog box
{
Flags = egeneralqueryflags;
Buttons = r_avkon_softkeys_yes_no; // The CBA displays the "yes" and "no" buttons.
Items =
{
Dlg_line
{
Type = eaknctquery;
Id = egeneralquery;
Control = avkon_confirmation_query // indicates that this is the confirm query dialog box. Select "yes" or "no"
{
Layout = econfirmationquerylayout;
Label = "text displayed in the dialog box ";
};
}
};
}

This type of dialog box can have a sound prompt, which is specified by newl's const ttone & atone parameter. The possible values are as follows:

Code:
Enum ttone {
/// No tone is played
Enotone = 0,
/// A confirmation tone is played
Econfirmationtone = eavkonsidconfirmationtone,
/// A warning tone is played
Ewarningtone = eavkonsidwarningtone,
/// An Error tone is played
Eerrortone = eavkonsiderrortone
};

You can define different dialog box resources to implement different dialog boxes. For example, the resource definition of the dialog box for users to enter text is as follows:

Code:
Resource dialog r_resource_data_query
{
Flags = egeneralqueryflags;
Buttons = r_avkon_softkeys_ OK _cancel; // The CBA button displays "OK" and "cancel"
Items =
{
Dlg_line
{
Type = eaknctquery;
Id = egeneralquery;
Control = avkon_data_query // indicates that this is the data query dialog box. You need to enter the content
{
Layout = edatalayout;
Label = "prompt content ";
Control = Edwin
{
Flags = eeikedwinnohorizscrolling | eeikedwinresizable;
Width = 30;
Lines = 2;
Maxlength = 159;
};
};
}
};
}
Usage:

Code:
Tbuf <128> MSG;
Cakntextquerydialog * DLG = new (eleave) cakntextquerydialog (MSG, caknquerydialog: enotone );
Tint ret = DLG-> executeld (r_resource_data_query );

After the user inputs the content, press "OK", and the content is stored in MSG. The function returns non-0. Press "cancel" and the function returns 0.

The class used here is caknquerydialog, a subclass of cakntextquerydialog.
The subclasses of caknquerydialog include:

Code:
Caknfloatingpointquerydialog // This class shocould be used when user is reguest to enter a flotaing point number
Caknfixedpointquerydialog //...
Cakndurationquerydialog // This class shocould be used when user is reguest to enter duration
Caknipaddressquerydialog // This class shocould be used when user is reguest to enter IP address, @ since 2.1
Caknmultilinedataquerydialog // query dialog with data input on more than one line (2 lines at the moment)
Create using newl methods and passing parameters as appropriate.
Attention: When deriving from this class, you must call setdatal
Second phase construction.
Caknmultilineipquerydialog //...
Caknnumberquerydialog // This class shocould be used when user is reguest to enter number
Cakntextquerydialog // This class shocould be used when user is reguest to enter plain text, secret text,

Phonenumber or pin-code
Cakntimequerydialog // This class shocould be used when user is reguest to enter time or date

Resource files are different when different classes are used.

In addition, when defining Edwin in a resource, you can specify the input and output, for example:

Code:
Control = Edwin
{
Flags = eeikedwinnohorizscrolling | eeikedwinresizable;
Width = 11;
Lines = 1;
Maxlength = 11;
Avkon_flags = eakneditorflagfixedcase |
Eakneditorflagnot9 | eakneditorflagsupressshiftmenu; // disable the switching Input key.
Allowed_input_modes = eakneditornumericinputmode;
Default_input_mode = eakneditornumericinputmode;
Numeric_keymap = eakneditorplainnumbermodekeymap;
};

The above statement indicates that the default input method is a number, and the switch key of the input method is disabled. That is, the switch key of the input method cannot be used to switch the input method.

6. edit box
Class used in the edit box:
Ceikglobaltexteditor
Header file: eikgted. h

Usage:

Code:
Ceikglobaltexteditor * igkeyed;
Tbuf <128> ikeytext;
Tresourcereader reader;
Icoeenv-> createresourcereaderlc (reader, r_resource_editor); // create an edit box from the resource file. for resources, see the definition below.
Igkeyed = new (eleave) ceikglobaltexteditor;
Igkeyed-> setcontainer1_wl (* This );
Igkeyed-> constructfromresourcel (Reader );
Cleanupstack: popanddestroy (); // resource Reader

// Set the initial text and position of the editing box. The size of the editing box is defined in the resource.
Tbuf <32> Buf;
Buf. Copy (_ L ("Demo "));
Igkeyed-> settextl (& BUF );
Igkeyed-> setextent (tpoint (5, 2), igkeyed-> minimumsize ());
Igkeyed-> setfocus (etrue );
// Igkeyed-> setreadonly (etrue); // The edit box is read-only.

// Center the text
Cparaformat paraformat;
Tparaformatmask paraformatmask;
Paraformatmask. setattrib (eattalignment); // set mask
Paraformat. ihorizontalalignment = cparaformat: ecenteralign;
Igkeyed-> applyparaformatl (& paraformat, paraformatmask );

Igkeyed-> gettext (ikeytext); // obtain the content in the edit box and save it to ikeytext.

Resource gtxted r_resource_editor // edit box resource
{
Flags = eakneditorflagdefault;
Width = 53;
Height = 16;
Numlines = 1;
Textlimit = 1;
Fontcontrolflags = egulfontcontrolall;
Fontnameflags = egulnosymbolfonts;

// The input method can also be set here
// Avkon_flags = eakneditorflagfixedcase |
Eakneditorflagnot9 | eakneditorflagsupressshiftmenu; // eakneditorflagsupressshiftmenu

Mask Switch Input key
// Allowed_input_modes = eakneditornumericinputmode;
// Default_input_mode = eakneditornumericinputmode;
// Numeric_keymap = eakneditorplainnumbermodekeymap;
}

Note: To display the edit box properly, remember to change the countcomponentcontrols and componentcontrol functions of the container to correctly process the number of controls and the edit box pointer. In addition, to enable the edit box to normally receive button events, you must call the edit box's offerkeyeventl function, as shown below:

Code:
Tkeyresponse cmobileguardsetkeycontainer: offerkeyeventl (const tkeyevent & akeyevent, teventcode Atype)
{
Return igkeyed-> offerkeyeventl (akeyevent, Atype );
}

Standard dialog box
The dialogs in Symbian OS are inherited from cakndialog. Most dialogs are a container that can accommodate other controls. The following example shows how to define a dialog box with an edit box in the resource file:
Resource dialog r_dialog_edit_dialog
{
Flags = eeikdialogflagnodrag | eeikdialogflagcbabuttons | eeikdialogflagwait;
Buttons = r_avkon_softkeys_ OK _cancel;
Items = {
Dlg_line
{
Id = econfirmationnotedlgcidfilename;
Type = eeikctlabel;
Control = label {};
},
Dlg_line
{
Id = econfirmationnotedlgcideditor;
Type = eeikctedwin;
Control = Edwin {maxlength = 20 ;};
}
};
}
Dialog has the following attributes to be set:
1. Flag attributes. Define the nature of the dialog box. In this example, three attributes are defined: eeikdialogflagnodrag (do not drag), eeikdialogflagcbabuttons (Use soft keys ),

Eeikdialogflagwait (wait ). These flags are defined in uikon. HRH.
2. Buttons attributes. Specifies the soft key used in the dialog box. Defined in avkon. RSG.
3. Items attributes. Defines the content actually contained in the dialog box. Items consists of some dlg_line, each of which contains a control.
4. The dlg_line attribute. Indicates each row of the dialog box. The control is usually composed of ID, type, and control.

After defining the dialog box in the resource file, you can compile the dialog box class. All the dialog classes of Symbian OS are inherited from cakndialog. The header file akndialog. h must be included.

The following are several important functions of cakndialog:
1. prelayoutdyninitl () to complete the initialization before the dialog box is loaded. In the dialog box, controls are initialized in this function. In the dialog box, the member function controlornull () is used to obtain the control pointer through ID. If the ID exists, the ccoecontrol pointer is returned. If not, null is returned. You can use the control () function to obtain the control pointer. Unlike controlornull (), if the ID does not exist, control () returns an error.
2. oktoexitl (), click the OK key (eaknsoftkeyok), and call this function before exiting the dialog box to obtain the control data in the dialog box.
3. Static function tbool rundlgld (), which contains the first-order constructor executeld () in the dialog box. This function is used to construct, display, and destroy the dialog box. To display the dialog box in the program, you only need to call cxxxdialog: rundlgld.
Tbool csimpledialog: rundlgld ()
{
Csimpledialog * dialog = new (eleave) csimpledialog ();
Return dialog-> executeld (r_dialog_edit_dialog );
}
Executeld () calls two functions of cakndialog: preparelc () and runld (). Preparelc () is responsible for placing the dialog box pointer to the cleaning stack to complete the dialog box construction.

Runld () is used to display the dialog box.

Usage of pending notifications and progress notifications
Maknbackgroundprocess has four interface functions.
Void dialogdismissedl (tint/* abuttonid */);
Tbool isprocessdone () const;
Void processfinished ();
Void stepl ();
A maknbackgroundprocess corresponds to a cactive
It should be used with caknwaitnotewrapper. After caknwaitnotewrapper calls the execution method. The specified dialog box is displayed, and you are constantly asked if isprocessdone () is used (). If isprocessdone ends the wait of the dialog box. First, you need to define a dialog box
Resource dialog r_waitnote_load_image_note
{
Flags = eaknwaitnoteflags;
Items =
{
Dlg_line
{
Type = eaknctnote;
Id = enotedlgcidopenimagenote;
Control = avkon_note
{
Layout = ewaitlayout;
Singular_label = "load image, please wait ";
Imagefile = "Z: // system/data/avkon. MBM ";
Imageid = embmavkonqgn_note_progress;
Imagemask = embmavkonqgn_note_progress_mask;
Animation = r_qgn_graf_wait_bar_anim;
};
}
};
}
Add the following to your code:
Caknwaitnotewrapper * waitnotewrapper = caknwaitnotewrapper: newl ();
// Required reinterpret_cast as caknwaitnotewrapper inherits privately From cactive
Cleanupstack: pushl (reinterpret_cast <cbase *> (waitnotewrapper ));

Tint result = 0;
Result = waitnotewrapper-> executel (r_waitnote_load_image_note, * This );
If (! Result) // This is a blocking call, remember the wrapper isn't a dialog, so it

Doesn' t need the eeikdialogflagwait flag to make it Blocking
{
// Cancel
}
Cleanupstack: popanddestroy ();
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.