Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MainWindow.cs « Samples « TestApps - github.com/mono/xwt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7523dc472be6150e8f30b708aeb953a043bdc73a (plain)
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
using System;
using Xwt;
using Xwt.Drawing;
using System.Xml;

namespace Samples
{
	public class MainWindow: Window
	{
		TreeView samplesTree;
		TreeStore store;
		Image icon;
		VBox sampleBox;
		Label title;
		Widget currentSample;
		
		DataField<string> nameCol = new DataField<string> ();
		DataField<Sample> widgetCol = new DataField<Sample> ();
		DataField<Image> iconCol = new DataField<Image> ();
		
		StatusIcon statusIcon;
		
		public MainWindow ()
		{
			Title = "Xwt Demo Application";
			Width = 500;
			Height = 400;

			try {
				statusIcon = Application.CreateStatusIcon ();
				statusIcon.Menu = new Menu ();
				statusIcon.Menu.Items.Add (new MenuItem ("Test"));
				statusIcon.Image = Image.FromResource (GetType (), "package.png");
			} catch {
				Console.WriteLine ("Status icon could not be shown");
			}
			
			Menu menu = new Menu ();
			
			var file = new MenuItem ("_File");
			file.SubMenu = new Menu ();
			file.SubMenu.Items.Add (new MenuItem ("_Open"));
			file.SubMenu.Items.Add (new MenuItem ("_New"));
			MenuItem mi = new MenuItem ("_Close");
			mi.Clicked += delegate {
				Application.Exit();
			};
			file.SubMenu.Items.Add (mi);
			menu.Items.Add (file);
			
			var edit = new MenuItem ("_Edit");
			edit.SubMenu = new Menu ();
			edit.SubMenu.Items.Add (new MenuItem ("_Copy"));
			edit.SubMenu.Items.Add (new MenuItem ("Cu_t"));
			edit.SubMenu.Items.Add (new MenuItem ("_Paste"));
			menu.Items.Add (edit);
			
			MainMenu = menu;
			
			
			HPaned box = new HPaned ();
			
			icon = Image.FromResource (typeof(App), "document-generic.png");
			
			store = new TreeStore (nameCol, iconCol, widgetCol);
			samplesTree = new TreeView ();
			samplesTree.Columns.Add ("Name", iconCol, nameCol);

			var w = AddSample (null, "Widgets", null);
			AddSample (w, "Boxes", typeof(Boxes));
			AddSample (w, "Buttons", typeof(ButtonSample));
			AddSample (w, "Calendar", typeof(CalendarSample));
			AddSample (w, "CheckBox", typeof(Checkboxes));
			AddSample (w, "Clipboard", typeof(ClipboardSample));
			AddSample (w, "ColorSelector", typeof(ColorSelectorSample));
			AddSample (w, "FileSelector", typeof (FileSelectorSample));
			AddSample (w, "FolderSelector", typeof (FolderSelectorSample));
			AddSample (w, "FontSelector", typeof(FontSelectorSample));
			AddSample (w, "ComboBox", typeof(ComboBoxes));
			AddSample (w, "DatePicker", typeof(DatePickerSample));
//			AddSample (null, "Designer", typeof(Designer));
			AddSample (w, "Expander", typeof (ExpanderSample));
			AddSample (w, "Progress bars", typeof(ProgressBarSample));
			AddSample (w, "Frames", typeof(Frames));
			var images = AddSample (w, "Images", typeof(Images));
			AddSample (images, "Themed", typeof(ThemedImages));
			AddSample (w, "Labels", typeof(Labels));
			AddSample (w, "ListBox", typeof(ListBoxSample));
			AddSample (w, "LinkLabels", typeof(LinkLabels));
			var listView = AddSample (w, "ListView", typeof(ListView1));
			AddSample (listView, "Editable Checkboxes", typeof(ListView2));
			AddSample (listView, "Cell Bounds", typeof(ListViewCellBounds));
			AddSample (listView, "Editable Entries", typeof (ListViewEntries));
			AddSample (listView, "ComboBox", typeof (ListViewCombos));
			AddSample (w, "Markdown", typeof (MarkDownSample));
			AddSample (w, "Menu", typeof(MenuSamples));
			AddSample (w, "Mnemonics", typeof (Mnemonics));
			AddSample (w, "Notebook", typeof(NotebookSample));
			AddSample (w, "Paneds", typeof(PanedViews));
			AddSample (w, "Popover", typeof(PopoverSample));
			AddSample (w, "RadioButton", typeof (RadioButtonSample));
			AddSample (w, "SpinButton", typeof (SpinButtonSample));
			AddSample (w, "Scroll View", typeof(ScrollWindowSample));
			AddSample (w, "Scrollbar", typeof(ScrollbarSample));
			AddSample (w, "Slider", typeof (SliderSample));
			AddSample (w, "Spinners", typeof (Spinners));
			AddSample (w, "Tables", typeof (Tables));
			AddSample (w, "Text Entry", typeof (TextEntries));
			AddSample (w, "Password Entry", typeof (PasswordEntries));
			var treeview = AddSample (w, "TreeView", typeof(TreeViews));
			AddSample (treeview, "Cell Bounds", typeof(TreeViewCellBounds));
			AddSample (w, "WebView", typeof(WebViewSample));

			var n = AddSample (null, "Drawing", null);
			AddSample (n, "Canvas with Widget (Linear)", typeof (CanvasWithWidget_Linear));
			AddSample (n, "Canvas with Widget (Radial)", typeof (CanvasWithWidget_Radial));
			AddSample (n, "Chart", typeof (ChartSample));
			AddSample (n, "Colors", typeof(ColorsSample));
			AddSample (n, "Figures", typeof(DrawingFigures));
			AddSample (n, "Transformations", typeof(DrawingTransforms));
			AddSample (n, "Images and Patterns", typeof(DrawingPatternsAndImages));
			AddSample (n, "Text", typeof(DrawingText));
			AddSample (n, "Partial Images", typeof (PartialImages));
			AddSample (n, "Custom Drawn Image", typeof (ImageScaling));
			AddSample (n, "9-patch Image", typeof (Image9Patch));
			AddSample (n, "Widget Rendering", typeof (WidgetRendering));
			AddSample (n, "Text Input", typeof (TextInput));
			var wf = AddSample (null, "Widget Features", null);
			AddSample (wf, "Drag & Drop", typeof(DragDrop));
			AddSample (wf, "Focus", typeof(WidgetFocus));
			AddSample (wf, "Widget Events", typeof(WidgetEvents));
			AddSample (wf, "Opacity", typeof(OpacitySample));
			AddSample (wf, "Tooltips", typeof(Tooltips));
			AddSample (wf, "Cursors", typeof(MouseCursors));

			var windows = AddSample (null, "Windows", typeof(Windows));
			AddSample (windows, "Message Dialogs", typeof(MessageDialogs));
			AddSample (windows, "Popup Windows", typeof(PopupWindows));
			
			AddSample (null, "Screens", typeof (ScreensSample));

			AddSample (null, "Multithreading", typeof (MultithreadingSample));

			samplesTree.DataSource = store;
			
			box.Panel1.Content = samplesTree;
			
			sampleBox = new VBox ();
			title = new Label ("Sample:");
			sampleBox.PackStart (title);
			
			box.Panel2.Content = sampleBox;
			box.Panel2.Resize = true;
			box.Position = 160;
			
			Content = box;
			
			samplesTree.SelectionChanged += HandleSamplesTreeSelectionChanged;

			CloseRequested += HandleCloseRequested;
		}

		void HandleCloseRequested (object sender, CloseRequestedEventArgs args)
		{
			args.AllowClose = MessageDialog.Confirm ("Samples will be closed", Command.Ok);
			if (args.AllowClose)
				Application.Exit ();
		}
		
		protected override void Dispose (bool disposing)
		{
			base.Dispose (disposing);
			
			if (statusIcon != null) {
				statusIcon.Dispose ();
			}
		}

		void HandleSamplesTreeSelectionChanged (object sender, EventArgs e)
		{
			if (samplesTree.SelectedRow != null) {
				if (currentSample != null)
					sampleBox.Remove (currentSample);
				Sample s = store.GetNavigatorAt (samplesTree.SelectedRow).GetValue (widgetCol);
				if (s.Type != null) {
					if (s.Widget == null)
						s.Widget = (Widget)Activator.CreateInstance (s.Type);
					sampleBox.PackStart (s.Widget, true);
				}

			//	Console.WriteLine (System.Xaml.XamlServices.Save (s.Widget));
				currentSample = s.Widget;
				Dump (currentSample, 0);
			}
		}
		
		void Dump (IWidgetSurface w, int ind)
		{
			if (w == null)
				return;
			var s = w.GetPreferredSize ();
			Console.WriteLine (new string (' ', ind * 2) + " " + w.GetType ().Name + " " + s.Width + " " + s.Height);
			foreach (var c in w.Children)
				Dump (c, ind + 1);
		}
		
		TreePosition AddSample (TreePosition pos, string name, Type sampleType)
		{
			//if (page != null)
			//	page.Margin.SetAll (5);
			return store.AddNode (pos).SetValue (nameCol, name).SetValue (iconCol, icon).SetValue (widgetCol, new Sample (sampleType)).CurrentPosition;
		}
	}
	
	class Sample
	{
		public Sample (Type type)
		{
			Type = type;
		}

		public Type Type;
		public Widget Widget;
	}
}