1998-03-05 07:53:47 +03:00
|
|
|
/* Module for creating a shaped window with text (for desktop icons)
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998 the Free Software Foundation
|
|
|
|
*
|
|
|
|
* Author: Federico Mena <federico@nuclecu.unam.mx>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gnome.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "gdesktop.h"
|
1998-04-01 04:52:33 +04:00
|
|
|
#include "gcache.h"
|
1998-03-17 11:27:10 +03:00
|
|
|
#include <gdk/gdkx.h>
|
1998-04-14 23:08:15 +04:00
|
|
|
|
1998-03-05 07:53:47 +03:00
|
|
|
/* The spacing between the cute little icon and the text */
|
|
|
|
#define SPACING 2
|
|
|
|
|
1998-04-14 23:08:15 +04:00
|
|
|
int want_transparent_icons = 1;
|
|
|
|
int want_transparent_text = 0;
|
|
|
|
|
|
|
|
|
1998-03-05 07:53:47 +03:00
|
|
|
static void
|
|
|
|
set_window_text (GtkWidget *window, GdkImlibImage *im, char *text)
|
|
|
|
{
|
|
|
|
GdkPixmap *pixmap;
|
|
|
|
GdkPixmap *im_pixmap;
|
|
|
|
GdkBitmap *mask;
|
|
|
|
GdkBitmap *im_mask;
|
1998-05-20 23:57:32 +04:00
|
|
|
GnomeIconTextInfo *ti;
|
1998-03-05 07:53:47 +03:00
|
|
|
GdkColor color;
|
1998-04-14 23:08:15 +04:00
|
|
|
GdkGC *p_gc, *m_gc;
|
1998-03-05 07:53:47 +03:00
|
|
|
int width, height;
|
|
|
|
|
1998-05-20 23:57:32 +04:00
|
|
|
ti = gnome_icon_layout_text (window->style->font, text, " /.-_", SNAP_X, FALSE);
|
1998-03-05 07:53:47 +03:00
|
|
|
|
|
|
|
width = MAX (ti->width, im->rgb_width);
|
|
|
|
height = im->rgb_height + SPACING + ti->height;
|
|
|
|
|
1998-04-14 23:08:15 +04:00
|
|
|
/* Create pixmap, mask, and gc's */
|
1998-03-05 07:53:47 +03:00
|
|
|
|
|
|
|
pixmap = gdk_pixmap_new (window->window, width, height, gdk_imlib_get_visual ()->depth);
|
1998-04-14 23:08:15 +04:00
|
|
|
mask = gdk_pixmap_new (window->window, width, height, 1);
|
1998-03-05 07:53:47 +03:00
|
|
|
|
1998-04-14 23:08:15 +04:00
|
|
|
p_gc = gdk_gc_new (pixmap);
|
|
|
|
m_gc = gdk_gc_new (mask);
|
1998-03-05 07:53:47 +03:00
|
|
|
|
1998-04-14 23:08:15 +04:00
|
|
|
/* Fill mask with transparent */
|
1998-03-05 07:53:47 +03:00
|
|
|
|
1998-04-14 23:08:15 +04:00
|
|
|
color.pixel = 0;
|
|
|
|
gdk_gc_set_foreground (m_gc, &color);
|
|
|
|
gdk_draw_rectangle (mask,
|
|
|
|
m_gc,
|
|
|
|
TRUE,
|
|
|
|
0, 0,
|
|
|
|
width, height);
|
1998-03-05 07:53:47 +03:00
|
|
|
|
1998-04-14 23:08:15 +04:00
|
|
|
/* Icon */
|
1998-03-05 07:53:47 +03:00
|
|
|
|
1998-04-14 23:08:15 +04:00
|
|
|
im_pixmap = gdk_imlib_move_image (im);
|
|
|
|
im_mask = gdk_imlib_move_mask (im);
|
1998-03-05 07:53:47 +03:00
|
|
|
|
1998-05-10 02:39:54 +04:00
|
|
|
if (!want_transparent_icons || im_mask == NULL) {
|
1998-04-14 23:08:15 +04:00
|
|
|
/* black background */
|
|
|
|
|
|
|
|
gdk_color_black (gdk_imlib_get_colormap (), &color);
|
|
|
|
gdk_gc_set_foreground (p_gc, &color);
|
|
|
|
gdk_draw_rectangle (pixmap,
|
|
|
|
p_gc,
|
|
|
|
TRUE,
|
|
|
|
(width - im->rgb_width) / 2,
|
|
|
|
0,
|
|
|
|
im->rgb_width,
|
|
|
|
im->rgb_height);
|
|
|
|
|
|
|
|
/* opaque mask */
|
|
|
|
|
|
|
|
color.pixel = 1;
|
|
|
|
gdk_gc_set_foreground (m_gc, &color);
|
|
|
|
gdk_draw_rectangle (mask,
|
|
|
|
m_gc,
|
|
|
|
TRUE,
|
|
|
|
(width - im->rgb_width) / 2,
|
|
|
|
0,
|
|
|
|
im->rgb_width,
|
|
|
|
im->rgb_height);
|
|
|
|
} else if (im_mask)
|
|
|
|
gdk_draw_pixmap (mask,
|
|
|
|
m_gc,
|
|
|
|
im_mask,
|
|
|
|
0, 0,
|
|
|
|
(width - im->rgb_width) / 2,
|
|
|
|
0,
|
|
|
|
im->rgb_width,
|
|
|
|
im->rgb_height);
|
1998-03-05 07:53:47 +03:00
|
|
|
|
1998-04-14 23:08:15 +04:00
|
|
|
if (im_mask) {
|
|
|
|
gdk_gc_set_clip_mask (p_gc, im_mask);
|
|
|
|
gdk_gc_set_clip_origin (p_gc, (width - im->rgb_width) / 2, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_draw_pixmap (pixmap,
|
|
|
|
p_gc,
|
|
|
|
im_pixmap,
|
|
|
|
0, 0,
|
|
|
|
(width - im->rgb_width) / 2,
|
|
|
|
0,
|
|
|
|
im->rgb_width,
|
|
|
|
im->rgb_height);
|
1998-03-05 07:53:47 +03:00
|
|
|
|
|
|
|
if (im_mask) {
|
1998-04-14 23:08:15 +04:00
|
|
|
gdk_gc_set_clip_mask (p_gc, NULL);
|
1998-03-05 07:53:47 +03:00
|
|
|
gdk_imlib_free_bitmap (im_mask);
|
|
|
|
}
|
1998-04-14 23:08:15 +04:00
|
|
|
|
|
|
|
gdk_imlib_free_pixmap (im_pixmap);
|
1998-03-05 07:53:47 +03:00
|
|
|
|
1998-04-14 23:08:15 +04:00
|
|
|
/* Text */
|
|
|
|
|
|
|
|
if (!want_transparent_text) {
|
|
|
|
/* black background */
|
|
|
|
|
|
|
|
gdk_color_black (gdk_imlib_get_colormap (), &color);
|
|
|
|
gdk_gc_set_foreground (p_gc, &color);
|
|
|
|
gdk_draw_rectangle (pixmap,
|
|
|
|
p_gc,
|
|
|
|
TRUE,
|
|
|
|
(width - ti->width) / 2,
|
|
|
|
im->rgb_height + SPACING,
|
|
|
|
ti->width,
|
|
|
|
ti->height);
|
|
|
|
|
|
|
|
/* opaque mask */
|
|
|
|
|
|
|
|
color.pixel = 1;
|
|
|
|
gdk_gc_set_foreground (m_gc, &color);
|
|
|
|
gdk_draw_rectangle (mask,
|
|
|
|
m_gc,
|
|
|
|
TRUE,
|
|
|
|
(width - ti->width) / 2,
|
|
|
|
im->rgb_height + SPACING,
|
|
|
|
ti->width,
|
|
|
|
ti->height);
|
|
|
|
} else {
|
|
|
|
color.pixel = 1;
|
|
|
|
gdk_gc_set_foreground (m_gc, &color);
|
1998-05-19 02:48:48 +04:00
|
|
|
gnome_icon_paint_text (ti, mask, m_gc,
|
|
|
|
(width - ti->width) / 2,
|
1998-05-21 03:06:52 +04:00
|
|
|
im->rgb_height + SPACING,
|
|
|
|
GTK_JUSTIFY_CENTER);
|
1998-04-14 23:08:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gdk_color_white (gdk_imlib_get_colormap (), &color);
|
|
|
|
gdk_gc_set_foreground (p_gc, &color);
|
1998-05-19 02:48:48 +04:00
|
|
|
gnome_icon_paint_text (ti, pixmap, p_gc,
|
|
|
|
(width - ti->width) / 2,
|
1998-05-21 03:06:52 +04:00
|
|
|
im->rgb_height + SPACING,
|
|
|
|
GTK_JUSTIFY_CENTER);
|
1998-03-05 07:53:47 +03:00
|
|
|
|
1998-04-14 23:08:15 +04:00
|
|
|
/* Set contents of window */
|
1998-03-05 07:53:47 +03:00
|
|
|
|
|
|
|
gtk_widget_set_usize (window, width, height);
|
|
|
|
gdk_window_set_back_pixmap (window->window, pixmap, FALSE);
|
|
|
|
gdk_window_shape_combine_mask (window->window, mask, 0, 0);
|
|
|
|
|
1998-04-14 23:08:15 +04:00
|
|
|
gdk_gc_destroy (p_gc);
|
|
|
|
gdk_gc_destroy (m_gc);
|
|
|
|
|
1998-03-05 07:53:47 +03:00
|
|
|
gdk_pixmap_unref (pixmap);
|
|
|
|
gdk_pixmap_unref (mask);
|
|
|
|
|
1998-05-19 02:48:48 +04:00
|
|
|
gnome_icon_text_info_free (ti);
|
1998-03-05 07:53:47 +03:00
|
|
|
}
|
|
|
|
|
1998-05-13 20:31:16 +04:00
|
|
|
static void
|
|
|
|
lower_icon_window(GtkWidget *widget, GdkEventExpose *event)
|
|
|
|
{
|
|
|
|
gdk_window_lower(widget->window);
|
|
|
|
}
|
|
|
|
|
1998-03-05 07:53:47 +03:00
|
|
|
GtkWidget *
|
|
|
|
create_transparent_text_window (char *file, char *text, int extra_events)
|
|
|
|
{
|
|
|
|
GtkWidget *window;
|
|
|
|
GdkImlibImage *im;
|
1998-04-15 11:45:51 +04:00
|
|
|
GdkCursor *cursor;
|
1998-04-01 04:52:33 +04:00
|
|
|
|
1998-03-05 07:53:47 +03:00
|
|
|
if (!g_file_exists (file))
|
|
|
|
return NULL;
|
1998-04-01 04:52:33 +04:00
|
|
|
|
|
|
|
im = image_cache_load_image (file);
|
1998-03-05 07:53:47 +03:00
|
|
|
if (!im)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
gtk_widget_push_visual (gdk_imlib_get_visual ());
|
|
|
|
gtk_widget_push_colormap (gdk_imlib_get_colormap ());
|
|
|
|
|
|
|
|
window = gtk_window_new (GTK_WINDOW_POPUP);
|
|
|
|
gtk_widget_set_events (window, gtk_widget_get_events (window) | extra_events);
|
|
|
|
|
|
|
|
gtk_widget_pop_colormap ();
|
|
|
|
gtk_widget_pop_visual ();
|
|
|
|
|
|
|
|
gtk_widget_realize (window);
|
|
|
|
|
|
|
|
gdk_imlib_render (im, im->rgb_width, im->rgb_height);
|
|
|
|
|
|
|
|
set_window_text (window, im, text);
|
|
|
|
|
1998-04-15 11:45:51 +04:00
|
|
|
cursor = gdk_cursor_new (GDK_TOP_LEFT_ARROW);
|
1998-03-24 08:03:56 +03:00
|
|
|
gdk_window_set_cursor (window->window, cursor);
|
1998-04-15 11:45:51 +04:00
|
|
|
gdk_cursor_destroy (cursor);
|
1998-03-24 08:03:56 +03:00
|
|
|
|
1998-05-15 05:08:46 +04:00
|
|
|
#if 0
|
|
|
|
/* Do not enable this code */
|
1998-05-13 20:31:16 +04:00
|
|
|
/* We do this so the desktop icons appear to really be part of the
|
|
|
|
desktop */
|
|
|
|
|
1998-05-15 05:08:46 +04:00
|
|
|
/* This is wrong. If you have two icons, one on top of the other,
|
|
|
|
* guess what is the result.
|
|
|
|
*/
|
|
|
|
gtk_signal_connect(window, "expose_event", GTK_SIGNAL_FUNC(lower_icon_window), NULL);
|
|
|
|
#endif
|
1998-03-05 07:53:47 +03:00
|
|
|
return window;
|
|
|
|
}
|
1998-03-06 06:48:31 +03:00
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
make_transparent_window (char *file)
|
|
|
|
{
|
|
|
|
GdkImlibImage *im;
|
|
|
|
GtkWidget *window;
|
1998-03-17 11:27:10 +03:00
|
|
|
XSetWindowAttributes xwa;
|
1998-03-06 06:48:31 +03:00
|
|
|
|
|
|
|
if (!g_file_exists (file))
|
|
|
|
return NULL;
|
|
|
|
|
1998-04-01 04:52:33 +04:00
|
|
|
im = image_cache_load_image (file);
|
1998-03-06 06:48:31 +03:00
|
|
|
if (!im)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
gtk_widget_push_visual (gdk_imlib_get_visual ());
|
|
|
|
gtk_widget_push_colormap (gdk_imlib_get_colormap ());
|
|
|
|
|
|
|
|
window = gtk_window_new (GTK_WINDOW_POPUP);
|
|
|
|
gtk_widget_pop_colormap ();
|
|
|
|
gtk_widget_pop_visual ();
|
|
|
|
|
|
|
|
gtk_widget_realize (window);
|
1998-03-24 08:03:56 +03:00
|
|
|
|
1998-03-17 11:27:10 +03:00
|
|
|
xwa.save_under = True;
|
|
|
|
XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window->window),
|
|
|
|
GDK_WINDOW_XWINDOW (window->window),
|
|
|
|
CWSaveUnder, &xwa);
|
|
|
|
|
1998-03-06 06:48:31 +03:00
|
|
|
gtk_widget_set_usize (window, im->rgb_width, im->rgb_height);
|
|
|
|
|
1998-05-01 03:55:40 +04:00
|
|
|
|
|
|
|
/* All of the following 3 lines should not be required, only
|
|
|
|
* gdk_imlib_apply_image, but is is buggy.
|
|
|
|
*/
|
|
|
|
gdk_imlib_render (im, im->rgb_width, im->rgb_height);
|
|
|
|
gdk_window_set_back_pixmap (window->window, gdk_imlib_move_image (im), FALSE);
|
|
|
|
gdk_window_shape_combine_mask (window->window, gdk_imlib_move_mask (im), 0, 0);
|
|
|
|
|
1998-03-06 06:48:31 +03:00
|
|
|
return window;
|
|
|
|
}
|