03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Simply put, the dialog has a title, standard OK and Cancel buttons, some flags, and some<br />

items. In keeping with guidelines for positioning buttons, the Cancel/OK buttons are<br />

indicated by the resource name R_EIK_BUTTONS_CANCEL_OK.<br />

Almost all dialogs should be coded with the line flags = EEikDialogFlagWait, which<br />

makes the dialog modal.<br />

Note<br />

Regrettably, this is not the default. The default behavior is that your<br />

application can continue executing while the dialog is displayed. This isn't<br />

quite the same as a nonmodal dialog. Nonwaiting dialogs are typically used<br />

for activities like progress monitoring, in which the application is busy while<br />

the dialog is being displayed. Because the application is busy, it doesn't<br />

accept user input, so a nonwaiting dialog is effectively modal.<br />

The body of the dialog is a vertical list of controls, each of which has<br />

� a caption or prompt, such as Text;<br />

� an ID, such as EExampleControlIdText;<br />

� a type, such as EEikCtEdwin, which may have some initialization data of a format<br />

corresponding to the type, such as EDWIN { width= 25; maxlength = 256; }.<br />

Don't use too many controls. As far as C++ is concerned, there is no limit, but in UIQ, for<br />

example, more than eight won't fit nicely onto a screen only 320 pixels high. If you code too<br />

many controls, the dialog becomes scrollable, and the user will have to scroll it to see all the<br />

controls. The dialog begins to overwhelm users with too much choice, making it hard to use.<br />

In some UIs, having too many controls will cause the dialog to overflow the screen, making it<br />

effectively unusable.<br />

The prompt serves to identify its purpose to the user, while the ID identifies the control to the<br />

programmer. Later, we'll see that control IDs are used by C++ programs to specify the<br />

controls whose values they want to set or read. Like command IDs, control IDs are defined<br />

in the application's .hrh file, so they can be accessed both by resource file definitions and<br />

C++ programs.<br />

One of the controls used here, EEikCtEdwin, is an edit window; the EDWIN resource<br />

STRUCT is required to initialize such a control. In this example, I specify the size of the<br />

control (25 characters) that affects the dialog layout, and the maximum length of the data<br />

(256 characters).<br />

10.2.2 Dialog Code<br />

The base class for all dialogs is CEikDialog. Any dialog you write in your application will<br />

derive from CEikDialog, and it will typically implement at least two member functions – one<br />

for initializing the dialog and one for processing the OK key (or the DONE key that is often<br />

used in UIQ).<br />

'Read-only' dialogs, for displaying application data, need only implement the initialization<br />

function. Ultra-trivial dialogs, initialized entirely from resource files, needn't even implement<br />

the initialization function. More complex dialogs can implement many functions besides the<br />

two shown below: we'll return to this later on. All CEikDialog virtual functions have a donothing<br />

default implementation: you only override them if necessary.<br />

The following code extract shows the declaration of CExampleWrite-FileDialog,from<br />

streams.cpp:<br />

Note<br />

That's right: streams.cpp, not streams.h. I've treated dialogs as being

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!