⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdkselection-win32.c

📁 linux下电话本所依赖的一些图形库
💻 C
📖 第 1 页 / 共 3 页
字号:
  g_return_val_if_fail (display == _gdk_display, 0);  GDK_NOTE (DND, (enc_name = gdk_atom_name (encoding),		  g_print ("gdk_text_property_to_text_list: %s %d %.20s %d\n",			   enc_name, format, text, length),		  g_free (enc_name)));  if (!list)    return 0;  if (encoding == GDK_TARGET_STRING)    source_charset = "ISO-8859-1";  else if (encoding == _utf8_string)    source_charset = "UTF-8";  else    source_charset = gdk_atom_name (encoding);      g_get_charset (&charset);  result = g_convert (text, length, charset, source_charset,		      NULL, NULL, &error);  if (!result)    {      g_error_free (error);      return 0;    }  *list = g_new (gchar *, 1);  **list = result;    return 1;}voidgdk_free_text_list (gchar **list){  g_return_if_fail (list != NULL);  g_free (*list);  g_free (list);}static gintmake_list (const gchar  *text,	   gint          length,	   gboolean      latin1,	   gchar      ***list){  GSList *strings = NULL;  gint n_strings = 0;  gint i;  const gchar *p = text;  const gchar *q;  GSList *tmp_list;  GError *error = NULL;  while (p < text + length)    {      gchar *str;            q = p;      while (*q && q < text + length)	q++;      if (latin1)	{	  str = g_convert (p, q - p,			   "UTF-8", "ISO-8859-1",			   NULL, NULL, &error);	  if (!str)	    {	      g_warning ("Error converting selection from STRING: %s",			 error->message);	      g_error_free (error);	    }	}      else	str = g_strndup (p, q - p);      if (str)	{	  strings = g_slist_prepend (strings, str);	  n_strings++;	}      p = q + 1;    }  if (list)    *list = g_new (gchar *, n_strings + 1);  (*list)[n_strings] = NULL;    i = n_strings;  tmp_list = strings;  while (tmp_list)    {      if (list)	(*list)[--i] = tmp_list->data;      else	g_free (tmp_list->data);      tmp_list = tmp_list->next;    }  g_slist_free (strings);  return n_strings;}gint gdk_text_property_to_utf8_list_for_display (GdkDisplay    *display,                                            GdkAtom        encoding,                                            gint           format,                                            const guchar  *text,                                            gint           length,                                            gchar       ***list){  g_return_val_if_fail (text != NULL, 0);  g_return_val_if_fail (length >= 0, 0);  g_return_val_if_fail (display == _gdk_display, 0);  if (encoding == GDK_TARGET_STRING)    {      return make_list ((gchar *)text, length, TRUE, list);    }  else if (encoding == _utf8_string)    {      return make_list ((gchar *)text, length, FALSE, list);    }  else    {      g_warning ("gdk_text_property_to_utf8_list_for_display: encoding %s not handled\n", gdk_atom_name (encoding));      if (list)	*list = NULL;      return 0;    }}gintgdk_string_to_compound_text_for_display (GdkDisplay  *display,					 const gchar *str,					 GdkAtom     *encoding,					 gint        *format,					 guchar     **ctext,					 gint        *length){  g_return_val_if_fail (str != NULL, 0);  g_return_val_if_fail (length >= 0, 0);  g_return_val_if_fail (display == _gdk_display, 0);  GDK_NOTE (DND, g_print ("gdk_string_to_compound_text_for_display: %.20s\n", str));  /* Always fail on Win32. No COMPOUND_TEXT support. */  if (encoding)    *encoding = GDK_NONE;  if (format)    *format = 0;  if (ctext)    *ctext = NULL;  if (length)    *length = 0;  return -1;}gchar *gdk_utf8_to_string_target (const gchar *str){  return _gdk_utf8_to_string_target_internal (str, strlen (str));}gbooleangdk_utf8_to_compound_text_for_display (GdkDisplay  *display,                                       const gchar *str,                                       GdkAtom     *encoding,                                       gint        *format,                                       guchar     **ctext,                                       gint        *length){  g_return_val_if_fail (str != NULL, FALSE);  g_return_val_if_fail (display == _gdk_display, FALSE);  GDK_NOTE (DND, g_print ("gdk_utf8_to_compound_text_for_display: %.20s\n", str));  /* Always fail on Win32. No COMPOUND_TEXT support. */  if (encoding)    *encoding = GDK_NONE;  if (format)    *format = 0;    if (ctext)    *ctext = NULL;  if (length)    *length = 0;  return FALSE;}voidgdk_free_compound_text (guchar *ctext){  /* As we never generate anything claimed to be COMPOUND_TEXT, this   * should never be called. Or if it is called, ctext should be the   * NULL returned for conversions to COMPOUND_TEXT above.   */  g_return_if_fail (ctext == NULL);}voidgdk_win32_selection_add_targets (GdkWindow  *owner,				 GdkAtom     selection,				 gint	     n_targets,				 GdkAtom    *targets){  HWND hwnd;  const gchar *target_name;  guint formatid;  gint i;  GSList *convertable_formats, *format;  gboolean has_set_dib = FALSE, has_real_dib = FALSE;  if (selection != GDK_SELECTION_CLIPBOARD)    return;  if (owner != NULL)    {      if (GDK_WINDOW_DESTROYED (owner))	return;      hwnd = GDK_WINDOW_HWND (owner);    }  if (!API_CALL (OpenClipboard, (hwnd)))    return;  convertable_formats = gdk_pixbuf_get_formats ();  for (i = 0; i < n_targets; ++i)    {      if (targets[i] == _utf8_string)	continue;      target_name = gdk_atom_name (targets[i]);      if (!(formatid = RegisterClipboardFormat (target_name))) {	WIN32_API_FAILED ("RegisterClipboardFormat");	API_CALL (CloseClipboard, ());	return;      }      g_hash_table_replace (_format_atom_table, GINT_TO_POINTER (formatid), targets[i]);      SetClipboardData (formatid, NULL);      /* We should replace the previous image format associated with       * CF_DIB with "image/bmp" if we find "image/bmp", "image/x-bmp"       * or "image/x-MS-bmp" is available.       */      if (!has_real_dib &&	  (!strcmp (target_name, "image/bmp") ||	   !strcmp (target_name, "image/x-bmp") ||	   !strcmp (target_name, "image/x-MS-bmp")))	{	  g_hash_table_replace (_format_atom_table,				GINT_TO_POINTER (CF_DIB),				targets[i]);	  if (!has_set_dib) {	    SetClipboardData (CF_DIB, NULL);	    has_set_dib = TRUE;	  }	  has_real_dib = TRUE;	  continue;	}      for (format = convertable_formats; !has_set_dib && format; format = format->next)	{	  gchar **mime_types =	    gdk_pixbuf_format_get_mime_types ((GdkPixbufFormat *) format->data);	  for (; *mime_types; ++mime_types)	    {	      if (!strcmp (target_name, *mime_types))	        {		  g_hash_table_replace (_format_atom_table,					GINT_TO_POINTER (CF_DIB),					targets[i]);		  SetClipboardData (CF_DIB, NULL);		  has_set_dib = TRUE;		  break;		}	    }	}    }  g_slist_free (convertable_formats);  API_CALL (CloseClipboard, ());}/* Convert from types such as "image/jpg" or "image/png" to DIB using * gdk-pixbuf so that image copied from GTK+ apps can be pasted in * native apps like mspaint.exe */HGLOBAL_gdk_win32_selection_convert_to_dib (HGLOBAL  hdata,				     GdkAtom  target){  GdkPixbufLoader *loader;  GdkPixbuf *pixbuf;  const gchar *target_name;  guchar *ptr;  gchar *bmp_buf;  gsize size;  gboolean ok;  if (!(target_name = gdk_atom_name (target)))    {      GlobalFree (hdata);      return NULL;    }  if (!strcmp (target_name, "image/bmp") ||      !strcmp (target_name, "image/x-bmp") ||      !strcmp (target_name, "image/x-MS-bmp"))    {      /* No conversion is needed, just strip the BITMAPFILEHEADER */      HGLOBAL hdatanew;      size = GlobalSize (hdata) - 1 - sizeof (BITMAPFILEHEADER);      ptr = GlobalLock (hdata);      memmove (ptr, ptr + sizeof (BITMAPFILEHEADER), size);      GlobalUnlock (hdata);      if (!(hdatanew = GlobalReAlloc (hdata, size, 0))) {	WIN32_API_FAILED ("GlobalReAlloc");	GlobalFree (hdata); /* the old hdata is not freed if error */      }      return hdatanew;    }  /* We actually provide image formats -other than- "image/bmp" etc   * and the requestor is either a native Win32 application or a GTK+   * client that requested "image/bmp".   */  if (!(loader = gdk_pixbuf_loader_new_with_mime_type (target_name, NULL)))    {      GlobalFree (hdata);      return NULL;    }  ptr = GlobalLock (hdata);  ok = gdk_pixbuf_loader_write (loader, ptr, GlobalSize (hdata) - 1, NULL) &&       gdk_pixbuf_loader_close (loader, NULL);  GlobalUnlock (hdata);  GlobalFree (hdata);  hdata = NULL;  if (ok && (pixbuf = gdk_pixbuf_loader_get_pixbuf (loader)) != NULL)    g_object_ref (pixbuf);  g_object_unref (loader);  if (ok && gdk_pixbuf_save_to_buffer (pixbuf, &bmp_buf, &size, "bmp", NULL, NULL))    {      size -= sizeof (BITMAPFILEHEADER);      if (!(hdata = GlobalAlloc (GMEM_MOVEABLE, size)))	{	  WIN32_API_FAILED ("GlobalAlloc");	  ok = FALSE;	}      if (ok)	{	  ptr = GlobalLock (hdata);	  memcpy (ptr, bmp_buf + sizeof (BITMAPFILEHEADER), size);	  GlobalUnlock (hdata);	}      g_free (bmp_buf);      g_object_unref (pixbuf);    }  return hdata;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -