]> Pileus Git - ~andy/gtk/blob - gdk/win32/gdkproperty-win32.c
applied patch from Andreas Persenius <ndap@swipnet.se> that updates the
[~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   
45   if (!atom_hash)
46     atom_hash = g_hash_table_new (g_str_hash, g_str_equal);
47
48   retval = GPOINTER_TO_UINT (g_hash_table_lookup (atom_hash, atom_name));
49   if (!retval)
50     {
51       if (strcmp (atom_name, "PRIMARY") == 0)
52         retval = GDK_SELECTION_PRIMARY;
53       else if (strcmp (atom_name, "SECONDARY") == 0)
54         retval = GDK_SELECTION_SECONDARY;
55       else if (strcmp (atom_name, "ATOM") == 0)
56         retval = GDK_SELECTION_TYPE_ATOM;
57       else if (strcmp (atom_name, "BITMAP") == 0)
58         retval = GDK_SELECTION_TYPE_BITMAP;
59       else if (strcmp (atom_name, "COLORMAP") == 0)
60         retval = GDK_SELECTION_TYPE_COLORMAP;
61       else if (strcmp (atom_name, "DRAWABLE") == 0)
62         retval = GDK_SELECTION_TYPE_DRAWABLE;
63       else if (strcmp (atom_name, "INTEGER") == 0)
64         retval = GDK_SELECTION_TYPE_INTEGER;
65       else if (strcmp (atom_name, "PIXMAP") == 0)
66         retval = GDK_SELECTION_TYPE_PIXMAP;
67       else if (strcmp (atom_name, "WINDOW") == 0)
68         retval = GDK_SELECTION_TYPE_WINDOW;
69       else if (strcmp (atom_name, "STRING") == 0)
70         retval = GDK_SELECTION_TYPE_STRING;
71       else
72         {
73           retval = GlobalFindAtom (atom_name);
74           if (only_if_exists && retval == 0)
75             retval = 0;
76           else
77             retval = GlobalAddAtom (atom_name);
78         }
79       g_hash_table_insert (atom_hash, 
80                            g_strdup (atom_name), 
81                            GUINT_TO_POINTER (retval));
82     }
83
84   return retval;
85 }
86
87 gchar *
88 gdk_atom_name (GdkAtom atom)
89 {
90   gchar name[256];
91
92   switch (atom)
93     {
94     case GDK_SELECTION_PRIMARY: return g_strdup ("PRIMARY");
95     case GDK_SELECTION_SECONDARY: return g_strdup ("SECONDARY");
96     case GDK_SELECTION_TYPE_ATOM: return g_strdup ("ATOM");
97     case GDK_SELECTION_TYPE_BITMAP: return g_strdup ("BITMAP");
98     case GDK_SELECTION_TYPE_COLORMAP: return g_strdup ("COLORMAP");
99     case GDK_SELECTION_TYPE_DRAWABLE: return g_strdup ("DRAWABLE");
100     case GDK_SELECTION_TYPE_INTEGER: return g_strdup ("INTEGER");
101     case GDK_SELECTION_TYPE_PIXMAP: return g_strdup ("PIXMAP");
102     case GDK_SELECTION_TYPE_WINDOW: return g_strdup ("WINDOW");
103     case GDK_SELECTION_TYPE_STRING: return g_strdup ("STRING");
104     }
105   if (atom < 0xC000)
106     return g_strdup_printf ("#%x", atom);
107   else if (GlobalGetAtomName (atom, name, sizeof (name)) == 0)
108     return NULL;
109   return g_strdup (name);
110 }
111
112 gint
113 gdk_property_get (GdkWindow   *window,
114                   GdkAtom      property,
115                   GdkAtom      type,
116                   gulong       offset,
117                   gulong       length,
118                   gint         pdelete,
119                   GdkAtom     *actual_property_type,
120                   gint        *actual_format_type,
121                   gint        *actual_length,
122                   guchar     **data)
123 {
124   g_return_val_if_fail (window != NULL, FALSE);
125   g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
126
127   if (GDK_WINDOW_DESTROYED (window))
128     return FALSE;
129
130   g_warning ("gdk_property_get: Not implemented");
131
132   return FALSE;
133 }
134
135 void
136 gdk_property_change (GdkWindow    *window,
137                      GdkAtom       property,
138                      GdkAtom       type,
139                      gint          format,
140                      GdkPropMode   mode,
141                      const guchar *data,
142                      gint          nelements)
143 {
144   HGLOBAL hdata;
145   gint i, length;
146   gchar *prop_name, *type_name;
147   guchar *ptr;
148
149   g_return_if_fail (window != NULL);
150   g_return_if_fail (GDK_IS_WINDOW (window));
151
152   if (GDK_WINDOW_DESTROYED (window))
153     return;
154
155   GDK_NOTE (MISC,
156             (prop_name = gdk_atom_name (property),
157              type_name = gdk_atom_name (type),
158              g_print ("gdk_property_change: %#x %#x (%s) %#x (%s) %s %d*%d bytes %.10s\n",
159                       GDK_WINDOW_HWND (window), property, prop_name,
160                       type, type_name,
161                       (mode == GDK_PROP_MODE_REPLACE ? "REPLACE" :
162                        (mode == GDK_PROP_MODE_PREPEND ? "PREPEND" :
163                         (mode == GDK_PROP_MODE_APPEND ? "APPEND" :
164                          "???"))),
165                       format, nelements, data),
166              g_free (prop_name),
167              g_free (type_name)));
168
169   if (property == gdk_selection_property
170       && type == GDK_TARGET_STRING
171       && format == 8
172       && mode == GDK_PROP_MODE_REPLACE)
173     {
174       length = nelements;
175       for (i = 0; i < nelements; i++)
176         if (data[i] == '\n')
177           length++;
178 #if 1      
179       GDK_NOTE (MISC, g_print ("...OpenClipboard(%#x)\n",
180                                GDK_WINDOW_HWND (window)));
181       if (!OpenClipboard (GDK_WINDOW_HWND (window)))
182         {
183           WIN32_API_FAILED ("OpenClipboard");
184           return;
185         }
186 #endif
187       hdata = GlobalAlloc (GMEM_MOVEABLE|GMEM_DDESHARE, length + 1);
188       ptr = GlobalLock (hdata);
189       GDK_NOTE (MISC, g_print ("...hdata=%#x, ptr=%#x\n", hdata, ptr));
190
191       for (i = 0; i < nelements; i++)
192         {
193           if (*data == '\n')
194             *ptr++ = '\r';
195           *ptr++ = *data++;
196         }
197       *ptr++ = '\0';
198       GlobalUnlock (hdata);
199       GDK_NOTE (MISC, g_print ("...SetClipboardData(CF_TEXT, %#x)\n",
200                                hdata));
201       if (!SetClipboardData(CF_TEXT, hdata))
202         WIN32_API_FAILED ("SetClipboardData");
203 #if 1
204       GDK_NOTE (MISC, g_print ("...CloseClipboard()\n"));
205       if (!CloseClipboard ())
206         WIN32_API_FAILED ("CloseClipboard");
207 #endif
208     }
209   else
210     g_warning ("gdk_property_change: General case not implemented");
211 }
212
213 void
214 gdk_property_delete (GdkWindow *window,
215                      GdkAtom    property)
216 {
217   gchar *prop_name, *type_name;
218   extern void gdk_selection_property_delete (GdkWindow *);
219
220   g_return_if_fail (window != NULL);
221   g_return_if_fail (GDK_IS_WINDOW (window));
222
223   GDK_NOTE (MISC,
224             (prop_name = gdk_atom_name (property),
225              g_print ("gdk_property_delete: %#x %#x (%s)\n",
226                       (window ? GDK_WINDOW_HWND (window) : 0),
227                       property, prop_name),
228              g_free (prop_name)));
229
230   if (property == gdk_selection_property)
231     gdk_selection_property_delete (window);
232   else
233     g_warning ("gdk_property_delete: General case not implemented");
234 }