-
Notifications
You must be signed in to change notification settings - Fork 3
/
AEI.c
1623 lines (1428 loc) · 41.6 KB
/
AEI.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
/* @(#)highwire/AEI.c
*/
#include <stdlib.h>
#include <string.h>
#ifdef __PUREC__
#include <tos.h>
#else /* LATTICE || __GNUC__ */
#include <osbind.h>
#endif
#include <gem.h>
#include "token.h" /* rpopbkm_open */
#ifdef __PUREC__
# define CONTAINR struct s_containr *
# define HISTORY struct s_history *
#endif
#include "global.h"
#include "version.h"
#include "vaproto.h"
/* #include "av_comm.h" */
#include "bookmark.h"
#include "Location.h"
#include "Containr.h"
#include "hwWind.h"
#include "Loader.h"
#include "cache.h"
#include "Logging.h"
#include "dragdrop.h"
#include "olga.h"
#ifdef GEM_MENU
# include "highwire.h"
extern OBJECT * menutree;
#endif
/*==============================================================================
* Checks if appl_getinfo() exists, and, if possible, calls it.
* WINX has appl_getinfo() since 2.2, appl_find("?AGI ") since 2.3c beta.
*/
#if (__GEMLIB_MINOR__<42)||((__GEMLIB_MINOR__==42)&&(__GEMLIB_REVISION__<2))
WORD appl_xgetinfo(WORD type, WORD *out1, WORD *out2, WORD *out3, WORD *out4)
{
static WORD has_agi = -1;
WORD u;
if (has_agi < 0)
has_agi = gl_ap_version >= 0x400 || appl_find("?AGI ") == 0
|| wind_get(0, WF_WINX, &u, &u, &u, &u) == WF_WINX;
/* || MagiC_version >= 0x0200? */
if (has_agi)
return appl_getinfo(type, out1, out2, out3, out4);
else
return FALSE;
}
#endif
/*==============================================================================
* Detects the system type, AES + kernel.
* This function shouldn't be called directly, use the sys_type() instead!
*/
UWORD _systype_v;
UWORD
_systype (void)
{
long * ptr = (long *)Setexc(0x5A0/4, (void (*)())-1);
_systype_v = SYS_TOS;
if (!ptr) {
return _systype_v; /* stone old TOS without any cookie support */
}
while (*ptr) {
if (*ptr == 0x4D674D63L/*MgMc*/ || *ptr == 0x4D616758L/*MagX*/) {
_systype_v = (_systype_v & ~0xF) | SYS_MAGIC;
} else if (*ptr == 0x4D694E54L/*MiNT*/) {
_systype_v = (_systype_v & ~0xF) | SYS_MINT;
} else if (*ptr == 0x476E7661L/*Gnva*/) {
_systype_v |= SYS_GENEVA;
} else if (*ptr == 0x6E414553L/*nAES*/) {
_systype_v |= SYS_NAES;
}
ptr += 2;
}
if (_systype_v & SYS_MINT) { /* check for XaAES */
WORD out = 0, u;
if (wind_get (0, (((WORD)'X') <<8)|'A', &out, &u,&u,&u) && out) {
_systype_v |= SYS_XAAES;
}
}
return _systype_v;
}
/*============================================================================*/
char *
file_selector (const char * label, const char * patt,
const char * file, char * buff, size_t blen)
{
char fsel_file[256] = "";
WORD r, butt;
char * slash = strrchr (fsel_path, '\\');
if (!slash) {
strcpy (fsel_path, "C:\\");
slash = fsel_path +2;
}
strcpy (slash +1, (patt ? patt : "*.*"));
if (file && *file) {
size_t f_len = strlen (file);
if (f_len >= sizeof(fsel_file)) {
f_len = sizeof(fsel_file) -1;
}
((char*)memcpy (fsel_file, file, f_len))[f_len] = '\0';
}
if ((gl_ap_version >= 0x140 && gl_ap_version < 0x200)
|| gl_ap_version >= 0x300 /* || getcookie(FSEL) */) {
r = fsel_exinput (fsel_path, fsel_file, &butt, label);
} else {
r = fsel_input (fsel_path, fsel_file, &butt);
}
if (!r || butt == FSEL_CANCEL) {
if (buff) {
*buff = '\0';
buff = NULL;
}
} else {
size_t f_len = strlen (fsel_file);
size_t p_len = strlen (fsel_path);
while (p_len && fsel_path[p_len-1] != '\\') p_len--;
if (f_len && p_len) {
if (!buff) {
buff = malloc (f_len + p_len +1);
} else if (blen < f_len + p_len +1) {
buff = NULL;
}
if (buff) {
memcpy (buff, fsel_path, p_len);
memcpy (buff + p_len, fsel_file, f_len +1);
}
}
}
return buff;
}
/*----------------------------------------------------------------------------*/
static BOOL
page_load(void)
{
char fsel_file[HW_PATH_MAX] = "";
const char * label = "HighWire: Open HTML or text";
const char * patt = (sys_XAAES() ? "*.[HJPT]*" : NULL);
if (!file_selector (label, patt, NULL, fsel_file,sizeof(fsel_file))) {
return FALSE;
} else {
start_cont_load (hwWind_Top->Pane, fsel_file, NULL, TRUE, TRUE);
}
return TRUE;
}
/*------------------------------------------------------------------------------
* rewrote by Rainer May 2002
*/
static void
vastart (const WORD msg[8], PXY mouse, UWORD state)
{
short answ[8];
char filename[HW_PATH_MAX];
const char *cmd = *(const char *const *)&msg[3];
/* if a parameter contains spaces then
* it is enclosed with '...', and a ' is encoded as '' */
const BOOL quoted = (cmd[0] == '\'' && cmd[1] != '\0'
&& strrchr(&cmd[2], '\'') != NULL
&& strrchr(&cmd[2], '\'')[1] == '\0');
HwWIND wind = (state && K_ALT
? NULL : hwWind_byCoord (mouse.p_x, mouse.p_y));
if (quoted) {
char *p = filename;
cmd++;
while (cmd[0] != '\0') {
if (cmd[0] == '\'' && cmd[1] == '\'')
cmd++;
p++[0] = cmd++[0];
}
p[-1] = '\0'; /* overwrite closing ' */
cmd = filename;
}
if (wind) {
start_page_load (wind->Pane, cmd, NULL, TRUE, NULL);
} else {
new_hwWind ("", cmd, TRUE);
}
answ[0] = (msg[0] == VA_START)? AV_STARTED : VA_WINDOPEN;
answ[1] = gl_apid;
answ[2] = 0;
answ[3] = msg[3];
answ[4] = msg[4];
answ[5] = 0;
answ[6] = 0;
answ[7] = 0;
appl_write(msg[1], 16, answ);
}
/*----------------------------------------------------------------------------*/
/* GEMScript support added
* Matthias Jaap December 21, 2001
*/
#define GS_REQUEST 0x1350
#define GS_REPLY 0x1351
#define GS_COMMAND 0x1352
#define GS_ACK 0x1353
#define GS_QUIT 0x1354
#define GS_OPENMACRO 0x1355
#define GS_MACRO 0x1356
#define GS_WRITE 0x1357
#define GS_CLOSEMACRO 0x1358
#define GSM_COMMAND 0x0001
#define GSM_MACRO 0x0002
#define GSM_WRITE 0x0004
#define GSM_HEXCODING 0x0008
#define GSACK_OK 0
#define GSACK_UNKNOWN 1
#define GSACK_ERROR 2
typedef struct
{
long len;
WORD version;
WORD msgs;
long ext;
} GS_INFO;
WORD gsapp = -1;
/* All GLOBAL memory is merged to one block and allocated in main().
* All pointers to GLOBAL memory are initialized before any AES call. */
char *gslongname; /* 32 byte */
GS_INFO *gsi; /* 16 byte */
char *gsanswer; /* HW_PATH_MAX byte */
static const char *
nextToken(const char *pcmd)
{
if (!pcmd)
return (NULL);
pcmd += (strlen(pcmd) + 1);
while (TRUE)
switch (*pcmd)
{
case 0:
return (NULL);
case 1: /* empty parameter */
case 2: /* hexadecimal coded parameter */
case 3: /* reserved, to ignore */
case 4:
case 5:
case 6:
pcmd += (strlen(pcmd) + 1);
break;
default:
return (pcmd);
}
}
/* Returns TRUE if HighWire shall exit. */
static BOOL
doGSCommand(const WORD msg[8])
{
const char *const * p_msg = (const char *const *)&msg[3];
const char *cmd = *p_msg;
WORD answ[8];
BOOL quit = FALSE;
answ[0] = GS_ACK;
answ[1] = gl_apid;
answ[2] = 0;
answ[3] = msg[3];
answ[4] = msg[4];
answ[5] = 0;
answ[6] = 0;
answ[7] = GSACK_UNKNOWN;
if (cmd)
{
char **pp;
if (!stricmp(cmd, "AppGetLongName"))
{
pp = (char **)&answ[5];
*pp = strcpy (gslongname, _HIGHWIRE_FULLNAME_);
answ[7] = GSACK_OK;
}
else if (!stricmp(cmd, "CheckCommand"))
{
cmd = nextToken(cmd);
if (!stricmp(cmd, "AppGetLongName") || !stricmp(cmd, "CheckCommand")
|| !stricmp(cmd, "Close") || !stricmp(cmd, "GetAllCommands")
|| !stricmp(cmd, "Open") || !stricmp(cmd, "Quit")) {
pp = (char **)&answ[5];
*pp = memcpy(gsanswer, "1\0", 3);
}
/* else answ[5..6] is initialized with NULL */
answ[7] = GSACK_OK;
}
else if (!stricmp(cmd, "GetAllCommands"))
{
#define _ALL_1 "AppGetLongName\0CheckCommand\0Close\0"
#define _ALL_2 "GetAllCommands\0Open <file>\0Quit\0"
#define ALL _ALL_1 _ALL_2
#ifdef __PUREC__
#if sizeof(ALL) + 1 > HW_PATH_MAX
#error gsanswer[HW_PATH_MAX] too small for GetAllCommands!
#endif
#endif
pp = (char **)&answ[5];
*pp = memcpy(gsanswer, ALL, sizeof(ALL));
answ[7] = GSACK_OK;
}
else if (!stricmp(cmd, "Quit"))
{
quit = TRUE;
answ[7] = GSACK_OK;
}
else if (!stricmp(cmd, "Open"))
{
cmd = nextToken(cmd);
new_hwWind ("", cmd, TRUE);
answ[7] = GSACK_OK;
}
else if (!stricmp(cmd, "AppGetLongName"))
{
strcpy(gslongname, _HIGHWIRE_FULLNAME_);
pp = (char **)&answ[5];
*pp = gslongname;
answ[7] = GSACK_OK;
}
}
appl_write(msg[1], 16, answ);
return quit;
}
/*----------------------------------------------------------------------------*/
static void
menu_about (void)
{
form_alert (1, "[1]"
"[" _HIGHWIRE_FULLNAME_ " HTML Browser"
"|GEM Menu v. 0.4"
"|Core v. " _HIGHWIRE_VERSION_ " " _HIGHWIRE_BETATAG_
"|http://highwire.atari-users.net/]"
"[ OK ]");
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static BOOL
menu_open_handler (OBJECT * form, WORD obj)
{
if (obj == URL_OK) {
char * ptext = form[URL_EDIT].ob_spec.tedinfo->te_ptext;
if (ptext[0]) {
start_page_load (hwWind_Top->Pane, ptext, NULL, TRUE, NULL);
}
} else if (obj == URL_FILE) {
page_load();
}
return TRUE; /* to be deleted */
}
/*============================================================================*/
void
menu_open (BOOL fsel)
{
#ifndef GEM_MENU
(void)fsel;
{
#else
if (!fsel) {
static OBJECT * form = NULL;
/* short x, y, w, h, n;*/
char * ptext;
if (!form) {
TEDINFO * tedinfo;
WORD dmy;
rsrc_gaddr (R_TREE, URLINPUT, &form);
if ((ptext = malloc (MAX_LEN *3)) == NULL) {
form = NULL;
return;
}
tedinfo = form[URL_EDIT].ob_spec.tedinfo;
tedinfo->te_ptext = ptext;
tedinfo->te_ptext[0] = '\0';
tedinfo->te_ptmplt = memset (ptext + MAX_LEN *1, '_', MAX_LEN-1);
tedinfo->te_ptmplt[MAX_LEN-1] = '\0';
tedinfo->te_pvalid = memset (ptext + MAX_LEN *2, 'X', MAX_LEN-1);
tedinfo->te_pvalid[MAX_LEN-1] = '\0';
tedinfo->te_txtlen = MAX_LEN;
form[URL_EDIT].ob_width = form[URL_ED_BG].ob_width
= (MAX_LEN -1) * 8;
form->ob_spec.obspec.framesize = 0;
form_center (form, &dmy,&dmy,&dmy,&dmy);
} else if (!(form->ob_flags & OF_FLAG15)) {
ptext = form[URL_EDIT].ob_spec.tedinfo->te_ptext;
form[URL_OK ].ob_state &= ~OS_SELECTED;
form[URL_CANCEL].ob_state &= ~OS_SELECTED;
form[URL_FILE ].ob_state &= ~OS_SELECTED;
} else {
return; /* already open */
}
ptext[0] = '\0';
formwind_do (form, URL_EDIT, "Open Page", TRUE, menu_open_handler);
} else {
#endif
page_load();
}
}
/*============================================================================*/
void
menu_info (void)
{
FRAME frame = hwWind_ActiveFrame (NULL);
CONTAINR cont = (frame ? frame->Container : hwWind_Top->Pane);
LOCATION loc = (frame ? frame->Location : NULL);
const char * file_ptr = (!loc ? "(empty)" : *loc->File ? loc->File : ".");
int file_ln = (int)strlen (file_ptr);
const char * file_pp = "";
const char * dir_ptr = (loc ? location_Path (loc, NULL) : fsel_path);
int dir_ln = (int)strlen (dir_ptr);
const char * dir_pp = "";
char * enc_ptr;
int enc_ln;
char * frm_ptr = (cont->Name ? cont->Name : "");
int frm_ln = (int)strlen (frm_ptr);
char * frm_pp = "";
char text[1000];
if (file_ln > 32) {
file_ln = 31;
file_pp = "\257";
}
if (dir_ln > 40) {
dir_ln = 39;
dir_pp = "\257";
}
switch (frame ? frame->Encoding : ENCODING_WINDOWS1252) {
case ENCODING_WINDOWS1252: enc_ptr = "Windows-1252"; break;
case ENCODING_ISO8859_2: enc_ptr = "ISO8859-2"; break;
case ENCODING_ISO8859_15: enc_ptr = "ISO8859-15"; break;
case ENCODING_UTF8: enc_ptr = "Unicode-UTF8"; break;
case ENCODING_UTF16: enc_ptr = "Unicode-UTF16"; break;
case ENCODING_MACINTOSH: enc_ptr = "MacintoshRoman"; break;
case ENCODING_ATARIST: enc_ptr = "AtariFont"; break;
default: enc_ptr = "<invalid>";
}
if (frm_ln > 37 - (enc_ln = (int)strlen (enc_ptr))) {
frm_ln = 37 - enc_ln;
frm_pp = "\257";
} else {
enc_ln = 37 - frm_ln;
}
sprintf (text, "[0][File '%.*s%s':|%.*s%s|'%.*s%s' %*s|][Ok|about:|About..]",
file_ln, file_ptr, file_pp,
dir_ln, dir_ptr, dir_pp,
frm_ln, frm_ptr, frm_pp,
enc_ln, enc_ptr);
switch (form_alert (1, text)) {
case 2:
new_hwWind ("About", "about:", TRUE);
break;
case 3:
menu_about();
break;
}
}
/*============================================================================*/
void
menu_quit (void)
{
hwWind_store (HWWS_GEOMETRY);
hwWind_store (HWWS_BOOKMGEO);
exit (EXIT_SUCCESS);
}
/*============================================================================*/
void
menu_fontsize (char plus_minus)
{
FRAME frame;
if (plus_minus == '+') {
if (font_size < 18) {
font_size++;
} else {
font_size += 3;
}
logprintf(LOG_BLACK, "+font_size %d\n", (int)font_size);
frame = hwWind_ActiveFrame (NULL);
} else if (font_size > 2) {
if (font_size < 20) {
font_size--;
} else {
font_size -= 3;
}
if (font_minsize > font_size) {
font_minsize = font_size; /* override setting */
}
logprintf(LOG_BLACK, "-font_size %d\n", (int)font_size);
frame = hwWind_ActiveFrame (NULL);
} else {
frame = NULL; /* nothing to do */
}
if (frame) {
start_cont_load (frame->Container, NULL, frame->Location, TRUE, TRUE);
}
}
/*============================================================================*/
void
menu_reload (ENCODING encoding)
{
if (encoding > ENCODING_Unknown) {
/* if an encoding is given (!=ENCODING_Unknown) set bit 7 to instruct
* the parser not to switch it.
*/
FRAME frame = hwWind_ActiveFrame (NULL);
if (frame) {
LOADER ldr = start_cont_load (frame->Container,
NULL, frame->Location, TRUE, TRUE);
if (ldr) {
ldr->Encoding = (encoding | 0x80u);
ldr->MarginW = frame->Page.Margin.Lft;
ldr->MarginH = frame->Page.Margin.Top;
}
}
} else {
hwWind_history (hwWind_Top, hwWind_Top->HistMenu, TRUE);
}
}
/*----------------------------------------------------------------------------*/
/* Bookmark dialog */
/* type : Define what text will displayed */
/* 'BA' add bookmark */
/* 'BE' edit bookmark */
/* 'GA' add group */
/* 'GE' edit group */
static const char *
bookmark_editor (UWORD type, const char * text,
const char * id, const char * url)
{
WORD title;
WORD x, y, w, h, n;
static OBJECT * tree = NULL;
graf_mouse (hwWind_Mshape = ARROW, NULL);
if (!tree) {
rsrc_gaddr (R_TREE, BKMEDIT, &tree);
title = tree[BKM_BG_TEXT].ob_head;
for (n = title; n != BKM_BG_TEXT; n = tree[n].ob_next) {
tree[n].ob_flags |= OF_HIDETREE;
tree[n].ob_y = 0;
}
n = tree[BKM_BG_TEXT].ob_height - tree[title].ob_height;
tree[BKM_BG_TEXT].ob_height -= n;
tree[BKM_BG_EDIT].ob_y -= n;
tree[ROOT].ob_height -= n;
}
switch (type) {
case ((UWORD)'B'<<8)|'A': title = BKM_TXT_B_ADD; break;
case ((UWORD)'B'<<8)|'E': title = BKM_TXT_B_EDIT; break;
case ((UWORD)'G'<<8)|'A': title = BKM_TXT_G_ADD; break;
case ((UWORD)'G'<<8)|'E': title = BKM_TXT_G_EDIT; break;
default: title = 0;
}
if (title) {
tree[title].ob_flags &= ~OF_HIDETREE;
}
tree[BKM_VISITED].ob_flags |= OF_HIDETREE;
if (url && (n = (WORD)strlen (url)) > 0) {
char * t = tree[BKM_URL].ob_spec.tedinfo->te_ptext;
size_t l = tree[BKM_URL].ob_spec.tedinfo->te_txtlen -1;
if (n <= l) {
memcpy (t, url, n);
memset (t + n, ' ', l - n);
t[l] = '\0';
} else {
memcpy (t, url, l -3);
strcpy (t + l -3, "\372\372\257");
}
tree[BKM_URL].ob_flags &= ~OF_HIDETREE;
} else {
tree[BKM_URL].ob_flags |= OF_HIDETREE;
}
if (id && bookmark_id2date (id,tree[BKM_ADDED].ob_spec.tedinfo->te_ptext,
tree[BKM_ADDED].ob_spec.tedinfo->te_txtlen)) {
char * t = tree[BKM_ADDED].ob_spec.tedinfo->te_ptext;
size_t l = tree[BKM_ADDED].ob_spec.tedinfo->te_txtlen -1;
if ((n = (WORD)strlen (t)) < l) {
memset (t + n, ' ', l - n);
t[l] = '\0';
}
tree[BKM_ADDED].ob_flags &= ~OF_HIDETREE;
} else {
tree[BKM_ADDED].ob_flags |= OF_HIDETREE;
}
if (id && (n = (WORD)strlen (id)) > 0) {
char * t = tree[BKM_ID].ob_spec.tedinfo->te_ptext;
size_t l = tree[BKM_ID].ob_spec.tedinfo->te_txtlen -1;
memcpy (t, id, min (l, n));
t += n;
while (n++ < l) *(t++) = ' ';
*t = '\0';
tree[BKM_ID].ob_flags &= ~OF_HIDETREE;
} else {
tree[BKM_ID].ob_flags |= OF_HIDETREE;
}
if (text && *text) {
char * t = tree[BKM_EDIT].ob_spec.tedinfo->te_ptext;
size_t l = tree[BKM_EDIT].ob_spec.tedinfo->te_txtlen -1;
strncpy (t, text, l);
text = t;
} else {
char * t = tree[BKM_EDIT].ob_spec.tedinfo->te_ptext;
*t = '\0';
text = t;
}
tree[BKM_OK].ob_state &= ~OS_SELECTED;
tree[BKM_CANCEL].ob_state &= ~OS_SELECTED;
wind_update (BEG_MCTRL);
form_center (tree, &x, &y, &w, &h);
form_dial (FMD_START, x,y,w,h, x,y,w,h);
objc_draw (tree, ROOT, MAX_DEPTH, x, y, w, h);
if (form_do (tree, BKM_EDIT) != BKM_OK || !*text) {
text = NULL;
}
form_dial (FMD_FINISH, x,y,w,h, x,y,w,h);
wind_update (END_MCTRL);
if (title) {
tree[title].ob_flags |= OF_HIDETREE;
}
return text;
}
/*============================================================================*/
void
menu_bookmark_url (LOCATION loc, const char * title)
{
HwWIND bmrk = NULL;
if (!loc) {
HwWIND wind = hwWind_Top;
if (wind && wind->Base.Ident == WIDENT_BMRK) {
bmrk = wind;
wind = hwWind_Next (bmrk);
}
if (wind) {
loc = wind->Location;
title = wind->Base.Name;
}
}
if (loc) {
char url[2 * HW_PATH_MAX];
location_FullName (loc, url, sizeof(url));
if (!title || !*title) {
title = bookmark_editor (((UWORD)'B'<<8)|'A', url, NULL, url);
}
if (title && add_bookmark (url, title)
&& (bmrk
|| (bmrk = (HwWIND)window_byIdent (WIDENT_BMRK)) != NULL)) {
hwWind_history (bmrk, bmrk->HistMenu, TRUE);
}
}
}
/*============================================================================*/
/* Open bookmark window */
void
menu_openbookmarks (void)
{
HwWIND wind = (HwWIND)window_byIdent (WIDENT_BMRK);
if (wind) hwWind_raise (wind, TRUE);
else new_hwWind ("", bkm_File, TRUE);
}
/*============================================================================*/
#ifdef GEM_MENU
WORD
menu_history (HISTORY hist[], UWORD used, WORD check)
{
static char m_empty[] = " (empty)";
static WORD m_checked = 0;
static WORD m_backgnd = 0;
static UWORD m_max_len;
static UWORD m_char_wd;
UWORD width = 0;
WORD shift = 0;
WORD last;
short i;
if (!m_backgnd) {
GRECT r;
m_backgnd = menutree[M_HIST_END].ob_next;
m_char_wd = menutree[m_backgnd].ob_width
/ ((UWORD)strlen (menutree[M_HIST_BEG].ob_spec.free_string) +2);
wind_get_grect (DESKTOP_HANDLE, WF_WORKXYWH, &r);
objc_offset (menutree, m_backgnd, &r.g_x, &r.g_y);
m_max_len = (r.g_w - r.g_x) / m_char_wd -1;
if (m_max_len > sizeof(((HISTORY)0)->Text) -2) {
m_max_len = sizeof(((HISTORY)0)->Text) -2;
}
for (i = M_HIST_BEG +1; i <= M_HIST_END; i++) {
menu_ienable (menutree, i, TRUE);
}
}
if (m_checked) {
menu_icheck (menutree, m_checked, FALSE);
}
wind_update (BEG_MCTRL);
if (!hist || !used) {
menu_ienable (menutree, M_HIST_BEG, FALSE);
last = M_HIST_BEG;
for (i = M_HIST_BEG; i <= M_HIST_END; i++) {
menu_text (menutree, i, menutree[i].ob_spec.free_string = m_empty);
}
width = sizeof (m_empty) -1;
} else {
menu_ienable (menutree, M_HIST_BEG, TRUE);
last = M_HIST_BEG -1;
for (i = 0; i < used; i++) {
++last;
if (hist[i]->Length > m_max_len) {
hist[i]->Text[m_max_len] = '\257';
hist[i]->Text[m_max_len +1] = '\0';
hist[i]->Length = m_max_len;
width = m_max_len;
} else if (hist[i]->Length > width) {
width = hist[i]->Length;
}
menu_text (menutree, last,
menutree[last].ob_spec.free_string = hist[i]->Text);
menutree[last].ob_flags &= ~OF_HIDETREE;
}
if (check >= 0) {
m_checked = check + M_HIST_BEG;
menu_icheck (menutree, m_checked, TRUE);
}
}
width = (width +2) * m_char_wd;
menutree[m_backgnd].ob_width = width;
menutree[m_backgnd].ob_height = menutree[last].ob_y
+ menutree[last].ob_height;
for (i = M_HIST_BEG; i <= last; i++) {
menutree[i].ob_width = width;
}
while (last < M_HIST_END) {
menutree[++last].ob_flags |= OF_HIDETREE;
}
wind_update (END_MCTRL);
return shift;
}
#endif
/*============================================================================*/
void
menu_cookies (int mode)
{
if (mode < 0) cfg_AllowCookies = !cfg_AllowCookies;
else if (mode) cfg_AllowCookies = TRUE;
else cfg_AllowCookies = FALSE;
if (mode < 0) {
save_config ("COOKIES", (cfg_AllowCookies ? "1" : "0"));
}
#ifdef GEM_MENU
menu_icheck (menutree, M_COOKIES, cfg_AllowCookies);
#endif
}
/*============================================================================*/
void
menu_images (int mode)
{
if (mode < 0) cfg_ViewImages = !cfg_ViewImages;
else if (mode) cfg_ViewImages = TRUE;
else cfg_ViewImages = FALSE;
if (mode < 0) {
save_config ("VIEW_IMAGES", (cfg_ViewImages ? "1" : "0"));
}
#ifdef GEM_MENU
menu_icheck (menutree, M_IMAGES, cfg_ViewImages);
#endif
}
/*============================================================================*/
void
menu_use_css (int mode)
{
if (mode < 0) cfg_UseCSS = !cfg_UseCSS;
else if (mode) cfg_UseCSS = TRUE;
else cfg_UseCSS = FALSE;
if (mode < 0) {
save_config ("USE_CSS", (cfg_UseCSS ? "1" : "0"));
}
#ifdef GEM_MENU
menu_icheck (menutree, M_USE_CSS, cfg_UseCSS);
#endif
}
/*============================================================================*/
void
menu_frm_ctrl (int mode)
{
if (mode < 0) mode = !force_frame_controls;
else if (mode) mode = TRUE;
else mode = FALSE;
force_frame_controls = mode;
#ifdef GEM_MENU
menu_icheck (menutree, M_FRM_CTRL, force_frame_controls);
#endif
}
/*============================================================================*/
void
menu_logging (int mode)
{
if (mode < 0) mode = !logging_is_on;
else if (mode) mode = TRUE;
else mode = FALSE;
logging_is_on = mode;
#ifdef GEM_MENU
menu_icheck (menutree, M_LOGGING, logging_is_on);
#endif
}
/*----------------------------------------------------------------------------*/
#ifdef GEM_MENU
static void
handle_menu (WORD title, WORD item, UWORD state)
{
if (title == M_HISTORY) {
hwWind_history (hwWind_Top, item - M_HIST_BEG, FALSE);
} else switch (item) {
case M_ABOUT: menu_about(); break;
case M_OPEN: menu_open (!(state & (K_RSHIFT|K_LSHIFT))); break;
case M_NEW: new_hwWind ("", cfg_StartPage, TRUE); break;
case M_INFO: menu_info(); break;
case M_QUIT: menu_quit(); break;
case M_RELOAD: menu_reload (ENCODING_Unknown); break;
case M_OPEN_BOOKMARKS: menu_openbookmarks(); break;
case M_BOOKMARK_URL: menu_bookmark_url (NULL, NULL); break;
#if (_HIGHWIRE_ENCMENU_ == 1)
case M_W1252: menu_reload (ENCODING_WINDOWS1252); break;
case M_I8859_2: menu_reload (ENCODING_ISO8859_2); break;
case M_I8859_15: menu_reload (ENCODING_ISO8859_15); break;
case M_UTF8: menu_reload (ENCODING_UTF8); break;
case M_UTF16: menu_reload (ENCODING_UTF16); break;
case M_UTF16LE: menu_reload (ENCODING_UTF16LE); break;
case M_MACINTOSH: menu_reload (ENCODING_MACINTOSH); break;
case M_ATARI_SYS: menu_reload (ENCODING_ATARIST); break;
case M_ATARINVDI: menu_reload (ENCODING_ATARINVDI); break;
#endif
case M_FONT_INC: menu_fontsize ('+'); break;
case M_FONT_DEC: menu_fontsize ('-'); break;
case M_COOKIES: menu_cookies (-1); break;
case M_IMAGES: menu_images (-1); break;
case M_USE_CSS: menu_use_css (-1); break;
case M_FRM_CTRL: menu_frm_ctrl (-1); break;
case M_LOGGING: menu_logging (-1); break;
case M_FONTS: fonts_setup (NULL); break;
}
if (title > 0) {
menu_tnormal (menutree, title, UNHIGHLIGHT);
}
}
#endif
/*============================================================================*/
#if (_HIGHWIRE_ENCMENU_ == 1)
void
update_menu (ENCODING encoding, BOOL raw_text)
{
short item;
for (item = M_W1252; item <= M_ATARINVDI; item++) {
menu_icheck (menutree, item, UNCHECK);
}
switch (encoding & 0x7Fu) {
case ENCODING_WINDOWS1252: item = M_W1252; break;
case ENCODING_ISO8859_2: item = M_I8859_2; break;
case ENCODING_ISO8859_15: item = M_I8859_15; break;
case ENCODING_UTF8: item = M_UTF8; break;
case ENCODING_UTF16: item = M_UTF16; break;
case ENCODING_UTF16LE: item = M_UTF16LE; break;
case ENCODING_MACINTOSH: item = M_MACINTOSH; break;
case ENCODING_ATARIST: item = M_ATARI_SYS; break;
case ENCODING_ATARINVDI: item = M_ATARINVDI; break;
default: item = -1;
}
if (item > 0) {
menu_icheck (menutree, item, CHECK);
}
menu_ienable (menutree, M_UTF16, raw_text);
menu_ienable (menutree, M_UTF16LE, raw_text);
}
#endif
/*----------------------------------------------------------------------------*/
static WORD
rpop_do (OBJECT * rpopup, WORD tree, WORD mx, WORD my)
{
WORD which_obj;
WORD x, y, w, h;
GRECT desk;
form_center (rpopup, &x, &y, &w, &h);
x -= rpopup->ob_x;
x += rpopup->ob_x = mx -2;
y -= rpopup->ob_y;
y += rpopup->ob_y = my -2;
wind_get_grect (DESKTOP_HANDLE, WF_WORKXYWH, &desk);
if ((desk.g_w += desk.g_x - (x + w)) < 0) {
rpopup->ob_x += desk.g_w;
x += desk.g_w;
}
if ((desk.g_x -= x) > 0) {
rpopup->ob_x += desk.g_x;
x += desk.g_x;
}
if ((desk.g_h += desk.g_y - (y + h)) < 0) {
rpopup->ob_y += desk.g_h;
y += desk.g_h;
}
if ((desk.g_y -= y) > 0) {
rpopup->ob_y += desk.g_y;
y += desk.g_y;
}
wind_update (BEG_MCTRL);
form_dial (FMD_START, x, y, w, h, x, y, w, h);
objc_draw (rpopup, ROOT, MAX_DEPTH, x, y, w, h);
which_obj = HW_form_do (rpopup, 0);
if (which_obj > 0) {
objc_change (rpopup, which_obj, 0, 0,0,0,0, OS_NORMAL, 0);
}