home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
x
/
volume6
/
wsxc2
/
part03
/
HelloWorld.c
next >
Wrap
C/C++ Source or Header
|
1990-04-26
|
4KB
|
100 lines
/*
*******************************************************************************
* HelloWorld.c
*******************************************************************************
This program demonstrates usage of the Xrm (X resource management) databse
for a widget tree definition and management.
There is very little code in this example, since the entire user interface
definition is stored in the Xrm database, preferably in the application
class resource file: ~/HelloWorldClass
ATTC NOTE: This example does NOT use Ws, since it's intended for use
outside Auto-trol.
/*
*******************************************************************************
* Include_files.
*******************************************************************************
*/
#include <Xm/Xm.h> /* Motif public header file */
#include <Xm/Label.h> /* Motif label widget */
#include <Xm/PushB.h> /* Motif pushbutton widget */
#include <Xm/RowColumn.h> /* Motif row column widget */
#include "WsCreate.h" /* Window System Creation routines */
/*
*******************************************************************************
* Application callback declaration (callbacks should be in a separate file)
*******************************************************************************
*/
void pushCB();
/*
*******************************************************************************
* MAIN function
*******************************************************************************
*/
main ( argc, argv )
int argc;
char **argv;
{
Widget app_shellW; /* application shell widget */
XtAppContext app;
/* -- Intialize AWS creating the application shell */
app_shellW = XtInitialize ( "helloWorldClass","HelloWorldClass", NULL, 0, &argc, argv );
app = XtWidgetToApplicationContext(app_shellW);
/* -- Register used widget constructors */
WsRegisterConstructor ( app, "XmCreateLabel", XmCreateLabel );
WsRegisterConstructor ( app, "XmCreatePushButton", XmCreatePushButton);
WsRegisterConstructor ( app, "XmCreateRowColumn", XmCreateRowColumn );
/* -- Register available callbacks */
WsRegisterCreateCallbacks ( app );
WsRegisterCallback ( app, "push", pushCB, NULL );
/* -- Create children of the toplevel shell defined by the Xrm database */
WsCreateKnownChildren ( app_shellW );
/* -- Realize the widget tree and enter the main application loop */
XtRealizeWidget ( app_shellW );
XtMainLoop ( );
}
/*
*******************************************************************************
Application callbacks (should be in a separate file)
*******************************************************************************
*/
/*
-- Push callback
*******************************************************************************
This callback is a state machine; the first invocation loads the text
specified as client data into XmNlabelString resource of invoking widget;
the next invocation exits the application.
*/
void pushCB ( w, client, call )
Widget w;
caddr_t client;
caddr_t call;
{
static Boolean first = TRUE;
if ( first )
{
static Arg setargs[] = { XmNlabelString, NULL };
String text = ( client ) ? (String) client : "No text in Xrdb" ;
setargs[0].value = (XtArgVal)XmStringCreateLtoR(text,XmSTRING_DEFAULT_CHARSET);
XtSetValues ( w, setargs, 1);
first = FALSE;
XmStringFree ( (XmString)setargs[0].value );
}
else
{
exit();
}
}