diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2010-11-11 21:41:05 +0800 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2010-11-11 22:03:56 +0800 |
commit | 379f636d605a99f04fbd29481ff755e783f34707 (patch) | |
tree | df9c758efcfb163647b25b4d5322d24b3bdb6634 | |
parent | 1c7e66a2a609bf5e956c6f76bf7db7e585860731 (diff) | |
download | gsoc2013-empathy-379f636d605a99f04fbd29481ff755e783f34707.tar gsoc2013-empathy-379f636d605a99f04fbd29481ff755e783f34707.tar.gz gsoc2013-empathy-379f636d605a99f04fbd29481ff755e783f34707.tar.bz2 gsoc2013-empathy-379f636d605a99f04fbd29481ff755e783f34707.tar.lz gsoc2013-empathy-379f636d605a99f04fbd29481ff755e783f34707.tar.xz gsoc2013-empathy-379f636d605a99f04fbd29481ff755e783f34707.tar.zst gsoc2013-empathy-379f636d605a99f04fbd29481ff755e783f34707.zip |
move size-requst handling in input-text-view
-rw-r--r-- | libempathy-gtk/empathy-chat.c | 38 | ||||
-rw-r--r-- | libempathy-gtk/empathy-input-text-view.c | 49 |
2 files changed, 48 insertions, 39 deletions
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index 7c238f0c4..04e786253 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -61,7 +61,6 @@ #define CHAT_DIR_CREATE_MODE (S_IRUSR | S_IWUSR | S_IXUSR) #define CHAT_FILE_CREATE_MODE (S_IRUSR | S_IWUSR) #define IS_ENTER(v) (v == GDK_KEY_Return || v == GDK_KEY_ISO_Enter || v == GDK_KEY_KP_Enter) -#define MAX_INPUT_HEIGHT 150 #define COMPOSING_STOP_TIMEOUT 5 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyChat) @@ -1610,40 +1609,6 @@ chat_text_view_focus_in_event_cb (GtkWidget *widget, return TRUE; } -static gboolean -chat_input_set_size_request_idle (gpointer sw) -{ - gtk_widget_set_size_request (sw, -1, MAX_INPUT_HEIGHT); - - return FALSE; -} - -static void -chat_input_size_request_cb (GtkWidget *widget, - GtkRequisition *requisition, - EmpathyChat *chat) -{ - EmpathyChatPriv *priv = GET_PRIV (chat); - GtkWidget *sw; - - sw = gtk_widget_get_parent (widget); - if (requisition->height >= MAX_INPUT_HEIGHT && !priv->has_input_vscroll) { - g_idle_add (chat_input_set_size_request_idle, sw); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_NEVER, - GTK_POLICY_ALWAYS); - priv->has_input_vscroll = TRUE; - } - - if (requisition->height < MAX_INPUT_HEIGHT && priv->has_input_vscroll) { - gtk_widget_set_size_request (sw, -1, -1); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_NEVER, - GTK_POLICY_NEVER); - priv->has_input_vscroll = FALSE; - } -} - static void chat_input_realize_cb (GtkWidget *widget, EmpathyChat *chat) @@ -2594,9 +2559,6 @@ chat_create_ui (EmpathyChat *chat) g_signal_connect (chat->input_text_view, "key-press-event", G_CALLBACK (chat_input_key_press_event_cb), chat); - g_signal_connect (chat->input_text_view, "size-request", - G_CALLBACK (chat_input_size_request_cb), - chat); g_signal_connect (chat->input_text_view, "realize", G_CALLBACK (chat_input_realize_cb), chat); diff --git a/libempathy-gtk/empathy-input-text-view.c b/libempathy-gtk/empathy-input-text-view.c index 73ef32a45..4b9a61150 100644 --- a/libempathy-gtk/empathy-input-text-view.c +++ b/libempathy-gtk/empathy-input-text-view.c @@ -30,14 +30,61 @@ G_DEFINE_TYPE (EmpathyInputTextView, empathy_input_text_view, GTK_TYPE_TEXT_VIEW); +#define MAX_INPUT_HEIGHT 150 + struct _EmpathyInputTextViewPrivate { - gpointer unused; + gboolean has_input_vscroll; }; +static gboolean +chat_input_set_size_request_idle (gpointer sw) +{ + gtk_widget_set_size_request (sw, -1, MAX_INPUT_HEIGHT); + + return FALSE; +} + +static void +empathy_input_text_view_size_request (GtkWidget *widget, + GtkRequisition *requisition) +{ + EmpathyInputTextView *self = (EmpathyInputTextView *) widget; + GtkWidget *sw; + + sw = gtk_widget_get_parent (widget); + if (requisition->height >= MAX_INPUT_HEIGHT && !self->priv->has_input_vscroll) + { + /* Display scroll bar */ + g_idle_add (chat_input_set_size_request_idle, sw); + + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), + GTK_POLICY_NEVER, + GTK_POLICY_ALWAYS); + + self->priv->has_input_vscroll = TRUE; + } + + if (requisition->height < MAX_INPUT_HEIGHT && self->priv->has_input_vscroll) + { + /* Hide scroll bar */ + gtk_widget_set_size_request (sw, -1, -1); + + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), + GTK_POLICY_NEVER, + GTK_POLICY_NEVER); + + self->priv->has_input_vscroll = FALSE; + } +} + static void empathy_input_text_view_class_init (EmpathyInputTextViewClass *cls) { + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (cls); + + widget_class->size_request = empathy_input_text_view_size_request; + g_type_class_add_private (cls, sizeof (EmpathyInputTextViewPrivate)); } |