2
$Id: clist.pp,v 1.2 2002/09/07 15:42:58 peter Exp $
4
This file extracted from the Gtk tutorial.
7
Converted from C to Pascal by Frank Loemker
8
<floemker@techfak.uni-bielefeld.de>
14
{ User clicked the 'Add List' button. }
15
procedure button_add_clicked (data: PGtkCList ); cdecl;
16
{ Something silly to add to the list. 4 rows of 2 columns each }
17
const drink : array[0..3,0..1] of Pgchar =
24
{ Here we do the actual adding of the text. It's done once for
27
gtk_clist_append (data, @drink[indx]);
30
{ User clicked the 'Clear List' button. }
31
procedure button_clear_clicked (data : PGtkCList ); cdecl;
33
{ Clear the list using gtk_clist_clear. This is much faster than
34
calling gtk_clist_remove once for each row. }
35
gtk_clist_clear (data);
38
{ The user clicked the 'Hide/Show titles' button. }
39
procedure button_hide_show_clicked (data : PGtkCList ); cdecl;
40
const flag:integer = 0;
42
{ Just a flag to remember the status. 0 = currently visible }
44
if flag = 0 then begin
45
{ Hide the titles and set the flag to 1 }
46
gtk_clist_column_titles_hide (data);
49
{ Show the titles and reset flag to 0 }
50
gtk_clist_column_titles_show (data);
55
{ If we come here, then the user has selected a row in the list. }
56
procedure selection_made (thelist : PGtkCLIST ; row, column: gint;
57
event : PGdkEventButton ; data : gpointer); cdecl;
60
{ Get the text that is stored in the selected row and column
61
which was clicked in. We will receive it as a pointer in the
63
gtk_clist_get_text(thelist, row, column, @text);
65
{ Just prints some information about the selected row }
66
writeln ('You selected row ',row,
67
'. More specifically you clicked in column ',column,
68
', and the text in this cell is ',text,#10);
72
titles: array[0..1] of Pgchar = ('Ingredients','Amount');
74
window,vbox,hbox,scroll, thelist,
75
button_add, button_clear,button_hide_show : PGtkWidget;
77
gtk_init (@argc, @argv);
80
window := gtk_window_new(gtk_WINDOW_TOPLEVEL);
81
gtk_widget_set_usize(PGtkWIDGET(window), 300, 150);
83
gtk_window_set_title(PGtkWINDOW(window), 'GtkCList Example');
84
gtk_signal_connect(PGtkOBJECT(window),'destroy',
85
tGtksignalfunc(@gtk_main_quit),
88
vbox := gtk_vbox_new(false, 5);
89
gtk_container_set_border_width(PGtkCONTAINER(vbox), 5);
90
gtk_container_add(PGtkCONTAINER(window), vbox);
92
{ Create the ScrolledWindow to pack the CList in. }
93
scroll := gtk_scrolled_window_new (NULL,NULL);
94
gtk_scrolled_window_set_policy (PGtkSCROLLEDWINDOW(scroll),
95
GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
96
gtk_box_pack_start(PGtkBOX(vbox), scroll, true, true, 0);
98
{ Create the GtkCList. For this example we use 2 columns }
99
thelist := gtk_clist_new_with_titles (2,titles);
100
gtk_container_add (PGtkContainer(scroll),thelist);
102
{ When a selection is made, we want to know about it. The callback
103
used is selection_made, and it's code can be found above }
104
gtk_signal_connect(PGtkOBJECT(thelist), 'select_row',
105
tGtksignalfunc(@selection_made),
108
{ It isn't necessary to shadow the border, but it looks nice :) }
109
gtk_clist_set_shadow_type(PGtkCLIST(thelist), gtk_SHADOW_OUT);
111
{ What however is important, is that we set the column widths as
112
they will never be right otherwise. Note that the columns are
113
numbered from 0 and up (to 1 in this case). }
114
gtk_clist_set_column_width (PGtkCLIST(thelist), 0, 150);
115
gtk_clist_set_column_width (PGtkCLIST(thelist), 1, 100);
117
{ Create the buttons and add them to the window. See the button
118
tutorial for more examples and comments on this. }
119
hbox := gtk_hbox_new(false, 0);
120
gtk_box_pack_start(PGtkBOX(vbox), hbox, false, true, 0);
122
button_add := gtk_button_new_with_label('Add List');
123
button_clear := gtk_button_new_with_label('Clear List');
124
button_hide_show := gtk_button_new_with_label('Hide/Show titles');
126
gtk_box_pack_start (PGtkBOX(hbox), button_add, true, true, 0);
127
gtk_box_pack_start (PGtkBOX(hbox), button_clear, true, true, 0);
128
gtk_box_pack_start (PGtkBOX(hbox), button_hide_show, true, true, 0);
130
{ Connect our callbacks to the three buttons }
131
gtk_signal_connect_object(PGtkOBJECT(button_add), 'clicked',
132
tGtksignalfunc(@button_add_clicked),
134
gtk_signal_connect_object(PGtkOBJECT(button_clear), 'clicked',
135
tGtksignalfunc(@button_clear_clicked),
137
gtk_signal_connect_object(PGtkOBJECT(button_hide_show), 'clicked',
138
tGtksignalfunc(@button_hide_show_clicked),
141
{ The interface is completely set up so we show all the widgets and
142
enter the gtk_main loop }
143
gtk_widget_show_all(window);
148
Revision 1.2 2002/09/07 15:42:58 peter
149
* old logs removed and tabs fixed
151
Revision 1.1 2002/01/29 17:55:05 peter
152
* splitted to base and extra