comparison src/conversation.c @ 666:71ea550c22ac

[gaim-migrate @ 676] la la la. i also modified how fonts work a bit to make the convo window smaller and the code more understandable. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Fri, 11 Aug 2000 03:04:29 +0000
parents 31384b25f7b6
children 02ef523db170
comparison
equal deleted inserted replaced
665:0bbcdd94e5b0 666:71ea550c22ac
79 int state_lock=0; 79 int state_lock=0;
80 80
81 GdkPixmap *dark_icon_pm = NULL; 81 GdkPixmap *dark_icon_pm = NULL;
82 GdkBitmap *dark_icon_bm = NULL; 82 GdkBitmap *dark_icon_bm = NULL;
83 83
84 char *fontface; 84 char fontface[64];
85 int bgcolor = 0;
86 int fgcolor = 0;
85 87
86 void check_everything(GtkWidget *entry); 88 void check_everything(GtkWidget *entry);
87 char *get_tag_by_prefix(GtkWidget *entry, const char *prefix);
88 gboolean keypress_callback(GtkWidget *entry, GdkEventKey *event, struct conversation *c); 89 gboolean keypress_callback(GtkWidget *entry, GdkEventKey *event, struct conversation *c);
89 90
90 /*------------------------------------------------------------------------*/ 91 /*------------------------------------------------------------------------*/
91 /* Helpers */ 92 /* Helpers */
92 /*------------------------------------------------------------------------*/ 93 /*------------------------------------------------------------------------*/
163 } 164 }
164 cnv = cnv->next; 165 cnv = cnv->next;
165 } 166 }
166 g_free(cuser); 167 g_free(cuser);
167 return NULL; 168 return NULL;
168 }
169
170 /* given the first part of a tag, returns the length up to the final '>';
171 useful for 'remove_tags' calls on variable data, such as <font face>
172 tags */
173 char *get_tag_by_prefix(GtkWidget *entry, const char *prefix)
174 {
175 char *s, *t;
176 int i = 0;
177
178 s = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
179 t = s;
180
181 if ((t = strstr(s, prefix)) != NULL)
182 {
183 for (i = 1; t[i] != '\0'; i++)
184 {
185
186 if (t[i] == '>')
187 break;
188 }
189
190 t = gtk_editable_get_chars(GTK_EDITABLE(entry), (t-s), (t-s) + i + 1);
191 }
192 return t;
193 } 169 }
194 170
195 void make_direct(struct conversation *c, gboolean direct, struct aim_conn_t *conn, gint watcher) 171 void make_direct(struct conversation *c, gboolean direct, struct aim_conn_t *conn, gint watcher)
196 { 172 {
197 char buf[BUF_LONG]; 173 char buf[BUF_LONG];
413 } 389 }
414 390
415 return TRUE; 391 return TRUE;
416 } 392 }
417 393
418 void set_font_face(GtkWidget *widget, struct conversation *c) 394 void set_font_face(char *newfont, struct conversation *c)
419 { 395 {
420 char *pre_fontface, *old_font_face; 396 char *pre_fontface;
421 int alloc = 0; 397 int alloc = 1;
422 398
423 if (c->current_fontface[0] && strcmp(c->current_fontface, "(null)")) 399 pre_fontface = g_strconcat("<FONT FACE=\"", newfont, "\">", '\0');
424 {
425 pre_fontface = g_strconcat("<FONT FACE=\"", c->current_fontface, "\">", '\0');
426 alloc++;
427 }
428 else
429 pre_fontface = "<FONT FACE=\"Helvetica\">";
430 400
431 if (!strcmp(pre_fontface, "<FONT FACE=\"\">")) 401 if (!strcmp(pre_fontface, "<FONT FACE=\"\">"))
432 { 402 {
433 g_free(pre_fontface); 403 g_free(pre_fontface);
434 alloc--; 404 alloc--;
435 pre_fontface = "<FONT FACE=\"Helvetica\">"; 405 pre_fontface = "<FONT FACE=\"Helvetica\">";
436 } 406 }
437 407
438 if ((old_font_face = get_tag_by_prefix(c->entry, "<FONT FACE")) != NULL)
439 {
440 remove_tags(c->entry, old_font_face);
441 remove_tags(c->entry, "</FONT>");
442 }
443
444 surround(c->entry, pre_fontface, "</FONT>"); 408 surround(c->entry, pre_fontface, "</FONT>");
445 gtk_widget_grab_focus(c->entry); 409 gtk_widget_grab_focus(c->entry);
446 410
447 if (alloc) 411 if (alloc)
448 g_free(pre_fontface); 412 g_free(pre_fontface);
449
450 g_free(old_font_face); /* mem allocated in get_tag_by_prefix() */
451 return;
452 } 413 }
453 414
454 static gint delete_event_convo(GtkWidget *w, GdkEventAny *e, struct conversation *c) 415 static gint delete_event_convo(GtkWidget *w, GdkEventAny *e, struct conversation *c)
455 { 416 {
456 delete_conversation(c); 417 delete_conversation(c);
612 g_snprintf(buf2, BUF_LONG, "<STRIKE>%s</STRIKE>", buf); 573 g_snprintf(buf2, BUF_LONG, "<STRIKE>%s</STRIKE>", buf);
613 strcpy(buf, buf2); 574 strcpy(buf, buf2);
614 } 575 }
615 576
616 if (font_options & OPT_FONT_FACE) { 577 if (font_options & OPT_FONT_FACE) {
617 g_snprintf(buf2, BUF_LONG, "<FONT FACE=\"%s\">%s</FONT>", c->current_fontface, buf); 578 g_snprintf(buf2, BUF_LONG, "<FONT FACE=\"%s\">%s</FONT>", fontface, buf);
618 strcpy(buf, buf2); 579 strcpy(buf, buf2);
619 } 580 }
581
582 if (font_options & OPT_FONT_FGCOL) {
583 g_snprintf(buf2, BUF_LONG, "<FONT COLOR=\"#%x\">%s</FONT>", fgcolor, buf);
584 strcpy(buf, buf2);
585 }
586
587 if (font_options & OPT_FONT_BGCOL) {
588 g_snprintf(buf2, BUF_LONG, "<BODY BGCOLOR=\"#%x\">%s</BODY>", bgcolor, buf);
589 strcpy(buf, buf2);
590 }
620 591
621 #ifdef GAIM_PLUGINS 592 #ifdef GAIM_PLUGINS
622 { 593 {
623 GList *ca = callbacks; 594 GList *ca = callbacks;
624 struct gaim_callback *g; 595 struct gaim_callback *g;
1628 gtk_window_set_focus(GTK_WINDOW(win),entry); 1599 gtk_window_set_focus(GTK_WINDOW(win),entry);
1629 1600
1630 gtk_signal_connect(GTK_OBJECT(win), "delete_event", GTK_SIGNAL_FUNC(delete_event_convo), c); 1601 gtk_signal_connect(GTK_OBJECT(win), "delete_event", GTK_SIGNAL_FUNC(delete_event_convo), c);
1631 gtk_signal_connect(GTK_OBJECT(entry), "insert-text", GTK_SIGNAL_FUNC(check_spelling), entry); 1602 gtk_signal_connect(GTK_OBJECT(entry), "insert-text", GTK_SIGNAL_FUNC(check_spelling), entry);
1632 gtk_signal_connect(GTK_OBJECT(entry), "key_press_event", GTK_SIGNAL_FUNC(entry_key_pressed), entry); 1603 gtk_signal_connect(GTK_OBJECT(entry), "key_press_event", GTK_SIGNAL_FUNC(entry_key_pressed), entry);
1633 1604
1634 if (fontface)
1635 strncpy(c->current_fontface, fontface, sizeof(c->current_fontface));
1636 if (fontname)
1637 strncpy(c->current_fontname, fontname, sizeof(c->current_fontname));
1638
1639 gtk_widget_show(win); 1605 gtk_widget_show(win);
1640 } 1606 }
1641 1607
1642 1608