* Form.cs (set_TransparencyKey): only call SetWindowTransparency
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Form.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2004-2006 Novell, Inc.
21 //
22 // Authors:
23 //      Peter Bartok    pbartok@novell.com
24 //
25
26 // NOT COMPLETE
27
28 using System;
29 using System.Drawing;
30 using System.ComponentModel;
31 using System.ComponentModel.Design;
32 using System.ComponentModel.Design.Serialization;
33 using System.Collections;
34 using System.Runtime.InteropServices;
35 using System.Threading;
36
37 namespace System.Windows.Forms {
38         [DesignerCategory("Form")]
39         [DesignTimeVisible(false)]
40         [Designer("System.Windows.Forms.Design.FormDocumentDesigner, " + Consts.AssemblySystem_Design, typeof(IRootDesigner))]
41         [DefaultEvent("Load")]
42         [ToolboxItem(false)]
43         public class Form : ContainerControl {
44                 #region Local Variables
45                 internal bool                   closing;
46                 FormBorderStyle                 form_border_style;
47                 private bool                    autoscale;
48                 private Size                    clientsize_set;
49                 private Size                    autoscale_base_size;
50                 private bool                    allow_transparency;
51                 private static Icon             default_icon;
52                 internal bool                   is_modal;
53                 internal FormWindowState        window_state;
54                 private bool                    control_box;
55                 private bool                    minimize_box;
56                 private bool                    maximize_box;
57                 private bool                    help_button;
58                 private bool                    show_in_taskbar;
59                 private bool                    topmost;
60                 private IButtonControl          accept_button;
61                 private IButtonControl          cancel_button;
62                 private DialogResult            dialog_result;
63                 private FormStartPosition       start_position;
64                 private Form                    owner;
65                 private Form.ControlCollection  owned_forms;
66                 private MdiClient               mdi_container;
67                 internal InternalWindowManager  window_manager;
68                 private Form                    mdi_parent;
69                 private bool                    key_preview;
70                 private MainMenu                menu;
71                 private Icon                    icon;
72                 private Size                    maximum_size;
73                 private Size                    minimum_size;
74                 private SizeGripStyle           size_grip_style;
75                 private Rectangle               maximized_bounds;
76                 private Rectangle               default_maximized_bounds;
77                 private double                  opacity;
78                 internal ApplicationContext     context;
79                 Color                           transparency_key;
80                 internal MenuTracker            active_tracker;
81                 private bool                    is_loaded;
82
83                 #endregion      // Local Variables
84
85                 #region Private & Internal Methods
86                 static Form ()
87                 {
88                         default_icon = Locale.GetResource("mono.ico") as Icon;
89                 }
90
91                 // warning: this is only hooked up when an mdi container is created.
92                 private void ControlAddedHandler (object sender, ControlEventArgs e)
93                 {
94                         if (mdi_container != null) {
95                                 mdi_container.SendToBack ();
96                         }
97                 }
98
99                 private void SelectActiveControl ()
100                 {
101                         if (this.IsMdiContainer)
102                                 return;
103                                 
104                         if (this.ActiveControl == null) {
105                                 bool visible;
106
107                                 // This visible hack is to work around CanSelect always being false if one of the parents
108                                 // is not visible; and we by default create Form invisible...
109                                 visible = this.is_visible;
110                                 this.is_visible = true;
111
112                                 if (SelectNextControl (this, true, true, true, true) == false) {
113                                         Select (this);
114                                 }
115
116                                 this.is_visible = visible;
117                         } else {
118                                 Select (ActiveControl);
119                         }
120                 }
121                 #endregion      // Private & Internal Methods
122
123                 #region Public Classes
124                 public new class ControlCollection : Control.ControlCollection {
125                         Form    form_owner;
126
127                         public ControlCollection(Form owner) : base(owner) {
128                                 this.form_owner = owner;
129                         }
130
131                         public override void Add(Control value) {
132                                 if (Contains (value))
133                                         return;
134                                 AddToList (value);
135                                 ((Form)value).owner=(Form)owner;
136                         }
137
138                         public override void Remove(Control value) {
139                                 ((Form)value).owner = null;
140                                 base.Remove (value);
141                         }
142                 }
143                 #endregion      // Public Classes
144
145                 #region Public Constructor & Destructor
146                 public Form ()
147                 {
148                         SizeF current_scale = GetAutoScaleSize (DeviceContext, Font);
149
150                         autoscale = true;
151                         autoscale_base_size = new Size ((int)current_scale.Width, (int) current_scale.Height);
152                         allow_transparency = false;
153                         closing = false;
154                         is_modal = false;
155                         dialog_result = DialogResult.None;
156                         start_position = FormStartPosition.WindowsDefaultLocation;
157                         form_border_style = FormBorderStyle.Sizable;
158                         window_state = FormWindowState.Normal;
159                         key_preview = false;
160                         opacity = 1D;
161                         menu = null;
162                         icon = default_icon;
163                         minimum_size = Size.Empty;
164                         maximum_size = Size.Empty;
165                         clientsize_set = Size.Empty;
166                         control_box = true;
167                         minimize_box = true;
168                         maximize_box = true;
169                         help_button = false;
170                         show_in_taskbar = true;
171                         ime_mode = ImeMode.NoControl;
172                         is_visible = false;
173                         is_toplevel = true;
174                         size_grip_style = SizeGripStyle.Auto;
175                         maximized_bounds = Rectangle.Empty;
176                         default_maximized_bounds = Rectangle.Empty;
177                         owned_forms = new Form.ControlCollection(this);
178                         transparency_key = Color.Empty;
179
180                         // FIXME: this should disappear just as soon as the handle creation is done in the right place (here is too soon()
181                         UpdateBounds();
182
183                 }
184                 #endregion      // Public Constructor & Destructor
185
186                 #region Public Static Properties
187
188                 public static Form ActiveForm {
189                         get {
190                                 Control active;
191
192                                 active = FromHandle(XplatUI.GetActive());
193
194                                 if (active != null) {
195                                         if ( !(active is Form)) {
196                                                 Control parent;
197
198                                                 parent = active.Parent;
199                                                 while (parent != null) {
200                                                         if (parent is Form) {
201                                                                 return (Form)parent;
202                                                         }
203                                                         parent = parent.Parent;
204                                                 }
205                                         } else {
206                                                 return (Form)active;
207                                         }
208                                 }
209                                 return null;
210                         }
211                 }
212
213                 #endregion      // Public Static Properties
214
215                 #region Public Instance Properties
216                 [DefaultValue(null)]
217                 public IButtonControl AcceptButton {
218                         get {
219                                 return accept_button;
220                         }
221
222                         set {
223                                 accept_button = value;
224                                 CheckAcceptButton();
225                         }
226                 }
227
228                 [Browsable(false)]
229                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
230                 public bool AllowTransparency {
231                         get {
232                                 return allow_transparency;
233                         }
234
235                         set {
236                                 if (value == allow_transparency) {
237                                         return;
238                                 }
239
240                                 allow_transparency = value;
241
242                                 if (value) {
243                                         if (IsHandleCreated) {
244                                                 if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
245                                                         XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
246                                                 }
247                                         } else {
248                                                 UpdateStyles(); // Remove the WS_EX_LAYERED style
249                                         }
250                                 }
251                         }
252                 }
253
254                 [DefaultValue(true)]
255                 [MWFCategory("Layout")]
256                 public bool AutoScale {
257                         get {
258                                 return autoscale;
259                         }
260
261                         set {
262                                 autoscale = value;
263                         }
264                 }
265
266                 [Localizable(true)]
267                 [Browsable(false)]
268                 [EditorBrowsable(EditorBrowsableState.Advanced)]
269                 public virtual Size AutoScaleBaseSize {
270                         get {
271                                 return autoscale_base_size;
272                         }
273
274                         set {
275                                 autoscale_base_size = value;
276                         }
277                 }
278
279                 [Localizable(true)]
280                 public override bool AutoScroll {
281                         get {
282                                 return base.AutoScroll;
283                         }
284                         set {
285                                 base.AutoScroll = value;
286                         }
287                 }
288
289                 public override Color BackColor {
290                         get {
291                                 /* we don't let parents override our
292                                  default background color for forms.
293                                  this fixes the default color for mdi
294                                  children. */
295                                 if (background_color.IsEmpty)
296                                         return DefaultBackColor;
297                                 else
298                                         return background_color;
299                         }
300                         set {
301                                 base.BackColor = value;
302                         }
303                 }
304
305                 [DefaultValue(null)]
306                 public IButtonControl CancelButton {
307                         get {
308                                 return cancel_button;
309                         }
310
311                         set {
312                                 cancel_button = value;
313                         }
314                 }
315
316                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
317                 [Localizable(true)]
318                 public Size ClientSize {
319                         get {
320                                 return base.ClientSize;
321                         }
322
323                         set {
324                                 base.ClientSize = value;
325                         }
326                 }
327
328                 [DefaultValue(true)]
329                 [MWFCategory("Window Style")]
330                 public bool ControlBox {
331                         get {
332                                 return control_box;
333                         }
334
335                         set {
336                                 if (control_box != value) {
337                                         control_box = value;
338                                         UpdateStyles();
339                                 }
340                         }
341                 }
342
343                 [Browsable(false)]
344                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
345                 public Rectangle DesktopBounds {
346                         get {
347                                 return new Rectangle(Location, Size);
348                         }
349
350                         set {
351                                 Bounds = value;
352                         }
353                 }
354
355                 [Browsable(false)]
356                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
357                 public Point DesktopLocation {
358                         get {
359                                 return Location;
360                         }
361
362                         set {
363                                 Location = value;
364                         }
365                 }
366
367                 [Browsable(false)]
368                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
369                 public DialogResult DialogResult {
370                         get {
371                                 return dialog_result;
372                         }
373
374                         set {
375                                 if (value < DialogResult.None || value > DialogResult.No)
376                                         throw new InvalidEnumArgumentException ("value", (int) value, 
377                                                         typeof (DialogResult));
378
379                                 dialog_result = value;
380                                 closing = (dialog_result != DialogResult.None && is_modal);
381                         }
382                 }
383
384                 [DefaultValue(FormBorderStyle.Sizable)]
385                 [DispId(-504)]
386                 [MWFCategory("Appearance")]
387                 public FormBorderStyle FormBorderStyle {
388                         get {
389                                 return form_border_style;
390                         }
391                         set {
392                                 form_border_style = value;
393
394                                 if (window_manager == null) {
395                                         if (IsHandleCreated) {
396                                                 XplatUI.SetBorderStyle(window.Handle, form_border_style);
397                                         }
398                                 } else {
399                                         window_manager.UpdateBorderStyle (value);
400                                 }
401
402                                 UpdateStyles();
403                         }
404                 }
405
406                 [DefaultValue(false)]
407                 [MWFCategory("Window Style")]
408                 public bool HelpButton {
409                         get {
410                                 return help_button;
411                         }
412
413                         set {
414                                 if (help_button != value) {
415                                         help_button = value;
416                                         UpdateStyles();
417                                 }
418                         }
419                 }
420
421                 [Localizable(true)]
422                 [AmbientValue(null)]
423                 [MWFCategory("Window Style")]
424                 public Icon Icon {
425                         get {
426                                 return icon;
427                         }
428
429                         set {
430                                 if (icon != value) {
431                                         icon = value;
432
433                                         if (IsHandleCreated) {
434                                                 XplatUI.SetIcon(Handle, icon == null ? default_icon : icon);
435                                         }
436                                 }
437                         }
438                 }
439
440                 [Browsable(false)]
441                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
442                 public bool IsMdiChild {
443                         get {
444                                 return mdi_parent != null;
445                         }
446                 }
447
448                 [DefaultValue(false)]
449                 [MWFCategory("Window Style")]
450                 public bool IsMdiContainer {
451                         get {
452                                 return mdi_container != null;
453                         }
454
455                         set {
456                                 if (value && mdi_container == null) {
457                                         mdi_container = new MdiClient ();
458                                         Controls.Add(mdi_container);
459                                         ControlAdded += new ControlEventHandler (ControlAddedHandler);
460                                         mdi_container.SendToBack ();
461                                 } else if (!value && mdi_container != null) {
462                                         Controls.Remove(mdi_container);
463                                         mdi_container = null;
464                                 }
465                         }
466                 }
467
468                 [Browsable(false)]
469                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
470                 public Form ActiveMdiChild {
471                         get {
472                                 if (!IsMdiContainer)
473                                         return null;
474                                 return (Form) mdi_container.ActiveMdiChild;
475                         }
476                 }
477
478                 [Browsable(false)]
479                 [EditorBrowsable(EditorBrowsableState.Advanced)]
480                 public bool IsRestrictedWindow {
481                         get {
482                                 return false;
483                         }
484                 }
485
486                 [DefaultValue(false)]
487                 public bool KeyPreview {
488                         get {
489                                 return key_preview;
490                         }
491
492                         set {
493                                 key_preview = value;
494                         }
495                 }
496
497                 [DefaultValue(true)]
498                 [MWFCategory("Window Style")]
499                 public bool MaximizeBox {
500                         get {
501                                 return maximize_box;
502                         }
503                         set {
504                                 if (maximize_box != value) {
505                                         maximize_box = value;
506                                         if (IsHandleCreated) {
507                                                 RecreateHandle();
508                                         }
509                                         UpdateStyles();
510                                 }
511                         }
512                 }
513
514                 [DefaultValue("{Width=0, Height=0}")]
515                 [Localizable(true)]
516                 [RefreshProperties(RefreshProperties.Repaint)]
517                 [MWFCategory("Layout")]
518                 public Size MaximumSize {
519                         get {
520                                 return maximum_size;
521                         }
522
523                         set {
524                                 if (maximum_size != value) {
525                                         maximum_size = value;
526                                         OnMaximumSizeChanged(EventArgs.Empty);
527                                         if (IsHandleCreated) {
528                                                 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
529                                         }
530                                 }
531                         }
532                 }
533
534                 [Browsable(false)]
535                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
536                 public Form[] MdiChildren {
537                         get {
538                                 if (mdi_container != null)
539                                         return mdi_container.MdiChildren;
540                                 else
541                                         return new Form[0];
542                         }
543                 }
544
545                 [Browsable(false)]
546                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
547                 public Form MdiParent {
548                         get {
549                                 return mdi_parent;
550                         }
551
552                         set {
553                                 if (value != null && !value.IsMdiContainer)
554                                         throw new ArgumentException ();
555
556                                 if (mdi_parent != null) {
557                                         mdi_parent.MdiContainer.original_order.Remove (this);
558                                         mdi_parent.MdiContainer.Controls.Remove (this);
559                                 }
560
561                                 if (value != null) {
562                                         mdi_parent = value;
563                                         window_manager = new MdiWindowManager (this,
564                                                         mdi_parent.MdiContainer);
565                                         mdi_parent.MdiContainer.original_order.Add (this);
566                                         mdi_parent.MdiContainer.Controls.Add (this);
567
568                                         RecreateHandle ();
569
570                                 } else if (mdi_parent != null) {
571                                         mdi_parent = null;
572
573                                         // Create a new window manager
574                                         window_manager = null;
575                                         FormBorderStyle = form_border_style;
576
577                                         RecreateHandle ();
578                                 }
579                         }
580                 }
581
582                 internal MenuTracker ActiveTracker {
583                         get { return active_tracker; }
584                         set {
585                                 if (value == active_tracker)
586                                         return;
587
588                                 Capture = value != null;
589                                 active_tracker = value;
590                         }
591                 }
592
593                 internal MdiClient MdiContainer {
594                         get { return mdi_container; }
595                 }
596
597                 internal InternalWindowManager WindowManager {
598                         get { return window_manager; }
599                 }
600
601                 [DefaultValue(null)]
602                 [MWFCategory("Window Style")]
603                 public MainMenu Menu {
604                         get {
605                                 return menu;
606                         }
607
608                         set {
609                                 if (menu != value) {
610                                         menu = value;
611
612                                         if (menu != null && !IsMdiChild) {
613                                                 menu.SetForm (this);
614
615                                                 if (IsHandleCreated) {
616                                                         XplatUI.SetMenu (window.Handle, menu);
617                                                 }
618
619                                                 if (clientsize_set != Size.Empty) {
620                                                         SetClientSizeCore(clientsize_set.Width, clientsize_set.Height);
621                                                 } else {
622                                                         UpdateBounds (bounds.X, bounds.Y, bounds.Width, bounds.Height, ClientSize.Width, ClientSize.Height - 
623                                                                 ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu, ClientSize.Width));
624                                                 }
625                                         } else
626                                                 UpdateBounds ();
627                                 }
628                         }
629                 }
630
631                 [Browsable(false)]
632                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
633                 [EditorBrowsable(EditorBrowsableState.Advanced)]
634                 public MainMenu MergedMenu {
635                         get {
636                                 if (!IsMdiChild || window_manager == null)
637                                         return null;
638                                 return ((MdiWindowManager) window_manager).MergedMenu;
639                         }
640                 }
641
642                 // This is the menu in display and being used because of merging this can
643                 // be different then the menu that is actually assosciated with the form
644                 internal MainMenu ActiveMenu {
645                         get {
646                                 if (IsMdiChild)
647                                         return null;
648
649                                 if (IsMdiContainer && mdi_container.Controls.Count > 0 &&
650                                                 ((Form) mdi_container.Controls [0]).WindowState == FormWindowState.Maximized) {
651                                         MdiWindowManager wm = (MdiWindowManager) ((Form) mdi_container.Controls [0]).WindowManager;
652                                         return wm.MaximizedMenu;
653                                 }
654
655                                 Form amc = ActiveMdiChild;
656                                 if (amc == null || amc.Menu == null)
657                                         return menu;
658                                 return amc.MergedMenu;
659                         }
660                 }
661
662                 internal MdiWindowManager ActiveMaximizedMdiChild {
663                         get {
664                                 Form child = ActiveMdiChild;
665                                 if (child == null)
666                                         return null;
667                                 if (child.WindowManager == null || child.window_state != FormWindowState.Maximized)
668                                         return null;
669                                 return (MdiWindowManager) child.WindowManager;
670                         }
671                 }
672
673                 [DefaultValue(true)]
674                 [MWFCategory("Window Style")]
675                 public bool MinimizeBox {
676                         get {
677                                 return minimize_box;
678                         }
679                         set {
680                                 if (minimize_box != value) {
681                                         minimize_box = value;
682                                         if (IsHandleCreated) {
683                                                 RecreateHandle();
684                                         }
685                                         UpdateStyles();
686                                 }
687                         }
688                 }
689
690                 [DefaultValue("{Width=0, Height=0}")]
691                 [Localizable(true)]
692                 [RefreshProperties(RefreshProperties.Repaint)]
693                 [MWFCategory("Layout")]
694                 public Size MinimumSize {
695                         get {
696                                 return minimum_size;
697                         }
698
699                         set {
700                                 if (minimum_size != value) {
701                                         minimum_size = value;
702
703                                         if ((Size.Width < value.Width) || (Size.Height < value.Height)) {
704                                                 Size = new Size(Math.Max(Size.Width, value.Width), Math.Max(Size.Height, value.Height));
705                                         }
706   
707
708                                         OnMinimumSizeChanged(EventArgs.Empty);
709                                         if (IsHandleCreated) {
710                                                 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
711                                         }
712                                 }
713                         }
714                 }
715
716                 [Browsable(false)]
717                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
718                 public bool Modal  {
719                         get {
720                                 return is_modal;
721                         }
722                 }
723
724                 [DefaultValue(1D)]
725                 [TypeConverter(typeof(OpacityConverter))]
726                 [MWFCategory("Window Style")]
727                 public double Opacity {
728                         get {
729                                 if (IsHandleCreated) {
730                                         if ((XplatUI.SupportsTransparency () & TransparencySupport.Get) != 0)
731                                                 return XplatUI.GetWindowTransparency (Handle);
732                                 }
733
734                                 return opacity;
735                         }
736
737                         set {
738                                 opacity = value;
739
740                                 AllowTransparency = true;
741
742                                 if (IsHandleCreated) {
743                                         UpdateStyles();
744                                         if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
745                                                 XplatUI.SetWindowTransparency(Handle, opacity, TransparencyKey);
746                                 }
747                         }
748                 }
749                         
750
751                 [Browsable(false)]
752                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
753                 public Form[] OwnedForms {
754                         get {
755                                 Form[] form_list;
756
757                                 form_list = new Form[owned_forms.Count];
758
759                                 for (int i=0; i<owned_forms.Count; i++) {
760                                         form_list[i] = (Form)owned_forms[i];
761                                 }
762
763                                 return form_list;
764                         }
765                 }
766
767                 [Browsable(false)]
768                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
769                 public Form Owner {
770                         get {
771                                 return owner;
772                         }
773
774                         set {
775                                 if (owner != value) {
776                                         if (owner != null) {
777                                                 owner.RemoveOwnedForm(this);
778                                         }
779                                         owner = value;
780                                         if (owner != null)
781                                                 owner.AddOwnedForm(this);
782                                         if (IsHandleCreated) {
783                                                 if (owner != null && owner.IsHandleCreated) {
784                                                         XplatUI.SetTopmost(this.window.Handle, owner.window.Handle, true);
785                                                 } else {
786                                                         XplatUI.SetTopmost(this.window.Handle, IntPtr.Zero, false);
787                                                 }
788                                         }
789                                 }
790                         }
791                 }
792
793                 [DefaultValue(true)]
794                 [MWFCategory("Window Style")]
795                 public bool ShowInTaskbar {
796                         get {
797                                 return show_in_taskbar;
798                         }
799                         set {
800                                 if (show_in_taskbar != value) {
801                                         show_in_taskbar = value;
802                                         if (IsHandleCreated) {
803                                                 RecreateHandle();
804                                         }
805                                         UpdateStyles();
806                                 }
807                         }
808                 }
809
810                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
811                 [Localizable(false)]
812                 public Size Size {
813                         get {
814                                 return base.Size;
815                         }
816
817                         set {
818                                 base.Size = value;
819                         }
820                 }
821
822                 [MonoTODO("Trigger something when GripStyle is set")]
823                 [DefaultValue(SizeGripStyle.Auto)]
824                 [MWFCategory("Window Style")]
825                 public SizeGripStyle SizeGripStyle {
826                         get {
827                                 return size_grip_style;
828                         }
829
830                         set {
831                                 size_grip_style = value;
832                         }
833                 }
834
835                 [DefaultValue(FormStartPosition.WindowsDefaultLocation)]
836                 [Localizable(true)]
837                 [MWFCategory("Layout")]
838                 public FormStartPosition StartPosition {
839                         get {
840                                 return start_position;
841                         }
842
843                         set {
844                                 if (start_position == FormStartPosition.WindowsDefaultLocation) {               // Only do this if it's not set yet
845                                         start_position = value;
846                                         if (IsHandleCreated) {
847                                                 switch(start_position) {
848                                                         case FormStartPosition.CenterParent: {
849                                                                 CenterToParent();
850                                                                 break;
851                                                         }
852
853                                                         case FormStartPosition.CenterScreen: {
854                                                                 CenterToScreen();
855                                                                 break;
856                                                         }
857
858                                                         case FormStartPosition.Manual: {
859                                                                 Left = CreateParams.X;
860                                                                 Top = CreateParams.Y;
861                                                                 break;
862                                                         }
863
864                                                         default: {
865                                                                 break;
866                                                         }
867                                                 }
868                                         }
869                                 }
870                         }
871                 }
872
873                 [Browsable(false)]
874                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
875                 [EditorBrowsable(EditorBrowsableState.Never)]
876                 public int TabIndex {
877                         get {
878                                 return base.TabIndex;
879                         }
880
881                         set {
882                                 base.TabIndex = value;
883                         }
884                 }
885
886                 [Browsable(false)]
887                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
888                 [EditorBrowsable(EditorBrowsableState.Advanced)]
889                 public bool TopLevel {
890                         get {
891                                 return GetTopLevel();
892                         }
893
894                         set {
895                                 if (!value && IsMdiContainer)
896                                         throw new ArgumentException ("MDI Container forms must be top level.");
897                                 SetTopLevel(value);
898                         }
899                 }
900
901                 [DefaultValue(false)]
902                 [MWFCategory("Window Style")]
903                 public bool TopMost {
904                         get {
905                                 return topmost;
906                         }
907
908                         set {
909                                 if (topmost != value) {
910                                         topmost = value;
911                                         if (IsHandleCreated)
912                                                 XplatUI.SetTopmost(window.Handle, owner != null ? owner.window.Handle : IntPtr.Zero, value);
913                                 }
914                         }
915                 }
916
917                 [MWFCategory("Window Style")]
918                 public Color TransparencyKey {
919                         get {
920                                 return transparency_key;
921                         }
922
923                         set {
924                                 transparency_key = value;
925
926                                 AllowTransparency = true;
927                                 UpdateStyles();
928                                 if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
929                                         XplatUI.SetWindowTransparency(Handle, Opacity, transparency_key);
930                         }
931                 }
932
933                 [DefaultValue(FormWindowState.Normal)]
934                 [MWFCategory("Layout")]
935                 public FormWindowState WindowState {
936                         get {
937                                 if (IsHandleCreated) {
938
939                                         if (window_manager != null)
940                                                 return window_manager.GetWindowState ();
941
942                                         FormWindowState new_state = XplatUI.GetWindowState(Handle);
943                                         if (new_state != (FormWindowState)(-1))
944                                                 window_state = new_state;
945                                 }
946
947                                 return window_state;
948                         }
949
950                         set {
951                                 FormWindowState old_state = window_state;
952                                 window_state = value;
953                                 if (IsHandleCreated) {
954
955                                         if (window_manager != null) {
956                                                 window_manager.SetWindowState (old_state, value);
957                                                 return;
958                                         }
959
960                                         XplatUI.SetWindowState(Handle, value);
961                                 }
962                         }
963                 }
964
965                 #endregion      // Public Instance Properties
966
967                 #region Protected Instance Properties
968                 protected override CreateParams CreateParams {
969                         get {
970                                 CreateParams cp = new CreateParams ();
971
972                                 cp.Caption = Text;
973                                 cp.ClassName = XplatUI.DefaultClassName;
974                                 cp.ClassStyle = 0;
975                                 cp.Style = 0;
976                                 cp.ExStyle = 0;
977                                 cp.Param = 0;
978                                 cp.Parent = IntPtr.Zero;
979                                 cp.menu = ActiveMenu;
980
981                                 if (start_position == FormStartPosition.WindowsDefaultLocation && !IsMdiChild) {
982                                         cp.X = unchecked((int)0x80000000);
983                                         cp.Y = unchecked((int)0x80000000);
984                                 } else {
985                                         cp.X = Left;
986                                         cp.Y = Top;
987                                 }
988                                 cp.Width = Width;
989                                 cp.Height = Height;
990
991                                 cp.Style = (int)(WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS);
992
993                                 if (IsMdiChild) {
994                                         cp.Style |= (int)(WindowStyles.WS_CHILD | WindowStyles.WS_CAPTION);
995                                         if (Parent != null) {
996                                                 cp.Parent = Parent.Handle;
997                                         }
998
999                                         cp.ExStyle |= (int) (WindowExStyles.WS_EX_WINDOWEDGE | WindowExStyles.WS_EX_MDICHILD);
1000
1001                                         switch (FormBorderStyle) {
1002                                         case FormBorderStyle.None:
1003                                                 break;
1004                                         case FormBorderStyle.FixedToolWindow:
1005                                         case FormBorderStyle.SizableToolWindow:
1006                                                 cp.ExStyle |= (int) WindowExStyles.WS_EX_TOOLWINDOW;
1007                                                 goto default;
1008                                         default:
1009                                                 cp.Style |= (int) WindowStyles.WS_OVERLAPPEDWINDOW;
1010                                                 break;
1011                                         }
1012                                         
1013                                 } else {
1014                                         switch (FormBorderStyle) {
1015                                                 case FormBorderStyle.Fixed3D: {
1016                                                         cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1017                                                         cp.ExStyle |= (int)WindowExStyles.WS_EX_CLIENTEDGE; 
1018                                                         break;
1019                                                 }
1020
1021                                                 case FormBorderStyle.FixedDialog: {
1022                                                         cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1023                                                         cp.ExStyle |= (int)(WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_CONTROLPARENT);
1024                                                         break;
1025                                                 }
1026
1027                                                 case FormBorderStyle.FixedSingle: {
1028                                                         cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1029                                                         break;
1030                                                 }
1031
1032                                                 case FormBorderStyle.FixedToolWindow: { 
1033                                                         cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1034                                                         cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
1035                                                         break;
1036                                                 }
1037
1038                                                 case FormBorderStyle.Sizable: {
1039                                                         cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION); 
1040                                                         break;
1041                                                 }
1042
1043                                                 case FormBorderStyle.SizableToolWindow: {
1044                                                         cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
1045                                                         cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
1046                                                         break;
1047                                                 }
1048
1049                                                 case FormBorderStyle.None: {
1050                                                         break;
1051                                                 }
1052                                         }
1053                                 }
1054
1055                                 switch(window_state) {
1056                                         case FormWindowState.Maximized: {
1057                                                 cp.Style |= (int)WindowStyles.WS_MAXIMIZE;
1058                                                 break;
1059                                         }
1060
1061                                         case FormWindowState.Minimized: {
1062                                                 cp.Style |= (int)WindowStyles.WS_MINIMIZE;
1063                                                 break;
1064                                         }
1065                                 }
1066
1067                                 if (TopMost) {
1068                                         cp.ExStyle |= (int) WindowExStyles.WS_EX_TOPMOST;
1069                                 }
1070
1071                                 if (ShowInTaskbar) {
1072                                         cp.ExStyle |= (int)WindowExStyles.WS_EX_APPWINDOW;
1073                                 }
1074
1075                                 if (MaximizeBox) {
1076                                         cp.Style |= (int)WindowStyles.WS_MAXIMIZEBOX;
1077                                 }
1078
1079                                 if (MinimizeBox) {
1080                                         cp.Style |= (int)WindowStyles.WS_MINIMIZEBOX;
1081                                 }
1082
1083                                 if (ControlBox) {
1084                                         cp.Style |= (int)WindowStyles.WS_SYSMENU;
1085                                 }
1086
1087                                 if (HelpButton && !MaximizeBox && !MinimizeBox) {
1088                                         cp.ExStyle |= (int)WindowExStyles.WS_EX_CONTEXTHELP;
1089                                 }
1090                                 
1091                                 if (Visible)
1092                                         cp.Style |= (int)WindowStyles.WS_VISIBLE;
1093
1094                                 if (Opacity < 1.0 || TransparencyKey != Color.Empty) {
1095                                         cp.ExStyle |= (int)WindowExStyles.WS_EX_LAYERED;
1096                                 }
1097
1098                                 if (!is_enabled && context == null) {
1099                                         cp.Style |= (int)(WindowStyles.WS_DISABLED);
1100                                 }
1101
1102                                 return cp;
1103                         }
1104                 }
1105
1106                 protected override ImeMode DefaultImeMode {
1107                         get {
1108                                 return ImeMode.NoControl;
1109                         }
1110                 }
1111
1112                 protected override Size DefaultSize {
1113                         get {
1114                                 return new Size (300, 300);
1115                         }
1116                 }
1117
1118                 protected Rectangle MaximizedBounds {
1119                         get {
1120                                 if (maximized_bounds != Rectangle.Empty) {
1121                                         return maximized_bounds;
1122                                 }
1123                                 return default_maximized_bounds;
1124                         }
1125
1126                         set {
1127                                 maximized_bounds = value;
1128                                 OnMaximizedBoundsChanged(EventArgs.Empty);
1129                                 if (IsHandleCreated) {
1130                                         XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
1131                                 }
1132                         }
1133                 }
1134                 #endregion      // Protected Instance Properties
1135
1136                 #region Public Static Methods
1137                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1138                 public static SizeF GetAutoScaleSize (Font font)
1139                 {
1140                         return XplatUI.GetAutoScaleSize(font);
1141                 }
1142
1143                 #endregion      // Public Static Methods
1144
1145                 #region Public Instance Methods
1146                 internal SizeF GetAutoScaleSize (Graphics g, Font font)
1147                 {
1148                         //
1149                         // The following constants come from the dotnet mailing list
1150                         // discussion: http://discuss.develop.com/archives/wa.exe?A2=ind0203A&L=DOTNET&P=R3655
1151                         //
1152                         // The magic number is "Its almost the length
1153                         // of the string with a smattering added in
1154                         // for compat with earlier code".
1155                         //
1156         
1157                         string magic_string = "The quick brown fox jumped over the lazy dog.";
1158                         double magic_number = 44.549996948242189;
1159                         float width = (float) (g.MeasureString (magic_string, font).Width / magic_number);
1160                         
1161                         return new SizeF (width, font.Height);
1162                 }
1163                                                  
1164                 public void Activate() {
1165                         Form    active;
1166
1167                         // The docs say activate only activates if our app is already active
1168                         if (IsHandleCreated) {
1169                                 if (IsMdiChild) {
1170                                         MdiParent.ActivateMdiChild (this);
1171                                 } else {
1172                                         active = ActiveForm;
1173                                         if ((active != null) && (this != active)) {
1174                                                 XplatUI.Activate(window.Handle);
1175                                         }
1176                                 }
1177                         }
1178                 }
1179
1180                 public void AddOwnedForm(Form ownedForm) {
1181                         if (!owned_forms.Contains(ownedForm)) {
1182                                 owned_forms.Add(ownedForm);
1183                         }
1184                         ownedForm.Owner = this;
1185                 }
1186
1187                 public void Close () {
1188                         if (IsDisposed)
1189                                 return;
1190
1191                         if (!is_visible)
1192                                 return;
1193
1194 #if NET_2_0
1195                         FormClosingEventArgs ce = new FormClosingEventArgs (CloseReason.FormOwnerClosing, false);
1196                         OnFormClosing (ce);
1197                         if (ce.Cancel)
1198                                 return;
1199 #endif
1200                         XplatUI.SendMessage(this.Handle, Msg.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
1201                 }
1202
1203                 public void LayoutMdi(MdiLayout value) {
1204                         if (mdi_container != null) {
1205                                 mdi_container.LayoutMdi(value);
1206                         }
1207                 }
1208
1209                 public void RemoveOwnedForm(Form ownedForm) {
1210                         owned_forms.Remove(ownedForm);
1211                 }
1212
1213                 public void SetDesktopBounds(int x, int y, int width, int height) {
1214                         DesktopBounds = new Rectangle(x, y, width, height);
1215                 }
1216
1217                 public void SetDesktopLocation(int x, int y) {
1218                         DesktopLocation = new Point(x, y);
1219                 }
1220
1221                 public DialogResult ShowDialog() {
1222                         return ShowDialog(this.owner);
1223                 }
1224
1225                 public DialogResult ShowDialog(IWin32Window ownerWin32) {
1226                         Rectangle       area;
1227                         bool            confined;
1228                         IntPtr          capture_window;
1229
1230                         owner = null;
1231
1232                         if (ownerWin32 != null) {
1233                                 Control c = Control.FromHandle (ownerWin32.Handle);
1234                                 if (c != null)
1235                                         owner = c.TopLevelControl as Form;
1236                         }
1237
1238                         if (owner == this) {
1239                                 throw new InvalidOperationException("The 'ownerWin32' cannot be the form being shown.");
1240                         }
1241
1242                         if (is_modal) {
1243                                 throw new InvalidOperationException("The form is already displayed as a modal dialog.");
1244                         }
1245
1246                         if (Visible) {
1247                                 throw new InvalidOperationException("Already visible forms cannot be displayed as a modal dialog. Set the Visible property to 'false' prior to calling Form.ShowDialog.");
1248                         }
1249
1250                         if (!Enabled) {
1251                                 throw new InvalidOperationException("Cannot display a disabled form as modal dialog.");
1252                         }
1253
1254                         if (TopLevelControl != this) {
1255                                 throw new InvalidOperationException("Can only display TopLevel forms as modal dialog.");
1256                         }
1257
1258                         #if broken
1259                         // Can't do this, will screw us in the modal loop
1260                         form_parent_window.Parent = this.owner;
1261                         #endif
1262
1263                         // Release any captures
1264                         XplatUI.GrabInfo(out capture_window, out confined, out area);
1265                         if (capture_window != IntPtr.Zero) {
1266                                 XplatUI.UngrabWindow(capture_window);
1267                         }
1268
1269 #if not
1270                         // Commented out; we instead let the Visible=true inside the runloop create the control
1271                         // otherwise setting DialogResult inside any of the events that are triggered by the
1272                         // create will not actually cause the form to not be displayed.
1273                         // Leaving this comment here in case there was an actual purpose to creating the control
1274                         // in here.
1275                         if (!IsHandleCreated) {
1276                                 CreateControl();
1277                         }
1278 #endif
1279
1280                         Application.RunLoop(true, new ApplicationContext(this));
1281
1282                         if (owner != null) {
1283                                 // Cannot use Activate(), it has a check for the current active window...
1284                                 XplatUI.Activate(owner.window.Handle);
1285                         }
1286
1287                         if (DialogResult != DialogResult.None) {
1288                                 return DialogResult;
1289                         }
1290                         DialogResult = DialogResult.Cancel;
1291                         return DialogResult.Cancel;
1292                 }
1293
1294                 public override string ToString() {
1295                         return GetType().FullName.ToString() + ", Text: " + Text;
1296                 }
1297                 #endregion      // Public Instance Methods
1298
1299                 #region Protected Instance Methods
1300                 protected void ActivateMdiChild(Form form) {
1301                         if (!IsMdiContainer)
1302                                 return;
1303                         mdi_container.ActivateChild (form);
1304                         OnMdiChildActivate(EventArgs.Empty);
1305                 }
1306
1307                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1308                 protected override void AdjustFormScrollbars(bool displayScrollbars) {
1309                         base.AdjustFormScrollbars (displayScrollbars);
1310                 }
1311
1312                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1313                 protected void ApplyAutoScaling()
1314                 {
1315                         SizeF current_size_f = GetAutoScaleSize (DeviceContext, Font);
1316                         Size current_size = new Size ((int) current_size_f.Width, (int) current_size_f.Height);
1317                         float   dx;
1318                         float   dy;
1319
1320                         if (current_size == autoscale_base_size)
1321                                 return;
1322
1323                         if (Environment.GetEnvironmentVariable ("MONO_MWF_SCALING") == "disable"){
1324                                 return;
1325                         }
1326                         
1327                         //
1328                         // I tried applying the Fudge height factor from:
1329                         // http://blogs.msdn.com/mharsh/archive/2004/01/25/62621.aspx
1330                         // but it makes things larger without looking better.
1331                         //
1332                         if (current_size_f.Width != AutoScaleBaseSize.Width) {
1333                                 dx = current_size_f.Width / AutoScaleBaseSize.Width + 0.08f;
1334                         } else {
1335                                 dx = 1;
1336                         }
1337
1338                         if (current_size_f.Height != AutoScaleBaseSize.Height) {
1339                                 dy = current_size_f.Height / AutoScaleBaseSize.Height + 0.08f;
1340                         } else {
1341                                 dy = 1;
1342                         }
1343
1344                         Scale (dx, dy);
1345                         
1346                         AutoScaleBaseSize = current_size;
1347                 }
1348
1349                 protected void CenterToParent() {
1350                         Control ctl;
1351                         int     w;
1352                         int     h;
1353
1354                         if (Width > 0) {
1355                                 w = Width;
1356                         } else {
1357                                 w = DefaultSize.Width;
1358                         }
1359
1360                         if (Height > 0) {
1361                                 h = Height;
1362                         } else {
1363                                 h = DefaultSize.Height;
1364                         }
1365
1366                         ctl = null;
1367                         if (parent != null) {
1368                                 ctl = parent;
1369                         } else if (owner != null) {
1370                                 ctl = owner;
1371                         }
1372
1373                         if (owner != null) {
1374                                 this.Location = new Point(ctl.Left + ctl.Width / 2 - w /2, ctl.Top + ctl.Height / 2 - h / 2);
1375                         }
1376                 }
1377
1378                 protected void CenterToScreen() {
1379                         Size    DisplaySize;
1380                         int     w;
1381                         int     h;
1382
1383                         if (Width > 0) {
1384                                 w = Width;
1385                         } else {
1386                                 w = DefaultSize.Width;
1387                         }
1388
1389                         if (Height > 0) {
1390                                 h = Height;
1391                         } else {
1392                                 h = DefaultSize.Height;
1393                         }
1394
1395                         XplatUI.GetDisplaySize(out DisplaySize);
1396                         this.Location = new Point(DisplaySize.Width / 2 - w / 2, DisplaySize.Height / 2 - h / 2);
1397                 }
1398
1399                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1400                 protected override Control.ControlCollection CreateControlsInstance() {
1401                         return base.CreateControlsInstance ();
1402                 }
1403
1404                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1405                 protected override void CreateHandle() {
1406                         base.CreateHandle ();
1407
1408                         UpdateBounds();
1409
1410                         if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
1411                                 if (allow_transparency) {
1412                                         XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
1413                                 }
1414                         }
1415
1416                         XplatUI.SetWindowMinMax(window.Handle, maximized_bounds, minimum_size, maximum_size);
1417                         if ((FormBorderStyle != FormBorderStyle.FixedDialog) && (icon != null)) {
1418                                 XplatUI.SetIcon(window.Handle, icon);
1419                         }
1420
1421                         if ((owner != null) && (owner.IsHandleCreated)) {
1422                                 XplatUI.SetTopmost(window.Handle, owner.window.Handle, true);
1423                         }
1424
1425                         for (int i = 0; i < owned_forms.Count; i++) {
1426                                 if (owned_forms[i].IsHandleCreated)
1427                                         XplatUI.SetTopmost(owned_forms[i].window.Handle, window.Handle, true);
1428                         }
1429                         
1430                         if (window_manager != null && window_state != FormWindowState.Normal) {
1431                                 window_manager.SetWindowState (FormWindowState.Normal, window_state);
1432                         }
1433
1434                 }
1435
1436                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1437                 protected override void DefWndProc(ref Message m) {
1438                         base.DefWndProc (ref m);
1439                 }
1440
1441                 protected override void Dispose(bool disposing)
1442                 {
1443                         for (int i = 0; i < owned_forms.Count; i++)
1444                                 ((Form)owned_forms[i]).Owner = null;
1445
1446                         owned_forms.Clear ();
1447                         
1448                         base.Dispose (disposing);
1449                 }
1450
1451                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1452                 protected virtual void OnActivated(EventArgs e)
1453                 {
1454                         if (is_loaded)
1455                                 SelectActiveControl ();
1456
1457                         if (Activated != null) {
1458                                 Activated(this, e);
1459                         }
1460                 }
1461
1462                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1463                 protected virtual void OnClosed(EventArgs e) {
1464                         if (Closed != null) {
1465                                 Closed(this, e);
1466                         }
1467                 }
1468
1469                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1470                 protected virtual void OnClosing(System.ComponentModel.CancelEventArgs e) {
1471                         if (Closing != null) {
1472                                 Closing(this, e);
1473                         }
1474                 }
1475
1476                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1477                 protected override void OnCreateControl() {
1478                         base.OnCreateControl ();
1479
1480                         if (menu != null) {
1481                                 XplatUI.SetMenu(window.Handle, menu);
1482                         }
1483
1484                         OnLoad(EventArgs.Empty);
1485                         
1486                         SelectActiveControl ();
1487
1488                         // Send initial location
1489                         OnLocationChanged(EventArgs.Empty);
1490
1491                         if (IsMdiContainer) {
1492                                 mdi_container.LayoutMdi (MdiLayout.Cascade);
1493                         }
1494                 }
1495
1496                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1497                 protected virtual void OnDeactivate(EventArgs e) {
1498                         if (Deactivate != null) {
1499                                 Deactivate(this, e);
1500                         }
1501                 }
1502
1503                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1504                 protected override void OnFontChanged(EventArgs e) {
1505                         base.OnFontChanged (e);
1506                 }
1507
1508                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1509                 protected override void OnHandleCreated(EventArgs e) {
1510                         XplatUI.SetBorderStyle(window.Handle, form_border_style);
1511                         base.OnHandleCreated (e);
1512                 }
1513
1514                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1515                 protected override void OnHandleDestroyed(EventArgs e) {
1516                         base.OnHandleDestroyed (e);
1517                 }
1518
1519                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1520                 protected virtual void OnInputLanguageChanged(InputLanguageChangedEventArgs e) {
1521                         if (InputLanguageChanged!=null) {
1522                                 InputLanguageChanged(this, e);
1523                         }
1524                 }
1525
1526                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1527                 protected virtual void OnInputLanguageChanging(InputLanguageChangingEventArgs e) {
1528                         if (InputLanguageChanging!=null) {
1529                                 InputLanguageChanging(this, e);
1530                         }
1531                 }
1532
1533                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1534                 protected virtual void OnLoad(EventArgs e) {
1535                         if (AutoScale){
1536                                 ApplyAutoScaling ();
1537                                 AutoScale = false;
1538                         }
1539
1540                         if (Load != null) {
1541                                 Load(this, e);
1542                         }
1543
1544                         if (!IsMdiChild) {
1545                                 switch (StartPosition) {
1546                                         case FormStartPosition.CenterScreen:
1547                                                 this.CenterToScreen();
1548                                                 break;
1549                                         case FormStartPosition.CenterParent:
1550                                                 this.CenterToParent ();
1551                                                 break;
1552                                         case FormStartPosition.Manual: 
1553                                                 Left = CreateParams.X;
1554                                                 Top = CreateParams.Y;
1555                                                 break;
1556                                 }
1557                         }
1558                         is_loaded = true;
1559                 }
1560
1561                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1562                 protected virtual void OnMaximizedBoundsChanged(EventArgs e) {
1563                         if (MaximizedBoundsChanged != null) {
1564                                 MaximizedBoundsChanged(this, e);
1565                         }
1566                 }
1567
1568                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1569                 protected virtual void OnMaximumSizeChanged(EventArgs e) {
1570                         if (MaximumSizeChanged != null) {
1571                                 MaximumSizeChanged(this, e);
1572                         }
1573                 }
1574
1575                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1576                 protected virtual void OnMdiChildActivate(EventArgs e) {
1577                         if (MdiChildActivate != null) {
1578                                 MdiChildActivate(this, e);
1579                         }
1580                 }
1581
1582                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1583                 protected virtual void OnMenuComplete(EventArgs e) {
1584                         if (MenuComplete != null) {
1585                                 MenuComplete(this, e);
1586                         }
1587                 }
1588
1589                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1590                 protected virtual void OnMenuStart(EventArgs e) {
1591                         if (MenuStart != null) {
1592                                 MenuStart(this, e);
1593                         }
1594                 }
1595
1596                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1597                 protected virtual void OnMinimumSizeChanged(EventArgs e) {
1598                         if (MinimumSizeChanged != null) {
1599                                 MinimumSizeChanged(this, e);
1600                         }
1601                 }
1602
1603                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1604                 protected override void OnPaint (PaintEventArgs pevent) {
1605                         base.OnPaint (pevent);
1606                 }
1607
1608                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1609                 protected override void OnResize(EventArgs e) {
1610                         base.OnResize(e);
1611
1612                         if (this.IsMdiChild && ParentForm != null) {
1613                                 ParentForm.PerformLayout();
1614                                 ParentForm.Size = ParentForm.Size;
1615                         }
1616                 }
1617
1618                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1619                 protected override void OnStyleChanged(EventArgs e) {
1620                         base.OnStyleChanged (e);
1621                 }
1622
1623                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1624                 protected override void OnTextChanged(EventArgs e) {
1625                         base.OnTextChanged (e);
1626
1627             if (mdi_container != null)
1628                 mdi_container.SetParentText(true);
1629                 }
1630
1631                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1632                 protected override void OnVisibleChanged(EventArgs e) {
1633                         base.OnVisibleChanged (e);
1634                         
1635                         if (Visible) {
1636                                 if (window_manager != null)
1637                                         window_manager.SetWindowState (WindowState, WindowState);
1638                         }
1639                 }
1640
1641                 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
1642                         if (base.ProcessCmdKey (ref msg, keyData)) {
1643                                 return true;
1644                         }
1645
1646                         // Give our menu a shot
1647                         if (ActiveMenu != null) {
1648                                 return ActiveMenu.ProcessCmdKey(ref msg, keyData);
1649                         }
1650
1651                         return false;
1652                 }
1653
1654                 // LAMESPEC - Not documented that Form overrides ProcessDialogChar; class-status showed
1655                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1656                 protected override bool ProcessDialogChar(char charCode) {
1657                         return base.ProcessDialogChar (charCode);
1658                 }
1659
1660                 protected override bool ProcessDialogKey(Keys keyData) {
1661                         if ((keyData & Keys.Modifiers) == 0) {
1662                                 if (keyData == Keys.Enter) {
1663                                         IntPtr window = XplatUI.GetFocus ();
1664                                         Control c = Control.FromHandle (window);
1665                                         if (c is Button && c.FindForm () == this) {
1666                                                 ((Button)c).PerformClick ();
1667                                                 return true;
1668                                         }
1669                                         else if (accept_button != null) {
1670                                                 accept_button.PerformClick();
1671                                                 return true;
1672                                         }
1673                                 } else if (keyData == Keys.Escape && cancel_button != null) {
1674                                         cancel_button.PerformClick();
1675                                         return true;
1676                                 }
1677                         }
1678                         return base.ProcessDialogKey(keyData);
1679                 }
1680
1681                 protected override bool ProcessKeyPreview(ref Message msg) {
1682                         if (key_preview) {
1683                                 if (ProcessKeyEventArgs(ref msg)) {
1684                                         return true;
1685                                 }
1686                         }
1687                         return base.ProcessKeyPreview (ref msg);
1688                 }
1689
1690                 protected override bool ProcessTabKey(bool forward) {
1691                         return SelectNextControl(ActiveControl, forward, true, true, true);
1692                 }
1693
1694                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1695                 protected override void ScaleCore(float dx, float dy) {
1696                         try {
1697                                 SuspendLayout();
1698
1699                                 // We can't scale max or min windows
1700                                 if (WindowState == FormWindowState.Normal) {
1701                                         // We cannot call base since base also adjusts X/Y, but
1702                                         // a form is toplevel and doesn't move
1703                                         Size    size;
1704
1705                                         size = ClientSize;
1706                                         if (!GetStyle(ControlStyles.FixedWidth)) {
1707                                                 size.Width = (int)(size.Width * dx);
1708                                         }
1709
1710                                         if (!GetStyle(ControlStyles.FixedHeight)) {
1711                                                 size.Height = (int)(size.Height * dy);
1712                                         }
1713
1714                                         ClientSize = size;
1715                                 }
1716
1717                                 /* Now scale our children */
1718                                 Control [] controls = child_controls.GetAllControls ();
1719                                 for (int i=0; i < controls.Length; i++) {
1720                                         controls[i].Scale(dx, dy);
1721                                 }
1722                         }
1723
1724                         finally {
1725                                 ResumeLayout();
1726                         }
1727                 }
1728
1729                 protected override void Select(bool directed, bool forward) {
1730                         Form    parent;
1731
1732                         if (directed) {
1733                                 base.SelectNextControl(null, forward, true, true, true);
1734                         }
1735
1736                         parent = this.ParentForm;
1737                         if (parent != null) {
1738                                 parent.ActiveControl = this;
1739                         }
1740
1741                         Activate();
1742                 }
1743
1744                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1745                 protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
1746                         base.SetBoundsCore (x, y, width, height, specified);
1747                 }
1748
1749                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1750                 protected override void SetClientSizeCore(int x, int y) {
1751                         if ((minimum_size.Width != 0) && (x < minimum_size.Width)) {
1752                                 x = minimum_size.Width;
1753                         } else if ((maximum_size.Width != 0) && (x > maximum_size.Width)) {
1754                                 x = maximum_size.Width;
1755                         }
1756
1757                         if ((minimum_size.Height != 0) && (y < minimum_size.Height)) {
1758                                 y = minimum_size.Height;
1759                         } else if ((maximum_size.Height != 0) && (y > maximum_size.Height)) {
1760                                 y = maximum_size.Height;
1761                         }
1762
1763                         Rectangle ClientRect = new Rectangle(0, 0, x, y);
1764                         Rectangle WindowRect;
1765                         CreateParams cp = this.CreateParams;
1766
1767                         clientsize_set = new Size(x, y);
1768
1769                         if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, cp.menu, out WindowRect)) {
1770                                 SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
1771                         }
1772                 }
1773
1774                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1775                 protected override void SetVisibleCore(bool value) {
1776                         base.SetVisibleCore (value);
1777                 }
1778
1779                 protected override void UpdateDefaultButton() {
1780                         base.UpdateDefaultButton ();
1781                 }
1782
1783                 [EditorBrowsable(EditorBrowsableState.Advanced)]
1784                 protected override void WndProc(ref Message m) {
1785
1786                         if (window_manager != null && window_manager.HandleMessage (ref m)) {
1787                                 return;
1788                         }
1789
1790                         switch((Msg)m.Msg) {
1791                                 case Msg.WM_DESTROY: {
1792                                         base.WndProc(ref m);
1793                                         if (!is_recreating) {
1794                                                 this.closing = true;
1795                                         }
1796                                         return;
1797                                 }
1798
1799                                 case Msg.WM_CLOSE_INTERNAL: {
1800                                         DestroyHandle();
1801                                         break;
1802                                 }
1803
1804                                 case Msg.WM_CLOSE: {
1805                                         Form act = Form.ActiveForm;
1806                                         if (act != null && act != this && act.Modal == true) {
1807                                                 return;
1808                                         }
1809
1810                                         CancelEventArgs args = new CancelEventArgs ();
1811
1812                                         if (mdi_container != null) {
1813                                                 foreach (Form mdi_child in mdi_container.MdiChildren) {
1814                                                         mdi_child.OnClosing (args);
1815                                                 }
1816                                         }
1817
1818                                         if (!is_modal) {
1819                                                 OnClosing (args);
1820                                                 if (!args.Cancel) {
1821                                                         OnClosed (EventArgs.Empty);
1822                                                         closing = true;
1823                                                 }
1824                                                 Dispose ();
1825                                         } else {
1826                                                 OnClosing (args);
1827                                                 if (args.Cancel) {
1828                                                         DialogResult = DialogResult.None;
1829                                                         closing = false;
1830                                                 } else {
1831                                                         OnClosed (EventArgs.Empty);
1832                                                         closing = true;
1833                                                         Hide ();
1834                                                 }
1835                                         }
1836
1837                                         return;
1838                                 }
1839
1840                                 case Msg.WM_WINDOWPOSCHANGED: {
1841                                         if (WindowState != FormWindowState.Minimized) {
1842                                                 base.WndProc(ref m);
1843                                         }
1844                                         return;
1845                                 }
1846
1847 #if NET_2_0
1848                                 case Msg.WM_SYSCOMMAND: {
1849                                         // Let *Strips know the app's title bar was clicked
1850                                         if (XplatUI.IsEnabled (Handle))
1851                                                 ToolStripMenuTracker.FireAppClicked ();
1852                                                 
1853                                         base.WndProc(ref m);
1854                                         break;
1855                                 }
1856 #endif
1857         
1858                                 case Msg.WM_ACTIVATE: {
1859                                         if (m.WParam != (IntPtr)WindowActiveFlags.WA_INACTIVE) {
1860                                                 OnActivated(EventArgs.Empty);
1861                                         } else {
1862                                                 OnDeactivate(EventArgs.Empty);
1863 #if NET_2_0
1864                                                 // Let *Strips know the app lost focus
1865                                                 if (XplatUI.IsEnabled (Handle))
1866                                                         ToolStripMenuTracker.FireAppFocusChanged ();
1867 #endif
1868                                         }
1869                                         return;
1870                                 }
1871
1872                                 case Msg.WM_KILLFOCUS: {
1873                                         base.WndProc(ref m);
1874                                         return;
1875                                 }
1876
1877                                 case Msg.WM_SETFOCUS: {
1878                                         if (ActiveControl != null && ActiveControl != this) {
1879                                                 ActiveControl.Focus();
1880                                                 return; // FIXME - do we need to run base.WndProc, even though we just changed focus?
1881                                         }
1882                                         base.WndProc(ref m);
1883                                         return;
1884                                 }
1885
1886                                 // Menu drawing
1887                                 case Msg.WM_NCLBUTTONDOWN: {
1888                                         if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
1889                                                 ActiveMenu.OnMouseDown(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, Control.MousePosition.X, Control.MousePosition.Y, 0));
1890                                         }
1891
1892                                         if (ActiveMaximizedMdiChild != null) {
1893                                                 if (ActiveMaximizedMdiChild.HandleMenuMouseDown (ActiveMenu,
1894                                                                 LowOrder ((int) m.LParam.ToInt32 ()),
1895                                                                 HighOrder ((int) m.LParam.ToInt32 ()))) {
1896                                                         // Don't let base process this message, otherwise we won't
1897                                                         // get a WM_NCLBUTTONUP.
1898                                                         return;
1899                                                 }
1900                                         }
1901                                         base.WndProc(ref m);
1902                                         return;
1903                                 }
1904                                 case Msg.WM_NCLBUTTONUP: {
1905                                         if (ActiveMaximizedMdiChild != null) {
1906                                                 ActiveMaximizedMdiChild.HandleMenuMouseUp (ActiveMenu,
1907                                                                 LowOrder ((int)m.LParam.ToInt32 ()),
1908                                                                 HighOrder ((int)m.LParam.ToInt32 ()));
1909                                         }
1910                                         base.WndProc (ref m);
1911                                         return;
1912                                 }
1913
1914                                 case Msg.WM_NCMOUSELEAVE: {
1915                                         if (ActiveMaximizedMdiChild != null) {
1916                                                 ActiveMaximizedMdiChild.HandleMenuMouseLeave(ActiveMenu,
1917                                                                 LowOrder((int)m.LParam.ToInt32()),
1918                                                                 HighOrder((int)m.LParam.ToInt32()));
1919                                         }
1920                                         base.WndProc(ref m);
1921                                         return;
1922                                 }
1923                                 
1924                                 case Msg.WM_NCMOUSEMOVE: {
1925                                         if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
1926                                                 ActiveMenu.OnMouseMove(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0));
1927                                         }
1928                                         
1929                                         if (ActiveMaximizedMdiChild != null) {
1930                                                 ActiveMaximizedMdiChild.HandleMenuMouseMove (ActiveMenu,
1931                                                                 LowOrder ((int)m.LParam.ToInt32 ()),
1932                                                                 HighOrder ((int)m.LParam.ToInt32 ()));
1933                                         }
1934                                         base.WndProc(ref m);
1935                                         return;
1936                                 }
1937
1938                                 case Msg.WM_NCPAINT: {
1939                                         if (ActiveMenu != null) {
1940                                                 PaintEventArgs  pe;
1941                                                 Point           pnt;
1942
1943                                                 pe = XplatUI.PaintEventStart(Handle, false);
1944                                                 pnt = XplatUI.GetMenuOrigin(window.Handle);
1945
1946                                                 // The entire menu has to be in the clip rectangle because the 
1947                                                 // control buttons are right-aligned and otherwise they would
1948                                                 // stay painted when the window gets resized.
1949                                                 Rectangle clip = new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0);
1950                                                 clip = Rectangle.Union(clip, pe.ClipRectangle);
1951                                                 pe.SetClip(clip);
1952                                                 pe.Graphics.SetClip(clip);
1953                                                 
1954                                                 ActiveMenu.Draw (pe, new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0));
1955
1956                                                 if (ActiveMaximizedMdiChild != null) {
1957                                                         ActiveMaximizedMdiChild.DrawMaximizedButtons (ActiveMenu, pe);
1958                                                 }
1959
1960                                                 XplatUI.PaintEventEnd(Handle, false);
1961                                         }
1962
1963                                         base.WndProc(ref m);
1964                                         return;
1965                                 }
1966
1967                                 case Msg.WM_NCCALCSIZE: {
1968                                         XplatUIWin32.NCCALCSIZE_PARAMS  ncp;
1969
1970                                         if ((ActiveMenu != null) && (m.WParam == (IntPtr)1)) {
1971                                                 ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
1972
1973                                                 // Adjust for menu
1974                                                 ncp.rgrc1.top += ThemeEngine.Current.CalcMenuBarSize (DeviceContext, ActiveMenu, ncp.rgrc1.right - ncp.rgrc1.left);
1975                                                 Marshal.StructureToPtr(ncp, m.LParam, true);
1976                                         }
1977                                         DefWndProc(ref m);
1978                                         break;
1979                                 }
1980
1981                                 case Msg.WM_MOUSEMOVE: {
1982                                         if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
1983                                                 MouseEventArgs args;
1984
1985                                                 args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), 
1986                                                         mouse_clicks,  LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),  0);
1987                                                 active_tracker.OnMotion(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
1988                                                 break;
1989                                         }
1990                                         base.WndProc(ref m);
1991                                         break;
1992                                 }
1993
1994                                 case Msg.WM_LBUTTONDOWN:
1995                                 case Msg.WM_MBUTTONDOWN:
1996                                 case Msg.WM_RBUTTONDOWN: {                                      
1997                                         if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
1998                                                 MouseEventArgs args;
1999
2000                                                 args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), 
2001                                                         mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
2002                                                 active_tracker.OnMouseDown(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
2003                                                 return;
2004                                         }
2005                                         base.WndProc(ref m);
2006                                         return;
2007                                 }
2008
2009                                 case Msg.WM_LBUTTONUP:
2010                                 case Msg.WM_MBUTTONUP:
2011                                 case Msg.WM_RBUTTONUP: {
2012                                         if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
2013                                                 MouseEventArgs args;
2014                                                 MouseButtons mb = FromParamToMouseButtons ((int) m.WParam.ToInt32());
2015                                                 
2016                                                 // We add in the button that was released (not sent in WParam)
2017                                                 switch((Msg)m.Msg) {
2018                                                         case Msg.WM_LBUTTONUP:
2019                                                                 mb |= MouseButtons.Left;
2020                                                                 break;
2021                                                         case Msg.WM_MBUTTONUP:
2022                                                                 mb |= MouseButtons.Middle;
2023                                                                 break;
2024                                                         case Msg.WM_RBUTTONUP:
2025                                                                 mb |= MouseButtons.Right;
2026                                                                 break;
2027                                                 }
2028                                                 
2029                                                 args = new MouseEventArgs (mb, mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
2030                                                 active_tracker.OnMouseUp(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
2031                                                 mouse_clicks = 1;
2032                                                 return;
2033                                         }
2034                                         base.WndProc(ref m);
2035                                         return;
2036                                 }
2037
2038                                 case Msg.WM_GETMINMAXINFO: {
2039                                         MINMAXINFO      mmi;
2040
2041                                         if (m.LParam != IntPtr.Zero) {
2042                                                 mmi = (MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(MINMAXINFO));
2043
2044                                                 default_maximized_bounds = new Rectangle(mmi.ptMaxPosition.x, mmi.ptMaxPosition.y, mmi.ptMaxSize.x, mmi.ptMaxSize.y);
2045                                                 if (maximized_bounds != Rectangle.Empty) {
2046                                                         mmi.ptMaxPosition.x = maximized_bounds.Left;
2047                                                         mmi.ptMaxPosition.y = maximized_bounds.Top;
2048                                                         mmi.ptMaxSize.x = maximized_bounds.Width;
2049                                                         mmi.ptMaxSize.y = maximized_bounds.Height;
2050                                                 }
2051
2052                                                 if (minimum_size != Size.Empty) {
2053                                                         mmi.ptMinTrackSize.x = minimum_size.Width;
2054                                                         mmi.ptMinTrackSize.y = minimum_size.Height;
2055                                                 }
2056
2057                                                 if (maximum_size != Size.Empty) {
2058                                                         mmi.ptMaxTrackSize.x = maximum_size.Width;
2059                                                         mmi.ptMaxTrackSize.y = maximum_size.Height;
2060                                                 }
2061                                                 Marshal.StructureToPtr(mmi, m.LParam, false);
2062                                         }
2063                                         break;
2064                                 }
2065                                 
2066 #if NET_2_0
2067                                 case Msg.WM_MOUSEACTIVATE: {
2068                                         // Let *Strips know the form or another control has been clicked
2069                                         if (XplatUI.IsEnabled (Handle))
2070                                                 ToolStripMenuTracker.FireAppClicked ();
2071                                                 
2072                                         base.WndProc (ref m);
2073                                         break;                          
2074                                 }
2075 #endif
2076
2077                                 default: {
2078                                         base.WndProc (ref m);
2079                                         break;
2080                                 }
2081                         }
2082                 }
2083                 #endregion      // Protected Instance Methods
2084
2085                 internal void RemoveWindowManager ()
2086                 {
2087                         window_manager = null;
2088                 }
2089                 
2090                 internal override void CheckAcceptButton()
2091                 {
2092                         if (accept_button != null) {
2093                                 Button a_button = accept_button as Button;
2094                                 
2095                                 if (ActiveControl == a_button)
2096                                         return;
2097                                 
2098                                 if (ActiveControl is Button) {
2099                                         a_button.paint_as_acceptbutton = false;
2100                                         a_button.Redraw();
2101                                         return;
2102                                 } else {
2103                                         a_button.paint_as_acceptbutton = true;
2104                                         a_button.Redraw();
2105                                 }
2106                         }
2107                 }
2108                 
2109                 #region Events
2110                 public event EventHandler Activated;
2111                 public event EventHandler Closed;
2112                 public event CancelEventHandler Closing;
2113                 public event EventHandler Deactivate;
2114                 public event InputLanguageChangedEventHandler InputLanguageChanged;
2115                 public event InputLanguageChangingEventHandler InputLanguageChanging;
2116                 public event EventHandler Load;
2117                 public event EventHandler MaximizedBoundsChanged;
2118                 public event EventHandler MaximumSizeChanged;
2119                 public event EventHandler MdiChildActivate;
2120                 public event EventHandler MenuComplete;
2121                 public event EventHandler MenuStart;
2122                 public event EventHandler MinimumSizeChanged;
2123
2124                 [Browsable(false)]
2125                 [EditorBrowsable(EditorBrowsableState.Never)]
2126                 public new event EventHandler TabIndexChanged {
2127                         add { base.TabIndexChanged += value; }
2128                         remove { base.TabIndexChanged -= value; }
2129                 }
2130                 #endregion      // Events
2131
2132 #if NET_2_0
2133                 public override string Text {
2134                         get {
2135                                 return base.Text;
2136                         }
2137
2138                         set {
2139                                 base.Text = value;
2140                         }
2141                 }
2142
2143                 public new Point Location {
2144                         get {
2145                                 return base.Location;
2146                         }
2147
2148                         set {
2149                                 base.Location = value;
2150                         }
2151                 }
2152
2153                 public event FormClosingEventHandler FormClosing;
2154                 public event FormClosedEventHandler FormClosed;
2155                 
2156                 protected virtual void OnFormClosing (FormClosingEventArgs e)
2157                 {
2158                         if (FormClosing != null)
2159                                 FormClosing (this, e);
2160                 }
2161 #endif
2162         }
2163 }