void DoDeactivateApp() { if (driver.Grab.Hwnd != IntPtr.Zero) { driver.SendMessage(driver.Grab.Hwnd, Msg.WM_CANCELMODE, IntPtr.Zero, IntPtr.Zero); driver.Grab.Hwnd = IntPtr.Zero; } driver.SendMessage(XplatUI.GetActive(), Msg.WM_ACTIVATEAPP, (IntPtr)WindowActiveFlags.WA_INACTIVE, IntPtr.Zero); }
public static bool MoveWindow(IntPtr hwnd, int X, int Y, int nWidth, int nHeight, bool bRepaint) { XplatUI.SetWindowPos(hwnd, X, Y, nWidth, nHeight); if (bRepaint) { XplatUI.UpdateWindow(hwnd); } return(true); }
public static IntPtr GetFocusLinux() { if (s_getFocus == null) { s_getFocus = XplatUI.GetMethod("GetFocus", BindingFlags.NonPublic | BindingFlags.Static, null, Type.EmptyTypes, null); } return((IntPtr)s_getFocus.Invoke(null, null)); }
public static void SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags) { // TODO: Handle all remaining flags if (0 == (uFlags & (uint)XplatUIWin32.SetWindowPosFlags.SWP_NOZORDER)) { XplatUI.SetZOrder(hWnd, hWndInsertAfter, true, false); } int x_, y_, w_, h_, clw_, clh_; XplatUI.GetWindowPos(hWnd, false, out x_, out y_, out w_, out h_, out clw_, out clh_); bool move = 0 == (uFlags & (uint)XplatUIWin32.SetWindowPosFlags.SWP_NOMOVE); if (!move) { x = x_; y = y_; } bool size = 0 == (uFlags & (uint)XplatUIWin32.SetWindowPosFlags.SWP_NOSIZE); if (!size) { cx = w_; cy = h_; } if (move || size) { XplatUI.SetWindowPos(hWnd, x, y, cx, cy); } bool visible = XplatUI.IsVisible(hWnd); bool show = 0 != (uFlags & (uint)XplatUIWin32.SetWindowPosFlags.SWP_SHOWWINDOW); bool hide = 0 != (uFlags & (uint)XplatUIWin32.SetWindowPosFlags.SWP_HIDEWINDOW); bool activate = 0 == (uFlags & (uint)XplatUIWin32.SetWindowPosFlags.SWP_NOACTIVATE); if ((show && !visible)) { XplatUI.SetVisible(hWnd, true, activate); } else if ((hide && visible)) { XplatUI.SetVisible(hWnd, false, false); } bool redraw = 0 == (uFlags & (uint)XplatUIWin32.SetWindowPosFlags.SWP_NOREDRAW); if (redraw) { XplatUI.UpdateWindow(hWnd); } }
public static IntPtr GetFocus() { if (s_getFocus == null) { s_getFocus = XplatUI.GetMethod("GetFocus", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static, null, Type.EmptyTypes, null); } return((IntPtr)s_getFocus.Invoke(null, null)); }
public override NSApplicationTerminateReply ApplicationShouldTerminate(NSApplication sender) { bool shouldTerminate = true; if (IsGoingToPowerOff && (DateTime.Now - IsGoingToPowerOfTime).TotalSeconds < IsGoingToPowerOfMaxDelay) { IsGoingToPowerOff = false; // For the case the shutdown is going to be cancelled foreach (var window in NSApplication.SharedApplication.Windows) { if (window.ContentView is MonoContentView) { if (IntPtr.Zero == XplatUI.SendMessage(window.ContentView.Handle, Msg.WM_QUERYENDSESSION, (IntPtr)1, (IntPtr)ENDSESSION_LOGOFF)) { shouldTerminate = false; } } } if (!shouldTerminate) { return(NSApplicationTerminateReply.Cancel); } foreach (var window in NSApplication.SharedApplication.Windows) { if (window.ContentView is MonoContentView) { XplatUI.SendMessage(window.ContentView.Handle, Msg.WM_ENDSESSION, (IntPtr)1, (IntPtr)ENDSESSION_LOGOFF); } } } if (Application.MessageLoop) { var form = Application.MWFThread.Current.Context.MainForm; if (form != null && form.IsHandleCreated && !form.Disposing && !form.IsDisposed && !form.Modal && form.Visible) { form.CloseReason = CloseReason.ApplicationExitCall; XplatUI.PostMessage(form.Handle, Msg.WM_CLOSE, IntPtr.Zero, IntPtr.Zero); return(NSApplicationTerminateReply.Cancel); } else { return(NSApplicationTerminateReply.Now); } } return(NSApplicationTerminateReply.Now); }
/// <summary> /// Please don't use this unless your really have to, and then only if its for sending messages internaly within the application. /// For example sending WM_NCPAINT maybe portable but sending WM_USER + N to another application is definitely not poratable. /// </summary> public static void SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam) { if (Platform.IsDotNet) { NativeSendMessage(hWnd, Msg, wParam, lParam); } else { if (_sendMessage == null) { _sendMessage = XplatUI.GetMethod("SendMessage", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static, null, new Type[] { typeof(IntPtr), typeof(int), typeof(IntPtr), typeof(IntPtr) }, null); } _sendMessage.Invoke(null, new object[] { hWnd, (int)Msg, (IntPtr)wParam, (IntPtr)lParam }); } }
private NSApplicationTerminateReply MonoApplication_ShouldTerminate(NSApplication sender) { bool shouldTerminate = true; var forms = new Collections.ArrayList(Application.OpenForms); forms.Reverse(); if (IsGoingToPowerOff && (DateTime.Now - IsGoingToPowerOfTime).TotalSeconds < IsGoingToPowerOfMaxDelay) { IsGoingToPowerOff = false; // For the case the shutdown is going to be cancelled foreach (Form form in forms) { if (IntPtr.Zero == XplatUI.SendMessage(form.Handle, Msg.WM_QUERYENDSESSION, (IntPtr)1, (IntPtr)ENDSESSION_LOGOFF)) { shouldTerminate = false; } } if (!shouldTerminate) { return(NSApplicationTerminateReply.Cancel); } foreach (Form form in forms) { XplatUI.SendMessage(form.Handle, Msg.WM_ENDSESSION, (IntPtr)1, (IntPtr)ENDSESSION_LOGOFF); } } if (Application.MessageLoop) { foreach (Form form in forms) { form.CloseReason = CloseReason.TaskManagerClosing; XplatUI.SendMessage(form.Handle, Msg.WM_CLOSE, IntPtr.Zero, IntPtr.Zero); if (form.IsHandleCreated) { return(NSApplicationTerminateReply.Cancel); } } } return(NSApplicationTerminateReply.Now); }
internal override void DestroyWindow(IntPtr handle) { X11Hwnd hwnd; hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle); if (hwnd == null) { #if DriverDebug || DriverDebugDestroy Console.WriteLine("window {0:X} already destroyed", handle.ToInt32()); #endif return; } #if DriverDebug || DriverDebugDestroy Console.WriteLine("Destroying window {0}", XplatUI.Window(hwnd.ClientWindow)); #endif display.DestroyWindow(hwnd); }
public static bool GetWindowPlacement(IntPtr hWnd, out WINDOWPLACEMENT lpwndpl) { // TODO: Add support for min & max states lpwndpl = new WINDOWPLACEMENT(); var nsobject = ObjCRuntime.Runtime.GetNSObject(hWnd); if (nsobject == null) { return(false); } var monoView = nsobject as MonoView; if (monoView == null) { return(false); } var window = monoView.Window; var isTopLevelView = window.ContentView.Handle == hWnd; var rScreen = isTopLevelView ? window.Frame // if it's top level view, then we have to use window's frame, because of the caption : monoView.Window.ConvertRectToScreen(monoView.ConvertRectToBase(monoView.Frame)); Size displaySize; XplatUI.GetDisplaySize(out displaySize); lpwndpl.rcNormalPosition = new RECT( (int)rScreen.Left, (int)(displaySize.Height - (rScreen.Top + rScreen.Height)), (int)rScreen.Right, (int)(displaySize.Height - rScreen.Top) ); return(true); }
public override NSMenu ApplicationDockMenu(NSApplication sender) { GCHandle gch = new GCHandle(); try { gch = GCHandle.Alloc(dockMenu); driver.SendMessage(XplatUI.GetActive(), Msg.WM_DOCK_MENU, IntPtr.Zero, GCHandle.ToIntPtr(gch)); } catch (Exception e) { DebugHelper.WriteLine($"Exception in WM_DOCK_MENU handler: {e}"); } finally { if (gch.IsAllocated) { gch.Free(); } } return(dockMenu); }
internal bool TryOpenFiles(string[] filenames, Msg msg = Msg.WM_OPEN_FILES) { GCHandle gch = new GCHandle(); try { gch = GCHandle.Alloc(filenames); var result = driver.SendMessage(XplatUI.GetActive(), msg, IntPtr.Zero, GCHandle.ToIntPtr(gch)); return(result == IntPtr.Zero); } catch (Exception e) { DebugHelper.WriteLine($"Failed opening file(s) or URL(s) [{String.Join(",", filenames)}]: {e}"); return(false); } finally { if (gch.IsAllocated) { gch.Free(); } } }
public static bool UpdateWindow(IntPtr hwnd) { XplatUI.UpdateWindow(hwnd); return(true); }
void DoActivateApp() { driver.SendMessage(XplatUI.GetActive(), Msg.WM_ACTIVATEAPP, (IntPtr)WindowActiveFlags.WA_ACTIVE, IntPtr.Zero); }
public static bool PostMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam) { XplatUI.PostMessage(hWnd, (Msg)msg, wParam, lParam); return(true); }
void DoActivateApp() { XplatUICocoa.UpdateModifiers(NSEvent.CurrentModifierFlags); driver.SendMessage(XplatUI.GetActive(), Msg.WM_ACTIVATEAPP, (IntPtr)WindowActiveFlags.WA_ACTIVE, IntPtr.Zero); }
public static bool EnableWindow(IntPtr hWnd, bool bEnable) { XplatUI.EnableWindow(hWnd, bEnable); return(true); }
public static IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam) { return(XplatUI.SendMessage(hWnd, (Msg)msg, wParam, lParam)); }
public static IntPtr GetFocus() { return(XplatUI.GetFocus()); }
public static bool IsWindowVisible(IntPtr hwnd) { return(XplatUI.IsVisible(hwnd)); }
private void ShowDropDownControl(Control control, bool resizeable) { dropdown_form.Size = control.Size; control.Dock = DockStyle.Fill; if (resizeable) { dropdown_form.Padding = dropdown_form_padding; dropdown_form.Width += dropdown_form_padding.Right; dropdown_form.Height += dropdown_form_padding.Bottom; dropdown_form.FormBorderStyle = FormBorderStyle.Sizable; dropdown_form.SizeGripStyle = SizeGripStyle.Show; } else { dropdown_form.FormBorderStyle = FormBorderStyle.None; dropdown_form.SizeGripStyle = SizeGripStyle.Hide; dropdown_form.Padding = Padding.Empty; } dropdown_form.Controls.Add(control); dropdown_form.Width = Math.Max(ClientRectangle.Width - SplitterLocation - (vbar.Visible ? vbar.Width : 0), control.Width); dropdown_form.Location = PointToScreen(new Point(grid_textbox.Right - dropdown_form.Width, grid_textbox.Location.Y + row_height)); RepositionInScreenWorkingArea(dropdown_form); Point location = dropdown_form.Location; Form owner = FindForm(); owner.AddOwnedForm(dropdown_form); dropdown_form.Show(); if (dropdown_form.Location != location) { dropdown_form.Location = location; } System.Windows.Forms.MSG msg = new MSG(); object queue_id = XplatUI.StartLoop(Thread.CurrentThread); control.Focus(); while (dropdown_form.Visible && XplatUI.GetMessage(queue_id, ref msg, IntPtr.Zero, 0, 0)) { switch (msg.message) { case Msg.WM_NCLBUTTONDOWN: case Msg.WM_NCMBUTTONDOWN: case Msg.WM_NCRBUTTONDOWN: case Msg.WM_LBUTTONDOWN: case Msg.WM_MBUTTONDOWN: case Msg.WM_RBUTTONDOWN: if (!HwndInControl(dropdown_form, msg.hwnd)) { CloseDropDown(); } break; case Msg.WM_ACTIVATE: case Msg.WM_NCPAINT: if (owner.window.Handle == msg.hwnd) { CloseDropDown(); } break; } XplatUI.TranslateMessage(ref msg); XplatUI.DispatchMessage(ref msg); } XplatUI.EndLoop(Thread.CurrentThread); }
public static bool InvalidateRect(IntPtr hwnd, ref Rectangle rect, bool bErase) { XplatUI.Invalidate(hwnd, rect, bErase); return(true); }