tut4_5.pp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. {
  2. $Id$
  3. This file extracted from the GTK 1.2 tutorial.
  4. Section 4.5
  5. Converted from C to Pascal by Thomas E. Payne
  6. }
  7. program Tut4_5;
  8. {$mode objfpc}
  9. uses
  10. glib,gdk,gtk,sysutils;
  11. //* Our callback.
  12. //* The data passed to this function is printed to stdout */
  13. procedure callback(widget : pGtkWidget ; data: pgpointer ); cdecl;
  14. begin
  15. writeln('Hello again - '+pchar(data)+' was pressed');
  16. end;
  17. //* This callback quits the program */
  18. function delete_event (widget : pGtkWidget ; event: pGdkEvent; data: pgpointer ): integer; cdecl;
  19. begin
  20. gtk_main_quit();
  21. delete_event:=0;
  22. end;
  23. var
  24. window, button, table :pGtkWidget;
  25. begin
  26. gtk_init (@argc, @argv);
  27. //* Create a new window */
  28. window := gtk_window_new (GTK_WINDOW_TOPLEVEL);
  29. //* Set the window title */
  30. gtk_window_set_title (GTK_WINDOW (window), 'Table');
  31. //* Set a handler for delete_event that immediately
  32. //* exits GTK. */
  33. gtk_signal_connect (GTK_OBJECT (window), 'delete_event',
  34. GTK_SIGNAL_FUNC (@delete_event), NIL);
  35. //* Sets the border width of the window. */
  36. gtk_container_set_border_width (GTK_CONTAINER (window), 20);
  37. //* Create a 2x2 table */
  38. table := gtk_table_new (2, 2, TRUE);
  39. //* Put the table in the main window */
  40. gtk_container_add (GTK_CONTAINER (window), table);
  41. //* Create first button */
  42. button := gtk_button_new_with_label ('button 1');
  43. //* When the button is clicked, we call the "callback" function
  44. //* with a pointer to "button 1" as its argument */
  45. gtk_signal_connect (GTK_OBJECT (button), 'clicked',
  46. GTK_SIGNAL_FUNC (@callback), pchar('button 1'));
  47. //* Insert button 1 into the upper left quadrant of the table */
  48. gtk_table_attach_defaults (GTK_TABLE(table), button, 0, 1, 0, 1);
  49. gtk_widget_show (button);
  50. //* Create second button */
  51. button := gtk_button_new_with_label ('button 2');
  52. //* When the button is clicked, we call the "callback" function
  53. //* with a pointer to "button 2" as its argument */
  54. gtk_signal_connect (GTK_OBJECT (button), 'clicked',
  55. GTK_SIGNAL_FUNC (@callback), pchar('button 2'));
  56. //* Insert button 2 into the upper right quadrant of the table */
  57. gtk_table_attach_defaults (GTK_TABLE(table), button, 1, 2, 0, 1);
  58. gtk_widget_show (button);
  59. //* Create "Quit" button */
  60. button := gtk_button_new_with_label ('Quit');
  61. //* When the button is clicked, we call the "delete_event" function
  62. //* and the program exits */
  63. gtk_signal_connect (GTK_OBJECT (button), 'clicked',
  64. GTK_SIGNAL_FUNC (@delete_event), NIL);
  65. //* Insert the quit button into the both
  66. //* lower quadrants of the table */
  67. gtk_table_attach_defaults (GTK_TABLE(table), button, 0, 2, 1, 2);
  68. gtk_widget_show (button);
  69. gtk_widget_show (table);
  70. gtk_widget_show (window);
  71. gtk_main ();
  72. end. $Log$
  73. end. Revision 1.2 2000-07-13 11:33:18 michael
  74. end. + removed logs
  75. end.
  76. }