Introduction to the Symbian learning dialog box

Source: Internet
Author: User

The base class of the symbain OS dialog box is the ceikdialog class defined in uikon. On this basis, various dialog box classes are encapsulated on each interface platform, for example, avkon of s60 defines the cakndialog class as the base class of the s60 dialog box, while the uiq platform still uses the ceikdialog class as the base class of the dialog box, however, it encapsulates the uiq platform-specific dialog box classes such as cqiksavefileinfolderdlg.

In uikon, ceikdialog implements three interfaces, including:

Mcoecontrolobserver: The Observer interface of the subcontrol in the dialog box. When the subcontrol status changes, the handlecontroleventl () function of the subcontrol is called.

Meikdialogpageobserver: In the multi-page dialog box, you can observe the page changes by implementing this interface.

Mcoecontrolcontext, an interface for sharing the graphical context between multiple controls.

The biggest difference between the cakndialog class and the ceikdialog class is that the former can have menus and correspondingly implements the meikmenuobserver interface, which is used to observe menu status changes.

Cakndialog is the base class of most series60 dialogs. The usage of the dialog box is roughly divided into the following steps: 1. Define resources. 2. Execution dialog box. 3. dynamically initialize the standard dialog box. 4. Exit the dialog box.

1. Define Resources

Use Dialog to define resources. The resource specifies the layout of the dialog box. In the resource, define the number of lines in the dialog box, the controls used, whether the dialog box is modal, and the soft keys used. The resource structure is defined in Eikon. Then:

Struct Dialog

{

Long flags = 0;

Ltext Title = "";

Llink pages = 0;

Llink buttons = 0;

Struct item [];

Llink form = 0;

}

Flags: Describes the properties of the dialog box. For more information about the attribute values, see.

# Define eeikdialogflagwait // wait dialog box

# Define eeikdialogflag1_yesc // exit notification. The oktoexit () function is called in the dialog box when a soft key is selected.

# Define eeikdialogflagbuttonsbelow

# Define eeikdialogflagbuttonsright

# Define eeikdialogflagnouserexit // you are not allowed to select the exit dialog box, that is, no soft key is displayed.

# Define eeikdialogflagmodeless // No Mode dialog box, use this

# Define eeikdialogflagnotitlebar // No title bar

# Define eeikdialogflagallkeystobuttons

# Define eeikdialogflagfillscreen

# Define eeikdialogflagnodrag // do not drag

# Define eeikdialogflagdensepacking

# Define eeikdialogflagnobackup

# Define eeikdialogflagfillappclientrect // the dialog box occupies the entire main panel

# Define eeikdialogflagcbabuttons // use the CBA button

# Define eeikdialogflagnoborder

# Define eeikdialogflagnoshadow

It is a good habit to define a standard dialog box as a waiting dialog box. The standard dialog box should be defined as non-waiting only when appropriate (for example, in the main application window.

Title: The title bar Text of the dialog box.

Pages: Page resource ID in the Multi-page dialog box

Buttons: Specifies the used soft key (the ID of the button resource). For the value, see

# Define r_avkon_softkeys_empty

# Define r_avkon_softkeys_empty_with_ids

# Define r_avkon_softkeys_ OK _empty

# Define r_avkon_softkeys_select_cancel

# Define r_avkon_softkeys_ OK _cancel

# Define r_avkon_softkeys_ OK _details

# Define r_avkon_softkeys_call_cancel

# Define r_avkon_softkeys_options_back

# Define r_avkon_softkeys_options_done

# Define r_avkon_softkeys_options_cancel

# Define r_avkon_softkeys_options_exit

# Define r_avkon_softkeys_ OK _back

# Define r_avkon_softkeys_cancel

# Define r_avkon_softkeys_back

# Define r_avkon_softkeys_close

# Define r_avkon_softkeys_done_back

# Define r_avkon_softkeys_done_cancel

# Define r_avkon_softkeys_select_back

# Define r_avkon_softkeys_mark_back

# Define r_avkon_softkeys_unmark_back

# Define r_avkon_softkeys_yes_no

# Define r_avkon_softkeys_unlock_empty

# Define r_avkon_softkeys_save_back

# Define r_avkon_softkeys_show_cancel

# Define r_avkon_softkeys_show_exit

# Define r_avkon_softkeys_answer_exit

# Define r_avkon_softkeys_exit

# Define r_avkon_softkeys_read_exit

# Define r_avkon_softkeys_listen_exit

# Define r_avkon_softkeys_search_back

# Define r_avkon_softkeys_again_quit

# Define r_avkon_softkeys_quit

# Define r_avkon_softkeys_insert_back

Items: it defines the actual content contained in the dialog box. You need to define a dlg_line for each control that you want to include in the dialog box, which is also defined in Eikon. RH. You should specify at least the following fields in each dlg_line:

* ID: use this value in the application to reference this dialog box line. It must be enumerated in the. HRH file of the application.

* Type: Type of the control contained in the dialog box (defined in avkon. HRH or uikon. HRH ).

* Control: controls used in this dialog box.

In addition, you can specify an itemflags field in the dlg_line resource to use this field to determine the row behavior of the dialog box. For example, the pop-up field text control can use itemflags to indicate that a pop-up window should be opened when the "select" Key is pressed, for example, eeikdlgitemtakesenterkey | eeikdlgitemofferallhotkeys. You can find the itemflags value in uikon. HRH. The most common is the eeikdlgitemseparatorbefore flag, which is used to insert a horizontal "separator" line before the dialog box line.

In this section, the mysimpledlg sample program defines a simple dialog box for displaying a tag. The resources defined in. RSS are as follows:

Resource dialog r_simpledlg_dialog

{

Flags = eeikdialogflagnodrag | eeikdialogflagnotitlebar | eeikdialogflagfillappclientrect |

Eeikdialogflagcbabuttons | eeikdialogflagwait | eeikdialogflag1_yesc;

Buttons = r_avkon_softkeys_ OK _cancel;

Items =

{

Dlg_line

{

Id = esimpledlgctllabel; // the ID of the Child control (defined in. HRH below)

Type = eeikctlabel; // type of the Child Control

Control = label // resource definition of the child Control

{

TXT = "this is a simple dialog ";

};

}

};

}

In addition, it must be defined in. HRH:

Enum tsimpledlgcontrolids

{

Esimpledlgctllabel = 1

};

2. Execution dialog box

In C ++ code, the ceikdialog: executeld () function execution dialog box is generally used. This function is defined in eikdialg. h:

// Eikdiag. h

...

Public:

Virtual tint executeld (tint aresourceid );

....

The aresourceid parameter of the function is the resource ID of the execution dialog box. If the attribute value of the dialog box contains eeikdialogflagwait, it indicates a waiting dialog box. In this case, the executeld () function is suspended, this function is returned only after the dialog box is closed. For the non-Wait dialog box, this function will return immediately. The dialog box will delete itself at the end of executeld.

In this section, the mysimpledlg program creates a cakndialog object and calls its executeld () function. The Code is as follows:

// Mysimpledlgappui. cpp

# Include

....

Void cmysimpledlgappui: handlecommandl (tint acommand)

{

Switch (acommand)

{

...

Case esimpledlg1_dialog: // defined in. RSS and. HRH below

{

Ieikonenv-> infomsg (_ L ("test "));

Cakndialog * dialog = new (eleave) cakndialog; // create a dialog box object

If (dialog-> executeld (r_simpledlg_dialog) // execute the dialog box and determine the return value.

{

_ Encrypt (kbuttonok, "OK ");

Ieikonenv-> infomsg (kbuttonok ());

}

Else

{

_ Cancel (kbuttoncancel, "cancel ");

Ieikonenv-> infomsg (kbuttoncancel ());

}

Break;

}

........

// Todo: add your command handling code here

Default:

Break;

}

}

So why didn't I push it into the clear stack after new? Because executeld () has the ownership of the change dialog box, this method encapsulates the call to the other two methods: preparelc () and runld (). Preparelc () puts the pointer of the dialog box into the clear stack, and then creates the dialog box. Runld () displays the dialog box and then pops up from the clear stack. However, if you need to call any code that may cause abnormal exit before calling executeld (), you should put it in the clearing stack and bring it up before calling executeld. However, if the dialog box is not waiting, it will be returned directly from executeld () without being deleted.

Define the esimpledlg1_dialog in the. RSS and. HRH files:

// Mysimpledlg. RSS

Resource menu_pane r_mysimpledlg_menu

{

Items =

{

Menu_item {command = esimpledlgcmddialog; TXT = qtn_appl_dialog ;},

Menu_item {command = esimpledlg1_prepare; TXT = qtn_appl_prepare ;},

Menu_item {command = esimpledlg1_prelayout; TXT = qtn_appl_prelayout ;},

Menu_item {command = eakncmdexit; TXT = qtn_appl_exit ;}

};

}

// Mysimpledlg. HRH

Enum tmysimpledlgcommandids

{

Esimpledlg1_dialog = 1,

Esimpledlg1_prepare,

Esimpledlg1_prelayout

};

3. Dynamic Standard initialization dialog box

The subcontrol of the dialog box is assigned an initial value during definition, but in some cases, the application needs to change the value of the subcontrol according to the situation before executing the dialog box. There are two methods:

First: Use the preparelc () function and runld () function

The executeld () function first calls the preparelc () function to load the dialog box from the resource, and then calls the runld () function to bring up the dialog box. Therefore, you can add the code of the initialization dialog box between the two functions, in this section, mysimpledlg sample program mysimpledlgappui. the code in the CPP file is as follows:

# Include

Void cmysimpledlgappui: handlecommandl (tint acommand)

{

Switch (acommand)

{

......

Case esimpledlg1_prepare:

{

Cakndialog * dialog = new (eleave) cakndialog;

Dialog-> preparelc (r_simpledlg_dialog); // load the dialog box from the resource file

Ceiklabel * label = static_cast (dialog-> Control (esimpledlgctllabel); // obtain the pointer of the subcontrol in the dialog box

_ Resolve (kmylabel, "changed after preparelc ()");

Label-> settextl (kmylabel (); // modify the sub-Control Value

Dialog-> runld ();

Break;

}

.......

// Todo: add your command handling code here

Default:

Break;

}

}

Note: you must add eikdlg. lib to The. MMP file.

Method 2: Use the prelayoutdyninitl () function or the postlayoutdyninitl () function

This method requires a custom dialog box class and reloads the ceikdialog: prelayoutdyninit () and ceikdialog: postlayoutdyninitl () functions. Both functions are virtual functions, which will be called before the dialog box is displayed. The prelayoutdyninitl () function is called to complete the control layout after the dialog box is completed. Therefore, this function is often used to complete initialization operations that may affect the dialog box layout, such as creating a new control. After the dialog box is laid out, the postlayoutdyninitl () function is called to perform operations that do not affect the layout of the dialog box, such as assigning values to controls.

In this section, the mysimpledlg sample program customizes a dialog box cmysimpledialog class, which overload the prelayoutdyninitl () function. The main code of mysimpledialog. cpp is as follows:

# Include // For ceikonenv

# Include // For example label Control

# Include "mysimpledlg. HRH"

Void cmysimpledialog: prelayoutdyninitl ()

{

Ceiklabel * label = static_cast (Control (esimpledlgctllabel); // obtain the control pointer through the ceikdialog: control () function

_ Resolve (kmylabel, "changed by prelayoutdyninitl ()");

Label-> settextl (kmylabel ());

}

Using this method, you can directly call the executeld () function execution dialog box. The mysimpledlgappui. CPP Code is as follows:

# Include // For ceiklabel

# Include

# Include // dialog box header file

# Include "mysimpledialog. H" // For cmysimpledialog

.....

Void cmysimpledlgappui: handlecommandl (tint acommand)

{

Switch (acommand)

{

......

Case esimpledlg1_prelayout:

{

Cakndialog * dialog = new (eleave) cmysimpledialog; // create a custom dialog box

Dialog-> executeld (r_simpledlg_dialog); // execution dialog box

Break;

}

// Todo: add your command handling code here

Default:

Break;

}

}

Note: when using the vc6.0 development environment for Symbian, it is best to add new classes. put the H header file in the INC folder ,. place the CPP source file in the SRC folder (to ensure consistency. add the source file to the MPs file, as in this chapter. the following code is added to the MPs:

Source mysimpledialog. cpp

Finally, re-compile.

4. Exit dialog box

When the eeikdialogflag1_yesc tag is specified for the dialog box resource, the dialog box calls the ceikdialog: oktoexitl () function when the user presses the soft key. Therefore, you can reload the ceikdialog: oktoexitl () function in the Custom dialog box. When the function returns etrue, the dialog box exits and is destroyed by the system. Returns efalse.

The dialog box is retained.

 

In this section, the custom dialog box cmysimpledialog class in the mysimpledlg sample program, this class reloads this function, the Code is as follows:

# Include // For ceikonenv

Tbool cmysimpledialog: oktoexitl (tint abuttonid)

{

// Call the oktkexitl () function of the base class to complete the default function, such as a pop-up menu.

Tbool ret = cakndialog: oktoexitl (abuttonid );

Ceikonenv * Env = ceikonenv: static ();

If (abuttonid = eeikbidok) // The left soft key is selected.

{

_ Values (koktoexit, "OK to exit ");

Env-> infomsg (koktoexit ());

}

Else if (abuttonid = eeikbidcancel) // you have selected the right soft key.

{

_ Values (kcanceltoexit, "Cancel to exit ");

Env-> infomsg (kcanceltoexit ());

}

Return ret; // return the return value of the cakndialog: oktoexitl () function

}

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.