Debian Codegraph @

terps/tads/tads3/vmbiftix.cpp

raw symbols SCIP
1 #ifdef RCSID
2 static char RCSid[] =
3 "$Header$";
4 #endif
5
6 /* Copyright (c) 2005 by Michael J. Roberts. All Rights Reserved. */
7 /*
8 Name
9 vmbiftix.cpp - TADS Input/Output Extensions function set
10 Function
11
12 Notes
13
14 Modified
15 03/02/05 MJRoberts - Creation
16 */
17
18 #include <stdio.h>
19 #include <string.h>
20 #include <time.h>
21
22 #include "t3std.h"
23 #include "os.h"
24 #include "osifcext.h"
25 #include "utf8.h"
26 #include "charmap.h"
27 #include "vmbiftix.h"
28 #include "vmstack.h"
29 #include "vmerr.h"
30 #include "vmerrnum.h"
31 #include "vmglob.h"
32 #include "vmpool.h"
33 #include "vmobj.h"
34 #include "vmstr.h"
35 #include "vmlst.h"
36 #include "vmrun.h"
37 #include "vmhost.h"
38 #include "vmconsol.h"
39 #include "vmvec.h"
40
41
42 /* ------------------------------------------------------------------------ */
43 /*
44 * Show a popup menu
45 */
46 void CVmBifTIOExt::show_popup_menu(VMG_ uint argc)
47 {
48 int x, y, default_pos;
49 char *txt;
50 os_event_info_t evt;
51 int ret;
52 int elecnt;
53 vm_obj_id_t lst_obj;
54 CVmObjList *lst;
55 vm_val_t val;
56
57 /* check arguments */
58 check_argc(vmg_ argc, 3);
59
60 /* get the x,y coordinates */
61 if (G_stk->get(0)->typ == VM_NIL)
62 {
63 /* nil x,y - use default position */
64 default_pos = TRUE;
65 x = y = 0;
66
67 /* discard the nil x,y values */
68 G_stk->discard(2);
69 }
70 else
71 {
72 /* pop the x,y positions */
73 x = pop_int_val(vmg0_);
74 y = pop_int_val(vmg0_);
75 }
76
77 /* get the HTML text for the contents of the window */
78 txt = pop_str_val_ui(vmg_ 0, 0);
79
80 /* flush the console display output */
81 G_console->flush_all(vmg_ VM_NL_NONE);
82
83 /* show the window */
84 ret = os_show_popup_menu(default_pos, x, y, txt, strlen(txt), &evt);
85
86 /* free the HTML text buffer we allocated */
87 t3free(txt);
88
89 /* see what we have */
90 switch (ret)
91 {
92 case OSPOP_FAIL:
93 case OSPOP_CANCEL:
94 case OSPOP_EOF:
95 default:
96 elecnt = 1;
97 break;
98
99 case OSPOP_HREF:
100 elecnt = 2;
101 break;
102 }
103
104 /* allocate the return list */
105 lst_obj = CVmObjList::create(vmg_ FALSE, elecnt);
106 lst = (CVmObjList *)vm_objp(vmg_ lst_obj);
107 lst->cons_clear();
108
109 /* protect the list from garbage collection */
110 val.set_obj(lst_obj);
111 G_stk->push(&val);
112
113 /* set the first element to the main return code */
114 val.set_int(ret);
115 lst->cons_set_element(0, &val);
116
117 /* set additional elements according to the return code */
118 switch (ret)
119 {
120 case OSPOP_HREF:
121 /* add the HREF element */
122 val.set_obj(str_from_ui_str(vmg_ evt.href));
123 lst->cons_set_element(1, &val);
124 break;
125
126 default:
127 /* there aren't any other elements for other return codes */
128 break;
129 }
130
131 /* return the list */
132 retval_obj(vmg_ lst_obj);
133
134 /* discard the GC protection */
135 G_stk->discard();
136 }
137
138 /* ------------------------------------------------------------------------ */
139 /*
140 * Enable one system menu command
141 */
142 static void enable_sys_menu_cmd_item(VMG_ const vm_val_t *idval, int stat)
143 {
144 int id;
145
146 /* retrieve the ID as an integer */
147 G_stk->push(idval);
148 id = CVmBif::pop_int_val(vmg0_);
149
150 /* set it */
151 os_enable_cmd_event(id, stat);
152 }
153
154 /*
155 * Enable/disable system menu commands
156 */
157 void CVmBifTIOExt::enable_sys_menu_cmd(VMG_ uint argc)
158 {
159 vm_val_t *valp;
160 int stat;
161 int cnt;
162
163 /* check arguments */
164 check_argc(vmg_ argc, 2);
165
166 /* the second argument is the new status - retrieve it as an integer */
167 G_stk->push(G_stk->get(1));
168 stat = pop_int_val(vmg0_);
169
170 /*
171 * The first argument is either a single menu ID, or a list of menu
172 * IDs. Check what we have.
173 */
174 valp = G_stk->get(0);
175 if (valp->is_listlike(vmg0_) && (cnt = valp->ll_length(vmg0_)) >= 0)
176 {
177 /* set the status for each element */
178 for (int i = 1 ; i <= cnt ; ++i)
179 {
180 /* get this element value */
181 vm_val_t ele;
182 valp->ll_index(vmg_ &ele, i);
183
184 /* set the status */
185 enable_sys_menu_cmd_item(vmg_ &ele, stat);
186 }
187 }
188 else if (valp->typ == VM_INT)
189 {
190 /* it's a single value - handle it individually */
191 enable_sys_menu_cmd_item(vmg_ valp, stat);
192 }
193
194 /* discard the arguments, and we're done */
195 G_stk->discard(2);
196 }
197