tut6_3.pp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. {
  2. This file extracted from the GTK 1.2 tutorial.
  3. Section 6.3
  4. Converted from C to Pascal by Thomas E. Payne
  5. }
  6. program Tut6_3;
  7. {$mode objfpc}
  8. uses
  9. glib,gdk,gtk,sysutils;
  10. //* Our usual callback function */
  11. procedure checkbox_callback( widget : pGtkWidget; data : pgpointer );cdecl;
  12. begin
  13. writeln ('Hello again - '+pchar(data)+' was pressed');
  14. if active(GTK_CHECK_BUTTON(widget)^.toggle_button)<>0 then
  15. //* If control reaches here, the check button is down */
  16. writeln('Check button is down')
  17. else
  18. //* If control reaches here, the check button is up */
  19. writeln('Check 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), 'Check 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_check_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 (@checkbox_callback), pchar('check 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 ('check 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. //return(0);}/* example-end */
  58. end.