public static void GrabWindow( Gtk.Window window )
        {
            window.GrabFocus();

            Grab.Add(window);

            Gdk.GrabStatus grabbed   = Gdk.Pointer.Grab(window.GdkWindow, true,
                                        Gdk.EventMask.ButtonPressMask
                                        | Gdk.EventMask.ButtonReleaseMask
                                        | Gdk.EventMask.PointerMotionMask, null, null, CURRENT_TIME);

            if (grabbed == Gdk.GrabStatus.Success)
            {
                grabbed = Gdk.Keyboard.Grab(window.GdkWindow, true, CURRENT_TIME);

                if (grabbed != Gdk.GrabStatus.Success)
                {
                    Grab.Remove(window);
                    window.Destroy();
                }
            }
            else
            {
                Grab.Remove(window);
                window.Destroy();
            }
        }
		public static void ShowContextMenu (Gtk.Widget parent, int x, int y, NSMenu menu)
		{
			if (parent == null)
				throw new ArgumentNullException ("parent");
			if (menu == null)
				throw new ArgumentNullException ("menu");

			parent.GrabFocus ();

			Gtk.Application.Invoke (delegate {
				// Explicitly release the grab because the menu is shown on the mouse position, and the widget doesn't get the mouse release event
				Gdk.Pointer.Ungrab (Gtk.Global.CurrentEventTime);
				var nsview = MonoDevelop.Components.Mac.GtkMacInterop.GetNSView (parent);
				var toplevel = parent.Toplevel as Gtk.Window;

				var nswindow = MonoDevelop.Components.Mac.GtkMacInterop.GetNSWindow (toplevel);
				var titleBarHeight = MonoDevelop.Components.Mac.GtkMacInterop.GetTitleBarHeight ();
				var pt = new CoreGraphics.CGPoint (x, nswindow.Frame.Height - y - titleBarHeight - 12);

				var tmp_event = NSEvent.MouseEvent (NSEventType.LeftMouseDown,
					pt,
					0, 0,
					nswindow.WindowNumber,
					null, 0, 0, 0);

				NSMenu.PopUpContextMenu (menu, tmp_event, nsview);
			});
		}
		public static void ShowContextMenu (Gtk.Widget parent, int x, int y, NSMenu menu, bool selectFirstItem = false)
		{
			if (parent == null)
				throw new ArgumentNullException ("parent");
			if (menu == null)
				throw new ArgumentNullException ("menu");

			parent.GrabFocus ();

			Gtk.Application.Invoke (delegate {
				// Explicitly release the grab because the menu is shown on the mouse position, and the widget doesn't get the mouse release event
				Gdk.Pointer.Ungrab (Gtk.Global.CurrentEventTime);
				var nsview = MonoDevelop.Components.Mac.GtkMacInterop.GetNSView (parent);
				var toplevel = parent.Toplevel as Gtk.Window;

				var nswindow = MonoDevelop.Components.Mac.GtkMacInterop.GetNSWindow (toplevel);

				int titleBarOffset;
				if (toplevel.TypeHint == Gdk.WindowTypeHint.Toolbar && toplevel.Type == Gtk.WindowType.Toplevel && toplevel.Decorated == false) {
					// Undecorated toplevel toolbars are used for auto-hide pad windows. Don't add a titlebar offset for them.
					titleBarOffset = 0;
				} else if (MonoDevelop.Ide.DesktopService.GetIsFullscreen (toplevel)) {
					titleBarOffset = 0;
				} else {
					titleBarOffset = MonoDevelop.Components.Mac.GtkMacInterop.GetTitleBarHeight () + 12;
				}

				if (selectFirstItem) {
					var pt = new CoreGraphics.CGPoint (x, y);
					menu.PopUpMenu (menu.ItemAt (0), pt, nsview);
				} else {
					var pt = new CoreGraphics.CGPoint (x, nswindow.Frame.Height - y - titleBarOffset);

					var tmp_event = NSEvent.MouseEvent (NSEventType.LeftMouseDown,
					                                pt,
					                                0, 0,
					                                nswindow.WindowNumber,
					                                null, 0, 0, 0);
					NSMenu.PopUpContextMenu (menu, tmp_event, nsview);
				}


			});
		}
		public static void ShowContextMenu (Gtk.Widget parent, Gdk.EventButton evt, NSMenu menu)
		{
			if (parent == null)
				throw new ArgumentNullException ("parent");
			if (menu == null)
				throw new ArgumentNullException ("menu");

			parent.GrabFocus ();
			int x, y;
			if (evt != null) {
				x = (int)evt.X;
				y = (int)evt.Y;
			} else {
				Gdk.ModifierType mod;
				parent.GdkWindow.GetPointer (out x, out y, out mod);

				var titleBarHeight = MonoDevelop.Components.Mac.GtkMacInterop.GetTitleBarHeight ();
				y -= titleBarHeight;
			}

			Gtk.Application.Invoke (delegate {
				// Explicitly release the grab because the menu is shown on the mouse position, and the widget doesn't get the mouse release event
				Gdk.Pointer.Ungrab (Gtk.Global.CurrentEventTime);
				var nsview = MonoDevelop.Components.Mac.GtkMacInterop.GetNSView (parent);
				var toplevel = parent.Toplevel as Gtk.Window;

				var screenPoint = NSEvent.CurrentMouseLocation;
				var screenRect = new CoreGraphics.CGRect (screenPoint.X, screenPoint.Y, 0, 0);
				var nswindow = MonoDevelop.Components.Mac.GtkMacInterop.GetNSWindow (toplevel);
				var rect = nswindow.ConvertRectFromScreen (screenRect);
				var pt = rect.Location;

				var tmp_event = NSEvent.MouseEvent (NSEventType.LeftMouseDown,
					pt,
					0, 0,
					nswindow.WindowNumber,
					null, 0, 0, 0);

				NSMenu.PopUpContextMenu (menu, tmp_event, nsview);
			});
		}
		bool ShowFixesMenu (Gtk.Widget parent, Gdk.Rectangle evt, FixMenuDescriptor entrySet)
		{
			if (parent == null || parent.GdkWindow == null) {
				Editor.SuppressTooltips = false;
				return true;
			}

			try {
				parent.GrabFocus ();
				int x, y;
				x = (int)evt.X;
				y = (int)evt.Y;

				// Explicitly release the grab because the menu is shown on the mouse position, and the widget doesn't get the mouse release event
				Gdk.Pointer.Ungrab (Gtk.Global.CurrentEventTime);

				var menu = CreateContextMenu (entrySet);
				menu.Show (parent, x, y, () => Editor.SuppressTooltips = false, true);
			} catch (Exception ex) {
				LoggingService.LogError ("Error while context menu popup.", ex);
			}
			return true;
		}
示例#6
0
		/// <summary>
		/// Shows a context menu.
		/// </summary>
		/// <param name='parent'>
		/// Widget for which the context menu is being shown
		/// </param>
		/// <param name='evt'>
		/// Current event
		/// </param>
		/// <param name='entrySet'>
		/// Entry with the command definitions
		/// </param>
		/// <param name='initialCommandTarget'>
		/// Initial command route target. The command handler will start looking for command handlers in this object.
		/// </param>
		public bool ShowContextMenu (Gtk.Widget parent, Gdk.EventButton evt, CommandEntrySet entrySet,
			object initialCommandTarget = null)
		{
			if (Platform.IsMac) {
				parent.GrabFocus ();
				int x, y;
				if (evt != null) {
					x = (int)evt.X;
					y = (int)evt.Y;
				} else {
					Gdk.Display.Default.GetPointer (out x, out y);
				}
				return DesktopService.ShowContextMenu (this, parent, x, y, entrySet, initialCommandTarget);
			} else {
				var menu = CreateMenu (entrySet);
				if (menu != null)
					ShowContextMenu (parent, evt, menu, initialCommandTarget);

				return true;
			}
		}
示例#7
0
文件: PathBar.cs 项目: msiyer/Pinta
		void PositionWidget (Gtk.Widget widget)
		{
			if (!(widget is Gtk.Window))
				return;
			int ox, oy;
			ParentWindow.GetOrigin (out ox, out oy);
			int w;
			int itemXPosition = GetHoverXPosition (out w);
			int dx = ox + this.Allocation.X + itemXPosition;
			int dy = oy + this.Allocation.Bottom;
			
			var req = widget.SizeRequest ();
			
			Gdk.Rectangle geometry = GtkWorkarounds.GetUsableMonitorGeometry (Screen, Screen.GetMonitorAtPoint (dx, dy));
			int width = System.Math.Max (req.Width, w);
			if (width >= geometry.Width - spacing * 2) {
				width = geometry.Width - spacing * 2;
				dx = geometry.Left + spacing;
			}
			widget.WidthRequest = width;
			if (dy + req.Height > geometry.Bottom)
				dy = oy + this.Allocation.Y - req.Height;
			if (dx + width > geometry.Right)
				dx = geometry.Right - width;
			(widget as Gtk.Window).Move (dx, dy);
			(widget as Gtk.Window).Resize (width, req.Height);
			widget.GrabFocus ();
		}
示例#8
0
 bool FocusWidget(Gtk.Widget widget)
 {
     if (widget.HasFocus)
         return true;
     if (widget.CanFocus) {
         widget.GrabFocus ();
         return true;
     }
     var container = widget as Gtk.Container;
     if (container != null) {
         var chain = container.FocusChain;
         System.Collections.IEnumerable children = chain.Length > 0 ? chain : container.AllChildren;
         foreach (Gtk.Widget child in children)
             if (FocusWidget (child))
                 return true;
     }
     return false;
 }
示例#9
0
 void SetFocus(Gtk.Widget w)
 {
     if (w.Parent != null)
         SetFocus (w.Parent);
     w.GrabFocus ();
     w.IsFocus = true;
     w.HasFocus = true;
 }
示例#10
0
        //This method handles TWO files:
        //(1) The file to initialize as the dictionary. Passed as `fi'
        //(2) The settings file. Refer to `settingsFile' member.
        static void initialize(FileInfo fi, Gtk.Entry input, Gtk.Button send, Gtk.Notebook nb, Gtk.Button leftButton, Gtk.Button rightButton)
        {
            if(teh != null)
            {
                teh.disconnectFromLog();
                teh = null;
            }
            teh = loadFile(fi.FullName);
            teh.connectToLog();

            if(!monitor.IsAlive)
            {
                monitor.Start();
            }
            else
            {
                monitor.Abort();
                monitor = new System.Threading.Thread(MainClass.ConsoleEater);
                monitor.Start();
            }

            if(!teh.reparse())
            {
                Gtk.MessageDialog m_d = new Gtk.MessageDialog(mainwindow, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Ok, "Error: Your dictionary file could not be parsed. Make sure it is not open in any other application, check the format, and try again.", new object[]{"Ok"});
                m_d.Run();
                System.Environment.Exit(0);
            }

            //We're still here, there were no fatal exceptions, so this dict is "safe" for opening on startup (we hope)
            //Remember this fact in the .tehthuconfig file.
            if(settingsFile != null)
            {
                TextWriter tw = new StreamWriter(settingsFile.OpenWrite());
                tw.WriteLine(teh.getFile().FullName);
                tw.Flush();
                tw.Close();
            }

            input.IsEditable = true;
            input.Sensitive = true;
            send.Sensitive = true;

            Gtk.Label inputTabLabel = (Gtk.Label) nb.GetTabLabel(nb.GetNthPage(0));
            inputTabLabel.Text = "Input ("
                + (leftToRight ? teh.getLeftLanguageName() : teh.getRightLanguageName())
                + ")";

            Gtk.Label outputTabLabel = (Gtk.Label) nb.GetTabLabel(nb.GetNthPage(1));
            outputTabLabel.Text = "Output ("
                + (leftToRight ? teh.getRightLanguageName() : teh.getLeftLanguageName())
                + ")";

            leftButton.Label = teh.getLeftLanguageName() + "-to-" + teh.getRightLanguageName();
            rightButton.Label = teh.getRightLanguageName() + "-to-" + teh.getLeftLanguageName();
            input.GrabFocus();
        }
		bool ShowFixesMenu (Gtk.Widget parent, Gdk.Rectangle evt, FixMenuDescriptor entrySet)
		{
			if (parent == null || parent.GdkWindow == null)
				return true;
			try {
				#if MAC
				parent.GrabFocus ();
				int x, y;
				x = (int)evt.X;
				y = (int)evt.Y;
				// Explicitly release the grab because the menu is shown on the mouse position, and the widget doesn't get the mouse release event
				Gdk.Pointer.Ungrab (Gtk.Global.CurrentEventTime);
				var menu = CreateNSMenu (entrySet);
				menu.Delegate = new ClosingMenuDelegate (document.Editor);
				var nsview = MonoDevelop.Components.Mac.GtkMacInterop.GetNSView (parent);
				var toplevel = parent.Toplevel as Gtk.Window;
				int trans_x, trans_y;
				parent.TranslateCoordinates (toplevel, (int)x, (int)y, out trans_x, out trans_y);

				// Window coordinates in gtk are the same for cocoa, with the exception of the Y coordinate, that has to be flipped.
				var pt = new CoreGraphics.CGPoint ((float)trans_x, (float)trans_y);
				int w,h;
				toplevel.GetSize (out w, out h);
				pt.Y = h - pt.Y;

				var tmp_event = AppKit.NSEvent.MouseEvent (AppKit.NSEventType.LeftMouseDown,
				pt,
				0, 0,
				MonoDevelop.Components.Mac.GtkMacInterop.GetNSWindow (toplevel).WindowNumber,
				null, 0, 0, 0);

				AppKit.NSMenu.PopUpContextMenu (menu, tmp_event, nsview);
				#else
				var menu = CreateGtkMenu (entrySet);
				menu.Events |= Gdk.EventMask.AllEventsMask;
				menu.SelectFirst (true);

				menu.Hidden += delegate {
					document.Editor.SuppressTooltips = false;
				};
				menu.ShowAll ();
				menu.SelectFirst (true);
				menu.MotionNotifyEvent += (o, args) => {
					if (args.Event.Window == Editor.Parent.TextArea.GdkWindow) {
						StartMenuCloseTimer ();
					} else {
						CancelMenuCloseTimer ();
					}
				};

				GtkWorkarounds.ShowContextMenu (menu, parent, null, evt);
				#endif
			} catch (Exception ex) {
				LoggingService.LogError ("Error while context menu popup.", ex);
			}
			return true;
		}
示例#12
0
		void PositionWidget (Gtk.Widget widget)
		{
			if (!(widget is Gtk.Window))
				return;
			int ox, oy;
			ParentWindow.GetOrigin (out ox, out oy);
			int w;
			int dx = ox + this.Allocation.X + GetHoverXPosition (out w);
			int dy = oy + this.Allocation.Bottom;
			
			var req = widget.SizeRequest ();
			
			int width = System.Math.Max (req.Width, w);
			widget.WidthRequest = width;
			Gdk.Rectangle geometry = Screen.GetMonitorGeometry (Screen.GetMonitorAtPoint (dx, dy));
			
			if (dy + req.Height > geometry.Bottom)
				dy = oy + this.Allocation.Y - req.Height;
			if (dx + width > geometry.Right)
				dx = geometry.Right - width;
			(widget as Gtk.Window).Move (dx, dy);
			widget.GrabFocus ();
		}
示例#13
0
		/// <summary>
		/// Shows a context menu.
		/// </summary>
		/// <param name='parent'>
		/// Widget for which the context menu is being shown
		/// </param>
		/// <param name='evt'>
		/// Current event
		/// </param>
		/// <param name='entrySet'>
		/// Entry with the command definitions
		/// </param>
		/// <param name='initialCommandTarget'>
		/// Initial command route target. The command handler will start looking for command handlers in this object.
		/// </param>
		public bool ShowContextMenu (Gtk.Widget parent, Gdk.EventButton evt, CommandEntrySet entrySet,
			object initialCommandTarget = null)
		{
			if (Platform.IsMac) {
				parent.GrabFocus ();
				return DesktopService.ShowContextMenu (this, parent, evt.X, evt.Y, entrySet);
			} else {
				var menu = CreateMenu (entrySet);
				if (menu != null)
					ShowContextMenu (parent, evt, menu, initialCommandTarget);

				return true;
			}
		}