gtkdrawingarea.c 4.46 KB
Newer Older
Cody Russell's avatar
Cody Russell committed
1
/* GTK - The GIMP Toolkit
Elliot Lee's avatar
Elliot Lee committed
2 3 4
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 *
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
Elliot Lee's avatar
Elliot Lee committed
6 7 8 9 10 11
 * 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
12
 * Lesser General Public License for more details.
Elliot Lee's avatar
Elliot Lee committed
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15 16 17
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
18
 */
19 20

/*
21
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22 23 24 25 26
 * 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/. 
 */

27
#include "config.h"
Elliot Lee's avatar
Elliot Lee committed
28
#include "gtkdrawingarea.h"
29
#include "gtkintl.h"
Elliot Lee's avatar
Elliot Lee committed
30 31 32 33 34


static void gtk_drawing_area_realize       (GtkWidget           *widget);
static void gtk_drawing_area_size_allocate (GtkWidget           *widget,
					    GtkAllocation       *allocation);
35
static void gtk_drawing_area_send_configure (GtkDrawingArea     *darea);
Elliot Lee's avatar
Elliot Lee committed
36

Matthias Clasen's avatar
Matthias Clasen committed
37
G_DEFINE_TYPE (GtkDrawingArea, gtk_drawing_area, GTK_TYPE_WIDGET)
Elliot Lee's avatar
Elliot Lee committed
38 39 40 41

static void
gtk_drawing_area_class_init (GtkDrawingAreaClass *class)
{
42
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
Elliot Lee's avatar
Elliot Lee committed
43 44 45 46 47 48 49 50

  widget_class->realize = gtk_drawing_area_realize;
  widget_class->size_allocate = gtk_drawing_area_size_allocate;
}

static void
gtk_drawing_area_init (GtkDrawingArea *darea)
{
51
  darea->draw_data = NULL;
Elliot Lee's avatar
Elliot Lee committed
52 53 54 55
}


GtkWidget*
56
gtk_drawing_area_new (void)
Elliot Lee's avatar
Elliot Lee committed
57
{
Manish Singh's avatar
Manish Singh committed
58
  return g_object_new (GTK_TYPE_DRAWING_AREA, NULL);
Elliot Lee's avatar
Elliot Lee committed
59 60 61 62 63
}

static void
gtk_drawing_area_realize (GtkWidget *widget)
{
64
  GtkDrawingArea *darea = GTK_DRAWING_AREA (widget);
65 66
  GtkAllocation allocation;
  GdkWindow *window;
Elliot Lee's avatar
Elliot Lee committed
67 68 69
  GdkWindowAttr attributes;
  gint attributes_mask;

70
  if (!gtk_widget_get_has_window (widget))
71 72 73 74 75
    {
      GTK_WIDGET_CLASS (gtk_drawing_area_parent_class)->realize (widget);
    }
  else
    {
76
      gtk_widget_set_realized (widget, TRUE);
77

78 79
      gtk_widget_get_allocation (widget, &allocation);

80
      attributes.window_type = GDK_WINDOW_CHILD;
81 82 83 84
      attributes.x = allocation.x;
      attributes.y = allocation.y;
      attributes.width = allocation.width;
      attributes.height = allocation.height;
85 86 87 88 89 90 91
      attributes.wclass = GDK_INPUT_OUTPUT;
      attributes.visual = gtk_widget_get_visual (widget);
      attributes.colormap = gtk_widget_get_colormap (widget);
      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;

92 93 94 95
      window = gdk_window_new (gtk_widget_get_parent_window (widget),
                               &attributes, attributes_mask);
      gdk_window_set_user_data (window, darea);
      gtk_widget_set_window (widget, window);
96

97 98
      gtk_widget_style_attach (widget);
      gtk_style_set_background (gtk_widget_get_style (widget), window, GTK_STATE_NORMAL);
99
    }
100 101

  gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
Elliot Lee's avatar
Elliot Lee committed
102 103 104 105 106 107 108 109 110
}

static void
gtk_drawing_area_size_allocate (GtkWidget     *widget,
				GtkAllocation *allocation)
{
  g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
  g_return_if_fail (allocation != NULL);

111
  gtk_widget_set_allocation (widget, allocation);
Elliot Lee's avatar
Elliot Lee committed
112

113
  if (gtk_widget_get_realized (widget))
Elliot Lee's avatar
Elliot Lee committed
114
    {
115
      if (gtk_widget_get_has_window (widget))
116
        gdk_window_move_resize (gtk_widget_get_window (widget),
117 118
                                allocation->x, allocation->y,
                                allocation->width, allocation->height);
Elliot Lee's avatar
Elliot Lee committed
119

120
      gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
Elliot Lee's avatar
Elliot Lee committed
121 122
    }
}
123 124 125 126

static void
gtk_drawing_area_send_configure (GtkDrawingArea *darea)
{
127
  GtkAllocation allocation;
128
  GtkWidget *widget;
129
  GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
130 131

  widget = GTK_WIDGET (darea);
132
  gtk_widget_get_allocation (widget, &allocation);
133

134
  event->configure.window = g_object_ref (gtk_widget_get_window (widget));
135
  event->configure.send_event = TRUE;
136 137 138 139
  event->configure.x = allocation.x;
  event->configure.y = allocation.y;
  event->configure.width = allocation.width;
  event->configure.height = allocation.height;
140
  
141 142
  gtk_widget_event (widget, event);
  gdk_event_free (event);
143
}