Dillo v3.1.1-120-g540bad94
Loading...
Searching...
No Matches
menu.cc
Go to the documentation of this file.
1/*
2 * File: menu.cc
3 *
4 * Copyright (C) 2005-2007 Jorge Arellano Cid <jcid@dillo.org>
5 * Copyright (C) 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
18#include <FL/Fl.H>
19#include <FL/Fl_Menu_Item.H>
20
21#include <unistd.h>
22#include <errno.h>
23#include "lout/misc.hh" /* SimpleVector */
24#include "msg.h"
25#include "menu.hh"
26#include "actions.h"
27#include "uicmd.hh"
28#include "history.h"
29#include "html.hh"
30#include "ui.hh" // for (UI *)
31#include "keys.hh"
32#include "timeout.hh"
33
34/*
35 * Local data types
36 */
37
38typedef struct {
39 const char *title;
40 const Fl_Menu_Item *picked;
41 const Fl_Menu_Item *menu;
42} Menu_popup_data_t;
43
44/*
45 * Local data
46 */
47
48// (This data can be encapsulated inside a class for each popup, but
49// as popups are modal, there's no need).
50static DilloUrl *popup_url = NULL;
51// Weak reference to the popup's bw
52static BrowserWindow *popup_bw = NULL;
53static void *popup_form = NULL;
54// Where to place the popup
55static int popup_x, popup_y;
56// History popup direction (-1 = back, 1 = forward).
57static int history_direction = -1;
58// History popup, list of URL-indexes.
59static int *history_list = NULL;
60
61
62//--------------------------------------------------------------------------
63static void Menu_nop_cb(Fl_Widget*, void*)
64{
65}
66
70static void filemenu_cb(Fl_Widget*, void *data)
71{
72 if (strcmp((char*)data, "nw") == 0) {
74 } else if (strcmp((char*)data, "nt") == 0) {
76 } else if (strcmp((char*)data, "of") == 0) {
78 } else if (strcmp((char*)data, "ou") == 0) {
80 } else if (strcmp((char*)data, "cw") == 0) {
82 } else if (strcmp((char*)data, "ed") == 0) {
84 }
85}
86
87
88static void Menu_copy_urlstr_cb(Fl_Widget*, void *user_data)
89{
90 if (user_data) {
91 DilloUrl *url = (DilloUrl *)user_data ;
93 }
94}
95
99static void Menu_open_url_cb(Fl_Widget*, void *user_data)
100{
101 DilloUrl *url = (DilloUrl *)user_data;
102 _MSG("Open URL cb: click! :-)\n");
104}
105
109static void Menu_open_url_nw_cb(Fl_Widget*, void *user_data)
110{
111 DilloUrl *url = (DilloUrl *)user_data;
112 _MSG("Open URL in new window cb: click! :-)\n");
114}
115
119static void Menu_open_url_nt_cb(Fl_Widget*, void *user_data)
120{
121 DilloUrl *url = (DilloUrl *)user_data;
122 int focus = prefs.focus_new_tab ? 1 : 0;
123 if (Fl::event_state(FL_SHIFT)) focus = !focus;
124 a_UIcmd_open_url_nt(popup_bw, url, focus);
125}
126
130static void Menu_add_bookmark_cb(Fl_Widget*, void *user_data)
131{
132 DilloUrl *url = (DilloUrl *)user_data;
134}
135
139static void Menu_find_text_cb(Fl_Widget*, void*)
140{
141 ((UI *)popup_bw->ui)->findbar_toggle(1);
142}
143
147static void Menu_save_link_cb(Fl_Widget*, void *user_data)
148{
149 DilloUrl *url = (DilloUrl *)user_data;
151}
152
156static void Menu_save_page_cb(Fl_Widget*, void*)
157{
159}
160
164static void Menu_view_page_source_cb(Fl_Widget*, void *user_data)
165{
166 DilloUrl *url = (DilloUrl *)user_data;
168}
169
173static void Menu_view_page_bugs_cb(Fl_Widget*, void*)
174{
176}
177
181static void Menu_load_images_cb(Fl_Widget*, void *user_data)
182{
183 DilloUrl *page_url = (DilloUrl *) user_data;
184 void *doc = a_Bw_get_url_doc(popup_bw, page_url);
185
186 if (doc)
188}
189
193static void Menu_form_submit_cb(Fl_Widget*, void*)
194{
195 void *doc = a_Bw_get_url_doc(popup_bw, popup_url);
196
197 if (doc)
199}
200
204static void Menu_form_reset_cb(Fl_Widget*, void*)
205{
206 void *doc = a_Bw_get_url_doc(popup_bw, popup_url);
207
208 if (doc)
210}
211
215static void Menu_form_hiddens_cb(Fl_Widget*, void *user_data)
216{
217 bool visible = *((bool *) user_data);
218 void *doc = a_Bw_get_url_doc(popup_bw, popup_url);
219
220 if (doc)
222}
223
224static void Menu_stylesheet_cb(Fl_Widget*, void *vUrl)
225{
226 int mb = Fl::event_button();
227 const DilloUrl *url = (const DilloUrl *) vUrl;
228
229 if (mb == 1) {
231 } else if (mb == 2) {
233 int focus = prefs.focus_new_tab ? 1 : 0;
234 if (Fl::event_state(FL_SHIFT)) focus = !focus;
235 a_UIcmd_open_url_nt(popup_bw, url, focus);
236 } else {
238 }
239 }
240}
241
242static void Menu_bugmeter_validate(const char *validator_url)
243{
244 if (popup_url &&
246 const char *popup_str = URL_STR(popup_url),
247 *ptr = strrchr(popup_str, '#');
248 char *no_fragment = ptr ? dStrndup(popup_str, ptr - popup_str)
249 : dStrdup(popup_str);
250 char *encoded = a_Url_encode_hex_str(no_fragment);
251 Dstr *dstr = dStr_sized_new(128);
252
253 dStr_sprintf(dstr, validator_url, encoded);
255 dStr_free(dstr, 1);
256 dFree(encoded);
257 dFree(no_fragment);
258 }
259}
260
264static void Menu_bugmeter_validate_w3c_nu_cb(Fl_Widget*, void*)
265{
267 "https://validator.w3.org/nu/"
268 "?useragent=Validator.nu%%2FLV+https%%3A%%2F%%2Fvalidator.w3.org%%2Fservices"
269 "&acceptlanguage="
270 "&doc=%s");
271}
272
276static void Menu_bugmeter_validate_w3c_cb(Fl_Widget*, void*)
277{
279 "https://validator.w3.org/check?uri=%s"
280 "&charset=%%28detect+automatically%%29"
281 "&doctype=Inline&group=0"
282 "&user-agent=W3C_Validator%%2F1.3+");
283}
284
288static void Menu_bugmeter_about_cb(Fl_Widget*, void*)
289{
290 a_UIcmd_open_urlstr(popup_bw, "https://dillo-browser.github.io/old/help/bug_meter.html");
291}
292
297static void Menu_history_cb(Fl_Widget*, void *data)
298{
299 int mb = Fl::event_button();
300 int offset = history_direction * VOIDP2INT(data);
301 const DilloUrl *url = a_History_get_url(history_list[VOIDP2INT(data)-1]);
302
303 if (mb == 1) {
304 a_UIcmd_nav_jump(popup_bw, offset, 0);
305 } else if (mb == 2) {
306 // Middle button, open in a new window/tab
308 int focus = prefs.focus_new_tab ? 1 : 0;
309 if (Fl::event_state(FL_SHIFT)) focus = !focus;
310 a_UIcmd_open_url_nt(popup_bw, url, focus);
311 } else {
313 }
314 }
315}
316
317/*
318 * Menus are popped-up from this timeout callback so the events
319 * associated with the button are gone when it pops. This way we
320 * avoid a segfault when a new page replaces the page that issued
321 * the popup menu.
322 */
323static void Menu_simple_popup_cb(void *data)
324{
325 const Fl_Menu_Item *m;
326
327 ((UI*)popup_bw->ui)->window()->cursor(FL_CURSOR_DEFAULT);
328
329 m = ((Fl_Menu_Item *)data)->popup(popup_x, popup_y);
330
331 if (m && m->callback())
332 m->do_callback((Fl_Widget *)data);
334}
335
336static void Menu_popup_cb(void *data)
337{
338 const Fl_Menu_Item *picked;
339 Menu_popup_data_t *d = (Menu_popup_data_t *)data;
340
341 ((UI*)popup_bw->ui)->window()->cursor(FL_CURSOR_DEFAULT);
342
343 picked = d->menu->popup(popup_x, popup_y, d->title, d->picked);
344 if (picked) {
345 d->picked = picked;
346 if (picked->callback())
347 picked->do_callback((Fl_Widget *)(d->menu));
348 }
350}
351
356 bool_t has_bugs, void *v_cssUrls)
357{
358 lout::misc::SimpleVector <DilloUrl*> *cssUrls =
359 (lout::misc::SimpleVector <DilloUrl*> *) v_cssUrls;
360 int j = 0;
361
362 static Fl_Menu_Item *stylesheets = NULL;
363 static Fl_Menu_Item pm[] = {
364 {"View page source", 0, Menu_view_page_source_cb,0,0,0,0,0,0},
365 {"View page bugs", 0, Menu_view_page_bugs_cb,0,0,0,0,0,0},
366 {"View stylesheets", 0, Menu_nop_cb,0,FL_SUBMENU_POINTER|FL_MENU_DIVIDER,
367 0,0,0,0},
368 {"Bookmark this page", 0,Menu_add_bookmark_cb,0,FL_MENU_DIVIDER,0,0,0,0},
369 {"Find text", 0, Menu_find_text_cb,0,0,0,0,0,0},
370 {"Save page as...", 0, Menu_save_page_cb,0,0,0,0,0,0},
371 {0,0,0,0,0,0,0,0,0}
372 };
373 static Menu_popup_data_t page_data = {"Page menu", NULL, pm};
374
375 popup_x = Fl::event_x();
376 popup_y = Fl::event_y();
377 popup_bw = bw;
379 popup_url = a_Url_dup(url);
380
381 has_bugs == TRUE ? pm[1].activate() : pm[1].deactivate();
382
383 if (dStrAsciiCasecmp(URL_SCHEME(url), "dpi") == 0 &&
384 strncmp(URL_PATH(url), "/vsource/", 9) == 0)
385 pm[0].deactivate();
386 else {
387 pm[0].activate();
388 pm[0].user_data(popup_url);
389 }
390
391 if (stylesheets) {
392 while (stylesheets[j].text) {
393 dFree((char *) stylesheets[j].label());
394 a_Url_free((DilloUrl *) stylesheets[j].user_data());
395 j++;
396 }
397 delete [] stylesheets;
398 stylesheets = NULL;
399 }
400
401 if (cssUrls && cssUrls->size () > 0) {
402 stylesheets = new Fl_Menu_Item[cssUrls->size() + 1];
403 memset(stylesheets, '\0', (cssUrls->size() + 1) * sizeof(Fl_Menu_Item));
404
405 for (j = 0; j < cssUrls->size(); j++) {
406 DilloUrl *url = cssUrls->get(j);
407 const char *url_str = URL_STR(url);
408 const uint_t head_length = 30, tail_length = 40,
409 url_len = strlen(url_str);
410 char *label;
411
412 if (url_len > head_length + tail_length + 3) {
413 /* trim long URLs when making the label */
414 char *url_head = dStrndup(url_str, head_length);
415 const char *url_tail = url_str + (url_len - tail_length);
416 label = dStrconcat(url_head, "...", url_tail, NULL);
417 dFree(url_head);
418 } else {
419 label = dStrdup(url_str);
420 }
421
422 stylesheets[j].label(FL_NORMAL_LABEL, label);
423 stylesheets[j].callback(Menu_stylesheet_cb, a_Url_dup(url));
424 }
425
426 pm[2].user_data(stylesheets);
427 pm[2].activate();
428 } else {
429 pm[2].deactivate();
430 }
431 pm[3].user_data(popup_url);
432
433 a_Timeout_add(0.0, Menu_popup_cb, (void*)&page_data);
434}
435
436static Fl_Menu_Item link_menu_[] = {
437 {"Open link in new tab", 0, Menu_open_url_nt_cb,0,0,0,0,0,0},
438 {"Open link in new window", 0, Menu_open_url_nw_cb,0,FL_MENU_DIVIDER,0,0,
439 0,0},
440 {"Bookmark this link", 0, Menu_add_bookmark_cb,0,0,0,0,0,0},
441 {"Copy link location", 0, Menu_copy_urlstr_cb,0,FL_MENU_DIVIDER,0,0,0,0},
442 {"Save link as...", 0, Menu_save_link_cb,0,FL_MENU_DIVIDER,0,0,0,0},
443 {0,0,0,0,0,0,0,0,0}
444};
445
446/* As we can only provide a pointer to the link menu items, we need to
447 * create an auxiliary structure to hold the current URL and the program
448 * that should run on each item. */
449struct link_menu_item {
450 const DilloUrl *url;
451 const DilloUrl *origin;
452 Action *action;
453};
454
458static void Menu_open_url_action_cb(Fl_Widget*, void *user_data)
459{
460 /* Don't use popup_url because it is used for the image URL when coming from
461 * the image menu. We should get rid of the global variables and pass them
462 * via the user_data. */
463
464 struct link_menu_item *mitem = (struct link_menu_item *) user_data;
465 const DilloUrl *url = mitem->url;
466 const DilloUrl *origin = mitem->origin;
467 Action *action = mitem->action;
468
469 /* Set the environment variables */
470 setenv("url", URL_STR(url), 1);
471 setenv("origin", URL_STR(origin), 1);
472
473 if (fork() == 0) {
474 /* Child */
475 errno = 0;
476 int ret = system(action->cmd);
477 if (ret == -1) {
478 MSG("Cannot run '%s': %s\n", action->cmd, strerror(errno));
479 exit(1);
480 } else if (ret != 0) {
481 MSG("Command exited with '%d': %s\n", ret, action->cmd);
482 exit(1);
483 } else {
484 /* All good, terminate the child */
485 exit(0);
486 }
487 }
488}
489
490static Fl_Menu_Item *get_link_menu(void)
491{
492 static Fl_Menu_Item *link_menu = NULL;
493 static struct link_menu_item *link_menu_item = NULL;
494
495 /* Already initialized */
496 if (link_menu != NULL)
497 return link_menu;
498
499 Dlist *actions = a_Actions_link_get();
500 int nactions = dList_length(actions);
501
502 /* Count static menu entries */
503 int nstatic = 0;
504 while (link_menu_[nstatic].text)
505 nstatic++;
506
507 int ntotal = nstatic + nactions;
508 link_menu = (Fl_Menu_Item *) calloc(ntotal + 1, sizeof(Fl_Menu_Item));
509 link_menu_item = (struct link_menu_item *) calloc(nactions, sizeof(struct link_menu_item));
510
511 /* Just copy the static entries */
512 for (int i = 0; i < nstatic; i++) {
513 memcpy(&link_menu[i], &link_menu_[i], sizeof(Fl_Menu_Item));
514 }
515
516 /* And append the dynamic ones */
517 for (int i = 0; i < nactions; i++) {
518 Action *action = (Action *) dList_nth_data(actions, i);
519 struct link_menu_item *mitem = &link_menu_item[i];
520 mitem->url = NULL; /* Not known yet */
521 mitem->action = action;
522
523 Fl_Menu_Item *item = &link_menu[nstatic + i];
524 item->text = action->label;
525 item->callback_ = Menu_open_url_action_cb;
526 item->user_data_ = mitem;
527 }
528
529 return link_menu;
530}
531
532static void Menu_set_link_menu_user_data(const DilloUrl *url, const DilloUrl *page_url)
533{
534 Fl_Menu_Item *link_menu = get_link_menu();
535 for (int i = 0; link_menu[i].label(); i++) {
536 if (link_menu[i].callback_ == Menu_open_url_action_cb) {
537 struct link_menu_item *mitem = (struct link_menu_item *) link_menu[i].user_data_;
538 /* Set the url and origin */
539 mitem->url = url;
540 mitem->origin = page_url;
541 } else {
542 link_menu[i].user_data_ = (void *) url;
543 }
544 }
545}
546
550void a_Menu_link_popup(BrowserWindow *bw, const DilloUrl *url, const DilloUrl *page_url)
551{
552 static Menu_popup_data_t link_data = {"Link menu", NULL, NULL};
553
554 popup_x = Fl::event_x();
555 popup_y = Fl::event_y();
556 popup_bw = bw;
558 popup_url = a_Url_dup(url);
559
560 Fl_Menu_Item *link_menu = get_link_menu();
561 link_data.menu = link_menu;
562
564
565 a_Timeout_add(0.0, Menu_popup_cb, (void*)&link_data);
566}
567
572 bool_t loaded_img, DilloUrl *page_url,
573 DilloUrl *link_url)
574{
575 static DilloUrl *popup_page_url = NULL;
576 static DilloUrl *popup_link_url = NULL;
577 static Fl_Menu_Item pm[] = {
578 {"Isolate image", 0, Menu_open_url_cb,0,0,0,0,0,0},
579 {"Open image in new tab", 0, Menu_open_url_nt_cb,0,0,0,0,0,0},
580 {"Open image in new window", 0, Menu_open_url_nw_cb, 0, FL_MENU_DIVIDER,
581 0,0,0,0},
582 {"Load image", 0, Menu_load_images_cb,0,0,0,0,0,0},
583 {"Bookmark this image", 0, Menu_add_bookmark_cb,0,0,0,0,0,0},
584 {"Copy image location", 0,Menu_copy_urlstr_cb,0,FL_MENU_DIVIDER,0,0,0,0},
585 {"Save image as...", 0, Menu_save_link_cb, 0, FL_MENU_DIVIDER,0,0,0,0},
586 {"Link menu", 0, Menu_nop_cb, get_link_menu(), FL_SUBMENU_POINTER,0,0,0,0},
587 {0,0,0,0,0,0,0,0,0}
588 };
589 static Menu_popup_data_t image_data = {"Image menu", NULL, pm};
590
591 popup_x = Fl::event_x();
592 popup_y = Fl::event_y();
593 popup_bw = bw;
595 popup_url = a_Url_dup(url);
596 a_Url_free(popup_page_url);
597 popup_page_url = a_Url_dup(page_url);
598 a_Url_free(popup_link_url);
599 popup_link_url = a_Url_dup(link_url);
600
601
602 pm[0].user_data(popup_url);
603 pm[1].user_data(popup_url);
604 pm[2].user_data(popup_url);
605
606 if (loaded_img) {
607 pm[3].deactivate();
608 } else {
609 pm[3].activate();
610 pm[3].user_data(popup_page_url);
611 }
612
613 pm[4].user_data(popup_url);
614 pm[5].user_data(popup_url);
615 pm[6].user_data(popup_url);
616
617 if (link_url) {
618 pm[7].activate();
619 Menu_set_link_menu_user_data(popup_link_url, popup_page_url);
620 } else {
621 pm[7].deactivate();
622 }
623
624 a_Timeout_add(0.0, Menu_popup_cb, (void*)&image_data);
625}
626
630void a_Menu_form_popup(BrowserWindow *bw, const DilloUrl *page_url,
631 void *formptr, bool_t hidvis)
632{
633 static bool hiddens_visible;
634 static Fl_Menu_Item pm[] = {
635 {"Submit form", 0, Menu_form_submit_cb,0,0,0,0,0,0},
636 {"Reset form", 0, Menu_form_reset_cb,0,0,0,0,0,0},
637 {0, 0, Menu_form_hiddens_cb, &hiddens_visible, 0,0,0,0,0},
638 {0,0,0,0,0,0,0,0,0}
639 };
640 static Menu_popup_data_t form_data = {"Form menu", NULL, pm};
641
642 popup_x = Fl::event_x();
643 popup_y = Fl::event_y();
644 popup_bw = bw;
646 popup_url = a_Url_dup(page_url);
647 popup_form = formptr;
648
649 hiddens_visible = hidvis;
650 pm[2].label(hiddens_visible ? "Hide hiddens": "Show hiddens");
651
652 a_Timeout_add(0.0, Menu_popup_cb, (void*)&form_data);
653}
654
658void a_Menu_file_popup(BrowserWindow *bw, void *v_wid)
659{
660 Fl_Widget *wid = (Fl_Widget*)v_wid;
661
662 static Fl_Menu_Item pm[] = {
664 (void*)"nt",0,0,0,0,0},
666 (void*)"nw", FL_MENU_DIVIDER,0,0,0,0},
667 {"Open file...", Keys::getShortcut(KEYS_OPEN), filemenu_cb,
668 (void*)"of",0,0,0,0,0},
669 {"Open URL...", Keys::getShortcut(KEYS_GOTO), filemenu_cb,
670 (void*)"ou",0,0,0,0,0},
672 (void*)"cw", FL_MENU_DIVIDER,0,0,0,0},
674 (void*)"ed",0,0,0,0,0},
675 {0,0,0,0,0,0,0,0,0}
676 };
677
678 popup_bw = bw;
679 popup_x = wid->x();
680 popup_y = wid->y() + wid->h();
682 popup_url = NULL;
683
684 //pm->label(wid->visible() ? NULL : "File");
685 a_Timeout_add(0.0, Menu_simple_popup_cb, (void*)pm);
686}
687
692{
693 static Fl_Menu_Item pm[] = {
694 {"Validate URL with W3C Nu validator (HTML5 only)", 0,
696 {"Validate URL with W3C validator (HTML 4.01 and older)", 0,
697 Menu_bugmeter_validate_w3c_cb,0,FL_MENU_DIVIDER,0,0,0,0},
698 {"About bug meter", 0,
699 Menu_bugmeter_about_cb,0,0,0,0,0,0},
700 {0,0,0,0,0,0,0,0,0}
701 };
702
703 popup_x = Fl::event_x();
704 popup_y = Fl::event_y();
705 popup_bw = bw;
707 popup_url = a_Url_dup(url);
708
709 a_Timeout_add(0.0, Menu_simple_popup_cb, (void*)pm);
710}
711
717void a_Menu_history_popup(BrowserWindow *bw, int x, int y, int direction)
718{
719 static Fl_Menu_Item *pm = 0;
720 int i, n;
721
722 popup_bw = bw;
723 popup_x = x;
724 popup_y = y;
725 history_direction = direction;
726
727 // TODO: hook popdown event with delete or similar.
728 if (pm)
729 delete [] pm;
730 if (history_list)
732
733 // Get a list of URLs for this popup
734 history_list = a_UIcmd_get_history(bw, direction);
735
736 for (n = 0; history_list[n] != -1; n++)
737 ;
738
739 pm = new Fl_Menu_Item[n + 1];
740 memset(pm, '\0', (n + 1) * sizeof(Fl_Menu_Item));
741
742 for (i = 0; i < n; i++) {
743 pm[i].label(FL_NORMAL_LABEL, a_History_get_title(history_list[i], 1));
744 pm[i].callback(Menu_history_cb, INT2VOIDP(i+1));
745 }
746 a_Timeout_add(0.0, Menu_simple_popup_cb, (void*)pm);
747}
748
752static void Menu_remote_css_cb(Fl_Widget *wid, void*)
753{
754 Fl_Menu_Item *item = (Fl_Menu_Item*) wid;
755
756 item->flags ^= FL_MENU_VALUE;
757 prefs.load_stylesheets = item->flags & FL_MENU_VALUE ? 1 : 0;
759}
760
764static void Menu_embedded_css_cb(Fl_Widget *wid, void*)
765{
766 Fl_Menu_Item *item = (Fl_Menu_Item*) wid;
767
768 item->flags ^= FL_MENU_VALUE;
769 prefs.parse_embedded_css = item->flags & FL_MENU_VALUE ? 1 : 0;
771}
772
773
777static void Menu_force_https_cb(Fl_Widget *wid, void*)
778{
779 Fl_Menu_Item *item = (Fl_Menu_Item*) wid;
780
781 item->flags ^= FL_MENU_VALUE;
782 prefs.http_force_https = item->flags & FL_MENU_VALUE ? 1 : 0;
784}
785
786static void Menu_panel_change_cb(Fl_Widget*, void *user_data)
787{
788 UI *ui = (UI*)popup_bw->ui;
789
790 if (VOIDP2INT(user_data) == 10) /* small icons */
791 ui->change_panel(ui->get_panelsize(), !ui->get_smallicons());
792 else
793 ui->change_panel(VOIDP2INT(user_data), ui->get_smallicons());
794}
795
799static void Menu_imgload_toggle_cb(Fl_Widget *wid, void*)
800{
801 Fl_Menu_Item *item = (Fl_Menu_Item*) wid;
802
803 item->flags ^= FL_MENU_VALUE;
804
805 if ((prefs.load_images = item->flags & FL_MENU_VALUE ? 1 : 0)) {
806 void *doc = a_Bw_get_current_doc(popup_bw);
807
808 if (doc) {
809 DilloUrl *pattern = NULL;
810 a_Html_load_images(doc, pattern);
811 }
812 }
813}
814
818static void Menu_bgimg_load_toggle_cb(Fl_Widget *wid, void*)
819{
820 Fl_Menu_Item *item = (Fl_Menu_Item*) wid;
821
822 item->flags ^= FL_MENU_VALUE;
823 prefs.load_background_images = item->flags & FL_MENU_VALUE ? 1 : 0;
825}
826
830void a_Menu_tools_popup(BrowserWindow *bw, int x, int y)
831{
832 const Fl_Menu_Item *item;
833 UI *ui = (UI*)bw->ui;
834
835 static Fl_Menu_Item pm[] = {
836 {"Use remote CSS", 0, Menu_remote_css_cb, 0, FL_MENU_TOGGLE,0,0,0,0},
837 {"Use embedded CSS", 0, Menu_embedded_css_cb, 0,
838 FL_MENU_TOGGLE|FL_MENU_DIVIDER,0,0,0,0},
839 {"Load images", 0, Menu_imgload_toggle_cb, 0,
840 FL_MENU_TOGGLE,0,0,0,0},
841 {"Load background images", 0, Menu_bgimg_load_toggle_cb, 0,
842 FL_MENU_TOGGLE|FL_MENU_DIVIDER,0,0,0,0},
843 {"Force HTTPS", 0, Menu_force_https_cb, 0,
844 FL_MENU_TOGGLE|FL_MENU_DIVIDER,0,0,0,0},
845 {"Panel size", 0, Menu_nop_cb, (void*)"Submenu1", FL_SUBMENU,0,0,0,0},
846 {"tiny", 0,Menu_panel_change_cb,(void*)0,FL_MENU_RADIO,0,0,0,0},
847 {"small", 0,Menu_panel_change_cb,(void*)1,FL_MENU_RADIO,0,0,0,0},
848 {"medium",0,Menu_panel_change_cb,(void*)2,
849 FL_MENU_RADIO|FL_MENU_DIVIDER,0,0,0,0},
850 {"small icons", 0,Menu_panel_change_cb,(void*)10,
851 FL_MENU_TOGGLE,0,0,0,0},
852 {0,0,0,0,0,0,0,0,0},
853 {0,0,0,0,0,0,0,0,0}
854 };
855
856 popup_bw = bw;
857 int cur_panelsize = ui->get_panelsize();
858 int cur_smallicons = ui->get_smallicons();
859
861 pm[0].set();
863 pm[1].set();
864 if (prefs.load_images)
865 pm[2].set();
867 pm[3].set();
869 pm[4].set();
870 pm[6+cur_panelsize].setonly();
871 cur_smallicons ? pm[9].set() : pm[9].clear();
872
873 item = pm->popup(x, y);
874 if (item) {
875 ((Fl_Widget *)item)->do_callback();
876 }
877}
878
Dlist * a_Actions_link_get(void)
Definition actions.c:62
#define _MSG(...)
Definition bookmarks.c:45
#define MSG(...)
Definition bookmarks.c:46
void * a_Bw_get_url_doc(BrowserWindow *bw, const DilloUrl *url)
Get document by URL.
Definition bw.c:250
void * a_Bw_get_current_doc(BrowserWindow *bw)
Get current document.
Definition bw.c:231
static int getShortcut(KeysCommand_t cmd)
Given a keys command, return a shortcut for it, or 0 if there is none (e.g., for KEYS_NEW_WINDOW,...
Definition keys.cc:298
Definition ui.hh:123
int get_panelsize()
Definition ui.hh:173
void change_panel(int new_size, int small_icons)
On-the-fly panel style change.
Definition ui.cc:985
int get_smallicons()
Definition ui.hh:174
T get(int i) const
Return the one element, explicitly.
Definition misc.hh:222
int size() const
Return the number of elements put into this vector.
Definition misc.hh:162
unsigned int uint_t
Definition d_size.h:20
unsigned char bool_t
Definition d_size.h:21
char * dStrconcat(const char *s1,...)
Concatenate a NULL-terminated list of strings.
Definition dlib.c:102
void dFree(void *mem)
Definition dlib.c:68
int dStrAsciiCasecmp(const char *s1, const char *s2)
Definition dlib.c:203
char * dStrdup(const char *s)
Definition dlib.c:77
Dstr * dStr_sized_new(int sz)
Create a new string with a given size.
Definition dlib.c:254
int dList_length(Dlist *lp)
For completing the ADT.
Definition dlib.c:613
void * dList_nth_data(Dlist *lp, int n0)
Return the nth data item, NULL when not found or 'n0' is out of range.
Definition dlib.c:662
void dStr_free(Dstr *ds, int all)
Free a dillo string.
Definition dlib.c:337
char * dStrndup(const char *s, size_t sz)
Definition dlib.c:88
void dStr_sprintf(Dstr *ds, const char *format,...)
Printf-like function.
Definition dlib.c:450
#define VOIDP2INT(p)
Definition dlib.h:43
#define TRUE
Definition dlib.h:23
#define INT2VOIDP(i)
Definition dlib.h:44
const DilloUrl * a_History_get_url(int idx)
Return the DilloUrl field (by index)
Definition history.c:80
const char * a_History_get_title(int idx, int force)
Return the title field (by index) ('force' returns URL_STR when there's no title)
Definition history.c:94
void a_Html_form_display_hiddens(void *v_html, void *v_form, bool_t display)
Used by the "Show/Hide hiddens" form menuitem.
Definition html.cc:279
void a_Html_form_submit(void *v_html, void *v_form)
Used by the "Submit form" form menuitem.
Definition html.cc:253
void a_Html_load_images(void *v_html, DilloUrl *pattern)
Used by the "Load images" page menuitem.
Definition html.cc:230
void a_Html_form_reset(void *v_html, void *v_form)
Used by the "Reset form" form menuitem.
Definition html.cc:266
@ KEYS_CLOSE_ALL
Definition keys.hh:36
@ KEYS_GOTO
Definition keys.hh:39
@ KEYS_OPEN
Definition keys.hh:20
@ KEYS_NEW_WINDOW
Definition keys.hh:21
@ KEYS_NEW_TAB
Definition keys.hh:22
@ KEYS_CLOSE_TAB
Definition keys.hh:25
static void Menu_copy_urlstr_cb(Fl_Widget *, void *user_data)
Definition menu.cc:88
static int popup_y
Definition menu.cc:55
static void Menu_add_bookmark_cb(Fl_Widget *, void *user_data)
Add bookmark.
Definition menu.cc:130
void a_Menu_page_popup(BrowserWindow *bw, const DilloUrl *url, bool_t has_bugs, void *v_cssUrls)
Page popup menu (construction & popup)
Definition menu.cc:355
static void Menu_panel_change_cb(Fl_Widget *, void *user_data)
Definition menu.cc:786
static void Menu_popup_cb(void *data)
Definition menu.cc:336
void a_Menu_file_popup(BrowserWindow *bw, void *v_wid)
File popup menu (construction & popup)
Definition menu.cc:658
static void Menu_embedded_css_cb(Fl_Widget *wid, void *)
Toggle use of embedded CSS style.
Definition menu.cc:764
static void Menu_bugmeter_about_cb(Fl_Widget *, void *)
Show info page for the bug meter.
Definition menu.cc:288
static void Menu_bgimg_load_toggle_cb(Fl_Widget *wid, void *)
Toggle loading of background images.
Definition menu.cc:818
static void Menu_open_url_nw_cb(Fl_Widget *, void *user_data)
Open URL in new window.
Definition menu.cc:109
static void Menu_open_url_action_cb(Fl_Widget *, void *user_data)
Open URL following a custom action.
Definition menu.cc:458
void a_Menu_tools_popup(BrowserWindow *bw, int x, int y)
Tools popup menu (construction & popup).
Definition menu.cc:830
static void Menu_open_url_cb(Fl_Widget *, void *user_data)
Open URL.
Definition menu.cc:99
static void Menu_save_link_cb(Fl_Widget *, void *user_data)
Save link.
Definition menu.cc:147
static void Menu_view_page_bugs_cb(Fl_Widget *, void *)
View current page's bugs.
Definition menu.cc:173
static void Menu_bugmeter_validate_w3c_nu_cb(Fl_Widget *, void *)
Validate URL with the W3C Nu validator (for HTML 5)
Definition menu.cc:264
static void Menu_stylesheet_cb(Fl_Widget *, void *vUrl)
Definition menu.cc:224
static void Menu_bugmeter_validate_w3c_cb(Fl_Widget *, void *)
Validate URL with the W3C legacy validator (HTML 4.01 and older)
Definition menu.cc:276
static void Menu_force_https_cb(Fl_Widget *wid, void *)
Toggle use of force https mode.
Definition menu.cc:777
static void Menu_form_hiddens_cb(Fl_Widget *, void *user_data)
Toggle display of 'hidden' form controls.
Definition menu.cc:215
static void Menu_form_submit_cb(Fl_Widget *, void *)
Submit form.
Definition menu.cc:193
static void Menu_set_link_menu_user_data(const DilloUrl *url, const DilloUrl *page_url)
Definition menu.cc:532
static void Menu_save_page_cb(Fl_Widget *, void *)
Save current page.
Definition menu.cc:156
void a_Menu_link_popup(BrowserWindow *bw, const DilloUrl *url, const DilloUrl *page_url)
Link popup menu (construction & popup)
Definition menu.cc:550
static void Menu_simple_popup_cb(void *data)
Definition menu.cc:323
static Fl_Menu_Item * get_link_menu(void)
Definition menu.cc:490
static void filemenu_cb(Fl_Widget *, void *data)
Static function for File menu callbacks.
Definition menu.cc:70
static void Menu_bugmeter_validate(const char *validator_url)
Definition menu.cc:242
static void Menu_form_reset_cb(Fl_Widget *, void *)
Reset form.
Definition menu.cc:204
static void Menu_view_page_source_cb(Fl_Widget *, void *user_data)
View current page source.
Definition menu.cc:164
static void * popup_form
Definition menu.cc:53
static Fl_Menu_Item link_menu_[]
Definition menu.cc:436
static void Menu_open_url_nt_cb(Fl_Widget *, void *user_data)
Open URL in new Tab.
Definition menu.cc:119
static void Menu_find_text_cb(Fl_Widget *, void *)
Find text.
Definition menu.cc:139
static void Menu_history_cb(Fl_Widget *, void *data)
Navigation History callback.
Definition menu.cc:297
static void Menu_load_images_cb(Fl_Widget *, void *user_data)
Load images on current page that match URL pattern.
Definition menu.cc:181
static int popup_x
Definition menu.cc:55
void a_Menu_image_popup(BrowserWindow *bw, const DilloUrl *url, bool_t loaded_img, DilloUrl *page_url, DilloUrl *link_url)
Image popup menu (construction & popup)
Definition menu.cc:571
void a_Menu_bugmeter_popup(BrowserWindow *bw, const DilloUrl *url)
Bugmeter popup menu (construction & popup)
Definition menu.cc:691
static int * history_list
Definition menu.cc:59
static void Menu_imgload_toggle_cb(Fl_Widget *wid, void *)
Toggle loading of images – and load them if enabling.
Definition menu.cc:799
void a_Menu_history_popup(BrowserWindow *bw, int x, int y, int direction)
Navigation History popup menu (construction & popup).
Definition menu.cc:717
static BrowserWindow * popup_bw
Definition menu.cc:52
static void Menu_remote_css_cb(Fl_Widget *wid, void *)
Toggle use of remote stylesheets.
Definition menu.cc:752
void a_Menu_form_popup(BrowserWindow *bw, const DilloUrl *page_url, void *formptr, bool_t hidvis)
Form popup menu (construction & popup)
Definition menu.cc:630
static int history_direction
Definition menu.cc:57
static void Menu_nop_cb(Fl_Widget *, void *)
Definition menu.cc:63
static DilloUrl * popup_url
Definition menu.cc:50
DilloPrefs prefs
Global Data.
Definition prefs.c:33
char * cmd
Definition actions.h:23
char * label
Definition actions.h:22
Contains the specific data for a single window.
Definition bw.h:27
void * ui
Pointer to the UI object this bw belongs to.
Definition bw.h:29
bool_t parse_embedded_css
Definition prefs.h:103
bool_t load_images
Definition prefs.h:99
bool_t focus_new_tab
Definition prefs.h:74
bool_t load_background_images
Definition prefs.h:101
bool_t load_stylesheets
Definition prefs.h:102
bool_t http_force_https
Definition prefs.h:106
bool_t middle_click_opens_new_tab
Definition prefs.h:114
Definition url.h:88
Definition dlib.h:131
Definition dlib.h:102
Dstr_char_t * str
Definition dlib.h:105
void a_Timeout_add(float t, TimeoutCb_t cb, void *cbdata)
Hook a one-time timeout function 'cb' after 't' seconds with 'cbdata" as its data.
Definition timeout.cc:25
void a_Timeout_remove()
Stop running a timeout function.
Definition timeout.cc:41
void a_UIcmd_copy_urlstr(BrowserWindow *bw, const char *urlstr)
Definition uicmd.cc:1306
void a_UIcmd_close_bw(void *vbw)
Definition uicmd.cc:675
int * a_UIcmd_get_history(BrowserWindow *bw, int direction)
Definition uicmd.cc:1375
void a_UIcmd_open_file(void *vbw)
Definition uicmd.cc:1153
void a_UIcmd_focus_location(void *vbw)
Definition uicmd.cc:1653
void a_UIcmd_open_url_nw(BrowserWindow *bw, const DilloUrl *url)
Definition uicmd.cc:836
void a_UIcmd_view_page_source(BrowserWindow *bw, const DilloUrl *url)
Definition uicmd.cc:1315
void a_UIcmd_view_page_bugs(void *vbw)
Definition uicmd.cc:1350
void a_UIcmd_nav_jump(BrowserWindow *bw, int offset, int new_bw)
Definition uicmd.cc:1399
void a_UIcmd_open_urlstr(void *vbw, const char *urlstr)
Definition uicmd.cc:760
void a_UIcmd_save(void *vbw)
Definition uicmd.cc:1110
void a_UIcmd_save_link(BrowserWindow *bw, const DilloUrl *url)
Definition uicmd.cc:1235
void a_UIcmd_repush(void *vbw)
Definition uicmd.cc:926
void a_UIcmd_close_all_bw(void *)
Definition uicmd.cc:714
void a_UIcmd_add_bookmark(BrowserWindow *bw, const DilloUrl *url)
Definition uicmd.cc:1253
void a_UIcmd_open_url(BrowserWindow *bw, const DilloUrl *url)
Definition uicmd.cc:801
void a_UIcmd_open_url_nt(void *vbw, const DilloUrl *url, int focus)
Definition uicmd.cc:852
char * a_Url_encode_hex_str(const char *str)
Urlencode 'str'.
Definition url.c:620
void a_Url_free(DilloUrl *url)
Free a DilloUrl.
Definition url.c:208
DilloUrl * a_Url_dup(const DilloUrl *ori)
Duplicate a Url structure.
Definition url.c:477
#define URL_PATH(u)
Definition url.h:72
#define URL_STR(u)
Definition url.h:76
#define URL_SCHEME(u)
Definition url.h:70