static VALUE rg_m_text_property_to_utf8_list(int argc, VALUE *argv, G_GNUC_UNUSED VALUE self) { gint num, i; gchar** list; VALUE ret = Qnil; if (argc == 3) { VALUE encoding, format, text; rb_scan_args(argc, argv, "30", &encoding, &format, &text); StringValue(text); num = gdk_text_property_to_utf8_list(RVAL2ATOM(encoding), NUM2INT(format), (const guchar*)RVAL2CSTR(text), RSTRING_LEN(text), &list); } else { #if GTK_CHECK_VERSION(2,2,0) VALUE display, encoding, format, text; rb_scan_args(argc, argv, "40", &display, &encoding, &format, &text); StringValue(text); num = gdk_text_property_to_utf8_list_for_display(GDK_DISPLAY_OBJECT(RVAL2GOBJ(display)), RVAL2ATOM(encoding), NUM2INT(format), (const guchar*)RVAL2CSTR(text), RSTRING_LEN(text), &list); #else VALUE encoding, format, text; rb_scan_args(argc, argv, "30", &encoding, &format, &text); StringValue(text); rb_warn("Gdk::Property.text_property_to_utf8_list: Not supported arguments in GTK+-2.0.x."); num = gdk_text_property_to_utf8_list(RVAL2ATOM(encoding), NUM2INT(format), (const guchar*)RVAL2CSTR(text), RSTRING_LEN(text), &list); #endif } ret = rb_ary_new2(num); for (i =0; i < num; i++) { rb_ary_push(ret, CSTR2RVAL(list[i])); } g_strfreev(list); return ret; }
static char* text_property_to_utf8 (const XTextProperty *prop) { char **list; int count; char *retval; ENTER; list = NULL; count = gdk_text_property_to_utf8_list (gdk_x11_xatom_to_atom (prop->encoding), prop->format, prop->value, prop->nitems, &list); DBG("count=%d\n", count); if (count == 0) return NULL; retval = list[0]; list[0] = g_strdup (""); /* something to free */ g_strfreev (list); RET(retval); }
char* meta_text_property_to_utf8 (Display *xdisplay, const XTextProperty *prop) { char **list; int count; char *retval; list = NULL; count = gdk_text_property_to_utf8_list (gdk_x11_xatom_to_atom (prop->encoding), prop->format, prop->value, prop->nitems, &list); if (count == 0) retval = NULL; else { retval = list[0]; list[0] = g_strdup (""); /* something to free */ } g_strfreev (list); return retval; }
nsresult compzillaWindow::GetUTF8StringProperty (Atom prop, nsACString& utf8Value) { SPEW ("GetUTF8StringProperty this=%p, prop=%s\n", this, XGetAtomName (mDisplay, prop)); Atom actual_type; int format; unsigned long nitems; unsigned long bytes_after_return; unsigned char *data; if (XGetWindowProperty (mDisplay, mWindow, prop, 0, BUFSIZ, false, AnyPropertyType, &actual_type, &format, &nitems, &bytes_after_return, &data) != Success || format == None) { SPEW (" + (Not Found)\n"); return NS_ERROR_FAILURE; } if (actual_type == atoms.x.UTF8_STRING) { utf8Value = (char*)data; } else if (actual_type == XA_STRING) { char **list = NULL; int count; count = gdk_text_property_to_utf8_list (gdk_x11_xatom_to_atom (actual_type), format, data, nitems, &list); if (count == 0) { XFree (data); return NS_ERROR_FAILURE; } utf8Value = list[0]; g_strfreev (list); } else { WARNING ("invalid type for string property '%s': '%s'\n", XGetAtomName (mDisplay, prop), XGetAtomName (mDisplay, actual_type)); XFree (data); return NS_ERROR_FAILURE; } XFree (data); return NS_OK; }
void selection_received (GtkWidget *widget, GtkSelectionData *data) { gchar *str; gchar **list; gint count; LOG(LOG_DEBUG, "IN : selection_received()"); if((data == NULL) || (data->data == NULL) || (data->length < 0)){ LOG(LOG_DEBUG, "no data"); goto END; } // No conversion required for STRING type. if (data->type == GDK_TARGET_STRING){ str = g_strndup(data->data, data->length); // Convert to UTF-8 for COMPOUND_TEXT type. } else if ((data->type == gdk_atom_intern ("COMPOUND_TEXT", FALSE)) || (data->type == gdk_atom_intern ("TEXT", FALSE))){ count = gdk_text_property_to_utf8_list (data->type, data->format, data->data, data->length, &list); if((count == 0) || (list == NULL)){ goto END; } str = g_strdup(list[0]); g_strfreev(list); } else { LOG(LOG_DEBUG, "unknown data type"); goto END; } remove_space(str); search_selected(str); g_free(str); END: if(selection_mode != SELECTION_DO_NOTHING){ auto_lookup_start(); } LOG(LOG_DEBUG, "OUT : selection_received()"); return; }
/* title_get_text_property */ static int _title_get_text_property(Title * title, Window window, Atom property, char ** ret) { int res; XTextProperty text; GdkAtom atom; int cnt; char ** list; int i; #ifdef DEBUG fprintf(stderr, "DEBUG: %s(title, window, %lu)\n", __func__, property); #endif gdk_error_trap_push(); res = XGetTextProperty(GDK_DISPLAY_XDISPLAY(title->display), window, &text, property); if(gdk_error_trap_pop() != 0 || res == 0) return 1; atom = gdk_x11_xatom_to_atom(text.encoding); #if GTK_CHECK_VERSION(2, 24, 0) cnt = gdk_x11_display_text_property_to_text_list(title->display, atom, text.format, text.value, text.nitems, &list); #else cnt = gdk_text_property_to_utf8_list(atom, text.format, text.value, text.nitems, &list); #endif if(cnt > 0) { *ret = list[0]; for(i = 1; i < cnt; i++) g_free(list[i]); g_free(list); } else *ret = NULL; if(text.value != NULL) XFree(text.value); return 0; }