~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/addins/MacPlatform/Framework/Carbon.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// 
2
 
// Carbon.cs
3
 
//  
4
 
// Author:
5
 
//       Michael Hutchinson <mhutchinson@novell.com>
6
 
//       Geoff Norton  <gnorton@novell.com>
7
 
// 
8
 
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
9
 
// 
10
 
// Permission is hereby granted, free of charge, to any person obtaining a copy
11
 
// of this software and associated documentation files (the "Software"), to deal
12
 
// in the Software without restriction, including without limitation the rights
13
 
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
 
// copies of the Software, and to permit persons to whom the Software is
15
 
// furnished to do so, subject to the following conditions:
16
 
// 
17
 
// The above copyright notice and this permission notice shall be included in
18
 
// all copies or substantial portions of the Software.
19
 
// 
20
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
 
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
 
// THE SOFTWARE.
27
 
 
28
 
using System;
29
 
using System.Runtime.InteropServices;
30
 
using System.Collections.Generic;
31
 
using System.Diagnostics;
32
 
 
33
 
namespace OSXIntegration.Framework
34
 
{
35
 
        internal delegate CarbonEventHandlerStatus EventDelegate (IntPtr callRef, IntPtr eventRef, IntPtr userData);
36
 
        internal delegate CarbonEventHandlerStatus AEHandlerDelegate (IntPtr inEvnt, IntPtr outEvt, uint refConst);
37
 
        
38
 
        internal static class Carbon
39
 
        {
40
 
                public const string CarbonLib = "/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon";
41
 
                
42
 
                [DllImport (CarbonLib)]
43
 
                public static extern IntPtr GetApplicationEventTarget ();
44
 
                
45
 
                [DllImport (CarbonLib)]
46
 
                public static extern IntPtr GetControlEventTarget (IntPtr control);
47
 
                
48
 
                [DllImport (CarbonLib)]
49
 
                public static extern IntPtr GetWindowEventTarget (IntPtr window);
50
 
                
51
 
                [DllImport (CarbonLib)]
52
 
                public static extern IntPtr GetMenuEventTarget (IntPtr menu);
53
 
 
54
 
                [DllImport (CarbonLib)]
55
 
                public static extern CarbonEventClass GetEventClass (IntPtr eventref);
56
 
                
57
 
                [DllImport (CarbonLib)]
58
 
                public static extern uint GetEventKind (IntPtr eventref);
59
 
                
60
 
                #region Event handler installation
61
 
                
62
 
                [DllImport (CarbonLib)]
63
 
                static extern EventStatus InstallEventHandler (IntPtr target, EventDelegate handler, uint count,
64
 
                                                               CarbonEventTypeSpec [] types, IntPtr user_data, out IntPtr handlerRef);
65
 
                
66
 
                [DllImport (CarbonLib)]
67
 
                public static extern EventStatus RemoveEventHandler (IntPtr handlerRef);
68
 
                
69
 
                public static IntPtr InstallEventHandler (IntPtr target, EventDelegate handler, CarbonEventTypeSpec [] types)
70
 
                {
71
 
                        IntPtr handlerRef;
72
 
                        CheckReturn (InstallEventHandler (target, handler, (uint)types.Length, types, IntPtr.Zero, out handlerRef));
73
 
                        return handlerRef;
74
 
                }
75
 
                
76
 
                public static IntPtr InstallEventHandler (IntPtr target, EventDelegate handler, CarbonEventTypeSpec type)
77
 
                {
78
 
                        return InstallEventHandler (target, handler, new CarbonEventTypeSpec[] { type });
79
 
                }
80
 
                
81
 
                public static IntPtr InstallApplicationEventHandler (EventDelegate handler, CarbonEventTypeSpec [] types)
82
 
                {
83
 
                        return InstallEventHandler (GetApplicationEventTarget (), handler, types);
84
 
                }
85
 
                
86
 
                public static IntPtr InstallApplicationEventHandler (EventDelegate handler, CarbonEventTypeSpec type)
87
 
                {
88
 
                        return InstallEventHandler (GetApplicationEventTarget (), handler, new CarbonEventTypeSpec[] { type });
89
 
                }
90
 
                
91
 
                #endregion
92
 
                
93
 
                #region Event parameter extraction
94
 
                
95
 
                [DllImport (CarbonLib)]
96
 
                public static extern EventStatus GetEventParameter (IntPtr eventRef, CarbonEventParameterName name, CarbonEventParameterType desiredType,
97
 
                                                                    out CarbonEventParameterType actualType, uint size, ref uint outSize, ref IntPtr outPtr);
98
 
                
99
 
                public static IntPtr GetEventParameter (IntPtr eventRef, CarbonEventParameterName name, CarbonEventParameterType desiredType)
100
 
                {
101
 
                        CarbonEventParameterType actualType;
102
 
                        uint outSize = 0;
103
 
                        IntPtr val = IntPtr.Zero;
104
 
                        CheckReturn (GetEventParameter (eventRef, name, desiredType, out actualType, (uint)IntPtr.Size, ref outSize, ref val));
105
 
                        return val;
106
 
                } 
107
 
                
108
 
                [DllImport (CarbonLib)]
109
 
                static extern EventStatus GetEventParameter (IntPtr eventRef, CarbonEventParameterName name, CarbonEventParameterType desiredType,      
110
 
                                                             out CarbonEventParameterType actualType, uint size, ref uint outSize, IntPtr dataBuffer);
111
 
                  
112
 
                [DllImport (CarbonLib)]
113
 
                static extern EventStatus GetEventParameter (IntPtr eventRef, CarbonEventParameterName name, CarbonEventParameterType desiredType,      
114
 
                                                             uint zero, uint size, uint zero2, IntPtr dataBuffer);
115
 
                
116
 
                public static T GetEventParameter<T> (IntPtr eventRef, CarbonEventParameterName name, CarbonEventParameterType desiredType) where T : struct
117
 
                {
118
 
                        int len = Marshal.SizeOf (typeof (T));
119
 
                        IntPtr bufferPtr = Marshal.AllocHGlobal (len);
120
 
                        CheckReturn (GetEventParameter (eventRef, name, desiredType, 0, (uint)len, 0, bufferPtr));
121
 
                        T val = (T)Marshal.PtrToStructure (bufferPtr, typeof (T));
122
 
                        Marshal.FreeHGlobal (bufferPtr);
123
 
                        return val;
124
 
                }
125
 
                
126
 
                #endregion
127
 
                
128
 
                #region Sending events
129
 
                
130
 
                [DllImport (CarbonLib)]
131
 
                static extern EventStatus SendEventToEventTarget (IntPtr eventRef, IntPtr eventTarget);
132
 
                
133
 
                [DllImport (CarbonLib)]
134
 
                static extern EventStatus CreateEvent (IntPtr allocator, CarbonEventClass classID, uint kind, double eventTime,
135
 
                                                       CarbonEventAttributes flags, out IntPtr eventHandle);
136
 
                
137
 
                [DllImport (CarbonLib)]
138
 
                static extern void ReleaseEvent (IntPtr eventHandle);
139
 
                
140
 
                static EventStatus SendApplicationEvent (CarbonEventClass classID, uint kind, CarbonEventAttributes flags)
141
 
                {
142
 
                        IntPtr eventHandle;
143
 
                        EventStatus s = CreateEvent (IntPtr.Zero, classID, kind, 0, flags, out eventHandle);
144
 
                        if (s != EventStatus.Ok)
145
 
                                return s;
146
 
                        s = SendEventToEventTarget (eventHandle, GetApplicationEventTarget ());
147
 
                        ReleaseEvent (eventHandle);
148
 
                        return s;
149
 
                }
150
 
                
151
 
                [DllImport (CarbonLib)]
152
 
                public static extern CarbonEventHandlerStatus ProcessHICommand (ref CarbonHICommand command);
153
 
                
154
 
                #endregion
155
 
                
156
 
                #region Error checking
157
 
                
158
 
                public static void CheckReturn (EventStatus status)
159
 
                {
160
 
                        int intStatus = (int) status;
161
 
                        if (intStatus < 0)
162
 
                                throw new EventStatusException (status);
163
 
                }
164
 
                
165
 
                public static void CheckReturn (int osErr)
166
 
                {
167
 
                        if (osErr != 0) {
168
 
                                string s = GetMacOSStatusCommentString (osErr);
169
 
                                throw new SystemException ("Unexpected OS error code " + osErr + ": " + s);
170
 
                        }
171
 
                }
172
 
                
173
 
                [DllImport (CarbonLib)]
174
 
                static extern string GetMacOSStatusCommentString (int osErr);
175
 
                
176
 
                #endregion
177
 
                
178
 
                #region Char code conversion
179
 
                
180
 
                internal static int ConvertCharCode (string fourcc)
181
 
                {
182
 
                        Debug.Assert (fourcc != null);
183
 
                        Debug.Assert (fourcc.Length == 4);
184
 
                        return (fourcc[3]) | (fourcc[2] << 8) | (fourcc[1] << 16) | (fourcc[0] << 24);
185
 
                }
186
 
                
187
 
                internal static string UnConvertCharCode (int i)
188
 
                {
189
 
                        return new string (new char[] {
190
 
                                (char)(i >> 24),
191
 
                                (char)(0xFF & (i >> 16)),
192
 
                                (char)(0xFF & (i >> 8)),
193
 
                                (char)(0xFF & i),
194
 
                        });
195
 
                }
196
 
                
197
 
                #endregion
198
 
                
199
 
                #region Navigation services
200
 
                
201
 
                [DllImport (CarbonLib)]
202
 
                static extern NavStatus NavDialogSetFilterTypeIdentifiers (IntPtr getFileDialogRef, IntPtr typeIdentifiersCFArray);
203
 
                
204
 
                
205
 
                [DllImport (CarbonLib)]
206
 
                static extern NavEventUPP NewNavEventUPP (NavEventProc userRoutine);
207
 
                
208
 
                [DllImport (CarbonLib)]
209
 
                static extern NavObjectFilterUPP NewNavObjectFilterUPP (NavObjectFilterProc userRoutine);
210
 
                
211
 
                [DllImport (CarbonLib)]
212
 
                static extern NavPreviewUPP NewNavPreviewUPP (NavPreviewProc userRoutine);
213
 
                
214
 
                delegate void NavEventProc (NavEventCallbackMessage callBackSelector, ref NavCBRec callBackParms, IntPtr callBackUD);
215
 
                
216
 
                delegate bool NavObjectFilterProc (ref AEDesc theItem, IntPtr info, IntPtr callBackUD, NavFilterModes filterMode);
217
 
                
218
 
                delegate bool NavPreviewProc (ref NavCBRec callBackParms, IntPtr callBackUD);
219
 
                
220
 
                [DllImport (CarbonLib)]
221
 
                static extern void DisposeNavEventUPP (NavEventUPP userUPP);
222
 
                
223
 
                [DllImport (CarbonLib)]
224
 
                static extern void DisposeNavObjectFilterUPP (NavObjectFilterUPP userUPP);
225
 
                
226
 
                [DllImport (CarbonLib)]
227
 
                static extern void DisposeNavPreviewUPP (NavPreviewUPP userUPP);
228
 
                
229
 
                #endregion
230
 
                
231
 
                #region Internal Mac API for setting process name
232
 
                
233
 
                [DllImport (CarbonLib)]
234
 
                static extern int GetCurrentProcess (out ProcessSerialNumber psn);
235
 
                
236
 
                [DllImport (CarbonLib)]
237
 
                static extern int CPSSetProcessName (ref ProcessSerialNumber psn, string name);
238
 
                
239
 
                public static void SetProcessName (string name)
240
 
                {
241
 
                        try {
242
 
                                ProcessSerialNumber psn;
243
 
                                if (GetCurrentProcess (out psn) == 0)
244
 
                                        CPSSetProcessName (ref psn, name);
245
 
                        } catch {} //EntryPointNotFoundException?
246
 
                }
247
 
                
248
 
                struct ProcessSerialNumber {
249
 
                        ulong highLongOfPSN;
250
 
                        ulong lowLongOfPSN;
251
 
                }
252
 
                
253
 
                #endregion
254
 
                
255
 
                public static Dictionary<string,int> GetFileListFromEventRef (IntPtr eventRef)
256
 
                {
257
 
                        AEDesc list = GetEventParameter<AEDesc> (eventRef, CarbonEventParameterName.DirectObject, CarbonEventParameterType.AEList);
258
 
                        try {
259
 
                                int line = 0;
260
 
                                try {
261
 
                                        SelectionRange range = GetEventParameter<SelectionRange> (eventRef, CarbonEventParameterName.AEPosition, CarbonEventParameterType.Char);
262
 
                                        line = range.lineNum+1;
263
 
                                } catch {
264
 
                                }
265
 
                                
266
 
                                var arr = AppleEvent.GetListFromAEDesc<string,FSRef> (ref list, CoreFoundation.FSRefToString,
267
 
                                        (OSType)(int)CarbonEventParameterType.FSRef);
268
 
                                var files = new Dictionary<string,int> ();
269
 
                                foreach (var s in arr) {
270
 
                                        if (!string.IsNullOrEmpty (s))
271
 
                                                files[s] = line;
272
 
                                }
273
 
                                return files;
274
 
                        } finally {
275
 
                                CheckReturn ((int)AppleEvent.AEDisposeDesc (ref list));
276
 
                        }
277
 
                }
278
 
                
279
 
                public static IList<string> GetUrlListFromEventRef (IntPtr eventRef)
280
 
                {
281
 
                        AEDesc list = GetEventParameter<AEDesc> (eventRef, CarbonEventParameterName.DirectObject, CarbonEventParameterType.AEList);
282
 
                        try {
283
 
                                return AppleEvent.GetUtf8StringListFromAEDesc (ref list, true);
284
 
                        } finally {
285
 
                                Carbon.CheckReturn ((int)AppleEvent.AEDisposeDesc (ref list));
286
 
                        }
287
 
                }
288
 
        }
289
 
        
290
 
        [StructLayout(LayoutKind.Sequential, Pack = 2, Size = 80)]
291
 
        struct FSRef
292
 
        {
293
 
                //this is an 80-char opaque byte array
294
 
                private byte hidden;
295
 
        }
296
 
        
297
 
        [StructLayout(LayoutKind.Sequential)]
298
 
        struct SelectionRange
299
 
        {
300
 
                public short unused1; // 0 (not used)
301
 
                public short lineNum; // line to select (<0 to specify range)
302
 
                public int startRange; // start of selection range (if line < 0)
303
 
                public int endRange; // end of selection range (if line < 0)
304
 
                public int unused2; // 0 (not used)
305
 
                public int theDate; // modification date/time
306
 
        }
307
 
        
308
 
        internal enum CarbonEventHandlerStatus //this is an OSStatus
309
 
        {
310
 
                Handled = 0,
311
 
                NotHandled = -9874,
312
 
                UserCancelled = -128,
313
 
        }
314
 
        
315
 
        internal enum CarbonEventParameterName : uint
316
 
        {
317
 
                DirectObject = 757935405, // '----'
318
 
                AEPosition = 1802530675, // 'kpos'
319
 
        }
320
 
        
321
 
        internal enum CarbonEventParameterType : uint
322
 
        {
323
 
                HICommand = 1751346532, // 'hcmd'
324
 
                MenuRef = 1835363957, // 'menu'
325
 
                WindowRef = 2003398244, // 'wind'
326
 
                Char = 1413830740, // 'TEXT'
327
 
                UInt32 = 1835100014, // 'magn'
328
 
                UnicodeText = 1970567284, // 'utxt'
329
 
                AEList = 1818850164, // 'list'
330
 
                WildCard = 707406378, // '****'
331
 
                FSRef = 1718841958, // 'fsrf' 
332
 
        }
333
 
        
334
 
        internal enum CarbonEventClass : uint
335
 
        {
336
 
                Mouse = 1836021107, // 'mous'
337
 
                Keyboard = 1801812322, // 'keyb'
338
 
                TextInput = 1952807028, // 'text'
339
 
                Application = 1634758764, // 'appl'
340
 
                RemoteAppleEvent = 1701867619,  //'eppc' //remote apple event?
341
 
                Menu = 1835363957, // 'menu'
342
 
                Window = 2003398244, // 'wind'
343
 
                Control = 1668183148, // 'cntl'
344
 
                Command = 1668113523, // 'cmds'
345
 
                Tablet = 1952607348, // 'tblt'
346
 
                Volume = 1987013664, // 'vol '
347
 
                Appearance = 1634758765, // 'appm'
348
 
                Service = 1936028278, // 'serv'
349
 
                Toolbar = 1952604530, // 'tbar'
350
 
                ToolbarItem = 1952606580, // 'tbit'
351
 
                Accessibility = 1633903461, // 'acce'
352
 
                HIObject = 1751740258, // 'hiob'
353
 
                AppleEvent = 1634039412, // 'aevt'
354
 
                Internet = 1196773964, // 'GURL'
355
 
        }
356
 
        
357
 
        public enum CarbonCommandID : uint
358
 
        {
359
 
                OK = 1869291552, // 'ok  '
360
 
                Cancel = 1852797985, // 'not!'
361
 
                Quit = 1903520116, // 'quit'
362
 
                Undo = 1970168943, // 'undo'
363
 
                Redo = 1919247471, // 'redo'
364
 
                Cut = 1668641824, // 'cut '
365
 
                Copy = 1668247673, // 'copy'
366
 
                Paste = 1885434740, // 'past'
367
 
                Clear = 1668048225, // 'clea',
368
 
                SelectAll = 1935764588, // 'sall',
369
 
                Preferences = 1886545254, //'pref'
370
 
                About = 1633841013, // 'abou'
371
 
                New = 1852143392, // 'new ',
372
 
                Open = 1869636974, // 'open'
373
 
                Close = 1668050803, // 'clos'
374
 
                Save = 1935767141, // 'save',
375
 
                SaveAs = 1937138035, // 'svas'
376
 
                Revert = 1920365172, // 'rvrt'
377
 
                Print = 1886547572, // 'prnt'
378
 
                PageSetup = 1885431653, // 'page',
379
 
                AppHelp = 1634233456, //'ahlp'
380
 
                
381
 
                //menu manager handles these automatically
382
 
                
383
 
                Hide = 1751737445, // 'hide'
384
 
                HideOthers = 1751737455, // 'hido'
385
 
                ShowAll = 1936220524, // 'shal'
386
 
                ZoomWindow = 2054123373, // 'zoom'
387
 
                MinimizeWindow = 1835626089, // 'mini'
388
 
                MinimizeAll = 1835626081, // 'mina'
389
 
                MaximizeAll = 1835104353, // 'maxa'
390
 
                ArrangeInFront = 1718775412, // 'frnt'
391
 
                BringAllToFront = 1650881140, // 'bfrt'
392
 
                SelectWindow = 1937205614, // 'swin'
393
 
                RotateWindowsForward = 1919906935, // 'rotw'
394
 
                RotateWindowsBackward = 1919906914, // 'rotb'
395
 
                RotateFloatingWindowsForward = 1920231031, // 'rtfw'
396
 
                RotateFloatingWindowsBackward = 1920231010, // 'rtfb'
397
 
                
398
 
                //created automatically -- used for inserting before/after the default window list
399
 
                WindowListSeparator = 2003592310, // 'wldv'
400
 
                WindowListTerminator = 2003596148, // 'wlst'
401
 
        }
402
 
        
403
 
        internal enum CarbonEventCommand : uint
404
 
        {
405
 
                Process = 1,
406
 
                UpdateStatus = 2,
407
 
        }
408
 
        
409
 
        internal enum CarbonEventMenu : uint
410
 
        {
411
 
                BeginTracking = 1,
412
 
                EndTracking = 2,
413
 
                ChangeTrackingMode = 3,
414
 
                Opening = 4,
415
 
                Closed = 5,
416
 
                TargetItem = 6,
417
 
                MatchKey = 7,
418
 
        }
419
 
        
420
 
        internal enum CarbonEventAttributes : uint
421
 
        {
422
 
                None = 0,
423
 
                UserEvent = (1 << 0),
424
 
                Monitored= 1 << 3,
425
 
        }
426
 
        
427
 
        internal enum CarbonEventApple
428
 
        {
429
 
                OpenApplication = 1868656752, // 'oapp'
430
 
                ReopenApplication = 1918988400, //'rapp'
431
 
                OpenDocuments = 1868853091, // 'odoc'
432
 
                PrintDocuments = 188563030, // 'pdoc'
433
 
                OpenContents = 1868787566, // 'ocon'
434
 
                QuitApplication =  1903520116, // 'quit'
435
 
                ShowPreferences = 1886545254, // 'pref'
436
 
                ApplicationDied = 1868720500, // 'obit'
437
 
                GetUrl = 1196773964, // 'GURL'
438
 
        }
439
 
        
440
 
        [StructLayout(LayoutKind.Sequential, Pack = 2)]
441
 
        struct CarbonEventTypeSpec
442
 
        {
443
 
                public CarbonEventClass EventClass;
444
 
                public uint EventKind;
445
 
 
446
 
                public CarbonEventTypeSpec (CarbonEventClass eventClass, UInt32 eventKind)
447
 
                {
448
 
                        this.EventClass = eventClass;
449
 
                        this.EventKind = eventKind;
450
 
                }
451
 
                
452
 
                public CarbonEventTypeSpec (CarbonEventMenu kind) : this (CarbonEventClass.Menu, (uint) kind)
453
 
                {
454
 
                }
455
 
                
456
 
                public CarbonEventTypeSpec (CarbonEventCommand kind) : this (CarbonEventClass.Command, (uint) kind)
457
 
                {
458
 
                }
459
 
                
460
 
                
461
 
                public CarbonEventTypeSpec (CarbonEventApple kind) : this (CarbonEventClass.AppleEvent, (uint) kind)
462
 
                {
463
 
                }
464
 
                
465
 
                public static implicit operator CarbonEventTypeSpec (CarbonEventMenu kind)
466
 
                {
467
 
                        return new CarbonEventTypeSpec (kind);
468
 
                }
469
 
                
470
 
                public static implicit operator CarbonEventTypeSpec (CarbonEventCommand kind)
471
 
                {
472
 
                        return new CarbonEventTypeSpec (kind);
473
 
                }
474
 
                
475
 
                public static implicit operator CarbonEventTypeSpec (CarbonEventApple kind)
476
 
                {
477
 
                        return new CarbonEventTypeSpec (kind);
478
 
                }
479
 
        }
480
 
        
481
 
        class EventStatusException : SystemException
482
 
        {
483
 
                public EventStatusException (EventStatus status)
484
 
                {
485
 
                        StatusCode = status;
486
 
                }
487
 
                
488
 
                public EventStatus StatusCode {
489
 
                        get; private set;
490
 
                }
491
 
        }
492
 
        
493
 
        enum EventStatus // this is an OSStatus
494
 
        {
495
 
                Ok = 0,
496
 
                
497
 
                //event manager
498
 
                EventAlreadyPostedErr = -9860,
499
 
                EventTargetBusyErr = -9861,
500
 
                EventClassInvalidErr = -9862,
501
 
                EventClassIncorrectErr = -9864,
502
 
                EventHandlerAlreadyInstalledErr = -9866,
503
 
                EventInternalErr = -9868,
504
 
                EventKindIncorrectErr = -9869,
505
 
                EventParameterNotFoundErr = -9870,
506
 
                EventNotHandledErr = -9874,
507
 
                EventLoopTimedOutErr = -9875,
508
 
                EventLoopQuitErr = -9876,
509
 
                EventNotInQueueErr = -9877,
510
 
                EventHotKeyExistsErr = -9878,
511
 
                EventHotKeyInvalidErr = -9879,
512
 
        }
513
 
        
514
 
        [StructLayout(LayoutKind.Explicit)]
515
 
        struct CarbonHICommand //technically HICommandExtended, but they're compatible
516
 
        {
517
 
                [FieldOffset(0)]
518
 
                CarbonHICommandAttributes attributes;
519
 
                
520
 
                [FieldOffset(4)]
521
 
                uint commandID;
522
 
                
523
 
                [FieldOffset(8)]
524
 
                IntPtr controlRef;
525
 
                
526
 
                [FieldOffset(8)]
527
 
                IntPtr windowRef;
528
 
                
529
 
                [FieldOffset(8)]
530
 
                HIMenuItem menuItem;
531
 
                
532
 
                public CarbonHICommand (uint commandID, HIMenuItem item)
533
 
                {
534
 
                        windowRef = controlRef = IntPtr.Zero;
535
 
                        this.commandID = commandID;
536
 
                        this.menuItem = item;
537
 
                        this.attributes = CarbonHICommandAttributes.FromMenu;
538
 
                }
539
 
                
540
 
                public CarbonHICommandAttributes Attributes { get { return attributes; } }
541
 
                public uint CommandID { get { return commandID; } }
542
 
                public IntPtr ControlRef { get { return controlRef; } }
543
 
                public IntPtr WindowRef { get { return windowRef; } }
544
 
                public HIMenuItem MenuItem { get { return menuItem; } }
545
 
                
546
 
                public bool IsFromMenu {
547
 
                        get { return attributes == CarbonHICommandAttributes.FromMenu; }
548
 
                }
549
 
                
550
 
                public bool IsFromControl {
551
 
                        get { return attributes == CarbonHICommandAttributes.FromControl; }
552
 
                }
553
 
                
554
 
                public bool IsFromWindow {
555
 
                        get { return attributes == CarbonHICommandAttributes.FromWindow; }
556
 
                }
557
 
        }
558
 
        
559
 
        [StructLayout(LayoutKind.Sequential, Pack = 2)]
560
 
        struct HIMenuItem
561
 
        {
562
 
                IntPtr menuRef;
563
 
                ushort index;
564
 
                
565
 
                public HIMenuItem (IntPtr menuRef, ushort index)
566
 
                {
567
 
                        this.index = index;
568
 
                        this.menuRef = menuRef;
569
 
                }
570
 
                
571
 
                public IntPtr MenuRef { get { return menuRef; } }
572
 
                public ushort Index { get { return index; } }
573
 
        }
574
 
        
575
 
        //*NOT* flags
576
 
        enum CarbonHICommandAttributes : uint
577
 
        {
578
 
                FromMenu = 1,
579
 
                FromControl = 1 << 1,
580
 
                FromWindow  = 1 << 2,
581
 
        }
582
 
 
583
 
        [StructLayout(LayoutKind.Sequential, Pack = 2)]
584
 
        struct FileTranslationSpec
585
 
        {
586
 
                uint componentSignature; // OSType
587
 
                IntPtr translationSystemInfo; // void*
588
 
                FileTypeSpec src;
589
 
                FileTypeSpec dst;
590
 
        }
591
 
        
592
 
        [StructLayout(LayoutKind.Sequential, Pack = 2)]
593
 
        struct FileTypeSpec
594
 
        {/*
595
 
                uint format; // FileType
596
 
                long hint;
597
 
                TranslationAttributes flags;
598
 
                uint catInfoType; // OSType
599
 
                uint catInfoCreator; // OSType
600
 
                */
601
 
        }
602
 
        
603
 
        struct OSType {
604
 
                int value;
605
 
                
606
 
                public int Value {
607
 
                        get { return Value; }
608
 
                }
609
 
                
610
 
                public OSType (int value)
611
 
                {
612
 
                        this.value = value;
613
 
                }
614
 
                
615
 
                public OSType (string fourcc)
616
 
                {
617
 
                        value = Carbon.ConvertCharCode (fourcc);
618
 
                }
619
 
                
620
 
                public static explicit operator OSType (string fourcc)
621
 
                {
622
 
                        return new OSType (fourcc); 
623
 
                }
624
 
                
625
 
                public static implicit operator int (OSType o)
626
 
                {
627
 
                        return o.value;
628
 
                }
629
 
                
630
 
                public static implicit operator OSType (int i)
631
 
                {
632
 
                        return new OSType (i);
633
 
                }
634
 
        }
635
 
}