Mercurial > pidgin.yaz
comparison src/gtkimhtml.c @ 3465:ec437d73b2ee
[gaim-migrate @ 3515]
This looks better.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Thu, 29 Aug 2002 01:43:23 +0000 |
parents | 66c7cca774f5 |
children | 3122c2eec3e8 |
comparison
equal
deleted
inserted
replaced
3464:01af3b8338a2 | 3465:ec437d73b2ee |
---|---|
41 #include <gdk-pixbuf/gdk-pixbuf-loader.h> | 41 #include <gdk-pixbuf/gdk-pixbuf-loader.h> |
42 #else | 42 #else |
43 #include "pixmaps/broken.xpm" | 43 #include "pixmaps/broken.xpm" |
44 #endif | 44 #endif |
45 | 45 |
46 #if GTK_CHECK_VERSION(1,3,0) | |
47 # define GTK_IMHTML_GET_STYLE_FONT(style) gtk_style_get_font (style) | |
48 #else | |
49 # define GTK_IMHTML_GET_STYLE_FONT(style) (style)->font | |
50 # define GTK_CLASS_TYPE(class) (class)->type | |
51 #endif | |
52 | |
53 #include "pixmaps/angel.xpm" | 46 #include "pixmaps/angel.xpm" |
54 #include "pixmaps/bigsmile.xpm" | 47 #include "pixmaps/bigsmile.xpm" |
55 #include "pixmaps/burp.xpm" | 48 #include "pixmaps/burp.xpm" |
56 #include "pixmaps/crossedlips.xpm" | 49 #include "pixmaps/crossedlips.xpm" |
57 #include "pixmaps/cry.xpm" | 50 #include "pixmaps/cry.xpm" |
88 #define TYPE_SMILEY 1 | 81 #define TYPE_SMILEY 1 |
89 #define TYPE_IMG 2 | 82 #define TYPE_IMG 2 |
90 #define TYPE_SEP 3 | 83 #define TYPE_SEP 3 |
91 #define TYPE_BR 4 | 84 #define TYPE_BR 4 |
92 #define TYPE_COMMENT 5 | 85 #define TYPE_COMMENT 5 |
86 | |
87 #define GTK_IMHTML_GET_STYLE_FONT(style) gtk_style_get_font (style) | |
93 | 88 |
94 #define DRAW_IMG(x) (((x)->type == TYPE_IMG) || (imhtml->smileys && ((x)->type == TYPE_SMILEY))) | 89 #define DRAW_IMG(x) (((x)->type == TYPE_IMG) || (imhtml->smileys && ((x)->type == TYPE_SMILEY))) |
95 | 90 |
96 typedef struct _GtkIMHtmlBit GtkIMHtmlBit; | 91 typedef struct _GtkIMHtmlBit GtkIMHtmlBit; |
97 typedef struct _FontDetail FontDetail; | 92 typedef struct _FontDetail FontDetail; |
1436 } | 1431 } |
1437 | 1432 |
1438 static gint | 1433 static gint |
1439 gtk_imhtml_tip_paint (GtkIMHtml *imhtml) | 1434 gtk_imhtml_tip_paint (GtkIMHtml *imhtml) |
1440 { | 1435 { |
1436 int x,y; | |
1441 GtkStyle *style; | 1437 GtkStyle *style; |
1442 GdkFont *font; | 1438 PangoLayout *layout; |
1443 gint y, baseline_skip, gap; | 1439 if (imhtml->tip_bit->url) |
1444 | 1440 layout = gtk_widget_create_pango_layout (imhtml->tip_window, imhtml->tip_bit->url); |
1441 else if (imhtml->tip_bit->img) | |
1442 layout = gtk_widget_create_pango_layout (imhtml->tip_window, imhtml->tip_bit->img->filename); | |
1443 else | |
1444 return FALSE; | |
1445 | |
1445 style = imhtml->tip_window->style; | 1446 style = imhtml->tip_window->style; |
1446 font = GTK_IMHTML_GET_STYLE_FONT (style); | 1447 pango_layout_get_size (layout, &x, &y); |
1447 | |
1448 gap = (font->ascent + font->descent) / 4; | |
1449 if (gap < 2) | |
1450 gap = 2; | |
1451 baseline_skip = font->ascent + font->descent + gap; | |
1452 | 1448 |
1453 if (!imhtml->tip_bit) | 1449 if (!imhtml->tip_bit) |
1454 return FALSE; | 1450 return FALSE; |
1455 | 1451 |
1456 gtk_paint_flat_box (style, imhtml->tip_window->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, | 1452 gtk_paint_flat_box (style, imhtml->tip_window->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, |
1457 NULL, imhtml->tip_window, "tooltip", 0, 0, -1, -1); | 1453 NULL, imhtml->tip_window, "tooltip", 0, 0, -1, -1); |
1458 | 1454 |
1459 y = font->ascent + 4; | 1455 gtk_paint_layout (style, imhtml->tip_window->window, GTK_STATE_NORMAL, TRUE, |
1460 if (imhtml->tip_bit->url) | 1456 NULL, imhtml->tip_window, "tooltip", 4, 4, layout); |
1461 gtk_paint_string (style, imhtml->tip_window->window, GTK_STATE_NORMAL, NULL, | 1457 |
1462 imhtml->tip_window, "tooltip", 4, y, imhtml->tip_bit->url); | 1458 g_object_unref (layout); |
1463 else if (imhtml->tip_bit->img) | |
1464 gtk_paint_string (style, imhtml->tip_window->window, GTK_STATE_NORMAL, NULL, | |
1465 imhtml->tip_window, "tooltip", 4, y, imhtml->tip_bit->img->filename); | |
1466 | |
1467 return FALSE; | 1459 return FALSE; |
1468 } | 1460 } |
1469 | 1461 |
1470 static gint | 1462 static gint |
1471 gtk_imhtml_tip (gpointer data) | 1463 gtk_imhtml_tip (gpointer data) |
1472 { | 1464 { |
1473 GtkIMHtml *imhtml = data; | 1465 GtkIMHtml *imhtml = data; |
1474 GtkWidget *widget = GTK_WIDGET (imhtml); | 1466 GtkWidget *widget = GTK_WIDGET (imhtml); |
1475 GtkStyle *style; | 1467 GtkStyle *style; |
1476 GdkFont *font; | 1468 PangoLayout *layout; |
1477 gint gap, x, y, w, h, scr_w, scr_h, baseline_skip; | 1469 gint x, y, w, h, scr_w, scr_h; |
1478 | 1470 |
1479 if (!imhtml->tip_bit || !GTK_WIDGET_DRAWABLE (widget)) { | 1471 if (!imhtml->tip_bit || !GTK_WIDGET_DRAWABLE (widget)) { |
1480 imhtml->tip_timer = 0; | 1472 imhtml->tip_timer = 0; |
1481 return FALSE; | 1473 return FALSE; |
1482 } | 1474 } |
1488 gtk_widget_set_app_paintable (imhtml->tip_window, TRUE); | 1480 gtk_widget_set_app_paintable (imhtml->tip_window, TRUE); |
1489 gtk_window_set_policy (GTK_WINDOW (imhtml->tip_window), FALSE, FALSE, TRUE); | 1481 gtk_window_set_policy (GTK_WINDOW (imhtml->tip_window), FALSE, FALSE, TRUE); |
1490 gtk_widget_set_name (imhtml->tip_window, "gtk-tooltips"); | 1482 gtk_widget_set_name (imhtml->tip_window, "gtk-tooltips"); |
1491 gtk_signal_connect_object (GTK_OBJECT (imhtml->tip_window), "expose_event", | 1483 gtk_signal_connect_object (GTK_OBJECT (imhtml->tip_window), "expose_event", |
1492 GTK_SIGNAL_FUNC (gtk_imhtml_tip_paint), GTK_OBJECT (imhtml)); | 1484 GTK_SIGNAL_FUNC (gtk_imhtml_tip_paint), GTK_OBJECT (imhtml)); |
1493 gtk_signal_connect_object (GTK_OBJECT (imhtml->tip_window), "draw", | |
1494 GTK_SIGNAL_FUNC (gtk_imhtml_tip_paint), GTK_OBJECT (imhtml)); | |
1495 | 1485 |
1496 gtk_widget_ensure_style (imhtml->tip_window); | 1486 gtk_widget_ensure_style (imhtml->tip_window); |
1497 style = imhtml->tip_window->style; | 1487 style = imhtml->tip_window->style; |
1498 font = GTK_IMHTML_GET_STYLE_FONT (style); | 1488 layout = gtk_widget_create_pango_layout(imhtml->tip_window, |
1489 imhtml->tip_bit->url ? imhtml->tip_bit->url : imhtml->tip_bit->img->filename); | |
1499 | 1490 |
1500 scr_w = gdk_screen_width (); | 1491 scr_w = gdk_screen_width (); |
1501 scr_h = gdk_screen_height (); | 1492 scr_h = gdk_screen_height (); |
1502 | 1493 |
1503 gap = (font->ascent + font->descent) / 4; | 1494 pango_layout_get_size(layout, &w, &h); |
1504 if (gap < 2) | 1495 |
1505 gap = 2; | 1496 w = PANGO_PIXELS(w) + 8; |
1506 baseline_skip = font->ascent + font->descent + gap; | 1497 h = PANGO_PIXELS(h) + 8; |
1507 | |
1508 w = 8 + gdk_string_width (font, imhtml->tip_bit->img ? imhtml->tip_bit->img->filename : | |
1509 imhtml->tip_bit->url); | |
1510 h = 8 - gap + baseline_skip; | |
1511 | 1498 |
1512 gdk_window_get_pointer (NULL, &x, &y, NULL); | 1499 gdk_window_get_pointer (NULL, &x, &y, NULL); |
1513 if (GTK_WIDGET_NO_WINDOW (widget)) | 1500 if (GTK_WIDGET_NO_WINDOW (widget)) |
1514 y += widget->allocation.y; | 1501 y += widget->allocation.y; |
1515 | 1502 |
1519 x -= (x + w) - scr_w; | 1506 x -= (x + w) - scr_w; |
1520 else if (x < 0) | 1507 else if (x < 0) |
1521 x = 0; | 1508 x = 0; |
1522 | 1509 |
1523 if ((y + h + + 4) > scr_h) | 1510 if ((y + h + + 4) > scr_h) |
1524 y = y - imhtml->tip_bit->font->ascent + imhtml->tip_bit->font->descent; | 1511 y = y - h; |
1525 else | 1512 else |
1526 if (imhtml->tip_bit->font) | 1513 y = y + h - 4; |
1527 y = y + imhtml->tip_bit->font->ascent + imhtml->tip_bit->font->descent; | 1514 |
1528 else | |
1529 y = y + font->ascent + font->descent; | |
1530 | |
1531 gtk_widget_set_usize (imhtml->tip_window, w, h); | 1515 gtk_widget_set_usize (imhtml->tip_window, w, h); |
1532 gtk_widget_set_uposition (imhtml->tip_window, x, y); | 1516 gtk_widget_set_uposition (imhtml->tip_window, x, y); |
1533 gtk_widget_show (imhtml->tip_window); | 1517 gtk_widget_show (imhtml->tip_window); |
1534 | 1518 |
1535 imhtml->tip_timer = 0; | 1519 imhtml->tip_timer = 0; |
1520 g_object_unref(layout); | |
1521 | |
1536 return FALSE; | 1522 return FALSE; |
1537 } | 1523 } |
1538 | 1524 |
1539 static gint | 1525 static gint |
1540 gtk_imhtml_motion_notify_event (GtkWidget *widget, | 1526 gtk_imhtml_motion_notify_event (GtkWidget *widget, |
1588 GList *click = imhtml->click; | 1574 GList *click = imhtml->click; |
1589 struct clickable *uw; | 1575 struct clickable *uw; |
1590 | 1576 |
1591 while (click) { | 1577 while (click) { |
1592 uw = (struct clickable *) click->data; | 1578 uw = (struct clickable *) click->data; |
1593 if ((x > uw->x) && (x < uw->x + uw->width) && | 1579 if ((uw->bit->url) && (x > uw->x) && (x < uw->x + uw->width) && |
1594 (y > uw->y) && (y < uw->y + uw->height) && | 1580 (y > uw->y) && (y < uw->y + uw->height) && |
1595 (uw->bit->url || uw->bit->img)) { | 1581 (uw->bit->url || uw->bit->img)) { |
1596 if (imhtml->tip_bit != uw->bit) { | 1582 if (imhtml->tip_bit != uw->bit) { |
1597 imhtml->tip_bit = uw->bit; | 1583 imhtml->tip_bit = uw->bit; |
1598 if (imhtml->tip_timer != 0) | 1584 if (imhtml->tip_timer != 0) |
2074 #define ENCDNG 14 | 2060 #define ENCDNG 14 |
2075 | 2061 |
2076 static const gchar* | 2062 static const gchar* |
2077 gtk_imhtml_get_font_name (GdkFont *font) | 2063 gtk_imhtml_get_font_name (GdkFont *font) |
2078 { | 2064 { |
2079 #if GTK_CHECK_VERSION(1,3,0) | |
2080 return gdk_x11_font_get_name(font); | 2065 return gdk_x11_font_get_name(font); |
2081 #else | |
2082 GdkFontPrivate *fontpriv = (GdkFontPrivate *) font; | |
2083 return fontpriv->names->data; | |
2084 #endif | |
2085 } | 2066 } |
2086 | 2067 |
2087 static GdkFont* | 2068 static GdkFont* |
2088 gtk_imhtml_font_load (GtkIMHtml *imhtml, | 2069 gtk_imhtml_font_load (GtkIMHtml *imhtml, |
2089 gchar *name, | 2070 gchar *name, |