tut6_2.pp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. {
  2. $Id$
  3. This file extracted from the GTK 1.2 tutorial.
  4. Section 6.2
  5. Converted from C to Pascal by Thomas E. Payne
  6. }
  7. program Tut6_2;
  8. {$mode objfpc}
  9. uses
  10. glib,gdk,gtk,sysutils;
  11. //* Our usual callback function */
  12. procedure toggle_callback( widget : pGtkWidget; data : pgpointer );cdecl;
  13. begin
  14. writeln ('Hello again - '+pchar(data)+' was pressed');
  15. if active(GTK_TOGGLE_BUTTON(widget)^)<>0 then
  16. //* If control reaches here, the toggle button is down */
  17. writeln('Toggle button is down')
  18. else
  19. //* If control reaches here, the toggle button is up */
  20. writeln('Toggle 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), 'Toggle 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_toggle_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 (@toggle_callback), pchar('toggle 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 ('toggle 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. end. $Log$
  59. end. Revision 1.2 2000-07-13 11:33:18 michael
  60. end. + removed logs
  61. end.
  62. }