Mercurial > dillo_port1.3
annotate src/uicmd.cc @ 341:215da0caf90b
- Implemented tabbed browsing.
author | jcid |
---|---|
date | Thu, 18 Sep 2008 00:16:38 +0200 |
parents | 4a6db4341660 |
children | de7f0e48470f |
rev | line source |
---|---|
0 | 1 /* |
2 * File: uicmd.cc | |
3 * | |
35 | 4 * Copyright (C) 2005-2007 Jorge Arellano Cid <jcid@dillo.org> |
0 | 5 * |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 3 of the License, or | |
9 * (at your option) any later version. | |
10 */ | |
11 | |
12 // Functions/Methods for commands triggered from the UI | |
13 | |
14 | |
15 #include <stdio.h> | |
16 #include <stdarg.h> | |
27 | 17 #include <math.h> /* for rint */ |
0 | 18 #include <fltk/Widget.h> |
341 | 19 #include <fltk/TabGroup.h> |
0 | 20 |
21 #include "dir.h" | |
22 #include "ui.hh" | |
23 #include "uicmd.hh" | |
24 #include "timeout.hh" | |
25 #include "menu.hh" | |
26 #include "dialog.hh" | |
27 #include "bookmark.h" | |
28 #include "history.h" | |
29 #include "msg.h" | |
30 #include "prefs.h" | |
31 | |
32 #include "dw/fltkviewport.hh" | |
33 | |
34 #include "nav.h" | |
35 | |
341 | 36 // Handy macro |
37 #define BW2UI(bw) ((UI*)(bw->ui)) | |
38 | |
0 | 39 // Platform idependent part |
40 using namespace dw::core; | |
41 // FLTK related | |
42 using namespace dw::fltk; | |
43 | |
44 | |
45 /* | |
46 * Local data | |
47 */ | |
48 static char *save_dir = NULL; | |
49 | |
50 using namespace fltk; | |
51 | |
341 | 52 // |
53 // For custom handling of keyboard | |
54 // | |
55 class CustTabGroup : public fltk::TabGroup { | |
56 public: | |
57 CustTabGroup (int x, int y, int ww, int wh, const char *lbl=0) : | |
58 TabGroup(x,y,ww,wh,lbl) {}; | |
59 int handle(int e) { | |
60 // Don't focus with arrow keys | |
61 _MSG("CustTabGroup::handle %d\n", e); | |
62 int k = event_key(); | |
63 // We're only interested in some flags | |
64 unsigned modifier = event_state() & (SHIFT | CTRL | ALT); | |
65 if (e == KEY) { | |
66 if (k == UpKey || k == DownKey || k == TabKey) { | |
67 return 0; | |
68 } else if (k == LeftKey || k == RightKey) { | |
69 if (modifier == SHIFT) { | |
70 int i = value(); | |
71 if (k == LeftKey) {i = i ? i-1 : children()-1;} | |
72 else {i++; if (i >= children()) i = 0;} | |
73 if (value(i)) do_callback(); | |
74 return 1; | |
75 } | |
76 return 0; | |
77 } | |
78 } | |
79 return TabGroup::handle(e); | |
80 } | |
81 }; | |
82 | |
0 | 83 |
84 /* | |
85 * Create a new UI and its associated BrowserWindow data structure. | |
72
fbda2a94d998
- Made "New browser window" inherit the panel style of its parent.
jcid
parents:
56
diff
changeset
|
86 * Use style from v_ui. If non-NULL it must be of type UI*. |
0 | 87 */ |
341 | 88 BrowserWindow *a_UIcmd_browser_window_new(int ww, int wh, const void *vbw) |
0 | 89 { |
341 | 90 static TabGroup *DilloTabs = NULL; |
91 BrowserWindow *old_bw = (BrowserWindow*)vbw; | |
92 BrowserWindow *new_bw = NULL; | |
93 | |
0 | 94 if (ww <= 0 || wh <= 0) { |
8 | 95 // Set default geometry from dillorc. |
96 ww = prefs.width; | |
97 wh = prefs.height; | |
0 | 98 } |
99 | |
341 | 100 if (!DilloTabs) { |
101 {Window *o = new Window(ww, wh); | |
102 o->shortcut(0); // Ignore Escape | |
103 o->clear_double_buffer(); | |
104 DilloTabs = new CustTabGroup(0, 0, ww, wh); | |
105 DilloTabs->selection_color(156); | |
106 //DilloTabs->clear_tab_to_focus(); | |
107 o->add(DilloTabs); | |
108 } | |
109 wh -= 20; | |
110 } | |
111 | |
0 | 112 // Create and set the UI |
341 | 113 UI *new_ui = new UI(0, 20, ww, wh, "Label", old_bw ? BW2UI(old_bw) : NULL); |
0 | 114 new_ui->set_status("http://www.dillo.org/"); |
341 | 115 new_ui->tabs(DilloTabs); |
0 | 116 //new_ui->set_location("http://dillo.org/"); |
117 //new_ui->customize(12); | |
118 | |
341 | 119 DilloTabs->add(new_ui); |
120 DilloTabs->resizable(new_ui); | |
121 DilloTabs->window()->resizable(new_ui); | |
122 DilloTabs->window()->show(); | |
123 | |
124 if (old_bw == NULL && prefs.xpos >= 0 && prefs.ypos >= 0) { | |
91 | 125 // position the first window according to preferences |
126 fltk::Rectangle r; | |
341 | 127 new_ui->window()->borders(&r); |
91 | 128 // borders() gives x and y border sizes as negative values |
341 | 129 new_ui->window()->position(prefs.xpos - r.x(), prefs.ypos - r.y()); |
91 | 130 } |
131 | |
0 | 132 // Now create the Dw render layout and viewport |
133 FltkPlatform *platform = new FltkPlatform (); | |
134 Layout *layout = new Layout (platform); | |
135 | |
86
c6cecbed4727
- Made TopGroup a PackedGroup, simplifying UI code and removing workarounds.
jcid
parents:
72
diff
changeset
|
136 FltkViewport *viewport = new FltkViewport (0, 0, 1, 1); |
c6cecbed4727
- Made TopGroup a PackedGroup, simplifying UI code and removing workarounds.
jcid
parents:
72
diff
changeset
|
137 |
c6cecbed4727
- Made TopGroup a PackedGroup, simplifying UI code and removing workarounds.
jcid
parents:
72
diff
changeset
|
138 layout->attachView (viewport); |
c6cecbed4727
- Made TopGroup a PackedGroup, simplifying UI code and removing workarounds.
jcid
parents:
72
diff
changeset
|
139 new_ui->set_render_layout(*viewport); |
50 | 140 |
327
7d83c41d52b9
- Adjusted internal font sizes so the default font_factor is 1.0
jcid
parents:
293
diff
changeset
|
141 viewport->setScrollStep((int) rint(14.0 * prefs.font_factor)); |
0 | 142 |
143 // Now, create a new browser window structure | |
341 | 144 new_bw = a_Bw_new(); |
0 | 145 |
341 | 146 // Store new_bw for callback data inside UI |
147 new_ui->vbw(new_bw); | |
148 | |
0 | 149 // Reference the UI from the bw |
150 new_bw->ui = (void *)new_ui; | |
151 // Copy the layout pointer into the bw data | |
152 new_bw->render_layout = (void*)layout; | |
153 | |
154 return new_bw; | |
155 } | |
156 | |
157 /* | |
158 * Close one browser window | |
159 */ | |
160 void a_UIcmd_close_bw(void *vbw) | |
161 { | |
162 BrowserWindow *bw = (BrowserWindow *)vbw; | |
341 | 163 UI *ui = BW2UI(bw); |
0 | 164 Layout *layout = (Layout*)bw->render_layout; |
165 | |
166 MSG("a_UIcmd_close_bw\n"); | |
95
ced56c7bf3f8
- Fixed a segfault bug when closing a bw under active networking.
jcid
parents:
91
diff
changeset
|
167 a_Bw_stop_clients(bw, BW_Root + BW_Img + Bw_Force); |
0 | 168 delete(layout); |
341 | 169 if (ui->tabs()) { |
170 ui->tabs()->remove(ui); | |
171 if (ui->tabs()->value() != -1) | |
172 ui->tabs()->selected_child()->take_focus(); | |
173 else | |
174 ui->tabs()->window()->hide(); | |
175 } | |
213
9a62d31d6f8b
- More switches from destroy() to delete() call for close window.
jcid
parents:
172
diff
changeset
|
176 delete(ui); |
0 | 177 a_Bw_free(bw); |
178 } | |
179 | |
180 /* | |
181 * Close all the browser windows | |
182 */ | |
183 void a_UIcmd_close_all_bw() | |
184 { | |
185 BrowserWindow *bw; | |
186 | |
187 while ((bw = a_Bw_get())) | |
188 a_UIcmd_close_bw((void*)bw); | |
189 } | |
190 | |
191 /* | |
192 * Open a new URL in the given browser window. | |
193 * | |
194 * our custom "file:" URIs are normalized here too. | |
195 */ | |
196 void a_UIcmd_open_urlstr(void *vbw, const char *urlstr) | |
197 { | |
198 char *new_urlstr; | |
199 DilloUrl *url; | |
200 int ch; | |
201 BrowserWindow *bw = (BrowserWindow*)vbw; | |
202 | |
203 if (urlstr && *urlstr) { | |
204 /* Filter URL string */ | |
205 new_urlstr = a_Url_string_strip_delimiters(urlstr); | |
206 | |
207 if (!dStrncasecmp(new_urlstr, "file:", 5)) { | |
208 /* file URI */ | |
209 ch = new_urlstr[5]; | |
210 if (!ch || ch == '.') { | |
334
619177c88430
- Forbid dpi GET and POST from non dpi-generated urls.
jcid
parents:
333
diff
changeset
|
211 url = a_Url_new(a_Dir_get_owd(), "file:"); |
0 | 212 } else if (ch == '~') { |
334
619177c88430
- Forbid dpi GET and POST from non dpi-generated urls.
jcid
parents:
333
diff
changeset
|
213 url = a_Url_new(dGethomedir(), "file:"); |
0 | 214 } else { |
334
619177c88430
- Forbid dpi GET and POST from non dpi-generated urls.
jcid
parents:
333
diff
changeset
|
215 url = a_Url_new(new_urlstr, "file:"); |
0 | 216 } |
217 | |
218 } else { | |
219 /* common case */ | |
334
619177c88430
- Forbid dpi GET and POST from non dpi-generated urls.
jcid
parents:
333
diff
changeset
|
220 url = a_Url_new(new_urlstr, NULL); |
0 | 221 } |
222 dFree(new_urlstr); | |
223 | |
224 if (url) { | |
225 a_Nav_push(bw, url); | |
226 a_Url_free(url); | |
227 } | |
228 } | |
229 | |
230 /* let the rendered area have focus */ | |
231 //gtk_widget_grab_focus(GTK_BIN(bw->render_main_scroll)->child); | |
232 } | |
233 | |
234 /* | |
235 * Open a new URL in the given browser window | |
236 */ | |
22 | 237 void a_UIcmd_open_url(BrowserWindow *bw, const DilloUrl *url) |
238 { | |
239 a_Nav_push(bw, url); | |
240 } | |
241 | |
242 /* | |
243 * Open a new URL in the given browser window | |
244 */ | |
11 | 245 void a_UIcmd_open_url_nw(BrowserWindow *bw, const DilloUrl *url) |
0 | 246 { |
247 a_Nav_push_nw(bw, url); | |
248 } | |
249 | |
250 /* | |
251 * Send the browser back to previous page | |
252 */ | |
253 void a_UIcmd_back(void *vbw) | |
254 { | |
255 a_Nav_back((BrowserWindow*)vbw); | |
256 } | |
257 | |
258 /* | |
259 * Popup the navigation menu of the Back button | |
260 */ | |
261 void a_UIcmd_back_popup(void *vbw) | |
262 { | |
263 a_Menu_history_popup((BrowserWindow*)vbw, -1); | |
264 } | |
265 | |
266 /* | |
267 * Send the browser to next page in the history list | |
268 */ | |
269 void a_UIcmd_forw(void *vbw) | |
270 { | |
271 a_Nav_forw((BrowserWindow*)vbw); | |
272 } | |
273 | |
274 /* | |
275 * Popup the navigation menu of the Forward button | |
276 */ | |
277 void a_UIcmd_forw_popup(void *vbw) | |
278 { | |
279 a_Menu_history_popup((BrowserWindow*)vbw, 1); | |
280 } | |
281 | |
282 /* | |
283 * Send the browser to home URL | |
284 */ | |
285 void a_UIcmd_home(void *vbw) | |
286 { | |
287 a_Nav_home((BrowserWindow*)vbw); | |
288 } | |
289 | |
290 /* | |
291 * Reload current URL | |
292 */ | |
293 void a_UIcmd_reload(void *vbw) | |
294 { | |
295 a_Nav_reload((BrowserWindow*)vbw); | |
296 } | |
297 | |
298 /* | |
40
b8319194f7da
Added a save-directory preference (save_dir in dillorc2).
jcid
parents:
35
diff
changeset
|
299 * Return a suitable filename for a given URL path. |
0 | 300 */ |
51 | 301 static char *UIcmd_make_save_filename(const char *pathstr) |
0 | 302 { |
303 size_t MaxLen = 64; | |
304 char *FileName, *name; | |
305 const char *dir = a_UIcmd_get_save_dir(); | |
306 | |
40
b8319194f7da
Added a save-directory preference (save_dir in dillorc2).
jcid
parents:
35
diff
changeset
|
307 if ((name = strrchr(pathstr, '/'))) { |
0 | 308 if (strlen(++name) > MaxLen) { |
309 name = name + strlen(name) - MaxLen; | |
310 } | |
311 FileName = dStrconcat(dir ? dir : "", name, NULL); | |
312 } else { | |
40
b8319194f7da
Added a save-directory preference (save_dir in dillorc2).
jcid
parents:
35
diff
changeset
|
313 FileName = dStrconcat(dir ? dir : "", pathstr, NULL); |
0 | 314 } |
315 return FileName; | |
316 } | |
317 | |
318 /* | |
319 * Get the default directory for saving files. | |
320 */ | |
321 const char *a_UIcmd_get_save_dir() | |
322 { | |
323 return save_dir; | |
324 } | |
325 | |
326 /* | |
327 * Set the default directory for saving files. | |
328 */ | |
329 void a_UIcmd_set_save_dir(const char *dir) | |
330 { | |
331 char *p; | |
332 | |
333 if (dir && (p = strrchr(dir, '/'))) { | |
334 dFree(save_dir); | |
335 // assert a trailing '/' | |
336 save_dir = dStrconcat(dir, (p[1] != 0) ? "/" : "", NULL); | |
337 } | |
338 } | |
339 | |
340 /* | |
341 * Save current URL | |
342 */ | |
343 void a_UIcmd_save(void *vbw) | |
344 { | |
345 const char *name; | |
346 char *SuggestedName, *urlstr; | |
347 DilloUrl *url; | |
348 | |
40
b8319194f7da
Added a save-directory preference (save_dir in dillorc2).
jcid
parents:
35
diff
changeset
|
349 a_UIcmd_set_save_dir(prefs.save_dir); |
0 | 350 |
351 urlstr = a_UIcmd_get_location_text((BrowserWindow*)vbw); | |
334
619177c88430
- Forbid dpi GET and POST from non dpi-generated urls.
jcid
parents:
333
diff
changeset
|
352 url = a_Url_new(urlstr, NULL); |
40
b8319194f7da
Added a save-directory preference (save_dir in dillorc2).
jcid
parents:
35
diff
changeset
|
353 SuggestedName = UIcmd_make_save_filename(URL_PATH(url)); |
0 | 354 name = a_Dialog_save_file("Save Page as File", NULL, SuggestedName); |
355 MSG("a_UIcmd_save: %s\n", name); | |
356 dFree(SuggestedName); | |
357 dFree(urlstr); | |
358 | |
359 if (name) { | |
360 a_Nav_save_url((BrowserWindow*)vbw, url, name); | |
361 } | |
362 | |
363 a_Url_free(url); | |
364 } | |
365 | |
366 /* | |
172
765db4e71128
- Implemented the file input control for forms (work in progress).
jcid
parents:
95
diff
changeset
|
367 * Select a file |
765db4e71128
- Implemented the file input control for forms (work in progress).
jcid
parents:
95
diff
changeset
|
368 */ |
765db4e71128
- Implemented the file input control for forms (work in progress).
jcid
parents:
95
diff
changeset
|
369 const char *a_UIcmd_select_file() |
765db4e71128
- Implemented the file input control for forms (work in progress).
jcid
parents:
95
diff
changeset
|
370 { |
765db4e71128
- Implemented the file input control for forms (work in progress).
jcid
parents:
95
diff
changeset
|
371 return a_Dialog_select_file("Select a File", NULL, NULL); |
765db4e71128
- Implemented the file input control for forms (work in progress).
jcid
parents:
95
diff
changeset
|
372 } |
765db4e71128
- Implemented the file input control for forms (work in progress).
jcid
parents:
95
diff
changeset
|
373 |
765db4e71128
- Implemented the file input control for forms (work in progress).
jcid
parents:
95
diff
changeset
|
374 /* |
0 | 375 * Stop network activity on this bw. |
376 * The stop button was pressed: stop page (and images) downloads. | |
377 */ | |
378 void a_UIcmd_stop(void *vbw) | |
379 { | |
380 BrowserWindow *bw = (BrowserWindow *)vbw; | |
381 | |
382 MSG("a_UIcmd_stop()\n"); | |
383 a_Bw_stop_clients(bw, BW_Root + BW_Img + Bw_Force); | |
384 a_UIcmd_set_buttons_sens(bw); | |
385 } | |
386 | |
387 /* | |
388 * Open URL with dialog chooser | |
389 */ | |
390 void a_UIcmd_open_file(void *vbw) | |
391 { | |
392 char *name; | |
393 DilloUrl *url; | |
394 | |
395 name = a_Dialog_open_file("Open File", NULL, ""); | |
396 | |
397 if (name) { | |
334
619177c88430
- Forbid dpi GET and POST from non dpi-generated urls.
jcid
parents:
333
diff
changeset
|
398 url = a_Url_new(name, "file:"); |
0 | 399 a_Nav_push((BrowserWindow*)vbw, url); |
400 a_Url_free(url); | |
401 dFree(name); | |
402 } | |
403 } | |
404 | |
405 /* | |
406 * Returns a newly allocated string holding a search url generated from | |
407 * a string of keywords (separarated by blanks) and prefs.search_url. | |
408 * The search string is urlencoded. | |
409 */ | |
51 | 410 static char *UIcmd_make_search_str(const char *str) |
0 | 411 { |
412 char *keys = a_Url_encode_hex_str(str), *c = prefs.search_url; | |
413 Dstr *ds = dStr_sized_new(128); | |
414 char *search_url; | |
415 | |
416 for (; *c; c++) { | |
417 if (*c == '%') | |
418 switch(*++c) { | |
419 case 's': | |
420 dStr_append(ds, keys); break;; | |
421 case '%': | |
422 dStr_append_c(ds, '%'); break;; | |
423 case 0: | |
424 MSG_WARN("search_url ends with '%%'\n"); c--; break;; | |
425 default: | |
426 MSG_WARN("illegal specifier '%%%c' in search_url\n", *c); | |
427 } | |
428 else | |
429 dStr_append_c(ds, *c); | |
430 } | |
431 dFree(keys); | |
432 | |
433 search_url = ds->str; | |
434 dStr_free(ds, 0); | |
435 return search_url; | |
436 } | |
437 | |
438 /* | |
439 * Get a query from a dialog and open it | |
440 */ | |
441 void a_UIcmd_search_dialog(void *vbw) | |
442 { | |
443 const char *query, *url_str; | |
444 | |
445 if ((query = a_Dialog_input("Search the Web:"))) { | |
446 url_str = UIcmd_make_search_str(query); | |
447 a_UIcmd_open_urlstr(vbw, url_str); | |
448 } | |
449 } | |
450 | |
451 /* | |
241 | 452 * Get password for user |
453 */ | |
454 const char *a_UIcmd_get_passwd(const char *user) | |
455 { | |
456 const char *passwd; | |
457 char *prompt = dStrconcat("Password for user \"", user, "\"", NULL); | |
458 passwd = a_Dialog_passwd(prompt); | |
459 dFree(prompt); | |
460 return passwd; | |
461 } | |
462 | |
463 /* | |
0 | 464 * Save link URL |
465 */ | |
466 void a_UIcmd_save_link(BrowserWindow *bw, const DilloUrl *url) | |
467 { | |
468 const char *name; | |
469 char *SuggestedName; | |
470 | |
42 | 471 a_UIcmd_set_save_dir(prefs.save_dir); |
0 | 472 |
473 SuggestedName = UIcmd_make_save_filename(URL_STR(url)); | |
474 name = a_Dialog_save_file("Save Link as File", NULL, SuggestedName); | |
475 MSG("a_UIcmd_save_link: %s\n", name); | |
476 dFree(SuggestedName); | |
477 | |
478 if (name) { | |
479 a_Nav_save_url(bw, url, name); | |
480 } | |
481 } | |
482 | |
483 /* | |
484 * Request the bookmarks page | |
485 */ | |
486 void a_UIcmd_book(void *vbw) | |
487 { | |
334
619177c88430
- Forbid dpi GET and POST from non dpi-generated urls.
jcid
parents:
333
diff
changeset
|
488 DilloUrl *url = a_Url_new("dpi:/bm/", NULL); |
0 | 489 a_Nav_push((BrowserWindow*)vbw, url); |
490 a_Url_free(url); | |
491 } | |
492 | |
493 /* | |
494 * Add a bookmark for a certain URL | |
495 */ | |
11 | 496 void a_UIcmd_add_bookmark(BrowserWindow *bw, const DilloUrl *url) |
0 | 497 { |
498 a_Bookmarks_add(bw, url); | |
499 } | |
500 | |
501 | |
502 /* | |
503 * Popup the page menu | |
504 */ | |
48
224c9f547b39
Implemented "Load Images" in the page menu and cleaned up html.hh.
jcid
parents:
42
diff
changeset
|
505 void a_UIcmd_page_popup(void *vbw, const DilloUrl *url, |
328
6a5b6bbf9836
- Fixed the "Load Images" menu item in the page popup.
jcid
parents:
327
diff
changeset
|
506 const char *bugs_txt, bool_t unloaded_imgs) |
0 | 507 { |
328
6a5b6bbf9836
- Fixed the "Load Images" menu item in the page popup.
jcid
parents:
327
diff
changeset
|
508 a_Menu_page_popup((BrowserWindow*)vbw, url, bugs_txt, unloaded_imgs); |
0 | 509 } |
510 | |
511 /* | |
512 * Popup the link menu | |
513 */ | |
11 | 514 void a_UIcmd_link_popup(void *vbw, const DilloUrl *url) |
0 | 515 { |
516 a_Menu_link_popup((BrowserWindow*)vbw, url); | |
517 } | |
518 | |
519 /* | |
22 | 520 * Pop up the image menu |
521 */ | |
522 void a_UIcmd_image_popup(void *vbw, const DilloUrl *url, DilloUrl *link_url) | |
523 { | |
524 a_Menu_image_popup((BrowserWindow*)vbw, url, link_url); | |
525 } | |
526 | |
527 /* | |
55 | 528 * Copy url string to paste buffer |
529 */ | |
530 void a_UIcmd_copy_urlstr(BrowserWindow *bw, const char *urlstr) | |
531 { | |
532 Layout *layout = (Layout*)bw->render_layout; | |
533 layout->copySelection(urlstr); | |
534 } | |
535 | |
536 /* | |
0 | 537 * Show a text window with the URL's source |
538 */ | |
11 | 539 void a_UIcmd_view_page_source(const DilloUrl *url) |
0 | 540 { |
541 char *buf; | |
542 int buf_size; | |
543 | |
544 if (a_Nav_get_buf(url, &buf, &buf_size)) { | |
260 | 545 void *vWindow = a_Dialog_make_text_window(buf, "View Page source"); |
546 a_Nav_unref_buf(url); | |
547 a_Dialog_show_text_window(vWindow); | |
0 | 548 } |
549 } | |
550 | |
551 /* | |
552 * Show a text window with the URL's source | |
553 */ | |
554 void a_UIcmd_view_page_bugs(void *vbw) | |
555 { | |
556 BrowserWindow *bw = (BrowserWindow*)vbw; | |
557 | |
558 if (bw->num_page_bugs > 0) { | |
260 | 559 void *vWindow = a_Dialog_make_text_window(bw->page_bugs->str, |
560 "Detected HTML errors"); | |
561 a_Dialog_show_text_window(vWindow); | |
0 | 562 } else { |
563 a_Dialog_msg("Zero detected HTML errors!"); | |
564 } | |
565 } | |
566 | |
567 /* | |
568 * Popup the bug meter menu | |
569 */ | |
570 void a_UIcmd_bugmeter_popup(void *vbw) | |
571 { | |
572 BrowserWindow *bw = (BrowserWindow*)vbw; | |
573 | |
19
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
574 a_Menu_bugmeter_popup(bw, a_History_get_url(NAV_TOP_UIDX(bw))); |
0 | 575 } |
576 | |
577 /* | |
578 * Make a list of URL indexes for the history popup | |
579 * based on direction (-1 = back, 1 = forward) | |
580 */ | |
581 int *a_UIcmd_get_history(BrowserWindow *bw, int direction) | |
582 { | |
583 int i, j, n; | |
584 int *hlist; | |
585 | |
586 // Count the number of URLs | |
587 i = a_Nav_stack_ptr(bw) + direction; | |
588 for (n = 0 ; i >= 0 && i < a_Nav_stack_size(bw); i+=direction) | |
589 ++n; | |
590 hlist = dNew(int, n + 1); | |
591 | |
592 // Fill the list | |
593 i = a_Nav_stack_ptr(bw) + direction; | |
594 for (j = 0 ; i >= 0 && i < a_Nav_stack_size(bw); i+=direction, j += 1) { | |
19
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
595 hlist[j] = NAV_UIDX(bw,i); |
0 | 596 } |
597 hlist[j] = -1; | |
598 | |
599 return hlist; | |
600 } | |
601 | |
602 /* | |
603 * Jump to a certain URL in the navigation stack. | |
604 */ | |
605 void a_UIcmd_nav_jump(BrowserWindow *bw, int offset, int new_bw) | |
606 { | |
607 a_Nav_jump(bw, offset, new_bw); | |
608 } | |
609 | |
610 // UI binding functions ------------------------------------------------------- | |
611 | |
612 /* | |
613 * Return browser window width and height | |
614 */ | |
615 void a_UIcmd_get_wh(BrowserWindow *bw, int *w, int *h) | |
616 { | |
617 *w = BW2UI(bw)->w(); | |
618 *h = BW2UI(bw)->h(); | |
619 _MSG("a_UIcmd_wh: w=%d, h=%d\n", *w, *h); | |
620 } | |
621 | |
622 /* | |
15
a15e6c075023
Fixed the problem of scrolling position (remember position in a page)
jcid
parents:
11
diff
changeset
|
623 * Get the scroll position (x, y offset pair) |
a15e6c075023
Fixed the problem of scrolling position (remember position in a page)
jcid
parents:
11
diff
changeset
|
624 */ |
a15e6c075023
Fixed the problem of scrolling position (remember position in a page)
jcid
parents:
11
diff
changeset
|
625 void a_UIcmd_get_scroll_xy(BrowserWindow *bw, int *x, int *y) |
a15e6c075023
Fixed the problem of scrolling position (remember position in a page)
jcid
parents:
11
diff
changeset
|
626 { |
a15e6c075023
Fixed the problem of scrolling position (remember position in a page)
jcid
parents:
11
diff
changeset
|
627 Layout *layout = (Layout*)bw->render_layout; |
a15e6c075023
Fixed the problem of scrolling position (remember position in a page)
jcid
parents:
11
diff
changeset
|
628 |
a15e6c075023
Fixed the problem of scrolling position (remember position in a page)
jcid
parents:
11
diff
changeset
|
629 if (layout) { |
a15e6c075023
Fixed the problem of scrolling position (remember position in a page)
jcid
parents:
11
diff
changeset
|
630 *x = layout->getScrollPosX(); |
a15e6c075023
Fixed the problem of scrolling position (remember position in a page)
jcid
parents:
11
diff
changeset
|
631 *y = layout->getScrollPosY(); |
a15e6c075023
Fixed the problem of scrolling position (remember position in a page)
jcid
parents:
11
diff
changeset
|
632 } |
a15e6c075023
Fixed the problem of scrolling position (remember position in a page)
jcid
parents:
11
diff
changeset
|
633 } |
a15e6c075023
Fixed the problem of scrolling position (remember position in a page)
jcid
parents:
11
diff
changeset
|
634 |
a15e6c075023
Fixed the problem of scrolling position (remember position in a page)
jcid
parents:
11
diff
changeset
|
635 /* |
19
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
636 * Set the scroll position ({x, y} offset pair) |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
637 */ |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
638 void a_UIcmd_set_scroll_xy(BrowserWindow *bw, int x, int y) |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
639 { |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
640 Layout *layout = (Layout*)bw->render_layout; |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
641 |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
642 if (layout) { |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
643 layout->scrollTo(HPOS_LEFT, VPOS_TOP, x, y, 0, 0); |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
644 } |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
645 } |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
646 |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
647 /* |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
648 * Set the scroll position by fragment (from URL) |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
649 */ |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
650 void a_UIcmd_set_scroll_by_fragment(BrowserWindow *bw, const char *f) |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
651 { |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
652 Layout *layout = (Layout*)bw->render_layout; |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
653 |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
654 if (layout && f) { |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
655 layout->setAnchor(f); |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
656 } |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
657 } |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
658 |
145bd87089e7
Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents:
15
diff
changeset
|
659 /* |
0 | 660 * Get location's text |
661 */ | |
662 char *a_UIcmd_get_location_text(BrowserWindow *bw) | |
663 { | |
664 return dStrdup(BW2UI(bw)->get_location()); | |
665 } | |
666 | |
667 /* | |
668 * Set location's text | |
669 */ | |
670 void a_UIcmd_set_location_text(void *vbw, const char *text) | |
671 { | |
672 BrowserWindow *bw = (BrowserWindow*)vbw; | |
673 BW2UI(bw)->set_location(text); | |
674 } | |
675 | |
676 /* | |
677 * Set the page progress bar | |
678 * cmd: 0 Deactivate, 1 Update, 2 Clear | |
679 */ | |
680 void a_UIcmd_set_page_prog(BrowserWindow *bw, size_t nbytes, int cmd) | |
681 { | |
682 BW2UI(bw)->set_page_prog(nbytes, cmd); | |
683 } | |
684 | |
685 /* | |
686 * Set the images progress bar | |
687 * cmd: 0 Deactivate, 1 Update, 2 Clear | |
688 */ | |
689 void a_UIcmd_set_img_prog(BrowserWindow *bw, int n_img, int t_img, int cmd) | |
690 { | |
691 BW2UI(bw)->set_img_prog(n_img, t_img, cmd); | |
291 | 692 #if 0 |
293 | 693 if (!cmd) |
291 | 694 a_UIcmd_close_bw(bw); |
695 #endif | |
0 | 696 } |
697 | |
698 /* | |
699 * Set the bug meter progress label | |
700 */ | |
701 void a_UIcmd_set_bug_prog(BrowserWindow *bw, int n_bug) | |
702 { | |
703 BW2UI(bw)->set_bug_prog(n_bug); | |
704 } | |
705 | |
706 /* | |
707 * Set the page title. | |
708 * now it goes to the window titlebar (maybe to TAB label in the future). | |
709 */ | |
710 void a_UIcmd_set_page_title(BrowserWindow *bw, const char *label) | |
711 { | |
712 BW2UI(bw)->set_page_title(label); | |
713 } | |
714 | |
715 /* | |
716 * Set a printf-like status string on the bottom of the dillo window. | |
717 * Beware: The safe way to set an arbitrary string is | |
718 * a_UIcmd_set_msg(bw, "%s", str) | |
719 */ | |
720 void a_UIcmd_set_msg(BrowserWindow *bw, const char *format, ...) | |
721 { | |
722 va_list argp; | |
723 Dstr *ds = dStr_sized_new(128); | |
724 va_start(argp, format); | |
725 dStr_vsprintf(ds, format, argp); | |
726 va_end(argp); | |
727 BW2UI(bw)->set_status(ds->str); | |
728 dStr_free(ds, 1); | |
729 } | |
730 | |
731 /* | |
732 * Set the sensitivity of back/forw/stop buttons. | |
733 */ | |
734 static void a_UIcmd_set_buttons_sens_cb(void *vbw) | |
735 { | |
736 int sens; | |
737 BrowserWindow *bw = (BrowserWindow*)vbw; | |
738 | |
739 // Stop | |
740 sens = (dList_length(bw->ImageClients) || dList_length(bw->RootClients)); | |
741 BW2UI(bw)->button_set_sens(UI_STOP, sens); | |
742 // Back | |
743 sens = (a_Nav_stack_ptr(bw) > 0); | |
744 BW2UI(bw)->button_set_sens(UI_BACK, sens); | |
745 // Forward | |
746 sens = (a_Nav_stack_ptr(bw) < a_Nav_stack_size(bw) - 1 && | |
747 !bw->nav_expecting); | |
748 BW2UI(bw)->button_set_sens(UI_FORW, sens); | |
749 | |
750 bw->sens_idle_up = 0; | |
751 } | |
752 | |
753 | |
754 /* | |
755 * Set the timeout function for button sensitivity | |
756 */ | |
757 void a_UIcmd_set_buttons_sens(BrowserWindow *bw) | |
758 { | |
759 if (bw->sens_idle_up == 0) { | |
760 a_Timeout_add(0.0, a_UIcmd_set_buttons_sens_cb, bw); | |
761 bw->sens_idle_up = 1; | |
762 } | |
763 } | |
764 | |
765 /* | |
766 * Toggle control panel (aka. fullscreen) | |
767 */ | |
768 void a_UIcmd_fullscreen_toggle(BrowserWindow *bw) | |
769 { | |
770 BW2UI(bw)->fullscreen_toggle(); | |
771 } | |
772 | |
56 | 773 /* |
774 * Search for next occurrence of key. | |
775 */ | |
776 void a_UIcmd_findtext_search(BrowserWindow *bw, const char *key, int case_sens) | |
777 { | |
778 Layout *l = (Layout *)bw->render_layout; | |
779 | |
780 switch (l->search(key, case_sens)) { | |
781 case FindtextState::RESTART: | |
782 a_UIcmd_set_msg(bw, "No further occurrences of \"%s\". " | |
783 "Restarting from the top.", key); | |
784 break; | |
785 case FindtextState::NOT_FOUND: | |
786 a_UIcmd_set_msg(bw, "\"%s\" not found.", key); | |
787 break; | |
788 case FindtextState::SUCCESS: | |
789 default: | |
790 a_UIcmd_set_msg(bw, ""); | |
791 } | |
792 } | |
793 | |
794 /* | |
795 * Reset text search state. | |
796 */ | |
797 void a_UIcmd_findtext_reset(BrowserWindow *bw) | |
798 { | |
799 Layout *l = (Layout *)bw->render_layout; | |
800 l->resetSearch(); | |
801 | |
802 a_UIcmd_set_msg(bw, ""); | |
803 } | |
804 | |
341 | 805 /* |
806 * Focus the rendered area. | |
807 */ | |
808 void a_UIcmd_focus_main_area(BrowserWindow *bw) | |
809 { | |
810 BW2UI(bw)->focus_main(); | |
811 } | |
812 | |
813 /* | |
814 * Focus the location bar. | |
815 */ | |
816 void a_UIcmd_focus_location(void *vbw) | |
817 { | |
818 BrowserWindow *bw = (BrowserWindow*)vbw; | |
819 BW2UI(bw)->focus_location(); | |
820 } | |
821 |