Mercurial > pidgin
comparison src/gtkimhtml.c @ 2994:60018f862a51
[gaim-migrate @ 3007]
Compiles without GdkPixbuf again.
Sorry about that :-[
-
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sat, 02 Mar 2002 19:40:54 +0000 |
parents | 7239a392486c |
children | 6fe330f1b951 |
comparison
equal
deleted
inserted
replaced
2993:7239a392486c | 2994:60018f862a51 |
---|---|
62 #include "pixmaps/smile8.xpm" | 62 #include "pixmaps/smile8.xpm" |
63 #include "pixmaps/think.xpm" | 63 #include "pixmaps/think.xpm" |
64 #include "pixmaps/tongue.xpm" | 64 #include "pixmaps/tongue.xpm" |
65 #include "pixmaps/wink.xpm" | 65 #include "pixmaps/wink.xpm" |
66 #include "pixmaps/yell.xpm" | 66 #include "pixmaps/yell.xpm" |
67 #include "pixmaps/broken.xpm" | |
67 | 68 |
68 #define MAX_FONT_SIZE 7 | 69 #define MAX_FONT_SIZE 7 |
69 | 70 |
70 #define POINT_SIZE(x) (_point_sizes [MIN ((x), MAX_FONT_SIZE) - 1]) | 71 #define POINT_SIZE(x) (_point_sizes [MIN ((x), MAX_FONT_SIZE) - 1]) |
71 static gint _point_sizes [] = { 80, 100, 120, 140, 200, 300, 400 }; | 72 static gint _point_sizes [] = { 80, 100, 120, 140, 200, 300, 400 }; |
252 | 253 |
253 gtk_smiley_tree_destroy (imhtml->smiley_data); | 254 gtk_smiley_tree_destroy (imhtml->smiley_data); |
254 imhtml->smiley_data = gtk_smiley_tree_new (); | 255 imhtml->smiley_data = gtk_smiley_tree_new (); |
255 } | 256 } |
256 | 257 |
257 #if USE_PIXBUF | |
258 struct im_image { | 258 struct im_image { |
259 gchar *filename; | 259 gchar *filename; |
260 | 260 |
261 gint len; | 261 gint len; |
262 gpointer data; | 262 gpointer data; |
263 GdkPixbuf *pb; | 263 |
264 | |
265 gint x,y; | 264 gint x,y; |
266 gint width,height; | 265 gint width,height; |
267 GtkIMHtml *imhtml; | 266 GtkIMHtml *imhtml; |
268 GtkIMHtmlBit *bit; | 267 GtkIMHtmlBit *bit; |
268 #if USE_PIXBUF | |
269 GdkPixbuf *pb; | |
270 #endif | |
269 }; | 271 }; |
270 #endif | |
271 | 272 |
272 struct _GtkIMHtmlBit { | 273 struct _GtkIMHtmlBit { |
273 gint type; | 274 gint type; |
274 | 275 |
275 gchar *text; | 276 gchar *text; |
276 #if USE_PIXBUF | |
277 struct im_image *img; | 277 struct im_image *img; |
278 #endif | |
279 GdkPixmap *pm; | 278 GdkPixmap *pm; |
280 GdkBitmap *bm; | 279 GdkBitmap *bm; |
281 | 280 |
282 GdkFont *font; | 281 GdkFont *font; |
283 GdkColor *fore; | 282 GdkColor *fore; |
821 | 820 |
822 if (!GTK_WIDGET_REALIZED (widget)) | 821 if (!GTK_WIDGET_REALIZED (widget)) |
823 return; | 822 return; |
824 | 823 |
825 imhtml = GTK_IMHTML (widget); | 824 imhtml = GTK_IMHTML (widget); |
825 if (imhtml->default_fg_color) | |
826 gdk_color_free(imhtml->default_fg_color); | |
827 if (imhtml->default_bg_color) | |
828 gdk_color_free(imhtml->default_bg_color); | |
829 if (imhtml->default_hl_color) | |
830 gdk_color_free(imhtml->default_hl_color); | |
831 if (imhtml->default_hlfg_color) | |
832 gdk_color_free(imhtml->default_hlfg_color); | |
833 imhtml->default_fg_color = gdk_color_copy (>K_WIDGET (imhtml)->style->fg [GTK_STATE_NORMAL]); | |
834 imhtml->default_bg_color = gdk_color_copy (>K_WIDGET (imhtml)->style->base [GTK_STATE_NORMAL]); | |
835 imhtml->default_hl_color = gdk_color_copy (>K_WIDGET (imhtml)->style->bg [GTK_STATE_SELECTED]); | |
836 imhtml->default_hlfg_color=gdk_color_copy (>K_WIDGET (imhtml)->style->fg [GTK_STATE_SELECTED]); | |
837 if (imhtml->default_font) | |
838 gdk_font_unref (imhtml->default_font); | |
839 imhtml->default_font = gdk_font_ref (GTK_IMHTML_GET_STYLE_FONT (widget->style)); | |
840 gdk_window_set_background (widget->window, &widget->style->base [GTK_STATE_NORMAL]); | |
841 gdk_window_set_background (GTK_LAYOUT (imhtml)->bin_window, | |
842 &widget->style->base [GTK_STATE_NORMAL]); | |
826 gtk_imhtml_draw_exposed (imhtml); | 843 gtk_imhtml_draw_exposed (imhtml); |
827 } | 844 } |
828 | 845 |
829 static gint | 846 static gint |
830 gtk_imhtml_expose_event (GtkWidget *widget, | 847 gtk_imhtml_expose_event (GtkWidget *widget, |
1589 struct imgsv { | 1606 struct imgsv { |
1590 GtkWidget *savedialog; | 1607 GtkWidget *savedialog; |
1591 struct im_image *img; | 1608 struct im_image *img; |
1592 }; | 1609 }; |
1593 | 1610 |
1594 #if USE_PIXBUF | |
1595 static void | 1611 static void |
1596 save_img (GtkObject *object, | 1612 save_img (GtkObject *object, |
1597 gpointer data) | 1613 gpointer data) |
1598 { | 1614 { |
1599 struct imgsv *is = data; | 1615 struct imgsv *is = data; |
1635 "clicked", GTK_SIGNAL_FUNC (save_img), is); | 1651 "clicked", GTK_SIGNAL_FUNC (save_img), is); |
1636 gtk_widget_show (savedialog); | 1652 gtk_widget_show (savedialog); |
1637 | 1653 |
1638 | 1654 |
1639 } | 1655 } |
1640 #endif | |
1641 | 1656 |
1642 | 1657 |
1643 static void | 1658 static void |
1644 menu_open_url (GtkObject *object, | 1659 menu_open_url (GtkObject *object, |
1645 gpointer data) | 1660 gpointer data) |
2083 if (!useregenc) { | 2098 if (!useregenc) { |
2084 newvals [RGSTRY] = "*"; | 2099 newvals [RGSTRY] = "*"; |
2085 newvals [ENCDNG] = "*"; | 2100 newvals [ENCDNG] = "*"; |
2086 } | 2101 } |
2087 /* right. */ | 2102 /* right. */ |
2088 if (bold) | 2103 if (usebold && bold) |
2089 if (usebold) | 2104 newvals [WGHT] = "bold"; |
2090 newvals [WGHT] = "bold"; | 2105 else if (!usebold) |
2091 else | 2106 newvals [WGHT] = "*"; |
2092 newvals [WGHT] = "*"; | 2107 |
2093 if (italics) | 2108 if (italics) |
2094 /* We'll try "i" "o" to get italics and then just use "*" */ | 2109 /* We'll try "i" "o" to get italics and then just use "*" */ |
2095 newvals [SLANT] = italicstrings[italicsind]; | 2110 newvals [SLANT] = italicstrings[italicsind]; |
2096 if (fontsize) { | 2111 |
2097 if (usesize) { | 2112 if (usesize && fontsize) { |
2098 g_snprintf (fs, sizeof (fs), "%d", POINT_SIZE (fontsize)); | 2113 g_snprintf (fs, sizeof (fs), "%d", POINT_SIZE (fontsize)); |
2099 newvals [PTSZ] = fs; | 2114 newvals [PTSZ] = fs; |
2100 } else | 2115 } else if (!usesize) |
2101 newvals [PTSZ] = "*"; | 2116 newvals [PTSZ] = "*"; |
2102 newvals [PXLSZ] = "*"; | 2117 newvals [PXLSZ] = "*"; |
2103 } | 2118 |
2104 | 2119 |
2105 if (name) { | 2120 if (name) { |
2106 /* we got passed a name. it might be a list of names. */ | 2121 /* we got passed a name. it might be a list of names. */ |
2107 gchar **tmp_nms = g_strsplit (name, ",", -1); | 2122 gchar **tmp_nms = g_strsplit (name, ",", -1); |
2108 for (j = 0; tmp_nms [j]; j++); | 2123 for (j = 0; tmp_nms [j]; j++); |
2144 /* For some reason, fontsets must end with a single * as an xlfd */ | 2159 /* For some reason, fontsets must end with a single * as an xlfd */ |
2145 gchar *garbage = tmp; | 2160 gchar *garbage = tmp; |
2146 tmp = g_strconcat(garbage, ",*", NULL); | 2161 tmp = g_strconcat(garbage, ",*", NULL); |
2147 ret_font = gdk_fontset_load (tmp); | 2162 ret_font = gdk_fontset_load (tmp); |
2148 } | 2163 } |
2149 | |
2150 /* If the font didn't load, we change some of the xlfds one by one | 2164 /* If the font didn't load, we change some of the xlfds one by one |
2151 * to get the closest we can. */ | 2165 * to get the closest we can. */ |
2152 if (!ret_font) { | 2166 if (!ret_font) { |
2153 if (!useregenc && | 2167 if (!useregenc && |
2154 (!italics || italicsind == 2) && | 2168 (!italics || italicsind == 2) && |
2155 (!bold || !usebold) && | 2169 !usebold && !usesize) { |
2156 (!fontsize || !usesize)) { | |
2157 useregenc = TRUE; | 2170 useregenc = TRUE; |
2158 usebold = TRUE; | 2171 usebold = TRUE; |
2159 italicsind = 0; | 2172 italicsind = 0; |
2160 usesize = TRUE; | 2173 usesize = TRUE; |
2161 if (names && !names[nameind++]) { | 2174 if (names && !names[nameind++]) { |
2163 break; | 2176 break; |
2164 } | 2177 } |
2165 } | 2178 } |
2166 if (useregenc) | 2179 if (useregenc) |
2167 useregenc = FALSE; | 2180 useregenc = FALSE; |
2168 else if (italics && italicsind != 2) { | 2181 else if (usesize) { |
2182 useregenc = TRUE; | |
2183 usesize = FALSE; | |
2184 } else if (italics && italicsind != 2) { | |
2169 useregenc = TRUE; | 2185 useregenc = TRUE; |
2170 italicsind++; | 2186 italicsind++; |
2171 } else if (bold && usebold) { | 2187 } else if (usebold) { |
2172 useregenc = TRUE; | 2188 useregenc = TRUE; |
2173 usebold = FALSE; | 2189 usebold = FALSE; |
2174 } else if (fontsize && usesize) | 2190 } |
2175 useregenc = TRUE; | |
2176 usesize = FALSE; | |
2177 } | 2191 } |
2178 g_strfreev (names); | 2192 g_strfreev (names); |
2179 names = NULL; | 2193 names = NULL; |
2180 g_free(tmp); | 2194 g_free(tmp); |
2181 tmp=NULL; | 2195 tmp=NULL; |
2182 } while (!ret_font); /* Loop with the new options */ | 2196 } while (!ret_font); /* Loop with the new options */ |
2183 | |
2184 return ret_font; | 2197 return ret_font; |
2185 } | 2198 } |
2186 | 2199 |
2187 static void | 2200 static void |
2188 gtk_imhtml_init (GtkIMHtml *imhtml) | 2201 gtk_imhtml_init (GtkIMHtml *imhtml) |
2267 { | 2280 { |
2268 GtkIMHtml *imhtml = gtk_type_new (GTK_TYPE_IMHTML); | 2281 GtkIMHtml *imhtml = gtk_type_new (GTK_TYPE_IMHTML); |
2269 | 2282 |
2270 gtk_imhtml_set_adjustments (imhtml, hadj, vadj); | 2283 gtk_imhtml_set_adjustments (imhtml, hadj, vadj); |
2271 | 2284 |
2272 #if USE_PIXBUF | |
2273 imhtml->im_images = NULL; | 2285 imhtml->im_images = NULL; |
2274 #endif | |
2275 | 2286 |
2276 imhtml->bits = NULL; | 2287 imhtml->bits = NULL; |
2277 imhtml->click = NULL; | 2288 imhtml->click = NULL; |
2278 | 2289 |
2279 imhtml->x = 0; | 2290 imhtml->x = 0; |
2427 if (uw->y + diff > imhtml->y) | 2438 if (uw->y + diff > imhtml->y) |
2428 uw->y += diff; | 2439 uw->y += diff; |
2429 ls = g_list_next (ls); | 2440 ls = g_list_next (ls); |
2430 } | 2441 } |
2431 | 2442 |
2432 #if USE_PIXBUF | |
2433 ls = imhtml->im_images; | 2443 ls = imhtml->im_images; |
2434 while(ls) { | 2444 while(ls) { |
2435 img = ls->data; | 2445 img = ls->data; |
2436 if (img->y + diff > imhtml->y) | 2446 if (img->y + diff > imhtml->y) |
2437 img->y += diff; | 2447 img->y += diff; |
2438 ls = g_list_next(ls); | 2448 ls = g_list_next(ls); |
2439 } | 2449 } |
2440 #endif | |
2441 | 2450 |
2442 imhtml->llheight = height; | 2451 imhtml->llheight = height; |
2443 if (ascent) | 2452 if (ascent) |
2444 imhtml->llascent = ascent; | 2453 imhtml->llascent = ascent; |
2445 else | 2454 else |
2504 li->width = width; | 2513 li->width = width; |
2505 li->height = imhtml->llheight; | 2514 li->height = imhtml->llheight; |
2506 li->ascent = 0; | 2515 li->ascent = 0; |
2507 li->bit = bit; | 2516 li->bit = bit; |
2508 | 2517 |
2509 #if USE_PIXBUF | 2518 |
2510 if (bit->url || bit->img) { | 2519 if (bit->url || bit->img) { |
2511 #else | |
2512 if (bit->url) { | |
2513 #endif | |
2514 uw = g_new0 (struct clickable, 1); | 2520 uw = g_new0 (struct clickable, 1); |
2515 uw->x = imhtml->x; | 2521 uw->x = imhtml->x; |
2516 uw->y = imhtml->y; | 2522 uw->y = imhtml->y; |
2517 uw->width = width; | 2523 uw->width = width; |
2518 uw->height = imhtml->llheight; | 2524 uw->height = imhtml->llheight; |
3337 | 3343 |
3338 if (!src) | 3344 if (!src) |
3339 break; | 3345 break; |
3340 | 3346 |
3341 if (!imhtml->img && id && datasize) { /* This is an embedded IM image */ | 3347 if (!imhtml->img && id && datasize) { /* This is an embedded IM image */ |
3342 #if USE_PIXBUF | |
3343 char *tmp, *imagedata, *e; | 3348 char *tmp, *imagedata, *e; |
3344 const gchar *alltext; | 3349 const gchar *alltext; |
3345 struct im_image *img; | 3350 struct im_image *img; |
3351 #if USE_PIXBUF | |
3346 GdkPixbufLoader *load; | 3352 GdkPixbufLoader *load; |
3347 GdkPixbuf *imagepb = NULL; | 3353 GdkPixbuf *imagepb = NULL; |
3348 | |
3349 #endif | 3354 #endif |
3350 NEW_BIT (NEW_TEXT_BIT); | 3355 NEW_BIT (NEW_TEXT_BIT); |
3351 #if USE_PIXBUF | |
3352 if (!id || !datasize) | 3356 if (!id || !datasize) |
3353 break; | 3357 break; |
3354 tmp = g_malloc(strlen("<DATA ID=\"\" SIZE=\"\">") + | 3358 tmp = g_malloc(strlen("<DATA ID=\"\" SIZE=\"\">") + |
3355 strlen(id) + strlen(datasize)); | 3359 strlen(id) + strlen(datasize)); |
3356 g_snprintf(tmp, strlen("<DATA ID=\"\" SIZE=\"\">") + | 3360 g_snprintf(tmp, strlen("<DATA ID=\"\" SIZE=\"\">") + |
3382 img->filename = g_strdup(src); | 3386 img->filename = g_strdup(src); |
3383 img->len = atoi(datasize); | 3387 img->len = atoi(datasize); |
3384 if (img->len) { | 3388 if (img->len) { |
3385 img->data = g_malloc(img->len); | 3389 img->data = g_malloc(img->len); |
3386 memcpy(img->data, imagedata, img->len); | 3390 memcpy(img->data, imagedata, img->len); |
3387 | 3391 #if USE_PIXBUF |
3388 load = gdk_pixbuf_loader_new(); | 3392 load = gdk_pixbuf_loader_new(); |
3389 if (!gdk_pixbuf_loader_write(load, imagedata, img->len)) | 3393 if (!gdk_pixbuf_loader_write(load, imagedata, img->len)) |
3390 g_print("IM Image corrupt or unreadable.\n"); | 3394 g_print("IM Image corrupt or unreadable.\n"); |
3391 else | 3395 else |
3392 imagepb = gdk_pixbuf_loader_get_pixbuf(load); | 3396 imagepb = gdk_pixbuf_loader_get_pixbuf(load); |
3393 img->pb = imagepb; | 3397 img->pb = imagepb; |
3398 #endif | |
3394 } | 3399 } |
3400 #if USE_PIXBUF | |
3395 if (imagepb) { | 3401 if (imagepb) { |
3396 bit = g_new0 (GtkIMHtmlBit, 1); | 3402 bit = g_new0 (GtkIMHtmlBit, 1); |
3397 bit->type = TYPE_IMG; | 3403 bit->type = TYPE_IMG; |
3398 bit->img = img; | 3404 bit->img = img; |
3399 if (url) | 3405 if (url) |
3401 | 3407 |
3402 NEW_BIT (bit); | 3408 NEW_BIT (bit); |
3403 } else { | 3409 } else { |
3404 g_free(img->filename); | 3410 g_free(img->filename); |
3405 g_free(img->data); | 3411 g_free(img->data); |
3406 gdk_pixbuf_unref(img->pb); | |
3407 } | 3412 } |
3413 #else | |
3414 bit = g_new0 (GtkIMHtmlBit, 1); | |
3415 bit->type = TYPE_IMG; | |
3416 bit->img = img; | |
3417 if (url) | |
3418 bit->url = g_strdup (url); | |
3419 if (!fonts || ((clr = ((FontDetail *) fonts->data)->back) == NULL)) | |
3420 clr = (bg != NULL) ? bg : imhtml->default_bg_color; | |
3421 | |
3422 bit->pm = gdk_pixmap_create_from_xpm_d (GTK_WIDGET (imhtml)->window, | |
3423 &bit->bm, clr, broken_xpm); | |
3424 NEW_BIT (bit); | |
3425 #endif | |
3408 g_free(imagedata); | 3426 g_free(imagedata); |
3409 g_free(e); | 3427 g_free(e); |
3410 g_free(id); | 3428 g_free(id); |
3411 g_free(datasize); | 3429 g_free(datasize); |
3412 | 3430 |
3413 #endif | |
3414 break; | 3431 break; |
3415 } | 3432 } |
3416 | 3433 |
3417 if (!imhtml->img || ((xpm = imhtml->img (src)) == NULL)) { | 3434 if (!imhtml->img || ((xpm = imhtml->img (src)) == NULL)) { |
3418 g_free (src); | 3435 g_free (src); |