00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "config.h"
00028
00029 #include <string.h>
00030
00031 #include <gdk/gdk.h>
00032 #include "gdkwin32.h"
00033
00034
00035
00036
00037
00038 typedef struct {
00039 guchar *data;
00040 gint length;
00041 gint format;
00042 GdkAtom type;
00043 } GdkSelProp;
00044
00045 static GHashTable *sel_prop_table = NULL;
00046
00047 void gdk_win32_selection_init(void)
00048 {
00049 if (sel_prop_table == NULL)
00050 sel_prop_table = g_hash_table_new(g_int_hash, g_int_equal);
00051 }
00052
00053 void
00054 gdk_sel_prop_store(GdkWindow * owner,
00055 GdkAtom type, gint format, guchar * data, gint length)
00056 {
00057 GdkSelProp *prop;
00058
00059 prop = g_hash_table_lookup(sel_prop_table, &GDK_DRAWABLE_XID(owner));
00060 if (prop != NULL) {
00061 g_free(prop->data);
00062 g_hash_table_remove(sel_prop_table, &GDK_DRAWABLE_XID(owner));
00063 }
00064 prop = g_new(GdkSelProp, 1);
00065 prop->data = data;
00066 prop->length = length;
00067 prop->format = format;
00068 prop->type = type;
00069 g_hash_table_insert(sel_prop_table, &GDK_DRAWABLE_XID(owner), prop);
00070 }
00071
00072 gint
00073 gdk_selection_owner_set(GdkWindow * owner,
00074 GdkAtom selection, guint32 time, gint send_event)
00075 {
00076 gchar *sel_name;
00077 HWND xwindow;
00078
00079 GDK_NOTE(DND,
00080 (sel_name = gdk_atom_name(selection),
00081 g_print("gdk_selection_owner_set: %#x %#x (%s)\n",
00082 (owner ? GDK_DRAWABLE_XID(owner) : 0),
00083 selection, sel_name), g_free(sel_name)));
00084
00085 if (selection != gdk_clipboard_atom)
00086 return FALSE;
00087
00088 if (owner != NULL)
00089 xwindow = GDK_DRAWABLE_XID(owner);
00090 else
00091 xwindow = NULL;
00092
00093 GDK_NOTE(DND, g_print("...OpenClipboard(%#x)\n", xwindow));
00094 if (!OpenClipboard(xwindow)) {
00095 WIN32_API_FAILED("OpenClipboard");
00096 return FALSE;
00097 }
00098 GDK_NOTE(DND, g_print("...EmptyClipboard()\n"));
00099 if (!EmptyClipboard()) {
00100 WIN32_API_FAILED("EmptyClipboard");
00101 CloseClipboard();
00102 return FALSE;
00103 }
00104 #if 0
00105
00106 if (xwindow != NULL)
00107 SetClipboardData(CF_TEXT, NULL);
00108 #endif
00109 GDK_NOTE(DND, g_print("...CloseClipboard()\n"));
00110 if (!CloseClipboard()) {
00111 WIN32_API_FAILED("CloseClipboard");
00112 return FALSE;
00113 }
00114 if (owner != NULL) {
00115
00116
00117
00118 SendMessage(xwindow, gdk_selection_request_msg, selection, 0);
00119 }
00120
00121 return TRUE;
00122 }
00123
00124 GdkWindow *gdk_selection_owner_get(GdkAtom selection)
00125 {
00126 GdkWindow *window;
00127 gchar *sel_name;
00128
00129 #if 0
00130
00131
00132
00133
00134 return NULL;
00135 #else
00136 if (selection != gdk_clipboard_atom)
00137 window = NULL;
00138 else {
00139 window = gdk_window_lookup(GetClipboardOwner());
00140 if (window == NULL)
00141 window = (GdkWindow *)GetClipboardOwner();
00142 }
00143
00144 #endif
00145
00146 GDK_NOTE(DND,
00147 (sel_name = gdk_atom_name(selection),
00148 g_print("gdk_selection_owner_get: %#x (%s) = %#x\n",
00149 selection, sel_name,
00150 (window ? GDK_DRAWABLE_XID(window) : 0)),
00151 g_free(sel_name)));
00152
00153 return window;
00154 }
00155
00156 void
00157 gdk_selection_convert(GdkWindow * requestor,
00158 GdkAtom selection, GdkAtom target, guint32 time)
00159 {
00160 HGLOBAL hdata;
00161 GdkSelProp *prop;
00162 guchar *ptr, *data, *datap, *p;
00163 guint i, length, slength;
00164 gchar *sel_name, *tgt_name;
00165
00166 g_return_if_fail(requestor != NULL);
00167 if (GDK_DRAWABLE_DESTROYED(requestor))
00168 return;
00169
00170 GDK_NOTE(DND,
00171 (sel_name = gdk_atom_name(selection),
00172 tgt_name = gdk_atom_name(target),
00173 g_print("gdk_selection_convert: %#x %#x (%s) %#x (%s)\n",
00174 GDK_DRAWABLE_XID(requestor), selection, sel_name,
00175 target, tgt_name), g_free(sel_name),
00176 g_free(tgt_name)));
00177
00178 if (selection == gdk_clipboard_atom) {
00179
00180
00181
00182
00183 GDK_NOTE(DND, g_print("...OpenClipboard(%#x)\n",
00184 GDK_DRAWABLE_XID(requestor)));
00185 if (!OpenClipboard(GDK_DRAWABLE_XID(requestor))) {
00186 WIN32_API_FAILED("OpenClipboard");
00187 return;
00188 }
00189
00190 GDK_NOTE(DND, g_print("...GetClipboardData(CF_TEXT)\n"));
00191 if ((hdata = GetClipboardData(CF_TEXT)) != NULL) {
00192 if ((ptr = GlobalLock(hdata)) != NULL) {
00193 length = GlobalSize(hdata);
00194
00195 GDK_NOTE(DND, g_print("...got data: %d bytes: %.10s\n",
00196 length, ptr));
00197
00198 slength = 0;
00199 p = ptr;
00200 for (i = 0; i < length; i++) {
00201 if (*p == '\0')
00202 break;
00203 else if (*p != '\r')
00204 slength++;
00205 p++;
00206 }
00207
00208 data = datap = g_malloc(slength + 1);
00209 p = ptr;
00210 for (i = 0; i < length; i++) {
00211 if (*p == '\0')
00212 break;
00213 else if (*p != '\r')
00214 *datap++ = *p;
00215 p++;
00216 }
00217 *datap++ = '\0';
00218 gdk_sel_prop_store(requestor, GDK_TARGET_STRING, 8,
00219 data, strlen(data) + 1);
00220
00221 GlobalUnlock(hdata);
00222 }
00223 }
00224 GDK_NOTE(DND, g_print("...CloseClipboard()\n"));
00225 CloseClipboard();
00226
00227
00228
00229
00230
00231 SendMessage(GDK_DRAWABLE_XID(requestor), gdk_selection_notify_msg,
00232 selection, target);
00233 } else if (selection == gdk_win32_dropfiles_atom) {
00234
00235
00236
00237
00238 GdkSelProp *prop;
00239
00240 prop = g_hash_table_lookup(sel_prop_table,
00241 &GDK_DRAWABLE_XID(gdk_parent_root));
00242
00243 if (prop != NULL) {
00244 g_hash_table_remove(sel_prop_table,
00245 &GDK_DRAWABLE_XID(gdk_parent_root));
00246 gdk_sel_prop_store(requestor, prop->type, prop->format,
00247 prop->data, prop->length);
00248 g_free(prop);
00249 SendMessage(GDK_DRAWABLE_XID(requestor), gdk_selection_notify_msg,
00250 selection, target);
00251 }
00252 } else {
00253 g_warning("gdk_selection_convert: General case not implemented");
00254 }
00255 }
00256
00257 gint
00258 gdk_selection_property_get(GdkWindow * requestor,
00259 guchar ** data,
00260 GdkAtom * ret_type, gint * ret_format)
00261 {
00262 GdkSelProp *prop;
00263
00264 g_return_val_if_fail(requestor != NULL, 0);
00265 g_return_val_if_fail(GDK_IS_WINDOW(requestor), 0);
00266
00267 if (GDK_DRAWABLE_DESTROYED(requestor))
00268 return 0;
00269
00270 GDK_NOTE(DND, g_print("gdk_selection_property_get: %#x",
00271 GDK_DRAWABLE_XID(requestor)));
00272
00273 prop =
00274 g_hash_table_lookup(sel_prop_table, &GDK_DRAWABLE_XID(requestor));
00275
00276 if (prop == NULL) {
00277 GDK_NOTE(DND, g_print(": NULL\n"));
00278 *data = NULL;
00279 return 0;
00280 }
00281 GDK_NOTE(DND, g_print(": %d bytes\n", prop->length));
00282 *data = g_malloc(prop->length);
00283 if (prop->length > 0)
00284 memmove(*data, prop->data, prop->length);
00285 if (ret_type)
00286 *ret_type = prop->type;
00287 if (ret_format)
00288 *ret_format = prop->format;
00289
00290 return prop->length;
00291 }
00292
00293 void gdk_selection_property_delete(GdkWindow * window)
00294 {
00295 GdkSelProp *prop;
00296
00297 GDK_NOTE(DND, g_print("gdk_selection_property_delete: %#x",
00298 GDK_DRAWABLE_XID(window)));
00299
00300 prop = g_hash_table_lookup(sel_prop_table, &GDK_DRAWABLE_XID(window));
00301 if (prop != NULL) {
00302 g_free(prop->data);
00303 g_hash_table_remove(sel_prop_table, &GDK_DRAWABLE_XID(window));
00304 } else
00305 g_warning("gdk_selection_property_delete: not found");
00306 }
00307
00308 void
00309 gdk_selection_send_notify(guint32 requestor,
00310 GdkAtom selection,
00311 GdkAtom target, GdkAtom property, guint32 time)
00312 {
00313 gchar *sel_name, *tgt_name, *prop_name;
00314
00315 GDK_NOTE(DND,
00316 (sel_name = gdk_atom_name(selection),
00317 tgt_name = gdk_atom_name(target),
00318 prop_name = gdk_atom_name(property),
00319 g_print
00320 ("gdk_selection_send_notify: %#x %#x (%s) %#x (%s) %#x (%s)\n",
00321 requestor, selection, sel_name, target, tgt_name, property,
00322 prop_name), g_free(sel_name), g_free(tgt_name),
00323 g_free(prop_name)));
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339 SendMessage((HWND) requestor, gdk_selection_clear_msg, selection, 0);
00340 }
00341
00342 gint
00343 gdk_text_property_to_text_list(GdkAtom encoding,
00344 gint format,
00345 const guchar * text,
00346 gint length, gchar *** list)
00347 {
00348 GDK_NOTE(DND,
00349 g_print("gdk_text_property_to_text_list not implemented\n"));
00350
00351 return 0;
00352 }
00353
00354 void gdk_free_text_list(gchar ** list)
00355 {
00356 g_return_if_fail(list != NULL);
00357
00358
00359 }
00360
00361 gint
00362 gdk_string_to_compound_text(const gchar * str,
00363 GdkAtom * encoding,
00364 gint * format, guchar ** ctext, gint * length)
00365 {
00366 g_warning("gdk_string_to_compound_text: Not implemented");
00367
00368 return 0;
00369 }
00370
00371 void gdk_free_compound_text(guchar * ctext)
00372 {
00373 g_warning("gdk_free_compound_text: Not implemented");
00374 }