From e54a41851747a881494195a6e1251db70d7edcf4 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Fri, 9 Nov 2007 12:20:30 -0500 Subject: [PATCH] Update. --- gntbox.c | 6 +-- gntentry.c | 129 +++++++++++++++++++++++++++++++----------------------------- gntlabel.c | 79 ++++++++++++++++++++++++++++++++----- gntmain.c | 5 +-- gntmenu.c | 1 - gntwindow.c | 6 +-- gntws.h | 2 +- mtn | 2 +- 8 files changed, 141 insertions(+), 89 deletions(-) diff --git a/gntbox.c b/gntbox.c index 2f646e0..c4320f4 100644 --- a/gntbox.c +++ b/gntbox.c @@ -652,7 +652,6 @@ void gnt_box_add_widget(GntBox *b, GntWidget *widget) { b->list = g_list_append(b->list, widget); widget->parent = GNT_WIDGET(b); - g_object_ref(widget); } void gnt_box_set_title(GntBox *b, const char *title) @@ -751,8 +750,6 @@ void gnt_box_set_alignment(GntBox *box, GntAlignment alignment) void gnt_box_remove(GntBox *box, GntWidget *widget) { - if (!g_list_find(box->list, widget)) - return; box->list = g_list_remove(box->list, widget); if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS) && GNT_WIDGET(box)->parent == NULL && box->focus) @@ -768,12 +765,11 @@ void gnt_box_remove(GntBox *box, GntWidget *widget) if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(box), GNT_WIDGET_MAPPED)) gnt_widget_draw(GNT_WIDGET(box)); - g_object_unref(widget); } void gnt_box_remove_all(GntBox *box) { - g_list_foreach(box->list, (GFunc)g_object_unref, NULL); + g_list_foreach(box->list, (GFunc)gnt_widget_destroy, NULL); g_list_free(box->list); g_list_free(box->focus); box->list = NULL; diff --git a/gntentry.c b/gntentry.c index b071943..0e8ea64 100644 --- a/gntentry.c +++ b/gntentry.c @@ -717,76 +717,79 @@ gnt_entry_key_pressed(GntWidget *widget, const char *text) return FALSE; } - else + + if ((text[0] == '\r' || text[0] == ' ') && entry->ddown) { - if ((text[0] == '\r' || text[0] == ' ') && entry->ddown) - { - char *text = g_strdup(gnt_tree_get_selection_data(GNT_TREE(entry->ddown))); - destroy_suggest(entry); - complete_suggest(entry, text); - g_free(text); - update_kill_ring(entry, ENTRY_JAIL, NULL, 0); - entry_text_changed(entry); - return TRUE; - } + char *text = g_strdup(gnt_tree_get_selection_data(GNT_TREE(entry->ddown))); + destroy_suggest(entry); + complete_suggest(entry, text); + g_free(text); + update_kill_ring(entry, ENTRY_JAIL, NULL, 0); + entry_text_changed(entry); + return TRUE; + } + + if (!iscntrl(text[0])) + { + const char *str, *next; - if (!iscntrl(text[0])) + for (str = text; *str; str = next) { - const char *str, *next; + int len; + next = g_utf8_find_next_char(str, NULL); + len = next - str; + + /* Valid input? */ + /* XXX: Is it necessary to use _unichar_ variants here? */ + if (ispunct(*str) && (entry->flag & GNT_ENTRY_FLAG_NO_PUNCT)) + continue; + if (isspace(*str) && (entry->flag & GNT_ENTRY_FLAG_NO_SPACE)) + continue; + if (isalpha(*str) && !(entry->flag & GNT_ENTRY_FLAG_ALPHA)) + continue; + if (isdigit(*str) && !(entry->flag & GNT_ENTRY_FLAG_INT)) + continue; + + /* Reached the max? */ + if (entry->max && g_utf8_pointer_to_offset(entry->start, entry->end) >= entry->max) + continue; + + if (entry->end + len - entry->start >= entry->buffer) + { + /* This will cause the buffer to grow */ + char *tmp = g_strdup(entry->start); + gnt_entry_set_text_internal(entry, tmp); + g_free(tmp); + } - for (str = text; *str; str = next) + memmove(entry->cursor + len, entry->cursor, entry->end - entry->cursor + 1); + entry->end += len; + + while (str < next) { - int len; - next = g_utf8_find_next_char(str, NULL); - len = next - str; - - /* Valid input? */ - /* XXX: Is it necessary to use _unichar_ variants here? */ - if (ispunct(*str) && (entry->flag & GNT_ENTRY_FLAG_NO_PUNCT)) - continue; - if (isspace(*str) && (entry->flag & GNT_ENTRY_FLAG_NO_SPACE)) - continue; - if (isalpha(*str) && !(entry->flag & GNT_ENTRY_FLAG_ALPHA)) - continue; - if (isdigit(*str) && !(entry->flag & GNT_ENTRY_FLAG_INT)) - continue; - - /* Reached the max? */ - if (entry->max && g_utf8_pointer_to_offset(entry->start, entry->end) >= entry->max) - continue; - - if (entry->end + len - entry->start >= entry->buffer) - { - /* This will cause the buffer to grow */ - char *tmp = g_strdup(entry->start); - gnt_entry_set_text_internal(entry, tmp); - g_free(tmp); - } - - memmove(entry->cursor + len, entry->cursor, entry->end - entry->cursor + 1); - entry->end += len; - - while (str < next) - { - if (*str == '\r' || *str == '\n') - *entry->cursor = ' '; - else - *entry->cursor = *str; - entry->cursor++; - str++; - } - - while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= widget->priv.width) - entry->scroll = g_utf8_find_next_char(entry->scroll, NULL); - - if (entry->ddown) - show_suggest_dropdown(entry); + if (*str == '\r' || *str == '\n') + *entry->cursor = ' '; + else + *entry->cursor = *str; + entry->cursor++; + str++; } - update_kill_ring(entry, ENTRY_JAIL, NULL, 0); - entry_redraw(widget); - entry_text_changed(entry); - return TRUE; + + while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= widget->priv.width) + entry->scroll = g_utf8_find_next_char(entry->scroll, NULL); + + if (entry->ddown) + show_suggest_dropdown(entry); } + update_kill_ring(entry, ENTRY_JAIL, NULL, 0); + entry_redraw(widget); + entry_text_changed(entry); + return TRUE; + } + + if (text[0] == '\r') { + gnt_widget_activate(widget); + return TRUE; } return FALSE; diff --git a/gntlabel.c b/gntlabel.c index cd99fbe..5a256c9 100644 --- a/gntlabel.c +++ b/gntlabel.c @@ -27,6 +27,13 @@ enum { + PROP_0, + PROP_TEXT, + PROP_TEXT_FLAG +}; + +enum +{ SIGS = 1, }; @@ -61,14 +68,72 @@ gnt_label_size_request(GntWidget *widget) } static void +gnt_label_set_property(GObject *obj, guint prop_id, const GValue *value, + GParamSpec *spec) +{ + GntLabel *label = GNT_LABEL(obj); + switch (prop_id) { + case PROP_TEXT: + g_free(label->text); + label->text = gnt_util_onscreen_fit_string(g_value_get_string(value), -1); + break; + case PROP_TEXT_FLAG: + label->flags = g_value_get_int(value); + break; + default: + g_return_if_reached(); + break; + } +} + +static void +gnt_label_get_property(GObject *obj, guint prop_id, GValue *value, + GParamSpec *spec) +{ + GntLabel *label = GNT_LABEL(obj); + switch (prop_id) { + case PROP_TEXT: + g_value_set_string(value, label->text); + break; + case PROP_TEXT_FLAG: + g_value_set_int(value, label->flags); + break; + default: + break; + } +} + +static void gnt_label_class_init(GntLabelClass *klass) { + GObjectClass *gclass = G_OBJECT_CLASS(klass); + parent_class = GNT_WIDGET_CLASS(klass); parent_class->destroy = gnt_label_destroy; parent_class->draw = gnt_label_draw; parent_class->map = NULL; parent_class->size_request = gnt_label_size_request; + gclass->set_property = gnt_label_set_property; + gclass->get_property = gnt_label_get_property; + + g_object_class_install_property(gclass, + PROP_TEXT, + g_param_spec_string("text", "Text", + "The text for the label.", + NULL, + G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB + ) + ); + + g_object_class_install_property(gclass, + PROP_TEXT_FLAG, + g_param_spec_int("text-flag", "Text flag", + "Text attribute to use when displaying the text in the label.", + GNT_TEXT_FLAG_NORMAL, GNT_TEXT_FLAG_HIGHLIGHT, GNT_TEXT_FLAG_NORMAL, + G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB + ) + ); GNTDEBUG; } @@ -76,6 +141,8 @@ static void gnt_label_init(GTypeInstance *instance, gpointer class) { GntWidget *widget = GNT_WIDGET(instance); + gnt_widget_set_take_focus(widget, FALSE); + GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X); widget->priv.minw = 3; widget->priv.minh = 1; @@ -120,21 +187,13 @@ GntWidget *gnt_label_new(const char *text) GntWidget *gnt_label_new_with_format(const char *text, GntTextFormatFlags flags) { - GntWidget *widget = g_object_new(GNT_TYPE_LABEL, NULL); - GntLabel *label = GNT_LABEL(widget); - - label->text = gnt_util_onscreen_fit_string(text, -1); - label->flags = flags; - gnt_widget_set_take_focus(widget, FALSE); - GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); - + GntWidget *widget = g_object_new(GNT_TYPE_LABEL, "text-flag", flags, "text", text, NULL); return widget; } void gnt_label_set_text(GntLabel *label, const char *text) { - g_free(label->text); - label->text = gnt_util_onscreen_fit_string(text, -1); + g_object_set(label, "text", text, NULL); if (GNT_WIDGET(label)->window) { diff --git a/gntmain.c b/gntmain.c index 89ec0e3..ae2cedb 100644 --- a/gntmain.c +++ b/gntmain.c @@ -291,8 +291,7 @@ io_invoke(GIOChannel *source, GIOCondition cond, gpointer null) k += p; } end: - if (wm) - gnt_wm_set_event_stack(wm, FALSE); + gnt_wm_set_event_stack(wm, FALSE); g_free(cvrt); return TRUE; } @@ -626,7 +625,6 @@ void gnt_register_action(const char *label, void (*callback)()) static void reset_menu(GntWidget *widget, gpointer null) { - g_object_unref(G_OBJECT(wm->menu)); wm->menu = NULL; } @@ -641,7 +639,6 @@ gboolean gnt_screen_menu_show(gpointer newmenu) wm->menu = newmenu; GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(wm->menu), GNT_WIDGET_INVISIBLE); gnt_widget_draw(GNT_WIDGET(wm->menu)); - g_object_ref(G_OBJECT(wm->menu)); g_signal_connect(G_OBJECT(wm->menu), "hide", G_CALLBACK(reset_menu), NULL); g_signal_connect(G_OBJECT(wm->menu), "destroy", G_CALLBACK(reset_menu), NULL); diff --git a/gntmenu.c b/gntmenu.c index 2ca2066..ab44fe6 100644 --- a/gntmenu.c +++ b/gntmenu.c @@ -463,7 +463,6 @@ GntWidget *gnt_menu_new(GntMenuType type) void gnt_menu_add_item(GntMenu *menu, GntMenuItem *item) { menu->list = g_list_append(menu->list, item); - g_object_ref(item); } GntMenuItem *gnt_menu_get_item(GntMenu *menu, const char *id) diff --git a/gntwindow.c b/gntwindow.c index 24b6255..f1464a6 100644 --- a/gntwindow.c +++ b/gntwindow.c @@ -59,7 +59,7 @@ gnt_window_destroy(GntWidget *widget) { GntWindow *window = GNT_WINDOW(widget); if (window->menu) - g_object_unref(G_OBJECT(window->menu)); + gnt_widget_destroy(GNT_WIDGET(window->menu)); if (window->priv) { g_hash_table_destroy(window->priv->accels); g_free(window->priv); @@ -184,7 +184,7 @@ void gnt_window_set_menu(GntWindow *window, GntMenu *menu) /* If a menu already existed, then destroy that first. */ const char *name = gnt_widget_get_name(GNT_WIDGET(window)); if (window->menu) - g_object_unref(G_OBJECT(window->menu)); + gnt_widget_destroy(GNT_WIDGET(window->menu)); window->menu = menu; if (name && window->priv) { if (!gnt_style_read_menu_accels(name, window->priv->accels)) { @@ -193,8 +193,6 @@ void gnt_window_set_menu(GntWindow *window, GntMenu *menu) window->priv = NULL; } } - if (menu) - g_object_ref(G_OBJECT(menu)); } const char * gnt_window_get_accel_item(GntWindow *window, const char *key) diff --git a/gntws.h b/gntws.h index 262178a..e4e68c6 100644 --- a/gntws.h +++ b/gntws.h @@ -42,7 +42,7 @@ typedef struct _GntWS GntWS; struct _GntWS { GntBindable inherit; - char *name; + gchar *name; GList *list; GList *ordered; gpointer ui_data; diff --git a/mtn b/mtn index d8b7e65..3b3d26a 100644 --- a/mtn +++ b/mtn @@ -1 +1 @@ -58a7a68ec9891c7989ec16c0a3d52f9756de75db +eb98a9d415b707f51d82a14c06c9b2314199a4b8 -- 2.11.4.GIT