+Mon Feb 22 08:45:10 GMT 1999 Tony Gale <gale@gtk.org>
+
+ * docs/gtk_tut.sgml:
+ - Complete the ProgressBar API
+ - Fix the CList example code
+
+ * examples/clist/clist.c, examples/progressbar/progressbar.c:
+ Update from tutorial
+
Sun Feb 21 17:44:52 1999 Owen Taylor <otaylor@redhat.com>
* gtk/testgtkrc: Removed check-y/check-n backgrounds -
+Mon Feb 22 08:45:10 GMT 1999 Tony Gale <gale@gtk.org>
+
+ * docs/gtk_tut.sgml:
+ - Complete the ProgressBar API
+ - Fix the CList example code
+
+ * examples/clist/clist.c, examples/progressbar/progressbar.c:
+ Update from tutorial
+
Sun Feb 21 17:44:52 1999 Owen Taylor <otaylor@redhat.com>
* gtk/testgtkrc: Removed check-y/check-n backgrounds -
+Mon Feb 22 08:45:10 GMT 1999 Tony Gale <gale@gtk.org>
+
+ * docs/gtk_tut.sgml:
+ - Complete the ProgressBar API
+ - Fix the CList example code
+
+ * examples/clist/clist.c, examples/progressbar/progressbar.c:
+ Update from tutorial
+
Sun Feb 21 17:44:52 1999 Owen Taylor <otaylor@redhat.com>
* gtk/testgtkrc: Removed check-y/check-n backgrounds -
+Mon Feb 22 08:45:10 GMT 1999 Tony Gale <gale@gtk.org>
+
+ * docs/gtk_tut.sgml:
+ - Complete the ProgressBar API
+ - Fix the CList example code
+
+ * examples/clist/clist.c, examples/progressbar/progressbar.c:
+ Update from tutorial
+
Sun Feb 21 17:44:52 1999 Owen Taylor <otaylor@redhat.com>
* gtk/testgtkrc: Removed check-y/check-n backgrounds -
+Mon Feb 22 08:45:10 GMT 1999 Tony Gale <gale@gtk.org>
+
+ * docs/gtk_tut.sgml:
+ - Complete the ProgressBar API
+ - Fix the CList example code
+
+ * examples/clist/clist.c, examples/progressbar/progressbar.c:
+ Update from tutorial
+
Sun Feb 21 17:44:52 1999 Owen Taylor <otaylor@redhat.com>
* gtk/testgtkrc: Removed check-y/check-n backgrounds -
+Mon Feb 22 08:45:10 GMT 1999 Tony Gale <gale@gtk.org>
+
+ * docs/gtk_tut.sgml:
+ - Complete the ProgressBar API
+ - Fix the CList example code
+
+ * examples/clist/clist.c, examples/progressbar/progressbar.c:
+ Update from tutorial
+
Sun Feb 21 17:44:52 1999 Owen Taylor <otaylor@redhat.com>
* gtk/testgtkrc: Removed check-y/check-n backgrounds -
+Mon Feb 22 08:45:10 GMT 1999 Tony Gale <gale@gtk.org>
+
+ * docs/gtk_tut.sgml:
+ - Complete the ProgressBar API
+ - Fix the CList example code
+
+ * examples/clist/clist.c, examples/progressbar/progressbar.c:
+ Update from tutorial
+
Sun Feb 21 17:44:52 1999 Owen Taylor <otaylor@redhat.com>
* gtk/testgtkrc: Removed check-y/check-n backgrounds -
name="<gale@gtk.org>"></tt>
Ian Main <tt><htmlurl url="mailto:imain@gtk.org"
name="<imain@gtk.org>"></tt>,
-<date>February 7th, 1999
+<date>February 21st, 1999
<abstract>
This is a tutorial on how to use GTK (the GIMP Toolkit) through its C
interface.
The second method has the advantage that we can use the adjustment
object to specify our own range parameters for the progress bar.
+The adjustment of a progress object can be changed dynamically using:
+
+<tscreen><verb>
+void gtk_progress_set_adjustment( GtkProgress *progress,
+ GtkAdjustment *adjustment );
+</verb></tscreen>
+
Now that the progress bar has been created we can use it.
<tscreen><verb>
<item> %l - lower range value
<item> %u - upper range value
</itemize>
-
+
+The displaying of this text string can be toggled using:
+
+<tscreen><verb>
+void gtk_progress_set_show_text( GtkProgress *progress,
+ gint show_text );
+</verb></tscreen>
+
+The <tt/show_text/ argument is a boolean TRUE/FALSE value. The
+appearance of the text can be modified further using:
+
+<tscreen><verb>
+void gtk_progress_set_text_alignment( GtkProgress *progress,
+ gfloat x_align,
+ gfloat y_align );
+</verb></tscreen>
+
+The <tt/x_align/ and <tt/y_align/ arguments take a value between 0.0
+and 1.0. Their value indicates the position of the text string within
+the trough. Values of 0.0 for both would place the string in the top
+left hand corner; values of 0.5 (the default) centres the text, and
+values of 1.0 places the text in the lower right hand corner.
+
+The current text setting of a progress object can be retrieved using
+the current or a specified adjustment value using the following two
+functions. The character string returned by these functions should be
+freed by the application (using the g_free() function). These
+functions return the formatted string that would be displayed within
+the trough.
+
+<tscreen><verb>
+gchar *gtk_progress_get_current_text( GtkProgress *progress );
+
+gchar *gtk_progress_get_text_from_value( GtkProgress *progress,
+ gfloat value );
+</verb></tscreen>
+
+There is yet another way to change the range and value of a progress
+object using the following function:
+
+<tscreen><verb>
+void gtk_progress_configure( GtkProgress *progress,
+ gfloat value,
+ gfloat min,
+ gfloat max );
+</verb></tscreen>
+
+This function provides quite a simple interface to the range and value
+of a progress object.
+
+The remaining functions can be used to get and set the current value
+of a progess object in various types and formats:
+
+<tscreen><verb>
+void gtk_progress_set_percentage( GtkProgress *progress,
+ gfloat percentage );
+
+void gtk_progress_set_value( GtkProgress *progress,
+ gfloat value );
+
+gfloat gtk_progress_get_value( GtkProgress *progress );
+
+gfloat gtk_progress_get_current_percentage( GtkProgress *progress );
+
+gfloat gtk_progress_get_percentage_from_value( GtkProgress *progress,
+ gfloat value );
+</verb></tscreen>
+
+These functions are pretty self explanatory. The last function uses
+the the adjustment of the specified progess object to compute the
+percentage value of the given range value.
+
Progress Bars are usually used with timeouts or other such functions
(see section on <ref id="sec_timeouts" name="Timeouts, I/O and Idle
Functions">) to give the illusion of multitasking. All will employ the
gtk_progress_bar_update function in the same manner.
-Here is an example of the progress bar, updated using timeouts. This
+Here is an example of the progress bar, updated using timeouts. This
code also shows you how to reset the Progress Bar.
<tscreen><verb>
gfloat new_val;
GtkAdjustment *adj;
- adj = GTK_PROGRESS (data)->adjustment;
-
/* Calculate the value of the progress bar using the
* value range set in the adjustment object */
- new_val = adj->value + 1;
+
+ new_val = gtk_progress_get_value( GTK_PROGRESS(data) ) + 1;
+
+ adj = GTK_PROGRESS (data)->adjustment;
if (new_val > adj->upper)
new_val = adj->lower;
<tscreen><verb>
/* example-start clist clist.c */
-#include <gtk/gtk.h>
-#include <glib.h>
+#include <gtk/gtk.h>
+
+/* User clicked the "Add List" button. */
+void button_add_clicked( gpointer data )
+{
+ int indx;
+
+ /* Something silly to add to the list. 4 rows of 2 columns each */
+ gchar *drink[4][2] = { { "Milk", "3 Oz" },
+ { "Water", "6 l" },
+ { "Carrots", "2" },
+ { "Snakes", "55" } };
+
+ /* Here we do the actual adding of the text. It's done once for
+ * each row.
+ */
+ for ( indx=0 ; indx < 4 ; indx++ )
+ gtk_clist_append( (GtkCList *) data, drink[indx]);
+
+ return;
+}
+
+/* User clicked the "Clear List" button. */
+void button_clear_clicked( gpointer data )
+{
+ /* Clear the list using gtk_clist_clear. This is much faster than
+ * calling gtk_clist_remove once for each row.
+ */
+ gtk_clist_clear( (GtkCList *) data);
+
+ return;
+}
+
+/* The user clicked the "Hide/Show titles" button. */
+void button_hide_show_clicked( gpointer data )
+{
+ /* Just a flag to remember the status. 0 = currently visible */
+ static short int flag = 0;
+
+ if (flag == 0)
+ {
+ /* Hide the titles and set the flag to 1 */
+ gtk_clist_column_titles_hide((GtkCList *) data);
+ flag++;
+ }
+ else
+ {
+ /* Show the titles and reset flag to 0 */
+ gtk_clist_column_titles_show((GtkCList *) data);
+ flag--;
+ }
+
+ return;
+}
+
+/* If we come here, then the user has selected a row in the list. */
+void selection_made( GtkWidget *clist,
+ gint row,
+ gint column,
+ GdkEventButton *event,
+ gpointer data )
+{
+ gchar *text;
-/* These are just the prototypes of the various callbacks */
-void button_add_clicked( GtkWidget *button, gpointer data);
-void button_clear_clicked( GtkWidget *button, gpointer data);
-void button_hide_show_clicked( GtkWidget *button, gpointer data);
-void selection_made( GtkWidget *clist, gint row, gint column,
- GdkEventButton *event, gpointer data);
+ /* Get the text that is stored in the selected row and column
+ * which was clicked in. We will receive it as a pointer in the
+ * argument text.
+ */
+ gtk_clist_get_text(GTK_CLIST(clist), row, column, &text);
+
+ /* Just prints some information about the selected row */
+ g_print("You selected row %d. More specifically you clicked in "
+ "column %d, and the text in this cell is %s\n\n",
+ row, column, text);
-gint main (int argc, gchar *argv[])
+ return;
+}
+
+int main( int argc,
+ gchar *argv[] )
{
- GtkWidget *window;
- GtkWidget *vbox, *hbox;
- GtkWidget *clist;
- GtkWidget *button_add, *button_clear, *button_hide_show;
- gchar *titles[2] = {"Ingredients","Amount"};
+ GtkWidget *window;
+ GtkWidget *vbox, *hbox;
+ GtkWidget *clist;
+ GtkWidget *button_add, *button_clear, *button_hide_show;
+ gchar *titles[2] = { "Ingredients", "Amount" };
gtk_init(&argc, &argv);
-
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_usize(GTK_WIDGET(window), 300, 150);
return(0);
}
-
-/* User clicked the "Add List" button. */
-void button_add_clicked( GtkWidget *button, gpointer data)
-{
- int indx;
-
- /* Something silly to add to the list. 4 rows of 2 columns each */
- gchar *drink[4][2] = {{"Milk", "3 Oz"},
- {"Water", "6 l"},
- {"Carrots", "2"},
- {"Snakes", "55"}};
-
- /* Here we do the actual adding of the text. It's done once for
- * each row.
- */
- for( indx=0; indx < 4; indx++)
- gtk_clist_append( (GtkCList*) data, drink[indx]);
-
- return;
-}
-
-/* User clicked the "Clear List" button. */
-void button_clear_clicked( GtkWidget *button, gpointer data)
-{
- /* Clear the list using gtk_clist_clear. This is much faster than
- * calling gtk_clist_remove once for each row.
- */
- gtk_clist_clear((GtkCList*) data);
-
- return;
-}
-
-/* The user clicked the "Hide/Show titles" button. */
-void button_hide_show_clicked( GtkWidget *button, gpointer data)
-{
- /* Just a flag to remember the status. 0 = currently visible */
- static short int flag = 0;
-
- if (flag == 0)
- {
- /* Hide the titles and set the flag to 1 */
- gtk_clist_column_titles_hide((GtkCList*) data);
- flag++;
- }
- else
- {
- /* Show the titles and reset flag to 0 */
- gtk_clist_column_titles_show((GtkCList*) data);
- flag--;
- }
-
- return;
-}
-
-/* If we come here, then the user has selected a row in the list. */
-void selection_made( GtkWidget *clist, gint row, gint column,
- GdkEventButton *event, gpointer data)
-{
- gchar *text;
-
- /* Get the text that is stored in the selected row and column
- * which was clicked in. We will receive it as a pointer in the
- * argument text.
- */
- gtk_clist_get_text(GTK_CLIST(clist), row, column, &text);
-
- /* Just prints some information about the selected row */
- g_print("You selected row %d. More specifically you clicked in column %d, and the text in this cell is %s\n\n", row, column, text);
-
- return;
-}
/* example-end */
</verb></tscreen>
A GtkTree is created in the usual way, using:
<tscreen><verb>
-GtkWidget* gtk_tree_new( void );
+GtkWidget *gtk_tree_new( void );
</verb></tscreen>
Like the GtkList widget, a GtkTree will simply keep growing as more
create one, using:
<tscreen><verb>
-GtkWidget* gtk_tree_item_new_with_label( gchar *label );
+GtkWidget *gtk_tree_item_new_with_label( gchar *label );
</verb></tscreen>
You can then add it to the tree using one of the following (see
<tscreen>
<verb>
-GtkWidget* gtk_menu_bar_new (void);
+GtkWidget *gtk_menu_bar_new( void );
</verb>
</tscreen>
functions to pack it into a box - the same as buttons.
<tscreen><verb>
-GtkWidget* gtk_menu_new (void);
+GtkWidget *gtk_menu_new( void );
</verb></tscreen>
This function returns a pointer to a new menu, it is never actually
the menu (and menubar).
<tscreen><verb>
-GtkWidget* gtk_menu_item_new (void);
+GtkWidget *gtk_menu_item_new( void );
</verb></tscreen>
and
<tscreen><verb>
-GtkWidget* gtk_menu_item_new_with_label (const char *label);
+GtkWidget *gtk_menu_item_new_with_label( const char *label );
</verb></tscreen>
These calls are used to create the menu items that are to be
with the function
<tscreen>
-void gtk_menu_item_set_submenu (GtkMenuItem *menu_item,
- GtkWidget *submenu);
+void gtk_menu_item_set_submenu( GtkMenuItem *menu_item,
+ GtkWidget *submenu );
</tscreen>
So, our example would continue with
accomplished using the function
<tscreen>
-void gtk_menu_bar_append (GtkMenuBar *menu_bar, GtkWidget *menu_item);
+void gtk_menu_bar_append( GtkMenuBar *menu_bar,
+ GtkWidget *menu_item );
</tscreen>
which in our case looks like this:
menubar.
<tscreen><verb>
-void gtk_menu_item_right_justify (GtkMenuItem *menu_item);
+void gtk_menu_item_right_justify( GtkMenuItem *menu_item );
</verb></tscreen>
Here is a summary of the steps needed to create a menu bar with menus
static gint button_press (GtkWidget *, GdkEvent *);
static void menuitem_response (gchar *);
-int main (int argc, char *argv[])
+int main( int argc,
+ char *argv[] )
{
GtkWidget *window;
gtk_main ();
- return 0;
+ return(0);
}
/* Respond to a button-press by posting a menu passed in as widget.
#include <strings.h>
/* Obligatory basic callback */
-static void
-print_hello (GtkWidget *w, gpointer data)
+static void print_hello( GtkWidget *w,
+ gpointer data )
{
g_message ("Hello, World!\n");
}
};
-void
-get_main_menu (GtkWidget *window, GtkWidget ** menubar)
+void get_main_menu( GtkWidget *window,
+ GtkWidget **menubar )
{
GtkItemFactory *item_factory;
GtkAccelGroup *accel_group;
*menubar = gtk_item_factory_get_widget (item_factory, "<main>");
}
-int
-main (int argc, char *argv[])
+int main( int argc,
+ char *argv[] )
{
GtkWidget *window;
GtkWidget *main_vbox;
gtk_widget_show (window);
gtk_main ();
- return 0;
+ return(0);
}
/* example-end */
</verb></tscreen>
-For now, there's only this example. An explanation and lots 'o' comments
+For now, there's only this example. An explanation and lots 'o' comments
will follow later.
<!-- ***************************************************************** -->
name="<gale@gtk.org>"></tt>
Ian Main <tt><htmlurl url="mailto:imain@gtk.org"
name="<imain@gtk.org>"></tt>,
-<date>February 7th, 1999
+<date>February 21st, 1999
<abstract>
This is a tutorial on how to use GTK (the GIMP Toolkit) through its C
interface.
The second method has the advantage that we can use the adjustment
object to specify our own range parameters for the progress bar.
+The adjustment of a progress object can be changed dynamically using:
+
+<tscreen><verb>
+void gtk_progress_set_adjustment( GtkProgress *progress,
+ GtkAdjustment *adjustment );
+</verb></tscreen>
+
Now that the progress bar has been created we can use it.
<tscreen><verb>
<item> %l - lower range value
<item> %u - upper range value
</itemize>
-
+
+The displaying of this text string can be toggled using:
+
+<tscreen><verb>
+void gtk_progress_set_show_text( GtkProgress *progress,
+ gint show_text );
+</verb></tscreen>
+
+The <tt/show_text/ argument is a boolean TRUE/FALSE value. The
+appearance of the text can be modified further using:
+
+<tscreen><verb>
+void gtk_progress_set_text_alignment( GtkProgress *progress,
+ gfloat x_align,
+ gfloat y_align );
+</verb></tscreen>
+
+The <tt/x_align/ and <tt/y_align/ arguments take a value between 0.0
+and 1.0. Their value indicates the position of the text string within
+the trough. Values of 0.0 for both would place the string in the top
+left hand corner; values of 0.5 (the default) centres the text, and
+values of 1.0 places the text in the lower right hand corner.
+
+The current text setting of a progress object can be retrieved using
+the current or a specified adjustment value using the following two
+functions. The character string returned by these functions should be
+freed by the application (using the g_free() function). These
+functions return the formatted string that would be displayed within
+the trough.
+
+<tscreen><verb>
+gchar *gtk_progress_get_current_text( GtkProgress *progress );
+
+gchar *gtk_progress_get_text_from_value( GtkProgress *progress,
+ gfloat value );
+</verb></tscreen>
+
+There is yet another way to change the range and value of a progress
+object using the following function:
+
+<tscreen><verb>
+void gtk_progress_configure( GtkProgress *progress,
+ gfloat value,
+ gfloat min,
+ gfloat max );
+</verb></tscreen>
+
+This function provides quite a simple interface to the range and value
+of a progress object.
+
+The remaining functions can be used to get and set the current value
+of a progess object in various types and formats:
+
+<tscreen><verb>
+void gtk_progress_set_percentage( GtkProgress *progress,
+ gfloat percentage );
+
+void gtk_progress_set_value( GtkProgress *progress,
+ gfloat value );
+
+gfloat gtk_progress_get_value( GtkProgress *progress );
+
+gfloat gtk_progress_get_current_percentage( GtkProgress *progress );
+
+gfloat gtk_progress_get_percentage_from_value( GtkProgress *progress,
+ gfloat value );
+</verb></tscreen>
+
+These functions are pretty self explanatory. The last function uses
+the the adjustment of the specified progess object to compute the
+percentage value of the given range value.
+
Progress Bars are usually used with timeouts or other such functions
(see section on <ref id="sec_timeouts" name="Timeouts, I/O and Idle
Functions">) to give the illusion of multitasking. All will employ the
gtk_progress_bar_update function in the same manner.
-Here is an example of the progress bar, updated using timeouts. This
+Here is an example of the progress bar, updated using timeouts. This
code also shows you how to reset the Progress Bar.
<tscreen><verb>
gfloat new_val;
GtkAdjustment *adj;
- adj = GTK_PROGRESS (data)->adjustment;
-
/* Calculate the value of the progress bar using the
* value range set in the adjustment object */
- new_val = adj->value + 1;
+
+ new_val = gtk_progress_get_value( GTK_PROGRESS(data) ) + 1;
+
+ adj = GTK_PROGRESS (data)->adjustment;
if (new_val > adj->upper)
new_val = adj->lower;
<tscreen><verb>
/* example-start clist clist.c */
-#include <gtk/gtk.h>
-#include <glib.h>
+#include <gtk/gtk.h>
+
+/* User clicked the "Add List" button. */
+void button_add_clicked( gpointer data )
+{
+ int indx;
+
+ /* Something silly to add to the list. 4 rows of 2 columns each */
+ gchar *drink[4][2] = { { "Milk", "3 Oz" },
+ { "Water", "6 l" },
+ { "Carrots", "2" },
+ { "Snakes", "55" } };
+
+ /* Here we do the actual adding of the text. It's done once for
+ * each row.
+ */
+ for ( indx=0 ; indx < 4 ; indx++ )
+ gtk_clist_append( (GtkCList *) data, drink[indx]);
+
+ return;
+}
+
+/* User clicked the "Clear List" button. */
+void button_clear_clicked( gpointer data )
+{
+ /* Clear the list using gtk_clist_clear. This is much faster than
+ * calling gtk_clist_remove once for each row.
+ */
+ gtk_clist_clear( (GtkCList *) data);
+
+ return;
+}
+
+/* The user clicked the "Hide/Show titles" button. */
+void button_hide_show_clicked( gpointer data )
+{
+ /* Just a flag to remember the status. 0 = currently visible */
+ static short int flag = 0;
+
+ if (flag == 0)
+ {
+ /* Hide the titles and set the flag to 1 */
+ gtk_clist_column_titles_hide((GtkCList *) data);
+ flag++;
+ }
+ else
+ {
+ /* Show the titles and reset flag to 0 */
+ gtk_clist_column_titles_show((GtkCList *) data);
+ flag--;
+ }
+
+ return;
+}
+
+/* If we come here, then the user has selected a row in the list. */
+void selection_made( GtkWidget *clist,
+ gint row,
+ gint column,
+ GdkEventButton *event,
+ gpointer data )
+{
+ gchar *text;
-/* These are just the prototypes of the various callbacks */
-void button_add_clicked( GtkWidget *button, gpointer data);
-void button_clear_clicked( GtkWidget *button, gpointer data);
-void button_hide_show_clicked( GtkWidget *button, gpointer data);
-void selection_made( GtkWidget *clist, gint row, gint column,
- GdkEventButton *event, gpointer data);
+ /* Get the text that is stored in the selected row and column
+ * which was clicked in. We will receive it as a pointer in the
+ * argument text.
+ */
+ gtk_clist_get_text(GTK_CLIST(clist), row, column, &text);
+
+ /* Just prints some information about the selected row */
+ g_print("You selected row %d. More specifically you clicked in "
+ "column %d, and the text in this cell is %s\n\n",
+ row, column, text);
-gint main (int argc, gchar *argv[])
+ return;
+}
+
+int main( int argc,
+ gchar *argv[] )
{
- GtkWidget *window;
- GtkWidget *vbox, *hbox;
- GtkWidget *clist;
- GtkWidget *button_add, *button_clear, *button_hide_show;
- gchar *titles[2] = {"Ingredients","Amount"};
+ GtkWidget *window;
+ GtkWidget *vbox, *hbox;
+ GtkWidget *clist;
+ GtkWidget *button_add, *button_clear, *button_hide_show;
+ gchar *titles[2] = { "Ingredients", "Amount" };
gtk_init(&argc, &argv);
-
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_usize(GTK_WIDGET(window), 300, 150);
return(0);
}
-
-/* User clicked the "Add List" button. */
-void button_add_clicked( GtkWidget *button, gpointer data)
-{
- int indx;
-
- /* Something silly to add to the list. 4 rows of 2 columns each */
- gchar *drink[4][2] = {{"Milk", "3 Oz"},
- {"Water", "6 l"},
- {"Carrots", "2"},
- {"Snakes", "55"}};
-
- /* Here we do the actual adding of the text. It's done once for
- * each row.
- */
- for( indx=0; indx < 4; indx++)
- gtk_clist_append( (GtkCList*) data, drink[indx]);
-
- return;
-}
-
-/* User clicked the "Clear List" button. */
-void button_clear_clicked( GtkWidget *button, gpointer data)
-{
- /* Clear the list using gtk_clist_clear. This is much faster than
- * calling gtk_clist_remove once for each row.
- */
- gtk_clist_clear((GtkCList*) data);
-
- return;
-}
-
-/* The user clicked the "Hide/Show titles" button. */
-void button_hide_show_clicked( GtkWidget *button, gpointer data)
-{
- /* Just a flag to remember the status. 0 = currently visible */
- static short int flag = 0;
-
- if (flag == 0)
- {
- /* Hide the titles and set the flag to 1 */
- gtk_clist_column_titles_hide((GtkCList*) data);
- flag++;
- }
- else
- {
- /* Show the titles and reset flag to 0 */
- gtk_clist_column_titles_show((GtkCList*) data);
- flag--;
- }
-
- return;
-}
-
-/* If we come here, then the user has selected a row in the list. */
-void selection_made( GtkWidget *clist, gint row, gint column,
- GdkEventButton *event, gpointer data)
-{
- gchar *text;
-
- /* Get the text that is stored in the selected row and column
- * which was clicked in. We will receive it as a pointer in the
- * argument text.
- */
- gtk_clist_get_text(GTK_CLIST(clist), row, column, &text);
-
- /* Just prints some information about the selected row */
- g_print("You selected row %d. More specifically you clicked in column %d, and the text in this cell is %s\n\n", row, column, text);
-
- return;
-}
/* example-end */
</verb></tscreen>
A GtkTree is created in the usual way, using:
<tscreen><verb>
-GtkWidget* gtk_tree_new( void );
+GtkWidget *gtk_tree_new( void );
</verb></tscreen>
Like the GtkList widget, a GtkTree will simply keep growing as more
create one, using:
<tscreen><verb>
-GtkWidget* gtk_tree_item_new_with_label( gchar *label );
+GtkWidget *gtk_tree_item_new_with_label( gchar *label );
</verb></tscreen>
You can then add it to the tree using one of the following (see
<tscreen>
<verb>
-GtkWidget* gtk_menu_bar_new (void);
+GtkWidget *gtk_menu_bar_new( void );
</verb>
</tscreen>
functions to pack it into a box - the same as buttons.
<tscreen><verb>
-GtkWidget* gtk_menu_new (void);
+GtkWidget *gtk_menu_new( void );
</verb></tscreen>
This function returns a pointer to a new menu, it is never actually
the menu (and menubar).
<tscreen><verb>
-GtkWidget* gtk_menu_item_new (void);
+GtkWidget *gtk_menu_item_new( void );
</verb></tscreen>
and
<tscreen><verb>
-GtkWidget* gtk_menu_item_new_with_label (const char *label);
+GtkWidget *gtk_menu_item_new_with_label( const char *label );
</verb></tscreen>
These calls are used to create the menu items that are to be
with the function
<tscreen>
-void gtk_menu_item_set_submenu (GtkMenuItem *menu_item,
- GtkWidget *submenu);
+void gtk_menu_item_set_submenu( GtkMenuItem *menu_item,
+ GtkWidget *submenu );
</tscreen>
So, our example would continue with
accomplished using the function
<tscreen>
-void gtk_menu_bar_append (GtkMenuBar *menu_bar, GtkWidget *menu_item);
+void gtk_menu_bar_append( GtkMenuBar *menu_bar,
+ GtkWidget *menu_item );
</tscreen>
which in our case looks like this:
menubar.
<tscreen><verb>
-void gtk_menu_item_right_justify (GtkMenuItem *menu_item);
+void gtk_menu_item_right_justify( GtkMenuItem *menu_item );
</verb></tscreen>
Here is a summary of the steps needed to create a menu bar with menus
static gint button_press (GtkWidget *, GdkEvent *);
static void menuitem_response (gchar *);
-int main (int argc, char *argv[])
+int main( int argc,
+ char *argv[] )
{
GtkWidget *window;
gtk_main ();
- return 0;
+ return(0);
}
/* Respond to a button-press by posting a menu passed in as widget.
#include <strings.h>
/* Obligatory basic callback */
-static void
-print_hello (GtkWidget *w, gpointer data)
+static void print_hello( GtkWidget *w,
+ gpointer data )
{
g_message ("Hello, World!\n");
}
};
-void
-get_main_menu (GtkWidget *window, GtkWidget ** menubar)
+void get_main_menu( GtkWidget *window,
+ GtkWidget **menubar )
{
GtkItemFactory *item_factory;
GtkAccelGroup *accel_group;
*menubar = gtk_item_factory_get_widget (item_factory, "<main>");
}
-int
-main (int argc, char *argv[])
+int main( int argc,
+ char *argv[] )
{
GtkWidget *window;
GtkWidget *main_vbox;
gtk_widget_show (window);
gtk_main ();
- return 0;
+ return(0);
}
/* example-end */
</verb></tscreen>
-For now, there's only this example. An explanation and lots 'o' comments
+For now, there's only this example. An explanation and lots 'o' comments
will follow later.
<!-- ***************************************************************** -->
/* example-start clist clist.c */
-#include <gtk/gtk.h>
-#include <glib.h>
+#include <gtk/gtk.h>
-/* These are just the prototypes of the various callbacks */
-void button_add_clicked( GtkWidget *button, gpointer data);
-void button_clear_clicked( GtkWidget *button, gpointer data);
-void button_hide_show_clicked( GtkWidget *button, gpointer data);
-void selection_made( GtkWidget *clist, gint row, gint column,
- GdkEventButton *event, gpointer data);
+/* User clicked the "Add List" button. */
+void button_add_clicked( gpointer data )
+{
+ int indx;
+
+ /* Something silly to add to the list. 4 rows of 2 columns each */
+ gchar *drink[4][2] = { { "Milk", "3 Oz" },
+ { "Water", "6 l" },
+ { "Carrots", "2" },
+ { "Snakes", "55" } };
+
+ /* Here we do the actual adding of the text. It's done once for
+ * each row.
+ */
+ for ( indx=0 ; indx < 4 ; indx++ )
+ gtk_clist_append( (GtkCList *) data, drink[indx]);
+
+ return;
+}
+
+/* User clicked the "Clear List" button. */
+void button_clear_clicked( gpointer data )
+{
+ /* Clear the list using gtk_clist_clear. This is much faster than
+ * calling gtk_clist_remove once for each row.
+ */
+ gtk_clist_clear( (GtkCList *) data);
+
+ return;
+}
+
+/* The user clicked the "Hide/Show titles" button. */
+void button_hide_show_clicked( gpointer data )
+{
+ /* Just a flag to remember the status. 0 = currently visible */
+ static short int flag = 0;
+
+ if (flag == 0)
+ {
+ /* Hide the titles and set the flag to 1 */
+ gtk_clist_column_titles_hide((GtkCList *) data);
+ flag++;
+ }
+ else
+ {
+ /* Show the titles and reset flag to 0 */
+ gtk_clist_column_titles_show((GtkCList *) data);
+ flag--;
+ }
+
+ return;
+}
+
+/* If we come here, then the user has selected a row in the list. */
+void selection_made( GtkWidget *clist,
+ gint row,
+ gint column,
+ GdkEventButton *event,
+ gpointer data )
+{
+ gchar *text;
-gint main (int argc, gchar *argv[])
+ /* Get the text that is stored in the selected row and column
+ * which was clicked in. We will receive it as a pointer in the
+ * argument text.
+ */
+ gtk_clist_get_text(GTK_CLIST(clist), row, column, &text);
+
+ /* Just prints some information about the selected row */
+ g_print("You selected row %d. More specifically you clicked in "
+ "column %d, and the text in this cell is %s\n\n",
+ row, column, text);
+
+ return;
+}
+
+int main( int argc,
+ gchar *argv[] )
{
- GtkWidget *window;
- GtkWidget *vbox, *hbox;
- GtkWidget *clist;
- GtkWidget *button_add, *button_clear, *button_hide_show;
- gchar *titles[2] = {"Ingredients","Amount"};
+ GtkWidget *window;
+ GtkWidget *vbox, *hbox;
+ GtkWidget *clist;
+ GtkWidget *button_add, *button_clear, *button_hide_show;
+ gchar *titles[2] = { "Ingredients", "Amount" };
gtk_init(&argc, &argv);
-
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_usize(GTK_WIDGET(window), 300, 150);
return(0);
}
-
-/* User clicked the "Add List" button. */
-void button_add_clicked( GtkWidget *button, gpointer data)
-{
- int indx;
-
- /* Something silly to add to the list. 4 rows of 2 columns each */
- gchar *drink[4][2] = {{"Milk", "3 Oz"},
- {"Water", "6 l"},
- {"Carrots", "2"},
- {"Snakes", "55"}};
-
- /* Here we do the actual adding of the text. It's done once for
- * each row.
- */
- for( indx=0; indx < 4; indx++)
- gtk_clist_append( (GtkCList*) data, drink[indx]);
-
- return;
-}
-
-/* User clicked the "Clear List" button. */
-void button_clear_clicked( GtkWidget *button, gpointer data)
-{
- /* Clear the list using gtk_clist_clear. This is much faster than
- * calling gtk_clist_remove once for each row.
- */
- gtk_clist_clear((GtkCList*) data);
-
- return;
-}
-
-/* The user clicked the "Hide/Show titles" button. */
-void button_hide_show_clicked( GtkWidget *button, gpointer data)
-{
- /* Just a flag to remember the status. 0 = currently visible */
- static short int flag = 0;
-
- if (flag == 0)
- {
- /* Hide the titles and set the flag to 1 */
- gtk_clist_column_titles_hide((GtkCList*) data);
- flag++;
- }
- else
- {
- /* Show the titles and reset flag to 0 */
- gtk_clist_column_titles_show((GtkCList*) data);
- flag--;
- }
-
- return;
-}
-
-/* If we come here, then the user has selected a row in the list. */
-void selection_made( GtkWidget *clist, gint row, gint column,
- GdkEventButton *event, gpointer data)
-{
- gchar *text;
-
- /* Get the text that is stored in the selected row and column
- * which was clicked in. We will receive it as a pointer in the
- * argument text.
- */
- gtk_clist_get_text(GTK_CLIST(clist), row, column, &text);
-
- /* Just prints some information about the selected row */
- g_print("You selected row %d. More specifically you clicked in column %d, and the text in this cell is %s\n\n", row, column, text);
-
- return;
-}
/* example-end */
gfloat new_val;
GtkAdjustment *adj;
- adj = GTK_PROGRESS (data)->adjustment;
-
/* Calculate the value of the progress bar using the
* value range set in the adjustment object */
- new_val = adj->value + 1;
+
+ new_val = gtk_progress_get_value( GTK_PROGRESS(data) ) + 1;
+
+ adj = GTK_PROGRESS (data)->adjustment;
if (new_val > adj->upper)
new_val = adj->lower;