/src/wrappers/gtk/examples/gtk-demo/sizegroup.e

http://github.com/tybor/Liberty · Specman e · 195 lines · 21 code · 38 blank · 136 comment · 2 complexity · 4ef16b133b6b247862ba9df55a9e86e5 MD5 · raw file

  1. indexing
  2. description: "."
  3. copyright: "[
  4. Copyright (C) 2006 Paolo Redaelli, GTK+ team
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation; either version 2.1 of
  8. the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA
  17. ]"
  18. class SIZEGROUP
  19. creation make
  20. feature
  21. -- /* Size Groups
  22. -- *
  23. -- * GtkSizeGroup provides a mechanism for grouping a number of
  24. -- * widgets together so they all request the same amount of space.
  25. -- * This is typically useful when you want a column of widgets to
  26. -- * have the same size, but you can't use a GtkTable widget.
  27. -- *
  28. -- * Note that size groups only affect the amount of space requested,
  29. -- * not the size that the widgets finally receive. If you want the
  30. -- * widgets in a GtkSizeGroup to actually be the same size, you need
  31. -- * to pack them in such a way that they get the size they request
  32. -- * and not more. For example, if you are packing your widgets
  33. -- * into a table, you would not include the GTK_FILL flag.
  34. -- */
  35. -- #include <gtk/gtk.h>
  36. -- static GtkWidget *window = NULL;
  37. -- /* Convenience function to create a combo box holding a number of strings
  38. -- */
  39. -- GtkWidget *
  40. -- create_combo_box (const char **strings)
  41. -- {
  42. -- GtkWidget *combo_box;
  43. -- const char **str;
  44. -- combo_box = gtk_combo_box_new_text ();
  45. -- for (str = strings; *str; str++)
  46. -- gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), *str);
  47. -- gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0);
  48. -- return combo_box;
  49. -- }
  50. -- static void
  51. -- add_row (GtkTable *table,
  52. -- int row,
  53. -- GtkSizeGroup *size_group,
  54. -- const char *label_text,
  55. -- const char **options)
  56. -- {
  57. -- GtkWidget *combo_box;
  58. -- GtkWidget *label;
  59. -- label = gtk_label_new_with_mnemonic (label_text);
  60. -- gtk_misc_set_alignment (GTK_MISC (label), 0, 1);
  61. -- gtk_table_attach (GTK_TABLE (table), label,
  62. -- 0, 1, row, row + 1,
  63. -- GTK_EXPAND | GTK_FILL, 0,
  64. -- 0, 0);
  65. -- combo_box = create_combo_box (options);
  66. -- gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo_box);
  67. -- gtk_size_group_add_widget (size_group, combo_box);
  68. -- gtk_table_attach (GTK_TABLE (table), combo_box,
  69. -- 1, 2, row, row + 1,
  70. -- 0, 0,
  71. -- 0, 0);
  72. -- }
  73. -- static void
  74. -- toggle_grouping (GtkToggleButton *check_button,
  75. -- GtkSizeGroup *size_group)
  76. -- {
  77. -- GtkSizeGroupMode new_mode;
  78. -- /* GTK_SIZE_GROUP_NONE is not generally useful, but is useful
  79. -- * here to show the effect of GTK_SIZE_GROUP_HORIZONTAL by
  80. -- * contrast.
  81. -- */
  82. -- if (gtk_toggle_button_get_active (check_button))
  83. -- new_mode = GTK_SIZE_GROUP_HORIZONTAL;
  84. -- else
  85. -- new_mode = GTK_SIZE_GROUP_NONE;
  86. -- gtk_size_group_set_mode (size_group, new_mode);
  87. -- }
  88. -- GtkWidget *
  89. -- do_sizegroup (GtkWidget *do_widget)
  90. -- {
  91. -- GtkWidget *table;
  92. -- GtkWidget *frame;
  93. -- GtkWidget *vbox;
  94. -- GtkWidget *check_button;
  95. -- GtkSizeGroup *size_group;
  96. -- static const char *color_options[] = {
  97. -- "Red", "Green", "Blue", NULL
  98. -- };
  99. -- static const char *dash_options[] = {
  100. -- "Solid", "Dashed", "Dotted", NULL
  101. -- };
  102. -- static const char *end_options[] = {
  103. -- "Square", "Round", "Arrow", NULL
  104. -- };
  105. -- if (!window)
  106. -- {
  107. -- window = gtk_dialog_new_with_buttons ("GtkSizeGroup",
  108. -- GTK_WINDOW (do_widget),
  109. -- 0,
  110. -- GTK_STOCK_CLOSE,
  111. -- GTK_RESPONSE_NONE,
  112. -- NULL);
  113. -- gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
  114. -- g_signal_connect (window, "response",
  115. -- G_CALLBACK (gtk_widget_destroy), NULL);
  116. -- g_signal_connect (window, "destroy",
  117. -- G_CALLBACK (gtk_widget_destroyed), &window);
  118. -- vbox = gtk_vbox_new (FALSE, 5);
  119. -- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox, TRUE, TRUE, 0);
  120. -- gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
  121. -- size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
  122. -- /* Create one frame holding color options
  123. -- */
  124. -- frame = gtk_frame_new ("Color Options");
  125. -- gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
  126. -- table = gtk_table_new (2, 2, FALSE);
  127. -- gtk_container_set_border_width (GTK_CONTAINER (table), 5);
  128. -- gtk_table_set_row_spacings (GTK_TABLE (table), 5);
  129. -- gtk_table_set_col_spacings (GTK_TABLE (table), 10);
  130. -- gtk_container_add (GTK_CONTAINER (frame), table);
  131. -- add_row (GTK_TABLE (table), 0, size_group, "_Foreground", color_options);
  132. -- add_row (GTK_TABLE (table), 1, size_group, "_Background", color_options);
  133. -- /* And another frame holding line style options
  134. -- */
  135. -- frame = gtk_frame_new ("Line Options");
  136. -- gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
  137. -- table = gtk_table_new (2, 2, FALSE);
  138. -- gtk_container_set_border_width (GTK_CONTAINER (table), 5);
  139. -- gtk_table_set_row_spacings (GTK_TABLE (table), 5);
  140. -- gtk_table_set_col_spacings (GTK_TABLE (table), 10);
  141. -- gtk_container_add (GTK_CONTAINER (frame), table);
  142. -- add_row (GTK_TABLE (table), 0, size_group, "_Dashing", dash_options);
  143. -- add_row (GTK_TABLE (table), 1, size_group, "_Line ends", end_options);
  144. -- /* And a check button to turn grouping on and off */
  145. -- check_button = gtk_check_button_new_with_mnemonic ("_Enable grouping");
  146. -- gtk_box_pack_start (GTK_BOX (vbox), check_button, FALSE, FALSE, 0);
  147. -- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), TRUE);
  148. -- g_signal_connect (check_button, "toggled",
  149. -- G_CALLBACK (toggle_grouping), size_group);
  150. -- }
  151. -- if (!GTK_WIDGET_VISIBLE (window))
  152. -- gtk_widget_show_all (window);
  153. -- else
  154. -- gtk_widget_destroy (window);
  155. -- return window;
  156. -- }
  157. end