1 /*
2 From: Joey Mukherjee <studjoey@bigfoot.com>
3 To: lesstif@hungry.com
4 Subject: Drawnbutton problems....
5 Date: Thu, 03 Dec 1998 13:39:56 -0600
6
7 Ok, I know I've whined about drawn buttons before, but this time I have
8 a simple way of making it fail.
9
10 If you change test5 in test/Xm/drawnbutton by adding the following three
11 lines at line 114:
12
13 XmString btn_text;
14 btn_text = XmStringCreateSimple ("Drawn Button");
15 XtSetArg(al[ac], XmNlabelString, btn_text); ac++;
16 XtSetArg(al[ac], XmNalignment, XmALIGNMENT_CENTER); ac++;
17
18 You'll see the text does not show up; however, under the real Motif it
19 does.
20
21 For some reason under the real Motif you must also set XmNalignment
22 in the resize/expose widget or else you will get the pixmap on top of
23 the text. What I do is do a :
24
25 XtVaSetValues (w,
26 XmNalignment, XmALIGNMENT_END,
27 NULL);
28
29 in my resize/expose widget. After that, the pixmap is to the far left
30 and the text is to the right. On LessTif, this will create the
31 "nervous" drawn button where it will continually resize/expose itself.
32 Adding that line to line 58 of test5.c shows the problem.
33
34 I've attached my test case to this message. If you reply, I'd really
35 appreciate a carbon copy of the email. I'm not subscribed to the list
36 anymore since I'm leaving for a while, but would love to know when/if
37 this is resolved.
38
39 Cheers!
40 Joey (joey@swri.org)
41 */
42
43 /*
44 ** Generated by X-Designer
45 */
46 /*
47 **LIBS: -lXm -lXt -lX11
48 */
49
50 #include <X11/Xatom.h>
51 #include <X11/Intrinsic.h>
52 #include <X11/Shell.h>
53
54 #include <Xm/Xm.h>
55 #include <Xm/DialogS.h>
56 #include <Xm/DrawnB.h>
57 #include <stdio.h>
58
59 extern void button_resize ();
60 extern void button_expose ();
61 extern Boolean aardvarkConverter ();
62 extern Boolean objStringConverter ();
63 Widget appshell = (Widget) NULL;
64 Widget drawnbutton = (Widget) NULL;
65 void create_gc();
66
67
68 GC gc=0;
69
70 #define LINE_WIDTH 10
71
72 void
button_expose(w,client_data,call_data)73 button_expose(w, client_data, call_data)
74 Widget w;
75 XtPointer client_data;
76 XtPointer call_data;
77 {
78 Dimension width, height, shadow, highlight;
79 int origin;
80 unsigned int arc_width, arc_height;
81 /* Call a routine to create a Graphics Context */
82 create_gc(w);
83 /* First get the various dimensions */
84 XtVaGetValues(w,
85 XmNwidth, &width,
86 XmNheight, &height,
87 XmNshadowThickness, &shadow,
88 XmNhighlightThickness, &highlight, NULL);
89 origin = shadow + highlight + 1 + (LINE_WIDTH / 2);
90 /* Don't draw 0 or negatively sized circles. */
91 if (width < origin * 2
92 || height < origin * 2)
93 return;
94 /* Calculate arc sizes */
95 arc_width = width - origin * 2;
96 arc_height = height - origin * 2;
97 /* Draw the Arc */
98 XDrawArc(XtDisplay(w), XtWindow(w), gc, origin, origin, arc_width,
99 arc_height, 0, 360 * 64);
100 XtVaSetValues (w,
101 XmNalignment, XmALIGNMENT_END,
102 NULL);
103 }
104
105 void
button_resize(w,client_data,call_data)106 button_resize(w, client_data, call_data)
107 Widget w;
108 XtPointer client_data;
109 XtPointer call_data;
110 {
111 XClearArea(XtDisplay(w), XtWindow(w), 0, 0, 0, 0, True);
112 }
113
114 void
create_gc(w)115 create_gc(w)
116 Widget w;
117 {
118 XGCValues values;
119 XColor screen_def, exact_def;
120 Display *display = XtDisplay(w);
121 Colormap cmap = XDefaultColormapOfScreen(XtScreen(w));
122 int mask = 0;
123
124 if (gc != 0)
125 return;
126 /* Allocate read-only colour cell for colour `red' */
127 if (XAllocNamedColor(display, cmap, "red", &screen_def, &exact_def)
128 != 0) {
129 /*
130 * Put the pixel value for red into the GC, ready for drawing
131 * operations
132 */
133 values.foreground = screen_def.pixel;
134 mask = GCForeground;
135 }
136 values.line_width=LINE_WIDTH;
137 mask|=GCLineWidth;
138 gc = XCreateGC(display, XtWindow(w), mask, &values);
139 }
140
create_appshell(display,app_name,app_argc,app_argv)141 void create_appshell (display, app_name, app_argc, app_argv)
142 Display *display;
143 char *app_name;
144 int app_argc;
145 char **app_argv;
146 {
147 Arg al[64]; /* Arg List */
148 register int ac = 0; /* Arg Count */
149 XmString btn_text;
150
151 XtSetArg(al[ac], XmNallowShellResize, TRUE); ac++;
152 XtSetArg(al[ac], XmNtitle, "Drawn Button"); ac++;
153 XtSetArg(al[ac], XmNargc, app_argc); ac++;
154 XtSetArg(al[ac], XmNargv, app_argv); ac++;
155 appshell = XtAppCreateShell ( app_name, "XApplication", applicationShellWidgetClass, display, al, ac );
156 ac = 0;
157 XtSetArg(al[ac], XmNwidth, 200); ac++;
158 XtSetArg(al[ac], XmNheight, 200); ac++;
159 btn_text = XmStringCreateSimple ("Drawn Button");
160 XtSetArg(al[ac], XmNlabelString, btn_text); ac++;
161 XtSetArg(al[ac], XmNalignment, XmALIGNMENT_CENTER); ac++;
162 drawnbutton = XmCreateDrawnButton ( appshell, "drawnbutton", al, ac );
163 ac = 0;
164 XtAddCallback (drawnbutton, XmNresizeCallback, button_resize,NULL);
165 XtAddCallback (drawnbutton, XmNexposeCallback, button_expose,NULL);
166 XtManageChild ( drawnbutton);
167 }
168
169
170
171 XtAppContext app_context;
172 Display *display; /* Display */
173
main(argc,argv)174 int main (argc,argv)
175 int argc;
176 char **argv;
177 {
178 XtSetLanguageProc ( (XtAppContext) NULL, (XtLanguageProc) NULL, (XtPointer) NULL );
179 XtToolkitInitialize ();
180 app_context = XtCreateApplicationContext ();
181 display = XtOpenDisplay (app_context, NULL, argv[0], "XApplication",
182 NULL, 0, &argc, argv);
183 if (!display)
184 {
185 printf("%s: can't open display, exiting...\n", argv[0]);
186 exit (-1);
187 }
188 create_appshell ( display, argv[0], argc, argv );
189 XtRealizeWidget (appshell);
190 LessTifTestWaitForIt(appshell);
191
192
193 /* Note: the following values are the result of
194 * querying the current geometry.
195 */
196 {
197 static XtWidgetGeometry Expected[] = {
198 CWWidth | CWHeight , 0, 0, 200, 200, 0,0,0, /* Button1 */
199 };
200 /* toplevel should be replaced with to correct applicationShell */
201 PrintDetails(appshell, Expected);
202 }
203 LessTifTestMainLoop(appshell);
204 exit (0);
205 }
206
207