File: Container7.c

package info (click to toggle)
motif 2.3.4-13
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 81,160 kB
  • ctags: 51,769
  • sloc: ansic: 596,938; cpp: 3,951; yacc: 2,854; makefile: 2,070; csh: 1,199; sh: 1,070; lex: 455
file content (196 lines) | stat: -rw-r--r-- 4,746 bytes parent folder | download | duplicates (3)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#ifdef REV_INFO
#ifndef lint
static char rcsid[] = "$XConsortium: Container7.c /main/2 1996/07/26 11:53:06 schuldy $"
#endif
#endif

#include <testlib.h>

char * BitmapPaths[] =
{
  "../bitmaps/circles1.bmp",
  "../bitmaps/collapsedState.bmp",
  "../bitmaps/dp.bmp",
  "../bitmaps/expandedState.bmp",
  "../bitmaps/gnu.bmp",
  "../bitmaps/mtn.bmp",
  "../bitmaps/null.bmp",
  "../bitmaps/smiley.bmp",
  "../bitmaps/warn.bmp"
};

#define NUM_PIXMAP 	sizeof (BitmapPaths) / sizeof (BitmapPaths[0])
#define NUM_LABEL	NUM_PIXMAP

/* Some jiggery pokery to make the icons surround a central point */
#define NUM_ELEMS	(NUM_PIXMAP + NUM_LABEL)

#define START_X		50
#define START_Y		50
#define INCR_X		100
#define INCR_Y		100
#define ELEM_IN_ROW	3

#define CURR_COL(n)	((int)(((n))%ELEM_IN_ROW))
#define CURR_ROW(n)	((int)(((n))/ELEM_IN_ROW))

#define PIXEL_X(n)	(START_X + INCR_X * CURR_COL(n))
#define PIXEL_Y(n)	(START_Y + INCR_Y * CURR_ROW(n))

  void
RestoreXY( Widget w, int x, int y )
{
    int n;
    Arg args[MAX_ARGS];

    n = 0;
    XtSetArg( args[n], XmNwidth, x ); n++;
    XtSetArg( args[n], XmNheight, y ); n++;
    XtSetValues( w, args, n );

    return;
}

  void
UnselectAll( Widget w )
{
    int n;
    Arg args[MAX_ARGS];

    n = 0;
    XtSetArg( args[n], XmNselectedObjects, NULL ); n++;
    XtSetArg( args[n], XmNselectedObjectCount, 0 ); n++;
    XtSetValues( w, args, n );

    return;
}
 

  int
main(int argc, char **argv)
{
    Widget              ScrollWin, Container, *IconGad;   
    int			i;
    Cardinal		n;
    Arg			args[MAX_ARGS];
    Dimension		x_size, y_size;

    CommonTestInit(argc, argv);

    n = 0;
    XtSetArg( args[n], XmNx, 20 ); n++;
    ScrollWin = XmCreateScrolledWindow(Shell1, "ScrollWin7", args, n);
    XtManageChild(ScrollWin);

    XtSetArg(args[n], XmNselectionPolicy, XmMULTIPLE_SELECT); n++;
    XtSetArg(args[n], XmNspatialStyle, XmNONE ); n++;
    Container = XmCreateContainer(ScrollWin, "Container7", args, n);
    XtManageChild(Container);

    /* Add a bunch of Icon Gadgets */

    IconGad = (Widget*) XtMalloc(NUM_ELEMS * sizeof(Widget));

    /* Put some pixmaps in the Container */
    for (i = 0; i <  NUM_PIXMAP; i++) {
	char        IconName[20] ;
	XmString   icon_name;
	Pixmap	pixmap;

	n = 0 ;
	sprintf(IconName, "IconGad%d", i);
	icon_name = XmStringGenerate(IconName, NULL, XmCHARSET_TEXT, NULL); 

   	/* make icons from pixmap files */

	pixmap = XmGetPixmap(screen, BitmapPaths[i],
	  BlackPixelOfScreen(screen),
	  WhitePixelOfScreen(screen));

	if (!pixmap)
	{
	  printf("Can't make pixmap for file %s!\n",
	    BitmapPaths[i]);
	  exit(1);
	}

	XtSetArg(args[n], XmNx, PIXEL_X(i) ); n++;
	XtSetArg(args[n], XmNy, PIXEL_Y(i) ); n++;
	XtSetArg(args[n], XmNlabelString, icon_name); n++;
	XtSetArg(args[n], XmNlargeIconPixmap, pixmap); n++;

	IconGad[i] = XmCreateIconGadget(Container, IconName, args, n);
        XtManageChild(IconGad[i]);
	XmStringFree(icon_name);
    }

    /* Put some labels in the Container */
    for (i = NUM_PIXMAP; i <  NUM_ELEMS; i++) {
	char        LabelName[20] ;
	XmString   label_name;

	n = 0 ;
	sprintf(LabelName, "LabelName%d", i);
	label_name = XmStringGenerate(LabelName, NULL, XmCHARSET_TEXT, NULL); 

	XtSetArg(args[n], XmNx, PIXEL_X(i) ); n++;
	XtSetArg(args[n], XmNy, PIXEL_Y(i) ); n++;
	XtSetArg(args[n], XmNlabelString, label_name); n++;
	XtSetArg(args[n], XmNlabelType, XmSTRING); n++;

	IconGad[i] =
		XmCreateIconGadget(Container, LabelName, args, n);
        XtManageChild(IconGad[i]);
	XmStringFree(label_name);
    }

    XtRealizeWidget(Shell1);

    /* Find out the default size for X and Y */
    n = 0;
    XtSetArg( args[n], XmNwidth, &x_size ); n++;
    XtSetArg( args[n], XmNheight, &y_size ); n++;
    XtGetValues( ScrollWin, args, n );

    /*************************
     * Assertions begin
     */

    /* Assertions 1 and 2 */
    n = 0;
    XtSetArg( args[n], XmNwidth, 175 ); n++;
    XtSetValues( ScrollWin, args, n );
    CommonPause();
    RestoreXY( ScrollWin, x_size, y_size );
    UnselectAll( Container );

    /* Assertions 3 and 4 */
    n = 0;
    XtSetArg( args[n], XmNwidth, 400 ); n++;
    XtSetValues( ScrollWin, args, n );
    CommonPause();
    RestoreXY( ScrollWin, x_size, y_size );
    UnselectAll( Container );

    /* Assertions 5 and 6 */
    n = 0;
    XtSetArg( args[n], XmNheight, 400 ); n++;
    XtSetValues( ScrollWin, args, n );
    CommonPause();
    RestoreXY( ScrollWin, x_size, y_size );
    UnselectAll( Container );

    /* Assertions 7 and 8 */
    CommonPause();

    XtAppMainLoop(app_context);


    for ( i=0; i < NUM_ELEMS; i++ )
      XtDestroyWidget( IconGad[i] );

    XtDestroyWidget( Container );
    XtDestroyWidget( ScrollWin );
    XtFree( (char *)IconGad );

}