Wiley.Developing.Software.for.Symbian.OS.2nd.Edition.Dec.2007 (779887), страница 76
Текст из файла (страница 76)
You can supplydefault data to the text edit box by initializing text to some default databefore calling CAknTextQueryDialog::NewL().SYMBIAN OS CONTROLS405Other S60 query dialogs include:•CAknNumberQueryDialog – used for entering an integer.•CAknTimeQueryDialog – used for entering a date/time query.•CAknListQueryDialog – used for entering a query that requires aselection from a list (setting DLG LINE control attribute to AVKONLIST QUERY for a single selection list, and AVKON MULTI- SELECTION LIST QUERY to allow multiple selections).Below are classes that are referred to as wrappers in S60, since theyrequire no resource to be defined, and thus are simple to use.• CAknConfirmationNote – allows the user to confirm an action, asin the following example:HBufC* msg =CCoeEnv::Static()->AllocReadResourceAsDes16L(R_MSG_DELETE_PENDING);CAknConfirmationNote* note = new(ELeave) CAknConfirmationNote();note->ExecuteLD(*msg);delete msg;•CAknInformationNote – used in a similar way to the above dialog,but displays an information note.•CAknErrorNote – displays an error message.•CAknWaitDialog – used to wait for a process to complete.•CAknProgressDialog – indicates the progress of a long-runningprocess.12.6 Symbian OS ControlsSymbian OS has a large variety of GUI controls available.
Many arecommon to all platforms, and others are specific to the particular UIplatform you are using. As we saw in the dialog example, you need toknow the following to use a control:•The RESOURCE structure to use for the control, and the appropriateattributes to set. The resource structures of all the common controlsare in uikon.rh and eikon.rh. UIQ-specific control structures arein Qikon.rh, and S60-specific controls are in avkon.rh.•The name of the control type identifier to use as the type attribute ofthe DLG LINE (e.g., type=EEikCtEdwin for a text edit control).406GUI APPLICATION PROGRAMMING•The class of the control, and its class-specific methods, includingthose to write data to and retrieve data from the control.•The header file to include for using the control class, and the libraryto link to.Note that, although it is most common to implement controls usingresource definitions within a dialog resource’s DLG LINE structure, thereare other options as well.
For example, your control could have its own,separate RESOURCE identifier, and you can use code to insert it into adialog, or directly into a view. Alternatively, you can incorporate thecontrol into your program without using a resource definition at all, usingcontrol-specific methods to set the control’s attributes.12.6.1 Types of ControlThis section gives a tour of some of the main control types.
It is notexhaustive, but the SDK documentation contains a complete list ofavailable controls.Edit controlsEdit controls allow the user to enter a piece of data of a specific type. Awide variety of edit controls exist, including text editors, number editors,calendar editors, date and time editors, duration editors, secret editors,PIN editors, color editors, IP address editors, and more.For example, we have seen the text editor, which uses resource structure EDWIN, control type identifier EEikCtEdwin, and class CEikEdwin. Its key methods are SetText() to write initial text into the editorand GetText() to retrieve the contents of the editor.List boxesList boxes are very common in Symbian OS software, and a wide varietyof list box types exist. These include, amongst others, single and multiplesection boxes, list boxes with graphics, numbered list boxes, double listboxes, and settings list boxes (where you can change the value of eachentry).List boxes use the LISTBOX resource structure, which is defined as:STRUCT LISTBOX{BYTE version=0;WORD flags = 0;WORD height = 5;WORD width = 10;LLINK array_id = 0;}// in items// in charsSYMBIAN OS CONTROLS407The flags attribute specifies the characteristics of the list (for example,EEikListBoxMultipleSelection means that the user can selectmultiple options in the list), and height and width specify the list’ssize.
array id points to an array resource of text items to displayin the list. Alternatively, you can leave this array id at 0 and buildyour own array in code, using class methods (such as Model() ->SetTextItemArray()) to associate the array with the list box.List box classes are ultimately derived from CEikListBox. The mainclasses available are:•CEikTextListBox (control type EEikCtListBox) – this is thebasic text list box.•CEikColumnListBox (control type EEikCtColListBox) –displays cells that are grouped in columns.•CeikHierarchicalListBox – displays a hierarchical list, whereitems can be expanded or collapsed.In UIQ, you usually use the above classes directly. List boxes are rarelyused in UIQ dialogs (choice lists are used instead), and list boxes aremost often added directly to your application view.In S60, you can use list box query dialogs as an alternative to includinga list box control in a dialog. S60 provides a number of specific classesfor the various types of list boxes.
For example:•CAknSingleStyleListBox (control type EAknCtSingleListBox) is a standard single-selection list box.•CAknSingleGraphicsStyleListBox (control type EAknCtSingleGraphicsListBox) allows you to include graphics in asingle-selection list box.There are many more list box classes to choose from – refer to the SDKdocumentation for the complete list.Progress barsA progress bar control uses a PROGRESSINFO resource structure, togetherwith a control type of EEikCtProgInfo and class CEikProgressInfo. You use this to provide user feedback on the progress of along-running process. The control gives a graphical representation ofprogress, as well as text showing the percentage (or fraction) completed.In S60, you usually display the progress bar using a dedicated dialog(class CAknProgressDialog) known as the progress note dialog.408GUI APPLICATION PROGRAMMINGOption buttonsAlso known as radio buttons, option buttons allow you to select oneoption from a small list of choices.UIQ has a vertical option list (class CQikVertOptionButtonList,resource structure QIK VERTOPBUT, type EQikCtVertOptionButtonList) and a horizontal option list (class CQikHorOptionButtonList, resource structure QIK HOROPBUT, type EQikCtHorOptionButtonList).You can also use option buttons in menus.
In this case, you needto indicate the position of each button, relative to the other buttonsin the sequence, by specifying one of EEikMenuItemRadioStart,EEikMenuItemRadioMiddle, or EEikMenuItemRadioEnd in theflags field of each button’s MENU ITEM structure. Use CEikMenuPane::SetItemButtonState() to set which button is selected.Check boxesCheck boxes allow you to select or deselect a particular item by checkingit or not.
You can use these to allow multiple selections of options froma list, or as a single enable/disable type field for a particular applicationsetting.Check box controls use a control type of EikCtCheckBox and classCEikCheckBox (methods SetState() and State(), respectively setand get the state of the check box). No resource structure is needed.Choice listA choice list allows you to select an item from a list of text options. Thecontrol displays a single item at a time, and pops up the list only whilethe user is changing the control value. Choice lists are supported in UIQ,but not in S60.The choice list uses a control type of EEikCtChoiceList, classCEikChoiceList, and resource structure CHOICELIST. As with listboxes, a choice list allows you either to specify the array of choicesin the resource file or to attach a list programmatically, using CEikChoiceList::SetArrayL().Combo boxA combo box is similar to a choice list, except that the user can also entertext into the control field, as well as select an item from the list (hencethe name: the control is a combination text editor and choice list).The combo box uses control type EEikCtComboBox, class CEikComboBox, and resource structure COMBOBOX.APPLICATION ICON AND CAPTION409As with choice lists and list boxes, you can set the array either in theresource or via EEikComboBox::SetArrayL().
Use class methodsSetTextL() and GetTextL() to set text to and retrieve text from thecontrol.12.7 View ArchitectureSymbian OS permits you to define multiple views for a single application,and allows you to switch between them. This means that you can, forexample, present application data to the user in various different ways.Each view is registered with its own identifier, and then the applicationcan switch between them in response to user events. It is also possiblefor one application to switch to the view of another. A view can have itsown set of commands and its own command handler.In theory, an application is not required to use the view architecture(and in fact our SimpleEx S60 example does not), however, with UIQ(UIQ version 3 specifically), its architecture depends so much on it that itis basically required (although our SimpleEx example contains just oneview).The view class for UIQ, as we have seen, is CQikViewBase.
Theview class for S60 is CAknView. Once you have set up your viewclasses properly, you can register them, set one as the default, and switchbetween them at will. For detailed information on creating and managingviews, reference [Harrison], as well as the SDK documentation.12.8 Application Icon and CaptionSymbian OS associates an icon as well as a caption with your application.You can supply an application caption and one or more icon bitmapsto represent the application by including a special resource file knownas a localized application information resource file (typically named<application name> loc.rss).