From 887b0710ec60775bb5423f9f72e39838c1aa6b8f Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 20 Oct 2006 19:15:10 +0200 Subject: [PATCH 1/2] Show the title in the entry, needs some love --- activities/web/toolbar.py | 6 +- lib/src/sugar-address-entry.c | 111 ++++++++++++++++++++++++++++++---- lib/src/sugar-address-entry.h | 2 + 3 files changed, 105 insertions(+), 14 deletions(-) diff --git a/activities/web/toolbar.py b/activities/web/toolbar.py index f66b7d9d..a2140791 100644 --- a/activities/web/toolbar.py +++ b/activities/web/toolbar.py @@ -83,6 +83,7 @@ class Toolbar(gtk.Toolbar): self._embed.connect("notify::progress", self._progress_changed_cb) self._embed.connect("notify::loading", self._loading_changed_cb) self._embed.connect("notify::address", self._address_changed_cb) + self._embed.connect("notify::title", self._title_changed_cb) self._embed.connect("notify::can-go-back", self._can_go_back_changed_cb) self._embed.connect("notify::can-go-forward", @@ -107,7 +108,10 @@ class Toolbar(gtk.Toolbar): self._update_stop_and_reload_icon() def _address_changed_cb(self, embed, spec): - self._entry.set_text(embed.props.address) + self._entry.props.address = embed.props.address + + def _title_changed_cb(self, embed, spec): + self._entry.props.title = embed.props.title def _can_go_back_changed_cb(self, embed, spec): self._back.props.sensitive = embed.props.can_go_back diff --git a/lib/src/sugar-address-entry.c b/lib/src/sugar-address-entry.c index bceea896..8e8a2c80 100644 --- a/lib/src/sugar-address-entry.c +++ b/lib/src/sugar-address-entry.c @@ -24,7 +24,9 @@ enum { PROP_0, - PROP_PROGRESS + PROP_PROGRESS, + PROP_ADDRESS, + PROP_TITLE }; typedef enum { @@ -491,19 +493,62 @@ sugar_address_entry_expose(GtkWidget *widget, } static void -sugar_address_entry_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) +update_entry_text(SugarAddressEntry *address_entry, + gboolean has_focus) +{ + if (has_focus) { + gtk_entry_set_text(GTK_ENTRY(address_entry), + address_entry->address); + } else { + gtk_entry_set_text(GTK_ENTRY(address_entry), + address_entry->title); + } +} + +static void +sugar_address_entry_set_address(SugarAddressEntry *address_entry, + const char *address) +{ + g_free(address_entry->address); + address_entry->address = g_strdup(address); + + update_entry_text(address_entry, + gtk_widget_is_focus(GTK_WIDGET(address_entry))); +} + +static void +sugar_address_entry_set_title(SugarAddressEntry *address_entry, + const char *title) +{ + g_free(address_entry->title); + address_entry->title = g_strdup(title); + + update_entry_text(address_entry, + gtk_widget_is_focus(GTK_WIDGET(address_entry))); +} + +static void +sugar_address_entry_set_property(GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) { SugarAddressEntry *address_entry = SUGAR_ADDRESS_ENTRY(object); GtkEntry *entry = GTK_ENTRY(object); switch (prop_id) { case PROP_PROGRESS: - address_entry->progress = g_value_get_double (value); - if (GTK_WIDGET_REALIZED (entry)) - gdk_window_invalidate_rect (entry->text_area, NULL, FALSE); + address_entry->progress = g_value_get_double(value); + if (GTK_WIDGET_REALIZED(entry)) + gdk_window_invalidate_rect(entry->text_area, NULL, FALSE); + break; + case PROP_ADDRESS: + sugar_address_entry_set_address(address_entry, + g_value_get_string(value)); + break; + case PROP_TITLE: + sugar_address_entry_set_title(address_entry, + g_value_get_string(value)); break; default: @@ -524,6 +569,12 @@ sugar_address_entry_get_property(GObject *object, case PROP_PROGRESS: g_value_set_double(value, entry->progress); break; + case PROP_TITLE: + g_value_set_string(value, entry->title); + break; + case PROP_ADDRESS: + g_value_set_string(value, entry->address); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -545,16 +596,50 @@ sugar_address_entry_class_init(SugarAddressEntryClass *klass) quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border"); g_object_class_install_property (gobject_class, PROP_PROGRESS, - g_param_spec_double ("progress", - "Progress", - "Progress", - 0.0, 1.0, 0.0, - G_PARAM_READWRITE)); + g_param_spec_double("progress", + "Progress", + "Progress", + 0.0, 1.0, 0.0, + G_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, PROP_TITLE, + g_param_spec_string("title", + "Title", + "Title", + "", + G_PARAM_READWRITE)); + + g_object_class_install_property (gobject_class, PROP_ADDRESS, + g_param_spec_string("address", + "Address", + "Address", + "", + G_PARAM_READWRITE)); +} + +static gboolean +focus_in_event_cb(GtkWidget *widget, GdkEventFocus *event) +{ + update_entry_text(SUGAR_ADDRESS_ENTRY(widget), TRUE); + return FALSE; +} + +static gboolean +focus_out_event_cb(GtkWidget *widget, GdkEventFocus *event) +{ + update_entry_text(SUGAR_ADDRESS_ENTRY(widget), FALSE); + return FALSE; } static void sugar_address_entry_init(SugarAddressEntry *entry) { entry->progress = 0.0; + entry->address = NULL; + entry->title = NULL; + + g_signal_connect(entry, "focus-in-event", + G_CALLBACK(focus_in_event_cb), NULL); + g_signal_connect(entry, "focus-out-event", + G_CALLBACK(focus_out_event_cb), NULL); } diff --git a/lib/src/sugar-address-entry.h b/lib/src/sugar-address-entry.h index 1145f41c..bf1838d1 100644 --- a/lib/src/sugar-address-entry.h +++ b/lib/src/sugar-address-entry.h @@ -39,6 +39,8 @@ struct _SugarAddressEntry { GtkEntry base_instance; float progress; + char *title; + char *address; }; struct _SugarAddressEntryClass { From 5a26d51d20938b7e982ef5d9fa5137e07b4a3f83 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 20 Oct 2006 19:54:28 +0200 Subject: [PATCH 2/2] Grab focus on the browser when explicitly opening an uri --- activities/web/toolbar.py | 1 + lib/python/_sugar.defs | 6 ++++++ lib/src/sugar-browser.cpp | 14 ++++++++++++++ lib/src/sugar-browser.h | 1 + 4 files changed, 22 insertions(+) diff --git a/activities/web/toolbar.py b/activities/web/toolbar.py index a2140791..a516d9f0 100644 --- a/activities/web/toolbar.py +++ b/activities/web/toolbar.py @@ -121,6 +121,7 @@ class Toolbar(gtk.Toolbar): def _entry_activate_cb(self, entry): self._embed.load_url(entry.get_text()) + self._embed.grab_focus() def _go_back_cb(self, button): self._embed.go_back() diff --git a/lib/python/_sugar.defs b/lib/python/_sugar.defs index 1e514651..1548d6ff 100644 --- a/lib/python/_sugar.defs +++ b/lib/python/_sugar.defs @@ -59,6 +59,12 @@ (return-type "none") ) +(define-method grab_focus + (of-object "SugarBrowser") + (c-name "sugar_browser_grab_focus") + (return-type "none") +) + (define-method create_window (of-object "SugarBrowser") (c-name "sugar_browser_create_window") diff --git a/lib/src/sugar-browser.cpp b/lib/src/sugar-browser.cpp index eea1e0c0..1d9efc7c 100644 --- a/lib/src/sugar-browser.cpp +++ b/lib/src/sugar-browser.cpp @@ -305,3 +305,17 @@ sugar_browser_scroll_pixels(SugarBrowser *browser, DOMWindow->ScrollBy (dx, dy); } + +void +sugar_browser_grab_focus(SugarBrowser *browser) +{ + GtkWidget *child; + + child = gtk_bin_get_child(GTK_BIN(browser)); + + if (child != NULL) { + gtk_widget_grab_focus (child); + } else { + g_warning ("Need to realize the embed before grabbing focus!\n"); + } +} diff --git a/lib/src/sugar-browser.h b/lib/src/sugar-browser.h index a978bf15..a60889f0 100644 --- a/lib/src/sugar-browser.h +++ b/lib/src/sugar-browser.h @@ -59,6 +59,7 @@ SugarBrowser *sugar_browser_create_window (SugarBrowser *browser); void sugar_browser_scroll_pixels (SugarBrowser *browser, int dx, int dy); +void sugar_browser_grab_focus (SugarBrowser *browser); G_END_DECLS