changeset 350:118fe0444e08

- 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
author jcid
date Fri, 26 Sep 2008 00:53:13 +0200
parents 836b65dec53b
children 6fdc59173d00
files dillo2rc src/html.cc src/menu.cc src/prefs.c src/prefs.h src/ui.cc src/ui.hh src/uicmd.cc src/uicmd.hh
diffstat 9 files changed, 149 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/dillo2rc	Wed Sep 24 21:02:34 2008 +0200
+++ b/dillo2rc	Fri Sep 26 00:53:13 2008 +0200
@@ -192,6 +192,15 @@
 # (my experience is that forms that lack a submit rely on Javascript)
 #generate_submit=NO
 
+# A mouse's middle click over a link opens a new Tab.
+# If you prefer to open a new Window instead, set it to NO.
+#middle_click_opens_new_tab=YES
+
+# Focus follows new Tabs.
+# You can hold SHIFT to temporarily revert this behaviour.
+#focus_new_tab=YES
+
+
 #-------------------------------------------------------------------------
 #                        DEBUG MESSAGES SECTION
 #-------------------------------------------------------------------------
--- a/src/html.cc	Wed Sep 24 21:02:34 2008 +0200
+++ b/src/html.cc	Fri Sep 26 00:53:13 2008 +0200
@@ -808,9 +808,14 @@
       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;
       }
--- a/src/menu.cc	Wed Sep 24 21:02:34 2008 +0200
+++ b/src/menu.cc	Fri Sep 26 00:53:13 2008 +0200
@@ -106,11 +106,21 @@
  */
 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 @@
       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 @@
        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");
--- a/src/prefs.c	Wed Sep 24 21:02:34 2008 +0200
+++ b/src/prefs.c	Fri Sep 26 00:53:13 2008 +0200
@@ -65,6 +65,7 @@
    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 @@
    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 @@
    { "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 @@
    { "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 @@
    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 @@
    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 @@
    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 @@
    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;
--- a/src/prefs.h	Wed Sep 24 21:02:34 2008 +0200
+++ b/src/prefs.h	Fri Sep 26 00:53:13 2008 +0200
@@ -36,6 +36,7 @@
    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 @@
    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;
--- a/src/ui.cc	Wed Sep 24 21:02:34 2008 +0200
+++ b/src/ui.cc	Fri Sep 26 00:53:13 2008 +0200
@@ -473,6 +473,8 @@
    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 @@
    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 @@
          } 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;
--- a/src/ui.hh	Wed Sep 24 21:02:34 2008 +0200
+++ b/src/ui.hh	Fri Sep 26 00:53:13 2008 +0200
@@ -36,15 +36,16 @@
    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 @@
    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; }
 
--- a/src/uicmd.cc	Wed Sep 24 21:02:34 2008 +0200
+++ b/src/uicmd.cc	Fri Sep 26 00:53:13 2008 +0200
@@ -79,6 +79,25 @@
       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 @@
    }
 };
 
-static CustTabGroup *DilloTabs = NULL;
 
 /*
  * Create a new UI and its associated BrowserWindow data structure.
@@ -107,28 +125,20 @@
       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 @@
 }
 
 /*
+ * 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 @@
    }
    delete(ui);
 
-   if (DilloTabs->children() <= 1)
-      DilloTabs->hideLabels();
    a_Bw_free(bw);
 }
 
@@ -262,6 +318,20 @@
 }
 
 /*
+ * 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)
--- a/src/uicmd.hh	Wed Sep 24 21:02:34 2008 +0200
+++ b/src/uicmd.hh	Fri Sep 26 00:53:13 2008 +0200
@@ -12,6 +12,7 @@
 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_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);