-
Notifications
You must be signed in to change notification settings - Fork 1
/
callback.c
1148 lines (944 loc) · 29.8 KB
/
callback.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
/*
* COPS (c) 1995 - 2003 Sven & Wilfried Behne
* 2004 F.Naumann & O.Skancke
*
* A XCONTROL compatible CPX manager.
*
* This file is part of COPS.
*
* COPS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* COPS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XaAES; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <gem.h>
#include <mint/cookie.h>
#include <mint/mintbind.h>
#ifdef __MINTLIB__
#include <fcntl.h>
#endif
#include "cops_rsc.h"
#include "adaptrsc.h"
#include "callback.h"
#include "cops.h"
#include "cpx_bind.h"
#include "fix_rsc.h"
#include "popup.h"
#include "objmacro.h"
#undef min
#undef max
#define DEBUG_CALLBACK(cpx) DEBUG((DEBUG_FMT "(%s)\n", DEBUG_ARGS, cpx ? cpx->file_name : "not found"))
static struct cpxlist *_cdecl get_cpx_list(void) { return cpxlist; }
static void _cdecl rsh_fix(struct rsh_fix_args);
static void _cdecl rsh_obfix(struct rsh_obfix_args);
static short _cdecl Popup(struct Popup_args);
static void _cdecl Sl_size(struct Sl_size_args);
static void _cdecl Sl_x(struct Sl_xy_args);
static void _cdecl Sl_y(struct Sl_xy_args);
static void _cdecl Sl_arrow(struct Sl_arrow_args);
static void _cdecl Sl_dragx(struct Sl_dragxy_args);
static void _cdecl Sl_dragy(struct Sl_dragxy_args);
static GRECT * _cdecl GetFirstRect(GRECT *prect);
static GRECT * _cdecl GetNextRect(void *args);
static void _cdecl Set_Evnt_Mask(struct Set_Evnt_Mask_args args);
static short _cdecl XGen_Alert(struct XGen_Alert_args);
static short _cdecl CPX_Save(void *ptr, long bytes);
static void * _cdecl Get_Buffer(void *args);
static void _cdecl MFsave(struct MFsave_args);
/*----------------------------------------------------------------------------------------*/
/* Cookie suchen */
/* Funktionsresultat: 0: nicht vorhanden 1: Cookie gefunden */
/* cookie: Cookietyp */
/* p_value: hier wird der Cookiewert zurueckgeliefert */
/*----------------------------------------------------------------------------------------*/
#if defined(__PUREC__) || defined(__AHCC__) || defined(__FASTCALL__)
static short _cdecl getcookie(long cookie, long *p_value)
{
DEBUG(("getcookie(0x%lx, %p)\n", cookie, p_value));
return get_cookie(cookie, p_value);
}
#endif
/*
* exported cpx support functions
*/
struct xcpb xctrl_pb =
{
0,
0,
0,
0,
get_cpx_list,
save_header,
rsh_fix,
rsh_obfix,
Popup,
Sl_size,
Sl_x,
Sl_y,
Sl_arrow,
Sl_dragx,
Sl_dragy,
Xform_do,
GetFirstRect,
(GRECT * _cdecl (*)(void))GetNextRect,
Set_Evnt_Mask,
XGen_Alert,
CPX_Save,
(void * _cdecl (*)(void))Get_Buffer,
#if defined(__PUREC__) || defined(__AHCC__) || defined(__FASTCALL__)
getcookie,
#else
get_cookie,
#endif
0, /* country; will be changed by initialization */
MFsave
};
/*
* search cpx
*/
CPX_DESC *
find_cpx_by_addr(void *pc)
{
const void *addr = pc;
CPX_DESC *cpx;
DEBUG(("find_cpx_by_addr(%p)\n", addr));
cpx = cpx_desc_list;
while (cpx)
{
if (cpx->start_of_cpx && cpx->end_of_cpx)
{
DEBUG(("find_cpx_by_addr: [%s] start %p end %p\n",
cpx->file_name, cpx->start_of_cpx, cpx->end_of_cpx));
if (addr >= cpx->start_of_cpx && addr < cpx->end_of_cpx)
break;
}
cpx = cpx->next;
}
return cpx;
}
/*----------------------------------------------------------------------------------------*/
/* CPX-Header speichern */
/* Funktionsresultat: CPX-Liste */
/* cpx_list: alte CPX-Beschreibung */
/*----------------------------------------------------------------------------------------*/
short _cdecl
save_header(struct cpxlist *cpx_list)
{
char name[256];
CPX_DESC *cpx_desc;
short handle;
short result = 0;
DEBUG(("save_header\n"));
cpx_desc = (CPX_DESC *)((unsigned char *)cpx_list - offsetof(CPX_DESC, old));
strcpy(name, settings.cpx_path);
strcat(name, cpx_desc->file_name);
handle = (short)Fopen(name, O_WRONLY);
if (handle > 0)
{
long ret;
ret = Fwrite(handle, sizeof(cpx_list->header), &(cpx_list->header));
if (ret == sizeof(cpx_list->header))
result = 1;
Fclose(handle);
}
return result;
}
/*----------------------------------------------------------------------------------------*/
/* Resource anpassen, Indizes in Zeiger wandeln, Pixelkoordinaten eintragen */
/* Funktionsresultat: - */
/* num_objs: Anzahl aller Objekte in rs_object */
/* num_frstr: Anzahl der freien Strings in rs_frstr */
/* num_frimg: Anzahl der freien BITBLKs in rs_frimg */
/* num_tree: Anzahl der Baeume in rs_trindex */
/* rs_object: Feld mit saemtlichen Resource-OBJECTs */
/* rs_tedinfo: Feld mit den von OBJECTs angesprochenen TEDINFOs */
/* rs_string: Feld mit Strings */
/* rs_iconblk: Feld mit ICONBLKs fuer OBJECTs */
/* rs_bitblk: Feld mit BITBLKs fuer OBJECTs */
/* rs_frstr: Feld mit Indizes/Zeigern auf freie Strings */
/* rs_frimg: Feld mit Indizes/Zeigern auf freie Images */
/* rs_trindex: Feld mit Indizes/Zeigern auf Objektbaeume */
/* rs_imdope: Feld mit Zeigern auf Images fuer ICONBLKs */
/*----------------------------------------------------------------------------------------*/
static void cpx_rsh_obfix(CPX_DESC *cpx_desc, OBJECT *tree, short ob);
static void cpx_rsh_fix(CPX_DESC *cpx_desc, const struct rsh_fix_args *args)
{
OBJECT *obj;
DEBUG_CALLBACK(cpx_desc);
if (cpx_desc->xctrl_pb.SkipRshFix == 0)
{
short num_objs = args->num_objs;
DEBUG(("rsh_fix num_objs %d, num_frstr %d, num_frimg %d, num_tree %d\n",
args->num_objs, args->num_frstr, args->num_frimg, args->num_tree));
fix_rsc(args->num_objs, args->num_frstr, args->num_frimg, args->num_tree,
args->rs_object, args->rs_tedinfo, args->rs_strings, args->rs_iconblk, args->rs_bitblk,
args->rs_frstr, args->rs_frimg, args->rs_trindex, args->rs_imdope);
obj = args->rs_object;
while (num_objs > 0)
{
cpx_rsh_obfix(cpx_desc, obj, 0); /* in Pixelkoordinaten wandeln */
obj++;
num_objs--;
}
if (args->rs_object->ob_width > 512) /* Grundobjekt zu breit? */
args->rs_object->ob_width = 512;
if (args->rs_object->ob_height > 384) /* Grundobjekt zu hoch? */
args->rs_object->ob_height = 384;
cpx_desc->xctrl_pb.SkipRshFix = 1; /* RSC wurde schon einmal initialisiert */
}
}
static void _cdecl
rsh_fix(struct rsh_fix_args args)
{
CPX_DESC *cpx;
void *pc = ((void **)&args)[-1];
cpx = find_cpx_by_addr(pc);
DEBUG_CALLBACK(cpx);
if (cpx)
{
cpx_rsh_fix(cpx, &args);
}
}
/*----------------------------------------------------------------------------------------*/
/* Zeichenkoordinaten eines Objekts in Pixel umrechnen */
/* Funktionsresultat: - */
/* tree: Adresse des Objektbaums */
/* ob: Objektnummer */
/*----------------------------------------------------------------------------------------*/
static void
cpx_rsh_obfix(CPX_DESC *cpx_desc, OBJECT *tree, short ob)
{
short hpix, ypix;
DEBUG_CALLBACK(cpx_desc);
DEBUG(("rsh_obfix ob %d\n", (int)ob));
ypix = (tree[ob].ob_y & 0xff00) >> 8;
tree[ob].ob_y &= 0xff;
hpix = (tree[ob].ob_height & 0xff00) >> 8;
tree[ob].ob_height &= 0xff;
rsrc_obfix(tree, ob); /* von Zeichen- in Pixelkoordinaten umrechnen */
if ((pwchar == 8) && (phchar == 8)) /* unselige Aufloesung? */
{
tree[ob].ob_y += tree[ob].ob_y; /* Hoehe und Position korrigieren */
tree[ob].ob_height += tree[ob].ob_height;
}
tree[ob].ob_y += ypix;
tree[ob].ob_height += hpix;
if ((ob == 0) && (cpx_desc->obfix_cnt == 0))
{
cpx_desc->box_width = tree->ob_width;
cpx_desc->box_height = tree->ob_height;
if (cpx_desc->box_width < 32) /* Grundobjekt zu schmal? */
cpx_desc->box_width = 32;
if (cpx_desc->box_height < 32) /* Grundobjekt zu niedrig? */
cpx_desc->box_height = 32;
if (cpx_desc->box_width > 512) /* Grundobjekt zu breit? */
cpx_desc->box_width = 512;
if (cpx_desc->box_height > 384) /* Grundobjekt zu hoch? */
cpx_desc->box_height = 384;
}
cpx_desc->obfix_cnt++;
/* Funktioniert in ram-residenten CPXen aufgrund der
* <SkipRshFix>-Abfrage vor der <for>-Schleife...
*/
cpx_desc->xctrl_pb.SkipRshFix = 1; /* RSC wurde schon einmal initialisiert */
}
static void _cdecl
rsh_obfix(struct rsh_obfix_args args)
{
CPX_DESC *cpx;
void *pc = ((void **)&args)[-1];
cpx = find_cpx_by_addr(pc);
DEBUG_CALLBACK(cpx);
if (cpx)
{
cpx_rsh_obfix(cpx, args.tree, args.ob);
}
}
/*----------------------------------------------------------------------------------------*/
/* Popup zeichnen */
/* Funktionsresultat: Index des angewaehlten Eintrags oder -1 */
/* strs: Strings */
/* no_strs: Anzahl der Strings */
/* slct: Index des selektierten Eintrags */
/* font: wird ignoriert */
/* button_rect: Ausmasse des Grundbuttons */
/* tree_rect: Ausmasse des CPX */
/*----------------------------------------------------------------------------------------*/
static short _cdecl
Popup(struct Popup_args args)
{
DEBUG(("Popup\n"));
return do_popup(args.up, args.items, args.no_items, 0, args.slct);
}
/*----------------------------------------------------------------------------------------*/
/* Objekt zeichnen */
/* Funktionsresultat: - */
/* fnt_dialog: Zeiger auf die Fontdialog-Struktur */
/* obj: Nummer des Objekts */
/*----------------------------------------------------------------------------------------*/
static void
redraw_obj(OBJECT *tree, short obj)
{
GRECT *r = (GRECT *) &tree->ob_x; /* Dialog-Rechteck */
wind_update(BEG_UPDATE);
objc_draw_grect(tree, obj, MAX_DEPTH, r);
wind_update(END_UPDATE);
}
/*----------------------------------------------------------------------------------------*/
/* Slidergroesse einstellen */
/* Funktionsresultat: - */
/* tree: Zeiger auf den Objektbaum */
/* base: Hintergrundobjekt fuer den Slider */
/* slider: Objektnummer des Sliders */
/* num_items: Anzahl der vorhandenen Elemente */
/* visible: Anzahl der sichtbaren Elemente */
/* direction: Richtung (0: vertikal, 1: horizontal) */
/* min_size: minimale Slidergroesse */
/*----------------------------------------------------------------------------------------*/
static void _cdecl
Sl_size(struct Sl_size_args args)
#define tree args.tree
#define base args.base
#define slider args.slider
#define num_items args.num_items
#define visible args.visible
#define direction args.direction
#define min_size args.min_size
{
DEBUG(("Sl_size base %d, slider %d, num_items %d, visible %d, direction %d, min_size %d\n",
base, slider, num_items, visible, direction, min_size));
if (direction)
{
/* horizontaler Slider */
tree[slider].ob_x = 0;
if (visible >= num_items) /* weniger Elemente als darstellbar? */
tree[slider].ob_width = tree[base].ob_width;
else
tree[slider].ob_width = (short) (((long) tree[base].ob_width * visible) / num_items);
if (tree[slider].ob_width < min_size)
tree[slider].ob_width = min_size;
}
else
{
/* vertikaler Slider */
tree[slider].ob_y = 0;
if (visible >= num_items) /* weniger Elemente als darstellbar? */
tree[slider].ob_height = tree[base].ob_height;
else
tree[slider].ob_height = (short) (((long) tree[base].ob_height * visible) / num_items);
if (tree[slider].ob_height < min_size)
tree[slider].ob_height = min_size;
}
}
#undef min_size
#undef direction
#undef visible
#undef num_items
#undef slider
#undef base
#undef tree
/*----------------------------------------------------------------------------------------*/
/* Slider in horizontaler Richtung positionieren */
/* Funktionsresultat: - */
/* tree: Zeiger auf den Objektbaum */
/* base: Hintergrundobjekt fuer den Slider */
/* slider: Objektnummer des Sliders */
/* value: neuer Wert, den der Slider repraesentieren soll */
/* min: Minimalwert, den value annehmen darf */
/* max: Maximalwert, den value annehmen darf */
/* userdef: benutzerdefinierte Funktion */
/*----------------------------------------------------------------------------------------*/
static void
cpx_Sl_x(OBJECT *tree, short base, short slider, short value,
short min, short max, void __CDECL (*userdef)(void))
{
short w;
DEBUG(("Sl_x base %d, slider %d, value %d, min %d, max %d\n",
base, slider, value, min, max));
w = tree[base].ob_width - tree[slider].ob_width;
if (min <= max) /* Slider hat links Minimalwert und rechts Maximalwert? */
{
value -= min;
max -= min;
if (value < 0)
value = 0;
if (value > max)
value = max;
tree[slider].ob_x = max == 0 ? 0 : (short)(((long) w * value) / max);
}
else /* Slider hat links Maximalwert und rechts Minimalwert */
{
value -= max;
min -= max;
if (value < 0)
value = 0;
if (value > min)
value = min;
tree[slider].ob_x = w - (short)(((long) w * value) / min);
}
/* benutzerdefinierte Funktion aufrufen */
cpx_userdef(userdef);
}
static void _cdecl
Sl_x(struct Sl_xy_args args)
{
cpx_Sl_x(args.tree, args.base, args.slider, args.value,
args.min, args.max, args.userdef);
}
/*----------------------------------------------------------------------------------------*/
/* Slider in vertikaler Richtung positionieren */
/* Funktionsresultat: - */
/* tree: Zeiger auf den Objektbaum */
/* base: Hintergrundobjekt fuer den Slider */
/* slider: Objektnummer des Sliders */
/* value: neuer Wert, den der Slider repraesentieren soll */
/* min: Minimalwert, den value annehmen darf */
/* max: Maximalwert, den value annehmen darf */
/* userdef: benutzerdefinierte Funktion */
/*----------------------------------------------------------------------------------------*/
static void
cpx_Sl_y(OBJECT *tree, short base, short slider, short value,
short min, short max, void __CDECL (*userdef)(void))
{
short h;
DEBUG(("Sl_y base %d, slider %d, value %d, min %d, max %d\n",
base, slider, value, min, max));
h = tree[base].ob_height - tree[slider].ob_height;
if (min <= max) /* Slider hat oben Maximalwert und unten Minimalwert? */
{
value -= min;
max -= min;
if (value < 0)
value = 0;
if (value > max)
value = max;
tree[slider].ob_y = h - (max == 0 ? 0 : (short)(((long) h * value) / max));
}
else /* Slider hat oben Minimalwert und unten Maximalwert */
{
value -= max;
min -= max;
if (value < 0)
value = 0;
if (value > min)
value = min;
tree[slider].ob_y = (short)(((long) h * value) / min);
}
/* benutzerdefinierte Funktion aufrufen */
cpx_userdef(userdef);
}
static void _cdecl
Sl_y(struct Sl_xy_args args)
{
cpx_Sl_y(args.tree, args.base, args.slider, args.value,
args.min, args.max, args.userdef);
}
/*----------------------------------------------------------------------------------------*/
/* Klick auf Scrollpfeil oder Sliderhintergrund bearbeiten */
/* Funktionsresultat: - */
/* tree: Zeiger auf den Objektbaum */
/* base: Hintergrundobjekt fuer den Slider */
/* slider: Objektnummer des Sliders */
/* inc: Anzahl der Einheiten, die addiert oder subtrahiert werden sollen*/
/* min: Minimalwert, den value annehmen darf */
/* max: Maximalwert, den value annehmen darf */
/* value: neuer Wert, den der Slider repraesentieren soll */
/* direction: Richtung (0: vertikal, 1: horizontal) */
/* userdef: benutzerdefinierte Funktion */
/*----------------------------------------------------------------------------------------*/
static void _cdecl
Sl_arrow(struct Sl_arrow_args args)
{
#define tree args.tree
#define base args.base
#define slider args.slider
#define obj args.obj
#define inc args.inc
#define min args.min
#define max args.max
#define value args.value
#define direction args.direction
#define userdef args.userdef
short val;
DEBUG(("Sl_arrow base %d, slider %d, obj %d, inc %d, min %d, max %d, value %d, direction %d\n",
base, slider, obj, inc, min, max, *value, direction));
val = *value + inc; /* neue Position */
if (min <= max)
{
if (val < min)
val = min;
if (val > max)
val = max;
}
else
{
if (val < max)
val = max;
if (val > min)
val = min;
}
*value = val; /* Wert zurueckschreiben */
if (obj >= 0)
{
obj_SELECTED(tree, obj);
redraw_obj(tree, obj); /* Button selektieren */
}
if (direction) /* horizontaler Slider? */
cpx_Sl_x(tree, base, slider, val, min, max, userdef);
else
cpx_Sl_y(tree, base, slider, val, min, max, userdef);
redraw_obj(tree, base); /* Slider neuzeichnen */
evnt_timer(40); /* warten, damit das Scrolling nicht zu schnell wird */
if (obj >= 0)
{
obj_DESELECTED(tree, obj);
redraw_obj(tree, obj); /* Button wieder normal */
}
#undef tree
#undef base
#undef slider
#undef obj
#undef inc
#undef min
#undef max
#undef value
#undef direction
#undef userdef
}
/*----------------------------------------------------------------------------------------*/
/* Slider in horizontaler Richtung bewegen */
/* Funktionsresultat: - */
/* tree: Zeiger auf den Objektbaum */
/* base: Hintergrundobjekt fuer den Slider */
/* slider: Objektnummer des Sliders */
/* inc: Anzahl der Einheiten, die addiert oder subtrahiert werden sollen*/
/* min: Minimalwert, den value annehmen darf */
/* max: Maximalwert, den value annehmen darf */
/* value: neuer Wert, den der Slider repraesentieren soll */
/* userdef: benutzerdefinierte Funktion */
/*----------------------------------------------------------------------------------------*/
static void _cdecl
Sl_dragx(struct Sl_dragxy_args args)
#define tree args.tree
#define base args.base
#define slider args.slider
#define min args.min
#define max args.max
#define value args.value
#define userdef args.userdef
{
short hpos;
DEBUG(("Sl_dragx base %d, slider %d, min %d, max %d, value %d\n",
base, slider, min, max, *value));
hpos = graf_slidebox(tree, base, slider,0);
*value = (short)(((long)(max - min) * hpos) / 1000);
*value += min;
cpx_Sl_x(tree, base, slider, *value, min, max, userdef);
/* Slider neuzeichnen */
redraw_obj(tree, base);
}
/*----------------------------------------------------------------------------------------*/
/* Slider in vertikaler Richtung bewegen */
/* Funktionsresultat: - */
/* tree: Zeiger auf den Objektbaum */
/* base: Hintergrundobjekt fuer den Slider */
/* slider: Objektnummer des Sliders */
/* inc: Anzahl der Einheiten, die addiert oder subtrahiert werden sollen*/
/* min: Minimalwert, den value annehmen darf */
/* max: Maximalwert, den value annehmen darf */
/* value: neuer Wert, den der Slider repraesentieren soll */
/* userdef: benutzerdefinierte Funktion */
/*----------------------------------------------------------------------------------------*/
static void _cdecl
Sl_dragy(struct Sl_dragxy_args args)
{
short vpos;
DEBUG(("Sl_dragy base %d, slider %d, min %d, max %d, value %d\n",
base, slider, min, max, *value));
vpos = graf_slidebox(tree, base, slider, 1);
*value = (short)(((long)(max - min) * (1000 - vpos)) / 1000);
*value += min;
cpx_Sl_y(tree, base, slider, *value, min, max, userdef);
/* Slider neuzeichnen */
redraw_obj(tree, base);
}
#undef userdef
#undef value
#undef max
#undef min
#undef slider
#undef base
#undef tree
static short
is_edit_obj_hidden(OBJECT *tree, short obj)
{
if (is_obj_HIDDEN(tree, obj))
return 1;
while (tree[obj].ob_next != -1) /* Wurzel gefunden? */
{
short last_obj;
last_obj = obj;
obj = tree[obj].ob_next; /* naechstes Objekt oder Vater */
if (last_obj == tree[obj].ob_tail) /* war das letzte Objekt ein Kind, ist obj der Vater? */
{
if (is_obj_HIDDEN(tree, obj))
return 1;
}
}
return 0;
}
_WORD find_obj(OBJECT *tree, _WORD startob, DIRS direction)
{
_WORD obj;
_WORD searchflag;
_WORD curflag;
_WORD inc;
obj = 0;
searchflag = OF_EDITABLE;
inc = 1;
switch (direction)
{
case BACKWARD:
inc = -1;
obj = startob + inc;
break;
case FORWARD:
if (!(tree[startob].ob_flags & OF_LASTOB))
obj = startob + inc;
else
obj = -1;
break;
case DEFAULTDIR:
searchflag = OF_DEFAULT;
break;
case NODIR:
return startob;
}
while (obj >= 0)
{
curflag = tree[obj].ob_flags;
if (searchflag & curflag)
return obj;
if (curflag & OF_LASTOB)
obj = -1;
else
obj += inc;
}
return startob;
}
/*----------------------------------------------------------------------------------------*/
/* (Xform_do) form_do() fuer CPX-Fenster simulieren */
/* Funktionsergebnis: CPX_DESC des neuen Kontexts */
/* cpx_desc: CPX-Beschreibung */
/* tree: Objektbaum des CPX */
/* edit_obj: Nummer des aktiven Editobjekts oder 0 */
/* msg: Zeiger auf Message-Buffer fuer ausgewaehlte Ereignisse */
/*----------------------------------------------------------------------------------------*/
void
cpx_form_do(CPX_DESC *cpx_desc, OBJECT *tree, _WORD edit_obj, _WORD *msg)
{
DIALOG *dialog;
_WORD last_edit_obj;
DEBUG_CALLBACK(cpx_desc);
dialog = cpx_desc->dialog;
if (tree != cpx_desc->tree) /* Objektbaum geaendert? */
{
if (cpx_desc->tree == NULL)
cpx_desc->size.g_y -= desk_grect.g_h; /* CPX-Rechteck wieder innerhalb des Schirms */
cpx_desc->tree = tree;
obj_HIDDEN(tree, ROOT); /* Baum nicht zeichnen! */
if (dialog)
wdlg_set_tree(dialog, tree); /* neuen Objektbaum setzen */
tree[ROOT].ob_x = cpx_desc->size.g_x;
tree[ROOT].ob_y = cpx_desc->size.g_y;
obj_VISIBLE(tree, ROOT);
if (edit_obj == 0)
edit_obj = find_obj(tree, 0, FORWARD);
cpx_desc->edit_obj = edit_obj;
cpx_desc->cursor_idx = -1;
cpx_desc->cursor = FALSE;
}
if (dialog)
{
last_edit_obj = wdlg_get_edit(dialog, &cpx_desc->cursor_idx); /* Editobjekt erfragen */
} else
{
last_edit_obj = 0;
}
if (last_edit_obj > 0) /* Editobjekt aktiv? */
{
if (dialog)
{
if (is_edit_obj_hidden(tree, last_edit_obj)) /* Editobjekt unsichtbar? */
{
obj_HIDDEN(tree, ROOT); /* Baum nicht zeichnen! */
wdlg_set_tree(dialog, tree); /* Objektbaum nochmals setzen, Cursorzustand zuruecksetzen */
obj_VISIBLE(tree, ROOT);
}
}
}
if (edit_obj)
{
if (dialog)
{
wdlg_set_edit(dialog, edit_obj); /* Editobjekt setzen */
} else
{
}
}
cpx_desc->button = -1; /* noch kein Button gedrueckt */
cpx_desc->msg = msg;
cpx_main_loop();
}
/*----------------------------------------------------------------------------------------*/
/* (GetFirstRect) erstes Redraw-Rechteck fuer CPX-Fenster zurueckliefern */
/* Funktionsergebnis: Redraw-Rechteck oder NULL */
/* cpx_desc: CPX-Beschreibung */
/* redraw_area: Maximale Groesse des insgesamt zu zeichnenden Bereichs */
/*----------------------------------------------------------------------------------------*/
static GRECT *cpx_get_first_rect(CPX_DESC *cpx_desc, GRECT *redraw_area)
{
GRECT *w;
DEBUG_CALLBACK(cpx_desc);
cpx_desc->redraw_area = *redraw_area; /* fuer Aufruf von cpx_get_next_rect() merken */
w = &cpx_desc->dirty_area;
DEBUG(("cpx_get_first_rect: redraw_area is x %d y %d w %d h %d\n",
redraw_area->g_x, redraw_area->g_y, redraw_area->g_w, redraw_area->g_h));
/* first redraw rectangle */
wind_get_grect(cpx_desc->whdl, WF_FIRSTXYWH, w);
while (w->g_w)
{
if (rc_intersect(&cpx_desc->redraw_area, w))
{
DEBUG(("cpx_get_first_rect: x %d y %d w %d h %d\n",
w->g_x, w->g_y, w->g_w, w->g_h));
/* zu zeichnender Bereich */
return w;
}
/* naechstes Redraw-Rechteck */
wind_get_grect(cpx_desc->whdl, WF_NEXTXYWH, w);
}
DEBUG(("cpx_get_first_rect: no more rectangles\n"));
return NULL;
}
static GRECT * _cdecl GetFirstRect(GRECT *prect)
{
CPX_DESC *cpx;
void *pc = ((void **)&prect)[-1];
cpx = find_cpx_by_addr(pc);
DEBUG_CALLBACK(cpx);
if (cpx)
{
return cpx_get_first_rect(cpx, prect);
}
return NULL;
}
/*----------------------------------------------------------------------------------------*/
/* (GetNextRect) naechstes Redraw-Rechteck fuer CPX-Fenster zurueckliefern */
/* Funktionsergebnis: Redraw-Rechteck oder NULL */
/* cpx_desc: CPX-Beschreibung */
/*----------------------------------------------------------------------------------------*/
static GRECT *cpx_get_next_rect(CPX_DESC *cpx_desc)
{
GRECT *w = &(cpx_desc->dirty_area);
DEBUG_CALLBACK(cpx_desc);
/* naechstes Redraw-Rechteck */
wind_get_grect(cpx_desc->whdl, WF_NEXTXYWH, w);
while (w->g_w)
{
if (rc_intersect(&cpx_desc->redraw_area, w))
{
DEBUG(("cpx_get_next_rect: x %d y %d w %d h %d\n",
w->g_x, w->g_y, w->g_w, w->g_h));
/* zu zeichnender Bereich */
return w;
}
/* naechstes Redraw-Rechteck */
wind_get_grect(cpx_desc->whdl, WF_NEXTXYWH, w);
}
DEBUG(("cpx_get_next_rect: no more rectangles\n"));
return NULL;
}
static GRECT * _cdecl GetNextRect(void *args)
{
CPX_DESC *cpx;
void *pc = (&args)[-1];
cpx = find_cpx_by_addr(pc);
DEBUG_CALLBACK(cpx);
if (cpx)
return cpx_get_next_rect(cpx);
return NULL;
}
/*----------------------------------------------------------------------------------------*/
/* (Set_Evnt_Mask) Eventmaske fuer evnt_multi veraendern; ggf. Mausrechtecke, Timer setzen */
/* Funktionsergebnis: 0: Fehler 1: alles in Ordnung */
/* cpx_desc: CPX-Beschreibung */
/* mask: zusaetzliche Ereignismaske */
/* m1: erstes Mausrechteck */
/* m2: zweites Mausrechteck */
/* time: Timerintervall */
/*----------------------------------------------------------------------------------------*/
static void
cpx_set_evnt_mask(CPX_DESC *cpx_desc, short mask, MOBLK *m1, MOBLK *m2, long timeout)
{
DEBUG_CALLBACK(cpx_desc);
if (m1) /* erstes Mausrechteck? */
cpx_desc->m1 = *m1;
else
mask &= ~MU_M1;
if (m2) /* zweites Mausrechteck? */
cpx_desc->m2 = *m2;
else
mask &= ~MU_M2;
if (mask & MU_TIMER) /* Timer? */
cpx_desc->time = timeout;
else
cpx_desc->time = 0;
cpx_desc->mask = mask; /* zusaetzliche Ereignismaske */
}
static void _cdecl Set_Evnt_Mask(struct Set_Evnt_Mask_args args)
{
CPX_DESC *cpx;
void *pc = ((void **)&args)[-1];
cpx = find_cpx_by_addr(pc);
DEBUG_CALLBACK(cpx);
if (cpx)
{
cpx_set_evnt_mask(cpx, args.mask, args.m1, args.m2, args.evtime);
}
}