本文整理汇总了C#中Gtk.GrabFocus方法的典型用法代码示例。如果您正苦于以下问题:C# Gtk.GrabFocus方法的具体用法?C# Gtk.GrabFocus怎么用?C# Gtk.GrabFocus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gtk
的用法示例。
在下文中一共展示了Gtk.GrabFocus方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GrabWindow
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();
}
}
示例2: ShowContextMenu
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);
});
}
示例3: ShowContextMenu
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);
}
});
}
示例4: ShowContextMenu
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);
});
}
示例5: ShowFixesMenu
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: ShowContextMenu
/// <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: PositionWidget
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: FocusWidget
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: SetFocus
void SetFocus(Gtk.Widget w)
{
if (w.Parent != null)
SetFocus (w.Parent);
w.GrabFocus ();
w.IsFocus = true;
w.HasFocus = true;
}
示例10: initialize
//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();
}
示例11: ShowFixesMenu
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: PositionWidget
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 ();
}