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
35 #include "gtkcontainer.h"
36 #include "gtkpixmap.h"
39 #define GTK_DISABLE_DEPRECATED
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;
73 gtk_pixmap_new (GdkPixmap *val,
78 g_return_val_if_fail (val != NULL, NULL);
80 pixmap = gtk_type_new (gtk_pixmap_get_type ());
82 pixmap->build_insensitive = TRUE;
83 gtk_pixmap_set (pixmap, val, mask);
85 return GTK_WIDGET (pixmap);
89 gtk_pixmap_finalize (GObject *object)
91 gtk_pixmap_set (GTK_PIXMAP (object), NULL, NULL);
93 G_OBJECT_CLASS (gtk_pixmap_parent_class)->finalize (object);
97 gtk_pixmap_set (GtkPixmap *pixmap,
106 g_return_if_fail (GTK_IS_PIXMAP (pixmap));
107 if(GDK_IS_DRAWABLE(val))
108 g_return_if_fail (gdk_colormap_get_visual (gtk_widget_get_colormap (GTK_WIDGET (pixmap)))->depth == gdk_drawable_get_depth (GDK_DRAWABLE (val)));
110 if (pixmap->pixmap != val)
112 oldwidth = GTK_WIDGET (pixmap)->requisition.width;
113 oldheight = GTK_WIDGET (pixmap)->requisition.height;
115 gdk_pixmap_unref (pixmap->pixmap);
116 if (pixmap->pixmap_insensitive)
117 gdk_pixmap_unref (pixmap->pixmap_insensitive);
118 pixmap->pixmap = val;
119 pixmap->pixmap_insensitive = NULL;
122 gdk_pixmap_ref (pixmap->pixmap);
123 gdk_window_get_size (pixmap->pixmap, &width, &height);
124 GTK_WIDGET (pixmap)->requisition.width =
125 width + GTK_MISC (pixmap)->xpad * 2;
126 GTK_WIDGET (pixmap)->requisition.height =
127 height + GTK_MISC (pixmap)->ypad * 2;
131 GTK_WIDGET (pixmap)->requisition.width = 0;
132 GTK_WIDGET (pixmap)->requisition.height = 0;
134 if (GTK_WIDGET_VISIBLE (pixmap))
136 if ((GTK_WIDGET (pixmap)->requisition.width != oldwidth) ||
137 (GTK_WIDGET (pixmap)->requisition.height != oldheight))
138 gtk_widget_queue_resize (GTK_WIDGET (pixmap));
140 gtk_widget_queue_clear (GTK_WIDGET (pixmap));
144 if (pixmap->mask != mask)
147 gdk_bitmap_unref (pixmap->mask);
150 gdk_bitmap_ref (pixmap->mask);
155 gtk_pixmap_get (GtkPixmap *pixmap,
159 g_return_if_fail (GTK_IS_PIXMAP (pixmap));
162 *val = pixmap->pixmap;
164 *mask = pixmap->mask;
168 gtk_pixmap_expose (GtkWidget *widget,
169 GdkEventExpose *event)
176 g_return_val_if_fail (GTK_IS_PIXMAP (widget), FALSE);
177 g_return_val_if_fail (event != NULL, FALSE);
179 if (GTK_WIDGET_DRAWABLE (widget))
181 pixmap = GTK_PIXMAP (widget);
182 misc = GTK_MISC (widget);
184 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
185 xalign = misc->xalign;
187 xalign = 1.0 - misc->xalign;
189 x = floor (widget->allocation.x + misc->xpad
190 + ((widget->allocation.width - widget->requisition.width) * xalign));
191 y = floor (widget->allocation.y + misc->ypad
192 + ((widget->allocation.height - widget->requisition.height) * misc->yalign));
196 gdk_gc_set_clip_mask (widget->style->black_gc, pixmap->mask);
197 gdk_gc_set_clip_origin (widget->style->black_gc, x, y);
200 if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE
201 && pixmap->build_insensitive)
203 if (!pixmap->pixmap_insensitive)
204 build_insensitive_pixmap (pixmap);
205 gdk_draw_pixmap (widget->window,
206 widget->style->black_gc,
207 pixmap->pixmap_insensitive,
212 gdk_draw_pixmap (widget->window,
213 widget->style->black_gc,
220 gdk_gc_set_clip_mask (widget->style->black_gc, NULL);
221 gdk_gc_set_clip_origin (widget->style->black_gc, 0, 0);
228 gtk_pixmap_set_build_insensitive (GtkPixmap *pixmap, gboolean build)
230 g_return_if_fail (GTK_IS_PIXMAP (pixmap));
232 pixmap->build_insensitive = build;
234 if (GTK_WIDGET_VISIBLE (pixmap))
236 gtk_widget_queue_clear (GTK_WIDGET (pixmap));
241 build_insensitive_pixmap (GtkPixmap *gtkpixmap)
243 GdkPixmap *pixmap = gtkpixmap->pixmap;
244 GdkPixmap *insensitive;
249 gdk_window_get_size (pixmap, &w, &h);
251 pixbuf = gdk_pixbuf_get_from_drawable (NULL,
253 gtk_widget_get_colormap (GTK_WIDGET (gtkpixmap)),
258 stated = gdk_pixbuf_copy (pixbuf);
260 gdk_pixbuf_saturate_and_pixelate (pixbuf, stated,
263 g_object_unref (G_OBJECT (pixbuf));
266 insensitive = gdk_pixmap_new (GTK_WIDGET (gtkpixmap)->window, w, h, -1);
268 gdk_draw_pixbuf (insensitive,
269 GTK_WIDGET (gtkpixmap)->style->white_gc,
274 GDK_RGB_DITHER_NORMAL,
277 gtkpixmap->pixmap_insensitive = insensitive;
279 g_object_unref (G_OBJECT (stated));
282 #define __GTK_PIXMAP_C__
283 #include "gtkaliasdef.c"