File: migrating-GtkAssistant.sgml

package info (click to toggle)
gtk%2B2.0 2.24.33-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie, trixie-proposed-updates, trixie-updates
  • size: 124,860 kB
  • sloc: ansic: 574,091; makefile: 5,171; sh: 4,618; xml: 1,193; python: 1,117; perl: 749; awk: 49; cpp: 34
file content (178 lines) | stat: -rw-r--r-- 5,847 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?xml version="1.0"?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
               "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
]>
<chapter id="gtk-migrating-GtkAssistant">
  <chapterinfo>
    <author>
      <firstname>Carlos</firstname>
      <surname>Garnacho</surname>
      <affiliation>
	<address>
	  <email>carlosg@gnome.org</email>
	</address>
      </affiliation>
    </author>
  </chapterinfo>

  <title>Migrating from GnomeDruid to GtkAssistant</title>

  <para>
    Since version 2.10, GTK+ provides the GtkAssistant widget as a replacement
    for the <structname>GnomeDruid</structname> widget in the libgnomeui 
    library.
  </para>

  <para>
    Conceptually, both <structname>GtkAssistant</structname> and
    <structname>GnomeDruid</structname> do the same task, but there are 
    several areas where the API has been completely redesigned, so this 
    chapter covers the main changes between both widgets.
  </para>

  <section id="inserting-pages">
    <title>Inserting pages</title>

    <para>
      <structname>GnomeDruid</structname> was implemented as a container for
	 <structname>GnomeDruidPage</structname> abstract objects, which are
         implemented by the <structname>GnomeDruidPageEdge</structname> and 
         <structname>GnomeDruidPageStandard</structname> widgets. Instead, 
         <structname>GtkAssistant</structname> allows any widget to be a page, 
         and implements per-page settings (such as page type or title) as 
         child properties. So instead of:
    </para>

    <programlisting>
/* Page 1 */
page = gnome_druid_page_edge_new (GNOME_EDGE_START);
gnome_druid_page_edge_set_test (GNOME_DRUID_PAGE_EDGE (page),
                                "Welcome to the assistant, it will make your life easier");
gtk_widget_show (page);
gnome_druid_append_page (GNOME_DRUID (druid), GNOME_DRUID_PAGE (page));

/* Page 2 */
page = gnome_druid_page_standard_new ();
gtk_container_add (GTK_CONTAINER (GNOME_DRUID_PAGE_STANDARD (page)->vbox,
                   create_page1 ());
gtk_widget_show_all (page);
gnome_druid_append_page (GNOME_DRUID (druid), GNOME_DRUID_PAGE (page));

/* Page 3 */
page = gnome_druid_page_edge_new (GNOME_EDGE_FINISH);
gnome_druid_page_edge_set_test (GNOME_DRUID_PAGE_EDGE (page),
                                "Now you are done, your life is easier");
gtk_widget_show (page);
gnome_druid_append_page (GNOME_DRUID (druid), GNOME_DRUID_PAGE (page));
    </programlisting>

    <para>
      You have to write:
    </para>

    <programlisting>
gtk_assistant_append_page (GTK_ASSISTANT (assistant),
                           gtk_label_new ("Welcome to the assistant, it will make your life easier"));
gtk_assistant_append_page (GTK_ASSISTANT (assistant),
                           create_page1 ());
gtk_assistant_append_page (GTK_ASSISTANT (assistant),
                           gtk_label_new ("Now you are done, your life is easier");
    </programlisting>
  </section>

  <section id="decorating-the-assistant-pages">
    <title>Decorating the assistant pages</title>

    <para>
      To decorate your assistant pages, <structname>GtkAssistant</structname> provides similar functions
	 to <structname>GnomeDruid</structname>, so you have to transform code like this:
    </para>

    <programlisting>
gnome_druid_page_edge_set_title (GNOME_DRUID_PAGE_EDGE (page), "Welcome");
gnome_druid_page_edge_set_logo (GNOME_DRUID_PAGE_EDGE (page), logo_pixbuf);
gnome_druid_page_edge_set_watermark (GNOME_DRUID_PAGE_EDGE (page), watermark_pixbuf);
    </programlisting>

    <para>
    Into this:
    </para>

    <programlisting>
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page_widget, "Welcome");
gtk_assistant_set_page_header_image (GTK_ASSISTANT (assistant), page_widget, logo_pixbuf);
gtk_assistant_set_page_side_image (GTK_ASSISTANT (assistant), page_widget, watermark_pixbuf);
    </programlisting>

    <para>
      Where page_widget is the widget used as a page.
    </para>
  </section>

  <section id="setting-the-page-flow">
    <title>Setting the page flow</title>

    <para>
      Here is the area where <structname>GtkAssistant</structname> and <structname>GnomeDruid</structname>
	 differ the most. While <structname>GnomeDruid</structname> used the "next" and "back" signals from the 
	 <structname>GnomeDruidPage</structname>, <structname>GtkAssistant</structname> uses the following
	 techniques:
    </para>

    <itemizedlist>
      <listitem>
	   <para>gtk_assistant_set_forward_page_func (): Allows to define a GtkAssistantPageFunc to let the
	   assistant know which will be the following page given the current page.</para>
      </listitem>
      <listitem>
	   <para>gtk_assistant_set_page_complete (): Lets the assistant know whether the specified page is complete
	   or not, updating buttons state accordingly.</para>
      </listitem>
      <listitem>
	   <para>gtk_assistant_set_page_type (): Lets the assistant know the page role and update the buttons
	   state accordingly. Pages can have the following roles:</para>
	   <simplelist>
	     <member>Intro</member>
		<member>Content</member>
		<member>Progress</member>
		<member>Confirmation</member>
		<member>Summary</member>
	   </simplelist>
      </listitem>
    </itemizedlist>

    <para>
      A sample GtkAssistantPageFunc could look like this:
    </para>

    <programlisting>
static gint
forward_page_function (gint     current_page,
                       gpointer data)
{
  switch (current_page)
    {
    case 0:
      return 1;
    case 1:
      if (check_page1_data ())
	   return 2;
	 else
	   return 3;
    case 2:
      return 3;
    default:
      return -1;
    }
}
    </programlisting>

  </section>
</chapter>

<!--
Local variables:
mode: sgml
sgml-parent-document: ("gtk-docs.sgml" "book" "part" "chapter")
End:
-->