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"
23 static void gtk_image_class_init (GtkImageClass *klass);
24 static void gtk_image_init (GtkImage *image);
25 static gint gtk_image_expose (GtkWidget *widget,
26 GdkEventExpose *event);
32 static guint image_type = 0;
36 GtkTypeInfo image_info =
40 sizeof (GtkImageClass),
41 (GtkClassInitFunc) gtk_image_class_init,
42 (GtkObjectInitFunc) gtk_image_init,
47 image_type = gtk_type_unique (gtk_misc_get_type (), &image_info);
54 gtk_image_class_init (GtkImageClass *class)
56 GtkWidgetClass *widget_class;
58 widget_class = (GtkWidgetClass*) class;
60 widget_class->expose_event = gtk_image_expose;
64 gtk_image_init (GtkImage *image)
66 GTK_WIDGET_SET_FLAGS (image, GTK_NO_WINDOW);
73 gtk_image_new (GdkImage *val,
78 g_return_val_if_fail (val != NULL, NULL);
80 image = gtk_type_new (gtk_image_get_type ());
82 gtk_image_set (image, val, mask);
84 return GTK_WIDGET (image);
88 gtk_image_set (GtkImage *image,
92 g_return_if_fail (image != NULL);
93 g_return_if_fail (GTK_IS_IMAGE (image));
100 GTK_WIDGET (image)->requisition.width = image->image->width + GTK_MISC (image)->xpad * 2;
101 GTK_WIDGET (image)->requisition.height = image->image->height + GTK_MISC (image)->ypad * 2;
105 GTK_WIDGET (image)->requisition.width = 0;
106 GTK_WIDGET (image)->requisition.height = 0;
109 if (GTK_WIDGET_VISIBLE (image))
110 gtk_widget_queue_resize (GTK_WIDGET (image));
114 gtk_image_get (GtkImage *image,
118 g_return_if_fail (image != NULL);
119 g_return_if_fail (GTK_IS_IMAGE (image));
129 gtk_image_expose (GtkWidget *widget,
130 GdkEventExpose *event)
132 g_return_val_if_fail (widget != NULL, FALSE);
133 g_return_val_if_fail (GTK_IS_IMAGE (widget), FALSE);
134 g_return_val_if_fail (event != NULL, FALSE);
136 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget))
140 GdkRectangle area, image_bound, intersection;
143 image = GTK_IMAGE (widget);
144 misc = GTK_MISC (widget);
146 x = (widget->allocation.x * (1.0 - misc->xalign) +
147 (widget->allocation.x + widget->allocation.width
148 - (widget->requisition.width - misc->xpad * 2)) *
150 y = (widget->allocation.y * (1.0 - misc->yalign) +
151 (widget->allocation.y + widget->allocation.height
152 - (widget->requisition.height - misc->ypad * 2)) *
157 gdk_gc_set_clip_mask (widget->style->black_gc, image->mask);
158 gdk_gc_set_clip_origin (widget->style->black_gc, x, y);
163 image_bound.width = image->image->width;
164 image_bound.height = image->image->height;
168 if(gdk_rectangle_intersect(&image_bound, &area, &intersection))
170 gdk_draw_image (widget->window,
171 widget->style->black_gc,
173 image_bound.x - x, image_bound.y - y,
174 image_bound.x, image_bound.y,
175 image_bound.width, image_bound.height);
180 gdk_gc_set_clip_mask (widget->style->black_gc, NULL);
181 gdk_gc_set_clip_origin (widget->style->black_gc, 0, 0);