Mercurial > pidgin
comparison src/gtkimhtml.c @ 8516:5b25f72c4723
[gaim-migrate @ 9254]
" Buttons don't push in and out when the cursor enters
regions that are differently formatted. For example, if
you move the cursor to a place where the text is bold,
the B button should probably be pushed in.
this patch adds the toolbar to update to the current
format when the mouse is clicked. I also cleaned up
some duplicated code and some logic." --Gary Kramlich
okay, that less than clear text basically boils down to you can move the
cursor with the mouse as well as the keyboard without confusing the toolbar
now
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sun, 28 Mar 2004 18:00:04 +0000 |
parents | 0b0d70464cad |
children | f8ab826e11ad |
comparison
equal
deleted
inserted
replaced
8515:0b0d70464cad | 8516:5b25f72c4723 |
---|---|
2558 g_signal_emit(object, signals[BUTTONS_UPDATE], 0, buttons); | 2558 g_signal_emit(object, signals[BUTTONS_UPDATE], 0, buttons); |
2559 imhtml->format_functions = buttons; | 2559 imhtml->format_functions = buttons; |
2560 g_object_unref(object); | 2560 g_object_unref(object); |
2561 } | 2561 } |
2562 | 2562 |
2563 void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gint offset, | 2563 static gboolean |
2564 gboolean *bold, gboolean *italic, | 2564 gtk_imhtml_has_open_tags(GtkIMHtml *imhtml) { |
2565 gboolean *underline) | 2565 if(imhtml->edit.bold && imhtml->edit.bold->end == NULL) |
2566 return TRUE; | |
2567 | |
2568 if(imhtml->edit.italic && imhtml->edit.italic->end == NULL) | |
2569 return TRUE; | |
2570 | |
2571 if(imhtml->edit.underline && imhtml->edit.underline->end == NULL) | |
2572 return TRUE; | |
2573 | |
2574 if(imhtml->edit.forecolor && imhtml->edit.forecolor->end == NULL) | |
2575 return TRUE; | |
2576 | |
2577 if(imhtml->edit.backcolor && imhtml->edit.backcolor->end == NULL) | |
2578 return TRUE; | |
2579 | |
2580 if(imhtml->edit.fontface && imhtml->edit.fontface->end == NULL) | |
2581 return TRUE; | |
2582 | |
2583 if(imhtml->edit.sizespan && imhtml->edit.sizespan->end == NULL) | |
2584 return TRUE; | |
2585 | |
2586 return FALSE; | |
2587 } | |
2588 | |
2589 void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gboolean *bold, | |
2590 gboolean *italic, gboolean *underline) | |
2566 { | 2591 { |
2567 GtkTextMark *ins_mark; | 2592 GtkTextMark *ins_mark; |
2568 GtkTextIter ins_iter, adj_iter, end_iter; | 2593 GtkTextIter ins_iter; |
2569 GSList *tags; | 2594 GSList *tags; |
2570 gint position, length, adjusted; | 2595 |
2571 | |
2572 /* grab the current cursor position compensate for the way that the | |
2573 * direction that the cursor was moved so that we get all the tags | |
2574 * for that current location | |
2575 */ | |
2576 ins_mark = gtk_text_buffer_get_insert(imhtml->text_buffer); | 2596 ins_mark = gtk_text_buffer_get_insert(imhtml->text_buffer); |
2577 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &ins_iter, ins_mark); | 2597 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &ins_iter, ins_mark); |
2578 position = gtk_text_iter_get_offset(&ins_iter); | 2598 |
2579 | 2599 if(gtk_imhtml_has_open_tags(imhtml)) { |
2580 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end_iter); | 2600 GtkTextIter end_iter; |
2581 length = gtk_text_iter_get_offset(&end_iter); | 2601 gint position, length; |
2582 | 2602 |
2583 adjusted = position + offset; | 2603 position = gtk_text_iter_get_offset(&ins_iter); |
2584 if(offset < 0) { /* moving left or up */ | 2604 |
2585 if(adjusted <= 0) | 2605 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end_iter); |
2586 adjusted = 1; | 2606 length = gtk_text_iter_get_offset(&end_iter); |
2587 } else if(offset > 0) { /* moving right or down */ | 2607 |
2588 if(adjusted >= length) | 2608 if(position == length) |
2589 adjusted = length - 1; | 2609 gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &ins_iter, |
2590 } | 2610 length - 1); |
2591 | 2611 } |
2592 gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &adj_iter, adjusted); | 2612 |
2593 | 2613 for(tags = gtk_text_iter_get_tags(&ins_iter); |
2594 /* grab the tags that apply to the cursor location */ | |
2595 for(tags = gtk_text_iter_get_tags(&adj_iter); | |
2596 tags != NULL; tags = tags->next) | 2614 tags != NULL; tags = tags->next) |
2597 { | 2615 { |
2598 GtkTextTag *tag = GTK_TEXT_TAG(tags->data); | 2616 GtkTextTag *tag = GTK_TEXT_TAG(tags->data); |
2599 if(tag->name) { | 2617 if(tag->name) { |
2600 if(g_ascii_strcasecmp(tag->name, "BOLD") == 0) | 2618 if(g_ascii_strcasecmp(tag->name, "BOLD") == 0) |