~ubuntu-branches/ubuntu/lucid/fpc/lucid-proposed

« back to all changes in this revision

Viewing changes to fpcsrc/packages/extra/gtk/examples/tutorial/tut6_2.pp

  • Committer: Bazaar Package Importer
  • Author(s): Mazen Neifer, Torsten Werner, Mazen Neifer
  • Date: 2008-10-09 23:29:00 UTC
  • mfrom: (4.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20081009232900-553f61m37jkp6upv
Tags: 2.2.2-4
[ Torsten Werner ]
* Update ABI version in fpc-depends automatically.
* Remove empty directories from binary package fpc-source.

[ Mazen Neifer ]
* Removed leading path when calling update-alternatives to remove a Linitian
  error.
* Fixed clean target.
* Improved description of packages. (Closes: #498882)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
{
2
 
 
3
 
  This file extracted from the GTK 1.2 tutorial.
4
 
  Section 6.2
5
 
 
6
 
  Converted from C to Pascal by Thomas E. Payne
7
 
}
8
 
 program Tut6_2;
9
 
 
10
 
{$mode objfpc}
11
 
 
12
 
 uses
13
 
  glib,gdk,gtk,sysutils;
14
 
 
15
 
   //* Our usual callback function */
16
 
 
17
 
 procedure toggle_callback( widget : pGtkWidget; data : pgpointer   );cdecl;
18
 
   begin
19
 
     writeln ('Hello again - '+pchar(data)+' was pressed');
20
 
          if active(GTK_TOGGLE_BUTTON(widget)^)<>0 then
21
 
            //* If control reaches here, the toggle button is down */
22
 
            writeln('Toggle button is down')
23
 
          else
24
 
            //* If control reaches here, the toggle button is up */
25
 
            writeln('Toggle button is up');
26
 
   end;
27
 
  var
28
 
    //* GtkWidget is the storage type for widgets */
29
 
    window,button,box1,label_ : pGtkWidget;
30
 
  begin
31
 
     gtk_init (@argc, @argv);
32
 
     //* Create a new window */
33
 
     window := gtk_window_new (GTK_WINDOW_TOPLEVEL);
34
 
     gtk_window_set_title (GTK_WINDOW (window), 'Toggle Buttons!');
35
 
     //* It's a good idea to do this for all windows. */
36
 
     gtk_signal_connect (GTK_OBJECT (window), 'destroy',
37
 
                         GTK_SIGNAL_FUNC (@gtk_exit), Nil);
38
 
     gtk_signal_connect (GTK_OBJECT (window), 'delete_event',
39
 
                         GTK_SIGNAL_FUNC (@gtk_exit), Nil);
40
 
     //* Sets the border width of the window. */
41
 
     gtk_container_set_border_width (GTK_CONTAINER (window), 10);
42
 
     gtk_widget_realize(window);
43
 
     //* Create a new button */
44
 
     button := gtk_toggle_button_new ();
45
 
     //* Connect the "clicked" signal of the button to our callback */
46
 
     gtk_signal_connect (GTK_OBJECT (button), 'clicked',
47
 
                         GTK_SIGNAL_FUNC (@toggle_callback), pchar('toggle button'));
48
 
     //* This calls our box creating function */
49
 
     box1 := gtk_hbox_new(False, 0);
50
 
     gtk_container_set_border_width (GTK_CONTAINER (box1), 2);
51
 
     //* Create a label for the button */
52
 
     label_ := gtk_label_new ('toggle button');
53
 
     gtk_box_pack_start (GTK_BOX (box1), label_, FALSE, FALSE, 3);
54
 
     //* Pack and show all our widgets */
55
 
     gtk_widget_show(label_);
56
 
     gtk_widget_show(box1);
57
 
     gtk_container_add (GTK_CONTAINER (button), box1);
58
 
     gtk_widget_show(button);
59
 
     gtk_container_add (GTK_CONTAINER (window), button);
60
 
     gtk_widget_show (window);
61
 
     //* Rest in gtk_main and wait for the fun to begin! */
62
 
     gtk_main ();
63
 
 end.