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 #undef GDK_DISABLE_DEPRECATED
31 #undef GTK_DISABLE_DEPRECATED
34 #include "gtkcontainer.h"
35 #include "gtkpixmap.h"
38 static void gtk_pixmap_class_init (GtkPixmapClass *klass);
39 static void gtk_pixmap_init (GtkPixmap *pixmap);
40 static gint gtk_pixmap_expose (GtkWidget *widget,
41 GdkEventExpose *event);
42 static void gtk_pixmap_finalize (GObject *object);
43 static void build_insensitive_pixmap (GtkPixmap *gtkpixmap);
45 static GtkWidgetClass *parent_class;
48 gtk_pixmap_get_type (void)
50 static GtkType pixmap_type = 0;
54 static const GtkTypeInfo pixmap_info =
58 sizeof (GtkPixmapClass),
59 (GtkClassInitFunc) gtk_pixmap_class_init,
60 (GtkObjectInitFunc) gtk_pixmap_init,
61 /* reserved_1 */ NULL,
62 /* reserved_2 */ NULL,
63 (GtkClassInitFunc) NULL,
66 pixmap_type = gtk_type_unique (GTK_TYPE_MISC, &pixmap_info);
73 gtk_pixmap_class_init (GtkPixmapClass *class)
75 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
76 GtkObjectClass *object_class;
77 GtkWidgetClass *widget_class;
79 object_class = (GtkObjectClass*) class;
80 widget_class = (GtkWidgetClass*) class;
81 parent_class = gtk_type_class (gtk_misc_get_type ());
83 gobject_class->finalize = gtk_pixmap_finalize;
85 widget_class->expose_event = gtk_pixmap_expose;
89 gtk_pixmap_init (GtkPixmap *pixmap)
91 GTK_WIDGET_SET_FLAGS (pixmap, GTK_NO_WINDOW);
93 pixmap->pixmap = NULL;
98 gtk_pixmap_new (GdkPixmap *val,
103 g_return_val_if_fail (val != NULL, NULL);
105 pixmap = gtk_type_new (gtk_pixmap_get_type ());
107 pixmap->build_insensitive = TRUE;
108 gtk_pixmap_set (pixmap, val, mask);
110 return GTK_WIDGET (pixmap);
114 gtk_pixmap_finalize (GObject *object)
116 gtk_pixmap_set (GTK_PIXMAP (object), NULL, NULL);
118 G_OBJECT_CLASS (parent_class)->finalize (object);
122 gtk_pixmap_set (GtkPixmap *pixmap,
131 g_return_if_fail (GTK_IS_PIXMAP (pixmap));
133 if (pixmap->pixmap != val)
135 oldwidth = GTK_WIDGET (pixmap)->requisition.width;
136 oldheight = GTK_WIDGET (pixmap)->requisition.height;
138 gdk_pixmap_unref (pixmap->pixmap);
139 if (pixmap->pixmap_insensitive)
140 gdk_pixmap_unref (pixmap->pixmap_insensitive);
141 pixmap->pixmap = val;
142 pixmap->pixmap_insensitive = NULL;
145 gdk_pixmap_ref (pixmap->pixmap);
146 gdk_window_get_size (pixmap->pixmap, &width, &height);
147 GTK_WIDGET (pixmap)->requisition.width =
148 width + GTK_MISC (pixmap)->xpad * 2;
149 GTK_WIDGET (pixmap)->requisition.height =
150 height + GTK_MISC (pixmap)->ypad * 2;
154 GTK_WIDGET (pixmap)->requisition.width = 0;
155 GTK_WIDGET (pixmap)->requisition.height = 0;
157 if (GTK_WIDGET_VISIBLE (pixmap))
159 if ((GTK_WIDGET (pixmap)->requisition.width != oldwidth) ||
160 (GTK_WIDGET (pixmap)->requisition.height != oldheight))
161 gtk_widget_queue_resize (GTK_WIDGET (pixmap));
163 gtk_widget_queue_clear (GTK_WIDGET (pixmap));
167 if (pixmap->mask != mask)
170 gdk_bitmap_unref (pixmap->mask);
173 gdk_bitmap_ref (pixmap->mask);
178 gtk_pixmap_get (GtkPixmap *pixmap,
182 g_return_if_fail (GTK_IS_PIXMAP (pixmap));
185 *val = pixmap->pixmap;
187 *mask = pixmap->mask;
191 gtk_pixmap_expose (GtkWidget *widget,
192 GdkEventExpose *event)
199 g_return_val_if_fail (GTK_IS_PIXMAP (widget), FALSE);
200 g_return_val_if_fail (event != NULL, FALSE);
202 if (GTK_WIDGET_DRAWABLE (widget))
204 pixmap = GTK_PIXMAP (widget);
205 misc = GTK_MISC (widget);
207 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
208 xalign = misc->xalign;
210 xalign = 1.0 - misc->xalign;
212 x = floor (widget->allocation.x + misc->xpad
213 + ((widget->allocation.width - widget->requisition.width) * xalign)
215 y = floor (widget->allocation.y + misc->ypad
216 + ((widget->allocation.height - widget->requisition.height) * misc->yalign)
221 gdk_gc_set_clip_mask (widget->style->black_gc, pixmap->mask);
222 gdk_gc_set_clip_origin (widget->style->black_gc, x, y);
225 if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE
226 && pixmap->build_insensitive)
228 if (!pixmap->pixmap_insensitive)
229 build_insensitive_pixmap (pixmap);
230 gdk_draw_pixmap (widget->window,
231 widget->style->black_gc,
232 pixmap->pixmap_insensitive,
237 gdk_draw_pixmap (widget->window,
238 widget->style->black_gc,
245 gdk_gc_set_clip_mask (widget->style->black_gc, NULL);
246 gdk_gc_set_clip_origin (widget->style->black_gc, 0, 0);
253 gtk_pixmap_set_build_insensitive (GtkPixmap *pixmap, gboolean build)
255 g_return_if_fail (GTK_IS_PIXMAP (pixmap));
257 pixmap->build_insensitive = build;
259 if (GTK_WIDGET_VISIBLE (pixmap))
261 gtk_widget_queue_clear (GTK_WIDGET (pixmap));
266 build_insensitive_pixmap (GtkPixmap *gtkpixmap)
268 GdkPixmap *pixmap = gtkpixmap->pixmap;
269 GdkPixmap *insensitive;
274 gdk_window_get_size (pixmap, &w, &h);
276 pixbuf = gdk_pixbuf_get_from_drawable (NULL,
278 gtk_widget_get_colormap (GTK_WIDGET(gtkpixmap)),
283 stated = gdk_pixbuf_copy (pixbuf);
285 gdk_pixbuf_saturate_and_pixelate (pixbuf, stated,
288 g_object_unref (G_OBJECT (pixbuf));
291 insensitive = gdk_pixmap_new (GTK_WIDGET (gtkpixmap)->window, w, h, -1);
293 gdk_draw_pixbuf (insensitive,
294 GTK_WIDGET (gtkpixmap)->style->white_gc,
299 GDK_RGB_DITHER_NORMAL,
302 gtkpixmap->pixmap_insensitive = insensitive;
304 g_object_unref (G_OBJECT (stated));