1998-08-13 13:11:14 +00:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
GtkWidget *hscale, *vscale;
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
void cb_pos_menu_select( GtkWidget *item,
|
|
|
|
GtkPositionType pos )
|
1998-08-13 13:11:14 +00:00
|
|
|
{
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Set the value position on both scale widgets */
|
|
|
|
gtk_scale_set_value_pos (GTK_SCALE (hscale), pos);
|
|
|
|
gtk_scale_set_value_pos (GTK_SCALE (vscale), pos);
|
1998-08-13 13:11:14 +00:00
|
|
|
}
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
void cb_update_menu_select( GtkWidget *item,
|
|
|
|
GtkUpdateType policy )
|
1998-08-13 13:11:14 +00:00
|
|
|
{
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Set the update policy for both scale widgets */
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (hscale), policy);
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (vscale), policy);
|
1998-08-13 13:11:14 +00:00
|
|
|
}
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
void cb_digits_scale( GtkAdjustment *adj )
|
1998-08-13 13:11:14 +00:00
|
|
|
{
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Set the number of decimal places to which adj->value is rounded */
|
|
|
|
gtk_scale_set_digits (GTK_SCALE (hscale), (gint) adj->value);
|
|
|
|
gtk_scale_set_digits (GTK_SCALE (vscale), (gint) adj->value);
|
1998-08-13 13:11:14 +00:00
|
|
|
}
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
void cb_page_size( GtkAdjustment *get,
|
|
|
|
GtkAdjustment *set )
|
1998-08-13 13:11:14 +00:00
|
|
|
{
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Set the page size and page increment size of the sample
|
|
|
|
* adjustment to the value specified by the "Page Size" scale */
|
|
|
|
set->page_size = get->value;
|
|
|
|
set->page_increment = get->value;
|
|
|
|
/* Now emit the "changed" signal to reconfigure all the widgets that
|
|
|
|
* are attached to this adjustment */
|
2002-02-16 23:52:30 +00:00
|
|
|
g_signal_emit_by_name (GTK_OBJECT (set), "changed");
|
1998-08-13 13:11:14 +00:00
|
|
|
}
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
void cb_draw_value( GtkToggleButton *button )
|
1998-08-13 13:11:14 +00:00
|
|
|
{
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Turn the value display on the scale widgets off or on depending
|
|
|
|
* on the state of the checkbutton */
|
|
|
|
gtk_scale_set_draw_value (GTK_SCALE (hscale), button->active);
|
|
|
|
gtk_scale_set_draw_value (GTK_SCALE (vscale), button->active);
|
1998-08-13 13:11:14 +00:00
|
|
|
}
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Convenience functions */
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
GtkWidget *make_menu_item( gchar *name,
|
|
|
|
GtkSignalFunc callback,
|
|
|
|
gpointer data )
|
1998-08-13 13:11:14 +00:00
|
|
|
{
|
1998-12-07 15:19:00 +00:00
|
|
|
GtkWidget *item;
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
item = gtk_menu_item_new_with_label (name);
|
2002-02-16 23:52:30 +00:00
|
|
|
g_signal_connect (GTK_OBJECT (item), "activate",
|
1998-12-07 15:19:00 +00:00
|
|
|
callback, data);
|
|
|
|
gtk_widget_show (item);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
2002-02-16 23:52:30 +00:00
|
|
|
return item;
|
1998-08-13 13:11:14 +00:00
|
|
|
}
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
void scale_set_default_values( GtkScale *scale )
|
1998-08-13 13:11:14 +00:00
|
|
|
{
|
1998-12-07 15:19:00 +00:00
|
|
|
gtk_range_set_update_policy (GTK_RANGE (scale),
|
|
|
|
GTK_UPDATE_CONTINUOUS);
|
|
|
|
gtk_scale_set_digits (scale, 1);
|
|
|
|
gtk_scale_set_value_pos (scale, GTK_POS_TOP);
|
|
|
|
gtk_scale_set_draw_value (scale, TRUE);
|
1998-08-13 13:11:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* makes the sample window */
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
void create_range_controls( void )
|
1998-08-13 13:11:14 +00:00
|
|
|
{
|
1998-12-07 15:19:00 +00:00
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *box1, *box2, *box3;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *scrollbar;
|
|
|
|
GtkWidget *separator;
|
|
|
|
GtkWidget *opt, *menu, *item;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *scale;
|
|
|
|
GtkObject *adj1, *adj2;
|
|
|
|
|
|
|
|
/* Standard window-creating stuff */
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2002-02-16 23:52:30 +00:00
|
|
|
g_signal_connect (GTK_OBJECT (window), "destroy",
|
1998-12-07 15:19:00 +00:00
|
|
|
GTK_SIGNAL_FUNC(gtk_main_quit),
|
|
|
|
NULL);
|
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "range controls");
|
|
|
|
|
|
|
|
box1 = gtk_vbox_new (FALSE, 0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (window), box1);
|
|
|
|
gtk_widget_show (box1);
|
|
|
|
|
|
|
|
box2 = gtk_hbox_new (FALSE, 10);
|
1999-01-28 10:35:40 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
|
1998-12-07 15:19:00 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (box2);
|
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
/* value, lower, upper, step_increment, page_increment, page_size */
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Note that the page_size value only makes a difference for
|
|
|
|
* scrollbar widgets, and the highest value you'll get is actually
|
|
|
|
* (upper - page_size). */
|
|
|
|
adj1 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
vscale = gtk_vscale_new (GTK_ADJUSTMENT (adj1));
|
|
|
|
scale_set_default_values (GTK_SCALE (vscale));
|
|
|
|
gtk_box_pack_start (GTK_BOX (box2), vscale, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (vscale);
|
|
|
|
|
|
|
|
box3 = gtk_vbox_new (FALSE, 10);
|
|
|
|
gtk_box_pack_start (GTK_BOX (box2), box3, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (box3);
|
|
|
|
|
|
|
|
/* Reuse the same adjustment */
|
|
|
|
hscale = gtk_hscale_new (GTK_ADJUSTMENT (adj1));
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_widget_set_size_request (GTK_WIDGET (hscale), 200, 30);
|
1998-12-07 15:19:00 +00:00
|
|
|
scale_set_default_values (GTK_SCALE (hscale));
|
|
|
|
gtk_box_pack_start (GTK_BOX (box3), hscale, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (hscale);
|
|
|
|
|
|
|
|
/* Reuse the same adjustment again */
|
|
|
|
scrollbar = gtk_hscrollbar_new (GTK_ADJUSTMENT (adj1));
|
|
|
|
/* Notice how this causes the scales to always be updated
|
|
|
|
* continuously when the scrollbar is moved */
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (scrollbar),
|
|
|
|
GTK_UPDATE_CONTINUOUS);
|
|
|
|
gtk_box_pack_start (GTK_BOX (box3), scrollbar, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (scrollbar);
|
|
|
|
|
|
|
|
box2 = gtk_hbox_new (FALSE, 10);
|
1999-01-28 10:35:40 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
|
1998-12-07 15:19:00 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (box2);
|
|
|
|
|
|
|
|
/* A checkbutton to control whether the value is displayed or not */
|
|
|
|
button = gtk_check_button_new_with_label("Display value on scale widgets");
|
1999-01-28 10:35:40 +00:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
|
2002-02-16 23:52:30 +00:00
|
|
|
g_signal_connect (GTK_OBJECT (button), "toggled",
|
1998-12-07 15:19:00 +00:00
|
|
|
GTK_SIGNAL_FUNC(cb_draw_value), NULL);
|
|
|
|
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (button);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
box2 = gtk_hbox_new (FALSE, 10);
|
1999-01-28 10:35:40 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
/* An option menu to change the position of the value */
|
|
|
|
label = gtk_label_new ("Scale Value Position:");
|
|
|
|
gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
opt = gtk_option_menu_new();
|
|
|
|
menu = gtk_menu_new();
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
item = make_menu_item ("Top",
|
|
|
|
GTK_SIGNAL_FUNC(cb_pos_menu_select),
|
|
|
|
GINT_TO_POINTER (GTK_POS_TOP));
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
item = make_menu_item ("Bottom", GTK_SIGNAL_FUNC (cb_pos_menu_select),
|
|
|
|
GINT_TO_POINTER (GTK_POS_BOTTOM));
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
item = make_menu_item ("Left", GTK_SIGNAL_FUNC (cb_pos_menu_select),
|
|
|
|
GINT_TO_POINTER (GTK_POS_LEFT));
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
item = make_menu_item ("Right", GTK_SIGNAL_FUNC (cb_pos_menu_select),
|
|
|
|
GINT_TO_POINTER (GTK_POS_RIGHT));
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
gtk_option_menu_set_menu (GTK_OPTION_MENU (opt), menu);
|
|
|
|
gtk_box_pack_start (GTK_BOX (box2), opt, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (opt);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (box2);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
box2 = gtk_hbox_new (FALSE, 10);
|
1999-01-28 10:35:40 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
/* Yet another option menu, this time for the update policy of the
|
|
|
|
* scale widgets */
|
|
|
|
label = gtk_label_new ("Scale Update Policy:");
|
|
|
|
gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
opt = gtk_option_menu_new();
|
|
|
|
menu = gtk_menu_new();
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
item = make_menu_item ("Continuous",
|
|
|
|
GTK_SIGNAL_FUNC (cb_update_menu_select),
|
|
|
|
GINT_TO_POINTER (GTK_UPDATE_CONTINUOUS));
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
item = make_menu_item ("Discontinuous",
|
|
|
|
GTK_SIGNAL_FUNC (cb_update_menu_select),
|
|
|
|
GINT_TO_POINTER (GTK_UPDATE_DISCONTINUOUS));
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
item = make_menu_item ("Delayed",
|
|
|
|
GTK_SIGNAL_FUNC (cb_update_menu_select),
|
|
|
|
GINT_TO_POINTER (GTK_UPDATE_DELAYED));
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
gtk_option_menu_set_menu (GTK_OPTION_MENU (opt), menu);
|
|
|
|
gtk_box_pack_start (GTK_BOX (box2), opt, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (opt);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (box2);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
box2 = gtk_hbox_new (FALSE, 10);
|
1999-01-28 10:35:40 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
/* An HScale widget for adjusting the number of digits on the
|
1998-12-07 15:19:00 +00:00
|
|
|
* sample scales. */
|
|
|
|
label = gtk_label_new ("Scale Digits:");
|
|
|
|
gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
adj2 = gtk_adjustment_new (1.0, 0.0, 5.0, 1.0, 1.0, 0.0);
|
2002-02-16 23:52:30 +00:00
|
|
|
g_signal_connect (GTK_OBJECT (adj2), "value_changed",
|
1998-12-07 15:19:00 +00:00
|
|
|
GTK_SIGNAL_FUNC (cb_digits_scale), NULL);
|
|
|
|
scale = gtk_hscale_new (GTK_ADJUSTMENT (adj2));
|
|
|
|
gtk_scale_set_digits (GTK_SCALE (scale), 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (box2), scale, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (scale);
|
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (box2);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
box2 = gtk_hbox_new (FALSE, 10);
|
1999-01-28 10:35:40 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
/* And, one last HScale widget for adjusting the page size of the
|
1998-12-07 15:19:00 +00:00
|
|
|
* scrollbar. */
|
|
|
|
label = gtk_label_new ("Scrollbar Page Size:");
|
|
|
|
gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
adj2 = gtk_adjustment_new (1.0, 1.0, 101.0, 1.0, 1.0, 0.0);
|
2002-02-16 23:52:30 +00:00
|
|
|
g_signal_connect (GTK_OBJECT (adj2), "value_changed",
|
1998-12-07 15:19:00 +00:00
|
|
|
GTK_SIGNAL_FUNC (cb_page_size), adj1);
|
|
|
|
scale = gtk_hscale_new (GTK_ADJUSTMENT (adj2));
|
|
|
|
gtk_scale_set_digits (GTK_SCALE (scale), 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (box2), scale, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (scale);
|
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (box2);
|
|
|
|
|
|
|
|
separator = gtk_hseparator_new ();
|
|
|
|
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
|
|
|
|
gtk_widget_show (separator);
|
|
|
|
|
|
|
|
box2 = gtk_vbox_new (FALSE, 10);
|
1999-01-28 10:35:40 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
|
1998-12-07 15:19:00 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
|
|
|
|
gtk_widget_show (box2);
|
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("Quit");
|
2002-02-16 23:52:30 +00:00
|
|
|
g_signal_connect_swapped (GTK_OBJECT (button), "clicked",
|
1998-12-07 15:19:00 +00:00
|
|
|
GTK_SIGNAL_FUNC(gtk_main_quit),
|
|
|
|
NULL);
|
|
|
|
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
|
|
|
|
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
|
|
|
|
gtk_widget_grab_default (button);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
gtk_widget_show (window);
|
1998-08-13 13:11:14 +00:00
|
|
|
}
|
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
int main( int argc,
|
|
|
|
char *argv[] )
|
1998-08-13 13:11:14 +00:00
|
|
|
{
|
1998-12-07 15:19:00 +00:00
|
|
|
gtk_init(&argc, &argv);
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
create_range_controls();
|
1998-08-13 13:11:14 +00:00
|
|
|
|
1998-12-07 15:19:00 +00:00
|
|
|
gtk_main();
|
1998-08-13 13:11:14 +00:00
|
|
|
|
2002-02-16 23:52:30 +00:00
|
|
|
return 0;
|
1998-08-13 13:11:14 +00:00
|
|
|
}
|
|
|
|
|