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