summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Fryatt <stevef@netsurf-browser.org>2013-12-30 15:41:38 +0000
committerSteve Fryatt <stevef@netsurf-browser.org>2013-12-30 15:41:38 +0000
commit6300c7ed90b472dc9a5f21d8054fd2e2689c8c9a (patch)
tree29969a49d4c25af43ca9c1ad3e5ce58409850e3c
parent1019692b882860bcae923fedb23269cbd2f0121b (diff)
downloadnetsurf-6300c7ed90b472dc9a5f21d8054fd2e2689c8c9a.tar.gz
netsurf-6300c7ed90b472dc9a5f21d8054fd2e2689c8c9a.tar.bz2
Tidy up hotlist icon interfaces and make consistant with rest of toolbar.
-rw-r--r--riscos/gui/url_bar.c81
-rw-r--r--riscos/gui/url_bar.h6
-rw-r--r--riscos/hotlist.c18
-rw-r--r--riscos/hotlist.h1
-rw-r--r--riscos/toolbar.c8
-rw-r--r--riscos/toolbar.h6
-rw-r--r--riscos/window.c4
7 files changed, 70 insertions, 54 deletions
diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c
index 0d82b60dd..4badb6bfb 100644
--- a/riscos/gui/url_bar.c
+++ b/riscos/gui/url_bar.c
@@ -30,7 +30,7 @@
#include "oslib/os.h"
#include "oslib/osspriteop.h"
#include "oslib/wimp.h"
-#include "desktop/hotlist.h"
+#include "riscos/hotlist.h"
#include "riscos/gui/url_bar.h"
#include "riscos/theme.h"
#include "riscos/url_suggest.h"
@@ -83,7 +83,7 @@ struct url_bar {
bool shaded;
struct {
- bool add;
+ bool set;
os_box extent;
os_coord offset;
} hotlist;
@@ -111,6 +111,7 @@ static struct url_bar_resource url_bar_res[URLBAR_RES_LAST] = {
}; /**< Treeview content resources */
+static void ro_gui_url_bar_set_hotlist(struct url_bar *url_bar, bool set);
/* This is an exported interface documented in url_bar.h */
@@ -159,7 +160,7 @@ struct url_bar *ro_gui_url_bar_create(struct theme_descriptor *theme)
strncpy(url_bar->favicon_sprite, "Ssmall_xxx",
URLBAR_FAVICON_NAME_LENGTH);
- url_bar->hotlist.add = true;
+ url_bar->hotlist.set = false;
url_bar->hotlist.extent.x0 = 0;
url_bar->hotlist.extent.y0 = 0;
url_bar->hotlist.extent.x1 = 0;
@@ -697,9 +698,9 @@ void ro_gui_url_bar_redraw(struct url_bar *url_bar, wimp_draw *redraw)
.background_images = true,
.plot = &ro_plotters
};
- struct url_bar_resource *hotlist_icon = url_bar->hotlist.add ?
- &(url_bar_res[URLBAR_RES_HOTLIST_ADD]) :
- &(url_bar_res[URLBAR_RES_HOTLIST_REMOVE]);
+ struct url_bar_resource *hotlist_icon = url_bar->hotlist.set ?
+ &(url_bar_res[URLBAR_RES_HOTLIST_REMOVE]) :
+ &(url_bar_res[URLBAR_RES_HOTLIST_ADD]);
xwimp_set_colour(wimp_COLOUR_WHITE);
xos_plot(os_MOVE_TO,
@@ -937,16 +938,8 @@ void ro_gui_url_bar_set_url(struct url_bar *url_bar, const char *url,
return;
if (nsurl_create(url, &n) == NSERROR_OK) {
- bool prev = url_bar->hotlist.add;
- url_bar->hotlist.add = !hotlist_has_url(n);
+ ro_gui_url_bar_set_hotlist(url_bar, ro_gui_hotlist_has_page(n));
nsurl_unref(n);
-
- if (prev != url_bar->hotlist.add && !url_bar->hidden)
- xwimp_force_redraw(url_bar->window,
- url_bar->hotlist.extent.x0,
- url_bar->hotlist.extent.y0,
- url_bar->hotlist.extent.x1,
- url_bar->hotlist.extent.y1);
}
if (url_bar->text_icon == -1) {
@@ -983,23 +976,42 @@ void ro_gui_url_bar_set_url(struct url_bar *url_bar, const char *url,
/* This is an exported interface documented in url_bar.h */
-void ro_gui_url_bar_hotlist_modifed(struct url_bar *url_bar, nsurl *url)
+void ro_gui_url_bar_update_hotlist(struct url_bar *url_bar)
{
+ const char *url;
nsurl *n;
- if (nsurl_create((const char *)url_bar->text_buffer,
- &n) == NSERROR_OK) {
- bool prev = url_bar->hotlist.add;
- url_bar->hotlist.add = !hotlist_has_url(n);
+ if (url_bar == NULL)
+ return;
+
+ url = (const char *) url_bar->text_buffer;
+ if (url != NULL && nsurl_create(url, &n) == NSERROR_OK) {
+ ro_gui_url_bar_set_hotlist(url_bar, ro_gui_hotlist_has_page(n));
nsurl_unref(n);
+ }
+}
- if (prev != url_bar->hotlist.add && !url_bar->hidden) {
+
+/**
+ * Set the state of a URL Bar's hotlist icon.
+ *
+ * \param *url_bar The URL Bar to update.
+ * \param set TRUE to set the hotlist icon; FALSE to clear it.
+ */
+
+static void ro_gui_url_bar_set_hotlist(struct url_bar *url_bar, bool set)
+{
+ if (url_bar == NULL || set == url_bar->hotlist.set)
+ return;
+
+ url_bar->hotlist.set = set;
+
+ if (!url_bar->hidden) {
xwimp_force_redraw(url_bar->window,
url_bar->hotlist.extent.x0,
url_bar->hotlist.extent.y0,
url_bar->hotlist.extent.x1,
url_bar->hotlist.extent.y1);
- }
}
}
@@ -1067,7 +1079,6 @@ bool ro_gui_url_bar_test_for_text_field_keypress(struct url_bar *url_bar,
{
const char *url;
nsurl *n;
- bool changed = false;
if (url_bar == NULL || url_bar->hidden || key == NULL)
return false;
@@ -1075,30 +1086,14 @@ bool ro_gui_url_bar_test_for_text_field_keypress(struct url_bar *url_bar,
if (key->w != url_bar->window || key->i != url_bar->text_icon)
return false;
- if (url_bar->hidden)
- return true;
-
/* Update hotlist indicator */
+
url = (const char *) url_bar->text_buffer;
if (url != NULL && nsurl_create(url, &n) == NSERROR_OK) {
- bool prev = url_bar->hotlist.add;
- url_bar->hotlist.add = !hotlist_has_url(n);
+ ro_gui_url_bar_set_hotlist(url_bar, ro_gui_hotlist_has_page(n));
nsurl_unref(n);
-
- if (prev != url_bar->hotlist.add) {
- changed = true;
- }
- } else if (!url_bar->hotlist.add) {
- url_bar->hotlist.add = true;
- changed = true;
- }
-
- if (changed) {
- xwimp_force_redraw(url_bar->window,
- url_bar->hotlist.extent.x0,
- url_bar->hotlist.extent.y0,
- url_bar->hotlist.extent.x1,
- url_bar->hotlist.extent.y1);
+ } else if (url_bar->hotlist.set) {
+ ro_gui_url_bar_set_hotlist(url_bar, false);
}
return true;
diff --git a/riscos/gui/url_bar.h b/riscos/gui/url_bar.h
index c20dbf943..034f74df6 100644
--- a/riscos/gui/url_bar.h
+++ b/riscos/gui/url_bar.h
@@ -234,13 +234,13 @@ void ro_gui_url_bar_set_url(struct url_bar *url_bar, const char *url,
/**
- * Update urlbar's hotlist icon, if necessary.
+ * Update the state of a URL Bar's hotlist icon to reflect any changes to the
+ * URL or the contents of the hotlist.
*
* \param *url_bar The URL Bar to update.
- * \param *url URL with updated hotlist presence, or NULL if unknown.
*/
-void ro_gui_url_bar_hotlist_modifed(struct url_bar *url_bar, nsurl *url);
+void ro_gui_url_bar_update_hotlist(struct url_bar *url_bar);
/**
diff --git a/riscos/hotlist.c b/riscos/hotlist.c
index cb014b572..3350ffb8b 100644
--- a/riscos/hotlist.c
+++ b/riscos/hotlist.c
@@ -612,6 +612,24 @@ void ro_gui_hotlist_remove_page(nsurl *url)
}
+/**
+ * Report whether the hotlist contains a given URL. This will be passed on to
+ * the core hotlist, unless we're configured to use an external hotlist in which
+ * case we always report false.
+ *
+ * \param *url The URL to be tested.
+ * \return true if the hotlist contains the URL; else false.
+ */
+
+bool ro_gui_hotlist_has_page(nsurl *url)
+{
+ if (url == NULL || nsoption_bool(external_hotlists))
+ return false;
+
+ return hotlist_has_url(url);
+}
+
+
#if 0
/**
* Handle URL dropped on hotlist
diff --git a/riscos/hotlist.h b/riscos/hotlist.h
index 4993092c9..4cb5a1ff3 100644
--- a/riscos/hotlist.h
+++ b/riscos/hotlist.h
@@ -48,6 +48,7 @@ bool ro_gui_hotlist_check_menu(wimp_menu *menu);
void ro_gui_hotlist_add_page(nsurl *url);
void ro_gui_hotlist_add_cleanup(void);
void ro_gui_hotlist_remove_page(nsurl *url);
+bool ro_gui_hotlist_has_page(nsurl *url);
#endif
diff --git a/riscos/toolbar.c b/riscos/toolbar.c
index 26a9bd440..d0c68c2b7 100644
--- a/riscos/toolbar.c
+++ b/riscos/toolbar.c
@@ -1620,10 +1620,12 @@ const char *ro_toolbar_get_url(struct toolbar *toolbar)
/* This is an exported interface documented in toolbar.h */
-void ro_toolbar_hotlist_modifed(struct toolbar *toolbar, nsurl *url)
+void ro_toolbar_update_hotlist(struct toolbar *toolbar)
{
- if (toolbar != NULL && toolbar->url != NULL)
- ro_gui_url_bar_hotlist_modifed(toolbar->url, url);
+ if (toolbar == NULL || toolbar->url == NULL)
+ return;
+
+ ro_gui_url_bar_update_hotlist(toolbar->url);
}
diff --git a/riscos/toolbar.h b/riscos/toolbar.h
index 284eee22d..e568b8c23 100644
--- a/riscos/toolbar.h
+++ b/riscos/toolbar.h
@@ -386,13 +386,13 @@ const char *ro_toolbar_get_url(struct toolbar *toolbar);
/**
- * Update toolbar's urlbar hotlist icon, if necessary.
+ * Update the state of a toolbar's URL Bar hotlist icon to reflect any changes
+ * to the URL or the hotlist contents.
*
* \param *toolbar The toolbar to update.
- * \param *url URL with updated hotlist presence, or NULL if unknown.
*/
-void ro_toolbar_hotlist_modifed(struct toolbar *toolbar, nsurl *url);
+void ro_toolbar_update_hotlist(struct toolbar *toolbar);
/**
diff --git a/riscos/window.c b/riscos/window.c
index 39ae5f658..0f81b8f89 100644
--- a/riscos/window.c
+++ b/riscos/window.c
@@ -4275,7 +4275,7 @@ static void ro_gui_window_action_add_bookmark(struct gui_window *g)
url = hlcache_handle_get_url(g->bw->current_content);
ro_gui_hotlist_add_page(url);
- ro_toolbar_hotlist_modifed(g->toolbar, url);
+ ro_toolbar_update_hotlist(g->toolbar);
}
@@ -4297,7 +4297,7 @@ static void ro_gui_window_action_remove_bookmark(struct gui_window *g)
url = hlcache_handle_get_url(g->bw->current_content);
ro_gui_hotlist_remove_page(url);
- ro_toolbar_hotlist_modifed(g->toolbar, url);
+ ro_toolbar_update_hotlist(g->toolbar);
}