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