5
// Michael Hutchinson <mhutchinson@novell.com>
7
// Copyright (c) 2010 Novell, Inc.
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
using System.Collections.Generic;
29
using System.Runtime.InteropServices;
32
namespace MacIntegration
34
public class IgeMacMenu
36
[DllImport("libigemacintegration.dylib")]
37
static extern void ige_mac_menu_connect_window_key_handler (IntPtr window);
39
public static void ConnectWindowKeyHandler (Gtk.Window window)
41
ige_mac_menu_connect_window_key_handler (window.Handle);
44
[DllImport("libigemacintegration.dylib")]
45
static extern void ige_mac_menu_set_global_key_handler_enabled (bool enabled);
47
public static bool GlobalKeyHandlerEnabled {
49
ige_mac_menu_set_global_key_handler_enabled (value);
53
[DllImport("libigemacintegration.dylib")]
54
static extern void ige_mac_menu_set_menu_bar (IntPtr menu_shell);
56
public static Gtk.MenuShell MenuBar {
58
ige_mac_menu_set_menu_bar (value == null ? IntPtr.Zero : value.Handle);
62
[DllImport("libigemacintegration.dylib")]
63
static extern void ige_mac_menu_set_quit_menu_item (IntPtr quit_item);
65
public static Gtk.MenuItem QuitMenuItem {
67
ige_mac_menu_set_quit_menu_item (value == null ? IntPtr.Zero : value.Handle);
71
[DllImport("libigemacintegration.dylib")]
72
static extern IntPtr ige_mac_menu_add_app_menu_group ();
74
public static IgeMacMenuGroup AddAppMenuGroup ()
76
IntPtr raw_ret = ige_mac_menu_add_app_menu_group();
77
IgeMacMenuGroup ret = raw_ret == IntPtr.Zero ? null : (IgeMacMenuGroup) GLib.Opaque.GetOpaque (raw_ret, typeof (IgeMacMenuGroup), false);
82
public class IgeMacMenuGroup : GLib.Opaque
84
[DllImport("libigemacintegration.dylib")]
85
static extern void ige_mac_menu_add_app_menu_item (IntPtr raw, IntPtr menu_item, IntPtr label);
87
public void AddMenuItem (Gtk.MenuItem menu_item, string label)
89
IntPtr native_label = GLib.Marshaller.StringToPtrGStrdup (label);
90
ige_mac_menu_add_app_menu_item(Handle, menu_item == null ? IntPtr.Zero : menu_item.Handle, native_label);
91
GLib.Marshaller.Free (native_label);
94
public IgeMacMenuGroup (IntPtr raw) : base (raw) {}
97
public static class PlatformDetection
99
public readonly static bool IsWindows;
100
public readonly static bool IsMac;
102
static PlatformDetection ()
104
IsWindows = Path.DirectorySeparatorChar == '\\';
105
IsMac = !IsWindows && IsRunningOnMac();
108
//From Managed.Windows.Forms/XplatUI
109
static bool IsRunningOnMac ()
111
IntPtr buf = IntPtr.Zero;
113
buf = Marshal.AllocHGlobal (8192);
114
// This is a hacktastic way of getting sysname from uname ()
115
if (uname (buf) == 0) {
116
string os = Marshal.PtrToStringAnsi (buf);
122
if (buf != IntPtr.Zero)
123
Marshal.FreeHGlobal (buf);
129
static extern int uname (IntPtr buf);
b'\\ No newline at end of file'