avalonia-native.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. #include "com.h"
  2. #include "key.h"
  3. #include "stddef.h"
  4. #define AVNCOM(name, id) COMINTERFACE(name, 2e2cda0a, 9ae5, 4f1b, 8e, 20, 08, 1a, 04, 27, 9f, id)
  5. struct IAvnWindowEvents;
  6. struct IAvnWindow;
  7. struct IAvnPopup;
  8. struct IAvnMacOptions;
  9. struct IAvnPlatformThreadingInterface;
  10. struct IAvnSystemDialogEvents;
  11. struct IAvnSystemDialogs;
  12. struct IAvnScreens;
  13. struct IAvnClipboard;
  14. struct IAvnCursor;
  15. struct IAvnCursorFactory;
  16. struct IAvnGlFeature;
  17. struct IAvnGlContext;
  18. struct IAvnGlDisplay;
  19. struct IAvnGlSurfaceRenderTarget;
  20. struct IAvnGlSurfaceRenderingSession;
  21. struct IAvnMenu;
  22. struct IAvnMenuItem;
  23. struct IAvnStringArray;
  24. struct IAvnDndResultCallback;
  25. struct IAvnGCHandleDeallocatorCallback;
  26. struct IAvnMenuEvents;
  27. struct IAvnNativeControlHost;
  28. struct IAvnNativeControlHostTopLevelAttachment;
  29. enum SystemDecorations {
  30. SystemDecorationsNone = 0,
  31. SystemDecorationsBorderOnly = 1,
  32. SystemDecorationsFull = 2,
  33. };
  34. struct AvnSize
  35. {
  36. double Width, Height;
  37. };
  38. struct AvnPixelSize
  39. {
  40. int Width, Height;
  41. };
  42. struct AvnRect
  43. {
  44. double X, Y, Width, Height;
  45. };
  46. struct AvnVector
  47. {
  48. double X, Y;
  49. };
  50. struct AvnPoint
  51. {
  52. double X, Y;
  53. };
  54. struct AvnScreen
  55. {
  56. AvnRect Bounds;
  57. AvnRect WorkingArea;
  58. float PixelDensity;
  59. bool Primary;
  60. };
  61. enum AvnPixelFormat
  62. {
  63. kAvnRgb565,
  64. kAvnRgba8888,
  65. kAvnBgra8888
  66. };
  67. struct AvnFramebuffer
  68. {
  69. void* Data;
  70. int Width;
  71. int Height;
  72. int Stride;
  73. AvnVector Dpi;
  74. AvnPixelFormat PixelFormat;
  75. };
  76. struct AvnColor
  77. {
  78. unsigned char Alpha;
  79. unsigned char Red;
  80. unsigned char Green;
  81. unsigned char Blue;
  82. };
  83. enum AvnRawMouseEventType
  84. {
  85. LeaveWindow,
  86. LeftButtonDown,
  87. LeftButtonUp,
  88. RightButtonDown,
  89. RightButtonUp,
  90. MiddleButtonDown,
  91. MiddleButtonUp,
  92. XButton1Down,
  93. XButton1Up,
  94. XButton2Down,
  95. XButton2Up,
  96. Move,
  97. Wheel,
  98. NonClientLeftButtonDown,
  99. TouchBegin,
  100. TouchUpdate,
  101. TouchEnd,
  102. TouchCancel
  103. };
  104. enum AvnRawKeyEventType
  105. {
  106. KeyDown,
  107. KeyUp
  108. };
  109. enum AvnInputModifiers
  110. {
  111. AvnInputModifiersNone = 0,
  112. Alt = 1,
  113. Control = 2,
  114. Shift = 4,
  115. Windows = 8,
  116. LeftMouseButton = 16,
  117. RightMouseButton = 32,
  118. MiddleMouseButton = 64,
  119. XButton1MouseButton = 128,
  120. XButton2MouseButton = 256
  121. };
  122. enum class AvnDragDropEffects
  123. {
  124. None = 0,
  125. Copy = 1,
  126. Move = 2,
  127. Link = 4,
  128. };
  129. enum class AvnDragEventType
  130. {
  131. Enter,
  132. Over,
  133. Leave,
  134. Drop
  135. };
  136. enum AvnWindowState
  137. {
  138. Normal,
  139. Minimized,
  140. Maximized,
  141. FullScreen,
  142. };
  143. enum AvnStandardCursorType
  144. {
  145. CursorArrow,
  146. CursorIbeam,
  147. CursorWait,
  148. CursorCross,
  149. CursorUpArrow,
  150. CursorSizeWestEast,
  151. CursorSizeNorthSouth,
  152. CursorSizeAll,
  153. CursorNo,
  154. CursorHand,
  155. CursorAppStarting,
  156. CursorHelp,
  157. CursorTopSide,
  158. CursorBottomSize,
  159. CursorLeftSide,
  160. CursorRightSide,
  161. CursorTopLeftCorner,
  162. CursorTopRightCorner,
  163. CursorBottomLeftCorner,
  164. CursorBottomRightCorner,
  165. CursorDragMove,
  166. CursorDragCopy,
  167. CursorDragLink,
  168. CursorNone
  169. };
  170. enum AvnWindowEdge
  171. {
  172. WindowEdgeNorthWest,
  173. WindowEdgeNorth,
  174. WindowEdgeNorthEast,
  175. WindowEdgeWest,
  176. WindowEdgeEast,
  177. WindowEdgeSouthWest,
  178. WindowEdgeSouth,
  179. WindowEdgeSouthEast
  180. };
  181. enum AvnMenuItemToggleType
  182. {
  183. None,
  184. CheckMark,
  185. Radio
  186. };
  187. enum AvnExtendClientAreaChromeHints
  188. {
  189. AvnNoChrome = 0,
  190. AvnSystemChrome = 0x01,
  191. AvnPreferSystemChrome = 0x02,
  192. AvnOSXThickTitleBar = 0x08,
  193. AvnDefaultChrome = AvnSystemChrome,
  194. };
  195. AVNCOM(IAvaloniaNativeFactory, 01) : IUnknown
  196. {
  197. public:
  198. virtual HRESULT Initialize(IAvnGCHandleDeallocatorCallback* deallocator) = 0;
  199. virtual IAvnMacOptions* GetMacOptions() = 0;
  200. virtual HRESULT CreateWindow(IAvnWindowEvents* cb, IAvnGlContext* gl, IAvnWindow** ppv) = 0;
  201. virtual HRESULT CreatePopup (IAvnWindowEvents* cb, IAvnGlContext* gl, IAvnPopup** ppv) = 0;
  202. virtual HRESULT CreatePlatformThreadingInterface(IAvnPlatformThreadingInterface** ppv) = 0;
  203. virtual HRESULT CreateSystemDialogs (IAvnSystemDialogs** ppv) = 0;
  204. virtual HRESULT CreateScreens (IAvnScreens** ppv) = 0;
  205. virtual HRESULT CreateClipboard(IAvnClipboard** ppv) = 0;
  206. virtual HRESULT CreateDndClipboard(IAvnClipboard** ppv) = 0;
  207. virtual HRESULT CreateCursorFactory(IAvnCursorFactory** ppv) = 0;
  208. virtual HRESULT ObtainGlDisplay(IAvnGlDisplay** ppv) = 0;
  209. virtual HRESULT SetAppMenu(IAvnMenu* menu) = 0;
  210. virtual HRESULT CreateMenu (IAvnMenuEvents* cb, IAvnMenu** ppv) = 0;
  211. virtual HRESULT CreateMenuItem (IAvnMenuItem** ppv) = 0;
  212. virtual HRESULT CreateMenuItemSeperator (IAvnMenuItem** ppv) = 0;
  213. };
  214. AVNCOM(IAvnString, 17) : IUnknown
  215. {
  216. virtual HRESULT Pointer(void**retOut) = 0;
  217. virtual HRESULT Length(int*ret) = 0;
  218. };
  219. AVNCOM(IAvnWindowBase, 02) : IUnknown
  220. {
  221. virtual HRESULT Show() = 0;
  222. virtual HRESULT Hide () = 0;
  223. virtual HRESULT Close() = 0;
  224. virtual HRESULT Activate () = 0;
  225. virtual HRESULT GetClientSize(AvnSize*ret) = 0;
  226. virtual HRESULT GetScaling(double*ret)=0;
  227. virtual HRESULT SetMinMaxSize(AvnSize minSize, AvnSize maxSize) = 0;
  228. virtual HRESULT Resize(double width, double height) = 0;
  229. virtual HRESULT Invalidate (AvnRect rect) = 0;
  230. virtual HRESULT BeginMoveDrag () = 0;
  231. virtual HRESULT BeginResizeDrag (AvnWindowEdge edge) = 0;
  232. virtual HRESULT GetPosition (AvnPoint*ret) = 0;
  233. virtual HRESULT SetPosition (AvnPoint point) = 0;
  234. virtual HRESULT PointToClient (AvnPoint point, AvnPoint*ret) = 0;
  235. virtual HRESULT PointToScreen (AvnPoint point, AvnPoint*ret) = 0;
  236. virtual HRESULT ThreadSafeSetSwRenderedFrame(AvnFramebuffer* fb, IUnknown* dispose) = 0;
  237. virtual HRESULT SetTopMost (bool value) = 0;
  238. virtual HRESULT SetCursor(IAvnCursor* cursor) = 0;
  239. virtual HRESULT CreateGlRenderTarget(IAvnGlSurfaceRenderTarget** ret) = 0;
  240. virtual HRESULT SetMainMenu(IAvnMenu* menu) = 0;
  241. virtual HRESULT ObtainNSWindowHandle(void** retOut) = 0;
  242. virtual HRESULT ObtainNSWindowHandleRetained(void** retOut) = 0;
  243. virtual HRESULT ObtainNSViewHandle(void** retOut) = 0;
  244. virtual HRESULT ObtainNSViewHandleRetained(void** retOut) = 0;
  245. virtual HRESULT CreateNativeControlHost(IAvnNativeControlHost** retOut) = 0;
  246. virtual HRESULT BeginDragAndDropOperation(AvnDragDropEffects effects, AvnPoint point,
  247. IAvnClipboard* clipboard, IAvnDndResultCallback* cb, void* sourceHandle) = 0;
  248. virtual HRESULT SetBlurEnabled (bool enable) = 0;
  249. };
  250. AVNCOM(IAvnPopup, 03) : virtual IAvnWindowBase
  251. {
  252. };
  253. AVNCOM(IAvnWindow, 04) : virtual IAvnWindowBase
  254. {
  255. virtual HRESULT SetEnabled (bool enable) = 0;
  256. virtual HRESULT SetParent (IAvnWindow* parent) = 0;
  257. virtual HRESULT SetCanResize(bool value) = 0;
  258. virtual HRESULT SetDecorations(SystemDecorations value) = 0;
  259. virtual HRESULT SetTitle (void* utf8Title) = 0;
  260. virtual HRESULT SetTitleBarColor (AvnColor color) = 0;
  261. virtual HRESULT SetWindowState(AvnWindowState state) = 0;
  262. virtual HRESULT GetWindowState(AvnWindowState*ret) = 0;
  263. virtual HRESULT TakeFocusFromChildren() = 0;
  264. virtual HRESULT SetExtendClientArea (bool enable) = 0;
  265. virtual HRESULT SetExtendClientAreaHints (AvnExtendClientAreaChromeHints hints) = 0;
  266. virtual HRESULT GetExtendTitleBarHeight (double*ret) = 0;
  267. virtual HRESULT SetExtendTitleBarHeight (double value) = 0;
  268. };
  269. AVNCOM(IAvnWindowBaseEvents, 05) : IUnknown
  270. {
  271. virtual HRESULT Paint() = 0;
  272. virtual void Closed() = 0;
  273. virtual void Activated() = 0;
  274. virtual void Deactivated() = 0;
  275. virtual void Resized(const AvnSize& size) = 0;
  276. virtual void PositionChanged (AvnPoint position) = 0;
  277. virtual void RawMouseEvent (AvnRawMouseEventType type,
  278. unsigned int timeStamp,
  279. AvnInputModifiers modifiers,
  280. AvnPoint point,
  281. AvnVector delta) = 0;
  282. virtual bool RawKeyEvent (AvnRawKeyEventType type, unsigned int timeStamp, AvnInputModifiers modifiers, unsigned int key) = 0;
  283. virtual bool RawTextInputEvent (unsigned int timeStamp, const char* text) = 0;
  284. virtual void ScalingChanged(double scaling) = 0;
  285. virtual void RunRenderPriorityJobs() = 0;
  286. virtual void LostFocus() = 0;
  287. virtual AvnDragDropEffects DragEvent(AvnDragEventType type, AvnPoint position,
  288. AvnInputModifiers modifiers, AvnDragDropEffects effects,
  289. IAvnClipboard* clipboard, void* dataObjectHandle) = 0;
  290. };
  291. AVNCOM(IAvnWindowEvents, 06) : IAvnWindowBaseEvents
  292. {
  293. /**
  294. * Closing Event
  295. * Called when the user presses the OS window close button.
  296. * return true to allow the close, return false to prevent close.
  297. */
  298. virtual bool Closing () = 0;
  299. virtual void WindowStateChanged (AvnWindowState state) = 0;
  300. virtual void GotInputWhenDisabled () = 0;
  301. };
  302. AVNCOM(IAvnMacOptions, 07) : IUnknown
  303. {
  304. virtual HRESULT SetShowInDock(int show) = 0;
  305. virtual HRESULT SetApplicationTitle (void* utf8string) = 0;
  306. };
  307. AVNCOM(IAvnActionCallback, 08) : IUnknown
  308. {
  309. virtual void Run() = 0;
  310. };
  311. AVNCOM(IAvnSignaledCallback, 09) : IUnknown
  312. {
  313. virtual void Signaled(int priority, bool priorityContainsMeaningfulValue) = 0;
  314. };
  315. AVNCOM(IAvnLoopCancellation, 0a) : IUnknown
  316. {
  317. virtual void Cancel() = 0;
  318. };
  319. AVNCOM(IAvnPlatformThreadingInterface, 0b) : IUnknown
  320. {
  321. virtual bool GetCurrentThreadIsLoopThread() = 0;
  322. virtual void SetSignaledCallback(IAvnSignaledCallback* cb) = 0;
  323. virtual IAvnLoopCancellation* CreateLoopCancellation() = 0;
  324. virtual HRESULT RunLoop(IAvnLoopCancellation* cancel) = 0;
  325. // Can't pass int* to sharpgentools for some reason
  326. virtual void Signal(int priority) = 0;
  327. virtual IUnknown* StartTimer(int priority, int ms, IAvnActionCallback* callback) = 0;
  328. };
  329. AVNCOM(IAvnSystemDialogEvents, 0c) : IUnknown
  330. {
  331. virtual void OnCompleted (int numResults, void* ptrFirstResult) = 0;
  332. };
  333. AVNCOM(IAvnSystemDialogs, 0d) : IUnknown
  334. {
  335. virtual void SelectFolderDialog (IAvnWindow* parentWindowHandle,
  336. IAvnSystemDialogEvents* events,
  337. const char* title,
  338. const char* initialPath) = 0;
  339. virtual void OpenFileDialog (IAvnWindow* parentWindowHandle,
  340. IAvnSystemDialogEvents* events,
  341. bool allowMultiple,
  342. const char* title,
  343. const char* initialDirectory,
  344. const char* initialFile,
  345. const char* filters) = 0;
  346. virtual void SaveFileDialog (IAvnWindow* parentWindowHandle,
  347. IAvnSystemDialogEvents* events,
  348. const char* title,
  349. const char* initialDirectory,
  350. const char* initialFile,
  351. const char* filters) = 0;
  352. };
  353. AVNCOM(IAvnScreens, 0e) : IUnknown
  354. {
  355. virtual HRESULT GetScreenCount (int* ret) = 0;
  356. virtual HRESULT GetScreen (int index, AvnScreen* ret) = 0;
  357. };
  358. AVNCOM(IAvnClipboard, 0f) : IUnknown
  359. {
  360. virtual HRESULT GetText (char* type, IAvnString**ppv) = 0;
  361. virtual HRESULT SetText (char* type, void* utf8Text) = 0;
  362. virtual HRESULT ObtainFormats(IAvnStringArray**ppv) = 0;
  363. virtual HRESULT GetStrings(char* type, IAvnStringArray**ppv) = 0;
  364. virtual HRESULT SetBytes(char* type, void* utf8Text, int len) = 0;
  365. virtual HRESULT GetBytes(char* type, IAvnString**ppv) = 0;
  366. virtual HRESULT Clear() = 0;
  367. };
  368. AVNCOM(IAvnCursor, 10) : IUnknown
  369. {
  370. };
  371. AVNCOM(IAvnCursorFactory, 11) : IUnknown
  372. {
  373. virtual HRESULT GetCursor (AvnStandardCursorType cursorType, IAvnCursor** retOut) = 0;
  374. };
  375. AVNCOM(IAvnGlDisplay, 13) : IUnknown
  376. {
  377. virtual HRESULT CreateContext(IAvnGlContext* share, IAvnGlContext**ppv) = 0;
  378. virtual void LegacyClearCurrentContext() = 0;
  379. virtual HRESULT WrapContext(void* native, IAvnGlContext**ppv) = 0;
  380. virtual void* GetProcAddress(char* proc) = 0;
  381. };
  382. AVNCOM(IAvnGlContext, 14) : IUnknown
  383. {
  384. virtual HRESULT MakeCurrent(IUnknown** ppv) = 0;
  385. virtual HRESULT LegacyMakeCurrent() = 0;
  386. virtual int GetSampleCount() = 0;
  387. virtual int GetStencilSize() = 0;
  388. virtual void* GetNativeHandle() = 0;
  389. };
  390. AVNCOM(IAvnGlSurfaceRenderTarget, 15) : IUnknown
  391. {
  392. virtual HRESULT BeginDrawing(IAvnGlSurfaceRenderingSession** ret) = 0;
  393. };
  394. AVNCOM(IAvnGlSurfaceRenderingSession, 16) : IUnknown
  395. {
  396. virtual HRESULT GetPixelSize(AvnPixelSize* ret) = 0;
  397. virtual HRESULT GetScaling(double* ret) = 0;
  398. };
  399. AVNCOM(IAvnMenu, 17) : IUnknown
  400. {
  401. virtual HRESULT InsertItem (int index, IAvnMenuItem* item) = 0;
  402. virtual HRESULT RemoveItem (IAvnMenuItem* item) = 0;
  403. virtual HRESULT SetTitle (void* utf8String) = 0;
  404. virtual HRESULT Clear () = 0;
  405. };
  406. AVNCOM(IAvnPredicateCallback, 18) : IUnknown
  407. {
  408. virtual bool Evaluate() = 0;
  409. };
  410. AVNCOM(IAvnMenuItem, 19) : IUnknown
  411. {
  412. virtual HRESULT SetSubMenu (IAvnMenu* menu) = 0;
  413. virtual HRESULT SetTitle (void* utf8String) = 0;
  414. virtual HRESULT SetGesture (void* utf8String, AvnInputModifiers modifiers) = 0;
  415. virtual HRESULT SetAction (IAvnPredicateCallback* predicate, IAvnActionCallback* callback) = 0;
  416. virtual HRESULT SetIsChecked (bool isChecked) = 0;
  417. virtual HRESULT SetToggleType (AvnMenuItemToggleType toggleType) = 0;
  418. virtual HRESULT SetIcon (void* data, size_t length) = 0;
  419. };
  420. AVNCOM(IAvnMenuEvents, 1A) : IUnknown
  421. {
  422. /**
  423. * NeedsUpdate
  424. */
  425. virtual void NeedsUpdate () = 0;
  426. };
  427. AVNCOM(IAvnStringArray, 20) : IUnknown
  428. {
  429. virtual unsigned int GetCount() = 0;
  430. virtual HRESULT Get(unsigned int index, IAvnString**ppv) = 0;
  431. };
  432. AVNCOM(IAvnDndResultCallback, 21) : IUnknown
  433. {
  434. virtual void OnDragAndDropComplete(AvnDragDropEffects effecct) = 0;
  435. };
  436. AVNCOM(IAvnGCHandleDeallocatorCallback, 22) : IUnknown
  437. {
  438. virtual void FreeGCHandle(void* handle) = 0;
  439. };
  440. AVNCOM(IAvnNativeControlHost, 20) : IUnknown
  441. {
  442. virtual HRESULT CreateDefaultChild(void* parent, void** retOut) = 0;
  443. virtual IAvnNativeControlHostTopLevelAttachment* CreateAttachment() = 0;
  444. virtual void DestroyDefaultChild(void* child) = 0;
  445. };
  446. AVNCOM(IAvnNativeControlHostTopLevelAttachment, 21) : IUnknown
  447. {
  448. virtual void* GetParentHandle() = 0;
  449. virtual HRESULT InitializeWithChildHandle(void* child) = 0;
  450. virtual HRESULT AttachTo(IAvnNativeControlHost* host) = 0;
  451. virtual void ShowInBounds(float x, float y, float width, float height) = 0;
  452. virtual void HideWithSize(float width, float height) = 0;
  453. virtual void ReleaseChild() = 0;
  454. };
  455. extern "C" IAvaloniaNativeFactory* CreateAvaloniaNative();