Fold back Svens g_signal fixes from the examples.

* docs/tutorial/gtk-tut.sgml: Fold back Svens g_signal fixes from
	the examples.

	* docs/tutorial/gtk-tut.sgml, examples/progressbar/progressbar.c,
	examples/progressbar/Makefile: Make the progressbar example
	deprecation-clean.
This commit is contained in:
Matthias Clasen 2002-02-20 01:40:15 +00:00
parent c53f6b6713
commit 8ac97865e8
10 changed files with 952 additions and 931 deletions

View File

@ -1,3 +1,12 @@
2002-02-20 Matthias Clasen <maclas@gmx.de>
* docs/tutorial/gtk-tut.sgml: Fold back Svens g_signal fixes from
the examples.
* docs/tutorial/gtk-tut.sgml, examples/progressbar/progressbar.c,
examples/progressbar/Makefile: Make the progressbar example
deprecation-clean.
Tue Feb 19 22:10:59 2002 Kristian Rietveld <kris@gtk.org> Tue Feb 19 22:10:59 2002 Kristian Rietveld <kris@gtk.org>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_mnemonic_activate): new * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_mnemonic_activate): new

View File

@ -1,3 +1,12 @@
2002-02-20 Matthias Clasen <maclas@gmx.de>
* docs/tutorial/gtk-tut.sgml: Fold back Svens g_signal fixes from
the examples.
* docs/tutorial/gtk-tut.sgml, examples/progressbar/progressbar.c,
examples/progressbar/Makefile: Make the progressbar example
deprecation-clean.
Tue Feb 19 22:10:59 2002 Kristian Rietveld <kris@gtk.org> Tue Feb 19 22:10:59 2002 Kristian Rietveld <kris@gtk.org>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_mnemonic_activate): new * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_mnemonic_activate): new

View File

@ -1,3 +1,12 @@
2002-02-20 Matthias Clasen <maclas@gmx.de>
* docs/tutorial/gtk-tut.sgml: Fold back Svens g_signal fixes from
the examples.
* docs/tutorial/gtk-tut.sgml, examples/progressbar/progressbar.c,
examples/progressbar/Makefile: Make the progressbar example
deprecation-clean.
Tue Feb 19 22:10:59 2002 Kristian Rietveld <kris@gtk.org> Tue Feb 19 22:10:59 2002 Kristian Rietveld <kris@gtk.org>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_mnemonic_activate): new * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_mnemonic_activate): new

View File

@ -1,3 +1,12 @@
2002-02-20 Matthias Clasen <maclas@gmx.de>
* docs/tutorial/gtk-tut.sgml: Fold back Svens g_signal fixes from
the examples.
* docs/tutorial/gtk-tut.sgml, examples/progressbar/progressbar.c,
examples/progressbar/Makefile: Make the progressbar example
deprecation-clean.
Tue Feb 19 22:10:59 2002 Kristian Rietveld <kris@gtk.org> Tue Feb 19 22:10:59 2002 Kristian Rietveld <kris@gtk.org>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_mnemonic_activate): new * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_mnemonic_activate): new

View File

@ -1,3 +1,12 @@
2002-02-20 Matthias Clasen <maclas@gmx.de>
* docs/tutorial/gtk-tut.sgml: Fold back Svens g_signal fixes from
the examples.
* docs/tutorial/gtk-tut.sgml, examples/progressbar/progressbar.c,
examples/progressbar/Makefile: Make the progressbar example
deprecation-clean.
Tue Feb 19 22:10:59 2002 Kristian Rietveld <kris@gtk.org> Tue Feb 19 22:10:59 2002 Kristian Rietveld <kris@gtk.org>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_mnemonic_activate): new * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_mnemonic_activate): new

View File

@ -1,3 +1,12 @@
2002-02-20 Matthias Clasen <maclas@gmx.de>
* docs/tutorial/gtk-tut.sgml: Fold back Svens g_signal fixes from
the examples.
* docs/tutorial/gtk-tut.sgml, examples/progressbar/progressbar.c,
examples/progressbar/Makefile: Make the progressbar example
deprecation-clean.
Tue Feb 19 22:10:59 2002 Kristian Rietveld <kris@gtk.org> Tue Feb 19 22:10:59 2002 Kristian Rietveld <kris@gtk.org>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_mnemonic_activate): new * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_mnemonic_activate): new

View File

@ -1,3 +1,12 @@
2002-02-20 Matthias Clasen <maclas@gmx.de>
* docs/tutorial/gtk-tut.sgml: Fold back Svens g_signal fixes from
the examples.
* docs/tutorial/gtk-tut.sgml, examples/progressbar/progressbar.c,
examples/progressbar/Makefile: Make the progressbar example
deprecation-clean.
Tue Feb 19 22:10:59 2002 Kristian Rietveld <kris@gtk.org> Tue Feb 19 22:10:59 2002 Kristian Rietveld <kris@gtk.org>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_mnemonic_activate): new * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_mnemonic_activate): new

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,11 @@
CC = gcc CC = gcc
#CFLAGS = -Wall \ CFLAGS = -Wall \
# -DG_DISABLE_DEPRECATED \ -DG_DISABLE_DEPRECATED \
# -DGDK_DISABLE_DEPRECATED \ -DGDK_DISABLE_DEPRECATED \
# -DGDK_PIXBUF_DISABLE_DEPRECATED \ -DGDK_PIXBUF_DISABLE_DEPRECATED \
# -DGTK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED
CFLAGS =
progressbar: progressbar.c progressbar: progressbar.c
$(CC) progressbar.c -o progressbar $(CFLAGS) `pkg-config gtk+-2.0 --cflags --libs` $(CC) progressbar.c -o progressbar $(CFLAGS) `pkg-config gtk+-2.0 --cflags --libs`

View File

@ -2,70 +2,83 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
typedef struct _ProgressData { typedef struct _ProgressData {
GtkWidget *window; GtkWidget *window;
GtkWidget *pbar; GtkWidget *pbar;
int timer; int timer;
gboolean activity_mode;
} ProgressData; } ProgressData;
/* Update the value of the progress bar so that we get /* Update the value of the progress bar so that we get
* some movement */ * some movement */
gint progress_timeout( gpointer data ) gint progress_timeout( gpointer data )
{ {
gfloat new_val; ProgressData *pdata = (ProgressData *)data;
GtkAdjustment *adj; gdouble new_val;
/* Calculate the value of the progress bar using the if (pdata->activity_mode)
* value range set in the adjustment object */ gtk_progress_bar_pulse (GTK_PROGRESS_BAR (pdata->pbar));
else
new_val = gtk_progress_get_value (GTK_PROGRESS (data)) + 1; {
/* Calculate the value of the progress bar using the
adj = GTK_PROGRESS (data)->adjustment; * value range set in the adjustment object */
if (new_val > adj->upper)
new_val = adj->lower; new_val = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (pdata->pbar)) + 0.01;
/* Set the new value */ if (new_val > 1.0)
gtk_progress_set_value (GTK_PROGRESS (data), new_val); new_val = 0.0;
/* As this is a timeout function, return TRUE so that it /* Set the new value */
* continues to get called */ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (pdata->pbar), new_val);
return TRUE; }
/* As this is a timeout function, return TRUE so that it
* continues to get called */
return TRUE;
} }
/* Callback that toggles the text display within the progress /* Callback that toggles the text display within the progress bar trough */
* bar trough */
void toggle_show_text( GtkWidget *widget, void toggle_show_text( GtkWidget *widget,
ProgressData *pdata ) ProgressData *pdata )
{ {
gtk_progress_set_show_text (GTK_PROGRESS (pdata->pbar), const gchar *text;
GTK_TOGGLE_BUTTON (widget)->active);
text = gtk_progress_bar_get_text (GTK_PROGRESS_BAR (pdata->pbar));
if (text && *text)
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (pdata->pbar), "");
else
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (pdata->pbar), "some text");
} }
/* Callback that toggles the activity mode of the progress /* Callback that toggles the activity mode of the progress bar */
* bar */
void toggle_activity_mode( GtkWidget *widget, void toggle_activity_mode( GtkWidget *widget,
ProgressData *pdata ) ProgressData *pdata )
{ {
gtk_progress_set_activity_mode (GTK_PROGRESS (pdata->pbar), pdata->activity_mode = !pdata->activity_mode;
GTK_TOGGLE_BUTTON (widget)->active); if (pdata->activity_mode)
gtk_progress_bar_pulse (GTK_PROGRESS_BAR (pdata->pbar));
else
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (pdata->pbar), 0.0);
} }
/* Callback that toggles the continuous mode of the progress
* bar */ /* Callback that toggles the orientation of the progress bar */
void set_continuous_mode( GtkWidget *widget, void toggle_orientation( GtkWidget *widget,
ProgressData *pdata ) ProgressData *pdata )
{ {
gtk_progress_bar_set_bar_style (GTK_PROGRESS_BAR (pdata->pbar), switch (gtk_progress_bar_get_orientation (GTK_PROGRESS_BAR (pdata->pbar))) {
GTK_PROGRESS_CONTINUOUS); case GTK_PROGRESS_LEFT_TO_RIGHT:
gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (pdata->pbar),
GTK_PROGRESS_RIGHT_TO_LEFT);
break;
case GTK_PROGRESS_RIGHT_TO_LEFT:
gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (pdata->pbar),
GTK_PROGRESS_LEFT_TO_RIGHT);
break;
default:
// do nothing
}
} }
/* Callback that toggles the discrete mode of the progress
* bar */
void set_discrete_mode( GtkWidget *widget,
ProgressData *pdata )
{
gtk_progress_bar_set_bar_style (GTK_PROGRESS_BAR (pdata->pbar),
GTK_PROGRESS_DISCRETE);
}
/* Clean up allocated memory and remove the timer */ /* Clean up allocated memory and remove the timer */
void destroy_progress( GtkWidget *widget, void destroy_progress( GtkWidget *widget,
@ -85,7 +98,6 @@ int main( int argc,
GtkWidget *align; GtkWidget *align;
GtkWidget *separator; GtkWidget *separator;
GtkWidget *table; GtkWidget *table;
GtkAdjustment *adj;
GtkWidget *button; GtkWidget *button;
GtkWidget *check; GtkWidget *check;
GtkWidget *vbox; GtkWidget *vbox;
@ -114,33 +126,21 @@ int main( int argc,
gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 5); gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 5);
gtk_widget_show (align); gtk_widget_show (align);
/* Create a Adjusment object to hold the range of the /* Create the GtkProgressBar */
* progress bar */ pdata->pbar = gtk_progress_bar_new ();
adj = (GtkAdjustment *) gtk_adjustment_new (0, 1, 150, 0, 0, 0);
/* Create the GtkProgressBar using the adjustment */
pdata->pbar = gtk_progress_bar_new_with_adjustment (adj);
/* Set the format of the string that can be displayed in the
* trough of the progress bar:
* %p - percentage
* %v - value
* %l - lower range value
* %u - upper range value */
gtk_progress_set_format_string (GTK_PROGRESS (pdata->pbar),
"%v from [%l-%u] (=%p%%)");
gtk_container_add (GTK_CONTAINER (align), pdata->pbar); gtk_container_add (GTK_CONTAINER (align), pdata->pbar);
gtk_widget_show (pdata->pbar); gtk_widget_show (pdata->pbar);
/* Add a timer callback to update the value of the progress bar */ /* Add a timer callback to update the value of the progress bar */
pdata->timer = gtk_timeout_add (100, progress_timeout, pdata->pbar); pdata->timer = gtk_timeout_add (100, progress_timeout, pdata);
separator = gtk_hseparator_new (); separator = gtk_hseparator_new ();
gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0);
gtk_widget_show (separator); gtk_widget_show (separator);
/* rows, columns, homogeneous */ /* rows, columns, homogeneous */
table = gtk_table_new (2, 3, FALSE); table = gtk_table_new (2, 2, FALSE);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);
gtk_widget_show (table); gtk_widget_show (table);
@ -148,7 +148,7 @@ int main( int argc,
check = gtk_check_button_new_with_label ("Show text"); check = gtk_check_button_new_with_label ("Show text");
gtk_table_attach (GTK_TABLE (table), check, 0, 1, 0, 1, gtk_table_attach (GTK_TABLE (table), check, 0, 1, 0, 1,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
5, 5); 5, 5);
g_signal_connect (G_OBJECT (check), "clicked", g_signal_connect (G_OBJECT (check), "clicked",
G_CALLBACK (toggle_show_text), G_CALLBACK (toggle_show_text),
pdata); pdata);
@ -164,37 +164,15 @@ int main( int argc,
pdata); pdata);
gtk_widget_show (check); gtk_widget_show (check);
separator = gtk_vseparator_new (); /* Add a check button to toggle orientation */
gtk_table_attach (GTK_TABLE (table), separator, 1, 2, 0, 2, check = gtk_check_button_new_with_label ("Right to Left");
gtk_table_attach (GTK_TABLE (table), check, 0, 1, 2, 3,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
5, 5); 5, 5);
gtk_widget_show (separator); g_signal_connect (G_OBJECT (check), "clicked",
G_CALLBACK (toggle_orientation),
/* Add a radio button to select continuous display mode */
button = gtk_radio_button_new_with_label (NULL, "Continuous");
gtk_table_attach (GTK_TABLE (table), button, 2, 3, 0, 1,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
5, 5);
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (set_continuous_mode),
pdata); pdata);
gtk_widget_show (button); gtk_widget_show (check);
/* Add a radio button to select discrete display mode */
button = gtk_radio_button_new_with_label(
gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)),
"Discrete");
gtk_table_attach (GTK_TABLE (table), button, 2, 3, 1, 2,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
5, 5);
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (set_discrete_mode),
pdata);
gtk_widget_show (button);
separator = gtk_hseparator_new ();
gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0);
gtk_widget_show (separator);
/* Add a button to exit the program */ /* Add a button to exit the program */
button = gtk_button_new_with_label ("close"); button = gtk_button_new_with_label ("close");