]> Pileus Git - ~andy/gtk/blobdiff - gdk/x11/gdkselection-x11.c
get directfb building with csw
[~andy/gtk] / gdk / x11 / gdkselection-x11.c
index c15d1f5abfbce5a68b79a4cbe41ef492c0028a7d..7d23080fdd05231c279af5620a66cc67f838c801 100644 (file)
@@ -24,7 +24,7 @@
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
-#include <config.h>
+#include "config.h"
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
 #include <string.h>
@@ -141,7 +141,7 @@ gdk_selection_owner_set_for_display (GdkDisplay *display,
 
   if (owner) 
     {
-      if (GDK_WINDOW_DESTROYED (owner))
+      if (GDK_WINDOW_DESTROYED (owner) || !GDK_WINDOW_IS_X11 (owner))
        return FALSE;
       
       xdisplay = GDK_WINDOW_XDISPLAY (owner);
@@ -231,7 +231,7 @@ gdk_selection_convert (GdkWindow *requestor,
 
   g_return_if_fail (selection != GDK_NONE);
   
-  if (GDK_WINDOW_DESTROYED (requestor))
+  if (GDK_WINDOW_DESTROYED (requestor) || !GDK_WINDOW_IS_X11 (requestor))
     return;
 
   display = GDK_WINDOW_DISPLAY (requestor);
@@ -279,10 +279,11 @@ gdk_selection_property_get (GdkWindow  *requestor,
 
   g_return_val_if_fail (requestor != NULL, 0);
   g_return_val_if_fail (GDK_IS_WINDOW (requestor), 0);
+  g_return_val_if_fail (GDK_WINDOW_IS_X11 (requestor), 0);
   
   display = GDK_WINDOW_DISPLAY (requestor);
 
-  if (GDK_WINDOW_DESTROYED (requestor))
+  if (GDK_WINDOW_DESTROYED (requestor) || !GDK_WINDOW_IS_X11 (requestor))
     goto err;
 
   t = NULL;
@@ -387,12 +388,12 @@ gdk_selection_property_get (GdkWindow  *requestor,
  * Since: 2.2
  **/
 void
-gdk_selection_send_notify_for_display (GdkDisplay *display,
-                                      guint32     requestor,
-                                      GdkAtom     selection,
-                                      GdkAtom     target,
-                                      GdkAtom     property, 
-                                      guint32     time)
+gdk_selection_send_notify_for_display (GdkDisplay       *display,
+                                      GdkNativeWindow  requestor,
+                                      GdkAtom          selection,
+                                      GdkAtom          target,
+                                      GdkAtom          property, 
+                                      guint32          time)
 {
   XSelectionEvent xevent;
   
@@ -404,7 +405,10 @@ gdk_selection_send_notify_for_display (GdkDisplay *display,
   xevent.requestor = requestor;
   xevent.selection = gdk_x11_atom_to_xatom_for_display (display, selection);
   xevent.target = gdk_x11_atom_to_xatom_for_display (display, target);
-  xevent.property = gdk_x11_atom_to_xatom_for_display (display, property);
+  if (property == GDK_NONE)
+    xevent.property = None;
+  else
+    xevent.property = gdk_x11_atom_to_xatom_for_display (display, property);
   xevent.time = time;
 
   _gdk_send_xevent (display, requestor, False, NoEventMask, (XEvent*) & xevent);
@@ -676,7 +680,7 @@ gdk_text_property_to_utf8_list_for_display (GdkDisplay    *display,
  * Convert a string from the encoding of the current 
  * locale into a form suitable for storing in a window property.
  * 
- * Returns: 0 upon sucess, non-zero upon failure. 
+ * Returns: 0 upon success, non-zero upon failure. 
  *
  * Since: 2.2
  **/
@@ -727,7 +731,8 @@ gdk_string_to_compound_text_for_display (GdkDisplay  *display,
  * from the input string and also canonicalizes \r, and \r\n to \n
  */
 static gchar * 
-sanitize_utf8 (const gchar *src)
+sanitize_utf8 (const gchar *src,
+              gboolean return_latin1)
 {
   gint len = strlen (src);
   GString *result = g_string_sized_new (len);
@@ -746,13 +751,26 @@ sanitize_utf8 (const gchar *src)
       else
        {
          gunichar ch = g_utf8_get_char (p);
-         char buf[7];
-         gint buflen;
          
          if (!((ch < 0x20 && ch != '\t' && ch != '\n') || (ch >= 0x7f && ch < 0xa0)))
            {
-             buflen = g_unichar_to_utf8 (ch, buf);
-             g_string_append_len (result, buf, buflen);
+             if (return_latin1)
+               {
+                 if (ch <= 0xff)
+                   g_string_append_c (result, ch);
+                 else
+                   g_string_append_printf (result,
+                                           ch < 0x10000 ? "\\u%04x" : "\\U%08x",
+                                           ch);
+               }
+             else
+               {
+                 char buf[7];
+                 gint buflen;
+                 
+                 buflen = g_unichar_to_utf8 (ch, buf);
+                 g_string_append_len (result, buf, buflen);
+               }
            }
 
          p = g_utf8_next_char (p);
@@ -779,21 +797,7 @@ sanitize_utf8 (const gchar *src)
 gchar *
 gdk_utf8_to_string_target (const gchar *str)
 {
-  GError *error = NULL;
-  
-  gchar *tmp_str = sanitize_utf8 (str);
-  gchar *result =  g_convert_with_fallback (tmp_str, -1,
-                                           "ISO-8859-1", "UTF-8",
-                                           NULL, NULL, NULL, &error);
-  if (!result)
-    {
-      g_warning ("Error converting from UTF-8 to STRING: %s",
-                error->message);
-      g_error_free (error);
-    }
-  
-  g_free (tmp_str);
-  return result;
+  return sanitize_utf8 (str, TRUE);
 }
 
 /**
@@ -832,7 +836,7 @@ gdk_utf8_to_compound_text_for_display (GdkDisplay  *display,
 
   need_conversion = !g_get_charset (&charset);
 
-  tmp_str = sanitize_utf8 (str);
+  tmp_str = sanitize_utf8 (str, FALSE);
 
   if (need_conversion)
     {