-
Notifications
You must be signed in to change notification settings - Fork 24
/
xtfuncs.c
1818 lines (1506 loc) · 55.2 KB
/
xtfuncs.c
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
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*----------------------------------------------------------------------*/
/* xtfuncs.c --- Functions associated with the XCircuit Xt GUI */
/* (no Tcl/Tk interpreter) */
/* Copyright (c) 2002 Tim Edwards, Johns Hopkins University */
/*----------------------------------------------------------------------*/
#ifndef TCL_WRAPPER
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <errno.h>
#include <limits.h>
#ifndef XC_WIN32
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xutil.h>
#include "Xw/Xw.h"
#include "Xw/MenuBtn.h"
#include "Xw/PopupMgr.h"
#endif
/*----------------------------------------------------------------------*/
/* Local includes */
/*----------------------------------------------------------------------*/
#include "colordefs.h"
#include "xcircuit.h"
/*----------------------------------------------------------------------*/
/* Function prototype declarations */
/*----------------------------------------------------------------------*/
#include "prototypes.h"
/*----------------------------------------------------------------------*/
/* External Variable definitions */
/*----------------------------------------------------------------------*/
extern char _STR2[250];
extern char _STR[150]; /* Generic multipurpose string */
extern xcWidget top;
extern Display *dpy;
extern Globaldata xobjs;
extern XCWindowData *areawin;
extern int number_colors;
extern colorindex *colorlist;
extern ApplicationData appdata;
extern Cursor appcursors[NUM_CURSORS];
extern fontinfo *fonts;
extern short fontcount;
extern xcWidget menuwidgets[];
extern xcWidget toolbar;
extern short popups; /* total number of popup windows */
/*----------------------------------------------------------------------*/
/* The rest of the local includes depend on the prototype declarations */
/* and some of the external global variable declarations. */
/*----------------------------------------------------------------------*/
#include "menus.h"
#include "menudep.h"
/*----------------------------------------------------------------------*/
/* External variable definitions */
/*----------------------------------------------------------------------*/
extern u_short *fontnumbers;
extern u_char nfontnumbers;
/*----------------------------------------------*/
/* Set Poly and Arc line styles and fill styles */
/*----------------------------------------------*/
#define BORDERS (NOBORDER | DOTTED | DASHED)
#define ALLFILLS (FILLSOLID | FILLED)
/*--------------------------------------------------------------*/
/* Menu toggle button functions (keeps Xt functions out of the */
/* file menucalls.c). These are wrappers for toggleexcl(). */
/*--------------------------------------------------------------*/
void togglegridstyles(xcWidget button) {
if (button != NULL)
toggleexcl(button, GridStyles, XtNumber(GridStyles));
}
void toggleanchors(xcWidget button) {
if (button != NULL)
toggleexcl(button, Anchors, XtNumber(Anchors));
}
void togglefontstyles(xcWidget button) {
if (button != NULL)
toggleexcl(button, FontStyles, XtNumber(FontStyles));
}
void toggleencodings(xcWidget button) {
if (button != NULL)
toggleexcl(button, FontEncodings, XtNumber(FontEncodings));
}
/*--------------------------------------------------------------*/
/* Toggle a bit in the anchoring field of a label */
/*--------------------------------------------------------------*/
void doanchorbit(xcWidget w, labelptr settext, short bitfield)
{
if (settext != NULL) {
int oldanchor = (int)settext->anchor;
undrawtext(settext);
settext->anchor ^= bitfield;
redrawtext(settext);
pwriteback(areawin->topinstance);
register_for_undo(XCF_Anchor, UNDO_MORE, areawin->topinstance,
(genericptr)settext, oldanchor);
}
else
areawin->anchor ^= bitfield;
if (w != NULL) {
Boolean boolval;
if (settext)
boolval = (settext->anchor & bitfield) ? 0 : 1;
else
boolval = (areawin->anchor & bitfield) ? 0 : 1;
toggle(w, (pointertype)(-1), &boolval);
}
}
/*--------------------------------------------------------------*/
/* Toggle a pin-related bit in the anchoring field of a */
/* label. This differs from doanchorbit() in that the label */
/* must be a pin, and this function cannot change the default */
/* behavior set by areawin->anchor. */
/*--------------------------------------------------------------*/
void dopinanchorbit(xcWidget w, labelptr settext, short bitfield)
{
if ((settext != NULL) && settext->pin) {
int oldanchor = (int)settext->anchor;
undrawtext(settext);
settext->anchor ^= bitfield;
redrawtext(settext);
pwriteback(areawin->topinstance);
register_for_undo(XCF_Anchor, UNDO_MORE, areawin->topinstance,
(genericptr)settext, oldanchor);
if (w != NULL) {
Boolean boolval = (settext->anchor & bitfield) ? 0 : 1;
toggle(w, (pointertype)(-1), &boolval);
}
}
}
/*----------------------------------------------------------------*/
/* Set the anchoring for the label passed as 3rd parameter */
/*----------------------------------------------------------------*/
void setanchor(xcWidget w, pointertype value, labelptr settext, short mode)
{
short newanchor, oldanchor;
if (settext != NULL) {
if (mode == 1)
newanchor = (settext->anchor & (NONANCHORFIELD | TBANCHORFIELD))
| value;
else
newanchor = (settext->anchor & (NONANCHORFIELD | RLANCHORFIELD))
| value;
if (settext->anchor != newanchor) {
oldanchor = (int)settext->anchor;
undrawtext(settext);
settext->anchor = newanchor;
redrawtext(settext);
pwriteback(areawin->topinstance);
register_for_undo(XCF_Anchor, UNDO_MORE, areawin->topinstance,
(genericptr)settext, oldanchor);
}
}
else {
if (mode == 1)
newanchor = (areawin->anchor & (NONANCHORFIELD | TBANCHORFIELD))
| value;
else
newanchor = (areawin->anchor & (NONANCHORFIELD | RLANCHORFIELD))
| value;
areawin->anchor = newanchor;
}
if (w != NULL) toggleanchors(w);
}
/*--------------------------------------------------------------*/
/* Set vertical anchoring (top, middle, bottom) on all */
/* selected labels */
/*--------------------------------------------------------------*/
void setvanchor(xcWidget w, pointertype value, caddr_t nulldata)
{
short *fselect;
labelptr settext;
short labelcount = 0;
if (eventmode == TEXT_MODE || eventmode == ETEXT_MODE) {
settext = *((labelptr *)EDITPART);
setanchor(w, value, settext, 2);
}
else {
for (fselect = areawin->selectlist; fselect < areawin->selectlist +
areawin->selects; fselect++) {
if (SELECTTYPE(fselect) == LABEL) {
labelcount++;
settext = SELTOLABEL(fselect);
setanchor(NULL, value, settext, 2);
}
}
if (labelcount == 0) setanchor(w, value, NULL, 2);
else unselect_all();
}
}
/*----------------------------------------------------------------*/
/* Set horizontal anchoring (left, center, right) on all */
/* selected labels */
/*----------------------------------------------------------------*/
void sethanchor(xcWidget w, pointertype value, caddr_t nulldata)
{
short *fselect;
labelptr settext;
short labelcount = 0;
if (eventmode == TEXT_MODE || eventmode == ETEXT_MODE) {
settext = *((labelptr *)EDITPART);
setanchor(w, value, settext, 1);
}
else {
for (fselect = areawin->selectlist; fselect < areawin->selectlist +
areawin->selects; fselect++) {
if (SELECTTYPE(fselect) == LABEL) {
labelcount++;
settext = SELTOLABEL(fselect);
setanchor(NULL, value, settext, 1);
}
}
if (labelcount == 0) setanchor(w, value, NULL, 1);
else unselect_all();
}
}
/*--------------------------------------------------------------*/
/* Set an anchor field bit on all selected labels */
/* (flip invariance, latex mode, etc.) */
/*--------------------------------------------------------------*/
void setanchorbit(xcWidget w, pointertype value, caddr_t nulldata)
{
short *fselect;
labelptr settext;
short labelcount = 0;
if (eventmode == TEXT_MODE || eventmode == ETEXT_MODE) {
settext = *((labelptr *)EDITPART);
doanchorbit(w, settext, (short)value);
}
else {
for (fselect = areawin->selectlist; fselect < areawin->selectlist +
areawin->selects; fselect++) {
if (SELECTTYPE(fselect) == LABEL) {
labelcount++;
settext = SELTOLABEL(fselect);
doanchorbit(NULL, settext, (short)value);
}
}
if (labelcount == 0) doanchorbit(w, NULL, (short)value);
else unselect_all();
}
}
/*--------------------------------------------------------------*/
/* Set pin-related bit field of "anchor" on all selected pins */
/* (e.g., pin visibility) */
/*--------------------------------------------------------------*/
void setpinanchorbit(xcWidget w, pointertype value, caddr_t nulldata)
{
short *fselect;
labelptr settext;
if (eventmode == TEXT_MODE || eventmode == ETEXT_MODE) {
settext = *((labelptr *)EDITPART);
if (settext->pin)
dopinanchorbit(w, settext, (short)value);
}
else {
for (fselect = areawin->selectlist; fselect < areawin->selectlist +
areawin->selects; fselect++) {
if (SELECTTYPE(fselect) == LABEL) {
settext = SELTOLABEL(fselect);
if (settext->pin)
dopinanchorbit(NULL, settext, (short)value);
}
}
unselect_all();
}
}
/*--------------------------------------------------------------*/
/* Enable or Disable the toolbar */
/*--------------------------------------------------------------*/
#ifdef HAVE_XPM
void dotoolbar(xcWidget w, caddr_t clientdata, caddr_t calldata)
{
Arg wargs[1];
if (areawin->toolbar_on) {
areawin->toolbar_on = False;
XtUnmanageChild(toolbar);
XtSetArg(wargs[0], XtNlabel, "Enable Toolbar");
XtSetValues(OptionsDisableToolbarButton, wargs, 1);
XtRemoveCallback(areawin->area, XtNresize, (XtCallbackProc)resizetoolbar, NULL);
}
else {
areawin->toolbar_on = True;
XtManageChild(toolbar);
XtSetArg(wargs[0], XtNlabel, "Disable Toolbar");
XtSetValues(OptionsDisableToolbarButton, wargs, 1);
XtAddCallback(areawin->area, XtNresize, (XtCallbackProc)resizetoolbar, NULL);
}
}
/*--------------------------------------------------------------*/
/* Overwrite the toolbar pixmap for color or stipple entries */
/*--------------------------------------------------------------*/
#ifndef XC_WIN32
void overdrawpixmap(xcWidget button)
{
xcWidget pbutton;
Arg args[3];
int ltype, color;
Pixmap stippix;
if (button == NULL) return;
XtSetArg(args[0], XtNlabelType, <ype);
XtGetValues(button, args, 1);
if (ltype != XwRECT && button != ColorInheritColorButton) return;
XtSetArg(args[0], XtNrectColor, &color);
XtSetArg(args[1], XtNrectStipple, &stippix);
XtGetValues(button, args, 2);
if (stippix == (Pixmap)NULL && button != FillBlackButton)
pbutton = ColorsToolButton;
else
pbutton = FillsToolButton;
if (button == ColorInheritColorButton) {
XtSetArg(args[0], XtNlabelType, XwIMAGE);
XtSetValues(pbutton, args, 1);
}
else if (button == FillBlackButton) {
XtSetArg(args[0], XtNlabelType, XwRECT);
XtSetArg(args[1], XtNrectColor, color);
XtSetArg(args[2], XtNrectStipple, (Pixmap)NULL);
XtSetValues(pbutton, args, 3);
}
else if (button != FillOpaqueButton) {
XtSetArg(args[0], XtNlabelType, XwRECT);
if (stippix == (Pixmap)NULL)
XtSetArg(args[1], XtNrectColor, color);
else
XtSetArg(args[1], XtNrectStipple, stippix);
XtSetValues(pbutton, args, 2);
}
}
#endif
#else
void overdrawpixmap(xcWidget button) {}
#endif /* XPM */
/*--------------------------------------------------------------*/
/* Generic routine for use by all other data handling routines */
/*--------------------------------------------------------------*/
buttonsave *getgeneric(xcWidget button, void (*getfunction)(), void *dataptr)
{
Arg wargs[1];
buttonsave *saveptr;
saveptr = (buttonsave *)malloc(sizeof(buttonsave));
saveptr->button = button;
saveptr->buttoncall = getfunction;
saveptr->dataptr = dataptr;
if (button != NULL) {
XtSetArg(wargs[0], XtNforeground, &saveptr->foreground);
XtGetValues(button, wargs, 1);
XtSetArg(wargs[0], XtNforeground, colorlist[OFFBUTTONCOLOR].color.pixel);
XtSetValues(button, wargs, 1);
XtRemoveAllCallbacks(button, XtNselect);
}
return saveptr;
}
/*--------------------------------------------------------------*/
/* Generate popup dialog for snap space value input */
/*--------------------------------------------------------------*/
void getsnapspace(xcWidget button, caddr_t clientdata, caddr_t calldata)
{
char buffer[50];
buttonsave *savebutton;
float *floatptr = &xobjs.pagelist[areawin->page]->snapspace;
savebutton = getgeneric(button, getsnapspace, (void *)floatptr);
measurestr(*floatptr, buffer);
popupprompt(button, "Enter value:", buffer, setgrid, savebutton, NULL);
}
/*--------------------------------------------------------------*/
/* Generate popup dialog for grid space value input */
/*--------------------------------------------------------------*/
void getgridspace(xcWidget button, caddr_t clientdata, caddr_t calldata)
{
char buffer[50];
buttonsave *savebutton;
float *floatptr = &xobjs.pagelist[areawin->page]->gridspace;
savebutton = getgeneric(button, getgridspace, (void *)floatptr);
measurestr(*floatptr, buffer);
popupprompt(button, "Enter value:", buffer, setgrid, savebutton, NULL);
}
/*----------------------------------------------------------------*/
/* Generic routine for setting a floating-point value (through a */
/* (float *) pointer passed as the second parameter) */
/*----------------------------------------------------------------*/
void setfloat(xcWidget w, float *dataptr)
{
float oldvalue = *dataptr;
int res = sscanf(_STR2, "%f", dataptr);
if (res == 0 || *dataptr <= 0) {
*dataptr = oldvalue;
Wprintf("Illegal value");
}
if (oldvalue != *dataptr) drawarea(NULL, NULL, NULL);
}
/*----------------------------------------------------------------*/
/* Set text scale. */
/*----------------------------------------------------------------*/
void settsize(xcWidget w, labelptr settext)
{
float tmpres;
int res = sscanf(_STR2, "%f", &tmpres);
if (res == 0 || tmpres <= 0) { /* can't interpret value or bad value */
Wprintf("Illegal value");
return;
}
changetextscale(tmpres);
if (areawin->selects > 0) unselect_all();
}
/*--------------------------------------------------------------*/
/* Auto-set: Enable automatic scaling */
/*--------------------------------------------------------------*/
void autoset(xcWidget w, xcWidgetList entertext, caddr_t nulldata)
{
xobjs.pagelist[areawin->page]->pmode |= 2;
updatetext(w, entertext, nulldata);
}
/*--------------------------------------------------------------*/
void autostop(xcWidget w, caddr_t clientdata, caddr_t nulldata)
{
xobjs.pagelist[areawin->page]->pmode &= 1;
}
/*--------------------------------------------------------------*/
/* Set the denomenator value of the drawing scale */
/*--------------------------------------------------------------*/
void setscaley(xcWidget w, float *dataptr)
{
float oldvalue = *dataptr;
int res = sscanf(_STR2, "%f", dataptr);
if (res == 0 || *dataptr <= 0 || topobject->bbox.height == 0) {
*dataptr = oldvalue;
Wprintf("Illegal value");
}
else {
*dataptr = (*dataptr * 72) / topobject->bbox.height;
*dataptr /= getpsscale(1.0, areawin->page);
}
}
/*----------------------------------------------------------------*/
/* Set the numerator value of the drawing scale */
/*----------------------------------------------------------------*/
void setscalex(xcWidget w, float *dataptr)
{
float oldvalue = *dataptr;
int res = sscanf(_STR2, "%f", dataptr);
if (res == 0 || *dataptr <= 0 || topobject->bbox.width == 0) {
*dataptr = oldvalue;
Wprintf("Illegal value");
}
else {
*dataptr = (*dataptr * 72) / topobject->bbox.width;
*dataptr /= getpsscale(1.0, areawin->page);
}
}
/*----------------------------------------------------------------*/
/* Set the page orientation (either Landscape or Portrait) */
/*----------------------------------------------------------------*/
void setorient(xcWidget w, short *dataptr)
{
Arg wargs[1];
if (*dataptr == 0) {
*dataptr = 90;
XtSetArg(wargs[0], XtNlabel, "Landscape");
}
else {
*dataptr = 0;
XtSetArg(wargs[0], XtNlabel, "Portrait");
}
XtSetValues(w, wargs, 1);
}
/*----------------------------------------------------------------*/
/* Set the output mode to "Full Page" (unencapsulated PostScript) */
/* or "Embedded" (encapsulated PostScript) */
/*----------------------------------------------------------------*/
void setpmode(xcWidget w, short *dataptr)
{
Arg wargs[1];
xcWidget pwidg = XtParent(w);
xcWidget autowidg = XtNameToWidget(pwidg, "Auto-fit");
if (!(*dataptr & 1)) {
*dataptr = 1;
XtSetArg(wargs[0], XtNlabel, "Full Page");
XtManageChild(XtNameToWidget(pwidg, "fpedit"));
XtManageChild(XtNameToWidget(pwidg, "fpokay"));
XtManageChild(autowidg);
}
else {
*dataptr = 0; /* This also turns off auto-fit */
XtSetArg(wargs[0], XtNset, False);
XtSetValues(autowidg, wargs, 1);
XtSetArg(wargs[0], XtNlabel, "Embedded");
XtUnmanageChild(XtNameToWidget(pwidg, "fpedit"));
XtUnmanageChild(XtNameToWidget(pwidg, "fpokay"));
XtUnmanageChild(autowidg);
}
XtSetValues(w, wargs, 1);
}
/*--------------------------------------------------------------*/
/* Set the output page size, in the current unit of measure */
/*--------------------------------------------------------------*/
void setpagesize(xcWidget w, XPoint *dataptr)
{
char fpedit[75];
Arg wargs[1];
Boolean is_inches;
is_inches = setoutputpagesize(dataptr);
sprintf(fpedit, "%3.2f x %3.2f %s",
(float)xobjs.pagelist[areawin->page]->pagesize.x / 72.0,
(float)xobjs.pagelist[areawin->page]->pagesize.y / 72.0,
(is_inches) ? "in" : "cm");
XtSetArg(wargs[0], XtNstring, fpedit);
XtSetValues(XtNameToWidget(XtParent(w), "fpedit"), wargs, 1);
}
/*--------------------------------------------------------------*/
/* Generate popup dialog to get a character kern value, which */
/* is two integer numbers in the range -128 to +127 (size char) */
/*--------------------------------------------------------------*/
void getkern(xcWidget button, caddr_t nulldata, caddr_t calldata)
{
char buffer[50];
buttonsave *savebutton;
int kx, ky;
stringpart *strptr, *nextptr;
strcpy(buffer, "0,0");
if (eventmode == TEXT_MODE || eventmode == ETEXT_MODE) {
labelptr curlabel = TOLABEL(EDITPART);
strptr = findstringpart(areawin->textpos - 1, NULL, curlabel->string,
areawin->topinstance);
nextptr = findstringpart(areawin->textpos, NULL, curlabel->string,
areawin->topinstance);
if (strptr->type == KERN) {
kx = strptr->data.kern[0];
ky = strptr->data.kern[1];
sprintf(buffer, "%d,%d", kx, ky);
}
else if (nextptr && nextptr->type == KERN) {
strptr = nextptr;
kx = strptr->data.kern[0];
ky = strptr->data.kern[1];
sprintf(buffer, "%d,%d", kx, ky);
}
else strptr = NULL;
}
savebutton = getgeneric(button, getkern, strptr);
popupprompt(button, "Enter Kern X,Y:", buffer, setkern, savebutton, NULL);
}
/*----------------------------------------------------------------*/
/* Generate popup dialog to get the drawing scale, specified as a */
/* whole-number ratio X:Y */
/*----------------------------------------------------------------*/
void getdscale(xcWidget button, caddr_t nulldata, caddr_t calldata)
{
char buffer[50];
buttonsave *savebutton;
XPoint *ptptr = &(xobjs.pagelist[areawin->page]->drawingscale);
savebutton = getgeneric(button, getdscale, ptptr);
sprintf(buffer, "%d:%d", ptptr->x, ptptr->y);
popupprompt(button, "Enter Scale:", buffer, setdscale, savebutton, NULL);
}
/*--------------------------------------------------------------*/
/* Generate the popup dialog for getting text scale. */
/*--------------------------------------------------------------*/
void gettsize(xcWidget button, caddr_t nulldata, caddr_t calldata)
{
char buffer[50];
buttonsave *savebutton;
float *floatptr;
Boolean local;
labelptr settext;
settext = gettextsize(&floatptr);
sprintf(buffer, "%5.2f", *floatptr);
if (settext) {
savebutton = getgeneric(button, gettsize, settext);
popupprompt(button, "Enter text scale:", buffer, settsize, savebutton, NULL);
}
else {
savebutton = getgeneric(button, gettsize, floatptr);
popupprompt(button,
"Enter default text scale:", buffer, setfloat, savebutton, NULL);
}
}
/*----------------------------------------------------------------*/
/* Generate popup dialog for getting object scale */
/*----------------------------------------------------------------*/
void getosize(xcWidget button, caddr_t clientdata, caddr_t calldata)
{
char buffer[50];
float flval;
buttonsave *savebutton;
short *osel = areawin->selectlist;
short selects = 0;
objinstptr setobj = NULL;
for (; osel < areawin->selectlist + areawin->selects; osel++)
if (SELECTTYPE(osel) == OBJINST) {
setobj = SELTOOBJINST(osel);
selects++;
break;
}
if (setobj == NULL) {
Wprintf("No objects were selected for scaling.");
return;
}
flval = setobj->scale;
savebutton = getgeneric(button, getosize, setobj);
sprintf(buffer, "%4.2f", flval);
popupprompt(button, "Enter object scale:", buffer, setosize, savebutton, NULL);
}
/*----------------------------------------------------------------*/
/* Generate popup prompt for getting global linewidth */
/*----------------------------------------------------------------*/
void getwirewidth(xcWidget button, caddr_t clientdata, caddr_t calldata)
{
char buffer[50];
buttonsave *savebutton;
float *widthptr;
widthptr = &(xobjs.pagelist[areawin->page]->wirewidth);
savebutton = getgeneric(button, getwirewidth, widthptr);
sprintf(buffer, "%4.2f", *widthptr / 2.0);
popupprompt(button, "Enter new global linewidth:", buffer, setwidth,
savebutton, NULL);
}
/*----------------------------------------------------------------*/
/* Generate popup dialong for getting linewidths of elements */
/*----------------------------------------------------------------*/
void getwwidth(xcWidget button, caddr_t clientdata, caddr_t calldata)
{
char buffer[50];
buttonsave *savebutton;
short *osel = areawin->selectlist;
genericptr setel;
float flval;
for (; osel < areawin->selectlist + areawin->selects; osel++) {
setel = *(topobject->plist + (*osel));
if (IS_ARC(setel)) {
flval = ((arcptr)setel)->width;
break;
}
else if (IS_POLYGON(setel)) {
flval = ((polyptr)setel)->width;
break;
}
else if (IS_SPLINE(setel)) {
flval = ((splineptr)setel)->width;
break;
}
else if (IS_PATH(setel)) {
flval = ((pathptr)setel)->width;
break;
}
}
savebutton = getgeneric(button, getwwidth, setel);
if (osel == areawin->selectlist + areawin->selects) {
sprintf(buffer, "%4.2f", areawin->linewidth);
popupprompt(button, "Enter new default line width:", buffer, setwwidth,
savebutton, NULL);
}
else {
sprintf(buffer, "%4.2f", flval);
popupprompt(button, "Enter new line width:", buffer, setwwidth,
savebutton, NULL);
}
}
/*----------------------------------------------------------------*/
/* Generic popup prompt for getting a floating-point value */
/*----------------------------------------------------------------*/
void getfloat(xcWidget button, float *floatptr, caddr_t calldata)
{
char buffer[50];
buttonsave *savebutton;
savebutton = getgeneric(button, getfloat, floatptr);
sprintf(buffer, "%4.2f", *floatptr);
popupprompt(button, "Enter value:", buffer, setfloat, savebutton, NULL);
}
/*----------------------------------------------------------------*/
/* Set the filename for the current page */
/*----------------------------------------------------------------*/
void setfilename(xcWidget w, char **dataptr)
{
short cpage, depend = 0;
objectptr checkpage;
char *oldstr = xobjs.pagelist[areawin->page]->filename;
if ((*dataptr != NULL) && !strcmp(*dataptr, _STR2))
return; /* no change in string */
/* Make the change to the current page */
xobjs.pagelist[areawin->page]->filename = strdup(_STR2);
/* All existing filenames which match the old string should also be changed */
for (cpage = 0; cpage < xobjs.pages; cpage++) {
if ((xobjs.pagelist[cpage]->pageinst != NULL) && (cpage != areawin->page)) {
if ((oldstr != NULL) && (!strcmp(xobjs.pagelist[cpage]->filename, oldstr))) {
free(xobjs.pagelist[cpage]->filename);
xobjs.pagelist[cpage]->filename = strdup(_STR2);
}
}
}
free(oldstr);
}
/*----------------------------------------------------------------*/
/* Set the page label for the current page */
/*----------------------------------------------------------------*/
void setpagelabel(xcWidget w, char *dataptr)
{
short i;
/* Whitespace and non-printing characters not allowed */
for (i = 0; i < strlen(_STR2); i++) {
if ((!isprint(_STR2[i])) || (isspace(_STR2[i]))) {
_STR2[i] = '_';
Wprintf("Replaced illegal whitespace in name with underscore");
}
}
if (!strcmp(dataptr, _STR2)) return; /* no change in string */
if (strlen(_STR2) == 0)
sprintf(topobject->name, "Page %d", areawin->page + 1);
else
sprintf(topobject->name, "%.79s", _STR2);
/* For schematics, all pages with associations to symbols must have */
/* unique names. */
if (topobject->symschem != NULL) checkpagename(topobject);
printname(topobject);
renamepage(areawin->page);
}
/*--------------------------------------------------------------*/
/* Change the Button1 binding for a particular mode (non-Tcl) */
/*--------------------------------------------------------------*/
/*--------------------------------------------------------------*/
/* Change to indicated tool (key binding w/o value) */
/*--------------------------------------------------------------*/
void changetool(xcWidget w, pointertype value, caddr_t nulldata)
{
mode_rebinding((int)value, (short)-1);
highlightexcl(w, (int)value, (int)-1);
}
/*--------------------------------------------------------------*/
/* Execute function binding for the indicated tool if something */
/* is selected; otherwise, change to the indicated tool mode. */
/*--------------------------------------------------------------*/
void exec_or_changetool(xcWidget w, pointertype value, caddr_t nulldata)
{
if (areawin->selects > 0)
mode_tempbinding((int)value, -1);
else {
mode_rebinding((int)value, -1);
highlightexcl(w, (int)value, -1);
}
}
/*--------------------------------------------------------------*/
/* Special case of exec_or_changetool(), where an extra value */
/* is passed to the routine indication amount of rotation, or */
/* type of flip operation. */
/*--------------------------------------------------------------*/
void rotatetool(xcWidget w, pointertype value, caddr_t nulldata)
{
if (areawin->selects > 0)
mode_tempbinding(XCF_Rotate, (int)value);
else {
mode_rebinding(XCF_Rotate, (int)value);
highlightexcl(w, (int)XCF_Rotate, (int)value);
}
}
/*--------------------------------------------------------------*/
/* Special case of changetool() for pan mode, where a value is */
/* required to pass to the key binding routine. */
/*--------------------------------------------------------------*/
void pantool(xcWidget w, pointertype value, caddr_t nulldata)
{
mode_rebinding(XCF_Pan, (int)value);
highlightexcl(w, (int)XCF_Pan, (int)value);
}
/*--------------------------------------------------------------*/
/* Add a new font name to the list of known fonts */
/* Register the font number for the Alt-F cycling mechanism */
/* Tcl: depends on command tag mechanism for GUI menu update. */
/*--------------------------------------------------------------*/
void makenewfontbutton()
{
Arg wargs[1];
int n = 0;
xcWidget newbutton, cascade;
if (fontcount == 0) return;
cascade = XtParent(FontAddNewFontButton);
XtnSetArg(XtNfont, appdata.xcfont);
newbutton = XtCreateWidget(fonts[fontcount - 1].family, XwmenubuttonWidgetClass,
cascade, wargs, n);
XtAddCallback (newbutton, XtNselect, (XtCallbackProc)setfont,
Number(fontcount - 1));
XtManageChild(newbutton);
nfontnumbers++;
if (nfontnumbers == 1)
fontnumbers = (u_short *)malloc(sizeof(u_short));
else
fontnumbers = (u_short *)realloc(fontnumbers, nfontnumbers
* sizeof(u_short));
fontnumbers[nfontnumbers - 1] = fontcount - 1;
}
/*--------------------------------------------------------------*/
/* Make new encoding menu button */
/*--------------------------------------------------------------*/
void makenewencodingbutton(char *ename, char value)
{
Arg wargs[1];
int n = 0;
xcWidget newbutton, cascade;
cascade = XtParent(EncodingStandardButton);
/* return if button has already been made */
newbutton = XtNameToWidget(cascade, ename);
if (newbutton != NULL) return;
XtnSetArg(XtNfont, appdata.xcfont);
newbutton = XtCreateWidget(ename, XwmenubuttonWidgetClass,
cascade, wargs, n);
XtAddCallback (newbutton, XtNselect, (XtCallbackProc)setfontencoding,
Number(value));
XtManageChild(newbutton);
}
/*--------------------------------------------------------------*/
/* Set the menu checkmarks on the font menu */
/*--------------------------------------------------------------*/
void togglefontmark(int fontval)
{
Arg args[1];
xcWidget widget, cascade, sibling;
short i;
cascade = XtParent(FontAddNewFontButton);
widget = XtNameToWidget(cascade, fonts[fontval].family);
/* Remove checkmark from all widgets in the list */
XtSetArg(args[0], XtNsetMark, False);
for (i = 0; i < fontcount; i++) {
if (i != fontval) {
sibling = XtNameToWidget(cascade, fonts[i].family);
XtSetValues(sibling, args, 1);
}
}
/* Add checkmark to designated font */
XtSetArg(args[0], XtNsetMark, True);
XtSetValues(widget, args, 1);
}