gtkinvisible.c 4.56 KB
Newer Older
Owen Taylor's avatar
Owen Taylor committed
1
2
3
4
/* GTK - The GIMP Toolkit
 * 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
Owen Taylor's avatar
Owen Taylor 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.
Owen Taylor's avatar
Owen Taylor committed
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
Owen Taylor's avatar
Owen Taylor committed
15
16
17
18
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
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 <gdk/gdk.h>
Owen Taylor's avatar
Owen Taylor committed
28
29
30
#include "gtksignal.h"
#include "gtkinvisible.h"

31
32
33
34
35
36
37
38
39
static void gtk_invisible_class_init    (GtkInvisibleClass *klass);
static void gtk_invisible_init          (GtkInvisible      *invisible);
static void gtk_invisible_destroy       (GtkObject         *object);
static void gtk_invisible_realize       (GtkWidget         *widget);
static void gtk_invisible_style_set     (GtkWidget         *widget,
					 GtkStyle          *previous_style);
static void gtk_invisible_show          (GtkWidget         *widget);
static void gtk_invisible_size_allocate (GtkWidget         *widget,
					 GtkAllocation     *allocation);
Owen Taylor's avatar
Owen Taylor committed
40
41
42
43
44
45
46
47

GtkType
gtk_invisible_get_type (void)
{
  static GtkType invisible_type = 0;

  if (!invisible_type)
    {
48
      static const GtkTypeInfo invisible_info =
Owen Taylor's avatar
Owen Taylor committed
49
50
51
52
53
54
55
56
57
58
59
      {
	"GtkInvisible",
	sizeof (GtkInvisible),
	sizeof (GtkInvisibleClass),
	(GtkClassInitFunc) gtk_invisible_class_init,
	(GtkObjectInitFunc) gtk_invisible_init,
	/* reserved_1 */ NULL,
        /* reserved_2 */ NULL,
        (GtkClassInitFunc) NULL,
      };

60
      invisible_type = gtk_type_unique (GTK_TYPE_WIDGET, &invisible_info);
Owen Taylor's avatar
Owen Taylor committed
61
62
63
64
65
66
67
68
    }

  return invisible_type;
}

static void
gtk_invisible_class_init (GtkInvisibleClass *class)
{
69
  GtkObjectClass *object_class;
Owen Taylor's avatar
Owen Taylor committed
70
71
72
  GtkWidgetClass *widget_class;

  widget_class = (GtkWidgetClass*) class;
73
  object_class = (GtkObjectClass*) class;
Owen Taylor's avatar
Owen Taylor committed
74
75

  widget_class->realize = gtk_invisible_realize;
76
  widget_class->style_set = gtk_invisible_style_set;
Owen Taylor's avatar
Owen Taylor committed
77
78
  widget_class->show = gtk_invisible_show;
  widget_class->size_allocate = gtk_invisible_size_allocate;
79
80

  object_class->destroy = gtk_invisible_destroy;
Owen Taylor's avatar
Owen Taylor committed
81
82
83
84
85
86
}

static void
gtk_invisible_init (GtkInvisible *invisible)
{
  GTK_WIDGET_UNSET_FLAGS (invisible, GTK_NO_WINDOW);
87
  GTK_WIDGET_SET_FLAGS (invisible, GTK_TOPLEVEL);
Owen Taylor's avatar
Owen Taylor committed
88
89
90

  gtk_widget_ref (GTK_WIDGET (invisible));
  gtk_object_sink (GTK_OBJECT (invisible));
91
92
93
94
95
96
97
98
99
100
101
102
103
104

  invisible->has_user_ref_count = TRUE;
}

static void
gtk_invisible_destroy (GtkObject *object)
{
  GtkInvisible *invisible = GTK_INVISIBLE (object);
  
  if (invisible->has_user_ref_count)
    {
      invisible->has_user_ref_count = FALSE;
      gtk_widget_unref (GTK_WIDGET (invisible));
    }
Owen Taylor's avatar
Owen Taylor committed
105
106
107
108
109
}

GtkWidget*
gtk_invisible_new (void)
{
110
111
112
113
  GtkWidget *result = GTK_WIDGET (gtk_type_new (GTK_TYPE_INVISIBLE));
  gtk_widget_realize (result);

  return result;
Owen Taylor's avatar
Owen Taylor committed
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
}

static void
gtk_invisible_realize (GtkWidget *widget)
{
  GdkWindowAttr attributes;
  gint attributes_mask;

  g_return_if_fail (widget != NULL);
  g_return_if_fail (GTK_IS_INVISIBLE (widget));

  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);

  attributes.x = -100;
  attributes.y = -100;
  attributes.width = 10;
  attributes.height = 10;
  attributes.window_type = GDK_WINDOW_TEMP;
  attributes.wclass = GDK_INPUT_ONLY;
  attributes.override_redirect = TRUE;
  attributes.event_mask = gtk_widget_get_events (widget);

  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;

  widget->window = gdk_window_new (NULL, &attributes, attributes_mask);
  gdk_window_set_user_data (widget->window, widget);
140
141
  
  widget->style = gtk_style_attach (widget->style, widget->window);
Owen Taylor's avatar
Owen Taylor committed
142
143
}

144
145
146
147
148
149
150
static void
gtk_invisible_style_set (GtkWidget *widget,
			 GtkStyle  *previous_style)
{
  /* Don't chain up to parent implementation */
}

Owen Taylor's avatar
Owen Taylor committed
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
static void
gtk_invisible_show (GtkWidget *widget)
{
  g_return_if_fail (widget != NULL);

  GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
  gtk_widget_map (widget);
}

static void
gtk_invisible_size_allocate (GtkWidget     *widget,
			    GtkAllocation *allocation)
{
  widget->allocation = *allocation;
}