summaryrefslogtreecommitdiff
path: root/examples/simple.c
blob: fd0cb32dc9cf5d3d21d6c7e75caddcc47110d1f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdlib.h>
#include <X11/StringDefs.h>
#include <Xaw/Box.h>
#include <Xaw/Simple.h>
#include <Xaw/Command.h>
#include <Xmu/Drawing.h>

/*
	this is the  draw function. it uses two pencils (GC) with
	different colors. one pencil is used to draw the logo,
	the other is used to fill the background.
*/

static void ac_set ( Widget w, XEvent *event, String *params, Cardinal *num_params ) 
{
	GC gc1,gc2;
 	XGCValues  values;
	Dimension wi,hi;	

	if (!XtIsRealized(w))
		return ;
	
	if (strcmp(XtName(w),"draw") != 0)
		return ;

	XtVaGetValues(w,XtNheight,&hi,XtNwidth,&wi,NULL);
  	values.foreground   = 0xcf00fe; //purple
  	gc1 = XtGetGC(w, GCForeground, &values);
  	values.foreground    = 0x00ff00; //green
  	gc2 = XtGetGC(w, GCForeground, &values);
	XmuDrawLogo(XtDisplay(w), XtWindow(w), gc1, gc2, 0,0, wi, hi );
	XtReleaseGC(w,gc1);
	XtReleaseGC(w,gc2);
}


static void
quit_cb(Widget w, XtPointer data, XtPointer call_data)
{
     XtAppSetExitFlag( XtWidgetToApplicationContext(w) ); 
};

int main(int argc, char **argv)
{
	Widget toplevel,box,command,simple;
	XtAppContext app;
	static char  translation[] = 
		       "<Expose>:set()\n";
      static XtActionsRec actionTable[] = {
	    {"set",ac_set }
      };

	toplevel = XtAppInitialize(&app, "demo", NULL, 0,
                               &argc, argv, NULL,
                               NULL, 0);

        XtAppAddActions(app, actionTable, XtNumber(actionTable) );

	box = XtCreateManagedWidget("box", boxWidgetClass, toplevel, NULL, 0);

	command = XtVaCreateManagedWidget("cmd",
                                   commandWidgetClass,  box,
                                      XtNlabel, "EXIT",
                                      NULL);

	simple=XtVaCreateManagedWidget("draw",
				       simpleWidgetClass,  box,
				       XtNheight,250,
				       XtNwidth,250,
					XtNbackground, 0xff0000,
				       XtNtranslations,XtParseTranslationTable(translation),
				       NULL);
	
	XtAddCallback(command, XtNcallback, quit_cb,  simple );
	
	XtRealizeWidget(toplevel);
        XtAppMainLoop(app);
	exit(0);
}