1 /*
2 ** Generated by X-Designer
3 */
4 /*
5 **LIBS: -lXm -lXt -lX11
6 */
7 
8 #include <X11/Xatom.h>
9 #include <X11/Intrinsic.h>
10 #include <X11/Shell.h>
11 
12 #include <Xm/Xm.h>
13 #include <Xm/DialogS.h>
14 #include <Xm/DrawnB.h>
15 #include <stdio.h>
16 
17 extern void button_resize ();
18 extern void button_expose ();
19 extern Boolean aardvarkConverter ();
20 extern Boolean objStringConverter ();
21 Widget appshell = (Widget) NULL;
22 Widget drawnbutton = (Widget) NULL;
23 void create_gc();
24 
25 
26 GC gc=0;
27 
28 #define LINE_WIDTH 10
29 
30 void
button_expose(w,client_data,call_data)31 button_expose(w, client_data, call_data)
32 	Widget          w;
33 	XtPointer       client_data;
34 	XtPointer       call_data;
35 {
36 	Dimension       width, height, shadow, highlight;
37 	int             origin;
38 	unsigned int    arc_width, arc_height;
39 	/* Call a routine to create a Graphics Context */
40 	create_gc(w);
41 	/* First get the various dimensions */
42 	XtVaGetValues(w,
43 		      XmNwidth, &width,
44 		      XmNheight, &height,
45 		      XmNshadowThickness, &shadow,
46 		      XmNhighlightThickness, &highlight, NULL);
47 	origin = shadow + highlight + 1 + (LINE_WIDTH / 2);
48 	/* Don't draw 0 or negatively sized circles. */
49 	if (width < origin * 2
50 	    || height < origin * 2)
51 		return;
52 	/* Calculate arc sizes */
53 	arc_width = width - origin * 2;
54 	arc_height = height - origin * 2;
55 	/* Draw the Arc */
56 	XDrawArc(XtDisplay(w), XtWindow(w), gc, origin, origin, arc_width,
57 		 arc_height, 0, 360 * 64);
58 }
59 
60 void
button_resize(w,client_data,call_data)61 button_resize(w, client_data, call_data)
62 	Widget          w;
63 	XtPointer       client_data;
64 	XtPointer       call_data;
65 {
66 	XClearArea(XtDisplay(w), XtWindow(w), 0, 0, 0, 0, True);
67 }
68 
69 void
create_gc(w)70 create_gc(w)
71 	Widget          w;
72 {
73 	XGCValues       values;
74 	XColor          screen_def, exact_def;
75 	Display        *display = XtDisplay(w);
76 	Colormap        cmap = XDefaultColormapOfScreen(XtScreen(w));
77 	int             mask = 0;
78 
79 	if (gc != 0)
80 		return;
81 	/* Allocate read-only colour cell for colour `red' */
82 	if (XAllocNamedColor(display, cmap, "red", &screen_def, &exact_def)
83 	    != 0) {
84 		/*
85 		 * Put the pixel value for red into the GC, ready for drawing
86 		 * operations
87 		 */
88 		values.foreground = screen_def.pixel;
89 		mask = GCForeground;
90 	}
91 	values.line_width=LINE_WIDTH;
92 	mask|=GCLineWidth;
93 	gc = XCreateGC(display, XtWindow(w), mask, &values);
94 }
95 
create_appshell(display,app_name,app_argc,app_argv)96 void create_appshell (display, app_name, app_argc, app_argv)
97 Display *display;
98 char *app_name;
99 int app_argc;
100 char **app_argv;
101 {
102 	Arg al[64];                    /* Arg List */
103 	register int ac = 0;           /* Arg Count */
104 
105 	XtSetArg(al[ac], XmNallowShellResize, TRUE); ac++;
106 	XtSetArg(al[ac], XmNtitle, "Drawn Button"); ac++;
107 	XtSetArg(al[ac], XmNargc, app_argc); ac++;
108 	XtSetArg(al[ac], XmNargv, app_argv); ac++;
109 	appshell = XtAppCreateShell ( app_name, "XApplication", applicationShellWidgetClass, display, al, ac );
110 	ac = 0;
111 	XtSetArg(al[ac], XmNwidth, 200); ac++;
112 	XtSetArg(al[ac], XmNheight, 200); ac++;
113 	drawnbutton = XmCreateDrawnButton ( appshell, "drawnbutton", al, ac );
114 	ac = 0;
115 	XtAddCallback (drawnbutton, XmNresizeCallback, button_resize,NULL);
116 	XtAddCallback (drawnbutton, XmNexposeCallback, button_expose,NULL);
117 	XtManageChild ( drawnbutton);
118 }
119 
120 
121 
122 XtAppContext app_context;
123 Display *display;       /*  Display             */
124 
main(argc,argv)125 int main (argc,argv)
126 int    argc;
127 char            **argv;
128 {
129 	XtSetLanguageProc ( (XtAppContext) NULL, (XtLanguageProc) NULL, (XtPointer) NULL );
130 	XtToolkitInitialize ();
131 	app_context = XtCreateApplicationContext ();
132 	display = XtOpenDisplay (app_context, NULL, argv[0], "XApplication",
133 	                         NULL, 0, &argc, argv);
134 	if (!display)
135 	{
136 	    printf("%s: can't open display, exiting...\n", argv[0]);
137 	    exit (-1);
138 	}
139 	create_appshell ( display, argv[0], argc, argv );
140 	XtRealizeWidget (appshell);
141 
142 
143 /* Note: the following values are the result of
144  * querying the current geometry.
145  */
146 {
147 static XtWidgetGeometry Expected[] = {
148    CWWidth | CWHeight            ,    0,    0,  200,  200, 0,0,0, /* Button1 */
149 };
150 /* toplevel should be replaced with to correct applicationShell */
151 PrintDetails(appshell, Expected);
152 }
153 LessTifTestMainLoop(appshell);
154 	exit (0);
155 }
156 
157