1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
19 #include "gtkcontainer.h"
20 #include "gtkpixmap.h"
23 static void gtk_pixmap_class_init (GtkPixmapClass *klass);
24 static void gtk_pixmap_init (GtkPixmap *pixmap);
25 static gint gtk_pixmap_expose (GtkWidget *widget,
26 GdkEventExpose *event);
27 static void gtk_pixmap_finalize (GtkObject *object);
29 static GtkWidgetClass *parent_class;
32 gtk_pixmap_get_type (void)
34 static GtkType pixmap_type = 0;
38 GtkTypeInfo pixmap_info =
42 sizeof (GtkPixmapClass),
43 (GtkClassInitFunc) gtk_pixmap_class_init,
44 (GtkObjectInitFunc) gtk_pixmap_init,
45 /* reserved_1 */ NULL,
46 /* reserved_2 */ NULL,
47 (GtkClassInitFunc) NULL,
50 pixmap_type = gtk_type_unique (GTK_TYPE_MISC, &pixmap_info);
57 gtk_pixmap_class_init (GtkPixmapClass *class)
59 GtkObjectClass *object_class;
60 GtkWidgetClass *widget_class;
62 object_class = (GtkObjectClass*) class;
63 widget_class = (GtkWidgetClass*) class;
64 parent_class = gtk_type_class (gtk_widget_get_type ());
66 object_class->finalize = gtk_pixmap_finalize;
67 widget_class->expose_event = gtk_pixmap_expose;
71 gtk_pixmap_init (GtkPixmap *pixmap)
73 GTK_WIDGET_SET_FLAGS (pixmap, GTK_NO_WINDOW);
75 pixmap->pixmap = NULL;
80 gtk_pixmap_new (GdkPixmap *val,
85 g_return_val_if_fail (val != NULL, NULL);
87 pixmap = gtk_type_new (gtk_pixmap_get_type ());
89 gtk_pixmap_set (pixmap, val, mask);
91 return GTK_WIDGET (pixmap);
95 gtk_pixmap_finalize (GtkObject *object)
97 gtk_pixmap_set (GTK_PIXMAP (object), NULL, NULL);
98 (* GTK_OBJECT_CLASS (parent_class)->finalize) (object);
102 gtk_pixmap_set (GtkPixmap *pixmap,
111 g_return_if_fail (pixmap != NULL);
112 g_return_if_fail (GTK_IS_PIXMAP (pixmap));
114 if (pixmap->pixmap != val)
116 oldwidth = GTK_WIDGET (pixmap)->requisition.width;
117 oldheight = GTK_WIDGET (pixmap)->requisition.height;
119 gdk_pixmap_unref (pixmap->pixmap);
120 pixmap->pixmap = val;
123 gdk_pixmap_ref (pixmap->pixmap);
124 gdk_window_get_size (pixmap->pixmap, &width, &height);
125 GTK_WIDGET (pixmap)->requisition.width =
126 width + GTK_MISC (pixmap)->xpad * 2;
127 GTK_WIDGET (pixmap)->requisition.height =
128 height + GTK_MISC (pixmap)->ypad * 2;
132 GTK_WIDGET (pixmap)->requisition.width = 0;
133 GTK_WIDGET (pixmap)->requisition.height = 0;
135 if (GTK_WIDGET_VISIBLE (pixmap))
137 if ((GTK_WIDGET (pixmap)->requisition.width != oldwidth) ||
138 (GTK_WIDGET (pixmap)->requisition.height != oldheight))
139 gtk_widget_queue_resize (GTK_WIDGET (pixmap));
141 gtk_widget_queue_clear (GTK_WIDGET (pixmap));
145 if (pixmap->mask != mask)
148 gdk_bitmap_unref (pixmap->mask);
151 gdk_bitmap_ref (pixmap->mask);
156 gtk_pixmap_get (GtkPixmap *pixmap,
160 g_return_if_fail (pixmap != NULL);
161 g_return_if_fail (GTK_IS_PIXMAP (pixmap));
164 *val = pixmap->pixmap;
166 *mask = pixmap->mask;
171 gtk_pixmap_expose (GtkWidget *widget,
172 GdkEventExpose *event)
178 g_return_val_if_fail (widget != NULL, FALSE);
179 g_return_val_if_fail (GTK_IS_PIXMAP (widget), FALSE);
180 g_return_val_if_fail (event != NULL, FALSE);
182 if (GTK_WIDGET_DRAWABLE (widget))
184 pixmap = GTK_PIXMAP (widget);
185 misc = GTK_MISC (widget);
187 x = (widget->allocation.x * (1.0 - misc->xalign) +
188 (widget->allocation.x + widget->allocation.width
189 - (widget->requisition.width - misc->xpad * 2)) *
191 y = (widget->allocation.y * (1.0 - misc->yalign) +
192 (widget->allocation.y + widget->allocation.height
193 - (widget->requisition.height - misc->ypad * 2)) *
198 gdk_gc_set_clip_mask (widget->style->black_gc, pixmap->mask);
199 gdk_gc_set_clip_origin (widget->style->black_gc, x, y);
202 gdk_draw_pixmap (widget->window,
203 widget->style->black_gc,
209 gdk_gc_set_clip_mask (widget->style->black_gc, NULL);
210 gdk_gc_set_clip_origin (widget->style->black_gc, 0, 0);