~ubuntu-branches/ubuntu/dapper/fpc/dapper

« back to all changes in this revision

Viewing changes to packages/extra/gtk/examples/clist.pp

  • Committer: Bazaar Package Importer
  • Author(s): Carlos Laviola
  • Date: 2004-08-12 16:29:37 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040812162937-moo8ulvysp1ln771
Tags: 1.9.4-5
fp-compiler: needs ld, adding dependency on binutils.  (Closes: #265265)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{
 
2
  $Id: clist.pp,v 1.2 2002/09/07 15:42:58 peter Exp $
 
3
 
 
4
  This file extracted from the Gtk tutorial.
 
5
  clist.c
 
6
 
 
7
  Converted from C to Pascal by Frank Loemker
 
8
  <floemker@techfak.uni-bielefeld.de>
 
9
}
 
10
program clist;
 
11
uses
 
12
  glib,Gdk,Gtk;
 
13
 
 
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 =
 
18
  (('Milk', '3 Oz'),
 
19
   ('Water', '6 l'),
 
20
   ('Carrots', '2'),
 
21
   ('Snakes', '55'));
 
22
var indx : integer ;
 
23
begin
 
24
  { Here we do the actual adding of the text. It's done once for
 
25
    each row. }
 
26
  for indx:=0 to 3 do
 
27
    gtk_clist_append (data, @drink[indx]);
 
28
end;
 
29
 
 
30
{ User clicked the 'Clear List' button. }
 
31
procedure button_clear_clicked (data : PGtkCList ); cdecl;
 
32
begin
 
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);
 
36
end;
 
37
 
 
38
{ The user clicked the 'Hide/Show titles' button. }
 
39
procedure button_hide_show_clicked (data : PGtkCList ); cdecl;
 
40
const flag:integer = 0;
 
41
begin
 
42
  { Just a flag to remember the status. 0 = currently visible }
 
43
 
 
44
  if flag = 0 then begin
 
45
        { Hide the titles and set the flag to 1 }
 
46
        gtk_clist_column_titles_hide (data);
 
47
        inc (flag);
 
48
  end else begin
 
49
    { Show the titles and reset flag to 0 }
 
50
    gtk_clist_column_titles_show (data);
 
51
    dec (flag);
 
52
  end;
 
53
end;
 
54
 
 
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;
 
58
var text : Pgchar;
 
59
begin
 
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
 
62
    argument text. }
 
63
  gtk_clist_get_text(thelist, row, column, @text);
 
64
 
 
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);
 
69
end;
 
70
 
 
71
const
 
72
  titles: array[0..1] of Pgchar = ('Ingredients','Amount');
 
73
var
 
74
  window,vbox,hbox,scroll, thelist,
 
75
  button_add, button_clear,button_hide_show : PGtkWidget;
 
76
begin
 
77
  gtk_init (@argc, @argv);
 
78
  gtk_rc_init;
 
79
 
 
80
  window := gtk_window_new(gtk_WINDOW_TOPLEVEL);
 
81
  gtk_widget_set_usize(PGtkWIDGET(window), 300, 150);
 
82
 
 
83
  gtk_window_set_title(PGtkWINDOW(window), 'GtkCList Example');
 
84
  gtk_signal_connect(PGtkOBJECT(window),'destroy',
 
85
                     tGtksignalfunc(@gtk_main_quit),
 
86
                     NIL);
 
87
 
 
88
  vbox := gtk_vbox_new(false, 5);
 
89
  gtk_container_set_border_width(PGtkCONTAINER(vbox), 5);
 
90
  gtk_container_add(PGtkCONTAINER(window), vbox);
 
91
 
 
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);
 
97
 
 
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);
 
101
 
 
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),
 
106
                     NIL);
 
107
 
 
108
  { It isn't necessary to shadow the border, but it looks nice :) }
 
109
  gtk_clist_set_shadow_type(PGtkCLIST(thelist), gtk_SHADOW_OUT);
 
110
 
 
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);
 
116
 
 
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);
 
121
 
 
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');
 
125
 
 
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);
 
129
 
 
130
  { Connect our callbacks to the three buttons }
 
131
  gtk_signal_connect_object(PGtkOBJECT(button_add), 'clicked',
 
132
                            tGtksignalfunc(@button_add_clicked),
 
133
                            gpointer(thelist));
 
134
  gtk_signal_connect_object(PGtkOBJECT(button_clear), 'clicked',
 
135
                            tGtksignalfunc(@button_clear_clicked),
 
136
                            gpointer (thelist));
 
137
  gtk_signal_connect_object(PGtkOBJECT(button_hide_show), 'clicked',
 
138
                            tGtksignalfunc(@button_hide_show_clicked),
 
139
                            gpointer (thelist));
 
140
 
 
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);
 
144
  gtk_main();
 
145
end.
 
146
{
 
147
  $Log: clist.pp,v $
 
148
  Revision 1.2  2002/09/07 15:42:58  peter
 
149
    * old logs removed and tabs fixed
 
150
 
 
151
  Revision 1.1  2002/01/29 17:55:05  peter
 
152
    * splitted to base and extra
 
153
 
 
154
}