-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects.c
2187 lines (1807 loc) · 62 KB
/
objects.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
/* gObject/gGroup related functions
*
* Copyright ©1996-2008 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"
#ifdef __amigaos4__
#include <stdarg.h>
#endif
#ifdef DEBUG
//# define G2(x) bug(" "); x
//# define G3(x) bug(" "); x
# define G2(x) ;
# define G3(x) ;
#else
# define G2(x) ;
# define G3(x) ;
#endif
extern struct RastPort *grp;
ULONG msfptrn;
WORD fx, fy, fw, fh, ofx, ofy;
static bool gCommandExecuted;
/*************************************** OO support functions ***************************************/
ULONG
gDoClassMethodA(struct gClass *gc, APTR go, Msg msg)
{
G2(bug("doClassMethodA: %lx - object: %lx - method: %ld\n", gc, go, *(ULONG *)msg));
if (gc)
{
return gc->gc_Dispatch(gc, go, msg);
}
return 0L;
}
#ifdef __amigaos4__
ULONG gDoClassMethod(struct gClass *gc, APTR go, ...) VARARGS68K;
ULONG gDoClassMethod(struct gClass *gc, APTR go, ...)
{
va_list ap;
Msg m;
if (gc)
{
ULONG rvalue;
va_startlinear(ap, go);
m = va_getlinearva(ap, Msg);
rvalue = gDoClassMethodA(gc, go, m);
va_end(ap);
return rvalue;
}
return 0L;
}
#else
ULONG
gDoClassMethod(struct gClass *gc, APTR go, ULONG id, ...)
{
G2(bug("doClassMethod: %lx - object: %lx - method: %ld\n", gc, go, id));
if (gc)
return gc->gc_Dispatch(gc, go, (Msg)&id);
return 0L;
}
#endif
ULONG PUBLIC
gDoMethodA(REG(a0, APTR go), REG(a1, Msg msg))
{
G2(bug("doMethodA: object: %lx - method: %ld\n", go, *(ULONG *)msg));
if (go)
return ((struct gObject *)go)->go_Class->gc_Dispatch(((struct gObject *)go)->go_Class, go, msg);
return 0L;
}
#ifdef __amigaos4__
ULONG gDoMethod(APTR go, ...) VARARGS68K;
ULONG gDoMethod(APTR go, ...)
{
va_list ap;
Msg m;
if (go)
{
ULONG rvalue;
va_startlinear(ap, go);
m = va_getlinearva(ap, Msg);
rvalue = gDoMethodA(go, m);
va_end(ap);
return rvalue;
}
return 0L;
}
#else
ULONG
gDoMethod(APTR go, ULONG id, ...)
{
G2(bug("doMethod: object: %lx - method: %ld\n", go, id));
if (go)
return ((struct gObject *)go)->go_Class->gc_Dispatch(((struct gObject *)go)->go_Class, go, (Msg)&id);
return 0L;
}
#endif
ULONG PUBLIC
gDoSuperMethodA(REG(a0, struct gClass *gc), REG(a1, APTR go), REG(a2, Msg msg))
{
G3(bug("doSuperMethodA: %lx - object: %lx - method: %ld\n", gc, go, *(ULONG *)msg));
if ((gc = gc->gc_Super) != 0)
return gc->gc_Dispatch(gc, go, msg);
return 0L;
}
BOOL PUBLIC
gIsSubclassFrom(REG(a0, struct gClass *gc), REG(a1, struct gClass *supergc))
{
if (!supergc)
return false;
while (gc)
{
if (gc == supergc)
return TRUE;
gc = gc->gc_Super;
}
return FALSE;
}
void PUBLIC
gSuperDraw(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))
{
if (gc->gc_Super->gc_Draw)
gc->gc_Super->gc_Draw(page, dpi, rp, gc->gc_Super, go, gb);
}
void
SetGRastPort(struct RastPort *rp)
{
G3(bug("setGRastPort: %lx\n", rp));
grp->BitMap = rp->BitMap;
grp->Layer = rp->Layer;
grp->Flags &= ~AREAOUTLINE;
grp->RP_User = rp->RP_User;
}
/*************************************** all other functions ***************************************/
void PUBLIC
gInsertRemoveCellsTerm(REG(a0, struct gcpInReCells *gcpc), REG(a1, struct Page *page), REG(a2, STRPTR *term), REG(a3, struct Term *t))
{
if (page != gcpc->gcpc_Page)
return;
tf_col = 0; tf_row = 0;
InReCeKn(t, gcpc->gcpc_Offset, gcpc->gcpc_Diff, gcpc->gcpc_Comp, gcpc->gcpc_First, gcpc->gcpc_Last);
if (term != NULL) // Update term string
{
FreeString(*term);
*term = TreeTerm(t, FALSE);
}
}
void PUBLIC
gInsertRemoveCellsTablePos(REG(a0, struct gcpInReCells *gcpc), REG(a1, struct Page *page), REG(a2, STRPTR *term), REG(a3, struct tablePos *tp))
{
if (page != gcpc->gcpc_Page)
return;
/* MERKER: to be implemented */
}
void
DrawGObject(struct RastPort *rp, struct Page *page, struct gObject *go, long x, long y)
{
struct gClass *gc = go->go_Class;
struct gBounds gb;
G2(bug("drawGObject: %lx - page: %lx - x: %ld - y: %ld\n", go, page, x, y));
if (gc->gc_Draw == NULL)
return;
gb.gb_Left = x + GOKNOB_SIZE;
gb.gb_Top = y + GOKNOB_SIZE;
gb.gb_Right = go->go_Right - go->go_Left + x - GOKNOB_SIZE;
gb.gb_Bottom = go->go_Bottom - go->go_Top + y - GOKNOB_SIZE;
gc->gc_Draw(page, page->pg_DPI, rp, gc, go, &gb);
}
void
DrawSingleGObject(struct Page *page, struct gObject *go)
{
struct Window *win;
G2(bug("drawSingleGObject\n"));
if (!page || !(win = page->pg_Window))
return;
DrawTableCoord(page, go->go_Left - page->pg_TabX + page->pg_wTabX, go->go_Top - page->pg_TabY + page->pg_wTabY,
go->go_Right - page->pg_TabX + page->pg_wTabX, go->go_Bottom - page->pg_TabY + page->pg_wTabY);
}
void
RefreshGObjectReferences(struct gObject *go)
{
struct Link *l;
G2(bug("refreshGObjectReferences\n"));
if (go == NULL)
return;
foreach (&go->go_ReferencedBy, l)
{
struct gObject *go = l->l_Link;
struct Page *page = go->go_Page;
if (page->pg_Window == NULL)
continue;
DrawTableCoord(page, go->go_Left - page->pg_TabX + page->pg_wTabX, go->go_Top - page->pg_TabY + page->pg_wTabY,
go->go_Right - page->pg_TabX + page->pg_wTabX, go->go_Bottom - page->pg_TabY + page->pg_wTabY);
}
}
void
DrawGObjectKnobs(struct Page *page,struct gObject *go)
{
long i,x,y,pen;
BOOL reset;
G2(bug("drawGObjectKnobs: page: %lx - go: %lx\n",page,go));
if (!page || !go || !page->pg_Window)
return;
makeClip(page->pg_Window,page->pg_wTabX,page->pg_wTabY,page->pg_wTabW,page->pg_wTabH);
SetHighColor(grp,0x000000); pen = GetAPen(grp); reset = FALSE;
for(i = 0;i < go->go_NumKnobs;i++)
{
x = page->pg_wTabX-page->pg_TabX+pixel(page,go->go_Knobs[i].x,TRUE);
y = page->pg_wTabY-page->pg_TabY+pixel(page,go->go_Knobs[i].y,FALSE);
if (ReadPixel(grp,x,y) == pen)
SetAPen(grp,0), reset = TRUE;
RectFill(grp,x-GOKNOB_SIZE,y-GOKNOB_SIZE,x+GOKNOB_SIZE,y+GOKNOB_SIZE);
if (reset)
SetAPen(grp,pen), reset = FALSE;
}
if (go->go_Flags & GOF_FRAMED)
DrawRect(grp,page->pg_wTabX-page->pg_TabX+go->go_Left+GOKNOB_SIZE,page->pg_wTabY-page->pg_TabY+go->go_Top+GOKNOB_SIZE,go->go_Right-go->go_Left-2*GOKNOB_SIZE,go->go_Bottom-go->go_Top-2*GOKNOB_SIZE);
freeClip(page->pg_Window);
}
LONG
CheckGObjectKnobs(struct Page *page,struct gObject *go,long x,long y)
{
long i,kx,ky;
for (i = 0; i < go->go_NumKnobs; i++)
{
kx = x-pixel(page,go->go_Knobs[i].x,TRUE);
ky = y-pixel(page,go->go_Knobs[i].y,FALSE);
if (abs(kx) <= GOKNOB_SIZE && abs(ky) <= GOKNOB_SIZE)
return i + 1;
}
return 0;
}
BYTE
CheckGObject(struct Page *page,struct gObject *go,long x,long y)
{
if (x > go->go_Left && x < go->go_Right && y > go->go_Top && y < go->go_Bottom)
return (BYTE)gDoMethod(go, GCM_HITTEST, mm(page,x,TRUE), mm(page,y,FALSE));
return false;
}
BYTE
CheckGGroup(struct Page *page,struct gGroup *gg,long x,long y)
{
if (gg->gg_Type == GOT_OBJECT)
{
struct gObject *go = GROUPOBJECT(gg);
long i;
if ((i = CheckGObjectKnobs(page,go,x,y)) != 0)
{
G2(bug("checkGGroup: change knob %d\n",i));
page->pg_ChangeObject = go;
page->pg_NumPoints = go->go_NumKnobs;
page->pg_CurrentPoint = i-1;
if ((page->pg_Points = AllocPooled(pool, sizeof(struct coord)*go->go_NumKnobs)) != 0)
{
for (i = 0; i < go->go_NumKnobs; i++)
{
page->pg_Points[i].x = pixel(page,go->go_Knobs[i].x,TRUE);
page->pg_Points[i].y = pixel(page,go->go_Knobs[i].y,FALSE);
}
}
return PGA_CHANGE | PGA_KNOBS;
}
return PGA_NONE;
}
else
{
struct gGroup *realgg = gg;
#if 0
if (prefs.pr_Disp->pd_Flags & PDF_SHOWGROUPS) /* Rahmen um Gruppen */
{
}
#endif
for(gg = (APTR)realgg->gg_Objects.mlh_TailPred;gg->gg_Node.mln_Pred;gg = (APTR)gg->gg_Node.mln_Pred)
{
if (CheckGObjectKnobs(page,GROUPOBJECT(gg),x,y))
return PGA_CHANGE | PGA_KNOBS;
}
#if 0
for(gg = (APTR)realgg->gg_Objects.mlh_TailPred;gg->gg_Node.mln_Pred;gg = (APTR)gg->gg_Node.mln_Pred)
{
if (CheckGObject(page,GROUPOBJECT(gg),x,y))
return(PGA_CHANGE);
}
#endif
}
return 0; /* suppress compiler warning */
}
void
DeselectGObject(struct Page *page,struct gObject *go)
{
if (!go || !(go->go_Flags & GOF_SELECTED)) /*** || (go->go_Flags & GOF_PROTECTED)) ***/
return;
go->go_Flags &= ~GOF_SELECTED;
DrawTableCoord(page,go->go_Left-page->pg_TabX+page->pg_wTabX,go->go_Top-page->pg_TabY+page->pg_wTabY,go->go_Right-page->pg_TabX+page->pg_wTabX,go->go_Bottom-page->pg_TabY+page->pg_wTabY);
}
void
DeselectGObjects(struct Page *page)
{
struct gObject *go;
for(go = (struct gObject *)page->pg_gObjects.mlh_Head;go->go_Node.ln_Succ;go = (APTR)go->go_Node.ln_Succ)
DeselectGObject(page,go);
}
void
UpdateGObject(struct Page *page,struct gObject *go)
{
G(bug("updateGObject: %lx - page: %lx\n",go,page));
go->go_Left = pixel(page,go->go_mmLeft,TRUE)-GOKNOB_SIZE;
go->go_Top = pixel(page,go->go_mmTop,FALSE)-GOKNOB_SIZE;
go->go_Right = pixel(page,go->go_mmRight,TRUE)+GOKNOB_SIZE;
go->go_Bottom = pixel(page,go->go_mmBottom,FALSE)+GOKNOB_SIZE;
gDoMethod(go,GCM_UPDATE,page->pg_DPI);
}
void
UpdateGGroup(struct Page *page,struct gGroup *gg)
{
G(bug("updateGGroup: %lx - page: %lx\n",gg,page));
if (gg->gg_Type == GOT_OBJECT)
UpdateGObject(page,GROUPOBJECT(gg));
else
{
struct gGroup *igg;
foreach(&gg->gg_Objects,igg)
UpdateGGroup(page,igg);
gg->gg_Left = pixel(page,gg->gg_mmLeft,TRUE);
gg->gg_Top = pixel(page,gg->gg_mmTop,FALSE);
gg->gg_Right = pixel(page,gg->gg_mmRight,TRUE);
gg->gg_Bottom = pixel(page,gg->gg_mmBottom,FALSE);
}
}
void
UpdateGGroups(struct Page *page)
{
struct gGroup *gg;
foreach(&page->pg_gGroups,gg)
UpdateGGroup(page,gg);
}
void
DeselectGGroup(struct Page *page,struct gGroup *gg,BYTE draw)
{
G(bug("deselectGGroup: %lx - page: %lx - draw: %d\n",gg,page,draw));
if (gg->gg_Type == GOT_OBJECT)
DeselectGObject(page,GROUPOBJECT(gg));
else
{
struct gGroup *igg;
foreach(&gg->gg_Objects,igg)
DeselectGGroup(page,igg,FALSE);
gg->gg_Flags &= ~GOF_SELECTED;
if (draw /*&& prefs.pr_Disp->pd_Flags & PDF_SHOWGROUPS*/) // <-- wäre ganz nett
DrawTableCoord(page,gg->gg_Left-page->pg_TabX+page->pg_wTabX,gg->gg_Top-page->pg_TabY+page->pg_wTabY,gg->gg_Right-page->pg_TabX+page->pg_wTabX,gg->gg_Bottom-page->pg_TabY+page->pg_wTabY);
}
}
void
DeselectGGroups(struct Page *page)
{
struct gGroup *gg;
if (!page)
return;
foreach(&page->pg_gGroups,gg)
{
if ((gg->gg_Flags & GOF_PROTECTED | GOF_SELECTED) == GOF_SELECTED)
DeselectGGroup(page,gg,TRUE);
}
}
void
SelectGGroup(struct Page *page,struct gGroup *gg,BYTE mode)
{
G(bug("selectGGroup: %lx - page: %lx - draw: %d\n",gg,page,mode));
if (!page || !gg)
return;
gg->gg_Flags |= GOF_PROTECTED;
if (mode == ACTGO_EXCLUSIVE)
DeselectGGroups(page);
gg->gg_Flags &= ~GOF_PROTECTED;
if (page->pg_Window)
SetGRastPort(page->pg_Window->RPort);
if (!(gg->gg_Flags & GOF_SELECTED))
{
if (gg->gg_Type == GOT_GROUP)
{
struct gGroup *igg;
for(igg = (APTR)gg->gg_Objects.mlh_Head;igg->gg_Node.mln_Succ;igg = (APTR)igg->gg_Node.mln_Succ)
{
if (gg->gg_Type == GOT_OBJECT)
DrawGObjectKnobs(page,GROUPOBJECT(igg));
}
}
else
DrawGObjectKnobs(page,GROUPOBJECT(gg));
}
gg->gg_Flags |= GOF_SELECTED;
/*if (gg->gg_Type == GOT_GROUP && prefs.pr_Disp->pd_Flags & PDF_SHOWGROUPS) // <-- wäre ganz nett
DrawGGroup(page,gg);*/
}
/*
BYTE CheckGObj(struct Page *page,struct gObj *go,long x,long y)
{
long x1,y1,x2,y2;
if (go->go_Frame->gf_Flags & GFF_HIDDEN)
return(FALSE);
if (go->go_Left <= x && (go->go_Left+go->go_Width) >= x && go->go_Top <= y && (go->go_Top+go->go_Height) >= y)
{
switch(go->go_Type)
{
case GOT_DIAGRAM:
case GOT_BUTTON:
case GOT_PICTURE:
return(TRUE);
case GOT_VECTOR:
if (go->go_SubType == GOSTV_LINE) // MERKER: muß auch nochmal überarbeitet werden
{
x1 = go->go_Left; y1 = go->go_Top; x2 = x1+go->go_Width; y2 = y1+go->go_Height;
if (go->go_Flip & GOFLIP_X)
swmem(&x1,&x2,sizeof(long));
if (go->go_Flip & GOFLIP_Y)
swmem(&y1,&y2,sizeof(long));
// bug("diff: %ld\n",abs((x2-x1)*(y-y1)-(y2-y1)*(x-x1)));
if (abs((x2-x1)*(y-y1)-(y2-y1)*(x-x1)) < 500)
return(TRUE);
}
else if (go->go_SubType == GOSTV_CIRCLE)
{
}
else
return(TRUE);
break;
}
}
return(FALSE);
}
*/
/*
BOOL UngroupGFrames(struct Page *page,STRPTR name)
{
struct gFrame *gf,*ngf,*cgf;
struct UndoNode *un = NULL;
struct gObj *go;
long count = 0,x,y,i = 0;
if (!page)
return(FALSE);
for(gf = (APTR)page->pg_gFrames.mlh_Head;gf->gf_Node.ln_Succ;i++,gf = ngf)
{
ngf = (APTR)gf->gf_Node.ln_Succ;
if (name && !stricmp(name,gf->gf_Node.ln_Name) || !name && (gf->gf_Flags & GFF_SELECTED) && CountNodes((struct List *)&gf->gf_Objects) > 1)
{
gf->gf_Pos = i;
if (!un)
{
if (un = CreateUndo(page,UNDO_PRIVATE,"Objektgruppierung auflösen"))
un->un_Type = UNT_OBJECTS;
}
if (un && (cgf = CopyGFrame(gf,TRUE)))
MyAddTail(&un->un_UndoList,cgf);
while(go = (APTR)MyRemHead((struct List *)&gf->gf_Objects))
{
go->go_Frame = go->go_OriginalFrame;
MyAddTail((struct List *)&go->go_Frame->gf_Objects,(struct Node *)go);
Insert((struct List *)&page->pg_gFrames,go->go_Frame,gf);
if (un && (cgf = CopyGFrame(gf,TRUE)))
{
go->go_Frame->gf_Undo = un;
MyAddTail(&un->un_UndoList,cgf);
}
go->go_Frame->gf_Pos = i++;
UpdateGFrameSize(page,go->go_Frame);
}
MyRemove(gf); count++; i--;
DrawTableCoord(page,x = gf->gf_Left-page->pg_TabX+page->pg_wTabX,y = gf->gf_Top-page->pg_TabY+page->pg_wTabY,x+gf->gf_Width,y+gf->gf_Height);
FreeGFrame(gf);
}
}
if (!count)
DisplayBeep(NULL);
}
struct gFrame *GroupGFrames(struct Page *page,STRPTR name)
{
struct gFrame *gf,*sgf,*ngf;
struct UndoNode *un;
struct gObj *go;
long count = 0,x,y;
if (!page)
return(NULL);
for(gf = (APTR)page->pg_gFrames.mlh_Head;gf->gf_Node.ln_Succ;gf = (APTR)gf->gf_Node.ln_Succ)
{
if (gf->gf_Flags & GFF_SELECTED)
count++;
}
if (count < 2)
{
ErrorRequest("Es müssen mindestens\n2 Objekte markiert sein.");
return(NULL);
}
un = BeginObjectsUndo(page,"Objekte gruppieren");
if (gf = CreateGFrame(page,NULL,FALSE))
{
if (name)
{
FreeString(gf->gf_Node.ln_Name);
gf->gf_Node.ln_Name = AllocString(name);
}
for(sgf = (APTR)page->pg_gFrames.mlh_Head;sgf->gf_Node.ln_Succ;)
{
ngf = (APTR)sgf->gf_Node.ln_Succ;
if (sgf->gf_Flags & GFF_SELECTED)
{
MyRemove(sgf);
sgf->gf_Flags &= ~GFF_SELECTED;
foreach(&sgf->gf_Objects,go)
{
go->go_Frame = gf;
MyRemove((struct Node *)go);
MyAddTail((struct List *)&gf->gf_Objects,(struct Node *)go);
}
}
sgf = ngf;
}
gf->gf_Flags |= GFF_SELECTED;
UpdateGFrameSize(page,gf);
if (gf->gf_Undo = un)
{
struct gFrame *cgf;
if (cgf = CopyGFrame(gf,TRUE))
MyAddTail(&un->un_RedoList,cgf);
}
DrawTableCoord(page,x = gf->gf_Left-page->pg_TabX+page->pg_wTabX,y = gf->gf_Top-page->pg_TabY+page->pg_wTabY,x+gf->gf_Width,y+gf->gf_Height);
}
return(gf);
}
*/
void
SizeGObject(struct Page *page,struct gObject *go,LONG w,LONG h)
{
struct UndoNode *un;
struct point2d *p;
G(bug("sizeGObject: %lx - page: %lx - w: %ld - h: %ld\n", go, page, w, h));
if (!page || !go)
return;
if (!w || !h)
{
UpdateObjectGadgets(go->go_Window);
ErrorRequest(GetString(&gLocaleInfo, MSG_INVALID_RESIZING_ERR));
return;
}
if ((p = AllocPooled(pool, sizeof(struct point2d) * go->go_NumKnobs)) != 0)
{
if ((un = CreateUndo(page, UNDO_PRIVATE, GetString(&gLocaleInfo, MSG_RESIZE_OBJECT_UNDO))) != 0)
{
double xf = (double)w / abs(go->go_mmRight - go->go_mmLeft);
double yf = (double)h / abs(go->go_mmBottom - go->go_mmTop);
long i;
un->un_Type = UNT_OBJECT_SIZE;
un->un_Object = go;
un->un_UndoKnobs = go->go_Knobs;
un->un_RedoKnobs = p;
for (i = 0; i < go->go_NumKnobs; i++)
{
p[i].x = (go->go_Knobs[i].x - go->go_mmLeft) * xf + go->go_mmLeft;
p[i].y = (go->go_Knobs[i].y - go->go_mmTop) * yf + go->go_mmTop;
}
ApplyObjectSizeUndoRedo(page, un, TYPE_REDO);
}
}
}
struct gObject *
gMakeRefObject(struct Page *page, struct gClass *gc, struct gObject *go, const STRPTR undoText)
{
LONG tags[3] = {GEA_References, 0, TAG_END};
struct UndoNode *un;
struct gObject *rgo;
if (!gc && !(gc = FindGClass("embedded")))
{
ErrorRequest(GetString(&gLocaleInfo, MSG_REFERENCE_CLASS_NOT_FOUND_ERR));
return NULL;
}
if (page->pg_Window)
ProjectToGObjects(page,(struct winData *)page->pg_Window->UserData);
tags[1] = (ULONG)go;
if ((rgo = (struct gObject *)gDoClassMethod(gc, gc, GCM_NEW, tags, page)) != 0)
{
if (!rgo->go_Node.ln_Name)
{
struct gObject *refgo = NULL;
STRPTR s,t;
GetGObjectAttr(rgo, GEA_References, (ULONG *)&refgo);
G3(bug("ref: refgo = %lx\n, go = %lx\n", refgo, go));
//refgo = ((struct gEmbedded *)GINST_DATA(gc,rgo))->ge_References;
if (refgo && (t = rgo->go_Node.ln_Name = AllocPooled(pool, strlen(s = refgo->go_Node.ln_Name) + 10)))
{
strcpy(t, s);
strcat(t, GetString(&gLocaleInfo, MSG_REFERENCE_SUFFIX_NAME));
}
else
rgo->go_Node.ln_Name = AllocString(GetString(&gLocaleInfo, MSG_REFERENCE_OBJECT_NAME));
}
MakeUniqueName(&page->pg_gObjects, &rgo->go_Node.ln_Name);
RefreshGObjectBounds(page, rgo);
AddGObject(page, NULL, rgo, ADDREM_DRAW);
if ((un = CreateUndo(page, UNDO_PRIVATE, undoText != NULL ? undoText : GetString(&gLocaleInfo, MSG_CREATE_REFERENCE_OBJECT_UNDO))) != 0)
{
un->un_Type = UNT_ADD_OBJECTS;
un->un_Object = rgo;
}
}
return 0; /* suppress compiler warning */
}
struct gInterface *
GetGInterfaceTag(struct gClass *gc, ULONG tag)
{
struct gInterface *gi;
G3(bug("GetGInterfaceTag(gc = 0x%lx (%s), tag = 0x%lx)\n", gc, gc ? gc->gc_ClassName : (STRPTR)"-", tag));
if (!gc)
return NULL;
if ((gi = gc->gc_Interface) != 0)
{
while (gi->gi_Tag && gi->gi_Tag != tag)
gi++;
if (gi->gi_Tag == tag)
return gi;
}
return GetGInterfaceTag(gc->gc_Super, tag);
}
void
CopyGTagValue(ULONG type, struct TagItem *ti)
{
switch (type)
{
case GIT_FONT:
ti->ti_Data = (ULONG)CopyFontInfo((struct FontInfo *)ti->ti_Data);
break;
case GIT_TEXT:
case GIT_FILENAME:
case GIT_FORMULA:
ti->ti_Data = (ULONG)AllocString((STRPTR)ti->ti_Data);
break;
case GIT_PEN:
case GIT_CHECKBOX:
case GIT_CYCLE:
case GIT_WEIGHT:
case GIT_DATA_PAGE:
break;
case GIT_BUTTON:
ti->ti_Tag = TAG_IGNORE;
break;
default:
ErrorRequest(GetString(&gLocaleInfo, MSG_UNKNOWN_TAG_TYPE_ERR), ti->ti_Tag, type);
break;
}
}
ULONG
GetGObjectAttr(struct gObject *go, ULONG tag, ULONG *data)
{
ULONG rvalue;
G2(bug("getGObjectAttr: %lx - tag: %lx - data: %lx\n", go, tag, data));
return gDoMethod(go, GCM_GET, tag, data);
}
/** Setzt ein oder mehrere Objektattribute und sorgt dafür, daß
* das die Änderungen korrekt dargestellt werden.
* Diese Funktion erstellt keine Undo/Redo-Möglichkeit.
*
* @param page die Seite des Objektes
* @param go das Objekt
* @param tags eine Tag-Liste deren Tags vom Objekt definiert werden
*/
void
gSetObjectAttrsA(struct Page *page, struct gObject *go, struct TagItem *tags)
{
long rc;
if ((rc = gDoMethod(go, GCM_SET, tags)) != 0)
{
if (rc == GCPR_REDRAW)
{
if (!gObjectIsDiagram(go))
{
DrawTableCoord(page, go->go_Left - page->pg_TabX + page->pg_wTabX, go->go_Top - page->pg_TabY + page->pg_wTabY,
go->go_Right - page->pg_TabX + page->pg_wTabX, go->go_Bottom - page->pg_TabY + page->pg_wTabY);
}
else
RefreshGObjectBounds(page, go);
RefreshGObjectReferences(go);
}
else if (rc & GCPR_UPDATESIZE)
RefreshGObjectDrawing(page, go);
}
}
#ifdef __amigaos4__
void gSetObjectAttrs(struct Page *page, struct gObject *go,...) VARARGS68K;
void gSetObjectAttrs(struct Page *page, struct gObject *go,...)
#else
void gSetObjectAttrs(struct Page *page, struct gObject *go, ULONG tag1, ...)
#endif
{
#ifdef __amigaos4__
va_list ap;
struct TagItem *tags;
va_startlinear(ap, go);
tags = va_getlinearva(ap, struct TagItem *);
gSetObjectAttrsA(page, go, tags);
#else
gSetObjectAttrsA(page, go, (struct TagItem *)&tag1);
#endif
}
/** Setzt ein oder mehrere Objektattribute und sorgt dafür, daß
* die Änderungen korrekt dargestellt werden, und daß der
* vorherige Zustand wieder hergestellt werden kann.<br>
* Benutzt gSetObjectAttrs().
*
* @param page die Seite des Objektes
* @param go das Objekt
* @param tags eine Tag-Liste deren Tags vom Objekt definiert werden
*/
void
SetGObjectAttrsA(struct Page *page, struct gObject *go, struct TagItem *tags)
{
struct UndoNode *un;
G(bug("setGObjectAttr: %lx - page: %lx - tags: %lx\n", go, page, tags));
if (!page || !go)
return;
if ((un = CreateUndo(page, UNDO_PRIVATE, GetString(&gLocaleInfo, MSG_OBJECT_ATTRIBUTES_UNDO))) != 0)
{
struct TagItem *ti, *fromTags, *toTags, *tstate = tags;
long i;
un->un_Type = UNT_OBJECT_ATTRS;
fromTags = CloneTagItems(tags);
toTags = CloneTagItems(tags);
if (fromTags && toTags)
{
struct gInterface *gi;
for (i = 0; (ti = NextTagItem(&tstate)) != 0; i++)
{
G3(bug("tag = 0x%08lx\n", ti->ti_Tag));
if ((gi = GetGInterfaceTag(go->go_Class, ti->ti_Tag)) != 0)
{
G3(bug(" -> interface found, type = %ld\n", gi->gi_Type));
if (gDoMethod(go, GCM_GET, fromTags[i].ti_Tag, &fromTags[i].ti_Data))
CopyGTagValue(gi->gi_Type, fromTags + i);
CopyGTagValue(gi->gi_Type, toTags + i);
G3(bug("%2ld. to: tag = 0x%08lx, value = 0x%08lx (%ld) (%s)\n", i, (toTags + i)->ti_Tag, (toTags + i)->ti_Data, (toTags + i)->ti_Data, gi->gi_Type == GIT_TEXT || gi->gi_Type == GIT_FORMULA ? (toTags + i)->ti_Data : (ULONG)"-"));
G3(bug(" from: tag = 0x%08lx, value = 0x%08lx (%ld) (%s)\n", fromTags[i].ti_Tag, fromTags[i].ti_Data, (fromTags + i)->ti_Data, gi->gi_Type == GIT_TEXT || gi->gi_Type == GIT_FORMULA ? (fromTags + i)->ti_Data : (ULONG)"-"));
}
else
{
G(bug("NO gInterface!!!\n"));
fromTags[i].ti_Tag = TAG_IGNORE;
toTags[i].ti_Tag = TAG_IGNORE;
}
}
un->un_UndoTags = fromTags;
un->un_RedoTags = toTags;
un->un_Object = go;
}
else
{
FreeTagItems(fromTags);
FreeTagItems(toTags);
}
}
gSetObjectAttrsA(page, go, tags);
UpdateObjectGadgets(go->go_Window);
}
#ifdef __amigaos4__
void SetGObjectAttrs(struct Page *page, struct gObject *go, ...) VARARGS68K;
void SetGObjectAttrs(struct Page *page, struct gObject *go, ...)
#else
void SetGObjectAttrs(struct Page *page, struct gObject *go, ULONG tag1, ...)
#endif
{
#ifdef __amigaos4__
va_list ap;
struct TagItem *tags;
va_startlinear(ap, go);
tags = va_getlinearva(ap, struct TagItem *);
SetGObjectAttrsA(page, go, tags);
#else
SetGObjectAttrsA(page, go, (struct TagItem *)&tag1);
#endif
}
void
FreeObjectChange(struct Page *page)
{
G(bug("freeObjectChange: page: %lx\n", page));
if (page->pg_Action & PGA_KNOBS)
{
FreePooled(pool, page->pg_Points, page->pg_NumPoints * sizeof(struct coord));
page->pg_Points = NULL;
page->pg_ChangeObject = NULL;
page->pg_CurrentPoint = 0;
page->pg_NumPoints = 0;
}
page->pg_Action = PGA_NONE;
}
void
DrawGObjectMove(struct Page *page)
{
if (!fx && !fy)
return;
makeClip(win, wd->wd_TabX, wd->wd_TabY, wd->wd_TabW, wd->wd_TabH);
SetGRastPort(win->RPort);
SetDrMd(grp, COMPLEMENT);
if (page->pg_Action & PGA_KNOBS) /* change knobs */
{
page->pg_Points[page->pg_CurrentPoint].x = fx;
page->pg_Points[page->pg_CurrentPoint].y = fy;
gDoMethod(page->pg_ChangeObject,GCM_CHANGEPOINT,grp,page->pg_Points,
(ofx << 16) | (ofy & 0xffff),page->pg_NumPoints,GCPAM_UPDATE,page->pg_CurrentPoint);
}
else /* move object(s) */
{
struct gObject *go;
for(go = (APTR)page->pg_gObjects.mlh_Head;go->go_Node.ln_Succ;go = (APTR)go->go_Node.ln_Succ)
{
if (go->go_Flags & GOF_SELECTED)
{
long x = wd->wd_TabX+go->go_Left-page->pg_TabX+fx;
long y = wd->wd_TabY+go->go_Top-page->pg_TabY+fy;