]> Pileus Git - ~andy/gtk/blob - gdk/quartz/gdkproperty-quartz.c
Implement atom-related vfuncs for quartz
[~andy/gtk] / gdk / quartz / gdkproperty-quartz.c
1 /* gdkproperty-quartz.c
2  *
3  * Copyright (C) 2005 Imendio AB
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #include "config.h"
22
23 #include "gdkproperty.h"
24
25 static GHashTable *names_to_atoms;
26 static GPtrArray *atoms_to_names;
27
28 static const gchar xatoms_string[] = 
29   /* These are all the standard predefined X atoms */
30   "NONE\0"
31   "PRIMARY\0"
32   "SECONDARY\0"
33   "ARC\0"
34   "ATOM\0"
35   "BITMAP\0"
36   "CARDINAL\0"
37   "COLORMAP\0"
38   "CURSOR\0"
39   "CUT_BUFFER0\0"
40   "CUT_BUFFER1\0"
41   "CUT_BUFFER2\0"
42   "CUT_BUFFER3\0"
43   "CUT_BUFFER4\0"
44   "CUT_BUFFER5\0"
45   "CUT_BUFFER6\0"
46   "CUT_BUFFER7\0"
47   "DRAWABLE\0"
48   "FONT\0"
49   "INTEGER\0"
50   "PIXMAP\0"
51   "POINT\0"
52   "RECTANGLE\0"
53   "RESOURCE_MANAGER\0"
54   "RGB_COLOR_MAP\0"
55   "RGB_BEST_MAP\0"
56   "RGB_BLUE_MAP\0"
57   "RGB_DEFAULT_MAP\0"
58   "RGB_GRAY_MAP\0"
59   "RGB_GREEN_MAP\0"
60   "RGB_RED_MAP\0"
61   "STRING\0"
62   "VISUALID\0"
63   "WINDOW\0"
64   "WM_COMMAND\0"
65   "WM_HINTS\0"
66   "WM_CLIENT_MACHINE\0"
67   "WM_ICON_NAME\0"
68   "WM_ICON_SIZE\0"
69   "WM_NAME\0"
70   "WM_NORMAL_HINTS\0"
71   "WM_SIZE_HINTS\0"
72   "WM_ZOOM_HINTS\0"
73   "MIN_SPACE\0"
74   "NORM_SPACE\0"
75   "MAX_SPACE\0"
76   "END_SPACE\0"
77   "SUPERSCRIPT_X\0"
78   "SUPERSCRIPT_Y\0"
79   "SUBSCRIPT_X\0"
80   "SUBSCRIPT_Y\0"
81   "UNDERLINE_POSITION\0"
82   "UNDERLINE_THICKNESS\0"
83   "STRIKEOUT_ASCENT\0"
84   "STRIKEOUT_DESCENT\0"
85   "ITALIC_ANGLE\0"
86   "X_HEIGHT\0"
87   "QUAD_WIDTH\0"
88   "WEIGHT\0"
89   "POINT_SIZE\0"
90   "RESOLUTION\0"
91   "COPYRIGHT\0"
92   "NOTICE\0"
93   "FONT_NAME\0"
94   "FAMILY_NAME\0"
95   "FULL_NAME\0"
96   "CAP_HEIGHT\0"
97   "WM_CLASS\0"
98   "WM_TRANSIENT_FOR\0"
99  /* Below here, these are our additions. Increment N_CUSTOM_PREDEFINED
100    * if you add any.
101    */
102   "CLIPBOARD\0"                 /* = 69 */;
103
104 static const gint xatoms_offset[] = {
105     0,   5,  13,  23,  27,  32,  39,  48,  57,  64,  76,  88, 
106   100, 112, 124, 136, 148, 160, 169, 174, 182, 189, 195, 205, 
107   222, 236, 249, 262, 278, 291, 305, 317, 324, 333, 340, 351, 
108   360, 378, 391, 404, 412, 428, 442, 456, 466, 477, 487, 497, 
109   511, 525, 537, 549, 568, 588, 605, 623, 636, 645, 656, 663, 
110   674, 685, 695, 702, 712, 724, 734, 745, 754, 771
111 };
112
113 #define N_CUSTOM_PREDEFINED 1
114
115 static void
116 ensure_atom_tables (void)
117 {
118   int i;
119   
120   if (names_to_atoms)
121     return;
122
123   names_to_atoms = g_hash_table_new (g_str_hash, g_str_equal);
124   atoms_to_names = g_ptr_array_sized_new (G_N_ELEMENTS (xatoms_offset));
125
126   for (i = 0; i < G_N_ELEMENTS (xatoms_offset); i++)
127     {
128       g_hash_table_insert(names_to_atoms, (gchar *)xatoms_string + xatoms_offset[i], GINT_TO_POINTER (i));
129       g_ptr_array_add(atoms_to_names, (gchar *)xatoms_string + xatoms_offset[i]);
130     }
131 }
132
133 static GdkAtom
134 intern_atom_internal (const gchar *atom_name, gboolean allocate)
135 {
136   gpointer result;
137   gchar *name;
138   g_return_val_if_fail (atom_name != NULL, GDK_NONE);
139
140   ensure_atom_tables ();
141   
142   if (g_hash_table_lookup_extended (names_to_atoms, atom_name, NULL, &result))
143     return result;
144   
145   result = GINT_TO_POINTER (atoms_to_names->len);
146   name = allocate ? g_strdup (atom_name) : (gchar *)atom_name;
147   g_hash_table_insert(names_to_atoms, name, result);
148   g_ptr_array_add(atoms_to_names, name);
149   
150   return result;  
151 }
152
153 GdkAtom
154 _gdk_quartz_display_manager_atom_intern (GdkDisplayManager *manager,
155                                          const gchar       *atom_name,
156                                          gboolean           copy_name)
157 {
158   return intern_atom_internal (atom_name, copy_name);
159 }
160
161 gchar *
162 _gdk_quartz_display_manager_get_atom_name (GdkDisplayManager *manager,
163                                            GdkAtom            atom)
164 {
165   ensure_atom_tables ();
166
167   if (GPOINTER_TO_INT (atom) >= atoms_to_names->len)
168     return NULL;
169
170   return g_strdup (g_ptr_array_index (atoms_to_names, GPOINTER_TO_INT (atom)));
171 }
172
173 void
174 gdk_property_delete (GdkWindow *window,
175                      GdkAtom    property)
176 {
177   /* FIXME: Implement */
178 }
179
180 gint
181 gdk_property_get (GdkWindow   *window,
182                   GdkAtom      property,
183                   GdkAtom      type,
184                   gulong       offset,
185                   gulong       length,
186                   gint         pdelete,
187                   GdkAtom     *actual_property_type,
188                   gint        *actual_format_type,
189                   gint        *actual_length,
190                   guchar     **data)
191 {
192   /* FIXME: Implement */
193   return 0;
194 }
195
196 void
197 gdk_property_change (GdkWindow   *window,
198                      GdkAtom      property,
199                      GdkAtom      type,
200                      gint         format,
201                      GdkPropMode  mode,
202                      const guchar *data,
203                      gint         nelements)
204 {
205   /* FIXME: Implement */
206 }