tut6_3.pp 2.4 KB

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