]> Pileus Git - ~andy/gtk/blob - gdk/win32/gdkproperty-win32.c
updated externals
[~andy/gtk] / gdk / win32 / gdkproperty-win32.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #include "config.h"
28
29 #include <string.h>
30
31 #include "gdkproperty.h"
32 #include "gdkselection.h"
33 #include "gdkinternals.h"
34 #include "gdkprivate-win32.h"
35 #include "gdkdrawable-win32.h"
36 #include "gdkwindow-win32.h"
37
38 GdkAtom
39 gdk_atom_intern (const gchar *atom_name,
40                  gint         only_if_exists)
41 {
42   GdkAtom retval;
43   static GHashTable *atom_hash = NULL;
44   ATOM win32_atom;
45   
46   if (!atom_hash)
47     atom_hash = g_hash_table_new (g_str_hash, g_str_equal);
48
49   retval = g_hash_table_lookup (atom_hash, atom_name);
50   if (!retval)
51     {
52       if (strcmp (atom_name, "PRIMARY") == 0)
53         retval = GDK_SELECTION_PRIMARY;
54       else if (strcmp (atom_name, "SECONDARY") == 0)
55         retval = GDK_SELECTION_SECONDARY;
56       else if (strcmp (atom_name, "CLIPBOARD") == 0)
57         retval = GDK_SELECTION_CLIPBOARD;
58       else if (strcmp (atom_name, "ATOM") == 0)
59         retval = GDK_SELECTION_TYPE_ATOM;
60       else if (strcmp (atom_name, "BITMAP") == 0)
61         retval = GDK_SELECTION_TYPE_BITMAP;
62       else if (strcmp (atom_name, "COLORMAP") == 0)
63         retval = GDK_SELECTION_TYPE_COLORMAP;
64       else if (strcmp (atom_name, "DRAWABLE") == 0)
65         retval = GDK_SELECTION_TYPE_DRAWABLE;
66       else if (strcmp (atom_name, "INTEGER") == 0)
67         retval = GDK_SELECTION_TYPE_INTEGER;
68       else if (strcmp (atom_name, "PIXMAP") == 0)
69         retval = GDK_SELECTION_TYPE_PIXMAP;
70       else if (strcmp (atom_name, "WINDOW") == 0)
71         retval = GDK_SELECTION_TYPE_WINDOW;
72       else if (strcmp (atom_name, "STRING") == 0)
73         retval = GDK_SELECTION_TYPE_STRING;
74       else
75         {
76           win32_atom = GlobalFindAtom (atom_name);
77           if (only_if_exists && retval == 0)
78             win32_atom = 0;
79           else
80             win32_atom = GlobalAddAtom (atom_name);
81           retval = GUINT_TO_POINTER (win32_atom);
82         }
83       g_hash_table_insert (atom_hash, 
84                            g_strdup (atom_name), 
85                            retval);
86     }
87
88   return retval;
89 }
90
91 gchar *
92 gdk_atom_name (GdkAtom atom)
93 {
94   gchar name[256];
95   ATOM win32_atom;
96
97   if (GDK_SELECTION_PRIMARY == atom) return g_strdup ("PRIMARY");
98   else if (GDK_SELECTION_SECONDARY == atom) return g_strdup ("SECONDARY");
99   else if (GDK_SELECTION_CLIPBOARD == atom) return g_strdup ("CLIPBOARD");
100   else if (GDK_SELECTION_TYPE_ATOM == atom) return g_strdup ("ATOM");
101   else if (GDK_SELECTION_TYPE_BITMAP == atom) return g_strdup ("BITMAP");
102   else if (GDK_SELECTION_TYPE_COLORMAP == atom) return g_strdup ("COLORMAP");
103   else if (GDK_SELECTION_TYPE_DRAWABLE == atom) return g_strdup ("DRAWABLE");
104   else if (GDK_SELECTION_TYPE_INTEGER == atom) return g_strdup ("INTEGER");
105   else if (GDK_SELECTION_TYPE_PIXMAP == atom) return g_strdup ("PIXMAP");
106   else if (GDK_SELECTION_TYPE_WINDOW == atom) return g_strdup ("WINDOW");
107   else if (GDK_SELECTION_TYPE_STRING == atom) return g_strdup ("STRING");
108   
109   win32_atom = GPOINTER_TO_UINT (atom);
110   
111   if (win32_atom < 0xC000)
112     return g_strdup_printf ("#%x", atom);
113   else if (GlobalGetAtomName (win32_atom, name, sizeof (name)) == 0)
114     return NULL;
115   return g_strdup (name);
116 }
117
118 gint
119 gdk_property_get (GdkWindow   *window,
120                   GdkAtom      property,
121                   GdkAtom      type,
122                   gulong       offset,
123                   gulong       length,
124                   gint         pdelete,
125                   GdkAtom     *actual_property_type,
126                   gint        *actual_format_type,
127                   gint        *actual_length,
128                   guchar     **data)
129 {
130   g_return_val_if_fail (window != NULL, FALSE);
131   g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
132
133   if (GDK_WINDOW_DESTROYED (window))
134     return FALSE;
135
136   g_warning ("gdk_property_get: Not implemented");
137
138   return FALSE;
139 }
140
141 void
142 gdk_property_change (GdkWindow    *window,
143                      GdkAtom       property,
144                      GdkAtom       type,
145                      gint          format,
146                      GdkPropMode   mode,
147                      const guchar *data,
148                      gint          nelements)
149 {
150   HGLOBAL hdata;
151   gint i, length;
152   gchar *prop_name, *type_name;
153   guchar *ptr;
154
155   g_return_if_fail (window != NULL);
156   g_return_if_fail (GDK_IS_WINDOW (window));
157
158   if (GDK_WINDOW_DESTROYED (window))
159     return;
160
161   GDK_NOTE (MISC,
162             (prop_name = gdk_atom_name (property),
163              type_name = gdk_atom_name (type),
164              g_print ("gdk_property_change: %#x %#x (%s) %#x (%s) %s %d*%d bytes %.10s\n",
165                       (guint) GDK_WINDOW_HWND (window),
166                       (guint) property, prop_name,
167                       (guint) type, type_name,
168                       (mode == GDK_PROP_MODE_REPLACE ? "REPLACE" :
169                        (mode == GDK_PROP_MODE_PREPEND ? "PREPEND" :
170                         (mode == GDK_PROP_MODE_APPEND ? "APPEND" :
171                          "???"))),
172                       format, nelements, data),
173              g_free (prop_name),
174              g_free (type_name)));
175
176   if (property == _gdk_selection_property
177       && type == GDK_TARGET_STRING
178       && format == 8
179       && mode == GDK_PROP_MODE_REPLACE)
180     {
181       length = nelements;
182       for (i = 0; i < nelements; i++)
183         if (data[i] == '\n')
184           length++;
185 #if 1      
186       GDK_NOTE (MISC, g_print ("...OpenClipboard(%#x)\n",
187                                (guint) GDK_WINDOW_HWND (window)));
188       if (!OpenClipboard (GDK_WINDOW_HWND (window)))
189         {
190           WIN32_API_FAILED ("OpenClipboard");
191           return;
192         }
193 #endif
194       hdata = GlobalAlloc (GMEM_MOVEABLE|GMEM_DDESHARE, length + 1);
195       ptr = GlobalLock (hdata);
196       GDK_NOTE (MISC, g_print ("...hdata=%#x, ptr=%p\n", (guint) hdata, ptr));
197
198       for (i = 0; i < nelements; i++)
199         {
200           if (*data == '\n')
201             *ptr++ = '\r';
202           *ptr++ = *data++;
203         }
204       *ptr++ = '\0';
205       GlobalUnlock (hdata);
206       GDK_NOTE (MISC, g_print ("...SetClipboardData(CF_TEXT, %#x)\n",
207                                (guint) hdata));
208       if (!SetClipboardData(CF_TEXT, hdata))
209         WIN32_API_FAILED ("SetClipboardData");
210 #if 1
211       GDK_NOTE (MISC, g_print ("...CloseClipboard()\n"));
212       if (!CloseClipboard ())
213         WIN32_API_FAILED ("CloseClipboard");
214 #endif
215     }
216   else
217     g_warning ("gdk_property_change: General case not implemented");
218 }
219
220 void
221 gdk_property_delete (GdkWindow *window,
222                      GdkAtom    property)
223 {
224   gchar *prop_name;
225   extern void gdk_selection_property_delete (GdkWindow *);
226
227   g_return_if_fail (window != NULL);
228   g_return_if_fail (GDK_IS_WINDOW (window));
229
230   GDK_NOTE (MISC,
231             (prop_name = gdk_atom_name (property),
232              g_print ("gdk_property_delete: %#x %#x (%s)\n",
233                       (window ? (guint) GDK_WINDOW_HWND (window) : 0),
234                       (guint) property, prop_name),
235              g_free (prop_name)));
236
237   if (property == _gdk_selection_property)
238     gdk_selection_property_delete (window);
239   else
240     g_warning ("gdk_property_delete: General case not implemented");
241 }
242
243 gboolean
244 gdk_setting_get (const gchar *name,
245                  GValue      *value)
246 {
247   /*
248    * XXX : if these values get changed through the Windoze UI the
249    *       respective gdk_events are not generated yet.
250    */
251   if (strcmp ("double-click-timeout", name) == 0)
252     {
253       g_value_set_int (value, GetDoubleClickTime ());
254       return TRUE;
255     }
256   else if (strcmp ("drag-threshold", name) == 0)
257     {
258       g_value_set_int (value, MAX(GetSystemMetrics (SM_CXDRAG), GetSystemMetrics (SM_CYDRAG)));
259       return TRUE;
260     }
261   else
262     return FALSE;
263 }