~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to languages/pascal/app_templates/fpcgtk/main.pp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
program %{APPNAMELC};
 
2
 
 
3
{$mode objfpc}
 
4
 
 
5
uses
 
6
 glib,gdk,gtk;
 
7
 
 
8
procedure hello(widget : pGtkWidget ; data: pgpointer ); cdecl;
 
9
begin
 
10
  writeln('Hello World');
 
11
end;
 
12
 
 
13
function delete_event (widget : pGtkWidget ; event: pGdkEvent; data: pgpointer ): integer; cdecl;
 
14
begin
 
15
  writeln('Delete Event Occurred');
 
16
  delete_event := ord(true);
 
17
end;
 
18
 
 
19
procedure destroy(widget : pGtkWidget ; data: pgpointer ); cdecl;
 
20
begin
 
21
  gtk_main_quit();
 
22
end;
 
23
 
 
24
var
 
25
  window, button :  pGtkWidget;//GtkWidget is the storage type for widgets
 
26
 
 
27
 
 
28
begin
 
29
  // This is called in all GTK applications. Arguments are parsed
 
30
  // from the command line and are returned to the application.
 
31
  gtk_init (@argc, @argv);
 
32
 
 
33
  // create a new window
 
34
  window := gtk_window_new (GTK_WINDOW_TOPLEVEL);
 
35
 
 
36
  // When the window is given the "delete_event" signal (this is given
 
37
  // by the window manager, usually by the 'close' option, or on the
 
38
  // titlebar), we ask it to call the delete_event () function
 
39
  // as defined above. The data passed to the callback
 
40
  // function is NULL and is ignored in the callback function.
 
41
  gtk_signal_connect (pGTKOBJECT (window), 'delete_event',
 
42
                      GTK_SIGNAL_FUNC (@delete_event), NIL);
 
43
 
 
44
 
 
45
  // Here we connect the "destroy" event to a signal handler.
 
46
  // This event occurs when we call gtk_widget_destroy() on the window,
 
47
  // or if we return 'FALSE' in the "delete_event" callback.
 
48
  gtk_signal_connect (pGTKOBJECT (window), 'destroy',
 
49
                    GTK_SIGNAL_FUNC (@destroy), NULL);
 
50
 
 
51
  // Sets the border width of the window.
 
52
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);
 
53
 
 
54
  // Creates a new button with the label "Hello World".
 
55
  button := gtk_button_new_with_label ('Hello_World');
 
56
 
 
57
  // When the button receives the "clicked" signal, it will call the
 
58
  // function hello() passing it NULL as its argument.  The hello()
 
59
  // function is defined above. */
 
60
  gtk_signal_connect (pGTKOBJECT (button), 'clicked',
 
61
                              GTK_SIGNAL_FUNC (@hello), NULL);
 
62
 
 
63
  // This will cause the window to be destroyed by calling
 
64
  // gtk_widget_destroy(window) when "clicked".  Again, the destroy
 
65
  // signal could come from here, or the window manager
 
66
  gtk_signal_connect_object (pGTKOBJECT (button), 'clicked',
 
67
                      GTK_SIGNAL_FUNC (@gtk_widget_destroy),
 
68
                      pGTKOBJECT(window));
 
69
 
 
70
  // This packs the button into the window (a gtk container).
 
71
  gtk_container_add (GTK_CONTAINER (window), button);
 
72
 
 
73
  // The final step is to display this newly created widget.
 
74
  gtk_widget_show (button);
 
75
 
 
76
  // and the window
 
77
  gtk_widget_show (window);
 
78
 
 
79
  // All GTK applications must have a gtk_main(). Control ends here
 
80
  // and waits for an event to occur (like a key press or
 
81
  // mouse event).
 
82
  gtk_main ();
 
83
 
 
84
end.