Example #1
0
        void OnAccessibilityShowMenu(object sender, EventArgs args)
        {
            var tab = sender as DockNotebookTab;

            DockNotebook.ActiveNotebook = notebook;
            notebook.CurrentTab         = tab;

            int x = tab.Allocation.X + (tab.Allocation.Width / 2);
            int y = tab.Allocation.Y + (tab.Allocation.Height / 2);

            // Fake an event, but all we need is the x and y.
            // Ugly but the only way without messing up the public API.
            var nativeEvent = new NativeEventButtonStruct {
                x = x,
                y = y,
            };

            IntPtr ptr = GLib.Marshaller.StructureToPtrAlloc(nativeEvent);

            try {
                Gdk.EventButton evnt = new Gdk.EventButton(ptr);
                notebook.DoPopupMenu(notebook, tab.Index, evnt);
            } finally {
                Marshal.FreeHGlobal(ptr);
            }
        }
Example #2
0
        void SendButtonEvent(Widget target, Gdk.EventType eventType, double x, double y, Gdk.ModifierType state, uint button)
        {
            Gdk.Window win = target.GdkWindow;

            int rx, ry;

            win.GetRootOrigin(out rx, out ry);

            var nativeEvent = new NativeEventButtonStruct {
                type       = eventType,
                send_event = 1,
                window     = win.Handle,
                state      = (uint)state,
                button     = button,
                x          = x,
                y          = y,
                axes       = IntPtr.Zero,
                device     = IntPtr.Zero,
                time       = Global.CurrentEventTime,
                x_root     = x + rx,
                y_root     = y + ry
            };

            IntPtr ptr = GLib.Marshaller.StructureToPtrAlloc(nativeEvent);

            try {
                Gdk.EventHelper.Put(new Gdk.EventButton(ptr));
            } finally {
                Marshal.FreeHGlobal(ptr);
            }
        }
Example #3
0
        /// <summary>
        /// Sends a custom button press (click) event to a widget.
        /// </summary>
        /// <param name="target">Widget which should receive the button press event.</param>
        /// <param name="eventType">Type of event to be sent.</param>
        /// <param name="state">Modifiers for the click - ie control click, shift click, etc.</param>
        /// <param name="button">Type of click - ie left click, middle click or right click.</param>
        /// <param name="x">x-coordinate of the click, relative to the top-left corner of the widget.</param>
        /// <param name="y">y-coordinate of the click, relative to the top-left corner of the widget.</param>
        /// <param name="wait">Iff true, will wait for gtk to process the event.</param>
        public static void Click(Widget target, EventType eventType, ModifierType state, ButtonPressType button, double x = 0, double y = 0, bool wait = true)
        {
            Gdk.Window win = target.GdkWindow;

            int rx, ry;

            win.GetRootOrigin(out rx, out ry);

            var nativeEvent = new NativeEventButtonStruct
            {
                type       = eventType,
                send_event = 1,
                window     = win.Handle,
                state      = (uint)state,
                button     = (uint)button,
                x          = x,
                y          = y,
                axes       = IntPtr.Zero,
                device     = IntPtr.Zero,
                time       = Gtk.Global.CurrentEventTime,
                x_root     = x + rx,
                y_root     = y + ry
            };

            IntPtr ptr = GLib.Marshaller.StructureToPtrAlloc(nativeEvent);

            try
            {
                EventHelper.Put(new EventButton(ptr));
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
            }

            if (wait)
            {
                // Clear gtk event loop.
                while (GLib.MainContext.Iteration())
                {
                    ;
                }
            }
        }
		void SendButtonEvent (Widget target, Gdk.EventType eventType, double x, double y, Gdk.ModifierType state, uint button)
		{
			Gdk.Window win = target.GdkWindow;

			int rx, ry;
			win.GetRootOrigin (out rx, out ry);

			var nativeEvent = new NativeEventButtonStruct {
				type = eventType,
				send_event = 1,
				window = win.Handle,
				state = (uint)state,
				button = button,
				x = x,
				y = y,
				axes = IntPtr.Zero,
				device = IntPtr.Zero,
				time = Global.CurrentEventTime,
				x_root = x + rx,
				y_root = y + ry
			};

			IntPtr ptr = GLib.Marshaller.StructureToPtrAlloc (nativeEvent);
			try {
				Gdk.EventHelper.Put (new Gdk.EventButton (ptr));
			} finally {
				Marshal.FreeHGlobal (ptr);
			}
		}