More abbreviation conversion

This commit is contained in:
Matthias Clasen
2005-05-16 19:34:39 +00:00
parent 7b0e05fcca
commit ce16af5a93
12 changed files with 325 additions and 518 deletions

View File

@ -111,7 +111,17 @@ content_files = \
visual_index.xml visual_index.xml
expand_content_files = \ expand_content_files = \
tree_widget.sgml glossary.xml \
migrating-checklist.sgml \
migrating-GtkAction.sgml \
migrating-GtkComboBox.sgml \
migrating-GtkFileChooser.sgml \
migrating-GtkIconView.sgml \
migrating-GtkAboutDialog.sgml \
migrating-GtkColorButton.sgml \
tree_widget.sgml \
text_widget.sgml \
question_index.sgml
# Images to copy into HTML directory # Images to copy into HTML directory
HTML_IMAGES = \ HTML_IMAGES = \

View File

@ -24,7 +24,7 @@
<para> <para>
A <glossterm linkend="container">container</glossterm> that A <glossterm linkend="container">container</glossterm> that
can hold at most one child widget. The base class for bins is can hold at most one child widget. The base class for bins is
<link linkend="GtkBin">GtkBin</link>. #GtkBin.
</para> </para>
<glossseealso> <glossseealso>
<glossterm linkend="container">container</glossterm> <glossterm linkend="container">container</glossterm>
@ -48,10 +48,9 @@
<glossdef> <glossdef>
<para> <para>
GTK+ contains several widgets which display data in columns, GTK+ contains several widgets which display data in columns,
e.g. the <link linkend="GtkTreeView">GtkTreeView</link>. e.g. the #GtkTreeView.
These <glossterm linkend="view-column">view columns</glossterm> in These <glossterm linkend="view-column">view columns</glossterm> in
the tree view are represented by the tree view are represented by #GtkTreeViewColumn
<link linkend="GtkTreeViewColumn">GtkTreeViewColumn</link>
objects inside GTK+. They should not be confused with objects inside GTK+. They should not be confused with
<glossterm linkend="model-column">model columns</glossterm> which <glossterm linkend="model-column">model columns</glossterm> which
are used to organize the data in tree models. are used to organize the data in tree models.
@ -69,14 +68,11 @@
<emphasis>parent</emphasis> of the <emphasis>child</emphasis> <emphasis>parent</emphasis> of the <emphasis>child</emphasis>
widgets. Some containers don't draw anything on their own, widgets. Some containers don't draw anything on their own,
but rather just organize their children's <glossterm but rather just organize their children's <glossterm
linkend="geometry">geometry</glossterm>; for example, <link linkend="geometry">geometry</glossterm>; for example, #GtkVBox lays out
linkend="GtkVBox">GtkVBox</link> lays out its children its children vertically without painting anything on its own. Other
vertically without painting anything on its own. Other containers include decorative elements; for example, #GtkFrame contains
containers include decorative elements; for example, <link the frame's child and a label in addition to the shaded frame it draws.
linkend="GtkFrame">GtkFrame</link> contains the frame's child The base class for containers is #GtkContainer.
and a label in addition to the shaded frame it draws. The
base class for containers is <link
linkend="GtkContainer">GtkContainer</link>.
</para> </para>
<glossseealso> <glossseealso>
<glossterm linkend="container">widget</glossterm> <glossterm linkend="container">widget</glossterm>
@ -94,8 +90,7 @@
of a keyboard, a pointing device and one or more of a keyboard, a pointing device and one or more
<glossterm linkend="screen">screens</glossterm>. <glossterm linkend="screen">screens</glossterm>.
Applications open a display to show windows and interact with the user. Applications open a display to show windows and interact with the user.
In GDK, a display is represented by a In GDK, a display is represented by a #GdkDisplay.
<link linkend="GdkDisplay">GdkDisplay</link>.
</para> </para>
</glossdef> </glossdef>
</glossentry> </glossentry>
@ -130,15 +125,13 @@
actually shows the GdkWindows it created when it was actually shows the GdkWindows it created when it was
<glossterm linkend="realization">realized</glossterm>. When a <glossterm linkend="realization">realized</glossterm>. When a
widget is mapped, it must turn on its widget is mapped, it must turn on its
<constant>GTK_MAPPED</constant> <link %GTK_MAPPED <link linkend="GtkWidgetFlags">flag</link>.
linkend="GtkWidgetFlags">flag</link>.
</para> </para>
<para> <para>
Note that due to the asynchronous nature of the X window Note that due to the asynchronous nature of the X window
system, a widget's window may not appear on the screen system, a widget's window may not appear on the screen
immediatly after one calls <link immediatly after one calls gdk_window_show():
linkend="gdk-window-show"><function>gdk_window_show()</function></link>:
you must wait for the corresponding map <glossterm you must wait for the corresponding map <glossterm
linkend="event">event</glossterm> to be received. You can do linkend="event">event</glossterm> to be received. You can do
this with the <link this with the <link
@ -155,7 +148,7 @@
A column in a tree model, holding data of a certain type. A column in a tree model, holding data of a certain type.
The types which can be stored in the columns of a model The types which can be stored in the columns of a model
have to be specified when the model is constructed, see have to be specified when the model is constructed, see
e.g. <link linkend="gtk-list-store-new">gtk_list_store_new()</link>. e.g. gtk_list_store_new().
</para> </para>
<glossseealso> <glossseealso>
<glossterm linkend="view-column">view column</glossterm> <glossterm linkend="view-column">view column</glossterm>
@ -170,17 +163,13 @@
These widgets follow the well-known model-view pattern, which separates These widgets follow the well-known model-view pattern, which separates
the data (the model) to be displayed from the component which does the the data (the model) to be displayed from the component which does the
actual visualization (the view). Examples of this pattern in GTK+ are actual visualization (the view). Examples of this pattern in GTK+ are
the <link linkend="GtkTreeView">GtkTreeView</link>/<link linkend="GtkTreeModel">GtkTreeModel</link> the #GtkTreeView/#GtkTreeModel and #GtkTextView/#GtkTextBuffer
and
<link linkend="GtkTextView">GtkTextView</link>/<link linkend="GtkTextBuffer">GtkTextBuffer</link>
</para> </para>
<para> <para>
One important advantage of this pattern is that it is possible to One important advantage of this pattern is that it is possible to
display the same model in multiple views; another one that the display the same model in multiple views; another one that the
separation of the model allows a great deal of flexibility, as separation of the model allows a great deal of flexibility, as
demonstrated by e.g. demonstrated by e.g. #GtkTreeModelSort or #GtkTreeModelFilter.
<link linkend="GtkTreeModelSort">GtkTreeModelSort</link> or
<link linkend="GtkTreeModelFilter">GtkTreeModelFilter</link>.
</para> </para>
</glossdef> </glossdef>
</glossentry> </glossentry>
@ -192,11 +181,8 @@
A widget that does not have a GdkWindow of its own on which to A widget that does not have a GdkWindow of its own on which to
draw its contents, but rather shares its <glossterm draw its contents, but rather shares its <glossterm
linkend="parent">parent's</glossterm>. Such a widget has the linkend="parent">parent's</glossterm>. Such a widget has the
<constant>GTK_NO_WINDOW</constant> <link %GTK_NO_WINDOW <link linkend="GtkWidgetFlags">flag</link> set, and
linkend="GtkWidgetFlags">flag</link> set, and can be tested can be tested with the GTK_WIDGET_NO_WINDOW() macro.
with the <link
linkend="gtk-widget-no-window:caps"><function>GTK_WIDGET_NO_WINDOW()</function></link>
macro.
</para> </para>
</glossdef> </glossdef>
</glossentry> </glossentry>
@ -224,17 +210,14 @@
also attach a <glossterm linkend="style">style</glossterm> to also attach a <glossterm linkend="style">style</glossterm> to
it. A widget becomes unrealized by destroying its associated it. A widget becomes unrealized by destroying its associated
GdkWindow. When a widget is realized, it must turn on its GdkWindow. When a widget is realized, it must turn on its
<constant>GTK_REALIZED</constant> <link %GTK_REALIZED <link linkend="GtkWidgetFlags">flag</link>.
linkend="GtkWidgetFlags">flag</link>.
</para> </para>
<para> <para>
Widgets that don't own the GdkWindow on which they draw are Widgets that don't own the GdkWindow on which they draw are
called <glossterm linkend="no-window">no-window called <glossterm linkend="no-window">no-window widgets</glossterm>.
widgets</glossterm>. This can be tested with the <link This can be tested with the GTK_WIDGET_NO_WINDOW() macro. Normally,
linkend="gtk-widget-no-window:caps"><function>GTK_WIDGET_NO_WINDOW()</function></link> these widgets draw on their parent's GdkWindow.
macro. Normally, these widgets draw on their parent's
GdkWindow.
</para> </para>
<para> <para>
@ -276,8 +259,7 @@
Each screen can stretch across multiple physical monitors. Each screen can stretch across multiple physical monitors.
</para> </para>
<para> <para>
In GDK, screens are represented by In GDK, screens are represented by #GdkScreen objects.
<link linkend="GdkScreen">GdkScreen</link> objects.
</para> </para>
</glossdef> </glossdef>
</glossentry> </glossentry>
@ -298,9 +280,8 @@
<glossdef> <glossdef>
<para> <para>
A <glossterm linkend="widget">widget</glossterm> that does not A <glossterm linkend="widget">widget</glossterm> that does not
require a <glossterm linkend="parent">parent</glossterm> require a <glossterm linkend="parent">parent</glossterm> container.
container. The only toplevel widgets in GTK+ are <link The only toplevel widgets in GTK+ are #GtkWindow and widgets derived from it.
linkend="GtkWindow">GtkWindow</link> and widgets derived from it.
</para> </para>
<glossseealso> <glossseealso>
<glossterm linkend="container">container</glossterm> <glossterm linkend="container">container</glossterm>
@ -323,7 +304,7 @@
<glossdef> <glossdef>
<para> <para>
A displayed column in a tree view, represented by a A displayed column in a tree view, represented by a
<link linkend="GtkTreeViewColumn">GtkTreeViewColumn</link> object. #GtkTreeViewColumn object.
</para> </para>
<glossseealso> <glossseealso>
<glossterm linkend="model-column">model column</glossterm> <glossterm linkend="model-column">model column</glossterm>
@ -362,8 +343,7 @@
linkend="geometry">geometry</glossterm> of the widgets: every linkend="geometry">geometry</glossterm> of the widgets: every
widget thus has a parent except those widgets which are widget thus has a parent except those widgets which are
<glossterm linkend="toplevel">toplevels</glossterm>. The base <glossterm linkend="toplevel">toplevels</glossterm>. The base
class for widgets is <link class for widgets is #GtkWidget.
linkend="GtkWidget">GtkWidget</link>.
</para> </para>
<glossseealso> <glossseealso>
<glossterm linkend="container">container</glossterm> <glossterm linkend="container">container</glossterm>

View File

@ -175,7 +175,7 @@
<!ENTITY visual-index SYSTEM "visual_index.xml"> <!ENTITY visual-index SYSTEM "visual_index.xml">
<!ENTITY index-Objects-Grouped SYSTEM "objects_grouped.sgml"> <!ENTITY index-Objects-Grouped SYSTEM "objects_grouped.sgml">
<!ENTITY gtk-TextWidget SYSTEM "text_widget.sgml"> <!ENTITY gtk-TextWidget SYSTEM "xml/text_widget.sgml">
<!ENTITY gtk-TreeWidget SYSTEM "xml/tree_widget.sgml"> <!ENTITY gtk-TreeWidget SYSTEM "xml/tree_widget.sgml">
<!ENTITY gtk-Compiling SYSTEM "compiling.sgml"> <!ENTITY gtk-Compiling SYSTEM "compiling.sgml">
<!ENTITY gtk-Building SYSTEM "building.sgml"> <!ENTITY gtk-Building SYSTEM "building.sgml">
@ -184,20 +184,20 @@
<!ENTITY gtk-Windows SYSTEM "windows.sgml"> <!ENTITY gtk-Windows SYSTEM "windows.sgml">
<!ENTITY gtk-Framebuffer SYSTEM "framebuffer.sgml"> <!ENTITY gtk-Framebuffer SYSTEM "framebuffer.sgml">
<!ENTITY gtk-X11 SYSTEM "x11.sgml"> <!ENTITY gtk-X11 SYSTEM "x11.sgml">
<!ENTITY gtk-Questions SYSTEM "question_index.sgml"> <!ENTITY gtk-Questions SYSTEM "xml/question_index.sgml">
<!ENTITY gtk-Changes-1-2 SYSTEM "changes-1.2.sgml"> <!ENTITY gtk-Changes-1-2 SYSTEM "changes-1.2.sgml">
<!ENTITY gtk-Changes-2-0 SYSTEM "changes-2.0.sgml"> <!ENTITY gtk-Changes-2-0 SYSTEM "changes-2.0.sgml">
<!ENTITY gtk-migrating-checklist SYSTEM "migrating-checklist.sgml"> <!ENTITY gtk-migrating-checklist SYSTEM "xml/migrating-checklist.sgml">
<!ENTITY gtk-migrating-GtkFileChooser SYSTEM "migrating-GtkFileChooser.sgml"> <!ENTITY gtk-migrating-GtkFileChooser SYSTEM "xml/migrating-GtkFileChooser.sgml">
<!ENTITY gtk-migrating-GtkAction SYSTEM "migrating-GtkAction.sgml"> <!ENTITY gtk-migrating-GtkAction SYSTEM "xml/migrating-GtkAction.sgml">
<!ENTITY gtk-migrating-GtkComboBox SYSTEM "migrating-GtkComboBox.sgml"> <!ENTITY gtk-migrating-GtkComboBox SYSTEM "xml/migrating-GtkComboBox.sgml">
<!ENTITY gtk-migrating-GtkIconView SYSTEM "migrating-GtkIconView.sgml"> <!ENTITY gtk-migrating-GtkIconView SYSTEM "xml/migrating-GtkIconView.sgml">
<!ENTITY gtk-migrating-GtkAboutDialog SYSTEM "migrating-GtkAboutDialog.sgml"> <!ENTITY gtk-migrating-GtkAboutDialog SYSTEM "xml/migrating-GtkAboutDialog.sgml">
<!ENTITY gtk-migrating-GtkColorButton SYSTEM "migrating-GtkColorButton.sgml"> <!ENTITY gtk-migrating-GtkColorButton SYSTEM "xml/migrating-GtkColorButton.sgml">
<!ENTITY version SYSTEM "version.xml"> <!ENTITY version SYSTEM "version.xml">
<!ENTITY gtk-query-immodules SYSTEM "gtk-query-immodules-2.0.xml"> <!ENTITY gtk-query-immodules SYSTEM "gtk-query-immodules-2.0.xml">
<!ENTITY gtk-update-icon-cache SYSTEM "gtk-update-icon-cache.xml"> <!ENTITY gtk-update-icon-cache SYSTEM "gtk-update-icon-cache.xml">
<!ENTITY gtk-glossary SYSTEM "glossary.xml"> <!ENTITY gtk-glossary SYSTEM "xml/glossary.xml">
]> ]>
<book id="index"> <book id="index">
<bookinfo> <bookinfo>

View File

@ -3,15 +3,13 @@
<title>Migrating from GnomeAbout to GtkAboutDialog</title> <title>Migrating from GnomeAbout to GtkAboutDialog</title>
<para> <para>
Since version 2.6, GTK+ provides the <link Since version 2.6, GTK+ provides the #GtkAboutDialog widget as a replacement for
linkend="GtkIconView">GtkAboutDialog</link> widget as a replacement for
the <structname>GnomeAbout</structname> dialog in the libgnomeui library. the <structname>GnomeAbout</structname> dialog in the libgnomeui library.
</para> </para>
<para> <para>
<link linkend="GtkIconView">GtkAboutDialog</link> supports all features #GtkAboutDialog supports all features found in <structname>GnomeAbout</structname>.
found in <structname>GnomeAbout</structname>. The The <structname>GtkAboutDialog</structname> API is bigger, since it follows
<structname>GtkAboutDialog</structname> API is bigger, since it follows
the GTK+ policy to have getters and setters for all widget properties, the GTK+ policy to have getters and setters for all widget properties,
but it isn't much more complex than <structname>GnomeAbout</structname>. but it isn't much more complex than <structname>GnomeAbout</structname>.
</para> </para>
@ -56,9 +54,9 @@
NULL); NULL);
g_object_unref (pixbuf); g_object_unref (pixbuf);
</programlisting></informalexample> </programlisting></informalexample>
If the <link linkend="g-object-new"><function>g_object_new()</function></link> construction scares you, If the g_object_new() construction scares you, you can also use
you can also use <link linkend="g-object-new"><function>gtk_about_dialog_new()</function></link> to gtk_about_dialog_new() to construct the dialog and then use the setters for
construct the dialog and then use the setters for the individual properties. the individual properties.
</para> </para>
<para> <para>
@ -82,9 +80,8 @@
</para></listitem> </para></listitem>
<listitem><para> <listitem><para>
If your credits contain email addresses or URLs, you can turn them If your credits contain email addresses or URLs, you can turn them
into clickable links using into clickable links using gtk_about_dialog_set_email_hook() and
<link linkend="gtk-about-dialog-set-email-hook"><function>gtk_about_dialog_set_email_hook()</function></link> and gtk_about_dialog_set_url_hook().
<link linkend="gtk-about-dialog-set-url-hook"><function>gtk_about_dialog_set_url_hook()</function></link>.
</para></listitem> </para></listitem>
</itemizedlist> </itemizedlist>
</para> </para>

View File

@ -15,40 +15,35 @@
<para> <para>
Prior to GTK+ 2.4, there were several APIs in use to create menus Prior to GTK+ 2.4, there were several APIs in use to create menus
and toolbars. GTK+ itself included <link and toolbars. GTK+ itself included #GtkItemFactory, which was
linkend="GtkItemFactory">GtkItemFactory</link>, which was
historically used in the GIMP; libgnomeui provided the gnome-ui historically used in the GIMP; libgnomeui provided the gnome-ui
set of macros; libbonoboui provided a complex mechanism to do menu set of macros; libbonoboui provided a complex mechanism to do menu
merging across embedded components. GTK+ 2.4 includes a system merging across embedded components. GTK+ 2.4 includes a system
for creating menus and toolbars, with merging of items, based for creating menus and toolbars, with merging of items, based
around the <link linkend="GtkAction">GtkAction</link> mechanism. around the #GtkAction mechanism.
</para> </para>
<section id="actions-and-action-groups"> <section id="actions-and-action-groups">
<title>Actions and Action Groups</title> <title>Actions and Action Groups</title>
<para> <para>
A <link linkend="GtkAction">GtkAction</link> represents an A #GtkAction represents an operation that the user can perform from
operation that the user can perform from the menus and toolbars the menus and toolbars of an application. It is similar to "verbs"
of an application. It is similar to "verbs" in other menu in other menu systems. A #GtkAction has a name, which is its identifier,
systems. A <link linkend="GtkAction">GtkAction</link> has a and it can have several widgets that represent it in the user interface.
name, which is its identifier, and it can have several widgets For example, an action for <symbol>EditCopy</symbol> can have a menu item
that represent it in the user interface. For example, an action as well as a toolbar button associated to it. If there is nothing selected
for <symbol>EditCopy</symbol> can have a menu item as well as a
toolbar button associated to it. If there is nothing selected
in the document, the application can simply de-sensitize the in the document, the application can simply de-sensitize the
<symbol>EditCopy</symbol> action; this will cause both the menu <symbol>EditCopy</symbol> action; this will cause both the menu
item and the toolbar button to be de-sensitized automatically. item and the toolbar button to be de-sensitized automatically.
Similarly, whenever the user selects the menu item or the Similarly, whenever the user selects the menu item or the
toolbar button associated to the <symbol>EditCopy</symbol> toolbar button associated to the <symbol>EditCopy</symbol>
action, the corresponding <link action, the corresponding #GtkAction object will emit an
linkend="GtkAction">GtkAction</link> object will emit an
"activate" signal. "activate" signal.
</para> </para>
<para> <para>
<link linkend="GtkActionGroup">GtkActionGroup</link> is simply a #GtkActionGroup is simply a group of #GtkAction objects. An
group of <link linkend="GtkAction">GtkAction</link> objects. An
application may want to have several groups: one for global application may want to have several groups: one for global
actions such as "new document", "about", and "exit"; then one actions such as "new document", "about", and "exit"; then one
group for each open document with actions specific to the group for each open document with actions specific to the
@ -72,22 +67,20 @@
<title>User Interface Manager Object</title> <title>User Interface Manager Object</title>
<para> <para>
<link linkend="GtkUIManager">GtkUIManager</link> is an object #GtkUIManager is an object that can construct menu and toolbar widgets
that can construct menu and toolbar widgets from an XML from an XML description. These widgets are in turn associated to
description. These widgets are in turn associated to
corresponding actions and action groups. corresponding actions and action groups.
</para> </para>
<para> <para>
<link linkend="GtkUIManager">GtkUIManager</link> supports #GtkUIManager supports merging of menus and toolbars for applications
merging of menus and toolbars for applications that have that have multiple components, each with separate sets of commands.
multiple components, each with separate sets of commands. For For example, a word processor that can embed images may want to have
example, a word processor that can embed images may want to have
toolbar buttons for Bold and Italic when the cursor is on a text toolbar buttons for Bold and Italic when the cursor is on a text
block, but Crop and Brightness/Contrast buttons when the cursor block, but Crop and Brightness/Contrast buttons when the cursor
is on an image. These actions, which change depending on the is on an image. These actions, which change depending on the
state of the application, can be merged and de-merged from a state of the application, can be merged and de-merged from a
<link linkend="GtkUIManager">GtkUIManager</link> as appropriate. #GtkUIManager as appropriate.
</para> </para>
</section> </section>
@ -102,8 +95,7 @@
array of <structname>GnomeUIInfo</structname> structures, which array of <structname>GnomeUIInfo</structname> structures, which
contain information for menu or toolbar items such as their contain information for menu or toolbar items such as their
label, icon, and accelerator key. Then, one calls label, icon, and accelerator key. Then, one calls
<function>gnome_app_fill_menu()</function> or gnome_app_fill_menu() or gnome_app_fill_toolbar(), or one of the
<function>gnome_app_fill_toolbar()</function>, or one of the
related functions, to create the appropriate widgets based on related functions, to create the appropriate widgets based on
these structures. these structures.
</para> </para>
@ -113,8 +105,7 @@
pass back pointers to the widgets that got created. This means pass back pointers to the widgets that got created. This means
that the structures cannot simply be kept around if the program that the structures cannot simply be kept around if the program
requires multiple instances of the user interface (e.g. several requires multiple instances of the user interface (e.g. several
windows); each new invocation of windows); each new invocation of gnome_app_fill_menu() would overwrite the
<function>gnome_app_fill_menu()</function> would overwrite the
widget fields of the structures. widget fields of the structures.
</para> </para>
@ -142,11 +133,9 @@
<para> <para>
Separate your existing GnomeUIInfo entries into normal Separate your existing GnomeUIInfo entries into normal
actions, toggle actions, and radio actions, and then create actions, toggle actions, and radio actions, and then create
a separate array of <link a separate array of #GtkActionEntry structures
linkend="GtkActionEntry">GtkActionEntry</link> structures
for each group. This will allow you to create the necessary for each group. This will allow you to create the necessary
<link linkend="GtkActionGroup">GtkActionGroup</link> #GtkActionGroup objects. Note that this does not describe the actual
objects. Note that this does not describe the actual
"shape" that your menus and toolbars will have; it simply "shape" that your menus and toolbars will have; it simply
defines the set of commands that will appear in them. defines the set of commands that will appear in them.
</para> </para>
@ -154,27 +143,22 @@
<listitem> <listitem>
<para> <para>
Create an XML description of your menus and toolbars for use Create an XML description of your menus and toolbars for use
with <link linkend="GtkUIManager">GtkUIManager</link>. This with #GtkUIManager. This defines the actual shape of the menus and toolbars.
defines the actual shape of the menus and toolbars.
</para> </para>
</listitem> </listitem>
<listitem> <listitem>
<para> <para>
Port the code that uses gnome-app and gnome-app-helper to Port the code that uses gnome-app and gnome-app-helper to
<link linkend="GtkAction">GtkAction</link> and <link #GtkAction and #GtkUIManager.
linkend="GtkUIManager">GtkUIManager</link>.
</para> </para>
</listitem> </listitem>
<listitem> <listitem>
<para> <para>
If your GnomeUIInfo entries use GNOME_APP_PIXMAP_DATA or If your GnomeUIInfo entries use GNOME_APP_PIXMAP_DATA or
GNOME_APP_PIXMAP_FILENAME for pixmaps, you have to create a GNOME_APP_PIXMAP_FILENAME for pixmaps, you have to create a
<link linkend="GtkIconFactory">GtkIconFactory</link>, add it #GtkIconFactory, add it to the list of default factories, then create a
to the list of default factories, then create a #GtkIconSet for each of your own icons. Add the sets to the factory, and
<link linkend="GtkIconSet">GtkIconSet</link> for each of your use the id in the #GtkActionEntry like a regular GTK+ stock id.
own icons. Add the sets to the factory, and use the id in the
<link linkend="GtkActionEntry">GtkActionEntry</link> like a
regular GTK+ stock id.
</para> </para>
</listitem> </listitem>
</orderedlist> </orderedlist>
@ -184,8 +168,8 @@
<para> <para>
The following code shows a declaration of a simple menu bar to The following code shows a declaration of a simple menu bar to
be used with <function>gnome_app_fill_menu()</function> or be used with gnome_app_fill_menu() or similar. The menu hierarchy looks
similar. The menu hierarchy looks like this: like this:
</para> </para>
<itemizedlist> <itemizedlist>
@ -269,15 +253,12 @@ static GnomeUIInfo menubar[] = {
The following code is the set of actions that are present in The following code is the set of actions that are present in
the <link linkend="gnomeuiinfo-example">previous the <link linkend="gnomeuiinfo-example">previous
example</link>. Note that the toggle and radio entries are example</link>. Note that the toggle and radio entries are
separate from normal actions. Also, note that <link separate from normal actions. Also, note that #GtkActionEntry
linkend="GtkActionEntry">GtkActionEntry</link> structures take structures take key names in the format of gdk_accelerator_parse()
key names in the format of gdk_accelerator_parse() rather than rather than key values plus modifiers; you will have to convert these
key values plus modifiers; you will have to convert these values by hand. For example, %GDK_F11 with no modifiers is equivalent
values by hand. For example, <constant>GDK_F11</constant> to a key name of <literal>"F11"</literal>. Likewise, <literal>"o"</literal>
with no modifiers is equivalent to a key name of with %GDK_CONTROL_MASK is equivalent to <literal>"&lt;ontrol&gt;O"</literal>.
<literal>"F11"</literal>. Likewise, <literal>"o"</literal>
with <constant>GDK_CONTROL_MASK</constant> is equivalent to
<literal>"&lt;ontrol&gt;O"</literal>.
</para> </para>
<programlisting> <programlisting>
@ -311,9 +292,8 @@ static GtkRadioActionEntry radio_entries[] = {
<para> <para>
After extracting the actions, you will need to create an XML After extracting the actions, you will need to create an XML
description of the actual layout of your menus and toolbars description of the actual layout of your menus and toolbars
for use with <link linkend="GtkUIManager">GtkUIManager</link>. for use with #GtkUIManager. The following code shows a simple
The following code shows a simple menu bar that corresponds to menu bar that corresponds to the <link linkend="gnomeuiinfo-example">previous
the <link linkend="gnomeuiinfo-example">previous
example</link>. Note that the <guimenu>File</guimenu> and example</link>. Note that the <guimenu>File</guimenu> and
<guimenu>View</guimenu> menus have their names specified in <guimenu>View</guimenu> menus have their names specified in
the <link linkend="gnomeuiinfo-action-entries">action the <link linkend="gnomeuiinfo-action-entries">action
@ -349,16 +329,12 @@ static const char *ui_description =
<title>Creating the Menu Bar</title> <title>Creating the Menu Bar</title>
<para> <para>
In this last example, we will create a <link In this last example, we will create a #GtkActionGroup based on the
linkend="GtkActionGroup">GtkActionGroup</link> based on the <link linkend="gnomeuiinfo-action-entries">action entries</link>
<link linkend="gnomeuiinfo-action-entries">action we created above. We will then create a #GtkUIManager with the <link
entries</link> we created above. We will then create a <link
linkend="GtkUIManager">GtkUIManager</link> with the <link
linkend="gnomeuiinfo-xml">XML description</link> of the menu linkend="gnomeuiinfo-xml">XML description</link> of the menu
layout. We will also extract the accelerator group and the layout. We will also extract the accelerator group and the
widgets from the <link widgets from the #GtkUIManager put them into a window.
linkend="GtkUIManager">GtkUIManager</link> put them into a
window.
</para> </para>
<programlisting> <programlisting>
@ -370,7 +346,7 @@ GtkUIManager *ui_manager;
GtkAccelGroup *accel_group; GtkAccelGroup *accel_group;
GError *error; GError *error;
register_my_stock_icons (); register_my_stock_icons (<!-- -->);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL); window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
@ -382,7 +358,7 @@ gtk_action_group_add_actions (action_group, entries, G_N_ELEMENTS (entries), win
gtk_action_group_add_toggle_actions (action_group, toggle_entries, G_N_ELEMENTS (toggle_entries), window); gtk_action_group_add_toggle_actions (action_group, toggle_entries, G_N_ELEMENTS (toggle_entries), window);
gtk_action_group_add_radio_actions (action_group, radio_entries, G_N_ELEMENTS (radio_entries), 0, radio_action_callback, window); gtk_action_group_add_radio_actions (action_group, radio_entries, G_N_ELEMENTS (radio_entries), 0, radio_action_callback, window);
ui_manager = gtk_ui_manager_new (); ui_manager = gtk_ui_manager_new (<!-- -->);
gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
accel_group = gtk_ui_manager_get_accel_group (ui_manager); accel_group = gtk_ui_manager_get_accel_group (ui_manager);
@ -431,12 +407,12 @@ register_my_stock_icons (void)
GtkIconSource *icon_source; GtkIconSource *icon_source;
gint i; gint i;
icon_factory = gtk_icon_factory_new (); icon_factory = gtk_icon_factory_new (<!-- -->);
for (i = 0; i &lt; n_stock_icons; i++) for (i = 0; i &lt; n_stock_icons; i++)
{ {
icon_set = gtk_icon_set_new (); icon_set = gtk_icon_set_new (<!-- -->);
icon_source = gtk_icon_source_new (); icon_source = gtk_icon_source_new (<!-- -->);
gtk_icon_source_set_filename (icon_source, stock_icons[i].filename); gtk_icon_source_set_filename (icon_source, stock_icons[i].filename);
gtk_icon_set_add_source (icon_set, icon_source); gtk_icon_set_add_source (icon_set, icon_source);
gtk_icon_source_free (icon_source); gtk_icon_source_free (icon_source);

View File

@ -3,10 +3,9 @@
<title>Migrating from GnomeColorPicker to GtkColorButton</title> <title>Migrating from GnomeColorPicker to GtkColorButton</title>
<para> <para>
Since version 2.6, GTK+ provides the <link linkend="GtkColorButton">GtkColorButton</link> Since version 2.6, GTK+ provides the #GtkColorButton
widget as a replacement for the <structname>GnomeColorPicker</structname> widget as a replacement for the <structname>GnomeColorPicker</structname>
widget in the libgnomeui widget in the libgnomeui library.
library.
</para> </para>
<para> <para>

View File

@ -1,21 +1,18 @@
<chapter id="gtk-migrating-GtkComboBox"> <chapter id="gtk-migrating-GtkComboBox">
<title>Migrating from GtkOptionMenu and GtkCombo to GtkComboBox and GtkComboBoxEntry</title> <title>Migrating from GtkOptionMenu and GtkCombo to GtkComboBox and
GtkComboBoxEntry</title>
<para> <para>
Prior to 2.4, GTK+ offered two widgets for the task of selecting one Prior to 2.4, GTK+ offered two widgets for the task of selecting one
item from a list of options. item from a list of options. #GtkOptionMenu presents the list of
<link linkend="GtkOptionMenu">GtkOptionMenu</link> presents the list of options as a menu while #GtkCombo presents them in a Windows-style list
options as a menu while <link linkend="GtkCombo">GtkCombo</link> presents popup. The only difference between the two is that a #GtkCombo allows to
them in a Windows-style list popup. The only difference between the two manually edit the selected value, while the #GtkOptionMenu does not.
is that a <link linkend="GtkCombo">GtkCombo</link> allows to manually
edit the selected value, while the
<link linkend="GtkOptionMenu">GtkOptionMenu</link> does not.
</para> </para>
<para> <para>
In GTK+ 2.4, a unified API for list selection was introduced, with In GTK+ 2.4, a unified API for list selection was introduced, with
<link linkend="GtkComboBox">GtkComboBox</link> for the non-editable case #GtkComboBox for the non-editable case and #GtkComboBoxEntry for the
and <link linkend="GtkComboBoxEntry">GtkComboBoxEntry</link> for the
editable case. editable case.
The selection of the display style &mdash; menu or list &mdash; The selection of the display style &mdash; menu or list &mdash;
is no longer done at the API level, but has been made themeable via is no longer done at the API level, but has been made themeable via
@ -28,12 +25,12 @@
<para> <para>
Here is an example of a simple, but typical use of Here is an example of a simple, but typical use of
<link linkend="GtkOptionMenu">GtkOptionMenu</link>: #GtkOptionMenu:
<informalexample><programlisting> <informalexample><programlisting>
GtkWidget *option_menu, *menu, *menu_item; GtkWidget *option_menu, *menu, *menu_item;
option_menu = gtk_option_menu_new (); option_menu = gtk_option_menu_new (<!-- -->);
menu = gtk_menu_new (); menu = gtk_menu_new (<!-- -->);
menu_item = gtk_menu_item_new_with_label ("First Item"); menu_item = gtk_menu_item_new_with_label ("First Item");
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
@ -48,23 +45,22 @@ gtk_widget_show (menu_item);
gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu); gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu);
</programlisting></informalexample> </programlisting></informalexample>
In order to react to the user's selection, connect to the "changed" In order to react to the user's selection, connect to the "changed"
signal on the option menu and use <link linkend="gtk-option-menu-get-history"><function>gtk_option_menu_get_history()</function></link> signal on the option menu and use gtk_option_menu_get_history()
to retrieve the index of the selected item. to retrieve the index of the selected item.
</para> </para>
<para> <para>
And here is how it would be done with a And here is how it would be done with a #GtkComboBox:
<link linkend="GtkComboBox">GtkComboBox</link>:
<informalexample><programlisting> <informalexample><programlisting>
GtkWidget *combo_box; GtkWidget *combo_box;
combo_box = gtk_combo_box_new_text (); combo_box = gtk_combo_box_new_text (<!-- -->);
gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), "First Item"); gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), "First Item");
gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), "Second Item"); gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), "Second Item");
gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), "Third Item"); gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), "Third Item");
</programlisting></informalexample> </programlisting></informalexample>
In order to react to the user's selection, connect to the "changed" In order to react to the user's selection, connect to the "changed"
signal on the combo box and use <link linkend="gtk-combo-box-get-active"><function>gtk_combo_box_get_active()</function></link> signal on the combo box and use gtk_combo_box_get_active()
to retrieve the index of the selected item. to retrieve the index of the selected item.
</para> </para>
@ -73,8 +69,8 @@ gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), "Third Item");
<informalexample><programlisting> <informalexample><programlisting>
GtkWidget *option_menu, *menu, *menu_item; GtkWidget *option_menu, *menu, *menu_item;
option_menu = gtk_option_menu_new (); option_menu = gtk_option_menu_new (<!-- -->);
menu = gtk_menu_new (); menu = gtk_menu_new (<!-- -->);
menu_item = gtk_image_menu_item_new_with_label ("First Item"); menu_item = gtk_image_menu_item_new_with_label ("First Item");
gtk_image_menu_item_set_image (gtk_image_new_from_pixbuf (pixbuf1)); gtk_image_menu_item_set_image (gtk_image_new_from_pixbuf (pixbuf1));
@ -93,8 +89,7 @@ gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu);
</programlisting></informalexample> </programlisting></informalexample>
</para> </para>
<para> <para>
can be done using a <link linkend="GtkComboBox">GtkComboBox</link> can be done using a #GtkComboBox as follows:
as follows:
<informalexample><programlisting> <informalexample><programlisting>
GtkListStore *store; GtkListStore *store;
GtkTreeIter iter; GtkTreeIter iter;
@ -112,13 +107,13 @@ gtk_list_store_set (store, &amp;iter, 0, pixbuf3, 1, "Third Item", -1);
combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store)); combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
renderer = gtk_cell_renderer_pixbuf_new (); renderer = gtk_cell_renderer_pixbuf_new (<!-- -->);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, FALSE); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer, gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
"pixbuf", 0, "pixbuf", 0,
NULL); NULL);
renderer = gtk_cell_renderer_text_new (); renderer = gtk_cell_renderer_text_new (<!-- -->);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer, gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
"text", 1, "text", 1,
@ -131,8 +126,7 @@ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
<title>Migrating from GtkCombo to GtkComboBoxEntry</title> <title>Migrating from GtkCombo to GtkComboBoxEntry</title>
<para> <para>
Here is an example of a simple, but typical use of a Here is an example of a simple, but typical use of a #GtkCombo:
<link linkend="GtkCombo">GtkCombo</link>:
<informalexample><programlisting> <informalexample><programlisting>
GtkWidget *combo; GtkWidget *combo;
GList *items = NULL; GList *items = NULL;
@ -141,7 +135,7 @@ items = g_list_append (items, "First Item");
items = g_list_append (items, "Second Item"); items = g_list_append (items, "Second Item");
items = g_list_append (items, "Third Item"); items = g_list_append (items, "Third Item");
combo = gtk_combo_new (); combo = gtk_combo_new (<!-- -->);
gtk_combo_set_popdown_strings (GTK_COMBO (combo), items); gtk_combo_set_popdown_strings (GTK_COMBO (combo), items);
</programlisting></informalexample> </programlisting></informalexample>
In order to react to the user's selection, connect to the "changed" In order to react to the user's selection, connect to the "changed"
@ -150,9 +144,9 @@ gtk_combo_set_popdown_strings (GTK_COMBO (combo), items);
to retrieve the selected text. to retrieve the selected text.
</para> </para>
<para> <para>
And here is how it would be done using <link linkend="GtkComboBoxEntry">GtkComboBoxEntry</link>: And here is how it would be done using #GtkComboBoxEntry:
<informalexample><programlisting> <informalexample><programlisting>
combo_box = gtk_combo_box_entry_new_text (); combo_box = gtk_combo_box_entry_new_text (<!-- -->);
gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), "First Item"); gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), "First Item");
gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), "Second Item"); gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), "Second Item");
@ -170,8 +164,7 @@ gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), "Third Item");
<para> <para>
The new widgets have more to offer than a mere combination of the The new widgets have more to offer than a mere combination of the
features of <link linkend="GtkOptionMenu">GtkOptionMenu</link> and features of #GtkOptionMenu and #GtkCombo. Notable new features
<link linkend="GtkCombo">GtkCombo</link>. Notable new features
include: include:
<variablelist> <variablelist>
<varlistentry> <varlistentry>
@ -181,29 +174,26 @@ gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), "Third Item");
would be a "color combo" where the individual items are small would be a "color combo" where the individual items are small
square color swatches. The new widgets support gridded display square color swatches. The new widgets support gridded display
with the functions with the functions
<link linkend="gtk-combo-box-set-wrap-width"><function>gtk_combo_box_set_wrap_width()</function></link>, gtk_combo_box_set_wrap_width(),
<link linkend="gtk-combo-box-set-row-span-column"><function>gtk_combo_box_set_row_span_column()</function></link> and gtk_combo_box_set_row_span_column() and
<link linkend ="gtk-combo-box-set-column-span-column"><function>gtk_combo_box_set_column_span_column()</function></link>. gtk_combo_box_set_column_span_column().
</para></listitem> </para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>Display of icons</term> <term>Display of icons</term>
<listitem><para>An often-heard complaint about <listitem><para>An often-heard complaint about #GtkOptionMenu is that
<link linkend="GtkOptionMenu">GtkOptionMenu</link> is that the the icons which appear in the image menu items in its menu are not
icons which appear in the image menu items in its menu are not
displayed in the button showing the selected item. This limitation displayed in the button showing the selected item. This limitation
has been removed in <link linkend="GtkComboBox">GtkComboBox</link>; has been removed in #GtkComboBox; the selected item appears in the
the selected item appears in the same way as the options in same way as the options in the popup.
the popup.
</para></listitem> </para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>Full tree model power</term> <term>Full tree model power</term>
<listitem><para> <listitem><para>
Since the new widgets are built around the same models that are Since the new widgets are built around the same models that are
used for <link linkend="GtkTreeView">GtkTreeView</link>, all of used for #GtkTreeView, all of the powerful machinery of tree models
the powerful machinery of tree models and cell renderers can be and cell renderers can be used.
used.
</para></listitem> </para></listitem>
</varlistentry> </varlistentry>
</variablelist> </variablelist>

View File

@ -14,30 +14,20 @@
<title>Migrating from GtkFileSelection to GtkFileChooser</title> <title>Migrating from GtkFileSelection to GtkFileChooser</title>
<para> <para>
<link linkend="GtkFileChooser">GtkFileChooser</link>, starting #GtkFileChooser, starting with GTK+ 2.4, is the new set of APIs for file
with GTK+ 2.4, is the new set of APIs for file selection widgets selection widgets and dialogs. Previous versions of GTK+ used #GtkFileSelection,
and dialogs. Previous versions of GTK+ used <link which has numerous problems.
linkend="GtkFileSelection">GtkFileSelection</link>, which has
numerous problems.
</para> </para>
<para> <para>
<link linkend="GtkFileChooser">GtkFileChooser</link> is an #GtkFileChooser is an abstract interface that can be implemented by widgets
abstract interface that can be implemented by widgets that perform that perform file selection tasks. Two widgets in GTK+ implement this
file selection tasks. Two widgets in GTK+ implement this interface: #GtkFileChooserDialog and #GtkFileChooserWidget. Most applications
interface: <link simply need to use #GtkFileChooserDialog, which is a dialog box that allows the
linkend="GtkFileChooserDialog">GtkFileChooserDialog</link> and user to select existing files for opening them, or to pick new filenames for
<link linkend="GtkFileChooserWidget">GtkFileChooserWidget</link>. saving documents. #GtkFileChooserWidget is for special applications that need to
Most applications simply need to use <link embed a file selection widget inside a larger window. In the context of GTK+,
linkend="GtkFileChooserDialog">GtkFileChooserDialog</link>, which #GtkFileChooserDialog is simply a #GtkDialog box with a #GtkFileChooserWidget.
is a dialog box that allows the user to select existing files for
opening them, or to pick new filenames for saving documents.
<link linkend="GtkFileChooserWidget">GtkFileChooserWidget</link>
is for special applications that need to embed a file selection
widget inside a larger window. In the context of GTK+, <link
linkend="GtkFileChooserDialog">GtkFileChooserDialog</link> is
simply a <link linkend="GtkDialog">GtkDialog</link> box with a
<link linkend="GtkFileChooserWidget">GtkFileChooserWidget</link>
inside. inside.
</para> </para>
@ -45,10 +35,8 @@
<title>Creating a GtkFileChooserDialog</title> <title>Creating a GtkFileChooserDialog</title>
<para> <para>
To create a <link To create a #GtkFileChooserDialog, you simply call gtk_file_chooser_dialog_new().
linkend="GtkFileChooserDialog">GtkFileChooserDialog</link>, you This function is similar to gtk_dialog_new() in that it takes parameters for the
simply call gtk_file_chooser_dialog_new(). This function is
similar to gtk_dialog_new() in that it takes parameters for the
title of the dialog box and its transient parent, as well as its title of the dialog box and its transient parent, as well as its
buttons. In addition, it takes in an argument that determines buttons. In addition, it takes in an argument that determines
whether the file chooser dialog will be used for opening whether the file chooser dialog will be used for opening
@ -66,25 +54,21 @@
<title>Selection Modes</title> <title>Selection Modes</title>
<para> <para>
<link linkend="GtkFileChooser">GtkFileChooser</link> can be used #GtkFileChooser can be used in two modes, to select a single file at a
in two modes, to select a single file at a time or to select a time or to select a set of more than one file. To set this, use
set of more than one file. To set this, use
gtk_file_chooser_set_select_multiple(). In single-selection gtk_file_chooser_set_select_multiple(). In single-selection
mode, you can use gtk_file_chooser_get_filename() to get a file mode, you can use gtk_file_chooser_get_filename() to get a file
name from the local file system or gtk_file_chooser_get_uri() to name from the local file system or gtk_file_chooser_get_uri() to
get a full-formed URI. In multiple-selection mode, you can use get a full-formed URI. In multiple-selection mode, you can use
gtk_file_chooser_get_filenames() to get a <link gtk_file_chooser_get_filenames() to get a #GSList of filename strings, or
linkend="GSList">GSList</link> of filename strings, or
gtk_file_chooser_get_uris() to get a list of URI strings. gtk_file_chooser_get_uris() to get a list of URI strings.
</para> </para>
<para> <para>
Also, you can configure <link Also, you can configure #GtkFileChooser to select files
linkend="GtkFileChooser">GtkFileChooser</link> to select files
or folders. Consider a backup program that needs to let the or folders. Consider a backup program that needs to let the
user select a folder that will be backed up along with its user select a folder that will be backed up along with its
subfolders. To configure whether <link subfolders. To configure whether #GtkFileChooser is used to select
linkend="GtkFileChooser">GtkFileChooser</link> is used to select
files or folders, use gtk_file_chooser_set_action(). In files or folders, use gtk_file_chooser_set_action(). In
addition, this lets you configure whether the file chooser will addition, this lets you configure whether the file chooser will
be used to select existing files or folders (e.g. for be used to select existing files or folders (e.g. for
@ -99,10 +83,8 @@
<para> <para>
Many applications need to have a preview facility within their Many applications need to have a preview facility within their
file chooser dialogs. Previous to GTK+ 2.4, one needed to file chooser dialogs. Previous to GTK+ 2.4, one needed to
access the <link access the #GtkFileSelection widget hierarchy directly to hook in
linkend="GtkFileSelection">GtkFileSelection</link> widget a preview widget. With #GtkFileChooser, there is a
hierarchy directly to hook in a preview widget. With <link
linkend="GtkFileChooser">GtkFileChooser</link>, there is a
dedicated API to do this. dedicated API to do this.
</para> </para>
@ -132,18 +114,15 @@
<title>New features</title> <title>New features</title>
<para> <para>
New features in <link New features in #GtkFileChooser include the following:
linkend="GtkFileChooser">GtkFileChooser</link> include the
following:
</para> </para>
<itemizedlist> <itemizedlist>
<listitem> <listitem>
<para> <para>
Ability to select URIs rather than just local files. You Ability to select URIs rather than just local files. You
must use a <link must use a #GtkFileSystem implementation that supports this,
linkend="GtkFileSystem">GtkFileSystem</link> implementation for example the gnome-vfs backend.
that supports this, for example the gnome-vfs backend.
</para> </para>
</listitem> </listitem>
@ -166,9 +145,8 @@
</itemizedlist> </itemizedlist>
<para> <para>
To see how to use these features, please consult the <link To see how to use these features, please consult the #GtkFileChooser
linkend="GtkFileChooser">GtkFileChooser</link> reference reference documentation.
documentation.
</para> </para>
</section> </section>
</chapter> </chapter>

View File

@ -3,10 +3,8 @@
<title>Migrating from GnomeIconList to GtkIconView</title> <title>Migrating from GnomeIconList to GtkIconView</title>
<para> <para>
Since version 2.6, GTK+ provides the <link Since version 2.6, GTK+ provides the #GtkIconView widget. It is similar in
linkend="GtkIconView">GtkIconView</link> functionality to the <structname>GnomeIconList</structname> widget in the
widget. It is similar in functionality to the
<structname>GnomeIconList</structname> widget in the
libgnomeui library, both widgets provide a way to lay out named icons in libgnomeui library, both widgets provide a way to lay out named icons in
a grid. The distinctive feature of the GTK+ widget is that it follows the a grid. The distinctive feature of the GTK+ widget is that it follows the
model-view pattern, allowing it to share the actual data (i.e. the names model-view pattern, allowing it to share the actual data (i.e. the names
@ -14,19 +12,17 @@
</para> </para>
<para> <para>
<link linkend="GtkIconView">GtkIconView</link> currently doesn't support #GtkIconView currently doesn't support some features found in
some features found in <structname>GnomeIconList</structname>. Icons can <structname>GnomeIconList</structname>. Icons can not be positioned freely,
not be positioned freely, the spacing is not customizable, and it is not the spacing is not customizable, and it is not possible to edit the names of
possible to edit the names of icons. icons.
</para> </para>
<para> <para>
To convert an application that uses <structname>GnomeIconList</structname> To convert an application that uses <structname>GnomeIconList</structname>
to <link linkend="GtkIconView">GtkIconView</link>, the first step is to to #GtkIconView, the first step is to organize your data in a #GtkTreeModel.
organize your data in a <link linkend="GtkTreeModel">GtkTreeModel</link>.
<structname>GnomeIconList</structname> lets you directly insert data with <structname>GnomeIconList</structname> lets you directly insert data with
<function>gnome_icon_list_insert()</function> and gnome_icon_list_insert() and gnome_icon_list_insert_pixbuf() and their
<function>gnome_icon_list_insert_pixbuf()</function> and their
append variants. So, if you previously had a function to fill your icon append variants. So, if you previously had a function to fill your icon
list similar to this one: list similar to this one:
<informalexample><programlisting> <informalexample><programlisting>
@ -81,7 +77,7 @@
/* do other initialization... */ /* do other initialization... */
/* construct the GtkIconView */ /* construct the GtkIconView */
icon_view = gtk_icon_view_new (); icon_view = gtk_icon_view_new (<!-- -->);
model = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER); model = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER);
gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (icon_view), PIXBUF_COLUMN); gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (icon_view), PIXBUF_COLUMN);
@ -93,18 +89,15 @@
/* ... */ /* ... */
} }
</programlisting></informalexample> </programlisting></informalexample>
This example uses a <link linkend="GtkListStore">GtkListStore</link> as This example uses a #GtkListStore as model, but part of the elegance of the
model, but part of the elegance of the model-view pattern is that you can model-view pattern is that you can easily use another tree model implementation,
easily use another tree model implementation, or even write your own or even write your own custom tree model.
custom tree model.
</para> </para>
<para> <para>
Your application may make use of extra data attached to the icons in the Your application may make use of extra data attached to the icons in the
<structname>GnomeIconList</structname> via <structname>GnomeIconList</structname> via gnome_icon_list_set_icon_data() and
<function>gnome_icon_list_set_icon_data()</function> and gnome_icon_list_get_icon_data(). With #GtkIconView such data is most
<function>gnome_icon_list_get_icon_data()</function>. With
<link linkend="GtkIconView">GtkIconView</link> such data is most
conveniently stored in an extra column in the tree model, so you would conveniently stored in an extra column in the tree model, so you would
call a function like call a function like
<informalexample><programlisting> <informalexample><programlisting>
@ -124,7 +117,7 @@
} }
</programlisting></informalexample> </programlisting></informalexample>
assuming that your tree model has a <literal>DATA_COLUMN</literal> of type assuming that your tree model has a <literal>DATA_COLUMN</literal> of type
<literal>G_TYPE_POINTER</literal>. %G_TYPE_POINTER.
</para> </para>
<para> <para>
@ -140,8 +133,7 @@
<listitem><para> <listitem><para>
<structname>GtkIconView</structname> can not be frozen in the same <structname>GtkIconView</structname> can not be frozen in the same
way as <structname>GnomeIconList</structname> can with way as <structname>GnomeIconList</structname> can with
<function>gnome_icon_list_freeze()</function> and gnome_icon_list_freeze() and gnome_icon_list_thaw(). Instead you can
<function>gnome_icon_list_thaw()</function>. Instead you can
replace the whole model of a <structname>GtkIconView</structname>, replace the whole model of a <structname>GtkIconView</structname>,
instead of doing many small changes to the existing model. instead of doing many small changes to the existing model.
</para></listitem> </para></listitem>

View File

@ -51,7 +51,7 @@ do_popup_menu (GtkWidget *my_widget, GdkEventButton *event)
GtkWidget *menu; GtkWidget *menu;
int button, event_time; int button, event_time;
menu = gtk_menu_new (); menu = gtk_menu_new (<!-- -->);
g_signal_connect (menu, "deactivate", g_signal_connect (menu, "deactivate",
G_CALLBACK (gtk_widget_destroy), NULL); G_CALLBACK (gtk_widget_destroy), NULL);
@ -65,7 +65,7 @@ do_popup_menu (GtkWidget *my_widget, GdkEventButton *event)
else else
{ {
button = 0; button = 0;
event_time = gtk_get_current_event_time (); event_time = gtk_get_current_event_time (<!-- -->);
} }
gtk_menu_popup (GTK_MENU (popup), NULL, NULL, NULL, NULL, gtk_menu_popup (GTK_MENU (popup), NULL, NULL, NULL, NULL,
@ -127,7 +127,7 @@ my_widget_popup_menu_handler (GtkWidget *widget)
in the case where the <parameter>event</parameter> is in the case where the <parameter>event</parameter> is
<constant>NULL</constant>. This function should compute the <constant>NULL</constant>. This function should compute the
desired position for a menu when it is invoked through the desired position for a menu when it is invoked through the
keyboard. For example, <xref linkend="GtkEntry"/> aligns the keyboard. For example, #GtkEntry aligns the
top edge of its popup menu with the bottom edge of the entry. top edge of its popup menu with the bottom edge of the entry.
</para> </para>
</note> </note>
@ -138,9 +138,8 @@ my_widget_popup_menu_handler (GtkWidget *widget)
able to take the keyboard focus. In general, widgets should able to take the keyboard focus. In general, widgets should
be fully usable through the keyboard and not just the mouse. be fully usable through the keyboard and not just the mouse.
The very first step of this is to ensure that your widget The very first step of this is to ensure that your widget
turns on the <link turns on the %GTK_CAN_FOCUS <link
linkend="gtkwidgetflags"><constant>GTK_CAN_FOCUS</constant></link> linkend="gtkwidgetflags">flag</link>.
FLAG.
</para> </para>
</note> </note>
</section> </section>
@ -218,7 +217,7 @@ my_widget_expose_event_handler (GtkWidget *widget, GdkEventExpose *event)
<title>Why</title> <title>Why</title>
<para> <para>
With With
<function>gtk_accelerator_get_default_mod_mask()</function> gtk_accelerator_get_default_mod_mask()
you can test for modifier keys reliably; this way your key you can test for modifier keys reliably; this way your key
event handlers will work correctly even if event handlers will work correctly even if
<keycap>NumLock</keycap> or <keycap>CapsLock</keycap> are <keycap>NumLock</keycap> or <keycap>CapsLock</keycap> are
@ -233,8 +232,7 @@ my_widget_expose_event_handler (GtkWidget *widget, GdkEventExpose *event)
Modifiers are keys like <keycap>Control</keycap> and Modifiers are keys like <keycap>Control</keycap> and
<keycap>NumLock</keycap>. When implementing a <link <keycap>NumLock</keycap>. When implementing a <link
linkend="GtkWidget-key-press-event">GtkWidget::key_press_event</link> linkend="GtkWidget-key-press-event">GtkWidget::key_press_event</link>
handler, you should use handler, you should use gtk_accelerator_get_default_mod_mask() to
<function>gtk_accelerator_get_default_mod_mask()</function> to
test against modifier keys. This function returns a bit mask test against modifier keys. This function returns a bit mask
which encompasses all the modifiers which the user may be which encompasses all the modifiers which the user may be
actively pressing, such as <keycap>Control</keycap>, actively pressing, such as <keycap>Control</keycap>,
@ -254,7 +252,7 @@ my_widget_expose_event_handler (GtkWidget *widget, GdkEventExpose *event)
<literal>GDK_CONTROL_MASK | GDK_LOCK_MASK</literal>, and the <literal>GDK_CONTROL_MASK | GDK_LOCK_MASK</literal>, and the
simple test will fail. By taking the logical-and of simple test will fail. By taking the logical-and of
<structfield>event->state</structfield> and <structfield>event->state</structfield> and
<function>gtk_accelerator_get_default_mod_mask()</function>, you gtk_accelerator_get_default_mod_mask(), you
can ignore the modifiers which are not actively pressed by the can ignore the modifiers which are not actively pressed by the
user at the same time as the base key. user at the same time as the base key.
</para> </para>
@ -271,7 +269,7 @@ my_widget_key_press_event_handler (GtkWidget *widget, GdkEventKey *event)
{ {
guint modifiers; guint modifiers;
modifiers = gtk_accelerator_get_default_mod_mask (); modifiers = gtk_accelerator_get_default_mod_mask (<!-- -->);
if (event-&gt;keysym == GDK_F10 if (event-&gt;keysym == GDK_F10
&amp;&amp; (event-&gt;state &amp; modifiers) == GDK_CONTROL_MASK) &amp;&amp; (event-&gt;state &amp; modifiers) == GDK_CONTROL_MASK)

View File

@ -96,22 +96,17 @@ from functions?
<answer> <answer>
<para> <para>
See the documentation for <link linkend="GObject">GObject</link> and See the documentation for #GObject and #GtkObject. For #GObject note specifically
<link linkend="GtkObject">GtkObject</link>. For <link g_object_ref() and g_object_unref(). #GtkObject is a subclass of #GObject so the
linkend="GObject">GObject</link> note specifically <link same points apply, except that it has a "floating" state (explained in its
linkend="g-object-ref">g_object_ref()</link> and <link documentation).
linkend="g-object-unref">g_object_unref()</link>. <link
linkend="GtkObject">GtkObject</link> is a subclass of <link
linkend="GObject">GObject</link> so the same points apply, except that
it has a "floating" state (explained in its documentation).
</para> </para>
<para> <para>
For strings returned from functions, they will be declared "const" For strings returned from functions, they will be declared "const" (using
(using <link linkend="G-CONST-RETURN-CAPS">G_CONST_RETURN</link>) if they #G_CONST_RETURN) if they should not be freed. Non-const strings should be freed
should not be freed. Non-const strings should be freed with <link with g_free(). Arrays follow the same rule. (If you find an exception to the rules,
linkend="g-free">g_free()</link>. Arrays follow the same rule. (If please report a bug to <ulink
you find an exception to the rules, please report a bug to <ulink
url="http://bugzilla.gnome.org">http://bugzilla.gnome.org</ulink>.) url="http://bugzilla.gnome.org">http://bugzilla.gnome.org</ulink>.)
</para> </para>
@ -193,12 +188,10 @@ or Linux system with gettext installed, type <literal>info
gettext</literal> to read the documentation. gettext</literal> to read the documentation.
</para> </para>
<para> <para>
The short checklist on how to use gettext is: call The short checklist on how to use gettext is: call bindtextdomain() so gettext
<function>bindtextdomain()</function> so gettext can find the files can find the files containing your translations, call textdomain() to set the
containing your translations, call <function>textdomain()</function> default translation domain, then call gettext() to look up each string to be
to set the default translation domain, then call translated in the default domain. Conventionally, people define macros as
<function>gettext()</function> to look up each string to be translated
in the default domain. Conventionally, people define macros as
follows for convenience: follows for convenience:
<informalexample> <informalexample>
<programlisting> <programlisting>
@ -206,13 +199,10 @@ follows for convenience:
#define N_(x) x #define N_(x) x
</programlisting> </programlisting>
</informalexample> </informalexample>
You use <function>N_()</function> (N stands for no-op) to mark You use N_() (N stands for no-op) to mark a string for translation in a context
a string for translation in a context where a function call where a function call to gettext() is not allowed, such as in an array initializer.
to <function>gettext()</function> is not allowed, such as in You eventually have to call gettext() on the string to actually fetch the
an array initializer. You eventually have to call translation. _() both marks the string for translation and actually translates it.
<function>gettext()</function> on the string to actually fetch the
translation. <function>_()</function> both marks the string for
translation and actually translates it.
</para> </para>
<para> <para>
Code using these macros ends up looking like this: Code using these macros ends up looking like this:
@ -238,14 +228,10 @@ Code using these macros ends up looking like this:
</informalexample> </informalexample>
</para> </para>
<para> <para>
Libraries using gettext should use <function>dgettext()</function> Libraries using gettext should use dgettext() instead of gettext(), which allows
instead of <function>gettext()</function>, which allows them to specify the translation domain each time they ask for a translation. Libraries
them to specify the translation domain each time they should also avoid calling textdomain(), since they'll be specifying the domain instead
ask for a translation. Libraries should also avoid calling of using the default.For dgettext() the _() macro can be defined as:
<function>textdomain()</function>, since they'll be specifying
the domain instead of using the default.
For <function>dgettext()</function> the <function>_()</function> macro
can be defined as:
<informalexample> <informalexample>
<programlisting> <programlisting>
#define _(x) dgettext ("MyDomain", x) #define _(x) dgettext ("MyDomain", x)
@ -285,9 +271,7 @@ The zero byte doesn't occur as part of a character, so that UTF-8 strings can
More information about Unicode and UTF-8 can be found in the More information about Unicode and UTF-8 can be found in the
<ulink url="http://www.cl.cam.ac.uk/~mgk25/unicode.html">UTF-8 and Unicode FAQ for Unix/Linux</ulink>. <ulink url="http://www.cl.cam.ac.uk/~mgk25/unicode.html">UTF-8 and Unicode FAQ for Unix/Linux</ulink>.
GLib provides functions for converting strings between UTF-8 and other GLib provides functions for converting strings between UTF-8 and other
encodings, see encodings, see g_locale_to_utf8() and g_convert().
<link linkend="g-locale-to-utf8">g_locale_to_utf8()</link> and <link
linkend="g-convert">g_convert()</link>.
</para> </para>
<para> <para>
Text coming from external sources (e.g. files or user input), has to be Text coming from external sources (e.g. files or user input), has to be
@ -343,9 +327,8 @@ very convenient. Be careful when mixing hexadecimal escapes with ordinary text;
<listitem><para> <listitem><para>
If the string literals can be represented in an encoding which your toolchain If the string literals can be represented in an encoding which your toolchain
can handle (e.g. IS0-8859-1), you can write your source files in that encoding can handle (e.g. IS0-8859-1), you can write your source files in that encoding
and use <link linkend="g-convert">g_convert()</link> to convert the strings to and use g_convert() to convert the strings to UTF-8 at runtime. Note that this has
UTF-8 at runtime. Note that this has some runtime overhead, so you may want to some runtime overhead, so you may want to move the conversion out of inner loops.
move the conversion out of inner loops.
</para></listitem> </para></listitem>
</varlistentry> </varlistentry>
</variablelist> </variablelist>
@ -429,28 +412,19 @@ How do I load an image or animation from a file?
<answer> <answer>
<para> <para>
To load an image file straight into a display widget, use <link To load an image file straight into a display widget, use gtk_image_new_from_file()
linkend="gtk-image-new-from-file">gtk_image_new_from_file()</link> <footnote><para> If the file load fails, gtk_image_new_from_file() will display no
<footnote><para> If the file load fails, <link image graphic &mdash; to detect a failed load yourself, use gdk_pixbuf_new_from_file()
linkend="gtk-image-new-from-file">gtk_image_new_from_file()</link> directly, then gtk_image_new_from_pixbuf().</para></footnote>.
will display a "broken image" graphic &mdash; to detect a failed load To load an image for another purpose, use gdk_pixbuf_new_from_file(). To load an
yourself, use <link animation, use gdk_pixbuf_animation_new_from_file().
linkend="gdk-pixbuf-new-from-file">gdk_pixbuf_new_from_file()</link> gdk_pixbuf_animation_new_from_file() can also load non-animated images, so use it
directly then <link in combination with gdk_pixbuf_animation_is_static_image() to load a file of unknown
linkend="gtk-image-new-from-pixbuf">gtk_image_new_from_pixbuf()</link>. type.
</para></footnote>. To load an image for another purpose, use <link
linkend="gdk-pixbuf-new-from-file">gdk_pixbuf_new_from_file()</link>.
To load an animation, use <link
linkend="gdk-pixbuf-animation-new-from-file">gdk_pixbuf_animation_new_from_file()</link>.
<link
linkend="gdk-pixbuf-animation-new-from-file">gdk_pixbuf_animation_new_from_file()</link>
can also load non-animated images, so use it in combination with
<link
linkend="gdk-pixbuf-animation-is-static-image">gdk_pixbuf_animation_is_static_image()</link> to load a file of unknown type.
</para> </para>
<para> <para>
To load an image or animation file asynchronously (without blocking), use To load an image or animation file asynchronously (without blocking), use
<link linkend="GdkPixbufLoader">GdkPixbufLoader</link>. #GdkPixbufLoader.
</para> </para>
</answer> </answer>
@ -463,8 +437,7 @@ How do I draw text ?
<answer> <answer>
<para> <para>
To draw a piece of text, use a Pango layout and To draw a piece of text, use a Pango layout and gdk_draw_layout(),
<link linkend="gdk-draw-layout">gdk_draw_layout()</link>,
using code like the following: using code like the following:
<informalexample> <informalexample>
<programlisting> <programlisting>
@ -476,7 +449,7 @@ using code like the following:
g_object_unref (layout); g_object_unref (layout);
</programlisting> </programlisting>
</informalexample> </informalexample>
Do not use the deprecated <link linkend="GdkFont">GdkFont</link> and <link linkend="gdk-draw-text">gdk_draw_text()</link>. Do not use the deprecated #GdkFont and gdk_draw_text().
</para> </para>
<para> <para>
@ -498,9 +471,7 @@ How do I measure the size of a piece of text ?
<answer> <answer>
<para> <para>
To obtain the size of a piece of text, use a Pango layout and To obtain the size of a piece of text, use a Pango layout and
<link pango_layout_get_pixel_size(), using code like the following:
linkend="pango-layout-get-pixel-size">pango_layout_get_pixel_size()</link>,
using code like the following:
<informalexample> <informalexample>
<programlisting> <programlisting>
layout = gtk_widget_create_pango_layout (widget, text); layout = gtk_widget_create_pango_layout (widget, text);
@ -511,7 +482,7 @@ using code like the following:
g_object_unref (layout); g_object_unref (layout);
</programlisting> </programlisting>
</informalexample> </informalexample>
Do not use the deprecated function <link linkend="gdk-text-width">gdk_text_width()</link>. Do not use the deprecated function gdk_text_width().
</para> </para>
<para> <para>
@ -558,12 +529,9 @@ volatile GType dummy = GTK_TYPE_BLAH;
<answer> <answer>
<para> <para>
See <link linkend="TreeWidget">tree widget overview</link> &mdash; you See <link linkend="TreeWidget">tree widget overview</link> &mdash; you
should use the <link linkend="GtkTreeView">GtkTreeView</link> widget. should use the #GtkTreeView widget. (A list is just a tree with no branches,
(A list is just a tree with no branches, so the tree widget is used so the tree widget is used for lists as well.) Do not use the deprecated
for lists as well.) Do not use the deprecated widgets <link widgets #GtkTree or #GtkCList/#GtkCTree in newly-written code, they are
linkend="GtkTree">GtkTree</link> or <link
linkend="GtkCList">GtkCList</link>/<link
linkend="GtkCTree">GtkCTree</link> in newly-written code, they are
less flexible and result in an inferior user interface. less flexible and result in an inferior user interface.
</para> </para>
</answer> </answer>
@ -577,17 +545,13 @@ less flexible and result in an inferior user interface.
<answer> <answer>
<para> <para>
See <link linkend="TextWidget">text widget overview</link> &mdash; you See <link linkend="TextWidget">text widget overview</link> &mdash; you
should use the <link linkend="GtkTextView">GtkTextView</link> widget. should use the #GtkTextView widget. Do not use the deprecated widget #GtkText
Do not use the deprecated widget <link in newly-written code, it has a number of problems that are best avoided.
linkend="GtkText">GtkText</link> in newly-written code, it has a
number of problems that are best avoided.
</para> </para>
<para> <para>
If you only have a small amount of text, <link If you only have a small amount of text, #GtkLabel may also be appropriate of course.
linkend="GtkLabel">GtkLabel</link> may also be appropriate of course. It can be made selectable with gtk_label_set_selectable(). For a single-line text
It can be made selectable with <link linkend="gtk-label-set-selectable"> entry, see #GtkEntry.
gtk_label_set_selectable()</link>. For a single-line text entry,
see <link linkend="GtkEntry">GtkEntry</link>.
</para> </para>
</answer> </answer>
</qandaentry> </qandaentry>
@ -600,11 +564,9 @@ see <link linkend="GtkEntry">GtkEntry</link>.
<answer> <answer>
<para> <para>
<link linkend="GtkImage">GtkImage</link> can display images #GtkImage can display images in just about any format GTK+ understands. You can also
in just about any format GTK+ understands. You can also use #GtkDrawingArea if you need to do something more complex, such as draw text or
use <link linkend="GtkDrawingArea">GtkDrawingArea</link> if you need graphics over the top of the image.
to do something more complex, such as draw text or graphics over the
top of the image.
</para> </para>
</answer> </answer>
</qandaentry> </qandaentry>
@ -617,31 +579,16 @@ would use a combo box?
<answer> <answer>
<para> <para>
With GTK+, a <link linkend="GtkOptionMenu">GtkOptionMenu</link> is With GTK+, a #GtkComboBox is the recommended widget to use for this use case.
recommended instead of a combo box, if the user is selecting from a This widget looks like either a combo box or the current option menu, depending
fixed set of options. That is, non-editable combo boxes are not on the current theme. If you need an editable text entry, use #GtkComboBoxEntry.
encouraged. <link linkend="GtkOptionMenu">GtkOptionMenu</link> is
much easier to use than <link linkend="GtkCombo">GtkCombo</link>
as well. Use <link linkend="GtkCombo">GtkCombo</link> only when you
need the editable text entry.
</para>
<para>
(As a future enhancement to GTK+, a new widget to replace <link
linkend="GtkOptionMenu">GtkOptionMenu</link> and <link
linkend="GtkCombo">GtkCombo</link> is planned. This widget will be
themeable to look like either a combo box or the current option menu,
and will address some shortcomings in the <link
linkend="GtkCombo">GtkCombo</link> API. <ulink
url="http://bugzilla.gnome.org/show_bug.cgi?id=50554">Bug
50554</ulink> tracks this issue, if you want to check status or post
comments.)
</para> </para>
</answer> </answer>
</qandaentry> </qandaentry>
</qandadiv> </qandadiv>
<qandadiv><title><link linkend="GtkWidget">GtkWidget</link></title> <qandadiv><title>#GtkWidget</title>
<qandaentry> <qandaentry>
<question><para> <question><para>
@ -649,23 +596,16 @@ How do I change the color of a widget?
</para></question> </para></question>
<answer><para> <answer><para>
See <link linkend="gtk-widget-modify-fg">gtk_widget_modify_fg()</link>, See gtk_widget_modify_fg(), gtk_widget_modify_bg(), gtk_widget_modify_base(),
<link linkend="gtk-widget-modify-bg">gtk_widget_modify_bg()</link>, and gtk_widget_modify_text(). See <link linkend="gtk-Resource-Files">GTK+
<link linkend="gtk-widget-modify-base">gtk_widget_modify_base()</link>, resource files</link> for more discussion. You can also change widget color by
and <link installing a resource file and parsing it with gtk_rc_add_default_file().
linkend="gtk-widget-modify-text">gtk_widget_modify_text()</link>. See
<link linkend="gtk-Resource-Files">GTK+ resource files</link> for more
discussion. You can also change widget color by installing a resource
file and parsing it with <link
linkend="gtk-rc-add-default-file">gtk_rc_add_default_file()</link>.
The advantage of a resource file is that users can then override the The advantage of a resource file is that users can then override the
color you've chosen. color you've chosen.
</para> </para>
<para>To change the background color for widgets such as <link <para>To change the background color for widgets such as #GtkLabel that have no
linkend="GtkLabel">GtkLabel</link> that have no background, place them background, place them in a #GtkEventBox and set the background of the event box.
in a <link linkend="GtkEventBox">GtkEventBox</link> and set the
background of the event box.
</para></answer> </para></answer>
</qandaentry> </qandaentry>
@ -675,36 +615,32 @@ How do I change the font of a widget?
</para></question> </para></question>
<answer><para> <answer><para>
This has several possible answers, depending on what exactly you want to This has several possible answers, depending on what exactly you want to achieve.
achieve. One option is <link One option is gtk_widget_modify_font(). Note that this function can be used to
linkend="gtk-widget-modify-font">gtk_widget_modify_font()</link>. Note that this function can be used to change only the font size, as in the following example: change only the font size, as in the following example:
<programlisting> <programlisting>
PangoFontDesc *font_desc = pango_font_description_new (); PangoFontDesc *font_desc = pango_font_description_new (<!-- -->);
pango_font_description_set_size (font_desc, 40); pango_font_description_set_size (font_desc, 40);
gtk_widget_modify_font (widget, font); gtk_widget_modify_font (widget, font);
pango_font_description_free (font_desc); pango_font_description_free (font_desc);
</programlisting> </programlisting>
</para> </para>
<para> <para>
If you want to make the text of a label larger, you can use <link If you want to make the text of a label larger, you can use gtk_label_set_markup():
linkend="gtk-label-set-markup">gtk_label_set_markup()</link>:
<programlisting> <programlisting>
gtk_label_set_markup (label, "&lt;big&gt;big text&lt;/big&gt;"); gtk_label_set_markup (label, "&lt;big&gt;big text&lt;/big&gt;");
</programlisting> </programlisting>
This is preferred for many apps because it's a relative size to the This is preferred for many apps because it's a relative size to the
user's chosen font size. See <link user's chosen font size. See g_markup_escape_text() if you are constructing such
linkend="g-markup-escape-text">g_markup_escape_text()</link> strings on the fly.
if you are constructing such strings on the fly.
</para> </para>
<para> <para>
You can also change the font of a widget by putting You can also change the font of a widget by putting
<programlisting> <programlisting>
gtk-font-name = "Sans 30" gtk-font-name = "Sans 30"
</programlisting> </programlisting>
in a resource file and parsing it with <link in a resource file and parsing it with gtk_rc_add_default_file(). The advantage of
linkend="gtk-rc-add-default-file">gtk_rc_add_default_file()</link>. a resource file is that users can then override the font you've chosen. See
The advantage of a resource file is that users can then override the
font you've chosen. See
<link linkend="gtk-Resource-Files">GTK+ resource files</link> for more <link linkend="gtk-Resource-Files">GTK+ resource files</link> for more
discussion. discussion.
</para> </para>
@ -717,15 +653,14 @@ How do I disable/ghost/desensitize a widget?
</para></question> </para></question>
<answer><para> In GTK+ a disabled widget is termed "insensitive." See <answer><para> In GTK+ a disabled widget is termed "insensitive." See
<link gtk_widget_set_sensitive().
linkend="gtk-widget-set-sensitive">gtk_widget_set_sensitive()</link>.
</para></answer> </para></answer>
</qandaentry> </qandaentry>
</qandadiv> </qandadiv>
<qandadiv><title><link linkend="GtkTextView">GtkTextView</link></title> <qandadiv><title>#GtkTextView</title>
<qandaentry> <qandaentry>
<question><para> <question><para>
@ -733,13 +668,8 @@ How do I get the contents of the entire text widget as a string?
</para></question> </para></question>
<answer><para> <answer><para>
See gtk_text_buffer_get_bounds() and gtk_text_buffer_get_text()
See <link or gtk_text_iter_get_text().
linkend="gtk-text-buffer-get-bounds">gtk_text_buffer_get_bounds()</link>
and <link
linkend="gtk-text-buffer-get-text">gtk_text_buffer_get_text()</link>
or <link
linkend="gtk-text-iter-get-text">gtk_text_iter_get_text()</link>.
</para> </para>
<para> <para>
<informalexample><programlisting> <informalexample><programlisting>
@ -762,12 +692,13 @@ How do I make a text widget display its complete contents in a specific font?
</para></question> </para></question>
<answer><para> <answer><para>
If you use <link If you use gtk_text_buffer_insert_with_tags() with appropriate tags to select the
linkend="gtk-text-buffer-insert-with-tags">gtk_text_buffer_insert_with_tags()</link> with appropriate tags to select the font, the inserted text will have the desired appearance, but text typed in by the user before or after the tagged block will appear in the default style. font, the inserted text will have the desired appearance, but text typed in by the
user before or after the tagged block will appear in the default style.
</para> </para>
<para> <para>
To ensure that all text has the desired appearance, use <link To ensure that all text has the desired appearance, use gtk_widget_modify_font()
linkend="gtk-widget-modify-font">gtk_widget_modify_font()</link> to change the default font for the widget. to change the default font for the widget.
</para></answer> </para></answer>
</qandaentry> </qandaentry>
@ -781,21 +712,17 @@ How do I make a text view scroll to the end of the buffer automatically ?
<answer> <answer>
<para> <para>
The "insert" <link linkend="GtkTextMark">mark</link> marks the insertion point The "insert" <link linkend="GtkTextMark">mark</link> marks the insertion point
where <link linkend="gtk-text-buffer-insert">gtk_text_buffer_insert()</link> where gtk_text_buffer_insert() inserts new text into the buffer. The text is inserted
inserts new text into the buffer. The text is inserted
<emphasis>before</emphasis> the "insert" mark, so that it generally stays <emphasis>before</emphasis> the "insert" mark, so that it generally stays
at the end of the buffer. If it gets explicitly moved to some other position, at the end of the buffer. If it gets explicitly moved to some other position,
e.g. when the user selects some text, e.g. when the user selects some text, use gtk_text_buffer_move_mark() to set it to
use <link linkend="gtk-text-buffer-move-mark">gtk_text_buffer_move_mark()</link> the desired location before inserting more text. The "insert" mark of a buffer can be
to set it to the desired location before inserting more text. obtained with gtk_text_buffer_get_insert().
The "insert" mark of a buffer can be obtained with <link
linkend="gtk-text-buffer-get-insert">gtk_text_buffer_get_insert()</link>.
</para> </para>
<para> <para>
To ensure that the end of the buffer remains visible, use To ensure that the end of the buffer remains visible, use
<link gtk_text_view_scroll_to_mark() to scroll to the "insert" mark after inserting new text.
linkend="gtk-text-view-scroll-to-mark">gtk_text_view_scroll_to_mark()</link> to scroll to the "insert" mark after inserting new text.
</para> </para>
</answer> </answer>
</qandaentry> </qandaentry>
@ -803,7 +730,7 @@ To ensure that the end of the buffer remains visible, use
<qandadiv><title><link linkend="GtkTreeView">GtkTreeView</link></title> <qandadiv><title>#GtkTreeView</title>
<qandaentry> <qandaentry>
<question><para> <question><para>
@ -812,28 +739,25 @@ How do I associate some data with a row in the tree?
<answer> <answer>
<para> <para>
Remember that the <link linkend="GtkTreeModel">GtkTreeModel</link> Remember that the #GtkTreeModel columns don't necessarily have to be displayed.
columns don't necessarily have to be displayed. So you can put So you can put non-user-visible data in your model just like any other data, and
non-user-visible data in your model just like any other data, and retrieve it with gtk_tree_model_get(). See the
retrieve it with <link <link linkend="TreeWidget">tree widget overview</link>.
linkend="gtk-tree-model-get">gtk_tree_model_get()</link>.
See the <link linkend="TreeWidget">tree widget overview</link>.
</para> </para>
</answer> </answer>
</qandaentry> </qandaentry>
<qandaentry> <qandaentry>
<question><para> <question><para>
What's the <link linkend="GtkTreeView">GtkTreeView</link> equivalent of What's the #GtkTreeView equivalent of gtk_clist_find_row_from_data()?
<link linkend="gtk-clist-find-row-from-data">gtk_clist_find_row_from_data()</link>?
</para></question> </para></question>
<answer> <answer>
<para> <para>
As there is no separate data column in the <link linkend="GtkTreeModel">GtkTreeModel</link>, there's no As there is no separate data column in the #GtkTreeModel, there's no
built in function to find the iter from data. You can write a custom built in function to find the iter from data. You can write a custom
searching function to walk the tree and find the data, or use searching function to walk the tree and find the data, or use
<link linkend="gtk-tree-model-foreach">gtk_tree_model_foreach()</link>. gtk_tree_model_foreach().
</para> </para>
</answer> </answer>
</qandaentry> </qandaentry>
@ -845,53 +769,36 @@ How do I put an image and some text in the same column?
<answer> <answer>
<para> <para>
You can pack more than one <link You can pack more than one #GtkCellRenderer into a single #GtkTreeViewColumn using
linkend="GtkCellRenderer">GtkCellRenderer</link> into a single gtk_tree_view_column_pack_start() or gtk_tree_view_column_pack_end(). So pack both
<link linkend="GtkTreeViewColumn">GtkTreeViewColumn</link> using a #GtkCellRendererPixbuf and a #GtkCellRendererText into the column.
<link
linkend="gtk-tree-view-column-pack-start">gtk_tree_view_column_pack_start()</link> or <link linkend="gtk-tree-view-column-pack-end">gtk_tree_view_column_pack_end()</link>. So pack both a <link
linkend="GtkCellRendererPixbuf">GtkCellRendererPixbuf</link>
and a <link
linkend="GtkCellRendererText">GtkCellRendererText</link> into the
column.
</para> </para>
</answer> </answer>
</qandaentry> </qandaentry>
<qandaentry> <qandaentry>
<question><para> <question><para>
I can set data easily on my <link I can set data easily on my #GtkTreeStore/#GtkListStore models using
linkend="GtkTreeStore">GtkTreeStore</link>/<link gtk_list_store_set() and gtk_tree_store_set(), but can't read it back?
linkend="GtkListStore">GtkListStore</link> models using <link
linkend="gtk-tree-model-get">gtk_list_store_set()</link> and <link
linkend="gtk-tree-model-get">gtk_tree_store_set()</link>, but can't read
it back?
</para></question> </para></question>
<answer> <answer>
<para> <para>
Both the <link Both the #GtkTreeStore and the #GtkListStore implement the #GtkTreeModel
linkend="GtkTreeStore">GtkTreeStore</link> and the <link interface. Consequentially, the can use any function this interface implements.
linkend="GtkListStore">GtkListStore</link> implement the The easiest way to read a set of data back is to use gtk_tree_model_get().
<link linkend="GtkTreeModel">GtkTreeModel</link>
interface. Consequentially, the can use any function
this interface implements. The easiest way to read a
set of data back is to use
<link
linkend="gtk-tree-model-get">gtk_tree_model_get()</link>.
</para> </para>
</answer> </answer>
</qandaentry> </qandaentry>
<qandaentry> <qandaentry>
<question><para> <question><para>
How do I change the way that numbers are formatted by <link linkend="GtkTreeView">GtkTreeView</link>? How do I change the way that numbers are formatted by #GtkTreeView?
</para></question> </para></question>
<answer><para> <answer><para>
Use <link linkend="gtk-tree-view-insert-column-with-data-func">gtk_tree_view_insert_column_with_data_func()</link> Use gtk_tree_view_insert_column_with_data_func()
or <link linkend="gtk-tree-view-column-set-cell-data-func">gtk_tree_view_column_set_cell_data_func()</link> or gtk_tree_view_column_set_cell_data_func() and do the conversion from number to
and do the conversion from number to string yourself (with, say, string yourself (with, say, g_strdup_printf()).
<link linkend="g-strdup-printf">g_strdup_printf()</link>).
</para> </para>
<para> <para>
@ -937,15 +844,15 @@ set_up_new_columns (GtkTreeView *myview)
gtk_tree_view_set_model (myview, GTK_TREE_MODEL (mycolumns)); gtk_tree_view_set_model (myview, GTK_TREE_MODEL (mycolumns));
/* Create a GtkCellRendererText */ /* Create a GtkCellRendererText */
renderer = gtk_cell_renderer_text_new (); renderer = gtk_cell_renderer_text_new (<!-- -->);
/* Create a new column that has a title ("Example column"), /* Create a new column that has a title ("Example column"),
* uses the above created renderer that will render the double * uses the above created renderer that will render the double
* value into text from the associated model's rows. * value into text from the associated model's rows.
*/ */
column = gtk_tree_view_column_new (); column = gtk_tree_view_column_new (<!-- -->);
gtk_tree_view_column_set_title (column, "Example column"); gtk_tree_view_column_set_title (column, "Example column");
renderer = gtk_cell_renderer_text_new (); renderer = gtk_cell_renderer_text_new (<!-- -->);
gtk_tree_view_column_pack_start (column, renderer, TRUE); gtk_tree_view_column_pack_start (column, renderer, TRUE);
/* Append the new column after the GtkTreeView's previous columns. */ /* Append the new column after the GtkTreeView's previous columns. */
@ -972,7 +879,7 @@ How do I hide the expander arrows in my tree view ?
<answer><para> <answer><para>
Set the expander-column property of the tree view to a hidden column. Set the expander-column property of the tree view to a hidden column.
See <link linkend="gtk-tree-view-set-expander-column">gtk_tree_view_set_expander_column()</link> and <link linkend="gtk-tree-view-column-set-visible">gtk_tree_view_column_set_visible()</link>. See gtk_tree_view_set_expander_column() and gtk_tree_view_column_set_visible().
</para></answer> </para></answer>
</qandaentry> </qandaentry>

View File

@ -6,7 +6,8 @@
</refmeta> </refmeta>
<refnamediv> <refnamediv>
<refname>Text Widget Overview</refname><refpurpose>Overview of <link linkend="GtkTextBuffer">GtkTextBuffer</link>, <link linkend="GtkTextView">GtkTextView</link>, and friends</refpurpose> <refname>Text Widget Overview</refname>
<refpurpose>Overview of #GtkTextBuffer, #GtkTextView, and friends</refpurpose>
</refnamediv> </refnamediv>
<refsect1> <refsect1>
@ -14,11 +15,9 @@
<para> <para>
GTK+ has an extremely powerful framework for multiline text editing. The GTK+ has an extremely powerful framework for multiline text editing. The
primary objects involved in the process are <link primary objects involved in the process are #GtkTextBuffer, which represents the
linkend="GtkTextBuffer">GtkTextBuffer</link>, which represents the text being text being edited, and #GtkTextView, a widget which can display a #GtkTextBuffer.
edited, and <link linkend="GtkTextView">GtkTextView</link>, a widget which can Each buffer can be displayed by any number of views.
display a <link linkend="GtkTextBuffer">GtkTextBuffer</link>. Each buffer can
be displayed by any number of views.
</para> </para>
<para> <para>
@ -38,15 +37,12 @@ be called "bold" and make the text inside the tag bold. However, the tag
concept is more general than that; tags don't have to affect appearance. They concept is more general than that; tags don't have to affect appearance. They
can instead affect the behavior of mouse and key presses, "lock" a range of can instead affect the behavior of mouse and key presses, "lock" a range of
text so the user can't edit it, or countless other things. A tag is text so the user can't edit it, or countless other things. A tag is
represented by a represented by a #GtkTextTag object. One #GtkTextTag can be applied to any number
<link linkend="GtkTextTag">GtkTextTag</link> object. One <link of text ranges in any number of buffers.
linkend="GtkTextTag">GtkTextTag</link> can be applied to any number of text
ranges in any number of buffers.
</para> </para>
<para> <para>
Each tag is stored in a <link Each tag is stored in a #GtkTextTagTable. A tag table defines a set of
linkend="GtkTextTagTable">GtkTextTagTable</link>. A tag table defines a set of
tags that can be used together. Each buffer has one tag table associated with tags that can be used together. Each buffer has one tag table associated with
it; only tags from that tag table can be used with the buffer. A single tag it; only tags from that tag table can be used with the buffer. A single tag
table can be shared between multiple buffers, however. table can be shared between multiple buffers, however.
@ -60,9 +56,8 @@ is convenient if you're creating tags on-the-fly).
<para> <para>
Most text manipulation is accomplished with <firstterm>iterators</firstterm>, Most text manipulation is accomplished with <firstterm>iterators</firstterm>,
represented by a <link linkend="GtkTextIter">GtkTextIter</link>. An iterator represented by a #GtkTextIter. An iterator represents a position between two
represents a position between two characters in the text buffer. <link characters in the text buffer. #GtkTextIter is a struct designed to be allocated
linkend="GtkTextIter">GtkTextIter</link> is a struct designed to be allocated
on the stack; it's guaranteed to be copiable by value and never contain any on the stack; it's guaranteed to be copiable by value and never contain any
heap-allocated data. Iterators are not valid indefinitely; whenever the buffer heap-allocated data. Iterators are not valid indefinitely; whenever the buffer
is modified in a way that affects the number of characters in the buffer, all is modified in a way that affects the number of characters in the buffer, all
@ -73,11 +68,10 @@ number of characters you pass through a state with a different number).
<para> <para>
Because of this, iterators can't be used to preserve positions across buffer Because of this, iterators can't be used to preserve positions across buffer
modifications. To preserve a position, the <link modifications. To preserve a position, the #GtkTextMark object is ideal. You can
linkend="GtkTextMark">GtkTextMark</link> object is ideal. You can think of a think of a mark as an invisible cursor or insertion point; it floats in the buffer,
mark as an invisible cursor or insertion point; it floats in the buffer, saving saving a position. If the text surrounding the mark is deleted, the mark remains
a position. If the text surrounding the mark is deleted, the mark remains in in the position the text once occupied; if text is inserted at the mark, the
the position the text once occupied; if text is inserted at the mark, the
mark ends up either to the left or to the right of the new text, depending on mark ends up either to the left or to the right of the new text, depending on
its <firstterm>gravity</firstterm>. The standard text cursor in left-to-right its <firstterm>gravity</firstterm>. The standard text cursor in left-to-right
languages is a mark with right gravity, because it stays to the right of languages is a mark with right gravity, because it stays to the right of
@ -86,21 +80,18 @@ inserted text.
<para> <para>
Like tags, marks can be either named or anonymous. There are two marks built-in Like tags, marks can be either named or anonymous. There are two marks built-in
to <link linkend="GtkTextBuffer">GtkTextBuffer</link>; these are named to #GtkTextBuffer; these are named <literal>"insert"</literal> and
<literal>"insert"</literal> and <literal>"selection_bound"</literal> and refer <literal>"selection_bound"</literal> and refer to the insertion point and the
to the insertion point and the boundary of the selection which is not the boundary of the selection which is not the insertion point, respectively. If no
insertion point, respectively. If no text is selected, these two marks will be text is selected, these two marks will be in the same position. You can manipulate
in the same position. You can manipulate what is selected and where the cursor what is selected and where the cursor appears by moving these marks around.
appears by moving these marks around.
<footnote> <footnote>
<para> <para>
If you want to place the cursor in response to a user action, be sure to use If you want to place the cursor in response to a user action, be sure to use
<link gtk_text_buffer_place_cursor(), which moves both at once without causing a
linkend="gtk-text-buffer-place-cursor">gtk_text_buffer_place_cursor()</link>, temporary selection (moving one then the other temporarily selects the range in
which moves both at once between the old and new positions).
without causing a temporary selection (moving one then the other temporarily
selects the range in between the old and new positions).
</para> </para>
</footnote> </footnote>
</para> </para>
@ -123,13 +114,12 @@ considered a line separator.
<title>Simple Example</title> <title>Simple Example</title>
<para> <para>
The simplest usage of <link linkend="GtkTextView">GtkTextView</link> The simplest usage of #GtkTextView might look like this:
might look like this:
<informalexample><programlisting> <informalexample><programlisting>
GtkWidget *view; GtkWidget *view;
GtkTextBuffer *buffer; GtkTextBuffer *buffer;
view = gtk_text_view_new (); view = gtk_text_view_new (<!-- -->);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
@ -140,11 +130,10 @@ might look like this:
* will be emitted, such as "changed", "insert_text", and so on. * will be emitted, such as "changed", "insert_text", and so on.
*/ */
</programlisting></informalexample> </programlisting></informalexample>
In many cases it's also convenient to first create the buffer with <link In many cases it's also convenient to first create the buffer with
linkend="gtk-text-buffer-new">gtk_text_buffer_new()</link>, then create a gtk_text_buffer_new(), then create a widget for that buffer with
widget for that buffer with <link linkend="gtk-text-view-new-with-buffer">gtk_text_view_new_with_buffer()</link>. gtk_text_view_new_with_buffer(). Or you can change the buffer the widget
Or you can change the buffer the widget displays after the widget is created displays after the widget is created with gtk_text_view_set_buffer().
with <link linkend="gtk-text-view-set-buffer">gtk_text_view_set_buffer()</link>.
</para> </para>
</refsect1> </refsect1>
@ -154,21 +143,13 @@ with <link linkend="gtk-text-view-set-buffer">gtk_text_view_set_buffer()</link>.
<para> <para>
There are two ways to affect text attributes in There are two ways to affect text attributes in #GtkTextView.
<link linkend="GtkTextView">GtkTextView</link>. You can change the default attributes for a given #GtkTextView, and you can
You can change the default attributes for a given apply tags that change the attributes for a region of text. For text features
<link linkend="GtkTextView">GtkTextView</link>, and you can that come from the theme &mdash; such as font and foreground color &mdash; use
apply tags that change the attributes for a region of text. standard #GtkWidget functions such as gtk_widget_modify_font() or
For text features that come from the theme &mdash; such as gtk_widget_modify_text(). For other attributes there are dedicated methods on
font and foreground color &mdash; use standard #GtkTextView such as gtk_text_view_set_tabs().
<link linkend="GtkWidget">GtkWidget</link>
functions such as
<link linkend="gtk-widget-modify-font">gtk_widget_modify_font()</link>
or
<link linkend="gtk-widget-modify-text">gtk_widget_modify_text()</link>.
For other attributes there are dedicated methods on
<link linkend="GtkTextView">GtkTextView</link> such as
<link linkend="gtk-text-view-set-tabs">gtk_text_view_set_tabs()</link>.
<informalexample><programlisting> <informalexample><programlisting>
GtkWidget *view; GtkWidget *view;
@ -178,7 +159,7 @@ For other attributes there are dedicated methods on
GdkColor color; GdkColor color;
GtkTextTag *tag; GtkTextTag *tag;
view = gtk_text_view_new (); view = gtk_text_view_new (<!-- -->);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
@ -208,8 +189,7 @@ For other attributes there are dedicated methods on
<para> <para>
The <application>gtk-demo</application> application that comes with The <application>gtk-demo</application> application that comes with
GTK+ contains more example code for <link GTK+ contains more example code for #GtkTextView.
linkend="GtkTextView">GtkTextView</link>.
</para> </para>
</refsect1> </refsect1>