- Tidy up of the menufactory example from Andy Kahn <kahn@zk3.dec.com> -
Thu Aug 13 09:11:11 BST 1998 Tony Gale <gale@gtk.org> * docs/gtk_tut.sgml: - Tidy up of the menufactory example from Andy Kahn <kahn@zk3.dec.com> - New section on Range Widgets from David Huggins-Daines <bn711@freenet.carleton.ca> - Started a new section on 'Advanced Event and Signal Handling' - used an email from Owen. - New appendix on Gdk Event Types - Added the tictactoe full example code to the 'Code Examples' appendix * Add the range widgets example. Re-add the text and tree examples, as cvs has lost them.
This commit is contained in:
committed by
Tony Gale
parent
52a9e5cae8
commit
7977bf7bc4
15
ChangeLog
15
ChangeLog
@@ -1,3 +1,18 @@
|
||||
Thu Aug 13 09:11:11 BST 1998 Tony Gale <gale@gtk.org>
|
||||
|
||||
* docs/gtk_tut.sgml:
|
||||
- Tidy up of the menufactory example from
|
||||
Andy Kahn <kahn@zk3.dec.com>
|
||||
- New section on Range Widgets from
|
||||
David Huggins-Daines <bn711@freenet.carleton.ca>
|
||||
- Started a new section on 'Advanced Event and Signal
|
||||
Handling' - used an email from Owen.
|
||||
- New appendix on Gdk Event Types
|
||||
- Added the tictactoe full example code to the
|
||||
'Code Examples' appendix
|
||||
* Add the range widgets example. Re-add the text and tree
|
||||
examples, as cvs has lost them.
|
||||
|
||||
Tue Aug 11 20:52:58 1998 Tim Janik <timj@gtk.org>
|
||||
|
||||
* gtk/gtktypeutils.c (gtk_type_class_init): relookup nodes after
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
Thu Aug 13 09:11:11 BST 1998 Tony Gale <gale@gtk.org>
|
||||
|
||||
* docs/gtk_tut.sgml:
|
||||
- Tidy up of the menufactory example from
|
||||
Andy Kahn <kahn@zk3.dec.com>
|
||||
- New section on Range Widgets from
|
||||
David Huggins-Daines <bn711@freenet.carleton.ca>
|
||||
- Started a new section on 'Advanced Event and Signal
|
||||
Handling' - used an email from Owen.
|
||||
- New appendix on Gdk Event Types
|
||||
- Added the tictactoe full example code to the
|
||||
'Code Examples' appendix
|
||||
* Add the range widgets example. Re-add the text and tree
|
||||
examples, as cvs has lost them.
|
||||
|
||||
Tue Aug 11 20:52:58 1998 Tim Janik <timj@gtk.org>
|
||||
|
||||
* gtk/gtktypeutils.c (gtk_type_class_init): relookup nodes after
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
Thu Aug 13 09:11:11 BST 1998 Tony Gale <gale@gtk.org>
|
||||
|
||||
* docs/gtk_tut.sgml:
|
||||
- Tidy up of the menufactory example from
|
||||
Andy Kahn <kahn@zk3.dec.com>
|
||||
- New section on Range Widgets from
|
||||
David Huggins-Daines <bn711@freenet.carleton.ca>
|
||||
- Started a new section on 'Advanced Event and Signal
|
||||
Handling' - used an email from Owen.
|
||||
- New appendix on Gdk Event Types
|
||||
- Added the tictactoe full example code to the
|
||||
'Code Examples' appendix
|
||||
* Add the range widgets example. Re-add the text and tree
|
||||
examples, as cvs has lost them.
|
||||
|
||||
Tue Aug 11 20:52:58 1998 Tim Janik <timj@gtk.org>
|
||||
|
||||
* gtk/gtktypeutils.c (gtk_type_class_init): relookup nodes after
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
Thu Aug 13 09:11:11 BST 1998 Tony Gale <gale@gtk.org>
|
||||
|
||||
* docs/gtk_tut.sgml:
|
||||
- Tidy up of the menufactory example from
|
||||
Andy Kahn <kahn@zk3.dec.com>
|
||||
- New section on Range Widgets from
|
||||
David Huggins-Daines <bn711@freenet.carleton.ca>
|
||||
- Started a new section on 'Advanced Event and Signal
|
||||
Handling' - used an email from Owen.
|
||||
- New appendix on Gdk Event Types
|
||||
- Added the tictactoe full example code to the
|
||||
'Code Examples' appendix
|
||||
* Add the range widgets example. Re-add the text and tree
|
||||
examples, as cvs has lost them.
|
||||
|
||||
Tue Aug 11 20:52:58 1998 Tim Janik <timj@gtk.org>
|
||||
|
||||
* gtk/gtktypeutils.c (gtk_type_class_init): relookup nodes after
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
Thu Aug 13 09:11:11 BST 1998 Tony Gale <gale@gtk.org>
|
||||
|
||||
* docs/gtk_tut.sgml:
|
||||
- Tidy up of the menufactory example from
|
||||
Andy Kahn <kahn@zk3.dec.com>
|
||||
- New section on Range Widgets from
|
||||
David Huggins-Daines <bn711@freenet.carleton.ca>
|
||||
- Started a new section on 'Advanced Event and Signal
|
||||
Handling' - used an email from Owen.
|
||||
- New appendix on Gdk Event Types
|
||||
- Added the tictactoe full example code to the
|
||||
'Code Examples' appendix
|
||||
* Add the range widgets example. Re-add the text and tree
|
||||
examples, as cvs has lost them.
|
||||
|
||||
Tue Aug 11 20:52:58 1998 Tim Janik <timj@gtk.org>
|
||||
|
||||
* gtk/gtktypeutils.c (gtk_type_class_init): relookup nodes after
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
Thu Aug 13 09:11:11 BST 1998 Tony Gale <gale@gtk.org>
|
||||
|
||||
* docs/gtk_tut.sgml:
|
||||
- Tidy up of the menufactory example from
|
||||
Andy Kahn <kahn@zk3.dec.com>
|
||||
- New section on Range Widgets from
|
||||
David Huggins-Daines <bn711@freenet.carleton.ca>
|
||||
- Started a new section on 'Advanced Event and Signal
|
||||
Handling' - used an email from Owen.
|
||||
- New appendix on Gdk Event Types
|
||||
- Added the tictactoe full example code to the
|
||||
'Code Examples' appendix
|
||||
* Add the range widgets example. Re-add the text and tree
|
||||
examples, as cvs has lost them.
|
||||
|
||||
Tue Aug 11 20:52:58 1998 Tim Janik <timj@gtk.org>
|
||||
|
||||
* gtk/gtktypeutils.c (gtk_type_class_init): relookup nodes after
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
Thu Aug 13 09:11:11 BST 1998 Tony Gale <gale@gtk.org>
|
||||
|
||||
* docs/gtk_tut.sgml:
|
||||
- Tidy up of the menufactory example from
|
||||
Andy Kahn <kahn@zk3.dec.com>
|
||||
- New section on Range Widgets from
|
||||
David Huggins-Daines <bn711@freenet.carleton.ca>
|
||||
- Started a new section on 'Advanced Event and Signal
|
||||
Handling' - used an email from Owen.
|
||||
- New appendix on Gdk Event Types
|
||||
- Added the tictactoe full example code to the
|
||||
'Code Examples' appendix
|
||||
* Add the range widgets example. Re-add the text and tree
|
||||
examples, as cvs has lost them.
|
||||
|
||||
Tue Aug 11 20:52:58 1998 Tim Janik <timj@gtk.org>
|
||||
|
||||
* gtk/gtktypeutils.c (gtk_type_class_init): relookup nodes after
|
||||
|
||||
3742
docs/gtk_tut.sgml
3742
docs/gtk_tut.sgml
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
8
examples/rangewidgets/Makefile
Normal file
8
examples/rangewidgets/Makefile
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
CC = gcc
|
||||
|
||||
rangewidgets: rangewidgets.c
|
||||
$(CC) `gtk-config --cflags` `gtk-config --libs` rangewidgets.c -o rangewidgets
|
||||
|
||||
clean:
|
||||
rm -f *.o rangewidgets
|
||||
287
examples/rangewidgets/rangewidgets.c
Normal file
287
examples/rangewidgets/rangewidgets.c
Normal file
@@ -0,0 +1,287 @@
|
||||
/* example-start rangewidgets rangewidgets.c */
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
GtkWidget *hscale, *vscale;
|
||||
|
||||
void cb_pos_menu_select (GtkWidget *item, GtkPositionType pos)
|
||||
{
|
||||
/* 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);
|
||||
}
|
||||
|
||||
void cb_update_menu_select (GtkWidget *item, GtkUpdateType policy)
|
||||
{
|
||||
/* 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);
|
||||
}
|
||||
|
||||
void cb_digits_scale (GtkAdjustment *adj)
|
||||
{
|
||||
/* set the number of decimal places to which adj->vaule is rounded
|
||||
*/
|
||||
gtk_scale_set_digits (GTK_SCALE (hscale), (gint) adj->value);
|
||||
gtk_scale_set_digits (GTK_SCALE (vscale), (gint) adj->value);
|
||||
}
|
||||
|
||||
void cb_page_size (GtkAdjustment *get, GtkAdjustment *set)
|
||||
{
|
||||
/* 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 */
|
||||
gtk_signal_emit_by_name (GTK_OBJECT (set), "changed");
|
||||
}
|
||||
|
||||
void cb_draw_value (GtkToggleButton *button)
|
||||
{
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* convenience functions */
|
||||
|
||||
GtkWidget *make_menu_item (gchar *name, GtkSignalFunc callback,
|
||||
gpointer data)
|
||||
{
|
||||
GtkWidget *item;
|
||||
|
||||
item = gtk_menu_item_new_with_label (name);
|
||||
gtk_signal_connect (GTK_OBJECT (item), "activate",
|
||||
callback, data);
|
||||
gtk_widget_show (item);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
void scale_set_default_values (GtkScale *scale)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/* makes the sample window */
|
||||
|
||||
void create_range_controls (void)
|
||||
{
|
||||
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);
|
||||
gtk_signal_connect (GTK_OBJECT (window), "destroy",
|
||||
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);
|
||||
gtk_container_border_width (GTK_CONTAINER (box2), 10);
|
||||
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
|
||||
gtk_widget_show (box2);
|
||||
|
||||
/* value, lower, upper, step_increment, page_increment, page_size */
|
||||
/* 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);
|
||||
|
||||
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));
|
||||
gtk_widget_set_usize (GTK_WIDGET (hscale), 200, 30);
|
||||
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);
|
||||
gtk_container_border_width (GTK_CONTAINER (box2), 10);
|
||||
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");
|
||||
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (button), TRUE);
|
||||
gtk_signal_connect (GTK_OBJECT (button), "toggled", GTK_SIGNAL_FUNC
|
||||
(cb_draw_value), NULL);
|
||||
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
|
||||
gtk_widget_show (button);
|
||||
|
||||
box2 = gtk_hbox_new (FALSE, 10);
|
||||
gtk_container_border_width (GTK_CONTAINER (box2), 10);
|
||||
|
||||
/* 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);
|
||||
|
||||
opt = gtk_option_menu_new();
|
||||
menu = gtk_menu_new();
|
||||
|
||||
item = make_menu_item ("Top", GTK_SIGNAL_FUNC (cb_pos_menu_select),
|
||||
GINT_TO_POINTER (GTK_POS_TOP));
|
||||
gtk_menu_append (GTK_MENU (menu), item);
|
||||
|
||||
item = make_menu_item ("Bottom", GTK_SIGNAL_FUNC (cb_pos_menu_select),
|
||||
GINT_TO_POINTER (GTK_POS_BOTTOM));
|
||||
gtk_menu_append (GTK_MENU (menu), item);
|
||||
|
||||
item = make_menu_item ("Left", GTK_SIGNAL_FUNC (cb_pos_menu_select),
|
||||
GINT_TO_POINTER (GTK_POS_LEFT));
|
||||
gtk_menu_append (GTK_MENU (menu), item);
|
||||
|
||||
item = make_menu_item ("Right", GTK_SIGNAL_FUNC (cb_pos_menu_select),
|
||||
GINT_TO_POINTER (GTK_POS_RIGHT));
|
||||
gtk_menu_append (GTK_MENU (menu), item);
|
||||
|
||||
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);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
|
||||
gtk_widget_show (box2);
|
||||
|
||||
box2 = gtk_hbox_new (FALSE, 10);
|
||||
gtk_container_border_width (GTK_CONTAINER (box2), 10);
|
||||
|
||||
/* 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);
|
||||
|
||||
opt = gtk_option_menu_new();
|
||||
menu = gtk_menu_new();
|
||||
|
||||
item = make_menu_item ("Continuous",
|
||||
GTK_SIGNAL_FUNC (cb_update_menu_select),
|
||||
GINT_TO_POINTER (GTK_UPDATE_CONTINUOUS));
|
||||
gtk_menu_append (GTK_MENU (menu), item);
|
||||
|
||||
item = make_menu_item ("Discontinuous",
|
||||
GTK_SIGNAL_FUNC (cb_update_menu_select),
|
||||
GINT_TO_POINTER (GTK_UPDATE_DISCONTINUOUS));
|
||||
gtk_menu_append (GTK_MENU (menu), item);
|
||||
|
||||
item = make_menu_item ("Delayed",
|
||||
GTK_SIGNAL_FUNC (cb_update_menu_select),
|
||||
GINT_TO_POINTER (GTK_UPDATE_DELAYED));
|
||||
gtk_menu_append (GTK_MENU (menu), item);
|
||||
|
||||
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);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
|
||||
gtk_widget_show (box2);
|
||||
|
||||
box2 = gtk_hbox_new (FALSE, 10);
|
||||
gtk_container_border_width (GTK_CONTAINER (box2), 10);
|
||||
|
||||
/* a GtkHScale widget for adjusting the number of digits on the
|
||||
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);
|
||||
gtk_signal_connect (GTK_OBJECT (adj2), "value_changed",
|
||||
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);
|
||||
|
||||
box2 = gtk_hbox_new (FALSE, 10);
|
||||
gtk_container_border_width (GTK_CONTAINER (box2), 10);
|
||||
|
||||
/* And, one last GtkHScale widget for adjusting the page size of the
|
||||
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);
|
||||
gtk_signal_connect (GTK_OBJECT (adj2), "value_changed",
|
||||
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);
|
||||
gtk_container_border_width (GTK_CONTAINER (box2), 10);
|
||||
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
|
||||
gtk_widget_show (box2);
|
||||
|
||||
button = gtk_button_new_with_label ("Quit");
|
||||
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
|
||||
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);
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
create_range_controls();
|
||||
|
||||
gtk_main();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* example-end */
|
||||
8
examples/text/Makefile
Normal file
8
examples/text/Makefile
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
CC = gcc
|
||||
|
||||
text: text.c
|
||||
$(CC) `gtk-config --cflags` `gtk-config --libs` text.c -o text
|
||||
|
||||
clean:
|
||||
rm -f *.o text
|
||||
181
examples/text/text.c
Normal file
181
examples/text/text.c
Normal file
@@ -0,0 +1,181 @@
|
||||
/* example-start text text.c */
|
||||
|
||||
/* text.c */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
void text_toggle_editable (GtkWidget *checkbutton,
|
||||
GtkWidget *text)
|
||||
{
|
||||
gtk_text_set_editable(GTK_TEXT(text),
|
||||
GTK_TOGGLE_BUTTON(checkbutton)->active);
|
||||
}
|
||||
|
||||
void text_toggle_word_wrap (GtkWidget *checkbutton,
|
||||
GtkWidget *text)
|
||||
{
|
||||
gtk_text_set_word_wrap(GTK_TEXT(text),
|
||||
GTK_TOGGLE_BUTTON(checkbutton)->active);
|
||||
}
|
||||
|
||||
void close_application( GtkWidget *widget, gpointer data )
|
||||
{
|
||||
gtk_main_quit();
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
GtkWidget *window;
|
||||
GtkWidget *box1;
|
||||
GtkWidget *box2;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *button;
|
||||
GtkWidget *check;
|
||||
GtkWidget *separator;
|
||||
GtkWidget *table;
|
||||
GtkWidget *vscrollbar;
|
||||
GtkWidget *text;
|
||||
GdkColormap *cmap;
|
||||
GdkColor colour;
|
||||
GdkFont *fixed_font;
|
||||
|
||||
FILE *infile;
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_widget_set_usize (window, 600, 500);
|
||||
gtk_window_set_policy (GTK_WINDOW(window), TRUE, TRUE, FALSE);
|
||||
gtk_signal_connect (GTK_OBJECT (window), "destroy",
|
||||
GTK_SIGNAL_FUNC(close_application),
|
||||
NULL);
|
||||
gtk_window_set_title (GTK_WINDOW (window), "Text Widget Example");
|
||||
gtk_container_border_width (GTK_CONTAINER (window), 0);
|
||||
|
||||
|
||||
box1 = gtk_vbox_new (FALSE, 0);
|
||||
gtk_container_add (GTK_CONTAINER (window), box1);
|
||||
gtk_widget_show (box1);
|
||||
|
||||
|
||||
box2 = gtk_vbox_new (FALSE, 10);
|
||||
gtk_container_border_width (GTK_CONTAINER (box2), 10);
|
||||
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
|
||||
gtk_widget_show (box2);
|
||||
|
||||
|
||||
table = gtk_table_new (2, 2, FALSE);
|
||||
gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
|
||||
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 2);
|
||||
gtk_box_pack_start (GTK_BOX (box2), table, TRUE, TRUE, 0);
|
||||
gtk_widget_show (table);
|
||||
|
||||
/* Create the GtkText widget */
|
||||
text = gtk_text_new (NULL, NULL);
|
||||
gtk_text_set_editable (GTK_TEXT (text), TRUE);
|
||||
gtk_table_attach (GTK_TABLE (table), text, 0, 1, 0, 1,
|
||||
GTK_EXPAND | GTK_SHRINK | GTK_FILL,
|
||||
GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
|
||||
gtk_widget_show (text);
|
||||
|
||||
/* Add a vertical scrollbar to the GtkText widget */
|
||||
vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
|
||||
gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,
|
||||
GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
|
||||
gtk_widget_show (vscrollbar);
|
||||
|
||||
/* Get the system colour map and allocate the colour red */
|
||||
cmap = gdk_colormap_get_system();
|
||||
colour.red = 0xffff;
|
||||
colour.green = 0;
|
||||
colour.blue = 0;
|
||||
if (!gdk_color_alloc(cmap, &colour)) {
|
||||
g_error("couldn't allocate colour");
|
||||
}
|
||||
|
||||
/* Load a fixed font */
|
||||
fixed_font = gdk_font_load ("-misc-fixed-medium-r-*-*-*-140-*-*-*-*-*-*");
|
||||
|
||||
/* Realizing a widget creates a window for it, ready for us to insert some text */
|
||||
gtk_widget_realize (text);
|
||||
|
||||
/* Freeze the text widget, ready for multiple updates */
|
||||
gtk_text_freeze (GTK_TEXT (text));
|
||||
|
||||
/* Insert some coloured text */
|
||||
gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL,
|
||||
"Supports ", -1);
|
||||
gtk_text_insert (GTK_TEXT (text), NULL, &colour, NULL,
|
||||
"colored ", -1);
|
||||
gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL,
|
||||
"text and different ", -1);
|
||||
gtk_text_insert (GTK_TEXT (text), fixed_font, &text->style->black, NULL,
|
||||
"fonts\n\n", -1);
|
||||
|
||||
/* Load the file text.c into the text window */
|
||||
|
||||
infile = fopen("text.c", "r");
|
||||
|
||||
if (infile) {
|
||||
char buffer[1024];
|
||||
int nchars;
|
||||
|
||||
while (1)
|
||||
{
|
||||
nchars = fread(buffer, 1, 1024, infile);
|
||||
gtk_text_insert (GTK_TEXT (text), fixed_font, NULL,
|
||||
NULL, buffer, nchars);
|
||||
|
||||
if (nchars < 1024)
|
||||
break;
|
||||
}
|
||||
|
||||
fclose (infile);
|
||||
}
|
||||
|
||||
/* Thaw the text widget, allowing the updates to become visible */
|
||||
gtk_text_thaw (GTK_TEXT (text));
|
||||
|
||||
hbox = gtk_hbutton_box_new ();
|
||||
gtk_box_pack_start (GTK_BOX (box2), hbox, FALSE, FALSE, 0);
|
||||
gtk_widget_show (hbox);
|
||||
|
||||
check = gtk_check_button_new_with_label("Editable");
|
||||
gtk_box_pack_start (GTK_BOX (hbox), check, FALSE, FALSE, 0);
|
||||
gtk_signal_connect (GTK_OBJECT(check), "toggled",
|
||||
GTK_SIGNAL_FUNC(text_toggle_editable), text);
|
||||
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(check), TRUE);
|
||||
gtk_widget_show (check);
|
||||
check = gtk_check_button_new_with_label("Wrap Words");
|
||||
gtk_box_pack_start (GTK_BOX (hbox), check, FALSE, TRUE, 0);
|
||||
gtk_signal_connect (GTK_OBJECT(check), "toggled",
|
||||
GTK_SIGNAL_FUNC(text_toggle_word_wrap), text);
|
||||
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(check), FALSE);
|
||||
gtk_widget_show (check);
|
||||
|
||||
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);
|
||||
gtk_container_border_width (GTK_CONTAINER (box2), 10);
|
||||
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
|
||||
gtk_widget_show (box2);
|
||||
|
||||
button = gtk_button_new_with_label ("close");
|
||||
gtk_signal_connect (GTK_OBJECT (button), "clicked",
|
||||
GTK_SIGNAL_FUNC(close_application),
|
||||
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);
|
||||
|
||||
gtk_main ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* example-end */
|
||||
8
examples/tree/Makefile
Normal file
8
examples/tree/Makefile
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
CC = gcc
|
||||
|
||||
tree: tree.c
|
||||
$(CC) `gtk-config --cflags` `gtk-config --libs` tree.c -o tree
|
||||
|
||||
clean:
|
||||
rm -f *.o tree
|
||||
178
examples/tree/tree.c
Normal file
178
examples/tree/tree.c
Normal file
@@ -0,0 +1,178 @@
|
||||
/* example-start tree tree.c */
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
/* for all the GtkItem:: and GtkTreeItem:: signals */
|
||||
static void cb_itemsignal (GtkWidget *item, gchar *signame)
|
||||
{
|
||||
gchar *name;
|
||||
GtkLabel *label;
|
||||
|
||||
/* It's a GtkBin, so it has one child, which we know to be a
|
||||
label, so get that */
|
||||
label = GTK_LABEL (GTK_BIN (item)->child);
|
||||
/* Get the text of the label */
|
||||
gtk_label_get (label, &name);
|
||||
/* Get the level of the tree which the item is in */
|
||||
g_print ("%s called for item %s->%p, level %d\n", signame, name,
|
||||
item, GTK_TREE (item->parent)->level);
|
||||
}
|
||||
|
||||
/* Note that this is never called */
|
||||
static void cb_unselect_child (GtkWidget *root_tree, GtkWidget *child,
|
||||
GtkWidget *subtree)
|
||||
{
|
||||
g_print ("unselect_child called for root tree %p, subtree %p, child %p\n",
|
||||
root_tree, subtree, child);
|
||||
}
|
||||
|
||||
/* Note that this is called every time the user clicks on an item,
|
||||
whether it is already selected or not. */
|
||||
static void cb_select_child (GtkWidget *root_tree, GtkWidget *child,
|
||||
GtkWidget *subtree)
|
||||
{
|
||||
g_print ("select_child called for root tree %p, subtree %p, child %p\n",
|
||||
root_tree, subtree, child);
|
||||
}
|
||||
|
||||
static void cb_selection_changed (GtkWidget *tree)
|
||||
{
|
||||
GList *i;
|
||||
|
||||
g_print ("selection_change called for tree %p\n", tree);
|
||||
g_print ("selected objects are:\n");
|
||||
|
||||
i = GTK_TREE_SELECTION(tree);
|
||||
while (i){
|
||||
gchar *name;
|
||||
GtkLabel *label;
|
||||
GtkWidget *item;
|
||||
|
||||
/* Get a GtkWidget pointer from the list node */
|
||||
item = GTK_WIDGET (i->data);
|
||||
label = GTK_LABEL (GTK_BIN (item)->child);
|
||||
gtk_label_get (label, &name);
|
||||
g_print ("\t%s on level %d\n", name, GTK_TREE
|
||||
(item->parent)->level);
|
||||
i = i->next;
|
||||
}
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
GtkWidget *window, *scrolled_win, *tree;
|
||||
static gchar *itemnames[] = {"Foo", "Bar", "Baz", "Quux",
|
||||
"Maurice"};
|
||||
gint i;
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
|
||||
/* a generic toplevel window */
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_signal_connect (GTK_OBJECT(window), "delete_event",
|
||||
GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
|
||||
gtk_container_border_width (GTK_CONTAINER(window), 5);
|
||||
|
||||
/* A generic scrolled window */
|
||||
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
gtk_widget_set_usize (scrolled_win, 150, 200);
|
||||
gtk_container_add (GTK_CONTAINER(window), scrolled_win);
|
||||
gtk_widget_show (scrolled_win);
|
||||
|
||||
/* Create the root tree */
|
||||
tree = gtk_tree_new();
|
||||
g_print ("root tree is %p\n", tree);
|
||||
/* connect all GtkTree:: signals */
|
||||
gtk_signal_connect (GTK_OBJECT(tree), "select_child",
|
||||
GTK_SIGNAL_FUNC(cb_select_child), tree);
|
||||
gtk_signal_connect (GTK_OBJECT(tree), "unselect_child",
|
||||
GTK_SIGNAL_FUNC(cb_unselect_child), tree);
|
||||
gtk_signal_connect (GTK_OBJECT(tree), "selection_changed",
|
||||
GTK_SIGNAL_FUNC(cb_selection_changed), tree);
|
||||
/* Add it to the scrolled window */
|
||||
gtk_container_add (GTK_CONTAINER(scrolled_win), tree);
|
||||
/* Set the selection mode */
|
||||
gtk_tree_set_selection_mode (GTK_TREE(tree),
|
||||
GTK_SELECTION_MULTIPLE);
|
||||
/* Show it */
|
||||
gtk_widget_show (tree);
|
||||
|
||||
for (i = 0; i < 5; i++){
|
||||
GtkWidget *subtree, *item;
|
||||
gint j;
|
||||
|
||||
/* Create a tree item */
|
||||
item = gtk_tree_item_new_with_label (itemnames[i]);
|
||||
/* Connect all GtkItem:: and GtkTreeItem:: signals */
|
||||
gtk_signal_connect (GTK_OBJECT(item), "select",
|
||||
GTK_SIGNAL_FUNC(cb_itemsignal), "select");
|
||||
gtk_signal_connect (GTK_OBJECT(item), "deselect",
|
||||
GTK_SIGNAL_FUNC(cb_itemsignal), "deselect");
|
||||
gtk_signal_connect (GTK_OBJECT(item), "toggle",
|
||||
GTK_SIGNAL_FUNC(cb_itemsignal), "toggle");
|
||||
gtk_signal_connect (GTK_OBJECT(item), "expand",
|
||||
GTK_SIGNAL_FUNC(cb_itemsignal), "expand");
|
||||
gtk_signal_connect (GTK_OBJECT(item), "collapse",
|
||||
GTK_SIGNAL_FUNC(cb_itemsignal), "collapse");
|
||||
/* Add it to the parent tree */
|
||||
gtk_tree_append (GTK_TREE(tree), item);
|
||||
/* Show it - this can be done at any time */
|
||||
gtk_widget_show (item);
|
||||
/* Create this item's subtree */
|
||||
subtree = gtk_tree_new();
|
||||
g_print ("-> item %s->%p, subtree %p\n", itemnames[i], item,
|
||||
subtree);
|
||||
|
||||
/* This is still necesary if you want these signals to be called
|
||||
for the subtree's children. Note that selection_change will be
|
||||
signalled for the root tree regardless. */
|
||||
gtk_signal_connect (GTK_OBJECT(subtree), "select_child",
|
||||
GTK_SIGNAL_FUNC(cb_select_child), subtree);
|
||||
gtk_signal_connect (GTK_OBJECT(subtree), "unselect_child",
|
||||
GTK_SIGNAL_FUNC(cb_unselect_child), subtree);
|
||||
/* This has absolutely no effect, because it is completely ignored
|
||||
in subtrees */
|
||||
gtk_tree_set_selection_mode (GTK_TREE(subtree),
|
||||
GTK_SELECTION_SINGLE);
|
||||
/* Neither does this, but for a rather different reason - the
|
||||
view_mode and view_line values of a tree are propagated to
|
||||
subtrees when they are mapped. So, setting it later on would
|
||||
actually have a (somewhat unpredictable) effect */
|
||||
gtk_tree_set_view_mode (GTK_TREE(subtree), GTK_TREE_VIEW_ITEM);
|
||||
/* Set this item's subtree - note that you cannot do this until
|
||||
AFTER the item has been added to its parent tree! */
|
||||
gtk_tree_item_set_subtree (GTK_TREE_ITEM(item), subtree);
|
||||
|
||||
for (j = 0; j < 5; j++){
|
||||
GtkWidget *subitem;
|
||||
|
||||
/* Create a subtree item, in much the same way */
|
||||
subitem = gtk_tree_item_new_with_label (itemnames[j]);
|
||||
/* Connect all GtkItem:: and GtkTreeItem:: signals */
|
||||
gtk_signal_connect (GTK_OBJECT(subitem), "select",
|
||||
GTK_SIGNAL_FUNC(cb_itemsignal), "select");
|
||||
gtk_signal_connect (GTK_OBJECT(subitem), "deselect",
|
||||
GTK_SIGNAL_FUNC(cb_itemsignal), "deselect");
|
||||
gtk_signal_connect (GTK_OBJECT(subitem), "toggle",
|
||||
GTK_SIGNAL_FUNC(cb_itemsignal), "toggle");
|
||||
gtk_signal_connect (GTK_OBJECT(subitem), "expand",
|
||||
GTK_SIGNAL_FUNC(cb_itemsignal), "expand");
|
||||
gtk_signal_connect (GTK_OBJECT(subitem), "collapse",
|
||||
GTK_SIGNAL_FUNC(cb_itemsignal), "collapse");
|
||||
g_print ("-> -> item %s->%p\n", itemnames[j], subitem);
|
||||
/* Add it to its parent tree */
|
||||
gtk_tree_append (GTK_TREE(subtree), subitem);
|
||||
/* Show it */
|
||||
gtk_widget_show (subitem);
|
||||
}
|
||||
}
|
||||
|
||||
/* Show the window and loop endlessly */
|
||||
gtk_widget_show (window);
|
||||
gtk_main();
|
||||
return 0;
|
||||
}
|
||||
/* example-end */
|
||||
Reference in New Issue
Block a user