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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
|
Copyright (c) 2005 X.Org Foundation LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Copyright (c) Applied Testing and Technology, Inc. 1993, 1994, 1995
Copyright (c) 88open Consortium, Ltd. 1990, 1991, 1992, 1993
All Rights Reserved.
>>#
>># Project: VSW5
>>#
>># File: xts/Xt8/XtMoveWidget.m
>>#
>># Description:
>># Tests for XtMoveWidget()
>>#
>># Modifications:
>># $Log: tmvwidget.m,v $
>># Revision 1.1 2005-02-12 14:38:23 anderson
>># Initial revision
>>#
>># Revision 8.0 1998/12/23 23:36:53 mar
>># Branch point for Release 5.0.2
>>#
>># Revision 7.0 1998/10/30 22:59:46 mar
>># Branch point for Release 5.0.2b1
>>#
>># Revision 6.0 1998/03/02 05:28:00 tbr
>># Branch point for Release 5.0.1
>>#
>># Revision 5.0 1998/01/26 03:24:34 tbr
>># Branch point for Release 5.0.1b1
>>#
>># Revision 4.0 1995/12/15 09:17:44 tbr
>># Branch point for Release 5.0.0
>>#
>># Revision 3.1 1995/12/15 01:22:00 andy
>># Prepare for GA Release
>>#
>>EXTERN
#include <X11/IntrinsicP.h>
#include <X11/ConstrainP.h>
#include <X11/CoreP.h>
#include <xt/SquareCelP.h>
XtAppContext app_ctext;
Widget topLevel, panedw, boxw1, boxw2;
Widget labelw, rowcolw, click_quit;
/*
* SquareCell.c - Square Widget
*/
#define INTERNAL_WIDTH 2
#define INTERNAL_HEIGHT 4
#define DEFAULT_PIXMAP_WIDTH 1 /* in cells */
#define DEFAULT_PIXMAP_HEIGHT 1 /* in cells */
#define DEFAULT_CELL_SIE 20 /* in pixels */
/* values for instance variable is_drawn */
#define DRAWN 1
#define UNDRAWN 0
/* modes for drawing */
#define DRAW 1
#define UNDRAW 0
#define MAXLINES 10 /* max of horiz or vertical cells */
#define SCROLLBARWIDTH 15
#define DEFAULTWIDTH 300 /* widget size when show_all is False */
#define offset(field) XtOffsetOf(SquareCellRec, field)
static XtResource resources[] = {
{
XtNforeground,
XtCForeground,
XtRPixel,
sizeof(Pixel),
offset(squareCell.foreground),
XtRString,
XtDefaultForeground
},
{
XavsNtoggleCallback,
XavsCToggleCallback,
XtRCallback,
sizeof(XtPointer),
offset(squareCell.callback),
XtRCallback,
NULL
},
{
XavsNcellSizeInPixels,
XavsCCellSizeInPixels,
XtRInt, sizeof(int),
offset(squareCell.cell_size_in_pixels),
XtRImmediate,
(XtPointer)DEFAULT_CELL_SIE
},
{
XavsNpixmapWidthInCells,
XavsCPixmapWidthInCells,
XtRDimension,
sizeof(Dimension),
offset(squareCell.pixmap_width_in_cells),
XtRImmediate,
(XtPointer)DEFAULT_PIXMAP_WIDTH
},
{
XavsNpixmapHeightInCells,
XavsCPixmapHeightInCells,
XtRDimension,
sizeof(Dimension),
offset(squareCell.pixmap_height_in_cells),
XtRImmediate,
(XtPointer)DEFAULT_PIXMAP_HEIGHT
},
{
XavsNcurX,
XavsCCurX,
XtRInt,
sizeof(int),
offset(squareCell.cur_x),
XtRImmediate,
(XtPointer) 0
},
{
XavsNcurY,
XavsCCurY,
XtRInt,
sizeof(int),
offset(squareCell.cur_y),
XtRImmediate,
(XtPointer) 0
},
{
XavsNcellArray,
XavsCCellArray,
XtRString,
sizeof(String),
offset(squareCell.cell),
XtRImmediate,
(XtPointer) 0
},
{
XavsNshowEntireBitmap,
XavsCShowEntireBitmap,
XtRBoolean,
sizeof(Boolean),
offset(squareCell.show_all),
XtRImmediate,
(XtPointer) TRUE
},
};
/* Declaration of methods */
static void Initialize();
static void Redisplay();
static void Destroy();
static void Resize();
static Boolean SetValues();
static XtGeometryResult QueryGeometry();
/* these Core methods not needed by SquareCell:
*
* static void ClassInitialize();
* static void Realize();
*/
/* the following are private functions unique to SquareCell */
static void DrawPixmaps(), DoCell(), ChangeCellSize();
/* the following are actions of SquareCell */
static void DrawCell(), UndrawCell(), ToggleCell();
/* The following are public functions of SquareCell, declared extern
* in the public include file: */
char *SquareCellGetArray();
static char defaultTranslations[] =
"<Btn1Down>: DrawCell() \n\
<Btn2Down>: UndrawCell() \n\
<Btn3Down>: ToggleCell() \n\
<Btn1Motion>: DrawCell() \n\
<Btn2Motion>: UndrawCell() \n\
<Btn3Motion>: ToggleCell()";
static XtActionsRec actions[] = {
{"DrawCell", DrawCell},
{"UndrawCell", UndrawCell},
{"ToggleCell", ToggleCell},
};
/* definition in SquareCell.h */
static SquareCellPointInfo info;
SquareCellClassRec squareCellClassRec = {
{
/* core_class fields */
/* superclass */ (WidgetClass) &coreClassRec,
/* class_name */ "SquareCell",
/* widget_size */ sizeof(SquareCellRec),
/* class_initialize */ NULL,
/* class_part_initialize */ NULL,
/* class_inited */ FALSE,
/* initialize */ Initialize,
/* initialize_hook */ NULL,
/* realize */ XtInheritRealize,
/* actions */ actions,
/* num_actions */ XtNumber(actions),
/* resources */ resources,
/* num_resources */ XtNumber(resources),
/* xrm_class */ NULLQUARK,
/* compress_motion */ TRUE,
/* compress_exposure */ XtExposeCompressMultiple,
/* compress_enterleave */ TRUE,
/* visible_interest */ FALSE,
/* destroy */ Destroy,
/* resize */ Resize,
/* expose */ Redisplay,
/* set_values */ SetValues,
/* set_values_hook */ NULL,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* accept_focus */ NULL,
/* version */ XtVersion,
/* callback_private */ NULL,
/* tm_table */ defaultTranslations,
/* query_geometry */ QueryGeometry,
/* display_accelerator */ XtInheritDisplayAccelerator,
/* extension */ NULL
},
{/* simple_class fields */
/* change_sensitive */ XtInheritChangeSensitive,
},
{
/* extension */ 0,
},
};
WidgetClass squareCellWidgetClass = (WidgetClass) & squareCellClassRec;
static void
GetDrawGC(w)
Widget w;
{
SquareCellWidget cw = (SquareCellWidget) w;
XGCValues values;
XtGCMask mask = GCForeground | GCBackground | GCDashOffset |
GCDashList | GCLineStyle;
/*
* Setting foreground and background to 1 and 0 looks like a
* kludge but isn't. This GC is used for drawing
* into a pixmap of depth one. Real colors are applied with a
* separate GC when the pixmap is copied into the window.
*/
values.foreground = 1;
values.background = 0;
values.dashes = 1;
values.dash_offset = 0;
values.line_style = LineOnOffDash;
cw->squareCell.draw_gc = XCreateGC(XtDisplay((Widget)cw),
cw->squareCell.big_picture, mask, &values);
}
static void
GetUndrawGC(w)
Widget w;
{
SquareCellWidget cw = (SquareCellWidget) w;
XGCValues values;
XtGCMask mask = GCForeground | GCBackground;
/* this looks like a kludge but isn't. This GC is used for drawing
* into a pixmap of depth one. Real colors are applied as the
* pixmap is copied into the window.
*/
values.foreground = 0;
values.background = 1;
cw->squareCell.undraw_gc = XCreateGC(XtDisplay((Widget)cw),
cw->squareCell.big_picture, mask, &values);
}
static void
GetCopyGC(w)
Widget w;
{
SquareCellWidget cw = (SquareCellWidget) w;
XGCValues values;
XtGCMask mask = GCForeground | GCBackground;
values.foreground = cw->squareCell.foreground;
values.background = cw->core.background_pixel;
cw->squareCell.copy_gc = XtGetGC((Widget)cw, mask, &values);
}
static void
Initialize(treq, tnew, args, num_args)
Widget treq, tnew;
ArgList args;
Cardinal *num_args;
{
SquareCellWidget new = (SquareCellWidget) tnew;
new->squareCell.cur_x = 0;
new->squareCell.cur_y = 0;
/*
* Check instance values set by resources that may be invalid.
*/
if ((new->squareCell.pixmap_width_in_cells < 1) ||
(new->squareCell.pixmap_height_in_cells < 1)) {
XtWarning("SquareCell: pixmapWidth and/or pixmapHeight is too small (using 10 x 10)");
new->squareCell.pixmap_width_in_cells = 10;
new->squareCell.pixmap_height_in_cells = 10;
}
if (new->squareCell.cell_size_in_pixels < 5) {
XtWarning("SquareCell: cellSize is too small (using 5)");
new->squareCell.cell_size_in_pixels = 5;
}
if ((new->squareCell.cur_x < 0) || (new->squareCell.cur_y < 0)) {
XtWarning("SquareCell: cur_x and cur_y must be non-negative (using 0, 0)");
new->squareCell.cur_x = 0;
new->squareCell.cur_y = 0;
}
if (new->squareCell.cell == NULL)
new->squareCell.cell = XtCalloc(
new->squareCell.pixmap_width_in_cells *
new->squareCell.pixmap_height_in_cells, sizeof(char));
else
new->squareCell.user_allocated = True; /* user supplied cell array */
new->squareCell.pixmap_width_in_pixels =
new->squareCell.pixmap_width_in_cells *
new->squareCell.cell_size_in_pixels;
new->squareCell.pixmap_height_in_pixels =
new->squareCell.pixmap_height_in_cells *
new->squareCell.cell_size_in_pixels;
if (new->core.width == 0) {
if (new->squareCell.show_all == False)
new->core.width = (new->squareCell.pixmap_width_in_pixels
> DEFAULTWIDTH) ? DEFAULTWIDTH :
(new->squareCell.pixmap_width_in_pixels);
else
new->core.width = new->squareCell.pixmap_width_in_pixels;
}
if (new->core.height == 0) {
if (new->squareCell.show_all == False)
new->core.height =
(new->squareCell.pixmap_height_in_pixels >
DEFAULTWIDTH) ? DEFAULTWIDTH :
(new->squareCell.pixmap_height_in_pixels);
else
new->core.height = new->squareCell.pixmap_height_in_pixels;
}
CreateBigPixmap(new);
GetDrawGC(new);
GetUndrawGC(new);
GetCopyGC(new);
DrawIntoBigPixmap(new);
}
static void
Redisplay(w, event)
Widget w;
XExposeEvent *event;
{
SquareCellWidget cw = (SquareCellWidget) w;
register int x, y;
unsigned int width, height;
if (!XtIsRealized((Widget)cw))
return;
if (event) { /* called from btn-event or expose */
x = event->x;
y = event->y;
width = event->width;
height = event->height;
}
else { /* called because complete redraw */
x = 0;
y = 0;
width = cw->squareCell.pixmap_width_in_pixels;
height = cw->squareCell.pixmap_height_in_pixels;
}
if (DefaultDepthOfScreen(XtScreen((Widget)cw)) == 1)
XCopyArea(XtDisplay((Widget)cw), cw->squareCell.big_picture,
XtWindow((Widget)cw), cw->squareCell.copy_gc, x +
cw->squareCell.cur_x, y + cw->squareCell.cur_y,
width, height, x, y);
else
XCopyPlane(XtDisplay((Widget)cw), cw->squareCell.big_picture,
XtWindow((Widget)cw), cw->squareCell.copy_gc, x +
cw->squareCell.cur_x, y + cw->squareCell.cur_y,
width, height, x, y, 1);
}
static Boolean
SetValues(current, request, new, args, num_args)
Widget current, request, new;
ArgList args;
Cardinal *num_args;
{
SquareCellWidget curcw = (SquareCellWidget) current;
SquareCellWidget newcw = (SquareCellWidget) new;
Boolean do_redisplay = False;
/*
** XtSetValues invoked procedure SetValues
*/
if (curcw->squareCell.foreground != newcw->squareCell.foreground) {
XtReleaseGC((Widget)curcw, curcw->squareCell.copy_gc);
GetCopyGC(newcw);
do_redisplay = True;
}
if ((curcw->squareCell.cur_x != newcw->squareCell.cur_x) ||
(curcw->squareCell.cur_y != newcw->squareCell.cur_y))
do_redisplay = True;
if (curcw->squareCell.cell_size_in_pixels !=
newcw->squareCell.cell_size_in_pixels) {
ChangeCellSize((Widget)curcw, newcw->squareCell.cell_size_in_pixels);
do_redisplay = True;
}
if (curcw->squareCell.pixmap_width_in_cells !=
newcw->squareCell.pixmap_width_in_cells) {
newcw->squareCell.pixmap_width_in_cells =
curcw->squareCell.pixmap_width_in_cells;
XtWarning("SquareCell: pixmap_width_in_cells cannot be set by XtSetValues.\n");
}
if (curcw->squareCell.pixmap_height_in_cells !=
newcw->squareCell.pixmap_height_in_cells) {
newcw->squareCell.pixmap_height_in_cells =
curcw->squareCell.pixmap_height_in_cells;
XtWarning("SquareCell: pixmap_height_in_cells cannot be set by XtSetValues.\n");
}
return do_redisplay;
}
static void
Destroy(w)
Widget w;
{
SquareCellWidget cw = (SquareCellWidget) w;
if (cw->squareCell.big_picture)
XFreePixmap(XtDisplay((Widget)cw), cw->squareCell.big_picture);
if (cw->squareCell.draw_gc)
XFreeGC(XtDisplay((Widget)cw), cw->squareCell.draw_gc);
if (cw->squareCell.undraw_gc)
XFreeGC(XtDisplay((Widget)cw), cw->squareCell.undraw_gc);
if (cw->squareCell.copy_gc)
XFreeGC(XtDisplay((Widget)cw), cw->squareCell.copy_gc);
/* Free memory allocated with Calloc. This was done
* only if application didn't supply cell array.
*/
if (!cw->squareCell.user_allocated)
XtFree(cw->squareCell.cell);
}
static void
DrawCell(w, event)
Widget w;
XEvent *event;
{
SquareCellWidget cw = (SquareCellWidget) w;
DrawPixmaps(cw->squareCell.draw_gc, DRAW, cw, event);
}
static void
UndrawCell(w, event)
Widget w;
XEvent *event;
{
SquareCellWidget cw = (SquareCellWidget) w;
DrawPixmaps(cw->squareCell.undraw_gc, UNDRAW, cw, event);
}
static void
ToggleCell(w, event)
Widget w;
XEvent *event;
{
SquareCellWidget cw = (SquareCellWidget) w;
static int oldx = -1, oldy = -1;
GC gc;
int mode;
int newx, newy;
/* This is strictly correct, but doesn't
* seem to be necessary */
if (event->type == ButtonPress) {
newx = (cw->squareCell.cur_x + ((XButtonEvent *)event)->x) /
cw->squareCell.cell_size_in_pixels;
newy = (cw->squareCell.cur_y + ((XButtonEvent *)event)->y) /
cw->squareCell.cell_size_in_pixels;
}
else {
newx = (cw->squareCell.cur_x + ((XMotionEvent *)event)->x) /
cw->squareCell.cell_size_in_pixels;
newy = (cw->squareCell.cur_y + ((XMotionEvent *)event)->y) /
cw->squareCell.cell_size_in_pixels;
}
if ((mode = cw->squareCell.cell[newx + newy * cw->squareCell.pixmap_width_in_cells]) == DRAWN) {
gc = cw->squareCell.undraw_gc;
mode = UNDRAW;
}
else {
gc = cw->squareCell.draw_gc;
mode = DRAW;
}
if (oldx != newx || oldy != newy) {
oldx = newx;
oldy = newy;
DrawPixmaps(gc, mode, cw, event);
}
}
static void
DrawPixmaps(gc, mode, w, event)
GC gc;
int mode;
Widget w;
XButtonEvent *event;
{
SquareCellWidget cw = (SquareCellWidget) w;
int newx = (cw->squareCell.cur_x + event->x) /
cw->squareCell.cell_size_in_pixels;
int newy = (cw->squareCell.cur_y + event->y) /
cw->squareCell.cell_size_in_pixels;
XExposeEvent fake_event;
/* if already done, return */
if (cw->squareCell.cell[newx + newy * cw->squareCell.pixmap_width_in_cells] == mode)
return;
/* otherwise, draw or undraw */
XFillRectangle(XtDisplay(cw), cw->squareCell.big_picture, gc,
cw->squareCell.cell_size_in_pixels*newx + 2,
cw->squareCell.cell_size_in_pixels*newy + 2,
(unsigned int)cw->squareCell.cell_size_in_pixels - 3,
(unsigned int)cw->squareCell.cell_size_in_pixels - 3);
cw->squareCell.cell[newx + newy * cw->squareCell.pixmap_width_in_cells] = mode;
info.mode = mode;
info.newx = newx;
info.newy = newy;
fake_event.x = cw->squareCell.cell_size_in_pixels * newx - cw->squareCell.cur_x;
fake_event.y = cw->squareCell.cell_size_in_pixels * newy - cw->squareCell.cur_y;
fake_event.width = cw->squareCell.cell_size_in_pixels;
fake_event.height = cw->squareCell.cell_size_in_pixels;
Redisplay(cw, &fake_event);
XtCallCallbacks((Widget)cw, XavsNtoggleCallback, &info);
}
CreateBigPixmap(w)
Widget w;
{
SquareCellWidget cw = (SquareCellWidget) w;
/* always a 1 bit deep pixmap, regardless of screen depth */
cw->squareCell.big_picture = XCreatePixmap(XtDisplay((Widget)cw),
RootWindow(XtDisplay(cw), DefaultScreen(XtDisplay((Widget)cw))),
cw->squareCell.pixmap_width_in_pixels + 2,
cw->squareCell.pixmap_height_in_pixels + 2, 1);
}
DrawIntoBigPixmap(w)
Widget w;
{
SquareCellWidget cw = (SquareCellWidget) w;
int n_horiz_segments, n_vert_segments;
XSegment segment[MAXLINES];
register int x, y;
XFillRectangle(XtDisplay((Widget)cw), cw->squareCell.big_picture,
cw->squareCell.undraw_gc, 0, 0,
cw->squareCell.pixmap_width_in_pixels
+ 2, cw->squareCell.pixmap_height_in_pixels + 2);
n_horiz_segments = cw->squareCell.pixmap_height_in_cells + 1;
n_vert_segments = cw->squareCell.pixmap_width_in_cells + 1;
for (x = 0; x < n_horiz_segments; x++) {
segment[x].x1 = 0;
segment[x].x2 = (short) cw->squareCell.pixmap_width_in_pixels;
segment[x].y1 = (short) cw->squareCell.cell_size_in_pixels * x;
segment[x].y2 = (short) cw->squareCell.cell_size_in_pixels * x;
}
XDrawSegments(XtDisplay((Widget)cw), cw->squareCell.big_picture, cw->squareCell.draw_gc, segment, n_horiz_segments);
for (y = 0; y < n_vert_segments; y++) {
segment[y].x1 = (short) y * cw->squareCell.cell_size_in_pixels;
segment[y].x2 = (short) y * cw->squareCell.cell_size_in_pixels;
segment[y].y1 = 0;
segment[y].y2 = (short) cw->squareCell.pixmap_height_in_pixels;
}
XDrawSegments(XtDisplay((Widget)cw), cw->squareCell.big_picture, cw->squareCell.draw_gc, segment, n_vert_segments);
/* draw current cell array into pixmap */
for (x = 0; x < cw->squareCell.pixmap_width_in_cells; x++) {
for (y = 0; y < cw->squareCell.pixmap_height_in_cells; y++) {
if (cw->squareCell.cell[x + (y * cw->squareCell.pixmap_width_in_cells)] == DRAWN)
DoCell(cw, x, y, cw->squareCell.draw_gc);
else
DoCell(cw, x, y, cw->squareCell.undraw_gc);
}
}
}
/* A Public function, not static */
char *
SquareCellGetArray(w, width_in_cells, height_in_cells)
Widget w;
int *width_in_cells, *height_in_cells;
{
SquareCellWidget cw = (SquareCellWidget) w;
*width_in_cells = cw->squareCell.pixmap_width_in_cells;
*height_in_cells = cw->squareCell.pixmap_height_in_cells;
return (cw->squareCell.cell);
}
static void
Resize(w)
Widget w;
{
SquareCellWidget cw = (SquareCellWidget) w;
/* resize does nothing unless new size is bigger than entire pixmap */
if ((cw->core.width > cw->squareCell.pixmap_width_in_pixels) &&
(cw->core.height > cw->squareCell.pixmap_height_in_pixels)) {
/*
* Calculate the maximum cell size that will allow the
* entire bitmap to be displayed.
*/
Dimension w_temp_cell_size_in_pixels, h_temp_cell_size_in_pixels;
Dimension new_cell_size_in_pixels;
w_temp_cell_size_in_pixels = cw->core.width / cw->squareCell.pixmap_width_in_cells;
h_temp_cell_size_in_pixels = cw->core.height / cw->squareCell.pixmap_height_in_cells;
if (w_temp_cell_size_in_pixels < h_temp_cell_size_in_pixels)
new_cell_size_in_pixels = w_temp_cell_size_in_pixels;
else
new_cell_size_in_pixels = h_temp_cell_size_in_pixels;
/* if size change mandates a new pixmap, make one */
if (new_cell_size_in_pixels != cw->squareCell.cell_size_in_pixels)
ChangeCellSize(cw, new_cell_size_in_pixels);
}
}
static void
ChangeCellSize(w, new_cell_size)
Widget w;
int new_cell_size;
{
SquareCellWidget cw = (SquareCellWidget) w;
int x, y;
cw->squareCell.cell_size_in_pixels = new_cell_size;
/* recalculate variables based on cell size */
cw->squareCell.pixmap_width_in_pixels =
cw->squareCell.pixmap_width_in_cells *
cw->squareCell.cell_size_in_pixels;
cw->squareCell.pixmap_height_in_pixels =
cw->squareCell.pixmap_height_in_cells *
cw->squareCell.cell_size_in_pixels;
/* destroy old and create new pixmap of correct size */
XFreePixmap(XtDisplay(cw), cw->squareCell.big_picture);
CreateBigPixmap(cw);
/* draw lines into new pixmap */
DrawIntoBigPixmap(cw);
/* draw current cell array into pixmap */
for (x = 0; x < cw->squareCell.pixmap_width_in_cells; x++) {
for (y = 0; y < cw->squareCell.pixmap_height_in_cells; y++) {
if (cw->squareCell.cell[x + (y * cw->squareCell.pixmap_width_in_cells)] == DRAWN)
DoCell(cw, x, y, cw->squareCell.draw_gc);
else
DoCell(cw, x, y, cw->squareCell.undraw_gc);
}
}
}
static void
DoCell(w, x, y, gc)
Widget w;
int x, y;
GC gc;
{
SquareCellWidget cw = (SquareCellWidget) w;
/* otherwise, draw or undraw */
XFillRectangle(XtDisplay((Widget)cw), cw->squareCell.big_picture, gc,
cw->squareCell.cell_size_in_pixels * x + 2,
cw->squareCell.cell_size_in_pixels * y + 2,
(unsigned int)cw->squareCell.cell_size_in_pixels - 3,
(unsigned int)cw->squareCell.cell_size_in_pixels - 3);
}
static XtGeometryResult QueryGeometry(w, proposed, answer)
Widget w;
XtWidgetGeometry *proposed, *answer;
{
SquareCellWidget cw = (SquareCellWidget) w;
/* set fields we care about */
answer->request_mode = CWWidth | CWHeight;
/* initial width and height */
if (cw->squareCell.show_all == True)
answer->width = cw->squareCell.pixmap_width_in_pixels;
else
answer->width = (cw->squareCell.pixmap_width_in_pixels >
DEFAULTWIDTH) ? DEFAULTWIDTH :
cw->squareCell.pixmap_width_in_pixels;
if (cw->squareCell.show_all == True)
answer->height = cw->squareCell.pixmap_height_in_pixels;
else
answer->height = (cw->squareCell.pixmap_height_in_pixels >
DEFAULTWIDTH) ? DEFAULTWIDTH :
cw->squareCell.pixmap_height_in_pixels;
if ( ((proposed->request_mode & (CWWidth | CWHeight))
== (CWWidth | CWHeight)) &&
proposed->width == answer->width &&
proposed->height == answer->height)
return XtGeometryYes;
else if (answer->width == cw->core.width &&
answer->height == cw->core.height)
return XtGeometryNo;
else
return XtGeometryAlmost;
}
>>TITLE XtMoveWidget Xt8
void
XtMoveWidget(w, x, y)
>>ASSERTION Good A
A successful call to
void XtMoveWidget(w, x, y)
when at least one of
.A x
or
.A y
is different from its corresponding value in the
object
.A w
shall write the specified values into the object.
>>CODE
XtWidgetGeometry intended, geom, geometry_good;
Widget squarew;
int x, y;
avs_xt_hier("Tmvwidget1", "XtMoveWidget");
tet_infoline("PREP: Create Square Cell widget");
squarew = XtVaCreateManagedWidget("squarew",
squareCellWidgetClass, boxw1, NULL);
tet_infoline("PREP: Change x, y geometry fields of squarew widget");
intended.request_mode = CWX|CWY;
XtQueryGeometry(squarew, &intended, &geom);
x = geom.x + 10;
y = geom.y + 10;
XtMoveWidget(squarew, x, y );
tet_infoline("TEST: Values have been changed");
XtQueryGeometry(squarew, &intended, &geometry_good);
check_dec(x, geometry_good.x, "x");
check_dec(y, geometry_good.y, "y");
tet_result(TET_PASS);
>>ASSERTION Good A
A call to
void XtMoveWidget(w, x, y)
when
.A x
and
.A y
are both equal to their corresponding values in the
object
.A w
shall return immediately.
>>CODE
XtWidgetGeometry intended, geom, geometry_good;
Widget squarew;
int x, y;
avs_xt_hier("Tmvwidget2", "XtMoveWidget");
tet_infoline("PREP: Create Square Cell widget");
squarew = XtVaCreateManagedWidget("squarew",
squareCellWidgetClass, boxw1, NULL);
tet_infoline("PREP: Put same x, y fields to squarew widget");
intended.request_mode = CWX|CWY;
XtQueryGeometry(squarew, &intended, &geom);
x = geom.x;
y = geom.y;
XtMoveWidget(squarew, x, y);
tet_infoline("TEST: XtMoveWidget returned immediately with same");
tet_infoline("TEST: geometry fields");
XtQueryGeometry(squarew, &intended, &geometry_good);
check_dec(x, geometry_good.x, "x");
check_dec(y, geometry_good.y, "y");
tet_result(TET_PASS);
>>ASSERTION Good A
When
.A w
is a widget that is realized and at least one of
.A x
or
.A y
is different from its corresponding value in the
widget a call to
void XtMoveWidget(w, x, y)
shall move the widget window to the position specified
by
.A x
and
.A y.
>>CODE
XtWidgetGeometry intended, geom, geometry_good;
Widget squarew;
int x, y;
/*should be verified with image capture*/
avs_xt_hier("Tmvwidget1", "XtMoveWidget");
tet_infoline("PREP: Create Square Cell widget");
squarew = XtVaCreateManagedWidget("squarew",
squareCellWidgetClass, boxw1, NULL);
tet_infoline("PREP: Change x, y geometry fields of squarew widget");
intended.request_mode = CWX|CWY;
XtQueryGeometry(squarew, &intended, &geom);
x = geom.x + 10;
y = geom.y + 10;
XtMoveWidget(squarew, x, y );
tet_infoline("TEST: Widget moved");
XtQueryGeometry(squarew, &intended, &geometry_good);
check_dec(x, geometry_good.x, "x");
check_dec(y, geometry_good.y, "y");
tet_result(TET_PASS);
|