Dillo v3.2.0-93-g6a586845
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
39/* FLTK versions prior to 1.3.10 didn't define back or forward buttons.
40 * They are now mapped to 4 and 5, but the raw values for X11 are 8 and 9. */
41#if (FL_MAJOR_VERSION == 1 && FL_MINOR_VERSION == 3 && FL_PATCH_VERSION < 10)
42#define FL_BACK_MOUSE 8
43#define FL_FORWARD_MOUSE 9
44#endif
45
46struct iconset {
47 Fl_Image *ImgMeterOK, *ImgMeterBug,
48 *ImgHome, *ImgReload, *ImgSave, *ImgBook, *ImgTools,
49 *ImgClear,*ImgSearch, *ImgHelp, *ImgLeft, *ImgLeftIn,
50 *ImgRight, *ImgRightIn, *ImgStop, *ImgStopIn;
51};
52
53static struct iconset standard_icons = {
54 new Fl_Pixmap(mini_ok_xpm),
55 new Fl_Pixmap(mini_bug_xpm),
56 new Fl_Pixmap(home_xpm),
57 new Fl_Pixmap(reload_xpm),
58 new Fl_Pixmap(save_xpm),
59 new Fl_Pixmap(bm_xpm),
60 new Fl_Pixmap(tools_xpm),
61 new Fl_Pixmap(new_s_xpm),
62 new Fl_Pixmap(search_xpm),
63 new Fl_Pixmap(help_xpm),
64 new Fl_Pixmap(left_xpm),
65 NULL,
66 new Fl_Pixmap(right_xpm),
67 NULL,
68 new Fl_Pixmap(stop_xpm),
69 NULL,
70};
71
72static struct iconset small_icons = {
73 standard_icons.ImgMeterOK,
74 standard_icons.ImgMeterBug,
75 new Fl_Pixmap(home_s_xpm),
76 new Fl_Pixmap(reload_s_xpm),
77 new Fl_Pixmap(save_s_xpm),
78 new Fl_Pixmap(bm_s_xpm),
79 new Fl_Pixmap(tools_s_xpm),
80 new Fl_Pixmap(new_s_xpm),
81 standard_icons.ImgSearch,
82 standard_icons.ImgHelp,
83 new Fl_Pixmap(left_s_xpm),
84 NULL,
85 new Fl_Pixmap(right_s_xpm),
86 NULL,
87 new Fl_Pixmap(stop_s_xpm),
88 NULL,
89};
90
91
92static struct iconset *icons = &standard_icons;
93
94/*
95 * Local sub classes
96 */
97
98//----------------------------------------------------------------------------
99
100#define DILLO_INPUTBOX (Fl_Boxtype) (FL_FREE_BOXTYPE + 1)
101
105class CustInput : public TipWinInput {
106public:
107 static const int margin_x = 3;
108 CustInput (int x, int y, int w, int h, const char* l=0) :
109 TipWinInput(x,y,w,h,l) {
110 /* Increase the margin of the current box by making a new clone
111 * of the current box with extra margin on dx. */
112 Fl_Boxtype b = box();
113 Fl::set_boxtype(DILLO_INPUTBOX, Fl::get_boxtype(b),
114 Fl::box_dx(b) + margin_x,
115 Fl::box_dy(b),
116 Fl::box_dw(b) + margin_x,
117 Fl::box_dh(b));
118 box(DILLO_INPUTBOX);
119 }
120 virtual int handle(int e);
121};
122
127int CustInput::handle(int e)
128{
129 int k = Fl::event_key();
130
131 _MSG("CustInput::handle event=%d\n", e);
132
133 // We're only interested in some flags
134 unsigned modifier = Fl::event_state() & (FL_SHIFT | FL_CTRL | FL_ALT);
135
136 // Don't focus with arrow keys
137 if (e == FL_FOCUS &&
138 (k == FL_Up || k == FL_Down || k == FL_Left || k == FL_Right)) {
139 return 0;
140 } else if (e == FL_KEYBOARD) {
141 if (k == FL_Escape && modifier == 0) {
142 // Let the parent group handle this Esc key
143 return 0;
144 } else if (modifier == FL_SHIFT) {
145 if (k == FL_Left || k == FL_Right) {
146 // Let these keys get to the UI
147 return 0;
148 }
149 } else if (modifier == FL_CTRL) {
150 if (k == 'e') {
151 position(size());
152 return 1;
153 } else if (k == 'k') {
154 cut(position(), size());
155 return 1;
156 } else if (k == 'd') {
157 cut(position(), position()+1);
158 return 1;
159 } else if (k == 'a' || k == 'l') {
160 // Make text selected when already focused.
161 position(size(), 0);
162 return 1;
163 } else if (k == 'h' || k == 'o' || k == 'r' ||
164 k == FL_Home || k == FL_End) {
165 // Let these keys get to the UI
166 return 0;
167 }
168 } else if (modifier == 0) {
169 if (k == FL_Down || k == FL_Up ||
170 k == FL_Page_Down || k == FL_Page_Up || k == FL_Tab) {
171 // Give up focus and honor the key
173 return 0;
174 }
175 }
176 if (k == FL_Page_Down || k == FL_Page_Up) {
177 // These do nothing of interest when FL_MULTILINE_INPUT isn't set.
178 // Let them through for key commands.
179 return 0;
180 }
181 }
182
183 return TipWinInput::handle(e);
184}
185
186//----------------------------------------------------------------------------
187
191class CustPasteButton : public CustButton {
192public:
193 CustPasteButton(int x, int y, int w, int h, const char *l=0) :
194 CustButton(x,y,w,h,l) {};
195 int handle(int e);
196};
197
198int CustPasteButton::handle(int e)
199{
200 if (e == FL_PASTE) {
201 const char* t = Fl::event_text();
202 if (t && *t) {
205 return 1;
206 }
207 }
208 return CustButton::handle(e);
209}
210
211//----------------------------------------------------------------------------
212
216class CustProgressBox : public Fl_Box {
217 int padding;
218public:
219 CustProgressBox(int x, int y, int w, int h, const char *l=0) :
220 Fl_Box(x,y,w,h,l) { padding = 0; };
221 void update_label(const char *lbl) {
222 int w = 0, h = 0;
223 if (!padding) {
224 copy_label("W");
225 measure_label(w, h);
226 padding = w > 2 ? w/2 : 1;
227 }
228 copy_label(lbl);
229 }
230};
231
232//
233// Toolbar buttons -----------------------------------------------------------
234//
235//static const char *button_names[] = {
236// "Back", "Forward", "Home", "Reload", "Save", "Stop", "Bookmarks", "Tools",
237// "Clear", "Search"
238//};
239
240
241//
242// Callback functions --------------------------------------------------------
243//
244
248static void search_cb(Fl_Widget *wid, void *data)
249{
250 int b = Fl::event_button();
251
252 if (b == FL_LEFT_MOUSE) {
254 }
255}
256
260static void help_cb(Fl_Widget *w, void *)
261{
262 char *path = dStrconcat(DILLO_DOCDIR, "user_help.html", NULL);
264
265 if (access(path, R_OK) == 0) {
266 char *urlstr = dStrconcat("file:", path, NULL);
267 a_UIcmd_open_urlstr(bw, urlstr);
268 dFree(urlstr);
269 } else {
270 MSG("Can't read local help file at \"%s\"."
271 " Getting remote help...\n", path);
272 a_UIcmd_open_urlstr(bw, "https://dillo-browser.github.io/user_help.html");
273 }
274 dFree(path);
275}
276
280static void filemenu_cb(Fl_Widget *wid, void *)
281{
282 int b = Fl::event_button();
283 if (b == FL_LEFT_MOUSE || b == FL_RIGHT_MOUSE) {
285 }
286}
287
291static void clear_cb(Fl_Widget *w, void *data)
292{
293 UI *ui = (UI*)data;
294
295 int b = Fl::event_button();
296 if (b == FL_LEFT_MOUSE) {
297 ui->set_location("");
298 ui->focus_location();
299 } else if (b == FL_MIDDLE_MOUSE) {
300 ui->paste_url();
301 }
302}
303
307static void location_cb(Fl_Widget *wid, void *data)
308{
309 Fl_Input *i = (Fl_Input*)wid;
310 UI *ui = (UI*)data;
311
312 _MSG("location_cb()\n");
314
315 if (ui->temporaryPanels())
316 ui->panels_toggle();
317}
318
319
323static void b1_cb(Fl_Widget *wid, void *cb_data)
324{
325 int bn = VOIDP2INT(cb_data);
326 int b = Fl::event_button();
327 if (b >= FL_LEFT_MOUSE && b <= FL_RIGHT_MOUSE) {
328 _MSG("[%s], mouse button %d was pressed\n", button_names[bn], b);
329 _MSG("mouse button %d was pressed\n", b);
330 }
331 switch (bn) {
332 case UI_BACK:
333 if (b == FL_LEFT_MOUSE) {
335 } else if (b == FL_MIDDLE_MOUSE) {
337 } else if (b == FL_RIGHT_MOUSE) {
339 wid->y() + wid->h());
340 }
341 break;
342 case UI_FORW:
343 if (b == FL_LEFT_MOUSE) {
345 } else if (b == FL_MIDDLE_MOUSE) {
347 } else if (b == FL_RIGHT_MOUSE) {
349 wid->y() + wid->h());
350 }
351 break;
352 case UI_HOME:
353 if (b == FL_LEFT_MOUSE) {
355 } else if (b == FL_MIDDLE_MOUSE) {
357 }
358 break;
359 case UI_RELOAD:
360 if (b == FL_LEFT_MOUSE) {
362 }
363 break;
364 case UI_SAVE:
365 if (b == FL_LEFT_MOUSE) {
367 }
368 break;
369 case UI_STOP:
370 if (b == FL_LEFT_MOUSE) {
372 }
373 break;
374 case UI_BOOK:
375 if (b == FL_LEFT_MOUSE) {
377 } else if (b == FL_MIDDLE_MOUSE) {
379 }
380 break;
381 case UI_TOOLS:
382 if (b == FL_LEFT_MOUSE || b == FL_RIGHT_MOUSE) {
384 wid->y() + wid->h());
385 }
386 break;
387 default:
388 break;
389 }
390}
391
395static void bugmeter_cb(Fl_Widget *wid, void *data)
396{
397 int b = Fl::event_button();
398 if (b == FL_LEFT_MOUSE) {
400 } else if (b == FL_RIGHT_MOUSE) {
402 }
403}
404
406// UI class methods
407//
408
409//----------------------------
410// Panel construction methods
411//----------------------------
412
416CustButton *UI::make_button(const char *label, Fl_Image *img, Fl_Image *deimg,
417 int b_n, int start)
418{
419 if (start)
420 p_xpos = 0;
421
422 CustButton *b = new CustButton(p_xpos, 0, bw, bh, (lbl) ? label : NULL);
423 if (img)
424 b->image(img);
425 if (deimg)
426 b->deimage(deimg);
427 b->callback(b1_cb, INT2VOIDP(b_n));
428 b->clear_visible_focus();
429 b->labelsize(12);
430 b->box(FL_FLAT_BOX);
431 b->down_box(FL_THIN_DOWN_FRAME);
432 p_xpos += bw;
433 return b;
434}
435
439void UI::make_toolbar(int tw, int th)
440{
441 if (!icons->ImgLeftIn) {
442 icons->ImgLeftIn = icons->ImgLeft->copy();
443 icons->ImgLeftIn->desaturate();
444 icons->ImgLeftIn->color_average(FL_BACKGROUND_COLOR, .14f);
445 }
446 if (!icons->ImgRightIn) {
447 icons->ImgRightIn = icons->ImgRight->copy();
448 icons->ImgRightIn->desaturate();
449 icons->ImgRightIn->color_average(FL_BACKGROUND_COLOR, .14f);
450 }
451 if (!icons->ImgStopIn) {
452 icons->ImgStopIn = icons->ImgStop->copy();
453 icons->ImgStopIn->desaturate();
454 icons->ImgStopIn->color_average(FL_BACKGROUND_COLOR, .14f);
455 }
456 Back = make_button("Back", icons->ImgLeft, icons->ImgLeftIn, UI_BACK, 1);
457 Forw = make_button("Forw", icons->ImgRight, icons->ImgRightIn, UI_FORW);
458 Home = make_button("Home", icons->ImgHome, NULL, UI_HOME);
459 Reload = make_button("Reload", icons->ImgReload, NULL, UI_RELOAD);
460 Save = make_button("Save", icons->ImgSave, NULL, UI_SAVE);
461 Stop = make_button("Stop", icons->ImgStop, icons->ImgStopIn, UI_STOP);
462 Bookmarks = make_button("Book", icons->ImgBook, NULL, UI_BOOK);
463 Tools = make_button("Tools", icons->ImgTools, NULL, UI_TOOLS);
464
465 Back->set_tooltip("Previous page");
466 Forw->set_tooltip("Next page");
467 Home->set_tooltip("Go to the Home page\nMiddle-click for new tab.");
468 Reload->set_tooltip("Reload");
469 Save->set_tooltip("Save this page");
470 Stop->set_tooltip("Stop loading");
471 Bookmarks->set_tooltip("View bookmarks\nMiddle-click for new tab.");
472 Tools->set_tooltip("Settings");
473}
474
479{
480 CustButton *b;
481
482 b = Clear = (CustButton*) new CustPasteButton(p_xpos,0,16,lh,0);
483 b->image(icons->ImgClear);
484 b->callback(clear_cb, this);
485 b->clear_visible_focus();
486 b->box(FL_THIN_UP_BOX);
487 b->set_tooltip("Clear the URL box.\nMiddle-click to paste a URL.");
488 p_xpos += b->w();
489
490 LocationGroup = new Fl_Group(p_xpos,0,ww-p_xpos-32,lh,0);
491 LocationGroup->begin();
492 CustInput *i = new CustInput(p_xpos,0,ww-p_xpos-32,lh,0);
493 Location = i;
494 i->when(FL_WHEN_ENTER_KEY);
495 i->callback(location_cb, this);
496 i->set_tooltip("Location");
497 i->textsize((int) rint(14.0 * prefs.font_factor));
498 p_xpos += i->w();
499 LocationGroup->box(FL_THIN_UP_BOX); // or FL_FLAT_BOX
500 LocationGroup->end();
501
502 Search = b = new CustButton(p_xpos,0,16,lh,0);
503 b->image(icons->ImgSearch);
504 b->callback(search_cb, this);
505 b->clear_visible_focus();
506 b->box(FL_THIN_UP_BOX);
507 b->set_tooltip("Search the Web");
508 p_xpos += b->w();
509
510 Help = b = new CustButton(p_xpos,0,16,lh,0);
511 b->image(icons->ImgHelp);
512 b->callback(help_cb, this);
513 b->clear_visible_focus();
514 b->box(FL_THIN_UP_BOX);
515 b->set_tooltip("Help");
516 p_xpos += b->w();
517
518}
519
523void UI::make_progress_bars(int wide, int thin_up)
524{
525 // Images
526 IProg = new CustProgressBox(p_xpos,p_ypos,pw,bh);
527 IProg->labelsize(12);
528 IProg->box(thin_up ? FL_THIN_UP_BOX : FL_EMBOSSED_BOX);
529 IProg->update_label(wide ? "Images\n0 of 0" : "0 of 0");
530 p_xpos += pw;
531 // Page
532 PProg = new CustProgressBox(p_xpos,p_ypos,pw,bh);
533 PProg->labelsize(12);
534 PProg->box(thin_up ? FL_THIN_UP_BOX : FL_EMBOSSED_BOX);
535 PProg->update_label(wide ? "Page\n0.0 KB" : "0.0 KB");
536}
537
543{
544 CustButton *btn;
545 int w = 0, h = 0, padding;
546
547 FileButton = btn = new CustButton(p_xpos,0,bw,bh,"W");
548 btn->labeltype(FL_FREE_LABELTYPE);
549 btn->measure_label(w, h);
550 padding = w;
551 btn->copy_label(PanelSize == P_tiny ? "&F" : "&File");
552 btn->measure_label(w,h);
553 h = (PanelSize == P_tiny) ? bh : lh;
554 btn->size(w+padding, h);
555 p_xpos += btn->w();
556 _MSG("UI::make_filemenu_button w=%d h=%d padding=%d\n", w, h, padding);
557 btn->box(FL_THIN_UP_BOX);
558 btn->callback(filemenu_cb, this);
559 btn->set_tooltip("File menu");
560 btn->clear_visible_focus();
561 if (!prefs.show_filemenu)
562 btn->hide();
563}
564
565
569void UI::make_panel(int ww)
570{
571 Fl_Widget *w;
572
573 if (Small_Icons)
575 else
577
578 pw = 70;
579 p_xpos = p_ypos = 0;
580 if (PanelSize == P_tiny) {
581 if (Small_Icons)
582 bw = 22, bh = 22, mh = 0, lh = 22, lbl = 0;
583 else
584 bw = 28, bh = 28, mh = 0, lh = 28, lbl = 0;
585 } else if (PanelSize == P_small) {
586 if (Small_Icons)
587 bw = 20, bh = 20, mh = 0, lh = 20, lbl = 0;
588 else
589 bw = 28, bh = 28, mh = 0, lh = 28, lbl = 0;
590 } else if (PanelSize == P_medium) {
591 if (Small_Icons)
592 bw = 42, bh = 36, mh = 0, lh = 22, lbl = 1;
593 else
594 bw = 45, bh = 45, mh = 0, lh = 28, lbl = 1;
595 }
596 nh = bh, fh = 28; sh = 20;
597
598 current(0);
599 if (PanelSize == P_tiny) {
600 NavBar = new CustGroupHorizontal(0,0,ww,nh);
601 NavBar->box(FL_NO_BOX);
602 NavBar->begin();
603 make_toolbar(ww,bh);
605 make_location(ww);
606 NavBar->resizable(LocationGroup);
608 NavBar->box(FL_THIN_UP_FRAME);
609 NavBar->end();
610 NavBar->rearrange();
611 TopGroup->insert(*NavBar,0);
612 } else {
613 // Location
614 LocBar = new CustGroupHorizontal(0,0,ww,lh);
615 LocBar->box(FL_NO_BOX);
616 LocBar->begin();
617 p_xpos = 0;
619 make_location(ww);
620 LocBar->resizable(LocationGroup);
621 LocBar->end();
622 LocBar->rearrange();
623 TopGroup->insert(*LocBar,0);
624
625 // Toolbar
626 p_ypos = 0;
627 NavBar = new CustGroupHorizontal(0,0,ww,bh);
628 NavBar->box(FL_NO_BOX);
629 NavBar->begin();
630 make_toolbar(ww,bh);
631 w = new Fl_Box(p_xpos,0,ww-p_xpos-2*pw,bh);
632 w->box(FL_FLAT_BOX);
633 NavBar->resizable(w);
634 p_xpos = ww - 2*pw;
635 if (PanelSize == P_small) {
637 } else {
639 }
640 NavBar->end();
641 NavBar->rearrange();
642 TopGroup->insert(*NavBar,1);
643 }
644}
645
649void UI::make_status_bar(int ww, int wh)
650{
651 const int bm_w = 20;
652 StatusBar = new CustGroupHorizontal(0, wh-sh, ww, sh);
653 StatusBar->box(FL_NO_BOX);
654
655 // Status box
656 StatusOutput = new Fl_Output(0, wh-sh, ww-bm_w, sh);
657 StatusOutput->value("https://dillo-browser.github.io/");
658 StatusOutput->labelsize(8);
659 StatusOutput->box(FL_THIN_DOWN_BOX);
660 StatusOutput->clear_visible_focus();
661 StatusOutput->color(FL_BACKGROUND_COLOR);
662
663 // Bug Meter
664 BugMeter = new CustButton(ww-bm_w,wh-sh,bm_w,sh);
665 BugMeter->image(icons->ImgMeterOK);
666 BugMeter->box(FL_THIN_DOWN_BOX);
667 BugMeter->align(FL_ALIGN_INSIDE | FL_ALIGN_TEXT_NEXT_TO_IMAGE);
668 BugMeter->set_tooltip("Show HTML bugs\n(right-click for menu)");
669 BugMeter->callback(bugmeter_cb, this);
670 BugMeter->clear_visible_focus();
671
672 StatusBar->end();
673 StatusBar->resizable(StatusOutput);
675}
676
680UI::UI(int x, int y, int ui_w, int ui_h, const char* label, const UI *cur_ui) :
681 CustGroupVertical(x, y, ui_w, ui_h, label)
682{
683 LocBar = NavBar = StatusBar = NULL;
684
685 Tabs = NULL;
686 TopGroup = this;
687 TopGroup->box(FL_NO_BOX);
688 clear_flag(SHORTCUT_LABEL);
689
690 PanelTemporary = false;
691 if (cur_ui) {
692 PanelSize = cur_ui->PanelSize;
693 Small_Icons = cur_ui->Small_Icons;
694 Panelmode = cur_ui->Panelmode;
695 } else {
696 // Set some default values
700 }
701
702 // Control panel
703 TopGroup->begin();
704 make_panel(ui_w);
705
706 // Render area
707 Main = new Fl_Group(0,0,0,0,"Welcome..."); // size is set by rearrange()
708 Main->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
709 Main->box(FL_FLAT_BOX);
710 Main->labelfont(FL_HELVETICA_BOLD_ITALIC);
711 Main->labelsize(36);
712 Main->labeltype(FL_SHADOW_LABEL);
713 TopGroup->add(Main);
714 TopGroup->resizable(Main);
715 MainIdx = TopGroup->find(Main);
716
717 // Find text bar
718 FindBar = new Findbar(ui_w, fh);
719 TopGroup->add(FindBar);
720
721 // Status Panel
722 make_status_bar(ui_w, ui_h);
723 TopGroup->add(StatusBar);
724 TopGroup->end();
726
727 customize();
728
729 if (Panelmode == UI_HIDDEN) {
731 }
732}
733
738{
739 _MSG("UI::~UI()\n");
740}
741
745int UI::handle(int event)
746{
747 _MSG("UI::handle event=%s\n", fl_eventnames[event]);
748
749 int ret = 0;
750 if (event == FL_KEYBOARD) {
751 return 0; // Receive as shortcut
752 } else if (event == FL_SHORTCUT) {
754 if (cmd == KEYS_NOP) {
755 // Do nothing
756 } else if (cmd == KEYS_SCREEN_UP || cmd == KEYS_SCREEN_DOWN ||
757 cmd == KEYS_SCREEN_LEFT || cmd == KEYS_SCREEN_RIGHT ||
758 cmd == KEYS_LINE_UP || cmd == KEYS_LINE_DOWN ||
759 cmd == KEYS_LEFT || cmd == KEYS_RIGHT ||
760 cmd == KEYS_TOP || cmd == KEYS_BOTTOM) {
762 ret = 1;
763 } else if (cmd == KEYS_BACK) {
765 ret = 1;
766 } else if (cmd == KEYS_FORWARD) {
768 ret = 1;
769 } else if (cmd == KEYS_COPY) {
771 ret = 1;
772 } else if (cmd == KEYS_ZOOM_IN) {
774 ret = 1;
775 } else if (cmd == KEYS_ZOOM_OUT) {
777 ret = 1;
778 } else if (cmd == KEYS_ZOOM_RESET) {
780 ret = 1;
781 } else if (cmd == KEYS_BOOKMARKS) {
783 ret = 1;
784 } else if (cmd == KEYS_FIND) {
786 ret = 1;
787 } else if (cmd == KEYS_WEBSEARCH) {
789 ret = 1;
790 } else if (cmd == KEYS_GOTO) {
792 ret = 1;
793 } else if (cmd == KEYS_HIDE_PANELS) {
794 /* Hide findbar if present, hide panels if not */
795 (FindBar->visible()) ? findbar_toggle(0) : panels_toggle();
796 temporaryPanels(false);
797 ret = 1;
798 } else if (cmd == KEYS_OPEN) {
800 ret = 1;
801 } else if (cmd == KEYS_HOME) {
803 ret = 1;
804 } else if (cmd == KEYS_RELOAD) {
806 ret = 1;
807 } else if (cmd == KEYS_STOP) {
809 ret = 1;
810 } else if (cmd == KEYS_SAVE) {
812 ret = 1;
813 } else if (cmd == KEYS_FILE_MENU) {
815 ret = 1;
816 } else if (cmd == KEYS_VIEW_SOURCE) {
820 ret = 1;
821 } else if (cmd >= KEYS_FOCUS_TAB1 && cmd <= KEYS_FOCUS_TAB10) {
822 int index = cmd - KEYS_FOCUS_TAB1; /* zero-based index */
824 ret = 1;
825 }
826 } else if (event == FL_RELEASE) {
827 if (Fl::event_button() == FL_MIDDLE_MOUSE &&
829 /* nobody claimed the event; try paste */
830 paste_url();
831 ret = 1;
832 }
833 } else if (event == FL_PUSH) {
835 _MSG("pressed button %d\n", Fl::event_button());
836 if (Fl::event_button() == FL_BACK_MOUSE) {
838 ret = 1;
839 } else if (Fl::event_button() == FL_FORWARD_MOUSE) {
841 ret = 1;
842 }
843 }
844
845 if (!ret) {
846 ret = Fl_Group::handle(event);
847 }
848 if (!ret && event == FL_PUSH && !prefs.middle_click_drags_page) {
849 /* nobody claimed FL_PUSH: ask for FL_RELEASE,
850 * which is necessary for middle-click paste URL) */
851 ret = 1;
852 }
853
854 return ret;
855}
856
857
858//----------------------------
859// API for the User Interface
860//----------------------------
861
865const char *UI::get_location()
866{
867 return Location->value();
868}
869
873void UI::set_location(const char *str)
874{
875 if (!str) str = "";
876 Location->value(str);
877 Location->position((Fl::focus() == Location) ? strlen(str) : 0);
878}
879
885{
886 if (Panelmode == UI_HIDDEN) {
888 temporaryPanels(true);
889 }
890 Location->take_focus();
891 // Make text selected when already focused.
892 Location->position(Location->size(), 0);
893}
894
899{
900 Main->take_focus();
901}
902
906void UI::set_status(const char *str)
907{
908 StatusOutput->value(str);
909}
910
915void UI::set_page_prog(size_t nbytes, int cmd)
916{
917 char str[32];
918
919 if (cmd == 0) {
920 PProg->deactivate();
921 } else {
922 PProg->activate();
923 if (cmd == 1) {
924 char prefix;
925 float magnitude;
926
927 if (nbytes >= 1024 * 1024) {
928 prefix = 'M';
929 magnitude = nbytes / (1024 * 1024.0);
930 } else {
931 prefix = 'K';
932 magnitude = nbytes / 1024.0;
933 }
934 snprintf(str, 32, "%s%.1f %cB",
935 (PanelSize == 0) ? "" : "Page\n", magnitude, prefix);
936 } else if (cmd == 2) {
937 str[0] = '\0';
938 }
939 PProg->update_label(str);
940 }
941}
942
947void UI::set_img_prog(int n_img, int t_img, int cmd)
948{
949 char str[32];
950
951 if (cmd == 0) {
952 IProg->deactivate();
953 } else {
954 IProg->activate();
955 if (cmd == 1) {
956 snprintf(str, 32, "%s%d of %d",
957 (PanelSize == 0) ? "" : "Images\n", n_img, t_img);
958 } else if (cmd == 2) {
959 str[0] = '\0';
960 }
961 IProg->update_label(str);
962 }
963}
964
968void UI::set_bug_prog(int n_bug)
969{
970 char str[32];
971 int new_w = 20;
972
973 if (n_bug == 0) {
974 BugMeter->image(icons->ImgMeterOK);
975 BugMeter->label("");
976 } else if (n_bug >= 1) {
977 if (n_bug == 1)
978 BugMeter->image(icons->ImgMeterBug);
979 snprintf(str, 32, "%d", n_bug);
980 BugMeter->copy_label(str);
981 new_w = strlen(str)*9 + 20;
982 }
983 BugMeter->size(new_w, BugMeter->h());
985}
986
991{
992 if ( !prefs.show_back )
993 Back->hide();
994 if ( !prefs.show_forw )
995 Forw->hide();
996 if ( !prefs.show_home )
997 Home->hide();
998 if ( !prefs.show_reload )
999 Reload->hide();
1000 if ( !prefs.show_save )
1001 Save->hide();
1002 if ( !prefs.show_stop )
1003 Stop->hide();
1004 if ( !prefs.show_bookmarks )
1005 Bookmarks->hide();
1006 if ( !prefs.show_tools )
1007 Tools->hide();
1008 if ( !prefs.show_clear_url )
1009 Clear->hide();
1010 if ( !prefs.show_url )
1011 Location->hide();
1012 if ( !prefs.show_search )
1013 Search->hide();
1014 if ( !prefs.show_help )
1015 Help->hide();
1016 if ( !prefs.show_progress_box ) {
1017 IProg->hide();
1018 PProg->hide();
1019 }
1020
1021 if (NavBar)
1022 NavBar->rearrange();
1023 if (LocBar)
1024 LocBar->rearrange();
1025}
1026
1030void UI::change_panel(int new_size, int small_icons)
1031{
1032 char *loc_text = dStrdup(Location->value());
1033
1034 // Remove current panel's bars
1035 init_sizes();
1036 TopGroup->remove(LocBar);
1037 Fl::delete_widget(LocBar);
1038 TopGroup->remove(NavBar);
1039 Fl::delete_widget(NavBar);
1040 LocBar = NavBar = NULL;
1041
1042 // Set internal vars for panel size
1043 PanelSize = new_size;
1045
1046 // make a new panel
1047 make_panel(TopGroup->w());
1048 customize();
1050
1052 Location->value(loc_text);
1053 Location->take_focus();
1054
1055 dFree(loc_text);
1056}
1057
1061void UI::set_render_layout(Fl_Group *nw)
1062{
1063 // Resize layout widget to current height
1064 nw->resize(0,Main->y(),Main->w(),Main->h());
1065
1066 TopGroup->insert(*nw, Main);
1067 remove(Main);
1068 delete(Main);
1069 Main = nw;
1070 TopGroup->resizable(Main);
1071}
1072
1077{
1078 switch (btn) {
1079 case UI_BACK:
1080 (sens) ? Back->activate() : Back->deactivate();
1081 break;
1082 case UI_FORW:
1083 (sens) ? Forw->activate() : Forw->deactivate();
1084 break;
1085 case UI_STOP:
1086 (sens) ? Stop->activate() : Stop->deactivate();
1087 break;
1088 default:
1089 break;
1090 }
1091}
1092
1097{
1098 Fl::paste(*Clear, false);
1099}
1100
1105{
1106 /* WORKAROUND:
1107 * This is tricky: As fltk-1.3 resizes hidden widgets (which it
1108 * doesn't resize when visible!). We need to set the size to (0,0) to
1109 * get the desired behaviour.
1110 * (STR#2639 in FLTK bug tracker).
1111 */
1112
1113 if (add) {
1114 if (!FindBar->visible())
1115 FindBar->size(w(), fh);
1116 FindBar->show();
1117 } else {
1118 // hide
1119 FindBar->size(0,0);
1120 FindBar->hide();
1121 // reset state
1123 // focus main area
1124 focus_main();
1125 }
1127}
1128
1136{
1137 int hide = StatusBar->visible();
1138
1139 // hide/show panels
1140 init_sizes();
1141 if (LocBar) {
1142 hide ? LocBar->size(0,0) : LocBar->size(w(),lh);
1143 hide ? LocBar->hide() : LocBar->show();
1144 }
1145 if (NavBar) {
1146 hide ? NavBar->size(0,0) : NavBar->size(w(),nh);
1147 hide ? NavBar->hide() : NavBar->show();
1148 }
1149 if (StatusBar) {
1150 hide ? StatusBar->size(0,0) : StatusBar->size(w(),sh);
1151 hide ? StatusBar->hide() : StatusBar->show();
1153 }
1154
1156 Panelmode = (hide) ? UI_HIDDEN : UI_NORMAL;
1157}
#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:947
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:1076
~UI()
UI destructor.
Definition ui.cc:737
void customize()
Customize the UI's panel (show/hide buttons)
Definition ui.cc:990
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:416
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:1104
void set_render_layout(Fl_Group *nw)
Set 'nw' as the main render area widget.
Definition ui.cc:1061
CustButton * Save
Definition ui.hh:127
Fl_Output * StatusOutput
Definition ui.hh:133
void focus_main()
Focus Main area.
Definition ui.cc:898
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:865
void make_toolbar(int tw, int th)
Create the archetipic browser buttons.
Definition ui.cc:439
void change_panel(int new_size, int small_icons)
On-the-fly panel style change.
Definition ui.cc:1030
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:884
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:745
void make_status_bar(int ww, int wh)
Create the status panel.
Definition ui.cc:649
void make_progress_bars(int wide, int thin_up)
Create the progress bars.
Definition ui.cc:523
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:478
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:680
CustProgressBox * IProg
Definition ui.hh:131
void set_bug_prog(int n_bug)
Set the bug meter progress text.
Definition ui.cc:968
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:1135
CustButton * BugMeter
Definition ui.hh:128
void set_status(const char *str)
Set a new message in the status bar.
Definition ui.cc:906
void paste_url()
Paste a middle-click-selection into "Clear" button as URL.
Definition ui.cc:1096
void make_panel(int ww)
Create the control panel.
Definition ui.cc:569
CustButton * Forw
Definition ui.hh:127
void set_location(const char *str)
Set a new URL in the location input-box.
Definition ui.cc:873
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:542
void set_page_prog(size_t nbytes, int cmd)
Set the page progress text.
Definition ui.cc:915
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:323
static void help_cb(Fl_Widget *w, void *)
Callback for the help button.
Definition ui.cc:260
static struct iconset * icons
Definition ui.cc:92
static struct iconset small_icons
Definition ui.cc:72
static struct iconset standard_icons
Definition ui.cc:53
#define DILLO_INPUTBOX
Definition ui.cc:100
static void bugmeter_cb(Fl_Widget *wid, void *data)
Callback for the bug meter button.
Definition ui.cc:395
static void filemenu_cb(Fl_Widget *wid, void *)
Callback for the File menu button.
Definition ui.cc:280
static void location_cb(Fl_Widget *wid, void *data)
Send the browser to the new URL in the location.
Definition ui.cc:307
static void search_cb(Fl_Widget *wid, void *data)
Callback for the search button.
Definition ui.cc:248
static void clear_cb(Fl_Widget *w, void *data)
Callback for the location's clear-button.
Definition ui.cc:291
@ 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