-
Notifications
You must be signed in to change notification settings - Fork 0
/
objid.goc
1709 lines (1498 loc) · 51.8 KB
/
objid.goc
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
/* This code runs on a foreign thread */
#pragma option -WDE
@include <stdapp.goh>
@include <foam.goh>
#include <ansi/stdio.h>
#include <ansi/string.h>
@include "common.goh"
@prototype optr OL_BUTTON_GET_GEN_PART_MSG() = cx:dx;
ObjectRefs G_lastObj;
ObjectRefTexts G_lastObjTexts;
optr G_lastFocus;
dword G_pseudoCursorPos, G_oldPseudoCursorPos;
/* Shorthands for common tests on an object */
#define HasVardata(_obj, _vardata) \
(@call _obj::MSG_META_GET_VAR_DATA(_vardata, 0, NULL) != (word)-1)
#define IsInClass(_obj, _class) \
(@call _obj::MSG_META_IS_OBJECT_IN_CLASS(&(_class)))
/* Test if an object is a special one in a particular application */
Boolean IsHackObject(optr obj, char *app, word id, word chunk)
{
GeodeHandle gh;
/* Quick test for chunk comes first */
if(OptrToChunk(obj)==chunk)
{
/* Is geode for special handling loaded? */
gh = GeodeFind(app, GEODE_NAME_SIZE, 0, 0);
/* Construct optr to the object we are looking for */
if(gh && OptrToHandle(obj)==GeodeGetGeodeResourceHandle(gh, id))
return TRUE;
}
return FALSE;
}
Boolean IsInHackClass(optr obj, char *app, word exp)
{
GeodeHandle gh;
/* Is geode for special handling loaded? */
gh = GeodeFind(app, GEODE_NAME_SIZE, 0, 0);
/* Is object of the class specified by its export ordinal number? */
if(gh && @call obj::MSG_META_IS_OBJECT_IN_CLASS(ProcGetLibraryEntry(gh, exp)))
return TRUE;
return FALSE;
}
void HackGetInstance(optr obj, word level, word ofs, void *data, word size)
{
byte *base;
ObjLockObjBlock(OptrToHandle(obj)); // Lock down object's block
base = ObjDeref(obj, level); // Dereference requested variant level
memcpy(data, base+ofs, size); // Get field at specified offset
MemUnlock(OptrToHandle(obj));
}
/* An XPath-inspired way of relative addressing within a Vis object tree... */
optr VisTreePath(optr obj, char *path)
{
int n;
optr obj1;
while(*path && obj)
{
obj1 = obj;
obj = NullOptr; // Not found unless clearly identified
/* '1'..'9' and 'a'..'z' specify a step to the n-th child (base36) */
if((*path>='1' && *path<='9') || (*path>='a' && *path<='z'))
{
n = (*path - '0') - ((*path>='a')? ('a' - '0' + 10) : 0);
if(IsInClass(obj1, VisCompClass))
obj = @call obj1::MSG_VIS_FIND_CHILD_AT_POSITION(n-1);
}
/* '*' specifies a step to the last child */
else if(*path=='*')
{
if(IsInClass(obj1, VisCompClass))
{
n = @call obj1::MSG_VIS_COUNT_CHILDREN();
if(n)
obj = @call obj1::MSG_VIS_FIND_CHILD_AT_POSITION(n-1);
}
}
/* '.' specifies a step to the parent */
else if(*path=='.')
{
if(IsInClass(obj1, VisClass))
obj = @call obj1::MSG_VIS_FIND_PARENT();
}
/* 'C' specifies a step to the content */
else if(*path=='C')
{
if(IsInClass(obj1, GenViewClass))
obj = @call obj1::MSG_GEN_VIEW_GET_CONTENT();
}
path++;
}
return obj;
}
/*
***************************************************************************
* Code for object identification
***************************************************************************
*/
#define PSEUDO_OBJ_NONE ConstructOptr(0xFFFF,1)
#define PSEUDO_OBJ_ON ConstructOptr(0xFFFF,2)
#define PSEUDO_OBJ_OFF ConstructOptr(0xFFFF,3)
#define PSEUDO_OBJ_TIME ConstructOptr(0xFFFF,4)
#define IS_PSEUDO_OBJ(_obj) (OptrToHandle(_obj)==0xFFFF)
char *G_textPtr;
word G_textBufsize;
optr G_getObject;
GStateHandle G_gstring;
optr G_actionObject;
dword G_actionType;
dword G_actionData;
Boolean _export _pascal FindText(byte *elm,GStateHandle gstate)
{
char *txt = NULL;
int len;
Boolean newField = FALSE;
char gsbuf[2];
word size;
#pragma argsused
if(*elm==GR_DRAW_TEXT)
{
txt = (char *)elm+sizeof(byte)+sizeof(word)+sizeof(word);
newField = TRUE;
}
else if(*elm==GR_DRAW_TEXT_CP)
txt = (char *)elm+sizeof(byte);
else if(*elm==GR_MOVE_TO) // Move to seperates fields in tables
newField = TRUE;
else if(*elm==GR_DRAW_BITMAP || *elm==GR_DRAW_BITMAP_CP ||
*elm==GR_FILL_BITMAP || *elm==GR_FILL_BITMAP_CP)
{
/* Get size of element */
GrGetGStringElement(gstate, G_gstring, sizeof(gsbuf), &gsbuf, &size);
/* Abort if buffer overflows */
len = strlen(G_textPtr);
if(len+12 >= G_textBufsize)
return TRUE;
/* Compute checksum and insert into string */
sprintf(G_textPtr+len, PL("%08lx"), calc_crc(elm,size));
}
if(newField && G_textPtr)
{
if(*G_textPtr && strlen(G_textPtr)+1 < G_textBufsize)
strcat(G_textPtr, " ");
}
if(txt)
{
len = strlen(G_textPtr);
if(len>2 && G_textPtr[len-2]=='-' && G_textPtr[len-1]==' ')
len-=2; // concatenate hyphenated words
if(len+*(word *)txt+1 >= G_textBufsize)
return TRUE; // abort if buffer overflows
strncpy(G_textPtr+len, txt+sizeof(word), *(word *)txt);
G_textPtr[len + *(word *)txt] = 0;
}
return FALSE;
}
void ExtractVisMoniker(optr vismon)
{
char *gs;
char *vmbuf,*end;
VisMonikerListEntry *vmle;
static void *findText = FindText;
ObjLockObjBlock(OptrToHandle(vismon));
vmbuf = LMemDeref(vismon);
end = vmbuf + LMemGetChunkSizePtr(vmbuf);
if( ((VisMoniker *)vmbuf)->VM_type & VMT_MONIKER_LIST )
{
/* Recursively run through a VisMonikerList to find some useful text */
/* Look for a Text style moniker */
vmle = (VisMonikerListEntry *)vmbuf;
while((char *)vmle<end &&
((vmle->VMLE_type & VMLET_STYLE)>>VMLET_STYLE_OFFSET)!=VMS_TEXT)
vmle++;
/* Check Text moniker with priority if found */
if((char *)vmle<end)
ExtractVisMoniker(vmle->VMLE_moniker);
/* Retry all monikers if Text search didn't produce results */
vmle = (VisMonikerListEntry *)vmbuf;
while((char *)vmle<end && !*G_textPtr) ExtractVisMoniker((vmle++)->VMLE_moniker);
}
else
{
if( ((VisMoniker *)vmbuf)->VM_type & VMT_GSTRING )
{
gs = vmbuf+VMWGS_gString;
G_gstring = GrLoadGString(PtrToSegment(gs), GST_PTR, PtrToOffset(gs));
My_GrParseGString((GStateHandle)0, G_gstring, GSC_ONE, findText);
GrDestroyGString(G_gstring, NULL, GSKT_LEAVE_DATA);
}
else
{
int i,j;
/* Copy moniker, possibly removing "-\r" sequence (multi-line) */
for(i=j=0; vmbuf[VMWT_text+i] && i<G_textBufsize-1; i++)
if(vmbuf[VMWT_text+i]!='-' || vmbuf[VMWT_text+i+1]!='\r')
G_textPtr[j++] = vmbuf[VMWT_text+i];
else
i++;
G_textPtr[j] = 0;
}
}
MemUnlock(OptrToHandle(vismon));
}
/*
* Get as much text out of the passed (G_getObject) object's moniker
* as possible. This assumes that it already runs on the object's thread.
*/
void _export GetVisMoniker(void)
{
ChunkHandle ch;
MemHandle block = OptrToHandle(G_getObject);
*G_textPtr = 0; // no text yet
ch = @call G_getObject::MSG_GEN_GET_VIS_MONIKER();
if(ch)
ExtractVisMoniker(ConstructOptr(block, ch));
}
/*
* Handles YearClass, assuming that it already runs on the object's thread.
*/
void _export GetYearMoniker(void)
{
byte month;
optr monthObj;
int d,fd;
dword monthMap,reservedMap;
char range[32], *p;
Boolean first = TRUE;
/* Get YI_curMonth and find corresponding month object */
HackGetInstance(G_getObject, 8, 0x0002, &month, sizeof(month));
monthObj = @call G_getObject::MSG_VIS_FIND_CHILD_AT_POSITION(month-1);
if(monthObj && IsInHackClass(monthObj, "geoplann", 1))
{
/* Get MI_titleString[32] to start month string */
HackGetInstance(monthObj, 8, 0x0023, G_textPtr, 32);
/* Read MI_monthMap and MI_reservedDayMap */
HackGetInstance(monthObj, 8, 0x0018, &monthMap, sizeof(monthMap));
HackGetInstance(monthObj, 8, 0x001C, &reservedMap, sizeof(reservedMap));
fd = -1;
monthMap |= reservedMap; // Whole days are also reserved
for(d=1; d<=32; d++) // Count 32 days to close all ranges
{
/* Continue while in continuous sequence of reserved days
of the same type (whole/partial day) */
if( ((monthMap>>d) & 1) &&
(fd==-1 || ((reservedMap>>fd) & 1)==((reservedMap>>d) & 1)) )
{
if(fd==-1) // Start a new range if not in one
fd = d;
}
else
{
if(fd!=-1) // Ending a range?
{
if(first) // Text between month and appointments
strcpy(range, PL("Appoint"));
else
*range = 0;
first = FALSE; // Past the first day with appointments
p = range + strlen(range); // Where to point the date range
if(fd==d-1) // A single isolated date
sprintf(p, " %d", d-1);
else if(fd==d-2 && !((reservedMap>>fd) & 1))
sprintf(p, " %d %d", fd, d-1);
// Two consecutive dates
else // More than two consecutive dates
sprintf(p, " %d" PL("to") "%d", fd, d-1);
if((reservedMap>>fd) & 1) // Mark ranges of reserved days
strcat(range, PL("resday"));
if(strlen(G_textPtr) + strlen(range) >= G_textBufsize)
break; // Abort if buffer overflows
strcat(G_textPtr, range); // Append date range
fd = -1; // Range has been dealt with
}
if((monthMap>>d) & 1) // If range type changed:
fd = d; // Start new range immediately
}
}
}
}
/*
* Handles CharsetContentClass, assuming that it already runs on the
* object's thread.
*/
void _export GetChrTableMoniker(void)
{
word selectionNumber;
const byte table[] = { // order of characters in table
0x88, 0x87, 0x8a, 0x89, 0x8b, 0xbe, 0x8c, 0x8d, 0x8f, 0x8e,
0x91, 0x90, 0x93, 0x92, 0x95, 0x94, 0x96, 0x98, 0x97, 0x9a,
0x99, 0x9b, 0xcf, 0xbf, 0xa7, 0x9d, 0x9c, 0x9f, 0x9e, 0xde,
0xd8, 0xcb, 0xe7, 0x80, 0xe5, 0xcc, 0xae, 0x81, 0x82, 0xe9,
0x83, 0xe8, 0xe6, 0xed, 0xea, 0xec, 0xeb, 0x84, 0xf1, 0xee,
0x85, 0xef, 0xcd, 0xce, 0xaf, 0xf4, 0xf2, 0x86, 0xf3, 0xdf,
0xd9, 0x24, 0x26, 0x7e, 0xa1, 0xa2, 0xa3, 0xa4, 0xa8, 0xa9,
0xaa, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb9, 0x60, 0xc2,
0xc3, 0xc4, 0xc5, 0xd6, 0xdb, 0xe4, 0xc0, 0xc1, 0xd1, 0xa5,
0x7b, 0x7d, 0x7c, 0x5e, 0xbd, 0xc9};
/* Get CCI_selectionNumber */
HackGetInstance(G_getObject, 4, sizeof(VisContentInstance),
&selectionNumber, sizeof(word));
/* Return character at position */
if(selectionNumber < sizeof(table))
{
G_textPtr[0] = (char)table[selectionNumber];
G_textPtr[1] = 0;
}
else
G_textPtr[1] = 0;
}
#pragma codeseg OBJID2_TEXT
/*
* Special translation for OLButtonClass objects to retrieve the
* corresponding Generic object, which is linked in a non-standard way,
* to supply state and moniker.
*/
optr GenEquiv(optr obj)
{
if(IsInClass(obj, *olbuttonclass))
{
return @call {OL_BUTTON_GET_GEN_PART_MSG}obj::{OL_BUTTON_GET_GEN_PART_MSG}(0x4803)();
}
return obj;
}
void collectChildren(optr root, ObjectRefs *oref, word xOfs, word yOfs)
{
int i,n;
optr obj,genObj;
GenInteractionVisibility giv;
word id;
Rectangle rect;
/* abort if object run by different thread (typically a VisContent),
to avoid deadlocking on @call */
if(!ObjTestIfObjBlockRunByCurThread(OptrToHandle(root))) return;
genObj = GenEquiv(root);
/* If we have seen the old pseudo cursor objects in the tree, keep them.
This ensures that the references get purged if the objects go out of
view. */
if(root==G_lastObj.pseudoCursor)
oref->pseudoCursor = root;
if(root==G_lastObj.pseudoCursorRoot)
oref->pseudoCursorRoot = root;
if(IsInClass(genObj, GenClass))
{
@call root::MSG_VIS_GET_BOUNDS(&rect);
rect.R_left += xOfs;
rect.R_top += yOfs;
/*
* Identify elements that map to the softkeys
*/
if(HasVardata(genObj, HINT_SEEK_REPLY_BAR) ||
HasVardata(genObj, HINT_SEEK_MENU_BAR))
{
if(@call genObj::MSG_GEN_GET_USABLE() &&
@call genObj::MSG_GEN_GET_ENABLED())
{
if(rect.R_top<48) oref->buttonLabels[0] = genObj;
else if(rect.R_top<96) oref->buttonLabels[1] = genObj;
else if(rect.R_top<144) oref->buttonLabels[2] = genObj;
else if(rect.R_top<192) oref->buttonLabels[3] = genObj;
else if(IsInClass(genObj, ComplexMonikerClass))
{
GetComplexMoniker gcm;
/* Recognize menu trigger by its name, just like the system */
@call genObj::MSG_COMPLEX_MONIKER_GET_MONIKER(&gcm);
if(gcm.GCM_topText==CMT_MENU)
oref->flags |= ORF_HAS_MENU;
}
}
}
/*
* Identify dialog label
*
* Rule:
* It must be the top-leftmost object meeting the following criteria:
* - It is wider than 7 pixels (to avoid confusion with vertical dividers)
* - It is in the upper half of the screen (e.g. Contacts window)
* - It is either a text object, or
* - It has a VisMoniker and is neither the GenPrimary nor a
* dialog-type GenInteraction nor a GenItem
*/
else if((!oref->dialogLabel ||
rect.R_top < oref->dialogLabelPos.P_y ||
(rect.R_top == oref->dialogLabelPos.P_y &&
rect.R_left < oref->dialogLabelPos.P_x)) &&
(rect.R_right-rect.R_left > 7) &&
(rect.R_top < 100))
{
if(IsInClass(genObj, GenTextClass) ||
(@call genObj::MSG_GEN_GET_VIS_MONIKER() &&
!IsInClass(genObj, GenPrimaryClass) &&
!IsInClass(genObj, GenItemClass) &&
(!IsInClass(genObj, GenInteractionClass) ||
@call genObj::MSG_GEN_INTERACTION_GET_VISIBILITY()==GIV_SUB_GROUP) &&
!HasVardata(genObj, HINT_DO_NOT_USE_MONIKER)))
{
oref->dialogLabel = genObj;
oref->dialogLabelPos.P_x = rect.R_left;
oref->dialogLabelPos.P_y = rect.R_top;
}
}
}
/*
* Try to refine an as-of-yet unidentified focus item
*/
if(!oref->focusLabel)
{
if(oref->textObj)
{
if(IsInClass(root, GenItemGroupClass) &&
(HasVardata(root, HINT_ITEM_GROUP_SCROLLABLE) ||
HasVardata(root, HINT_ITEM_GROUP_SHOW_SELECTION_EVEN_WHEN_NOT_FOCUS)))
{
id = @call root::MSG_GEN_ITEM_GROUP_GET_FOCUS_ITEM();
if(id != GIGS_NONE)
{
obj = @call root::MSG_GEN_ITEM_GROUP_GET_ITEM_OPTR(id);
if(obj)
oref->focusLabel = @call root::MSG_GEN_ITEM_GROUP_GET_ITEM_OPTR(id);
}
else
{
/*
* HACK:
*
* For calculator result list, focus the last entry which
* contains the most recent result.
*/
if(IsHackObject(oref->textObj, "calc ", 11, 0x40))
{
n = @call root::MSG_VIS_COUNT_CHILDREN();
if(n)
oref->focusLabel = @call root::MSG_VIS_FIND_CHILD_AT_POSITION(n-1);
}
}
}
}
else
{
if(IsInClass(root, VisTextClass))
{
if(@call root::MSG_VIS_TEXT_GET_STATE() & VTS_EDITABLE)
oref->textObj = root;
else
oref->focusLabel = root;
}
}
}
/*
* Ignore non-selected call headers in phone application
*/
if(IsInHackClass(root, "phone ", 7))
{
Boolean selected = FALSE;
/* Get CHI_selected instance of CallHeaderClass */
HackGetInstance(root, 6, 0x45, &selected, sizeof(selected));
if(!selected)
return;
}
/*
* Process children of composite objects
*/
if(IsInClass(genObj, GenViewClass))
{
obj = @call root::MSG_GEN_VIEW_GET_CONTENT();
/* Devlivery Reports screen contains a view with itself as content! */
if(obj != root)
collectChildren(obj, oref, rect.R_left, rect.R_top);
}
else if(IsInClass(root, VisCompClass))
{
n = @call root::MSG_VIS_COUNT_CHILDREN();
for(i=0; i<n; i++)
{
obj = @call root::MSG_VIS_FIND_CHILD_AT_POSITION(i);
/* Skip unopened sub-dialogs */
if(IsInClass(obj, GenInteractionClass))
{
giv = @call obj::MSG_GEN_INTERACTION_GET_VISIBILITY();
if(giv==GIV_POPUP || giv==GIV_DIALOG)
continue;
}
collectChildren(obj, oref, xOfs, yOfs);
}
}
}
Boolean getObjectsInContent(optr obj, ObjectRefs *oref)
{
Boolean ret = FALSE;
optr first,parent;
if(IsInClass(obj, VisTextClass))
{
if(@call obj::MSG_VIS_TEXT_GET_STATE() & VTS_EDITABLE)
oref->textObj = obj;
else
oref->focusLabel = obj;
parent = @call obj::MSG_VIS_FIND_PARENT();
if(IsInClass(parent, VisCompClass) &&
!(GEO_ATTRS(@call parent::MSG_VIS_COMP_GET_GEO_ATTRS()) &
VCGA_ORIENT_CHILDREN_VERTICALLY))
{
first = @call parent::MSG_VIS_FIND_CHILD_AT_POSITION(0);
if(first!=obj && IsInClass(first, VisTextClass))
{
if(oref->textObj)
oref->focusLabel = first;
else
oref->focusParent = first;
}
}
ret = TRUE;
}
return ret;
}
void getObjects(optr obj, optr *focusTree, optr nFocus, ObjectRefs *oref)
{
optr genObj,genInt;
int level, focuslevel;
GenInteractionVisibility giv;
/* See if we can identify the focus by some special shortcuts for
VisContent structures like the Calendar application. */
getObjectsInContent(obj, oref);
if(oref->focusLabel)
focuslevel = 0;
else
focuslevel = -1;
level = 0;
genInt = 0;
do {
if(focuslevel==-1 && IsInClass(obj, GenBooleanClass))
{
optr parent = @call obj::MSG_GEN_FIND_PARENT();
if(IsInClass(parent, GenBooleanGroupClass))
{
word id = @call obj::MSG_GEN_BOOLEAN_GET_IDENTIFIER();
if(@call parent::MSG_GEN_BOOLEAN_GROUP_GET_SELECTED_BOOLEANS() & id)
oref->focusLabel = PSEUDO_OBJ_ON;
else
oref->focusLabel = PSEUDO_OBJ_OFF;
oref->focusParent = obj;
focuslevel = level;
oref->flags |= ORF_CHOICE_FOCUS;
}
}
genObj = GenEquiv(obj);
if(IsInClass(genObj, GenClass))
{
if(!genInt && genObj==obj)
{
if(IsInClass(genObj, GenInteractionClass))
{
giv = @call genObj::MSG_GEN_INTERACTION_GET_VISIBILITY();
if(giv==GIV_POPUP || giv==GIV_DIALOG)
{
genInt = genObj;
break;
}
}
else if(IsInClass(genObj, GenDisplayClass))
{
genInt = genObj;
break;
}
}
/* Vardata check guards against rare cases where a dialog box title
is mistaken for the label of the focussed field. */
if(@call genObj::MSG_GEN_GET_VIS_MONIKER()
&& oref->textObj != genObj
&& !(IsInClass(genObj, ComplexMonikerClass)
&& (HasVardata(genObj, HINT_COMPLEX_MONIKER_DRAW_SEPARATOR)
|| HasVardata(genObj, ATTR_COMPLEX_MONIKER_SEPARATOR_START_POINT))))
{
if(focuslevel==-1)
{
oref->focusLabel = genObj;
focuslevel = level;
}
else if(!oref->focusParent && (level==focuslevel+1 || level==focuslevel+2))
oref->focusParent = genObj;
}
}
if(IsInClass(obj, VisClass))
{
obj = @call obj::MSG_VIS_FIND_PARENT();
}
else if(nFocus)
{
obj = focusTree[--nFocus];
}
else
{
obj = NullOptr;
}
level++;
} while(obj);
/* If we have a text object and a label, make room for focus
in a selection list, if any */
if(oref->textObj && !oref->focusParent)
{
oref->focusParent = oref->focusLabel;
oref->focusLabel = NullOptr;
}
if(genInt)
{
collectChildren(genInt, oref, 0, 0);
/*
* HACK:
*
* Special focus redirections for certain dialogs
*/
if(IsHackObject(genInt, "fclock ", 16, 0x1e))
{
// Read alarm time in clock
oref->focusLabel = VisTreePath(genInt, "11121221");
oref->focusParent = VisTreePath(genInt, "1112121");
}
else if(IsHackObject(genInt, "fclock ", 11, 0x1e))
{
// Speek time of day in Clock's main view
oref->treeObj = VisTreePath(genInt, "111222");
oref->focusLabel = PSEUDO_OBJ_TIME;
}
else if(IsHackObject(genInt, "fclock ", 13, 0x1e))
{
// Speek info in World Time window
oref->treeObj = VisTreePath(genInt, "111");
oref->focusLabel = oref->dialogLabel = NullOptr;
}
else if(IsHackObject(oref->buttonLabels[0], "geoplann", 30, 0x2e))
{
/* We have to detect this state through the button label because
the genInt and dialogLabel is always the same in the planner */
// Find objects in month view of calendar
oref->dialogLabel = VisTreePath(genInt, "1211C1"); /* YearClass */
oref->focusLabel = VisTreePath(genInt, "12211"); /* Current day */
oref->treeObj = VisTreePath(oref->focusLabel, "C"); /* Day's appointments */
/* Make sure appointments are re-read when day changes */
oref->flags |= ORF_TREE_TO_FOCUS;
}
else if(IsHackObject(oref->focusParent, "geoplann", 36, 0x3e) ||
IsHackObject(oref->focusParent, "geoplann", 36, 0x72))
{
// Insert "whole days" or "(date)" in Details view of Calendar
oref->focusLabel = VisTreePath(oref->focusParent, "2");
}
else if(IsHackObject(oref->textObj, "geoplann", 36, 0x9e))
{
// Insert "minutes before event" in "Alarm" submenu of event details
oref->focusLabel = VisTreePath(oref->textObj, ".2");
}
else if(IsHackObject(genInt, "about ", 5, 0x1e))
{
// Read version/build number in "About" screen
oref->focusLabel = VisTreePath(genInt, "1122C18");
}
else if(IsInHackClass(genInt, "text ", 53))
{
// Read character in Chr dialog
oref->focusLabel = VisTreePath(genInt, "12C");
}
else if(IsHackObject(genInt, "phone ", 21, 0x0040))
{
// Do not mistake one of the call glyphs for a dialog label
oref->dialogLabel = NullOptr;
}
else if(IsInHackClass(oref->focusParent, "contlog ", 1))
{
// Do not speak heading of contact log table (LogGenDynamicListClass)
oref->focusParent = NullOptr;
}
else if(IsHackObject(genInt, "sys ", 8, 0x3a))
{
// Screen blanker period (numeric display)
oref->focusLabel = VisTreePath(genInt, "11*11");
}
else if(IsHackObject(genInt, "sys ", 8, 0x78))
{
// Backlight period (numeric display)
oref->focusLabel = VisTreePath(genInt, "11*1");
}
else if(IsHackObject(genInt, "notebk ", 5, 0x70))
{
// File info in Notes
oref->focusLabel = NullOptr;
oref->treeObj = VisTreePath(genInt, "11");
}
else if(IsInHackClass(genInt, "foam ", 0x7b))
{
// Second line in progress dialog
oref->focusLabel = VisTreePath(genInt, "13");
}
else if(IsInHackClass(genInt, "nwapb ", 26))
{
// Entire page in WAP browser as tree root
oref->treeObj = VisTreePath(genInt, "113C");
}
else if(IsInHackClass(oref->textObj, "convrt ", 4))
{
// Focus is on ConverterFieldTextClass in Converter?
// Find left border object and test if it is the right class,
// i.e. ConverterFormListBorderClass.
obj = VisTreePath(genInt, "1111");
if(obj && IsInHackClass(obj, "convrt ", 1))
{
Boolean thickBoxFlag;
// Get CFLBI_thickBoxFlag
HackGetInstance(obj, 6, 0x0015, &thickBoxFlag, sizeof(Boolean));
// If left box is not focused, select right list and text object
if(!thickBoxFlag)
{
word id;
oref->focusLabel = VisTreePath(genInt, "11221");
obj = VisTreePath(genInt, "11121C1");
oref->textObj = NullOptr;
oref->focusParent = NullOptr;
if(obj)
{
// Get selected list item
id = @call obj::MSG_GEN_ITEM_GROUP_GET_FOCUS_ITEM();
if(id != GIGS_NONE)
oref->focusParent = @call obj::MSG_GEN_ITEM_GROUP_GET_ITEM_OPTR(id);
}
}
}
}
}
if(oref->dialogLabel==oref->focusLabel)
oref->focusLabel = NullOptr;
if(oref->dialogLabel==oref->focusParent)
oref->focusParent = NullOptr;
if(oref->dialogLabel==oref->textObj)
oref->dialogLabel = NullOptr;
/*
* Identify focus type
*/
if(oref->focusLabel && !IS_PSEUDO_OBJ(oref->focusLabel))
{
if(HasVardata(oref->focusLabel, HINT_IS_POPUP_LIST))
oref->flags |= ORF_CHOICE_FOCUS;
else if(IsInClass(oref->focusLabel, GenItemClass))
{
optr parent = @call oref->focusLabel::MSG_VIS_FIND_PARENT();
if(IsInClass(parent, GenItemGroupClass))
{
Boolean exclusive;
/* Get OLIGI_exclusiveBehavior of OLItemGroupInstance */
HackGetInstance(parent, 4, 0x41, &exclusive, sizeof(Boolean));
if(exclusive)
{
oref->flags |= ORF_MENU_EXCL;
}
else
{
/* Listbox is in multiselection mode - find out state of item */
word id = @call oref->focusLabel::MSG_GEN_ITEM_GET_IDENTIFIER();
if(@call parent::MSG_GEN_ITEM_GROUP_IS_ITEM_SELECTED(id))
oref->flags |= ORF_MENU_SELECTED;
}
}
oref->flags |= ORF_MENU_FOCUS;
}
}
/*
* Identify single- vs. multiple line text fields
*/
if(oref->textObj && IsInClass(oref->textObj, VisTextClass) &&
(@call oref->textObj::MSG_VIS_TEXT_GET_STATE() & VTS_ONE_LINE))
{
oref->flags |= ORF_TEXT_IS_ONE_LINE;
}
/*
* HACK
*
* Voice recorder: do not speak key changes, to avoid
* disrupting recording and playback.
*/
if(IsHackObject(genInt, "vrecd ", 5, 0x46))
oref->flags |= ORF_DONT_SPEAK_KEYS;
}
#pragma codeseg OBJID3_TEXT
void rtrim(char *buf)
{
word len;
/* Truncate trailing control characters (typically CRs) */
len = strlen(buf);
while(len && ((byte)buf[len-1])<=' ' && buf[len-1]!='\x01')
len--;
buf[len] = 0;
}
void cleanup(char *buf, int bufsize)
{
int i,j;
/* Remove control characters. Replace all except for soft hyphens
by spaces, since it doesn't matter for speaking anyway. */
for(i=j=0; buf[i] && i<bufsize-1; i++)
{
if((byte)buf[i] >= ' ' || buf[i]=='\x01')
buf[j++] = buf[i];
else if(buf[i]==C_GRAPHIC)
{
/* Replace graphic by placeholder - we have to do this without
overflowing or overwriting the buffer that we are working in. */
const char ins[] = PL("Image");
const int inslen = sizeof(ins)-1;
int d = inslen - (i-j) - 1;
if(d>0)
{
memmove(buf+i+d, buf+i, bufsize-i-d);
i += d;
}
memcpy(buf+j, ins, inslen);
j += inslen;
}
else if(buf[i]!=C_OPTHYPHEN)
buf[j++] = ' ';
}
buf[j] = 0;
}
char getBackspChar(optr obj)
{
Boolean editable;
VisTextRange cpos;
TextReference tr;
char backspChar[2] = {0,0};
editable = @call obj::MSG_VIS_TEXT_GET_STATE() & VTS_EDITABLE;
@call obj::MSG_VIS_TEXT_GET_SELECTION_RANGE(&cpos);
/* Get character affected by Backspace */
if(editable && cpos.VTR_start>0)
{
/* Get character into the passed buffer */
tr.TR_type = TRT_POINTER;
tr.TR_ref.TRU_pointer.TRP_pointer = backspChar;
@call obj::MSG_VIS_TEXT_GET_TEXT_RANGE(0, tr,
cpos.VTR_start, cpos.VTR_start-1);
}
return backspChar[0];
}
dword getTextPart(optr obj, dword pos, word getWhat, char *labelText,
word bufsize, word *cursorPos, word *cursorPos2)
#define GET_WHAT_LETTER 0
#define GET_WHAT_WORD 1
#define GET_WHAT_LINE 2
#define GET_WHAT_ALL 3
#define GET_WHAT_SELECTION 4
#define GET_WHAT_SELECTION_OR_ALL 5
#define GET_WHAT_NEXT_LINE 6
#define GET_WHAT_PREV_LINE 7
{
VisTextGetLineInfoReturnValues retValue;
VisTextGetLineInfoParameters vtglip;
VisTextGetLineOffsetAndFlagsParameters vtgloafp;
LineInfo li;
TextReference tr;
dword size;
dword start,end;
VisTextRange cpos;
int i,j;
byte c;
Boolean clipped = FALSE;
Boolean acquired = FALSE;
Boolean editable;
editable = @call obj::MSG_VIS_TEXT_GET_STATE() & VTS_EDITABLE;
@call obj::MSG_VIS_TEXT_GET_SELECTION_RANGE(&cpos);
size = @call obj::MSG_VIS_TEXT_GET_TEXT_SIZE();
*labelText = 0;
if(cursorPos) // default: no cursor position
{
*cursorPos = *cursorPos2 = CURSOR_POS_NONE;
if(!editable)
cursorPos = NULL; // do not return cursor if non-editable
}
if(pos==(dword)-1 || pos==TEXT_ADDRESS_PAST_END)
{
pos = editable? cpos.VTR_start : 0;
acquired = TRUE;
}
/* Get start of cursor line */
switch(getWhat)
{
case GET_WHAT_LETTER:
start = pos;
end = start+1;
break;
case GET_WHAT_WORD:
case GET_WHAT_LINE:
case GET_WHAT_PREV_LINE:
case GET_WHAT_NEXT_LINE:
vtgloafp.VTGLOAFP_line = @call obj::MSG_VIS_TEXT_GET_LINE_FROM_OFFSET(pos);
/* Go to next/previous line (if exists) from current one */
if(!acquired)
{