Create FUNDING.yml
[wdl/wdl-ol.git] / WDL / swell / swell.h
blobc373d91d9a2ebe3c8a5111b25e8e76a8ddf8fff6
1 /* Cockos SWELL (Simple/Small Win32 Emulation Layer for Linux/OSX)
2 Copyright (C) 2006 and later, Cockos, Inc.
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
21 SWELL provides _EXTREMELY BASIC_ win32 wrapping for OS X and maybe other platforms.
26 #ifndef _WIN32
29 #ifndef _WDL_SWELL_H_ // here purely for apps/other libraries (dirscan.h uses it), each section actually has its own define
30 #define _WDL_SWELL_H_
33 #if defined(__APPLE__) && !defined(SWELL_FORCE_GENERIC)
34 #define SWELL_TARGET_OSX
35 #define SWELL_TARGET_OSX_COCOA
36 #endif
38 // for swell*generic
39 // #define SWELL_TARGET_GDK
40 // #define SWELL_LICE_GDI
42 #endif
44 #ifdef __APPLE__
45 // go ahead and get this included before we define FSHIFT in swell-types.h
46 #include <sys/param.h>
47 #endif
49 // IF YOU ADD TO SWELL:
50 // Adding types, defines, etc: add to swell-types.h
51 // Adding functions: put them in swell-functions.h
54 #include "swell-types.h"
55 #include "swell-functions.h"
58 #ifndef SWELL_PROVIDED_BY_APP
59 #ifndef _WDL_SWELL_H_UTIL_DEFINED_
60 #define _WDL_SWELL_H_UTIL_DEFINED_
62 // these should never be called directly!!! put SWELL_POSTMESSAGE_DELEGATE_IMPL in your nsapp delegate, and call SWELL_POSTMESSAGE_INIT at some point from there too
64 #define SWELL_POSTMESSAGE_INIT SWELL_Internal_PostMessage_Init();
65 #define SWELL_POSTMESSAGE_DELEGATE_IMPL \
66 -(bool)swellPostMessage:(HWND)dest msg:(int)message wp:(WPARAM)wParam lp:(LPARAM)lParam { \
67 return SWELL_Internal_PostMessage(dest,message,wParam,lParam); \
68 } \
69 -(void)swellPostMessageClearQ:(HWND)dest { \
70 SWELL_Internal_PMQ_ClearAllMessages(dest); \
71 } \
72 -(void)swellPostMessageTick:(id)sender { \
73 SWELL_MessageQueue_Flush(); \
76 BOOL SWELL_Internal_PostMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
77 void SWELL_Internal_PMQ_ClearAllMessages(HWND hwnd);
80 // if you use this then include swell-appstub.mm in your project
81 #define SWELL_APPAPI_DELEGATE_IMPL \
82 -(void *)swellGetAPPAPIFunc { \
83 void *SWELLAPI_GetFunc(const char *name); \
84 return (void*)SWELLAPI_GetFunc; \
87 #endif // _WDL_SWELL_H_UTIL_DEFINED_
88 #endif // !SWELL_PROVIDED_BY_APP
90 #endif // !_WIN32
93 #ifndef SWELL_TARGET_OSX
95 #ifndef SWELL_CB_InsertString
97 #define SWELL_CB_InsertString(hwnd, idx, pos, str) ((int)SendDlgItemMessage(hwnd,idx,CB_INSERTSTRING,(pos),(LPARAM)(str)))
98 #define SWELL_CB_AddString(hwnd, idx, str) ((int)SendDlgItemMessage(hwnd,idx,CB_ADDSTRING,0,(LPARAM)(str)))
99 #define SWELL_CB_SetCurSel(hwnd,idx,val) ((int)SendDlgItemMessage(hwnd,idx,CB_SETCURSEL,(WPARAM)(val),0))
100 #define SWELL_CB_GetNumItems(hwnd,idx) ((int)SendDlgItemMessage(hwnd,idx,CB_GETCOUNT,0,0))
101 #define SWELL_CB_GetCurSel(hwnd,idx) ((int)SendDlgItemMessage(hwnd,idx,CB_GETCURSEL,0,0))
102 #define SWELL_CB_SetItemData(hwnd,idx,item,val) SendDlgItemMessage(hwnd,idx,CB_SETITEMDATA,(item),(val))
103 #define SWELL_CB_GetItemData(hwnd,idx,item) SendDlgItemMessage(hwnd,idx,CB_GETITEMDATA,(item),0)
104 #define SWELL_CB_GetItemText(hwnd,idx,item,buf,bufsz) SendDlgItemMessage(hwnd,idx,CB_GETLBTEXT,(item),(LPARAM)(buf))
105 #define SWELL_CB_Empty(hwnd,idx) SendDlgItemMessage(hwnd,idx,CB_RESETCONTENT,0,0)
106 #define SWELL_CB_DeleteString(hwnd,idx,str) SendDlgItemMessage(hwnd,idx,CB_DELETESTRING,str,0)
108 #define SWELL_TB_SetPos(hwnd, idx, pos) SendDlgItemMessage(hwnd,idx, TBM_SETPOS,TRUE,(pos))
109 #define SWELL_TB_SetRange(hwnd, idx, low, hi) SendDlgItemMessage(hwnd,idx,TBM_SETRANGE,TRUE,(LPARAM)MAKELONG((low),(hi)))
110 #define SWELL_TB_GetPos(hwnd, idx) ((int)SendDlgItemMessage(hwnd,idx,TBM_GETPOS,0,0))
111 #define SWELL_TB_SetTic(hwnd, idx, pos) SendDlgItemMessage(hwnd,idx,TBM_SETTIC,0,(pos))
113 #endif
115 #endif// !SWELL_TARGET_OSX
120 #ifndef WDL_GDP_CTX // stupid GDP compatibility layer, deprecated
123 #define WDL_GDP_CTX HDC
124 #define WDL_GDP_PEN HPEN
125 #define WDL_GDP_BRUSH HBRUSH
126 #define WDL_GDP_CreatePen(col, wid) (WDL_GDP_PEN)CreatePen(PS_SOLID,(wid),(col))
127 #define WDL_GDP_DeletePen(pen) DeleteObject((HGDIOBJ)(pen))
128 #define WDL_GDP_SetPen(ctx, pen) ((WDL_GDP_PEN)SelectObject(ctx,(HGDIOBJ)(pen)))
129 #define WDL_GDP_SetBrush(ctx, brush) ((WDL_GDP_BRUSH)SelectObject(ctx,(HGDIOBJ)(brush)))
130 #define WDL_GDP_CreateBrush(col) (WDL_GDP_BRUSH)CreateSolidBrush(col)
131 #define WDL_GDP_DeleteBrush(brush) DeleteObject((HGDIOBJ)(brush))
132 #define WDL_GDP_FillRectWithBrush(hdc,r,br) FillRect(hdc,r,(HBRUSH)(br))
133 #define WDL_GDP_Rectangle(hdc,l,t,r,b) Rectangle(hdc,l,t,r,b)
134 #define WDL_GDP_Polygon(hdc,pts,n) Polygon(hdc,pts,n)
135 #define WDL_GDP_MoveToEx(hdc,x,y,op) MoveToEx(hdc,x,y,op)
136 #define WDL_GDP_LineTo(hdc,x,y) LineTo(hdc,x,y)
137 #define WDL_GDP_PutPixel(hdc,x,y,c) SetPixel(hdc,x,y,c)
138 #define WDL_GDP_PolyBezierTo(hdc,p,np) PolyBezierTo(hdc,p,np)
140 #define SWELL_SyncCtxFrameBuffer(x) // no longer used
142 #endif
144 #if !defined(SWELL_AUTORELEASE_HELPER_DEFINED) && defined(__cplusplus) && (!defined(SWELL_TARGET_OSX) || defined(SWELL_API_DEFINE))
145 #define SWELL_AUTORELEASE_HELPER_DEFINED
147 class SWELL_AutoReleaseHelper // no-op on non-apple
149 #ifdef SWELL_TARGET_OSX
150 void *m_arp;
151 #endif
152 public:
153 SWELL_AutoReleaseHelper()
155 #ifdef SWELL_TARGET_OSX
156 m_arp = SWELL_InitAutoRelease();
157 #endif
159 ~SWELL_AutoReleaseHelper()
161 #ifdef SWELL_TARGET_OSX
162 release();
163 #endif
166 void release()
168 #ifdef SWELL_TARGET_OSX
169 if (m_arp) { SWELL_QuitAutoRelease(m_arp); m_arp=NULL; }
170 #endif
175 #endif
177 #if defined(_WIN32) && !defined(LoadLibraryGlobals)
178 #define LoadLibraryGlobals(a,b) LoadLibrary(a)
179 #endif