Xt get application resources example

From Motif 2. RenderTables are fully described in Chapter 24 ; briefly, a RenderTable describes a complete style by which a compound string can be rendered. In Motif 2. These and other aspects of rendering compound strings are described in the following sections. Under this model, an application uses a library that reads a customization database at run-time to get information about the user's language environment.

The language procedure returns a language string that is used by XtResolvePathname to find locale-specific resource files. See Volume 4, X Toolkit Intrinsics Programming Manual , for more information on the localization of the resource database. One of the important characteristics of a language environment is the encoding that is used to represent the character set for the particular language.

In X, character set simply refers to a set of characters, while an encoding is a numeric representation of these characters. The first half of Latin-1 is standard ASCII, while the second half with the eighth bit set contains accented characters needed for Western languages other than English. However, not all languages can be represented by a single charset. Japanese text commonly contains words written using the Latin alphabet, as well as phonetic characters from the katakana and hirigana alphabets, and ideographic kanji characters.

Each of these character sets has its own charset; the phonetic and Latin charsets are 8-bits wide, while the ideographic charset is bits wide. The charsets must be combined into a single encoding for Japanese text, so the encoding uses shift sequences to specify the character set for each character in a string. Strings in an encoding that contains shift sequences and characters with non-uniform width can be stored in a standard NULL -terminated array of characters; this representation is known as a multibyte string.

Strings can also be stored using a wide-character type in which each character has a fixed size and occupies one array element in the string. The text output routines in X11R5 support both multibyte and wide-character strings. To support languages that use multiple charsets, X developed the XFontSet abstraction for its text output routines.


  • X/Motif Programming | Linux Journal.
  • le migliori app per smartphone android gratis.
  • ?
  • You May Like;
  • lose it app for smartphone.
  • !

An XFontSet contains all of the fonts that are needed to display text in the current locale. The new text output routines work with font sets, so they can render text for languages that require multiple charsets. See Volume 1, Xlib Programming Manual , for more information on internationalized text output. With the addition of these features in X, a developer can write an internationalized application without using the internationalization features provided by compound strings.

In an internationalized application, strings are interpreted using the encoding for the current locale. To support a number of locales, the application needs to store string data in separate files from the application code. The application must provide a separate file for each of the locales supported, so that the program can read the appropriate file during localization.

However, since most Motif widgets use compound strings for representing textual data, a Motif application has to use compound strings to display text. As we describe compound strings in this chapter, we'll discuss how to use them so as not to interfere with the lower-level X internationalization features. However, since Rendition objects in Motif 2. Creating Compound Strings Almost all of the Motif widgets use compound strings to specify textual data. Labels, PushButtons, and Lists, among others, all require their text to be given in compound string format, whether or not you require the additional flexibility compound strings provide.

The only widgets that don't use compound strings are the Text and TextField widgets 2. As a result, you cannot use the compound string techniques for displaying text using multiple fonts. However, these widgets do support internationalized text output, so they can display text using multiple character sets. For information on the internationalization capabilities of the Text and TextField widgets, see the Text Widget Internationalization Section of Chapter A compound string XmString is made of three components: The tag is an arbitrary name that the programmer can use to associate a compound string with particular rendition data.

In Motif 1. Since the tag doesn't necessarily specify a character set, Motif 1. A render table consists of rendition objects: One of the things which a rendition object contains is a font. Renditions and Render Tables can be shared between, and inherited from, other widgets. An application can create a compound string that uses multiple fonts by concatenating separate compound strings with different rendition tags to produce a single compound string.

Concatenating compound strings with different renditions is a powerful way to create graphically interesting labels and captions. More importantly, because renditions and render tables are loosely bound to compound strings via resources, you can dynamically associate new renditions with a widget while an application is running and effectively change text styles on the fly. The Simple Case Many applications only need to use compound strings to specify various textual resources. In this case, all that is needed is a routine that converts a standard C-style NULL -terminated text string into a compound string.

The most basic form of conversion can be done using the XmStringCreateLocalized function, as demonstrated in examples throughout this book. This routine takes the following form: The value returned is of type XmString , which is an opaque type to the programmer. This routine interprets the text string in the current locale when creating the compound string. If you are writing an internationalized application that needs to support multiple locales, you should use XmStringCreateLocalized to create compound strings.

The routine allows you to take advantage of the lower-level internationalization features of X. Most applications specify compound string resources in resource files. This technique is appropriate for an internationalized application, as there can be a separate resource file for each language environment that is supported.

If an application needs to create a compound string programmatically, it should use XmStringCreateLocalized to ensure that the string is interpreted in the current locale. The examples in other chapters of this book use XmStringCreateLocalized to demonstrate the appropriate technique, even though the examples are only designed to work in the C locale. With XmStringCreateLocalized , you cannot explicitly specify the tag or the string direction that is used for the compound string, and in Motif 1.

XmStringCreateLocalized allocates memory to store the compound string that is returned. Widgets that have compound string resources always allocate their own space and store copies of the compound string values you give them. When you are done using a compound string to set widget resources, you must free it using XmStringFree. The following code fragment demonstrates this usage: The process of creating a compound string, setting a widget resource, and then freeing the string is the most common use of compound strings. However, this process involves quite a bit of overhead, as memory operations are expensive.

Memory is allocated by the string creation function and again by the internals of the widget for its own storage, and then your copy of the string must be deallocated. The programmatic interface to the string creation process can also be achieved by using the XtVaTypedArg feature in Xt. It allows you to specify a resource using a convenient type and have Xt do the conversion for you. In the case of compound strings, we could use this method to convert a C string to a compound string.

The following code fragment has the same logical effect as the previous example: We set the XmNlabelString resource. The XtVaTypedArg method for specifying a compound string resource is only a programmatic convenience; it does not save time or improve performance.

The three-step process of creating, setting, and freeing the compound string still takes place, but it happens within Motif's compound string resource converter. Using automatic conversion is actually slower than converting a string using XmStringCreateLocalized. However, unless you are creating hundreds of strings, the difference may well be negligible. The XtVaTypedArg method is perfectly reasonable for converting other types of resources, however.

If you are converting a lot of values from one type to another, it is in your own best interest to evaluate the conversion process yourself by testing the automatic versus the manual conversion methods. Rendition Tags Motif provides compound string creation routines that allow you to specify a tag used to associate the compound string with a rendition. This tag is a programmer-specified identifier that enables a Motif widget to pick its rendition from a render table at run-time 5. The XmStringCreate routine allows you to specify a rendition tag. The routine takes the following form: As with any compound string, be sure to free it with XmStringFree when you are done using it.

XmStringCreate creates a compound string that has no specified direction. The default direction of a string may be taken from the XmNlayoutDirection resource 6. This resource is defined by manager widgets; it specifies the layout and string direction for all the children of the manager. If the default direction is not adequate, XmStringDirectionCreate can be used to create a compound string with an explicit direction, as we'll discuss shortly. This routine can convert either single or multi-byte character strings to compound string format. The routine is defined as follows: This can be either single or multi-byte data, the type parameter will inform the function of the supplied text type.

The tag parameter is simply the name to be associated with the created compound string: The following code fragment is the simple case: Every Motif widget that displays text has an XmNrenderTable resource. This resource specifies a list of rendition objects for the widget; each entry in the list may have an optional tag associated with it.

For example, a resource file might specify a render table as follows: This callback, if specified, can be used to supply the missing rendition information. If this default rendition also has no font, the compound string is not drawn, and a warning message is displayed. This loose binding between the compound string and the rendition and hence the font or font set used to render it is useful in a number of ways: The same compound string can be rendered using different fonts in different widgets simply by specifying a different render table for each widget.

For example: The font for each segment is selected from the renditions within the widget's render table by means of a unique tag. Compound strings can be language-independent, with the tag used to select between fonts with different character set encodings. This is the least common use for compound strings, and as of X11R5, it is no longer needed to support internationalized text output. Create three pushbuttons: Since each render table only contains one rendition, Motif has no choice but to attempt to display the compound string using the font associated with the single rendition.

The second PushButton does not render the compound string label because there is no rendition with a matching tag, and no default unnamed rendition. Motif prints out a warning message: No font found. This behavior is different to that of Motif 1. When a compound string is created using XmStringCreateLocalized , this tag is used. Motif looks for a rendition with a matching tag when it renders the compound string. However, it is possible to use explicit rendition tags for locale-specific text.

Explicit tags are necessary when an application wants to display compound strings using different point sizes or type styles. If the user has set the LANG environment variable, its value is used for this character set. For backwards compatibility, Motif 1. Again for backwards compatibility, in Motif 2. RenderTable Resources Some Motif widgets define rendition resources that allow them to provide a consistent appearance for all of their children.

These resources referred to XmFontList data, and were applied to all of the buttons, Labels, and Text widgets that are descendents of the widget. For backwards compatibility, if one of the more specific font list resources was not set, its value was taken from XmNdefaultFontList. These render tables apply to the buttons, Labels, and Text widgets that descend from a BulletinBoard. All of these render table resources are designed to help you maintain a consistent interface. However, you can always specify the font for a particular button, Label, or Text widget using the widget's XmNrenderTable resource, as this resource overrides the more general ones.

Compound String Segments A compound string is composed of segments , where each segment contains a continuous sequence of text with no change in rendition tag or direction. A compound string segment can be terminated by a separator , which is the equivalent of a newline in a character string. XmStringComponentCreate provides complete control over the creation of a compound string, as it allows you to specify individual text, rendition tag, tab, and direction components which can be concatenated together into a whole If you are going to use left-to-right strings uniformly in your applications, you really don't need to read this section.

There are several ways to build a compound string that is rendered from right-to-left; the best method is dependent on the nature of your application.

X Toolkit Intrinsics - C Language Interface

If your application uses right-to-left strings for all of its widgets, you may want to use the XmNlayoutDirection resource This resource specifies the layout of the component in general terms: Most right-to-left languages display certain things, like numbers, from left-to-right, so it is not always possible to use the XmNlayoutDirection resource. In this case, you have to create compound string segments that hard-code their directional information. Both of these routines take an argument of type XmStringDirection , which is defined as an unsigned char. For a description of the changes that we made to convert the example programs to Motif 1.

To compile any of the examples on a UNIX system without using imake , use the following command line: Now let's take a look at this program step by step, noting elements of the underlying Xt model and where Motif differs from it. An application that uses the Motif toolkit must include a header file for each widget that it uses. For example, hello. The one with the name ending in a "P" e.

Private header files are used only by the code that implements a widget class and its subclasses. Xt uses public and private header files to hide the details of widget implementation from applications. This technique provides object-oriented encapsulation and data hiding in the C language, which is not designed to support object-oriented programming. For some types of objects, you may see another pair of header files, each containing a capital "G" at the end of their names for example, PushBG. These files are for the gadget version of the object.

For the most part, when we talk about widgets, we include gadgets. Later chapters make it clear when to use gadgets and when to use widgets. Release 1. We recommend that you not duplicate the inclusion of header files. One reason is that if you include only the header files that you need, whoever has to maintain your code can see which widgets you are dealing with in your source files. Another reason is that duplicating header files is generally bad practice, as you run the risk of redeclaring macros, functions, and variables. However, it isn't always easy to prevent multiple inclusions.

All of the Motif, Xt and X header files are protected from multiple inclusion using a technique called ifdef-wrapping. We recommend that you use this method in your own header files as well. Of course, the wrapper prevents multiple inclusion only within a single source file; the next source file that gets compiled goes through the same test.

If the same files are included, the same macros, data types, and functions are declared again for the benefit of the new file. For this reason, you should never write functions in a header file, since it would be equivalent to having the same function exist in every source file. Function declarations, however, are acceptable and expected.

The order of inclusion is generally not important unless certain types or declarations required by one file are declared in another. In this case, you should include the files in the necessary order. Otherwise, application-specific header files are usually included first, followed by UI-specific header files with Xt header files, if any, preceding Motif header files , followed by system-specific header files.

How to: Use Application Resources

An internationalized application retrieves the user's language called a locale from the environment or a resource file and operates in that language without changes to the binary. An internationalized application must display all of its text in the user's language and accept textual input in that same language. It must also display dates, times, and numbers in the appropriate format for the language environment. This approach is based on the concept of localization , whereby an application uses a library that reads a customizing database at startup time.

This database contains information about the characteristics of every locale that is supported by the system. When an application establishes its locale by calling setlocale , the library customizes the behavior of various routines based on the locale. Xt support of internationalization is trivial in most applications; the only additional code needed is a call to XtSetLanguageProc before the toolkit is initialized.

XtSetLanguageProc sets the language procedure that is used to set the locale of an application. The first argument to the routine specifies an application context, the second argument specifies the language procedure, and the third parameter specifies additional data that is passed to the language procedure when it is called. Since the language procedure is responsible for setting the locale, an Xt application does not call setlocale directly.

The language procedure is called by XtDisplayInitialize. Here's the call that we used in the source code to set the default language procedure: Most of the support for internationalization in Motif 1. Xlib provides support for internationalized text output, interclient communication, and localization of the resource database, while Xt handles establishing the locale. The Motif Text and TextField widgets have been modified to support internationalized text input and output; see Section stexti18n for more information.

The Motif routines that work with compound strings and font lists have also been updated in Motif 1.

Before an application creates any widgets, it must initialize the toolkit. There are many ways to perform this task, most of which also perform a number of related tasks, such as opening a connection to the X server and loading the resource database. Here's a list of some of the things that are almost always done: The simpler X11R3 initialization call, XtInitialize , is still supported by later versions of the toolkit. Its use is discouraged because the new initialization calls provide a greater degree of upward compatibility with future Xt-based applications. The simpler function creates an application context that is stored internally by Xt.

The second argument to XtVaAppInitialize is a string that defines the class name of the application. A class name is used in resource files to specify resource values that apply to all instances of an application, a widget, or a resource. For many applications, the application class is rarely used and the class name is important only because it is also used as the name of the application's app-defaults file. Whenever a widget is created in Xt, its resources must have certain initial or default values. You can either hard-code the values, allow them to default to widget-defined values, or specify the default values in the app-defaults file.

These default values are used unless the user has provided his own default settings in another resource file. By convention, the class name is the same as the name of the application itself, except that the first letter is capitalized. For example, a program named draw would have Some applications follow the convention that if the application's name begins with an "X", the X is silent and so the second letter is capitalized as well. For example, the class name of xterm is XTerm.

Note, however, that there is no requirement that an app-defaults file with this name actually be installed. Exceptions can be made to this convention, as long as you document it. For example, all the example programs in this book have the class name of Demos , which allows us to set certain common defaults in a single file. This technique can be useful whenever you have a large collection of independent programs that are part of the same suite of applications. The third and fourth arguments specify an array of objects that describe the command-line arguments for your program, if any, and the number of arguments in the array.

These arguments are unused in most of the examples in this book and are specified as NULL and 0 , respectively. The program xshowbitmap. The fifth and sixth arguments contain the value argv and count argc of any actual command-line arguments. The initialization call actually removes and acts on any arguments it recognizes, such as the standard X Toolkit command-line options and any options that you have defined in the third argument.

After this call, argv should contain only the application name and any expected arguments such as filenames. You may want to check the argument count at this point and issue an error message if any spurious arguments are found. The seventh argument is the start of a NULL -terminated list of fallback resources for the top-level shell widget created by the initialization call. Fallback resources provide a kind of "belt and suspenders" protection against the possibility that an app-defaults file is not installed. They are ignored if the app-defaults file or any other explicit resource settings are found.

When no fallback resources are specified, the seventh argument should be NULL. It is generally a good idea to provide fallbacks for resources that are essential to the operation of your application. An example of how fallback resources can be used by an application is shown in the following code fragment: Fallback resources protect your application against a missing app-defaults file, but they do not guard against one that is modified incorrectly or otherwise corrupted, since they are not used if the app-defaults file is present in any form.

A better fallback mechanism would provide protection against these types of problems. Fortunately, X11 Release 5 introduces a new function, XrmCombineDatabases , that allows you to provide real fallbacks in case the user or the system administrator misconfigures the app-defaults file. If there are no resource settings, which is often the case for this function, you can pass NULL as the eighth parameter.

If you do pass any parameters, it should be done just as we describe for XtVaCreateWidget later in this chapter. All of the functions whose names begin with XtVa support the same type of varargs-style variadic argument lists. This problem only arises for some compilers that do not understand function prototypes. The problem is rare since it is compiler-dependent and it only happens on older compilers. It is not a compiler error but an Xt error, since functions are not supposed to mix fixed parameter declarations with variadic declarations.

XtVaAppInitialize mixes these declarations; the first seven parameters are fixed while the eighth through n th arguments are variadic. ANSI-C allows, and even requires, this type of specification. There is a convenience function for creating every class of widget and gadget supported by the Motif toolkit. In addition, there are convenience functions for creating compound objects. A compound object is a collection of widgets that is treated like a single object.

XmCreateScrolledList creates the compound object consisting of both widgets. These functions allow you to decide whether to create a widget as managed or unmanaged, while the Motif convenience functions always create unmanaged widgets. X nests windows using a parent-child model. A display screen is defined as the root window; every application has a top-level window that is a child of the root window. A top-level window in turn has subwindows, which overlay it but cannot extend beyond its boundaries. If a window extends beyond the boundaries of its parent, it is clipped.

Because every widget has its own X window, widgets follow a similar parent-child model. Whenever a widget is created, it is created as the child of another widget. The shell widget returned by the call to XtVaAppInitialize is the top-level widget of an application. It is usually overlaid with a special class of widget called a manager widget , which implements rules for controlling the size and placement of widget children.

For example, the Motif RowColumn widget is a manager that allows widgets to be laid out in regular rows and columns, while the Form widget is a manager that allows widgets to be placed at precise positions relative to one another. A manager widget can contain other manager widgets as well as primitive widgets , which are used to implement actual user-interface controls. Managers also support gadgets. A gadget is a lighter-weight object that is identical to its corresponding widget in appearance, but does not have its own window. In the source code the button was created as a child of the top-level shell window.

This simple application contains only one visible widget, so it does not use a manager. Actually, shells are extremely simple managers. A shell can only have one child; the shell makes itself exactly the same size as the child so the shell remains invisible behind the child. Here's the call we used to create the button: The second argument is the class of the widget to be created. This name is defined in the public header file for the widget. The widget reference pages in Volume Six B list the widget class name for each Motif and Xt widget class.

The third argument is the parent of the widget, which must be a manager widget that has already been created. In this example, the parent of the PushButton widget is toplevel , the shell widget returned by the call to XtVaAppInitialize. The remainder of the argument list is a variable-length list of resource settings. We'll talk about the format of these resource settings in the next section.

A widget class defines resources of its own and it inherits resources from its superclasses. The most useful resources are described in detail in the individual chapters on each of the Motif widget classes. When resources are set in a program, each resource name begins with the prefix XmN. These names are mnemonic constants that correspond to actual C strings that have the same name without the XmN prefix. For example, the actual resource name associated with XmNlabelString is labelString. The XmN identifies the resource as being Motif-related. Motif also uses the XmC prefix to identify resource class symbols.

Xt uses the prefix XtN for any resources defined by its base widget classes. Motif also provides corresponding XmN names for most of these resources. Some toolkits use the XtN prefix, even though its resource are not common to all Xt toolkits. The resource naming convention has not been used long enough for all vendors to conform to it. When you are specifying resources in a resource file or when you are using the -xrm option to specify resources on the command line, omit the XmN prefix.

The main purpose of the constant definitions for resource names is to allow the C preprocessor to catch spelling errors. If you use the string width rather than the constant XmNwidth , the program still works.

X Window System

However, if you type widdth , the compiler happily compiles the application, but your program won't work and you'll have a difficult time trying to figure out why. Because resource names are strings, there is no way for Xt or Motif to report an error when an unknown resource name is encountered. You pass this array to the function, along with the number of items in the array. Other resources could have been set in the same call, as shown in the following code: When you set resources in the creation call for the widget, those resources can no longer be configured by the user.

Such resources are said to be hard-coded. For example, since we've set the width and height of the PushButton in the call to XtVaCreateManagedWidget , a user resource specification of the following form is ignored: Every resource has a data type that is specified by the widget class defining the resource.

When a resource is specified in a resource file, Xt automatically converts the resource value from a string to the appropriate type.

However, when you set a resource in your program, you must specify the value as the appropriate type. Rather than specifying a value of the appropriate type, you can invoke Xt's resource converters in a varargs list using the keyword XtVaTypedArg , followed by four additional parameters: Xt figures out the type of value that is needed and performs the necessary conversion.

For example, to specify the background color of the button directly in our program without calling an Xlib routine to allocate a colormap entry, we can use the following code: The data type in this construct is specified using a special symbol called a representation type , rather than the C type. An XmR prefix identifies the symbol as a representation type. These symbols are defined in the same way as the XmN symbols that are used for resource names. After a widget has been created, you can set resources for it using XtVaSetValues.

The values set by this function override any values that are set either in the widget creation call or in a resource file. The syntax for using XtVaSetValues is: Some Motif widget classes also provide convenience routines for setting certain resources. A convenience function has direct access to the internal fields in a widget's data structures, so it might have slightly better performance than XtVaSetValues.

Functionally, however, the two methods are interchangeable. The routine used to get widget resource values is XtVaGetValues. For example, the following code gets the label string and the width for a Label widget: There are some things to be careful about when you are getting resource values from a widget. First, always pass the address of the variable that is being used to store the retrieved value.

A value represented by a pointer is not copied into the address space. Instead, the routine sets the value for the address of the pointer to the position of the internal variable that contains the desired value. If you pass an array, rather than a pointer to the array, the routine cannot move its address.


  • .
  • samsung galaxy tab 3 10.1 p5200 price in malaysia!
  • ;
  • .
  • How to: Use Application Resources | Microsoft Docs.
  • Xt and the Athena Widgets.
  • ?

If you pass the address of a pointer, XtVaGetValues is able to reset the pointer to the correct internal value. The Motif toolkit sometimes sets the given address to allocated data, which must be freed when it is no longer needed. This situation occurs when a compound string resource is retrieved from a widget and when the text value of a Text widget is retrieved. For values that are not represented by pointers, such as integers, the value is simply copied.

For example, the width value is an int , so the resource value is copied into the variable. You should also be careful about changing the value of a variable returned by XtVaGetValues. In the case of a variable that is not a pointer, the value can be changed because the variable contains a copy of the value and does not point to internal data for the widget. However, if the variable is a pointer to a string or a data structure, it does point to internal data for the widget. If you dereference the pointer and change the resulting value, you are changing the internal contents of the widget.

This technique should not be used to change the value of a resource. To modify a resource value, you should use XtVaSetValues with a defined resource name, as this routine ensures that the widget redraws and manages itself appropriately. Motif also provides convenience routines for getting certain resource values from particular widget classes. Most of these functions correspond to the convenience routines for setting resource values.

Many of the functions allocate memory for the value that is returned. When a convenience function for retrieving a resource value is available, we generally recommend using it. While we use the variadic functions almost exclusively in this book, you should know how to use the old-style argument lists needed by the Motif widget creation functions. The Motif convenience functions, and some Xt functions like XtCreateWidget and XtCreateManagedWidget , require you to set resources using a separately-declared array of objects of type Arg. You pass this array to the appropriate function along with the number of items in the array.

For example, the following code fragment creates a PushButton widget like the one in hello. Xt also provides some generic widget creation functions that use the old-style argument lists for specifying widget resources. The following code fragment shows the use of XtCreateWidget: The argument-list style of setting resources is quite clumsy and error-prone, since it requires you to declare an array either locally or statically and to make sure that it has enough elements.

In spite of the disadvantages of this method of setting resources, there are still cases where the convenience routines may be useful. One such case is when the routine creates several widgets and arranges them in a predefined way consistent with the Motif Style Guide. The argument-list style functions also can be useful when you have different resources that should be set depending on run-time constraints. For example, the following code fragment creates a widget whose foreground color is set only if the application knows it is using a color display: To set resources in a resource file, you need to specify the names of the widgets, which in this case are all set to label.

It is perfectly legal to give the same name to more than one widget. As a result, a resource specification in a resource file that uses a particular name affects all of the widgets with that name, provided that the widget tree matches the resource specification. For example, you could set the foreground color of all of the Labels using the following resource specification: Other widgets in the application that have the widget name label , but are not children of the widget named rc , are not affected by this specification. Obviously, whether you really want to use the same name for a number of widgets is dependent on your application.

This technique makes it easier to maintain a consistent interface, but it also limits the extent to which the application can be customized. We could have used the elements of the labels array as widget names, but in this example, these strings contain spaces, which are "illegal" widget names. If per-widget resource specification is not a concern, you can use any widget name you like, including NULL or the null string "".

Even if a widget has an illegal name, the user can still specify resources for it using the widget class, as in the following example: Once we have created and configured the widgets for an application, they must be hooked up to application functions via callback resources.

Before we can talk about callback resources and callback functions, we need to discuss events and event handling.