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