Dillo v3.2.0-90-g29a46a2d
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
93#define DILLO_INPUTBOX (Fl_Boxtype) (FL_FREE_BOXTYPE + 1)
94
98class CustInput : public TipWinInput {
99public:
100 static const int margin_x = 3;
101 CustInput (int x, int y, int w, int h, const char* l=0) :
102 TipWinInput(x,y,w,h,l) {
103 /* Increase the margin of the current box by making a new clone
104 * of the current box with extra margin on dx. */
105 Fl_Boxtype b = box();
106 Fl::set_boxtype(DILLO_INPUTBOX, Fl::get_boxtype(b),
107 Fl::box_dx(b) + margin_x,
108 Fl::box_dy(b),
109 Fl::box_dw(b) + margin_x,
110 Fl::box_dh(b));
111 box(DILLO_INPUTBOX);
112 }
113 virtual int handle(int e);
114};
115
120int CustInput::handle(int e)
121{
122 int k = Fl::event_key();
123
124 _MSG("CustInput::handle event=%d\n", e);
125
126 // We're only interested in some flags
127 unsigned modifier = Fl::event_state() & (FL_SHIFT | FL_CTRL | FL_ALT);
128
129 // Don't focus with arrow keys
130 if (e == FL_FOCUS &&
131 (k == FL_Up || k == FL_Down || k == FL_Left || k == FL_Right)) {
132 return 0;
133 } else if (e == FL_KEYBOARD) {
134 if (k == FL_Escape && modifier == 0) {
135 // Let the parent group handle this Esc key
136 return 0;
137 } else if (modifier == FL_SHIFT) {
138 if (k == FL_Left || k == FL_Right) {
139 // Let these keys get to the UI
140 return 0;
141 }
142 } else if (modifier == FL_CTRL) {
143 if (k == 'e') {
144 position(size());
145 return 1;
146 } else if (k == 'k') {
147 cut(position(), size());
148 return 1;
149 } else if (k == 'd') {
150 cut(position(), position()+1);
151 return 1;
152 } else if (k == 'a' || k == 'l') {
153 // Make text selected when already focused.
154 position(size(), 0);
155 return 1;
156 } else if (k == 'h' || k == 'o' || k == 'r' ||
157 k == FL_Home || k == FL_End) {
158 // Let these keys get to the UI
159 return 0;
160 }
161 } else if (modifier == 0) {
162 if (k == FL_Down || k == FL_Up ||
163 k == FL_Page_Down || k == FL_Page_Up || k == FL_Tab) {
164 // Give up focus and honor the key
166 return 0;
167 }
168 }
169 if (k == FL_Page_Down || k == FL_Page_Up) {
170 // These do nothing of interest when FL_MULTILINE_INPUT isn't set.
171 // Let them through for key commands.
172 return 0;
173 }
174 }
175
176 return TipWinInput::handle(e);
177}
178
179//----------------------------------------------------------------------------
180
184class CustPasteButton : public CustButton {
185public:
186 CustPasteButton(int x, int y, int w, int h, const char *l=0) :
187 CustButton(x,y,w,h,l) {};
188 int handle(int e);
189};
190
191int CustPasteButton::handle(int e)
192{
193 if (e == FL_PASTE) {
194 const char* t = Fl::event_text();
195 if (t && *t) {
198 return 1;
199 }
200 }
201 return CustButton::handle(e);
202}
203
204//----------------------------------------------------------------------------
205
209class CustProgressBox : public Fl_Box {
210 int padding;
211public:
212 CustProgressBox(int x, int y, int w, int h, const char *l=0) :
213 Fl_Box(x,y,w,h,l) { padding = 0; };
214 void update_label(const char *lbl) {
215 int w = 0, h = 0;
216 if (!padding) {
217 copy_label("W");
218 measure_label(w, h);
219 padding = w > 2 ? w/2 : 1;
220 }
221 copy_label(lbl);
222 }
223};
224
225//
226// Toolbar buttons -----------------------------------------------------------
227//
228//static const char *button_names[] = {
229// "Back", "Forward", "Home", "Reload", "Save", "Stop", "Bookmarks", "Tools",
230// "Clear", "Search"
231//};
232
233
234//
235// Callback functions --------------------------------------------------------
236//
237
241static void search_cb(Fl_Widget *wid, void *data)
242{
243 int b = Fl::event_button();
244
245 if (b == FL_LEFT_MOUSE) {
247 }
248}
249
253static void help_cb(Fl_Widget *w, void *)
254{
255 char *path = dStrconcat(DILLO_DOCDIR, "user_help.html", NULL);
257
258 if (access(path, R_OK) == 0) {
259 char *urlstr = dStrconcat("file:", path, NULL);
260 a_UIcmd_open_urlstr(bw, urlstr);
261 dFree(urlstr);
262 } else {
263 MSG("Can't read local help file at \"%s\"."
264 " Getting remote help...\n", path);
265 a_UIcmd_open_urlstr(bw, "https://dillo-browser.github.io/user_help.html");
266 }
267 dFree(path);
268}
269
273static void filemenu_cb(Fl_Widget *wid, void *)
274{
275 int b = Fl::event_button();
276 if (b == FL_LEFT_MOUSE || b == FL_RIGHT_MOUSE) {
278 }
279}
280
284static void clear_cb(Fl_Widget *w, void *data)
285{
286 UI *ui = (UI*)data;
287
288 int b = Fl::event_button();
289 if (b == FL_LEFT_MOUSE) {
290 ui->set_location("");
291 ui->focus_location();
292 } else if (b == FL_MIDDLE_MOUSE) {
293 ui->paste_url();
294 }
295}
296
300static void location_cb(Fl_Widget *wid, void *data)
301{
302 Fl_Input *i = (Fl_Input*)wid;
303 UI *ui = (UI*)data;
304
305 _MSG("location_cb()\n");
307
308 if (ui->temporaryPanels())
309 ui->panels_toggle();
310}
311
312
316static void b1_cb(Fl_Widget *wid, void *cb_data)
317{
318 int bn = VOIDP2INT(cb_data);
319 int b = Fl::event_button();
320 if (b >= FL_LEFT_MOUSE && b <= FL_RIGHT_MOUSE) {
321 _MSG("[%s], mouse button %d was pressed\n", button_names[bn], b);
322 _MSG("mouse button %d was pressed\n", b);
323 }
324 switch (bn) {
325 case UI_BACK:
326 if (b == FL_LEFT_MOUSE) {
328 } else if (b == FL_MIDDLE_MOUSE) {
330 } else if (b == FL_RIGHT_MOUSE) {
332 wid->y() + wid->h());
333 }
334 break;
335 case UI_FORW:
336 if (b == FL_LEFT_MOUSE) {
338 } else if (b == FL_MIDDLE_MOUSE) {
340 } else if (b == FL_RIGHT_MOUSE) {
342 wid->y() + wid->h());
343 }
344 break;
345 case UI_HOME:
346 if (b == FL_LEFT_MOUSE) {
348 } else if (b == FL_MIDDLE_MOUSE) {
350 }
351 break;
352 case UI_RELOAD:
353 if (b == FL_LEFT_MOUSE) {
355 }
356 break;
357 case UI_SAVE:
358 if (b == FL_LEFT_MOUSE) {
360 }
361 break;
362 case UI_STOP:
363 if (b == FL_LEFT_MOUSE) {
365 }
366 break;
367 case UI_BOOK:
368 if (b == FL_LEFT_MOUSE) {
370 } else if (b == FL_MIDDLE_MOUSE) {
372 }
373 break;
374 case UI_TOOLS:
375 if (b == FL_LEFT_MOUSE || b == FL_RIGHT_MOUSE) {
377 wid->y() + wid->h());
378 }
379 break;
380 default:
381 break;
382 }
383}
384
388static void bugmeter_cb(Fl_Widget *wid, void *data)
389{
390 int b = Fl::event_button();
391 if (b == FL_LEFT_MOUSE) {
393 } else if (b == FL_RIGHT_MOUSE) {
395 }
396}
397
399// UI class methods
400//
401
402//----------------------------
403// Panel construction methods
404//----------------------------
405
409CustButton *UI::make_button(const char *label, Fl_Image *img, Fl_Image *deimg,
410 int b_n, int start)
411{
412 if (start)
413 p_xpos = 0;
414
415 CustButton *b = new CustButton(p_xpos, 0, bw, bh, (lbl) ? label : NULL);
416 if (img)
417 b->image(img);
418 if (deimg)
419 b->deimage(deimg);
420 b->callback(b1_cb, INT2VOIDP(b_n));
421 b->clear_visible_focus();
422 b->labelsize(12);
423 b->box(FL_FLAT_BOX);
424 b->down_box(FL_THIN_DOWN_FRAME);
425 p_xpos += bw;
426 return b;
427}
428
432void UI::make_toolbar(int tw, int th)
433{
434 if (!icons->ImgLeftIn) {
435 icons->ImgLeftIn = icons->ImgLeft->copy();
436 icons->ImgLeftIn->desaturate();
437 icons->ImgLeftIn->color_average(FL_BACKGROUND_COLOR, .14f);
438 }
439 if (!icons->ImgRightIn) {
440 icons->ImgRightIn = icons->ImgRight->copy();
441 icons->ImgRightIn->desaturate();
442 icons->ImgRightIn->color_average(FL_BACKGROUND_COLOR, .14f);
443 }
444 if (!icons->ImgStopIn) {
445 icons->ImgStopIn = icons->ImgStop->copy();
446 icons->ImgStopIn->desaturate();
447 icons->ImgStopIn->color_average(FL_BACKGROUND_COLOR, .14f);
448 }
449 Back = make_button("Back", icons->ImgLeft, icons->ImgLeftIn, UI_BACK, 1);
450 Forw = make_button("Forw", icons->ImgRight, icons->ImgRightIn, UI_FORW);
451 Home = make_button("Home", icons->ImgHome, NULL, UI_HOME);
452 Reload = make_button("Reload", icons->ImgReload, NULL, UI_RELOAD);
453 Save = make_button("Save", icons->ImgSave, NULL, UI_SAVE);
454 Stop = make_button("Stop", icons->ImgStop, icons->ImgStopIn, UI_STOP);
455 Bookmarks = make_button("Book", icons->ImgBook, NULL, UI_BOOK);
456 Tools = make_button("Tools", icons->ImgTools, NULL, UI_TOOLS);
457
458 Back->set_tooltip("Previous page");
459 Forw->set_tooltip("Next page");
460 Home->set_tooltip("Go to the Home page\nMiddle-click for new tab.");
461 Reload->set_tooltip("Reload");
462 Save->set_tooltip("Save this page");
463 Stop->set_tooltip("Stop loading");
464 Bookmarks->set_tooltip("View bookmarks\nMiddle-click for new tab.");
465 Tools->set_tooltip("Settings");
466}
467
472{
473 CustButton *b;
474
475 b = Clear = (CustButton*) new CustPasteButton(p_xpos,0,16,lh,0);
476 b->image(icons->ImgClear);
477 b->callback(clear_cb, this);
478 b->clear_visible_focus();
479 b->box(FL_THIN_UP_BOX);
480 b->set_tooltip("Clear the URL box.\nMiddle-click to paste a URL.");
481 p_xpos += b->w();
482
483 LocationGroup = new Fl_Group(p_xpos,0,ww-p_xpos-32,lh,0);
484 LocationGroup->begin();
485 CustInput *i = new CustInput(p_xpos,0,ww-p_xpos-32,lh,0);
486 Location = i;
487 i->when(FL_WHEN_ENTER_KEY);
488 i->callback(location_cb, this);
489 i->set_tooltip("Location");
490 i->textsize((int) rint(14.0 * prefs.font_factor));
491 p_xpos += i->w();
492 LocationGroup->box(FL_THIN_UP_BOX); // or FL_FLAT_BOX
493 LocationGroup->end();
494
495 Search = b = new CustButton(p_xpos,0,16,lh,0);
496 b->image(icons->ImgSearch);
497 b->callback(search_cb, this);
498 b->clear_visible_focus();
499 b->box(FL_THIN_UP_BOX);
500 b->set_tooltip("Search the Web");
501 p_xpos += b->w();
502
503 Help = b = new CustButton(p_xpos,0,16,lh,0);
504 b->image(icons->ImgHelp);
505 b->callback(help_cb, this);
506 b->clear_visible_focus();
507 b->box(FL_THIN_UP_BOX);
508 b->set_tooltip("Help");
509 p_xpos += b->w();
510
511}
512
516void UI::make_progress_bars(int wide, int thin_up)
517{
518 // Images
519 IProg = new CustProgressBox(p_xpos,p_ypos,pw,bh);
520 IProg->labelsize(12);
521 IProg->box(thin_up ? FL_THIN_UP_BOX : FL_EMBOSSED_BOX);
522 IProg->update_label(wide ? "Images\n0 of 0" : "0 of 0");
523 p_xpos += pw;
524 // Page
525 PProg = new CustProgressBox(p_xpos,p_ypos,pw,bh);
526 PProg->labelsize(12);
527 PProg->box(thin_up ? FL_THIN_UP_BOX : FL_EMBOSSED_BOX);
528 PProg->update_label(wide ? "Page\n0.0 KB" : "0.0 KB");
529}
530
536{
537 CustButton *btn;
538 int w = 0, h = 0, padding;
539
540 FileButton = btn = new CustButton(p_xpos,0,bw,bh,"W");
541 btn->labeltype(FL_FREE_LABELTYPE);
542 btn->measure_label(w, h);
543 padding = w;
544 btn->copy_label(PanelSize == P_tiny ? "&F" : "&File");
545 btn->measure_label(w,h);
546 h = (PanelSize == P_tiny) ? bh : lh;
547 btn->size(w+padding, h);
548 p_xpos += btn->w();
549 _MSG("UI::make_filemenu_button w=%d h=%d padding=%d\n", w, h, padding);
550 btn->box(FL_THIN_UP_BOX);
551 btn->callback(filemenu_cb, this);
552 btn->set_tooltip("File menu");
553 btn->clear_visible_focus();
554 if (!prefs.show_filemenu)
555 btn->hide();
556}
557
558
562void UI::make_panel(int ww)
563{
564 Fl_Widget *w;
565
566 if (Small_Icons)
568 else
570
571 pw = 70;
572 p_xpos = p_ypos = 0;
573 if (PanelSize == P_tiny) {
574 if (Small_Icons)
575 bw = 22, bh = 22, mh = 0, lh = 22, lbl = 0;
576 else
577 bw = 28, bh = 28, mh = 0, lh = 28, lbl = 0;
578 } else if (PanelSize == P_small) {
579 if (Small_Icons)
580 bw = 20, bh = 20, mh = 0, lh = 20, lbl = 0;
581 else
582 bw = 28, bh = 28, mh = 0, lh = 28, lbl = 0;
583 } else if (PanelSize == P_medium) {
584 if (Small_Icons)
585 bw = 42, bh = 36, mh = 0, lh = 22, lbl = 1;
586 else
587 bw = 45, bh = 45, mh = 0, lh = 28, lbl = 1;
588 }
589 nh = bh, fh = 28; sh = 20;
590
591 current(0);
592 if (PanelSize == P_tiny) {
593 NavBar = new CustGroupHorizontal(0,0,ww,nh);
594 NavBar->box(FL_NO_BOX);
595 NavBar->begin();
596 make_toolbar(ww,bh);
598 make_location(ww);
599 NavBar->resizable(LocationGroup);
601 NavBar->box(FL_THIN_UP_FRAME);
602 NavBar->end();
603 NavBar->rearrange();
604 TopGroup->insert(*NavBar,0);
605 } else {
606 // Location
607 LocBar = new CustGroupHorizontal(0,0,ww,lh);
608 LocBar->box(FL_NO_BOX);
609 LocBar->begin();
610 p_xpos = 0;
612 make_location(ww);
613 LocBar->resizable(LocationGroup);
614 LocBar->end();
615 LocBar->rearrange();
616 TopGroup->insert(*LocBar,0);
617
618 // Toolbar
619 p_ypos = 0;
620 NavBar = new CustGroupHorizontal(0,0,ww,bh);
621 NavBar->box(FL_NO_BOX);
622 NavBar->begin();
623 make_toolbar(ww,bh);
624 w = new Fl_Box(p_xpos,0,ww-p_xpos-2*pw,bh);
625 w->box(FL_FLAT_BOX);
626 NavBar->resizable(w);
627 p_xpos = ww - 2*pw;
628 if (PanelSize == P_small) {
630 } else {
632 }
633 NavBar->end();
634 NavBar->rearrange();
635 TopGroup->insert(*NavBar,1);
636 }
637}
638
642void UI::make_status_bar(int ww, int wh)
643{
644 const int bm_w = 20;
645 StatusBar = new CustGroupHorizontal(0, wh-sh, ww, sh);
646 StatusBar->box(FL_NO_BOX);
647
648 // Status box
649 StatusOutput = new Fl_Output(0, wh-sh, ww-bm_w, sh);
650 StatusOutput->value("https://dillo-browser.github.io/");
651 StatusOutput->labelsize(8);
652 StatusOutput->box(FL_THIN_DOWN_BOX);
653 StatusOutput->clear_visible_focus();
654 StatusOutput->color(FL_BACKGROUND_COLOR);
655
656 // Bug Meter
657 BugMeter = new CustButton(ww-bm_w,wh-sh,bm_w,sh);
658 BugMeter->image(icons->ImgMeterOK);
659 BugMeter->box(FL_THIN_DOWN_BOX);
660 BugMeter->align(FL_ALIGN_INSIDE | FL_ALIGN_TEXT_NEXT_TO_IMAGE);
661 BugMeter->set_tooltip("Show HTML bugs\n(right-click for menu)");
662 BugMeter->callback(bugmeter_cb, this);
663 BugMeter->clear_visible_focus();
664
665 StatusBar->end();
666 StatusBar->resizable(StatusOutput);
668}
669
673UI::UI(int x, int y, int ui_w, int ui_h, const char* label, const UI *cur_ui) :
674 CustGroupVertical(x, y, ui_w, ui_h, label)
675{
676 LocBar = NavBar = StatusBar = NULL;
677
678 Tabs = NULL;
679 TopGroup = this;
680 TopGroup->box(FL_NO_BOX);
681 clear_flag(SHORTCUT_LABEL);
682
683 PanelTemporary = false;
684 if (cur_ui) {
685 PanelSize = cur_ui->PanelSize;
686 Small_Icons = cur_ui->Small_Icons;
687 Panelmode = cur_ui->Panelmode;
688 } else {
689 // Set some default values
693 }
694
695 // Control panel
696 TopGroup->begin();
697 make_panel(ui_w);
698
699 // Render area
700 Main = new Fl_Group(0,0,0,0,"Welcome..."); // size is set by rearrange()
701 Main->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
702 Main->box(FL_FLAT_BOX);
703 Main->labelfont(FL_HELVETICA_BOLD_ITALIC);
704 Main->labelsize(36);
705 Main->labeltype(FL_SHADOW_LABEL);
706 TopGroup->add(Main);
707 TopGroup->resizable(Main);
708 MainIdx = TopGroup->find(Main);
709
710 // Find text bar
711 FindBar = new Findbar(ui_w, fh);
712 TopGroup->add(FindBar);
713
714 // Status Panel
715 make_status_bar(ui_w, ui_h);
716 TopGroup->add(StatusBar);
717 TopGroup->end();
719
720 customize();
721
722 if (Panelmode == UI_HIDDEN) {
724 }
725}
726
731{
732 _MSG("UI::~UI()\n");
733}
734
738int UI::handle(int event)
739{
740 _MSG("UI::handle event=%s\n", fl_eventnames[event]);
741
742 int ret = 0;
743 if (event == FL_KEYBOARD) {
744 return 0; // Receive as shortcut
745 } else if (event == FL_SHORTCUT) {
747 if (cmd == KEYS_NOP) {
748 // Do nothing
749 } else if (cmd == KEYS_SCREEN_UP || cmd == KEYS_SCREEN_DOWN ||
750 cmd == KEYS_SCREEN_LEFT || cmd == KEYS_SCREEN_RIGHT ||
751 cmd == KEYS_LINE_UP || cmd == KEYS_LINE_DOWN ||
752 cmd == KEYS_LEFT || cmd == KEYS_RIGHT ||
753 cmd == KEYS_TOP || cmd == KEYS_BOTTOM) {
755 ret = 1;
756 } else if (cmd == KEYS_BACK) {
758 ret = 1;
759 } else if (cmd == KEYS_FORWARD) {
761 ret = 1;
762 } else if (cmd == KEYS_COPY) {
764 ret = 1;
765 } else if (cmd == KEYS_ZOOM_IN) {
767 ret = 1;
768 } else if (cmd == KEYS_ZOOM_OUT) {
770 ret = 1;
771 } else if (cmd == KEYS_ZOOM_RESET) {
773 ret = 1;
774 } else if (cmd == KEYS_BOOKMARKS) {
776 ret = 1;
777 } else if (cmd == KEYS_FIND) {
779 ret = 1;
780 } else if (cmd == KEYS_WEBSEARCH) {
782 ret = 1;
783 } else if (cmd == KEYS_GOTO) {
785 ret = 1;
786 } else if (cmd == KEYS_HIDE_PANELS) {
787 /* Hide findbar if present, hide panels if not */
788 (FindBar->visible()) ? findbar_toggle(0) : panels_toggle();
789 temporaryPanels(false);
790 ret = 1;
791 } else if (cmd == KEYS_OPEN) {
793 ret = 1;
794 } else if (cmd == KEYS_HOME) {
796 ret = 1;
797 } else if (cmd == KEYS_RELOAD) {
799 ret = 1;
800 } else if (cmd == KEYS_STOP) {
802 ret = 1;
803 } else if (cmd == KEYS_SAVE) {
805 ret = 1;
806 } else if (cmd == KEYS_FILE_MENU) {
808 ret = 1;
809 } else if (cmd == KEYS_VIEW_SOURCE) {
813 ret = 1;
814 } else if (cmd >= KEYS_FOCUS_TAB1 && cmd <= KEYS_FOCUS_TAB10) {
815 int index = cmd - KEYS_FOCUS_TAB1; /* zero-based index */
817 ret = 1;
818 }
819 } else if (event == FL_RELEASE) {
820 if (Fl::event_button() == FL_MIDDLE_MOUSE &&
822 /* nobody claimed the event; try paste */
823 paste_url();
824 ret = 1;
825 }
826 }
827
828 if (!ret) {
829 ret = Fl_Group::handle(event);
830 }
831 if (!ret && event == FL_PUSH && !prefs.middle_click_drags_page) {
832 /* nobody claimed FL_PUSH: ask for FL_RELEASE,
833 * which is necessary for middle-click paste URL) */
834 ret = 1;
835 }
836
837 return ret;
838}
839
840
841//----------------------------
842// API for the User Interface
843//----------------------------
844
848const char *UI::get_location()
849{
850 return Location->value();
851}
852
856void UI::set_location(const char *str)
857{
858 if (!str) str = "";
859 Location->value(str);
860 Location->position((Fl::focus() == Location) ? strlen(str) : 0);
861}
862
868{
869 if (Panelmode == UI_HIDDEN) {
871 temporaryPanels(true);
872 }
873 Location->take_focus();
874 // Make text selected when already focused.
875 Location->position(Location->size(), 0);
876}
877
882{
883 Main->take_focus();
884}
885
889void UI::set_status(const char *str)
890{
891 StatusOutput->value(str);
892}
893
898void UI::set_page_prog(size_t nbytes, int cmd)
899{
900 char str[32];
901
902 if (cmd == 0) {
903 PProg->deactivate();
904 } else {
905 PProg->activate();
906 if (cmd == 1) {
907 char prefix;
908 float magnitude;
909
910 if (nbytes >= 1024 * 1024) {
911 prefix = 'M';
912 magnitude = nbytes / (1024 * 1024.0);
913 } else {
914 prefix = 'K';
915 magnitude = nbytes / 1024.0;
916 }
917 snprintf(str, 32, "%s%.1f %cB",
918 (PanelSize == 0) ? "" : "Page\n", magnitude, prefix);
919 } else if (cmd == 2) {
920 str[0] = '\0';
921 }
922 PProg->update_label(str);
923 }
924}
925
930void UI::set_img_prog(int n_img, int t_img, int cmd)
931{
932 char str[32];
933
934 if (cmd == 0) {
935 IProg->deactivate();
936 } else {
937 IProg->activate();
938 if (cmd == 1) {
939 snprintf(str, 32, "%s%d of %d",
940 (PanelSize == 0) ? "" : "Images\n", n_img, t_img);
941 } else if (cmd == 2) {
942 str[0] = '\0';
943 }
944 IProg->update_label(str);
945 }
946}
947
951void UI::set_bug_prog(int n_bug)
952{
953 char str[32];
954 int new_w = 20;
955
956 if (n_bug == 0) {
957 BugMeter->image(icons->ImgMeterOK);
958 BugMeter->label("");
959 } else if (n_bug >= 1) {
960 if (n_bug == 1)
961 BugMeter->image(icons->ImgMeterBug);
962 snprintf(str, 32, "%d", n_bug);
963 BugMeter->copy_label(str);
964 new_w = strlen(str)*9 + 20;
965 }
966 BugMeter->size(new_w, BugMeter->h());
968}
969
974{
975 if ( !prefs.show_back )
976 Back->hide();
977 if ( !prefs.show_forw )
978 Forw->hide();
979 if ( !prefs.show_home )
980 Home->hide();
981 if ( !prefs.show_reload )
982 Reload->hide();
983 if ( !prefs.show_save )
984 Save->hide();
985 if ( !prefs.show_stop )
986 Stop->hide();
987 if ( !prefs.show_bookmarks )
988 Bookmarks->hide();
989 if ( !prefs.show_tools )
990 Tools->hide();
991 if ( !prefs.show_clear_url )
992 Clear->hide();
993 if ( !prefs.show_url )
994 Location->hide();
995 if ( !prefs.show_search )
996 Search->hide();
997 if ( !prefs.show_help )
998 Help->hide();
999 if ( !prefs.show_progress_box ) {
1000 IProg->hide();
1001 PProg->hide();
1002 }
1003
1004 if (NavBar)
1005 NavBar->rearrange();
1006 if (LocBar)
1007 LocBar->rearrange();
1008}
1009
1013void UI::change_panel(int new_size, int small_icons)
1014{
1015 char *loc_text = dStrdup(Location->value());
1016
1017 // Remove current panel's bars
1018 init_sizes();
1019 TopGroup->remove(LocBar);
1020 Fl::delete_widget(LocBar);
1021 TopGroup->remove(NavBar);
1022 Fl::delete_widget(NavBar);
1023 LocBar = NavBar = NULL;
1024
1025 // Set internal vars for panel size
1026 PanelSize = new_size;
1028
1029 // make a new panel
1030 make_panel(TopGroup->w());
1031 customize();
1033
1035 Location->value(loc_text);
1036 Location->take_focus();
1037
1038 dFree(loc_text);
1039}
1040
1044void UI::set_render_layout(Fl_Group *nw)
1045{
1046 // Resize layout widget to current height
1047 nw->resize(0,Main->y(),Main->w(),Main->h());
1048
1049 TopGroup->insert(*nw, Main);
1050 remove(Main);
1051 delete(Main);
1052 Main = nw;
1053 TopGroup->resizable(Main);
1054}
1055
1060{
1061 switch (btn) {
1062 case UI_BACK:
1063 (sens) ? Back->activate() : Back->deactivate();
1064 break;
1065 case UI_FORW:
1066 (sens) ? Forw->activate() : Forw->deactivate();
1067 break;
1068 case UI_STOP:
1069 (sens) ? Stop->activate() : Stop->deactivate();
1070 break;
1071 default:
1072 break;
1073 }
1074}
1075
1080{
1081 Fl::paste(*Clear, false);
1082}
1083
1088{
1089 /* WORKAROUND:
1090 * This is tricky: As fltk-1.3 resizes hidden widgets (which it
1091 * doesn't resize when visible!). We need to set the size to (0,0) to
1092 * get the desired behaviour.
1093 * (STR#2639 in FLTK bug tracker).
1094 */
1095
1096 if (add) {
1097 if (!FindBar->visible())
1098 FindBar->size(w(), fh);
1099 FindBar->show();
1100 } else {
1101 // hide
1102 FindBar->size(0,0);
1103 FindBar->hide();
1104 // reset state
1106 // focus main area
1107 focus_main();
1108 }
1110}
1111
1119{
1120 int hide = StatusBar->visible();
1121
1122 // hide/show panels
1123 init_sizes();
1124 if (LocBar) {
1125 hide ? LocBar->size(0,0) : LocBar->size(w(),lh);
1126 hide ? LocBar->hide() : LocBar->show();
1127 }
1128 if (NavBar) {
1129 hide ? NavBar->size(0,0) : NavBar->size(w(),nh);
1130 hide ? NavBar->hide() : NavBar->show();
1131 }
1132 if (StatusBar) {
1133 hide ? StatusBar->size(0,0) : StatusBar->size(w(),sh);
1134 hide ? StatusBar->hide() : StatusBar->show();
1136 }
1137
1139 Panelmode = (hide) ? UI_HIDDEN : UI_NORMAL;
1140}
#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:930
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:1059
~UI()
UI destructor.
Definition ui.cc:730
void customize()
Customize the UI's panel (show/hide buttons)
Definition ui.cc:973
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:409
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:1087
void set_render_layout(Fl_Group *nw)
Set 'nw' as the main render area widget.
Definition ui.cc:1044
CustButton * Save
Definition ui.hh:127
Fl_Output * StatusOutput
Definition ui.hh:133
void focus_main()
Focus Main area.
Definition ui.cc:881
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:848
void make_toolbar(int tw, int th)
Create the archetipic browser buttons.
Definition ui.cc:432
void change_panel(int new_size, int small_icons)
On-the-fly panel style change.
Definition ui.cc:1013
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:867
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:738
void make_status_bar(int ww, int wh)
Create the status panel.
Definition ui.cc:642
void make_progress_bars(int wide, int thin_up)
Create the progress bars.
Definition ui.cc:516
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:471
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:673
CustProgressBox * IProg
Definition ui.hh:131
void set_bug_prog(int n_bug)
Set the bug meter progress text.
Definition ui.cc:951
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:1118
CustButton * BugMeter
Definition ui.hh:128
void set_status(const char *str)
Set a new message in the status bar.
Definition ui.cc:889
void paste_url()
Paste a middle-click-selection into "Clear" button as URL.
Definition ui.cc:1079
void make_panel(int ww)
Create the control panel.
Definition ui.cc:562
CustButton * Forw
Definition ui.hh:127
void set_location(const char *str)
Set a new URL in the location input-box.
Definition ui.cc:856
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:535
void set_page_prog(size_t nbytes, int cmd)
Set the page progress text.
Definition ui.cc:898
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:316
static void help_cb(Fl_Widget *w, void *)
Callback for the help button.
Definition ui.cc:253
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
#define DILLO_INPUTBOX
Definition ui.cc:93
static void bugmeter_cb(Fl_Widget *wid, void *data)
Callback for the bug meter button.
Definition ui.cc:388
static void filemenu_cb(Fl_Widget *wid, void *)
Callback for the File menu button.
Definition ui.cc:273
static void location_cb(Fl_Widget *wid, void *data)
Send the browser to the new URL in the location.
Definition ui.cc:300
static void search_cb(Fl_Widget *wid, void *data)
Callback for the search button.
Definition ui.cc:241
static void clear_cb(Fl_Widget *w, void *data)
Callback for the location's clear-button.
Definition ui.cc:284
@ 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