tut2_1.pp 2.9 KB

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