aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjcid <devnull@localhost>2008-09-26 00:53:13 +0200
committerjcid <devnull@localhost>2008-09-26 00:53:13 +0200
commitf0eaf18f7bf51913b8e10c98ee92c69e6fff6a30 (patch)
tree214b09c3ceebfe19e56093b49ec1953974b695d3 /src
parent061a12750c5fafcb0c582d182975022c3aa8b7ff (diff)
- Added the "middle_click_opens_new_tab" option to dillo2rc.
- Added the "focus_new_tab" option to dillo2rc. - Added "New Tab", "Open Link in new Tab" and "Open Image in new Tab". - Fixed the resizable when removed by tabs
Diffstat (limited to 'src')
-rw-r--r--src/html.cc9
-rw-r--r--src/menu.cc18
-rw-r--r--src/prefs.c12
-rw-r--r--src/prefs.h2
-rw-r--r--src/ui.cc9
-rw-r--r--src/ui.hh9
-rw-r--r--src/uicmd.cc104
-rw-r--r--src/uicmd.hh3
8 files changed, 140 insertions, 26 deletions
diff --git a/src/html.cc b/src/html.cc
index cc8aab43..f5160e5c 100644
--- a/src/html.cc
+++ b/src/html.cc
@@ -808,9 +808,14 @@ bool DilloHtml::HtmlLinkReceiver::click (Widget *widget, int link, int img,
Html_set_link_coordinates(html, link, x, y);
if (event->button == 1) {
- a_Nav_push(bw, url);
+ a_UIcmd_open_url(bw, url);
} else if (event->button == 2) {
- a_Nav_push_nw(bw, url);
+ if (prefs.middle_click_opens_new_tab) {
+ int focus = prefs.focus_new_tab ? 1 : 0;
+ if (event->state == SHIFT_MASK) focus = !focus;
+ a_UIcmd_open_url_nt(bw, url, focus);
+ } else
+ a_UIcmd_open_url_nw(bw, url);
} else {
return false;
}
diff --git a/src/menu.cc b/src/menu.cc
index c6a4bb90..d8d7480d 100644
--- a/src/menu.cc
+++ b/src/menu.cc
@@ -106,11 +106,21 @@ static void Menu_open_url_cb(Widget* )
*/
static void Menu_open_url_nw_cb(Widget* )
{
- MSG("Open URL in new window cb: click! :-)\n");
+ _MSG("Open URL in new window cb: click! :-)\n");
a_UIcmd_open_url_nw(popup_bw, popup_url);
}
/*
+ * Open URL in new Tab
+ */
+static void Menu_open_url_nt_cb(Widget* )
+{
+ int focus = prefs.focus_new_tab ? 1 : 0;
+ if (event_state(SHIFT)) focus = !focus;
+ a_UIcmd_open_url_nt(popup_bw, popup_url, focus);
+}
+
+/*
* Add bookmark
*/
static void Menu_add_bookmark_cb(Widget* )
@@ -303,6 +313,9 @@ void a_Menu_link_popup(BrowserWindow *bw, const DilloUrl *url)
pm->begin();
i = new Item("Open Link in New Window");
i->callback(Menu_open_url_nw_cb);
+ i = new Item("Open Link in New Tab");
+ i->callback(Menu_open_url_nt_cb);
+ new Divider();
i = new Item("Bookmark this Link");
i->callback(Menu_add_bookmark_cb);
i = new Item("Copy Link location");
@@ -343,6 +356,9 @@ void a_Menu_image_popup(BrowserWindow *bw, const DilloUrl *url,
i->callback(Menu_open_url_cb);
i = new Item("Open Image in New Window");
i->callback(Menu_open_url_nw_cb);
+ i = new Item("Open Image in New Tab");
+ i->callback(Menu_open_url_nt_cb);
+ new Divider();
i = load_menuitem = new Item("Load image");
i->callback(Menu_load_images_cb);
i = new Item("Bookmark this Image");
diff --git a/src/prefs.c b/src/prefs.c
index dc453655..3c87f730 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -65,6 +65,7 @@ typedef enum {
DRC_TOKEN_BG_COLOR,
DRC_TOKEN_CONTRAST_VISITED_COLOR,
DRC_TOKEN_ENTERPRESS_FORCES_SUBMIT,
+ DRC_TOKEN_FOCUS_NEW_TAB,
DRC_TOKEN_FONT_FACTOR,
DRC_TOKEN_FORCE_MY_COLORS,
DRC_TOKEN_FULLWINDOW_START,
@@ -75,6 +76,7 @@ typedef enum {
DRC_TOKEN_LIMIT_TEXT_WIDTH,
DRC_TOKEN_LINK_COLOR,
DRC_TOKEN_LOAD_IMAGES,
+ DRC_TOKEN_MIDDLE_CLICK_OPENS_NEW_TAB,
DRC_TOKEN_NOPROXY,
DRC_TOKEN_PANEL_SIZE,
DRC_TOKEN_PROXY,
@@ -123,6 +125,7 @@ static const SymNode_t symbols[] = {
{ "bg_color", DRC_TOKEN_BG_COLOR },
{ "contrast_visited_color", DRC_TOKEN_CONTRAST_VISITED_COLOR },
{ "enterpress_forces_submit", DRC_TOKEN_ENTERPRESS_FORCES_SUBMIT },
+ { "focus_new_tab", DRC_TOKEN_FOCUS_NEW_TAB },
{ "font_factor", DRC_TOKEN_FONT_FACTOR },
{ "force_my_colors", DRC_TOKEN_FORCE_MY_COLORS },
{ "fullwindow_start", DRC_TOKEN_FULLWINDOW_START },
@@ -136,6 +139,7 @@ static const SymNode_t symbols[] = {
{ "limit_text_width", DRC_TOKEN_LIMIT_TEXT_WIDTH },
{ "link_color", DRC_TOKEN_LINK_COLOR },
{ "load_images", DRC_TOKEN_LOAD_IMAGES },
+ { "middle_click_opens_new_tab", DRC_TOKEN_MIDDLE_CLICK_OPENS_NEW_TAB },
{ "no_proxy", DRC_TOKEN_NOPROXY },
{ "panel_size", DRC_TOKEN_PANEL_SIZE },
{ "save_dir", DRC_TOKEN_SAVE_DIR },
@@ -263,6 +267,9 @@ static int Prefs_parse_pair(char *name, char *value)
case DRC_TOKEN_SHOW_TOOLTIP:
prefs.show_tooltip = (strcmp(value, "YES") == 0);
break;
+ case DRC_TOKEN_FOCUS_NEW_TAB:
+ prefs.focus_new_tab = (strcmp(value, "YES") == 0);
+ break;
case DRC_TOKEN_FONT_FACTOR:
prefs.font_factor = strtod(value, NULL);
break;
@@ -328,6 +335,9 @@ static int Prefs_parse_pair(char *name, char *value)
case DRC_TOKEN_ENTERPRESS_FORCES_SUBMIT:
prefs.enterpress_forces_submit = (strcmp(value, "YES") == 0);
break;
+ case DRC_TOKEN_MIDDLE_CLICK_OPENS_NEW_TAB:
+ prefs.middle_click_opens_new_tab = (strcmp(value, "YES") == 0);
+ break;
case DRC_TOKEN_SEARCH_URL:
dFree(prefs.search_url);
prefs.search_url = dStrdup(value);
@@ -418,6 +428,7 @@ void a_Prefs_init(void)
prefs.small_icons = FALSE;
prefs.limit_text_width = FALSE;
prefs.w3c_plus_heuristics = TRUE;
+ prefs.focus_new_tab = TRUE;
prefs.font_factor = 1.0;
prefs.show_back=TRUE;
prefs.show_forw=TRUE;
@@ -437,6 +448,7 @@ void a_Prefs_init(void)
prefs.fw_fontname = dStrdup(D_FW_FONTNAME);
prefs.generate_submit = FALSE;
prefs.enterpress_forces_submit = FALSE;
+ prefs.middle_click_opens_new_tab = TRUE;
prefs.search_url = dStrdup(D_SEARCH_URL);
prefs.save_dir = dStrdup(D_SAVE_DIR);
prefs.show_msg = TRUE;
diff --git a/src/prefs.h b/src/prefs.h
index c7658c80..46096aff 100644
--- a/src/prefs.h
+++ b/src/prefs.h
@@ -36,6 +36,7 @@ struct _DilloPrefs {
bool_t small_icons;
bool_t limit_text_width;
bool_t w3c_plus_heuristics;
+ bool_t focus_new_tab;
double font_factor;
bool_t show_back;
bool_t show_forw;
@@ -55,6 +56,7 @@ struct _DilloPrefs {
char *fw_fontname;
bool_t generate_submit;
bool_t enterpress_forces_submit;
+ bool_t middle_click_opens_new_tab;
char *search_url;
char *save_dir;
bool_t show_msg;
diff --git a/src/ui.cc b/src/ui.cc
index 0529f13f..ffffd7bb 100644
--- a/src/ui.cc
+++ b/src/ui.cc
@@ -473,6 +473,8 @@ static void menubar_cb(Widget *wid, void *data)
if (strcmp((char*)data, "nb") == 0) {
a_UIcmd_browser_window_new(wid->window()->w(), wid->window()->h(),
wid->window()->user_data());
+ } else if (strcmp((char*)data, "nt") == 0) {
+ a_UIcmd_open_url_nt(wid->window()->user_data(), NULL, 1);
} else if (strcmp((char*)data, "of") == 0) {
a_UIcmd_open_file(wid->window()->user_data());
} else if (strcmp((char*)data, "ou") == 0) {
@@ -493,7 +495,9 @@ void UI::make_menubar(int x, int y, int w, int h)
mb->begin();
ItemGroup *g = new ItemGroup( "&File" );
g->begin();
- new Item("&New Browser", COMMAND + 'n', menubar_cb, (void *)"nb");
+ new Item("&New Window", COMMAND + 'n', menubar_cb, (void *)"nb");
+ new Item("New &Tab", COMMAND + 't', menubar_cb, (void *)"nt");
+ new Divider();
new Item("&Open File...", COMMAND + 'o', menubar_cb, (void *)"of");
new Item("Open UR&L...", COMMAND + 'l', menubar_cb, (void *)"ou");
new Item("Close &Window", COMMAND + 'q', menubar_cb, (void *)"cw");
@@ -786,6 +790,9 @@ int UI::handle(int event)
} else if (k == 's') {
a_UIcmd_search_dialog(this->window()->user_data());
ret = 1;
+ } else if (k == 't') {
+ a_UIcmd_open_url_nt(this->window()->user_data(), NULL, 1);
+ ret = 1;
} else if (k == ' ') {
panelmode_cb_i();
ret = 1;
diff --git a/src/ui.hh b/src/ui.hh
index 45659aba..605ccc7b 100644
--- a/src/ui.hh
+++ b/src/ui.hh
@@ -36,15 +36,16 @@ typedef enum {
UI_TEMPORARILY_SHOW_PANELS
} UIPanelmode;
-// Private class
+// Private classes
class CustProgressBox;
+class CustTabGroup;
//
// UI class definition -------------------------------------------------------
//
class UI : public fltk::Group {
void *Bw;
- TabGroup *Tabs;
+ CustTabGroup *Tabs;
char *TabTooltip;
Group *TopGroup;
@@ -105,8 +106,8 @@ public:
Widget *fullscreen_button() { return FullScreen; }
void fullscreen_toggle() { FullScreen->do_callback(); }
- TabGroup *tabs() { return Tabs; }
- void tabs(TabGroup *tabs) { Tabs = tabs; }
+ CustTabGroup *tabs() { return Tabs; }
+ void tabs(CustTabGroup *tabs) { Tabs = tabs; }
void *vbw() { return Bw; }
void vbw(void *v_bw) { Bw = v_bw; }
diff --git a/src/uicmd.cc b/src/uicmd.cc
index 2cc26b8e..ef1d19ff 100644
--- a/src/uicmd.cc
+++ b/src/uicmd.cc
@@ -79,6 +79,25 @@ public:
return TabGroup::handle(e);
}
+ void remove (Widget *w) {
+ TabGroup::remove (w);
+ /* fixup resizable in case we just removed it */
+ if (resizable () == w)
+ if (children () > 0)
+ resizable (child (children () - 1));
+ else
+ resizable (NULL);
+
+ if (children () < 2)
+ hideLabels ();
+ }
+
+ void add (Widget *w) {
+ TabGroup::add (w);
+ if (children () > 1)
+ showLabels ();
+ }
+
void hideLabels() {
for (int i = children () - 1; i >= 0; i--)
child(i)->resize(x(), y(), w(), h());
@@ -90,7 +109,6 @@ public:
}
};
-static CustTabGroup *DilloTabs = NULL;
/*
* Create a new UI and its associated BrowserWindow data structure.
@@ -107,28 +125,20 @@ BrowserWindow *a_UIcmd_browser_window_new(int ww, int wh, const void *vbw)
wh = prefs.height;
}
- if (!DilloTabs) {
- {Window *o = new Window(ww, wh);
- o->shortcut(0); // Ignore Escape
- o->clear_double_buffer();
- DilloTabs = new CustTabGroup(0, 0, ww, wh);
- DilloTabs->selection_color(156);
- //DilloTabs->clear_tab_to_focus();
- o->add(DilloTabs);
- }
- }
+ Window *win = new Window(ww, wh);
+ win->shortcut(0); // Ignore Escape
+ win->clear_double_buffer();
+ CustTabGroup *DilloTabs = new CustTabGroup(0, 0, ww, wh);
+ DilloTabs->selection_color(156);
+ win->add(DilloTabs);
// Create and set the UI
UI *new_ui = new UI(0, 0, ww, wh, "Label", old_bw ? BW2UI(old_bw) : NULL);
new_ui->set_status("http://www.dillo.org/");
new_ui->tabs(DilloTabs);
- //new_ui->set_location("http://dillo.org/");
- //new_ui->customize(12);
DilloTabs->add(new_ui);
DilloTabs->resizable(new_ui);
- if (DilloTabs->children () > 1)
- DilloTabs->showLabels ();
DilloTabs->window()->resizable(new_ui);
DilloTabs->window()->show();
@@ -166,6 +176,54 @@ BrowserWindow *a_UIcmd_browser_window_new(int ww, int wh, const void *vbw)
}
/*
+ * Create a new Tab.
+ * i.e the new UI and its associated BrowserWindow data structure.
+ */
+BrowserWindow *UIcmd_tab_new(const void *vbw)
+{
+ _MSG(" UIcmd_tab_new vbw=%p\n", vbw);
+
+ dReturn_val_if_fail (vbw != NULL, NULL);
+
+ BrowserWindow *new_bw = NULL;
+ BrowserWindow *old_bw = (BrowserWindow*)vbw;
+ UI *ui = BW2UI(old_bw);
+
+ // Create and set the UI
+ UI *new_ui = new UI(0, 0, ui->w(), ui->h(), "Label", ui);
+ new_ui->tabs(ui->tabs());
+
+ new_ui->tabs()->add(new_ui);
+ new_ui->tabs()->resizable(new_ui);
+ new_ui->tabs()->window()->resizable(new_ui);
+ new_ui->tabs()->window()->show();
+
+ // Now create the Dw render layout and viewport
+ FltkPlatform *platform = new FltkPlatform ();
+ Layout *layout = new Layout (platform);
+
+ FltkViewport *viewport = new FltkViewport (0, 0, 1, 1);
+
+ layout->attachView (viewport);
+ new_ui->set_render_layout(*viewport);
+
+ viewport->setScrollStep((int) rint(14.0 * prefs.font_factor));
+
+ // Now, create a new browser window structure
+ new_bw = a_Bw_new();
+
+ // Store new_bw for callback data inside UI
+ new_ui->vbw(new_bw);
+
+ // Reference the UI from the bw
+ new_bw->ui = (void *)new_ui;
+ // Copy the layout pointer into the bw data
+ new_bw->render_layout = (void*)layout;
+
+ return new_bw;
+}
+
+/*
* Close one browser window
*/
void a_UIcmd_close_bw(void *vbw)
@@ -186,8 +244,6 @@ void a_UIcmd_close_bw(void *vbw)
}
delete(ui);
- if (DilloTabs->children() <= 1)
- DilloTabs->hideLabels();
a_Bw_free(bw);
}
@@ -262,6 +318,20 @@ void a_UIcmd_open_url_nw(BrowserWindow *bw, const DilloUrl *url)
}
/*
+ * Open a new URL in a new tab in the same browser window
+ */
+void a_UIcmd_open_url_nt(void *vbw, const DilloUrl *url, int focus)
+{
+ BrowserWindow *new_bw = UIcmd_tab_new(vbw);
+ if (url)
+ a_Nav_push(new_bw, url);
+ if (focus) {
+ BW2UI(new_bw)->tabs()->selected_child(BW2UI(new_bw));
+ BW2UI(new_bw)->tabs()->selected_child()->take_focus();
+ }
+}
+
+/*
* Send the browser back to previous page
*/
void a_UIcmd_back(void *vbw)
diff --git a/src/uicmd.hh b/src/uicmd.hh
index 1dbf0d99..c5c86f6f 100644
--- a/src/uicmd.hh
+++ b/src/uicmd.hh
@@ -12,6 +12,7 @@ BrowserWindow *a_UIcmd_browser_window_new(int ww, int wh, const void *v_bw);
void a_UIcmd_open_urlstr(void *vbw, const char *urlstr);
void a_UIcmd_open_url(BrowserWindow *bw, const DilloUrl *url);
void a_UIcmd_open_url_nw(BrowserWindow *bw, const DilloUrl *url);
+void a_UIcmd_open_url_nt(void *vbw, const DilloUrl *url, int focus);
void a_UIcmd_back(void *vbw);
void a_UIcmd_back_popup(void *vbw);
void a_UIcmd_forw(void *vbw);
@@ -29,7 +30,7 @@ void a_UIcmd_book(void *vbw);
void a_UIcmd_add_bookmark(BrowserWindow *bw, const DilloUrl *url);
void a_UIcmd_fullscreen_toggle(BrowserWindow *bw);
void a_UIcmd_findtext_dialog(BrowserWindow *bw);
-void a_UIcmd_findtext_search(BrowserWindow *bw, const char *key, int case_sens);
+void a_UIcmd_findtext_search(BrowserWindow *bw,const char *key,int case_sens);
void a_UIcmd_findtext_reset(BrowserWindow *bw);
void a_UIcmd_focus_main_area(BrowserWindow *bw);
void a_UIcmd_focus_location(void *vbw);