]> Pileus Git - ~andy/gtk/blob - docs/reference/gtk/tmpl/gtkimage.sgml
Document GdkScreen.
[~andy/gtk] / docs / reference / gtk / tmpl / gtkimage.sgml
1 <!-- ##### SECTION Title ##### -->
2 GtkImage
3
4 <!-- ##### SECTION Short_Description ##### -->
5 A widget displaying an image
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
9 The #GtkImage widget displays an image. Various kinds of object 
10 can be displayed as an image; most typically, you would load a 
11 #GdkPixbuf ("pixel buffer") from a file, and then display that. 
12 There's a convenience function to do this, gtk_image_new_from_file(),
13 used as follows:
14 <informalexample><programlisting>
15   GtkWidget *image;
16   image = gtk_image_new_from_file ("myfile.png");
17 </programlisting></informalexample>
18 If the file isn't loaded successfully, the image will contain a
19 "broken image" icon similar to that used in many web browsers.
20 If you want to handle errors in loading the file yourself, 
21 for example by displaying an error message, then load the image with
22 gdk_pixbuf_new_from_file(), then create the #GtkImage with 
23 gtk_image_new_from_pixbuf().
24 </para>
25 <para>
26 The image file may contain an animation, if so the #GtkImage will 
27 display an animation (#GdkPixbufAnimation) instead of a static image.
28 </para>
29 <para>
30 #GtkImage is a subclass of #GtkMisc, which implies that you can 
31 align it (center, left, right) and add padding to it, using 
32 #GtkMisc methods.
33 </para>
34 <para>
35 #GtkImage is a "no window" widget (has no #GdkWindow of its own), 
36 so by default does not receive events. If you want to receive events
37 on the image, such as button clicks, place the image inside a 
38 #GtkEventBox, then connect to the event signals on the event box.
39 <example>
40 <title>Handling button press events on a 
41 <structname>GtkImage</structname>.</title>
42 <programlisting>
43   static void
44   button_press_callback (GtkWidget      *event_box, 
45                          GdkEventButton *event,
46                          gpointer        data)
47   {
48     g_print ("Event box clicked at coordinates &percent;d,&percent;d\n", 
49              event->x, event->y);
50
51     /* Returning TRUE means we handled the event, so the signal 
52      * emission should be stopped (don't call any further 
53      * callbacks that may be connected). Return FALSE
54      * to continue invoking callbacks.
55      */
56     return TRUE;
57   }
58
59   static GtkWidget*
60   create_image (void)
61   {
62     GtkWidget *image;
63     GtkWidget *event_box;
64
65     image = gtk_image_new_from_file ("myfile.png");
66
67     event_box = gtk_event_box_new (<!>);
68
69     gtk_container_add (GTK_CONTAINER (event_box), image);
70
71     g_signal_connect (G_OBJECT (event_box), 
72                       "button_press_event",
73                       G_CALLBACK (button_press_callback),
74                       image);
75
76     return image;
77   }
78 </programlisting>
79 </example>
80 </para>
81 <para>
82 When handling events on the event box, keep in mind that coordinates
83 in the image may be different from event box coordinates due to 
84 the alignment and padding settings on the image (see #GtkMisc). 
85 The simplest way to solve this is to set the alignment to 0.0
86 (left/top), and set the padding to zero. Then the origin of 
87 the image will be the same as the origin of the event box.
88 </para>
89
90 <para>
91 Sometimes an application will want to avoid depending on external data
92 files, such as image files. GTK+ comes with a program to avoid this,
93 called <application>gdk-pixbuf-csource</application>. This program
94 allows you to convert an image into a C variable declaration, which
95 can then be loaded into a #GdkPixbuf using
96 gdk_pixbuf_new_from_inline().
97 </para>
98
99 <!-- ##### SECTION See_Also ##### -->
100 <para>
101 #GdkPixbuf
102 </para>
103
104 <!-- ##### STRUCT GtkImage ##### -->
105 <para>
106 This struct contain private data only and should be accessed by the functions
107 below.
108 </para>
109
110
111 <!-- ##### ENUM GtkImageType ##### -->
112 <para>
113 Describes the image data representation used by a #GtkImage. If you
114 want to get the image from the widget, you can only get the
115 currently-stored representation. e.g.  if the
116 gtk_image_get_storage_type() returns #GTK_IMAGE_PIXBUF, then you can
117 call gtk_image_get_pixbuf() but not gtk_image_get_stock().  For empty
118 images, you can request any storage type (call any of the "get"
119 functions), but they will all return %NULL values.
120 </para>
121
122 @GTK_IMAGE_EMPTY: there is no image displayed by the widget
123 @GTK_IMAGE_PIXMAP: the widget contains a #GdkPixmap
124 @GTK_IMAGE_IMAGE: the widget contains a #GdkImage
125 @GTK_IMAGE_PIXBUF: the widget contains a #GdkPixbuf
126 @GTK_IMAGE_STOCK: the widget contains a stock icon name
127 @GTK_IMAGE_ICON_SET: the widget contains a #GtkIconSet
128 @GTK_IMAGE_ANIMATION: the widget contains a #GdkPixbufAnimation
129
130 <!-- ##### FUNCTION gtk_image_get_icon_set ##### -->
131 <para>
132
133 </para>
134
135 @image: 
136 @icon_set: 
137 @size: 
138
139
140 <!-- ##### FUNCTION gtk_image_get_image ##### -->
141 <para>
142
143 </para>
144
145 @image: 
146 @gdk_image: 
147 @mask: 
148
149
150 <!-- ##### FUNCTION gtk_image_get_pixbuf ##### -->
151 <para>
152
153 </para>
154
155 @image: 
156 @Returns: 
157
158
159 <!-- ##### FUNCTION gtk_image_get_pixmap ##### -->
160 <para>
161
162 </para>
163
164 @image: 
165 @pixmap: 
166 @mask: 
167
168
169 <!-- ##### FUNCTION gtk_image_get_stock ##### -->
170 <para>
171
172 </para>
173
174 @image: 
175 @stock_id: 
176 @size: 
177
178
179 <!-- ##### FUNCTION gtk_image_get_animation ##### -->
180 <para>
181
182 </para>
183
184 @image: 
185 @Returns: 
186
187
188 <!-- ##### FUNCTION gtk_image_get_storage_type ##### -->
189 <para>
190
191 </para>
192
193 @image: 
194 @Returns: 
195
196
197 <!-- ##### FUNCTION gtk_image_new_from_file ##### -->
198 <para>
199
200 </para>
201
202 @filename: 
203 @Returns: 
204
205
206 <!-- ##### FUNCTION gtk_image_new_from_icon_set ##### -->
207 <para>
208
209 </para>
210
211 @icon_set: 
212 @size: 
213 @Returns: 
214
215
216 <!-- ##### FUNCTION gtk_image_new_from_image ##### -->
217 <para>
218
219 </para>
220
221 @image: 
222 @mask: 
223 @Returns: 
224
225
226 <!-- ##### FUNCTION gtk_image_new_from_pixbuf ##### -->
227 <para>
228
229 </para>
230
231 @pixbuf: 
232 @Returns: 
233
234
235 <!-- ##### FUNCTION gtk_image_new_from_pixmap ##### -->
236 <para>
237
238 </para>
239
240 @pixmap: 
241 @mask: 
242 @Returns: 
243
244
245 <!-- ##### FUNCTION gtk_image_new_from_stock ##### -->
246 <para>
247
248 </para>
249
250 @stock_id: 
251 @size: 
252 @Returns: 
253
254
255 <!-- ##### FUNCTION gtk_image_new_from_animation ##### -->
256 <para>
257
258 </para>
259
260 @animation: 
261 @Returns: 
262
263
264 <!-- ##### FUNCTION gtk_image_set_from_file ##### -->
265 <para>
266
267 </para>
268
269 @image: 
270 @filename: 
271
272
273 <!-- ##### FUNCTION gtk_image_set_from_icon_set ##### -->
274 <para>
275
276 </para>
277
278 @image: 
279 @icon_set: 
280 @size: 
281
282
283 <!-- ##### FUNCTION gtk_image_set_from_image ##### -->
284 <para>
285
286 </para>
287
288 @image: 
289 @gdk_image: 
290 @mask: 
291
292
293 <!-- ##### FUNCTION gtk_image_set_from_pixbuf ##### -->
294 <para>
295
296 </para>
297
298 @image: 
299 @pixbuf: 
300
301
302 <!-- ##### FUNCTION gtk_image_set_from_pixmap ##### -->
303 <para>
304
305 </para>
306
307 @image: 
308 @pixmap: 
309 @mask: 
310
311
312 <!-- ##### FUNCTION gtk_image_set_from_stock ##### -->
313 <para>
314
315 </para>
316
317 @image: 
318 @stock_id: 
319 @size: 
320
321
322 <!-- ##### FUNCTION gtk_image_set_from_animation ##### -->
323 <para>
324
325 </para>
326
327 @image: 
328 @animation: 
329
330
331 <!-- ##### FUNCTION gtk_image_new ##### -->
332 <para>
333
334 </para>
335
336 @Returns: the #GtkImage
337 <!-- # Unused Parameters # -->
338 @val: 
339 @mask: a #GdkBitmap that indicates which parts of the image should be transparent.
340
341
342 <!-- ##### FUNCTION gtk_image_set ##### -->
343 <para>
344 Sets the #GtkImage.
345 </para>
346
347 @image: a #GdkPixmap
348 @val: 
349 @mask: a #GdkBitmap that indicates which parts of the image should be transparent.
350
351
352 <!-- ##### FUNCTION gtk_image_get ##### -->
353 <para>
354 Gets the #GtkImage.
355 </para>
356
357 @image: a #GdkPixmap
358 @val: 
359 @mask: a #GdkBitmap that indicates which parts of the image should be transparent.
360
361
362 <!-- ##### ARG GtkImage:pixbuf ##### -->
363 <para>
364
365 </para>
366
367 <!-- ##### ARG GtkImage:pixmap ##### -->
368 <para>
369
370 </para>
371
372 <!-- ##### ARG GtkImage:image ##### -->
373 <para>
374
375 </para>
376
377 <!-- ##### ARG GtkImage:mask ##### -->
378 <para>
379
380 </para>
381
382 <!-- ##### ARG GtkImage:file ##### -->
383 <para>
384
385 </para>
386
387 <!-- ##### ARG GtkImage:stock ##### -->
388 <para>
389
390 </para>
391
392 <!-- ##### ARG GtkImage:icon-set ##### -->
393 <para>
394
395 </para>
396
397 <!-- ##### ARG GtkImage:icon-size ##### -->
398 <para>
399
400 </para>
401
402 <!-- ##### ARG GtkImage:pixbuf-animation ##### -->
403 <para>
404
405 </para>
406
407 <!-- ##### ARG GtkImage:storage-type ##### -->
408 <para>
409
410 </para>
411