static void efhd_set_widget_bg (GtkWidget *w, GtkHTML *html) { GtkStyle *style; GdkColor color; style = gtk_widget_get_style((GtkWidget *)html); if (style) { int state = GTK_WIDGET_STATE(html); gushort r, g, b; #define SCALE (238) /* choose a suitably darker or lighter colour */ r = style->base[state].red >> 8; g = style->base[state].green >> 8; b = style->base[state].blue >> 8; if (r+b+g > 128*3) { r = (r*SCALE) >> 8; g = (g*SCALE) >> 8; b = (b*SCALE) >> 8; } else { r = 128 - ((SCALE * r) >> 9); g = 128 - ((SCALE * g) >> 9); b = 128 - ((SCALE * b) >> 9); } color.red = r; color.green = g; color.blue = b; gtk_widget_modify_bg (w, state, &color); // printf ("code\n"); // printf ("r: %d g: %d b :%d\n", r, g, b); // printf ("shift r: %d g: %d b:%d \n", r<<16, g<<8, b); // printf ("code end \n"); #undef SCALE } } static gboolean efhd_attachment_image(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObject *pobject) { GtkWidget *box; EMFormatHTMLJob *job; struct _attach_puri *info; GdkPixbuf *pixbuf; GtkTargetEntry drag_types[] = { { NULL, 0, 0 }, { "text/uri-list", 0, 1 }, }; char *simple_type; info = (struct _attach_puri *)em_format_find_puri((EMFormat *)efh, pobject->classid); info->image = (GtkImage *)gtk_image_new(); pixbuf = em_icon_stream_get_image(pobject->classid, info->fit_width, info->fit_height); if (pixbuf) { gtk_image_set_from_pixbuf(info->image, pixbuf); g_object_unref(pixbuf); } else { job = em_format_html_job_new(efh, efhd_write_icon_job, pobject); job->stream = (CamelStream *)em_icon_stream_new((GtkImage *)info->image, pobject->classid, info->fit_width, info->fit_height, TRUE); em_format_html_job_queue(efh, job); } box = gtk_event_box_new(); gtk_container_add((GtkContainer *)box, (GtkWidget *)info->image); efhd_set_widget_bg (box, efh->html); gtk_widget_show_all(box); gtk_container_add((GtkContainer *)eb, box); g_signal_connect(eb, "size_allocate", G_CALLBACK(efhd_image_resized), info); simple_type = camel_content_type_simple(((CamelDataWrapper *)pobject->part)->mime_type); camel_strdown(simple_type); drag_types[0].target = simple_type; gtk_drag_source_set(box, GDK_BUTTON1_MASK, drag_types, sizeof(drag_types)/sizeof(drag_types[0]), GDK_ACTION_COPY); g_free(simple_type); g_signal_connect(box, "drag-data-get", G_CALLBACK(efhd_drag_data_get), pobject); g_signal_connect (box, "drag-data-delete", G_CALLBACK(efhd_drag_data_delete), pobject); g_signal_connect(box, "button_press_event", G_CALLBACK(efhd_image_popup), info); g_signal_connect(box, "enter-notify-event", G_CALLBACK(efhd_change_cursor), info); g_signal_connect(box, "popup_menu", G_CALLBACK(efhd_attachment_popup_menu), info); g_signal_connect(box, "button-press-event", G_CALLBACK(efhd_image_fit_width), info); return TRUE; }