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