changeset 926:caf45b6c8535

Fixed the load image popup option. Also cleaned up the API a bit. Introduced a_Bw_get_url_doc(). Mainly for popup menus.
author corvid <corvid@lavabit.com>
date Sun, 08 Feb 2009 19:31:32 -0300
parents f3a156cbce61
children ee1e8682d8dc
files src/bw.c src/bw.h src/html.cc src/menu.cc src/menu.hh src/uicmd.cc src/uicmd.hh
diffstat 7 files changed, 55 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/src/bw.c	Sun Feb 08 18:32:52 2009 -0300
+++ b/src/bw.c	Sun Feb 08 19:31:32 2009 -0300
@@ -13,6 +13,7 @@
 
 
 #include "bw.h"
+#include "msg.h"
 #include "list.h"
 #include "capi.h"
 #include "uicmd.hh"
@@ -217,6 +218,38 @@
 }
 
 /*
+ * Get current document.
+ */
+void *a_Bw_get_current_doc(BrowserWindow *bw)
+{
+   void *doc = NULL;
+   int len = dList_length(bw->Docs);
+
+   if (len == 1)
+      doc = dList_nth_data(bw->Docs, 0);
+   else if (len > 1)
+      MSG("a_Bw_get_current_doc() multiple docs not implemented\n");
+
+   return doc;
+}
+
+/*
+ * Get document by URL.
+ *
+ * This is currently used by popup menus that need to ensure that the
+ * page has not changed while the menu was popped up.
+ */
+void *a_Bw_get_url_doc(BrowserWindow *bw, const DilloUrl *url)
+{
+   void *doc = NULL;
+
+   if (url && dList_find_custom(bw->PageUrls, url, (dCompareFunc)a_Url_cmp)) {
+      doc = a_Bw_get_current_doc(bw);
+   }
+   return doc;
+}
+
+/*
  * Remove a document from the bw's list
  */
 void a_Bw_remove_doc(BrowserWindow *bw, void *vdoc)
--- a/src/bw.h	Sun Feb 08 18:32:52 2009 -0300
+++ b/src/bw.h	Sun Feb 08 19:31:32 2009 -0300
@@ -81,6 +81,8 @@
 void a_Bw_close_client(BrowserWindow *bw, int ClientKey);
 void a_Bw_stop_clients(BrowserWindow *bw, int flags);
 void a_Bw_add_doc(BrowserWindow *bw, void *vdoc);
+void *a_Bw_get_current_doc(BrowserWindow *bw);
+void *a_Bw_get_url_doc(BrowserWindow *bw, const DilloUrl *Url);
 void a_Bw_remove_doc(BrowserWindow *bw, void *vdoc);
 void a_Bw_add_url(BrowserWindow *bw, const DilloUrl *Url);
 void a_Bw_cleanup(BrowserWindow *bw);
--- a/src/html.cc	Sun Feb 08 18:32:52 2009 -0300
+++ b/src/html.cc	Sun Feb 08 19:31:32 2009 -0300
@@ -727,8 +727,8 @@
          if (link != -1)
             linkurl = html->links->get(link);
          const bool_t loaded_img = (html->images->get(img)->image == NULL);
-         a_UIcmd_image_popup(
-            bw, html->images->get(img)->url, loaded_img, linkurl);
+         a_UIcmd_image_popup(bw, html->images->get(img)->url, loaded_img,
+                             html->page_url, linkurl);
          ret = true;
       } else {
          if (link == -1) {
--- a/src/menu.cc	Sun Feb 08 18:32:52 2009 -0300
+++ b/src/menu.cc	Sun Feb 08 19:31:32 2009 -0300
@@ -192,35 +192,15 @@
 }
 
 /*
- * Get the document (HTML page) this menu was triggered for.
- */
-static void *Menu_get_bw_doc()
-{
-   void *doc = NULL;
-
-   if (popup_bw && popup_bw->Docs) {
-      if (!popup_url || dList_find_custom(popup_bw->PageUrls, popup_url,
-                                          (dCompareFunc)a_Url_cmp)){
-         /* HTML page is still there */
-         if (dList_length(popup_bw->Docs) == 1)
-            doc = dList_nth_data(popup_bw->Docs, 0);
-         else
-            MSG("Menu_get_bw_doc() multiple docs not implemented\n");
-      }
-   }
-   return doc;
-}
-
-/*
  * Load images on current page that match URL pattern
  */
 static void Menu_load_images_cb(Widget*, void *user_data)
 {
-   DilloUrl *pattern = (DilloUrl *) user_data;
-   void *doc = Menu_get_bw_doc();
+   DilloUrl *page_url = (DilloUrl *) user_data;
+   void *doc = a_Bw_get_url_doc(popup_bw, page_url);
 
    if (doc)
-      a_Html_load_images(doc, pattern);
+      a_Html_load_images(doc, popup_url);
 }
 
 /*
@@ -228,7 +208,7 @@
  */
 static void Menu_form_submit_cb(Widget*, void *v_form)
 {
-   void *doc = Menu_get_bw_doc();
+   void *doc = a_Bw_get_url_doc(popup_bw, popup_url);
 
    if (doc)
       a_Html_form_submit(doc, v_form);
@@ -239,7 +219,7 @@
  */
 static void Menu_form_reset_cb(Widget*, void *v_form)
 {
-   void *doc = Menu_get_bw_doc();
+   void *doc = a_Bw_get_url_doc(popup_bw, popup_url);
 
    if (doc)
       a_Html_form_reset(doc, v_form);
@@ -252,7 +232,7 @@
 {
    void *v_form = w->parent()->user_data();
    bool visible = *((bool *) user_data);
-   void *doc = Menu_get_bw_doc();
+   void *doc = a_Bw_get_url_doc(popup_bw, popup_url);
 
    if (doc)
       a_Html_form_display_hiddens(doc, v_form, !visible);
@@ -427,18 +407,22 @@
  * Image popup menu (construction & popup)
  */
 void a_Menu_image_popup(BrowserWindow *bw, const DilloUrl *url,
-                        bool_t loaded_img, DilloUrl *link_url)
+                        bool_t loaded_img, DilloUrl *page_url,
+                        DilloUrl *link_url)
 {
    // One menu for every browser window
    static PopupMenu *pm = 0;
    // Active/inactive control.
    static Item *link_menuitem = 0;
    static Item *load_img_menuitem = 0;
+   static DilloUrl *popup_page_url = NULL;
    static DilloUrl *popup_link_url = NULL;
 
    popup_bw = bw;
    a_Url_free(popup_url);
    popup_url = a_Url_dup(url);
+   a_Url_free(popup_page_url);
+   popup_page_url = a_Url_dup(page_url);
    a_Url_free(popup_link_url);
    popup_link_url = a_Url_dup(link_url);
    
@@ -474,7 +458,7 @@
       load_img_menuitem->deactivate();
    } else {
       load_img_menuitem->activate();
-      load_img_menuitem->user_data(popup_url);
+      load_img_menuitem->user_data(popup_page_url);
    }
 
    if (link_url) {
@@ -653,8 +637,7 @@
 static void Menu_imgload_toggle_cb(Widget *wid)
 {
    if ((prefs.load_images = wid->state() ? 1 : 0)) {
-      popup_url = NULL;
-      void *doc = Menu_get_bw_doc();
+      void *doc = a_Bw_get_current_doc(popup_bw);
 
       if (doc) {
          DilloUrl *pattern = NULL;
--- a/src/menu.hh	Sun Feb 08 18:32:52 2009 -0300
+++ b/src/menu.hh	Sun Feb 08 19:31:32 2009 -0300
@@ -11,7 +11,8 @@
                        bool_t has_bugs);
 void a_Menu_link_popup(BrowserWindow *bw, const DilloUrl *url);
 void a_Menu_image_popup(BrowserWindow *bw, const DilloUrl *url,
-                        bool_t loaded_img, DilloUrl *link_url);
+                        bool_t loaded_img, DilloUrl *page_url,
+                        DilloUrl *link_url);
 void a_Menu_form_popup(BrowserWindow *bw, const DilloUrl *page_url,
                        void *vform, bool_t showing_hiddens);
 void a_Menu_file_popup(BrowserWindow *bw, void *v_wid);
--- a/src/uicmd.cc	Sun Feb 08 18:32:52 2009 -0300
+++ b/src/uicmd.cc	Sun Feb 08 19:31:32 2009 -0300
@@ -678,9 +678,9 @@
  * Pop up the image menu
  */
 void a_UIcmd_image_popup(void *vbw, const DilloUrl *url, bool_t loaded_img,
-                         DilloUrl *link_url)
+                         DilloUrl *page_url, DilloUrl *link_url)
 {
-   a_Menu_image_popup((BrowserWindow*)vbw, url, loaded_img, link_url);
+   a_Menu_image_popup((BrowserWindow*)vbw, url, loaded_img, page_url,link_url);
 }
 
 /*
--- a/src/uicmd.hh	Sun Feb 08 18:32:52 2009 -0300
+++ b/src/uicmd.hh	Sun Feb 08 19:31:32 2009 -0300
@@ -42,7 +42,7 @@
 void a_UIcmd_page_popup(void *vbw, bool_t has_bugs);
 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);
+                         DilloUrl *page_url, DilloUrl *link_url);
 void a_UIcmd_form_popup(void *vbw, const DilloUrl *url, void *vform,
                         bool_t showing_hiddens);
 void a_UIcmd_file_popup(void *vbw, void *v_wid);