2 <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
3 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
5 <chapter id="gtk-migrating-2-to-3">
6 <title>Migrating from GTK+ 2.x to GTK+ 3</title>
9 GTK+ 3 is a major new version of GTK+ that breaks both API and ABI
10 compared to GTK+ 2.x, which has remained API- and ABI-stable for a
11 long time. Thankfully, most of the changes are not hard to adapt to
12 and there are a number of steps that you can take to prepare your
13 GTK+ 2.x application for the switch to GTK+ 3. After that, there's
14 a small number of adjustments that you may have to do when you actually
15 switch your application to build against GTK+ 3.
19 <title>Preparation in GTK+ 2.x</title>
22 The steps outlined in the following sections assume that your
23 application is working with GTK+ 2.24, which is the final stable
24 release of GTK+ 2.x. It includes all the necessary APIs and tools
25 to help you port your application to GTK+ 3. If you are still using
26 an older version of GTK+ 2.x, you should first get your application
27 to build and work with 2.24.
31 <title>Do not include individual headers</title>
33 With GTK+ 2.x it was common to include just the header files for
34 a few widgets that your application was using, which could lead
35 to problems with missing definitions, etc. GTK+ 3 tightens the
36 rules about which header files you are allowed to include directly.
37 The allowed header files are are
40 <term><filename>gtk/gtk.h</filename></term>
41 <listitem>for GTK</listitem>
44 <term><filename>gtk/gtkunixprint.h</filename></term>
45 <listitem>for low-level, UNIX-specific printing functions</listitem>
48 <term><filename>gdk/gdk.h</filename></term>
49 <listitem>for GDK</listitem>
52 <term><filename>gdk/gdkx.h</filename></term>
53 <listitem>for GDK functions that are X11-specific</listitem>
56 <term><filename>gdk/gdkwin32.h</filename></term>
57 <listitem>for GDK functions that are Windows-specific</listitem>
60 (these relative paths are assuming that you are using the include
61 paths that are specified in the gtk+-2.0.pc file, as returned by
62 <literal>pkg-config --cflags gtk+-2.0.pc</literal>.)
65 To check that your application only includes the allowed headers,
66 you can use defines to disable inclusion of individual headers,
69 make CFLAGS+="-DGTK_DISABLE_SINGLE_INCLUDES"
75 <title>Do not use deprecated symbols</title>
77 Over the years, a number of functions, and in some cases, entire
78 widgets have been deprecated. These deprecations are clearly spelled
79 out in the API reference, with hints about the recommended replacements.
80 The API reference also includes an
81 <link linkend="api-index-deprecated">index</link> of all deprecated
85 To verify that your program does not use any deprecated symbols,
86 you can use defines to remove deprecated symbols from the header files,
89 make CFLAGS+="-DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED"
95 <title>Use accessor functions instead of direct access</title>
97 GTK+ 3 removes many implementation details and struct members from
101 To ensure that your application does not have problems with this, you
102 define the preprocessor symbol <literal>GSEAL_ENABLE</literal>. This
103 will make the compiler catch all uses of direct access to struct fields
104 so that you can go through them one by one and replace them with a call
105 to an accessor function instead.
107 make CFLAGS+="-DGSEAL_ENABLE"
113 <title>Replace GDK_<keyname> with GDK_KEY_<keyname></title>
116 Key constants have gained a <literal>_KEY_</literal> infix.
117 For example, <literal>GDK_a</literal> is now
118 <literal>GDK_KEY_a</literal>. In GTK+ 2, the old names continue
119 to be available. In GTK+ 3 however, the old names will require
120 an explicit include of the <literal>gdkkeysyms-compat.h</literal> header.
126 <title>Use cairo for drawing</title>
128 In GTK+ 3, the GDK drawing API (which closely mimics the X
129 drawing API, which is itself modeled after PostScript) has been
130 removed. All drawing in GTK+ 3 is done via cairo.
133 The #GdkGC and #GdkImage objects, as well as all the functions using
134 them, are gone. This includes the <literal>gdk_draw</literal> family
135 of functions like gdk_draw_rectangle() and gdk_draw_drawable(). As
136 #GdkGC is roughly equivalent to #cairo_t and #GdkImage was used for
137 drawing images to GdkDrawables, which cairo supports automatically,
138 a transition is usually straightforward.
141 The following examples show a few common drawing idioms used by
142 applications that have been ported to use cairo and how the code
146 <title>Drawing a GdkPixbuf onto a GdkDrawable</title>
148 Drawing a pixbuf onto a drawable used to be done like this:
149 <programlisting><![CDATA[
150 gdk_draw_pixbuf (window,
151 gtk_widget_get_style (widget)->black_gc,
155 gdk_pixbuf_get_width (pixbuf),
156 gdk_pixbuf_get_height (pixbuf),
157 GDK_RGB_DITHER_NORMAL,
160 Doing the same thing with cairo:
161 <programlisting><![CDATA[
162 cairo_t *cr = gdk_cairo_create (window);
163 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
167 Note that very similar code can be used for drawing pixmaps
168 by using gdk_cairo_set_source_pixmap() instead of
169 gdk_cairo_set_source_pixbuf().
173 <title>Drawing a tiled GdkPixmap to a GdkDrawable</title>
175 Tiled pixmaps are often used for drawing backgrounds.
176 Old code looked something like this:
177 <programlisting><![CDATA[
178 GdkGCValues gc_values;
182 gc = gtk_widget_get_style (widget)->black_gc;
183 gdk_gc_set_tile (gc, pixmap);
184 gdk_gc_set_fill (gc, GDK_TILED);
185 gdk_gc_set_ts_origin (gc, x_origin, y_origin);
187 gdk_draw_rectangle (drawable, gc, TRUE, 0, 0, width, height);
189 gdk_gc_set_tile (gc, NULL);
190 gdk_gc_set_fill (gc, GDK_SOLID);
191 gdk_gc_set_ts_origin (gc, 0, 0);
193 The equivalent cairo code looks like this:
194 <programlisting><![CDATA[
197 cr = gdk_cairo_create (drawable);
198 gdk_cairo_set_source_pixmap (cr, pixmap, x_origin, y_origin);
199 cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);
200 cairo_rectangle (cr, 0, 0, width, height);
204 Again, you can exchange pixbufs and pixmaps by using
205 gdk_cairo_set_source_pixbuf() instead of
206 gdk_cairo_set_source_pixmap().
210 <title>Drawing a PangoLayout to a clipped area</title>
212 Drawing layouts clipped is often used to avoid overdraw or to
213 allow drawing selections. Code would have looked like this:
214 <programlisting><![CDATA[
218 gc = gtk_widget_get_style (widget)->text_gc[state];
219 gdk_gc_set_clip_rectangle (gc, &area);
221 gdk_draw_layout (drawable, gc, x, y, layout);
223 gdk_gc_set_clip_rectangle (gc, NULL);
225 With cairo, the same effect can be achieved using:
226 <programlisting><![CDATA[
229 cr = gdk_cairo_create (drawable);
231 gdk_cairo_rectangle (cr, &area);
233 /* set the correct source color */
234 gdk_cairo_set_source_color (cr, >k_widget_get_style (widget)->text[state]);
236 cairo_move_to (cr, x, y);
237 pango_cairo_show_layout (cr, layout);
240 Clipping using cairo_clip() is of course not restricted to text
241 rendering and can be used everywhere where GC clips were used.
242 And using gdk_cairo_set_source_color() with style colors should
243 be used in all the places where a style’s GC was used to achieve
248 <title>What should you be aware of ?</title>
249 <formalpara><title>No more stippling</title>
251 Stippling is the usage of a bi-level mask, called a #GdkBitmap.
252 It was often used to achieve a checkerboard effect. You can use
253 cairo_mask() to achieve this effect. To get a checkerbox mask,
254 you can use code like this:
255 <programlisting><![CDATA[
256 static cairo_pattern_t *
257 gtk_color_button_get_checkered (void)
259 /* need to respect pixman's stride being a multiple of 4 */
260 static unsigned char data[8] = { 0xFF, 0x00, 0x00, 0x00,
261 0x00, 0xFF, 0x00, 0x00 };
262 cairo_surface_t *surface;
263 cairo_pattern_t *pattern;
265 surface = cairo_image_surface_create_for_data (data,
269 pattern = cairo_pattern_create_for_surface (surface);
270 cairo_surface_destroy (surface);
271 cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
272 cairo_pattern_set_filter (pattern, CAIRO_FILTER_NEAREST);
277 Note that stippling looks very outdated in UIs, and is rarely
278 used in modern applications. All properties that made use of
279 stippling have been removed from GTK+ 3. Most prominently,
280 stippling is absent from text rendering, in particular #GtkTextTag.
283 <formalpara><title>Using the the target drawable also as source or mask</title>
285 The gdk_draw_drawable() function allowed using the same drawable
286 as source and target. This was often used to achieve a scrolling
287 effect. Cairo does not allow this yet. You can however use
288 cairo_push_group() to get a different intermediate target that
289 you can copy to. So you can replace this code:
290 <programlisting><![CDATA[
291 gdk_draw_drawable (pixmap,
294 area.x + dx, area.y + dy,
296 area.width, area.height);
299 <programlisting><![CDATA[
300 cairo_t *cr = gdk_cairo_create (pixmap);
301 /* clipping restricts the intermediate surface's size, so it's a good idea
303 gdk_cairo_rectangle (cr, &area);
305 /* Now push a group to change the target */
306 cairo_push_group (cr);
307 gdk_cairo_set_source_pixmap (cr, pixmap, dx, dy);
309 /* Now copy the intermediate target back */
310 cairo_pop_group_to_source (cr);
314 The cairo developers plan to add self-copies in the future to allow
315 exactly this effect, so you might want to keep up on cairo
316 development to be able to change your code.
319 <formalpara><title>Using pango_cairo_show_layout(<!-- -->) instead of gdk_draw_layout_with_colors(<!-- -->)</title>
321 GDK provided a way to ignore the color attributes of text and use
322 a hardcoded text color with the gdk_draw_layout_with_colors()
323 function. This is often used to draw text shadows or selections.
324 Pango’s cairo support does not yet provide this functionality. If
325 you use Pango layouts that change colors, the easiest way to achieve
326 a similar effect is using pango_cairo_layout_path() and cairo_fill()
327 instead of gdk_draw_layout_with_colors(). Note that this results in
328 a slightly uglier-looking text, as subpixel anti-aliasing is not
337 <title>Changes that need to be done at the time of the switch</title>
340 This section outlines porting tasks that you need to tackle when
341 you get to the point that you actually build your application against
342 GTK+ 3. Making it possible to prepare for these in GTK+ 2.24 would
343 have been either impossible or impractical.
347 <title>Replace size_request by get_preferred_width/height</title>
350 The request-phase of the traditional GTK+ geometry management
351 has been replaced by a more flexible height-for-width system,
352 which is described in detail in the API documentation
353 (see <xref linkend="geometry-management"/>). As a consequence,
354 the ::size-request signal and vfunc has been removed from
355 #GtkWidgetClass. The replacement for size_request() can
356 take several levels of sophistication:
360 As a minimal replacement to keep current functionality,
361 you can simply implement the #GtkWidgetClass.get_preferred_width() and
362 #GtkWidgetClass.get_preferred_height() vfuncs by calling your existing
363 size_request() function. So you go from
364 <informalexample><programlisting>
366 my_widget_class_init (MyWidgetClass *class)
368 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
372 widget_class->size_request = my_widget_size_request;
376 </programlisting></informalexample>
378 to something that looks more like this:
380 <informalexample><programlisting>
382 my_widget_get_preferred_width (GtkWidget *widget,
386 GtkRequisition requisition;
388 my_widget_size_request (widget, &requisition);
390 *minimal_width = *natural_width = requisition.width;
394 my_widget_get_preferred_height (GtkWidget *widget,
395 gint *minimal_height,
396 gint *natural_height)
398 GtkRequisition requisition;
400 my_widget_size_request (widget, &requisition);
402 *minimal_height = *natural_height = requisition.height;
408 my_widget_class_init (MyWidgetClass *class)
410 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
414 widget_class->get_preferred_width = my_widget_get_preferred_width;
415 widget_class->get_preferred_height = my_widget_get_preferred_height;
420 </programlisting></informalexample>
422 Sometimes you can make things a little more streamlined
423 by replacing your existing size_request() implementation by
424 one that takes an orientation parameter:
426 <informalexample><programlisting>
428 my_widget_get_preferred_size (GtkWidget *widget,
429 GtkOrientation orientation,
434 /* do things that are common for both orientations ... */
436 if (orientation == GTK_ORIENTATION_HORIZONTAL)
438 /* do stuff that only applies to width... */
440 *minimal_size = *natural_size = ...
444 /* do stuff that only applies to height... */
446 *minimal_size = *natural_size = ...
451 my_widget_get_preferred_width (GtkWidget *widget,
455 my_widget_get_preferred_size (widget,
456 GTK_ORIENTATION_HORIZONTAL,
462 my_widget_get_preferred_height (GtkWidget *widget,
463 gint *minimal_height,
464 gint *natural_height)
466 my_widget_get_preferred_size (widget,
467 GTK_ORIENTATION_VERTICAL,
473 </programlisting></informalexample>
477 <para>If your widget can cope with a small size,
478 but would appreciate getting some more space (a common
479 example would be that it contains ellipsizable labels),
480 you can do that by making your #GtkWidgetClass.get_preferred_width() /
481 #GtkWidgetClass.get_preferred_height()
482 functions return a smaller value for @minimal than for @natural.
483 For @minimal, you probably want to return the same value
484 that your size_request() function returned before (since
485 size_request() was defined as returning the minimal size
486 a widget can work with). A simple way to obtain good
487 values for @natural, in the case of containers, is to use
488 gtk_widget_get_preferred_width() and
489 gtk_widget_get_preferred_height() on the children of the
490 container, as in the following example:
491 <informalexample><programlisting>
493 gtk_fixed_get_preferred_height (GtkWidget *widget,
497 GtkFixed *fixed = GTK_FIXED (widget);
498 GtkFixedPrivate *priv = fixed->priv;
499 GtkFixedChild *child;
501 gint child_min, child_nat;
506 for (children = priv->children; children; children = children->next)
508 child = children->data;
510 if (!gtk_widget_get_visible (child->widget))
513 gtk_widget_get_preferred_height (child->widget, &child_min, &child_nat);
515 *minimum = MAX (*minimum, child->y + child_min);
516 *natural = MAX (*natural, child->y + child_nat);
519 </programlisting></informalexample>
524 Note that the #GtkWidgetClass.get_preferred_width() /
525 #GtkWidgetClass.get_preferred_height() functions
526 only allow you to deal with one dimension at a time. If your
527 size_request() handler is doing things that involve both
528 width and height at the same time (e.g. limiting the aspect
529 ratio), you will have to implement
530 #GtkWidgetClass.get_preferred_height_for_width()
531 and #GtkWidgetClass.get_preferred_width_for_height().
536 To make full use of the new capabilities of the
537 height-for-width geometry management, you need to additionally
538 implement the #GtkWidgetClass.get_preferred_height_for_width() and
539 #GtkWidgetClass.get_preferred_width_for_height(). For details on
540 these functions, see <xref linkend="geometry-management"/>.
548 <title>Replace GdkRegion by cairo_region_t</title>
551 Starting with version 1.10, cairo provides a region API that is
552 equivalent to the GDK region API (which was itself copied from
553 the X server). Therefore, the region API has been removed in GTK+ 3.
556 Porting your application to the cairo region API should be a straight
557 find-and-replace task. Please refer to the following table:
561 <row><entry>GDK</entry><entry>cairo</entry></row>
564 <row><entry>#GdkRegion</entry><entry>#cairo_region_t</entry></row>
565 <row><entry>#GdkRectangle</entry><entry>#cairo_rectangle_int_t</entry></row>
566 <row><entry>gdk_rectangle_intersect()</entry><entry>this function is still there</entry></row>
567 <row><entry>gdk_rectangle_union()</entry><entry>this function is still there</entry></row>
568 <row><entry>gdk_region_new()</entry><entry>cairo_region_create()</entry></row>
569 <row><entry>gdk_region_copy()</entry><entry>cairo_region_copy()</entry></row>
570 <row><entry>gdk_region_destroy()</entry><entry>cairo_region_destroy()</entry></row>
571 <row><entry>gdk_region_rectangle()</entry><entry>cairo_region_create_rectangle()</entry></row>
572 <row><entry>gdk_region_get_clipbox()</entry><entry>cairo_region_get_extents()</entry></row>
573 <row><entry>gdk_region_get_rectangles()</entry><entry>cairo_region_num_rectangles() and
574 cairo_region_get_rectangle()</entry></row>
575 <row><entry>gdk_region_empty()</entry><entry>cairo_region_is_empty()</entry></row>
576 <row><entry>gdk_region_equal()</entry><entry>cairo_region_equal()</entry></row>
577 <row><entry>gdk_region_point_in()</entry><entry>cairo_region_contains_point()</entry></row>
578 <row><entry>gdk_region_rect_in()</entry><entry>cairo_region_contains_rectangle()</entry></row>
579 <row><entry>gdk_region_offset()</entry><entry>cairo_region_translate()</entry></row>
580 <row><entry>gdk_region_union_with_rect()</entry><entry>cairo_region_union_rectangle()</entry></row>
581 <row><entry>gdk_region_intersect()</entry><entry>cairo_region_intersect()</entry></row>
582 <row><entry>gdk_region_union()</entry><entry>cairo_region_union()</entry></row>
583 <row><entry>gdk_region_subtract()</entry><entry>cairo_region_subtract()</entry></row>
584 <row><entry>gdk_region_xor()</entry><entry>cairo_region_xor()</entry></row>
585 <row><entry>gdk_region_shrink()</entry><entry>no replacement</entry></row>
586 <row><entry>gdk_region_polygon()</entry><entry>no replacement, use cairo paths instead</entry></row>
594 <title>Replace GdkPixmap by cairo surfaces</title>
596 The #GdkPixmap object and related functions have been removed.
597 In the cairo-centric world of GTK+ 3, cairo surfaces take over
601 <title>Creating custom cursors</title>
603 One place where pixmaps were commonly used is to create custom
609 GdkColor fg = { 0, 0, 0, 0 };
611 pixmap = gdk_pixmap_new (NULL, 1, 1, 1);
613 cr = gdk_cairo_create (pixmap);
614 cairo_rectangle (cr, 0, 0, 1, 1);
618 cursor = gdk_cursor_new_from_pixmap (pixmap, pixmap, &fg, &fg, 0, 0);
620 g_object_unref (pixmap);
622 The same can be achieved without pixmaps, by drawing onto
630 s = cairo_image_surface_create (CAIRO_FORMAT_A1, 3, 3);
631 cr = cairo_create (s);
632 cairo_arc (cr, 1.5, 1.5, 1.5, 0, 2 * M_PI);
636 pixbuf = gdk_pixbuf_get_from_surface (NULL, s,
640 cairo_surface_destroy (s);
642 cursor = gdk_cursor_new_from_pixbuf (display, pixbuf, 0, 0);
644 g_object_unref (pixbuf);
651 <title>Replace colormaps by visuals</title>
653 For drawing with cairo, it is not necessary to allocate colors, and
654 a #GdkVisual provides enough information for cairo to handle colors
655 in 'native' surfaces. Therefore, #GdkColormap and related functions
656 have been removed in GTK+ 3, and visuals are used instead. The
657 colormap-handling functions of #GtkWidget (gtk_widget_set_colormap(),
658 etc) have been removed and gtk_window_set_visual() has been added.
660 <example><title>Setting up a translucent window</title>
661 <para>You might have a screen-changed handler like the following
662 to set up a translucent window with an alpha-channel:
666 on_alpha_screen_changed (GtkWidget *widget,
667 GdkScreen *old_screen,
670 GdkScreen *screen = gtk_widget_get_screen (widget);
671 GdkColormap *colormap = gdk_screen_get_rgba_colormap (screen);
673 if (colormap == NULL)
674 colormap = gdk_screen_get_default_colormap (screen);
676 gtk_widget_set_colormap (widget, colormap);
680 With visuals instead of colormaps, this will look as follows:
684 on_alpha_screen_changed (GtkWindow *window,
685 GdkScreen *old_screen,
688 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (window));
689 GdkVisual *visual = gdk_screen_get_rgba_visual (screen);
692 visual = gdk_screen_get_system_visual (screen);
694 gtk_window_set_visual (window, visual);
701 <title>The GtkWidget::draw signal</title>
703 The GtkWidget #GtkWidget::expose-event signal has been replaced by
704 a new #GtkWidget::draw signal, which takes a #cairo_t instead of
705 an expose event. The cairo context is being set up so that the origin
706 at (0, 0) coincides with the upper left corner of the widget, and
709 <note><para>In other words, the cairo context of the draw signal is set
710 up in 'widget coordinates', which is different from traditional expose
711 event handlers, which always assume 'window coordinates'.
714 The widget is expected to draw itself with its allocated size, which
715 is available via the new gtk_widget_get_allocated_width() and
716 gtk_widget_get_allocated_height() functions. It is not necessary to
717 check for GTK_WIDGET_IS_DRAWABLE(), since GTK+ already does this check
718 before emitting the ::draw signal.
721 There are some special considerations for widgets with multiple windows.
722 Expose events are window-specific, and widgets with multiple windows
723 could expect to get an expose event for each window that needs to be
724 redrawn. Therefore, multi-window expose event handlers typically look
726 <informalexample><programlisting>
727 if (event->window == widget->window1)
729 /* ... draw window1 ... */
731 else if (event->window == widget->window2)
733 /* ... draw window2 ... */
736 </programlisting></informalexample>
737 In contrast, the ::draw signal handler may have to draw multiple
738 windows in one call. GTK+ has a convenience function
739 gtk_cairo_should_draw_window() that can be used to find out if
740 a window needs to be drawn. With that, the example above would look
741 like this (note that the 'else' is gone):
742 <informalexample><programlisting>
743 if (gtk_cairo_should_draw_window (cr, widget->window1)
745 /* ... draw window1 ... */
747 if (gtk_cairo_should_draw_window (cr, widget->window2)
749 /* ... draw window2 ... */
752 </programlisting></informalexample>
753 Another convenience function that can help when implementing
754 ::draw for multi-window widgets is gtk_cairo_transform_to_window(),
755 which transforms a cairo context from widget-relative coordinates
756 to window-relative coordinates.
759 All GtkStyle drawing functions (gtk_paint_box(), etc) have been changed
760 to take a #cairo_t instead of a window and a clip area. ::draw
761 implementations will usually just use the cairo context that has been
764 <example><title>A simple ::draw function</title>
767 gtk_arrow_draw (GtkWidget *widget,
774 width = gtk_widget_get_allocated_width (widget);
775 height = gtk_widget_get_allocated_height (widget);
777 extent = MIN (width - 2 * PAD, height - 2 * PAD);
781 gtk_paint_arrow (gtk_widget_get_style (widget),
783 gtk_widget_get_state (widget),
787 widget->priv->arrow_type,
789 x, y, extent, extent);
796 <title>GtkProgressBar orientation</title>
799 In GTK+ 2.x, #GtkProgressBar and #GtkCellRendererProgress were using the
800 GtkProgressBarOrientation enumeration to specify their orientation and
801 direction. In GTK+ 3, both the widget and the cell renderer implement
802 #GtkOrientable, and have an additional 'inverted' property to determine
803 their direction. Therefore, a call to gtk_progress_bar_set_orientation()
804 needs to be replaced by a pair of calls to
805 gtk_orientable_set_orientation() and gtk_progress_bar_set_inverted().
806 The following values correspond:
809 <colspec colname="1"/>
810 <colspec colname="2"/>
811 <colspec colname="3"/>
813 <row><entry>GTK+ 2.x</entry><entry namest="2" nameend="3">GTK+ 3</entry></row>
814 <row><entry>GtkProgressBarOrientation</entry><entry>GtkOrientation</entry><entry>inverted</entry></row>
817 <row><entry>GTK_PROGRESS_LEFT_TO_RIGHT</entry><entry>GTK_ORIENTATION_HORIZONTAL</entry><entry>FALSE</entry></row>
818 <row><entry>GTK_PROGRESS_RIGHT_TO_LEFT</entry><entry>GTK_ORIENTATION_HORIZONTAL</entry><entry>TRUE</entry></row>
819 <row><entry>GTK_PROGRESS_TOP_TO_BOTTOM</entry><entry>GTK_ORIENTATION_VERTICAL</entry><entry>FALSE</entry></row>
820 <row><entry>GTK_PROGRESS_BOTTOM_TO_TOP</entry><entry>GTK_ORIENTATION_VERTICAL</entry><entry>TRUE</entry></row>
828 <title>Check your expand flags</title>
831 The behaviour of expanding widgets has changed slightly in GTK+ 3,
832 compared to GTK+ 2.x. It is now 'inherited', i.e. a container that
833 has an expanding child is considered expanding itself. This is often
834 the desired behaviour. In places where you don't want this to happen,
835 setting the container explicity as not expanding will stop the
836 expand flag of the child from being inherited. See
837 gtk_widget_set_hexpand() and gtk_widget_set_vexpand().
842 <title>Scrolling changes</title>
845 The default values for the #GtkScrolledWindow:hscrollbar-policy and
846 #GtkScrolledWindow:vscrollbar-policy properties have been changed from
847 'never' to 'automatic'. If your application was relying on the default
848 value, you will have explicitly set it explicitly.
852 The ::set-scroll-adjustments signal on GtkWidget has been replaced
853 by the #GtkScrollable interface which must be implemented by a widget
854 that wants to be placed in a #GtkScrolledWindow. Instead of emitting
855 ::set-scroll-adjustments, the scrolled window simply sets the
856 #GtkScrollable::hadjustment and #GtkScrollable::vadjustment properties.
861 <title>GtkObject is gone</title>
864 GtkObject has been removed in GTK+ 3. Its remaining functionality,
865 the ::destroy signal, has been moved to GtkWidget. If you have non-widget
866 classes that are directly derived from GtkObject, you have to make
867 them derive from #GInitiallyUnowned (or, if you don't need the floating
868 functionality, #GObject). If you have widgets that override the
869 destroy class handler, you have to adust your class_init function,
870 since destroy is now a member of GtkWidgetClass:
871 <informalexample><programlisting>
872 GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
874 object_class->destroy = my_destroy;
875 </programlisting></informalexample>
877 <informalexample><programlisting>
878 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
880 widget_class->destroy = my_destroy;
881 </programlisting></informalexample>
882 In the unlikely case that you have a non-widget class that is derived
883 from GtkObject and makes use of the destroy functionality, you have
884 to implement ::destroy yourself.
889 <title>Resize grips</title>
892 The resize grip functionality has been moved from #GtkStatusbar
893 to #GtkWindow. Any window can now have resize grips, regardless whether
894 it has a statusbar or not. The functions
895 gtk_statusbar_set_has_resize_grip() and gtk_statusbar_get_has_resize_grip()
896 have disappeared, and instead there are now
897 gtk_window_set_has_resize_grip() and gtk_window_get_has_resize_grip().
902 <title>Prevent mixed linkage</title>
904 Linking against GTK+ 2.x and GTK+ 3 in the same process is problematic
905 and can lead to hard-to-diagnose crashes. The gtk_init() function in
906 both GTK+ 2.22 and in GTK+ 3 tries to detect this situation and abort
907 with a diagnostic message, but this check is not 100% reliable (e.g. if
908 the problematic linking happens only in loadable modules).
911 Direct linking of your application against both versions of GTK+ is
912 easy to avoid; the problem gets harder when your application is using
913 libraries that are themselves linked against some version of GTK+.
914 In that case, you have to verify that you are using a version of the
915 library that is linked against GTK+ 3.
918 If you are using packages provided by a distributor, it is likely that
919 parallel installable versions of the library exist for GTK+ 2.x and
920 GTK+ 3, e.g for vte, check for vte3; for webkitgtk look for webkitgtk3,
926 <title>Install GTK+ modules in the right place</title>
928 Some software packages install loadable GTK+ modules such as theme engines,
929 gdk-pixbuf loaders or input methods. Since GTK+ 3 is parallel-installable
930 with GTK+ 2.x, the two GTK+ versions have separate locations for their
931 loadable modules. The location for GTK+ 2.x is
932 <filename><replaceable>libdir</replaceable>/gtk-2.0</filename>
933 (and its subdirectories), for GTK+ 3 the location is
934 <filename><replaceable>libdir</replaceable>/gtk-3.0</filename>
935 (and its subdirectories).
938 For some kinds of modules, namely input methods and pixbuf loaders,
939 GTK+ keeps a cache file with extra information about the modules.
940 For GTK+ 2.x, these cache files are located in
941 <filename><replaceable>sysconfdir</replaceable>/gtk-2.0</filename>.
942 For GTK+ 3, they have been moved to
943 <filename><replaceable>libdir</replaceable>/gtk-3.0/3.0.0/</filename>.
944 The commands that create these cache files have been renamed with a -3
945 suffix to make them parallel-installable.
948 Note that GTK+ modules often link against libgtk, libgdk-pixbuf, etc.
949 If that is the case for your module, you have to be careful to link the
950 GTK+ 2.x version of your module against the 2.x version of the libraries,
951 and the GTK+ 3 version against hte 3.x versions. Loading a module linked
952 against libgtk 2.x into an application using GTK+ 3 will lead to
953 unhappiness and must be avoided.