File: TestSizeGroup.cs

package info (click to toggle)
gtk-sharp3 2.99.3-4.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 25,488 kB
  • sloc: xml: 308,885; cs: 38,796; sh: 11,336; perl: 1,295; makefile: 1,099; ansic: 903
file content (139 lines) | stat: -rw-r--r-- 3,374 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//
// TestSizeGroup.cs
//
// Author: Duncan Mak  (duncan@ximian.com)
//
// Copyright (C) 2002, Duncan Mak, Ximian Inc.
//

using System;

using Gtk;

namespace WidgetViewer {
	public class TestSizeGroup {

		static Dialog window = null;
		static SizeGroup size_group = null;

		public static Gtk.Window Create ()
		{
			window = new Dialog ();
			window.Title = "Sized groups";
			window.Resizable = false;
			
			VBox vbox = new VBox (false, 5);
			window.ContentArea.PackStart (vbox, true, true, 0);
			vbox.BorderWidth = 5;

			size_group = new SizeGroup (SizeGroupMode.Horizontal);

			Frame frame = new Frame ("Color Options");
			vbox.PackStart (frame, true, true, 0);

			Table table = new Table (2, 2, false);
			table.BorderWidth = 5;
			table.RowSpacing = 5;
			table.ColumnSpacing = 10;
			frame.Add (table);

			string [] colors = {"Red", "Green", "Blue", };
			string [] dashes = {"Solid", "Dashed", "Dotted", };
			string [] ends = {"Square", "Round", "Arrow", };

			Add_Row (table, 0, size_group, "_Foreground", colors);
			Add_Row (table, 1, size_group, "_Background", colors);

			frame = new Frame ("Line Options");
			vbox.PackStart (frame, false, false, 0);

			table = new Table (2, 2, false);
			table.BorderWidth = 5;
			table.RowSpacing = 5;
			table.ColumnSpacing = 10;
			frame.Add (table);

			Add_Row (table, 0, size_group, "_Dashing", dashes);
			Add_Row (table, 1, size_group, "_Line ends", ends);

			CheckButton check_button = new CheckButton ("_Enable grouping");
			vbox.PackStart (check_button, false, false, 0);
			check_button.Active = true;
			check_button.Toggled += new EventHandler (Button_Toggle_Cb);

			Button close_button = new Button (Stock.Close);
			close_button.Clicked += new EventHandler (Close_Button);
			window.ActionArea.PackStart (close_button, false, false, 0);
			
			window.ShowAll ();
			return window;
		}

		static ComboBox Create_ComboBox (string [] strings)
		{
			/*Menu menu = new Menu ();

			MenuItem menu_item = null;

			foreach (string str in strings) {
				menu_item = new MenuItem (str);
				menu_item.Show ();
				menu.Append (menu_item);
			}

			OptionMenu option_menu = new OptionMenu ();
			option_menu.Menu = menu;

			return option_menu;*/
			ComboBoxText combo_box = new ComboBoxText ();
			foreach (string str in strings) {
				combo_box.AppendText (str);
			}
			
			return combo_box;
		}

		static void Add_Row (Table table, uint row, SizeGroup size_group,
				     string label_text, string [] options)
		{
			Label label = new Label (label_text);
			label.SetAlignment (0, 1);

			table.Attach (label,
				      0, 1, row, row + 1,
				      AttachOptions.Expand, AttachOptions.Fill,
				      0, 0);

			ComboBox combo_box = Create_ComboBox (options);

			size_group.AddWidget (combo_box);
			table.Attach (combo_box,
				      1, 2, row, row + 1,
				      AttachOptions.Expand, AttachOptions.Expand,
				      0, 0);
		}

		static void Button_Toggle_Cb (object o, EventArgs args)
		{
			Toggle_Grouping ((ToggleButton) o, size_group);
		}

		static void Toggle_Grouping (ToggleButton check_button,
					     SizeGroup size_group)
		{
			SizeGroupMode mode;

			if (check_button.Active)
				mode = SizeGroupMode.Horizontal;
			else
				mode = SizeGroupMode.None;

			size_group.Mode = mode;
		}

		static void Close_Button (object o, EventArgs args)
		{
			window.Destroy ();
		}
	}
}