* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
- * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
+ * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
-#include "config.h"
+#undef GDK_DISABLE_DEPRECATED
+#undef GTK_DISABLE_DEPRECATED
+
+#include <config.h>
#include <math.h>
#include <string.h>
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
-#include "gdkx.h"
#include "gdk/gdkrgb.h"
#include "gtkpreview.h"
#include "gtksignal.h"
+#include "gtkprivate.h"
+#include "gtkintl.h"
+#include "gtkalias.h"
#define PREVIEW_CLASS(w) GTK_PREVIEW_CLASS (GTK_OBJECT (w)->klass)
-
-static void gtk_preview_class_init (GtkPreviewClass *klass);
-static void gtk_preview_init (GtkPreview *preview);
-static void gtk_preview_finalize (GtkObject *object);
+enum {
+ PROP_0,
+ PROP_EXPAND
+};
+
+
+static void gtk_preview_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gtk_preview_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void gtk_preview_finalize (GObject *object);
static void gtk_preview_realize (GtkWidget *widget);
static void gtk_preview_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void gtk_preview_make_buffer (GtkPreview *preview);
static void gtk_fill_lookup_array (guchar *array);
-static GtkWidgetClass *parent_class = NULL;
static GtkPreviewClass *preview_class = NULL;
static gint install_cmap = FALSE;
-guint
-gtk_preview_get_type (void)
-{
- static guint preview_type = 0;
-
- if (!preview_type)
- {
- static const GtkTypeInfo preview_info =
- {
- "GtkPreview",
- sizeof (GtkPreview),
- sizeof (GtkPreviewClass),
- (GtkClassInitFunc) gtk_preview_class_init,
- (GtkObjectInitFunc) gtk_preview_init,
- /* reserved_1 */ NULL,
- /* reserved_2 */ NULL,
- (GtkClassInitFunc) NULL,
- };
-
- preview_type = gtk_type_unique (gtk_widget_get_type (), &preview_info);
- }
-
- return preview_type;
-}
+G_DEFINE_TYPE (GtkPreview, gtk_preview, GTK_TYPE_WIDGET)
static void
gtk_preview_class_init (GtkPreviewClass *klass)
{
- GtkObjectClass *object_class;
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class;
- object_class = (GtkObjectClass*) klass;
widget_class = (GtkWidgetClass*) klass;
- parent_class = gtk_type_class (gtk_widget_get_type ());
preview_class = klass;
- object_class->finalize = gtk_preview_finalize;
+ gobject_class->finalize = gtk_preview_finalize;
+
+ gobject_class->set_property = gtk_preview_set_property;
+ gobject_class->get_property = gtk_preview_get_property;
widget_class->realize = gtk_preview_realize;
widget_class->size_allocate = gtk_preview_size_allocate;
widget_class->expose_event = gtk_preview_expose;
- klass->info.visual = NULL;
- klass->info.cmap = NULL;
-
klass->info.lookup = NULL;
klass->info.gamma = 1.0;
gdk_rgb_init ();
- klass->info.cmap = gdk_rgb_get_cmap ();
- klass->info.visual = gdk_rgb_get_visual ();
+
+ g_object_class_install_property (gobject_class,
+ PROP_EXPAND,
+ g_param_spec_boolean ("expand",
+ P_("Expand"),
+ P_("Whether the preview widget should take up the entire space it is allocated"),
+ FALSE,
+ GTK_PARAM_READWRITE));
+}
+
+static void
+gtk_preview_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkPreview *preview = GTK_PREVIEW (object);
+
+ switch (prop_id)
+ {
+ case PROP_EXPAND:
+ gtk_preview_set_expand (preview, g_value_get_boolean (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_preview_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkPreview *preview;
+
+ preview = GTK_PREVIEW (object);
+
+ switch (prop_id)
+ {
+ case PROP_EXPAND:
+ g_value_set_boolean (value, preview->expand);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
void
void
gtk_preview_uninit (void)
{
-
/* unimplemented */
}
gint width,
gint height)
{
- g_return_if_fail (preview != NULL);
g_return_if_fail (GTK_IS_PREVIEW (preview));
if ((width != GTK_WIDGET (preview)->requisition.width) ||
gint width,
gint height)
{
- GtkWidget *widget;
GdkRectangle r1, r2, r3;
guchar *src;
guint bpp;
guint rowstride;
- g_return_if_fail (preview != NULL);
g_return_if_fail (GTK_IS_PREVIEW (preview));
g_return_if_fail (window != NULL);
if (!preview->buffer)
return;
- widget = GTK_WIDGET (preview);
-
r1.x = 0;
r1.y = 0;
r1.width = preview->buffer_width;
guint bpp;
guint rowstride;
- g_return_if_fail (preview != NULL);
g_return_if_fail (GTK_IS_PREVIEW (preview));
g_return_if_fail (data != NULL);
- g_return_if_fail (preview_class->info.visual != NULL);
bpp = (preview->type == GTK_PREVIEW_COLOR ? 3 : 1);
rowstride = (preview->buffer_width * bpp + 3) & -4;
void
gtk_preview_set_expand (GtkPreview *preview,
- gint expand)
+ gboolean expand)
{
- g_return_if_fail (preview != NULL);
g_return_if_fail (GTK_IS_PREVIEW (preview));
- preview->expand = (expand != FALSE);
+ expand = expand != FALSE;
+
+ if (preview->expand != expand)
+ {
+ preview->expand = expand;
+ gtk_widget_queue_resize (GTK_WIDGET (preview));
+
+ g_object_notify (G_OBJECT (preview), "expand");
+ }
}
void
GdkVisual*
gtk_preview_get_visual (void)
{
- if (!preview_class)
- preview_class = gtk_type_class (gtk_preview_get_type ());
-
- return preview_class->info.visual;
+ return gdk_screen_get_rgb_visual (gdk_screen_get_default ());
}
GdkColormap*
gtk_preview_get_cmap (void)
{
- if (!preview_class)
- preview_class = gtk_type_class (gtk_preview_get_type ());
-
- return preview_class->info.cmap;
+ return gdk_screen_get_rgb_colormap (gdk_screen_get_default ());
}
GtkPreviewInfo*
static void
-gtk_preview_finalize (GtkObject *object)
+gtk_preview_finalize (GObject *object)
{
GtkPreview *preview;
- g_return_if_fail (object != NULL);
g_return_if_fail (GTK_IS_PREVIEW (object));
preview = GTK_PREVIEW (object);
g_free (preview->buffer);
preview->type = (GtkPreviewType) -1;
- (* GTK_OBJECT_CLASS (parent_class)->finalize) (object);
+ G_OBJECT_CLASS (gtk_preview_parent_class)->finalize (object);
}
static void
GdkWindowAttr attributes;
gint attributes_mask;
- g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_PREVIEW (widget));
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
attributes.y = widget->allocation.y + (widget->allocation.height - attributes.height) / 2;;
attributes.wclass = GDK_INPUT_OUTPUT;
- attributes.visual = preview_class->info.visual;
- attributes.colormap = preview_class->info.cmap;
attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
- attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+ attributes_mask = GDK_WA_X | GDK_WA_Y;
widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
gdk_window_set_user_data (widget->window, widget);
GtkPreview *preview;
gint width, height;
- g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_PREVIEW (widget));
preview = GTK_PREVIEW (widget);
GtkPreview *preview;
gint width, height;
- g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (GTK_IS_PREVIEW (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
gint width;
gint height;
- g_return_if_fail (preview != NULL);
g_return_if_fail (GTK_IS_PREVIEW (preview));
widget = GTK_WIDGET (preview);
}
}
-/* This will be useful for implementing gamma. */
+/* This is used for implementing gamma. */
static void
gtk_fill_lookup_array (guchar *array)
{
array[i] = val;
}
}
+
+#define __GTK_PREVIEW_C__
+#include "gtkaliasdef.c"