Online Documentation Server
 ПОИСК
ods.com.ua Web
 КАТЕГОРИИ
Home
Programming
Net technology
Unixes
Security
RFC, HOWTO
Web technology
Data bases
Other docs

 


 ПОДПИСКА

 О КОПИРАЙТАХ
Вся предоставленная на этом сервере информация собрана нами из разных источников. Если Вам кажется, что публикация каких-то документов нарушает чьи-либо авторские права, сообщите нам об этом.




xbutton
next up previous contents
Next: Program Listing of Up: Example Programs Previous: Example Programs

xbutton

The first application xbutton, although very simple, serves as an introduction to programming using the X Toolkit. Basically, it displays a button labelled ``Quit'', in a window. Clicking the left mouse button on this button causes the application to terminate. Two versions of this simple application are given, one using the Athena widget set and the other using the Motif widget set.

The program sequence is as follows. XtVaAppInitialize initializes the Xt intrinsics and, amongst other things, handles connection to a display and sets the application's class name to XButton, which is used to locate the application's external resource settings. It returns an instance of an application shell widget, which is required as the top-level widget of any application.

A widget instance is created using XtVaCreateManagedWidget. The first parameter to this routine is the widget's instance name. This name is also used for the default value of the label resource for Athena Command class widgets, or the labelString resource for Motif XmPushButton class widgets. In both cases, it appears as the text in the button. The second parameter specifies the widget's class, identifying the kind of widget required. For a button widget, this is commandWidgetClass for the Athena version, and xmPushButtonWidgetClass for the Motif version. These constants can be obtained from the reference manual for the widget set. The third parameter, top, is the variable name of the parent widget, which in this case refers to the top level application shell widget. Making the button widget a child of the application shell widget causes the button to be placed inside the application shell widget. The final parameter, NULL, is used to terminate the list of parameters to the routine.

XtAddCallback is used to add the application routine Stop to the callback list resource of the button widget. This callback will be triggered when the button is activated. It is good practice to use an uppercase letter at the beginning of a callback routine's name. XtRealizeWidget causes windows to be drawn for each widget, in this case an application shell window containing a child button window, completely overlaying the shell's window. Finally, XtAppMainLoop transfers control of the application to the event handling mechanism of the Xt intrinsics.

Figure 18 shows two external resource settings to set the button widget's label resource to alter the text of the button. The first setting applies to the Athena version and the second to the Motif version.

 
Figure 18: Sample external resource settings for xbutton

With these external resource settings in an appropriate file, figure 19 shows the result of running the Athena version of the xbutton application and figure 20 shows the Motif version. Note the twm window manager's addition of a title bar to the top of the application's main window.



next up previous contents
Next: Program Listing of Up: Example Programs Previous: Example Programs



JR Pitchers
Wed May 3 16:45:04 BST 1995


With any suggestions or questions please feel free to contact us