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/.
33 #undef GTK_DISABLE_DEPRECATED
34 #define __GTK_PIXMAP_C__
36 #include "gtkcontainer.h"
37 #include "gtkpixmap.h"
43 static gint gtk_pixmap_expose (GtkWidget *widget,
44 GdkEventExpose *event);
45 static void gtk_pixmap_finalize (GObject *object);
46 static void build_insensitive_pixmap (GtkPixmap *gtkpixmap);
48 G_DEFINE_TYPE (GtkPixmap, gtk_pixmap, GTK_TYPE_MISC)
51 gtk_pixmap_class_init (GtkPixmapClass *class)
53 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
54 GtkWidgetClass *widget_class;
56 widget_class = (GtkWidgetClass*) class;
58 gobject_class->finalize = gtk_pixmap_finalize;
60 widget_class->expose_event = gtk_pixmap_expose;
64 gtk_pixmap_init (GtkPixmap *pixmap)
66 GTK_WIDGET_SET_FLAGS (pixmap, GTK_NO_WINDOW);
68 pixmap->pixmap = NULL;
74 * @mask: (allow-none):
77 gtk_pixmap_new (GdkPixmap *val,
82 g_return_val_if_fail (val != NULL, NULL);
84 pixmap = gtk_type_new (gtk_pixmap_get_type ());
86 pixmap->build_insensitive = TRUE;
87 gtk_pixmap_set (pixmap, val, mask);
89 return GTK_WIDGET (pixmap);
93 gtk_pixmap_finalize (GObject *object)
95 gtk_pixmap_set (GTK_PIXMAP (object), NULL, NULL);
97 G_OBJECT_CLASS (gtk_pixmap_parent_class)->finalize (object);
101 gtk_pixmap_set (GtkPixmap *pixmap,
110 g_return_if_fail (GTK_IS_PIXMAP (pixmap));
111 if(GDK_IS_DRAWABLE(val))
112 g_return_if_fail (gdk_colormap_get_visual (gtk_widget_get_colormap (GTK_WIDGET (pixmap)))->depth == gdk_drawable_get_depth (GDK_DRAWABLE (val)));
114 if (pixmap->pixmap != val)
116 oldwidth = GTK_WIDGET (pixmap)->requisition.width;
117 oldheight = GTK_WIDGET (pixmap)->requisition.height;
119 g_object_unref (pixmap->pixmap);
120 if (pixmap->pixmap_insensitive)
121 g_object_unref (pixmap->pixmap_insensitive);
122 pixmap->pixmap = val;
123 pixmap->pixmap_insensitive = NULL;
126 g_object_ref (pixmap->pixmap);
127 gdk_drawable_get_size (pixmap->pixmap, &width, &height);
128 GTK_WIDGET (pixmap)->requisition.width =
129 width + GTK_MISC (pixmap)->xpad * 2;
130 GTK_WIDGET (pixmap)->requisition.height =
131 height + GTK_MISC (pixmap)->ypad * 2;
135 GTK_WIDGET (pixmap)->requisition.width = 0;
136 GTK_WIDGET (pixmap)->requisition.height = 0;
138 if (GTK_WIDGET_VISIBLE (pixmap))
140 if ((GTK_WIDGET (pixmap)->requisition.width != oldwidth) ||
141 (GTK_WIDGET (pixmap)->requisition.height != oldheight))
142 gtk_widget_queue_resize (GTK_WIDGET (pixmap));
144 gtk_widget_queue_draw (GTK_WIDGET (pixmap));
148 if (pixmap->mask != mask)
151 g_object_unref (pixmap->mask);
154 g_object_ref (pixmap->mask);
159 gtk_pixmap_get (GtkPixmap *pixmap,
163 g_return_if_fail (GTK_IS_PIXMAP (pixmap));
166 *val = pixmap->pixmap;
168 *mask = pixmap->mask;
172 gtk_pixmap_expose (GtkWidget *widget,
173 GdkEventExpose *event)
180 g_return_val_if_fail (GTK_IS_PIXMAP (widget), FALSE);
181 g_return_val_if_fail (event != NULL, FALSE);
183 if (GTK_WIDGET_DRAWABLE (widget))
185 pixmap = GTK_PIXMAP (widget);
186 misc = GTK_MISC (widget);
188 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
189 xalign = misc->xalign;
191 xalign = 1.0 - misc->xalign;
193 x = floor (widget->allocation.x + misc->xpad
194 + ((widget->allocation.width - widget->requisition.width) * xalign));
195 y = floor (widget->allocation.y + misc->ypad
196 + ((widget->allocation.height - widget->requisition.height) * misc->yalign));
200 gdk_gc_set_clip_mask (widget->style->black_gc, pixmap->mask);
201 gdk_gc_set_clip_origin (widget->style->black_gc, x, y);
204 if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE
205 && pixmap->build_insensitive)
207 if (!pixmap->pixmap_insensitive)
208 build_insensitive_pixmap (pixmap);
209 gdk_draw_drawable (widget->window,
210 widget->style->black_gc,
211 pixmap->pixmap_insensitive,
216 gdk_draw_drawable (widget->window,
217 widget->style->black_gc,
224 gdk_gc_set_clip_mask (widget->style->black_gc, NULL);
225 gdk_gc_set_clip_origin (widget->style->black_gc, 0, 0);
232 gtk_pixmap_set_build_insensitive (GtkPixmap *pixmap, gboolean build)
234 g_return_if_fail (GTK_IS_PIXMAP (pixmap));
236 pixmap->build_insensitive = build;
238 if (GTK_WIDGET_VISIBLE (pixmap))
240 gtk_widget_queue_draw (GTK_WIDGET (pixmap));
245 build_insensitive_pixmap (GtkPixmap *gtkpixmap)
247 GdkPixmap *pixmap = gtkpixmap->pixmap;
248 GdkPixmap *insensitive;
253 gdk_drawable_get_size (pixmap, &w, &h);
255 pixbuf = gdk_pixbuf_get_from_drawable (NULL,
257 gtk_widget_get_colormap (GTK_WIDGET (gtkpixmap)),
262 stated = gdk_pixbuf_copy (pixbuf);
264 gdk_pixbuf_saturate_and_pixelate (pixbuf, stated,
267 g_object_unref (pixbuf);
270 insensitive = gdk_pixmap_new (GTK_WIDGET (gtkpixmap)->window, w, h, -1);
272 gdk_draw_pixbuf (insensitive,
273 GTK_WIDGET (gtkpixmap)->style->white_gc,
278 GDK_RGB_DITHER_NORMAL,
281 gtkpixmap->pixmap_insensitive = insensitive;
283 g_object_unref (stated);
286 #include "gtkaliasdef.c"