Re: Convenience APIs for selections



On Thu, Apr 15, 2004 at 12:32:42PM -0500, Federico Mena Quintero wrote:
> 
> /* Sets "application/x-color" from the 16-bit RGB values */
> void gtk_selection_data_set_color (GtkSelectionData *data,
> 				   const GdkColor   *color);
> /* Parses from "application/x-color", handling old KDE's broken
>  * colors.  Returns an error if the selection type doesn't have
>  * the right atom or if parsing fails.
>  */
> gboolean gtk_selection_data_get_color (GtkSelectionData *data,
> 				       GdkColor         *color,
> 				       GError          **error);

    * type: application/x-color
    * format::16
    * data[0]: red
    * data[1]: green
    * data[2]: blue
    * data[3]: opacity
 
Looks like we'd want
    GdkColor *color, guint16 *alpha

> /* Parses "text/uri-list".  Returns a list of char *.  Returns an
>  * error if the selection type doesn't have the right atom
>  * or if parsing fails.
>  */
> gboolean gtk_selection_data_get_uri_list (GtkSelectionData *data,
> 					  GList           **uri_list,
> 					  GError          **error);

Docs should be clear on 'char *' vs 'const char *' who needs to free
those strings ?
 
>   if (gtk_selection_data_is_color (selection_data))
>     {
>       GdkColor color;
>       GError *error;
> 
>       error = NULL;
>       if (!gtk_selection_data_get_color (selection_data, &color, &error))
>         {
>           g_print ("broken color: %s", error->message);
>           g_error_free (error);
>         }
>       else
>         do_something_with_color (&color);
>     }
Why not combine the two operations
    if (gtk_selection_data_is_color (selection_data, &color, &alpha))
	do_stuff
why should an application care if something is sending invalid
clipboard data ?  Let the toolkit handle it.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]