using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
-#if NET_2_0
using System.Text;
-#endif
using System.Windows.Forms.VisualStyles;
namespace System.Windows.Forms
private static readonly ArrayList message_filters = new ArrayList();
private static readonly FormCollection forms = new FormCollection ();
-#if NET_2_0
private static bool use_wait_cursor;
private static ToolStrip keyboard_capture;
-#endif
private static VisualStyleState visual_style_state = VisualStyleState.ClientAndNonClientAreasEnabled;
static bool visual_styles_enabled;
browser_embedded = false;
}
-#if NET_2_0
static Application ()
{
// Attempt to load UIA support for winforms
// UIA support requires .NET 2.0
InitializeUIAutomation ();
}
-#endif
#region Private Methods
-#if NET_2_0
private static void InitializeUIAutomation ()
{
- // Initialize the UIAutomationWinforms FormListener
- // class, which signs up for the PreRun and FormAdded
- // events so that it can provide a11y support for MWF.
- string uia_winforms_assembly = "UIAutomationWinforms, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f4ceacb585d99812";
- string listener_type_name = string.Empty;
- string init_method_name = "Initialize";
+ // Initialize the UIAutomationWinforms Global class,
+ // which create some listeners which subscribe to internal
+ // MWF events so that it can provide a11y support for MWF
+ const string UIA_WINFORMS_ASSEMBLY =
+ "UIAutomationWinforms, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f4ceacb585d99812";
MethodInfo init_method;
-
Assembly mwf_providers = null;
try {
- mwf_providers = Assembly.Load (uia_winforms_assembly);
+ mwf_providers = Assembly.Load (UIA_WINFORMS_ASSEMBLY);
} catch { }
if (mwf_providers == null)
return;
-
+
+ const string UIA_WINFORMS_TYPE = "Mono.UIAutomation.Winforms.Global";
+ const string UIA_WINFORMS_METHOD = "Initialize";
try {
- //FormListener
- listener_type_name = "Mono.UIAutomation.Winforms.FormListener";
- Type listener_type = mwf_providers.GetType (listener_type_name, false);
- if (listener_type != null) {
- init_method = listener_type.GetMethod (init_method_name, BindingFlags.Static | BindingFlags.Public);
- if (init_method != null)
- init_method.Invoke (null, new object [] {});
- }
- //ToolTipListener
- listener_type_name = "Mono.UIAutomation.Winforms.ToolTipListener";
- listener_type = mwf_providers.GetType (listener_type_name, false);
- if (listener_type != null) {
- init_method = listener_type.GetMethod (init_method_name, BindingFlags.Static | BindingFlags.Public);
- if (init_method != null)
- init_method.Invoke (null, new object [] {});
- }
- //HelpProviderListener
- listener_type_name = "Mono.UIAutomation.Winforms.HelpProviderListener";
- listener_type = mwf_providers.GetType (listener_type_name, false);
- if (listener_type != null) {
- init_method = listener_type.GetMethod (init_method_name, BindingFlags.Static | BindingFlags.Public);
- if (init_method != null)
- init_method.Invoke (null, new object [] {});
- }
- //ErrorProviderListener
- listener_type_name = "Mono.UIAutomation.Winforms.ErrorProviderListener";
- listener_type = mwf_providers.GetType (listener_type_name, false);
- if (listener_type != null) {
- init_method = listener_type.GetMethod (init_method_name, BindingFlags.Static | BindingFlags.Public);
+ Type global_type = mwf_providers.GetType (UIA_WINFORMS_TYPE, false);
+ if (global_type != null) {
+ init_method = global_type.GetMethod (UIA_WINFORMS_METHOD,
+ BindingFlags.Static |
+ BindingFlags.Public);
if (init_method != null)
init_method.Invoke (null, new object [] {});
+ else
+ throw new Exception (String.Format ("Method {0} not found in type {1}.",
+ UIA_WINFORMS_METHOD, UIA_WINFORMS_TYPE));
}
+ else
+ throw new Exception (String.Format ("Type {0} not found in assembly {1}.",
+ UIA_WINFORMS_TYPE, UIA_WINFORMS_ASSEMBLY));
} catch (Exception ex) {
Console.Error.WriteLine ("Error setting up UIA: " + ex);
}
-
-
}
-#endif
internal static void CloseForms (Thread thread)
{
}
}
-#if NET_2_0
public static bool UseWaitCursor {
get {
return use_wait_cursor;
}
}
}
-#endif
-
-#if NET_2_0
- public
-#else
- internal
-#endif
- static bool RenderWithVisualStyles {
+
+ public static bool RenderWithVisualStyles {
get {
if (VisualStyleInformation.IsSupportedByOS) {
if (!VisualStyleInformation.IsEnabledByUser)
}
}
-#if NET_2_0
- public
-#else
- internal
-#endif
- static VisualStyleState VisualStyleState {
+ public static VisualStyleState VisualStyleState {
get { return Application.visual_style_state; }
set { Application.visual_style_state = value; }
}
XplatUI.EnableThemes ();
}
-#if NET_2_0
[EditorBrowsable (EditorBrowsableState.Advanced)]
- public
-#endif
- static bool FilterMessage (ref Message message)
+ public static bool FilterMessage (ref Message message)
{
lock (message_filters) {
for (int i = 0; i < message_filters.Count; i++) {
return false;
}
-#if NET_2_0
//
// If true, it uses GDI+, performance reasons were quoted
//
Application.Exit ();
Process.Start (procInfo);
}
-#endif
public static void Exit ()
{
-#if NET_2_0
Exit (new CancelEventArgs ());
-#else
- XplatUI.PostQuitMessage (0);
- CloseForms (null);
-#endif
}
-#if NET_2_0
[EditorBrowsable (EditorBrowsableState.Advanced)]
public static void Exit (CancelEventArgs e)
{
XplatUI.PostQuitMessage (0);
}
-#endif
public static void ExitThread()
{
Run (new ApplicationContext (mainForm));
}
+ internal static void FirePreRun ()
+ {
+ EventHandler handler = PreRun;
+ if (handler != null)
+ handler (null, EventArgs.Empty);
+ }
+
public static void Run (ApplicationContext context)
{
-#if NET_2_0
- // Signal that the Application loop is about to run.
- // This allows UIA to initialize a11y support for MWF
- // before the main loop begins.
- if (PreRun != null)
- PreRun (null, EventArgs.Empty);
// If a sync context hasn't been created by now, create
// a default one
if (SynchronizationContext.Current == null)
SynchronizationContext.SetSynchronizationContext (new SynchronizationContext ());
-#endif
RunLoop (false, context);
-#if NET_2_0
// Reset the sync context back to the default
if (SynchronizationContext.Current is WindowsFormsSynchronizationContext)
WindowsFormsSynchronizationContext.Uninstall ();
-#endif
}
private static void DisableFormsForModalLoop (Queue toplevels, ApplicationContext context)
Control c;
c = Control.FromHandle(msg.hwnd);
-#if NET_2_0
// If we have a control with keyboard capture (usually a *Strip)
// give it the message, and then drop the message
if (keyboard_capture != null) {
// WM_SYSKEYUP does not make it into ProcessCmdKey, so do it here
- if ((Msg)m.Msg == Msg.WM_SYSKEYUP)
+ if ((Msg)m.Msg == Msg.WM_SYSKEYDOWN)
if (m.WParam.ToInt32() == (int)Keys.Menu) {
keyboard_capture.GetTopLevelToolStrip ().Dismiss (ToolStripDropDownCloseReason.Keyboard);
continue;
break;
}
}
-#endif
if (((c != null) && c.PreProcessControlMessageInternal (ref m) != PreProcessControlState.MessageProcessed) ||
(c == null)) {
goto default;
}
break;
-#if NET_2_0
+
case Msg.WM_LBUTTONDOWN:
case Msg.WM_MBUTTONDOWN:
case Msg.WM_RBUTTONDOWN:
if (keyboard_capture != null) {
Control c2 = Control.FromHandle (msg.hwnd);
-
+
+ // the target is not a winforms control (an embedded control, perhaps), so
+ // release everything
+ if (c2 == null) {
+ ToolStripManager.FireAppClicked ();
+ goto default;
+ }
+
// If we clicked a ToolStrip, we have to make sure it isn't
// the one we are on, or any of its parents or children
// If we clicked off the dropped down menu, release everything
}
goto default;
-#endif
+
case Msg.WM_QUIT:
quit = true; // make sure we exit
break;
break;
}
- // Handle exit, Form might have received WM_CLOSE and set 'closing' in response
+ // If our Form doesn't have a handle anymore, it means it was destroyed and we need to *wait* for WM_QUIT.
+ if ((context.MainForm != null) && (!context.MainForm.IsHandleCreated))
+ continue;
+
+ // Handle exit, Form might have received WM_CLOSE and set 'closing' in response.
if ((context.MainForm != null) && (context.MainForm.closing || (Modal && !context.MainForm.Visible))) {
if (!Modal) {
XplatUI.PostQuitMessage (0);
public static event EventHandler ThreadExit;
public static event ThreadExceptionEventHandler ThreadException;
-#if NET_2_0
// These are used externally by the UIA framework
internal static event EventHandler FormAdded;
internal static event EventHandler PreRun;
+#pragma warning disable 0067
+ [MonoTODO]
[EditorBrowsable (EditorBrowsableState.Advanced)]
public static event EventHandler EnterThreadModal;
+ [MonoTODO]
[EditorBrowsable (EditorBrowsableState.Advanced)]
public static event EventHandler LeaveThreadModal;
-#endif
+#pragma warning restore 0067
#endregion // Events
#region Public Delegates
-#if NET_2_0
[EditorBrowsable (EditorBrowsableState.Advanced)]
public delegate bool MessageLoopCallback ();
-#endif
#endregion
#region Internal Properties
-#if NET_2_0
internal static ToolStrip KeyboardCapture {
get { return keyboard_capture; }
set { keyboard_capture = value; }
}
-#endif
internal static bool VisualStylesEnabled {
get { return visual_styles_enabled; }
{
lock (forms)
forms.Add (f);
-#if NET_2_0
// Signal that a Form has been added to this
// Application. Used by UIA to detect new Forms that
// need a11y support. This event may be fired even if
// account for that when handling this signal.
if (FormAdded != null)
FormAdded (f, null);
-#endif
}
internal static void RemoveForm (Form f)
forms.Remove (f);
}
-#if NET_2_0
private static bool ControlOnToolStrip (Control c)
{
Control p = c.Parent;
return false;
}
-#endif
// Takes a starting path, appends company name, product name, and
// product version. If the directory doesn't exist, create it