annotate src/uicmd.cc @ 341:215da0caf90b

- Implemented tabbed browsing.
author jcid
date Thu, 18 Sep 2008 00:16:38 +0200
parents 4a6db4341660
children de7f0e48470f
rev   line source
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
2 * File: uicmd.cc
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
3 *
35
d9e7b35430de Updated copyright lines
jcid
parents: 27
diff changeset
4 * Copyright (C) 2005-2007 Jorge Arellano Cid <jcid@dillo.org>
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
5 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
8 * the Free Software Foundation; either version 3 of the License, or
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
9 * (at your option) any later version.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
10 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
11
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
12 // Functions/Methods for commands triggered from the UI
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
13
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
14
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
15 #include <stdio.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
16 #include <stdarg.h>
27
52953eeba59d Hooked vertical scrolling to the mouse wheel.
jcid
parents: 22
diff changeset
17 #include <math.h> /* for rint */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
18 #include <fltk/Widget.h>
341
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
19 #include <fltk/TabGroup.h>
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
20
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
21 #include "dir.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
22 #include "ui.hh"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
23 #include "uicmd.hh"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
24 #include "timeout.hh"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
25 #include "menu.hh"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
26 #include "dialog.hh"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
27 #include "bookmark.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
28 #include "history.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
29 #include "msg.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
30 #include "prefs.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
31
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
32 #include "dw/fltkviewport.hh"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
33
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
34 #include "nav.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
35
341
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
36 // Handy macro
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
37 #define BW2UI(bw) ((UI*)(bw->ui))
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
38
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
39 // Platform idependent part
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
40 using namespace dw::core;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
41 // FLTK related
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
42 using namespace dw::fltk;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
43
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
44
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
45 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
46 * Local data
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
47 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
48 static char *save_dir = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
49
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
50 using namespace fltk;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
51
341
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
52 //
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
53 // For custom handling of keyboard
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
54 //
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
55 class CustTabGroup : public fltk::TabGroup {
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
56 public:
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
57 CustTabGroup (int x, int y, int ww, int wh, const char *lbl=0) :
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
58 TabGroup(x,y,ww,wh,lbl) {};
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
59 int handle(int e) {
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
60 // Don't focus with arrow keys
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
61 _MSG("CustTabGroup::handle %d\n", e);
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
62 int k = event_key();
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
63 // We're only interested in some flags
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
64 unsigned modifier = event_state() & (SHIFT | CTRL | ALT);
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
65 if (e == KEY) {
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
66 if (k == UpKey || k == DownKey || k == TabKey) {
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
67 return 0;
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
68 } else if (k == LeftKey || k == RightKey) {
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
69 if (modifier == SHIFT) {
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
70 int i = value();
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
71 if (k == LeftKey) {i = i ? i-1 : children()-1;}
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
72 else {i++; if (i >= children()) i = 0;}
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
73 if (value(i)) do_callback();
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
74 return 1;
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
75 }
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
76 return 0;
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
77 }
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
78 }
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
79 return TabGroup::handle(e);
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
80 }
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
81 };
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
82
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
83
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
84 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
85 * Create a new UI and its associated BrowserWindow data structure.
72
fbda2a94d998 - Made "New browser window" inherit the panel style of its parent.
jcid
parents: 56
diff changeset
86 * Use style from v_ui. If non-NULL it must be of type UI*.
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
87 */
341
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
88 BrowserWindow *a_UIcmd_browser_window_new(int ww, int wh, const void *vbw)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
89 {
341
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
90 static TabGroup *DilloTabs = NULL;
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
91 BrowserWindow *old_bw = (BrowserWindow*)vbw;
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
92 BrowserWindow *new_bw = NULL;
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
93
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
94 if (ww <= 0 || wh <= 0) {
8
ab2998c07f18 enabled geometry in preferences
jcid
parents: 0
diff changeset
95 // Set default geometry from dillorc.
ab2998c07f18 enabled geometry in preferences
jcid
parents: 0
diff changeset
96 ww = prefs.width;
ab2998c07f18 enabled geometry in preferences
jcid
parents: 0
diff changeset
97 wh = prefs.height;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
98 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
99
341
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
100 if (!DilloTabs) {
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
101 {Window *o = new Window(ww, wh);
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
102 o->shortcut(0); // Ignore Escape
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
103 o->clear_double_buffer();
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
104 DilloTabs = new CustTabGroup(0, 0, ww, wh);
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
105 DilloTabs->selection_color(156);
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
106 //DilloTabs->clear_tab_to_focus();
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
107 o->add(DilloTabs);
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
108 }
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
109 wh -= 20;
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
110 }
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
111
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
112 // Create and set the UI
341
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
113 UI *new_ui = new UI(0, 20, ww, wh, "Label", old_bw ? BW2UI(old_bw) : NULL);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
114 new_ui->set_status("http://www.dillo.org/");
341
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
115 new_ui->tabs(DilloTabs);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
116 //new_ui->set_location("http://dillo.org/");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
117 //new_ui->customize(12);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
118
341
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
119 DilloTabs->add(new_ui);
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
120 DilloTabs->resizable(new_ui);
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
121 DilloTabs->window()->resizable(new_ui);
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
122 DilloTabs->window()->show();
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
123
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
124 if (old_bw == NULL && prefs.xpos >= 0 && prefs.ypos >= 0) {
91
950979eb5ead - Enabled the geometry offset part (dillorc2).
jcid
parents: 86
diff changeset
125 // position the first window according to preferences
950979eb5ead - Enabled the geometry offset part (dillorc2).
jcid
parents: 86
diff changeset
126 fltk::Rectangle r;
341
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
127 new_ui->window()->borders(&r);
91
950979eb5ead - Enabled the geometry offset part (dillorc2).
jcid
parents: 86
diff changeset
128 // borders() gives x and y border sizes as negative values
341
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
129 new_ui->window()->position(prefs.xpos - r.x(), prefs.ypos - r.y());
91
950979eb5ead - Enabled the geometry offset part (dillorc2).
jcid
parents: 86
diff changeset
130 }
950979eb5ead - Enabled the geometry offset part (dillorc2).
jcid
parents: 86
diff changeset
131
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
132 // Now create the Dw render layout and viewport
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
133 FltkPlatform *platform = new FltkPlatform ();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
134 Layout *layout = new Layout (platform);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
135
86
c6cecbed4727 - Made TopGroup a PackedGroup, simplifying UI code and removing workarounds.
jcid
parents: 72
diff changeset
136 FltkViewport *viewport = new FltkViewport (0, 0, 1, 1);
c6cecbed4727 - Made TopGroup a PackedGroup, simplifying UI code and removing workarounds.
jcid
parents: 72
diff changeset
137
c6cecbed4727 - Made TopGroup a PackedGroup, simplifying UI code and removing workarounds.
jcid
parents: 72
diff changeset
138 layout->attachView (viewport);
c6cecbed4727 - Made TopGroup a PackedGroup, simplifying UI code and removing workarounds.
jcid
parents: 72
diff changeset
139 new_ui->set_render_layout(*viewport);
50
22a3dedcb1a0 - s/camp/field/ s/CAMP/FIELD/
jcid
parents: 48
diff changeset
140
327
7d83c41d52b9 - Adjusted internal font sizes so the default font_factor is 1.0
jcid
parents: 293
diff changeset
141 viewport->setScrollStep((int) rint(14.0 * prefs.font_factor));
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
142
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
143 // Now, create a new browser window structure
341
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
144 new_bw = a_Bw_new();
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
145
341
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
146 // Store new_bw for callback data inside UI
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
147 new_ui->vbw(new_bw);
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
148
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
149 // Reference the UI from the bw
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
150 new_bw->ui = (void *)new_ui;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
151 // Copy the layout pointer into the bw data
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
152 new_bw->render_layout = (void*)layout;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
153
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
154 return new_bw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
155 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
156
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
157 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
158 * Close one browser window
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
159 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
160 void a_UIcmd_close_bw(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
161 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
162 BrowserWindow *bw = (BrowserWindow *)vbw;
341
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
163 UI *ui = BW2UI(bw);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
164 Layout *layout = (Layout*)bw->render_layout;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
165
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
166 MSG("a_UIcmd_close_bw\n");
95
ced56c7bf3f8 - Fixed a segfault bug when closing a bw under active networking.
jcid
parents: 91
diff changeset
167 a_Bw_stop_clients(bw, BW_Root + BW_Img + Bw_Force);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
168 delete(layout);
341
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
169 if (ui->tabs()) {
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
170 ui->tabs()->remove(ui);
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
171 if (ui->tabs()->value() != -1)
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
172 ui->tabs()->selected_child()->take_focus();
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
173 else
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
174 ui->tabs()->window()->hide();
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
175 }
213
9a62d31d6f8b - More switches from destroy() to delete() call for close window.
jcid
parents: 172
diff changeset
176 delete(ui);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
177 a_Bw_free(bw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
178 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
179
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
180 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
181 * Close all the browser windows
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
182 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
183 void a_UIcmd_close_all_bw()
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
184 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
185 BrowserWindow *bw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
186
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
187 while ((bw = a_Bw_get()))
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
188 a_UIcmd_close_bw((void*)bw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
189 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
190
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
191 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
192 * Open a new URL in the given browser window.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
193 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
194 * our custom "file:" URIs are normalized here too.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
195 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
196 void a_UIcmd_open_urlstr(void *vbw, const char *urlstr)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
197 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
198 char *new_urlstr;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
199 DilloUrl *url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
200 int ch;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
201 BrowserWindow *bw = (BrowserWindow*)vbw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
202
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
203 if (urlstr && *urlstr) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
204 /* Filter URL string */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
205 new_urlstr = a_Url_string_strip_delimiters(urlstr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
206
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
207 if (!dStrncasecmp(new_urlstr, "file:", 5)) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
208 /* file URI */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
209 ch = new_urlstr[5];
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
210 if (!ch || ch == '.') {
334
619177c88430 - Forbid dpi GET and POST from non dpi-generated urls.
jcid
parents: 333
diff changeset
211 url = a_Url_new(a_Dir_get_owd(), "file:");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
212 } else if (ch == '~') {
334
619177c88430 - Forbid dpi GET and POST from non dpi-generated urls.
jcid
parents: 333
diff changeset
213 url = a_Url_new(dGethomedir(), "file:");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
214 } else {
334
619177c88430 - Forbid dpi GET and POST from non dpi-generated urls.
jcid
parents: 333
diff changeset
215 url = a_Url_new(new_urlstr, "file:");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
216 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
217
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
218 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
219 /* common case */
334
619177c88430 - Forbid dpi GET and POST from non dpi-generated urls.
jcid
parents: 333
diff changeset
220 url = a_Url_new(new_urlstr, NULL);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
221 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
222 dFree(new_urlstr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
223
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
224 if (url) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
225 a_Nav_push(bw, url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
226 a_Url_free(url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
227 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
228 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
229
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
230 /* let the rendered area have focus */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
231 //gtk_widget_grab_focus(GTK_BIN(bw->render_main_scroll)->child);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
232 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
233
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
234 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
235 * Open a new URL in the given browser window
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
236 */
22
571f09e42ab6 - Hooked "Activate" to the form_receiver.
jcid
parents: 19
diff changeset
237 void a_UIcmd_open_url(BrowserWindow *bw, const DilloUrl *url)
571f09e42ab6 - Hooked "Activate" to the form_receiver.
jcid
parents: 19
diff changeset
238 {
571f09e42ab6 - Hooked "Activate" to the form_receiver.
jcid
parents: 19
diff changeset
239 a_Nav_push(bw, url);
571f09e42ab6 - Hooked "Activate" to the form_receiver.
jcid
parents: 19
diff changeset
240 }
571f09e42ab6 - Hooked "Activate" to the form_receiver.
jcid
parents: 19
diff changeset
241
571f09e42ab6 - Hooked "Activate" to the form_receiver.
jcid
parents: 19
diff changeset
242 /*
571f09e42ab6 - Hooked "Activate" to the form_receiver.
jcid
parents: 19
diff changeset
243 * Open a new URL in the given browser window
571f09e42ab6 - Hooked "Activate" to the form_receiver.
jcid
parents: 19
diff changeset
244 */
11
4a5942beffdf Added some "const" qualifiers.
jcid
parents: 8
diff changeset
245 void a_UIcmd_open_url_nw(BrowserWindow *bw, const DilloUrl *url)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
246 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
247 a_Nav_push_nw(bw, url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
248 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
249
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
250 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
251 * Send the browser back to previous page
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
252 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
253 void a_UIcmd_back(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
254 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
255 a_Nav_back((BrowserWindow*)vbw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
256 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
257
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
258 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
259 * Popup the navigation menu of the Back button
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
260 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
261 void a_UIcmd_back_popup(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
262 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
263 a_Menu_history_popup((BrowserWindow*)vbw, -1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
264 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
265
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
266 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
267 * Send the browser to next page in the history list
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
268 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
269 void a_UIcmd_forw(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
270 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
271 a_Nav_forw((BrowserWindow*)vbw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
272 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
273
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
274 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
275 * Popup the navigation menu of the Forward button
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
276 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
277 void a_UIcmd_forw_popup(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
278 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
279 a_Menu_history_popup((BrowserWindow*)vbw, 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
280 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
281
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
282 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
283 * Send the browser to home URL
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
284 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
285 void a_UIcmd_home(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
286 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
287 a_Nav_home((BrowserWindow*)vbw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
288 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
289
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
290 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
291 * Reload current URL
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
292 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
293 void a_UIcmd_reload(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
294 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
295 a_Nav_reload((BrowserWindow*)vbw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
296 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
297
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
298 /*
40
b8319194f7da Added a save-directory preference (save_dir in dillorc2).
jcid
parents: 35
diff changeset
299 * Return a suitable filename for a given URL path.
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
300 */
51
6ff7b6758e0c Added the "static" qualifier where missing.
jcid
parents: 50
diff changeset
301 static char *UIcmd_make_save_filename(const char *pathstr)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
302 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
303 size_t MaxLen = 64;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
304 char *FileName, *name;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
305 const char *dir = a_UIcmd_get_save_dir();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
306
40
b8319194f7da Added a save-directory preference (save_dir in dillorc2).
jcid
parents: 35
diff changeset
307 if ((name = strrchr(pathstr, '/'))) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
308 if (strlen(++name) > MaxLen) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
309 name = name + strlen(name) - MaxLen;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
310 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
311 FileName = dStrconcat(dir ? dir : "", name, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
312 } else {
40
b8319194f7da Added a save-directory preference (save_dir in dillorc2).
jcid
parents: 35
diff changeset
313 FileName = dStrconcat(dir ? dir : "", pathstr, NULL);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
314 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
315 return FileName;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
316 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
317
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
318 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
319 * Get the default directory for saving files.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
320 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
321 const char *a_UIcmd_get_save_dir()
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
322 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
323 return save_dir;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
324 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
325
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
326 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
327 * Set the default directory for saving files.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
328 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
329 void a_UIcmd_set_save_dir(const char *dir)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
330 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
331 char *p;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
332
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
333 if (dir && (p = strrchr(dir, '/'))) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
334 dFree(save_dir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
335 // assert a trailing '/'
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
336 save_dir = dStrconcat(dir, (p[1] != 0) ? "/" : "", NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
337 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
338 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
339
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
340 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
341 * Save current URL
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
342 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
343 void a_UIcmd_save(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
344 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
345 const char *name;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
346 char *SuggestedName, *urlstr;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
347 DilloUrl *url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
348
40
b8319194f7da Added a save-directory preference (save_dir in dillorc2).
jcid
parents: 35
diff changeset
349 a_UIcmd_set_save_dir(prefs.save_dir);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
350
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
351 urlstr = a_UIcmd_get_location_text((BrowserWindow*)vbw);
334
619177c88430 - Forbid dpi GET and POST from non dpi-generated urls.
jcid
parents: 333
diff changeset
352 url = a_Url_new(urlstr, NULL);
40
b8319194f7da Added a save-directory preference (save_dir in dillorc2).
jcid
parents: 35
diff changeset
353 SuggestedName = UIcmd_make_save_filename(URL_PATH(url));
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
354 name = a_Dialog_save_file("Save Page as File", NULL, SuggestedName);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
355 MSG("a_UIcmd_save: %s\n", name);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
356 dFree(SuggestedName);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
357 dFree(urlstr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
358
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
359 if (name) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
360 a_Nav_save_url((BrowserWindow*)vbw, url, name);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
361 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
362
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
363 a_Url_free(url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
364 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
365
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
366 /*
172
765db4e71128 - Implemented the file input control for forms (work in progress).
jcid
parents: 95
diff changeset
367 * Select a file
765db4e71128 - Implemented the file input control for forms (work in progress).
jcid
parents: 95
diff changeset
368 */
765db4e71128 - Implemented the file input control for forms (work in progress).
jcid
parents: 95
diff changeset
369 const char *a_UIcmd_select_file()
765db4e71128 - Implemented the file input control for forms (work in progress).
jcid
parents: 95
diff changeset
370 {
765db4e71128 - Implemented the file input control for forms (work in progress).
jcid
parents: 95
diff changeset
371 return a_Dialog_select_file("Select a File", NULL, NULL);
765db4e71128 - Implemented the file input control for forms (work in progress).
jcid
parents: 95
diff changeset
372 }
765db4e71128 - Implemented the file input control for forms (work in progress).
jcid
parents: 95
diff changeset
373
765db4e71128 - Implemented the file input control for forms (work in progress).
jcid
parents: 95
diff changeset
374 /*
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
375 * Stop network activity on this bw.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
376 * The stop button was pressed: stop page (and images) downloads.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
377 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
378 void a_UIcmd_stop(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
379 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
380 BrowserWindow *bw = (BrowserWindow *)vbw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
381
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
382 MSG("a_UIcmd_stop()\n");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
383 a_Bw_stop_clients(bw, BW_Root + BW_Img + Bw_Force);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
384 a_UIcmd_set_buttons_sens(bw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
385 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
386
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
387 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
388 * Open URL with dialog chooser
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
389 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
390 void a_UIcmd_open_file(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
391 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
392 char *name;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
393 DilloUrl *url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
394
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
395 name = a_Dialog_open_file("Open File", NULL, "");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
396
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
397 if (name) {
334
619177c88430 - Forbid dpi GET and POST from non dpi-generated urls.
jcid
parents: 333
diff changeset
398 url = a_Url_new(name, "file:");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
399 a_Nav_push((BrowserWindow*)vbw, url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
400 a_Url_free(url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
401 dFree(name);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
402 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
403 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
404
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
405 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
406 * Returns a newly allocated string holding a search url generated from
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
407 * a string of keywords (separarated by blanks) and prefs.search_url.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
408 * The search string is urlencoded.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
409 */
51
6ff7b6758e0c Added the "static" qualifier where missing.
jcid
parents: 50
diff changeset
410 static char *UIcmd_make_search_str(const char *str)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
411 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
412 char *keys = a_Url_encode_hex_str(str), *c = prefs.search_url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
413 Dstr *ds = dStr_sized_new(128);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
414 char *search_url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
415
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
416 for (; *c; c++) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
417 if (*c == '%')
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
418 switch(*++c) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
419 case 's':
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
420 dStr_append(ds, keys); break;;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
421 case '%':
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
422 dStr_append_c(ds, '%'); break;;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
423 case 0:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
424 MSG_WARN("search_url ends with '%%'\n"); c--; break;;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
425 default:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
426 MSG_WARN("illegal specifier '%%%c' in search_url\n", *c);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
427 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
428 else
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
429 dStr_append_c(ds, *c);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
430 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
431 dFree(keys);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
432
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
433 search_url = ds->str;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
434 dStr_free(ds, 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
435 return search_url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
436 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
437
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
438 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
439 * Get a query from a dialog and open it
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
440 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
441 void a_UIcmd_search_dialog(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
442 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
443 const char *query, *url_str;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
444
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
445 if ((query = a_Dialog_input("Search the Web:"))) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
446 url_str = UIcmd_make_search_str(query);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
447 a_UIcmd_open_urlstr(vbw, url_str);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
448 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
449 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
450
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
451 /*
241
78fa66a3ba64 - Enabled proxy_user in preferences.
jcid
parents: 224
diff changeset
452 * Get password for user
78fa66a3ba64 - Enabled proxy_user in preferences.
jcid
parents: 224
diff changeset
453 */
78fa66a3ba64 - Enabled proxy_user in preferences.
jcid
parents: 224
diff changeset
454 const char *a_UIcmd_get_passwd(const char *user)
78fa66a3ba64 - Enabled proxy_user in preferences.
jcid
parents: 224
diff changeset
455 {
78fa66a3ba64 - Enabled proxy_user in preferences.
jcid
parents: 224
diff changeset
456 const char *passwd;
78fa66a3ba64 - Enabled proxy_user in preferences.
jcid
parents: 224
diff changeset
457 char *prompt = dStrconcat("Password for user \"", user, "\"", NULL);
78fa66a3ba64 - Enabled proxy_user in preferences.
jcid
parents: 224
diff changeset
458 passwd = a_Dialog_passwd(prompt);
78fa66a3ba64 - Enabled proxy_user in preferences.
jcid
parents: 224
diff changeset
459 dFree(prompt);
78fa66a3ba64 - Enabled proxy_user in preferences.
jcid
parents: 224
diff changeset
460 return passwd;
78fa66a3ba64 - Enabled proxy_user in preferences.
jcid
parents: 224
diff changeset
461 }
78fa66a3ba64 - Enabled proxy_user in preferences.
jcid
parents: 224
diff changeset
462
78fa66a3ba64 - Enabled proxy_user in preferences.
jcid
parents: 224
diff changeset
463 /*
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
464 * Save link URL
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
465 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
466 void a_UIcmd_save_link(BrowserWindow *bw, const DilloUrl *url)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
467 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
468 const char *name;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
469 char *SuggestedName;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
470
42
42bc9637b93d Fixed a bug in the save_dir patch
jcid
parents: 40
diff changeset
471 a_UIcmd_set_save_dir(prefs.save_dir);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
472
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
473 SuggestedName = UIcmd_make_save_filename(URL_STR(url));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
474 name = a_Dialog_save_file("Save Link as File", NULL, SuggestedName);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
475 MSG("a_UIcmd_save_link: %s\n", name);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
476 dFree(SuggestedName);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
477
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
478 if (name) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
479 a_Nav_save_url(bw, url, name);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
480 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
481 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
482
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
483 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
484 * Request the bookmarks page
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
485 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
486 void a_UIcmd_book(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
487 {
334
619177c88430 - Forbid dpi GET and POST from non dpi-generated urls.
jcid
parents: 333
diff changeset
488 DilloUrl *url = a_Url_new("dpi:/bm/", NULL);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
489 a_Nav_push((BrowserWindow*)vbw, url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
490 a_Url_free(url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
491 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
492
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
493 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
494 * Add a bookmark for a certain URL
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
495 */
11
4a5942beffdf Added some "const" qualifiers.
jcid
parents: 8
diff changeset
496 void a_UIcmd_add_bookmark(BrowserWindow *bw, const DilloUrl *url)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
497 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
498 a_Bookmarks_add(bw, url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
499 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
500
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
501
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
502 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
503 * Popup the page menu
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
504 */
48
224c9f547b39 Implemented "Load Images" in the page menu and cleaned up html.hh.
jcid
parents: 42
diff changeset
505 void a_UIcmd_page_popup(void *vbw, const DilloUrl *url,
328
6a5b6bbf9836 - Fixed the "Load Images" menu item in the page popup.
jcid
parents: 327
diff changeset
506 const char *bugs_txt, bool_t unloaded_imgs)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
507 {
328
6a5b6bbf9836 - Fixed the "Load Images" menu item in the page popup.
jcid
parents: 327
diff changeset
508 a_Menu_page_popup((BrowserWindow*)vbw, url, bugs_txt, unloaded_imgs);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
509 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
510
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
511 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
512 * Popup the link menu
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
513 */
11
4a5942beffdf Added some "const" qualifiers.
jcid
parents: 8
diff changeset
514 void a_UIcmd_link_popup(void *vbw, const DilloUrl *url)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
515 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
516 a_Menu_link_popup((BrowserWindow*)vbw, url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
517 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
518
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
519 /*
22
571f09e42ab6 - Hooked "Activate" to the form_receiver.
jcid
parents: 19
diff changeset
520 * Pop up the image menu
571f09e42ab6 - Hooked "Activate" to the form_receiver.
jcid
parents: 19
diff changeset
521 */
571f09e42ab6 - Hooked "Activate" to the form_receiver.
jcid
parents: 19
diff changeset
522 void a_UIcmd_image_popup(void *vbw, const DilloUrl *url, DilloUrl *link_url)
571f09e42ab6 - Hooked "Activate" to the form_receiver.
jcid
parents: 19
diff changeset
523 {
571f09e42ab6 - Hooked "Activate" to the form_receiver.
jcid
parents: 19
diff changeset
524 a_Menu_image_popup((BrowserWindow*)vbw, url, link_url);
571f09e42ab6 - Hooked "Activate" to the form_receiver.
jcid
parents: 19
diff changeset
525 }
571f09e42ab6 - Hooked "Activate" to the form_receiver.
jcid
parents: 19
diff changeset
526
571f09e42ab6 - Hooked "Activate" to the form_receiver.
jcid
parents: 19
diff changeset
527 /*
55
a1f38544fab6 copy image/link location
jcid
parents: 51
diff changeset
528 * Copy url string to paste buffer
a1f38544fab6 copy image/link location
jcid
parents: 51
diff changeset
529 */
a1f38544fab6 copy image/link location
jcid
parents: 51
diff changeset
530 void a_UIcmd_copy_urlstr(BrowserWindow *bw, const char *urlstr)
a1f38544fab6 copy image/link location
jcid
parents: 51
diff changeset
531 {
a1f38544fab6 copy image/link location
jcid
parents: 51
diff changeset
532 Layout *layout = (Layout*)bw->render_layout;
a1f38544fab6 copy image/link location
jcid
parents: 51
diff changeset
533 layout->copySelection(urlstr);
a1f38544fab6 copy image/link location
jcid
parents: 51
diff changeset
534 }
a1f38544fab6 copy image/link location
jcid
parents: 51
diff changeset
535
a1f38544fab6 copy image/link location
jcid
parents: 51
diff changeset
536 /*
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
537 * Show a text window with the URL's source
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
538 */
11
4a5942beffdf Added some "const" qualifiers.
jcid
parents: 8
diff changeset
539 void a_UIcmd_view_page_source(const DilloUrl *url)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
540 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
541 char *buf;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
542 int buf_size;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
543
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
544 if (a_Nav_get_buf(url, &buf, &buf_size)) {
260
81fc5011ea56 - Moved charset decoding into cache.
jcid
parents: 241
diff changeset
545 void *vWindow = a_Dialog_make_text_window(buf, "View Page source");
81fc5011ea56 - Moved charset decoding into cache.
jcid
parents: 241
diff changeset
546 a_Nav_unref_buf(url);
81fc5011ea56 - Moved charset decoding into cache.
jcid
parents: 241
diff changeset
547 a_Dialog_show_text_window(vWindow);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
548 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
549 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
550
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
551 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
552 * Show a text window with the URL's source
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
553 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
554 void a_UIcmd_view_page_bugs(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
555 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
556 BrowserWindow *bw = (BrowserWindow*)vbw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
557
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
558 if (bw->num_page_bugs > 0) {
260
81fc5011ea56 - Moved charset decoding into cache.
jcid
parents: 241
diff changeset
559 void *vWindow = a_Dialog_make_text_window(bw->page_bugs->str,
81fc5011ea56 - Moved charset decoding into cache.
jcid
parents: 241
diff changeset
560 "Detected HTML errors");
81fc5011ea56 - Moved charset decoding into cache.
jcid
parents: 241
diff changeset
561 a_Dialog_show_text_window(vWindow);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
562 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
563 a_Dialog_msg("Zero detected HTML errors!");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
564 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
565 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
566
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
567 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
568 * Popup the bug meter menu
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
569 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
570 void a_UIcmd_bugmeter_popup(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
571 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
572 BrowserWindow *bw = (BrowserWindow*)vbw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
573
19
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
574 a_Menu_bugmeter_popup(bw, a_History_get_url(NAV_TOP_UIDX(bw)));
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
575 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
576
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
577 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
578 * Make a list of URL indexes for the history popup
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
579 * based on direction (-1 = back, 1 = forward)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
580 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
581 int *a_UIcmd_get_history(BrowserWindow *bw, int direction)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
582 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
583 int i, j, n;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
584 int *hlist;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
585
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
586 // Count the number of URLs
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
587 i = a_Nav_stack_ptr(bw) + direction;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
588 for (n = 0 ; i >= 0 && i < a_Nav_stack_size(bw); i+=direction)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
589 ++n;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
590 hlist = dNew(int, n + 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
591
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
592 // Fill the list
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
593 i = a_Nav_stack_ptr(bw) + direction;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
594 for (j = 0 ; i >= 0 && i < a_Nav_stack_size(bw); i+=direction, j += 1) {
19
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
595 hlist[j] = NAV_UIDX(bw,i);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
596 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
597 hlist[j] = -1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
598
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
599 return hlist;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
600 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
601
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
602 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
603 * Jump to a certain URL in the navigation stack.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
604 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
605 void a_UIcmd_nav_jump(BrowserWindow *bw, int offset, int new_bw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
606 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
607 a_Nav_jump(bw, offset, new_bw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
608 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
609
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
610 // UI binding functions -------------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
611
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
612 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
613 * Return browser window width and height
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
614 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
615 void a_UIcmd_get_wh(BrowserWindow *bw, int *w, int *h)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
616 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
617 *w = BW2UI(bw)->w();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
618 *h = BW2UI(bw)->h();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
619 _MSG("a_UIcmd_wh: w=%d, h=%d\n", *w, *h);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
620 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
621
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
622 /*
15
a15e6c075023 Fixed the problem of scrolling position (remember position in a page)
jcid
parents: 11
diff changeset
623 * Get the scroll position (x, y offset pair)
a15e6c075023 Fixed the problem of scrolling position (remember position in a page)
jcid
parents: 11
diff changeset
624 */
a15e6c075023 Fixed the problem of scrolling position (remember position in a page)
jcid
parents: 11
diff changeset
625 void a_UIcmd_get_scroll_xy(BrowserWindow *bw, int *x, int *y)
a15e6c075023 Fixed the problem of scrolling position (remember position in a page)
jcid
parents: 11
diff changeset
626 {
a15e6c075023 Fixed the problem of scrolling position (remember position in a page)
jcid
parents: 11
diff changeset
627 Layout *layout = (Layout*)bw->render_layout;
a15e6c075023 Fixed the problem of scrolling position (remember position in a page)
jcid
parents: 11
diff changeset
628
a15e6c075023 Fixed the problem of scrolling position (remember position in a page)
jcid
parents: 11
diff changeset
629 if (layout) {
a15e6c075023 Fixed the problem of scrolling position (remember position in a page)
jcid
parents: 11
diff changeset
630 *x = layout->getScrollPosX();
a15e6c075023 Fixed the problem of scrolling position (remember position in a page)
jcid
parents: 11
diff changeset
631 *y = layout->getScrollPosY();
a15e6c075023 Fixed the problem of scrolling position (remember position in a page)
jcid
parents: 11
diff changeset
632 }
a15e6c075023 Fixed the problem of scrolling position (remember position in a page)
jcid
parents: 11
diff changeset
633 }
a15e6c075023 Fixed the problem of scrolling position (remember position in a page)
jcid
parents: 11
diff changeset
634
a15e6c075023 Fixed the problem of scrolling position (remember position in a page)
jcid
parents: 11
diff changeset
635 /*
19
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
636 * Set the scroll position ({x, y} offset pair)
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
637 */
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
638 void a_UIcmd_set_scroll_xy(BrowserWindow *bw, int x, int y)
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
639 {
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
640 Layout *layout = (Layout*)bw->render_layout;
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
641
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
642 if (layout) {
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
643 layout->scrollTo(HPOS_LEFT, VPOS_TOP, x, y, 0, 0);
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
644 }
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
645 }
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
646
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
647 /*
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
648 * Set the scroll position by fragment (from URL)
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
649 */
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
650 void a_UIcmd_set_scroll_by_fragment(BrowserWindow *bw, const char *f)
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
651 {
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
652 Layout *layout = (Layout*)bw->render_layout;
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
653
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
654 if (layout && f) {
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
655 layout->setAnchor(f);
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
656 }
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
657 }
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
658
145bd87089e7 Implemented a new scheme of scroll-position remembering. This is one per
jcid
parents: 15
diff changeset
659 /*
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
660 * Get location's text
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
661 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
662 char *a_UIcmd_get_location_text(BrowserWindow *bw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
663 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
664 return dStrdup(BW2UI(bw)->get_location());
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
665 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
666
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
667 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
668 * Set location's text
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
669 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
670 void a_UIcmd_set_location_text(void *vbw, const char *text)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
671 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
672 BrowserWindow *bw = (BrowserWindow*)vbw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
673 BW2UI(bw)->set_location(text);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
674 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
675
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
676 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
677 * Set the page progress bar
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
678 * cmd: 0 Deactivate, 1 Update, 2 Clear
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
679 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
680 void a_UIcmd_set_page_prog(BrowserWindow *bw, size_t nbytes, int cmd)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
681 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
682 BW2UI(bw)->set_page_prog(nbytes, cmd);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
683 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
684
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
685 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
686 * Set the images progress bar
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
687 * cmd: 0 Deactivate, 1 Update, 2 Clear
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
688 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
689 void a_UIcmd_set_img_prog(BrowserWindow *bw, int n_img, int t_img, int cmd)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
690 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
691 BW2UI(bw)->set_img_prog(n_img, t_img, cmd);
291
f8ec5a664371 - Updated AUTHORS
jcid
parents: 260
diff changeset
692 #if 0
293
8b9684badb34 - Added a minor debug feature.
jcid
parents: 291
diff changeset
693 if (!cmd)
291
f8ec5a664371 - Updated AUTHORS
jcid
parents: 260
diff changeset
694 a_UIcmd_close_bw(bw);
f8ec5a664371 - Updated AUTHORS
jcid
parents: 260
diff changeset
695 #endif
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
696 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
697
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
698 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
699 * Set the bug meter progress label
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
700 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
701 void a_UIcmd_set_bug_prog(BrowserWindow *bw, int n_bug)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
702 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
703 BW2UI(bw)->set_bug_prog(n_bug);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
704 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
705
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
706 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
707 * Set the page title.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
708 * now it goes to the window titlebar (maybe to TAB label in the future).
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
709 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
710 void a_UIcmd_set_page_title(BrowserWindow *bw, const char *label)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
711 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
712 BW2UI(bw)->set_page_title(label);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
713 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
714
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
715 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
716 * Set a printf-like status string on the bottom of the dillo window.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
717 * Beware: The safe way to set an arbitrary string is
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
718 * a_UIcmd_set_msg(bw, "%s", str)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
719 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
720 void a_UIcmd_set_msg(BrowserWindow *bw, const char *format, ...)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
721 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
722 va_list argp;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
723 Dstr *ds = dStr_sized_new(128);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
724 va_start(argp, format);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
725 dStr_vsprintf(ds, format, argp);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
726 va_end(argp);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
727 BW2UI(bw)->set_status(ds->str);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
728 dStr_free(ds, 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
729 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
730
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
731 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
732 * Set the sensitivity of back/forw/stop buttons.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
733 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
734 static void a_UIcmd_set_buttons_sens_cb(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
735 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
736 int sens;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
737 BrowserWindow *bw = (BrowserWindow*)vbw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
738
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
739 // Stop
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
740 sens = (dList_length(bw->ImageClients) || dList_length(bw->RootClients));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
741 BW2UI(bw)->button_set_sens(UI_STOP, sens);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
742 // Back
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
743 sens = (a_Nav_stack_ptr(bw) > 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
744 BW2UI(bw)->button_set_sens(UI_BACK, sens);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
745 // Forward
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
746 sens = (a_Nav_stack_ptr(bw) < a_Nav_stack_size(bw) - 1 &&
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
747 !bw->nav_expecting);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
748 BW2UI(bw)->button_set_sens(UI_FORW, sens);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
749
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
750 bw->sens_idle_up = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
751 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
752
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
753
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
754 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
755 * Set the timeout function for button sensitivity
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
756 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
757 void a_UIcmd_set_buttons_sens(BrowserWindow *bw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
758 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
759 if (bw->sens_idle_up == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
760 a_Timeout_add(0.0, a_UIcmd_set_buttons_sens_cb, bw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
761 bw->sens_idle_up = 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
762 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
763 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
764
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
765 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
766 * Toggle control panel (aka. fullscreen)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
767 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
768 void a_UIcmd_fullscreen_toggle(BrowserWindow *bw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
769 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
770 BW2UI(bw)->fullscreen_toggle();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
771 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
772
56
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
773 /*
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
774 * Search for next occurrence of key.
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
775 */
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
776 void a_UIcmd_findtext_search(BrowserWindow *bw, const char *key, int case_sens)
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
777 {
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
778 Layout *l = (Layout *)bw->render_layout;
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
779
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
780 switch (l->search(key, case_sens)) {
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
781 case FindtextState::RESTART:
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
782 a_UIcmd_set_msg(bw, "No further occurrences of \"%s\". "
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
783 "Restarting from the top.", key);
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
784 break;
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
785 case FindtextState::NOT_FOUND:
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
786 a_UIcmd_set_msg(bw, "\"%s\" not found.", key);
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
787 break;
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
788 case FindtextState::SUCCESS:
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
789 default:
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
790 a_UIcmd_set_msg(bw, "");
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
791 }
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
792 }
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
793
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
794 /*
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
795 * Reset text search state.
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
796 */
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
797 void a_UIcmd_findtext_reset(BrowserWindow *bw)
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
798 {
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
799 Layout *l = (Layout *)bw->render_layout;
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
800 l->resetSearch();
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
801
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
802 a_UIcmd_set_msg(bw, "");
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
803 }
7bf5884218c4 - Bound Ctrl+Space to fullscreen toggle.
jcid
parents: 55
diff changeset
804
341
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
805 /*
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
806 * Focus the rendered area.
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
807 */
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
808 void a_UIcmd_focus_main_area(BrowserWindow *bw)
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
809 {
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
810 BW2UI(bw)->focus_main();
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
811 }
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
812
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
813 /*
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
814 * Focus the location bar.
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
815 */
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
816 void a_UIcmd_focus_location(void *vbw)
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
817 {
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
818 BrowserWindow *bw = (BrowserWindow*)vbw;
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
819 BW2UI(bw)->focus_location();
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
820 }
215da0caf90b - Implemented tabbed browsing.
jcid
parents: 335
diff changeset
821