| United States-English |
|
|
|
![]() |
Common Desktop Environment: Programmer's Guide > Chapter 8 Invoking
Actions from Applicationsactions.c Example Program |
|
This section describes a simple example program, actions.c. A complete listing of actions.c is at the end of this chapter. Before your application can invoke an action, it must initialize the Desktop Services library (which contains the action invocation API) and load the database of action and data-type definitions.
If you use DtDbLoad() in a long-lived application, it must dynamically reload the database whenever it is modified.
Callback_proc cleans up any cached database information your application is holding and then invokes DtDbLoad(). Client_data may be used to pass additional client information to the callback routine. Your application accesses the database if it needs to display the icon or label for an action. Also before invoking an action, your application can check that it exists. An action is identified in the database by the action name:
For example, the action definition for the Calculator looks like this:
The action name for the Calculator action is Dtcalc. When an executable file has a file name that matches an action name in the existing database, that file is an action file—a representation for the underlying action. The information about the icon and label for that file are stored in the database.
An action definition specifies the icon image used to represent the action in the definition's ICON field:
DtActionIcon() returns a character string containing the value of the icon image field. If the action definition does not contain an icon field, the function returns the value of the default action icon image, Dtactn. You then need to determine the location of the icon, and the size you want to use. Icons can exist in four sizes and are available in bitmap or pixmap form. For example, you can find the base name of the icon file from the action definition for the Calculator. You then use the base name coupled with the information given in Table 8-1 “Icon Sizes and File Names” and knowledge of the location of all the icons to find the specific icon file you want. The icon name for the calculator action is Dtcalc, but that is not the entire file name. Icon file names are based on the size of the icon. Table 8-1 “Icon Sizes and File Names” shows the sizes and file-naming conventions for the desktop icons. Table 8-1 Icon Sizes and File Names
For bitmaps, there is an additional file that is used as a mask, and its extension ends with _m.bm. Thus, there can be a total of three files for each size icon. Here are the icon files for the calculator:
DtActionIcon() returns only a base name; for the Calculator it is Dtcalc. You must choose the type (pixmap or bitmap) and size (tiny, small, medium, or large) and append the applicable extension to the base name. In addition, you must know where the file resides. An action definition may include a label. The label is defined using the label_text field:
This label is used in graphical components (such as File Manager and the Application Manager) to label the action's icon. If an action definition does not include a label_text field, the action_name is used. The value of label_text string should be used by all interface components to identify the action to the end user. The DtActionLabel() function returns the value of the label_text field in the action definition of the action named actionName. If the label_text field does not exist, the function returns the actionName. After your application has initialized the Desktop Services Library it can then invoke an action. DtActionInvoke() searches the action database for an entry that matches the specified action name, and accepts arguments of the class, type, and count provided. Remember that your application must initialize and load the database before invoking an action. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||