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 Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #include "gtkcontainer.h"
19 #include "gtkpixmap.h"
22 static void gtk_pixmap_class_init (GtkPixmapClass *klass);
23 static void gtk_pixmap_init (GtkPixmap *pixmap);
24 static gint gtk_pixmap_expose (GtkWidget *widget,
25 GdkEventExpose *event);
29 gtk_pixmap_get_type ()
31 static guint pixmap_type = 0;
35 GtkTypeInfo pixmap_info =
39 sizeof (GtkPixmapClass),
40 (GtkClassInitFunc) gtk_pixmap_class_init,
41 (GtkObjectInitFunc) gtk_pixmap_init,
45 pixmap_type = gtk_type_unique (gtk_misc_get_type (), &pixmap_info);
52 gtk_pixmap_class_init (GtkPixmapClass *class)
54 GtkWidgetClass *widget_class;
56 widget_class = (GtkWidgetClass*) class;
58 widget_class->expose_event = gtk_pixmap_expose;
62 gtk_pixmap_init (GtkPixmap *pixmap)
64 GTK_WIDGET_SET_FLAGS (pixmap, GTK_NO_WINDOW);
66 pixmap->pixmap = NULL;
71 gtk_pixmap_new (GdkPixmap *val,
76 g_return_val_if_fail (val != NULL, NULL);
78 pixmap = gtk_type_new (gtk_pixmap_get_type ());
80 gtk_pixmap_set (pixmap, val, mask);
82 return GTK_WIDGET (pixmap);
86 gtk_pixmap_set (GtkPixmap *pixmap,
93 g_return_if_fail (pixmap != NULL);
94 g_return_if_fail (GTK_IS_PIXMAP (pixmap));
95 g_return_if_fail (val != NULL);
102 gdk_window_get_size (pixmap->pixmap, &width, &height);
103 GTK_WIDGET (pixmap)->requisition.width = width + GTK_MISC (pixmap)->xpad * 2;
104 GTK_WIDGET (pixmap)->requisition.height = height + GTK_MISC (pixmap)->ypad * 2;
108 GTK_WIDGET (pixmap)->requisition.width = 0;
109 GTK_WIDGET (pixmap)->requisition.height = 0;
112 if (GTK_WIDGET_VISIBLE (pixmap))
113 gtk_widget_queue_resize (GTK_WIDGET (pixmap));
117 gtk_pixmap_get (GtkPixmap *pixmap,
121 g_return_if_fail (pixmap != NULL);
122 g_return_if_fail (GTK_IS_PIXMAP (pixmap));
125 *val = pixmap->pixmap;
127 *mask = pixmap->mask;
132 gtk_pixmap_expose (GtkWidget *widget,
133 GdkEventExpose *event)
139 g_return_val_if_fail (widget != NULL, FALSE);
140 g_return_val_if_fail (GTK_IS_PIXMAP (widget), FALSE);
141 g_return_val_if_fail (event != NULL, FALSE);
143 if (GTK_WIDGET_DRAWABLE (widget))
145 pixmap = GTK_PIXMAP (widget);
146 misc = GTK_MISC (widget);
148 x = (widget->allocation.x * (1.0 - misc->xalign) +
149 (widget->allocation.x + widget->allocation.width
150 - (widget->requisition.width - misc->xpad * 2)) *
152 y = (widget->allocation.y * (1.0 - misc->yalign) +
153 (widget->allocation.y + widget->allocation.height
154 - (widget->requisition.height - misc->ypad * 2)) *
159 gdk_gc_set_clip_mask (widget->style->black_gc, pixmap->mask);
160 gdk_gc_set_clip_origin (widget->style->black_gc, x, y);
163 gdk_draw_pixmap (widget->window,
164 widget->style->black_gc,
170 gdk_gc_set_clip_mask (widget->style->black_gc, NULL);
171 gdk_gc_set_clip_origin (widget->style->black_gc, 0, 0);