src/gtkblist.c

changeset 11892
88eba6864684
parent 11890
3126a9d03cbd
child 11894
86966cf2b2b4
equal deleted inserted replaced
11891:164ee732273d 11892:88eba6864684
1989 1989
1990 struct tooltip_data { 1990 struct tooltip_data {
1991 PangoLayout *layout; 1991 PangoLayout *layout;
1992 GdkPixbuf *status_icon; 1992 GdkPixbuf *status_icon;
1993 GdkPixbuf *avatar; 1993 GdkPixbuf *avatar;
1994 int avatar_width;
1995 int width;
1996 int height;
1994 }; 1997 };
1995 1998
1996 static struct tooltip_data * create_tip_for_node(GaimBlistNode *node) 1999 static struct tooltip_data * create_tip_for_node(GaimBlistNode *node)
1997 { 2000 {
1998 struct tooltip_data *td = g_new0(struct tooltip_data, 1); 2001 struct tooltip_data *td = g_new0(struct tooltip_data, 1);
2003 2006
2004 td->layout = gtk_widget_create_pango_layout(gtkblist->tipwindow, NULL); 2007 td->layout = gtk_widget_create_pango_layout(gtkblist->tipwindow, NULL);
2005 pango_layout_set_markup(td->layout, tooltip_text, strlen(tooltip_text)); 2008 pango_layout_set_markup(td->layout, tooltip_text, strlen(tooltip_text));
2006 pango_layout_set_wrap(td->layout, PANGO_WRAP_WORD); 2009 pango_layout_set_wrap(td->layout, PANGO_WRAP_WORD);
2007 pango_layout_set_width(td->layout, 300000); 2010 pango_layout_set_width(td->layout, 300000);
2011
2012 pango_layout_get_size (td->layout, &td->width, &td->height);
2013 td->width = PANGO_PIXELS(td->width) + 38 + 8;
2014 td->height = MAX(PANGO_PIXELS(td->height) + 8, 38);
2015
2016 if(td->avatar) {
2017 td->avatar_width = gdk_pixbuf_get_width(td->avatar);
2018 td->width += td->avatar_width + 8;
2019 td->height = MAX(td->height, gdk_pixbuf_get_height(td->avatar) + 8);
2020 }
2008 2021
2009 return td; 2022 return td;
2010 } 2023 }
2011 2024
2012 static void gaim_gtk_blist_paint_tip(GtkWidget *widget, GdkEventExpose *event, GaimBlistNode *node) 2025 static void gaim_gtk_blist_paint_tip(GtkWidget *widget, GdkEventExpose *event, GaimBlistNode *node)
2013 { 2026 {
2014 GtkStyle *style; 2027 GtkStyle *style;
2015 int current_height; 2028 int current_height, max_width;
2016 GList *l; 2029 GList *l;
2017 2030
2018 if(gtkblist->tooltipdata == NULL) 2031 if(gtkblist->tooltipdata == NULL)
2019 return; 2032 return;
2020 2033
2021 style = gtkblist->tipwindow->style; 2034 style = gtkblist->tipwindow->style;
2022 gtk_paint_flat_box(style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, 2035 gtk_paint_flat_box(style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT,
2023 NULL, gtkblist->tipwindow, "tooltip", 0, 0, -1, -1); 2036 NULL, gtkblist->tipwindow, "tooltip", 0, 0, -1, -1);
2037
2038 max_width = 0;
2039 for(l = gtkblist->tooltipdata; l; l = l->next)
2040 {
2041 struct tooltip_data *td = l->data;
2042 max_width = MAX(max_width, td->width);
2043 }
2024 2044
2025 current_height = 0; 2045 current_height = 0;
2026 for(l = gtkblist->tooltipdata; l; l = l->next) 2046 for(l = gtkblist->tooltipdata; l; l = l->next)
2027 { 2047 {
2028 struct tooltip_data *td = l->data; 2048 struct tooltip_data *td = l->data;
2029 int w, h;
2030 int layout_width, layout_height;
2031
2032 pango_layout_get_size (td->layout, &w, &h);
2033 layout_width = PANGO_PIXELS(w) + 8;
2034 layout_height = PANGO_PIXELS(h) + 8;
2035
2036
2037 2049
2038 #if GTK_CHECK_VERSION(2,2,0) 2050 #if GTK_CHECK_VERSION(2,2,0)
2039 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, td->status_icon, 2051 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, td->status_icon,
2040 0, 0, 4, current_height + 4, -1 , -1, GDK_RGB_DITHER_NONE, 0, 0); 2052 0, 0, 4, current_height + 4, -1 , -1, GDK_RGB_DITHER_NONE, 0, 0);
2041 if(td->avatar) 2053 if(td->avatar)
2042 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, 2054 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->tipwindow->window), NULL,
2043 td->avatar, 0, 0, layout_width + 38 + 4, current_height + 4, -1 , -1, GDK_RGB_DITHER_NONE, 0, 0); 2055 td->avatar, 0, 0, max_width - (td->avatar_width + 4), current_height + 4, -1 , -1, GDK_RGB_DITHER_NONE, 0, 0);
2044 #else 2056 #else
2045 gdk_pixbuf_render_to_drawable(td->status_icon, GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, 0, 0, 4, current_height + 4, -1, -1, GDK_RGB_DITHER_NONE, 0, 0); 2057 gdk_pixbuf_render_to_drawable(td->status_icon, GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, 0, 0, 4, current_height + 4, -1, -1, GDK_RGB_DITHER_NONE, 0, 0);
2046 if(td->avatar) 2058 if(td->avatar)
2047 gdk_pixbuf_render_to_drawable(td->avatar, 2059 gdk_pixbuf_render_to_drawable(td->avatar,
2048 GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, 0, 0, layout_width + 38 + 4, 2060 GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, 0, 0,
2061 max_width - (td->avatar_width + 4),
2049 current_height + 4, -1, -1, GDK_RGB_DITHER_NONE, 0, 0); 2062 current_height + 4, -1, -1, GDK_RGB_DITHER_NONE, 0, 0);
2050 #endif 2063 #endif
2051 2064
2052 gtk_paint_layout (style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, FALSE, 2065 gtk_paint_layout (style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, FALSE,
2053 NULL, gtkblist->tipwindow, "tooltip", 38 + 4, current_height + 4, td->layout); 2066 NULL, gtkblist->tipwindow, "tooltip", 38 + 4, current_height + 4, td->layout);
2054 2067
2055 current_height += MAX(MAX(layout_height, 38), (td->avatar ? gdk_pixbuf_get_height(td->avatar) : 0)); 2068 current_height += td->height;
2056 } 2069 }
2057 } 2070 }
2058 2071
2059 static void gaim_gtk_blist_tooltip_destroy() 2072 static void gaim_gtk_blist_tooltip_destroy()
2060 { 2073 {
2159 gtkblist->tipwindow = gtk_window_new(GTK_WINDOW_POPUP); 2172 gtkblist->tipwindow = gtk_window_new(GTK_WINDOW_POPUP);
2160 2173
2161 if(GAIM_BLIST_NODE_IS_CHAT(node) || GAIM_BLIST_NODE_IS_BUDDY(node)) { 2174 if(GAIM_BLIST_NODE_IS_CHAT(node) || GAIM_BLIST_NODE_IS_BUDDY(node)) {
2162 struct tooltip_data *td = create_tip_for_node(node); 2175 struct tooltip_data *td = create_tip_for_node(node);
2163 gtkblist->tooltipdata = g_list_append(gtkblist->tooltipdata, td); 2176 gtkblist->tooltipdata = g_list_append(gtkblist->tooltipdata, td);
2164 pango_layout_get_size (td->layout, &w, &h); 2177 w = td->width;
2165 w = PANGO_PIXELS(w) + 8 + 38; 2178 h = td->height;
2166 h = MAX(PANGO_PIXELS(h) + 8, 38);
2167 if(td->avatar) {
2168 w += gdk_pixbuf_get_width(td->avatar) + 8;
2169 h = MAX(h, gdk_pixbuf_get_width(td->avatar) + 8);
2170 }
2171 } else if(GAIM_BLIST_NODE_IS_CONTACT(node)) { 2179 } else if(GAIM_BLIST_NODE_IS_CONTACT(node)) {
2172 GaimBlistNode *child; 2180 GaimBlistNode *child;
2173 w = h = 0; 2181 w = h = 0;
2174 for(child = node->child; child; child = child->next) 2182 for(child = node->child; child; child = child->next)
2175 { 2183 {
2176 if(GAIM_BLIST_NODE_IS_BUDDY(child) && buddy_is_displayable((GaimBuddy*)child)) { 2184 if(GAIM_BLIST_NODE_IS_BUDDY(child) && buddy_is_displayable((GaimBuddy*)child)) {
2177 int thisw, thish;
2178 struct tooltip_data *td = create_tip_for_node(child); 2185 struct tooltip_data *td = create_tip_for_node(child);
2179 gtkblist->tooltipdata = g_list_append(gtkblist->tooltipdata, td); 2186 gtkblist->tooltipdata = g_list_append(gtkblist->tooltipdata, td);
2180 pango_layout_get_size (td->layout, &thisw, &thish); 2187 w = MAX(w, td->width);
2181 w = MAX(w, PANGO_PIXELS(thisw) + 8 + 38 + (td->avatar ? gdk_pixbuf_get_width(td->avatar) + 8 : 0)); 2188 h += td->height;
2182 h += MAX(MAX(PANGO_PIXELS(thish) + 8, 38), (td->avatar ? gdk_pixbuf_get_height(td->avatar) + 8 : 0));
2183 } 2189 }
2184 } 2190 }
2185 } else { 2191 } else {
2186 gtk_widget_destroy(gtkblist->tipwindow); 2192 gtk_widget_destroy(gtkblist->tipwindow);
2193 gtkblist->tipwindow = NULL;
2187 return FALSE; 2194 return FALSE;
2188 } 2195 }
2189 2196
2190 if (gtkblist->tooltipdata == NULL) { 2197 if (gtkblist->tooltipdata == NULL) {
2191 gtk_widget_destroy(gtkblist->tipwindow); 2198 gtk_widget_destroy(gtkblist->tipwindow);
2199 gtkblist->tipwindow = NULL;
2192 return FALSE; 2200 return FALSE;
2193 } 2201 }
2194 2202
2195 gtknode = node->ui_data; 2203 gtknode = node->ui_data;
2196 2204

mercurial