Mercurial > pidgin.yaz
comparison src/gtkimhtml.c @ 8526:2f81f6478bae
[gaim-migrate @ 9265]
Daniel Atallah made it so tooltips shouldn't crash now.
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Tue, 30 Mar 2004 15:34:09 +0000 |
parents | f8ab826e11ad |
children | e0f659e4323e |
comparison
equal
deleted
inserted
replaced
8525:d8dfab355d2c | 8526:2f81f6478bae |
---|---|
22 */ | 22 */ |
23 | 23 |
24 #ifdef HAVE_CONFIG_H | 24 #ifdef HAVE_CONFIG_H |
25 #include <config.h> | 25 #include <config.h> |
26 #endif | 26 #endif |
27 #include "debug.h" | |
27 #include "util.h" | 28 #include "util.h" |
28 #include "gtkimhtml.h" | 29 #include "gtkimhtml.h" |
29 #include "gtksourceiter.h" | 30 #include "gtksourceiter.h" |
30 #include <gtk/gtk.h> | 31 #include <gtk/gtk.h> |
31 #include <glib/gerror.h> | 32 #include <glib/gerror.h> |
209 | 210 |
210 static gint | 211 static gint |
211 gtk_imhtml_tip (gpointer data) | 212 gtk_imhtml_tip (gpointer data) |
212 { | 213 { |
213 GtkIMHtml *imhtml = data; | 214 GtkIMHtml *imhtml = data; |
214 PangoFontMetrics *font; | 215 PangoFontMetrics *font_metrics; |
215 PangoLayout *layout; | 216 PangoLayout *layout; |
217 PangoFont *font; | |
216 | 218 |
217 gint gap, x, y, h, w, scr_w, baseline_skip; | 219 gint gap, x, y, h, w, scr_w, baseline_skip; |
218 | 220 |
219 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); | 221 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); |
220 | 222 |
236 g_signal_connect_swapped (G_OBJECT (imhtml->tip_window), "expose_event", | 238 g_signal_connect_swapped (G_OBJECT (imhtml->tip_window), "expose_event", |
237 G_CALLBACK (gtk_imhtml_tip_paint), imhtml); | 239 G_CALLBACK (gtk_imhtml_tip_paint), imhtml); |
238 | 240 |
239 gtk_widget_ensure_style (imhtml->tip_window); | 241 gtk_widget_ensure_style (imhtml->tip_window); |
240 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); | 242 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); |
241 font = pango_font_get_metrics(pango_context_load_font(pango_layout_get_context(layout), | 243 font = pango_context_load_font(pango_layout_get_context(layout), |
242 imhtml->tip_window->style->font_desc), | 244 imhtml->tip_window->style->font_desc); |
243 NULL); | 245 |
246 if (font == NULL) { | |
247 char *tmp = pango_font_description_to_string( | |
248 imhtml->tip_window->style->font_desc); | |
249 | |
250 gaim_debug(GAIM_DEBUG_ERROR, "gtk_imhtml_tip", | |
251 "pango_context_load_font() couldn't load font: '%s'\n", | |
252 tmp); | |
253 g_free(tmp); | |
254 | |
255 return FALSE; | |
256 | |
257 } | |
258 | |
259 font_metrics = pango_font_get_metrics(font, NULL); | |
244 | 260 |
245 | 261 |
246 pango_layout_get_pixel_size(layout, &scr_w, NULL); | 262 pango_layout_get_pixel_size(layout, &scr_w, NULL); |
247 gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font) + | 263 gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font_metrics) + |
248 pango_font_metrics_get_descent(font))/ 4); | 264 pango_font_metrics_get_descent(font_metrics))/ 4); |
249 | 265 |
250 if (gap < 2) | 266 if (gap < 2) |
251 gap = 2; | 267 gap = 2; |
252 baseline_skip = PANGO_PIXELS(pango_font_metrics_get_ascent(font) + | 268 baseline_skip = PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) + |
253 pango_font_metrics_get_descent(font)); | 269 pango_font_metrics_get_descent(font_metrics)); |
254 w = 8 + scr_w; | 270 w = 8 + scr_w; |
255 h = 8 + baseline_skip; | 271 h = 8 + baseline_skip; |
256 | 272 |
257 gdk_window_get_pointer (NULL, &x, &y, NULL); | 273 gdk_window_get_pointer (NULL, &x, &y, NULL); |
258 if (GTK_WIDGET_NO_WINDOW (GTK_WIDGET(imhtml))) | 274 if (GTK_WIDGET_NO_WINDOW (GTK_WIDGET(imhtml))) |
265 if ((x + w) > scr_w) | 281 if ((x + w) > scr_w) |
266 x -= (x + w) - scr_w; | 282 x -= (x + w) - scr_w; |
267 else if (x < 0) | 283 else if (x < 0) |
268 x = 0; | 284 x = 0; |
269 | 285 |
270 y = y + PANGO_PIXELS(pango_font_metrics_get_ascent(font) + | 286 y = y + PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) + |
271 pango_font_metrics_get_descent(font)); | 287 pango_font_metrics_get_descent(font_metrics)); |
272 | 288 |
273 gtk_widget_set_size_request (imhtml->tip_window, w, h); | 289 gtk_widget_set_size_request (imhtml->tip_window, w, h); |
274 gtk_widget_show (imhtml->tip_window); | 290 gtk_widget_show (imhtml->tip_window); |
275 gtk_window_move (GTK_WINDOW(imhtml->tip_window), x, y); | 291 gtk_window_move (GTK_WINDOW(imhtml->tip_window), x, y); |
276 | 292 |
277 pango_font_metrics_unref(font); | 293 pango_font_metrics_unref(font_metrics); |
278 g_object_unref(layout); | 294 g_object_unref(layout); |
279 | 295 |
280 return FALSE; | 296 return FALSE; |
281 } | 297 } |
282 | 298 |