diff options
author | Richard Hult <rhult@codefactory.se> | 2002-10-21 07:36:48 +0000 |
---|---|---|
committer | Richard Hult <rhult@src.gnome.org> | 2002-10-21 07:36:48 +0000 |
commit | 194396aa4515e010195a2d5538114b69d9973d25 (patch) | |
tree | 8334b004768560067899d7a385832a1afa84f387 | |
parent | 232bf89fd42ffbcc88a9425727cccdc11015af22 (diff) | |
download | yelp-194396aa4515e010195a2d5538114b69d9973d25.tar.gz |
Don't try to set focus on view, use view->widget.
2002-10-21 Richard Hult <rhult@codefactory.se>
* src/yelp-view-content.c (content_show_uri): Don't try to set
focus on view, use view->widget.
* src/yelp-view-toc.c (toc_get_html):
* src/yelp-view-index.c (index_get_html):
* src/yelp-view.c (yelp_view_get_html): Implement
YelpView::get_html.
* src/yelp-view.h: Add virtual function get_html that returns the
YelpHtml used by the view.
* src/yelp-html-gtkhtml2.c (yelp_html_find_next): Implement.
* src/yelp-html.h (yelp_html_find_next): Add virtual function
find_next.
* src/yelp-window.c (window_find_cb): The start of find
functionality, needs more work.
(window_init): Remove unused view_current variable.
-rw-r--r-- | ChangeLog | 22 | ||||
-rw-r--r-- | src/yelp-html-gtkhtml2.c | 135 | ||||
-rw-r--r-- | src/yelp-html.h | 2 | ||||
-rw-r--r-- | src/yelp-view-content.c | 26 | ||||
-rw-r--r-- | src/yelp-view-content.h | 3 | ||||
-rw-r--r-- | src/yelp-view-index.c | 19 | ||||
-rw-r--r-- | src/yelp-view-toc.c | 18 | ||||
-rw-r--r-- | src/yelp-view.c | 9 | ||||
-rw-r--r-- | src/yelp-view.h | 4 | ||||
-rw-r--r-- | src/yelp-window.c | 48 |
10 files changed, 276 insertions, 10 deletions
@@ -1,3 +1,25 @@ +2002-10-21 Richard Hult <rhult@codefactory.se> + + * src/yelp-view-content.c (content_show_uri): Don't try to set + focus on view, use view->widget. + + * src/yelp-view-toc.c (toc_get_html): + * src/yelp-view-index.c (index_get_html): + * src/yelp-view.c (yelp_view_get_html): Implement + YelpView::get_html. + + * src/yelp-view.h: Add virtual function get_html that returns the + YelpHtml used by the view. + + * src/yelp-html-gtkhtml2.c (yelp_html_find_next): Implement. + + * src/yelp-html.h (yelp_html_find_next): Add virtual function + find_next. + + * src/yelp-window.c (window_find_cb): The start of find + functionality, needs more work. + (window_init): Remove unused view_current variable. + 2002-10-19 Mikael Hallendal <micke@codefactory.se> * src/Makefile.am (yelp_LDADD): link with POPT_LIBS. diff --git a/src/yelp-html-gtkhtml2.c b/src/yelp-html-gtkhtml2.c index 11154e24..ce610a78 100644 --- a/src/yelp-html-gtkhtml2.c +++ b/src/yelp-html-gtkhtml2.c @@ -28,6 +28,9 @@ #include <libgnomevfs/gnome-vfs-mime-utils.h> #include <libgnome/gnome-i18n.h> #include <libgtkhtml/gtkhtml.h> +#include <libgtkhtml/dom/traversal/dom-nodeiterator.h> +#include <libgtkhtml/dom/traversal/dom-documenttraversal.h> +#include <libgtkhtml/view/htmlselection.h> #include <string.h> #include <stdio.h> @@ -41,10 +44,15 @@ #define d(x) struct _YelpHtmlPriv { - HtmlView *view; + HtmlView *view; - HtmlDocument *doc; - YelpURI *base_uri; + HtmlDocument *doc; + YelpURI *base_uri; + + gchar *find_string; + DomNodeIterator *find_iter; + DomNode *find_node; + gint find_offset; }; @@ -172,6 +180,12 @@ html_url_requested_cb (HtmlDocument *doc, html = YELP_HTML (data); priv = html->priv; + + /* Reset find data when we load a new page. */ + if (priv->find_iter) { + g_object_unref (priv->find_iter); + priv->find_iter = NULL; + } html_stream_set_cancel_func (stream, html_cancel_stream, html); @@ -239,6 +253,12 @@ html_link_clicked_cb (HtmlDocument *doc, const gchar *url, YelpHtml *html) } } + /* Reset find data when link is clicked. */ + if (priv->find_iter) { + g_object_unref (priv->find_iter); + priv->find_iter = NULL; + } + g_signal_emit (html, signals[URI_SELECTED], 0, uri, handled); yelp_uri_unref (uri); @@ -368,3 +388,112 @@ yelp_html_get_widget (YelpHtml *html) return GTK_WIDGET (html->priv->view); } + +/* Experimental find stuff. */ + +void +yelp_html_find_next (YelpHtml *html) +{ + YelpHtmlPriv *priv; + DomNode *root; + DomNode *node; + DomNodeIterator *iter; + gchar *str; + gchar *tmp; + gchar *hit; + gchar *haystack; + + g_return_if_fail (YELP_IS_HTML (html)); + + priv = html->priv; + + if (!priv->find_string) { + priv->find_string = g_utf8_casefold ("e", -1); + } + + if (!priv->find_iter) { + iter = dom_DocumentTraversal_createNodeIterator ( + DOM_DOCUMENT_TRAVERSAL (priv->doc->dom_document), + DOM_NODE (priv->doc->dom_document), + DOM_SHOW_ALL, + NULL, + FALSE, + NULL); + + root = NULL; + while ((node = dom_NodeIterator_nextNode (iter, NULL))) { + if (!g_ascii_strcasecmp (dom_Node__get_nodeName (node), "body")) { + root = node; + /*str = dom_Node__get_nodeName (node); + g_free (str);*/ + break; + } + + /*str = dom_Node__get_nodeName (node); + g_free (str);*/ + } + + g_object_unref (iter); + iter = NULL; + + if (!root) { + g_warning ("No body!\n"); + return; + } + + priv->find_iter = dom_DocumentTraversal_createNodeIterator ( + DOM_DOCUMENT_TRAVERSAL (priv->doc->dom_document), + root, + DOM_SHOW_TEXT, + NULL, + FALSE, + NULL); + + priv->find_node = dom_NodeIterator_nextNode (priv->find_iter, NULL); + priv->find_offset = 0; + } + + while (priv->find_node) { + str = dom_Node__get_nodeValue (priv->find_node, NULL); + tmp = str + priv->find_offset; + haystack = g_utf8_casefold (tmp, -1); + + g_strstrip (haystack); + g_print (">>> '%s'\n", tmp); + + hit = strstr (haystack, priv->find_string); + if (hit) { + html_selection_set (priv->view, + priv->find_node, + hit - haystack + priv->find_offset, + strlen (priv->find_string)); + + priv->find_offset += hit - haystack; + + g_print ("'%s', %d\n", hit, priv->find_offset); + + html_view_scroll_to_node (priv->view, + priv->find_node, + HTML_VIEW_SCROLL_TO_TOP); + + priv->find_offset++; + + g_free (str); + g_free (haystack); + break; + } + + g_free (str); + g_free (haystack); + + priv->find_node = dom_NodeIterator_nextNode (priv->find_iter, NULL); + priv->find_offset = 0; + } + + if (!priv->find_node) { + g_object_unref (priv->find_iter); + priv->find_iter = NULL; + html_selection_clear (priv->view); + } +} + diff --git a/src/yelp-html.h b/src/yelp-html.h index 0d3958a8..9565cbb7 100644 --- a/src/yelp-html.h +++ b/src/yelp-html.h @@ -71,5 +71,7 @@ void yelp_html_close (YelpHtml *html); GtkWidget * yelp_html_get_widget (YelpHtml *html); +void yelp_html_find_next (YelpHtml *html); + #endif /* __YELP_HTML_H__ */ diff --git a/src/yelp-view-content.c b/src/yelp-view-content.c index 1624ee57..6b12a24c 100644 --- a/src/yelp-view-content.c +++ b/src/yelp-view-content.c @@ -74,9 +74,13 @@ static void content_insert_tree (YelpViewContent *content, static void content_set_tree (YelpViewContent *content, GNode *node); static void -content_show_uri (YelpView *view, - YelpURI *uri, - GError **error); +content_show_uri (YelpView *view, + YelpURI *uri, + GError **error); + +static YelpHtml * +content_get_html (YelpView *view); + struct _YelpViewContentPriv { GtkWidget *hpaned; @@ -176,6 +180,7 @@ content_class_init (YelpViewContentClass *klass) YelpViewClass *view_class = YELP_VIEW_CLASS (klass); view_class->show_uri = content_show_uri; + view_class->get_html = content_get_html; } static void @@ -474,7 +479,7 @@ content_show_uri (YelpView *view, YelpURI *uri, GError **error) } if (reset_focus) { - gtk_widget_child_focus (GTK_WIDGET (view), + gtk_widget_child_focus (GTK_WIDGET (view->widget), GTK_DIR_TAB_FORWARD); } @@ -568,3 +573,16 @@ yelp_view_content_new (GNode *doc_tree) return YELP_VIEW (view); } +static YelpHtml * +content_get_html (YelpView *view) +{ + YelpViewContent *content; + YelpViewContentPriv *priv; + + g_return_val_if_fail (YELP_IS_VIEW_CONTENT (view), NULL); + + content = YELP_VIEW_CONTENT (view); + priv = content->priv; + + return YELP_HTML (priv->html_view); +} diff --git a/src/yelp-view-content.h b/src/yelp-view-content.h index 5184657f..be0c2d2f 100644 --- a/src/yelp-view-content.h +++ b/src/yelp-view-content.h @@ -51,6 +51,7 @@ struct _YelpViewContentClass { }; GType yelp_view_content_get_type (void); -YelpView * yelp_view_content_new (GNode *doc_tree); + +YelpView * yelp_view_content_new (GNode *doc_tree); #endif /* __YELP_VIEW_CONTENT__ */ diff --git a/src/yelp-view-index.c b/src/yelp-view-index.c index 0e5f49ca..0d69bc5e 100644 --- a/src/yelp-view-index.c +++ b/src/yelp-view-index.c @@ -82,6 +82,10 @@ static void index_show_uri (YelpView *view, YelpURI *index_uri, GError **error); +static YelpHtml * +index_get_html (YelpView *view); + + struct _YelpViewIndexPriv { /* List of keywords */ GtkWidget *index_view; @@ -176,6 +180,7 @@ index_class_init (YelpViewIndexClass *klass) YelpViewClass *view_class = YELP_VIEW_CLASS (klass); view_class->show_uri = index_show_uri; + view_class->get_html = index_get_html; } static void @@ -434,6 +439,20 @@ index_show_uri (YelpView *view, YelpURI *index_uri, GError **error) /* yelp_html_open_uri (priv->html_view, uri, error); */ } +static YelpHtml * +index_get_html (YelpView *view) +{ + YelpViewIndex *index; + YelpViewIndexPriv *priv; + + g_return_val_if_fail (YELP_IS_VIEW_INDEX (view), NULL); + + index = YELP_VIEW_INDEX (view); + priv = index->priv; + + return YELP_HTML (priv->html_view); +} + YelpView * yelp_view_index_new (GList *index) { diff --git a/src/yelp-view-toc.c b/src/yelp-view-toc.c index 99825505..8b722bf3 100644 --- a/src/yelp-view-toc.c +++ b/src/yelp-view-toc.c @@ -61,6 +61,9 @@ static void toc_page_end (YelpViewTOC *view); static void toc_show_uri (YelpView *view, YelpURI *uri, GError **error); +static YelpHtml * +toc_get_html (YelpView *view); + typedef struct { char *title; @@ -133,6 +136,7 @@ toc_class_init (YelpViewTOCClass *klass) YelpViewClass *view_class = YELP_VIEW_CLASS (klass); view_class->show_uri = toc_show_uri; + view_class->get_html = toc_get_html; } #if 0 @@ -887,6 +891,20 @@ toc_show_uri (YelpView *view, YelpURI *uri, GError **error) } } +static YelpHtml * +toc_get_html (YelpView *view) +{ + YelpViewTOC *toc; + YelpViewTOCPriv *priv; + + g_return_val_if_fail (YELP_IS_VIEW_TOC (view), NULL); + + toc = YELP_VIEW_TOC (view); + priv = toc->priv; + + return YELP_HTML (priv->html_view); +} + YelpView * yelp_view_toc_new (GNode *doc_tree) { diff --git a/src/yelp-view.c b/src/yelp-view.c index 433f3a76..f122a392 100644 --- a/src/yelp-view.c +++ b/src/yelp-view.c @@ -126,3 +126,12 @@ yelp_view_show_uri (YelpView *view, YelpURI *uri, GError **error) } } +YelpHtml * +yelp_view_get_html (YelpView *view) +{ + if (YELP_VIEW_GET_CLASS (view)->get_html) { + return YELP_VIEW_GET_CLASS (view)->get_html (view); + } + + return NULL; +} diff --git a/src/yelp-view.h b/src/yelp-view.h index 8843dfbd..475e345b 100644 --- a/src/yelp-view.h +++ b/src/yelp-view.h @@ -26,6 +26,7 @@ #include <gtk/gtkhpaned.h> #include <gtk/gtktreemodel.h> #include "yelp-section.h" +#include "yelp-html.h" #define YELP_TYPE_VIEW (yelp_view_get_type ()) #define YELP_VIEW(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), YELP_TYPE_VIEW, YelpView)) @@ -58,6 +59,7 @@ struct _YelpViewClass { void (*show_uri) (YelpView *view, YelpURI *uri, GError **error); + YelpHtml * (*get_html) (YelpView *view); }; GType yelp_view_get_type (void); @@ -66,4 +68,6 @@ void yelp_view_show_uri (YelpView *view, YelpURI *uri, GError **error); +YelpHtml * yelp_view_get_html (YelpView *view); + #endif /* __YELP_INDEX__ */ diff --git a/src/yelp-window.c b/src/yelp-window.c index e9f30dfe..39505a54 100644 --- a/src/yelp-window.c +++ b/src/yelp-window.c @@ -90,6 +90,8 @@ static void window_new_window_cb (gpointer data, static void window_close_window_cb (gpointer data, guint section, GtkWidget *widget); +static void window_find_cb (gpointer data, guint section, + GtkWidget *widget); static void window_history_go_cb (gpointer data, guint section, GtkWidget *widget); @@ -131,7 +133,7 @@ struct _YelpWindowPriv { YelpView *content_view; YelpView *index_view; - GtkWidget *view_current; + GtkWidget *find_dialog; YelpHistory *history; @@ -144,6 +146,7 @@ struct _YelpWindowPriv { static GtkItemFactoryEntry menu_items[] = { {N_("/_File"), NULL, 0, 0, "<Branch>"}, {N_("/File/_New window"), NULL, window_new_window_cb, 0, "<StockItem>", GTK_STOCK_NEW }, +/* {N_("/File/_Find in page..."), NULL, window_find_cb, 0, "<StockItem>", GTK_STOCK_FIND },*/ {N_("/File/_Close window"), NULL, window_close_window_cb, 0, "<StockItem>", GTK_STOCK_CLOSE }, {N_("/_Go"), NULL, 0, 0, "<Branch>"}, {N_("/Go/_Back"), NULL, window_history_go_cb, YELP_WINDOW_ACTION_BACK, "<StockItem>", GTK_STOCK_GO_BACK }, @@ -193,7 +196,6 @@ window_init (YelpWindow *window) priv->toc_view = NULL; priv->content_view = NULL; priv->index_view = NULL; - priv->view_current = NULL; priv->history = yelp_history_new (); @@ -550,6 +552,48 @@ window_close_window_cb (gpointer data, } static void +window_find_cb (gpointer data, guint section, GtkWidget *widget) +{ + YelpWindow *window = data; + YelpWindowPriv *priv; + YelpHtml *html; + + g_return_if_fail (YELP_IS_WINDOW (data)); + + window = YELP_WINDOW (data); + + priv = window->priv; + + /* To get rid of warning for now. */ + if (0) { + window_find_cb (data, section, widget); + } + + switch (gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook))) { + case PAGE_TOC_VIEW: + html = yelp_view_get_html (priv->toc_view); + break; + case PAGE_CONTENT_VIEW: + html = yelp_view_get_html (priv->content_view); + break; + case PAGE_INDEX_VIEW: + html = yelp_view_get_html (priv->index_view); + break; + default: + g_assert_not_reached (); + } + + if (priv->find_dialog) { + gtk_window_present (GTK_WINDOW (priv->find_dialog)); + } else { + priv->find_dialog = NULL; + } + + /* FIXME: Implement the dialog. */ + yelp_html_find_next (html); +} + +static void window_history_go_cb (gpointer data, guint section, GtkWidget *widget) { window_history_action (data, section); |