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.
26 * GTK+ DirectFB backend
27 * Copyright (C) 2001-2002 convergence integrated media GmbH
28 * Copyright (C) 2002-2004 convergence GmbH
29 * Written by Denis Oliver Kropp <dok@convergence.de> and
30 * Sven Neumann <sven@convergence.de>
38 #include "gdkproperty.h"
40 #include "gdkdirectfb.h"
41 #include "gdkprivate-directfb.h"
43 #include "gdkinternals.h"
47 static GHashTable *names_to_atoms;
48 static GPtrArray *atoms_to_names;
50 static const gchar xatoms_string[] =
51 /* These are all the standard predefined X atoms */
103 "UNDERLINE_POSITION\0"
104 "UNDERLINE_THICKNESS\0"
106 "STRIKEOUT_DESCENT\0"
123 static const gint xatoms_offset[] = {
124 0, 5, 13, 23, 27, 32, 39, 48, 57, 64, 76, 88,
125 100, 112, 124, 136, 148, 160, 169, 174, 182, 189, 195, 205,
126 222, 236, 249, 262, 278, 291, 305, 317, 324, 333, 340, 351,
127 360, 378, 391, 404, 412, 428, 442, 456, 466, 477, 487, 497,
128 511, 525, 537, 549, 568, 588, 605, 623, 636, 645, 656, 663,
129 674, 685, 695, 702, 712, 724, 734, 745, 754
132 #define N_CUSTOM_PREDEFINED 1
135 ensure_atom_tables (void)
142 names_to_atoms = g_hash_table_new (g_str_hash, g_str_equal);
143 atoms_to_names = g_ptr_array_sized_new (G_N_ELEMENTS (xatoms_offset));
145 for (i = 0; i < G_N_ELEMENTS (xatoms_offset); i++)
147 g_hash_table_insert(names_to_atoms, (gchar *)xatoms_string + xatoms_offset[i], GINT_TO_POINTER (i));
148 g_ptr_array_add(atoms_to_names, (gchar *)xatoms_string + xatoms_offset[i]);
153 intern_atom_internal (const gchar *atom_name, gboolean allocate)
157 g_return_val_if_fail (atom_name != NULL, GDK_NONE);
159 ensure_atom_tables ();
161 if (g_hash_table_lookup_extended (names_to_atoms, atom_name, NULL, &result))
164 result = GINT_TO_POINTER (atoms_to_names->len);
165 name = allocate ? g_strdup (atom_name) : (gchar *)atom_name;
166 g_hash_table_insert(names_to_atoms, name, result);
167 g_ptr_array_add(atoms_to_names, name);
173 gdk_atom_intern (const gchar *atom_name,
174 gboolean only_if_exists)
176 return intern_atom_internal (atom_name, TRUE);
180 gdk_atom_intern_static_string (const gchar *atom_name)
182 return intern_atom_internal (atom_name, FALSE);
187 gdk_atom_name (GdkAtom atom)
192 if (GPOINTER_TO_INT (atom) >= atoms_to_names->len)
194 return g_strdup(g_ptr_array_index (atoms_to_names, GPOINTER_TO_INT (atom)));
199 gdk_property_delete_2 (GdkWindow *window,
201 GdkWindowProperty *prop)
203 GdkWindowImplDirectFB *impl;
205 GdkWindow *event_window;
207 impl = GDK_WINDOW_IMPL_DIRECTFB (GDK_WINDOW_OBJECT (window)->impl);
209 g_hash_table_remove (impl->properties, GUINT_TO_POINTER (property));
212 event_window = gdk_directfb_other_event_window (window, GDK_PROPERTY_NOTIFY);
216 event = gdk_directfb_event_make (event_window, GDK_PROPERTY_NOTIFY);
217 event->property.atom = property;
218 event->property.state = GDK_PROPERTY_DELETE;
223 gdk_property_delete (GdkWindow *window,
226 GdkWindowImplDirectFB *impl;
227 GdkWindowProperty *prop;
229 g_return_if_fail (GDK_IS_WINDOW (window));
231 impl = GDK_WINDOW_IMPL_DIRECTFB (GDK_WINDOW_OBJECT (window)->impl);
233 if (!impl->properties)
236 prop = g_hash_table_lookup (impl->properties, GUINT_TO_POINTER (property));
240 gdk_property_delete_2 (window, property, prop);
244 gdk_property_get (GdkWindow *window,
250 GdkAtom *actual_property_type,
251 gint *actual_format_type,
255 GdkWindowImplDirectFB *impl;
256 GdkWindowProperty *prop;
259 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), FALSE);
260 g_return_val_if_fail (data != NULL, FALSE);
263 window = _gdk_parent_root;
265 if (GDK_WINDOW_DESTROYED (window))
268 impl = GDK_WINDOW_IMPL_DIRECTFB (GDK_WINDOW_OBJECT (window)->impl);
270 if (!impl->properties)
273 prop = g_hash_table_lookup (impl->properties, GUINT_TO_POINTER (property));
276 if (actual_property_type)
277 *actual_property_type = GDK_NONE;
281 nbytes = CLAMP (length, 0, prop->length - offset * 4);
284 (prop->type == 0 /* AnyPropertyType */ || prop->type == type))
286 *data = g_malloc (nbytes + 1);
287 memcpy (*data, prop->data + offset, nbytes);
296 *actual_length = nbytes;
297 if (actual_property_type)
298 *actual_property_type = prop->type;
299 if (actual_format_type)
300 *actual_format_type = prop->format;
302 /* only delete the property if it was completely retrieved */
303 if (pdelete && length >= *actual_length && *data != NULL)
305 gdk_property_delete_2 (window, property, prop);
312 gdk_property_change (GdkWindow *window,
320 GdkWindowImplDirectFB *impl;
321 GdkWindowProperty *prop;
322 GdkWindowProperty *new_prop;
325 GdkWindow *event_window;
327 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
330 window = _gdk_parent_root;
332 if (GDK_WINDOW_DESTROYED (window))
335 impl = GDK_WINDOW_IMPL_DIRECTFB (GDK_WINDOW_OBJECT (window)->impl);
337 if (!impl->properties)
338 impl->properties = g_hash_table_new (NULL, NULL);
340 prop = g_hash_table_lookup (impl->properties, GUINT_TO_POINTER (property));
344 case GDK_PROP_MODE_REPLACE:
345 new_size = nelements * (format >> 3);
348 case GDK_PROP_MODE_PREPEND:
349 case GDK_PROP_MODE_APPEND:
350 new_size = nelements * (format >> 3);
353 if (type != prop->type || format != prop->format)
355 new_size += prop->length;
360 new_prop = g_malloc (G_STRUCT_OFFSET (GdkWindowProperty, data) + new_size);
361 new_prop->length = new_size;
362 new_prop->type = type;
363 new_prop->format = format;
367 case GDK_PROP_MODE_REPLACE:
368 memcpy (new_prop->data, data, new_size);
371 case GDK_PROP_MODE_APPEND:
373 memcpy (new_prop->data, prop->data, prop->length);
374 memcpy (new_prop->data + new_prop->length,
375 data, (nelements * (format >> 3)));
378 case GDK_PROP_MODE_PREPEND:
379 memcpy (new_prop->data, data, (nelements * (format >> 3)));
381 memcpy (new_prop->data + (nelements * (format >> 3)),
382 prop->data, prop->length);
386 g_hash_table_insert (impl->properties,
387 GUINT_TO_POINTER (property), new_prop);
390 event_window = gdk_directfb_other_event_window (window, GDK_PROPERTY_NOTIFY);
394 event = gdk_directfb_event_make (event_window, GDK_PROPERTY_NOTIFY);
395 event->property.atom = property;
396 event->property.state = GDK_PROPERTY_NEW_VALUE;
399 #define __GDK_PROPERTY_X11_C__
400 #include "gdkaliasdef.c"