2
2
// Copyright 2010, Novell, Inc.
3
// Copyright 2012 Xamarin Inc.
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
31
33
namespace MonoMac.AppKit {
32
34
public partial class NSApplication : NSResponder {
35
public static bool CheckForIllegalCrossThreadCalls = true;
36
private static Thread mainThread;
33
38
static NSApplication () {
34
39
System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof (NSObject).TypeHandle);
35
40
class_ptr = Class.GetHandle ("NSApplication");
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 ());
71
// Establish the main thread at the time of Init to support hosts
72
// that don't call Main.
73
NSApplication.mainThread = Thread.CurrentThread;
60
76
// Install hook to register dynamically loaded assemblies
72
88
public static void Main (string [] args)
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 ());
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;
74
98
NSApplicationMain (args.Length, args);
101
public static void EnsureUIThread()
103
if (NSApplication.CheckForIllegalCrossThreadCalls && NSApplication.mainThread != Thread.CurrentThread)
104
throw new AppKitThreadAccessException();
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)
111
return NextEvent ((uint) mask, expiration, mode, deqFlag);
114
public void DiscardEvents (NSEventMask mask, NSEvent lastEvent)
116
DiscardEvents ((uint) mask, lastEvent);
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); }
b'\\ No newline at end of file'