1 /* $Header: /cvsroot/lesstif/lesstif/test/Xm/pushbutton/test15.c,v 1.6 2001/06/18 09:04:00 amai Exp $
2 From:        Eric Howe <mu@clio.trends.ca>
3 To:          lesstif@hungry.com
4 Subject:     Default Button Clipping
5 Date:        Tue, 14 Jul 1998 01:28:40 -0400 (EDT)
6 */
7 
8 /*
9  * This program will show a clipping problem when a push button (or gadget)
10  * is forced to be smaller than it wants to be and a default button is
11  * being used.
12  */
13 
14 #include <stdlib.h>
15 #include <stdio.h>
16 
17 #include <Xm/Xm.h>
18 #include <Xm/Form.h>
19 #include <Xm/PushB.h>
20 #include <Xm/PushBG.h>
21 #include <Xm/RowColumn.h>
22 
23 #include "../../common/Test.h"
24 
25 
26 #define LABEL \
27 	"A big label to show the\n" \
28 	"\"default button\" clipping\n" \
29 	"problem blah blah blah blah\n" \
30 	"blah blah blah blah blah blah"
31 Widget top;
32 
33 static void
dothings(Display * dpy,char * title,WidgetClass buttonClass)34 dothings(Display *dpy, char *title, WidgetClass buttonClass)
35 {
36 	Widget    form, b1, b2;
37 	XmString  x;
38 	Dimension width, height;
39 
40 	top = XtVaAppCreateShell(NULL, "DefBut",applicationShellWidgetClass,dpy,
41 		XmNtitle,    title,
42 		XmNiconName, title,
43 		NULL);
44 	form = XtVaCreateWidget("form", xmFormWidgetClass, top, NULL);
45 
46 	x = XmStringCreateLtoR(LABEL, XmFONTLIST_DEFAULT_TAG);
47 	b1 = XtVaCreateManagedWidget("one", buttonClass, form,
48 		XmNlabelString,      x,
49 		XmNtopAttachment,    XmATTACH_FORM,
50 		XmNbottomAttachment, XmATTACH_FORM,
51 		XmNleftAttachment,   XmATTACH_FORM,
52 		NULL);
53 	b2 = XtVaCreateManagedWidget("two", buttonClass, form,
54 		XmNlabelString,      x,
55 		XmNtopAttachment,    XmATTACH_FORM,
56 		XmNbottomAttachment, XmATTACH_FORM,
57 		XmNrightAttachment,  XmATTACH_FORM,
58 		XmNleftAttachment,   XmATTACH_WIDGET,
59 		XmNleftWidget,       b1,
60 		NULL);
61 	XmStringFree(x);
62 	XtVaSetValues(form, XmNdefaultButton, b1, NULL);
63 
64 	XtManageChild(form);
65 	XtRealizeWidget(top);
66 
67 	XtVaGetValues(top, XmNwidth, &width, XmNheight, &height, NULL);
68 	width  = (width  * 2) / 3;
69 	height = (height * 2) / 3;
70 	XtVaSetValues(top, XmNwidth, width, XmNheight, height, NULL);
71 }
72 
73 int
main(int argc,char ** argv)74 main(int argc, char **argv)
75 {
76 	XtAppContext ac;
77 	Display      *dpy;
78 
79 	XtSetLanguageProc(NULL, NULL, NULL);
80 	XtToolkitInitialize();
81 	ac  = XtCreateApplicationContext();
82 	dpy = XtOpenDisplay(ac, NULL, NULL, "DefBut", NULL, 0, &argc, argv);
83 
84 	dothings(dpy, "PushButtonGadget", xmPushButtonGadgetClass);
85 	dothings(dpy, "PushButtonWidget", xmPushButtonWidgetClass);
86 
87 /* Note: the following values are the result of
88  * querying the current geometry.
89  */
90 {
91 static XtWidgetGeometry Expected[] = {
92    CWWidth | CWHeight            ,    0,    0,  264,   50, 0,0,0, /* form */
93    CWWidth | CWHeight | CWX | CWY,    0,    0,  198,   50, 0,0,0, /* one */
94    CWWidth | CWHeight | CWX | CWY,  198,    0,  66,   50, 0,0,0, /* two */
95 };
96 /* toplevel should be replaced with to correct applicationShell */
97 PrintDetails(top, Expected);
98 }
99 LessTifTestMainLoop(top);
100 	return 0;
101 }
102