gdkproperty-win32.c

Go to the documentation of this file.
00001 /* GDK - The GIMP Drawing Kit
00002  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  */
00019 
00020 /*
00021  * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
00022  * file for a list of people on the GTK+ Team.  See the ChangeLog
00023  * files for a list of changes.  These files are distributed with
00024  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
00025  */
00026 
00027 #include "config.h"
00028 
00029 #include <string.h>
00030 
00031 #include "gdkproperty.h"
00032 #include "gdkselection.h"
00033 #include "gdkprivate.h"
00034 #include "gdkwin32.h"
00035 
00036 GdkAtom gdk_atom_intern(const gchar * atom_name, gint only_if_exists)
00037 {
00038    GdkAtom retval;
00039    static GHashTable *atom_hash = NULL;
00040 
00041    if (!atom_hash)
00042       atom_hash = g_hash_table_new(g_str_hash, g_str_equal);
00043 
00044    retval = GPOINTER_TO_UINT(g_hash_table_lookup(atom_hash, atom_name));
00045    if (!retval) {
00046       if (strcmp(atom_name, "PRIMARY") == 0)
00047          retval = GDK_SELECTION_PRIMARY;
00048       else if (strcmp(atom_name, "SECONDARY") == 0)
00049          retval = GDK_SELECTION_SECONDARY;
00050       else if (strcmp(atom_name, "ATOM") == 0)
00051          retval = GDK_SELECTION_TYPE_ATOM;
00052       else if (strcmp(atom_name, "BITMAP") == 0)
00053          retval = GDK_SELECTION_TYPE_BITMAP;
00054       else if (strcmp(atom_name, "COLORMAP") == 0)
00055          retval = GDK_SELECTION_TYPE_COLORMAP;
00056       else if (strcmp(atom_name, "DRAWABLE") == 0)
00057          retval = GDK_SELECTION_TYPE_DRAWABLE;
00058       else if (strcmp(atom_name, "INTEGER") == 0)
00059          retval = GDK_SELECTION_TYPE_INTEGER;
00060       else if (strcmp(atom_name, "PIXMAP") == 0)
00061          retval = GDK_SELECTION_TYPE_PIXMAP;
00062       else if (strcmp(atom_name, "WINDOW") == 0)
00063          retval = GDK_SELECTION_TYPE_WINDOW;
00064       else if (strcmp(atom_name, "STRING") == 0)
00065          retval = GDK_SELECTION_TYPE_STRING;
00066       else {
00067          retval = GlobalFindAtom(atom_name);
00068          if (only_if_exists && retval == 0)
00069             retval = 0;
00070          else
00071             retval = GlobalAddAtom(atom_name);
00072       }
00073       g_hash_table_insert(atom_hash,
00074                           g_strdup(atom_name), GUINT_TO_POINTER(retval));
00075    }
00076 
00077    return retval;
00078 }
00079 
00080 gchar *gdk_atom_name(GdkAtom atom)
00081 {
00082    gchar name[256];
00083 
00084    switch (atom) {
00085    case GDK_SELECTION_PRIMARY:
00086       return g_strdup("PRIMARY");
00087    case GDK_SELECTION_SECONDARY:
00088       return g_strdup("SECONDARY");
00089    case GDK_SELECTION_TYPE_ATOM:
00090       return g_strdup("ATOM");
00091    case GDK_SELECTION_TYPE_BITMAP:
00092       return g_strdup("BITMAP");
00093    case GDK_SELECTION_TYPE_COLORMAP:
00094       return g_strdup("COLORMAP");
00095    case GDK_SELECTION_TYPE_DRAWABLE:
00096       return g_strdup("DRAWABLE");
00097    case GDK_SELECTION_TYPE_INTEGER:
00098       return g_strdup("INTEGER");
00099    case GDK_SELECTION_TYPE_PIXMAP:
00100       return g_strdup("PIXMAP");
00101    case GDK_SELECTION_TYPE_WINDOW:
00102       return g_strdup("WINDOW");
00103    case GDK_SELECTION_TYPE_STRING:
00104       return g_strdup("STRING");
00105    }
00106    if (atom < 0xC000)
00107       return g_strdup_printf("#%x", atom);
00108    else if (GlobalGetAtomName(atom, name, sizeof(name)) == 0)
00109       return NULL;
00110    return g_strdup(name);
00111 }
00112 
00113 gint
00114 gdk_property_get(GdkWindow * window,
00115                  GdkAtom property,
00116                  GdkAtom type,
00117                  gulong offset,
00118                  gulong length,
00119                  gint pdelete,
00120                  GdkAtom * actual_property_type,
00121                  gint * actual_format_type,
00122                  gint * actual_length, guchar ** data)
00123 {
00124    g_return_val_if_fail(window != NULL, FALSE);
00125    g_return_val_if_fail(GDK_IS_WINDOW(window), FALSE);
00126 
00127    if (GDK_DRAWABLE_DESTROYED(window))
00128       return FALSE;
00129 
00130    g_warning("gdk_property_get: Not implemented");
00131 
00132    return FALSE;
00133 }
00134 
00135 void
00136 gdk_property_change(GdkWindow * window,
00137                     GdkAtom property,
00138                     GdkAtom type,
00139                     gint format,
00140                     GdkPropMode mode, const guchar * data, gint nelements)
00141 {
00142    HGLOBAL hdata;
00143    gint i, length;
00144    gchar *prop_name, *type_name;
00145    guchar *ptr;
00146 
00147    g_return_if_fail(window != NULL);
00148    g_return_if_fail(GDK_IS_WINDOW(window));
00149 
00150    if (GDK_DRAWABLE_DESTROYED(window))
00151       return;
00152 
00153    GDK_NOTE(DND,
00154             (prop_name = gdk_atom_name(property),
00155              type_name = gdk_atom_name(type),
00156              g_print
00157              ("gdk_property_change: %#x %#x (%s) %#x (%s) %s %d*%d bytes %.10s\n",
00158               GDK_DRAWABLE_XID(window), property, prop_name, type,
00159               type_name,
00160               (mode ==
00161                GDK_PROP_MODE_REPLACE ? "REPLACE" : (mode ==
00162                                                     GDK_PROP_MODE_PREPEND ?
00163                                                     "PREPEND" : (mode ==
00164                                                                  GDK_PROP_MODE_APPEND
00165                                                                  ? "APPEND"
00166                                                                  :
00167                                                                  "???"))),
00168               format, nelements, data), g_free(prop_name),
00169              g_free(type_name)));
00170 
00171    if (property == gdk_selection_property
00172        && type == GDK_TARGET_STRING
00173        && format == 8 && mode == GDK_PROP_MODE_REPLACE) {
00174       length = nelements;
00175       for (i = 0; i < nelements; i++)
00176          if (data[i] == '\n')
00177             length++;
00178 #if 1
00179       GDK_NOTE(DND, g_print("...OpenClipboard(%#x)\n",
00180                             GDK_DRAWABLE_XID(window)));
00181       if (!OpenClipboard(GDK_DRAWABLE_XID(window))) {
00182          WIN32_API_FAILED("OpenClipboard");
00183          return;
00184       }
00185 #endif
00186       hdata = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, length + 1);
00187       ptr = GlobalLock(hdata);
00188       GDK_NOTE(DND, g_print("...hdata=%#x, ptr=%#x\n", hdata, ptr));
00189 
00190       for (i = 0; i < nelements; i++) {
00191          if (*data == '\n')
00192             *ptr++ = '\r';
00193          *ptr++ = *data++;
00194       }
00195       *ptr++ = '\0';
00196       GlobalUnlock(hdata);
00197       GDK_NOTE(DND, g_print("...SetClipboardData(CF_TEXT, %#x)\n", hdata));
00198       if (!SetClipboardData(CF_TEXT, hdata))
00199          WIN32_API_FAILED("SetClipboardData");
00200 #if 1
00201       GDK_NOTE(DND, g_print("...CloseClipboard()\n"));
00202       if (!CloseClipboard())
00203          WIN32_API_FAILED("CloseClipboard");
00204 #endif
00205    } else
00206       g_warning("gdk_property_change: General case not implemented");
00207 }
00208 
00209 void gdk_property_delete(GdkWindow * window, GdkAtom property)
00210 {
00211    gchar *prop_name, *type_name;
00212    extern void gdk_selection_property_delete(GdkWindow *);
00213 
00214    g_return_if_fail(window != NULL);
00215    g_return_if_fail(GDK_IS_WINDOW(window));
00216 
00217    GDK_NOTE(DND,
00218             (prop_name = gdk_atom_name(property),
00219              g_print("gdk_property_delete: %#x %#x (%s)\n",
00220                      (window ? GDK_DRAWABLE_XID(window) : 0),
00221                      property, prop_name), g_free(prop_name)));
00222 
00223    if (property == gdk_selection_property)
00224       gdk_selection_property_delete(window);
00225    else
00226       g_warning("gdk_property_delete: General case not implemented");
00227 }

Generated on Tue Jul 5 14:14:40 2011 for ROOT_528-00b_version by  doxygen 1.5.1