-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.c
1651 lines (1406 loc) · 40 KB
/
classes.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
/* Several graphics base classes
*
* Copyright 1996-2007 pinc Software. All Rights Reserved.
* Licensed under the terms of the GNU General Public License, version 3.
*/
#include "types.h"
#include "funcs.h"
#include "classes.h"
#include <graphics/scale.h>
#ifdef __amigaos4__
#include <proto/elf.h>
#endif
#define G_POINTS 8
#define GRLOAD_BUFFERSIZE 2048
#ifdef DEBUG
# define GLOAD(x) ;
#else
# define GLOAD(x) ;
#endif
struct MinList gclasses, gdiagrams, intclasses;
extern struct RastPort *doublerp;
extern struct { UWORD jsr; APTR func; } gClassFuncTable[];
extern int32 gClassFuncTableSize;
// these should be "const", but SAS/C seems to have problems with this (at compile time)...
/*************************************** class definitions ***************************************/
const STRPTR gcNames[] = {"embedded","embed_diagram","axes", "picture",NULL};
const STRPTR gcSuper[] = {"root", "embedded", "diagram","root"};
const UBYTE gcTypes[] = {0, 0, 0, GCT_OBJECT};
const STRPTR gcImages[] = {NULL, NULL, NULL, "icons/obj_pic.icon"};
const APTR gcDispatch[] = {gEmbeddedDispatch, gEmbedDiagramDispatch, gAxesDispatch, gPictureDispatch};
const APTR gcDraw[] = {gEmbeddedDraw, gEmbedDiagramDraw, gAxesDraw, gPictureDraw};
struct gInterface *gcInterface[] = {gEmbeddedInterface, gEmbedDiagramInterface, gAxesInterface, gPictureInterface};
const ULONG gcObjSize[] = {sizeof(struct gEmbedded), 0, sizeof(struct gAxes), sizeof(struct gPicture)};
STRPTR gcLabels[4];
/*************************************** rootclass ***************************************/
struct gInterface gRootInterface[] = {
{GOA_Name, NULL, GIT_TEXT, NULL, "name"},
{0}
};
ULONG
gRootSet(struct gObject *go,struct TagItem *tstate)
{
struct TagItem *ti;
if (tstate) {
while ((ti = NextTagItem(&tstate)) != 0) {
switch (ti->ti_Tag) {
case GOA_Name:
FreeString(go->go_Node.ln_Name);
go->go_Node.ln_Name = AllocString((STRPTR)ti->ti_Data);
break;
case GOA_Help:
FreeString(go->go_Help);
go->go_Help = AllocString((STRPTR)ti->ti_Data);
break;
case GOA_Command:
FreeString(go->go_Command);
go->go_Command = AllocString((STRPTR)ti->ti_Data);
break;
case GOA_Page:
go->go_Page = (struct Page *)ti->ti_Data;
break;
case GOA_ContinualCommand:
if (ti->ti_Data)
go->go_Flags |= GOF_CONTINUALCMD;
else
go->go_Flags &= ~GOF_CONTINUALCMD;
break;
}
}
}
return GCPR_NONE;
}
#if (G_POINTS == 8)
void
gRootSetEdgeKnobs(struct point2d *p)
{
p[4].x = (p[3].x+p[0].x)/2; p[4].y = p[0].y;
p[5].x = p[4].x; p[5].y = p[3].y;
p[6].x = p[0].x; p[6].y = (p[3].y+p[0].y)/2;
p[7].x = p[3].x; p[7].y = p[6].y;
}
#endif
void
WriteTag(struct IFFHandle *iff,UBYTE cmd,ULONG tag)
{
WriteChunkBytes(iff,&cmd,1);
WriteChunkBytes(iff,&tag,4);
}
UBYTE *gio_types;
LONG gio_numtags;
static void
AddGObjectTag(struct TagItem **tags, long *tagpos, ULONG tag, UBYTE type, APTR data)
{
if (*tagpos + 1 > gio_numtags) {
struct TagItem *newtags;
UBYTE *newtypes;
if ((newtags = AllocPooled(pool, (gio_numtags + 14) * sizeof(struct TagItem))) != 0) {
if ((newtypes = AllocPooled(pool, (gio_numtags + 14))) != 0) {
if (gio_types) {
CopyMem(gio_types,newtypes,gio_numtags);
FreePooled(pool,gio_types,gio_numtags);
}
gio_types = newtypes;
}
if (*tags) {
CopyMem(*tags,newtags,gio_numtags * sizeof(struct TagItem));
FreePooled(pool,*tags,gio_numtags * sizeof(struct TagItem));
}
*tags = newtags;
gio_numtags += 14;
} else
return;
}
if (!*tags)
return;
(*tags)[*tagpos].ti_Tag = tag;
(*tags)[*tagpos].ti_Data = (ULONG)data;
gio_types[*tagpos] = type;
(*tagpos)++;
}
void
FreeLoadedGObjectTags(struct TagItem *tags)
{
if (!tags)
return;
if (gio_types) {
int i;
for (i = 0;i < gio_numtags;i++) {
switch (gio_types[i]) {
case GIT_FILENAME:
case GIT_TEXT:
case GIT_FORMULA:
FreeString((STRPTR)tags[i].ti_Data);
break;
}
}
FreePooled(pool,gio_types,gio_numtags);
}
FreePooled(pool,tags,gio_numtags*sizeof(struct TagItem));
}
struct TagItem *
LoadGObjectTags(struct gcpIO *gcpio)
{
struct IFFHandle *iff = gcpio->gcpio_IFFHandle;
struct TagItem *tags = NULL;
long i,tag,tagpos = 0;
char *buf,type;
STRPTR s;
if (!(buf = AllocPooled(pool,GRLOAD_BUFFERSIZE)))
return NULL;
gio_numtags = 0; gio_types = NULL;
do {
ReadChunkBytes(iff,&type,1);
if (!type)
break;
if (ReadChunkBytes(iff,&tag,4) != 4)
break;
switch (type) {
case GIT_FONT:
{
LONG size,style;
UWORD number;
if (ReadChunkBytes(iff, &number, 2) == 2
&& ReadChunkBytes(iff, &size, 4) == 4
&& ReadChunkBytes(iff, &style, 4)) {
struct Node *ln;
if ((ln = FindListNumber(gcpio->gcpio_Fonts, number)) != 0) {
struct FontInfo *fi;
if ((fi = NewFontInfo(NULL, gDPI, FA_Family, ln->ln_Name,
FA_PointHeight, size,
FA_Style, style,
TAG_END)) != 0)
AddGObjectTag(&tags, &tagpos, tag, type, fi);
GLOAD(bug(" font: %s - size: %ld - style: %ld\n",((struct Node *)ln->ln_Name)->ln_Name,size >> 16,style));
} else {
GLOAD(bug(" font not found.\n"));
}
}
break;
}
case GIT_FILENAME:
case GIT_TEXT:
if ((s = AllocString(ReadChunkString(iff, buf, GRLOAD_BUFFERSIZE))) != 0)
AddGObjectTag(&tags,&tagpos,tag,type,s);
GLOAD(bug(" text: '%s'\n",s));
break;
case GIT_FORMULA:
{
if ((s = ReadChunkString(iff, buf, GRLOAD_BUFFERSIZE)) != 0) {
long oldflags = calcflags;
struct Term *term = NULL;
if (*s == '=')
{
term = CreateTree(gcpio->gcpio_Page, s);
}
else if (*s == '#')
s = AllocString(s + 1);
else
s = AllocString(s);
calcflags = calcflags & ~(CF_REQUESTER | CF_SHORTFUNCS);
AddGObjectTag(&tags,&tagpos,tag,type,term ? TreeTerm(term,TRUE) : s);
DeleteTree(term);
calcflags = oldflags;
}
GLOAD(bug(" formula: '%s'\n",s));
break;
}
case GIT_CYCLE:
case GIT_CHECKBOX:
case GIT_WEIGHT:
case GIT_BUTTON:
if (ReadChunkBytes(iff,&i,4) == 4)
AddGObjectTag(&tags,&tagpos,tag,type,(APTR)i);
GLOAD(bug(" value: %ld\n",i));
break;
case GIT_PEN:
i = 0;
if (ReadChunkBytes(iff,&i,3) == 3) {
i = (i >> 8) & 0xffffff;
AddGObjectTag(&tags,&tagpos,tag,type,(APTR)i);
}
GLOAD(bug(" pen: %lx\n",i));
break;
}
} while (tag);
FreePooled(pool, buf, GRLOAD_BUFFERSIZE);
if (tags)
AddGObjectTag(&tags, &tagpos, TAG_END, 0, NULL);
return tags;
}
struct gObject *
gRootLoad(struct gObject *go,struct gcpIO *gcpio)
{
struct IFFHandle *iff = gcpio->gcpio_IFFHandle;
struct TagItem *tags;
struct gClass *gc;
struct point2d *p;
long i,num,pos;
STRPTR s,name;
if (go) /* called as a member function */
return NULL;
GLOAD(bug("gRootLoad() - class function\n"));
{
char ibuf[128];
if (!(s = ReadChunkString(iff,ibuf,128)))
return NULL;
if (!(gc = FindGClass(s)))
return NULL;
if (!(gc->gc_Node.in_Type & GCT_INTERNAL) && !gc->gc_Segment && !LoadGClass(gc))
return NULL;
if (!(name = AllocString(ReadChunkString(iff,ibuf,128))))
return NULL;
}
ReadChunkBytes(iff,&pos,4);
if (ReadChunkBytes(iff,&num,4) != 4 || !num || !(p = AllocPooled(pool,sizeof(struct point2d)*num)))
{
FreeString(name);
return NULL;
}
ReadChunkBytes(iff,p,sizeof(struct point2d)*num);
tags = LoadGObjectTags(gcpio);
{
struct point2d *sp;
gDoClassMethod(gc,NULL,GCM_ENDPOINTS,p,i = num,&sp,&num);
if (sp != p)
FreePooled(pool,p,i*sizeof(struct point2d));
if (sp && num && (go = (struct gObject *)gDoClassMethod(gc,gc,GCM_NEW,tags,gcpio->gcpio_Page)))
{
go->go_Node.ln_Name = name;
go->go_Pos = pos;
go->go_Knobs = sp;
go->go_NumKnobs = num;
RefreshGObjectBounds(gcpio->gcpio_Page,go);
}
FreeLoadedGObjectTags(tags);
if (go)
{
if (gDoMethodA(go,(Msg)gcpio) < 0)
ErrorRequest(GetString(&gLocaleInfo, MSG_LOAD_OBJECT_ERR),go->go_Node.ln_Name,gc->gc_Node.in_Name);
}
else if (sp)
FreePooled(pool,sp,num*sizeof(struct point2d));
}
return go;
}
void
SaveGInterface(struct gcpIO *gcpio, struct gInterface *gi, struct gObject *go)
{
struct IFFHandle *iff = gcpio->gcpio_IFFHandle;
struct MinList *fonts = gcpio->gcpio_Fonts;
long tag,i;
if (!gi)
return;
for (; (tag = gi->gi_Tag); gi++)
{
UBYTE c;
switch (c = (UBYTE)gi->gi_Type)
{
case GIT_TEXT:
case GIT_FILENAME:
{
STRPTR s;
if (GetGObjectAttr(go,tag,(ULONG *)&s) && s)
{
WriteTag(iff,c,tag);
WriteChunkString(iff,s);
}
break;
}
case GIT_FORMULA:
{
STRPTR s;
if (GetGObjectAttr(go,tag,(ULONG *)&s) && s)
{
long oldflags = calcflags;
struct Term *term = NULL;
WriteTag(iff, c, tag);
if (*s == '=')
{
calcflags &= ~CF_SHORTFUNCS;
#ifdef __amigaos4__
term = CreateTree(go->go_Page,s); //graphic.h line 440 is gcpio_Page only valid for Load
#else
term = CreateTree(gcpio->gcpio_Page,s);
#endif
calcflags |= CF_SHORTFUNCS;
}
WriteChunkString(iff,term ? StaticTreeTerm(term,FALSE) : s);
DeleteTree(term);
calcflags = oldflags;
}
break;
}
case GIT_FONT:
{
struct NumberLink *nl = NULL;
struct FontInfo *fi;
if (GetGObjectAttr(go,tag,(ULONG *)&fi) && (nl = FindLink(fonts,fi->fi_Family)))
{
WriteTag(iff,c,tag);
WriteChunkBytes(iff,&nl->nl_Number,2);
WriteChunkBytes(iff,&fi->fi_FontSize->fs_PointHeight,4);
WriteChunkBytes(iff,&fi->fi_Style,4);
}
break;
}
case GIT_PEN:
{
ULONG pen;
if (GetGObjectAttr(go, tag, &pen))
{
WriteTag(iff, c, tag);
WriteChunkBytes(iff, ((UBYTE *)&pen) + 1, 3);
}
break;
}
case GIT_CYCLE:
case GIT_CHECKBOX:
case GIT_WEIGHT:
if (GetGObjectAttr(go,tag,(ULONG *)&i))
{
WriteTag(iff,c,tag);
WriteChunkBytes(iff,&i,4);
}
break;
case GIT_BUTTON: /* werden nicht gespeichert */
case GIT_NONE:
break;
#ifdef DEBUG
default:
bug("%lx: kann Attribut nicht speichern: %lx (Typ: %ld)\n", go, gi->gi_Tag, c);
break;
#endif
}
}
i = 0;
WriteChunkBytes(iff, &i, 1);
}
ULONG
gRootSave(struct gObject *go,struct gcpIO *gcpio)
{
struct IFFHandle *iff = gcpio->gcpio_IFFHandle;
WriteChunkString(iff, go->go_Class->gc_ClassName);
WriteChunkString(iff, go->go_Node.ln_Name);
WriteChunkBytes(iff, &go->go_Pos, 4);
if (go->go_Knobs)
{
struct point2d *p;
long num;
if (gDoMethod(go, GCM_REALPOINTS, &p, &num))
{
WriteChunkBytes(iff, &num,4);
WriteChunkBytes(iff, p, num*sizeof(struct point2d));
if (p != go->go_Knobs)
FreePooled(pool,p,sizeof(struct point2d)*num);
}
}
else
{
long i = 0;
WriteChunkBytes(iff, &i, 4);
}
SaveGInterface(gcpio, go->go_Class->gc_Interface, go);
return 0L;
}
ULONG PUBLIC
gRootDispatch(REG(a0, struct gClass *gc), REG(a2, struct gObject *go), REG(a1, Msg msg))
{
ULONG rc = 0L;
switch (msg->MethodID)
{
case GCM_NEW:
{
struct gObject *ngo;
if (((struct gClass *)go)->gc_Dispatch == (APTR)gRootDispatch) // keine Instanzen dieser Klasse
return 0;
if (go && (ngo = AllocPooled(pool,((struct gClass *)go)->gc_InstSize)))
{
ngo->go_Class = (struct gClass *)go;
ngo->go_Type = GOT_OBJECT;
ngo->go_Page = ((struct gcpNew *)msg)->gcpn_Page;
ngo->go_Pos = -1;
MyNewList(&ngo->go_ReferencedBy);
gRootSet(ngo,((struct gcpNew *)msg)->gcpn_AttrList);
rc = (ULONG)ngo;
}
break;
}
case GCM_DISPOSE:
{
struct gObject *rgo;
struct Link *l;
CloseAppWindow(go->go_Window, TRUE);
while ((l = (struct Link *)MyRemHead(&go->go_ReferencedBy)) != 0)
{
rgo = l->l_Link;
SetGObjectAttrs(rgo->go_Page, rgo, GEA_References, NULL, TAG_END);
}
FreeString(go->go_Node.ln_Name);
FreeString(go->go_Help);
FreeString(go->go_Command);
FreePooled(pool,go,go->go_Class->gc_InstSize);
break;
}
case GCM_COPY:
{
struct gObject *cgo;
if (go && (cgo = AllocPooled(pool,go->go_Class->gc_InstSize)))
{
CopyMem(go,cgo,go->go_Class->gc_InstSize);
cgo->go_Node.ln_Name = AllocString(go->go_Node.ln_Name);
cgo->go_Help = AllocString(go->go_Help);
cgo->go_Command = AllocString(go->go_Command);
MyNewList(&cgo->go_ReferencedBy);
if ((cgo->go_Knobs = AllocPooled(pool, go->go_NumKnobs * sizeof(struct point2d))) != 0)
CopyMem(go->go_Knobs,cgo->go_Knobs,sizeof(struct point2d)*go->go_NumKnobs);
cgo->go_Pos = -1;
cgo->go_Page = NULL;
cgo->go_Window = NULL;
rc = (ULONG)cgo;
}
break;
}
case GCM_SET:
rc = gRootSet(go,((struct gcpSet *)msg)->gcps_AttrList);
break;
case GCM_GET:
rc = TRUE;
switch(((struct gcpGet *)msg)->gcpg_Tag)
{
case GOA_Name:
*((struct gcpGet *)msg)->gcpg_Storage = (ULONG)go->go_Node.ln_Name;
break;
case GOA_Command:
*((struct gcpGet *)msg)->gcpg_Storage = (ULONG)go->go_Command;
break;
case GOA_Help:
*((struct gcpGet *)msg)->gcpg_Storage = (ULONG)go->go_Help;
break;
case GOA_ContinualCommand:
*((struct gcpGet *)msg)->gcpg_Storage = (ULONG)(go->go_Flags & GOF_CONTINUALCMD);
break;
default:
rc = FALSE;
}
break;
case GCM_OPENWINDOW:
return (ULONG)OpenAppWindow(WDT_OBJECT, WA_Data, go, TAG_END);
break;
case GCM_CLOSEWINDOW:
CloseAppWindow(go->go_Window, TRUE);
break;
case GCM_REALPOINTS:
{
struct point2d *p;
UWORD num = 2;
if ((p = AllocPooled(pool, sizeof(struct point2d) * num)) != 0)
{
p[0] = go->go_Knobs[0];
p[1] = go->go_Knobs[3];
*((struct gcpRealPoints *)msg)->gcpr_StoragePoints = p;
*((struct gcpRealPoints *)msg)->gcpr_StorageNumPoints = num;
rc = TRUE;
}
break;
}
case GCM_BEGINPOINTS:
rc = 2;
break;
case GCM_ENDPOINTS:
{
struct point2d *s = ((struct gcpEndPoints *)msg)->gcpe_Points,*t;
UWORD num = ((struct gcpEndPoints *)msg)->gcpe_NumPoints;
#if (G_POINTS == 4)
if (t = AllocPooled(pool,sizeof(struct point2d)*4))
{
t[0] = s[0];
t[1].x = s[1].x; t[1].y = s[0].y;
t[2].x = s[0].x; t[2].y = s[1].y;
t[3] = s[1];
num = 4;
}
#elif (G_POINTS == 8)
if ((t = AllocPooled(pool, sizeof(struct point2d) * 8)) != 0)
{
t[0] = s[0];
t[1].x = s[1].x; t[1].y = s[0].y;
t[2].x = s[0].x; t[2].y = s[1].y;
t[3] = s[1];
gRootSetEdgeKnobs(t);
num = 8;
}
#endif
*((struct gcpEndPoints *)msg)->gcpe_StoragePoints = t;
*((struct gcpEndPoints *)msg)->gcpe_StorageNumPoints = num;
break;
}
case GCM_UPDATEPOINT:
{
struct point2d *p = go->go_Knobs;
LONG num = ((struct gcpUpdatePoint *)msg)->gcpu_NumPoint;
p[num].x = ((struct gcpUpdatePoint *)msg)->gcpu_Point.x;
p[num].y = ((struct gcpUpdatePoint *)msg)->gcpu_Point.y;
switch (num)
{
case 0:
p[1].y = p[0].y;
p[2].x = p[0].x;
break;
case 1:
p[0].y = p[1].y;
p[3].x = p[1].x;
break;
case 2:
p[3].y = p[2].y;
p[0].x = p[2].x;
break;
case 3:
p[2].y = p[3].y;
p[1].x = p[3].x;
break;
#if (G_POINTS == 8)
case 4:
p[0].y = p[4].y;
p[1].y = p[4].y;
break;
case 5:
p[2].y = p[5].y;
p[3].y = p[5].y;
break;
case 6:
p[0].x = p[6].x;
p[2].x = p[6].x;
break;
case 7:
p[1].x = p[7].x;
p[3].x = p[7].x;
break;
#endif
}
if (p[0].x > p[1].x)
{
swmem((UBYTE *)&p[0].x, (UBYTE *)&p[1].x, sizeof(long));
swmem((UBYTE *)&p[2].x, (UBYTE *)&p[3].x, sizeof(long));
}
if (p[0].y > p[2].y)
{
swmem((UBYTE *)&p[0].y, (UBYTE *)&p[2].y, sizeof(long));
swmem((UBYTE *)&p[1].y, (UBYTE *)&p[3].y, sizeof(long));
}
#if (G_POINTS == 8)
gRootSetEdgeKnobs(p);
#endif
break;
}
case GCM_ADDPOINT:
/* we refresh the whole drawing, so we don't care about GCPAM_UPDATE/REDRAW */
if (((struct gcpAddPoint *)msg)->gcpa_NumPoints == 2)
{
struct coord *p = ((struct gcpAddPoint *)msg)->gcpa_Points;
WORD ox = ((struct gcpAddPoint *)msg)->gcpa_Offset.x, oy = ((struct gcpAddPoint *)msg)->gcpa_Offset.y;
DrawRect(((struct gcpAddPoint *)msg)->gcpa_RastPort,p[0].x+ox,p[0].y+oy,p[1].x-p[0].x,p[1].y-p[0].y);
}
break;
case GCM_CHANGEPOINT:
{
struct coord *p = ((struct gcpAddPoint *)msg)->gcpa_Points;
WORD ox = ((struct gcpAddPoint *)msg)->gcpa_Offset.x,oy = ((struct gcpAddPoint *)msg)->gcpa_Offset.y;
switch(((struct gcpAddPoint *)msg)->gcpa_Point)
{
case 1:
p[0].y = p[1].y;
p[3].x = p[1].x;
break;
case 2:
p[3].y = p[2].y;
p[0].x = p[2].x;
break;
#if (G_POINTS == 8)
case 4:
p[0].y = p[4].y;
break;
case 5:
p[3].y = p[5].y;
break;
case 6:
p[0].x = p[6].x;
break;
case 7:
p[3].x = p[7].x;
break;
#endif
}
DrawRect(((struct gcpAddPoint *)msg)->gcpa_RastPort,p[0].x+ox,p[0].y+oy,p[3].x-p[0].x,p[3].y-p[0].y);
break;
}
case GCM_BOX:
{
struct point2d *p = go->go_Knobs;
LONG xmin,ymin,xmax,ymax,i;
if (!p)
break;
xmin = xmax = p[0].x;
ymin = ymax = p[0].y;
for(i = 1;i < go->go_NumKnobs;i++)
{
if (p[i].x < xmin)
xmin = p[i].x;
else if (p[i].x > xmax)
xmax = p[i].x;
if (p[i].y < ymin)
ymin = p[i].y;
else if (p[i].y > ymax)
ymax = p[i].y;
}
go->go_mmLeft = xmin; go->go_mmTop = ymin;
go->go_mmRight = xmax; go->go_mmBottom = ymax;
//gDoMethod(go,GCM_UPDATEPOINT,xmin,ymin,0);
//gDoMethod(go,GCM_UPDATEPOINT,xmax,ymax,3);
break;
}
case GCM_HITTEST:
rc = TRUE;
break;
case GCM_COMMAND:
/* Execute command */
ProcessAppCmd(go->go_Page,go->go_Command);
break;
case GCM_SAVE:
rc = gRootSave(go,(struct gcpIO *)msg);
break;
case GCM_LOAD:
rc = (ULONG)gRootLoad(go,(struct gcpIO *)msg);
break;
case GCM_UPDATE_UI:
if (go->go_Window)
UpdateObjectGadgets(go->go_Window);
break;
}
return rc;
}
/******************************* embedded object *****************************/
struct gInterface gEmbeddedInterface[] = {
{GEA_References, NULL, GIT_BUTTON, NULL, NULL},
{GEA_AdoptSize, NULL, GIT_BUTTON, NULL, NULL},
{0}
};
void PUBLIC
gEmbeddedDraw(REG(d0, struct Page *page), REG(d1, ULONG dpi), REG(a0, struct RastPort *rp), REG(a1, struct gClass *gc),
REG(a2, struct gObject *go), REG(a3, struct gBounds *gb))
{
struct gEmbedded *ge = GINST_DATA(gc, go);
struct gObject *rgo;
long x = gb->gb_Left,y = gb->gb_Top;
long width = gb->gb_Right-gb->gb_Left;
long height = gb->gb_Bottom-gb->gb_Top;
/*SetHighColor(grp,page->pg_BPen);
RectFill(grp,x,y,x+width,y+height);*/
if ((rgo = ge->ge_References) != 0)
rgo->go_Class->gc_Draw(page,dpi,grp,rgo->go_Class,rgo,gb);
else
{
long w10 = width/10,h10 = height/10;
long w4 = width/4,h4 = height/4;
long w2 = width/2,h2 = height/2;
SetAPen(grp,1);
DrawRect(grp,x,y,width,height);
SetHighColor(grp,0xff0000);
gAreaMove(grp,x+w2-w4,y+h2+h4-h10);
gAreaDraw(grp,x+w2+w4-w10,y+h2-h4);
gAreaDraw(grp,x+w2+w4,y+h2-h4+h10);
gAreaDraw(grp,x+w2-w4+w10,y+h2+h4);
gAreaEnd(grp);
gAreaMove(grp,x+w2-w4+w10,y+h2-h4);
gAreaDraw(grp,x+w2+w4,y+h2+h4-h10);
gAreaDraw(grp,x+w2+w4-w10,y+h2+h4);
gAreaDraw(grp,x+w2-w4,y+h2-h4+h10);
gAreaEnd(grp);
//RectFill(grp,x+width/3,y+height/3,x+width/2,y+height/2);
}
}
ULONG
gEmbeddedSet(struct gObject *go, struct gEmbedded *ge, struct TagItem *tstate)
{
ULONG rc = GCPR_NONE;
struct TagItem *ti;
if (tstate)
{
while ((ti = NextTagItem(&tstate)) != 0)
{
switch (ti->ti_Tag)
{
case GEA_References:
{
struct gObject *rgo,*posgo;
struct point2d *p;
if (ti->ti_Data == ~0L) // Button pressed
{
if (ge->ge_References)
gDoMethod(ge->ge_References, GCM_OPENWINDOW);
break;
}
posgo = rgo = (struct gObject *)ti->ti_Data;
/* if data is an embedded object, data's referenced is used */
if (rgo && rgo->go_Class == go->go_Class)
rgo = ((struct gEmbedded *)GINST_DATA(go->go_Class, rgo))->ge_References;
if (!go->go_Page || ge->ge_References == rgo)
break;
if (rgo && rgo->go_Type != GOT_OBJECT)
{
ErrorRequest(GetString(&gLocaleInfo, MSG_REFERENCE_TO_GROUP_ERR));
break;
}
if (ge->ge_References)
MyRemove(&ge->ge_Link);
if (rgo)
MyAddTail(&rgo->go_ReferencedBy, &ge->ge_Link);
ge->ge_References = rgo;
if (rgo && go->go_mmLeft == go->go_mmRight && (p = AllocPooled(pool,2*sizeof(struct point2d))))
{
struct point2d *sp;
long num;
p[0].x = posgo->go_mmLeft+5*1024;
p[0].y = posgo->go_mmTop+5*1024;
p[1].x = posgo->go_mmRight+5*1024;
p[1].y = posgo->go_mmBottom+5*1024;
gDoClassMethod(go->go_Class,NULL,GCM_ENDPOINTS,p,2,&sp,&num);
if (sp != p)
FreePooled(pool,p,2*sizeof(struct point2d));
if (go->go_Knobs) /* alte Knobs entfernen */
FreePooled(pool,go->go_Knobs,go->go_NumKnobs*sizeof(struct point2d));
go->go_Knobs = sp; /* neue Knobs setzen */
go->go_NumKnobs = num;
}
rc |= GCPR_REDRAW;
break;
}
case GEA_AdoptSize:
{
struct gObject *rgo = ge->ge_References;
if (!rgo)
break;
if (ti->ti_Data == ~0L)
SizeGObject(go->go_Page,go,rgo->go_mmRight - rgo->go_mmLeft,rgo->go_mmBottom - rgo->go_mmTop);
rc |= GCPR_UPDATESIZE;
break;
}
}
}
}
return rc;
}
ULONG PUBLIC
gEmbeddedDispatch(REG(a0, struct gClass *gc), REG(a2, struct gObject *go), REG(a1, Msg msg))
{
struct gEmbedded *ge = GINST_DATA(gc, go);
ULONG rc;
switch (msg->MethodID)
{
case GCM_NEW:
if ((rc = gDoSuperMethodA(gc, go, msg)) != 0)
{
go = (struct gObject *)rc; ge = GINST_DATA(gc, go);
go->go_Flags |= GOF_FRAMED;
ge->ge_Link.l_Link = go;
ge->ge_Type = GET_LINK;
gEmbeddedSet(go, ge, ((struct gcpSet *)msg)->gcps_AttrList);
}
break;
case GCM_COPY:
{
struct gObject *cgo;
if ((cgo = (struct gObject *)(rc = gDoSuperMethodA(gc, go, msg))) != 0)
{
struct gEmbedded *cge = GINST_DATA(gc, cgo);
cge->ge_Link.l_Link = cgo;
if (cge->ge_References)
MyAddTail(&cge->ge_References->go_ReferencedBy, &cge->ge_Link);
}
break;
}
case GCM_SET:
if (!(rc = gDoSuperMethodA(gc, go, msg)))
return gEmbeddedSet(go, ge, ((struct gcpSet *)msg)->gcps_AttrList);
break;
case GCM_GET:
switch(((struct gcpGet *)msg)->gcpg_Tag)
{
case GEA_References:
D(bug("get GEA_REFERENCES **************************************************************************************\n"));
//*((struct gcpGet *)msg)->gcpg_Storage = ge->ge_References ? ge->ge_References->go_Pos : -1;
*((struct gcpGet *)msg)->gcpg_Storage = (ULONG)ge->ge_References;
return TRUE;
case GEA_AdoptSize:
*((struct gcpGet *)msg)->gcpg_Storage = 0L;
return TRUE;
default:
return gDoSuperMethodA(gc, go, msg);
}
break;
case GCM_INITAFTERLOAD:
{
struct gObject *rgo;
struct Page *page;
rc = gDoSuperMethodA(gc,go,msg);
if (ge->ge_Type == GET_DIAGRAM || !go->go_Page || !(page = (struct Page *)FindListNumber(&go->go_Page->pg_Mappe->mp_Pages,ge->ge_PageNumber)))
break;
foreach(&page->pg_gObjects,rgo)
{
if (rgo->go_Pos == ge->ge_Pos)
{
ULONG tags[3] = {GEA_References, 0, TAG_END};
tags[1] = (ULONG)rgo;
gDoMethod(go, GCM_SET, tags);
break;
}