| 4930 } |
4930 } |
| 4931 |
4931 |
| 4932 static gboolean |
4932 static gboolean |
| 4933 resize_webview_cb(PidginConversation *gtkconv) |
4933 resize_webview_cb(PidginConversation *gtkconv) |
| 4934 { |
4934 { |
| 4935 #if 0 |
4935 WebKitWebView *webview; |
| 4936 /* TODO WebKit: entry sizing */ |
4936 gint min_lines; |
| 4937 GtkTextBuffer *buffer; |
4937 gint max_height; |
| 4938 GtkTextIter iter; |
4938 gint min_height; |
| 4939 int lines; |
4939 gint font_size; |
| 4940 GdkRectangle oneline; |
4940 gint total_height; |
| 4941 int height, diff; |
4941 gint height; |
| 4942 int pad_top, pad_inside, pad_bottom; |
4942 gint toolbar_size; |
| 4943 int total_height; |
|
| 4944 int max_height; |
|
| 4945 int min_lines = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/minimum_entry_lines"); |
|
| 4946 int min_height; |
|
| 4947 gboolean interior_focus; |
|
| 4948 int focus_width; |
|
| 4949 GtkAllocation webview_allocation; |
4943 GtkAllocation webview_allocation; |
| 4950 GtkAllocation entry_allocation; |
4944 GtkAllocation entry_allocation; |
| 4951 GtkAllocation lower_hbox_allocation; |
4945 |
| 4952 |
4946 webview = PIDGIN_WEBVIEW(gtkconv->entry); |
| |
4947 |
| |
4948 /* Get text height from the DOM */ |
| |
4949 height = pidgin_webview_get_DOM_height(webview); |
| |
4950 |
| |
4951 /* Find the height of the conversation window to calculate the maximum possible entry |
| |
4952 * size (1/2 of the window) |
| |
4953 */ |
| 4953 gtk_widget_get_allocation(gtkconv->webview, &webview_allocation); |
4954 gtk_widget_get_allocation(gtkconv->webview, &webview_allocation); |
| 4954 gtk_widget_get_allocation(gtkconv->entry, &entry_allocation); |
4955 gtk_widget_get_allocation(gtkconv->entry, &entry_allocation); |
| 4955 gtk_widget_get_allocation(gtkconv->lower_hbox, &lower_hbox_allocation); |
|
| 4956 total_height = webview_allocation.height + entry_allocation.height; |
4956 total_height = webview_allocation.height + entry_allocation.height; |
| 4957 max_height = total_height / 2; |
4957 max_height = total_height / 2; |
| 4958 |
4958 |
| 4959 pad_top = gtk_text_view_get_pixels_above_lines(GTK_TEXT_VIEW(gtkconv->entry)); |
4959 /* Get size of the characters to calculate initial minimum space for the entry */ |
| 4960 pad_bottom = gtk_text_view_get_pixels_below_lines(GTK_TEXT_VIEW(gtkconv->entry)); |
4960 font_size = pidgin_webview_get_font_size(webview); |
| 4961 pad_inside = gtk_text_view_get_pixels_inside_wrap(GTK_TEXT_VIEW(gtkconv->entry)); |
4961 |
| 4962 |
4962 /* Allow to have a minimum of "min_lines" height as defined in the preference */ |
| 4963 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry)); |
4963 min_lines = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/minimum_entry_lines"); |
| 4964 gtk_text_buffer_get_start_iter(buffer, &iter); |
4964 min_height = (font_size + WEBVIEW_DOM_FONT_PADDING) * min_lines + WEBVIEW_DOM_TEXT_PADDING; |
| 4965 gtk_text_view_get_iter_location(GTK_TEXT_VIEW(gtkconv->entry), &iter, &oneline); |
4965 |
| 4966 |
4966 |
| 4967 lines = gtk_text_buffer_get_line_count(buffer); |
4967 /* Take into account the size of the formatting toolbar */ |
| 4968 |
4968 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/show_formatting_toolbar")) { |
| 4969 height = 0; |
4969 toolbar_size = gtk_widget_get_allocated_height(pidgin_webview_get_toolbar(webview)); |
| 4970 do { |
4970 } else { |
| 4971 int lineheight = 0; |
4971 toolbar_size = 0; |
| 4972 gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(gtkconv->entry), &iter, NULL, &lineheight); |
4972 } |
| 4973 height += lineheight; |
4973 |
| 4974 lines--; |
4974 /* Calculate conv entry height */ |
| 4975 } while (gtk_text_iter_forward_line(&iter)); |
|
| 4976 height += lines * (oneline.height + pad_top + pad_bottom); |
|
| 4977 |
|
| 4978 /* Make sure there's enough room for at least min_lines. Allocate enough space to |
|
| 4979 * prevent scrolling when the second line is a continuation of the first line, or |
|
| 4980 * is the beginning of a new paragraph. */ |
|
| 4981 min_height = min_lines * (oneline.height + MAX(pad_inside, pad_top + pad_bottom)); |
|
| 4982 height = CLAMP(height, MIN(min_height, max_height), max_height); |
4975 height = CLAMP(height, MIN(min_height, max_height), max_height); |
| 4983 |
4976 /* Add the size used by the toolbar so we always take it into consideration. */ |
| 4984 gtk_widget_style_get(gtkconv->entry, |
4977 height += toolbar_size; |
| 4985 "interior-focus", &interior_focus, |
4978 |
| 4986 "focus-line-width", &focus_width, |
4979 /* Actually set the size of the gtkconv entry widget. */ |
| 4987 NULL); |
4980 gtk_widget_set_size_request(gtkconv->lower_hbox, -1, height); |
| 4988 if (!interior_focus) |
4981 purple_debug_info("pidgin", "resizing to %d, %d lines\n", height, min_lines); |
| 4989 height += 2 * focus_width; |
|
| 4990 |
|
| 4991 diff = height - entry_allocation.height; |
|
| 4992 if (ABS(diff) < oneline.height / 2) |
|
| 4993 return FALSE; |
|
| 4994 |
|
| 4995 purple_debug_info("pidgin", "resizing to %d, %d lines, diff %d\n", |
|
| 4996 diff + lower_hbox_allocation.height, min_lines, diff); |
|
| 4997 |
|
| 4998 gtk_widget_set_size_request(gtkconv->lower_hbox, -1, |
|
| 4999 diff + lower_hbox_allocation.height); |
|
| 5000 #endif |
|
| 5001 gtk_widget_set_size_request(gtkconv->lower_hbox, -1, -1); |
|
| 5002 |
4982 |
| 5003 return FALSE; |
4983 return FALSE; |
| 5004 } |
4984 } |
| 5005 |
4985 |
| 5006 static void |
4986 static void |
| 5716 g_signal_connect_swapped(G_OBJECT(gtkconv->entry_buffer), "changed", |
5696 g_signal_connect_swapped(G_OBJECT(gtkconv->entry_buffer), "changed", |
| 5717 G_CALLBACK(resize_webview_cb), gtkconv); |
5697 G_CALLBACK(resize_webview_cb), gtkconv); |
| 5718 g_signal_connect_swapped(G_OBJECT(gtkconv->entry), "size-allocate", |
5698 g_signal_connect_swapped(G_OBJECT(gtkconv->entry), "size-allocate", |
| 5719 G_CALLBACK(resize_webview_cb), gtkconv); |
5699 G_CALLBACK(resize_webview_cb), gtkconv); |
| 5720 #endif |
5700 #endif |
| |
5701 g_signal_connect_swapped(G_OBJECT(gtkconv->entry), "changed", |
| |
5702 G_CALLBACK(resize_webview_cb), gtkconv); |
| |
5703 g_signal_connect_swapped(G_OBJECT(gtkconv->entry), "size-allocate", |
| |
5704 G_CALLBACK(resize_webview_cb), gtkconv); |
| 5721 |
5705 |
| 5722 default_formatize(gtkconv); |
5706 default_formatize(gtkconv); |
| 5723 g_signal_connect_after(G_OBJECT(gtkconv->entry), "format-cleared", |
5707 g_signal_connect_after(G_OBJECT(gtkconv->entry), "format-cleared", |
| 5724 G_CALLBACK(clear_formatting_cb), gtkconv); |
5708 G_CALLBACK(clear_formatting_cb), gtkconv); |
| 5725 return vbox; |
5709 return vbox; |