| Yattm - unified GTK instant-messaging client | ![]() |
| [Generated for version 0.2-17 - Mon Jan 6 19:01:23 GMT+1 2003] |
#include "intl.h"#include <gtk/gtk.h>#include <string.h>#include <stdlib.h>#include <stdio.h>#include <ctype.h>#include "pixmaps/aol_icon.xpm"#include "pixmaps/free_icon.xpm"#include "pixmaps/dt_icon.xpm"#include "pixmaps/admin_icon.xpm"#include "pixmaps/no_such_smiley.xpm"#include "extgtktext.h"#include "browser.h"#include "globals.h"#include "smileys.h"Include dependency graph for gtk_eb_html.c:

Go to the source code of this file.
Data Structures | |
| struct | _font_stack |
Defines | |
| #define | DEBUG |
Typedefs | |
| typedef _font_stack | font_stack |
Functions | |
| int | _adjust_font_metrics (int size) |
| char * | _unescape_string (char *input) |
| GdkFont * | _getfont (char *font, int bold, int italic, int size, int ptsize) |
| GdkColor * | _getcolor (GdkColormap *map, char *name) |
| void | _extract_parameter (char *parm, char *buffer, int buffer_size) |
| font_stack * | _font_stack_init () |
| font_stack * | _font_stack_push (font_stack *fs) |
| font_stack * | _font_stack_pop (font_stack *fs) |
| void | handle_click (GdkWindow *widget, gpointer data) |
| void | gtk_eb_html_init (ExtGtkText *widget) |
| int | _lighten (int color) |
| int | _darken (int color) |
| int | _is_dark (int r, int g, int b) |
| void | _adjust_colors (int *fg_r, int *fg_g, int *fg_b, int r, int g, int b) |
| void | gtk_eb_html_add (ExtGtkText *widget, char *text, int ignore_bgcolor, int ignore_fgcolor, int ignore_font) |
Variables | |
| GData * | font_cache |
| gboolean | cache_init = FALSE |
| gint | font_size |
|
|
Definition at line 56 of file gtk_eb_html.c. |
|
|
|
|
||||||||||||||||||||||||||||
|
Definition at line 439 of file gtk_eb_html.c. References _darken(), _is_dark(), _lighten(), DBG_HTML, and eb_debug. Referenced by gtk_eb_html_add().
00441 {
00442 int bg_dark = _is_dark(r,g,b);
00443 int fg_dark = _is_dark(*fg_r, *fg_g, *fg_b);
00444
00445 eb_debug(DBG_HTML, "adjusting color %x %x %x", *fg_r, *fg_g, *fg_b);
00446
00447 if(bg_dark && fg_dark)
00448 {
00449 *fg_r = _lighten(*fg_r);
00450 *fg_g = _lighten(*fg_g);
00451 *fg_b = _lighten(*fg_b);
00452 }
00453 else if(!bg_dark && !fg_dark)
00454 {
00455 *fg_r = _darken(*fg_r);
00456 *fg_g = _darken(*fg_g);
00457 *fg_b = _darken(*fg_b);
00458 }
00459 }
|
|
|
Definition at line 58 of file gtk_eb_html.c. References font_size. Referenced by _getfont().
|
|
|
Definition at line 421 of file gtk_eb_html.c. Referenced by _adjust_colors().
00422 {
00423 if(color > 0x80)
00424 {
00425 return color - 0x80;
00426 }
00427 return 0x00;
00428 }
|
|
||||||||||||||||
|
Definition at line 301 of file gtk_eb_html.c. Referenced by gtk_eb_html_add().
00302 {
00303 /*
00304 *if we start with a quote, we should end with a quote
00305 * other wise we end with a space
00306 */
00307
00308 if(*parm == '\"')
00309 {
00310 int cnt = 0;
00311 parm += 1;
00312
00313 for(cnt = 0; *parm && *parm != '\"' && cnt < buffer_size-1;
00314 parm++, cnt++)
00315 {
00316 buffer[cnt] = *parm;
00317 }
00318 buffer[cnt] = '\0';
00319 }
00320 else
00321 {
00322 int cnt = 0;
00323
00324 for(cnt = 0; *parm && !isspace(*parm) && *parm != '>' && cnt < buffer_size-1;
00325 parm++, cnt++)
00326 {
00327 buffer[cnt] = *parm;
00328 }
00329 buffer[cnt] = '\0';
00330 }
00331 }
|
|
|
Definition at line 343 of file gtk_eb_html.c. References _font_stack::font_name, _font_stack::font_ptsize, font_size, and _font_stack::font_size. Referenced by gtk_eb_html_add().
00344 {
00345 font_stack * fs = g_new0(font_stack, 1);
00346
00347 fs->font_size = 3;
00348 fs->font_ptsize = font_size + 5;
00349
00350 strcpy(fs->font_name, "helvetica");
00351 return fs;
00352 }
|
|
|
Definition at line 375 of file gtk_eb_html.c. References _font_stack::back, _font_stack::fore, and _font_stack::next. Referenced by gtk_eb_html_add().
|
|
|
Definition at line 354 of file gtk_eb_html.c. References _font_stack::back, _font_stack::fore, and _font_stack::next. Referenced by gtk_eb_html_add().
00355 {
00356 font_stack * fs2 = g_new0(font_stack, 1);
00357 memcpy(fs2, fs, sizeof(font_stack));
00358 fs2->next = fs;
00359
00360 if(fs2->fore)
00361 {
00362 fs2->fore = g_new0(GdkColor, 1);
00363 memcpy(fs2->fore, fs->fore, sizeof(GdkColor));
00364 }
00365
00366 if(fs2->back)
00367 {
00368 fs2->back = g_new0(GdkColor, 1);
00369 memcpy(fs2->back, fs->back, sizeof(GdkColor));
00370 }
00371
00372 return fs2;
00373 }
|
|
||||||||||||
|
Definition at line 290 of file gtk_eb_html.c. Referenced by gtk_eb_html_add().
00291 {
00292 GdkColor * color;
00293
00294 color = (GdkColor *)g_new0(GdkColor, 1);
00295 gdk_color_parse(name, color);
00296 gdk_color_alloc(map, color);
00297
00298 return color;
00299 }
|
|
||||||||||||||||||||||||
|
Definition at line 128 of file gtk_eb_html.c. References _adjust_font_metrics(), cache_init, DBG_HTML, eb_debug, font_cache, and font_size. Referenced by gtk_eb_html_add().
00129 {
00130 gchar font_name[1024] = "-*-";
00131 GdkFont * my_font;
00132
00133 if(!cache_init)
00134 {
00135 g_datalist_init(&font_cache);
00136 cache_init = TRUE;
00137 }
00138
00139
00140
00141 if(strlen(font))
00142 {
00143 strcat( font_name, font );
00144 }
00145 else
00146 {
00147 strcat( font_name, "*" );
00148 }
00149 strcat( font_name, "-" );
00150
00151 if(bold)
00152 {
00153 strcat( font_name, "bold");
00154 }
00155 else
00156 {
00157 strcat( font_name, "medium");
00158 }
00159 strcat( font_name, "-" );
00160
00161 /*
00162 * here is the deal, some fonts have oblique but not italics
00163 * other fonts have italics but not oblique
00164 * so we are going to try both
00165 */
00166
00167 if( italic == 1 )
00168 {
00169 strcat( font_name, "i");
00170 }
00171 else if( italic == 2 )
00172 {
00173 strcat( font_name, "o" );
00174 }
00175 else
00176 {
00177 strcat( font_name, "r");
00178 }
00179 strcat( font_name, "-*-*-");
00180 {
00181 char buff[256];
00182 if(size != -1)
00183 {
00184 int size2 = 0;
00185 size2 = _adjust_font_metrics(size);
00186 sprintf(buff, "%d-*-*-*-*-*-*-*", size2);
00187 }
00188 else
00189 {
00190 sprintf(buff, "*-%d-*-*-*-*-*-*", (ptsize+font_size-6)*10);
00191 }
00192
00193 strcat( font_name, buff );
00194 }
00195
00196 eb_debug(DBG_HTML, "Wanting font %s\n", font_name);
00197
00198 g_strdown(font_name);
00199
00200 if(( my_font =
00201 g_datalist_id_get_data(&font_cache, g_quark_from_string(font_name)) ))
00202 {
00203 return my_font;
00204 }
00205 my_font = gdk_font_load(font_name);
00206 if( !my_font )
00207 {
00208 if( italic == 1 )
00209 {
00210 my_font = _getfont(font, bold, 2, size, ptsize );
00211 }
00212 else if(strcmp(font, "helvetica"))
00213 {
00214 my_font = _getfont("helvetica", bold, italic, size, ptsize );
00215 }
00216 else
00217 {
00218 my_font = _getfont("fixed", bold, italic, size, ptsize );
00219 }
00220 }
00221 g_datalist_id_set_data( &font_cache,
00222 g_quark_from_string(font_name),
00223 my_font );
00224 return my_font;
00225 }
|
|
||||||||||||||||
|
Definition at line 430 of file gtk_eb_html.c. Referenced by _adjust_colors().
00431 {
00432 if((r+g+b)<(0x80*3))
00433 {
00434 return 1;
00435 }
00436 return 0;
00437 }
|
|
|
Definition at line 412 of file gtk_eb_html.c. Referenced by _adjust_colors().
00413 {
00414 if(color < 0x80)
00415 {
00416 return color + 0x80;
00417 }
00418 return 0xFF;
00419 }
|
|
|
Definition at line 77 of file gtk_eb_html.c. Referenced by gtk_eb_html_add().
00078 {
00079 int i = 0;
00080 int j = 0;
00081 for(i = 0; input[i]; )
00082 {
00083 if(input[i] == '&')
00084 {
00085 if(!g_strncasecmp(input+i+1, "gt;", 3))
00086 {
00087 input[j++] = '>';
00088 i+=4;
00089 }
00090 else if(!g_strncasecmp(input+i+1, "lt;", 3))
00091 {
00092 input[j++] = '<';
00093 i+=4;
00094 }
00095 else if(!g_strncasecmp(input+i+1, "amp;", 4))
00096 {
00097 input[j++] = '&';
00098 i+=5;
00099 }
00100 else if(!g_strncasecmp(input+i+1, "#8212;", 6))
00101 {
00102 input[j++] = '-';
00103 input[j++] = '-';
00104 i+=7;
00105 }
00106 else if(!g_strncasecmp(input+i+1, "nbsp;", 5))
00107 {
00108 input[j++] = ' ';
00109 i+=6;
00110 }
00111 else
00112 {
00113 input[j++] = '&';
00114 i++;
00115 }
00116 }
00117 else
00118 {
00119 input[j++] = input[i++];
00120 }
00121 }
00122 input[j] = '\0';
00123 return input;
00124 }
|
|
||||||||||||||||||||||||
|
Definition at line 463 of file gtk_eb_html.c. References _adjust_colors(), _extract_parameter(), _font_stack_init(), _font_stack_pop(), _font_stack_push(), _getcolor(), _getfont(), _unescape_string(), _font_stack::back, DBG_HTML, eb_debug, ext_gtk_text_insert(), ext_gtk_text_insert_data_underlined(), ext_gtk_text_insert_divider(), ext_gtk_text_insert_pixmap(), _font_stack::font_name, _font_stack::font_ptsize, _font_stack::font_size, _font_stack::fore, handle_click(), smiley_struct::name, and smiley_struct::pixmap. Referenced by eb_chat_room_show_3rdperson(), eb_chat_room_show_message(), eb_chat_window_display_error(), eb_chat_window_display_remote_message(), eb_chat_window_do_timestamp(), eb_info_window_add_info(), eb_restore_last_conv(), send_file(), send_message(), and set_html_text().
00465 {
00466 gchar ** tokens;
00467 int i = 0;
00468 #ifndef HAVE_LIBXFT
00469 GdkFont * font = NULL;
00470 #else
00471 XftFont * font = NULL;
00472 #endif
00473 /*
00474 * these atributes don't go into the font stact because we should not
00475 * allow nesting of these attributes, but allow then to be changed
00476 * independently of the font stact
00477 */
00478
00479 int font_bold = 0;
00480 int font_italic = 0;
00481 char * url = NULL;
00482
00483 int first = 0;
00484
00485
00486
00487 /*
00488 * the ignore variable is used so we can ignore any header that may
00489 * be on the html
00490 */
00491
00492 int ignore = 0;
00493
00494 font_stack * fs = _font_stack_init();
00495
00496 fs->fore = g_new0(GdkColor, 1);
00497 memcpy(fs->fore, >K_WIDGET (widget)->style->fg[0],
00498 sizeof(GdkColor));
00499
00500 //#ifdef HAVE_LIBXFT
00501 font = _getfont(fs->font_name, font_bold, font_italic,
00502 fs->font_size, fs->font_ptsize);
00503 //#endif
00504
00505
00506 /*
00507 * Since the first thing in a split list may or may not be starting with a
00508 * < we need to keep track of that manually
00509 */
00510
00511 if(*text != '<')
00512 {
00513 first = 1;
00514 }
00515
00516 /*
00517 * a nice heuristic to decide if we should be proper with
00518 * our html and ignore the \n
00519 * or deal with our not-so-fortunate human typers
00520 * that don't do proper html
00521 */
00522
00523 if(strstr(text, "<br>") || strstr(text, "<BR>"))
00524 {
00525 char * c = text;
00526 while((c = strstr(c, "\n")) != 0)
00527 {
00528 *c = ' ';
00529 }
00530 c = text;
00531 while((c = strstr(c, "\r")) != 0)
00532 {
00533 *c = ' ';
00534 }
00535 }
00536 else if(strstr(text, "\r"))
00537 { char * c = text;
00538 if(strstr(text, "\n"))
00539 { /* drop the useless \r's */
00540 while((c = strstr(c,"\r")) != 0)
00541 {
00542 *c = ' ';
00543 }
00544 }
00545 else
00546 { /* convert the \r to readable \n */
00547 while((c = strstr(c,"\r")) != 0)
00548 {
00549 *c = '\n';
00550 }
00551 }
00552 }
00553
00554 tokens = g_strsplit(text, "<", 0);
00555
00556
00557 /*
00558 * if we started with a < then the first thing in the list
00559 * will be a 0 lenght string, so we want to skip that
00560 */
00561
00562 for( i = first?0:1; tokens[i]; i++ )
00563 {
00564
00565
00566 eb_debug(DBG_HTML, "Part %d: %s\n", i, tokens[i]);
00567
00568 if(!first && strstr(tokens[i], ">"))
00569 {
00570 char * copy = strdup(tokens[i]);
00571 #ifdef __MINGW32__
00572 gchar ** tags = g_strsplit(tokens[i], ">", 2);
00573 #else
00574 gchar ** tags = g_strsplit(tokens[i], ">", 1);
00575 #endif
00576 /*
00577 * Okay, we now know that tags[0] is an html tag because
00578 * there was a < before it and a > after it
00579 */
00580
00581 /*
00582 * first let's clean it up
00583 */
00584
00585 eb_debug(DBG_HTML, "\t Part a: %s\n", tags[0]);
00586 eb_debug(DBG_HTML, "\t Part b: %s\n", tags[1]);
00587 g_strstrip(tags[0]);
00588 g_strdown(tags[0]);
00589
00590 if(!strncmp(tags[0], "font", strlen("font")))
00591 {
00592 char * data = tags[0] + strlen("font");
00593 char * parm;
00594
00595 fs = _font_stack_push(fs);
00596
00597 if((parm = strstr(data, "face=")) != NULL)
00598 {
00599 parm += strlen("face=");
00600 _extract_parameter(parm, fs->font_name, 255);
00601 }
00602
00603 if((parm = strstr(data, "ptsize=")) != NULL)
00604 {
00605 char size[25];
00606 parm += strlen("ptsize=");
00607 _extract_parameter(parm, size, 25);
00608 fs->font_size = -1;
00609 fs->font_ptsize = atoi(size);
00610 eb_debug(DBG_HTML, "got a ptsize of %d\n", fs->font_ptsize);
00611 }
00612 else if((parm = strstr(data, "absz=")) != NULL)
00613 {
00614 char size[25];
00615 parm += strlen("absz=");
00616 _extract_parameter(parm, size, 25);
00617 fs->font_size = -1;
00618 fs->font_ptsize = atoi(size);
00619 eb_debug(DBG_HTML, "got a ptsize of %d\n", fs->font_ptsize);
00620 }
00621 else if((parm = strstr(data, "size=")) != NULL)
00622 {
00623 char size[25];
00624 parm += strlen("size=");
00625 _extract_parameter(parm, size, 25);
00626
00627 if(*size == '+')
00628 {
00629 fs->font_size += atoi(size+1);
00630 }
00631 else if(*size == '-')
00632 {
00633 fs->font_size -= atoi(size+1);
00634 }
00635 else
00636 {
00637 fs->font_size = atoi(size);
00638 }
00639 }
00640 if((parm = strstr(data, "color=")) != NULL)
00641 {
00642 char color[255];
00643 parm += strlen("color=");
00644 _extract_parameter(parm, color, 255);
00645 if(fs->fore)
00646 {
00647 g_free(fs->fore);
00648 fs->fore = NULL;
00649 }
00650 if(!ignore_fgcolor)
00651 {
00652 //fprintf(stderr, "color: %s\n", color);
00653
00654
00655 if(!fs->back)
00656 {
00657 GdkColor * bg = >K_WIDGET(widget)->style->base[GTK_STATE_NORMAL];
00658 int r, g, b;
00659 char color2[20];
00660 int fg_r, fg_g, fg_b;
00661 if(!sscanf(color, "#%02x%02x%02x", &fg_r, &fg_g, &fg_b))
00662 {
00663 GdkColor *tmpColor = _getcolor(gdk_window_get_colormap(GTK_WIDGET(widget)->window), color);
00664 fg_r = (tmpColor->red >> 8)&0xFF;
00665 fg_g = (tmpColor->green >> 8)&0xFF;
00666 fg_b = (tmpColor->blue >> 8)&0xFF;
00667 g_free(tmpColor);
00668
00669 }
00670
00671
00672 r = (bg->red >> 8)&0xFF;
00673 g = (bg->green >> 8)&0xFF;
00674 b = (bg->blue >> 8)&0xFF;
00675
00676 _adjust_colors(&fg_r, &fg_g, &fg_b,
00677 r, g, b);
00678
00679 sprintf(color2, "#%02x%02x%02x",fg_r, fg_g,fg_b);
00680 //fprintf(stderr, "Result: %s\n", color2);
00681 fs->fore = _getcolor(gdk_window_get_colormap(GTK_WIDGET(widget)->window), color2);
00682 }
00683 else
00684 {
00685 fs->fore = _getcolor(gdk_window_get_colormap(GTK_WIDGET(widget)->window), color);
00686 }
00687 }
00688 else
00689 {
00690 if(!fs->back && !ignore_bgcolor)
00691 {
00692 fs->fore = g_new0(GdkColor, 1);
00693 memcpy(fs->fore, >K_WIDGET (widget)->style->fg[0],
00694 sizeof(GdkColor));
00695 }
00696 else
00697 {
00698 fs->fore = _getcolor(gdk_window_get_colormap(GTK_WIDGET(widget)->window), "black");
00699 }
00700 }
00701
00702 }
00703
00704 if(!ignore_font)
00705 {
00706 font = _getfont(fs->font_name, font_bold, font_italic,
00707 fs->font_size, fs->font_ptsize);
00708 }
00709 else
00710 {
00711 #ifndef HAVE_LIBXFT
00712 font = NULL;
00713 #endif
00714 }
00715 }
00716 else if(!strncmp(tags[0], "img ", strlen("img ")))
00717 {
00718 char * parm;
00719 if((parm = strstr(copy, "src=")) != NULL
00720 ||(parm = strstr(copy, "SRC=")) != NULL)
00721 {
00722 char tmp_url[1024];
00723 GdkPixmap *icon;
00724 GdkBitmap *mask;
00725 parm += strlen("src=");
00726
00727 _extract_parameter(parm,
00728 tmp_url, 1024);
00729
00730 if(!strcmp(tmp_url, "aol_icon.gif"))
00731 {
00732 icon = gdk_pixmap_create_from_xpm_d(GTK_WIDGET(widget)->window, &mask, NULL, aol_icon_xpm);
00733 ext_gtk_text_insert_pixmap(widget, font, fs->fore, fs->back,
00734 icon, mask, "aol_icon", 0);
00735
00736 }
00737 else if(!strcmp(tmp_url, "free_icon.gif"))
00738 {
00739 icon = gdk_pixmap_create_from_xpm_d(GTK_WIDGET(widget)->window, &mask, NULL, free_icon_xpm);
00740 ext_gtk_text_insert_pixmap(widget, font, fs->fore, fs->back,
00741 icon, mask, "free_icon", 0);
00742
00743 }
00744 else if(!strcmp(tmp_url, "dt_icon.gif"))
00745 {
00746 icon = gdk_pixmap_create_from_xpm_d(GTK_WIDGET(widget)->window, &mask, NULL, dt_icon_xpm);
00747 ext_gtk_text_insert_pixmap(widget, font, fs->fore, fs->back,
00748 icon, mask, "dt_icon", 0);
00749
00750 }
00751 else if(!strcmp(tmp_url, "admin_icon.gif"))
00752 {
00753 icon = gdk_pixmap_create_from_xpm_d(GTK_WIDGET(widget)->window, &mask, NULL, admin_icon_xpm);
00754 ext_gtk_text_insert_pixmap(widget, font, fs->fore, fs->back,
00755 icon, mask, "admin_icon", 0);
00756
00757 }
00758 }
00759 }
00760 else if(!strncmp(tags[0], "smiley ", strlen("smiley ")))
00761 {
00762 char * parm;
00763 if((parm = strstr(copy, "name=")) != NULL
00764 ||(parm = strstr(copy, "NAME=")) != NULL)
00765 {
00766 char tmp_sname[64];
00767 GdkPixmap *icon;
00768 GdkBitmap *mask;
00769 GList * slist=smileys;
00770 smiley * smile;
00771
00772 parm += strlen("name=");
00773 // here
00774 _extract_parameter(parm, tmp_sname, 64);
00775
00776 while(slist!=NULL)
00777 {
00778 smile=(smiley *)slist->data;
00779 if(!strcmp(smile->name, tmp_sname))
00780 {
00781 icon = gdk_pixmap_create_from_xpm_d(GTK_WIDGET(widget)->window, &mask, NULL, smile->pixmap);
00782 ext_gtk_text_insert_pixmap(widget, font, fs->fore, fs->back,
00783 icon, mask, "smiley", strlen("smiley"));
00784 break;
00785 }
00786 slist=slist->next;
00787 }
00788 if(slist==NULL)
00789 {
00790 if((parm = strstr(copy, "alt=")) != NULL
00791 || (parm = strstr(copy, "ALT=")) != NULL)
00792 {
00793 parm += strlen("alt=");
00794 _extract_parameter(parm, tmp_sname, 64);
00795 ext_gtk_text_insert(widget, font, fs->fore, fs->back,
00796 tmp_sname, strlen(tmp_sname));
00797 }
00798 else
00799 {
00800 icon =gdk_pixmap_create_from_xpm_d(GTK_WIDGET(widget)->window, &mask, NULL, no_such_smiley_xpm);
00801 ext_gtk_text_insert_pixmap(widget, font, fs->fore, fs->back,
00802 icon, mask, "smiley", strlen("smiley"));
00803 }
00804 }
00805 }
00806 }
00807 else if(!strncmp(tags[0], "a ", strlen("a ")))
00808 {
00809 /* UNUSED char * data = tags[0] + strlen("a "); */
00810 char * parm;
00811
00812 fs = _font_stack_push(fs);
00813
00814 if((parm = strstr(copy, "href=")) != NULL
00815 ||(parm = strstr(copy, "HREF=")) != NULL
00816 )
00817 {
00818 char tmp_url[1024];
00819 int r=0, g=0, b=0xFF;
00820 GdkColor * bg = >K_WIDGET(widget)->style->base[GTK_STATE_NORMAL];
00821 char color[20];
00822 int bg_r, bg_g, bg_b;
00823
00824
00825 bg_r = (bg->red >> 8)&0xFF;
00826 bg_g = (bg->green >> 8)&0xFF;
00827 bg_b = (bg->blue >> 8)&0xFF;
00828
00829 _adjust_colors(&r, &g, &b, bg_r, bg_g, bg_b);
00830 sprintf(color, "#%02x%02x%02x", r, g, b);
00831 fs->fore = _getcolor(gdk_window_get_colormap(GTK_WIDGET(widget)->window), color);
00832
00833 parm += strlen("href=");
00834
00835 _extract_parameter(parm,
00836 tmp_url, 1024);
00837 if(url)
00838 {
00839 g_free(url);
00840 }
00841 url = strdup(tmp_url);
00842
00843
00844 }
00845 }
00846 else if(!strcmp(tags[0], "/a"))
00847 {
00848 fs = _font_stack_pop(fs);
00849 if(url)
00850 {
00851 g_free(url);
00852 }
00853 url = NULL;
00854
00855 if(!fs)
00856 {
00857 fs = _font_stack_init();
00858 fs->fore = g_new0(GdkColor, 1);
00859 memcpy(fs->fore, >K_WIDGET (widget)->style->fg[0],
00860 sizeof(GdkColor));
00861 }
00862 if(!ignore_font)
00863 {
00864 font = _getfont(fs->font_name, font_bold, font_italic,
00865 fs->font_size, fs->font_ptsize);
00866 }
00867 else
00868 {
00869 #ifndef HAVE_LIBXFT
00870 font = NULL;
00871 #endif
00872 }
00873 }
00874 else if(!strcmp(tags[0], "b"))
00875 {
00876 font_bold = 1;
00877 if(!ignore_font)
00878 {
00879 font = _getfont(fs->font_name, font_bold, font_italic,
00880 fs->font_size, fs->font_ptsize);
00881 }
00882 else
00883 {
00884 #ifndef HAVE_LIBXFT
00885 font = NULL;
00886 #endif
00887 }
00888
00889 }
00890 else if(!strcmp(tags[0], "u"))
00891 {
00892 eb_debug(DBG_HTML, "Underline tag found\n");
00893 if(!url)
00894 {
00895 url = strdup("");
00896 }
00897 else
00898 {
00899 eb_debug(DBG_HTML, "Underline tag ignored\n");
00900 }
00901 }
00902 else if(!strcmp(tags[0], "/u"))
00903 {
00904 /*
00905 * the widget stores a copy, so we must free
00906 * the original
00907 */
00908 if(url)
00909 {
00910 g_free(url);
00911 url = NULL;
00912 }
00913 }
00914 else if(!strcmp(tags[0], "/b"))
00915 {
00916 font_bold = 0;
00917 if(!ignore_font)
00918 {
00919 font = _getfont(fs->font_name, font_bold, font_italic,
00920 fs->font_size, fs->font_ptsize);
00921 }
00922 else
00923 {
00924 #ifndef HAVE_LIBXFT
00925 font = NULL;
00926 #endif
00927 }
00928 }
00929 else if(!strcmp(tags[0], "i"))
00930 {
00931 font_italic = 1;
00932 if(!ignore_font)
00933 {
00934 font = _getfont(fs->font_name, font_bold, font_italic,
00935 fs->font_size, fs->font_ptsize);
00936 }
00937 else
00938 {
00939 #ifndef HAVE_LIBXFT
00940 font = NULL;
00941 #endif
00942 }
00943 }
00944 else if(!strcmp(tags[0], "/i"))
00945 {
00946 font_italic = 0;
00947 if(!ignore_font)
00948 {
00949 font = _getfont(fs->font_name, font_bold, font_italic,
00950 fs->font_size, fs->font_ptsize);
00951 }
00952 else
00953 {
00954 #ifndef HAVE_LIBXFT
00955 font = NULL;
00956 #endif
00957 }
00958 }
00959 else if(!strcmp(tags[0], "br"))
00960 {
00961 if(url)
00962 {
00963 ext_gtk_text_insert_data_underlined(widget, font, fs->fore, fs->back,
00964 url, strlen(url)+1, handle_click, "\n", strlen("\n"));
00965 }
00966 else
00967 {
00968 ext_gtk_text_insert(widget, font, fs->fore, fs->back,
00969 "\n", strlen("\n"));
00970 }
00971 }
00972 else if(!strcmp(tags[0], "html")
00973 | !strcmp(tags[0], "/html")
00974 | !strcmp(tags[0], "/p")
00975 | !strcmp(tags[0], "p")
00976 | !strcmp(tags[0], "title")
00977 | !strcmp(tags[0], "/title")
00978 | !strcmp(tags[0], "pre")
00979 | !strcmp(tags[0], "/pre")
00980 | !strncmp(tags[0], "img", strlen("img")))
00981 {
00982 }
00983 else if(!strcmp(tags[0], "hr")
00984 || !strncmp(tags[0], "hr ", strlen("hr ")))
00985 {
00986 ext_gtk_text_insert(widget, font, fs->fore, fs->back,
00987 "\n", strlen("\n"));
00988 ext_gtk_text_insert_divider(widget, font, fs->fore, fs->back,
00989 " \n", strlen(" \n"));
00990
00991
00992 }
00993 else if(!strcmp(tags[0], "/font")
00994 || !strcmp(tags[0], "/body"))
00995 {
00996 fs = _font_stack_pop(fs);
00997
00998
00999 /*
01000 * we don't want to pop off the very first element in the stack
01001 * because that is the defaults, if we are in a positon of trying
01002 * that means the user tried doing one too many </font>'s
01003 * heh
01004 */
01005
01006 if(!fs)
01007 {
01008 fs = _font_stack_init();
01009 fs->fore = g_new0(GdkColor, 1);
01010 memcpy(fs->fore, >K_WIDGET (widget)->style->fg[0],
01011 sizeof(GdkColor));
01012 }
01013 if(!ignore_font)
01014 {
01015 font = _getfont(fs->font_name, font_bold, font_italic,
01016 fs->font_size, fs->font_ptsize);
01017 }
01018 else
01019 {
01020 #ifndef HAVE_LIBXFT
01021 font = NULL;
01022 #endif
01023 }
01024 }
01025 else if(!strncmp(tags[0], "head", strlen("head")))
01026 {
01027 /*
01028 * we want to ignore the header of an html doc
01029 */
01030
01031 ignore = 1;
01032 }
01033 else if(!strncmp(tags[0], "body", strlen("body")))
01034 {
01035 char * data = tags[0] + strlen("body");
01036 char * parm;
01037
01038 ignore = 0;
01039
01040
01041 fs = _font_stack_push(fs);
01042
01043 if((parm = strstr(data, "bgcolor=")) != NULL)
01044 {
01045 char color[255];
01046 parm += strlen("bgcolor=");
01047 _extract_parameter(parm, color, 255);
01048 if(fs->back)
01049 {
01050 g_free(fs->back);
01051 }
01052 if(!ignore_bgcolor)
01053 {
01054 fs->back = _getcolor(gdk_window_get_colormap(GTK_WIDGET(widget)->window), color);
01055 //fs->fore = _getcolor(gdk_window_get_colormap(GTK_WIDGET(widget)->window), "black");
01056 }
01057 else
01058 {
01059 fs->back = NULL;
01060 }
01061 }
01062 }
01063 else
01064 {
01065 _unescape_string(copy);
01066 if(url)
01067 {
01068 ext_gtk_text_insert_data_underlined(widget, font, fs->fore, fs->back,
01069 url, strlen(url)+1, handle_click, "<", 1);
01070 ext_gtk_text_insert_data_underlined(widget, font, fs->fore, fs->back,
01071 url, strlen(url)+1, handle_click, copy, strlen(copy));
01072 }
01073 else
01074 {
01075 ext_gtk_text_insert(widget, font, fs->fore, fs->back,
01076 "<", 1);
01077 ext_gtk_text_insert(widget, font, fs->fore, fs->back,
01078 copy, strlen(copy));
01079 }
01080 g_strfreev(tags);
01081 free(copy);
01082 first = 0;
01083 continue;
01084
01085 }
01086
01087 if(tags[1] && !ignore)
01088 {
01089 _unescape_string(tags[1]);
01090
01091 if(url)
01092 {
01093 ext_gtk_text_insert_data_underlined(widget, font, fs->fore, fs->back,
01094 url, strlen(url)+1, handle_click, tags[1], strlen(tags[1]));
01095 eb_debug(DBG_HTML, "Underlined text inserted\n");
01096 }
01097 else
01098 {
01099 ext_gtk_text_insert(widget, font, fs->fore, fs->back,
01100 tags[1], strlen(tags[1]));
01101 }
01102 }
01103 g_strfreev(tags);
01104 free(copy);
01105 }
01106 else
01107 {
01108 /*
01109 * Otherwise then it is all just text
01110 */
01111
01112 /*
01113 * first we were not supposed to have gotten rid of that < ;P
01114 */
01115
01116 if(!ignore)
01117 {
01118 if(!first)
01119 {
01120 if(url)
01121 {
01122 ext_gtk_text_insert_data_underlined( widget, font, fs->fore,
01123 fs->back, url, strlen(url)+1, handle_click, "<", strlen("<") );
01124 }
01125 else
01126 {
01127 ext_gtk_text_insert( widget, font, fs->fore,
01128 fs->back, "<", strlen("<") );
01129 }
01130 }
01131
01132 _unescape_string(tokens[i]);
01133 if(url)
01134 {
01135 ext_gtk_text_insert_data_underlined(widget, font, fs->fore, fs->back,
01136 url, strlen(url)+1, handle_click, tokens[i], strlen(tokens[i]));
01137 }
01138 else
01139 {
01140 ext_gtk_text_insert(widget, font, fs->fore, fs->back,
01141 tokens[i], strlen(tokens[i]));
01142 }
01143 }
01144
01145 }
01146 first = 0;
01147 }
01148 /*
01149 * we got this quirk of loosing the < if it ends
01150 * with the <
01151 * this is the fix
01152 */
01153
01154 if(text[strlen(text)-1] == '<')
01155 {
01156 if(url)
01157 {
01158 ext_gtk_text_insert_data_underlined( widget, font, fs->fore,
01159 fs->back, url, strlen(url)+1, handle_click, "<", strlen("<") );
01160 }
01161 else
01162 {
01163 ext_gtk_text_insert( widget, font, fs->fore,
01164 fs->back, "<", strlen("<") );
01165 }
01166 }
01167
01168 g_strfreev(tokens);
01169
01170 while(fs)
01171 {
01172 fs = _font_stack_pop(fs);
01173 }
01174 }
|
|
|
Definition at line 400 of file gtk_eb_html.c. References EXT_GTK_TEXT, ext_gtk_text_set_editable(), ext_gtk_text_set_line_wrap(), ext_gtk_text_set_word_wrap(), and handle_click(). Referenced by create_html_widget(), eb_chat_window_new(), eb_info_window_new(), and eb_join_chat_room().
00401 {
00402 gtk_signal_connect_after(GTK_OBJECT(widget), "button_press_event",
00403 GTK_SIGNAL_FUNC(handle_click), NULL);
00404 ext_gtk_text_set_editable(EXT_GTK_TEXT(widget), FALSE);
00405 ext_gtk_text_set_line_wrap(EXT_GTK_TEXT(widget), TRUE);
00406 ext_gtk_text_set_word_wrap(EXT_GTK_TEXT(widget), TRUE);
00407
00408
00409
00410 }
|
|
||||||||||||
|
Definition at line 388 of file gtk_eb_html.c. References open_url_nw(). Referenced by gtk_eb_html_add(), and gtk_eb_html_init().
00389 {
00390 if(data && strlen(data) > 1 && strcmp(data, "\n"))
00391 {
00392 #ifdef __MINGW32__
00393 open_url_nw(widget, data);
00394 #else
00395 open_url_nw(NULL, data);
00396 #endif
00397 }
00398 }
|
|
|
Definition at line 48 of file gtk_eb_html.c. Referenced by _getfont(). |
|
|
Definition at line 47 of file gtk_eb_html.c. Referenced by _getfont(). |
|
|
Definition at line 50 of file gtk_eb_html.c. Referenced by _adjust_font_metrics(), _font_stack_init(), _getfont(), build_chat_prefs(), cancel_chat_prefs(), eb_read_prefs(), and write_chat_prefs(). |