~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/addins/WindowsPlatform/Dialogs/WinFormsRoot.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.ComponentModel;
 
3
using System.Collections.Generic;
 
4
using System.Text;
 
5
using System.Windows.Forms;
 
6
using System.Drawing;
 
7
using CustomControls.OS;
 
8
 
 
9
namespace MonoDevelop.Platform
 
10
{
 
11
    class WinFormsRoot : Form
 
12
    {
 
13
                // From OpenFileDialogEx.cs
 
14
                private SetWindowPosFlags UFLAGSHIDE =     
 
15
                        SetWindowPosFlags.SWP_NOACTIVATE |
 
16
                        SetWindowPosFlags.SWP_NOOWNERZORDER |
 
17
                        SetWindowPosFlags.SWP_NOMOVE |
 
18
                        SetWindowPosFlags.SWP_NOSIZE | 
 
19
                        SetWindowPosFlags.SWP_HIDEWINDOW;
 
20
                
 
21
                IDisposable nativeDialogWindow;         
 
22
                bool watchForActivate;
 
23
                
 
24
        public WinFormsRoot()
 
25
        {
 
26
            this.Text = "";
 
27
            this.StartPosition = FormStartPosition.Manual;
 
28
            this.Location = new Point(-32000, -32000);
 
29
            this.ShowInTaskbar = false;
 
30
            this.Icon = MonoDevelopIcon; // Icon is inherited to FileDialog objects
 
31
            Show();
 
32
                        Win32.SetWindowPos(Handle, IntPtr.Zero, 0, 0, 0, 0, UFLAGSHIDE);
 
33
                        watchForActivate = true;
 
34
        }
 
35
 
 
36
        public static readonly Icon MonoDevelopIcon = LoadMonoDevelopIcon ();
 
37
 
 
38
        static Icon LoadMonoDevelopIcon ()
 
39
        {
 
40
            // IconSize.Dnd seems to be the best match for Form.Icon
 
41
            var pixbuf = MonoDevelop.Ide.ImageService.GetPixbuf ("md-monodevelop", Gtk.IconSize.Dnd);
 
42
            return new Icon (new System.IO.MemoryStream (pixbuf.SaveToBuffer ("ico")));
 
43
        }
 
44
                
 
45
                protected override void OnClosing (CancelEventArgs args)
 
46
                {
 
47
                        base.OnClosing (args);
 
48
                        if (nativeDialogWindow != null)
 
49
                                nativeDialogWindow.Dispose ();
 
50
                }
 
51
 
 
52
        protected override void WndProc(ref Message m)
 
53
        {       
 
54
                        if (m.Msg == (int)Msg.WM_ACTIVATE && watchForActivate) {
 
55
                                watchForActivate = false;
 
56
                                nativeDialogWindow = new NativeDialogWindow (m.LParam);
 
57
                        }
 
58
 
 
59
            base.WndProc(ref m);
 
60
        }
 
61
                
 
62
                // The CommonDialog's Form Handle
 
63
                class NativeDialogWindow : NativeWindow, IDisposable
 
64
                {
 
65
                        IntPtr handle;
 
66
                        
 
67
                        public NativeDialogWindow (IntPtr handle)
 
68
                        {
 
69
                                this.handle = handle;
 
70
                                AssignHandle (handle);
 
71
                        }
 
72
                        
 
73
                        public void Dispose ()
 
74
                        {
 
75
                                ReleaseHandle ();
 
76
                        }
 
77
                        
 
78
                        protected override void WndProc (ref Message m)
 
79
                        {                                       
 
80
                                /* Disable the handling of the pending events of the
 
81
                                 * MD's UI thread, as we are running them in a separated thread now,
 
82
                                 * but leave them here since we may need them when/if the MD's Main
 
83
                                 * method is marked with the STAThread attribute.
 
84
                                switch (m.Msg) {
 
85
                                        case (int) Msg.WM_ENTERIDLE:
 
86
                                        case (int) Msg.WM_WINDOWPOSCHANGED:
 
87
                                                MonoDevelop.Ide.DispatchService.RunPendingEvents ();
 
88
                                                break;
 
89
                                }
 
90
                                 */
 
91
                                
 
92
                                base.WndProc (ref m);
 
93
                        }
 
94
                }
 
95
    }
 
96
 
 
97
    class WinFormsRunner
 
98
    {
 
99
        bool firstRun = true;
 
100
        EventHandler action;
 
101
 
 
102
        public void Run(EventHandler action)
 
103
        {
 
104
            this.action = action;
 
105
            Application.Idle += WinFormsIdle;
 
106
            Application.Run();
 
107
            Application.Idle -= WinFormsIdle;
 
108
        }
 
109
 
 
110
        void WinFormsIdle(object sender, EventArgs e)
 
111
        {
 
112
            if (firstRun)
 
113
            {
 
114
                firstRun = false;
 
115
                action(null, null);
 
116
            }
 
117
            else
 
118
                MonoDevelop.Ide.DispatchService.RunPendingEvents();
 
119
        }
 
120
    }
 
121
}