]> Pileus Git - ~andy/gtk/blob - gtk/gtkselection.h
Add infrastructure for copy/paste and DND of rich text for GtkTextBuffer.
[~andy/gtk] / gtk / gtkselection.h
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 #ifndef __GTK_SELECTION_H__
28 #define __GTK_SELECTION_H__
29
30
31 #include <gdk/gdk.h>
32 #include <gtk/gtkenums.h>
33 #include <gtk/gtkwidget.h>
34 #include <gtk/gtktextiter.h>
35
36 G_BEGIN_DECLS
37
38 typedef struct _GtkTargetList    GtkTargetList;
39 typedef struct _GtkTargetEntry   GtkTargetEntry;
40
41 #define GTK_TYPE_SELECTION_DATA (gtk_selection_data_get_type ())
42 #define GTK_TYPE_TARGET_LIST    (gtk_target_list_get_type ())
43
44 /* The contents of a selection are returned in a GtkSelectionData
45  * structure. selection/target identify the request.  type specifies
46  * the type of the return; if length < 0, and the data should be
47  * ignored. This structure has object semantics - no fields should be
48  * modified directly, they should not be created directly, and
49  * pointers to them should not be stored beyond the duration of a
50  * callback. (If the last is changed, we'll need to add reference
51  * counting.) The time field gives the timestamp at which the data was
52  * sent.
53  */
54
55 struct _GtkSelectionData
56 {
57   GdkAtom       selection;
58   GdkAtom       target;
59   GdkAtom       type;
60   gint          format;
61   guchar       *data;  
62   gint          length;
63   GdkDisplay   *display;
64 };
65
66 struct _GtkTargetEntry {
67   gchar *target;
68   guint  flags;
69   guint  info;
70 };
71
72 /* These structures not public, and are here only for the convenience of
73  * gtkdnd.c 
74  */
75
76 typedef struct _GtkTargetPair GtkTargetPair;
77
78 /* This structure is a list of destinations, and associated guint id's */
79 struct _GtkTargetList {
80   GList *list;
81   guint ref_count;
82 };
83
84 struct _GtkTargetPair {
85   GdkAtom   target;
86   guint     flags;
87   guint     info;
88 };
89
90 GtkTargetList *gtk_target_list_new       (const GtkTargetEntry *targets,
91                                           guint                 ntargets);
92 GtkTargetList *gtk_target_list_ref       (GtkTargetList  *list);
93 void           gtk_target_list_unref     (GtkTargetList  *list);
94 void           gtk_target_list_add       (GtkTargetList  *list,
95                                           GdkAtom         target,
96                                           guint           flags,
97                                           guint           info);
98 void           gtk_target_list_add_text_targets      (GtkTargetList  *list,
99                                                       guint           info);
100 void           gtk_target_list_add_rich_text_targets (GtkTargetList  *list,
101                                                       guint           info,
102                                                       gboolean        deserializable,
103                                                       GtkTextBuffer  *buffer);
104 void           gtk_target_list_add_image_targets     (GtkTargetList  *list,
105                                                       guint           info,
106                                                       gboolean        writable);
107 void           gtk_target_list_add_uri_targets       (GtkTargetList  *list,
108                                                       guint           info);
109 void           gtk_target_list_add_table (GtkTargetList        *list,
110                                           const GtkTargetEntry *targets,
111                                           guint                 ntargets);
112 void           gtk_target_list_remove    (GtkTargetList  *list,
113                                           GdkAtom         target);
114 gboolean       gtk_target_list_find      (GtkTargetList  *list,
115                                           GdkAtom         target,
116                                           guint          *info);
117
118 GtkTargetEntry * gtk_target_table_new_from_list (GtkTargetList  *list,
119                                                  gint           *n_targets);
120 void             gtk_target_table_free          (GtkTargetEntry *targets,
121                                                  gint            n_targets);
122
123 /* Public interface */
124
125 gboolean gtk_selection_owner_set             (GtkWidget  *widget,
126                                               GdkAtom     selection,
127                                               guint32     time_);
128 gboolean gtk_selection_owner_set_for_display (GdkDisplay *display,
129                                               GtkWidget  *widget,
130                                               GdkAtom     selection,
131                                               guint32     time_);
132
133 void     gtk_selection_add_target    (GtkWidget            *widget,
134                                       GdkAtom               selection,
135                                       GdkAtom               target,
136                                       guint                 info);
137 void     gtk_selection_add_targets   (GtkWidget            *widget,
138                                       GdkAtom               selection,
139                                       const GtkTargetEntry *targets,
140                                       guint                 ntargets);
141 void     gtk_selection_clear_targets (GtkWidget            *widget,
142                                       GdkAtom               selection);
143 gboolean gtk_selection_convert       (GtkWidget            *widget,
144                                       GdkAtom               selection,
145                                       GdkAtom               target,
146                                       guint32               time_);
147 void     gtk_selection_data_set      (GtkSelectionData     *selection_data,
148                                       GdkAtom               type,
149                                       gint                  format,
150                                       const guchar         *data,
151                                       gint                  length);
152 gboolean gtk_selection_data_set_text (GtkSelectionData     *selection_data,
153                                       const gchar          *str,
154                                       gint                  len);
155 guchar * gtk_selection_data_get_text (GtkSelectionData     *selection_data);
156 gboolean gtk_selection_data_set_pixbuf   (GtkSelectionData  *selection_data,
157                                           GdkPixbuf         *pixbuf);
158 GdkPixbuf *gtk_selection_data_get_pixbuf (GtkSelectionData  *selection_data);
159 gboolean gtk_selection_data_set_uris (GtkSelectionData     *selection_data,
160                                       gchar               **uris);
161 gchar  **gtk_selection_data_get_uris (GtkSelectionData     *selection_data);
162
163 gboolean gtk_selection_data_get_targets          (GtkSelectionData  *selection_data,
164                                                   GdkAtom          **targets,
165                                                   gint              *n_atoms);
166 gboolean gtk_selection_data_targets_include_text (GtkSelectionData  *selection_data);
167 gboolean gtk_selection_data_targets_include_rich_text (GtkSelectionData *selection_data,
168                                                        GtkTextBuffer    *buffer);
169 gboolean gtk_selection_data_targets_include_image (GtkSelectionData  *selection_data,
170                                                    gboolean           writable);
171 gboolean gtk_selection_data_targets_include_uri  (GtkSelectionData  *selection_data);
172 gboolean gtk_targets_include_text                (GdkAtom       *targets,
173                                                   gint           n_targets);
174 gboolean gtk_targets_include_rich_text           (GdkAtom       *targets,
175                                                   gint           n_targets,
176                                                   GtkTextBuffer *buffer);
177 gboolean gtk_targets_include_image               (GdkAtom       *targets,
178                                                   gint           n_targets,
179                                                   gboolean       writable);
180 gboolean gtk_targets_include_uri                 (GdkAtom       *targets,
181                                                   gint           n_targets);
182
183 /* Called when a widget is destroyed */
184
185 void gtk_selection_remove_all      (GtkWidget *widget);
186
187 /* Event handlers */
188 #if !defined(GTK_DISABLE_DEPRECATED) || defined (GTK_COMPILATION)
189 gboolean gtk_selection_clear              (GtkWidget         *widget,
190                                            GdkEventSelection *event);
191 #endif
192 gboolean _gtk_selection_request           (GtkWidget         *widget,
193                                            GdkEventSelection *event);
194 gboolean _gtk_selection_incr_event        (GdkWindow         *window,
195                                            GdkEventProperty  *event);
196 gboolean _gtk_selection_notify            (GtkWidget         *widget,
197                                            GdkEventSelection *event);
198 gboolean _gtk_selection_property_notify   (GtkWidget         *widget,
199                                            GdkEventProperty  *event);
200
201 GType             gtk_selection_data_get_type (void) G_GNUC_CONST;
202 GtkSelectionData *gtk_selection_data_copy     (GtkSelectionData *data);
203 void              gtk_selection_data_free     (GtkSelectionData *data);
204
205 GType             gtk_target_list_get_type    (void) G_GNUC_CONST;
206
207 G_END_DECLS
208
209 #endif /* __GTK_SELECTION_H__ */