Mercurial > pidgin
comparison src/gtkimhtml.c @ 11224:409d6a11da51
[gaim-migrate @ 13360]
Restrict the conversation scrollback. Current default is 4000 lines. This also fixes the IM images not actually being cleared by gtk_imhtml_clear().
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Wed, 10 Aug 2005 21:13:44 +0000 |
parents | 5c56223fa24f |
children | f08d22130bb2 |
comparison
equal
deleted
inserted
replaced
11223:d424c3bbac8d | 11224:409d6a11da51 |
---|---|
75 #define gtk_widget_get_clipboard(x, y) gtk_clipboard_get(y) | 75 #define gtk_widget_get_clipboard(x, y) gtk_clipboard_get(y) |
76 #endif | 76 #endif |
77 | 77 |
78 static GtkTextViewClass *parent_class = NULL; | 78 static GtkTextViewClass *parent_class = NULL; |
79 | 79 |
80 struct scalable_data { | |
81 GtkIMHtmlScalable *scalable; | |
82 GtkTextMark *mark; | |
83 }; | |
84 | |
85 | |
86 struct im_image_data { | |
87 int id; | |
88 GtkTextMark *mark; | |
89 }; | |
90 | |
80 static gboolean | 91 static gboolean |
81 gtk_text_view_drag_motion (GtkWidget *widget, | 92 gtk_text_view_drag_motion (GtkWidget *widget, |
82 GdkDragContext *context, | 93 GdkDragContext *context, |
83 gint x, | 94 gint x, |
84 gint y, | 95 gint y, |
369 | 380 |
370 xminus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(widget)) + | 381 xminus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(widget)) + |
371 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(widget)); | 382 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(widget)); |
372 | 383 |
373 while(iter){ | 384 while(iter){ |
374 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(iter->data); | 385 struct scalable_data *sd = iter->data; |
386 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(sd->scalable); | |
375 scale->scale(scale, rect.width - xminus, rect.height); | 387 scale->scale(scale, rect.width - xminus, rect.height); |
376 | 388 |
377 iter = iter->next; | 389 iter = iter->next; |
378 } | 390 } |
379 } | 391 } |
1137 } | 1149 } |
1138 if(imhtml->tip_timer) | 1150 if(imhtml->tip_timer) |
1139 gtk_timeout_remove(imhtml->tip_timer); | 1151 gtk_timeout_remove(imhtml->tip_timer); |
1140 | 1152 |
1141 for(scalables = imhtml->scalables; scalables; scalables = scalables->next) { | 1153 for(scalables = imhtml->scalables; scalables; scalables = scalables->next) { |
1142 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(scalables->data); | 1154 struct scalable_data *sd = scalables->data; |
1155 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(sd->scalable); | |
1143 scale->free(scale); | 1156 scale->free(scale); |
1157 g_free(sd); | |
1144 } | 1158 } |
1145 | 1159 |
1146 for (l = imhtml->im_images; l; l = l->next) { | 1160 for (l = imhtml->im_images; l; l = l->next) { |
1147 int id; | 1161 struct im_image_data *img_data = l->data; |
1148 id = GPOINTER_TO_INT(l->data); | |
1149 if (imhtml->funcs->image_unref) | 1162 if (imhtml->funcs->image_unref) |
1150 imhtml->funcs->image_unref(id); | 1163 imhtml->funcs->image_unref(img_data->id); |
1164 g_free(img_data); | |
1151 } | 1165 } |
1152 | 1166 |
1153 if (imhtml->clipboard_text_string) { | 1167 if (imhtml->clipboard_text_string) { |
1154 g_free(imhtml->clipboard_text_string); | 1168 g_free(imhtml->clipboard_text_string); |
1155 g_free(imhtml->clipboard_html_string); | 1169 g_free(imhtml->clipboard_html_string); |
2461 break; | 2475 break; |
2462 case 26: /* HR */ | 2476 case 26: /* HR */ |
2463 case 42: /* HR (opt) */ | 2477 case 42: /* HR (opt) */ |
2464 { | 2478 { |
2465 int minus; | 2479 int minus; |
2480 struct scalable_data *sd = g_new(struct scalable_data, 1); | |
2466 | 2481 |
2467 ws[wpos++] = '\n'; | 2482 ws[wpos++] = '\n'; |
2468 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | 2483 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
2469 | 2484 |
2470 scalable = gtk_imhtml_hr_new(); | 2485 sd->scalable = scalable = gtk_imhtml_hr_new(); |
2471 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | 2486 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
2472 scalable->add_to(scalable, imhtml, iter); | 2487 scalable->add_to(scalable, imhtml, iter); |
2473 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) + | 2488 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) + |
2474 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml)); | 2489 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml)); |
2475 scalable->scale(scalable, rect.width - minus, rect.height); | 2490 scalable->scale(scalable, rect.width - minus, rect.height); |
2476 imhtml->scalables = g_list_append(imhtml->scalables, scalable); | 2491 sd->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE); |
2492 imhtml->scalables = g_list_append(imhtml->scalables, sd); | |
2477 ws[0] = '\0'; wpos = 0; | 2493 ws[0] = '\0'; wpos = 0; |
2478 ws[wpos++] = '\n'; | 2494 ws[wpos++] = '\n'; |
2479 | 2495 |
2480 break; | 2496 break; |
2481 } | 2497 } |
2967 g_free(imhtml->protocol_name); | 2983 g_free(imhtml->protocol_name); |
2968 imhtml->protocol_name = protocol_name ? g_strdup(protocol_name) : NULL; | 2984 imhtml->protocol_name = protocol_name ? g_strdup(protocol_name) : NULL; |
2969 } | 2985 } |
2970 | 2986 |
2971 void | 2987 void |
2972 gtk_imhtml_clear (GtkIMHtml *imhtml) | 2988 gtk_imhtml_delete(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) { |
2973 { | 2989 GList *l; |
2974 GList *del; | 2990 GSList *sl; |
2975 GtkTextIter start, end; | 2991 GtkTextIter i; |
2976 GObject *object = g_object_ref(G_OBJECT(imhtml)); | 2992 GObject *object = g_object_ref(G_OBJECT(imhtml)); |
2977 | 2993 |
2978 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); | 2994 if (start == NULL) { |
2979 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | 2995 GtkTextIter i_s; |
2980 gtk_text_buffer_delete(imhtml->text_buffer, &start, &end); | 2996 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &i_s); |
2981 | 2997 start = &i_s; |
2982 for(del = imhtml->scalables; del; del = del->next) { | 2998 } |
2983 GtkIMHtmlScalable *scale = del->data; | 2999 |
2984 scale->free(scale); | 3000 if (end == NULL) { |
2985 } | 3001 GtkTextIter i_e; |
2986 | 3002 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &i_e); |
2987 g_list_free(imhtml->scalables); | 3003 end = &i_e; |
2988 imhtml->scalables = NULL; | 3004 } |
3005 | |
3006 l = imhtml->scalables; | |
3007 while (l) { | |
3008 GList *next = l->next; | |
3009 struct scalable_data *sd = l->data; | |
3010 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, | |
3011 &i, sd->mark); | |
3012 if (gtk_text_iter_in_range(&i, start, end)) { | |
3013 GtkIMHtmlScalable *scale = sd->scalable; | |
3014 scale->free(scale); | |
3015 imhtml->scalables = g_list_remove_link(imhtml->scalables, l); | |
3016 } | |
3017 l = next; | |
3018 } | |
3019 | |
3020 sl = imhtml->im_images; | |
3021 while (sl) { | |
3022 GSList *next = sl->next; | |
3023 struct im_image_data *img_data = sl->data; | |
3024 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, | |
3025 &i, img_data->mark); | |
3026 if (gtk_text_iter_in_range(&i, start, end)) { | |
3027 if (imhtml->funcs->image_unref) | |
3028 imhtml->funcs->image_unref(img_data->id); | |
3029 imhtml->im_images = g_slist_delete_link(imhtml->im_images, sl); | |
3030 g_free(img_data); | |
3031 } | |
3032 sl = next; | |
3033 } | |
3034 gtk_text_buffer_delete(imhtml->text_buffer, start, end); | |
2989 | 3035 |
2990 g_object_unref(object); | 3036 g_object_unref(object); |
2991 } | 3037 } |
2992 | 3038 |
2993 void gtk_imhtml_page_up (GtkIMHtml *imhtml) | 3039 void gtk_imhtml_page_up (GtkIMHtml *imhtml) |
4192 GdkPixbuf *pixbuf = NULL; | 4238 GdkPixbuf *pixbuf = NULL; |
4193 const char *filename = NULL; | 4239 const char *filename = NULL; |
4194 gpointer image; | 4240 gpointer image; |
4195 GdkRectangle rect; | 4241 GdkRectangle rect; |
4196 GtkIMHtmlScalable *scalable = NULL; | 4242 GtkIMHtmlScalable *scalable = NULL; |
4243 struct scalable_data *sd; | |
4197 int minus; | 4244 int minus; |
4198 | 4245 |
4199 if (!imhtml->funcs || !imhtml->funcs->image_get || | 4246 if (!imhtml->funcs || !imhtml->funcs->image_get || |
4200 !imhtml->funcs->image_get_size || !imhtml->funcs->image_get_data || | 4247 !imhtml->funcs->image_get_size || !imhtml->funcs->image_get_data || |
4201 !imhtml->funcs->image_get_filename || !imhtml->funcs->image_ref || | 4248 !imhtml->funcs->image_get_filename || !imhtml->funcs->image_ref || |
4224 } | 4271 } |
4225 | 4272 |
4226 if (pixbuf) { | 4273 if (pixbuf) { |
4227 filename = imhtml->funcs->image_get_filename(image); | 4274 filename = imhtml->funcs->image_get_filename(image); |
4228 imhtml->funcs->image_ref(id); | 4275 imhtml->funcs->image_ref(id); |
4229 imhtml->im_images = g_slist_prepend(imhtml->im_images, GINT_TO_POINTER(id)); | 4276 struct im_image_data *t = g_new(struct im_image_data, 1); |
4277 t->id = id; | |
4278 t->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE); | |
4279 imhtml->im_images = g_slist_prepend(imhtml->im_images, t); | |
4230 } else { | 4280 } else { |
4231 pixbuf = gtk_widget_render_icon(GTK_WIDGET(imhtml), GTK_STOCK_MISSING_IMAGE, | 4281 pixbuf = gtk_widget_render_icon(GTK_WIDGET(imhtml), GTK_STOCK_MISSING_IMAGE, |
4232 GTK_ICON_SIZE_BUTTON, "gtkimhtml-missing-image"); | 4282 GTK_ICON_SIZE_BUTTON, "gtkimhtml-missing-image"); |
4233 } | 4283 } |
4234 | 4284 |
4235 scalable = gtk_imhtml_image_new(pixbuf, filename, id); | 4285 sd = g_new(struct scalable_data, 1); |
4286 sd->scalable = scalable = gtk_imhtml_image_new(pixbuf, filename, id); | |
4236 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | 4287 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
4237 scalable->add_to(scalable, imhtml, iter); | 4288 scalable->add_to(scalable, imhtml, iter); |
4238 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) + | 4289 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) + |
4239 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml)); | 4290 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml)); |
4240 scalable->scale(scalable, rect.width - minus, rect.height); | 4291 scalable->scale(scalable, rect.width - minus, rect.height); |
4241 imhtml->scalables = g_list_append(imhtml->scalables, scalable); | 4292 sd->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE); |
4293 imhtml->scalables = g_list_append(imhtml->scalables, sd); | |
4242 | 4294 |
4243 g_object_unref(G_OBJECT(pixbuf)); | 4295 g_object_unref(G_OBJECT(pixbuf)); |
4244 } | 4296 } |
4245 | 4297 |
4246 static const gchar *tag_to_html_start(GtkTextTag *tag) | 4298 static const gchar *tag_to_html_start(GtkTextTag *tag) |