1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * Insensitive pixmap building code by Eckehard Berns from GNOME Stock
5 * Copyright (C) 1997, 1998 Free Software Foundation
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
25 * file for a list of people on the GTK+ Team. See the ChangeLog
26 * files for a list of changes. These files are distributed with
27 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 #include "gtkcontainer.h"
31 #include "gtkpixmap.h"
34 static void gtk_pixmap_class_init (GtkPixmapClass *klass);
35 static void gtk_pixmap_init (GtkPixmap *pixmap);
36 static gint gtk_pixmap_expose (GtkWidget *widget,
37 GdkEventExpose *event);
38 static void gtk_pixmap_finalize (GObject *object);
39 static void build_insensitive_pixmap (GtkPixmap *gtkpixmap);
41 static GtkWidgetClass *parent_class;
44 gtk_pixmap_get_type (void)
46 static GtkType pixmap_type = 0;
50 static const GtkTypeInfo pixmap_info =
54 sizeof (GtkPixmapClass),
55 (GtkClassInitFunc) gtk_pixmap_class_init,
56 (GtkObjectInitFunc) gtk_pixmap_init,
57 /* reserved_1 */ NULL,
58 /* reserved_2 */ NULL,
59 (GtkClassInitFunc) NULL,
62 pixmap_type = gtk_type_unique (GTK_TYPE_MISC, &pixmap_info);
69 gtk_pixmap_class_init (GtkPixmapClass *class)
71 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
72 GtkObjectClass *object_class;
73 GtkWidgetClass *widget_class;
75 object_class = (GtkObjectClass*) class;
76 widget_class = (GtkWidgetClass*) class;
77 parent_class = gtk_type_class (gtk_widget_get_type ());
79 gobject_class->finalize = gtk_pixmap_finalize;
81 widget_class->expose_event = gtk_pixmap_expose;
85 gtk_pixmap_init (GtkPixmap *pixmap)
87 GTK_WIDGET_SET_FLAGS (pixmap, GTK_NO_WINDOW);
89 pixmap->pixmap = NULL;
94 gtk_pixmap_new (GdkPixmap *val,
99 g_return_val_if_fail (val != NULL, NULL);
101 pixmap = gtk_type_new (gtk_pixmap_get_type ());
103 pixmap->build_insensitive = TRUE;
104 gtk_pixmap_set (pixmap, val, mask);
106 return GTK_WIDGET (pixmap);
110 gtk_pixmap_finalize (GObject *object)
112 gtk_pixmap_set (GTK_PIXMAP (object), NULL, NULL);
114 G_OBJECT_CLASS (parent_class)->finalize (object);
118 gtk_pixmap_set (GtkPixmap *pixmap,
127 g_return_if_fail (pixmap != NULL);
128 g_return_if_fail (GTK_IS_PIXMAP (pixmap));
130 if (pixmap->pixmap != val)
132 oldwidth = GTK_WIDGET (pixmap)->requisition.width;
133 oldheight = GTK_WIDGET (pixmap)->requisition.height;
135 gdk_pixmap_unref (pixmap->pixmap);
136 if (pixmap->pixmap_insensitive)
137 gdk_pixmap_unref (pixmap->pixmap_insensitive);
138 pixmap->pixmap = val;
139 pixmap->pixmap_insensitive = NULL;
142 gdk_pixmap_ref (pixmap->pixmap);
143 gdk_window_get_size (pixmap->pixmap, &width, &height);
144 GTK_WIDGET (pixmap)->requisition.width =
145 width + GTK_MISC (pixmap)->xpad * 2;
146 GTK_WIDGET (pixmap)->requisition.height =
147 height + GTK_MISC (pixmap)->ypad * 2;
151 GTK_WIDGET (pixmap)->requisition.width = 0;
152 GTK_WIDGET (pixmap)->requisition.height = 0;
154 if (GTK_WIDGET_VISIBLE (pixmap))
156 if ((GTK_WIDGET (pixmap)->requisition.width != oldwidth) ||
157 (GTK_WIDGET (pixmap)->requisition.height != oldheight))
158 gtk_widget_queue_resize (GTK_WIDGET (pixmap));
160 gtk_widget_queue_clear (GTK_WIDGET (pixmap));
164 if (pixmap->mask != mask)
167 gdk_bitmap_unref (pixmap->mask);
170 gdk_bitmap_ref (pixmap->mask);
175 gtk_pixmap_get (GtkPixmap *pixmap,
179 g_return_if_fail (pixmap != NULL);
180 g_return_if_fail (GTK_IS_PIXMAP (pixmap));
183 *val = pixmap->pixmap;
185 *mask = pixmap->mask;
189 gtk_pixmap_expose (GtkWidget *widget,
190 GdkEventExpose *event)
196 g_return_val_if_fail (widget != NULL, FALSE);
197 g_return_val_if_fail (GTK_IS_PIXMAP (widget), FALSE);
198 g_return_val_if_fail (event != NULL, FALSE);
200 if (GTK_WIDGET_DRAWABLE (widget))
202 pixmap = GTK_PIXMAP (widget);
203 misc = GTK_MISC (widget);
205 x = (widget->allocation.x * (1.0 - misc->xalign) +
206 (widget->allocation.x + widget->allocation.width
207 - (widget->requisition.width - misc->xpad * 2)) *
209 y = (widget->allocation.y * (1.0 - misc->yalign) +
210 (widget->allocation.y + widget->allocation.height
211 - (widget->requisition.height - misc->ypad * 2)) *
216 gdk_gc_set_clip_mask (widget->style->black_gc, pixmap->mask);
217 gdk_gc_set_clip_origin (widget->style->black_gc, x, y);
220 if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE
221 && pixmap->build_insensitive)
223 if (!pixmap->pixmap_insensitive)
224 build_insensitive_pixmap (pixmap);
225 gdk_draw_pixmap (widget->window,
226 widget->style->black_gc,
227 pixmap->pixmap_insensitive,
232 gdk_draw_pixmap (widget->window,
233 widget->style->black_gc,
240 gdk_gc_set_clip_mask (widget->style->black_gc, NULL);
241 gdk_gc_set_clip_origin (widget->style->black_gc, 0, 0);
248 gtk_pixmap_set_build_insensitive (GtkPixmap *pixmap, guint build)
250 g_return_if_fail (pixmap != NULL);
251 g_return_if_fail (GTK_IS_PIXMAP (pixmap));
253 pixmap->build_insensitive = build;
255 if (GTK_WIDGET_VISIBLE (pixmap))
257 gtk_widget_queue_clear (GTK_WIDGET (pixmap));
262 build_insensitive_pixmap(GtkPixmap *gtkpixmap)
264 GdkPixmap *pixmap = gtkpixmap->pixmap;
265 GdkPixmap *insensitive;
270 gdk_window_get_size (pixmap, &w, &h);
272 pixbuf = gdk_pixbuf_get_from_drawable (NULL,
274 gtk_widget_get_colormap (GTK_WIDGET(gtkpixmap)),
279 stated = gdk_pixbuf_copy (pixbuf);
281 gdk_pixbuf_saturate_and_pixelate (pixbuf, stated,
284 g_object_unref (G_OBJECT (pixbuf));
287 insensitive = gdk_pixmap_new (GTK_WIDGET (gtkpixmap)->window, w, h, -1);
289 gdk_pixbuf_render_to_drawable (stated,
291 GTK_WIDGET (gtkpixmap)->style->white_gc,
295 GDK_RGB_DITHER_NORMAL,
298 gtkpixmap->pixmap_insensitive = insensitive;
300 g_object_unref (G_OBJECT (stated));