tut6_2.pp 2.3 KB

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