Commit 572bb200 authored by Matthias Clasen's avatar Matthias Clasen

Deal with property encoding functions

Move everything dealing with compound text to be X11 specific
Only gdk_text_property_to_utf8_list and gdk_utf8_to_string_target
are kept across backends, so add vfuncs for these.

Also, remove the non-multihead-safe variants of all these.
parent 61104d58
......@@ -197,8 +197,6 @@ gdk_event_type_get_type G_GNUC_CONST
gdk_extension_mode_get_type G_GNUC_CONST
gdk_filter_return_get_type G_GNUC_CONST
gdk_flush
gdk_free_compound_text
gdk_free_text_list
gdk_get_default_root_window
gdk_get_display
gdk_get_display_arg_name
......@@ -323,15 +321,10 @@ gdk_set_show_events
gdk_setting_action_get_type G_GNUC_CONST
gdk_setting_get
gdk_status_get_type G_GNUC_CONST
gdk_string_to_compound_text
gdk_string_to_compound_text_for_display
gdk_synthesize_window_state
gdk_test_render_sync
gdk_test_simulate_button
gdk_test_simulate_key
gdk_text_property_to_text_list
gdk_text_property_to_text_list_for_display
gdk_text_property_to_utf8_list
gdk_text_property_to_utf8_list_for_display
gdk_threads_add_idle
gdk_threads_add_idle_full
......@@ -344,8 +337,6 @@ gdk_threads_init
gdk_threads_leave
gdk_threads_set_lock_functions
gdk_unicode_to_keyval G_GNUC_CONST
gdk_utf8_to_compound_text
gdk_utf8_to_compound_text_for_display
gdk_utf8_to_string_target
gdk_visibility_state_get_type G_GNUC_CONST
gdk_visual_get_best
......@@ -539,7 +530,12 @@ gdk_x11_display_get_xdisplay
gdk_x11_display_grab
gdk_x11_display_set_cursor_theme
gdk_x11_display_set_startup_notification_id
gdk_x11_display_string_to_compound_text
gdk_x11_display_text_property_to_text_list
gdk_x11_display_ungrab
gdk_x11_display_utf8_to_compound_text
gdk_x11_free_compound_text
gdk_x11_free_text_list
gdk_x11_get_default_root_xwindow
gdk_x11_get_default_screen
gdk_x11_get_default_xdisplay
......
......@@ -220,6 +220,15 @@ struct _GdkDisplayClass
GdkAtom target,
guint32 time);
gint (*text_property_to_utf8_list) (GdkDisplay *display,
GdkAtom encoding,
gint format,
const guchar *text,
gint length,
gchar ***list);
gchar * (*utf8_to_string_target) (GdkDisplay *display,
const gchar *text);
/* Signals */
void (*closed) (GdkDisplay *display,
gboolean is_error);
......
......@@ -54,83 +54,39 @@ typedef enum
GdkAtom gdk_atom_intern (const gchar *atom_name,
gboolean only_if_exists);
gboolean only_if_exists);
GdkAtom gdk_atom_intern_static_string (const gchar *atom_name);
gchar* gdk_atom_name (GdkAtom atom);
gboolean gdk_property_get (GdkWindow *window,
GdkAtom property,
GdkAtom type,
gulong offset,
gulong length,
gint pdelete,
GdkAtom *actual_property_type,
gint *actual_format,
gint *actual_length,
guchar **data);
GdkAtom property,
GdkAtom type,
gulong offset,
gulong length,
gint pdelete,
GdkAtom *actual_property_type,
gint *actual_format,
gint *actual_length,
guchar **data);
void gdk_property_change (GdkWindow *window,
GdkAtom property,
GdkAtom type,
gint format,
GdkPropMode mode,
const guchar *data,
gint nelements);
GdkAtom property,
GdkAtom type,
gint format,
GdkPropMode mode,
const guchar *data,
gint nelements);
void gdk_property_delete (GdkWindow *window,
GdkAtom property);
GdkAtom property);
#ifndef GDK_MULTIHEAD_SAFE
gint gdk_text_property_to_text_list (GdkAtom encoding,
gint format,
const guchar *text,
gint length,
gchar ***list);
gint gdk_text_property_to_utf8_list (GdkAtom encoding,
gint format,
const guchar *text,
gint length,
gchar ***list);
gboolean gdk_utf8_to_compound_text (const gchar *str,
GdkAtom *encoding,
gint *format,
guchar **ctext,
gint *length);
gint gdk_string_to_compound_text (const gchar *str,
GdkAtom *encoding,
gint *format,
guchar **ctext,
gint *length);
#endif /* GDK_MULTIHEAD_SAFE */
gint gdk_text_property_to_utf8_list_for_display (GdkDisplay *display,
GdkAtom encoding,
gint format,
const guchar *text,
gint length,
gchar ***list);
gint gdk_text_property_to_text_list_for_display (GdkDisplay *display,
GdkAtom encoding,
gint format,
const guchar *text,
gint length,
gchar ***list);
gint gdk_text_property_to_utf8_list_for_display (GdkDisplay *display,
GdkAtom encoding,
gint format,
const guchar *text,
gint length,
gchar ***list);
gchar *gdk_utf8_to_string_target (const gchar *str);
gint gdk_string_to_compound_text_for_display (GdkDisplay *display,
const gchar *str,
GdkAtom *encoding,
gint *format,
guchar **ctext,
gint *length);
gboolean gdk_utf8_to_compound_text_for_display (GdkDisplay *display,
const gchar *str,
GdkAtom *encoding,
gint *format,
guchar **ctext,
gint *length);
void gdk_free_text_list (gchar **list);
void gdk_free_compound_text (guchar *ctext);
gchar *gdk_utf8_to_string_target (const gchar *str);
G_END_DECLS
......
......@@ -137,116 +137,6 @@ gdk_selection_send_notify (GdkNativeWindow requestor,
target, property, time);
}
/**
* gdk_text_property_to_text_list:
* @encoding: an atom representing the encoding. The most common
* values for this are <literal>STRING</literal>,
* or <literal>COMPOUND_TEXT</literal>. This is
* value used as the type for the property.
* @format: the format of the property.
* @text: the text data.
* @length: the length of the property, in items.
* @list: location to store a terminated array of strings
* in the encoding of the current locale. This
* array should be freed using gdk_free_text_list().
*
* Converts a text string from the encoding as it is stored in
* a property into an array of strings in the encoding of
* the current local. (The elements of the array represent
* the nul-separated elements of the original text string.)
*
* Returns: the number of strings stored in @list, or 0,
* if the conversion failed.
*/
gint
gdk_text_property_to_text_list (GdkAtom encoding,
gint format,
const guchar *text,
gint length,
gchar ***list)
{
return gdk_text_property_to_text_list_for_display (gdk_display_get_default (),
encoding, format, text, length, list);
}
/**
* gdk_text_property_to_utf8_list:
* @encoding: an atom representing the encoding of the text
* @format: the format of the property
* @text: the text to convert
* @length: the length of @text, in bytes
* @list: (allow-none): location to store the list of strings or %NULL. The
* list should be freed with g_strfreev().
*
* Convert a text property in the giving encoding to
* a list of UTF-8 strings.
*
* Return value: the number of strings in the resulting
* list.
**/
gint
gdk_text_property_to_utf8_list (GdkAtom encoding,
gint format,
const guchar *text,
gint length,
gchar ***list)
{
return gdk_text_property_to_utf8_list_for_display (gdk_display_get_default (),
encoding, format, text, length, list);
}
/**
* gdk_string_to_compound_text:
* @str: a nul-terminated string.
* @encoding: location to store the encoding atom (to be used as
* the type for the property).
* @format: location to store the format for the property.
* @ctext: location to store newly allocated data for the property.
* @length: location to store the length of @ctext in items.
*
* Converts 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.
*/
gint
gdk_string_to_compound_text (const gchar *str,
GdkAtom *encoding,
gint *format,
guchar **ctext,
gint *length)
{
return gdk_string_to_compound_text_for_display (gdk_display_get_default (),
str, encoding, format,
ctext, length);
}
/**
* gdk_utf8_to_compound_text:
* @str: a UTF-8 string
* @encoding: location to store resulting encoding
* @format: location to store format of the result
* @ctext: location to store the data of the result
* @length: location to store the length of the data
* stored in @ctext
*
* Convert from UTF-8 to compound text.
*
* Return value: %TRUE if the conversion succeeded, otherwise
* false.
**/
gboolean
gdk_utf8_to_compound_text (const gchar *str,
GdkAtom *encoding,
gint *format,
guchar **ctext,
gint *length)
{
return gdk_utf8_to_compound_text_for_display (gdk_display_get_default (),
str, encoding, format,
ctext, length);
}
/**
* gdk_selection_owner_set_for_display:
* @display: the #GdkDisplay
......@@ -386,3 +276,58 @@ gdk_selection_convert (GdkWindow *requestor,
GDK_DISPLAY_GET_CLASS (display)
->convert_selection (display, requestor, selection, target, time);
}
/**
* gdk_text_property_to_utf8_list_for_display:
* @display: a #GdkDisplay
* @encoding: an atom representing the encoding of the text
* @format: the format of the property
* @text: the text to convert
* @length: the length of @text, in bytes
* @list: location to store the list of strings or %NULL. The
* list should be freed with g_strfreev().
*
* Converts a text property in the given encoding to
* a list of UTF-8 strings.
*
* Return value: the number of strings in the resulting list
*
* Since: 2.2
*/
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 (GDK_IS_DISPLAY (display), 0);
return GDK_DISPLAY_GET_CLASS (display)
->text_property_to_utf8_list (display, encoding, format, text, length, list);
}
/**
* gdk_utf8_to_string_target:
* @str: a UTF-8 string
*
* Converts an UTF-8 string into the best possible representation
* as a STRING. The representation of characters not in STRING
* is not specified; it may be as pseudo-escape sequences
* \x{ABCD}, or it may be in some other form of approximation.
*
* Return value: the newly-allocated string, or %NULL if the
* conversion failed. (It should not fail for
* any properly formed UTF-8 string unless system
* limits like memory or file descriptors are exceeded.)
**/
gchar *
gdk_utf8_to_string_target (const gchar *str)
{
GdkDisplay *display = gdk_display_get_default ();
return GDK_DISPLAY_GET_CLASS (display)->utf8_to_string_target (display, str);
}
......@@ -2765,4 +2765,6 @@ _gdk_display_x11_class_init (GdkDisplayX11Class * class)
display_class->send_selection_notify = _gdk_x11_display_send_selection_notify;
display_class->get_selection_property = _gdk_x11_display_get_selection_property;
display_class->convert_selection = _gdk_x11_display_convert_selection;
display_class->text_property_to_utf8_list = _gdk_x11_display_text_property_to_utf8_list;
display_class->utf8_to_string_target = _gdk_x11_display_utf8_to_string_target;
}
......@@ -213,6 +213,15 @@ void _gdk_x11_display_convert_selection (GdkDisplay *display,
GdkAtom target,
guint32 time);
gint _gdk_x11_display_text_property_to_utf8_list (GdkDisplay *display,
GdkAtom encoding,
gint format,
const guchar *text,
gint length,
gchar ***list);
gchar * _gdk_x11_display_utf8_to_string_target (GdkDisplay *displayt,
const gchar *str);
void _gdk_x11_device_check_extension_events (GdkDevice *device);
GdkDeviceManager *_gdk_x11_device_manager_new (GdkDisplay *display);
......
This diff is collapsed.
......@@ -2231,10 +2231,10 @@ set_text_property (GdkDisplay *display,
else
{
GdkAtom gdk_type;
gdk_utf8_to_compound_text_for_display (display,
utf8_str, &gdk_type, &prop_format,
(guchar **)&prop_text, &prop_length);
gdk_x11_display_utf8_to_compound_text (display,
utf8_str, &gdk_type, &prop_format,
(guchar **)&prop_text, &prop_length);
prop_type = gdk_x11_atom_to_xatom_for_display (display, gdk_type);
is_compound_text = TRUE;
}
......@@ -2249,7 +2249,7 @@ set_text_property (GdkDisplay *display,
prop_length);
if (is_compound_text)
gdk_free_compound_text ((guchar *)prop_text);
gdk_x11_free_compound_text ((guchar *)prop_text);
else
g_free (prop_text);
}
......
......@@ -231,6 +231,30 @@ GdkWindow *gdk_x11_window_foreign_new_for_display (GdkDisplay *display,
GdkWindow *gdk_x11_window_lookup_for_display (GdkDisplay *display,
Window window);
gint gdk_x11_display_text_property_to_text_list (GdkDisplay *display,
GdkAtom encoding,
gint format,
const guchar *text,
gint length,
gchar ***list);
void gdk_x11_free_text_list (gchar **list);
gint gdk_x11_display_string_to_compound_text (GdkDisplay *display,
const gchar *str,
GdkAtom *encoding,
gint *format,
guchar **ctext,
gint *length);
gboolean gdk_x11_display_utf8_to_compound_text (GdkDisplay *display,
const gchar *str,
GdkAtom *encoding,
gint *format,
guchar **ctext,
gint *length);
void gdk_x11_free_compound_text (guchar *ctext);
G_END_DECLS
#endif /* __GDK_X_H__ */
......@@ -1318,18 +1318,22 @@ selection_set_compound_text (GtkSelectionData *selection_data,
gint format;
gint new_length;
gboolean result = FALSE;
tmp = g_strndup (str, len);
if (gdk_utf8_to_compound_text_for_display (selection_data->display, tmp,
&encoding, &format, &text, &new_length))
#ifdef GDK_WINDOWING_X11
if (GDK_IS_DISPLAY_X11 (selection_data->display))
{
gtk_selection_data_set (selection_data, encoding, format, text, new_length);
gdk_free_compound_text (text);
result = TRUE;
}
tmp = g_strndup (str, len);
if (gdk_x11_display_utf8_to_compound_text (selection_data->display, tmp,
&encoding, &format, &text, &new_length))
{
gtk_selection_data_set (selection_data, encoding, format, text, new_length);
gdk_x11_free_compound_text (text);
g_free (tmp);
result = TRUE;
}
g_free (tmp);
}
#endif
return result;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment