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

« back to all changes in this revision

Viewing changes to src/addins/MacPlatform/MacInterop/HIToolbox.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
// HIToolbox.cs
 
3
//  
 
4
// Author:
 
5
//       Michael Hutchinson <mhutchinson@novell.com>
 
6
//       Miguel de Icaza
 
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
 
 
31
namespace MonoDevelop.MacInterop
 
32
{
 
33
        internal static class HIToolbox
 
34
        {
 
35
                const string hiToolboxLib = "/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/HIToolbox";
 
36
                
 
37
                [DllImport (hiToolboxLib)]
 
38
                static extern CarbonMenuStatus CreateNewMenu (ushort menuId, MenuAttributes attributes, out IntPtr menuRef);
 
39
                
 
40
                public static IntPtr CreateMenu (ushort id, string title, MenuAttributes attributes)
 
41
                {
 
42
                        IntPtr menuRef;
 
43
                        CheckResult (CreateNewMenu (id, attributes, out menuRef));
 
44
                        SetMenuTitle (menuRef, title);
 
45
                        return menuRef;
 
46
                }
 
47
 
 
48
                [DllImport (hiToolboxLib)]
 
49
                internal static extern CarbonMenuStatus SetRootMenu (IntPtr menuRef);
 
50
 
 
51
                [DllImport (hiToolboxLib)]
 
52
                internal static extern void DeleteMenu (IntPtr menuRef);
 
53
 
 
54
                [DllImport (hiToolboxLib)]
 
55
                internal static extern void FlashMenuBar (uint menuID);
 
56
                
 
57
                [DllImport (hiToolboxLib)]
 
58
                internal static extern uint GetMenuID (IntPtr menuRef);
 
59
                
 
60
                [DllImport (hiToolboxLib)]
 
61
                internal static extern void ClearMenuBar ();
 
62
                
 
63
                [DllImport (hiToolboxLib)]
 
64
                internal static extern ushort CountMenuItems (IntPtr menuRef);
 
65
                
 
66
                [DllImport (hiToolboxLib)]
 
67
                internal static extern void DeleteMenuItem (IntPtr menuRef, ushort index);
 
68
                
 
69
                [DllImport (hiToolboxLib)]
 
70
                internal static extern void InsertMenu (IntPtr menuRef, ushort before_id);
 
71
                
 
72
                [DllImport (hiToolboxLib)]
 
73
                static extern CarbonMenuStatus AppendMenuItemTextWithCFString (IntPtr menuRef, IntPtr cfString, MenuItemAttributes attributes, uint commandId, out ushort index);
 
74
                
 
75
                public static ushort AppendMenuItem (IntPtr parentRef, string title, MenuItemAttributes attributes, uint commandId)
 
76
                {
 
77
                        ushort index;
 
78
                        IntPtr str = CoreFoundation.CreateString (title);
 
79
                        CarbonMenuStatus result = AppendMenuItemTextWithCFString (parentRef, str, attributes, commandId, out index);
 
80
                        CoreFoundation.Release (str);
 
81
                        CheckResult (result);
 
82
                        return index;
 
83
                }
 
84
                
 
85
                public static ushort AppendMenuSeparator (IntPtr parentRef)
 
86
                {
 
87
                        ushort index;
 
88
                        CarbonMenuStatus result = AppendMenuItemTextWithCFString (parentRef, IntPtr.Zero, MenuItemAttributes.Separator, 0, out index);
 
89
                        CheckResult (result);
 
90
                        return index;
 
91
                }
 
92
                
 
93
                [DllImport (hiToolboxLib)]
 
94
                static extern CarbonMenuStatus InsertMenuItemTextWithCFString (IntPtr menuRef, IntPtr cfString, ushort afterItemIndex,
 
95
                                                                         MenuItemAttributes attributes, uint commandID, out ushort index);
 
96
                
 
97
                public static ushort InsertMenuItem (IntPtr parentRef, string title, ushort afterItemIndex, MenuItemAttributes attributes, uint commandId)
 
98
                {
 
99
                        ushort index;
 
100
                        IntPtr str = CoreFoundation.CreateString (title);
 
101
                        CarbonMenuStatus result = InsertMenuItemTextWithCFString (parentRef, str, afterItemIndex, attributes, commandId, out index);
 
102
                        CoreFoundation.Release (str);
 
103
                        CheckResult (result);
 
104
                        return index;
 
105
                }
 
106
                
 
107
                public static ushort InsertMenuSeparator (IntPtr parentRef, ushort afterItemIndex)
 
108
                {
 
109
                        ushort index;
 
110
                        CarbonMenuStatus result = InsertMenuItemTextWithCFString (parentRef, IntPtr.Zero, afterItemIndex, MenuItemAttributes.Separator, 0, out index);
 
111
                        CheckResult (result);
 
112
                        return index;
 
113
                }
 
114
 
 
115
                
 
116
                [DllImport (hiToolboxLib)]
 
117
                static extern CarbonMenuStatus EnableMenuItem (IntPtr menuRef, ushort index);
 
118
                
 
119
                public static void EnableMenuItem (HIMenuItem item)
 
120
                {
 
121
                        CheckResult (EnableMenuItem (item.MenuRef, item.Index));
 
122
                }
 
123
                
 
124
                [DllImport (hiToolboxLib)]
 
125
                static extern CarbonMenuStatus DisableMenuItem (IntPtr menuRef, ushort index);
 
126
                
 
127
                public static void DisableMenuItem (HIMenuItem item)
 
128
                {
 
129
                        CheckResult (DisableMenuItem (item.MenuRef, item.Index));
 
130
                }
 
131
                
 
132
                [DllImport (hiToolboxLib)]
 
133
                static extern CarbonMenuStatus ChangeMenuItemAttributes (IntPtr menu, ushort item, MenuItemAttributes setTheseAttributes, 
 
134
                                                                         MenuItemAttributes clearTheseAttributes);
 
135
                
 
136
                public static void ChangeMenuItemAttributes (HIMenuItem item, MenuItemAttributes toSet, MenuItemAttributes toClear)
 
137
                {
 
138
                        CheckResult (ChangeMenuItemAttributes (item.MenuRef, item.Index, toSet, toClear));
 
139
                }
 
140
                
 
141
                [DllImport (hiToolboxLib)]
 
142
                internal static extern CarbonMenuStatus SetMenuItemHierarchicalMenu (IntPtr parentMenu, ushort parent_index, IntPtr submenu);
 
143
                
 
144
                [DllImport (hiToolboxLib)]
 
145
                internal static extern CarbonMenuStatus GetMenuItemHierarchicalMenu (IntPtr parentMenu, ushort parent_index, out IntPtr submenu);
 
146
                
 
147
                [DllImport (hiToolboxLib)]
 
148
                static extern CarbonMenuStatus SetMenuTitleWithCFString (IntPtr menuRef, IntPtr cfstring);
 
149
                
 
150
                public static void SetMenuTitle (IntPtr menuRef, string title)
 
151
                {
 
152
                        IntPtr str = CoreFoundation.CreateString (title);
 
153
                        CarbonMenuStatus result = SetMenuTitleWithCFString (menuRef, str);
 
154
                        CoreFoundation.Release (str);
 
155
                        CheckResult (result);
 
156
                }
 
157
 
 
158
                [DllImport (hiToolboxLib)]
 
159
                static extern CarbonMenuStatus SetMenuItemTextWithCFString (IntPtr menuRef, ushort index, IntPtr cfstring);
 
160
                
 
161
                public static void SetMenuItemText (IntPtr menuRef, ushort index, string title)
 
162
                {
 
163
                        IntPtr str = CoreFoundation.CreateString (title);
 
164
                        CarbonMenuStatus result = SetMenuItemTextWithCFString (menuRef, index, str);
 
165
                        CoreFoundation.Release (str);
 
166
                        CheckResult (result);
 
167
                }
 
168
 
 
169
                [DllImport (hiToolboxLib)]
 
170
                internal static extern CarbonMenuStatus SetMenuItemKeyGlyph (IntPtr menuRef, ushort index, short glyph);
 
171
 
 
172
                [DllImport (hiToolboxLib)]
 
173
                internal static extern CarbonMenuStatus SetMenuItemCommandKey (IntPtr menuRef, ushort index, bool isVirtualKey, ushort key);
 
174
 
 
175
                [DllImport (hiToolboxLib)]
 
176
                internal static extern CarbonMenuStatus SetMenuItemModifiers (IntPtr menuRef, ushort index, MenuAccelModifier modifiers);
 
177
                
 
178
                [DllImport (hiToolboxLib)]
 
179
                static extern CarbonMenuStatus GetMenuItemCommandID (IntPtr menuRef, ushort index, out uint commandId);
 
180
                
 
181
                public static uint GetMenuItemCommandID (HIMenuItem item)
 
182
                {
 
183
                        uint id;
 
184
                        CheckResult (GetMenuItemCommandID (item.MenuRef, item.Index, out id));
 
185
                        return id;
 
186
                }
 
187
                
 
188
                [DllImport (hiToolboxLib)]
 
189
                static extern CarbonMenuStatus GetIndMenuItemWithCommandID (IntPtr startAtMenuRef, uint commandID, uint commandItemIndex, 
 
190
                                                                      out IntPtr itemMenuRef, out ushort itemIndex);
 
191
                
 
192
                public static HIMenuItem GetMenuItem (uint commandId)
 
193
                {
 
194
                        IntPtr itemMenuRef;
 
195
                        ushort itemIndex;
 
196
                        CheckResult (GetIndMenuItemWithCommandID (IntPtr.Zero, commandId, 1, out itemMenuRef, out itemIndex));
 
197
                        return new HIMenuItem (itemMenuRef, itemIndex);
 
198
                }
 
199
                
 
200
                [DllImport (hiToolboxLib)]
 
201
                public static extern CarbonMenuStatus CancelMenuTracking (IntPtr rootMenu, bool inImmediate, MenuDismissalReason reason);
 
202
                
 
203
                [DllImport (hiToolboxLib)]
 
204
                public static extern CarbonMenuStatus SetMenuItemData (IntPtr menu, uint indexOrCommandID, bool isCommandID, ref MenuItemData data);
 
205
                
 
206
                [DllImport (hiToolboxLib)]
 
207
                static extern CarbonMenuStatus SetMenuItemRefCon (IntPtr menuRef, ushort index, uint inRefCon);
 
208
                
 
209
                public static void SetMenuItemReferenceConstant (HIMenuItem item, uint value)
 
210
                {
 
211
                        CheckResult (SetMenuItemRefCon (item.MenuRef, item.Index, value));
 
212
                }
 
213
                
 
214
                [DllImport (hiToolboxLib)]
 
215
                static extern CarbonMenuStatus GetMenuItemRefCon (IntPtr menuRef, ushort index, out uint inRefCon);
 
216
                
 
217
                public static uint GetMenuItemReferenceConstant (HIMenuItem item)
 
218
                {
 
219
                        uint val;
 
220
                        CheckResult (GetMenuItemRefCon (item.MenuRef, item.Index, out val));
 
221
                        return val;
 
222
                }
 
223
                
 
224
                internal static void CheckResult (CarbonMenuStatus result)
 
225
                {
 
226
                        if (result != CarbonMenuStatus.Ok)
 
227
                                throw new CarbonMenuException (result);
 
228
                }
 
229
        }
 
230
        
 
231
        class CarbonMenuException : Exception
 
232
        {
 
233
                public CarbonMenuException (CarbonMenuStatus result)
 
234
                {
 
235
                        this.Result = result;
 
236
                }
 
237
                
 
238
                public CarbonMenuStatus Result { get; private set; }
 
239
                
 
240
                public override string ToString ()
 
241
                {
 
242
                        return string.Format("CarbonMenuException: Result={0}\n{1}", Result, StackTrace);
 
243
                }
 
244
        }
 
245
        
 
246
        internal enum CarbonMenuStatus // this is an OSStatus
 
247
        { 
 
248
                Ok = 0,
 
249
                PropertyInvalid = -5603,
 
250
                PropertyNotFound = -5604,
 
251
                NotFound  = -5620,
 
252
                UsesSystemDef = -5621,
 
253
                ItemNotFound = -5622,
 
254
                Invalid = -5623
 
255
        }
 
256
 
 
257
        [Flags]
 
258
        internal enum MenuAttributes {
 
259
                ExcludesMarkColumn = 1,
 
260
                AutoDisable = 1 << 2,
 
261
                UsePencilGlyph = 1 << 3,
 
262
                Hidden = 1 << 4,
 
263
                CondenseSeparators = 1 << 5,
 
264
                DoNotCacheImage = 1 << 6,
 
265
                DoNotUseUserCommandKeys = 1 << 7
 
266
        }
 
267
 
 
268
        internal enum MenuAccelModifier : byte
 
269
        {
 
270
                CommandModifier = 0,
 
271
                ShiftModifier = 1 << 0,
 
272
                OptionModifier = 1 << 1,
 
273
                ControlModifier = 1 << 2,
 
274
                None = 1 << 3
 
275
        }
 
276
        
 
277
        [Flags]
 
278
        internal enum MenuItemAttributes : uint
 
279
        {
 
280
                Disabled = 1 << 0,
 
281
                IconDisabled = 1 << 1,
 
282
                SubmenuParentChoosable = 1 << 2,
 
283
                Dynamic = 1 << 3,
 
284
                NotPreviousAlternate = 1 << 4,
 
285
                Hidden = 1 << 5,
 
286
                Separator = 1 << 6,
 
287
                SectionHeader = 1 << 7,
 
288
                IgnoreMeta = 1 << 8,
 
289
                AutoRepeat = 1 << 9,
 
290
                UseVirtualKey = 1 << 10,
 
291
                CustomDraw = 1 << 11,
 
292
                IncludeInCmdKeyMatching = 1 << 12,
 
293
                AutoDisable = 1 << 13,
 
294
                UpdateSingleItem = 1 << 14
 
295
        }
 
296
        
 
297
        internal enum MenuDismissalReason : uint
 
298
        {
 
299
                DismissedBySelection   = 1,
 
300
                DismissedByUserCancel  = 2,
 
301
                DismissedByMouseDown   = 3,
 
302
                DismissedByMouseUp     = 4,
 
303
                DismissedByKeyEvent    = 5,
 
304
                DismissedByAppSwitch   = 6,
 
305
                DismissedByTimeout     = 7,
 
306
                DismissedByCancelMenuTracking = 8,
 
307
                DismissedByActivationChange = 9,
 
308
                DismissedByFocusChange = 10,
 
309
        }
 
310
        
 
311
        
 
312
        [StructLayout(LayoutKind.Sequential, Pack = 2)]
 
313
        internal struct MenuItemData
 
314
        {
 
315
                #pragma warning disable 0169
 
316
                MenuItemDataFlags whichData; //8
 
317
                IntPtr text; //Str255 //12
 
318
                [MarshalAs (UnmanagedType.U2)] //14
 
319
                char mark;
 
320
                [MarshalAs (UnmanagedType.U2)] //16
 
321
                char cmdKey;
 
322
                uint cmdKeyGlyph; //20
 
323
                uint cmdKeyModifiers; //24
 
324
                byte style; //25
 
325
                [MarshalAs (UnmanagedType.U1)] //26
 
326
                bool enabled;
 
327
                [MarshalAs (UnmanagedType.U1)] //27
 
328
                bool iconEnabled;
 
329
                byte filler1; //28
 
330
                int iconID; //32
 
331
                uint iconType; //36
 
332
                IntPtr iconHandle; //40
 
333
                uint cmdID; //44
 
334
                CarbonTextEncoding encoding; //48
 
335
                ushort submenuID; //50
 
336
                IntPtr submenuHandle; //54
 
337
                int fontID; //58
 
338
                uint refcon; //62
 
339
                // LAMESPEC: this field is documented as OptionBits
 
340
                MenuItemAttributes attr; //66
 
341
                IntPtr cfText; //70
 
342
                // Collection 
 
343
                IntPtr properties; //74
 
344
                uint indent; //78
 
345
                ushort cmdVirtualKey; //80
 
346
                
 
347
                //these aren't documented
 
348
                IntPtr attributedText; //84
 
349
                IntPtr font; //88
 
350
                #pragma warning restore 0169
 
351
                
 
352
                #region Properties
 
353
                
 
354
                public IntPtr Text {
 
355
                        get { return text; }
 
356
                        set {
 
357
                                whichData |= MenuItemDataFlags.Text;
 
358
                                text = value;
 
359
                        }
 
360
                }
 
361
                
 
362
                public char Mark {
 
363
                        get { return mark; }
 
364
                        set {
 
365
                                whichData |= MenuItemDataFlags.Mark;
 
366
                                mark = value;
 
367
                        }
 
368
                }
 
369
                
 
370
                public char CommandKey {
 
371
                        get { return cmdKey; }
 
372
                        set {
 
373
                                whichData |= MenuItemDataFlags.CmdKey;
 
374
                                cmdKey = value;
 
375
                        }
 
376
                }
 
377
                
 
378
                public uint CommandKeyGlyph {
 
379
                        get { return cmdKeyGlyph; }
 
380
                        set {
 
381
                                whichData |= MenuItemDataFlags.CmdKeyGlyph;
 
382
                                cmdKeyGlyph = value;
 
383
                        }
 
384
                }
 
385
                
 
386
                public MenuAccelModifier CommandKeyModifiers {
 
387
                        get { return (MenuAccelModifier) cmdKeyModifiers; }
 
388
                        set {
 
389
                                whichData |= MenuItemDataFlags.CmdKeyModifiers;
 
390
                                cmdKeyModifiers = (uint) value;
 
391
                        }
 
392
                }
 
393
                
 
394
                public byte Style {
 
395
                        get { return style; }
 
396
                        set {
 
397
                                whichData |= MenuItemDataFlags.Style;
 
398
                                style = value;
 
399
                        }
 
400
                }
 
401
                
 
402
                public bool Enabled {
 
403
                        get { return enabled; }
 
404
                        set {
 
405
                                whichData |= MenuItemDataFlags.Enabled;
 
406
                                enabled = value;
 
407
                        }
 
408
                }
 
409
                
 
410
                public bool IconEnabled {
 
411
                        get { return iconEnabled; }
 
412
                        set {
 
413
                                whichData |= MenuItemDataFlags.IconEnabled;
 
414
                                iconEnabled = value;
 
415
                        }
 
416
                }
 
417
                
 
418
                public int IconID {
 
419
                        get { return iconID; }
 
420
                        set {
 
421
                                whichData |= MenuItemDataFlags.IconID;
 
422
                                iconID = value;
 
423
                        }
 
424
                }
 
425
                
 
426
                public HIIconHandle IconHandle {
 
427
                        get { return new HIIconHandle (iconHandle, iconType); }
 
428
                        set {
 
429
                                whichData |= MenuItemDataFlags.IconHandle;
 
430
                                iconHandle = value.Ref;
 
431
                                iconType = value.Type;
 
432
                        }
 
433
                }
 
434
                
 
435
                public uint CommandID {
 
436
                        get { return cmdID; }
 
437
                        set {
 
438
                                whichData |= MenuItemDataFlags.CommandID;
 
439
                                cmdID = value;
 
440
                        }
 
441
                }
 
442
                
 
443
                public CarbonTextEncoding Encoding {
 
444
                        get { return encoding; }
 
445
                        set {
 
446
                                whichData |= MenuItemDataFlags.TextEncoding;
 
447
                                encoding = value;
 
448
                        }
 
449
                }
 
450
                
 
451
                public ushort SubmenuID {
 
452
                        get { return submenuID; }
 
453
                        set {
 
454
                                whichData |= MenuItemDataFlags.SubmenuID;
 
455
                                submenuID = value;
 
456
                        }
 
457
                }
 
458
                
 
459
                public IntPtr SubmenuHandle {
 
460
                        get { return submenuHandle; }
 
461
                        set {
 
462
                                whichData |= MenuItemDataFlags.SubmenuHandle;
 
463
                                submenuHandle = value;
 
464
                        }
 
465
                }
 
466
                
 
467
                public int FontID {
 
468
                        get { return fontID; }
 
469
                        set {
 
470
                                whichData |= MenuItemDataFlags.FontID;
 
471
                                fontID = value;
 
472
                        }
 
473
                }
 
474
                
 
475
                public uint ReferenceConstant {
 
476
                        get { return refcon; }
 
477
                        set {
 
478
                                whichData |= MenuItemDataFlags.Refcon;
 
479
                                refcon = value;
 
480
                        }
 
481
                }
 
482
                
 
483
                public MenuItemAttributes Attributes {
 
484
                        get { return attr; }
 
485
                        set {
 
486
                                whichData |= MenuItemDataFlags.Attributes;
 
487
                                attr = value;
 
488
                        }
 
489
                }
 
490
                
 
491
                public IntPtr CFText {
 
492
                        get { return cfText; }
 
493
                        set {
 
494
                                whichData |= MenuItemDataFlags.CFString;
 
495
                                cfText = value;
 
496
                        }
 
497
                }
 
498
                
 
499
                public IntPtr Properties {
 
500
                        get { return properties; }
 
501
                        set {
 
502
                                whichData |= MenuItemDataFlags.Properties;
 
503
                                properties = value;
 
504
                        }
 
505
                }
 
506
                
 
507
                public uint Indent {
 
508
                        get { return indent; }
 
509
                        set {
 
510
                                whichData |= MenuItemDataFlags.Indent;
 
511
                                indent = value;
 
512
                        }
 
513
                }
 
514
                
 
515
                public ushort CommandVirtualKey {
 
516
                        get { return cmdVirtualKey; }
 
517
                        set {
 
518
                                whichData |= MenuItemDataFlags.CmdVirtualKey;
 
519
                                cmdVirtualKey = value;
 
520
                        }
 
521
                }
 
522
                
 
523
                #endregion
 
524
                
 
525
                #region 'Has' properties
 
526
                
 
527
                public bool HasText {
 
528
                        get { return (whichData & MenuItemDataFlags.Text) != 0; }
 
529
                }
 
530
                
 
531
                public bool HasMark {
 
532
                        get { return (whichData & MenuItemDataFlags.Mark) != 0; }
 
533
                }
 
534
                
 
535
                public bool HasCommandKey {
 
536
                        get { return (whichData & MenuItemDataFlags.CmdKey) != 0; }
 
537
                }
 
538
                
 
539
                public bool HasCommandKeyGlyph {
 
540
                        get { return (whichData & MenuItemDataFlags.CmdKeyGlyph) != 0; }
 
541
                }
 
542
                
 
543
                public bool HasCommandKeyModifiers {
 
544
                        get { return (whichData & MenuItemDataFlags.CmdKeyModifiers) != 0; }
 
545
                }
 
546
                
 
547
                public bool HasStyle {
 
548
                        get { return (whichData & MenuItemDataFlags.Style) != 0; }
 
549
                }
 
550
                
 
551
                public bool HasEnabled {
 
552
                        get { return (whichData & MenuItemDataFlags.Enabled) != 0; }
 
553
                }
 
554
                
 
555
                public bool HasIconEnabled {
 
556
                        get { return (whichData & MenuItemDataFlags.IconEnabled) != 0; }
 
557
                }
 
558
                
 
559
                public bool HasIconID {
 
560
                        get { return (whichData & MenuItemDataFlags.IconID) != 0; }
 
561
                }
 
562
                
 
563
                public bool HasIconHandle {
 
564
                        get { return (whichData & MenuItemDataFlags.IconHandle) != 0; }
 
565
                }
 
566
                
 
567
                public bool HasCommandID {
 
568
                        get { return (whichData & MenuItemDataFlags.CommandID) != 0; }
 
569
                }
 
570
                
 
571
                public bool HasEncoding {
 
572
                        get { return (whichData & MenuItemDataFlags.TextEncoding) != 0; }
 
573
                }
 
574
                
 
575
                public bool HasSubmenuID {
 
576
                        get { return (whichData & MenuItemDataFlags.SubmenuID) != 0; }
 
577
                }
 
578
                
 
579
                public bool HasSubmenuHandle {
 
580
                        get { return (whichData & MenuItemDataFlags.SubmenuHandle) != 0; }
 
581
                }
 
582
                
 
583
                public bool HasFontID {
 
584
                        get { return (whichData & MenuItemDataFlags.FontID) != 0; }
 
585
                }
 
586
                
 
587
                public bool HasRefcon {
 
588
                        get { return (whichData & MenuItemDataFlags.Refcon) != 0; }
 
589
                }
 
590
                
 
591
                public bool HasAttributes {
 
592
                        get { return (whichData & MenuItemDataFlags.Attributes) != 0; }
 
593
                }
 
594
                
 
595
                public bool HasCFText {
 
596
                        get { return (whichData & MenuItemDataFlags.CFString) != 0; }
 
597
                }
 
598
                
 
599
                public bool HasProperties {
 
600
                        get { return (whichData & MenuItemDataFlags.Properties) != 0; }
 
601
                }
 
602
                
 
603
                public bool HasIndent {
 
604
                        get { return (whichData & MenuItemDataFlags.Indent) != 0; }
 
605
                }
 
606
                
 
607
                public bool HasCommandVirtualKey {
 
608
                        get { return (whichData & MenuItemDataFlags.CmdVirtualKey) != 0; }
 
609
                }
 
610
                
 
611
                #endregion
 
612
        }
 
613
        
 
614
        struct HIIconHandle
 
615
        {
 
616
                IntPtr _ref;
 
617
                uint type;
 
618
                
 
619
                public HIIconHandle (IntPtr @ref, uint type)
 
620
                {
 
621
                        this._ref = @ref;
 
622
                        this.type = type;
 
623
                }
 
624
                
 
625
                public IntPtr Ref { get { return _ref; } }
 
626
                public uint Type { get { return type; } }
 
627
        }
 
628
        
 
629
        enum CarbonTextEncoding : uint
 
630
        {
 
631
        }
 
632
        
 
633
        enum MenuItemDataFlags : ulong
 
634
        {
 
635
                Text = (1 << 0),
 
636
                Mark = (1 << 1),
 
637
                CmdKey = (1 << 2),
 
638
                CmdKeyGlyph = (1 << 3),
 
639
                CmdKeyModifiers = (1 << 4),
 
640
                Style = (1 << 5),
 
641
                Enabled = (1 << 6),
 
642
                IconEnabled = (1 << 7),
 
643
                IconID = (1 << 8),
 
644
                IconHandle = (1 << 9),
 
645
                CommandID = (1 << 10),
 
646
                TextEncoding = (1 << 11),
 
647
                SubmenuID = (1 << 12),
 
648
                SubmenuHandle = (1 << 13),
 
649
                FontID = (1 << 14),
 
650
                Refcon = (1 << 15),
 
651
                Attributes = (1 << 16),
 
652
                CFString = (1 << 17),
 
653
                Properties = (1 << 18),
 
654
                Indent = (1 << 19),
 
655
                CmdVirtualKey = (1 << 20),
 
656
                AllDataVersionOne = 0x000FFFFF,
 
657
                AllDataVersionTwo = AllDataVersionOne | CmdVirtualKey,
 
658
        }
 
659
        
 
660
        enum MenuGlyphs : byte //char
 
661
        {
 
662
                None = 0x00,
 
663
                TabRight = 0x02,
 
664
                TabLeft = 0x03,
 
665
                Enter = 0x04,
 
666
                Shift = 0x05,
 
667
                Control = 0x06,
 
668
                Option = 0x07,
 
669
                Space = 0x09,
 
670
                DeleteRight = 0x0A,
 
671
                Return = 0x0B,
 
672
                ReturnR2L = 0x0C,
 
673
                NonmarkingReturn = 0x0D,
 
674
                Pencil = 0x0F,
 
675
                DownwardArrowDashed = 0x10,
 
676
                Command = 0x11,
 
677
                Checkmark = 0x12,
 
678
                Diamond = 0x13,
 
679
                AppleLogoFilled = 0x14,
 
680
                ParagraphKorean = 0x15,
 
681
                DeleteLeft = 0x17,
 
682
                LeftArrowDashed = 0x18,
 
683
                UpArrowDashed = 0x19,
 
684
                RightArrowDashed = 0x1A,
 
685
                Escape = 0x1B,
 
686
                Clear = 0x1C,
 
687
                LeftDoubleQuotesJapanese = 0x1D,
 
688
                RightDoubleQuotesJapanese = 0x1E,
 
689
                TrademarkJapanese = 0x1F,
 
690
                Blank = 0x61,
 
691
                PageUp = 0x62,
 
692
                CapsLock = 0x63,
 
693
                LeftArrow = 0x64,
 
694
                RightArrow = 0x65,
 
695
                NorthwestArrow = 0x66,
 
696
                Help = 0x67,
 
697
                UpArrow = 0x68,
 
698
                SoutheastArrow = 0x69,
 
699
                DownArrow = 0x6A,
 
700
                PageDown = 0x6B,
 
701
                AppleLogoOutline = 0x6C,
 
702
                ContextualMenu = 0x6D,
 
703
                Power = 0x6E,
 
704
                F1 = 0x6F,
 
705
                F2 = 0x70,
 
706
                F3 = 0x71,
 
707
                F4 = 0x72,
 
708
                F5 = 0x73,
 
709
                F6 = 0x74,
 
710
                F7 = 0x75,
 
711
                F8 = 0x76,
 
712
                F9 = 0x77,
 
713
                F10 = 0x78,
 
714
                F11 = 0x79,
 
715
                F12 = 0x7A,
 
716
                F13 = 0x87,
 
717
                F14 = 0x88,
 
718
                F15 = 0x89,
 
719
                ControlISO = 0x8A,
 
720
                Eject = 0x8C
 
721
        };
 
722
}