button_box.inc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. (* Button Boxes
  2. *
  3. * The Button Box widgets are used to arrange buttons with padding.
  4. *)
  5. function create_bbox (horizontal : gboolean;
  6. title : pgchar;
  7. spacing : gint;
  8. layout : TGtkButtonBoxStyle): PGtkWidget;
  9. var
  10. frame,
  11. bbox,
  12. button : PGtkWidget;
  13. begin
  14. frame := gtk_frame_new (title);
  15. if horizontal then
  16. bbox := gtk_hbutton_box_new ()
  17. else
  18. bbox := gtk_vbutton_box_new ();
  19. gtk_container_set_border_width (GTK_CONTAINER (bbox), 5);
  20. gtk_container_add (GTK_CONTAINER (frame), bbox);
  21. gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout);
  22. gtk_box_set_spacing (GTK_BOX (bbox), spacing);
  23. button := gtk_button_new_from_stock (GTK_STOCK_OK);
  24. gtk_container_add (GTK_CONTAINER (bbox), button);
  25. button := gtk_button_new_from_stock (GTK_STOCK_CANCEL);
  26. gtk_container_add (GTK_CONTAINER (bbox), button);
  27. button := gtk_button_new_from_stock (GTK_STOCK_HELP);
  28. gtk_container_add (GTK_CONTAINER (bbox), button);
  29. create_bbox := frame;
  30. end;
  31. var bbox_window : PGtkWidget;
  32. function do_button_box : PGtkWidget;
  33. var
  34. main_vbox,
  35. vbox,
  36. hbox,
  37. frame_horz,
  38. frame_vert : PGtkWidget;
  39. begin
  40. if bbox_window = NULL then
  41. begin
  42. bbox_window := gtk_window_new (GTK_WINDOW_TOPLEVEL);
  43. gtk_window_set_title (GTK_WINDOW (bbox_window), 'Button Boxes');
  44. g_signal_connect (bbox_window, 'destroy',
  45. G_CALLBACK (@gtk_widget_destroyed),
  46. @bbox_window);
  47. gtk_container_set_border_width (GTK_CONTAINER (bbox_window), 10);
  48. main_vbox := gtk_vbox_new (FALSE, 0);
  49. gtk_container_add (GTK_CONTAINER (bbox_window), main_vbox);
  50. frame_horz := gtk_frame_new ('Horizontal Button Boxes');
  51. gtk_box_pack_start (GTK_BOX (main_vbox), frame_horz, TRUE, TRUE, 10);
  52. vbox := gtk_vbox_new (FALSE, 0);
  53. gtk_container_set_border_width (GTK_CONTAINER (vbox), 10);
  54. gtk_container_add (GTK_CONTAINER (frame_horz), vbox);
  55. gtk_box_pack_start (GTK_BOX (vbox),
  56. create_bbox (TRUE, 'Spread', 40, GTK_BUTTONBOX_SPREAD),
  57. TRUE, TRUE, 0);
  58. gtk_box_pack_start (GTK_BOX (vbox),
  59. create_bbox (TRUE, 'Edge', 40, GTK_BUTTONBOX_EDGE),
  60. TRUE, TRUE, 5);
  61. gtk_box_pack_start (GTK_BOX (vbox),
  62. create_bbox (TRUE, 'Start', 40, GTK_BUTTONBOX_START),
  63. TRUE, TRUE, 5);
  64. gtk_box_pack_start (GTK_BOX (vbox),
  65. create_bbox (TRUE, 'End', 40, GTK_BUTTONBOX_END),
  66. TRUE, TRUE, 5);
  67. frame_vert := gtk_frame_new ('Vertical Button Boxes');
  68. gtk_box_pack_start (GTK_BOX (main_vbox), frame_vert, TRUE, TRUE, 10);
  69. hbox := gtk_hbox_new (FALSE, 0);
  70. gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
  71. gtk_container_add (GTK_CONTAINER (frame_vert), hbox);
  72. gtk_box_pack_start (GTK_BOX (hbox),
  73. create_bbox (FALSE, 'Spread', 30, GTK_BUTTONBOX_SPREAD),
  74. TRUE, TRUE, 0);
  75. gtk_box_pack_start (GTK_BOX (hbox),
  76. create_bbox (FALSE, 'Edge', 30, GTK_BUTTONBOX_EDGE),
  77. TRUE, TRUE, 5);
  78. gtk_box_pack_start (GTK_BOX (hbox),
  79. create_bbox (FALSE, 'Start', 30, GTK_BUTTONBOX_START),
  80. TRUE, TRUE, 5);
  81. gtk_box_pack_start (GTK_BOX (hbox),
  82. create_bbox (FALSE, 'End', 30, GTK_BUTTONBOX_END),
  83. TRUE, TRUE, 5);
  84. end;
  85. if not GTK_WIDGET_VISIBLE (bbox_window) then
  86. gtk_widget_show_all (bbox_window)
  87. else
  88. begin
  89. gtk_widget_destroy (bbox_window);
  90. bbox_window := NULL;
  91. end;
  92. do_button_box := bbox_window;
  93. end;