aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcorvid <corvid@lavabit.com>2009-02-08 19:31:32 -0300
committercorvid <corvid@lavabit.com>2009-02-08 19:31:32 -0300
commit76c6fe90916a407aace73ab6c79e08495c4bcec0 (patch)
treef9f4e5a89f5223b9174a2012c31ca1dc2ae423e1 /src
parent24cc07871e0744853dfaed26c9a8eff0b62ff35d (diff)
Fixed the load image popup option. Also cleaned up the API a bit.
Introduced a_Bw_get_url_doc(). Mainly for popup menus.
Diffstat (limited to 'src')
-rw-r--r--src/bw.c33
-rw-r--r--src/bw.h2
-rw-r--r--src/html.cc4
-rw-r--r--src/menu.cc43
-rw-r--r--src/menu.hh3
-rw-r--r--src/uicmd.cc4
-rw-r--r--src/uicmd.hh2
7 files changed, 55 insertions, 36 deletions
diff --git a/src/bw.c b/src/bw.c
index d0c92086..92d24556 100644
--- a/src/bw.c
+++ b/src/bw.c
@@ -13,6 +13,7 @@
#include "bw.h"
+#include "msg.h"
#include "list.h"
#include "capi.h"
#include "uicmd.hh"
@@ -217,6 +218,38 @@ void a_Bw_add_doc(BrowserWindow *bw, void *vdoc)
}
/*
+ * 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)
diff --git a/src/bw.h b/src/bw.h
index 1dcf3a3a..1c27b676 100644
--- a/src/bw.h
+++ b/src/bw.h
@@ -81,6 +81,8 @@ int a_Bw_remove_client(BrowserWindow *bw, int ClientKey);
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);
diff --git a/src/html.cc b/src/html.cc
index be85d47f..fa46de34 100644
--- a/src/html.cc
+++ b/src/html.cc
@@ -727,8 +727,8 @@ bool DilloHtml::HtmlLinkReceiver::press (Widget *widget, int link, int img,
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) {
diff --git a/src/menu.cc b/src/menu.cc
index 32d8ba94..9d03c439 100644
--- a/src/menu.cc
+++ b/src/menu.cc
@@ -192,35 +192,15 @@ static void Menu_view_page_bugs_cb(Widget* )
}
/*
- * 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_load_images_cb(Widget*, void *user_data)
*/
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_submit_cb(Widget*, void *v_form)
*/
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 @@ static void Menu_form_hiddens_cb(Widget *w, void *user_data)
{
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 @@ void a_Menu_link_popup(BrowserWindow *bw, const DilloUrl *url)
* 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 @@ void a_Menu_image_popup(BrowserWindow *bw, const DilloUrl *url,
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_embedded_css_cb(Widget *wid)
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;
diff --git a/src/menu.hh b/src/menu.hh
index d0246c2e..36f7ad21 100644
--- a/src/menu.hh
+++ b/src/menu.hh
@@ -11,7 +11,8 @@ void a_Menu_page_popup(BrowserWindow *bw, const DilloUrl *url,
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);
diff --git a/src/uicmd.cc b/src/uicmd.cc
index 620669af..05b1a523 100644
--- a/src/uicmd.cc
+++ b/src/uicmd.cc
@@ -678,9 +678,9 @@ void a_UIcmd_link_popup(void *vbw, const DilloUrl *url)
* 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);
}
/*
diff --git a/src/uicmd.hh b/src/uicmd.hh
index b08b4f8d..90e7c89d 100644
--- a/src/uicmd.hh
+++ b/src/uicmd.hh
@@ -42,7 +42,7 @@ void a_UIcmd_focus_location(void *vbw);
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);