/* ** Generated by X-Designer */ /* **LIBS: -lXm -lXt -lX11 */ #include #include #include #include #include #include #include extern void button_resize (); extern void button_expose (); extern Boolean aardvarkConverter (); extern Boolean objStringConverter (); Widget appshell = (Widget) NULL; Widget drawnbutton = (Widget) NULL; void create_gc(); GC gc=0; #define LINE_WIDTH 10 void button_expose(w, client_data, call_data) Widget w; XtPointer client_data; XtPointer call_data; { Dimension width, height, shadow, highlight; int origin; unsigned int arc_width, arc_height; /* Call a routine to create a Graphics Context */ create_gc(w); /* First get the various dimensions */ XtVaGetValues(w, XmNwidth, &width, XmNheight, &height, XmNshadowThickness, &shadow, XmNhighlightThickness, &highlight, NULL); origin = shadow + highlight + 1 + (LINE_WIDTH / 2); /* Don't draw 0 or negatively sized circles. */ if (width < origin * 2 || height < origin * 2) return; /* Calculate arc sizes */ arc_width = width - origin * 2; arc_height = height - origin * 2; /* Draw the Arc */ XDrawArc(XtDisplay(w), XtWindow(w), gc, origin, origin, arc_width, arc_height, 0, 360 * 64); } void button_resize(w, client_data, call_data) Widget w; XtPointer client_data; XtPointer call_data; { XClearArea(XtDisplay(w), XtWindow(w), 0, 0, 0, 0, True); } void create_gc(w) Widget w; { XGCValues values; XColor screen_def, exact_def; Display *display = XtDisplay(w); Colormap cmap = XDefaultColormapOfScreen(XtScreen(w)); int mask = 0; if (gc != 0) return; /* Allocate read-only colour cell for colour `red' */ if (XAllocNamedColor(display, cmap, "red", &screen_def, &exact_def) != 0) { /* * Put the pixel value for red into the GC, ready for drawing * operations */ values.foreground = screen_def.pixel; mask = GCForeground; } values.line_width=LINE_WIDTH; mask|=GCLineWidth; gc = XCreateGC(display, XtWindow(w), mask, &values); } void create_appshell (display, app_name, app_argc, app_argv) Display *display; char *app_name; int app_argc; char **app_argv; { Arg al[64]; /* Arg List */ register int ac = 0; /* Arg Count */ XtSetArg(al[ac], XmNallowShellResize, TRUE); ac++; XtSetArg(al[ac], XmNtitle, "Drawn Button"); ac++; XtSetArg(al[ac], XmNargc, app_argc); ac++; XtSetArg(al[ac], XmNargv, app_argv); ac++; appshell = XtAppCreateShell ( app_name, "XApplication", applicationShellWidgetClass, display, al, ac ); ac = 0; XtSetArg(al[ac], XmNwidth, 200); ac++; XtSetArg(al[ac], XmNheight, 200); ac++; XtSetArg(al[ac], XmNlabelString, XmStringCreateSimple("Drawn Button")); ac++; XtSetArg(al[ac], XmNalignment, XmALIGNMENT_CENTER); ac++; drawnbutton = XmCreateDrawnButton ( appshell, "drawnbutton", al, ac ); ac = 0; XtAddCallback (drawnbutton, XmNresizeCallback, button_resize,NULL); XtAddCallback (drawnbutton, XmNexposeCallback, button_expose,NULL); XtManageChild ( drawnbutton); } XtAppContext app_context; Display *display; /* Display */ int main (argc,argv) int argc; char **argv; { XtSetLanguageProc ( (XtAppContext) NULL, (XtLanguageProc) NULL, (XtPointer) NULL ); XtToolkitInitialize (); app_context = XtCreateApplicationContext (); display = XtOpenDisplay (app_context, NULL, argv[0], "XApplication", NULL, 0, &argc, argv); if (!display) { printf("%s: can't open display, exiting...\n", argv[0]); exit (-1); } create_appshell ( display, argv[0], argc, argv ); XtRealizeWidget (appshell); /* Note: the following values are the result of * querying the current geometry. */ { static XtWidgetGeometry Expected[] = { CWWidth | CWHeight , 0, 0, 200, 200, 0,0,0, /* Button1 */ }; /* toplevel should be replaced with to correct applicationShell */ PrintDetails(appshell, Expected); } LessTifTestMainLoop(appshell); exit (0); }