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

« back to all changes in this revision

Viewing changes to external/monomac/src/AppKit/NSApplication.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
1
//
2
2
// Copyright 2010, Novell, Inc.
 
3
// Copyright 2012 Xamarin Inc.
3
4
//
4
5
// Permission is hereby granted, free of charge, to any person obtaining
5
6
// a copy of this software and associated documentation files (the
23
24
using System;
24
25
using System.Reflection;
25
26
using System.Runtime.InteropServices;
 
27
using System.Threading;
26
28
 
27
29
using MonoMac;
28
30
using MonoMac.Foundation;
30
32
 
31
33
namespace MonoMac.AppKit {
32
34
        public partial class NSApplication : NSResponder {
 
35
                public static bool CheckForIllegalCrossThreadCalls = true;
 
36
                private static Thread mainThread;
 
37
 
33
38
                static NSApplication () {
34
39
                        System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof (NSObject).TypeHandle);
35
40
                        class_ptr = Class.GetHandle ("NSApplication");
56
61
                                }
57
62
                        }
58
63
 
 
64
                        // Runtime hosts embedding MonoMac may use a different sync context 
 
65
                        // and call NSApplicationMain externally prior to this Init, so only
 
66
                        // initialize the context if it hasn't been set externally. Alternatively,
 
67
                        // AppKitSynchronizationContext could be made public.
 
68
                        if(SynchronizationContext.Current == null)
 
69
                                SynchronizationContext.SetSynchronizationContext (new AppKitSynchronizationContext ());
 
70
 
 
71
                        // Establish the main thread at the time of Init to support hosts
 
72
                        // that don't call Main.
 
73
                        NSApplication.mainThread = Thread.CurrentThread;
 
74
 
59
75
                        // TODO:
60
76
                        //   Install hook to register dynamically loaded assemblies
61
77
                }
71
87
 
72
88
                public static void Main (string [] args)
73
89
                {
 
90
                        // Switch to an AppKitSynchronizationContext if Main is invoked
 
91
                        if(SynchronizationContext.Current == null || !typeof(AppKitSynchronizationContext).IsAssignableFrom(SynchronizationContext.Current.GetType()))
 
92
                                SynchronizationContext.SetSynchronizationContext (new AppKitSynchronizationContext ());
 
93
 
 
94
                        // Init where this is set the first time is generally paired
 
95
                        // with a call to Main, but this guarantees the right thread.
 
96
                        NSApplication.mainThread = Thread.CurrentThread;
 
97
 
74
98
                        NSApplicationMain (args.Length, args);
75
99
                }
 
100
 
 
101
                public static void EnsureUIThread()
 
102
                {
 
103
                        if (NSApplication.CheckForIllegalCrossThreadCalls && NSApplication.mainThread != Thread.CurrentThread)
 
104
                                throw new AppKitThreadAccessException();
 
105
                }
 
106
 
 
107
                // NSEventMask is a superset (64 bits) of the mask that can be used (32 bits)
 
108
                // NSEventMaskFromType is often used to convert from NSEventType to the mask
 
109
                public NSEvent NextEvent (NSEventMask mask, NSDate expiration, string mode, bool deqFlag)
 
110
                {
 
111
                        return NextEvent ((uint) mask, expiration, mode, deqFlag);
 
112
                }
 
113
 
 
114
                public void DiscardEvents (NSEventMask mask, NSEvent lastEvent)
 
115
                {
 
116
                        DiscardEvents ((uint) mask, lastEvent);
 
117
                }
 
118
 
 
119
                // note: if needed override the protected Get|Set methods
 
120
                public NSApplicationActivationPolicy ActivationPolicy { 
 
121
                        get { return GetActivationPolicy (); }
 
122
                        // ignore return value (bool)
 
123
                        set { SetActivationPolicy (value); }
 
124
                }
76
125
        }
77
 
}
 
126
}
 
 
b'\\ No newline at end of file'