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

Label.cs « System.Windows.Forms « System.Windows.Forms « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 96abdbe6951320d0a2006629d014a6d0d8d7e0d9 (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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
//
// System.Windows.Forms.Label.cs
//
// Author:
//   stubbed out by Daniel Carrera (dcarrera@math.toronto.edu)
//	  implemented for Gtk+ by Rachel Hestilow (hestilow@ximian.com)
//	Dennis Hayes (dennish@raytek.com)
//   WineLib implementation started by John Sohn (jsohn@columbus.rr.com)
//
// (C) 2002/3 Ximian, Inc
//

namespace System.Windows.Forms {
    	using System.ComponentModel;
    	using System.Drawing;
    	using System.Drawing.Text;
	
    	public class Label : Control {
    		Image background_image;
    		BorderStyle border_style;
    		bool autoSize;
    		Image image;
    		ContentAlignment image_align;
    		ImeMode default_ime_mode;
    		bool render_transparent;
    		FlatStyle flat_style;
    		int preferred_height;
    		int preferred_width;
    		bool tab_stop;
    		ContentAlignment text_align;
    		bool use_mnemonic;
    
    		public Label () : base ()
    		{
			// Defaults in the Spec
			autoSize = false;
			border_style = BorderStyle.None;
			base.TabStop = false;
			text_align = ContentAlignment.TopLeft;
			SubClassWndProc_ = true;
			SetStyle (ControlStyles.Selectable, false);
			SetStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
    		}

#region Properties
    		public virtual bool AutoSize {
    			get {
    				return autoSize;
    			}
    			set {
    				autoSize = value;
    			}
    		}
    
    		public override Image BackgroundImage {
    			get {
    				return background_image;
    			}
    			set {
    				background_image = value;
				Refresh ();
    			}
    		}
    
    		public virtual BorderStyle BorderStyle {
    			get {
    				return border_style;
    			}
    			set {
				if (border_style == value)
					return;
				
    				border_style = value;
				RecreateHandle ();
    			}
    		}
    
    
    		public FlatStyle FlatStyle {
    			get {
    				return flat_style;
    			}
    			set {
    				flat_style = value;
				Refresh ();
    			}
    		}
    
    		public Image Image {
    			get {
    				return image;
    			}
    			set {
    				image = value;
				Refresh ();
    			}
    		}
    
    		public ContentAlignment ImageAlign {
    			get {
    				return image_align;
    			}
    			set {
    				image_align = value;
    			}
    		}
    
    
    		[MonoTODO]
    		public int ImageIndex {
    			get {
    				throw new NotImplementedException ();
    			}
    			set {
					//FIXME:
			}
    		}
    
    		[MonoTODO]
    		public ImageList ImageList {
    			get {
    				throw new NotImplementedException ();
    			}
    			set {
					//FIXME:
    			}
    		}
    
    		[MonoTODO]
    		public new ImeMode ImeMode {
    			get {
    				throw new NotImplementedException ();
    			}
    			set {
					//FIXME:
				}
    		}
    
    		public virtual int PreferredHeight {
    			get {
    				return preferred_height;
    			}
    		}
    
    		public virtual int PreferredWidth {
    			get {
    				return preferred_width;
    			}
    		}
    
    		public new bool TabStop {
    			get {
    				return tab_stop;
    			}
    			set {
    				tab_stop = value;
    			}
    		}
    
 		//Compact Framework
    		public virtual ContentAlignment TextAlign {
    			get {
    				return text_align;
    			}
    			set {
    				text_align = value;
    			}
    		}
    
    		public bool UseMnemonic {
    			get {
    				return use_mnemonic;
    			}
    			set {
    				use_mnemonic = value;
    			}
    		}
		
    		protected override CreateParams CreateParams {
    			get {
				CreateParams createParams = base.CreateParams;

				createParams.ClassName = "Static";

				int bs = 0;
				if (border_style == BorderStyle.FixedSingle)
					bs |= (int) WindowStyles.WS_BORDER;
				else if (border_style == BorderStyle.Fixed3D)
					bs |= (int) WindowStyles.WS_BORDER | (int) SS_Static_Control_Types.SS_SUNKEN;
					
					
				createParams.Style = (int) (
					(int)WindowStyles.WS_CHILD | 
					(int)WindowStyles.WS_VISIBLE | 
					(int)SS_Static_Control_Types.SS_LEFT |
					(int)WindowStyles.WS_CLIPCHILDREN |
					(int)WindowStyles.WS_CLIPSIBLINGS |
					(int)SS_Static_Control_Types.SS_OWNERDRAW |
					bs);

				return createParams;
    			}
    		}
    
    		protected override Size DefaultSize {
    			get {
    				return new Size(100,23);//Correct value
    			}
    		}
    
			protected virtual bool RenderTransparent {
				get {
					return render_transparent;
				}
				set {
					//FIXME:
				}
			}
    
    		protected override ImeMode DefaultImeMode {
    			get {
				//FIXME:
				return default_ime_mode;
    			}
    		}
    
#endregion

#region Methods

    		public override string ToString()
    		{
			//FIXME: add name of lable, as well as text. would adding base.ToString work?
    			return "Label: " + base.Text;
    		}

    		[MonoTODO]
			protected override void Dispose(bool disposing){
				base.Dispose(disposing);
			}

    		[MonoTODO]
    		protected Rectangle CalcImageRenderBounds (
    			Image image, Rectangle r, ContentAlignment align)
    		{
    			throw new NotImplementedException ();
    		}
    
      		[MonoTODO]
      		protected  override AccessibleObject CreateAccessibilityInstance()
      		{
				//FIXME:
				return base.CreateAccessibilityInstance();
      		}

    		[MonoTODO]
    		protected  void DrawImage (Graphics g, Image image, 
    					   Rectangle r, ContentAlignment align)
    		{
				//FIXME:
			}
    
    		protected virtual void OnAutoSizeChanged (EventArgs e)
		{
    			if (AutoSizeChanged != null) AutoSizeChanged (this, e);
    		}
    
    		protected override void OnEnabledChanged (EventArgs e)
    		{
				//FIXME:
				base.OnEnabledChanged (e);
    		}
    
    		protected override void OnFontChanged (EventArgs e)
    		{
				//FIXME:
				base.OnFontChanged (e);
    		}
    
    		protected override void OnPaint (PaintEventArgs e)
    		{
				Rectangle paintBounds = ClientRectangle;
				Bitmap bmp = new Bitmap( paintBounds.Width, paintBounds.Height,e.Graphics);
				Graphics paintOn = Graphics.FromImage(bmp);
			
				Color controlColor = BackColor; //SystemColors.Control;
				Color textColor = ForeColor; // SystemColors.ControlText;
				if (BackColor == System.Drawing.Color.Red) {
					Color t = System.Drawing.Color.Red;
				}
			
				Rectangle rc = paintBounds;
				Rectangle rcImageClip = paintBounds;
				rcImageClip.Inflate(-2,-2);

				SolidBrush sb = new SolidBrush( controlColor);
				paintOn.FillRectangle(sb, rc);
				sb.Dispose();
				
				// Do not place Text and Images on the borders 
				paintOn.Clip = new Region(rcImageClip);
				if(Image != null) {
					int X = rc.X;
					int Y = rc.Y;

					if( ImageAlign == ContentAlignment.TopCenter ||
						ImageAlign == ContentAlignment.MiddleCenter ||
						ImageAlign == ContentAlignment.BottomCenter) {
						X += (rc.Width - Image.Width) / 2;
					}
					else if(ImageAlign == ContentAlignment.TopRight ||
						ImageAlign == ContentAlignment.MiddleRight||
						ImageAlign == ContentAlignment.BottomRight) {
						X += (rc.Width - Image.Width);
					}

					if( ImageAlign == ContentAlignment.BottomCenter ||
						ImageAlign == ContentAlignment.BottomLeft ||
						ImageAlign == ContentAlignment.BottomRight) {
						Y += rc.Height - Image.Height;
					}
					else if(ImageAlign == ContentAlignment.MiddleCenter ||
							ImageAlign == ContentAlignment.MiddleLeft ||
							ImageAlign == ContentAlignment.MiddleRight) {
						Y += (rc.Height - Image.Height) / 2;
					}
					paintOn.DrawImage(Image, X, Y, Image.Width, Image.Height);
				}

				if( Enabled) {
					SolidBrush  brush;

					brush=new SolidBrush(textColor);
					paintOn.DrawString(Text, Font, brush, rc, Win32.ContentAlignment2StringFormat(TextAlign, HotkeyPrefix.Show));
					brush.Dispose();
				}
				else {
					ControlPaint.DrawStringDisabled(paintOn, Text, Font, textColor, rc, Win32.ContentAlignment2StringFormat(TextAlign, HotkeyPrefix.Hide));
				}

				e.Graphics.DrawImage(bmp, 0, 0, paintBounds.Width, paintBounds.Height);
				paintOn.Dispose ();
				bmp.Dispose();
			}
    
  			//Compact Framework
    		protected override void OnParentChanged (EventArgs e)
    		{
    			base.OnParentChanged (e);
    		}
    
    		protected virtual void OnTextAlignChanged (EventArgs e) {
    			if (TextAlignChanged != null) TextAlignChanged (this, e);
    		}
    
 			//Compact Framework
    		protected override void OnTextChanged (EventArgs e) {
				base.OnTextChanged (e);
				Invalidate ();
				Refresh ();
    		}
    
    		protected override void OnVisibleChanged (EventArgs e)
    		{
    			base.OnVisibleChanged (e);
    		}
    
    		protected override bool ProcessMnemonic(char charCode)
    		{
    			return base.ProcessMnemonic (charCode);
    		}
    
//    		[MonoTODO]
//    		protected new ContentAlignment RtlTranslateAlignment (
//    			ContentAlignment alignment)
//    		{
//    			throw new NotImplementedException ();
//    		}
//    
//    		[MonoTODO]
//    		protected new HorizontalAlignment RtlTranslateAlignment (
//    			HorizontalAlignment alignment)
//    		{
//    			throw new NotImplementedException ();
//    		}
//    		
//    		[MonoTODO]
//    		protected new LeftRightAlignment RtlTranslateAlignment (
//    			LeftRightAlignment align)
//    		{
//    			throw new NotImplementedException ();
//    		}
//    
//    		[MonoTODO]
//    		protected new virtual void Select (bool directed, bool forward)
//    		{
//				//FIXME:
//			}
    
    		protected override void SetBoundsCore (
    			int x, int y, int width, int height,
    			BoundsSpecified specified)
    		{
    			base.SetBoundsCore (x, y, width, height, specified);
    		}
    
//    		protected new void UpdateBounds()
//    		{
//    			base.UpdateBounds ();
//    		}
//    
//    		protected new void UpdateBounds (int x, int y,
//    					     int width, int height)
//    		{
//    			base.UpdateBounds (x, y, width, height);
//    		}
//    
//    
//    		protected new void UpdateBounds (int x, int y, int width,
//						 int height, int clientWidth,
//						 int clientHeight)
//		{
//    			base.UpdateBounds (x, y, width, height, clientWidth, clientHeight);
//		}

    		protected override void WndProc(ref Message m)
    		{
				switch ((Msg) m.Msg) {
					case Msg.WM_DRAWITEM: {
						m.Result = (IntPtr)1;
					}
						break;
					default:
						base.WndProc (ref m);
						break;
				}
    		}
#endregion

#region Events
    		public event EventHandler AutoSizeChanged;
   
    		public event EventHandler TextAlignChanged;
#endregion
		
    	}
    }