Merge branch 'master' of git+ssh://dev.laptop.org/git/sugar

This commit is contained in:
Dan Williams 2006-10-20 15:01:20 -04:00
commit ed7016e699
6 changed files with 127 additions and 14 deletions

View File

@ -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
@ -117,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()

View File

@ -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")

View File

@ -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);
}

View File

@ -39,6 +39,8 @@ struct _SugarAddressEntry {
GtkEntry base_instance;
float progress;
char *title;
char *address;
};
struct _SugarAddressEntryClass {

View File

@ -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");
}
}

View File

@ -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