Ecmascript: the code adjusted for SEE-2.0
[elinks.git] / src / ecmascript / see / unibar.c
blobc5fa9047fd33adfe5ffd6460d6f7b0ea859d87cf
1 /* The SEE location and history objects implementation. */
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
11 #include "elinks.h"
13 #include <see/see.h>
15 #include "bfu/dialog.h"
16 #include "cache/cache.h"
17 #include "cookies/cookies.h"
18 #include "dialogs/menu.h"
19 #include "dialogs/status.h"
20 #include "document/html/frames.h"
21 #include "document/document.h"
22 #include "document/forms.h"
23 #include "document/view.h"
24 #include "ecmascript/ecmascript.h"
25 #include "ecmascript/see/input.h"
26 #include "ecmascript/see/strings.h"
27 #include "ecmascript/see/unibar.h"
28 #include "ecmascript/see/window.h"
29 #include "intl/gettext/libintl.h"
30 #include "main/select.h"
31 #include "osdep/newwin.h"
32 #include "osdep/sysname.h"
33 #include "protocol/http/http.h"
34 #include "protocol/uri.h"
35 #include "session/history.h"
36 #include "session/location.h"
37 #include "session/session.h"
38 #include "session/task.h"
39 #include "terminal/tab.h"
40 #include "terminal/terminal.h"
41 #include "util/conv.h"
42 #include "util/memory.h"
43 #include "util/string.h"
44 #include "viewer/text/draw.h"
45 #include "viewer/text/form.h"
46 #include "viewer/text/link.h"
47 #include "viewer/text/vs.h"
49 static void unibar_get(struct SEE_interpreter *, struct SEE_object *, struct SEE_string *, struct SEE_value *);
50 static void unibar_put(struct SEE_interpreter *, struct SEE_object *, struct SEE_string *, struct SEE_value *, int);
51 static int unibar_canput(struct SEE_interpreter *, struct SEE_object *, struct SEE_string *);
52 static int unibar_hasproperty(struct SEE_interpreter *, struct SEE_object *, struct SEE_string *);
54 struct js_unibar_object {
55 struct SEE_object object;
56 unsigned char bar;
59 struct SEE_objectclass js_menubar_object_class = {
60 "menubar",
61 unibar_get,
62 unibar_put,
63 unibar_canput,
64 unibar_hasproperty,
65 SEE_no_delete,
66 SEE_no_defaultvalue,
67 NULL,
68 NULL,
69 NULL,
70 NULL
73 struct SEE_objectclass js_statusbar_object_class = {
74 "statusbar",
75 unibar_get,
76 unibar_put,
77 unibar_canput,
78 unibar_hasproperty,
79 SEE_no_delete,
80 SEE_no_defaultvalue,
81 NULL,
82 NULL,
83 NULL,
84 NULL
87 static void
88 unibar_get(struct SEE_interpreter *interp, struct SEE_object *o,
89 struct SEE_string *p, struct SEE_value *res)
91 struct global_object *g = (struct global_object *)interp;
92 struct view_state *vs = g->win->vs;
93 struct document_view *doc_view = vs->doc_view;
94 struct session_status *status = &doc_view->session->status;
95 struct js_unibar_object *obj = (struct js_unibar_object *)o;
96 unsigned char bar = obj->bar;
98 checktime(interp);
99 if (p == s_visible) {
100 #define unibar_fetch(bar) \
101 SEE_SET_BOOLEAN(res, status->force_show_##bar##_bar >= 0 \
102 ? status->force_show_##bar##_bar \
103 : status->show_##bar##_bar)
104 switch (bar) {
105 case 's':
106 unibar_fetch(status);
107 break;
108 case 't':
109 unibar_fetch(title);
110 break;
111 default:
112 SEE_SET_BOOLEAN(res, 0);
113 break;
115 #undef unibar_fetch
116 return;
118 SEE_SET_UNDEFINED(res);
121 static void
122 unibar_put(struct SEE_interpreter *interp, struct SEE_object *o,
123 struct SEE_string *p, struct SEE_value *val, int attr)
125 checktime(interp);
126 if (p == s_location) {
127 struct global_object *g = (struct global_object *)interp;
128 struct view_state *vs = g->win->vs;
129 struct document_view *doc_view = vs->doc_view;
130 struct session_status *status = &doc_view->session->status;
131 struct js_unibar_object *obj = (struct js_unibar_object *)o;
132 unsigned char bar = obj->bar;
134 switch (bar) {
135 case 's':
136 status->force_show_status_bar =
137 SEE_ToUint32(interp, val);
138 break;
139 case 't':
140 status->force_show_title_bar =
141 SEE_ToUint32(interp, val);
142 break;
143 default:
144 break;
150 static int
151 unibar_canput(struct SEE_interpreter *interp, struct SEE_object *o,
152 struct SEE_string *p)
154 checktime(interp);
155 if (p == s_visible)
156 return 1;
157 return 0;
160 static int
161 unibar_hasproperty(struct SEE_interpreter *interp, struct SEE_object *o,
162 struct SEE_string *p)
164 checktime(interp);
165 if (p == s_visible)
166 return 1;
167 return 0;
170 void
171 init_js_menubar_object(struct ecmascript_interpreter *interpreter)
173 struct global_object *g = interpreter->backend_data;
174 struct SEE_interpreter *interp = &g->interp;
175 struct SEE_value v;
176 struct js_unibar_object *menu;
178 menu = SEE_NEW(interp, struct js_unibar_object);
180 menu->object.objectclass = &js_menubar_object_class;
181 menu->object.Prototype = NULL;
182 menu->bar = 't';
184 SEE_SET_OBJECT(&v, (struct SEE_object *)menu);
185 SEE_OBJECT_PUT(interp, interp->Global, s_menubar, &v, 0);
188 void
189 init_js_statusbar_object(struct ecmascript_interpreter *interpreter)
191 struct global_object *g = interpreter->backend_data;
192 struct SEE_interpreter *interp = &g->interp;
193 struct SEE_value v;
194 struct js_unibar_object *status;
196 status = SEE_NEW(interp, struct js_unibar_object);
198 status->object.objectclass = &js_statusbar_object_class;
199 status->object.Prototype = NULL;
200 status->bar = 's';
202 SEE_SET_OBJECT(&v, (struct SEE_object *)status);
203 SEE_OBJECT_PUT(interp, interp->Global, s_statusbar, &v, 0);