~ubuntu-branches/ubuntu/raring/monodevelop/raring

« back to all changes in this revision

Viewing changes to src/tools/mdmonitor/MacIntegration/MacIntegration.cs

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2011-06-29 06:56:25 UTC
  • mfrom: (1.8.1 upstream) (1.3.11 experimental)
  • Revision ID: james.westby@ubuntu.com-20110629065625-7xx19c4vb95j65pl
Tags: 2.5.92+dfsg-1ubuntu1
* Merge from Debian experimental:
 - Dropped patches & changes to debian/control for Moonlight
   + debian/patches/remove_support_for_moonlight.patch,
   + debian/patches/dont_add_moonlight_to_core_addins.patch,
 - Remaining patches:
   + debian/patches/no_appmenu:

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// MacIntegration.cs
 
3
//  
 
4
// Author:
 
5
//       Michael Hutchinson <mhutchinson@novell.com>
 
6
// 
 
7
// Copyright (c) 2010 Novell, Inc.
 
8
// 
 
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:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
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
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
using System.Collections.Generic;
 
29
using System.Runtime.InteropServices;
 
30
using System.IO;
 
31
 
 
32
namespace MacIntegration
 
33
{
 
34
        public class IgeMacMenu
 
35
        {
 
36
                [DllImport("libigemacintegration.dylib")]
 
37
                static extern void ige_mac_menu_connect_window_key_handler (IntPtr window);
 
38
 
 
39
                public static void ConnectWindowKeyHandler (Gtk.Window window)
 
40
                {
 
41
                        ige_mac_menu_connect_window_key_handler (window.Handle);
 
42
                }
 
43
 
 
44
                [DllImport("libigemacintegration.dylib")]
 
45
                static extern void ige_mac_menu_set_global_key_handler_enabled (bool enabled);
 
46
 
 
47
                public static bool GlobalKeyHandlerEnabled {
 
48
                        set { 
 
49
                                ige_mac_menu_set_global_key_handler_enabled (value);
 
50
                        }
 
51
                }
 
52
 
 
53
                [DllImport("libigemacintegration.dylib")]
 
54
                static extern void ige_mac_menu_set_menu_bar (IntPtr menu_shell);
 
55
 
 
56
                public static Gtk.MenuShell MenuBar { 
 
57
                        set {
 
58
                                ige_mac_menu_set_menu_bar (value == null ? IntPtr.Zero : value.Handle);
 
59
                        }
 
60
                }
 
61
 
 
62
                [DllImport("libigemacintegration.dylib")]
 
63
                static extern void ige_mac_menu_set_quit_menu_item (IntPtr quit_item);
 
64
 
 
65
                public static Gtk.MenuItem QuitMenuItem { 
 
66
                        set {
 
67
                                ige_mac_menu_set_quit_menu_item (value == null ? IntPtr.Zero : value.Handle);
 
68
                        }
 
69
                }
 
70
 
 
71
                [DllImport("libigemacintegration.dylib")]
 
72
                static extern IntPtr ige_mac_menu_add_app_menu_group ();
 
73
 
 
74
                public static IgeMacMenuGroup AddAppMenuGroup ()
 
75
                {
 
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);
 
78
                        return ret;
 
79
                }
 
80
        }
 
81
 
 
82
        public class IgeMacMenuGroup : GLib.Opaque
 
83
        {
 
84
                [DllImport("libigemacintegration.dylib")]
 
85
                static extern void ige_mac_menu_add_app_menu_item (IntPtr raw, IntPtr menu_item, IntPtr label);
 
86
 
 
87
                public void AddMenuItem (Gtk.MenuItem menu_item, string label)
 
88
                {
 
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);
 
92
                }
 
93
 
 
94
                public IgeMacMenuGroup (IntPtr raw) : base (raw) {}
 
95
        }
 
96
        
 
97
        public static class PlatformDetection
 
98
        {
 
99
                public readonly static bool IsWindows;
 
100
                public readonly static bool IsMac;
 
101
         
 
102
                static PlatformDetection ()
 
103
                {
 
104
                        IsWindows = Path.DirectorySeparatorChar == '\\';
 
105
                        IsMac = !IsWindows && IsRunningOnMac();
 
106
                }
 
107
         
 
108
                //From Managed.Windows.Forms/XplatUI
 
109
                static bool IsRunningOnMac ()
 
110
                {
 
111
                        IntPtr buf = IntPtr.Zero;
 
112
                        try {
 
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);
 
117
                                        if (os == "Darwin")
 
118
                                                return true;
 
119
                                }
 
120
                        } catch {
 
121
                        } finally {
 
122
                                if (buf != IntPtr.Zero)
 
123
                                        Marshal.FreeHGlobal (buf);
 
124
                        }
 
125
                        return false;
 
126
                }
 
127
         
 
128
                [DllImport ("libc")]
 
129
                static extern int uname (IntPtr buf);
 
130
        }
 
131
}
 
 
b'\\ No newline at end of file'