Dillo v3.2.0-88-g47ab7c70
Loading...
Searching...
No Matches
ui.cc
Go to the documentation of this file.
1/*
2 * File: ui.cc
3 *
4 * Copyright (C) 2005-2007 Jorge Arellano Cid <jcid@dillo.org>
5 * Copyright (C) 2024-2025 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
17#include <unistd.h>
18#include <stdio.h>
19#include <math.h> /* rint */
20
21#include "keys.hh"
22#include "ui.hh"
23#include "msg.h"
24#include "timeout.hh"
25#include "utf8.hh"
26#include "tipwin.hh"
27
28#include <FL/Fl.H>
29#include <FL/Fl_Pixmap.H>
30#include <FL/Fl_Box.H>
31#include <FL/names.h>
32
33// Include image data
34#include "pixmaps.h"
35#include "uicmd.hh"
36#include "history.h"
37#include "nav.h"
38
39struct iconset {
40 Fl_Image *ImgMeterOK, *ImgMeterBug,
41 *ImgHome, *ImgReload, *ImgSave, *ImgBook, *ImgTools,
42 *ImgClear,*ImgSearch, *ImgHelp, *ImgLeft, *ImgLeftIn,
43 *ImgRight, *ImgRightIn, *ImgStop, *ImgStopIn;
44};
45
46static struct iconset standard_icons = {
47 new Fl_Pixmap(mini_ok_xpm),
48 new Fl_Pixmap(mini_bug_xpm),
49 new Fl_Pixmap(home_xpm),
50 new Fl_Pixmap(reload_xpm),
51 new Fl_Pixmap(save_xpm),
52 new Fl_Pixmap(bm_xpm),
53 new Fl_Pixmap(tools_xpm),
54 new Fl_Pixmap(new_s_xpm),
55 new Fl_Pixmap(search_xpm),
56 new Fl_Pixmap(help_xpm),
57 new Fl_Pixmap(left_xpm),
58 NULL,
59 new Fl_Pixmap(right_xpm),
60 NULL,
61 new Fl_Pixmap(stop_xpm),
62 NULL,
63};
64
65static struct iconset small_icons = {
66 standard_icons.ImgMeterOK,
67 standard_icons.ImgMeterBug,
68 new Fl_Pixmap(home_s_xpm),
69 new Fl_Pixmap(reload_s_xpm),
70 new Fl_Pixmap(save_s_xpm),
71 new Fl_Pixmap(bm_s_xpm),
72 new Fl_Pixmap(tools_s_xpm),
73 new Fl_Pixmap(new_s_xpm),
74 standard_icons.ImgSearch,
75 standard_icons.ImgHelp,
76 new Fl_Pixmap(left_s_xpm),
77 NULL,
78 new Fl_Pixmap(right_s_xpm),
79 NULL,
80 new Fl_Pixmap(stop_s_xpm),
81 NULL,
82};
83
84
85static struct iconset *icons = &standard_icons;
86
87/*
88 * Local sub classes
89 */
90
91//----------------------------------------------------------------------------
92
96class CustInput : public TipWinInput {
97public:
98 CustInput (int x, int y, int w, int h, const char* l=0) :
99 TipWinInput(x,y,w,h,l) {};
100 virtual int handle(int e);
101};
102
107int CustInput::handle(int e)
108{
109 int k = Fl::event_key();
110
111 _MSG("CustInput::handle event=%d\n", e);
112
113 // We're only interested in some flags
114 unsigned modifier = Fl::event_state() & (FL_SHIFT | FL_CTRL | FL_ALT);
115
116 // Don't focus with arrow keys
117 if (e == FL_FOCUS &&
118 (k == FL_Up || k == FL_Down || k == FL_Left || k == FL_Right)) {
119 return 0;
120 } else if (e == FL_KEYBOARD) {
121 if (k == FL_Escape && modifier == 0) {
122 // Let the parent group handle this Esc key
123 return 0;
124 } else if (modifier == FL_SHIFT) {
125 if (k == FL_Left || k == FL_Right) {
126 // Let these keys get to the UI
127 return 0;
128 }
129 } else if (modifier == FL_CTRL) {
130 if (k == 'e') {
131 position(size());
132 return 1;
133 } else if (k == 'k') {
134 cut(position(), size());
135 return 1;
136 } else if (k == 'd') {
137 cut(position(), position()+1);
138 return 1;
139 } else if (k == 'a' || k == 'l') {
140 // Make text selected when already focused.
141 position(size(), 0);
142 return 1;
143 } else if (k == 'h' || k == 'o' || k == 'r' ||
144 k == FL_Home || k == FL_End) {
145 // Let these keys get to the UI
146 return 0;
147 }
148 } else if (modifier == 0) {
149 if (k == FL_Down || k == FL_Up ||
150 k == FL_Page_Down || k == FL_Page_Up || k == FL_Tab) {
151 // Give up focus and honor the key
153 return 0;
154 }
155 }
156 if (k == FL_Page_Down || k == FL_Page_Up) {
157 // These do nothing of interest when FL_MULTILINE_INPUT isn't set.
158 // Let them through for key commands.
159 return 0;
160 }
161 }
162
163 return TipWinInput::handle(e);
164}
165
166//----------------------------------------------------------------------------
167
171class CustPasteButton : public CustButton {
172public:
173 CustPasteButton(int x, int y, int w, int h, const char *l=0) :
174 CustButton(x,y,w,h,l) {};
175 int handle(int e);
176};
177
178int CustPasteButton::handle(int e)
179{
180 if (e == FL_PASTE) {
181 const char* t = Fl::event_text();
182 if (t && *t) {
185 return 1;
186 }
187 }
188 return CustButton::handle(e);
189}
190
191//----------------------------------------------------------------------------
192
196class CustProgressBox : public Fl_Box {
197 int padding;
198public:
199 CustProgressBox(int x, int y, int w, int h, const char *l=0) :
200 Fl_Box(x,y,w,h,l) { padding = 0; };
201 void update_label(const char *lbl) {
202 int w = 0, h = 0;
203 if (!padding) {
204 copy_label("W");
205 measure_label(w, h);
206 padding = w > 2 ? w/2 : 1;
207 }
208 copy_label(lbl);
209 }
210};
211
212//
213// Toolbar buttons -----------------------------------------------------------
214//
215//static const char *button_names[] = {
216// "Back", "Forward", "Home", "Reload", "Save", "Stop", "Bookmarks", "Tools",
217// "Clear", "Search"
218//};
219
220
221//
222// Callback functions --------------------------------------------------------
223//
224
228static void search_cb(Fl_Widget *wid, void *data)
229{
230 int b = Fl::event_button();
231
232 if (b == FL_LEFT_MOUSE) {
234 }
235}
236
240static void help_cb(Fl_Widget *w, void *)
241{
242 char *path = dStrconcat(DILLO_DOCDIR, "user_help.html", NULL);
244
245 if (access(path, R_OK) == 0) {
246 char *urlstr = dStrconcat("file:", path, NULL);
247 a_UIcmd_open_urlstr(bw, urlstr);
248 dFree(urlstr);
249 } else {
250 MSG("Can't read local help file at \"%s\"."
251 " Getting remote help...\n", path);
252 a_UIcmd_open_urlstr(bw, "https://dillo-browser.github.io/user_help.html");
253 }
254 dFree(path);
255}
256
260static void filemenu_cb(Fl_Widget *wid, void *)
261{
262 int b = Fl::event_button();
263 if (b == FL_LEFT_MOUSE || b == FL_RIGHT_MOUSE) {
265 }
266}
267
271static void clear_cb(Fl_Widget *w, void *data)
272{
273 UI *ui = (UI*)data;
274
275 int b = Fl::event_button();
276 if (b == FL_LEFT_MOUSE) {
277 ui->set_location("");
278 ui->focus_location();
279 } else if (b == FL_MIDDLE_MOUSE) {
280 ui->paste_url();
281 }
282}
283
287static void location_cb(Fl_Widget *wid, void *data)
288{
289 Fl_Input *i = (Fl_Input*)wid;
290 UI *ui = (UI*)data;
291
292 _MSG("location_cb()\n");
294
295 if (ui->temporaryPanels())
296 ui->panels_toggle();
297}
298
299
303static void b1_cb(Fl_Widget *wid, void *cb_data)
304{
305 int bn = VOIDP2INT(cb_data);
306 int b = Fl::event_button();
307 if (b >= FL_LEFT_MOUSE && b <= FL_RIGHT_MOUSE) {
308 _MSG("[%s], mouse button %d was pressed\n", button_names[bn], b);
309 _MSG("mouse button %d was pressed\n", b);
310 }
311 switch (bn) {
312 case UI_BACK:
313 if (b == FL_LEFT_MOUSE) {
315 } else if (b == FL_MIDDLE_MOUSE) {
317 } else if (b == FL_RIGHT_MOUSE) {
319 wid->y() + wid->h());
320 }
321 break;
322 case UI_FORW:
323 if (b == FL_LEFT_MOUSE) {
325 } else if (b == FL_MIDDLE_MOUSE) {
327 } else if (b == FL_RIGHT_MOUSE) {
329 wid->y() + wid->h());
330 }
331 break;
332 case UI_HOME:
333 if (b == FL_LEFT_MOUSE) {
335 } else if (b == FL_MIDDLE_MOUSE) {
337 }
338 break;
339 case UI_RELOAD:
340 if (b == FL_LEFT_MOUSE) {
342 }
343 break;
344 case UI_SAVE:
345 if (b == FL_LEFT_MOUSE) {
347 }
348 break;
349 case UI_STOP:
350 if (b == FL_LEFT_MOUSE) {
352 }
353 break;
354 case UI_BOOK:
355 if (b == FL_LEFT_MOUSE) {
357 } else if (b == FL_MIDDLE_MOUSE) {
359 }
360 break;
361 case UI_TOOLS:
362 if (b == FL_LEFT_MOUSE || b == FL_RIGHT_MOUSE) {
364 wid->y() + wid->h());
365 }
366 break;
367 default:
368 break;
369 }
370}
371
375static void bugmeter_cb(Fl_Widget *wid, void *data)
376{
377 int b = Fl::event_button();
378 if (b == FL_LEFT_MOUSE) {
380 } else if (b == FL_RIGHT_MOUSE) {
382 }
383}
384
386// UI class methods
387//
388
389//----------------------------
390// Panel construction methods
391//----------------------------
392
396CustButton *UI::make_button(const char *label, Fl_Image *img, Fl_Image *deimg,
397 int b_n, int start)
398{
399 if (start)
400 p_xpos = 0;
401
402 CustButton *b = new CustButton(p_xpos, 0, bw, bh, (lbl) ? label : NULL);
403 if (img)
404 b->image(img);
405 if (deimg)
406 b->deimage(deimg);
407 b->callback(b1_cb, INT2VOIDP(b_n));
408 b->clear_visible_focus();
409 b->labelsize(12);
410 b->box(FL_FLAT_BOX);
411 b->down_box(FL_THIN_DOWN_FRAME);
412 p_xpos += bw;
413 return b;
414}
415
419void UI::make_toolbar(int tw, int th)
420{
421 if (!icons->ImgLeftIn) {
422 icons->ImgLeftIn = icons->ImgLeft->copy();
423 icons->ImgLeftIn->desaturate();
424 icons->ImgLeftIn->color_average(FL_BACKGROUND_COLOR, .14f);
425 }
426 if (!icons->ImgRightIn) {
427 icons->ImgRightIn = icons->ImgRight->copy();
428 icons->ImgRightIn->desaturate();
429 icons->ImgRightIn->color_average(FL_BACKGROUND_COLOR, .14f);
430 }
431 if (!icons->ImgStopIn) {
432 icons->ImgStopIn = icons->ImgStop->copy();
433 icons->ImgStopIn->desaturate();
434 icons->ImgStopIn->color_average(FL_BACKGROUND_COLOR, .14f);
435 }
436 Back = make_button("Back", icons->ImgLeft, icons->ImgLeftIn, UI_BACK, 1);
437 Forw = make_button("Forw", icons->ImgRight, icons->ImgRightIn, UI_FORW);
438 Home = make_button("Home", icons->ImgHome, NULL, UI_HOME);
439 Reload = make_button("Reload", icons->ImgReload, NULL, UI_RELOAD);
440 Save = make_button("Save", icons->ImgSave, NULL, UI_SAVE);
441 Stop = make_button("Stop", icons->ImgStop, icons->ImgStopIn, UI_STOP);
442 Bookmarks = make_button("Book", icons->ImgBook, NULL, UI_BOOK);
443 Tools = make_button("Tools", icons->ImgTools, NULL, UI_TOOLS);
444
445 Back->set_tooltip("Previous page");
446 Forw->set_tooltip("Next page");
447 Home->set_tooltip("Go to the Home page\nMiddle-click for new tab.");
448 Reload->set_tooltip("Reload");
449 Save->set_tooltip("Save this page");
450 Stop->set_tooltip("Stop loading");
451 Bookmarks->set_tooltip("View bookmarks\nMiddle-click for new tab.");
452 Tools->set_tooltip("Settings");
453}
454
459{
460 CustButton *b;
461
462 b = Clear = (CustButton*) new CustPasteButton(p_xpos,0,16,lh,0);
463 b->image(icons->ImgClear);
464 b->callback(clear_cb, this);
465 b->clear_visible_focus();
466 b->box(FL_THIN_UP_BOX);
467 b->set_tooltip("Clear the URL box.\nMiddle-click to paste a URL.");
468 p_xpos += b->w();
469
470 LocationGroup = new Fl_Group(p_xpos,0,ww-p_xpos-32,lh,0);
471 LocationGroup->begin();
472 CustInput *i = new CustInput(p_xpos,0,ww-p_xpos-32,lh,0);
473 Location = i;
474 i->when(FL_WHEN_ENTER_KEY);
475 i->callback(location_cb, this);
476 i->set_tooltip("Location");
477 i->textsize((int) rint(14.0 * prefs.font_factor));
478 p_xpos += i->w();
479 LocationGroup->box(FL_THIN_UP_BOX); // or FL_FLAT_BOX
480 LocationGroup->end();
481
482 Search = b = new CustButton(p_xpos,0,16,lh,0);
483 b->image(icons->ImgSearch);
484 b->callback(search_cb, this);
485 b->clear_visible_focus();
486 b->box(FL_THIN_UP_BOX);
487 b->set_tooltip("Search the Web");
488 p_xpos += b->w();
489
490 Help = b = new CustButton(p_xpos,0,16,lh,0);
491 b->image(icons->ImgHelp);
492 b->callback(help_cb, this);
493 b->clear_visible_focus();
494 b->box(FL_THIN_UP_BOX);
495 b->set_tooltip("Help");
496 p_xpos += b->w();
497
498}
499
503void UI::make_progress_bars(int wide, int thin_up)
504{
505 // Images
506 IProg = new CustProgressBox(p_xpos,p_ypos,pw,bh);
507 IProg->labelsize(12);
508 IProg->box(thin_up ? FL_THIN_UP_BOX : FL_EMBOSSED_BOX);
509 IProg->update_label(wide ? "Images\n0 of 0" : "0 of 0");
510 p_xpos += pw;
511 // Page
512 PProg = new CustProgressBox(p_xpos,p_ypos,pw,bh);
513 PProg->labelsize(12);
514 PProg->box(thin_up ? FL_THIN_UP_BOX : FL_EMBOSSED_BOX);
515 PProg->update_label(wide ? "Page\n0.0 KB" : "0.0 KB");
516}
517
523{
524 CustButton *btn;
525 int w = 0, h = 0, padding;
526
527 FileButton = btn = new CustButton(p_xpos,0,bw,bh,"W");
528 btn->labeltype(FL_FREE_LABELTYPE);
529 btn->measure_label(w, h);
530 padding = w;
531 btn->copy_label(PanelSize == P_tiny ? "&F" : "&File");
532 btn->measure_label(w,h);
533 h = (PanelSize == P_tiny) ? bh : lh;
534 btn->size(w+padding, h);
535 p_xpos += btn->w();
536 _MSG("UI::make_filemenu_button w=%d h=%d padding=%d\n", w, h, padding);
537 btn->box(FL_THIN_UP_BOX);
538 btn->callback(filemenu_cb, this);
539 btn->set_tooltip("File menu");
540 btn->clear_visible_focus();
541 if (!prefs.show_filemenu)
542 btn->hide();
543}
544
545
549void UI::make_panel(int ww)
550{
551 Fl_Widget *w;
552
553 if (Small_Icons)
555 else
557
558 pw = 70;
559 p_xpos = p_ypos = 0;
560 if (PanelSize == P_tiny) {
561 if (Small_Icons)
562 bw = 22, bh = 22, mh = 0, lh = 22, lbl = 0;
563 else
564 bw = 28, bh = 28, mh = 0, lh = 28, lbl = 0;
565 } else if (PanelSize == P_small) {
566 if (Small_Icons)
567 bw = 20, bh = 20, mh = 0, lh = 20, lbl = 0;
568 else
569 bw = 28, bh = 28, mh = 0, lh = 28, lbl = 0;
570 } else if (PanelSize == P_medium) {
571 if (Small_Icons)
572 bw = 42, bh = 36, mh = 0, lh = 22, lbl = 1;
573 else
574 bw = 45, bh = 45, mh = 0, lh = 28, lbl = 1;
575 }
576 nh = bh, fh = 28; sh = 20;
577
578 current(0);
579 if (PanelSize == P_tiny) {
580 NavBar = new CustGroupHorizontal(0,0,ww,nh);
581 NavBar->box(FL_NO_BOX);
582 NavBar->begin();
583 make_toolbar(ww,bh);
585 make_location(ww);
586 NavBar->resizable(LocationGroup);
588 NavBar->box(FL_THIN_UP_FRAME);
589 NavBar->end();
590 NavBar->rearrange();
591 TopGroup->insert(*NavBar,0);
592 } else {
593 // Location
594 LocBar = new CustGroupHorizontal(0,0,ww,lh);
595 LocBar->box(FL_NO_BOX);
596 LocBar->begin();
597 p_xpos = 0;
599 make_location(ww);
600 LocBar->resizable(LocationGroup);
601 LocBar->end();
602 LocBar->rearrange();
603 TopGroup->insert(*LocBar,0);
604
605 // Toolbar
606 p_ypos = 0;
607 NavBar = new CustGroupHorizontal(0,0,ww,bh);
608 NavBar->box(FL_NO_BOX);
609 NavBar->begin();
610 make_toolbar(ww,bh);
611 w = new Fl_Box(p_xpos,0,ww-p_xpos-2*pw,bh);
612 w->box(FL_FLAT_BOX);
613 NavBar->resizable(w);
614 p_xpos = ww - 2*pw;
615 if (PanelSize == P_small) {
617 } else {
619 }
620 NavBar->end();
621 NavBar->rearrange();
622 TopGroup->insert(*NavBar,1);
623 }
624}
625
629void UI::make_status_bar(int ww, int wh)
630{
631 const int bm_w = 20;
632 StatusBar = new CustGroupHorizontal(0, wh-sh, ww, sh);
633 StatusBar->box(FL_NO_BOX);
634
635 // Status box
636 StatusOutput = new Fl_Output(0, wh-sh, ww-bm_w, sh);
637 StatusOutput->value("https://dillo-browser.github.io/");
638 StatusOutput->labelsize(8);
639 StatusOutput->box(FL_THIN_DOWN_BOX);
640 StatusOutput->clear_visible_focus();
641 StatusOutput->color(FL_BACKGROUND_COLOR);
642
643 // Bug Meter
644 BugMeter = new CustButton(ww-bm_w,wh-sh,bm_w,sh);
645 BugMeter->image(icons->ImgMeterOK);
646 BugMeter->box(FL_THIN_DOWN_BOX);
647 BugMeter->align(FL_ALIGN_INSIDE | FL_ALIGN_TEXT_NEXT_TO_IMAGE);
648 BugMeter->set_tooltip("Show HTML bugs\n(right-click for menu)");
649 BugMeter->callback(bugmeter_cb, this);
650 BugMeter->clear_visible_focus();
651
652 StatusBar->end();
653 StatusBar->resizable(StatusOutput);
655}
656
660UI::UI(int x, int y, int ui_w, int ui_h, const char* label, const UI *cur_ui) :
661 CustGroupVertical(x, y, ui_w, ui_h, label)
662{
663 LocBar = NavBar = StatusBar = NULL;
664
665 Tabs = NULL;
666 TopGroup = this;
667 TopGroup->box(FL_NO_BOX);
668 clear_flag(SHORTCUT_LABEL);
669
670 PanelTemporary = false;
671 if (cur_ui) {
672 PanelSize = cur_ui->PanelSize;
673 Small_Icons = cur_ui->Small_Icons;
674 Panelmode = cur_ui->Panelmode;
675 } else {
676 // Set some default values
680 }
681
682 // Control panel
683 TopGroup->begin();
684 make_panel(ui_w);
685
686 // Render area
687 Main = new Fl_Group(0,0,0,0,"Welcome..."); // size is set by rearrange()
688 Main->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
689 Main->box(FL_FLAT_BOX);
690 Main->labelfont(FL_HELVETICA_BOLD_ITALIC);
691 Main->labelsize(36);
692 Main->labeltype(FL_SHADOW_LABEL);
693 TopGroup->add(Main);
694 TopGroup->resizable(Main);
695 MainIdx = TopGroup->find(Main);
696
697 // Find text bar
698 FindBar = new Findbar(ui_w, fh);
699 TopGroup->add(FindBar);
700
701 // Status Panel
702 make_status_bar(ui_w, ui_h);
703 TopGroup->add(StatusBar);
704 TopGroup->end();
706
707 customize();
708
709 if (Panelmode == UI_HIDDEN) {
711 }
712}
713
718{
719 _MSG("UI::~UI()\n");
720}
721
725int UI::handle(int event)
726{
727 _MSG("UI::handle event=%s\n", fl_eventnames[event]);
728
729 int ret = 0;
730 if (event == FL_KEYBOARD) {
731 return 0; // Receive as shortcut
732 } else if (event == FL_SHORTCUT) {
734 if (cmd == KEYS_NOP) {
735 // Do nothing
736 } else if (cmd == KEYS_SCREEN_UP || cmd == KEYS_SCREEN_DOWN ||
737 cmd == KEYS_SCREEN_LEFT || cmd == KEYS_SCREEN_RIGHT ||
738 cmd == KEYS_LINE_UP || cmd == KEYS_LINE_DOWN ||
739 cmd == KEYS_LEFT || cmd == KEYS_RIGHT ||
740 cmd == KEYS_TOP || cmd == KEYS_BOTTOM) {
742 ret = 1;
743 } else if (cmd == KEYS_BACK) {
745 ret = 1;
746 } else if (cmd == KEYS_FORWARD) {
748 ret = 1;
749 } else if (cmd == KEYS_COPY) {
751 ret = 1;
752 } else if (cmd == KEYS_ZOOM_IN) {
754 ret = 1;
755 } else if (cmd == KEYS_ZOOM_OUT) {
757 ret = 1;
758 } else if (cmd == KEYS_ZOOM_RESET) {
760 ret = 1;
761 } else if (cmd == KEYS_BOOKMARKS) {
763 ret = 1;
764 } else if (cmd == KEYS_FIND) {
766 ret = 1;
767 } else if (cmd == KEYS_WEBSEARCH) {
769 ret = 1;
770 } else if (cmd == KEYS_GOTO) {
772 ret = 1;
773 } else if (cmd == KEYS_HIDE_PANELS) {
774 /* Hide findbar if present, hide panels if not */
775 (FindBar->visible()) ? findbar_toggle(0) : panels_toggle();
776 temporaryPanels(false);
777 ret = 1;
778 } else if (cmd == KEYS_OPEN) {
780 ret = 1;
781 } else if (cmd == KEYS_HOME) {
783 ret = 1;
784 } else if (cmd == KEYS_RELOAD) {
786 ret = 1;
787 } else if (cmd == KEYS_STOP) {
789 ret = 1;
790 } else if (cmd == KEYS_SAVE) {
792 ret = 1;
793 } else if (cmd == KEYS_FILE_MENU) {
795 ret = 1;
796 } else if (cmd == KEYS_VIEW_SOURCE) {
800 ret = 1;
801 } else if (cmd >= KEYS_FOCUS_TAB1 && cmd <= KEYS_FOCUS_TAB10) {
802 int index = cmd - KEYS_FOCUS_TAB1; /* zero-based index */
804 ret = 1;
805 }
806 } else if (event == FL_RELEASE) {
807 if (Fl::event_button() == FL_MIDDLE_MOUSE &&
809 /* nobody claimed the event; try paste */
810 paste_url();
811 ret = 1;
812 }
813 }
814
815 if (!ret) {
816 ret = Fl_Group::handle(event);
817 }
818 if (!ret && event == FL_PUSH && !prefs.middle_click_drags_page) {
819 /* nobody claimed FL_PUSH: ask for FL_RELEASE,
820 * which is necessary for middle-click paste URL) */
821 ret = 1;
822 }
823
824 return ret;
825}
826
827
828//----------------------------
829// API for the User Interface
830//----------------------------
831
835const char *UI::get_location()
836{
837 return Location->value();
838}
839
843void UI::set_location(const char *str)
844{
845 if (!str) str = "";
846 Location->value(str);
847 Location->position((Fl::focus() == Location) ? strlen(str) : 0);
848}
849
855{
856 if (Panelmode == UI_HIDDEN) {
858 temporaryPanels(true);
859 }
860 Location->take_focus();
861 // Make text selected when already focused.
862 Location->position(Location->size(), 0);
863}
864
869{
870 Main->take_focus();
871}
872
876void UI::set_status(const char *str)
877{
878 StatusOutput->value(str);
879}
880
885void UI::set_page_prog(size_t nbytes, int cmd)
886{
887 char str[32];
888
889 if (cmd == 0) {
890 PProg->deactivate();
891 } else {
892 PProg->activate();
893 if (cmd == 1) {
894 char prefix;
895 float magnitude;
896
897 if (nbytes >= 1024 * 1024) {
898 prefix = 'M';
899 magnitude = nbytes / (1024 * 1024.0);
900 } else {
901 prefix = 'K';
902 magnitude = nbytes / 1024.0;
903 }
904 snprintf(str, 32, "%s%.1f %cB",
905 (PanelSize == 0) ? "" : "Page\n", magnitude, prefix);
906 } else if (cmd == 2) {
907 str[0] = '\0';
908 }
909 PProg->update_label(str);
910 }
911}
912
917void UI::set_img_prog(int n_img, int t_img, int cmd)
918{
919 char str[32];
920
921 if (cmd == 0) {
922 IProg->deactivate();
923 } else {
924 IProg->activate();
925 if (cmd == 1) {
926 snprintf(str, 32, "%s%d of %d",
927 (PanelSize == 0) ? "" : "Images\n", n_img, t_img);
928 } else if (cmd == 2) {
929 str[0] = '\0';
930 }
931 IProg->update_label(str);
932 }
933}
934
938void UI::set_bug_prog(int n_bug)
939{
940 char str[32];
941 int new_w = 20;
942
943 if (n_bug == 0) {
944 BugMeter->image(icons->ImgMeterOK);
945 BugMeter->label("");
946 } else if (n_bug >= 1) {
947 if (n_bug == 1)
948 BugMeter->image(icons->ImgMeterBug);
949 snprintf(str, 32, "%d", n_bug);
950 BugMeter->copy_label(str);
951 new_w = strlen(str)*9 + 20;
952 }
953 BugMeter->size(new_w, BugMeter->h());
955}
956
961{
962 if ( !prefs.show_back )
963 Back->hide();
964 if ( !prefs.show_forw )
965 Forw->hide();
966 if ( !prefs.show_home )
967 Home->hide();
968 if ( !prefs.show_reload )
969 Reload->hide();
970 if ( !prefs.show_save )
971 Save->hide();
972 if ( !prefs.show_stop )
973 Stop->hide();
974 if ( !prefs.show_bookmarks )
975 Bookmarks->hide();
976 if ( !prefs.show_tools )
977 Tools->hide();
978 if ( !prefs.show_clear_url )
979 Clear->hide();
980 if ( !prefs.show_url )
981 Location->hide();
982 if ( !prefs.show_search )
983 Search->hide();
984 if ( !prefs.show_help )
985 Help->hide();
986 if ( !prefs.show_progress_box ) {
987 IProg->hide();
988 PProg->hide();
989 }
990
991 if (NavBar)
992 NavBar->rearrange();
993 if (LocBar)
994 LocBar->rearrange();
995}
996
1000void UI::change_panel(int new_size, int small_icons)
1001{
1002 char *loc_text = dStrdup(Location->value());
1003
1004 // Remove current panel's bars
1005 init_sizes();
1006 TopGroup->remove(LocBar);
1007 Fl::delete_widget(LocBar);
1008 TopGroup->remove(NavBar);
1009 Fl::delete_widget(NavBar);
1010 LocBar = NavBar = NULL;
1011
1012 // Set internal vars for panel size
1013 PanelSize = new_size;
1015
1016 // make a new panel
1017 make_panel(TopGroup->w());
1018 customize();
1020
1022 Location->value(loc_text);
1023 Location->take_focus();
1024
1025 dFree(loc_text);
1026}
1027
1031void UI::set_render_layout(Fl_Group *nw)
1032{
1033 // Resize layout widget to current height
1034 nw->resize(0,Main->y(),Main->w(),Main->h());
1035
1036 TopGroup->insert(*nw, Main);
1037 remove(Main);
1038 delete(Main);
1039 Main = nw;
1040 TopGroup->resizable(Main);
1041}
1042
1047{
1048 switch (btn) {
1049 case UI_BACK:
1050 (sens) ? Back->activate() : Back->deactivate();
1051 break;
1052 case UI_FORW:
1053 (sens) ? Forw->activate() : Forw->deactivate();
1054 break;
1055 case UI_STOP:
1056 (sens) ? Stop->activate() : Stop->deactivate();
1057 break;
1058 default:
1059 break;
1060 }
1061}
1062
1067{
1068 Fl::paste(*Clear, false);
1069}
1070
1075{
1076 /* WORKAROUND:
1077 * This is tricky: As fltk-1.3 resizes hidden widgets (which it
1078 * doesn't resize when visible!). We need to set the size to (0,0) to
1079 * get the desired behaviour.
1080 * (STR#2639 in FLTK bug tracker).
1081 */
1082
1083 if (add) {
1084 if (!FindBar->visible())
1085 FindBar->size(w(), fh);
1086 FindBar->show();
1087 } else {
1088 // hide
1089 FindBar->size(0,0);
1090 FindBar->hide();
1091 // reset state
1093 // focus main area
1094 focus_main();
1095 }
1097}
1098
1106{
1107 int hide = StatusBar->visible();
1108
1109 // hide/show panels
1110 init_sizes();
1111 if (LocBar) {
1112 hide ? LocBar->size(0,0) : LocBar->size(w(),lh);
1113 hide ? LocBar->hide() : LocBar->show();
1114 }
1115 if (NavBar) {
1116 hide ? NavBar->size(0,0) : NavBar->size(w(),nh);
1117 hide ? NavBar->hide() : NavBar->show();
1118 }
1119 if (StatusBar) {
1120 hide ? StatusBar->size(0,0) : StatusBar->size(w(),sh);
1121 hide ? StatusBar->hide() : StatusBar->show();
1123 }
1124
1126 Panelmode = (hide) ? UI_HIDDEN : UI_NORMAL;
1127}
#define _MSG(...)
Definition bookmarks.c:45
#define MSG(...)
Definition bookmarks.c:46
A button that highlights on mouse over.
Definition tipwin.hh:49
virtual int handle(int e)
Definition tipwin.cc:181
Used to reposition group's widgets when some of them are hidden.
Definition ui.hh:51
void rearrange()
Definition ui.hh:57
void rearrange()
Definition ui.hh:96
Searchbar to find text in page.
Definition findbar.hh:16
void show()
Show the findbar and focus the input field.
Definition findbar.cc:198
static KeysCommand_t getKeyCmd(void)
Look if the just pressed key is bound to a command.
Definition keys.cc:213
void set_tooltip(const char *s)
Definition tipwin.cc:162
An Input with custom tooltip window.
Definition tipwin.hh:61
virtual int handle(int e)
Definition tipwin.cc:222
Definition ui.hh:123
int sh
Definition ui.hh:139
int mh
Definition ui.hh:139
void set_img_prog(int n_img, int t_img, int cmd)
Set the image progress text.
Definition ui.cc:917
bool PanelTemporary
Definition ui.hh:140
CustButton * Bookmarks
Definition ui.hh:127
CustButton * Search
Definition ui.hh:128
void button_set_sens(UIButton btn, int sens)
Set button sensitivity (Back/Forw/Stop)
Definition ui.cc:1046
~UI()
UI destructor.
Definition ui.cc:717
void customize()
Customize the UI's panel (show/hide buttons)
Definition ui.cc:960
Fl_Group * LocationGroup
Definition ui.hh:132
int p_xpos
Definition ui.hh:139
CustGroupHorizontal * LocBar
Definition ui.hh:129
int nh
Definition ui.hh:139
CustButton * make_button(const char *label, Fl_Image *img, Fl_Image *deimg, int b_n, int start=0)
Make a generic navigation button.
Definition ui.cc:396
CustButton * Stop
Definition ui.hh:127
void findbar_toggle(bool add)
Adjust space for the findbar (if necessary) and show or remove it.
Definition ui.cc:1074
void set_render_layout(Fl_Group *nw)
Set 'nw' as the main render area widget.
Definition ui.cc:1031
CustButton * Save
Definition ui.hh:127
Fl_Output * StatusOutput
Definition ui.hh:133
void focus_main()
Focus Main area.
Definition ui.cc:868
int fh
Definition ui.hh:139
int pw
Definition ui.hh:139
const char * get_location()
Get the text from the location input-box.
Definition ui.cc:835
void make_toolbar(int tw, int th)
Create the archetipic browser buttons.
Definition ui.cc:419
void change_panel(int new_size, int small_icons)
On-the-fly panel style change.
Definition ui.cc:1000
bool temporaryPanels()
Definition ui.hh:181
int lh
Definition ui.hh:139
int bw
Definition ui.hh:139
CustProgressBox * PProg
Definition ui.hh:131
void focus_location()
Focus location entry.
Definition ui.cc:854
int bh
Definition ui.hh:139
int p_ypos
Definition ui.hh:139
int Small_Icons
Definition ui.hh:138
CustButton * Home
Definition ui.hh:127
int handle(int event)
To manage what events to catch and which to let pass.
Definition ui.cc:725
void make_status_bar(int ww, int wh)
Create the status panel.
Definition ui.cc:629
void make_progress_bars(int wide, int thin_up)
Create the progress bars.
Definition ui.cc:503
CustButton * Back
Definition ui.hh:127
CustGroupVertical * TopGroup
Definition ui.hh:126
int MainIdx
Definition ui.hh:136
CustGroupHorizontal * NavBar
Definition ui.hh:129
CustButton * Tools
Definition ui.hh:128
void make_location(int ww)
Create the location box (Clear/Input/Search)
Definition ui.cc:458
CustButton * FileButton
Definition ui.hh:128
Fl_Group * Main
Definition ui.hh:132
CustButton * Reload
Definition ui.hh:127
CustTabs * Tabs
Definition ui.hh:124
CustButton * Help
Definition ui.hh:128
UI(int x, int y, int w, int h, const char *label=0, const UI *cur_ui=NULL)
User Interface constructor.
Definition ui.cc:660
CustProgressBox * IProg
Definition ui.hh:131
void set_bug_prog(int n_bug)
Set the bug meter progress text.
Definition ui.cc:938
Fl_Input * Location
Definition ui.hh:130
CustGroupHorizontal * StatusBar
Definition ui.hh:129
void panels_toggle()
Make panels disappear growing the render area.
Definition ui.cc:1105
CustButton * BugMeter
Definition ui.hh:128
void set_status(const char *str)
Set a new message in the status bar.
Definition ui.cc:876
void paste_url()
Paste a middle-click-selection into "Clear" button as URL.
Definition ui.cc:1066
void make_panel(int ww)
Create the control panel.
Definition ui.cc:549
CustButton * Forw
Definition ui.hh:127
void set_location(const char *str)
Set a new URL in the location input-box.
Definition ui.cc:843
CustButton * Clear
Definition ui.hh:128
int PanelSize
Definition ui.hh:138
Findbar * FindBar
Definition ui.hh:134
UIPanelmode Panelmode
Definition ui.hh:142
int lbl
Definition ui.hh:139
void make_filemenu_button()
Create the "File" menu.
Definition ui.cc:522
void set_page_prog(size_t nbytes, int cmd)
Set the page progress text.
Definition ui.cc:885
char * dStrconcat(const char *s1,...)
Concatenate a NULL-terminated list of strings.
Definition dlib.c:102
void dFree(void *mem)
Definition dlib.c:68
char * dStrdup(const char *s)
Definition dlib.c:77
#define VOIDP2INT(p)
Definition dlib.h:55
#define INT2VOIDP(i)
Definition dlib.h:56
const DilloUrl * a_History_get_url(int idx)
Return the DilloUrl field (by index)
Definition history.c:80
KeysCommand_t
Definition keys.hh:17
@ KEYS_COPY
Definition keys.hh:52
@ KEYS_SCREEN_RIGHT
Definition keys.hh:45
@ KEYS_BOTTOM
Definition keys.hh:51
@ KEYS_STOP
Definition keys.hh:32
@ KEYS_LEFT
Definition keys.hh:48
@ KEYS_FOCUS_TAB10
Definition keys.hh:65
@ KEYS_RELOAD
Definition keys.hh:31
@ KEYS_RIGHT
Definition keys.hh:49
@ KEYS_NOP
Definition keys.hh:19
@ KEYS_BOOKMARKS
Definition keys.hh:30
@ KEYS_BACK
Definition keys.hh:37
@ KEYS_ZOOM_OUT
Definition keys.hh:54
@ KEYS_LINE_UP
Definition keys.hh:46
@ KEYS_WEBSEARCH
Definition keys.hh:29
@ KEYS_ZOOM_RESET
Definition keys.hh:55
@ KEYS_SCREEN_DOWN
Definition keys.hh:43
@ KEYS_GOTO
Definition keys.hh:39
@ KEYS_OPEN
Definition keys.hh:20
@ KEYS_SAVE
Definition keys.hh:33
@ KEYS_FIND
Definition keys.hh:28
@ KEYS_HIDE_PANELS
Definition keys.hh:34
@ KEYS_FILE_MENU
Definition keys.hh:35
@ KEYS_FORWARD
Definition keys.hh:38
@ KEYS_TOP
Definition keys.hh:50
@ KEYS_VIEW_SOURCE
Definition keys.hh:41
@ KEYS_HOME
Definition keys.hh:40
@ KEYS_LINE_DOWN
Definition keys.hh:47
@ KEYS_FOCUS_TAB1
Definition keys.hh:56
@ KEYS_SCREEN_LEFT
Definition keys.hh:44
@ KEYS_SCREEN_UP
Definition keys.hh:42
@ KEYS_ZOOM_IN
Definition keys.hh:53
static void filemenu_cb(Fl_Widget *, void *data)
Static function for File menu callbacks.
Definition menu.cc:70
#define NAV_TOP_UIDX(bw)
Definition nav.h:10
static const char *const home_xpm[]
Definition pixmaps.h:331
static const char *const save_xpm[]
Definition pixmaps.h:462
static const char *const stop_s_xpm[]
Definition pixmaps.h:1178
static const char *const help_xpm[]
Definition pixmaps.h:1494
static const char *const left_s_xpm[]
Definition pixmaps.h:815
static const char *const left_xpm[]
Definition pixmaps.h:17
static const char *const new_s_xpm[]
Definition pixmaps.h:1413
static const char *const stop_xpm[]
Definition pixmaps.h:547
static const char *const search_xpm[]
Definition pixmaps.h:1463
static const char *const mini_bug_xpm[]
Definition pixmaps.h:1530
static const char *const tools_xpm[]
Definition pixmaps.h:762
static const char *const right_s_xpm[]
Definition pixmaps.h:867
static const char *const save_s_xpm[]
Definition pixmaps.h:1108
static const char *const bm_xpm[]
Definition pixmaps.h:650
static const char *const reload_s_xpm[]
Definition pixmaps.h:1015
static const char *const bm_s_xpm[]
Definition pixmaps.h:1263
static const char *const reload_xpm[]
Definition pixmaps.h:159
static const char *const right_xpm[]
Definition pixmaps.h:88
static const char *const home_s_xpm[]
Definition pixmaps.h:942
static const char *const mini_ok_xpm[]
Definition pixmaps.h:1557
static const char *const tools_s_xpm[]
Definition pixmaps.h:1346
DilloPrefs prefs
Global Data.
Definition prefs.c:33
@ P_small
Definition prefs.h:35
@ P_tiny
Definition prefs.h:35
@ P_medium
Definition prefs.h:35
static void b1_cb(Fl_Widget *wid, void *cb_data)
Callback handler for button press on the panel.
Definition ui.cc:303
static void help_cb(Fl_Widget *w, void *)
Callback for the help button.
Definition ui.cc:240
static struct iconset * icons
Definition ui.cc:85
static struct iconset small_icons
Definition ui.cc:65
static struct iconset standard_icons
Definition ui.cc:46
static void bugmeter_cb(Fl_Widget *wid, void *data)
Callback for the bug meter button.
Definition ui.cc:375
static void filemenu_cb(Fl_Widget *wid, void *)
Callback for the File menu button.
Definition ui.cc:260
static void location_cb(Fl_Widget *wid, void *data)
Send the browser to the new URL in the location.
Definition ui.cc:287
static void search_cb(Fl_Widget *wid, void *data)
Callback for the search button.
Definition ui.cc:228
static void clear_cb(Fl_Widget *w, void *data)
Callback for the location's clear-button.
Definition ui.cc:271
@ UI_HIDDEN
Definition ui.hh:32
@ UI_NORMAL
make sure it's compatible with bool
Definition ui.hh:31
UIButton
Definition ui.hh:17
@ UI_BOOK
Definition ui.hh:24
@ UI_RELOAD
Definition ui.hh:21
@ UI_SAVE
Definition ui.hh:22
@ UI_TOOLS
Definition ui.hh:25
@ UI_FORW
Definition ui.hh:19
@ UI_HOME
Definition ui.hh:20
@ UI_BACK
Definition ui.hh:18
@ UI_STOP
Definition ui.hh:23
Contains the specific data for a single window.
Definition bw.h:27
bool_t show_progress_box
Definition prefs.h:96
bool_t show_reload
Definition prefs.h:86
bool_t show_filemenu
Definition prefs.h:91
bool_t small_icons
Definition prefs.h:70
bool_t fullwindow_start
Definition prefs.h:98
bool_t show_help
Definition prefs.h:95
bool_t show_tools
Definition prefs.h:90
bool_t show_search
Definition prefs.h:94
bool_t show_stop
Definition prefs.h:88
int panel_size
Definition prefs.h:69
bool_t middle_click_drags_page
Definition prefs.h:123
bool_t show_home
Definition prefs.h:85
bool_t show_save
Definition prefs.h:87
bool_t show_clear_url
Definition prefs.h:92
bool_t show_back
Definition prefs.h:83
bool_t show_bookmarks
Definition prefs.h:89
double font_factor
Definition prefs.h:75
bool_t show_url
Definition prefs.h:93
bool_t show_forw
Definition prefs.h:84
Definition url.h:88
static void path()
Definition cookies.c:859
void a_UIcmd_tools(void *vbw, int x, int y)
Definition uicmd.cc:1184
void a_UIcmd_book(void *vbw, int nt)
Definition uicmd.cc:1282
void a_UIcmd_bugmeter_popup(void *vbw)
Definition uicmd.cc:1410
void a_UIcmd_forw_nt(void *vbw)
Definition uicmd.cc:907
void a_UIcmd_home(void *vbw, int nt)
Definition uicmd.cc:923
void a_UIcmd_open_file(void *vbw)
Definition uicmd.cc:1192
void a_UIcmd_zoom_reset(void *vbw)
Definition uicmd.cc:1013
void a_UIcmd_focus_tab(void *vbw, int index)
Definition uicmd.cc:1708
void a_UIcmd_zoom_in(void *vbw)
Definition uicmd.cc:981
void a_UIcmd_zoom_out(void *vbw)
Definition uicmd.cc:997
void a_UIcmd_focus_main_area(BrowserWindow *bw)
Definition uicmd.cc:1691
void a_UIcmd_reload(void *vbw)
Definition uicmd.cc:934
BrowserWindow * a_UIcmd_get_bw_by_widget(void *v_wid)
Definition uicmd.cc:553
void a_UIcmd_file_popup(void *vbw, void *v_wid)
Definition uicmd.cc:1342
void a_UIcmd_view_page_source(BrowserWindow *bw, const DilloUrl *url)
Definition uicmd.cc:1361
void a_UIcmd_search_dialog(void *vbw)
Definition uicmd.cc:1247
void a_UIcmd_view_page_bugs(void *vbw)
Definition uicmd.cc:1396
void a_UIcmd_open_urlstr(void *vbw, const char *urlstr)
Definition uicmd.cc:770
void a_UIcmd_set_buttons_sens(BrowserWindow *bw)
Definition uicmd.cc:1623
void a_UIcmd_forw_popup(void *vbw, int x, int y)
Definition uicmd.cc:915
void a_UIcmd_save(void *vbw)
Definition uicmd.cc:1149
void a_UIcmd_back(void *vbw)
Definition uicmd.cc:875
void a_UIcmd_forw(void *vbw)
Definition uicmd.cc:899
void a_UIcmd_copy(void *vbw)
Definition uicmd.cc:971
void a_UIcmd_back_popup(void *vbw, int x, int y)
Definition uicmd.cc:891
void a_UIcmd_stop(void *vbw)
Definition uicmd.cc:1171
void a_UIcmd_findtext_reset(BrowserWindow *bw)
Definition uicmd.cc:1672
void a_UIcmd_scroll(BrowserWindow *bw, int icmd)
Definition uicmd.cc:1502
void a_UIcmd_back_nt(void *vbw)
Definition uicmd.cc:883
void a_UIcmd_set_location_text(void *vbw, const char *text)
Definition uicmd.cc:1546