changeset 827:d513abcd4949

Implemented the tools button with CSS options. Also removed nav.h from html.cc
author Jorge Arellano Cid <jcid@dillo.org>
date Tue, 27 Jan 2009 18:30:24 -0300
parents b04673615946
children 17b50727731a
files ChangeLog src/history.c src/history.h src/html.cc src/menu.cc src/menu.hh src/pixmaps.h src/plain.cc src/ui.cc src/ui.hh src/uicmd.cc src/uicmd.hh
diffstat 12 files changed, 245 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Jan 26 22:46:07 2009 +0100
+++ b/ChangeLog	Tue Jan 27 18:30:24 2009 -0300
@@ -53,6 +53,8 @@
  - Implemented CSS Stylesheet loading.
  - Made a big cleanup of cache.c WRT charset decoding (fixes bugs).
  - Made an extensive cleanup/fixup of the whole image handling process.
+ - Implemented the tools button with a couple CSS options.
+ - Removed the nav.h dependency from html.cc
    Patches: Jorge Arellano Cid
 
 dw
--- a/src/history.c	Mon Jan 26 22:46:07 2009 +0100
+++ b/src/history.c	Tue Jan 27 18:30:24 2009 -0300
@@ -75,19 +75,6 @@
 }
 
 /*
- * Set the page-title for a given URL (by idx)
- * (this is known when the first chunks of HTML data arrive)
- */
-int a_History_set_title(int idx, const char *title)
-{
-   dReturn_val_if_fail(idx >= 0 && idx < history_size, 0);
-
-   dFree(history[idx].title);
-   history[idx].title = dStrdup(title);
-   return 1;
-}
-
-/*
  * Return the DilloUrl field (by index)
  */
 DilloUrl *a_History_get_url(int idx)
@@ -137,6 +124,27 @@
    return NULL;
 }
 
+/*
+ * Set the page-title for a given URL
+ */
+void a_History_set_title_by_url(const DilloUrl *url, const char *title)
+{
+   int i;
+
+   dReturn_if (url == NULL);
+
+   for (i = history_size - 1; i >= 0; --i)
+      if (a_Url_cmp(url, history[i].url) == 0)
+         break;
+
+   if (i >= 0) {
+      dFree(history[i].title);
+      history[i].title = dStrdup(title);
+   } else {
+      MSG_ERR("a_History_set_title_by_url: %s not found\n", URL_STR(url));
+   }
+}
+
 
 /*
  * Free all the memory used by this module
--- a/src/history.h	Mon Jan 26 22:46:07 2009 +0100
+++ b/src/history.h	Tue Jan 27 18:30:24 2009 -0300
@@ -10,7 +10,7 @@
 #endif /* __cplusplus */
 
 int a_History_add_url(DilloUrl *url);
-int a_History_set_title(int idx, const char *title);
+void a_History_set_title_by_url(const DilloUrl *url, const char *title);
 DilloUrl *a_History_get_url(int idx);
 const char *a_History_get_title(int idx, int force);
 const char *a_History_get_title_by_url(const DilloUrl *url, int force);
--- a/src/html.cc	Mon Jan 26 22:46:07 2009 +0100
+++ b/src/html.cc	Tue Jan 27 18:30:24 2009 -0300
@@ -33,7 +33,6 @@
 #include "misc.h"
 #include "uicmd.hh"
 #include "history.h"
-#include "nav.h"
 #include "menu.hh"
 #include "prefs.h"
 #include "capi.h"
@@ -721,8 +720,7 @@
          ret = true;
       } else {
          if (link == -1) {
-            a_UIcmd_page_popup(bw, a_History_get_url(NAV_TOP_UIDX(bw)),
-                               bw->num_page_bugs != 0,
+            a_UIcmd_page_popup(bw, bw->num_page_bugs != 0,
                                html->unloadedImages());
             ret = true;
          } else {
@@ -1575,7 +1573,7 @@
       if (html->repush_after_head) {
          html->stop_parser = true;
          MSG(" [html->stop_parser = true]\n");
-         a_Nav_repush(html->bw);
+         a_UIcmd_repush(html->bw);
       }
    }
 }
@@ -1599,7 +1597,7 @@
    if (html->InFlags & IN_HEAD) {
       /* title is only valid inside HEAD */
       a_UIcmd_set_page_title(html->bw, html->Stash->str);
-      a_History_set_title(NAV_TOP_UIDX(html->bw),html->Stash->str);
+      a_History_set_title_by_url(html->page_url, html->Stash->str);
    } else {
       BUG_MSG("the TITLE element must be inside the HEAD section\n");
    }
@@ -2792,7 +2790,7 @@
       BrowserWindow *bw = ((DilloWeb *)Client->Web)->bw;
       /* Repush when we've got them all */
       if (--bw->NumPendingStyleSheets == 0)
-         a_Nav_repush(bw);
+         a_UIcmd_repush(bw);
    }
 }
 
@@ -2803,11 +2801,11 @@
 {
    char *data;
    int len;
-   if (a_Nav_get_buf(url, &data, &len)) {
+   if (a_Capi_get_buf(url, &data, &len)) {
       /* Haven't looked into what origin_count is */
       if (a_Capi_get_flags(url) & CAPI_Completed)
          html->styleEngine->parse(data, len, 0, CSS_ORIGIN_AUTHOR);
-      a_Nav_unref_buf(url);
+      a_Capi_unref_buf(url);
    } else if (!html->repush_after_head) {
       /* Fill a Web structure for the cache query */
       int ClientKey;
@@ -2838,9 +2836,11 @@
    //MSG("Html_tag_open_link(): %s\n", tag_str);
    //dFree(tag_str);
 
+   /* Remote stylesheets enabled? */
+   dReturn_if_fail (prefs.load_stylesheets);
    /* When viewing suspicious HTML email, don't load LINK */
-   if (URL_FLAGS(html->base_url) & URL_SpamSafe)
-      return;
+   dReturn_if (URL_FLAGS(html->base_url) & URL_SpamSafe);
+
    /* Ignore LINK outside HEAD */
    if (!(html->InFlags & IN_HEAD)) {
       BUG_MSG("the LINK element must be inside the HEAD section\n");
--- a/src/menu.cc	Mon Jan 26 22:46:07 2009 +0100
+++ b/src/menu.cc	Tue Jan 27 18:30:24 2009 -0300
@@ -16,6 +16,7 @@
 #include <fltk/events.h>
 #include <fltk/PopupMenu.h>
 #include <fltk/Item.h>
+#include <fltk/ToggleItem.h>
 #include <fltk/Divider.h>
 
 #include "msg.h"
@@ -619,7 +620,6 @@
  */
 void a_Menu_history_popup(BrowserWindow *bw, int direction)
 {
-   // One menu for every browser window
    static PopupMenu *pm = 0;
    Item *it;
    int i;
@@ -654,3 +654,51 @@
    pm->popup();
 }
 
+/*
+ * Toggle use of remote stylesheets
+ */ 
+static void Menu_remote_css_cb(Widget *wid)
+{
+   _MSG("Menu_remote_css_cb\n");
+   prefs.load_stylesheets = wid->state() ? 1 : 0;
+   a_UIcmd_repush(popup_bw);
+}
+
+/*
+ * Toggle use of embedded CSS style
+ */ 
+static void Menu_embedded_css_cb(Widget *wid)
+{
+   prefs.parse_embedded_css = wid->state() ? 1 : 0;
+   a_UIcmd_repush(popup_bw);
+}
+
+/*
+ * Tools popup menu (construction & popup)
+ */
+void a_Menu_tools_popup(BrowserWindow *bw, void *v_wid)
+{
+   // One menu shared by every browser window
+   static PopupMenu *pm = NULL;
+   Widget *wid = (Widget*)v_wid;
+   Item *it;
+
+   popup_bw = bw;
+
+   if (!pm) {
+      pm = new PopupMenu(0,0,0,0, "TOOLS");
+      pm->begin();
+       it = new ToggleItem("Use remote CSS");
+       it->callback(Menu_remote_css_cb);
+       it->state(true);
+       it = new ToggleItem("Use embedded CSS");
+       it->callback(Menu_embedded_css_cb);
+       it->state(true);
+       pm->type(PopupMenu::POPUP13);
+      pm->end();
+   }
+   //pm->popup();
+   pm->value(-1);
+   ((Menu*)pm)->popup(Rectangle(0,wid->h(),pm->w(),pm->h()));
+}
+
--- a/src/menu.hh	Mon Jan 26 22:46:07 2009 +0100
+++ b/src/menu.hh	Tue Jan 27 18:30:24 2009 -0300
@@ -17,6 +17,7 @@
 void a_Menu_file_popup(BrowserWindow *bw, void *v_wid);
 void a_Menu_bugmeter_popup(BrowserWindow *bw, const DilloUrl *url);
 void a_Menu_history_popup(BrowserWindow *bw, int direction);
+void a_Menu_tools_popup(BrowserWindow *bw, void *v_wid);
 
 
 #ifdef __cplusplus
--- a/src/pixmaps.h	Mon Jan 26 22:46:07 2009 +0100
+++ b/src/pixmaps.h	Tue Jan 27 18:30:24 2009 -0300
@@ -675,6 +675,7 @@
 "     .KLLLLLLLK.      ",
 "      .........       ",
 "                      "};
+
 /* XPM */
 static const char *const bm_xpm[] = {
 "22 22 86 1",
@@ -787,6 +788,57 @@
 "         .S. TU.      ",
 "          .   .       "};
 
+/* XPM */
+static const char *const tools_xpm[] = {
+"22 22 25 1",
+"       c #None",
+".      c #696977777676",
+"X      c #96969B9B9B9B",
+"o      c #848490908F8F",
+"O      c #D7D7D7D7D7D7",
+"+      c #B5B5B7B7B7B7",
+"@      c #EAEAEAEAEAEA",
+"#      c #797987878787",
+"$      c #F1F1EFEFEFEF",
+"%      c #CCCCCCCCCCCC",
+"&      c #8B8B97979696",
+"*      c #CACACACACACA",
+"=      c #787878787878",
+"-      c #AAAAB5B5B5B5",
+";      c #F9F9F8F8F9F9",
+":      c #A6A6A8A8A8A8",
+">      c #7F7F90907F7F",
+",      c #A4A4BDBDA4A4",
+"<      c #A5A58A8A5353",
+"1      c #00008B8B0000",
+"2      c #6C6C6C6C6C6C",
+"3      c #BCBCC3C3C2C2",
+"4      c #CACAD8D8D8D8",
+"5      c #9999A8A8A8A8",
+"6      c #848489898989",
+"                      ",
+"                      ",
+"        .XXo.         ",
+"        oO $$+.       ",
+"        oo@$$$@#      ",
+"         #o@$$$O#     ",
+"          #X$$$$%X    ",
+"  &#%      #X$$$@o    ",
+"  #*o      =-@$$$#    ",
+"  oO*o    #$@$$$$#    ",
+"  oOOOX  oO@;$$$$X    ",
+"  #@O*OXo:>,<$$$$o    ",
+"  XO@O*O*12>,<$$$#    ",
+"   X$@O*+<12>,<$$&    ",
+"    +$@O*+<12>,<;@    ",
+"     :$@O*+<12>,<$@   ",
+"      &34O*-<11>,<$$  ",
+"        -X&X&<12>,<$O ",
+"            45<11>,<3 ",
+"             45<1=>O# ",
+"              -&X6&=# ",
+"                      "};
+
 /* Small icons here */
 
 /* XPM */
@@ -1321,6 +1373,73 @@
 "      .v. wx.   "};
 
 /* XPM */
+static const char *const tools_s_xpm[] = {
+"16 16 45 1",
+"  c #7B127D1C7D08",
+". c #82778EED8E15",
+"X c #8F3F975396FF",
+"o c #9A98A40CA38F",
+"O c #833D8EC28E02",
+"+ c #99C89EDF9EC2",
+"@ c #B347BD91BD42",
+"# c #7E4181A081AF",
+"$ c #8744915990DA",
+"% c #86728A968A7C",
+"& c #8D56924B9226",
+"* c #96DF9AC79AA6",
+"= c #9E01A473A438",
+"- c #AB41B55EB546",
+"; c #ABD1B155B117",
+": c #B5BFBC3DBC2F",
+"> c #B917BCECBCAB",
+", c #B558B98BB958",
+"< c #CEA2CFDBCFD4",
+"1 c #A699AC55ABF1",
+"2 c #C2A5C5A8C57A",
+"3 c #C8B2CA27CA1C",
+"4 c #D80FD952D955",
+"5 c #DF19E120E134",
+"6 c #EAC7E9ECE9FE",
+"7 c #F164EF95EF9D",
+"8 c #F6E0F5E6F61C",
+"9 c #F013EEAEEEBF",
+"0 c #487651675130",
+"q c #6E4D7BA97B06",
+"w c #88F190679051",
+"e c #92339C0E9BC1",
+"r c #A1BBAB0FAA98",
+"t c #A24AA7C4A7A7",
+"y c #86C7935E92DC",
+"u c #C8C4D721D725",
+"i c #D0E6D516D518",
+"p c #76A38450834A",
+"a c #6B4B7B507A6D",
+"s c #7C6D882B878D",
+"d c #88F395099487",
+"f c #DB34DCE9DCF5",
+"g c #5B05673F66CD",
+"h c #9402A0549FCC",
+"  c None",
+/* pixels */
+"                ",
+"     gO+Oq      ",
+"     p*45<Xg    ",
+"     h.>885oa   ",
+"      p.3883Xg  ",
+" i$O   s$488;s  ",
+" O>1p  e;588;a  ",
+" O331sr;7778:s  ",
+" O343,**3678;a  ",
+" f,643;#%368:s  ",
+"  t<64>= &374f  ",
+"   t244>= &379ih",
+"    d@:;=& &475u",
+"      ssr-* *44r",
+"         u-%#*%0",
+"          feww0g"
+};
+
+/* XPM */
 static const char *const new_s_xpm[] = {
 "11 11 35 1",
 "       c None",
--- a/src/plain.cc	Mon Jan 26 22:46:07 2009 +0100
+++ b/src/plain.cc	Tue Jan 27 18:30:24 2009 -0300
@@ -139,7 +139,7 @@
    _MSG("DilloPlain::PlainEventReceiver::buttonPress\n");
 
    if (event->button == 3) {
-      a_UIcmd_page_popup(plain->bw, plain->url, FALSE, FALSE);
+      a_UIcmd_page_popup(plain->bw, FALSE, FALSE);
       return true;
    }
    return false;
--- a/src/ui.cc	Mon Jan 26 22:46:07 2009 +0100
+++ b/src/ui.cc	Tue Jan 27 18:30:24 2009 -0300
@@ -38,7 +38,8 @@
 
 struct iconset {
    Image *ImgMeterOK, *ImgMeterBug,
-         *ImgHome, *ImgReload, *ImgSave, *ImgBook, *ImgClear, *ImgSearch;
+         *ImgHome, *ImgReload, *ImgSave, *ImgBook, *ImgTools,
+         *ImgClear,*ImgSearch;
    MultiImage *ImgLeftMulti, *ImgRightMulti, *ImgStopMulti, *ImgImageLoadMulti;
 };
 
@@ -49,6 +50,7 @@
    new xpmImage(reload_xpm),
    new xpmImage(save_xpm),
    new xpmImage(bm_xpm),
+   new xpmImage(tools_xpm),
    new xpmImage(new_s_xpm),
    new xpmImage(search_xpm),
    new MultiImage(*new xpmImage(left_xpm), INACTIVE_R,
@@ -68,6 +70,7 @@
    new xpmImage(reload_s_xpm),
    new xpmImage(save_s_xpm),
    new xpmImage(bm_s_xpm),
+   new xpmImage(tools_s_xpm),
    new xpmImage(new_s_xpm),
    standard_icons.ImgSearch,
    new MultiImage(*new xpmImage(left_s_xpm), INACTIVE_R,
@@ -189,7 +192,7 @@
 // Toolbar buttons -----------------------------------------------------------
 //
 //static const char *button_names[] = {
-//   "Back", "Forward", "Home", "Reload", "Save", "Stop", "Bookmarks",
+//   "Back", "Forward", "Home", "Reload", "Save", "Stop", "Bookmarks", "Tools",
 //   "Clear", "Search"
 //};
 
@@ -324,6 +327,11 @@
          a_UIcmd_book(a_UIcmd_get_bw_by_widget(wid));
       }
       break;
+   case UI_TOOLS:
+      if (k == 1 || k == 3) {
+         a_UIcmd_tools(a_UIcmd_get_bw_by_widget(wid), wid);
+      }
+      break;
    default:
       break;
    }
@@ -411,6 +419,12 @@
     b->callback(b1_cb, (void *)UI_BOOK);
     b->clear_tab_to_focus();
 
+    Tools = b = new HighlightButton(xpos, 0, bw, bh, (lbl) ? "Tools" : 0);
+    b->image(icons->ImgTools);
+    b->tooltip("Settings");
+    b->callback(b1_cb, (void *)UI_TOOLS);
+    b->clear_tab_to_focus();
+
    p1->type(PackedGroup::ALL_CHILDREN_VERTICAL);
    p1->end();
 
--- a/src/ui.hh	Mon Jan 26 22:46:07 2009 +0100
+++ b/src/ui.hh	Tue Jan 27 18:30:24 2009 -0300
@@ -26,6 +26,7 @@
    UI_SAVE,
    UI_STOP,
    UI_BOOK,
+   UI_TOOLS,
    UI_CLEAR,
    UI_SEARCH
 } UIButton;
@@ -48,7 +49,7 @@
    char *TabTooltip;
 
    Group *TopGroup;
-   Button *Back, *Forw, *Home, *Reload, *Save, *Stop, *Bookmarks,
+   Button *Back, *Forw, *Home, *Reload, *Save, *Stop, *Bookmarks, *Tools,
           *Clear, *Search, *FullScreen, *ImageLoad, *BugMeter, *FileButton;
    Input  *Location;
    PackedGroup *ProgBox;
--- a/src/uicmd.cc	Mon Jan 26 22:46:07 2009 +0100
+++ b/src/uicmd.cc	Tue Jan 27 18:30:24 2009 -0300
@@ -439,6 +439,14 @@
 }
 
 /*
+ * Repush current URL
+ */
+void a_UIcmd_repush(void *vbw)
+{
+   a_Nav_repush((BrowserWindow*)vbw);
+}
+
+/*
  * Return a suitable filename for a given URL path.
  */
 static char *UIcmd_make_save_filename(const char *pathstr)
@@ -526,6 +534,14 @@
 }
 
 /*
+ * Popup the tools menu
+ */
+void a_UIcmd_tools(void *vbw, void *v_wid)
+{
+   a_Menu_tools_popup((BrowserWindow*)vbw, v_wid);
+}
+
+/*
  * Open URL with dialog chooser
  */
 void a_UIcmd_open_file(void *vbw)
@@ -643,10 +659,11 @@
 /*
  * Popup the page menu
  */
-void a_UIcmd_page_popup(void *vbw, const DilloUrl *url,
-                        bool_t has_bugs, bool_t unloaded_imgs)
+void a_UIcmd_page_popup(void *vbw, bool_t has_bugs, bool_t unloaded_imgs)
 {
-   a_Menu_page_popup((BrowserWindow*)vbw, url, has_bugs, unloaded_imgs);
+   BrowserWindow *bw = (BrowserWindow*)vbw;
+   DilloUrl *url = a_History_get_url(NAV_TOP_UIDX(bw));
+   a_Menu_page_popup(bw, url, has_bugs, unloaded_imgs);
 }
 
 /*
--- a/src/uicmd.hh	Mon Jan 26 22:46:07 2009 +0100
+++ b/src/uicmd.hh	Tue Jan 27 18:30:24 2009 -0300
@@ -21,8 +21,10 @@
 void a_UIcmd_forw_popup(void *vbw);
 void a_UIcmd_home(void *vbw);
 void a_UIcmd_reload(void *vbw);
+void a_UIcmd_repush(void *vbw);
 void a_UIcmd_save(void *vbw);
 void a_UIcmd_stop(void *vbw);
+void a_UIcmd_tools(void *vbw, void *v_wid);
 void a_UIcmd_save_link(BrowserWindow *bw, const DilloUrl *url);
 void a_UIcmd_open_file(void *vbw);
 const char *a_UIcmd_select_file();
@@ -36,8 +38,7 @@
 void a_UIcmd_findtext_reset(BrowserWindow *bw);
 void a_UIcmd_focus_main_area(BrowserWindow *bw);
 void a_UIcmd_focus_location(void *vbw);
-void a_UIcmd_page_popup(void *vbw, const DilloUrl *url,
-                        bool_t has_bugs, bool_t unloaded_imgs);
+void a_UIcmd_page_popup(void *vbw, bool_t has_bugs, bool_t unloaded_imgs);
 void a_UIcmd_link_popup(void *vbw, const DilloUrl *url);
 void a_UIcmd_image_popup(void *vbw, const DilloUrl *url, bool_t loaded_img,
                          DilloUrl *link_url);