1 /*
2 * Copyright (c) 2015 Guillaume Piolat
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 *   notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 *   notice, this list of conditions and the following disclaimer in the
14 *   documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the names 'Derelict', 'DerelictSDL', nor the names of its contributors
17 *   may be used to endorse or promote products derived from this software
18 *   without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 module derelict.carbon.hitoolbox;
33 
34 import derelict.carbon.corefoundation;
35 import derelict.carbon.coregraphics;
36 
37 
38 alias WindowRef = void*; // This actually belongs to QD framework
39 
40 // <HIToolbox/CarbonEventsCore.h.h>
41 
42 alias EventRef = void*;
43 alias EventLoopRef = void*;
44 alias EventLoopTimerRef = void*;
45 alias EventHandlerRef = void*;
46 alias EventHandlerCallRef = void*;
47 alias EventTargetRef = void*;
48 
49 alias EventParamName = OSType;
50 alias EventParamType = OSType;
51 alias EventTime = double;
52 alias EventTimeout = EventTime;
53 alias EventTimerInterval = EventTime;
54 
55 enum EventTime kEventDurationSecond = 1.0;
56 
57 enum : int
58 {
59     eventAlreadyPostedErr         = -9860,
60     eventTargetBusyErr            = -9861,
61     eventClassInvalidErr          = -9862,
62     eventClassIncorrectErr        = -9864,
63     eventDeferAccessibilityEventErr = -9865,
64     eventHandlerAlreadyInstalledErr = -9866,
65     eventInternalErr              = -9868,
66     eventKindIncorrectErr         = -9869,
67     eventParameterNotFoundErr     = -9870,
68     eventNotHandledErr            = -9874,
69     eventLoopTimedOutErr          = -9875,
70     eventLoopQuitErr              = -9876,
71     eventNotInQueueErr            = -9877,
72     eventHotKeyExistsErr          = -9878,
73     eventHotKeyInvalidErr         = -9879,
74     eventPassToNextTargetErr      = -9880
75 }
76 
77 
78 struct EventTypeSpec
79 {
80     OSType eventClass;
81     UInt32 eventKind;
82 }
83 
84 extern (C) nothrow @nogc
85 {
86     alias da_GetMainEventLoop = EventLoopRef function();
87     alias da_InstallEventHandler = OSStatus function(EventTargetRef, EventHandlerUPP, ItemCount, const(EventTypeSpec)*, void*, EventHandlerRef*);
88     alias da_GetEventClass = OSType function(EventRef inEvent);
89     alias da_GetEventKind = UInt32 function(EventRef inEvent);
90     alias da_GetEventParameter = OSStatus function(EventRef, EventParamName, EventParamType, EventParamType*, ByteCount, ByteCount*, void*);
91     alias da_InstallEventLoopTimer = OSStatus function(EventLoopRef, EventTimerInterval, EventTimerInterval,
92                                                        EventLoopTimerUPP, void*, EventLoopTimerRef*);
93 
94     alias da_RemoveEventHandler = OSStatus function(EventHandlerRef);
95     alias da_RemoveEventLoopTimer = OSStatus function(EventLoopTimerRef);
96 }
97 
98 __gshared
99 {
100     da_GetMainEventLoop GetMainEventLoop;
101     da_InstallEventHandler InstallEventHandler;
102     da_GetEventClass GetEventClass;
103     da_GetEventKind GetEventKind;
104     da_GetEventParameter GetEventParameter;
105     da_InstallEventLoopTimer InstallEventLoopTimer;
106     da_RemoveEventLoopTimer RemoveEventLoopTimer;
107     da_RemoveEventHandler RemoveEventHandler;
108 }
109 
110 
111 extern(C) nothrow
112 {
113     alias EventHandlerProcPtr = OSStatus function(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData);
114     alias EventHandlerUPP = EventHandlerProcPtr;
115     alias EventLoopTimerUPP = void function(EventLoopTimerRef inTimer, void* inUserData);
116 }
117 
118 
119 
120 // <HIToolbox/CarbonEvents.h>
121 
122 enum : int
123 {
124   kEventClassMouse              = CCONST('m', 'o', 'u', 's'),
125   kEventClassKeyboard           = CCONST('k', 'e', 'y', 'b'),
126   kEventClassTextInput          = CCONST('t', 'e', 'x', 't'),
127   kEventClassApplication        = CCONST('a', 'p', 'p', 'l'),
128   kEventClassAppleEvent         = CCONST('e', 'p', 'p', 'c'),
129   kEventClassMenu               = CCONST('m', 'e', 'n', 'u'),
130   kEventClassWindow             = CCONST('w', 'i', 'n', 'd'),
131   kEventClassControl            = CCONST('c', 'n', 't', 'l'),
132   kEventClassCommand            = CCONST('c', 'm', 'd', 's'),
133   kEventClassTablet             = CCONST('t', 'b', 'l', 't'),
134   kEventClassVolume             = CCONST('v', 'o', 'l', ' '),
135   kEventClassAppearance         = CCONST('a', 'p', 'p', 'm'),
136   kEventClassService            = CCONST('s', 'e', 'r', 'v'),
137   kEventClassToolbar            = CCONST('t', 'b', 'a', 'r'),
138   kEventClassToolbarItem        = CCONST('t', 'b', 'i', 't'),
139   kEventClassToolbarItemView    = CCONST('t', 'b', 'i', 'v'),
140   kEventClassAccessibility      = CCONST('a', 'c', 'c', 'e'),
141   kEventClassSystem             = CCONST('m', 'a', 'c', 's'),
142   kEventClassInk                = CCONST('i', 'n', 'k', ' '),
143   kEventClassTSMDocumentAccess  = CCONST('t', 'd', 'a', 'c'),
144   kEventClassGesture            = CCONST('g', 'e', 's', 't')
145 }
146 
147 enum : int
148 {
149     kEventControlInitialize                     = 1000,
150     kEventControlDispose                        = 1001,
151     kEventControlGetOptimalBounds               = 1003,
152     kEventControlOptimalBoundsChanged           = 1004,
153     kEventControlDefInitialize                  = kEventControlInitialize,
154     kEventControlDefDispose                     = kEventControlDispose,
155     kEventControlHit                            = 1,
156     kEventControlSimulateHit                    = 2,
157     kEventControlHitTest                        = 3,
158     kEventControlDraw                           = 4,
159     kEventControlApplyBackground                = 5,
160     kEventControlApplyTextColor                 = 6,
161     kEventControlSetFocusPart                   = 7,
162     kEventControlGetFocusPart                   = 8,
163     kEventControlActivate                       = 9,
164     kEventControlDeactivate                     = 10,
165     kEventControlSetCursor                      = 11,
166     kEventControlContextualMenuClick            = 12,
167     kEventControlClick                          = 13,
168     kEventControlGetNextFocusCandidate          = 14,
169     kEventControlGetAutoToggleValue             = 15,
170     kEventControlInterceptSubviewClick          = 16,
171     kEventControlGetClickActivation             = 17,
172     kEventControlDragEnter                      = 18,
173     kEventControlDragWithin                     = 19,
174     kEventControlDragLeave                      = 20,
175     kEventControlDragReceive                    = 21,
176     kEventControlInvalidateForSizeChange        = 22,
177     kEventControlTrackingAreaEntered            = 23,
178     kEventControlTrackingAreaExited             = 24,
179     kEventControlTrack                          = 51,
180     kEventControlGetScrollToHereStartPoint      = 52,
181     kEventControlGetIndicatorDragConstraint     = 53,
182     kEventControlIndicatorMoved                 = 54,
183     kEventControlGhostingFinished               = 55,
184     kEventControlGetActionProcPart              = 56,
185     kEventControlGetPartRegion                  = 101,
186     kEventControlGetPartBounds                  = 102,
187     kEventControlSetData                        = 103,
188     kEventControlGetData                        = 104,
189     kEventControlGetSizeConstraints             = 105,
190     kEventControlGetFrameMetrics                = 106,
191     kEventControlValueFieldChanged              = 151,
192     kEventControlAddedSubControl                = 152,
193     kEventControlRemovingSubControl             = 153,
194     kEventControlBoundsChanged                  = 154,
195     kEventControlVisibilityChanged              = 157,
196     kEventControlTitleChanged                   = 158,
197     kEventControlOwningWindowChanged            = 159,
198     kEventControlHiliteChanged                  = 160,
199     kEventControlEnabledStateChanged            = 161,
200     kEventControlLayoutInfoChanged              = 162,
201     kEventControlFocusPartChanged               = 164,
202     kEventControlArbitraryMessage               = 201
203 }
204 
205 enum : int
206 {
207     kEventMouseDown                 = 1,
208     kEventMouseUp                   = 2,
209     kEventMouseMoved                = 5,
210     kEventMouseDragged              = 6,
211     kEventMouseEntered              = 8,
212     kEventMouseExited               = 9,
213     kEventMouseWheelMoved           = 10,
214     kEventMouseScroll               = 11
215 }
216 
217 alias EventMouseWheelAxis = UInt16;
218 enum : EventMouseWheelAxis
219 {
220     kEventMouseWheelAxisX         = 0,
221     kEventMouseWheelAxisY         = 1
222 }
223 
224 
225 enum : int
226 {
227     kEventRawKeyDown                = 1,
228     kEventRawKeyRepeat              = 2,
229     kEventRawKeyUp                  = 3,
230     kEventRawKeyModifiersChanged    = 4,
231     kEventHotKeyPressed             = 5,
232     kEventHotKeyReleased            = 6
233 }
234 
235 enum : int
236 {
237     kEventWindowUpdate                  = 1,
238     kEventWindowDrawContent             = 2,
239     kEventWindowActivated               = 5,
240     kEventWindowDeactivated             = 6,
241     kEventWindowHandleActivate          = 91,
242     kEventWindowHandleDeactivate        = 92,
243     kEventWindowGetClickActivation      = 7,
244     kEventWindowGetClickModality        = 8,
245     kEventWindowShowing                 = 22,
246     kEventWindowHiding                  = 23,
247     kEventWindowShown                   = 24,
248     kEventWindowHidden                  = 25,
249     kEventWindowCollapsing              = 86,
250     kEventWindowExpanding               = 87,
251     kEventWindowExpanded                = 70,
252     kEventWindowZoomed                  = 76,
253     kEventWindowBoundsChanging          = 26,
254     kEventWindowBoundsChanged           = 27,
255     kEventWindowResizeStarted           = 28,
256     kEventWindowResizeCompleted         = 29,
257     kEventWindowDragStarted             = 30,
258     kEventWindowDragCompleted           = 31,
259     kEventWindowClosed                  = 73,
260     kEventWindowTransitionStarted       = 88,
261     kEventWindowTransitionCompleted     = 89,
262     kEventWindowClickDragRgn            = 32,
263     kEventWindowClickResizeRgn          = 33,
264     kEventWindowClickCollapseRgn        = 34,
265     kEventWindowClickCloseRgn           = 35,
266     kEventWindowClickZoomRgn            = 36,
267     kEventWindowClickContentRgn         = 37,
268     kEventWindowClickProxyIconRgn       = 38,
269     kEventWindowClickToolbarButtonRgn   = 41,
270     kEventWindowClickStructureRgn       = 42,
271     kEventWindowCursorChange            = 40,
272     kEventWindowCollapse                = 66,
273     kEventWindowCollapsed               = 67,
274     kEventWindowCollapseAll             = 68,
275     kEventWindowExpand                  = 69,
276     kEventWindowExpandAll               = 71,
277     kEventWindowClose                   = 72,
278     kEventWindowCloseAll                = 74,
279     kEventWindowZoom                    = 75,
280     kEventWindowZoomAll                 = 77,
281     kEventWindowContextualMenuSelect    = 78,
282     kEventWindowPathSelect              = 79,
283     kEventWindowGetIdealSize            = 80,
284     kEventWindowGetMinimumSize          = 81,
285     kEventWindowGetMaximumSize          = 82,
286     kEventWindowConstrain               = 83,
287     kEventWindowRestoreFromDock         = 84,
288     kEventWindowHandleContentClick      = 85,
289     kEventWindowGetDockTileMenu         = 90,
290     kEventWindowGetIdealStandardState   = 93,
291     kEventWindowUpdateDockTile          = 94,
292     kEventWindowColorSpaceChanged       = 95,
293     kEventWindowRestoredAfterRelaunch   = 96,
294     kEventWindowProxyBeginDrag          = 128,
295     kEventWindowProxyEndDrag            = 129,
296     kEventWindowToolbarSwitchMode       = 150,
297     kEventWindowFocusAcquired           = 200,
298     kEventWindowFocusRelinquish         = 201,
299     kEventWindowFocusContent            = 202,
300     kEventWindowFocusToolbar            = 203,
301     kEventWindowFocusDrawer             = 204,
302     kEventWindowFocusLost               = 205,
303     kEventWindowFocusRestored           = 206,
304     kEventWindowSheetOpening            = 210,
305     kEventWindowSheetOpened             = 211,
306     kEventWindowSheetClosing            = 212,
307     kEventWindowSheetClosed             = 213,
308     kEventWindowDrawerOpening           = 220,
309     kEventWindowDrawerOpened            = 221,
310     kEventWindowDrawerClosing           = 222,
311     kEventWindowDrawerClosed            = 223,
312     kEventWindowGetFullScreenContentSize    = 240,
313     kEventWindowFullScreenEnterStarted      = 241,
314     kEventWindowFullScreenEnterCompleted    = 242,
315     kEventWindowFullScreenExitStarted       = 243,
316     kEventWindowFullScreenExitCompleted     = 244,
317     kEventWindowDrawFrame               = 1000,
318     kEventWindowDrawPart                = 1001,
319     kEventWindowGetRegion               = 1002,
320     kEventWindowHitTest                 = 1003,
321     kEventWindowInit                    = 1004,
322     kEventWindowDispose                 = 1005,
323     kEventWindowDragHilite              = 1006,
324     kEventWindowModified                = 1007,
325     kEventWindowSetupProxyDragImage     = 1008,
326     kEventWindowStateChanged            = 1009,
327     kEventWindowMeasureTitle            = 1010,
328     kEventWindowDrawGrowBox             = 1011,
329     kEventWindowGetGrowImageRegion      = 1012,
330     kEventWindowPaint                   = 1013,
331     kEventWindowAttributesChanged       = 1019,
332     kEventWindowTitleChanged            = 1020
333 }
334 
335 enum : int
336 {
337     kEventParamMouseLocation      = CCONST('m', 'l', 'o', 'c'),
338     kEventParamWindowMouseLocation = CCONST('w', 'm', 'o', 'u'),
339     kEventParamMouseButton        = CCONST('m', 'b', 't', 'n'),
340     kEventParamClickCount         = CCONST('c', 'c', 'n', 't'),
341     kEventParamMouseWheelAxis     = CCONST('m', 'w', 'a', 'x'),
342     kEventParamMouseWheelDelta    = CCONST('m', 'w', 'd', 'l'),
343     kEventParamMouseWheelSmoothVerticalDelta = CCONST('s', 'a', 'x', 'y'),
344     kEventParamMouseWheelSmoothHorizontalDelta = CCONST('s', 'a', 'x', 'x'),
345     kEventParamDirectionInverted  = CCONST('d', 'i', 'r', 'i'),
346     kEventParamMouseDelta         = CCONST('m', 'd', 't', 'a'),
347     kEventParamMouseChord         = CCONST('c', 'h', 'o', 'r'),
348     kEventParamTabletEventType    = CCONST('t', 'b', 'l', 't'),
349     kEventParamMouseTrackingRef   = CCONST('m', 't', 'r', 'f'),
350     typeMouseButton               = CCONST('m', 'b', 't', 'n'),
351     typeMouseWheelAxis            = CCONST('m', 'w', 'a', 'x'),
352     typeMouseTrackingRef          = CCONST('m', 't', 'r', 'f')
353 }
354 
355 enum : int
356 {
357     kEventParamWindowRef          = CCONST('w', 'i', 'n', 'd'),
358     kEventParamGrafPort           = CCONST('g', 'r', 'a', 'f'),
359     kEventParamMenuRef            = CCONST('m', 'e', 'n', 'u'),
360     kEventParamEventRef           = CCONST('e', 'v', 'n', 't'),
361     kEventParamControlRef         = CCONST('c', 't', 'r', 'l'),
362     kEventParamRgnHandle          = CCONST('r', 'g', 'n', 'h'),
363     kEventParamEnabled            = CCONST('e', 'n', 'a', 'b'),
364     kEventParamDimensions         = CCONST('d', 'i', 'm', 's'),
365     kEventParamBounds             = CCONST('b', 'o', 'u', 'n'),
366     kEventParamAvailableBounds    = CCONST('a', 'v', 'l', 'b'),
367 //    kEventParamAEEventID          = keyAEEventID,
368 //    kEventParamAEEventClass       = keyAEEventClass,
369     kEventParamCGContextRef       = CCONST('c', 'n', 't', 'x'),
370     kEventParamCGImageRef         = CCONST('c', 'g', 'i', 'm'),
371     kEventParamDeviceDepth        = CCONST('d', 'e', 'v', 'd'),
372     kEventParamDeviceColor        = CCONST('d', 'e', 'v', 'c'),
373     kEventParamMutableArray       = CCONST('m', 'a', 'r', 'r'),
374     kEventParamResult             = CCONST('a', 'n', 's', 'r'),
375     kEventParamMinimumSize        = CCONST('m', 'n', 's', 'z'),
376     kEventParamMaximumSize        = CCONST('m', 'x', 's', 'z'),
377     kEventParamAttributes         = CCONST('a', 't', 't', 'r'),
378     kEventParamReason             = CCONST('w', 'h', 'y', '?'),
379     kEventParamTransactionID      = CCONST('t', 'r', 'n', 's'),
380     kEventParamDisplayDevice      = CCONST('g', 'd', 'e', 'v'),
381 //    kEventParamGDevice            = kEventParamDisplayDevice,
382     kEventParamIndex              = CCONST('i', 'n', 'd', 'x'),
383     kEventParamUserData           = CCONST('u', 's', 'r', 'd'),
384     kEventParamShape              = CCONST('s', 'h', 'a', 'p'),
385     typeWindowRef                 = CCONST('w', 'i', 'n', 'd'),
386     typeGrafPtr                   = CCONST('g', 'r', 'a', 'f'),
387     typeGWorldPtr                 = CCONST('g', 'w', 'l', 'd'),
388     typeMenuRef                   = CCONST('m', 'e', 'n', 'u'),
389     typeControlRef                = CCONST('c', 't', 'r', 'l'),
390     typeCollection                = CCONST('c', 'l', 't', 'n'),
391     typeQDRgnHandle               = CCONST('r', 'g', 'n', 'h'),
392     typeOSStatus                  = CCONST('o', 's', 's', 't'),
393     typeCFIndex                   = CCONST('c', 'f', 'i', 'x'),
394     typeCGContextRef              = CCONST('c', 'n', 't', 'x'),
395     typeCGImageRef                = CCONST('c', 'g', 'i', 'm'),
396     typeHIPoint                   = CCONST('h', 'i', 'p', 't'),
397     typeHISize                    = CCONST('h', 'i', 's', 'z'),
398     typeHIRect                    = CCONST('h', 'i', 'r', 'c'),
399     typeHIShapeRef                = CCONST('s', 'h', 'a', 'p'),
400     typeVoidPtr                   = CCONST('v', 'o', 'i', 'd'),
401     typeGDHandle                  = CCONST('g', 'd', 'e', 'v'),
402     typeCGDisplayID               = CCONST('c', 'g', 'i', 'd'),
403     typeCGFloat                   = CCONST('c', 'g', 'f', 'l'),
404     typeHIPoint72DPIGlobal        = CCONST('h', 'i', 'p', 'g'),
405     typeHIPointScreenPixel        = CCONST('h', 'i', 'p', 's'),
406     typeHISize72DPIGlobal         = CCONST('h', 'i', 's', 'g'),
407     typeHISizeScreenPixel         = CCONST('h', 'i', 's', 's'),
408     typeHIRect72DPIGlobal         = CCONST('h', 'i', 'r', 'g'),
409     typeHIRectScreenPixel         = CCONST('h', 'i', 'r', 's'),
410     typeCGFloat72DPIGlobal        = CCONST('h', 'i', 'f', 'g'),
411     typeCGFloatScreenPixel        = CCONST('h', 'i', 'f', 's'),
412     kEventParamDisplayChangeFlags = CCONST('c', 'g', 'd', 'p'),
413     typeCGDisplayChangeFlags      = CCONST('c', 'g', 'd', 'f')
414 }
415 
416 enum : int
417 {
418     kEventParamKeyCode            = CCONST('k', 'c', 'o', 'd'),
419     kEventParamKeyMacCharCodes    = CCONST('k', 'c', 'h', 'r'),
420     kEventParamKeyModifiers       = CCONST('k', 'm', 'o', 'd'),
421     kEventParamKeyUnicodes        = CCONST('k', 'u', 'n', 'i'),
422     kEventParamKeyboardType       = CCONST('k', 'b', 'd', 't'),
423     typeEventHotKeyID             = CCONST('h', 'k', 'i', 'd')
424 }
425 
426 alias EventMouseButton = UInt16;
427 enum : EventMouseButton
428 {
429     kEventMouseButtonPrimary      = 1,
430     kEventMouseButtonSecondary    = 2,
431     kEventMouseButtonTertiary     = 3
432 }
433 
434 OSStatus InstallControlEventHandler(ControlRef target, EventHandlerUPP handler, ItemCount numTypes,
435                                     const(EventTypeSpec)* list, void* userData, EventHandlerRef* outHandlerRef) nothrow @nogc
436 {
437     return InstallEventHandler(GetControlEventTarget(target), handler, numTypes, list, userData, outHandlerRef);
438 }
439 
440 OSStatus InstallWindowEventHandler(WindowRef target, EventHandlerUPP handler, ItemCount numTypes,
441                                    const(EventTypeSpec)* list, void* userData, EventHandlerRef* outHandlerRef) nothrow @nogc
442 {
443     return InstallEventHandler(GetWindowEventTarget(target), handler, numTypes, list, userData, outHandlerRef);
444 }
445 
446 
447 
448 
449 
450 extern (C) nothrow @nogc
451 {
452     alias da_GetControlEventTarget = EventTargetRef function(ControlRef);
453     alias da_GetWindowEventTarget = EventTargetRef function(WindowRef);
454 }
455 
456 __gshared
457 {
458     da_GetControlEventTarget GetControlEventTarget;
459     da_GetWindowEventTarget GetWindowEventTarget;
460 }
461 
462 
463 // <HIToolbox/Controls.h>
464 
465 enum : int
466 {
467   kControlSupportsGhosting      = 1 << 0,
468   kControlSupportsEmbedding     = 1 << 1,
469   kControlSupportsFocus         = 1 << 2,
470   kControlWantsIdle             = 1 << 3,
471   kControlWantsActivate         = 1 << 4,
472   kControlHandlesTracking       = 1 << 5,
473   kControlSupportsDataAccess    = 1 << 6,
474   kControlHasSpecialBackground  = 1 << 7,
475   kControlGetsFocusOnClick      = 1 << 8,
476   kControlSupportsCalcBestRect  = 1 << 9,
477   kControlSupportsLiveFeedback  = 1 << 10,
478   kControlHasRadioBehavior      = 1 << 11,
479   kControlSupportsDragAndDrop   = 1 << 12,
480   kControlAutoToggles           = 1 << 14,
481   kControlSupportsGetRegion     = 1 << 17,
482   kControlSupportsFlattening    = 1 << 19,
483   kControlSupportsSetCursor     = 1 << 20,
484   kControlSupportsContextualMenus = 1 << 21,
485   kControlSupportsClickActivation = 1 << 22,
486   kControlIdlesWithTimer        = 1 << 23,
487   kControlInvertsUpDownValueMeaning = 1 << 24
488 }
489 
490 struct ControlID
491 {
492     OSType              signature;
493     SInt32              id;
494 }
495 
496 extern (C) nothrow @nogc
497 {
498  //   alias da_GetRootControl = OSErr function(WindowRef, ControlRef*);
499  //   alias da_CreateRootControl = OSErr function(WindowRef inWindow, ControlRef* outControl);
500     alias da_SizeControl = void function(ControlRef theControl, SInt16 w, SInt16 h);
501  //   alias da_EmbedControl = OSErr function(ControlRef inControl, ControlRef inContainer);
502 }
503 
504 __gshared
505 {
506 //    da_GetRootControl GetRootControl;
507 //    da_CreateRootControl CreateRootControl;
508     da_SizeControl SizeControl;
509 //    da_EmbedControl EmbedControl;
510 }
511 
512 
513 // <HIToolbox/Events.h>
514 
515 alias EventModifiers = ushort;
516 enum
517 {
518   activeFlagBit                 = 0,
519   btnStateBit                   = 7,
520   cmdKeyBit                     = 8,
521   shiftKeyBit                   = 9,
522   alphaLockBit                  = 10,
523   optionKeyBit                  = 11,
524   controlKeyBit                 = 12,
525 }
526 
527 enum : EventModifiers
528 {
529   activeFlag                    = 1 << activeFlagBit,
530   btnState                      = 1 << btnStateBit,
531   cmdKey                        = 1 << cmdKeyBit,
532   shiftKey                      = 1 << shiftKeyBit,
533   alphaLock                     = 1 << alphaLockBit,
534   optionKey                     = 1 << optionKeyBit,
535   controlKey                    = 1 << controlKeyBit
536 }
537 
538 
539 // <HIToolbox/HIContainerViews.h>
540 
541 extern (C) nothrow @nogc
542 {
543     alias da_CreateUserPaneControl = OSStatus function(WindowRef, const(Rect)*, UInt32, ControlRef*);
544 }
545 
546 __gshared
547 {
548     da_CreateUserPaneControl CreateUserPaneControl;
549 }
550 
551 
552 
553 // <HIToolbox/HIGeometry.h>
554 
555 alias HIRect = CGRect;
556 alias HIPoint = CGPoint;
557 
558 alias HICoordinateSpace = UInt32;
559 enum : HICoordinateSpace
560 {
561   kHICoordSpace72DPIGlobal      = 1,
562   kHICoordSpaceScreenPixel      = 2,
563   kHICoordSpaceWindow           = 3,
564   kHICoordSpaceView             = 4
565 }
566 
567 extern (C) nothrow @nogc
568 {
569     alias da_HIPointConvert = void function(HIPoint*, HICoordinateSpace, void*, HICoordinateSpace, void*);
570 }
571 
572 __gshared
573 {
574     da_HIPointConvert HIPointConvert;
575 }
576 
577 
578 
579 // <HIToolbox/HIObject.h>
580 
581 alias ControlRef = void*;
582 alias HIViewRef = ControlRef;
583 alias HIViewID = ControlID;
584 
585 
586 // <HIToolbox/HIView.h>
587 
588 enum : int
589 {
590   kHIViewFeatureSupportsGhosting = 1 << 0,
591   kHIViewFeatureAllowsSubviews  = 1 << 1,
592   kHIViewFeatureGetsFocusOnClick = 1 << 8,
593   kHIViewFeatureSupportsLiveFeedback = 1 << 10,
594   kHIViewFeatureSupportsRadioBehavior = 1 << 11,
595   kHIViewFeatureAutoToggles     = 1 << 14,
596   kHIViewFeatureIdlesWithTimer  = 1 << 23,
597   kHIViewFeatureInvertsUpDownValueMeaning = 1 << 24,
598   kHIViewFeatureIsOpaque        = 1 << 25,
599   kHIViewFeatureDoesNotDraw     = 1 << 27,
600   kHIViewFeatureDoesNotUseSpecialParts = 1 << 28,
601   kHIViewFeatureIgnoresClicks   = 1 << 29
602 }
603 
604 extern (C) nothrow @nogc
605 {
606     alias da_HIViewGetRoot = HIViewRef function(WindowRef inWindow);
607     alias da_HIViewFindByID = OSStatus function(HIViewRef inStartView, HIViewID inID, HIViewRef* outView);
608     alias da_HIViewAddSubview = OSStatus function(HIViewRef inParent, HIViewRef inNewChild);
609     alias da_HIViewSetNeedsDisplayInRect = OSStatus function(HIViewRef, const(HIRect)*, Boolean);
610     alias da_HIViewGetBounds = OSStatus function(HIViewRef, HIRect* outRect);
611 }
612 
613 __gshared
614 {
615     da_HIViewGetRoot HIViewGetRoot;
616     da_HIViewFindByID HIViewFindByID;
617     da_HIViewAddSubview HIViewAddSubview;
618     da_HIViewSetNeedsDisplayInRect HIViewSetNeedsDisplayInRect;
619     da_HIViewGetBounds HIViewGetBounds;
620 }
621 
622 
623 // <HIToolbox/HIWindowViews.h>
624 
625 static immutable HIViewID kHIViewWindowContentID = HIViewID(CCONST('w', 'i', 'n', 'd'), 1); // MAYDO: is it portable across OSX versions? Seems so.
626 
627 // <HIToolbox/MacWindows.h>
628 
629 alias WindowClass = int;
630 alias WindowAttributes = OptionBits;
631 
632 enum : int
633 {
634     kHIWindowBitCloseBox          = 1,
635     kHIWindowBitZoomBox           = 2,
636     kHIWindowBitCollapseBox       = 4,
637     kHIWindowBitResizable         = 5,
638     kHIWindowBitSideTitlebar      = 6,
639     kHIWindowBitToolbarButton     = 7,
640     kHIWindowBitUnifiedTitleAndToolbar = 8,
641     kHIWindowBitTextured          = 9,
642     kHIWindowBitNoTitleBar        = 10,
643     kHIWindowBitTexturedSquareCorners = 11,
644     kHIWindowBitNoTexturedContentSeparator = 12,
645     kHIWindowBitRoundBottomBarCorners = 13,
646     kHIWindowBitDoesNotCycle      = 16,
647     kHIWindowBitNoUpdates         = 17,
648     kHIWindowBitNoActivates       = 18,
649     kHIWindowBitOpaqueForEvents   = 19,
650     kHIWindowBitCompositing       = 20,
651     kHIWindowBitFrameworkScaled   = 21,
652     kHIWindowBitNoShadow          = 22,
653     kHIWindowBitCanBeVisibleWithoutLogin = 23,
654     kHIWindowBitAsyncDrag         = 24,
655     kHIWindowBitHideOnSuspend     = 25,
656     kHIWindowBitStandardHandler   = 26,
657     kHIWindowBitHideOnFullScreen  = 27,
658     kHIWindowBitInWindowMenu      = 28,
659     kHIWindowBitLiveResize        = 29,
660     kHIWindowBitIgnoreClicks      = 30,
661     kHIWindowBitNoConstrain       = 32,
662     kHIWindowBitDoesNotHide       = 33,
663     kHIWindowBitAutoViewDragTracking = 34
664 }
665 
666 enum : int
667 {
668     kWindowNoAttributes           = 0,
669     kWindowCloseBoxAttribute      = (1 << (kHIWindowBitCloseBox - 1)),
670     kWindowHorizontalZoomAttribute = (1 << (kHIWindowBitZoomBox - 1)),
671     kWindowVerticalZoomAttribute  = (1 << kHIWindowBitZoomBox),
672     kWindowFullZoomAttribute      = (kWindowVerticalZoomAttribute | kWindowHorizontalZoomAttribute),
673     kWindowCollapseBoxAttribute   = (1 << (kHIWindowBitCollapseBox - 1)),
674     kWindowResizableAttribute     = (1 << (kHIWindowBitResizable - 1)),
675     kWindowSideTitlebarAttribute  = (1 << (kHIWindowBitSideTitlebar - 1)),
676     kWindowToolbarButtonAttribute = (1 << (kHIWindowBitToolbarButton - 1)),
677     kWindowUnifiedTitleAndToolbarAttribute = (1 << (kHIWindowBitUnifiedTitleAndToolbar - 1)),
678     kWindowMetalAttribute         = (1 << (kHIWindowBitTextured - 1)),
679     kWindowNoTitleBarAttribute    = (1 << (kHIWindowBitNoTitleBar - 1)),
680     kWindowTexturedSquareCornersAttribute = (1 << (kHIWindowBitTexturedSquareCorners - 1)),
681     kWindowMetalNoContentSeparatorAttribute = (1 << (kHIWindowBitNoTexturedContentSeparator - 1)),
682     kWindowHasRoundBottomBarCornersAttribute = (1 << (kHIWindowBitRoundBottomBarCorners - 1)),
683     kWindowDoesNotCycleAttribute  = (1 << (kHIWindowBitDoesNotCycle - 1)),
684     kWindowNoUpdatesAttribute     = (1 << (kHIWindowBitNoUpdates - 1)),
685     kWindowNoActivatesAttribute   = (1 << (kHIWindowBitNoActivates - 1)),
686     kWindowOpaqueForEventsAttribute = (1 << (kHIWindowBitOpaqueForEvents - 1)),
687     kWindowCompositingAttribute   = (1 << (kHIWindowBitCompositing - 1)),
688     kWindowNoShadowAttribute      = (1 << (kHIWindowBitNoShadow - 1)),
689     kWindowCanBeVisibleWithoutLoginAttribute = (1 << (kHIWindowBitCanBeVisibleWithoutLogin - 1)),
690     kWindowHideOnSuspendAttribute = (1 << (kHIWindowBitHideOnSuspend - 1)),
691     kWindowAsyncDragAttribute     = (1 << (kHIWindowBitAsyncDrag - 1)),
692     kWindowStandardHandlerAttribute = (1 << (kHIWindowBitStandardHandler - 1)),
693     kWindowHideOnFullScreenAttribute = (1 << (kHIWindowBitHideOnFullScreen - 1)),
694     kWindowInWindowMenuAttribute  = (1 << (kHIWindowBitInWindowMenu - 1)),
695     kWindowLiveResizeAttribute    = (1 << (kHIWindowBitLiveResize - 1)),
696     kWindowIgnoreClicksAttribute  = (1 << (kHIWindowBitIgnoreClicks - 1)),
697     kWindowFrameworkScaledAttribute = (1 << (kHIWindowBitFrameworkScaled - 1)),
698     kWindowStandardDocumentAttributes = (kWindowCloseBoxAttribute | kWindowFullZoomAttribute | kWindowCollapseBoxAttribute | kWindowResizableAttribute),
699     kWindowStandardFloatingAttributes = (kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute)
700 }
701 
702 
703 extern (C) nothrow @nogc
704 {
705     alias da_GetWindowAttributes = OSStatus function(WindowRef window, WindowAttributes* outAttributes);
706 }
707 
708 __gshared
709 {
710     da_GetWindowAttributes GetWindowAttributes;
711 }
712