1 /* GDK - The GIMP Drawing Kit
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 Lesser 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 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser 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.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gdkproperty.h"
32 #include "gdkprivate.h"
33 #include "gdkprivate-fb.h"
36 gdk_atom_intern (const gchar *atom_name,
37 gboolean only_if_exists)
39 g_return_val_if_fail (atom_name != NULL, GDK_NONE);
41 if (strcmp (atom_name, "PRIMARY") == 0)
42 return GDK_SELECTION_PRIMARY;
43 else if (strcmp (atom_name, "SECONDARY") == 0)
44 return GDK_SELECTION_SECONDARY;
45 else if (strcmp (atom_name, "CLIPBOARD") == 0)
46 return GDK_SELECTION_CLIPBOARD;
47 else if (strcmp (atom_name, "ATOM") == 0)
48 return GDK_SELECTION_TYPE_ATOM;
49 else if (strcmp (atom_name, "BITMAP") == 0)
50 return GDK_SELECTION_TYPE_BITMAP;
51 else if (strcmp (atom_name, "COLORMAP") == 0)
52 return GDK_SELECTION_TYPE_COLORMAP;
53 else if (strcmp (atom_name, "DRAWABLE") == 0)
54 return GDK_SELECTION_TYPE_DRAWABLE;
55 else if (strcmp (atom_name, "INTEGER") == 0)
56 return GDK_SELECTION_TYPE_INTEGER;
57 else if (strcmp (atom_name, "PIXMAP") == 0)
58 return GDK_SELECTION_TYPE_PIXMAP;
59 else if (strcmp (atom_name, "WINDOW") == 0)
60 return GDK_SELECTION_TYPE_WINDOW;
61 else if (strcmp (atom_name, "STRING") == 0)
62 return GDK_SELECTION_TYPE_STRING;
64 return GUINT_TO_POINTER (256 + g_quark_from_string (atom_name));
68 gdk_atom_name (GdkAtom atom)
70 if (GPOINTER_TO_UINT (atom) < 256)
73 switch (GPOINTER_TO_UINT (atom))
75 case GDK_SELECTION_PRIMARY: return g_strdup ("PRIMARY");
76 case GDK_SELECTION_SECONDARY: return g_strdup ("SECONDARY");
77 case GDK_SELECTION_CLIPBOARD: return g_strdup ("CLIPBOARD");
78 case GDK_SELECTION_TYPE_ATOM: return g_strdup ("ATOM");
79 case GDK_SELECTION_TYPE_BITMAP: return g_strdup ("BITMAP");
80 case GDK_SELECTION_TYPE_COLORMAP: return g_strdup ("COLORMAP");
81 case GDK_SELECTION_TYPE_DRAWABLE: return g_strdup ("DRAWABLE");
82 case GDK_SELECTION_TYPE_INTEGER: return g_strdup ("INTEGER");
83 case GDK_SELECTION_TYPE_PIXMAP: return g_strdup ("PIXMAP");
84 case GDK_SELECTION_TYPE_WINDOW: return g_strdup ("WINDOW");
85 case GDK_SELECTION_TYPE_STRING: return g_strdup ("STRING");
87 g_warning (G_STRLOC "Invalid atom");
88 return g_strdup ("<invalid>");
92 return g_strdup (g_quark_to_string (GPOINTER_TO_UINT (atom) - 256));
96 gdk_property_delete_2 (GdkWindow *window,
98 GdkWindowProperty *prop)
100 GdkWindowFBData *fbd = GDK_WINDOW_IMPL_FBDATA(window);
102 GdkWindow *event_window;
104 g_hash_table_remove (fbd->properties, GUINT_TO_POINTER (property));
107 event_window = gdk_fb_other_event_window (window, GDK_PROPERTY_NOTIFY);
110 event = gdk_event_make (event_window, GDK_PROPERTY_NOTIFY, TRUE);
111 event->property.atom = property;
112 event->property.state = GDK_PROPERTY_DELETE;
117 gdk_property_delete (GdkWindow *window,
120 GdkWindowFBData *fbd = GDK_WINDOW_FBDATA (window);
121 GdkWindowProperty *prop;
123 g_return_if_fail (window != NULL);
124 g_return_if_fail (GDK_IS_WINDOW (window));
126 if (!fbd->properties)
129 prop = g_hash_table_lookup (fbd->properties, GUINT_TO_POINTER(property));
133 gdk_property_delete_2 (window, property, prop);
137 gdk_property_get (GdkWindow *window,
143 GdkAtom *actual_property_type,
144 gint *actual_format_type,
148 GdkWindowFBData *fbd = GDK_WINDOW_FBDATA (window);
149 GdkWindowProperty *prop;
152 g_return_val_if_fail (window != NULL, FALSE);
153 g_return_val_if_fail (data != NULL, FALSE);
154 g_return_val_if_fail (actual_length != NULL, FALSE);
155 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
157 if (!fbd->properties)
160 prop = g_hash_table_lookup (fbd->properties, GUINT_TO_POINTER (property));
164 nbytes = (offset + length * (prop->format >> 3)) - prop->length;
165 nbytes = MAX (nbytes, 0);
168 *data = g_malloc (nbytes+1);
169 memcpy (data, prop->data + offset, nbytes);
174 *actual_length = nbytes / (prop->format >> 3);
175 *actual_property_type = prop->type;
176 *actual_format_type = prop->format;
179 gdk_property_delete_2 (window, property, prop);
185 gdk_property_change (GdkWindow *window,
193 GdkWindowFBData *fbd = GDK_WINDOW_FBDATA (window);
194 GdkWindowProperty *prop, *new_prop;
197 GdkWindow *event_window;
199 g_return_if_fail (window != NULL);
200 g_return_if_fail (GDK_IS_WINDOW (window));
202 if (!fbd->properties)
203 fbd->properties = g_hash_table_new (NULL, NULL);
205 prop = g_hash_table_lookup (fbd->properties, GUINT_TO_POINTER (property));
209 case GDK_PROP_MODE_REPLACE:
210 new_size = nelements * (format >> 3);
212 case GDK_PROP_MODE_PREPEND:
213 case GDK_PROP_MODE_APPEND:
214 new_size = nelements * (format >> 3);
216 new_size += prop->length;
221 new_prop = g_malloc (G_STRUCT_OFFSET (GdkWindowProperty, data) + new_size);
222 new_prop->length = new_size;
223 new_prop->type = type;
224 new_prop->format = format;
228 case GDK_PROP_MODE_REPLACE:
229 memcpy (new_prop->data, data, new_size);
231 case GDK_PROP_MODE_APPEND:
233 memcpy (new_prop->data, prop->data, prop->length);
234 memcpy (new_prop->data + prop->length, data, (nelements * (format >> 3)));
236 case GDK_PROP_MODE_PREPEND:
237 memcpy (new_prop->data, data, (nelements * (format >> 3)));
239 memcpy (new_prop->data + (nelements * (format >> 3)), prop->data, prop->length);
243 g_hash_table_insert (fbd->properties, GUINT_TO_POINTER (property), new_prop);
246 event_window = gdk_fb_other_event_window (window, GDK_PROPERTY_NOTIFY);
249 event = gdk_event_make (event_window, GDK_PROPERTY_NOTIFY, TRUE);
250 event->property.atom = property;
251 event->property.state = GDK_PROPERTY_NEW_VALUE;