]> Pileus Git - ~andy/gtk/blob - gdk/quartz/gdkproperty-quartz.c
Change FSF Address
[~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, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include "config.h"
20
21 #include "gdkproperty.h"
22
23 static GHashTable *names_to_atoms;
24 static GPtrArray *atoms_to_names;
25
26 static const gchar xatoms_string[] = 
27   /* These are all the standard predefined X atoms */
28   "NONE\0"
29   "PRIMARY\0"
30   "SECONDARY\0"
31   "ARC\0"
32   "ATOM\0"
33   "BITMAP\0"
34   "CARDINAL\0"
35   "COLORMAP\0"
36   "CURSOR\0"
37   "CUT_BUFFER0\0"
38   "CUT_BUFFER1\0"
39   "CUT_BUFFER2\0"
40   "CUT_BUFFER3\0"
41   "CUT_BUFFER4\0"
42   "CUT_BUFFER5\0"
43   "CUT_BUFFER6\0"
44   "CUT_BUFFER7\0"
45   "DRAWABLE\0"
46   "FONT\0"
47   "INTEGER\0"
48   "PIXMAP\0"
49   "POINT\0"
50   "RECTANGLE\0"
51   "RESOURCE_MANAGER\0"
52   "RGB_COLOR_MAP\0"
53   "RGB_BEST_MAP\0"
54   "RGB_BLUE_MAP\0"
55   "RGB_DEFAULT_MAP\0"
56   "RGB_GRAY_MAP\0"
57   "RGB_GREEN_MAP\0"
58   "RGB_RED_MAP\0"
59   "STRING\0"
60   "VISUALID\0"
61   "WINDOW\0"
62   "WM_COMMAND\0"
63   "WM_HINTS\0"
64   "WM_CLIENT_MACHINE\0"
65   "WM_ICON_NAME\0"
66   "WM_ICON_SIZE\0"
67   "WM_NAME\0"
68   "WM_NORMAL_HINTS\0"
69   "WM_SIZE_HINTS\0"
70   "WM_ZOOM_HINTS\0"
71   "MIN_SPACE\0"
72   "NORM_SPACE\0"
73   "MAX_SPACE\0"
74   "END_SPACE\0"
75   "SUPERSCRIPT_X\0"
76   "SUPERSCRIPT_Y\0"
77   "SUBSCRIPT_X\0"
78   "SUBSCRIPT_Y\0"
79   "UNDERLINE_POSITION\0"
80   "UNDERLINE_THICKNESS\0"
81   "STRIKEOUT_ASCENT\0"
82   "STRIKEOUT_DESCENT\0"
83   "ITALIC_ANGLE\0"
84   "X_HEIGHT\0"
85   "QUAD_WIDTH\0"
86   "WEIGHT\0"
87   "POINT_SIZE\0"
88   "RESOLUTION\0"
89   "COPYRIGHT\0"
90   "NOTICE\0"
91   "FONT_NAME\0"
92   "FAMILY_NAME\0"
93   "FULL_NAME\0"
94   "CAP_HEIGHT\0"
95   "WM_CLASS\0"
96   "WM_TRANSIENT_FOR\0"
97  /* Below here, these are our additions. Increment N_CUSTOM_PREDEFINED
98    * if you add any.
99    */
100   "CLIPBOARD\0"                 /* = 69 */;
101
102 static const gint xatoms_offset[] = {
103     0,   5,  13,  23,  27,  32,  39,  48,  57,  64,  76,  88, 
104   100, 112, 124, 136, 148, 160, 169, 174, 182, 189, 195, 205, 
105   222, 236, 249, 262, 278, 291, 305, 317, 324, 333, 340, 351, 
106   360, 378, 391, 404, 412, 428, 442, 456, 466, 477, 487, 497, 
107   511, 525, 537, 549, 568, 588, 605, 623, 636, 645, 656, 663, 
108   674, 685, 695, 702, 712, 724, 734, 745, 754, 771
109 };
110
111 #define N_CUSTOM_PREDEFINED 1
112
113 static void
114 ensure_atom_tables (void)
115 {
116   int i;
117   
118   if (names_to_atoms)
119     return;
120
121   names_to_atoms = g_hash_table_new (g_str_hash, g_str_equal);
122   atoms_to_names = g_ptr_array_sized_new (G_N_ELEMENTS (xatoms_offset));
123
124   for (i = 0; i < G_N_ELEMENTS (xatoms_offset); i++)
125     {
126       g_hash_table_insert(names_to_atoms, (gchar *)xatoms_string + xatoms_offset[i], GINT_TO_POINTER (i));
127       g_ptr_array_add(atoms_to_names, (gchar *)xatoms_string + xatoms_offset[i]);
128     }
129 }
130
131 static GdkAtom
132 intern_atom_internal (const gchar *atom_name, gboolean allocate)
133 {
134   gpointer result;
135   gchar *name;
136   g_return_val_if_fail (atom_name != NULL, GDK_NONE);
137
138   ensure_atom_tables ();
139   
140   if (g_hash_table_lookup_extended (names_to_atoms, atom_name, NULL, &result))
141     return result;
142   
143   result = GINT_TO_POINTER (atoms_to_names->len);
144   name = allocate ? g_strdup (atom_name) : (gchar *)atom_name;
145   g_hash_table_insert(names_to_atoms, name, result);
146   g_ptr_array_add(atoms_to_names, name);
147   
148   return result;  
149 }
150
151 GdkAtom
152 _gdk_quartz_display_manager_atom_intern (GdkDisplayManager *manager,
153                                          const gchar       *atom_name,
154                                          gboolean           copy_name)
155 {
156   return intern_atom_internal (atom_name, copy_name);
157 }
158
159 gchar *
160 _gdk_quartz_display_manager_get_atom_name (GdkDisplayManager *manager,
161                                            GdkAtom            atom)
162 {
163   ensure_atom_tables ();
164
165   if (GPOINTER_TO_INT (atom) >= atoms_to_names->len)
166     return NULL;
167
168   return g_strdup (g_ptr_array_index (atoms_to_names, GPOINTER_TO_INT (atom)));
169 }
170
171 void
172 _gdk_quartz_window_delete_property (GdkWindow *window,
173                                     GdkAtom    property)
174 {
175   /* FIXME: Implement */
176 }
177
178 gint
179 _gdk_quartz_window_get_property (GdkWindow   *window,
180                                  GdkAtom      property,
181                                  GdkAtom      type,
182                                  gulong       offset,
183                                  gulong       length,
184                                  gint         pdelete,
185                                  GdkAtom     *actual_property_type,
186                                  gint        *actual_format_type,
187                                  gint        *actual_length,
188                                  guchar     **data)
189 {
190   /* FIXME: Implement */
191   return 0;
192 }
193
194 void
195 _gdk_quartz_window_change_property (GdkWindow   *window,
196                                     GdkAtom      property,
197                                     GdkAtom      type,
198                                     gint         format,
199                                     GdkPropMode  mode,
200                                     const guchar *data,
201                                     gint         nelements)
202 {
203   /* FIXME: Implement */
204 }