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

Control.cs « Gtk « System.Windows.Forms « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6f3354bfff805f69391aa221d656922bdf9347af (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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
//
// System.Windows.Forms.Form
//
// Author:
//   Miguel de Icaza (miguel@ximian.com)
//   Rachel Hestilow (hestilow@ximian.com)
//
// (C) 2002 Ximian, Inc
//

using System;
using System.Drawing;
using Gtk;
using GtkSharp;
using System.ComponentModel;
using System.Collections;

namespace System.Windows.Forms {
	public class Control : Component {
		internal Widget widget;
		Control parent;
		string text;
		int left, top, width, height;
		ControlCollection controls = CreateControlsInstance ();
		Point location = new Point (0, 0);
		Gtk.Layout layout = null;
		AnchorStyles anchor = AnchorStyles.Top|AnchorStyles.Left;
		
		static int init_me;

		public class ControlCollection : IList, ICollection, IEnumerable, ICloneable 
		{
			ArrayList list = new ArrayList ();
			Control owner;

			public ControlCollection (Control owner)
			{
				this.owner = owner;
			}

			private ControlCollection ()
			{
			}

			// ControlCollection
			public virtual void Add (Control value) {
				list.Add (value);
				owner.OnControlAdded (new ControlEventArgs (value));
			}
			public virtual void AddRange (Control[] controls) {
				list.AddRange (controls);
				foreach (Control c in controls)
					owner.OnControlAdded (new ControlEventArgs (c));
			}
			
			public bool Contains (Control value) { return list.Contains (value); }
			public int IndexOf (Control value) { return list.IndexOf (value); }
			public virtual void Remove (Control value) {
				list.Remove (value);
				owner.OnControlAdded (new ControlEventArgs (value));
			}
			public virtual Control this[int index] { get { return (Control) list[index]; } }
			public int GetChildIndex (Control child) {
				return GetChildIndex (child, true);
			}
			public int GetChildIndex (Control child, bool throwException) {
				if (throwException && !Contains (child))
					throw new Exception ();
				return list.IndexOf (child);
			}
			public int IndexOf (Control value) { return list.IndexOf (value); }
			public void SetChildIndex (Control child, int newIndex) {
				int oldIndex = GetChildIndex (child);
				if (oldIndex == newIndex)
					return;
				// is this correct behavior?
				Control other = (Control) list[newIndex];
				list[oldIndex] = other;
				list[newIndex] = child;
			}

			// IList
			public bool IsFixedSize { get { return list.IsFixedSize; } }
			public bool IsReadOnly { get { return list.IsReadOnly; } }
			public object this[int index]
			{
				get { return list[index]; }
				set { list[index] = value; }
			}
			int IList.Add (object value) { return list.Add (value); }
			public void Clear () { list.Clear (); }
			bool IList.Contains (object value) { return list.Contains (value); }
			int IList.IndexOf (object value) { return list.IndexOf (value); }
			void IList.Insert (int index, object value) { list.Insert (index, value); }
			void IList.Remove (object value) { list.Remove (value); }
			public void RemoveAt (int index) { list.RemoveAt (index); }

			// ICollection
			public int Count { get { return list.Count; } }
			public bool IsSynchronized { get { return list.IsSynchronized; } }
			public object SyncRoot { get { return list.SyncRoot; } }
			public void CopyTo (Array array, int index) { list.CopyTo (array, index); }
			
			// IEnumerable
			public IEnumerator GetEnumerator () { return list.GetEnumerator (); }

			// ICloneable
			public object Clone () {
				ControlCollection c = new ControlCollection ();
				c.list = (ArrayList) list.Clone ();
				c.owner = owner;
				return c;
			}
		}
		
		static Control ()
		{
			init_me = 1;
		}
		
		public Control () : this ("")
		{
		}

		public Control (string text) : this (null, text)
		{
		}

		public Control (Control parent, string text)
		{
			this.parent = parent;
			this.text = text;
		}

		public Control (string text, int left, int top, int width, int height)
		{
		}

		public Control (Control parent, string text, int left, int top, int width, int height)
		{
		}

		internal Widget Widget {
			get {
				if (widget == null)
					widget = CreateWidget ();
				return widget;
			}
		}
		
		internal virtual Widget CreateWidget ()
		{
			layout = new Gtk.Layout (new Gtk.Adjustment (IntPtr.Zero), new Gtk.Adjustment (IntPtr.Zero));
			layout.Show ();
			return layout;
		}

		public virtual string Text {
			get {
				return text;
			}

			set {
				text = value;
				OnTextChanged (EventArgs.Empty);
			}
		}
		
		public event EventHandler TextChanged;

		protected virtual void OnTextChanged (EventArgs e) {
			if (TextChanged != null)
			 TextChanged (this, e);
		}
		
		public void Show ()
		{
			Widget.Show ();
		}

		public void Hide ()
		{
			Widget.Hide ();
		}

		public bool Visible {
			get {
				return Widget.Visible;
			}

			set {
				Widget.Visible = value;
			}
		}
		
		public ControlCollection Controls {
			get { return controls;}
		}
		
		protected virtual ControlCollection CreateControlsInstance() {
			controls = new ControlCollection (this);
			return controls;
		}
		
		public event ControlEventHandler ControlAdded;
		public event ControlEventHandler ControlRemoved;

		internal void ControlLocationChanged (object o, EventArgs e)
		{
			Control c = (Control) o;
			Point l = c.Location;
			if (layout == null) {
				Widget w = Widget;
			}
				
			layout.Move (c.Widget, l.X, l.Y); 
		}

		protected virtual void OnControlAdded(ControlEventArgs e) {
			e.Control.Visible = true;
			
			if (ControlAdded != null)
				ControlAdded (this, e);

			Point l = e.Control.Location;
			if (layout == null) { 
				Widget w = Widget;
			}
			layout.Put (e.Control.Widget, l.X, l.Y);
			e.Control.LocationChanged += new EventHandler (ControlLocationChanged);
		}

		protected virtual void OnControlRemoved(ControlEventArgs e) {
			if (ControlRemoved != null)
				ControlRemoved (this, e);
		}

		public Point Location {
			get { return location; }
			set {
				location = value;
				OnLocationChanged (EventArgs.Empty);
			}
		}

		public event EventHandler LocationChanged;

		public virtual void OnLocationChanged (EventArgs e) {
			
			if (LocationChanged != null)
				LocationChanged (this, e);
		}

		public event EventHandler Click;

		protected virtual void OnClick (EventArgs e) {
			if (Click != null)
				Click (this, e);
		}
		
		public virtual AnchorStyles Anchor {
			get { return anchor; }
			set { anchor=value; }
    }
	}
}