* TabControl.cs: Show the tooltip depending on the value
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / MdiWindowManager.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) 2005 Novell, Inc. (http://www.novell.com)
21 //
22 // Authors:
23 //      Jackson Harper (jackson@ximian.com)
24 //
25 //
26
27
28 using System;
29 using System.Drawing;
30 using System.Drawing.Drawing2D;
31 using System.Runtime.InteropServices;
32
33 namespace System.Windows.Forms {
34
35         internal class MdiWindowManager : InternalWindowManager {
36
37                 private MainMenu merged_menu;
38                 private MainMenu maximized_menu;
39                 private MenuItem icon_menu;
40                 private ContextMenu icon_popup_menu;
41                 internal bool was_minimized;
42                 
43                 private PaintEventHandler draw_maximized_buttons;
44                 internal EventHandler form_closed_handler;
45                 
46                 private MdiClient mdi_container;
47                 private Rectangle prev_virtual_position;
48
49                 private Point icon_clicked;
50                 private DateTime icon_clicked_time;
51                 private bool icon_dont_show_popup;
52
53                 private TitleButtons maximized_title_buttons;
54                 private bool is_visible_pending;
55                 private byte last_activation_event; // 0 = none, 1 = activated, 2 = deactivated.
56
57                 public void RaiseActivated ()
58                 {
59                         if (last_activation_event == 1)
60                                 return;
61                         
62                         last_activation_event = 1;
63                         form.OnActivatedInternal ();
64                         form.SelectActiveControl ();
65                 }
66                 
67                 public void RaiseDeactivate ()
68                 {
69                         if (last_activation_event != 1)
70                                 return;
71                         last_activation_event = 2;
72                         form.OnDeactivateInternal ();
73                 }
74
75                 public override int MenuHeight {
76                         get {
77                                 // Mdi children don't get menus on the form, they're shown on the main form.
78                                 return 0;
79                         }
80                 }
81
82                 internal bool IsVisiblePending {
83                         get {
84                                 return is_visible_pending;
85                         }
86                         set {
87                                 is_visible_pending = value;
88                         }
89                 }
90
91                 private TitleButtons MaximizedTitleButtons {
92                         get {
93                                 if (maximized_title_buttons == null) {
94                                         maximized_title_buttons = new TitleButtons (this.Form);
95                                         maximized_title_buttons.CloseButton.Visible = true;
96                                         maximized_title_buttons.RestoreButton.Visible = true;
97                                         maximized_title_buttons.MinimizeButton.Visible = true;
98                                 }
99                                 return maximized_title_buttons;
100                         }
101                 }
102                 
103                 internal override Rectangle MaximizedBounds {
104                         get {
105                                 Rectangle pb = mdi_container.ClientRectangle;
106                                 int bw = ThemeEngine.Current.ManagedWindowBorderWidth (this);
107                                 int tw = TitleBarHeight;
108
109                                 Rectangle new_bounds = new Rectangle (pb.Left - bw,
110                                                 pb.Top - tw - bw,
111                                                 pb.Width + bw * 2,
112                                                 pb.Height + tw + bw * 2);
113                                 return new_bounds;
114                         }
115                 }
116                 
117                 
118                 
119                 public MdiWindowManager (Form form, MdiClient mdi_container) : base (form)
120                 {
121                         this.mdi_container = mdi_container;
122                         if (form.WindowState == FormWindowState.Normal) {
123                                 NormalBounds = form.Bounds;
124                         }
125                         form_closed_handler = new EventHandler (FormClosed);
126                         form.Closed += form_closed_handler;
127                         form.TextChanged += new EventHandler (FormTextChangedHandler);
128                         form.SizeChanged += new EventHandler (FormSizeChangedHandler);
129                         form.LocationChanged += new EventHandler (FormLocationChangedHandler);
130                         form.VisibleChanged += new EventHandler (FormVisibleChangedHandler);
131                         draw_maximized_buttons = new PaintEventHandler (DrawMaximizedButtons);
132                         CreateIconMenus ();
133                 }
134
135                 private void FormVisibleChangedHandler (object sender, EventArgs e)
136                 {
137                         if (mdi_container == null)
138                                 return;
139                                 
140                         if (form.Visible) {
141                                 mdi_container.ActivateChild (form);
142                         } else if (mdi_container.Controls.Count > 1) {
143                                 mdi_container.ActivateActiveMdiChild ();
144                         }
145                 }
146
147                 private void FormTextChangedHandler (object sender, EventArgs e)
148                 {
149                         mdi_container.SetParentText (false);
150
151 #if NET_2_0
152                         if (form.MdiParent.MainMenuStrip != null)
153                                 form.MdiParent.MainMenuStrip.RefreshMdiItems ();
154 #endif
155                 }
156
157                 private void FormLocationChangedHandler (object sender, EventArgs e)
158                 {
159                         if (form.window_state == FormWindowState.Minimized)
160                                 IconicBounds = form.Bounds;
161                         form.MdiParent.MdiContainer.SizeScrollBars ();
162                 }
163
164                 private void FormSizeChangedHandler (object sender, EventArgs e)
165                 {
166                         if (form.window_state == FormWindowState.Maximized && form.Bounds != MaximizedBounds)
167                                 form.Bounds = MaximizedBounds;
168                         
169                         form.MdiParent.MdiContainer.SizeScrollBars ();
170                 }
171         
172                 public MainMenu MergedMenu {
173                         get {
174                                 if (merged_menu == null)
175                                         merged_menu = CreateMergedMenu ();
176                                 return merged_menu;
177                         }
178                 }
179
180                 private MainMenu CreateMergedMenu ()
181                 {
182                         Form parent = (Form) mdi_container.Parent;
183                         MainMenu clone;
184                         if (parent.Menu != null)
185                                 clone = (MainMenu) parent.Menu.CloneMenu ();
186                         else
187                                 clone = new MainMenu ();
188                                 
189                         if (form.WindowState == FormWindowState.Maximized) {
190                                 
191                         }
192                         clone.MergeMenu (form.Menu);
193                         clone.MenuChanged += new EventHandler (MenuChangedHandler);
194                         clone.SetForm (parent);
195                         return clone;
196                 }
197
198                 public MainMenu MaximizedMenu {
199                         get {
200                                 if (maximized_menu == null)
201                                         maximized_menu = CreateMaximizedMenu ();
202                                 return maximized_menu;
203                         }
204                 }
205
206                 private MainMenu CreateMaximizedMenu ()
207                 {
208                         Form parent = (Form) mdi_container.Parent;
209
210 #if NET_2_0
211                         if (form.MainMenuStrip != null || parent.MainMenuStrip != null)
212                                 return null;
213 #endif
214
215                         MainMenu res = new MainMenu ();
216
217                         if (parent.Menu != null) {
218                                 MainMenu clone = (MainMenu) parent.Menu.CloneMenu ();
219                                 res.MergeMenu (clone);
220                         }
221                         
222                         if (form.Menu != null) {
223                                 MainMenu clone = (MainMenu) form.Menu.CloneMenu ();
224                                 res.MergeMenu (clone);
225                         }
226                         
227                         if (res.MenuItems.Count == 0)
228                                 res.MenuItems.Add (new MenuItem ()); // Dummy item to get the menu height correct
229                         
230                         res.MenuItems.Insert (0, icon_menu);
231                         
232                         res.SetForm (parent);
233                         return res;
234                 }
235
236                 private void CreateIconMenus ()
237                 {
238                         icon_menu = new MenuItem ();
239                         icon_popup_menu = new ContextMenu ();
240
241                         icon_menu.OwnerDraw = true;
242                         icon_menu.MeasureItem += new MeasureItemEventHandler (MeasureIconMenuItem);
243                         icon_menu.DrawItem += new DrawItemEventHandler (DrawIconMenuItem);
244                         icon_menu.Click += new EventHandler (ClickIconMenuItem);
245
246                         MenuItem restore = new MenuItem ("&Restore", new EventHandler (RestoreItemHandler));
247                         MenuItem move = new MenuItem ("&Move", new EventHandler (MoveItemHandler));
248                         MenuItem size = new MenuItem ("&Size", new EventHandler (SizeItemHandler));
249                         MenuItem minimize = new MenuItem ("Mi&nimize", new EventHandler (MinimizeItemHandler));
250                         MenuItem maximize = new MenuItem ("Ma&ximize", new EventHandler (MaximizeItemHandler));
251                         MenuItem close = new MenuItem ("&Close", new EventHandler (CloseItemHandler));
252                         MenuItem next = new MenuItem ("Nex&t", new EventHandler (NextItemHandler));
253
254                         icon_menu.MenuItems.AddRange (new MenuItem [] { restore, move, size, minimize,
255                                                                         maximize, close, next });
256                         icon_popup_menu.MenuItems.AddRange (new MenuItem [] { restore, move, size, minimize,
257                                                                         maximize, close, next });
258                 }
259
260                 private void ClickIconMenuItem(object sender, EventArgs e)
261                 {
262                         if ((DateTime.Now - icon_clicked_time).TotalMilliseconds <= SystemInformation.DoubleClickTime) {
263                                 form.Close ();
264                                 return;
265                         }
266                         icon_clicked_time = DateTime.Now;
267                         Point pnt = Point.Empty;
268                         pnt = form.MdiParent.PointToScreen (pnt);
269                         pnt = form.PointToClient (pnt);
270                         ShowPopup (pnt);
271                 }
272                 
273                 internal void ShowPopup (Point pnt)
274                 {
275 #if NET_2_0
276                         // If we are using MainMenuStrip, display that menu instead
277                         if (form.WindowState == FormWindowState.Maximized && form.MdiParent.MainMenuStrip != null)
278                                 if (form.MdiParent.MainMenuStrip.Items.Count > 0) {
279                                         ToolStripItem tsi = form.MdiParent.MainMenuStrip.Items[0];
280                                         
281                                         if (tsi is MdiControlStrip.SystemMenuItem) {
282                                                 (tsi as MdiControlStrip.SystemMenuItem).ShowDropDown ();
283                                                 return;
284                                         }
285                                 }
286 #endif
287                                 
288                         icon_popup_menu.MenuItems[0].Enabled = form.window_state != FormWindowState.Normal;    // restore
289                         icon_popup_menu.MenuItems[1].Enabled = form.window_state != FormWindowState.Maximized; // move
290                         icon_popup_menu.MenuItems[2].Enabled = form.window_state != FormWindowState.Maximized; // size
291                         icon_popup_menu.MenuItems[3].Enabled = form.window_state != FormWindowState.Minimized; // minimize
292                         icon_popup_menu.MenuItems[4].Enabled = form.window_state != FormWindowState.Maximized; // maximize
293                         icon_popup_menu.MenuItems[5].Enabled = true;  // close
294                         icon_popup_menu.MenuItems[6].Enabled = true;  // next
295                         
296                         icon_popup_menu.Show(form, pnt);
297                 }
298                 
299                 private void RestoreItemHandler (object sender, EventArgs e)
300                 {
301                         form.WindowState = FormWindowState.Normal;
302                 }
303
304                 private void MoveItemHandler (object sender, EventArgs e)
305                 {
306                         int x = 0;
307                         int y = 0;
308
309                         PointToScreen (ref x, ref y);
310                         Cursor.Position = new Point (x, y);
311                         form.Cursor = Cursors.Cross;
312                         state = State.Moving;
313                         form.Capture = true;
314                 }
315
316                 private void SizeItemHandler (object sender, EventArgs e)
317                 {
318                         int x = 0;
319                         int y = 0;
320
321                         PointToScreen (ref x, ref y);
322                         Cursor.Position = new Point (x, y);
323                         form.Cursor = Cursors.Cross;
324                         state = State.Sizing;
325                         form.Capture = true;
326                 }               
327
328                 private void MinimizeItemHandler (object sender, EventArgs e)
329                 {
330                         form.WindowState = FormWindowState.Minimized;
331                 }
332
333                 private void MaximizeItemHandler (object sender, EventArgs e)
334                 {
335                         if (form.WindowState != FormWindowState.Maximized)
336                                 form.WindowState = FormWindowState.Maximized;
337                 }
338
339                 private void CloseItemHandler (object sender, EventArgs e)
340                 {
341                         form.Close ();
342                 }
343
344                 private void NextItemHandler (object sender, EventArgs e)
345                 {
346                         mdi_container.ActivateNextChild ();
347                 }
348
349                 private void DrawIconMenuItem (object sender, DrawItemEventArgs de)
350                 {
351                         de.Graphics.DrawIcon (form.Icon, new Rectangle (de.Bounds.X + 2, de.Bounds.Y + 2,
352                                                               de.Bounds.Height - 4, de.Bounds.Height - 4));
353                 }
354
355                 private void MeasureIconMenuItem (object sender, MeasureItemEventArgs me)
356                 {
357                         int size = SystemInformation.MenuHeight;
358                         me.ItemHeight = size;
359                         me.ItemWidth = size + 2; // some padding
360                 }
361
362                 private void MenuChangedHandler (object sender, EventArgs e)
363                 {
364                         CreateMergedMenu ();
365                 }
366
367                 public override void PointToClient (ref int x, ref int y)
368                 {
369                         XplatUI.ScreenToClient (mdi_container.Handle, ref x, ref y);
370                 }
371
372                 public override void PointToScreen (ref int x, ref int y)
373                 {
374                         XplatUI.ClientToScreen (mdi_container.Handle, ref x, ref y);
375                 }
376
377                 public override void UpdateWindowDecorations (FormWindowState window_state)
378                 {                       
379                         if (MaximizedMenu != null) {
380                                 switch (window_state) {
381                                 case FormWindowState.Minimized:
382                                 case FormWindowState.Normal:
383                                         MaximizedMenu.Paint -= draw_maximized_buttons;
384                                         MaximizedTitleButtons.Visible = false;
385                                         TitleButtons.Visible = true;
386                                         break;
387                                 case FormWindowState.Maximized:
388                                         MaximizedMenu.Paint += draw_maximized_buttons;
389                                         MaximizedTitleButtons.Visible = true;
390                                         TitleButtons.Visible = false;
391                                         break;
392                                 }
393                         }
394                         
395                         base.UpdateWindowDecorations (window_state);
396                 }
397
398                 public override void SetWindowState (FormWindowState old_state, FormWindowState window_state)
399                 {
400                         mdi_container.SetWindowState (form, old_state, window_state, false);
401                 }
402
403                 private void FormClosed (object sender, EventArgs e)
404                 {
405                         mdi_container.ChildFormClosed (form);
406
407 #if NET_2_0
408                         if (form.MdiParent.MainMenuStrip != null)
409                                 form.MdiParent.MainMenuStrip.RefreshMdiItems ();
410
411                         mdi_container.RemoveControlMenuItems (this);
412 #endif
413                 }
414
415                 public override void DrawMaximizedButtons (object sender, PaintEventArgs pe)
416                 {
417                         Size bs = ThemeEngine.Current.ManagedWindowGetMenuButtonSize (this);
418                         Point pnt =  XplatUI.GetMenuOrigin (mdi_container.ParentForm.Handle);
419                         int bw = ThemeEngine.Current.ManagedWindowBorderWidth (this);
420                         TitleButtons buttons = MaximizedTitleButtons;
421                         
422                         buttons.Visible = true;
423                         TitleButtons.Visible = false;
424                         
425                         buttons.CloseButton.Rectangle = new Rectangle (mdi_container.ParentForm.Size.Width - 1 - bw - bs.Width - 2,
426                                         pnt.Y + 2, bs.Width, bs.Height);
427
428                         buttons.RestoreButton.Rectangle = new Rectangle (buttons.CloseButton.Rectangle.Left - 2 - bs.Width,
429                                         pnt.Y + 2, bs.Width, bs.Height);
430
431                         buttons.MinimizeButton.Rectangle = new Rectangle (buttons.RestoreButton.Rectangle.Left - bs.Width,
432                                         pnt.Y + 2, bs.Width, bs.Height);
433
434                         DrawTitleButton (pe.Graphics, buttons.MinimizeButton, pe.ClipRectangle);
435                         DrawTitleButton (pe.Graphics, buttons.RestoreButton, pe.ClipRectangle);
436                         DrawTitleButton (pe.Graphics, buttons.CloseButton, pe.ClipRectangle);
437
438                         buttons.MinimizeButton.Rectangle.Y -= pnt.Y;
439                         buttons.RestoreButton.Rectangle.Y -= pnt.Y;
440                         buttons.CloseButton.Rectangle.Y -= pnt.Y;
441                 }
442                 
443                 public bool HandleMenuMouseDown (MainMenu menu, int x, int y)
444                 {
445                         Point pt = MenuTracker.ScreenToMenu (menu, new Point (x, y));
446
447                         HandleTitleBarDown (pt.X, pt.Y);
448                         return TitleButtons.AnyPushedTitleButtons;
449                 }
450
451                 public void HandleMenuMouseUp (MainMenu menu, int x, int y)
452                 {
453                         Point pt = MenuTracker.ScreenToMenu (menu, new Point (x, y));
454
455                         HandleTitleBarUp (pt.X, pt.Y);
456                 }
457
458                 public void HandleMenuMouseLeave (MainMenu menu, int x, int y)
459                 {
460                         Point pt = MenuTracker.ScreenToMenu (menu, new Point (x, y));
461                         HandleTitleBarLeave (pt.X, pt.Y);
462
463                 }
464
465                 public void HandleMenuMouseMove (MainMenu menu, int x, int y)
466                 {
467                         Point pt = MenuTracker.ScreenToMenu (menu, new Point (x, y));
468
469                         HandleTitleBarMouseMove (pt.X, pt.Y);
470
471                 }
472
473                 protected override void HandleTitleBarLeave (int x, int y)
474                 {
475                         base.HandleTitleBarLeave (x, y);
476
477                         if (maximized_title_buttons != null) {
478                                 maximized_title_buttons.MouseLeave (x, y);
479                         }
480                         
481                         if (IsMaximized)
482                                 XplatUI.InvalidateNC (form.MdiParent.Handle);
483                 }
484                 
485                 protected override void HandleTitleBarUp (int x, int y)
486                 {                       
487                         if (IconRectangleContains (x, y)) {
488                                 if (!icon_dont_show_popup) {
489                                         if (IsMaximized)
490                                                 ClickIconMenuItem (null, null);
491                                         else
492                                                 ShowPopup (Point.Empty);
493                                 } else {
494                                         icon_dont_show_popup = false;
495                                 }
496                                 return;
497                         }
498                         
499                         bool was_maximized = IsMaximized;
500                         base.HandleTitleBarUp (x, y);
501                         if (maximized_title_buttons != null && was_maximized) {
502                                 maximized_title_buttons.MouseUp (x, y);
503                         }
504
505                         if (IsMaximized)
506                                 XplatUI.InvalidateNC (mdi_container.Parent.Handle);
507                 }
508
509                 protected override void HandleTitleBarDoubleClick (int x, int y)
510                 {
511                         if (IconRectangleContains (x, y)) {
512                                 form.Close ();
513                         } else if (form.MaximizeBox == true) {
514                                 form.WindowState = FormWindowState.Maximized;
515                         }
516                         base.HandleTitleBarDoubleClick (x, y);
517                 }
518                 
519                 protected override void HandleTitleBarDown (int x, int y)
520                 {                       
521                         if (IconRectangleContains (x, y)) {
522                                 if ((DateTime.Now - icon_clicked_time).TotalMilliseconds <= SystemInformation.DoubleClickTime && icon_clicked.X == x && icon_clicked.Y == y) {
523                                         form.Close ();
524                                 } else {
525                                         icon_clicked_time = DateTime.Now;
526                                         icon_clicked.X = x;
527                                         icon_clicked.Y = y;
528                                 }
529                                 
530                                 return;
531                         }
532
533                         base.HandleTitleBarDown (x, y);
534
535                         if (maximized_title_buttons != null) {
536                                 maximized_title_buttons.MouseDown (x, y);
537                         }
538                         
539                         if (IsMaximized) {
540                                 XplatUI.InvalidateNC (mdi_container.Parent.Handle);
541                         }
542                 }
543
544                 protected override void HandleTitleBarMouseMove (int x, int y)
545                 {
546                         base.HandleTitleBarMouseMove (x, y);
547
548                         if (maximized_title_buttons != null && maximized_title_buttons.MouseMove (x, y))
549                                 XplatUI.InvalidateNC (form.MdiParent.Handle);
550                 }
551
552                 protected override bool HandleLButtonDblClick (ref Message m)
553                 {
554
555                         int x = Control.LowOrder ((int)m.LParam.ToInt32 ());
556                         int y = Control.HighOrder ((int)m.LParam.ToInt32 ());
557
558                         // Correct since we are in NC land.
559                         NCClientToNC (ref x, ref y);
560
561                         if (IconRectangleContains (x, y)) {
562                                 icon_popup_menu.Wnd.Hide ();
563                                 form.Close ();
564                                 return true;
565                         }
566                         
567                         return base.HandleLButtonDblClick (ref m);
568                 }
569
570                 protected override bool HandleLButtonDown (ref Message m)
571                 {
572
573                         int x = Control.LowOrder ((int)m.LParam.ToInt32 ());
574                         int y = Control.HighOrder ((int)m.LParam.ToInt32 ());
575
576                         // Correct y since we are in NC land.
577                         NCClientToNC(ref x, ref y);
578
579                         if (IconRectangleContains (x, y)){
580                                 if ((DateTime.Now - icon_clicked_time).TotalMilliseconds <= SystemInformation.DoubleClickTime) {
581                                         if (icon_popup_menu != null && icon_popup_menu.Wnd != null) {
582                                                 icon_popup_menu.Wnd.Hide ();
583                                         }
584                                         form.Close ();
585                                         return true;
586                                 } else if (form.Capture) {
587                                         icon_dont_show_popup = true;
588                                 }
589                         }
590                         return base.HandleLButtonDown (ref m);
591                 }
592
593                 protected override bool ShouldRemoveWindowManager (FormBorderStyle style)
594                 {
595                         return false;
596                 }
597
598                 protected override void HandleWindowMove (Message m)
599                 {
600                         Point pos = Cursor.Position;
601                         Point move = MouseMove (pos);
602                         
603                         if (move.X == 0 && move.Y == 0)
604                                 return;
605                         
606                         int x = virtual_position.X + move.X;
607                         int y = virtual_position.Y + move.Y;
608                 
609                         Rectangle client = mdi_container.ClientRectangle;
610                         if (mdi_container.VerticalScrollbarVisible)
611                                 client.Width -= SystemInformation.VerticalScrollBarWidth;
612                         if (mdi_container.HorizontalScrollbarVisible)
613                                 client.Height -= SystemInformation.HorizontalScrollBarHeight;
614
615                         UpdateVP (x, y, form.Width, form.Height);
616
617                         start = pos;
618                 }
619
620                 protected override bool HandleNCMouseMove (ref Message m)
621                 {
622                         XplatUI.RequestAdditionalWM_NCMessages (form.Handle, true, true);
623                         return base.HandleNCMouseMove (ref m);
624                 }
625
626                 protected override void DrawVirtualPosition (Rectangle virtual_position)
627                 {
628                         ClearVirtualPosition ();
629
630                         if (form.Parent != null)
631                                 XplatUI.DrawReversibleRectangle (form.Parent.Handle, virtual_position, 2);
632                         prev_virtual_position = virtual_position;
633                 }
634
635                 protected override void ClearVirtualPosition ()
636                 {
637                         if (prev_virtual_position != Rectangle.Empty && form.Parent != null)
638                                 XplatUI.DrawReversibleRectangle (form.Parent.Handle,
639                                                 prev_virtual_position, 2);
640                         prev_virtual_position = Rectangle.Empty;
641                 }
642
643                 protected override void OnWindowFinishedMoving ()
644                 {
645                         form.Refresh ();
646                 }
647
648                 public override bool IsActive {
649                         get {
650                                 if (mdi_container == null)
651                                         return false;
652                                 return mdi_container.ActiveMdiChild == form;
653                         }
654                 }
655
656                 protected override void Activate ()
657                 {
658                         if (mdi_container.ActiveMdiChild != form) {
659                                 mdi_container.ActivateChild (form);
660                         }
661                         base.Activate ();
662                 }       
663         }
664 }
665