panes.inc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. (* Paned Widgets
  2. *
  3. * The GtkHPaned and GtkVPaned Widgets divide their content
  4. * area into two panes with a divider in between that the
  5. * user can adjust. A separate child is placed into each
  6. * pane.
  7. *
  8. * There are a number of options that can be set for each pane.
  9. * This test contains both a horizontal (HPaned) and a vertical
  10. * (VPaned) widget, and allows you to adjust the options for
  11. * each side of each widget.
  12. *)
  13. var
  14. panes_window : PGtkWidget;
  15. procedure toggle_resize (widget : PGtkWidget;
  16. child : PGtkWidget); cdecl;
  17. var
  18. paned : PGtkPaned;
  19. is_child1,
  20. resize,
  21. shrink : gboolean;
  22. begin
  23. paned := PGtkPaned (child^.parent);
  24. is_child1 := (child = paned^.child1);
  25. if is_child1 then
  26. begin
  27. resize := child1_resize (paned^) <> 0;
  28. shrink := child1_shrink (paned^) <> 0;
  29. end else
  30. begin
  31. resize := child2_resize (paned^) <> 0;
  32. shrink := child2_shrink (paned^) <> 0;
  33. end;
  34. gtk_widget_ref (child);
  35. gtk_container_remove (pGtkContainer (child^.parent), child);
  36. if is_child1 then
  37. gtk_paned_pack1 (paned, child, not resize, shrink)
  38. else
  39. gtk_paned_pack2 (paned, child, not resize, shrink);
  40. gtk_widget_unref (child);
  41. end;
  42. procedure toggle_shrink (widget : PGtkWidget;
  43. child : PGtkWidget); cdecl;
  44. var
  45. paned : PGtkPaned;
  46. is_child1,
  47. resize,
  48. shrink : gboolean;
  49. begin
  50. paned := PGtkPaned (child^.parent);
  51. is_child1 := (child = paned^.child1);
  52. if is_child1 then
  53. begin
  54. resize := child1_resize (paned^) <> 0;
  55. shrink := child1_shrink (paned^) <> 0;
  56. end else
  57. begin
  58. resize := child2_resize (paned^) <> 0;
  59. shrink := child2_shrink (paned^) <> 0;
  60. end;
  61. gtk_widget_ref (child);
  62. gtk_container_remove (pGtkContainer (child^.parent), child);
  63. if is_child1 then
  64. gtk_paned_pack1 (paned, child, resize, not shrink)
  65. else
  66. gtk_paned_pack2 (paned, child, resize, not shrink);
  67. gtk_widget_unref (child);
  68. end;
  69. function create_pane_options (paned : PGtkPaned;
  70. frame_label : pgchar;
  71. label1 : pgchar;
  72. label2 : pgchar): PGtkWidget; cdecl;
  73. var
  74. frame,
  75. table,
  76. thelabel,
  77. check_button : PGtkWidget;
  78. begin
  79. frame := gtk_frame_new (frame_label);
  80. gtk_container_set_border_width (pGtkContainer(frame), 4);
  81. table := gtk_table_new (3, 2, TRUE);
  82. gtk_container_add (pGtkContainer(frame), table);
  83. thelabel := gtk_label_new (label1);
  84. gtk_table_attach_defaults (pGtkTable(table), thelabel, 0, 1, 0, 1);
  85. check_button := gtk_check_button_new_with_mnemonic ('_Resize');
  86. gtk_table_attach_defaults (pGtkTable(table), check_button, 0, 1, 1, 2);
  87. g_signal_connect (check_button, 'toggled',
  88. TGCallback (@toggle_resize), paned^.child1);
  89. check_button := gtk_check_button_new_with_mnemonic ('_Shrink');
  90. gtk_table_attach_defaults (pGtkTable(table), check_button, 0, 1, 2, 3);
  91. gtk_toggle_button_set_active (pGtkToggleButton(check_button), TRUE);
  92. g_signal_connect (check_button, 'toggled', TGCallback(@toggle_shrink), paned^.child1);
  93. thelabel := gtk_label_new (label2);
  94. gtk_table_attach_defaults (pGtkTable(table), thelabel, 1, 2, 0, 1);
  95. check_button := gtk_check_button_new_with_mnemonic ('_Resize');
  96. gtk_table_attach_defaults (pGtkTable(table), check_button, 1, 2, 1, 2);
  97. gtk_toggle_button_set_active (pGtkToggleButton(check_button), TRUE);
  98. g_signal_connect (check_button, 'toggled', TGCallback(@toggle_resize), paned^.child2);
  99. check_button := gtk_check_button_new_with_mnemonic ('_Shrink');
  100. gtk_table_attach_defaults (pGtkTable(table), check_button, 1, 2, 2, 3);
  101. gtk_toggle_button_set_active (pGtkToggleButton(check_button), TRUE);
  102. g_signal_connect (check_button, 'toggled', TGCallback(@toggle_shrink), paned^.child2);
  103. create_pane_options := frame;
  104. end;
  105. function do_panes : PGtkWidget;
  106. var
  107. frame,
  108. hpaned,
  109. vpaned,
  110. button,
  111. vbox : PGtkWidget;
  112. begin
  113. if panes_window = NULL then
  114. begin
  115. panes_window := gtk_window_new (GTK_WINDOW_TOPLEVEL);
  116. g_signal_connect (panes_window, 'destroy',
  117. TGCallback(@gtk_widget_destroyed), @panes_window);
  118. gtk_window_set_title (pGtkWindow(panes_window), 'Panes');
  119. gtk_container_set_border_width (pGtkContainer(panes_window), 0);
  120. vbox := gtk_vbox_new (FALSE, 0);
  121. gtk_container_add (pGtkContainer(panes_window), vbox);
  122. vpaned := gtk_vpaned_new ();
  123. gtk_box_pack_start (pGtkBox(vbox), vpaned, TRUE, TRUE, 0);
  124. gtk_container_set_border_width (pGtkContainer(vpaned), 5);
  125. hpaned := gtk_hpaned_new ();
  126. gtk_paned_add1 (pGtkPaned(vpaned), hpaned);
  127. frame := gtk_frame_new (NULL);
  128. gtk_frame_set_shadow_type (pGtkFrame(frame), GTK_SHADOW_IN);
  129. gtk_widget_set_size_request (frame, 60, 60);
  130. gtk_paned_add1 (pGtkPaned(hpaned), frame);
  131. button := gtk_button_new_with_mnemonic ('_Hi there');
  132. gtk_container_add (pGtkContainer(frame), button);
  133. frame := gtk_frame_new (NULL);
  134. gtk_frame_set_shadow_type (pGtkFrame(frame), GTK_SHADOW_IN);
  135. gtk_widget_set_size_request (frame, 80, 60);
  136. gtk_paned_add2 (pGtkPaned(hpaned), frame);
  137. frame := gtk_frame_new (NULL);
  138. gtk_frame_set_shadow_type (pGtkFrame(frame), GTK_SHADOW_IN);
  139. gtk_widget_set_size_request (frame, 60, 80);
  140. gtk_paned_add2 (pGtkPaned(vpaned), frame);
  141. (* Now create toggle buttons to control sizing *)
  142. gtk_box_pack_start (pGtkBox(vbox),
  143. create_pane_options (pGtkPaned(hpaned),
  144. 'Horizontal',
  145. 'Left',
  146. 'Right'),
  147. FALSE, FALSE, 0);
  148. gtk_box_pack_start (pGtkBox(vbox),
  149. create_pane_options (pGtkPaned(vpaned),
  150. 'Vertical',
  151. 'Top',
  152. 'Bottom'),
  153. FALSE, FALSE, 0);
  154. gtk_widget_show_all (vbox);
  155. end;
  156. if not GTK_WIDGET_VISIBLE (panes_window) then
  157. gtk_widget_show (panes_window)
  158. else begin
  159. gtk_widget_destroy (panes_window);
  160. panes_window := NULL;
  161. end;
  162. do_panes := panes_window;
  163. end;