comparison src/gtkimhtml.c @ 9025:b24967757d46

[gaim-migrate @ 9801] " - Fixed text-decoration: underline; parsing from being dependent on font-size specified - IM HTML Toolbar dialogs now automatically fill with the color/font for the current text - Made most of the IMHTML formatting buttons fire signals where appropriate - Implemented a global on or off "Send default formatting with outgoing messages" option - If user previously sent a font name, we assume they want formatting on, otherwise it defaults to off. - Removed font and color from the GaimGtkConversation struct, because this wasn't being used anywhere, by anything and just resulted in more confusing code. - Removed three functions related to the struct, including one that was declared, but never actually written. - Added get_current_fontface, get_current_fontsize, get_current_forecolor, get_current_backcolor to gtk_imhtml_* to get the formatting at the cursor (or whole buffer when wbfo is on) - Removed all dialogs used only by the old default formatting preferences from dialogs.c - When font background, color, or face are "disabled" they are stored as an empty string in their prefs. - Fixed a bug where NULL for background, color, or face did not remove the tags in wbfo " all that, quoth SimGuy committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Sun, 23 May 2004 03:54:20 +0000
parents 6dc1f052edc0
children 6fd7de357672
comparison
equal deleted inserted replaced
9024:85caba2f820a 9025:b24967757d46
2297 if (oldfont) 2297 if (oldfont)
2298 { 2298 {
2299 font->underline = oldfont->underline; 2299 font->underline = oldfont->underline;
2300 } 2300 }
2301 if (textdec && font->underline != 1 2301 if (textdec && font->underline != 1
2302 && size 2302 && g_ascii_strcasecmp(textdec, "underline") == 0
2303 && g_ascii_strcasecmp(size, "underline") == 0
2304 && (imhtml->format_functions & GTK_IMHTML_UNDERLINE)) 2303 && (imhtml->format_functions & GTK_IMHTML_UNDERLINE))
2305 { 2304 {
2306 gtk_imhtml_toggle_underline(imhtml); 2305 gtk_imhtml_toggle_underline(imhtml);
2307 font->underline = 1; 2306 font->underline = 1;
2308 } 2307 }
3127 (*italic) = TRUE; 3126 (*italic) = TRUE;
3128 if (imhtml->edit.underline) 3127 if (imhtml->edit.underline)
3129 (*underline) = TRUE; 3128 (*underline) = TRUE;
3130 } 3129 }
3131 3130
3131 char *
3132 gtk_imhtml_get_current_fontface(GtkIMHtml *imhtml)
3133 {
3134 if (imhtml->edit.fontface)
3135 return g_strdup(imhtml->edit.fontface);
3136 else
3137 return NULL;
3138 }
3139
3140 char *
3141 gtk_imhtml_get_current_forecolor(GtkIMHtml *imhtml)
3142 {
3143 if (imhtml->edit.forecolor)
3144 return g_strdup(imhtml->edit.forecolor);
3145 else
3146 return NULL;
3147 }
3148
3149 char *
3150 gtk_imhtml_get_current_backcolor(GtkIMHtml *imhtml)
3151 {
3152 if (imhtml->edit.backcolor)
3153 return g_strdup(imhtml->edit.backcolor);
3154 else
3155 return NULL;
3156 }
3157
3158 gint
3159 gtk_imhtml_get_current_fontsize(GtkIMHtml *imhtml)
3160 {
3161 return imhtml->edit.fontsize;
3162 }
3163
3132 gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml) 3164 gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml)
3133 { 3165 {
3134 return imhtml->editable; 3166 return imhtml->editable;
3135 } 3167 }
3136 3168
3287 return imhtml->edit.underline != FALSE; 3319 return imhtml->edit.underline != FALSE;
3288 } 3320 }
3289 3321
3290 void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size) 3322 void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size)
3291 { 3323 {
3324 GObject *object;
3292 GtkTextIter start, end; 3325 GtkTextIter start, end;
3326 GtkIMHtmlButtons b = 0;
3293 3327
3294 imhtml->edit.fontsize = size; 3328 imhtml->edit.fontsize = size;
3295 3329
3296 3330
3297 if (imhtml->wbfo) { 3331 if (imhtml->wbfo) {
3303 remove_font_size(imhtml, &start, &end, FALSE); 3337 remove_font_size(imhtml, &start, &end, FALSE);
3304 gtk_text_buffer_apply_tag(imhtml->text_buffer, 3338 gtk_text_buffer_apply_tag(imhtml->text_buffer,
3305 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); 3339 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
3306 } 3340 }
3307 3341
3342 object = g_object_ref(G_OBJECT(imhtml));
3343 b |= GTK_IMHTML_SHRINK;
3344 b |= GTK_IMHTML_GROW;
3345 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, b);
3346 g_object_unref(object);
3308 } 3347 }
3309 3348
3310 void gtk_imhtml_font_shrink(GtkIMHtml *imhtml) 3349 void gtk_imhtml_font_shrink(GtkIMHtml *imhtml)
3311 { 3350 {
3351 GObject *object;
3312 GtkTextIter start, end; 3352 GtkTextIter start, end;
3313 3353
3314 if (imhtml->edit.fontsize == 1) 3354 if (imhtml->edit.fontsize == 1)
3315 return; 3355 return;
3316 3356
3327 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { 3367 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
3328 remove_font_size(imhtml, &start, &end, FALSE); 3368 remove_font_size(imhtml, &start, &end, FALSE);
3329 gtk_text_buffer_apply_tag(imhtml->text_buffer, 3369 gtk_text_buffer_apply_tag(imhtml->text_buffer,
3330 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); 3370 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
3331 } 3371 }
3372 object = g_object_ref(G_OBJECT(imhtml));
3373 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_SHRINK);
3374 g_object_unref(object);
3332 } 3375 }
3333 3376
3334 void gtk_imhtml_font_grow(GtkIMHtml *imhtml) 3377 void gtk_imhtml_font_grow(GtkIMHtml *imhtml)
3335 { 3378 {
3379 GObject *object;
3336 GtkTextIter start, end; 3380 GtkTextIter start, end;
3337 3381
3338 if (imhtml->edit.fontsize == MAX_FONT_SIZE) 3382 if (imhtml->edit.fontsize == MAX_FONT_SIZE)
3339 return; 3383 return;
3340 3384
3351 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { 3395 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
3352 remove_font_size(imhtml, &start, &end, FALSE); 3396 remove_font_size(imhtml, &start, &end, FALSE);
3353 gtk_text_buffer_apply_tag(imhtml->text_buffer, 3397 gtk_text_buffer_apply_tag(imhtml->text_buffer,
3354 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); 3398 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
3355 } 3399 }
3400 object = g_object_ref(G_OBJECT(imhtml));
3401 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_GROW);
3402 g_object_unref(object);
3356 } 3403 }
3357 3404
3358 gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color) 3405 gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color)
3359 { 3406 {
3407 GObject *object;
3360 GtkTextIter start, end; 3408 GtkTextIter start, end;
3361 3409
3362 if (imhtml->edit.forecolor != NULL) 3410 if (imhtml->edit.forecolor != NULL)
3363 g_free(imhtml->edit.forecolor); 3411 g_free(imhtml->edit.forecolor);
3364 3412
3365 if (color) { 3413 if (color && strcmp(color, "") != 0) {
3366 imhtml->edit.forecolor = g_strdup(color); 3414 imhtml->edit.forecolor = g_strdup(color);
3367 if (imhtml->wbfo) { 3415 if (imhtml->wbfo) {
3368 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); 3416 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
3369 remove_font_forecolor(imhtml, &start, &end, TRUE); 3417 remove_font_forecolor(imhtml, &start, &end, TRUE);
3370 gtk_text_buffer_apply_tag(imhtml->text_buffer, 3418 gtk_text_buffer_apply_tag(imhtml->text_buffer,
3375 find_font_forecolor_tag(imhtml, imhtml->edit.forecolor), 3423 find_font_forecolor_tag(imhtml, imhtml->edit.forecolor),
3376 &start, &end); 3424 &start, &end);
3377 } 3425 }
3378 } else { 3426 } else {
3379 imhtml->edit.forecolor = NULL; 3427 imhtml->edit.forecolor = NULL;
3380 } 3428 if (imhtml->wbfo) {
3429 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
3430 remove_font_forecolor(imhtml, &start, &end, TRUE);
3431 }
3432 }
3433
3434 object = g_object_ref(G_OBJECT(imhtml));
3435 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_FORECOLOR);
3436 g_object_unref(object);
3381 3437
3382 return imhtml->edit.forecolor != NULL; 3438 return imhtml->edit.forecolor != NULL;
3383 } 3439 }
3384 3440
3385 gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color) 3441 gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color)
3386 { 3442 {
3443 GObject *object;
3387 GtkTextIter start, end; 3444 GtkTextIter start, end;
3388 3445
3389 if (imhtml->edit.backcolor != NULL) 3446 if (imhtml->edit.backcolor != NULL)
3390 g_free(imhtml->edit.backcolor); 3447 g_free(imhtml->edit.backcolor);
3391 3448
3392 if (color) { 3449 if (color && strcmp(color, "") != 0) {
3393 imhtml->edit.backcolor = g_strdup(color); 3450 imhtml->edit.backcolor = g_strdup(color);
3394 3451
3395 if (imhtml->wbfo) { 3452 if (imhtml->wbfo) {
3396 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); 3453 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
3397 remove_font_backcolor(imhtml, &start, &end, TRUE); 3454 remove_font_backcolor(imhtml, &start, &end, TRUE);
3403 find_font_backcolor_tag(imhtml, 3460 find_font_backcolor_tag(imhtml,
3404 imhtml->edit.backcolor), &start, &end); 3461 imhtml->edit.backcolor), &start, &end);
3405 } 3462 }
3406 } else { 3463 } else {
3407 imhtml->edit.backcolor = NULL; 3464 imhtml->edit.backcolor = NULL;
3408 } 3465 if (imhtml->wbfo) {
3466 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
3467 remove_font_backcolor(imhtml, &start, &end, TRUE);
3468 }
3469 }
3470
3471 object = g_object_ref(G_OBJECT(imhtml));
3472 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_BACKCOLOR);
3473 g_object_unref(object);
3409 3474
3410 return imhtml->edit.backcolor != NULL; 3475 return imhtml->edit.backcolor != NULL;
3411 } 3476 }
3412 3477
3413 gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face) 3478 gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face)
3414 { 3479 {
3480 GObject *object;
3415 GtkTextIter start, end; 3481 GtkTextIter start, end;
3416 3482
3417 if (imhtml->edit.fontface != NULL) 3483 if (imhtml->edit.fontface != NULL)
3418 g_free(imhtml->edit.fontface); 3484 g_free(imhtml->edit.fontface);
3419 3485
3420 if (face) { 3486 if (face && strcmp(face, "") != 0) {
3421 imhtml->edit.fontface = g_strdup(face); 3487 imhtml->edit.fontface = g_strdup(face);
3422 3488
3423 if (imhtml->wbfo) { 3489 if (imhtml->wbfo) {
3424 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); 3490 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
3425 remove_font_face(imhtml, &start, &end, TRUE); 3491 remove_font_face(imhtml, &start, &end, TRUE);
3431 find_font_face_tag(imhtml, imhtml->edit.fontface), 3497 find_font_face_tag(imhtml, imhtml->edit.fontface),
3432 &start, &end); 3498 &start, &end);
3433 } 3499 }
3434 } else { 3500 } else {
3435 imhtml->edit.fontface = NULL; 3501 imhtml->edit.fontface = NULL;
3436 } 3502 if (imhtml->wbfo) {
3503 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
3504 remove_font_face(imhtml, &start, &end, TRUE);
3505 }
3506 }
3507
3508 object = g_object_ref(G_OBJECT(imhtml));
3509 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_FACE);
3510 g_object_unref(object);
3437 3511
3438 return imhtml->edit.fontface != NULL; 3512 return imhtml->edit.fontface != NULL;
3439 } 3513 }
3440 3514
3441 void gtk_imhtml_toggle_link(GtkIMHtml *imhtml, const char *url) 3515 void gtk_imhtml_toggle_link(GtkIMHtml *imhtml, const char *url)
3442 { 3516 {
3517 GObject *object;
3443 GtkTextIter start, end; 3518 GtkTextIter start, end;
3444 GtkTextTag *linktag; 3519 GtkTextTag *linktag;
3445 static guint linkno = 0; 3520 static guint linkno = 0;
3446 gchar str[48]; 3521 gchar str[48];
3447 GdkColor *color = NULL; 3522 GdkColor *color = NULL;
3467 if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { 3542 if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
3468 remove_font_link(imhtml, &start, &end, FALSE); 3543 remove_font_link(imhtml, &start, &end, FALSE);
3469 gtk_text_buffer_apply_tag(imhtml->text_buffer, linktag, &start, &end); 3544 gtk_text_buffer_apply_tag(imhtml->text_buffer, linktag, &start, &end);
3470 } 3545 }
3471 } 3546 }
3547
3548 object = g_object_ref(G_OBJECT(imhtml));
3549 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_LINK);
3550 g_object_unref(object);
3472 } 3551 }
3473 3552
3474 void gtk_imhtml_insert_link(GtkIMHtml *imhtml, GtkTextMark *mark, const char *url, const char *text) 3553 void gtk_imhtml_insert_link(GtkIMHtml *imhtml, GtkTextMark *mark, const char *url, const char *text)
3475 { 3554 {
3476 GtkTextIter iter; 3555 GtkTextIter iter;