~ubuntu-branches/ubuntu/quantal/banshee/quantal

« back to all changes in this revision

Viewing changes to src/Backends/Banshee.Osx/OsxIntegration.Framework/Carbon.cs

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2012-09-23 16:41:43 UTC
  • mfrom: (1.2.22) (6.3.25 experimental)
  • Revision ID: package-import@ubuntu.com-20120923164143-xuygdccvr2uqjdfj
Tags: 2.5.1-1ubuntu1
* [9615bd3e] Merge from Debian Experimental (LP: #1041245), remaining changes:
  - Enable and recommend SoundMenu and Disable NotificationArea by default
  - Disable boo and karma extensions
  - Move desktop file for Meego UI to /usr/share/une/applications
  - Change the url for the Amazon store redirector
  - [9b356d6] Add workaround for set_Height exception.
  - [ccbcbbd] Make Banshee translatable in Launchpad
* [77c7309] Drop Workaruond-for-set_Height-Exceptions.patch.
  Applied upstream

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
 
 
32
 
#pragma warning disable 0169
33
 
 
34
 
namespace OsxIntegration.Framework
35
 
{
36
 
        internal delegate CarbonEventHandlerStatus EventDelegate (IntPtr callRef, IntPtr eventRef, IntPtr userData);
37
 
        internal delegate CarbonEventHandlerStatus AEHandlerDelegate (IntPtr inEvnt, IntPtr outEvt, uint refConst);
38
 
        
39
 
        internal static class Carbon
40
 
        {
41
 
                public const string CarbonLib = "/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon";
42
 
                
43
 
                [DllImport (CarbonLib)]
44
 
                public static extern IntPtr GetApplicationEventTarget ();
45
 
                
46
 
                [DllImport (CarbonLib)]
47
 
                public static extern IntPtr GetControlEventTarget (IntPtr control);
48
 
                
49
 
                [DllImport (CarbonLib)]
50
 
                public static extern IntPtr GetWindowEventTarget (IntPtr window);
51
 
                
52
 
                [DllImport (CarbonLib)]
53
 
                public static extern IntPtr GetMenuEventTarget (IntPtr menu);
54
 
 
55
 
                [DllImport (CarbonLib)]
56
 
                public static extern CarbonEventClass GetEventClass (IntPtr eventref);
57
 
                
58
 
                [DllImport (CarbonLib)]
59
 
                public static extern uint GetEventKind (IntPtr eventref);
60
 
                
61
 
                #region Event handler installation
62
 
                
63
 
                [DllImport (CarbonLib)]
64
 
                static extern EventStatus InstallEventHandler (IntPtr target, EventDelegate handler, uint count,
65
 
                                                               CarbonEventTypeSpec [] types, IntPtr user_data, out IntPtr handlerRef);
66
 
                
67
 
                [DllImport (CarbonLib)]
68
 
                public static extern EventStatus RemoveEventHandler (IntPtr handlerRef);
69
 
                
70
 
                public static IntPtr InstallEventHandler (IntPtr target, EventDelegate handler, CarbonEventTypeSpec [] types)
71
 
                {
72
 
                        IntPtr handlerRef;
73
 
                        CheckReturn (InstallEventHandler (target, handler, (uint)types.Length, types, IntPtr.Zero, out handlerRef));
74
 
                        return handlerRef;
75
 
                }
76
 
                
77
 
                public static IntPtr InstallEventHandler (IntPtr target, EventDelegate handler, CarbonEventTypeSpec type)
78
 
                {
79
 
                        return InstallEventHandler (target, handler, new CarbonEventTypeSpec[] { type });
80
 
                }
81
 
                
82
 
                public static IntPtr InstallApplicationEventHandler (EventDelegate handler, CarbonEventTypeSpec [] types)
83
 
                {
84
 
                        return InstallEventHandler (GetApplicationEventTarget (), handler, types);
85
 
                }
86
 
                
87
 
                public static IntPtr InstallApplicationEventHandler (EventDelegate handler, CarbonEventTypeSpec type)
88
 
                {
89
 
                        return InstallEventHandler (GetApplicationEventTarget (), handler, new CarbonEventTypeSpec[] { type });
90
 
                }
91
 
                
92
 
                #endregion
93
 
                
94
 
                #region Event parameter extraction
95
 
                
96
 
                [DllImport (CarbonLib)]
97
 
                public static extern EventStatus GetEventParameter (IntPtr eventRef, CarbonEventParameterName name, CarbonEventParameterType desiredType,
98
 
                                                                    out CarbonEventParameterType actualType, uint size, ref uint outSize, ref IntPtr outPtr);
99
 
                
100
 
                public static IntPtr GetEventParameter (IntPtr eventRef, CarbonEventParameterName name, CarbonEventParameterType desiredType)
101
 
                {
102
 
                        CarbonEventParameterType actualType;
103
 
                        uint outSize = 0;
104
 
                        IntPtr val = IntPtr.Zero;
105
 
                        CheckReturn (GetEventParameter (eventRef, name, desiredType, out actualType, (uint)IntPtr.Size, ref outSize, ref val));
106
 
                        return val;
107
 
                } 
108
 
                
109
 
                [DllImport (CarbonLib)]
110
 
                static extern EventStatus GetEventParameter (IntPtr eventRef, CarbonEventParameterName name, CarbonEventParameterType desiredType,      
111
 
                                                             out CarbonEventParameterType actualType, uint size, ref uint outSize, IntPtr dataBuffer);
112
 
                  
113
 
                [DllImport (CarbonLib)]
114
 
                static extern EventStatus GetEventParameter (IntPtr eventRef, CarbonEventParameterName name, CarbonEventParameterType desiredType,      
115
 
                                                             uint zero, uint size, uint zero2, IntPtr dataBuffer);
116
 
                
117
 
                public static T GetEventParameter<T> (IntPtr eventRef, CarbonEventParameterName name, CarbonEventParameterType desiredType) where T : struct
118
 
                {
119
 
                        int len = Marshal.SizeOf (typeof (T));
120
 
                        IntPtr bufferPtr = Marshal.AllocHGlobal (len);
121
 
                        CheckReturn (GetEventParameter (eventRef, name, desiredType, 0, (uint)len, 0, bufferPtr));
122
 
                        T val = (T)Marshal.PtrToStructure (bufferPtr, typeof (T));
123
 
                        Marshal.FreeHGlobal (bufferPtr);
124
 
                        return val;
125
 
                }
126
 
                
127
 
                #endregion
128
 
                
129
 
                #region Sending events
130
 
                
131
 
                [DllImport (CarbonLib)]
132
 
                static extern EventStatus SendEventToEventTarget (IntPtr eventRef, IntPtr eventTarget);
133
 
                
134
 
                [DllImport (CarbonLib)]
135
 
                static extern EventStatus CreateEvent (IntPtr allocator, CarbonEventClass classID, uint kind, double eventTime,
136
 
                                                       CarbonEventAttributes flags, out IntPtr eventHandle);
137
 
                
138
 
                [DllImport (CarbonLib)]
139
 
                static extern void ReleaseEvent (IntPtr eventHandle);
140
 
                
141
 
                static EventStatus SendApplicationEvent (CarbonEventClass classID, uint kind, CarbonEventAttributes flags)
142
 
                {
143
 
                        IntPtr eventHandle;
144
 
                        EventStatus s = CreateEvent (IntPtr.Zero, classID, kind, 0, flags, out eventHandle);
145
 
                        if (s != EventStatus.Ok)
146
 
                                return s;
147
 
                        s = SendEventToEventTarget (eventHandle, GetApplicationEventTarget ());
148
 
                        ReleaseEvent (eventHandle);
149
 
                        return s;
150
 
                }
151
 
                
152
 
                [DllImport (CarbonLib)]
153
 
                public static extern CarbonEventHandlerStatus ProcessHICommand (ref CarbonHICommand command);
154
 
                
155
 
                #endregion
156
 
                
157
 
                #region AEList manipulation
158
 
                
159
 
                [DllImport (CarbonLib)]
160
 
                static extern int AECountItems (ref AEDesc descList, out int count); //return an OSErr
161
 
                
162
 
                public static int AECountItems (ref AEDesc descList)
163
 
                {
164
 
                        int count;
165
 
                        CheckReturn (AECountItems (ref descList, out count));
166
 
                        return count;
167
 
                }
168
 
                
169
 
                [DllImport (CarbonLib)]
170
 
                static extern AEDescStatus AEGetNthPtr (ref AEDesc descList, int index, CarbonEventParameterType desiredType, uint keyword,
171
 
                                                        out CarbonEventParameterType actualType, IntPtr buffer, int bufferSize, out int actualSize);
172
 
                
173
 
                [DllImport (CarbonLib)]
174
 
                static extern AEDescStatus AEGetNthPtr (ref AEDesc descList, int index, CarbonEventParameterType desiredType, uint keyword,
175
 
                                                        uint zero, IntPtr buffer, int bufferSize, int zero2);
176
 
                
177
 
                public static T AEGetNthPtr<T> (ref AEDesc descList, int index, CarbonEventParameterType desiredType) where T : struct
178
 
                {
179
 
                        int len = Marshal.SizeOf (typeof (T));
180
 
                        IntPtr bufferPtr = Marshal.AllocHGlobal (len);
181
 
                        try {
182
 
                                CheckReturn ((int)AEGetNthPtr (ref descList, index, desiredType, 0, 0, bufferPtr, len, 0));
183
 
                                T val = (T)Marshal.PtrToStructure (bufferPtr, typeof (T));
184
 
                                return val;
185
 
                        } finally{ 
186
 
                                Marshal.FreeHGlobal (bufferPtr);
187
 
                        }
188
 
                }
189
 
                
190
 
                [DllImport (CarbonLib)]
191
 
                static extern AEDescStatus AEGetNthPtr (ref AEDesc descList, int index, CarbonEventParameterType desiredType, uint keyword,
192
 
                                                        uint zero, out IntPtr outPtr, int bufferSize, int zero2);
193
 
                
194
 
                public static IntPtr AEGetNthPtr (ref AEDesc descList, int index, CarbonEventParameterType desiredType)
195
 
                {
196
 
                        IntPtr ret;
197
 
                        CheckReturn ((int)AEGetNthPtr (ref descList, index, desiredType, 0, 0, out ret, 4, 0));
198
 
                        return ret;
199
 
                }
200
 
                
201
 
                [DllImport (CarbonLib)]
202
 
                public static extern int AEDisposeDesc (ref AEDesc desc);
203
 
                
204
 
                [DllImport (CarbonLib)]
205
 
                public static extern AEDescStatus AESizeOfNthItem  (ref AEDesc descList, int index, ref CarbonEventParameterType type, out int size);
206
 
                
207
 
                //FIXME: this might not work in some encodings. need to test more.
208
 
                static string GetStringFromAEPtr (ref AEDesc descList, int index)
209
 
                {
210
 
                        int size;
211
 
                        CarbonEventParameterType type = CarbonEventParameterType.UnicodeText;
212
 
                        if (AESizeOfNthItem (ref descList, index, ref type, out size) == AEDescStatus.Ok) {
213
 
                                IntPtr buffer = Marshal.AllocHGlobal (size);
214
 
                                try {
215
 
                                        if (AEGetNthPtr (ref descList, index, type, 0, 0, buffer, size, 0) == AEDescStatus.Ok)
216
 
                                                return Marshal.PtrToStringAuto (buffer, size);
217
 
                                } finally {
218
 
                                        Marshal.FreeHGlobal (buffer);
219
 
                                }
220
 
                        }
221
 
                        return null;
222
 
                }
223
 
                
224
 
                #endregion
225
 
                
226
 
                [DllImport (CarbonLib)]
227
 
                static extern int FSRefMakePath (ref FSRef fsRef, IntPtr buffer, uint bufferSize);
228
 
                
229
 
                public static string FSRefToPath (ref FSRef fsRef)
230
 
                {
231
 
                        //FIXME: is this big enough?
232
 
                        const int MAX_LENGTH = 4096;
233
 
                        IntPtr buf = IntPtr.Zero;
234
 
                        string ret;
235
 
                        try {
236
 
                                buf = Marshal.AllocHGlobal (MAX_LENGTH);
237
 
                                CheckReturn (FSRefMakePath (ref fsRef, buf, (uint)MAX_LENGTH));
238
 
                                //FIXME: on Mono, auto is UTF-8, which is correct but I'd prefer to be more explicit
239
 
                                ret = Marshal.PtrToStringAuto (buf, MAX_LENGTH);
240
 
                        } finally {
241
 
                                if (buf != IntPtr.Zero)
242
 
                                        Marshal.FreeHGlobal (buf);
243
 
                        }
244
 
                        return ret;
245
 
                }
246
 
                
247
 
                #region Error checking
248
 
                
249
 
                public static void CheckReturn (EventStatus status)
250
 
                {
251
 
                        int intStatus = (int) status;
252
 
                        if (intStatus < 0)
253
 
                                throw new EventStatusException (status);
254
 
                }
255
 
                
256
 
                public static void CheckReturn (int osErr)
257
 
                {
258
 
                        if (osErr != 0) {
259
 
                                string s = GetMacOSStatusCommentString (osErr);
260
 
                                throw new SystemException ("Unexpected OS error code " + osErr + ": " + s);
261
 
                        }
262
 
                }
263
 
                
264
 
                [DllImport (CarbonLib)]
265
 
                static extern string GetMacOSStatusCommentString (int osErr);
266
 
                
267
 
                #endregion
268
 
                
269
 
                #region Char code conversion
270
 
                
271
 
                internal static int ConvertCharCode (string code)
272
 
                {
273
 
                        return (code[3]) | (code[2] << 8) | (code[1] << 16) | (code[0] << 24);
274
 
                }
275
 
                
276
 
                internal static string UnConvertCharCode (int i)
277
 
                {
278
 
                        return new string (new char[] {
279
 
                                (char)(i >> 24),
280
 
                                (char)(0xFF & (i >> 16)),
281
 
                                (char)(0xFF & (i >> 8)),
282
 
                                (char)(0xFF & i),
283
 
                        });
284
 
                }
285
 
                
286
 
                #endregion
287
 
                
288
 
                #region Navigation services
289
 
                
290
 
                [DllImport (CarbonLib)]
291
 
                static extern NavStatus NavDialogSetFilterTypeIdentifiers (IntPtr getFileDialogRef, IntPtr typeIdentifiersCFArray);
292
 
                
293
 
                
294
 
                [DllImport (CarbonLib)]
295
 
                static extern NavEventUPP NewNavEventUPP (NavEventProc userRoutine);
296
 
                
297
 
                [DllImport (CarbonLib)]
298
 
                static extern NavObjectFilterUPP NewNavObjectFilterUPP (NavObjectFilterProc userRoutine);
299
 
                
300
 
                [DllImport (CarbonLib)]
301
 
                static extern NavPreviewUPP NewNavPreviewUPP (NavPreviewProc userRoutine);
302
 
                
303
 
                delegate void NavEventProc (NavEventCallbackMessage callBackSelector, ref NavCBRec callBackParms, IntPtr callBackUD);
304
 
                
305
 
                delegate bool NavObjectFilterProc (ref AEDesc theItem, IntPtr info, IntPtr callBackUD, NavFilterModes filterMode);
306
 
                
307
 
                delegate bool NavPreviewProc (ref NavCBRec callBackParms, IntPtr callBackUD);
308
 
                
309
 
                [DllImport (CarbonLib)]
310
 
                static extern void DisposeNavEventUPP (NavEventUPP userUPP);
311
 
                
312
 
                [DllImport (CarbonLib)]
313
 
                static extern void DisposeNavObjectFilterUPP (NavObjectFilterUPP userUPP);
314
 
                
315
 
                [DllImport (CarbonLib)]
316
 
                static extern void DisposeNavPreviewUPP (NavPreviewUPP userUPP);
317
 
                
318
 
                #endregion
319
 
                
320
 
                #region Internal Mac API for setting process name
321
 
                
322
 
                [DllImport (CarbonLib)]
323
 
                static extern int GetCurrentProcess (out ProcessSerialNumber psn);
324
 
                
325
 
                [DllImport (CarbonLib)]
326
 
                static extern int CPSSetProcessName (ref ProcessSerialNumber psn, string name);
327
 
                
328
 
                public static void SetProcessName (string name)
329
 
                {
330
 
                        try {
331
 
                                ProcessSerialNumber psn;
332
 
                                if (GetCurrentProcess (out psn) == 0)
333
 
                                        CPSSetProcessName (ref psn, name);
334
 
                        } catch {} //EntryPointNotFoundException?
335
 
                }
336
 
                
337
 
                struct ProcessSerialNumber {
338
 
                        ulong highLongOfPSN;
339
 
                        ulong lowLongOfPSN;
340
 
                }
341
 
                
342
 
                #endregion
343
 
                
344
 
                public static List<string> GetFileListFromEventRef (IntPtr eventRef)
345
 
                {
346
 
                        AEDesc list = GetEventParameter<AEDesc> (eventRef, CarbonEventParameterName.DirectObject, CarbonEventParameterType.AEList);
347
 
                        long count = AECountItems (ref list);
348
 
                        var files = new List<string> ();
349
 
                        for (int i = 1; i <= count; i++) {
350
 
                                FSRef fsRef = AEGetNthPtr<FSRef> (ref list, i, CarbonEventParameterType.FSRef);
351
 
                                string file = FSRefToPath (ref fsRef);
352
 
                                if (!string.IsNullOrEmpty (file))
353
 
                                        files.Add (file);
354
 
                        }
355
 
                        CheckReturn (AEDisposeDesc (ref list));
356
 
                        return files;
357
 
                }
358
 
                
359
 
                public static List<string> GetUrlListFromEventRef (IntPtr eventRef)
360
 
                {
361
 
                        AEDesc list = GetEventParameter<AEDesc> (eventRef, CarbonEventParameterName.DirectObject, CarbonEventParameterType.AEList);
362
 
                        long count = AECountItems (ref list);
363
 
                        var files = new List<string> ();
364
 
                        for (int i = 1; i <= count; i++) {
365
 
                                string url = GetStringFromAEPtr (ref list, i); 
366
 
                                if (!string.IsNullOrEmpty (url))
367
 
                                        files.Add (url);
368
 
                        }
369
 
                        Carbon.CheckReturn (Carbon.AEDisposeDesc (ref list));
370
 
                        return files;
371
 
                }
372
 
        }
373
 
        
374
 
        
375
 
        [StructLayout(LayoutKind.Sequential, Pack = 2)]
376
 
        struct AEDesc
377
 
        {
378
 
                uint descriptorType;
379
 
                IntPtr dataHandle;
380
 
        }
381
 
        
382
 
        [StructLayout(LayoutKind.Sequential, Pack = 2, Size = 80)]
383
 
        struct FSRef
384
 
        {
385
 
                //this is an 80-char opaque byte array
386
 
                private byte hidden;
387
 
        }
388
 
        
389
 
        internal enum CarbonEventHandlerStatus //this is an OSStatus
390
 
        {
391
 
                Handled = 0,
392
 
                NotHandled = -9874,
393
 
        }
394
 
        
395
 
        internal enum CarbonEventParameterName : uint
396
 
        {
397
 
                DirectObject = 757935405, // '----'
398
 
        }
399
 
        
400
 
        internal enum CarbonEventParameterType : uint
401
 
        {
402
 
                HICommand = 1751346532, // 'hcmd'
403
 
                MenuRef = 1835363957, // 'menu'
404
 
                WindowRef = 2003398244, // 'wind'
405
 
                Char = 1413830740, // 'TEXT'
406
 
                UInt32 = 1835100014, // 'magn'
407
 
                UnicodeText = 1970567284, // 'utxt'
408
 
                AEList = 1818850164, // 'list'
409
 
                WildCard = 707406378, // '****'
410
 
                FSRef = 1718841958, // 'fsrf' 
411
 
        }
412
 
        
413
 
        internal enum CarbonEventClass : uint
414
 
        {
415
 
                Mouse = 1836021107, // 'mous'
416
 
                Keyboard = 1801812322, // 'keyb'
417
 
                TextInput = 1952807028, // 'text'
418
 
                Application = 1634758764, // 'appl'
419
 
                RemoteAppleEvent = 1701867619,  //'eppc' //remote apple event?
420
 
                Menu = 1835363957, // 'menu'
421
 
                Window = 2003398244, // 'wind'
422
 
                Control = 1668183148, // 'cntl'
423
 
                Command = 1668113523, // 'cmds'
424
 
                Tablet = 1952607348, // 'tblt'
425
 
                Volume = 1987013664, // 'vol '
426
 
                Appearance = 1634758765, // 'appm'
427
 
                Service = 1936028278, // 'serv'
428
 
                Toolbar = 1952604530, // 'tbar'
429
 
                ToolbarItem = 1952606580, // 'tbit'
430
 
                Accessibility = 1633903461, // 'acce'
431
 
                HIObject = 1751740258, // 'hiob'
432
 
                AppleEvent = 1634039412, // 'aevt'
433
 
                Internet = 1196773964, // 'GURL'
434
 
        }
435
 
        
436
 
        public enum CarbonCommandID : uint
437
 
        {
438
 
                OK = 1869291552, // 'ok  '
439
 
                Cancel = 1852797985, // 'not!'
440
 
                Quit = 1903520116, // 'quit'
441
 
                Undo = 1970168943, // 'undo'
442
 
                Redo = 1919247471, // 'redo'
443
 
                Cut = 1668641824, // 'cut '
444
 
                Copy = 1668247673, // 'copy'
445
 
                Paste = 1885434740, // 'past'
446
 
                Clear = 1668048225, // 'clea',
447
 
                SelectAll = 1935764588, // 'sall',
448
 
                Preferences = 1886545254, //'pref'
449
 
                About = 1633841013, // 'abou'
450
 
                New = 1852143392, // 'new ',
451
 
                Open = 1869636974, // 'open'
452
 
                Close = 1668050803, // 'clos'
453
 
                Save = 1935767141, // 'save',
454
 
                SaveAs = 1937138035, // 'svas'
455
 
                Revert = 1920365172, // 'rvrt'
456
 
                Print = 1886547572, // 'prnt'
457
 
                PageSetup = 1885431653, // 'page',
458
 
                AppHelp = 1634233456, //'ahlp'
459
 
                
460
 
                //menu manager handles these automatically
461
 
                
462
 
                Hide = 1751737445, // 'hide'
463
 
                HideOthers = 1751737455, // 'hido'
464
 
                ShowAll = 1936220524, // 'shal'
465
 
                ZoomWindow = 2054123373, // 'zoom'
466
 
                MinimizeWindow = 1835626089, // 'mini'
467
 
                MinimizeAll = 1835626081, // 'mina'
468
 
                MaximizeAll = 1835104353, // 'maxa'
469
 
                ArrangeInFront = 1718775412, // 'frnt'
470
 
                BringAllToFront = 1650881140, // 'bfrt'
471
 
                SelectWindow = 1937205614, // 'swin'
472
 
                RotateWindowsForward = 1919906935, // 'rotw'
473
 
                RotateWindowsBackward = 1919906914, // 'rotb'
474
 
                RotateFloatingWindowsForward = 1920231031, // 'rtfw'
475
 
                RotateFloatingWindowsBackward = 1920231010, // 'rtfb'
476
 
                
477
 
                //created automatically -- used for inserting before/after the default window list
478
 
                WindowListSeparator = 2003592310, // 'wldv'
479
 
                WindowListTerminator = 2003596148, // 'wlst'
480
 
        }
481
 
        
482
 
        internal enum CarbonEventCommand : uint
483
 
        {
484
 
                Process = 1,
485
 
                UpdateStatus = 2,
486
 
        }
487
 
        
488
 
        internal enum CarbonEventMenu : uint
489
 
        {
490
 
                BeginTracking = 1,
491
 
                EndTracking = 2,
492
 
                ChangeTrackingMode = 3,
493
 
                Opening = 4,
494
 
                Closed = 5,
495
 
                TargetItem = 6,
496
 
                MatchKey = 7,
497
 
        }
498
 
        
499
 
        internal enum CarbonEventAttributes : uint
500
 
        {
501
 
                None = 0,
502
 
                UserEvent = (1 << 0),
503
 
                Monitored= 1 << 3,
504
 
        }
505
 
        
506
 
        internal enum CarbonEventApple
507
 
        {
508
 
                OpenApplication = 1868656752, // 'oapp'
509
 
                ReopenApplication = 1918988400, //'rapp'
510
 
                OpenDocuments = 1868853091, // 'odoc'
511
 
                PrintDocuments = 188563030, // 'pdoc'
512
 
                OpenContents = 1868787566, // 'ocon'
513
 
                QuitApplication =  1903520116, // 'quit'
514
 
                ShowPreferences = 1886545254, // 'pref'
515
 
                ApplicationDied = 1868720500, // 'obit'
516
 
                GetUrl = 1196773964, // 'GURL'
517
 
        }
518
 
        
519
 
        [StructLayout(LayoutKind.Sequential, Pack = 2)]
520
 
        struct CarbonEventTypeSpec
521
 
        {
522
 
                public CarbonEventClass EventClass;
523
 
                public uint EventKind;
524
 
 
525
 
                public CarbonEventTypeSpec (CarbonEventClass eventClass, UInt32 eventKind)
526
 
                {
527
 
                        this.EventClass = eventClass;
528
 
                        this.EventKind = eventKind;
529
 
                }
530
 
                
531
 
                public CarbonEventTypeSpec (CarbonEventMenu kind) : this (CarbonEventClass.Menu, (uint) kind)
532
 
                {
533
 
                }
534
 
                
535
 
                public CarbonEventTypeSpec (CarbonEventCommand kind) : this (CarbonEventClass.Command, (uint) kind)
536
 
                {
537
 
                }
538
 
                
539
 
                
540
 
                public CarbonEventTypeSpec (CarbonEventApple kind) : this (CarbonEventClass.AppleEvent, (uint) kind)
541
 
                {
542
 
                }
543
 
                
544
 
                public static implicit operator CarbonEventTypeSpec (CarbonEventMenu kind)
545
 
                {
546
 
                        return new CarbonEventTypeSpec (kind);
547
 
                }
548
 
                
549
 
                public static implicit operator CarbonEventTypeSpec (CarbonEventCommand kind)
550
 
                {
551
 
                        return new CarbonEventTypeSpec (kind);
552
 
                }
553
 
                
554
 
                public static implicit operator CarbonEventTypeSpec (CarbonEventApple kind)
555
 
                {
556
 
                        return new CarbonEventTypeSpec (kind);
557
 
                }
558
 
        }
559
 
        
560
 
        class EventStatusException : SystemException
561
 
        {
562
 
                public EventStatusException (EventStatus status)
563
 
                {
564
 
                        StatusCode = status;
565
 
                }
566
 
                
567
 
                public EventStatus StatusCode {
568
 
                        get; private set;
569
 
                }
570
 
        }
571
 
        
572
 
        enum EventStatus // this is an OSStatus
573
 
        {
574
 
                Ok = 0,
575
 
                
576
 
                //event manager
577
 
                EventAlreadyPostedErr = -9860,
578
 
                EventTargetBusyErr = -9861,
579
 
                EventClassInvalidErr = -9862,
580
 
                EventClassIncorrectErr = -9864,
581
 
                EventHandlerAlreadyInstalledErr = -9866,
582
 
                EventInternalErr = -9868,
583
 
                EventKindIncorrectErr = -9869,
584
 
                EventParameterNotFoundErr = -9870,
585
 
                EventNotHandledErr = -9874,
586
 
                EventLoopTimedOutErr = -9875,
587
 
                EventLoopQuitErr = -9876,
588
 
                EventNotInQueueErr = -9877,
589
 
                EventHotKeyExistsErr = -9878,
590
 
                EventHotKeyInvalidErr = -9879,
591
 
        }
592
 
        
593
 
        enum AEDescStatus
594
 
        {
595
 
                Ok = 0,
596
 
                MemoryFull = -108,
597
 
                CoercionFail = -1700,
598
 
                DescRecordNotFound = -1701,
599
 
                WrongDataType = -1703,
600
 
                NotAEDesc = -1704,
601
 
                ReplyNotArrived = -1718,
602
 
        }
603
 
        
604
 
        [StructLayout(LayoutKind.Explicit)]
605
 
        struct CarbonHICommand //technically HICommandExtended, but they're compatible
606
 
        {
607
 
                [FieldOffset(0)]
608
 
                CarbonHICommandAttributes attributes;
609
 
                
610
 
                [FieldOffset(4)]
611
 
                uint commandID;
612
 
                
613
 
                [FieldOffset(8)]
614
 
                IntPtr controlRef;
615
 
                
616
 
                [FieldOffset(8)]
617
 
                IntPtr windowRef;
618
 
                
619
 
                [FieldOffset(8)]
620
 
                HIMenuItem menuItem;
621
 
                
622
 
                public CarbonHICommand (uint commandID, HIMenuItem item)
623
 
                {
624
 
                        windowRef = controlRef = IntPtr.Zero;
625
 
                        this.commandID = commandID;
626
 
                        this.menuItem = item;
627
 
                        this.attributes = CarbonHICommandAttributes.FromMenu;
628
 
                }
629
 
                
630
 
                public CarbonHICommandAttributes Attributes { get { return attributes; } }
631
 
                public uint CommandID { get { return commandID; } }
632
 
                public IntPtr ControlRef { get { return controlRef; } }
633
 
                public IntPtr WindowRef { get { return windowRef; } }
634
 
                public HIMenuItem MenuItem { get { return menuItem; } }
635
 
                
636
 
                public bool IsFromMenu {
637
 
                        get { return attributes == CarbonHICommandAttributes.FromMenu; }
638
 
                }
639
 
                
640
 
                public bool IsFromControl {
641
 
                        get { return attributes == CarbonHICommandAttributes.FromControl; }
642
 
                }
643
 
                
644
 
                public bool IsFromWindow {
645
 
                        get { return attributes == CarbonHICommandAttributes.FromWindow; }
646
 
                }
647
 
        }
648
 
        
649
 
        [StructLayout(LayoutKind.Sequential, Pack = 2)]
650
 
        struct HIMenuItem
651
 
        {
652
 
                IntPtr menuRef;
653
 
                ushort index;
654
 
                
655
 
                public HIMenuItem (IntPtr menuRef, ushort index)
656
 
                {
657
 
                        this.index = index;
658
 
                        this.menuRef = menuRef;
659
 
                }
660
 
                
661
 
                public IntPtr MenuRef { get { return menuRef; } }
662
 
                public ushort Index { get { return index; } }
663
 
        }
664
 
        
665
 
        //*NOT* flags
666
 
        enum CarbonHICommandAttributes : uint
667
 
        {
668
 
                FromMenu = 1,
669
 
                FromControl = 1 << 1,
670
 
                FromWindow  = 1 << 2,
671
 
        }
672
 
 
673
 
        [StructLayout(LayoutKind.Sequential, Pack = 2)]
674
 
        struct FileTranslationSpec
675
 
        {
676
 
                uint componentSignature; // OSType
677
 
                IntPtr translationSystemInfo; // void*
678
 
                FileTypeSpec src;
679
 
                FileTypeSpec dst;
680
 
        }
681
 
        
682
 
        [StructLayout(LayoutKind.Sequential, Pack = 2)]
683
 
        struct FileTypeSpec
684
 
        {/*
685
 
                uint format; // FileType
686
 
                long hint;
687
 
                TranslationAttributes flags;
688
 
                uint catInfoType; // OSType
689
 
                uint catInfoCreator; // OSType
690
 
                */
691
 
        }
692
 
}