2
0

NSWindow.odin 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. package objc_Foundation
  2. import "core:strings"
  3. import "base:runtime"
  4. import "base:intrinsics"
  5. Rect :: struct {
  6. using origin: Point,
  7. using size: Size,
  8. }
  9. Depth :: enum UInteger {
  10. onehundredtwentyeightBitRGB = 544,
  11. sixtyfourBitRGB = 528,
  12. twentyfourBitRGB = 520,
  13. }
  14. when size_of(Float) == 8 {
  15. _RECT_ENCODING :: "{CGRect="+_POINT_ENCODING+_SIZE_ENCODING+"}"
  16. } else {
  17. _RECT_ENCODING :: "{NSRect="+_POINT_ENCODING+_SIZE_ENCODING+"}"
  18. }
  19. WindowStyleFlag :: enum UInteger {
  20. Titled = 0,
  21. Closable = 1,
  22. Miniaturizable = 2,
  23. Resizable = 3,
  24. TexturedBackground = 8,
  25. UnifiedTitleAndToolbar = 12,
  26. FullScreen = 14,
  27. FullSizeContentView = 15,
  28. UtilityWindow = 4,
  29. DocModalWindow = 6,
  30. NonactivatingPanel = 7,
  31. HUDWindow = 13,
  32. }
  33. WindowStyleMask :: distinct bit_set[WindowStyleFlag; UInteger]
  34. WindowStyleMaskBorderless :: WindowStyleMask{}
  35. WindowStyleMaskTitled :: WindowStyleMask{.Titled}
  36. WindowStyleMaskClosable :: WindowStyleMask{.Closable}
  37. WindowStyleMaskMiniaturizable :: WindowStyleMask{.Miniaturizable}
  38. WindowStyleMaskResizable :: WindowStyleMask{.Resizable}
  39. WindowStyleMaskTexturedBackground :: WindowStyleMask{.TexturedBackground}
  40. WindowStyleMaskUnifiedTitleAndToolbar :: WindowStyleMask{.UnifiedTitleAndToolbar}
  41. WindowStyleMaskFullScreen :: WindowStyleMask{.FullScreen}
  42. WindowStyleMaskFullSizeContentView :: WindowStyleMask{.FullSizeContentView}
  43. WindowStyleMaskUtilityWindow :: WindowStyleMask{.UtilityWindow}
  44. WindowStyleMaskDocModalWindow :: WindowStyleMask{.DocModalWindow}
  45. WindowStyleMaskNonactivatingPanel :: WindowStyleMask{.NonactivatingPanel}
  46. WindowStyleMaskHUDWindow :: WindowStyleMask{.HUDWindow}
  47. BackingStoreType :: enum UInteger {
  48. Retained = 0,
  49. Nonretained = 1,
  50. Buffered = 2,
  51. }
  52. WindowDelegateTemplate :: struct {
  53. // Managing Sheets
  54. windowWillPositionSheetUsingRect: proc(window: ^Window, sheet: ^Window, rect: Rect) -> Rect,
  55. windowWillBeginSheet: proc(notification: ^Notification),
  56. windowDidEndSheet: proc(notification: ^Notification),
  57. // Sizing Windows
  58. windowWillResizeToSize: proc(sender: ^Window, frameSize: Size) -> Size,
  59. windowDidResize: proc(notification: ^Notification),
  60. windowWillStartLiveResize: proc(noitifcation: ^Notification),
  61. windowDidEndLiveResize: proc(notification: ^Notification),
  62. // Minimizing Windows
  63. windowWillMiniaturize: proc(notification: ^Notification),
  64. windowDidMiniaturize: proc(notification: ^Notification),
  65. windowDidDeminiaturize: proc(notification: ^Notification),
  66. // Zooming window
  67. windowWillUseStandardFrameDefaultFrame: proc(window: ^Window, newFrame: Rect) -> Rect,
  68. windowShouldZoomToFrame: proc(window: ^Window, newFrame: Rect) -> BOOL,
  69. // Managing Full-Screen Presentation
  70. windowWillUseFullScreenContentSize: proc(window: ^Window, proposedSize: Size) -> Size,
  71. windowWillUseFullScreenPresentationOptions: proc(window: ^Window, proposedOptions: ApplicationPresentationOptions) -> ApplicationPresentationOptions,
  72. windowWillEnterFullScreen: proc(notification: ^Notification),
  73. windowDidEnterFullScreen: proc(notification: ^Notification),
  74. windowWillExitFullScreen: proc(notification: ^Notification),
  75. windowDidExitFullScreen: proc(notification: ^Notification),
  76. // Custom Full-Screen Presentation Animations
  77. customWindowsToEnterFullScreenForWindow: proc(window: ^Window) -> ^Array,
  78. customWindowsToEnterFullScreenForWindowOnScreen: proc(window: ^Window, screen: ^Screen) -> ^Array,
  79. windowStartCustomAnimationToEnterFullScreenWithDuration: proc(window: ^Window, duration: TimeInterval),
  80. windowStartCustomAnimationToEnterFullScreenOnScreenWithDuration: proc(window: ^Window, screen: ^Screen, duration: TimeInterval),
  81. windowDidFailToEnterFullScreen: proc(window: ^Window),
  82. customWindowsToExitFullScreenForWindow: proc(window: ^Window) -> ^Array,
  83. windowStartCustomAnimationToExitFullScreenWithDuration: proc(window: ^Window, duration: TimeInterval),
  84. windowDidFailToExitFullScreen: proc(window: ^Window),
  85. // Moving Windows
  86. windowWillMove: proc(notification: ^Notification),
  87. windowDidMove: proc(notification: ^Notification),
  88. windowDidChangeScreen: proc(notification: ^Notification),
  89. windowDidChangeScreenProfile: proc(notification: ^Notification),
  90. windowDidChangeBackingProperties: proc(notification: ^Notification),
  91. // Closing Windows
  92. windowShouldClose: proc(sender: ^Window) -> BOOL,
  93. windowWillClose: proc(notification: ^Notification),
  94. // Managing Key Status
  95. windowDidBecomeKey: proc(notification: ^Notification),
  96. windowDidResignKey: proc(notification: ^Notification),
  97. // Managing Main Status
  98. windowDidBecomeMain: proc(notification: ^Notification),
  99. windowDidResignMain: proc(notification: ^Notification),
  100. // Managing Field Editors
  101. windowWillReturnFieldEditorToObject: proc(sender: ^Window, client: id) -> id,
  102. // Updating Windows
  103. windowDidUpdate: proc (notification: ^Notification),
  104. // Exposing Windows
  105. windowDidExpose: proc (notification: ^Notification),
  106. // Managing Occlusion State
  107. windowDidChangeOcclusionState: proc(notification: ^Notification),
  108. // Dragging Windows
  109. windowShouldDragDocumentWithEventFromWithPasteboard: proc(window: ^Window, event: ^Event, dragImageLocation: Point, pasteboard: ^Pasteboard) -> BOOL,
  110. // Getting the Undo Manager
  111. windowWillReturnUndoManager: proc(window: ^Window) -> ^UndoManager,
  112. // Managing Titles
  113. windowShouldPopUpDocumentPathMenu: proc(window: ^Window, menu: ^Menu) -> BOOL,
  114. // Managing Restorable State
  115. windowWillEncodeRestorableState: proc(window: ^Window, state: ^Coder),
  116. windowDidEncodeRestorableState: proc(window: ^Window, state: ^Coder),
  117. // Managing Presentation in Version Browsers
  118. windowWillResizeForVersionBrowserWithMaxPreferredSizeMaxAllowedSize: proc(window: ^Window, maxPreferredFrameSize: Size, maxAllowedFrameSize: Size) -> Size,
  119. windowWillEnterVersionBrowser: proc(notification: ^Notification),
  120. windowDidEnterVersionBrowser: proc(notification: ^Notification),
  121. windowWillExitVersionBrowser: proc(notification: ^Notification),
  122. windowDidExitVersionBrowser: proc(notification: ^Notification),
  123. }
  124. WindowDelegate :: struct { using _: Object } // This is not the same as NSWindowDelegate
  125. _WindowDelegateInternal :: struct {
  126. using _: WindowDelegateTemplate,
  127. _context: runtime.Context,
  128. }
  129. window_delegate_register_and_alloc :: proc(template: WindowDelegateTemplate, class_name: string, delegate_context: Maybe(runtime.Context)) -> ^WindowDelegate {
  130. class := objc_allocateClassPair(intrinsics.objc_find_class("NSObject"), strings.clone_to_cstring(class_name, context.temp_allocator), 0); if class == nil {
  131. // Class already registered
  132. return nil
  133. }
  134. if template.windowWillPositionSheetUsingRect != nil {
  135. windowWillPositionSheetUsingRect :: proc "c" (self: id, window: ^Window, sheet: ^Window, rect: Rect) -> Rect {
  136. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  137. context = del._context
  138. return del.windowWillPositionSheetUsingRect(window, sheet, rect)
  139. }
  140. class_addMethod(class, intrinsics.objc_find_selector("window:willPositionSheet:usingRect:"), auto_cast windowWillPositionSheetUsingRect, _RECT_ENCODING+"@:@@"+_RECT_ENCODING)
  141. }
  142. if template.windowWillBeginSheet != nil {
  143. windowWillBeginSheet :: proc "c" (self: id, notification: ^Notification) {
  144. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  145. context = del._context
  146. del.windowWillBeginSheet(notification)
  147. }
  148. class_addMethod(class, intrinsics.objc_find_selector("windowWillBeginSheet:"), auto_cast windowWillBeginSheet, "v@:@")
  149. }
  150. if template.windowDidEndSheet != nil {
  151. windowDidEndSheet :: proc "c" (self: id, notification: ^Notification) {
  152. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  153. context = del._context
  154. del.windowDidEndSheet(notification)
  155. }
  156. class_addMethod(class, intrinsics.objc_find_selector("windowDidEndSheet:"), auto_cast windowDidEndSheet, "v@:@")
  157. }
  158. if template.windowWillResizeToSize != nil {
  159. windowWillResizeToSize :: proc "c" (self: id, sender: ^Window, frameSize: Size) -> Size {
  160. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  161. context = del._context
  162. return del.windowWillResizeToSize(sender, frameSize)
  163. }
  164. class_addMethod(class, intrinsics.objc_find_selector("windowWillResize:toSize:"), auto_cast windowWillResizeToSize, _SIZE_ENCODING+"@:@"+_SIZE_ENCODING)
  165. }
  166. if template.windowDidResize != nil {
  167. windowDidResize :: proc "c" (self: id, notification: ^Notification) {
  168. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  169. context = del._context
  170. del.windowDidResize(notification)
  171. }
  172. class_addMethod(class, intrinsics.objc_find_selector("windowDidResize:"), auto_cast windowDidResize, "v@:@")
  173. }
  174. if template.windowWillStartLiveResize != nil {
  175. windowWillStartLiveResize :: proc "c" (self: id, notification: ^Notification) {
  176. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  177. context = del._context
  178. del.windowWillStartLiveResize(notification)
  179. }
  180. class_addMethod(class, intrinsics.objc_find_selector("windowWillStartLiveResize:"), auto_cast windowWillStartLiveResize, "v@:@")
  181. }
  182. if template.windowDidEndLiveResize != nil {
  183. windowDidEndLiveResize :: proc "c" (self: id, notification: ^Notification) {
  184. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  185. context = del._context
  186. del.windowDidEndLiveResize(notification)
  187. }
  188. class_addMethod(class, intrinsics.objc_find_selector("windowDidEndLiveResize:"), auto_cast windowDidEndLiveResize, "v@:@")
  189. }
  190. if template.windowWillMiniaturize != nil {
  191. windowWillMiniaturize :: proc "c" (self: id, notification: ^Notification) {
  192. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  193. context = del._context
  194. del.windowWillMiniaturize(notification)
  195. }
  196. class_addMethod(class, intrinsics.objc_find_selector("windowWillMiniaturize:"), auto_cast windowWillMiniaturize, "v@:@")
  197. }
  198. if template.windowDidMiniaturize != nil {
  199. windowDidMiniaturize :: proc "c" (self: id, notification: ^Notification) {
  200. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  201. context = del._context
  202. del.windowDidMiniaturize(notification)
  203. }
  204. class_addMethod(class, intrinsics.objc_find_selector("windowDidMiniaturize:"), auto_cast windowDidMiniaturize, "v@:@")
  205. }
  206. if template.windowDidDeminiaturize != nil {
  207. windowDidDeminiaturize :: proc "c" (self: id, notification: ^Notification) {
  208. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  209. context = del._context
  210. del.windowDidDeminiaturize(notification)
  211. }
  212. class_addMethod(class, intrinsics.objc_find_selector("windowDidDeminiaturize:"), auto_cast windowDidDeminiaturize, "v@:@")
  213. }
  214. if template.windowWillUseStandardFrameDefaultFrame != nil {
  215. windowWillUseStandardFrameDefaultFrame :: proc(self: id, window: ^Window, newFrame: Rect) -> Rect {
  216. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  217. context = del._context
  218. return del.windowWillUseStandardFrameDefaultFrame(window, newFrame)
  219. }
  220. class_addMethod(class, intrinsics.objc_find_selector("windowWillUseStandardFrame:defaultFrame:"), auto_cast windowWillUseStandardFrameDefaultFrame, _RECT_ENCODING+"@:@"+_RECT_ENCODING)
  221. }
  222. if template.windowShouldZoomToFrame != nil {
  223. windowShouldZoomToFrame :: proc "c" (self: id, window: ^Window, newFrame: Rect) -> BOOL {
  224. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  225. context = del._context
  226. return del.windowShouldZoomToFrame(window, newFrame)
  227. }
  228. class_addMethod(class, intrinsics.objc_find_selector("windowShouldZoom:toFrame:"), auto_cast windowShouldZoomToFrame, "B@:@"+_RECT_ENCODING)
  229. }
  230. if template.windowWillUseFullScreenContentSize != nil {
  231. windowWillUseFullScreenContentSize :: proc "c" (self: id, window: ^Window, proposedSize: Size) -> Size {
  232. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  233. context = del._context
  234. return del.windowWillUseFullScreenContentSize(window, proposedSize)
  235. }
  236. class_addMethod(class, intrinsics.objc_find_selector("window:willUseFullScreenContentSize:"), auto_cast windowWillUseFullScreenContentSize, _SIZE_ENCODING+"@:@"+_SIZE_ENCODING)
  237. }
  238. if template.windowWillUseFullScreenPresentationOptions != nil {
  239. windowWillUseFullScreenPresentationOptions :: proc(self: id, window: ^Window, proposedOptions: ApplicationPresentationOptions) -> ApplicationPresentationOptions {
  240. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  241. context = del._context
  242. return del.windowWillUseFullScreenPresentationOptions(window, proposedOptions)
  243. }
  244. class_addMethod(class, intrinsics.objc_find_selector("window:willUseFullScreenPresentationOptions:"), auto_cast windowWillUseFullScreenPresentationOptions, _UINTEGER_ENCODING+"@:@"+_UINTEGER_ENCODING)
  245. }
  246. if template.windowWillEnterFullScreen != nil {
  247. windowWillEnterFullScreen :: proc "c" (self: id, notification: ^Notification) {
  248. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  249. context = del._context
  250. del.windowWillEnterFullScreen(notification)
  251. }
  252. class_addMethod(class, intrinsics.objc_find_selector("windowWillEnterFullScreen:"), auto_cast windowWillEnterFullScreen, "v@:@")
  253. }
  254. if template.windowDidEnterFullScreen != nil {
  255. windowDidEnterFullScreen :: proc "c" (self: id, notification: ^Notification) {
  256. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  257. context = del._context
  258. del.windowDidEnterFullScreen(notification)
  259. }
  260. class_addMethod(class, intrinsics.objc_find_selector("windowDidEnterFullScreen:"), auto_cast windowDidEnterFullScreen, "v@:@")
  261. }
  262. if template.windowWillExitFullScreen != nil {
  263. windowWillExitFullScreen :: proc "c" (self: id, notification: ^Notification) {
  264. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  265. context = del._context
  266. del.windowWillExitFullScreen(notification)
  267. }
  268. class_addMethod(class, intrinsics.objc_find_selector("windowWillExitFullScreen:"), auto_cast windowWillExitFullScreen, "v@:@")
  269. }
  270. if template.windowDidExitFullScreen != nil {
  271. windowDidExitFullScreen :: proc "c" (self: id, notification: ^Notification) {
  272. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  273. context = del._context
  274. del.windowDidExitFullScreen(notification)
  275. }
  276. class_addMethod(class, intrinsics.objc_find_selector("windowDidExitFullScreen:"), auto_cast windowDidExitFullScreen, "v@:@")
  277. }
  278. if template.customWindowsToEnterFullScreenForWindow != nil {
  279. customWindowsToEnterFullScreenForWindow :: proc "c" (self: id, window: ^Window) -> ^Array {
  280. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  281. context = del._context
  282. return del.customWindowsToEnterFullScreenForWindow(window)
  283. }
  284. class_addMethod(class, intrinsics.objc_find_selector("customWindowsToEnterFullScreenForWindow:"), auto_cast customWindowsToEnterFullScreenForWindow, "@@:@")
  285. }
  286. if template.customWindowsToEnterFullScreenForWindowOnScreen != nil {
  287. customWindowsToEnterFullScreenForWindowOnScreen :: proc(self: id, window: ^Window, screen: ^Screen) -> ^Array {
  288. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  289. context = del._context
  290. return del.customWindowsToEnterFullScreenForWindowOnScreen(window, screen)
  291. }
  292. class_addMethod(class, intrinsics.objc_find_selector("customWindowsToEnterFullScreenForWindow:onScreen:"), auto_cast customWindowsToEnterFullScreenForWindowOnScreen, "@@:@@")
  293. }
  294. if template.windowStartCustomAnimationToEnterFullScreenWithDuration != nil {
  295. windowStartCustomAnimationToEnterFullScreenWithDuration :: proc "c" (self: id, window: ^Window, duration: TimeInterval) {
  296. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  297. context = del._context
  298. del.windowStartCustomAnimationToEnterFullScreenWithDuration(window, duration)
  299. }
  300. class_addMethod(class, intrinsics.objc_find_selector("window:startCustomAnimationToEnterFullScreenWithDuration:"), auto_cast windowStartCustomAnimationToEnterFullScreenWithDuration, "v@:@@")
  301. }
  302. if template.windowStartCustomAnimationToEnterFullScreenOnScreenWithDuration != nil {
  303. windowStartCustomAnimationToEnterFullScreenOnScreenWithDuration :: proc(self: id, window: ^Window, screen: ^Screen, duration: TimeInterval) {
  304. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  305. context = del._context
  306. del.windowStartCustomAnimationToEnterFullScreenOnScreenWithDuration(window, screen, duration)
  307. }
  308. class_addMethod(class, intrinsics.objc_find_selector("window:startCustomAnimationToEnterFullScreenOnScreen:withDuration:"), auto_cast windowStartCustomAnimationToEnterFullScreenOnScreenWithDuration, "v@:@@d")
  309. }
  310. if template.windowDidFailToEnterFullScreen != nil {
  311. windowDidFailToEnterFullScreen :: proc "c" (self: id, window: ^Window) {
  312. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  313. context = del._context
  314. del.windowDidFailToEnterFullScreen(window)
  315. }
  316. class_addMethod(class, intrinsics.objc_find_selector("windowDidFailToEnterFullScreen:"), auto_cast windowDidFailToEnterFullScreen, "v@:@")
  317. }
  318. if template.customWindowsToExitFullScreenForWindow != nil {
  319. customWindowsToExitFullScreenForWindow :: proc "c" (self: id, window: ^Window) -> ^Array {
  320. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  321. context = del._context
  322. return del.customWindowsToExitFullScreenForWindow(window)
  323. }
  324. class_addMethod(class, intrinsics.objc_find_selector("customWindowsToExitFullScreenForWindow:"), auto_cast customWindowsToExitFullScreenForWindow, "@@:@")
  325. }
  326. if template.windowStartCustomAnimationToExitFullScreenWithDuration != nil {
  327. windowStartCustomAnimationToExitFullScreenWithDuration :: proc "c" (self: id, window: ^Window, duration: TimeInterval) {
  328. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  329. context = del._context
  330. del.windowStartCustomAnimationToExitFullScreenWithDuration(window, duration)
  331. }
  332. class_addMethod(class, intrinsics.objc_find_selector("window:startCustomAnimationToExitFullScreenWithDuration:"), auto_cast windowStartCustomAnimationToExitFullScreenWithDuration, "v@:@d")
  333. }
  334. if template.windowDidFailToExitFullScreen != nil {
  335. windowDidFailToExitFullScreen :: proc "c" (self: id, window: ^Window) {
  336. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  337. context = del._context
  338. del.windowDidFailToExitFullScreen(window)
  339. }
  340. class_addMethod(class, intrinsics.objc_find_selector("windowDidFailToExitFullScreen:"), auto_cast windowDidFailToExitFullScreen, "v@:@")
  341. }
  342. if template.windowWillMove != nil {
  343. windowWillMove :: proc "c" (self: id, notification: ^Notification) {
  344. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  345. context = del._context
  346. del.windowWillMove(notification)
  347. }
  348. class_addMethod(class, intrinsics.objc_find_selector("windowWillMove:"), auto_cast windowWillMove, "v@:@")
  349. }
  350. if template.windowDidMove != nil {
  351. windowDidMove :: proc "c" (self: id, notification: ^Notification) {
  352. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  353. context = del._context
  354. del.windowDidMove(notification)
  355. }
  356. class_addMethod(class, intrinsics.objc_find_selector("windowDidMove:"), auto_cast windowDidMove, "v@:@")
  357. }
  358. if template.windowDidChangeScreen != nil {
  359. windowDidChangeScreen :: proc "c" (self: id, notification: ^Notification) {
  360. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  361. context = del._context
  362. del.windowDidChangeScreen(notification)
  363. }
  364. class_addMethod(class, intrinsics.objc_find_selector("windowDidChangeScreen:"), auto_cast windowDidChangeScreen, "v@:@")
  365. }
  366. if template.windowDidChangeScreenProfile != nil {
  367. windowDidChangeScreenProfile :: proc "c" (self: id, notification: ^Notification) {
  368. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  369. context = del._context
  370. del.windowDidChangeScreenProfile(notification)
  371. }
  372. class_addMethod(class, intrinsics.objc_find_selector("windowDidChangeScreenProfile:"), auto_cast windowDidChangeScreenProfile, "v@:@")
  373. }
  374. if template.windowDidChangeBackingProperties != nil {
  375. windowDidChangeBackingProperties :: proc "c" (self: id, notification: ^Notification) {
  376. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  377. context = del._context
  378. del.windowDidChangeBackingProperties(notification)
  379. }
  380. class_addMethod(class, intrinsics.objc_find_selector("windowDidChangeBackingProperties:"), auto_cast windowDidChangeBackingProperties, "v@:@")
  381. }
  382. if template.windowShouldClose != nil {
  383. windowShouldClose :: proc "c" (self:id, sender: ^Window) -> BOOL {
  384. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  385. context = del._context
  386. return del.windowShouldClose(sender)
  387. }
  388. class_addMethod(class, intrinsics.objc_find_selector("windowShouldClose:"), auto_cast windowShouldClose, "B@:@")
  389. }
  390. if template.windowWillClose != nil {
  391. windowWillClose :: proc "c" (self:id, notification: ^Notification) {
  392. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  393. context = del._context
  394. del.windowWillClose(notification)
  395. }
  396. class_addMethod(class, intrinsics.objc_find_selector("windowWillClose:"), auto_cast windowWillClose, "v@:@")
  397. }
  398. if template.windowDidBecomeKey != nil {
  399. windowDidBecomeKey :: proc "c" (self: id, notification: ^Notification) {
  400. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  401. context = del._context
  402. del.windowDidBecomeKey(notification)
  403. }
  404. class_addMethod(class, intrinsics.objc_find_selector("windowDidBecomeKey:"), auto_cast windowDidBecomeKey, "v@:@")
  405. }
  406. if template.windowDidResignKey != nil {
  407. windowDidResignKey :: proc "c" (self: id, notification: ^Notification) {
  408. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  409. context = del._context
  410. del.windowDidResignKey(notification)
  411. }
  412. class_addMethod(class, intrinsics.objc_find_selector("windowDidResignKey:"), auto_cast windowDidResignKey, "v@:@")
  413. }
  414. if template.windowDidBecomeMain != nil {
  415. windowDidBecomeMain :: proc "c" (self: id, notification: ^Notification) {
  416. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  417. context = del._context
  418. del.windowDidBecomeMain(notification)
  419. }
  420. class_addMethod(class, intrinsics.objc_find_selector("windowDidBecomeMain:"), auto_cast windowDidBecomeMain, "v@:@")
  421. }
  422. if template.windowDidResignMain != nil {
  423. windowDidResignMain :: proc "c" (self: id, notification: ^Notification) {
  424. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  425. context = del._context
  426. del.windowDidResignMain(notification)
  427. }
  428. class_addMethod(class, intrinsics.objc_find_selector("windowDidResignMain:"), auto_cast windowDidResignMain, "v@:@")
  429. }
  430. if template.windowWillReturnFieldEditorToObject != nil {
  431. windowWillReturnFieldEditorToObject :: proc "c" (self:id, sender: ^Window, client: id) -> id {
  432. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  433. context = del._context
  434. return del.windowWillReturnFieldEditorToObject(sender, client)
  435. }
  436. class_addMethod(class, intrinsics.objc_find_selector("windowWillReturnFieldEditor:toObject:"), auto_cast windowWillReturnFieldEditorToObject, "@@:@@")
  437. }
  438. if template.windowDidUpdate != nil {
  439. windowDidUpdate :: proc "c" (self: id, notification: ^Notification) {
  440. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  441. context = del._context
  442. del.windowDidUpdate(notification)
  443. }
  444. class_addMethod(class, intrinsics.objc_find_selector("windowDidUpdate:"), auto_cast windowDidUpdate, "v@:@")
  445. }
  446. if template.windowDidExpose != nil {
  447. windowDidExpose :: proc "c" (self: id, notification: ^Notification) {
  448. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  449. context = del._context
  450. del.windowDidExpose(notification)
  451. }
  452. class_addMethod(class, intrinsics.objc_find_selector("windowDidExpose:"), auto_cast windowDidExpose, "v@:@")
  453. }
  454. if template.windowDidChangeOcclusionState != nil {
  455. windowDidChangeOcclusionState :: proc "c" (self: id, notification: ^Notification) {
  456. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  457. context = del._context
  458. del.windowDidChangeOcclusionState(notification)
  459. }
  460. class_addMethod(class, intrinsics.objc_find_selector("windowDidChangeOcclusionState:"), auto_cast windowDidChangeOcclusionState, "v@:@")
  461. }
  462. if template.windowShouldDragDocumentWithEventFromWithPasteboard != nil {
  463. windowShouldDragDocumentWithEventFromWithPasteboard :: proc "c" (self: id, window: ^Window, event: ^Event, dragImageLocation: Point, pasteboard: ^Pasteboard) -> BOOL {
  464. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  465. context = del._context
  466. return del.windowShouldDragDocumentWithEventFromWithPasteboard(window, event, dragImageLocation, pasteboard)
  467. }
  468. class_addMethod(class, intrinsics.objc_find_selector("window:shouldDragDocumentWithEvent:from:withPasteboard:"), auto_cast windowShouldDragDocumentWithEventFromWithPasteboard, "B@:@@"+_POINT_ENCODING+"@")
  469. }
  470. if template.windowWillReturnUndoManager != nil {
  471. windowWillReturnUndoManager :: proc "c" (self: id, window: ^Window) -> ^UndoManager {
  472. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  473. context = del._context
  474. return del.windowWillReturnUndoManager(window)
  475. }
  476. class_addMethod(class, intrinsics.objc_find_selector("windowWillReturnUndoManager:"), auto_cast windowWillReturnUndoManager, "@@:@")
  477. }
  478. if template.windowShouldPopUpDocumentPathMenu != nil {
  479. windowShouldPopUpDocumentPathMenu :: proc "c" (self: id, window: ^Window, menu: ^Menu) -> BOOL {
  480. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  481. context = del._context
  482. return del.windowShouldPopUpDocumentPathMenu(window, menu)
  483. }
  484. class_addMethod(class, intrinsics.objc_find_selector("window:shouldPopUpDocumentPathMenu:"), auto_cast windowShouldPopUpDocumentPathMenu, "B@:@@")
  485. }
  486. if template.windowWillEncodeRestorableState != nil {
  487. windowWillEncodeRestorableState :: proc "c" (self: id, window: ^Window, state: ^Coder) {
  488. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  489. context = del._context
  490. del.windowWillEncodeRestorableState(window, state)
  491. }
  492. class_addMethod(class, intrinsics.objc_find_selector("window:willEncodeRestorableState:"), auto_cast windowWillEncodeRestorableState, "v@:@@")
  493. }
  494. if template.windowDidEncodeRestorableState != nil {
  495. windowDidEncodeRestorableState :: proc "c" (self: id, window: ^Window, state: ^Coder) {
  496. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  497. context = del._context
  498. del.windowDidEncodeRestorableState(window, state)
  499. }
  500. class_addMethod(class, intrinsics.objc_find_selector("window:didDecodeRestorableState:"), auto_cast windowDidEncodeRestorableState, "v@:@@")
  501. }
  502. if template.windowWillResizeForVersionBrowserWithMaxPreferredSizeMaxAllowedSize != nil {
  503. windowWillResizeForVersionBrowserWithMaxPreferredSizeMaxAllowedSize :: proc "c" (self: id, window: ^Window, maxPreferredFrameSize: Size, maxAllowedFrameSize: Size) -> Size {
  504. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  505. context = del._context
  506. return del.windowWillResizeForVersionBrowserWithMaxPreferredSizeMaxAllowedSize(window, maxPreferredFrameSize, maxPreferredFrameSize)
  507. }
  508. class_addMethod(class, intrinsics.objc_find_selector("window:willResizeForVersionBrowserWithMaxPreferredSize:maxAllowedSize:"), auto_cast windowWillResizeForVersionBrowserWithMaxPreferredSizeMaxAllowedSize, _SIZE_ENCODING+"@:@"+_SIZE_ENCODING+_SIZE_ENCODING)
  509. }
  510. if template.windowWillEnterVersionBrowser != nil {
  511. windowWillEnterVersionBrowser :: proc "c" (self: id, notification: ^Notification) {
  512. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  513. context = del._context
  514. del.windowWillEnterVersionBrowser(notification)
  515. }
  516. class_addMethod(class, intrinsics.objc_find_selector("windowWillEnterVersionBrowser:"), auto_cast windowWillEnterVersionBrowser, "v@:@")
  517. }
  518. if template.windowDidEnterVersionBrowser != nil {
  519. windowDidEnterVersionBrowser :: proc "c" (self: id, notification: ^Notification) {
  520. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  521. context = del._context
  522. del.windowDidEnterVersionBrowser(notification)
  523. }
  524. class_addMethod(class, intrinsics.objc_find_selector("windowDidEnterVersionBrowser:"), auto_cast windowDidEnterVersionBrowser, "v@:@")
  525. }
  526. if template.windowWillExitVersionBrowser != nil {
  527. windowWillExitVersionBrowser :: proc "c" (self: id, notification: ^Notification) {
  528. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  529. context = del._context
  530. del.windowWillExitVersionBrowser(notification)
  531. }
  532. class_addMethod(class, intrinsics.objc_find_selector("windowWillExitVersionBrowser:"), auto_cast windowWillExitVersionBrowser, "v@:@")
  533. }
  534. if template.windowDidExitVersionBrowser != nil {
  535. windowDidExitVersionBrowser :: proc "c" (self: id, notification: ^Notification) {
  536. del := cast(^_WindowDelegateInternal)object_getIndexedIvars(self)
  537. context = del._context
  538. del.windowDidExitVersionBrowser(notification)
  539. }
  540. class_addMethod(class, intrinsics.objc_find_selector("windowDidExitVersionBrowser:"), auto_cast windowDidExitVersionBrowser, "v@:@")
  541. }
  542. objc_registerClassPair(class)
  543. del := class_createInstance(class, size_of(_WindowDelegateInternal))
  544. del_internal := cast(^_WindowDelegateInternal)object_getIndexedIvars(del)
  545. del_internal^ = {
  546. template,
  547. delegate_context.(runtime.Context) or_else runtime.default_context(),
  548. }
  549. return cast(^WindowDelegate)del
  550. }
  551. @(objc_class="CALayer")
  552. Layer :: struct { using _: Object }
  553. @(objc_type=Layer, objc_name="contentsScale")
  554. Layer_contentsScale :: proc "c" (self: ^Layer) -> Float {
  555. return msgSend(Float, self, "contentsScale")
  556. }
  557. @(objc_type=Layer, objc_name="setContentsScale")
  558. Layer_setContentsScale :: proc "c" (self: ^Layer, scale: Float) {
  559. msgSend(nil, self, "setContentsScale:", scale)
  560. }
  561. @(objc_type=Layer, objc_name="frame")
  562. Layer_frame :: proc "c" (self: ^Layer) -> Rect {
  563. return msgSend(Rect, self, "frame")
  564. }
  565. @(objc_type=Layer, objc_name="addSublayer")
  566. Layer_addSublayer :: proc "c" (self: ^Layer, layer: ^Layer) {
  567. msgSend(nil, self, "addSublayer:", layer)
  568. }
  569. @(objc_class="NSResponder")
  570. Responder :: struct {using _: Object}
  571. @(objc_class="NSView")
  572. View :: struct {using _: Responder}
  573. @(objc_type=View, objc_name="initWithFrame")
  574. View_initWithFrame :: proc "c" (self: ^View, frame: Rect) -> ^View {
  575. return msgSend(^View, self, "initWithFrame:", frame)
  576. }
  577. @(objc_type=View, objc_name="bounds")
  578. View_bounds :: proc "c" (self: ^View) -> Rect {
  579. return msgSend(Rect, self, "bounds")
  580. }
  581. @(objc_type=View, objc_name="layer")
  582. View_layer :: proc "c" (self: ^View) -> ^Layer {
  583. return msgSend(^Layer, self, "layer")
  584. }
  585. @(objc_type=View, objc_name="setLayer")
  586. View_setLayer :: proc "c" (self: ^View, layer: ^Layer) {
  587. msgSend(nil, self, "setLayer:", layer)
  588. }
  589. @(objc_type=View, objc_name="wantsLayer")
  590. View_wantsLayer :: proc "c" (self: ^View) -> BOOL {
  591. return msgSend(BOOL, self, "wantsLayer")
  592. }
  593. @(objc_type=View, objc_name="setWantsLayer")
  594. View_setWantsLayer :: proc "c" (self: ^View, wantsLayer: BOOL) {
  595. msgSend(nil, self, "setWantsLayer:", wantsLayer)
  596. }
  597. @(objc_type=View, objc_name="convertPointFromView")
  598. View_convertPointFromView :: proc "c" (self: ^View, point: Point, view: ^View) -> Point {
  599. return msgSend(Point, self, "convertPoint:fromView:", point, view)
  600. }
  601. @(objc_class="NSWindow")
  602. Window :: struct {using _: Responder}
  603. @(objc_type=Window, objc_name="alloc", objc_is_class_method=true)
  604. Window_alloc :: proc "c" () -> ^Window {
  605. return msgSend(^Window, Window, "alloc")
  606. }
  607. @(objc_type=Window, objc_name="initWithContentRect")
  608. Window_initWithContentRect :: proc (self: ^Window, contentRect: Rect, styleMask: WindowStyleMask, backing: BackingStoreType, doDefer: BOOL) -> ^Window {
  609. self := self
  610. // HACK: due to a compiler bug, the generated calling code does not
  611. // currently work for this message. Has to do with passing a struct along
  612. // with other parameters, so we don't send the rect here.
  613. // Omiting the rect argument here actually works, because of how the C
  614. // calling conventions are defined.
  615. self = msgSend(^Window, self, "initWithContentRect:styleMask:backing:defer:", styleMask, backing, doDefer)
  616. // apply the contentRect now, since we did not pass it to the init call
  617. msgSend(nil, self, "setContentSize:", contentRect.size)
  618. msgSend(nil, self, "setFrameOrigin:", contentRect.origin)
  619. return self
  620. }
  621. @(objc_type=Window, objc_name="contentView")
  622. Window_contentView :: proc "c" (self: ^Window) -> ^View {
  623. return msgSend(^View, self, "contentView")
  624. }
  625. @(objc_type=Window, objc_name="setContentView")
  626. Window_setContentView :: proc "c" (self: ^Window, content_view: ^View) {
  627. msgSend(nil, self, "setContentView:", content_view)
  628. }
  629. @(objc_type=Window, objc_name="contentLayoutRect")
  630. Window_contentLayoutRect :: proc "c" (self: ^Window) -> Rect {
  631. return msgSend(Rect, self, "contentLayoutRect")
  632. }
  633. @(objc_type=Window, objc_name="frame")
  634. Window_frame :: proc "c" (self: ^Window) -> Rect {
  635. return msgSend(Rect, self, "frame")
  636. }
  637. @(objc_type=Window, objc_name="setFrame")
  638. Window_setFrame :: proc "c" (self: ^Window, frame: Rect) {
  639. msgSend(nil, self, "setFrame:", frame)
  640. }
  641. @(objc_type=Window, objc_name="opaque")
  642. Window_opaque :: proc "c" (self: ^Window) -> BOOL {
  643. return msgSend(BOOL, self, "opaque")
  644. }
  645. @(objc_type=Window, objc_name="setOpaque")
  646. Window_setOpaque :: proc "c" (self: ^Window, ok: BOOL) {
  647. msgSend(nil, self, "setOpaque:", ok)
  648. }
  649. @(objc_type=Window, objc_name="backgroundColor")
  650. Window_backgroundColor :: proc "c" (self: ^Window) -> ^Color {
  651. return msgSend(^Color, self, "backgroundColor")
  652. }
  653. @(objc_type=Window, objc_name="setBackgroundColor")
  654. Window_setBackgroundColor :: proc "c" (self: ^Window, color: ^Color) {
  655. msgSend(nil, self, "setBackgroundColor:", color)
  656. }
  657. @(objc_type=Window, objc_name="makeKeyAndOrderFront")
  658. Window_makeKeyAndOrderFront :: proc "c" (self: ^Window, key: ^Object) {
  659. msgSend(nil, self, "makeKeyAndOrderFront:", key)
  660. }
  661. @(objc_type=Window, objc_name="setTitle")
  662. Window_setTitle :: proc "c" (self: ^Window, title: ^String) {
  663. msgSend(nil, self, "setTitle:", title)
  664. }
  665. @(objc_type=Window, objc_name="setTitlebarAppearsTransparent")
  666. Window_setTitlebarAppearsTransparent :: proc "c" (self: ^Window, ok: BOOL) {
  667. msgSend(nil, self, "setTitlebarAppearsTransparent:", ok)
  668. }
  669. @(objc_type=Window, objc_name="setMovable")
  670. Window_setMovable :: proc "c" (self: ^Window, ok: BOOL) {
  671. msgSend(nil, self, "setMovable:", ok)
  672. }
  673. @(objc_type=Window, objc_name="setMovableByWindowBackground")
  674. Window_setMovableByWindowBackground :: proc "c" (self: ^Window, ok: BOOL) {
  675. msgSend(nil, self, "setMovableByWindowBackground:", ok)
  676. }
  677. @(objc_type=Window, objc_name="setStyleMask")
  678. Window_setStyleMask :: proc "c" (self: ^Window, style_mask: WindowStyleMask) {
  679. msgSend(nil, self, "setStyleMask:", style_mask)
  680. }
  681. @(objc_type=Window, objc_name="close")
  682. Window_close :: proc "c" (self: ^Window) {
  683. msgSend(nil, self, "close")
  684. }
  685. @(objc_type=Window, objc_name="setDelegate")
  686. Window_setDelegate :: proc "c" (self: ^Window, delegate: ^WindowDelegate) {
  687. msgSend(nil, self, "setDelegate:", delegate)
  688. }
  689. @(objc_type=Window, objc_name="backingScaleFactor")
  690. Window_backingScaleFactor :: proc "c" (self: ^Window) -> Float {
  691. return msgSend(Float, self, "backingScaleFactor")
  692. }