Dillo v3.2.0-170-gacf511bb
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-2026 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 int d_position();
122 void d_position(int p);
123 void d_position(int p, int m);
124};
125
126/* FLTK 1.4 deprecated "position()" for "insert_position()", so we make
127 * a backward compatible wrapper. */
128int CustInput::d_position()
129{
130#if FL_API_VERSION < 10400
131 return CustInput::position();
132#else
133 return CustInput::insert_position();
134#endif
135}
136
137void CustInput::d_position(int p)
138{
139#if FL_API_VERSION < 10400
140 CustInput::position(p);
141#else
142 CustInput::insert_position(p);
143#endif
144}
145
146
147void CustInput::d_position(int p, int m)
148{
149#if FL_API_VERSION < 10400
150 CustInput::position(p, m);
151#else
152 CustInput::insert_position(p, m);
153#endif
154}
155
160int CustInput::handle(int e)
161{
162 int k = Fl::event_key();
163
164 _MSG("CustInput::handle event=%d\n", e);
165
166 // We're only interested in some flags
167 unsigned modifier = Fl::event_state() & (FL_SHIFT | FL_CTRL | FL_ALT);
168
169 // Don't focus with arrow keys
170 if (e == FL_FOCUS &&
171 (k == FL_Up || k == FL_Down || k == FL_Left || k == FL_Right)) {
172 return 0;
173 } else if (e == FL_KEYBOARD) {
174 if (k == FL_Escape && modifier == 0) {
175 // Let the parent group handle this Esc key
176 return 0;
177 } else if (modifier == FL_SHIFT) {
178 if (k == FL_Left || k == FL_Right) {
179 // Let these keys get to the UI
180 return 0;
181 }
182 } else if (modifier == FL_CTRL) {
183 if (k == 'e') {
184 d_position(size());
185 return 1;
186 } else if (k == 'k') {
187 cut(d_position(), size());
188 return 1;
189 } else if (k == 'd') {
190 cut(d_position(), d_position()+1);
191 return 1;
192 } else if (k == 'a' || k == 'l') {
193 // Make text selected when already focused.
194 d_position(size(), 0);
195 return 1;
196 } else if (k == 'h' || k == 'o' || k == 'r' ||
197 k == FL_Home || k == FL_End) {
198 // Let these keys get to the UI
199 return 0;
200 }
201 } else if (modifier == 0) {
202 if (k == FL_Down || k == FL_Up ||
203 k == FL_Page_Down || k == FL_Page_Up || k == FL_Tab) {
204 // Give up focus and honor the key
206 return 0;
207 }
208 }
209 if (k == FL_Page_Down || k == FL_Page_Up) {
210 // These do nothing of interest when FL_MULTILINE_INPUT isn't set.
211 // Let them through for key commands.
212 return 0;
213 }
214 }
215
216 return TipWinInput::handle(e);
217}
218
219//----------------------------------------------------------------------------
220
224class CustPasteButton : public CustButton {
225public:
226 CustPasteButton(int x, int y, int w, int h, const char *l=0) :
227 CustButton(x,y,w,h,l) {};
228 int handle(int e);
229};
230
231int CustPasteButton::handle(int e)
232{
233 if (e == FL_PASTE) {
234 const char* t = Fl::event_text();
235 if (t && *t) {
238 return 1;
239 }
240 }
241 return CustButton::handle(e);
242}
243
244//----------------------------------------------------------------------------
245
249class CustProgressBox : public Fl_Box {
250 int padding;
251public:
252 CustProgressBox(int x, int y, int w, int h, const char *l=0) :
253 Fl_Box(x,y,w,h,l) { padding = 0; };
254 void update_label(const char *lbl) {
255 int w = 0, h = 0;
256 if (!padding) {
257 copy_label("W");
258 measure_label(w, h);
259 padding = w > 2 ? w/2 : 1;
260 }
261 copy_label(lbl);
262 }
263};
264
265//
266// Toolbar buttons -----------------------------------------------------------
267//
268//static const char *button_names[] = {
269// "Back", "Forward", "Home", "Reload", "Save", "Stop", "Bookmarks", "Tools",
270// "Clear", "Search"
271//};
272
273
274//
275// Callback functions --------------------------------------------------------
276//
277
281static void search_cb(Fl_Widget *wid, void *data)
282{
283 int b = Fl::event_button();
284
285 if (b == FL_LEFT_MOUSE) {
287 }
288}
289
293static void help_cb(Fl_Widget *w, void *)
294{
295 char *path = dStrconcat(DILLO_DOCDIR, "user_help.html", NULL);
297
298 if (access(path, R_OK) == 0) {
299 char *urlstr = dStrconcat("file:", path, NULL);
300 a_UIcmd_open_urlstr(bw, urlstr);
301 dFree(urlstr);
302 } else {
303 MSG("Can't read local help file at \"%s\"."
304 " Getting remote help...\n", path);
305 a_UIcmd_open_urlstr(bw, "https://dillo-browser.org/user_help.html");
306 }
307 dFree(path);
308}
309
313static void filemenu_cb(Fl_Widget *wid, void *)
314{
315 int b = Fl::event_button();
316 if (b == FL_LEFT_MOUSE || b == FL_RIGHT_MOUSE) {
318 }
319}
320
324static void clear_cb(Fl_Widget *w, void *data)
325{
326 UI *ui = (UI*)data;
327
328 int b = Fl::event_button();
329 if (b == FL_LEFT_MOUSE) {
330 ui->set_location("");
331 ui->focus_location();
332 } else if (b == FL_MIDDLE_MOUSE) {
333 ui->paste_url();
334 }
335}
336
340static void location_cb(Fl_Widget *wid, void *data)
341{
342 Fl_Input *i = (Fl_Input*)wid;
343 UI *ui = (UI*)data;
344
345 _MSG("location_cb()\n");
347
348 if (ui->temporaryPanels())
349 ui->panels_toggle();
350}
351
352
356static void b1_cb(Fl_Widget *wid, void *cb_data)
357{
358 int bn = VOIDP2INT(cb_data);
359 int b = Fl::event_button();
360 if (b >= FL_LEFT_MOUSE && b <= FL_RIGHT_MOUSE) {
361 _MSG("[%s], mouse button %d was pressed\n", button_names[bn], b);
362 _MSG("mouse button %d was pressed\n", b);
363 }
364 switch (bn) {
365 case UI_BACK:
366 if (b == FL_LEFT_MOUSE) {
368 } else if (b == FL_MIDDLE_MOUSE) {
370 } else if (b == FL_RIGHT_MOUSE) {
372 wid->y() + wid->h());
373 }
374 break;
375 case UI_FORW:
376 if (b == FL_LEFT_MOUSE) {
378 } else if (b == FL_MIDDLE_MOUSE) {
380 } else if (b == FL_RIGHT_MOUSE) {
382 wid->y() + wid->h());
383 }
384 break;
385 case UI_HOME:
386 if (b == FL_LEFT_MOUSE) {
388 } else if (b == FL_MIDDLE_MOUSE) {
390 }
391 break;
392 case UI_RELOAD:
393 if (b == FL_LEFT_MOUSE) {
395 }
396 break;
397 case UI_SAVE:
398 if (b == FL_LEFT_MOUSE) {
400 }
401 break;
402 case UI_STOP:
403 if (b == FL_LEFT_MOUSE) {
405 }
406 break;
407 case UI_BOOK:
408 if (b == FL_LEFT_MOUSE) {
410 } else if (b == FL_MIDDLE_MOUSE) {
412 }
413 break;
414 case UI_TOOLS:
415 if (b == FL_LEFT_MOUSE || b == FL_RIGHT_MOUSE) {
417 wid->y() + wid->h());
418 }
419 break;
420 default:
421 break;
422 }
423}
424
428static void bugmeter_cb(Fl_Widget *wid, void *data)
429{
430 int b = Fl::event_button();
431 if (b == FL_LEFT_MOUSE) {
433 } else if (b == FL_RIGHT_MOUSE) {
435 }
436}
437
439// UI class methods
440//
441
442//----------------------------
443// Panel construction methods
444//----------------------------
445
449CustButton *UI::make_button(const char *label, Fl_Image *img, Fl_Image *deimg,
450 int b_n, int start)
451{
452 if (start)
453 p_xpos = 0;
454
455 CustButton *b = new CustButton(p_xpos, 0, bw, bh, (lbl) ? label : NULL);
456 if (img)
457 b->image(img);
458 if (deimg)
459 b->deimage(deimg);
460 b->callback(b1_cb, INT2VOIDP(b_n));
461 b->clear_visible_focus();
462 b->labelsize(12);
463 b->box(FL_FLAT_BOX);
464 b->down_box(FL_THIN_DOWN_FRAME);
465 p_xpos += bw;
466 return b;
467}
468
472void UI::make_toolbar(int tw, int th)
473{
474 if (!icons->ImgLeftIn) {
475 icons->ImgLeftIn = icons->ImgLeft->copy();
476 icons->ImgLeftIn->desaturate();
477 icons->ImgLeftIn->color_average(FL_BACKGROUND_COLOR, .14f);
478 }
479 if (!icons->ImgRightIn) {
480 icons->ImgRightIn = icons->ImgRight->copy();
481 icons->ImgRightIn->desaturate();
482 icons->ImgRightIn->color_average(FL_BACKGROUND_COLOR, .14f);
483 }
484 if (!icons->ImgStopIn) {
485 icons->ImgStopIn = icons->ImgStop->copy();
486 icons->ImgStopIn->desaturate();
487 icons->ImgStopIn->color_average(FL_BACKGROUND_COLOR, .14f);
488 }
489 Back = make_button("Back", icons->ImgLeft, icons->ImgLeftIn, UI_BACK, 1);
490 Forw = make_button("Forw", icons->ImgRight, icons->ImgRightIn, UI_FORW);
491 Home = make_button("Home", icons->ImgHome, NULL, UI_HOME);
492 Reload = make_button("Reload", icons->ImgReload, NULL, UI_RELOAD);
493 Save = make_button("Save", icons->ImgSave, NULL, UI_SAVE);
494 Stop = make_button("Stop", icons->ImgStop, icons->ImgStopIn, UI_STOP);
495 Bookmarks = make_button("Book", icons->ImgBook, NULL, UI_BOOK);
496 Tools = make_button("Tools", icons->ImgTools, NULL, UI_TOOLS);
497
498 Back->set_tooltip("Previous page");
499 Forw->set_tooltip("Next page");
500 Home->set_tooltip("Go to the Home page\nMiddle-click for new tab.");
501 Reload->set_tooltip("Reload");
502 Save->set_tooltip("Save this page");
503 Stop->set_tooltip("Stop loading");
504 Bookmarks->set_tooltip("View bookmarks\nMiddle-click for new tab.");
505 Tools->set_tooltip("Settings");
506}
507
512{
513 CustButton *b;
514
515 b = Clear = (CustButton*) new CustPasteButton(p_xpos,0,16,lh,0);
516 b->image(icons->ImgClear);
517 b->callback(clear_cb, this);
518 b->clear_visible_focus();
519 b->box(FL_THIN_UP_BOX);
520 b->set_tooltip("Clear the URL box.\nMiddle-click to paste a URL.");
521 p_xpos += b->w();
522
523 LocationGroup = new Fl_Group(p_xpos,0,ww-p_xpos-32,lh,0);
524 LocationGroup->begin();
525 CustInput *i = new CustInput(p_xpos,0,ww-p_xpos-32,lh,0);
526 Location = i;
527 i->when(FL_WHEN_ENTER_KEY);
528 i->callback(location_cb, this);
529 i->set_tooltip("Location");
530 i->textsize((int) rint(14.0 * prefs.font_factor));
531 p_xpos += i->w();
532 LocationGroup->box(FL_THIN_UP_BOX); // or FL_FLAT_BOX
533 LocationGroup->end();
534
535 Search = b = new CustButton(p_xpos,0,16,lh,0);
536 b->image(icons->ImgSearch);
537 b->callback(search_cb, this);
538 b->clear_visible_focus();
539 b->box(FL_THIN_UP_BOX);
540 b->set_tooltip("Search the Web");
541 p_xpos += b->w();
542
543 Help = b = new CustButton(p_xpos,0,16,lh,0);
544 b->image(icons->ImgHelp);
545 b->callback(help_cb, this);
546 b->clear_visible_focus();
547 b->box(FL_THIN_UP_BOX);
548 b->set_tooltip("Help");
549 p_xpos += b->w();
550
551}
552
556void UI::make_progress_bars(int wide, int thin_up)
557{
558 // Images
559 IProg = new CustProgressBox(p_xpos,p_ypos,pw,bh);
560 IProg->labelsize(12);
561 IProg->box(thin_up ? FL_THIN_UP_BOX : FL_EMBOSSED_BOX);
562 IProg->update_label(wide ? "Images\n0 of 0" : "0 of 0");
563 p_xpos += pw;
564 // Page
565 PProg = new CustProgressBox(p_xpos,p_ypos,pw,bh);
566 PProg->labelsize(12);
567 PProg->box(thin_up ? FL_THIN_UP_BOX : FL_EMBOSSED_BOX);
568 PProg->update_label(wide ? "Page\n0.0 KB" : "0.0 KB");
569}
570
576{
577 CustButton *btn;
578 int w = 0, h = 0, padding;
579
580 FileButton = btn = new CustButton(p_xpos,0,bw,bh,"W");
581 btn->labeltype(FL_FREE_LABELTYPE);
582 btn->measure_label(w, h);
583 padding = w;
584 btn->copy_label(PanelSize == P_tiny ? "&F" : "&File");
585 btn->measure_label(w,h);
586 h = (PanelSize == P_tiny) ? bh : lh;
587 btn->size(w+padding, h);
588 p_xpos += btn->w();
589 _MSG("UI::make_filemenu_button w=%d h=%d padding=%d\n", w, h, padding);
590 btn->box(FL_THIN_UP_BOX);
591 btn->callback(filemenu_cb, this);
592 btn->set_tooltip("File menu");
593 btn->clear_visible_focus();
594 if (!prefs.show_filemenu)
595 btn->hide();
596}
597
598
602void UI::make_panel(int ww)
603{
604 Fl_Widget *w;
605
606 if (Small_Icons)
608 else
610
611 pw = 70;
612 p_xpos = p_ypos = 0;
613 if (PanelSize == P_tiny) {
614 if (Small_Icons)
615 bw = 22, bh = 22, mh = 0, lh = 22, lbl = 0;
616 else
617 bw = 28, bh = 28, mh = 0, lh = 28, lbl = 0;
618 } else if (PanelSize == P_small) {
619 if (Small_Icons)
620 bw = 20, bh = 20, mh = 0, lh = 20, lbl = 0;
621 else
622 bw = 28, bh = 28, mh = 0, lh = 28, lbl = 0;
623 } else if (PanelSize == P_medium) {
624 if (Small_Icons)
625 bw = 42, bh = 36, mh = 0, lh = 22, lbl = 1;
626 else
627 bw = 45, bh = 45, mh = 0, lh = 28, lbl = 1;
628 }
629 nh = bh, fh = 28; sh = 20;
630
631 current(0);
632 if (PanelSize == P_tiny) {
633 NavBar = new CustGroupHorizontal(0,0,ww,nh);
634 NavBar->box(FL_NO_BOX);
635 NavBar->begin();
636 make_toolbar(ww,bh);
638 make_location(ww);
639 NavBar->resizable(LocationGroup);
641 NavBar->box(FL_THIN_UP_FRAME);
642 NavBar->end();
643 NavBar->rearrange();
644 TopGroup->insert(*NavBar,0);
645 } else {
646 // Location
647 LocBar = new CustGroupHorizontal(0,0,ww,lh);
648 LocBar->box(FL_NO_BOX);
649 LocBar->begin();
650 p_xpos = 0;
652 make_location(ww);
653 LocBar->resizable(LocationGroup);
654 LocBar->end();
655 LocBar->rearrange();
656 TopGroup->insert(*LocBar,0);
657
658 // Toolbar
659 p_ypos = 0;
660 NavBar = new CustGroupHorizontal(0,0,ww,bh);
661 NavBar->box(FL_NO_BOX);
662 NavBar->begin();
663 make_toolbar(ww,bh);
664 w = new Fl_Box(p_xpos,0,ww-p_xpos-2*pw,bh);
665 w->box(FL_FLAT_BOX);
666 NavBar->resizable(w);
667 p_xpos = ww - 2*pw;
668 if (PanelSize == P_small) {
670 } else {
672 }
673 NavBar->end();
674 NavBar->rearrange();
675 TopGroup->insert(*NavBar,1);
676 }
677}
678
682void UI::make_status_bar(int ww, int wh)
683{
684 const int bm_w = 20;
685 StatusBar = new CustGroupHorizontal(0, wh-sh, ww, sh);
686 StatusBar->box(FL_NO_BOX);
687
688 // Status box
689 StatusOutput = new Fl_Output(0, wh-sh, ww-bm_w, sh);
690 StatusOutput->value("https://dillo-browser.org/");
691 StatusOutput->labelsize(8);
692 StatusOutput->box(FL_THIN_DOWN_BOX);
693 StatusOutput->clear_visible_focus();
694 StatusOutput->color(FL_BACKGROUND_COLOR);
695
696 // Bug Meter
697 BugMeter = new CustButton(ww-bm_w,wh-sh,bm_w,sh);
698 BugMeter->image(icons->ImgMeterOK);
699 BugMeter->box(FL_THIN_DOWN_BOX);
700 BugMeter->align(FL_ALIGN_INSIDE | FL_ALIGN_TEXT_NEXT_TO_IMAGE);
701 BugMeter->set_tooltip("Show HTML bugs\n(right-click for menu)");
702 BugMeter->callback(bugmeter_cb, this);
703 BugMeter->clear_visible_focus();
704
705 StatusBar->end();
706 StatusBar->resizable(StatusOutput);
708}
709
713UI::UI(int x, int y, int ui_w, int ui_h, const char* label, const UI *cur_ui) :
714 CustGroupVertical(x, y, ui_w, ui_h, label)
715{
716 LocBar = NavBar = StatusBar = NULL;
717
718 Tabs = NULL;
719 TopGroup = this;
720 TopGroup->box(FL_NO_BOX);
721 clear_flag(SHORTCUT_LABEL);
722
723 PanelTemporary = false;
724 if (cur_ui) {
725 PanelSize = cur_ui->PanelSize;
726 Small_Icons = cur_ui->Small_Icons;
727 Panelmode = cur_ui->Panelmode;
728 } else {
729 // Set some default values
733 }
734
735 // Control panel
736 TopGroup->begin();
737 make_panel(ui_w);
738
739 // Render area
740 Main = new Fl_Group(0,0,0,0,"Welcome..."); // size is set by rearrange()
741 Main->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
742 Main->box(FL_FLAT_BOX);
743 Main->labelfont(FL_HELVETICA_BOLD_ITALIC);
744 Main->labelsize(36);
745 Main->labeltype(FL_SHADOW_LABEL);
746 TopGroup->add(Main);
747 TopGroup->resizable(Main);
748 MainIdx = TopGroup->find(Main);
749
750 // Find text bar
751 FindBar = new Findbar(ui_w, fh);
752 TopGroup->add(FindBar);
753
754 // Status Panel
755 make_status_bar(ui_w, ui_h);
756 TopGroup->add(StatusBar);
757 TopGroup->end();
759
760 customize();
761
762 if (Panelmode == UI_HIDDEN) {
764 }
765}
766
771{
772 _MSG("UI::~UI()\n");
773}
774
778int UI::handle(int event)
779{
780 _MSG("UI::handle event=%s\n", fl_eventnames[event]);
781
782 int ret = 0;
783 if (event == FL_KEYBOARD) {
784 return 0; // Receive as shortcut
785 } else if (event == FL_SHORTCUT) {
787 if (cmd == KEYS_NOP) {
788 // Do nothing
789 } else if (cmd == KEYS_SCREEN_UP || cmd == KEYS_SCREEN_DOWN ||
790 cmd == KEYS_SCREEN_LEFT || cmd == KEYS_SCREEN_RIGHT ||
791 cmd == KEYS_LINE_UP || cmd == KEYS_LINE_DOWN ||
792 cmd == KEYS_LEFT || cmd == KEYS_RIGHT ||
793 cmd == KEYS_TOP || cmd == KEYS_BOTTOM) {
795 ret = 1;
796 } else if (cmd == KEYS_BACK) {
798 ret = 1;
799 } else if (cmd == KEYS_FORWARD) {
801 ret = 1;
802 } else if (cmd == KEYS_COPY) {
804 ret = 1;
805 } else if (cmd == KEYS_ZOOM_IN) {
807 ret = 1;
808 } else if (cmd == KEYS_ZOOM_OUT) {
810 ret = 1;
811 } else if (cmd == KEYS_ZOOM_RESET) {
813 ret = 1;
814 } else if (cmd == KEYS_BOOKMARKS) {
816 ret = 1;
817 } else if (cmd == KEYS_FIND) {
819 ret = 1;
820 } else if (cmd == KEYS_WEBSEARCH) {
822 ret = 1;
823 } else if (cmd == KEYS_GOTO) {
825 ret = 1;
826 } else if (cmd == KEYS_HIDE_PANELS) {
827 /* Hide findbar if present, hide panels if not */
828 (FindBar->visible()) ? findbar_toggle(0) : panels_toggle();
829 temporaryPanels(false);
830 ret = 1;
831 } else if (cmd == KEYS_OPEN) {
833 ret = 1;
834 } else if (cmd == KEYS_HOME) {
836 ret = 1;
837 } else if (cmd == KEYS_RELOAD) {
839 ret = 1;
840 } else if (cmd == KEYS_STOP) {
842 ret = 1;
843 } else if (cmd == KEYS_SAVE) {
845 ret = 1;
846 } else if (cmd == KEYS_FILE_MENU) {
848 ret = 1;
849 } else if (cmd == KEYS_VIEW_SOURCE) {
853 ret = 1;
854 } else if (cmd >= KEYS_FOCUS_TAB1 && cmd <= KEYS_FOCUS_TAB10) {
855 int index = cmd - KEYS_FOCUS_TAB1; /* zero-based index */
857 ret = 1;
858 }
859 } else if (event == FL_RELEASE) {
860 if (Fl::event_button() == FL_MIDDLE_MOUSE &&
862 /* nobody claimed the event; try paste */
863 paste_url();
864 ret = 1;
865 }
866 } else if (event == FL_PUSH) {
868 _MSG("pressed button %d\n", Fl::event_button());
869 if (Fl::event_button() == FL_BACK_MOUSE) {
871 ret = 1;
872 } else if (Fl::event_button() == FL_FORWARD_MOUSE) {
874 ret = 1;
875 }
876 }
877
878 if (!ret) {
879 ret = Fl_Group::handle(event);
880 }
881 if (!ret && event == FL_PUSH && !prefs.middle_click_drags_page) {
882 /* nobody claimed FL_PUSH: ask for FL_RELEASE,
883 * which is necessary for middle-click paste URL) */
884 ret = 1;
885 }
886
887 return ret;
888}
889
890
891//----------------------------
892// API for the User Interface
893//----------------------------
894
898const char *UI::get_location()
899{
900 return Location->value();
901}
902
906void UI::set_location(const char *str)
907{
908 if (!str) str = "";
909 Location->value(str);
910 ((CustInput *) Location)->d_position((Fl::focus() == Location) ? strlen(str) : 0);
911}
912
918{
919 if (Panelmode == UI_HIDDEN) {
921 temporaryPanels(true);
922 }
923 Location->take_focus();
924 // Make text selected when already focused.
925 ((CustInput *) Location)->d_position(Location->size(), 0);
926}
927
932{
933 Main->take_focus();
934}
935
939void UI::set_status(const char *str)
940{
941 StatusOutput->value(str);
942}
943
948void UI::set_page_prog(size_t nbytes, int cmd)
949{
950 char str[32];
951
952 if (cmd == 0) {
953 PProg->deactivate();
954 } else {
955 PProg->activate();
956 if (cmd == 1) {
957 char prefix;
958 float magnitude;
959
960 if (nbytes >= 1024 * 1024) {
961 prefix = 'M';
962 magnitude = nbytes / (1024 * 1024.0);
963 } else {
964 prefix = 'K';
965 magnitude = nbytes / 1024.0;
966 }
967 snprintf(str, 32, "%s%.1f %cB",
968 (PanelSize == 0) ? "" : "Page\n", magnitude, prefix);
969 } else if (cmd == 2) {
970 str[0] = '\0';
971 }
972 PProg->update_label(str);
973 }
974}
975
980void UI::set_img_prog(int n_img, int t_img, int cmd)
981{
982 char str[32];
983
984 if (cmd == 0) {
985 IProg->deactivate();
986 } else {
987 IProg->activate();
988 if (cmd == 1) {
989 snprintf(str, 32, "%s%d of %d",
990 (PanelSize == 0) ? "" : "Images\n", n_img, t_img);
991 } else if (cmd == 2) {
992 str[0] = '\0';
993 }
994 IProg->update_label(str);
995 }
996}
997
1001void UI::set_bug_prog(int n_bug)
1002{
1003 char str[32];
1004 int new_w = 20;
1005
1006 if (n_bug == 0) {
1007 BugMeter->image(icons->ImgMeterOK);
1008 BugMeter->label("");
1009 } else if (n_bug >= 1) {
1010 if (n_bug == 1)
1011 BugMeter->image(icons->ImgMeterBug);
1012 snprintf(str, 32, "%d", n_bug);
1013 BugMeter->copy_label(str);
1014 new_w = strlen(str)*9 + 20;
1015 }
1016 BugMeter->size(new_w, BugMeter->h());
1018}
1019
1024{
1025 if ( !prefs.show_back )
1026 Back->hide();
1027 if ( !prefs.show_forw )
1028 Forw->hide();
1029 if ( !prefs.show_home )
1030 Home->hide();
1031 if ( !prefs.show_reload )
1032 Reload->hide();
1033 if ( !prefs.show_save )
1034 Save->hide();
1035 if ( !prefs.show_stop )
1036 Stop->hide();
1037 if ( !prefs.show_bookmarks )
1038 Bookmarks->hide();
1039 if ( !prefs.show_tools )
1040 Tools->hide();
1041 if ( !prefs.show_clear_url )
1042 Clear->hide();
1043 if ( !prefs.show_url )
1044 Location->hide();
1045 if ( !prefs.show_search )
1046 Search->hide();
1047 if ( !prefs.show_help )
1048 Help->hide();
1049 if ( !prefs.show_progress_box ) {
1050 IProg->hide();
1051 PProg->hide();
1052 }
1053
1054 if (NavBar)
1055 NavBar->rearrange();
1056 if (LocBar)
1057 LocBar->rearrange();
1058}
1059
1063void UI::change_panel(int new_size, int small_icons)
1064{
1065 char *loc_text = dStrdup(Location->value());
1066
1067 // Remove current panel's bars
1068 init_sizes();
1069 TopGroup->remove(LocBar);
1070 Fl::delete_widget(LocBar);
1071 TopGroup->remove(NavBar);
1072 Fl::delete_widget(NavBar);
1073 LocBar = NavBar = NULL;
1074
1075 // Set internal vars for panel size
1076 PanelSize = new_size;
1078
1079 // make a new panel
1080 make_panel(TopGroup->w());
1081 customize();
1083
1085 Location->value(loc_text);
1086 Location->take_focus();
1087
1088 dFree(loc_text);
1089}
1090
1094void UI::set_render_layout(Fl_Group *nw)
1095{
1096 // Resize layout widget to current height
1097 nw->resize(0,Main->y(),Main->w(),Main->h());
1098
1099 TopGroup->insert(*nw, Main);
1100 remove(Main);
1101 delete(Main);
1102 Main = nw;
1103 TopGroup->resizable(Main);
1104}
1105
1110{
1111 switch (btn) {
1112 case UI_BACK:
1113 (sens) ? Back->activate() : Back->deactivate();
1114 break;
1115 case UI_FORW:
1116 (sens) ? Forw->activate() : Forw->deactivate();
1117 break;
1118 case UI_STOP:
1119 (sens) ? Stop->activate() : Stop->deactivate();
1120 break;
1121 default:
1122 break;
1123 }
1124}
1125
1130{
1131 Fl::paste(*Clear, false);
1132}
1133
1138{
1139 /* WORKAROUND:
1140 * This is tricky: As fltk-1.3 resizes hidden widgets (which it
1141 * doesn't resize when visible!). We need to set the size to (0,0) to
1142 * get the desired behaviour.
1143 * (STR#2639 in FLTK bug tracker).
1144 */
1145
1146 if (add) {
1147 if (!FindBar->visible())
1148 FindBar->size(w(), fh);
1149 FindBar->show();
1150 } else {
1151 // hide
1152 FindBar->size(0,0);
1153 FindBar->hide();
1154 // reset state
1156 // focus main area
1157 focus_main();
1158 }
1160}
1161
1169{
1170 int hide = StatusBar->visible();
1171
1172 // hide/show panels
1173 init_sizes();
1174 if (LocBar) {
1175 hide ? LocBar->size(0,0) : LocBar->size(w(),lh);
1176 hide ? LocBar->hide() : LocBar->show();
1177 }
1178 if (NavBar) {
1179 hide ? NavBar->size(0,0) : NavBar->size(w(),nh);
1180 hide ? NavBar->hide() : NavBar->show();
1181 }
1182 if (StatusBar) {
1183 hide ? StatusBar->size(0,0) : StatusBar->size(w(),sh);
1184 hide ? StatusBar->hide() : StatusBar->show();
1186 }
1187
1189 Panelmode = (hide) ? UI_HIDDEN : UI_NORMAL;
1190}
#define _MSG(...)
Definition bookmarks.c:44
#define MSG(...)
Definition bookmarks.c:45
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:221
static KeysCommand_t getKeyCmd(void)
Look if the just pressed key is bound to a command.
Definition keys.cc:211
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:980
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:1109
~UI()
UI destructor.
Definition ui.cc:770
void customize()
Customize the UI's panel (show/hide buttons)
Definition ui.cc:1023
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:449
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:1137
void set_render_layout(Fl_Group *nw)
Set 'nw' as the main render area widget.
Definition ui.cc:1094
CustButton * Save
Definition ui.hh:127
Fl_Output * StatusOutput
Definition ui.hh:133
void focus_main()
Focus Main area.
Definition ui.cc:931
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:898
void make_toolbar(int tw, int th)
Create the archetipic browser buttons.
Definition ui.cc:472
void change_panel(int new_size, int small_icons)
On-the-fly panel style change.
Definition ui.cc:1063
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:917
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:778
void make_status_bar(int ww, int wh)
Create the status panel.
Definition ui.cc:682
void make_progress_bars(int wide, int thin_up)
Create the progress bars.
Definition ui.cc:556
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:511
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:713
CustProgressBox * IProg
Definition ui.hh:131
void set_bug_prog(int n_bug)
Set the bug meter progress text.
Definition ui.cc:1001
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:1168
CustButton * BugMeter
Definition ui.hh:128
void set_status(const char *str)
Set a new message in the status bar.
Definition ui.cc:939
void paste_url()
Paste a middle-click-selection into "Clear" button as URL.
Definition ui.cc:1129
void make_panel(int ww)
Create the control panel.
Definition ui.cc:602
CustButton * Forw
Definition ui.hh:127
void set_location(const char *str)
Set a new URL in the location input-box.
Definition ui.cc:906
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:575
void set_page_prog(size_t nbytes, int cmd)
Set the page progress text.
Definition ui.cc:948
char * dStrconcat(const char *s1,...)
Concatenate a NULL-terminated list of strings.
Definition dlib.c:101
void dFree(void *mem)
Definition dlib.c:67
char * dStrdup(const char *s)
Definition dlib.c:76
#define VOIDP2INT(p)
Definition dlib.h:72
#define INT2VOIDP(i)
Definition dlib.h:73
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:356
static void help_cb(Fl_Widget *w, void *)
Callback for the help button.
Definition ui.cc:293
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:428
static void filemenu_cb(Fl_Widget *wid, void *)
Callback for the File menu button.
Definition ui.cc:313
static void location_cb(Fl_Widget *wid, void *data)
Send the browser to the new URL in the location.
Definition ui.cc:340
static void search_cb(Fl_Widget *wid, void *data)
Callback for the search button.
Definition ui.cc:281
static void clear_cb(Fl_Widget *w, void *data)
Callback for the location's clear-button.
Definition ui.cc:324
@ 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:124
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:858
void a_UIcmd_tools(void *vbw, int x, int y)
Definition uicmd.cc:1200
void a_UIcmd_book(void *vbw, int nt)
Definition uicmd.cc:1298
void a_UIcmd_bugmeter_popup(void *vbw)
Definition uicmd.cc:1426
void a_UIcmd_forw_nt(void *vbw)
Definition uicmd.cc:911
void a_UIcmd_home(void *vbw, int nt)
Definition uicmd.cc:927
void a_UIcmd_open_file(void *vbw)
Definition uicmd.cc:1208
void a_UIcmd_zoom_reset(void *vbw)
Definition uicmd.cc:1029
void a_UIcmd_focus_tab(void *vbw, int index)
Definition uicmd.cc:1766
void a_UIcmd_zoom_in(void *vbw)
Definition uicmd.cc:997
void a_UIcmd_zoom_out(void *vbw)
Definition uicmd.cc:1013
void a_UIcmd_focus_main_area(BrowserWindow *bw)
Definition uicmd.cc:1749
void a_UIcmd_reload(void *vbw)
Definition uicmd.cc:938
BrowserWindow * a_UIcmd_get_bw_by_widget(void *v_wid)
Definition uicmd.cc:554
void a_UIcmd_file_popup(void *vbw, void *v_wid)
Definition uicmd.cc:1358
void a_UIcmd_view_page_source(BrowserWindow *bw, const DilloUrl *url)
Definition uicmd.cc:1377
void a_UIcmd_search_dialog(void *vbw)
Definition uicmd.cc:1263
void a_UIcmd_view_page_bugs(void *vbw)
Definition uicmd.cc:1412
void a_UIcmd_open_urlstr(void *vbw, const char *urlstr)
Definition uicmd.cc:774
void a_UIcmd_set_buttons_sens(BrowserWindow *bw)
Definition uicmd.cc:1650
void a_UIcmd_forw_popup(void *vbw, int x, int y)
Definition uicmd.cc:919
void a_UIcmd_save(void *vbw)
Definition uicmd.cc:1165
void a_UIcmd_back(void *vbw)
Definition uicmd.cc:879
void a_UIcmd_forw(void *vbw)
Definition uicmd.cc:903
void a_UIcmd_copy(void *vbw)
Definition uicmd.cc:987
void a_UIcmd_back_popup(void *vbw, int x, int y)
Definition uicmd.cc:895
void a_UIcmd_stop(void *vbw)
Definition uicmd.cc:1187
void a_UIcmd_findtext_reset(BrowserWindow *bw)
Definition uicmd.cc:1730
void a_UIcmd_scroll(BrowserWindow *bw, int icmd)
Definition uicmd.cc:1518
void a_UIcmd_back_nt(void *vbw)
Definition uicmd.cc:887
void a_UIcmd_set_location_text(void *vbw, const char *text)
Definition uicmd.cc:1562