Merge pull request #110 from tesselode/fixes
[wdl/wdl-ol.git] / WDL / swell / swell-functions.h
blob74973929daf31f9da56f1e9bfbc616eb5e276f77
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.
25 #ifndef _WDL_SWELL_H_API_DEFINED_
26 #define _WDL_SWELL_H_API_DEFINED_
28 ////////////////////////////////////////////
29 /////////// FUNCTIONS
30 ////////////////////////////////////////////
32 #ifndef SWELL_API_DEFINE
35 #ifdef SWELL_PROVIDED_BY_APP
36 #ifdef __cplusplus
37 #define SWELL_API_DEFINE(ret,func,parms) extern "C" ret (*func)parms;
38 #else
39 #define SWELL_API_DEFINE(ret,func,parms) extern ret (*func)parms;
40 #endif
41 #else
42 #define SWELL_API_DEFINE(ret,func,parms) ret func parms ;
43 #endif
44 #endif
46 // when adding APIs, add it using:
47 // SWELL_API_DEFINE(void, function_name, (int parm, int parm2))
48 // rather than:
49 // void function_name(int parm, int parm2);
51 /*
52 ** lstrcpyn: this is provided because strncpy is braindead (filling with zeroes, and not
53 ** NULL terminating if the destination buffer is too short? ASKING for trouble..)
54 ** lstrpcyn always null terminates the string and doesnt fill anything extra.
56 SWELL_API_DEFINE(char *, lstrcpyn, (char *dest, const char *src, int l))
60 ** MulDiv(): (parm1*parm2)/parm3
61 ** Implemented using long longs.
63 SWELL_API_DEFINE(int, MulDiv, (int, int, int))
67 ** Sleep() sleeps for specified milliseconds. This maps to usleep, with a ms value of 0
68 ** usleeping for 100 microseconds.
70 SWELL_API_DEFINE(void, Sleep,(int ms))
73 ** GetTickCount() and timeGetTime() give you ms level timings via gettimeofday().
74 **
75 ** NOTE: This doesn't map to time since system start (like in win32), so a wrap around
76 ** is slightly more likely (i.e. even if you booted your system an hour ago it could happen).
78 SWELL_API_DEFINE(DWORD, GetTickCount,())
79 #ifndef timeGetTime
80 #define timeGetTime() GetTickCount()
81 #endif
84 ** GetFileTime() gets the file time of a file (FILE *), and converts it to the Windows time.
86 ** NOTE: while it returns a 64 bit time value, it is only accurate to the second since thats
87 ** what fstat() returns. Takes an int filedes rather than a HANDLE.
89 SWELL_API_DEFINE(BOOL, GetFileTime,(int filedes, FILETIME *lpCreationTime, FILETIME *lpLastAccessTime, FILETIME *lpLastWriteTime))
92 ** *PrivateProfileString/Int():
93 ** These are mostly thread-safe, mostly inter-process safe, and mostly module safe
94 ** (i.e. writes from other modules) should be synchronized).
96 ** NOTES:
97 ** the filename used MUST be the full filename, unlike on Windows where files without paths go to
98 ** C:/Windows, here they will be opened in the current directory.
100 ** It's probably not a good idea to push your luck with simultaneous writes from multiple
101 ** modules in different threads/processes, but in theory it should work.
103 SWELL_API_DEFINE(BOOL, WritePrivateProfileString, (const char *appname, const char *keyname, const char *val, const char *fn))
104 SWELL_API_DEFINE(DWORD, GetPrivateProfileString, (const char *appname, const char *keyname, const char *def, char *ret, int retsize, const char *fn))
105 SWELL_API_DEFINE(int, GetPrivateProfileInt,(const char *appname, const char *keyname, int def, const char *fn))
106 SWELL_API_DEFINE(BOOL, GetPrivateProfileStruct,(const char *appname, const char *keyname, void *buf, int bufsz, const char *fn))
107 SWELL_API_DEFINE(BOOL, WritePrivateProfileStruct,(const char *appname, const char *keyname, const void *buf, int bufsz, const char *fn))
108 SWELL_API_DEFINE(BOOL, WritePrivateProfileSection, (const char *appname, const char *strings, const char *fn))
109 SWELL_API_DEFINE(DWORD, GetPrivateProfileSection, (const char *appname, char *strout, DWORD strout_len, const char *fn))
112 ** GetModuleFileName()
113 ** Can pass NULL (exe filename) or a hInstance from DllMain or LoadLibrary
115 SWELL_API_DEFINE(DWORD, GetModuleFileName,(HINSTANCE hInst, char *fn, DWORD nSize))
117 #ifdef SWELL_TARGET_OSX
119 ** SWELL_CStringToCFString(): Creates a CFString/NSString * from a C string. This is mostly
120 ** used internally but you may wish to use it as well (though none of the SWELL APIs take
121 ** CFString/NSString.
123 SWELL_API_DEFINE(void *,SWELL_CStringToCFString,(const char *str))
124 SWELL_API_DEFINE(void, SWELL_CFStringToCString, (const void *str, char *buf, int buflen))
125 #endif
129 ** PtInRect() should hopefully function just like it's win32 equivelent.
130 ** there is #define funkiness because some Mac system headers define PtInRect as well.
132 #ifdef PtInRect
133 #undef PtInRect
134 #endif
135 #define PtInRect(r,p) SWELL_PtInRect(r,p)
136 SWELL_API_DEFINE(BOOL, SWELL_PtInRect,(const RECT *r, POINT p))
139 ** ShellExecute():
140 ** NOTE: currently action is ignored, and it only works on content1 being an app, an URL beginning with http://,
141 ** "notepad.exe" (content2=file to open), or "explorer.exe" (content2=folder to open, or content2=/select,"file_to_reveal_if_10.6+")
142 ** TODO: finish implementation
144 SWELL_API_DEFINE(BOOL, ShellExecute,(HWND hwndDlg, const char *action, const char *content1, const char *content2, const char *content3, int blah))
147 ** MessageBox().
149 SWELL_API_DEFINE(int, MessageBox,(HWND hwndParent, const char *text, const char *caption, int type))
153 ** GetOpenFileName() / GetSaveFileName()
154 ** These are a different API because we didnt feel like reeimplimenting the full API.
155 ** Extlist is something similar you'd pass getopenfilename,
156 ** initialdir and initialfile are optional (and NULL means not set).
159 // free() the result of this, if non-NULL.
160 // if allowmul is set, the multiple files are specified the same way GetOpenFileName() returns.
161 SWELL_API_DEFINE(char *,BrowseForFiles,(const char *text, const char *initialdir,
162 const char *initialfile, bool allowmul, const char *extlist))
164 // returns TRUE if file was chosen.
165 SWELL_API_DEFINE(bool, BrowseForSaveFile,(const char *text, const char *initialdir, const char *initialfile, const char *extlist,
166 char *fn, int fnsize))
168 // returns TRUE if path was chosen.
169 SWELL_API_DEFINE(bool, BrowseForDirectory,(const char *text, const char *initialdir, char *fn, int fnsize))
171 // can use this before calling BrowseForFiles or BrowseForSaveFile to use a template dialog
172 SWELL_API_DEFINE(void,BrowseFile_SetTemplate,(const char *dlgid, DLGPROC dlgProc, struct SWELL_DialogResourceIndex *reshead))
175 // Note that window functions are generally NOT threadsafe.
176 // all of these treat HWND as NSView and/or NSWindow (usually smartish about it)
180 ** GetDlgItem(hwnd,0) returns hwnd if hwnd is a NSView, or the contentview if hwnd is a NSWindow.
181 ** Note that this GetDlgItem will actually search a view hierarchy for the tagged view,
182 ** unlike Win32 where it will only look at immediate children.
184 SWELL_API_DEFINE(HWND, GetDlgItem,(HWND, int))
187 ** ShowWindow() works for hwnds that represent NSView and/or NSWindow.
188 ** SW_SHOW, SW_SHOWNA, and SW_HIDE are defined, and some of the other common uses
189 ** alias to these.
191 SWELL_API_DEFINE(void, ShowWindow,(HWND, int))
195 ** DestroyWindow() works for both a NSWindow or NSView.
196 ** Note that if the window is a fake window with a procedure
197 ** (created via CreateDialog or DialogBox below) then WM_DESTROY
198 ** will be called immediately, though the window/view may be freed
199 ** sometime later via the autorelease pool.
201 SWELL_API_DEFINE(void, DestroyWindow,(HWND hwnd))
203 SWELL_API_DEFINE(BOOL, SWELL_GetGestureInfo, (LPARAM lParam, GESTUREINFO* gi))
205 SWELL_API_DEFINE(void, SWELL_HideApp,())
208 ** These should all work like their Win32 versions, though if idx=0 it gets/sets the
209 ** value for the window. Note that SetDlgItemText() for an edit control does NOT send
210 ** a WM_COMMAND notification like on win32, so you will have to do this yourself.
212 SWELL_API_DEFINE(BOOL, SetDlgItemText,(HWND, int idx, const char *text))
213 SWELL_API_DEFINE(BOOL, SetDlgItemInt,(HWND, int idx, int val, int issigned))
214 SWELL_API_DEFINE(int, GetDlgItemInt,(HWND, int idx, BOOL *translated, int issigned))
215 SWELL_API_DEFINE(BOOL, GetDlgItemText,(HWND, int idx, char *text, int textlen))
217 #ifndef GetWindowText
218 #define GetWindowText(hwnd,text,textlen) GetDlgItemText(hwnd,0,text,textlen)
219 #define SetWindowText(hwnd,text) SetDlgItemText(hwnd,0,text)
220 #endif
223 SWELL_API_DEFINE(void, CheckDlgButton,(HWND hwnd, int idx, int check))
224 SWELL_API_DEFINE(int, IsDlgButtonChecked,(HWND hwnd, int idx))
225 SWELL_API_DEFINE(void, EnableWindow,(HWND hwnd, int enable))
226 SWELL_API_DEFINE(void, SetFocus,(HWND hwnd)) // these take NSWindow/NSView, and return NSView *
227 SWELL_API_DEFINE(HWND, GetFocus,())
228 SWELL_API_DEFINE(void, SetForegroundWindow,(HWND hwnd)) // these take NSWindow/NSView, and return NSView *
229 SWELL_API_DEFINE(HWND, GetForegroundWindow,())
230 #ifndef GetActiveWindow
231 #define GetActiveWindow() GetForegroundWindow()
232 #endif
233 #ifndef SetActiveWindow
234 #define SetActiveWindow(x) SetForegroundWindow(x)
235 #endif
238 ** GetCapture/SetCapture/ReleaseCapture are completely faked, with just an internal state.
239 ** Mouse click+drag automatically captures the focus sending mouseDrag events in OSX, so
240 ** these are as a porting aid.
242 ** Updated: they actually send WM_CAPTURECHANGED messages now, if the window supports
243 ** onSwellMessage:p1:p2: and swellCapChangeNotify (and swellCapChangeNotify returns YES).
245 ** Note that any HWND that returns YES to swellCapChangeNotify should do the following on
246 ** destroy or dealloc: if (GetCapture()==(HWND)self) ReleaseCapture(); Failure to do so
247 ** can cause a dealloc'd window to get messages sent to it.
249 SWELL_API_DEFINE(HWND, SetCapture,(HWND hwnd))
250 SWELL_API_DEFINE(HWND, GetCapture,())
251 SWELL_API_DEFINE(void, ReleaseCapture,())
254 ** IsChild()
255 ** Notes: hwndChild must be a NSView (if not then false is returned)
256 ** hwndParent can be a NSWindow or NSView.
257 ** NSWindow level ownership/children are not detected.
259 SWELL_API_DEFINE(int, IsChild,(HWND hwndParent, HWND hwndChild))
263 ** GetParent()
264 ** Notes: if hwnd is a NSView, then gets the parent view (or NSWindow
265 ** if the parent view is the window's contentview). If hwnd is a NSWindow,
266 ** then GetParent returns the owner window, if any. Note that the owner
267 ** window system is not part of OSX, but rather part of SWELL.
269 SWELL_API_DEFINE(HWND, GetParent,(HWND hwnd))
272 ** SetParent()
273 ** Notes: hwnd must be a NSView, newPar can be either NSView or NSWindow.
275 SWELL_API_DEFINE(HWND, SetParent,(HWND hwnd, HWND newPar))
278 ** GetWindow()
279 ** Most of the standard GW_CHILD etc work. Does not do anything to prevent you from
280 ** getting into infinite loops if you go changing the order on the fly etc.
282 SWELL_API_DEFINE(HWND, GetWindow,(HWND hwnd, int what))
284 SWELL_API_DEFINE(BOOL, EnumWindows, (BOOL (*proc)(HWND, LPARAM), LPARAM lp))
286 SWELL_API_DEFINE(HWND,FindWindowEx,(HWND par, HWND lastw, const char *classname, const char *title))
290 ** Notes: common win32 code like this:
291 ** RECT r;
292 ** GetWindowRect(hwnd,&r);
293 ** ScreenToClient(otherhwnd,(LPPOINT)&r);
294 ** ScreenToClient(otherhwnd,((LPPOINT)&r)+1);
295 ** does work, however be aware that in certain instances r.bottom may be less
296 ** than r.top, due to flipped coordinates. SetWindowPos and other functions
297 ** handle negative heights gracefully, and you should too.
299 ** Note: GetWindowContentViewRect gets the rectangle of the content view (pre-NCCALCSIZE etc)
301 SWELL_API_DEFINE(void, ClientToScreen,(HWND hwnd, POINT *p))
302 SWELL_API_DEFINE(void, ScreenToClient,(HWND hwnd, POINT *p))
303 SWELL_API_DEFINE(bool, GetWindowRect,(HWND hwnd, RECT *r))
304 SWELL_API_DEFINE(void, GetWindowContentViewRect, (HWND hwnd, RECT *r))
305 SWELL_API_DEFINE(void, GetClientRect,(HWND hwnd, RECT *r))
306 SWELL_API_DEFINE(HWND, WindowFromPoint,(POINT p))
307 SWELL_API_DEFINE(BOOL, WinOffsetRect, (LPRECT lprc, int dx, int dy))
308 SWELL_API_DEFINE(BOOL, WinSetRect, (LPRECT lprc, int xLeft, int yTop, int xRight, int yBottom))
309 SWELL_API_DEFINE(void,WinUnionRect,(RECT *out, const RECT *in1, const RECT *in2))
310 SWELL_API_DEFINE(int,WinIntersectRect,(RECT *out, const RECT *in1, const RECT *in2))
314 ** SetWindowPos():
315 ** Notes: Z ordering stuff is ignored, as are most flags.
316 ** SWP_NOMOVE and SWP_NOSIZE are the only flags used.
318 SWELL_API_DEFINE(void, SetWindowPos,(HWND hwnd, HWND unused, int x, int y, int cx, int cy, int flags))
320 SWELL_API_DEFINE(int, SWELL_SetWindowLevel, (HWND hwnd, int newlevel))
323 ** InvalidateRect()
324 ** Notes: eraseBk is ignored, probably not threadsafe! hwnd can be NSWindow or NSView
326 SWELL_API_DEFINE(BOOL,InvalidateRect,(HWND hwnd, const RECT *r, int eraseBk))
329 ** UpdateWindow()
330 ** Notes: not currently implemented but provided here in case someday it is necessary
332 SWELL_API_DEFINE(void,UpdateWindow,(HWND hwnd))
336 ** GetWindowLong()/SetWindowLong()
338 ** GWL_ID is supported for all objects that support the 'tag'/'setTag' methods,
339 ** which would be controls and SWELL created windows/dialogs/controls.
341 ** GWL_USERDATA is supported by SWELL created windows/dialogs/controls, using
342 ** (int)getSwellUserData and setSwellUserData:(int).
344 ** GWL_WNDPROC is supported by SWELL created windows/dialogs/controls, using
345 ** (int)getSwellWindowProc and setSwellWindowProc:(int).
347 ** DWL_DLGPROC is supported by SWELL created dialogs now (it might work in windows/controls but isnt recommended)
349 ** GWL_STYLE is only supported for NSButton. Currently the only flags supported are
350 ** BS_AUTO3STATE (BS_AUTOCHECKBOX is returned but also ignored).
352 ** indices of >= 0 and < 128 (32 integers) are supported for SWELL created
353 ** windows/dialogs/controls, via (int)getSwellExtraData:(int)idx and
354 ** setSwellExtraData:(int)idx value:(int)val .
356 SWELL_API_DEFINE(LONG_PTR, GetWindowLong,(HWND hwnd, int idx))
357 SWELL_API_DEFINE(LONG_PTR, SetWindowLong,(HWND hwnd, int idx, LONG_PTR val))
360 SWELL_API_DEFINE(BOOL, ScrollWindow, (HWND hwnd, int xamt, int yamt, const RECT *lpRect, const RECT *lpClipRect))
363 ** GetProp() SetProp() RemoveProp() EnumPropsEx()
364 ** These should work like in win32. Free your props otherwise they will leak.
365 ** Restriction on what you can do in the PROPENUMPROCEX is similar to win32
366 ** (you can remove only the called prop, and can't add props within it).
367 ** if the prop name is < (void *)65536 then it is treated as a short identifier.
369 SWELL_API_DEFINE(int, EnumPropsEx,(HWND, PROPENUMPROCEX, LPARAM))
370 SWELL_API_DEFINE(HANDLE, GetProp, (HWND, const char *))
371 SWELL_API_DEFINE(BOOL, SetProp, (HWND, const char *, HANDLE))
372 SWELL_API_DEFINE(HANDLE, RemoveProp, (HWND, const char *))
376 ** IsWindowVisible()
377 ** if hwnd is a NSView, returns !isHiddenOrHasHiddenAncestor
378 ** if hwnd is a NSWindow returns isVisible
379 ** otherwise returns TRUE if non-null hwnd
381 SWELL_API_DEFINE(bool, IsWindowVisible,(HWND hwnd))
383 SWELL_API_DEFINE(bool, IsWindow, (HWND hwnd)) // very costly (compared to win32) -- enumerates all windows, searches for hwnd
384 SWELL_API_DEFINE(void, CenterWindow, (HWND hwnd))
388 ** SetTimer/KillTimer():
389 ** Notes:
390 ** The timer API may be threadsafe though it is highly untested.
391 ** Note also that the mechanism for sending timers is SWELL_Timer:(id).
392 ** The fourth parameter to SetTimer() is not supported and will be ignored, so you must
393 ** receive your timers via a WM_TIMER (or SWELL_Timer:(id))
395 ** You can kill all timers for a window using KillTimer(hwnd,-1);
396 ** You MUST kill all timers for a window before destroying it. Note that SWELL created
397 ** windows/dialogs/controls automatically do this, but if you use SetTimer() on a NSView *
398 ** or NSWindow * directly, then you should kill all timers in -dealloc.
400 SWELL_API_DEFINE(UINT_PTR, SetTimer,(HWND hwnd, UINT_PTR timerid, UINT rate, TIMERPROC tProc))
401 SWELL_API_DEFINE(BOOL, KillTimer,(HWND hwnd, UINT_PTR timerid))
403 #ifdef SWELL_TARGET_OSX
405 ** These provide the interfaces for directly updating a combo box control. This is no longer
406 ** required as SendMessage can now be used with CB_* etc.
407 ** Combo boxes may be implemented using a NSComboBox or NSPopUpButton depending on the style.
409 ** Notes: CB_SetItemData/CB_GetItemData only work for the non-user-editable version (using NSPopUpbutotn).
411 SWELL_API_DEFINE(int, SWELL_CB_AddString,(HWND hwnd, int idx, const char *str))
412 SWELL_API_DEFINE(void, SWELL_CB_SetCurSel,(HWND hwnd, int idx, int sel))
413 SWELL_API_DEFINE(int, SWELL_CB_GetCurSel,(HWND hwnd, int idx))
414 SWELL_API_DEFINE(int, SWELL_CB_GetNumItems,(HWND hwnd, int idx))
415 SWELL_API_DEFINE(void, SWELL_CB_SetItemData,(HWND hwnd, int idx, int item, LONG_PTR data)) // these two only work for the combo list version for now
416 SWELL_API_DEFINE(LONG_PTR, SWELL_CB_GetItemData,(HWND hwnd, int idx, int item))
417 SWELL_API_DEFINE(void, SWELL_CB_Empty,(HWND hwnd, int idx))
418 SWELL_API_DEFINE(int, SWELL_CB_InsertString,(HWND hwnd, int idx, int pos, const char *str))
419 SWELL_API_DEFINE(int, SWELL_CB_GetItemText,(HWND hwnd, int idx, int item, char *buf, int bufsz))
420 SWELL_API_DEFINE(void, SWELL_CB_DeleteString,(HWND hwnd, int idx, int wh))
421 SWELL_API_DEFINE(int, SWELL_CB_FindString,(HWND hwnd, int idx, int startAfter, const char *str, bool exact))
425 ** Trackbar API
426 ** These provide the interfaces for directly updating a trackbar (implemented using NSSlider).
427 ** Note that you can now use SendMessage with TBM_* instead.
429 SWELL_API_DEFINE(void, SWELL_TB_SetPos,(HWND hwnd, int idx, int pos))
430 SWELL_API_DEFINE(void, SWELL_TB_SetRange,(HWND hwnd, int idx, int low, int hi))
431 SWELL_API_DEFINE(int, SWELL_TB_GetPos,(HWND hwnd, int idx))
432 SWELL_API_DEFINE(void, SWELL_TB_SetTic,(HWND hwnd, int idx, int pos))
435 #endif
438 ** ListView API. In owner data mode only LVN_GETDISPINFO is used (not ODFINDITEM etc).
439 ** LVN_BEGINDRAG also should work as on windows. Imagelists state icons work as well.
441 SWELL_API_DEFINE(void, ListView_SetExtendedListViewStyleEx,(HWND h, int mask, int style))
442 SWELL_API_DEFINE(void, ListView_InsertColumn,(HWND h, int pos, const LVCOLUMN *lvc))
443 SWELL_API_DEFINE(bool, ListView_DeleteColumn,(HWND h, int pos))
444 SWELL_API_DEFINE(void, ListView_SetColumn,(HWND h, int pos, const LVCOLUMN *lvc))
445 SWELL_API_DEFINE(int, ListView_GetColumnWidth,(HWND h, int pos))
446 SWELL_API_DEFINE(int, ListView_InsertItem,(HWND h, const LVITEM *item))
447 SWELL_API_DEFINE(void, ListView_SetItemText,(HWND h, int ipos, int cpos, const char *txt))
448 SWELL_API_DEFINE(bool, ListView_SetItem,(HWND h, LVITEM *item))
449 SWELL_API_DEFINE(int, ListView_GetNextItem,(HWND h, int istart, int flags))
450 SWELL_API_DEFINE(bool, ListView_GetItem,(HWND h, LVITEM *item))
451 SWELL_API_DEFINE(int, ListView_GetItemState,(HWND h, int ipos, UINT mask))
452 SWELL_API_DEFINE(void, ListView_DeleteItem,(HWND h, int ipos))
453 SWELL_API_DEFINE(void, ListView_DeleteAllItems,(HWND h))
454 SWELL_API_DEFINE(int, ListView_GetSelectedCount,(HWND h))
455 SWELL_API_DEFINE(int, ListView_GetItemCount,(HWND h))
456 SWELL_API_DEFINE(int, ListView_GetSelectionMark,(HWND h))
457 SWELL_API_DEFINE(void, ListView_SetColumnWidth,(HWND h, int colpos, int wid))
458 SWELL_API_DEFINE(bool, ListView_SetItemState,(HWND h, int item, UINT state, UINT statemask))
459 SWELL_API_DEFINE(void, ListView_RedrawItems,(HWND h, int startitem, int enditem))
460 SWELL_API_DEFINE(void, ListView_SetItemCount,(HWND h, int cnt))
461 #ifdef ListView_SetItemCountEx
462 #undef ListView_SetItemCountEx
463 #endif
464 #define ListView_SetItemCountEx(list,cnt,flags) ListView_SetItemCount(list,cnt)
466 SWELL_API_DEFINE(void, ListView_EnsureVisible,(HWND h, int i, BOOL pok))
467 SWELL_API_DEFINE(bool, ListView_GetSubItemRect,(HWND h, int item, int subitem, int code, RECT *r))
468 SWELL_API_DEFINE(void, ListView_SetImageList,(HWND h, HIMAGELIST imagelist, int which))
469 SWELL_API_DEFINE(int, ListView_HitTest,(HWND h, LVHITTESTINFO *pinf))
470 SWELL_API_DEFINE(int, ListView_SubItemHitTest,(HWND h, LVHITTESTINFO *pinf))
471 SWELL_API_DEFINE(void, ListView_GetItemText,(HWND hwnd, int item, int subitem, char *text, int textmax))
472 SWELL_API_DEFINE(void, ListView_SortItems,(HWND hwnd, PFNLVCOMPARE compf, LPARAM parm))
473 SWELL_API_DEFINE(bool, ListView_GetItemRect,(HWND h, int item, RECT *r, int code))
474 SWELL_API_DEFINE(bool, ListView_Scroll,(HWND h, int xscroll, int yscroll))
475 SWELL_API_DEFINE(int, ListView_GetTopIndex,(HWND h))
476 SWELL_API_DEFINE(int, ListView_GetCountPerPage,(HWND h))
477 SWELL_API_DEFINE(BOOL, ListView_SetColumnOrderArray,(HWND h, int cnt, int* arr))
478 SWELL_API_DEFINE(BOOL, ListView_GetColumnOrderArray,(HWND h, int cnt, int* arr))
479 SWELL_API_DEFINE(HWND, ListView_GetHeader,(HWND h))
480 SWELL_API_DEFINE(int, Header_GetItemCount,(HWND h))
481 SWELL_API_DEFINE(BOOL, Header_GetItem,(HWND h, int col, HDITEM* hi))
482 SWELL_API_DEFINE(BOOL, Header_SetItem,(HWND h, int col, HDITEM* hi))
484 SWELL_API_DEFINE(int, SWELL_GetListViewHeaderHeight, (HWND h))
486 #ifndef ImageList_Create
487 #define ImageList_Create(x,y,a,b,c) ImageList_CreateEx();
488 #endif
489 SWELL_API_DEFINE(HIMAGELIST, ImageList_CreateEx,())
490 SWELL_API_DEFINE(BOOL, ImageList_Remove, (HIMAGELIST list, int idx))
491 SWELL_API_DEFINE(int, ImageList_ReplaceIcon,(HIMAGELIST list, int offset, HICON image))
492 SWELL_API_DEFINE(int, ImageList_Add,(HIMAGELIST list, HBITMAP image, HBITMAP mask))
493 SWELL_API_DEFINE(void, ImageList_Destroy, (HIMAGELIST))
495 ** TabCtrl api.
497 SWELL_API_DEFINE(int, TabCtrl_GetItemCount,(HWND hwnd))
498 SWELL_API_DEFINE(BOOL, TabCtrl_DeleteItem,(HWND hwnd, int idx))
499 SWELL_API_DEFINE(int, TabCtrl_InsertItem,(HWND hwnd, int idx, TCITEM *item))
500 SWELL_API_DEFINE(int, TabCtrl_SetCurSel,(HWND hwnd, int idx))
501 SWELL_API_DEFINE(int, TabCtrl_GetCurSel,(HWND hwnd))
502 SWELL_API_DEFINE(BOOL, TabCtrl_AdjustRect, (HWND hwnd, BOOL fLarger, RECT *r))
505 ** TreeView
508 SWELL_API_DEFINE(HTREEITEM, TreeView_InsertItem, (HWND hwnd, TV_INSERTSTRUCT *ins))
509 SWELL_API_DEFINE(BOOL, TreeView_Expand,(HWND hwnd, HTREEITEM item, UINT flag))
510 SWELL_API_DEFINE(HTREEITEM, TreeView_GetSelection,(HWND hwnd))
511 SWELL_API_DEFINE(void, TreeView_DeleteItem,(HWND hwnd, HTREEITEM item))
512 SWELL_API_DEFINE(void, TreeView_DeleteAllItems,(HWND hwnd))
513 SWELL_API_DEFINE(void, TreeView_SelectItem,(HWND hwnd, HTREEITEM item))
514 SWELL_API_DEFINE(BOOL, TreeView_GetItem,(HWND hwnd, LPTVITEM pitem))
515 SWELL_API_DEFINE(BOOL, TreeView_SetItem,(HWND hwnd, LPTVITEM pitem))
516 SWELL_API_DEFINE(HTREEITEM, TreeView_HitTest, (HWND hwnd, TVHITTESTINFO *hti))
517 SWELL_API_DEFINE(BOOL, TreeView_SetIndent,(HWND hwnd, int indent))
519 SWELL_API_DEFINE(HTREEITEM, TreeView_GetChild, (HWND hwnd, HTREEITEM item))
520 SWELL_API_DEFINE(HTREEITEM, TreeView_GetNextSibling, (HWND hwnd, HTREEITEM item))
521 SWELL_API_DEFINE(HTREEITEM, TreeView_GetRoot, (HWND hwnd))
523 SWELL_API_DEFINE(void,TreeView_SetBkColor,(HWND hwnd, int color))
524 SWELL_API_DEFINE(void,TreeView_SetTextColor,(HWND hwnd, int color))
525 SWELL_API_DEFINE(void,ListView_SetBkColor,(HWND hwnd, int color))
526 SWELL_API_DEFINE(void,ListView_SetTextBkColor,(HWND hwnd, int color))
527 SWELL_API_DEFINE(void,ListView_SetTextColor,(HWND hwnd, int color))
528 SWELL_API_DEFINE(void,ListView_SetGridColor,(HWND hwnd, int color))
529 SWELL_API_DEFINE(void,ListView_SetSelColors,(HWND hwnd, int *colors, int ncolors))
532 ** These are deprecated functions for launching a modal window but still running
533 ** your own code. In general use DialogBox with a timer if needed instead.
535 SWELL_API_DEFINE(void *, SWELL_ModalWindowStart,(HWND hwnd))
536 SWELL_API_DEFINE(bool, SWELL_ModalWindowRun,(void *ctx, int *ret)) // returns false and puts retval in *ret when done
537 SWELL_API_DEFINE(void, SWELL_ModalWindowEnd,(void *ctx))
538 SWELL_API_DEFINE(void, SWELL_CloseWindow,(HWND hwnd))
542 ** Menu functions
543 ** HMENU is a NSMenu *.
545 SWELL_API_DEFINE(HMENU, CreatePopupMenu,())
546 SWELL_API_DEFINE(HMENU, CreatePopupMenuEx,(const char *title))
547 SWELL_API_DEFINE(void, DestroyMenu,(HMENU hMenu))
548 SWELL_API_DEFINE(int, AddMenuItem,(HMENU hMenu, int pos, const char *name, int tagid))
549 SWELL_API_DEFINE(HMENU, GetSubMenu,(HMENU hMenu, int pos))
550 SWELL_API_DEFINE(int, GetMenuItemCount,(HMENU hMenu))
551 SWELL_API_DEFINE(int, GetMenuItemID,(HMENU hMenu, int pos))
552 SWELL_API_DEFINE(bool, SetMenuItemModifier,(HMENU hMenu, int idx, int flag, int code, unsigned int mask))
553 SWELL_API_DEFINE(bool, SetMenuItemText,(HMENU hMenu, int idx, int flag, const char *text))
554 SWELL_API_DEFINE(bool, EnableMenuItem,(HMENU hMenu, int idx, int en))
555 SWELL_API_DEFINE(bool, DeleteMenu,(HMENU hMenu, int idx, int flag))
556 SWELL_API_DEFINE(bool, CheckMenuItem,(HMENU hMenu, int idx, int chk))
557 SWELL_API_DEFINE(void, InsertMenuItem,(HMENU hMenu, int pos, BOOL byPos, MENUITEMINFO *mi))
558 SWELL_API_DEFINE(void,SWELL_InsertMenu,(HMENU menu, int pos, unsigned int flag, UINT_PTR idx, const char *str))
559 #ifdef InsertMenu
560 #undef InsertMenu
561 #endif
562 #define InsertMenu SWELL_InsertMenu
564 SWELL_API_DEFINE(BOOL, GetMenuItemInfo,(HMENU hMenu, int pos, BOOL byPos, MENUITEMINFO *mi))
565 SWELL_API_DEFINE(BOOL, SetMenuItemInfo,(HMENU hMenu, int pos, BOOL byPos, MENUITEMINFO *mi))
566 SWELL_API_DEFINE(void, DrawMenuBar,(HWND))
571 ** LoadMenu()
572 ** Loads a menu created with SWELL_DEFINE_MENU_RESOURCE_BEGIN(), see swell-menugen.h
573 ** Notes: the hinst parameter is ignored, the menu must have been defined in the same
574 ** APP or DYLIB as the LoadMenu call. If you wish to load a menu from another module,
575 ** you should somehow get its SWELL_curmodule_menuresource_head and pass it to SWELL_LoadMenu
576 ** directly.
578 #ifndef LoadMenu
579 #define LoadMenu(hinst,resid) SWELL_LoadMenu(SWELL_curmodule_menuresource_head,(resid))
580 #endif
581 SWELL_API_DEFINE(HMENU, SWELL_LoadMenu,(struct SWELL_MenuResourceIndex *head, const char *resid))
584 ** TrackPopupMenu
585 ** Notes: the rectangle and many flags are ignored, but TPM_NONOTIFY is used.
586 ** It always returns the command selected, even if TPM_RETURNCMD is not specified.
588 SWELL_API_DEFINE(int, TrackPopupMenu,(HMENU hMenu, int flags, int xpos, int ypos, int resvd, HWND hwnd, const RECT *r))
591 ** SWELL_SetMenuDestination: set the action destination for all items in a menu
592 ** Notes:
593 ** TrackPopupMenu and SetMenu use this internally, but it may be useful.
595 SWELL_API_DEFINE(void, SWELL_SetMenuDestination,(HMENU menu, HWND hwnd))
598 ** SWELL_DuplicateMenu:
599 ** Copies an entire menu.
601 SWELL_API_DEFINE(HMENU, SWELL_DuplicateMenu,(HMENU menu))
604 ** SetMenu()/GetMenu()
605 ** Notes: These work on SWELL created NSWindows, or objective C objects that respond to
606 ** swellSetMenu:(HMENU) and swellGetMenu.
607 ** Setting these values doesnt mean anything, except that the SWELL windows will automatically
608 ** set the application menu via NSApp setMainMenu: when activated.
611 SWELL_API_DEFINE(BOOL, SetMenu,(HWND hwnd, HMENU menu))
612 SWELL_API_DEFINE(HMENU, GetMenu,(HWND hwnd))
615 ** SWELL_SetDefaultWindowMenu()/SWELL_GetDefaultWindowMenu()
616 ** these set an internal flag for the default window menu, which will be set
617 ** when switching to a window that has no menu set. Set this to your application's
618 ** main menu.
620 SWELL_API_DEFINE(HMENU, SWELL_GetDefaultWindowMenu,())
621 SWELL_API_DEFINE(void, SWELL_SetDefaultWindowMenu,(HMENU))
622 SWELL_API_DEFINE(HMENU, SWELL_GetDefaultModalWindowMenu,())
623 SWELL_API_DEFINE(void, SWELL_SetDefaultModalWindowMenu,(HMENU))
624 SWELL_API_DEFINE(HMENU, SWELL_GetCurrentMenu,())
625 SWELL_API_DEFINE(void, SWELL_SetCurrentMenu,(HMENU))
630 ** SWELL dialog box/control/window/child dialog/etc creation
631 ** DialogBox(), DialogBoxParam(), CreateDialog(), and CreateDialogParam()
633 ** Notes:
634 ** hInstance parameters are ignored. If you wish to load a dialog resource from another
635 ** module (DYLIB), you should get its SWELL_curmodule_dialogresource_head via your own
636 ** mechanism and pass it as the first parameter of SWELL_DialogBox or whichever API.
638 ** If you are using CreateDialog() and creating a child window, you can use a resource ID of
639 ** 0, which creates an opaque child window. Instead of passing a DLGPROC, you should pass a
640 ** routine that retuns LRESULT (and cast it to DLGPROC).
644 #ifndef DialogBox
645 #define DialogBox(hinst, resid, par, dlgproc) SWELL_DialogBox(SWELL_curmodule_dialogresource_head,(resid),par,dlgproc,0)
646 #define DialogBoxParam(hinst, resid, par, dlgproc, param) SWELL_DialogBox(SWELL_curmodule_dialogresource_head,(resid),par,dlgproc,param)
647 #define CreateDialog(hinst,resid,par,dlgproc) SWELL_CreateDialog(SWELL_curmodule_dialogresource_head,(resid),par,dlgproc,0)
648 #define CreateDialogParam(hinst,resid,par,dlgproc,param) SWELL_CreateDialog(SWELL_curmodule_dialogresource_head,(resid),par,dlgproc,param)
649 #endif
650 SWELL_API_DEFINE(int, SWELL_DialogBox,(struct SWELL_DialogResourceIndex *reshead, const char *resid, HWND parent, DLGPROC dlgproc, LPARAM param))
651 SWELL_API_DEFINE(HWND, SWELL_CreateDialog,(struct SWELL_DialogResourceIndex *reshead, const char *resid, HWND parent, DLGPROC dlgproc, LPARAM param))
655 ** SWELL_RegisterCustomControlCreator(), SWELL_UnregisterCustomControlCreator()
656 ** Notes:
657 ** Pass these a callback function that can create custom controls based on classname.
658 ** Todo: document.
661 SWELL_API_DEFINE(void, SWELL_RegisterCustomControlCreator,(SWELL_ControlCreatorProc proc))
662 SWELL_API_DEFINE(void, SWELL_UnregisterCustomControlCreator,(SWELL_ControlCreatorProc proc))
665 ** DefWindowProc().
666 ** Notes: Doesnt do much but call it anyway from any child windows created with CreateDialog
667 ** and a 0 resource-id window proc.
669 SWELL_API_DEFINE(LRESULT, DefWindowProc,(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam))
672 ** EndDialog():
673 ** Notes: _ONLY_ use on a dialog created with DialogBox(). Will do nothing on other dialogs.
675 SWELL_API_DEFINE(void, EndDialog,(HWND, int))
678 SWELL_API_DEFINE(int,SWELL_GetDefaultButtonID,(HWND hwndDlg, bool onlyIfEnabled))
682 ** SendMessage()
683 ** Notes:
684 ** LIMITATION - SendMessage should only be used from the same thread that the window/view
685 ** was created in. Cross-thread use SHOULD BE AVOIDED. It may work, but it may blow up.
686 ** PostMessage (below) can be used in certain instances for asynchronous notifications.
688 ** If the hwnd supports onSwellMessage:p1:p2: then the message is sent via this.
689 ** Alternatively, buttons created via the dialog interface support BM_GETIMAGE/BM_SETIMAGE
690 ** NSPopUpButton and NSComboBox controls support CB_*
691 ** NSSlider controls support TBM_*
692 ** If the receiver is a view and none of these work, the message goes to the window's onSwellMessage, if any
693 ** If the receiver is a window and none of these work, the message goes to the window's contentview's onSwellMessage, if any
696 SWELL_API_DEFINE(LRESULT, SendMessage,(HWND, UINT, WPARAM, LPARAM))
697 #ifndef SendDlgItemMessage
698 #define SendDlgItemMessage(hwnd,idx,msg,wparam,lparam) SendMessage(GetDlgItem(hwnd,idx),msg,wparam,lparam)
699 #endif
701 SWELL_API_DEFINE(void,SWELL_BroadcastMessage,(UINT, WPARAM, LPARAM))
704 ** PostMessage()
705 ** Notes:
706 ** Queues a message into the application message queue. Note that you should only ever
707 ** send messages to destinations that were created from the main thread. They will be
708 ** processed later from a timer (in the main thread).
709 ** When a window is destroyed any outstanding messages will be discarded for it.
711 SWELL_API_DEFINE(BOOL, PostMessage,(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam))
714 ** SWELL_MessageQueue_Flush():
715 ** Notes:
716 ** Processes all messages in the message queue. ONLY call from the main thread.
718 SWELL_API_DEFINE(void, SWELL_MessageQueue_Flush,())
721 ** SWELL_MessageQueue_Clear():
722 ** Notes:
723 ** Discards all messages from the message queue if h is NULL, otherwise discards all messages
724 ** to h.
726 SWELL_API_DEFINE(void, SWELL_MessageQueue_Clear,(HWND h))
731 ** keyboard/mouse support
735 ** SWELL_MacKeyToWindowsKey()
736 ** Pass a keyboard NSEvent *, and it will return a windows VK_ keycode (or ascii), and set flags,
737 ** including (possibly) FSHIFT, FCONTROL (apple key), FALT, and FVIRTKEY. The ctrl key is not checked,
738 ** as SWELL generally encourages this to be used soley for a right mouse button (as modifier).
740 #ifdef SWELL_TARGET_OSX
741 SWELL_API_DEFINE(int, SWELL_MacKeyToWindowsKey,(void *nsevent, int *flags))
743 // ex is the same as normal, except if mode=1 it does more processing of raw keys w/ modifiers
744 // and also if nsevent==NULL current event is used
745 SWELL_API_DEFINE(int, SWELL_MacKeyToWindowsKeyEx,(void *nsevent, int *flags, int mode))
746 #endif
747 SWELL_API_DEFINE(int,SWELL_KeyToASCII,(int wParam, int lParam, int *newflags))
751 ** GetAsyncKeyState()
752 ** Notes: only supports MK_LBUTTON, MK_RBUTTON, MK_MBUTTON, VK_SHIFT, VK_MENU, and VK_CONTROL (apple key) for now.
754 SWELL_API_DEFINE(WORD, GetAsyncKeyState,(int key))
757 ** GetCursorPos(), GetMessagePos()
758 ** Notes: GetMessagePos() currently returns the same coordinates as GetCursorPos(),
759 ** this needs to be fixed.
761 SWELL_API_DEFINE(void, GetCursorPos,(POINT *pt))
762 SWELL_API_DEFINE(DWORD, GetMessagePos,())
765 ** LoadCursor().
766 ** Notes: hinstance parameter ignored, currently only supports loading some of the predefined values.
767 ** (IDC_SIZEALL etc). If it succeeds value is a NSCursor *
769 SWELL_API_DEFINE(HCURSOR, SWELL_LoadCursor,(const char *idx))
770 #ifndef LoadCursor
771 #define LoadCursor(a,x) SWELL_LoadCursor(x)
772 #endif
775 ** SetCursor()
776 ** Sets a cursor as active (can be HCURSOR or NSCursor * cast as such).
778 #ifdef SetCursor
779 #undef SetCursor
780 #endif
781 #define SetCursor(x) SWELL_SetCursor(x)
782 SWELL_API_DEFINE(void, SWELL_SetCursor,(HCURSOR curs))
785 #ifdef GetCursor
786 #undef GetCursor
787 #endif
788 #define GetCursor SWELL_GetCursor
790 #ifdef ShowCursor
791 #undef ShowCursor
792 #endif
793 #define ShowCursor SWELL_ShowCursor
795 #ifdef SetCursorPos
796 #undef SetCursorPos
797 #endif
798 #define SetCursorPos SWELL_SetCursorPos
800 #ifdef ScrollWindowEx
801 #undef ScrollWindowEx
802 #endif
803 #define ScrollWindowEx(a,b,c,d,e,f,g,h) ScrollWindow(a,b,c,d,e)
807 ** Globally enable or disable emulating mouse right-click using control+left-click
809 SWELL_API_DEFINE(void, SWELL_EnableRightClickEmulate, (BOOL enable))
813 ** GetCursor() gets the actual system cursor,
814 ** SWELL_GetLastSetCursor() gets the last cursor set via SWELL (if they differ than some other window must have changed the cursor)
816 SWELL_API_DEFINE(HCURSOR, SWELL_GetCursor,())
817 SWELL_API_DEFINE(HCURSOR, SWELL_GetLastSetCursor,())
819 SWELL_API_DEFINE(bool, SWELL_IsCursorVisible, ())
820 SWELL_API_DEFINE(int, SWELL_ShowCursor, (BOOL bShow))
821 SWELL_API_DEFINE(BOOL, SWELL_SetCursorPos, (int X, int Y))
824 ** SWELL_GetViewPort
825 ** Gets screen information, for the screen that contains sourcerect. if wantWork is set
826 ** it excluses the menu bar etc.
828 SWELL_API_DEFINE(void, SWELL_GetViewPort,(RECT *r, const RECT *sourcerect, bool wantWork))
831 ** Clipboard API emulation
832 ** Notes: setting multiple types may not work right
835 SWELL_API_DEFINE(bool, OpenClipboard,(HWND hwndDlg))
836 SWELL_API_DEFINE(void, CloseClipboard,())
837 SWELL_API_DEFINE(HANDLE, GetClipboardData,(UINT type))
839 SWELL_API_DEFINE(void, EmptyClipboard,())
840 SWELL_API_DEFINE(void, SetClipboardData,(UINT type, HANDLE h))
841 SWELL_API_DEFINE(UINT, RegisterClipboardFormat,(const char *desc))
842 SWELL_API_DEFINE(UINT, EnumClipboardFormats,(UINT lastfmt))
844 #ifndef CF_TEXT
845 #define CF_TEXT (RegisterClipboardFormat("SWELL__CF_TEXT"))
846 #endif
849 ** GlobalAlloc*()
850 ** These are only currently used by the clipboard system,
851 ** but should work normally.
854 SWELL_API_DEFINE(HANDLE, GlobalAlloc,(int flags, int sz))
855 SWELL_API_DEFINE(void *, GlobalLock,(HANDLE h))
856 SWELL_API_DEFINE(int, GlobalSize,(HANDLE h))
857 SWELL_API_DEFINE(void, GlobalUnlock,(HANDLE h))
858 SWELL_API_DEFINE(void, GlobalFree,(HANDLE h))
861 SWELL_API_DEFINE(HANDLE,CreateThread,(void *TA, DWORD stackSize, DWORD (*ThreadProc)(LPVOID), LPVOID parm, DWORD cf, DWORD *tidOut))
862 SWELL_API_DEFINE(HANDLE,CreateEvent,(void *SA, BOOL manualReset, BOOL initialSig, const char *ignored))
863 SWELL_API_DEFINE(HANDLE,CreateEventAsSocket,(void *SA, BOOL manualReset, BOOL initialSig, const char *ignored))
866 #ifdef _beginthreadex
867 #undef _beginthreadex
868 #endif
869 #define _beginthreadex(a,b,c,d,e,f) ((UINT_PTR)CreateThread(a,b,(unsigned (*)(LPVOID))(c),d,e,(DWORD*)(f)))
871 SWELL_API_DEFINE(DWORD,GetCurrentThreadId,())
872 SWELL_API_DEFINE(DWORD,WaitForSingleObject,(HANDLE hand, DWORD msTO))
873 SWELL_API_DEFINE(DWORD,WaitForAnySocketObject,(int numObjs, HANDLE *objs, DWORD msTO)) // waits for any number of socket objects
874 SWELL_API_DEFINE(BOOL,CloseHandle,(HANDLE hand))
875 SWELL_API_DEFINE(BOOL,SetThreadPriority,(HANDLE evt, int prio))
876 SWELL_API_DEFINE(BOOL,SetEvent,(HANDLE evt))
877 SWELL_API_DEFINE(BOOL,ResetEvent,(HANDLE evt))
879 #ifdef SWELL_TARGET_OSX
880 SWELL_API_DEFINE(void,SWELL_EnsureMultithreadedCocoa,())
881 SWELL_API_DEFINE(void *, SWELL_InitAutoRelease,())
882 SWELL_API_DEFINE(void, SWELL_QuitAutoRelease,(void *p))
883 SWELL_API_DEFINE(int,SWELL_TerminateProcess,(HANDLE hand))
884 SWELL_API_DEFINE(int,SWELL_GetProcessExitCode,(HANDLE hand))
885 SWELL_API_DEFINE(HANDLE,SWELL_CreateProcessIO,(const char *exe, int nparams, const char **params, bool redirectIO))
886 SWELL_API_DEFINE(int,SWELL_ReadWriteProcessIO,(HANDLE, int w/*stdin,stdout,stderr*/, char *buf, int bufsz))
887 #endif
889 SWELL_API_DEFINE(HANDLE,SWELL_CreateProcess,(const char *exe, int nparams, const char **params))
892 SWELL_API_DEFINE(HINSTANCE,LoadLibraryGlobals,(const char *fileName, bool symbolsAsGlobals))
893 SWELL_API_DEFINE(HINSTANCE,LoadLibrary,(const char *fileName))
894 SWELL_API_DEFINE(void *,GetProcAddress,(HINSTANCE hInst, const char *procName))
895 SWELL_API_DEFINE(BOOL,FreeLibrary,(HINSTANCE hInst))
897 SWELL_API_DEFINE(void*,SWELL_GetBundle,(HINSTANCE hInst))
900 ** GDI functions.
901 ** Everything should be all hunky dory, your windows may get WM_PAINT, call
902 ** GetDC()/ReleaseDC(), etc.
904 ** Or, there are these helper functions:
909 ** SWELL_CreateMemContext()
910 ** Creates a memory context (that you can get the bits for, below)
911 ** hdc is currently ignored.
913 SWELL_API_DEFINE(HDC, SWELL_CreateMemContext,(HDC hdc, int w, int h))
916 ** SWELL_DeleteGfxContext()
917 ** Deletes a context created with SWELL_CreateMemContext() (or the internal SWELL_CreateGfxContext)
919 SWELL_API_DEFINE(void, SWELL_DeleteGfxContext,(HDC))
922 ** SWELL_GetCtxGC()
923 ** Returns the CGContextRef of a HDC
925 SWELL_API_DEFINE(void *, SWELL_GetCtxGC,(HDC ctx))
929 ** SWELL_GetCtxFrameBuffer()
930 ** Gets the framebuffer of a memory context. NULL if none available.
932 SWELL_API_DEFINE(void *, SWELL_GetCtxFrameBuffer,(HDC ctx))
937 ** Some utility functions for pushing, setting, and popping the clip region.
939 SWELL_API_DEFINE(void, SWELL_PushClipRegion,(HDC ctx))
940 SWELL_API_DEFINE(void, SWELL_SetClipRegion,(HDC ctx, const RECT *r))
941 SWELL_API_DEFINE(void, SWELL_PopClipRegion,(HDC ctx))
946 ** GDI emulation functions
947 ** todo: document
950 SWELL_API_DEFINE(HFONT, CreateFontIndirect,(LOGFONT *))
951 SWELL_API_DEFINE(HFONT, CreateFont,(int lfHeight, int lfWidth, int lfEscapement, int lfOrientation, int lfWeight, char lfItalic,
952 char lfUnderline, char lfStrikeOut, char lfCharSet, char lfOutPrecision, char lfClipPrecision,
953 char lfQuality, char lfPitchAndFamily, const char *lfFaceName))
955 SWELL_API_DEFINE(HPEN, CreatePen,(int attr, int wid, int col))
956 SWELL_API_DEFINE(HBRUSH, CreateSolidBrush,(int col))
957 SWELL_API_DEFINE(HPEN, CreatePenAlpha,(int attr, int wid, int col, float alpha))
958 SWELL_API_DEFINE(HBRUSH, CreateSolidBrushAlpha,(int col, float alpha))
959 SWELL_API_DEFINE(HGDIOBJ, SelectObject,(HDC ctx, HGDIOBJ pen))
960 SWELL_API_DEFINE(HGDIOBJ, GetStockObject,(int wh))
961 SWELL_API_DEFINE(void, DeleteObject,(HGDIOBJ))
962 #ifndef DestroyIcon
963 #define DestroyIcon(x) DeleteObject(x)
964 #endif
966 #ifdef LineTo
967 #undef LineTo
968 #endif
969 #ifdef SetPixel
970 #undef SetPixel
971 #endif
972 #ifdef FillRect
973 #undef FillRect
974 #endif
975 #ifdef DrawText
976 #undef DrawText
977 #endif
978 #ifdef Polygon
979 #undef Polygon
980 #endif
982 #define DrawText SWELL_DrawText
983 #define FillRect SWELL_FillRect
984 #define LineTo SWELL_LineTo
985 #define SetPixel SWELL_SetPixel
986 #define Polygon(a,b,c) SWELL_Polygon(a,b,c)
988 SWELL_API_DEFINE(void, SWELL_FillRect,(HDC ctx, const RECT *r, HBRUSH br))
989 SWELL_API_DEFINE(void, Rectangle,(HDC ctx, int l, int t, int r, int b))
990 SWELL_API_DEFINE(void, Ellipse,(HDC ctx, int l, int t, int r, int b))
991 SWELL_API_DEFINE(void, SWELL_Polygon,(HDC ctx, POINT *pts, int npts))
992 SWELL_API_DEFINE(void, MoveToEx,(HDC ctx, int x, int y, POINT *op))
993 SWELL_API_DEFINE(void, LineTo,(HDC ctx, int x, int y))
994 SWELL_API_DEFINE(void, SetPixel,(HDC ctx, int x, int y, int c))
995 SWELL_API_DEFINE(void, PolyBezierTo,(HDC ctx, POINT *pts, int np))
996 SWELL_API_DEFINE(int, SWELL_DrawText,(HDC ctx, const char *buf, int len, RECT *r, int align))
997 SWELL_API_DEFINE(void, SetTextColor,(HDC ctx, int col))
998 SWELL_API_DEFINE(int, GetTextColor,(HDC ctx))
999 SWELL_API_DEFINE(void, SetBkColor,(HDC ctx, int col))
1000 SWELL_API_DEFINE(void, SetBkMode,(HDC ctx, int col))
1001 SWELL_API_DEFINE(int, GetGlyphIndicesW, (HDC ctx, wchar_t *buf, int len, unsigned short *indices, int flags))
1003 SWELL_API_DEFINE(void, RoundRect,(HDC ctx, int x, int y, int x2, int y2, int xrnd, int yrnd))
1004 SWELL_API_DEFINE(void, PolyPolyline,(HDC ctx, POINT *pts, DWORD *cnts, int nseg))
1005 SWELL_API_DEFINE(BOOL, GetTextMetrics,(HDC ctx, TEXTMETRIC *tm))
1006 SWELL_API_DEFINE(int, GetTextFace,(HDC ctx, int nCount, LPTSTR lpFaceName))
1007 #ifdef SWELL_TARGET_OSX
1008 SWELL_API_DEFINE(void *, GetNSImageFromHICON,(HICON))
1009 #endif
1010 SWELL_API_DEFINE(BOOL, GetObject, (HICON icon, int bmsz, void *_bm))
1011 SWELL_API_DEFINE(HICON, CreateIconIndirect, (ICONINFO* iconinfo))
1012 SWELL_API_DEFINE(HICON, LoadNamedImage,(const char *name, bool alphaFromMask))
1013 SWELL_API_DEFINE(void, DrawImageInRect,(HDC ctx, HICON img, const RECT *r))
1014 SWELL_API_DEFINE(void, BitBlt,(HDC hdcOut, int x, int y, int w, int h, HDC hdcIn, int xin, int yin, int mode))
1015 SWELL_API_DEFINE(void, StretchBlt,(HDC hdcOut, int x, int y, int w, int h, HDC hdcIn, int xin, int yin, int srcw, int srch, int mode))
1016 #ifndef SWELL_TARGET_OSX
1017 SWELL_API_DEFINE(void, StretchBltFromMem,(HDC hdcOut, int x, int y, int w, int h, const void *bits, int srcw, int srch, int srcspan))
1018 SWELL_API_DEFINE(int, SWELL_GetScaling256, (void))
1019 #endif
1021 SWELL_API_DEFINE(void*, SWELL_ExtendedAPI, (const char *key, void *v))
1023 SWELL_API_DEFINE(int, GetSysColor,(int idx))
1024 SWELL_API_DEFINE(HBITMAP, CreateBitmap,(int width, int height, int numplanes, int bitsperpixel, unsigned char* bits))
1026 SWELL_API_DEFINE(void, SetOpaque, (HWND h, bool isopaque))
1027 SWELL_API_DEFINE(void, SetAllowNoMiddleManRendering, (HWND h, bool allow)) // defaults to allow, use this to disable
1028 #ifdef SWELL_TARGET_OSX
1029 SWELL_API_DEFINE(int, SWELL_IsRetinaDC, (HDC hdc)) // returns 1 if DC is a retina DC (2x res possible)
1030 SWELL_API_DEFINE(int, SWELL_IsRetinaHWND, (HWND h)) // returns 1 if HWND is a retina HWND
1031 SWELL_API_DEFINE(void, SWELL_SetViewGL, (HWND h, bool wantGL))
1032 SWELL_API_DEFINE(bool, SWELL_GetViewGL, (HWND h))
1033 SWELL_API_DEFINE(bool, SWELL_SetGLContextToView, (HWND h)) // sets GL context to that view, returns TRUE if successs (use NULL to clear GL context)
1034 #endif
1036 SWELL_API_DEFINE(HDC, BeginPaint,(HWND, PAINTSTRUCT *))
1037 SWELL_API_DEFINE(BOOL, EndPaint,(HWND, PAINTSTRUCT *))
1039 SWELL_API_DEFINE(HDC, GetDC,(HWND)) // use these sparingly! they kinda work but shouldnt be overused!!
1040 SWELL_API_DEFINE(HDC, GetWindowDC,(HWND))
1041 SWELL_API_DEFINE(void, ReleaseDC,(HWND, HDC))
1043 #ifdef SWELL_TARGET_OSX
1044 SWELL_API_DEFINE(void, SWELL_FlushWindow,(HWND))
1045 #endif
1047 SWELL_API_DEFINE(void, SWELL_FillDialogBackground,(HDC hdc, const RECT *r, int level))
1049 SWELL_API_DEFINE(HGDIOBJ,SWELL_CloneGDIObject,(HGDIOBJ a))
1051 SWELL_API_DEFINE(int, GetSystemMetrics, (int))
1053 SWELL_API_DEFINE(BOOL, DragQueryPoint,(HDROP,LPPOINT))
1054 SWELL_API_DEFINE(void, DragFinish,(HDROP))
1055 SWELL_API_DEFINE(UINT, DragQueryFile,(HDROP,UINT,char *,UINT))
1057 // source drag/drop - callback is source implementing "create dropped files at droppath"
1058 SWELL_API_DEFINE(void, SWELL_InitiateDragDrop, (HWND, RECT* srcrect, const char* srcfn, void (*callback)(const char* droppath)))
1059 SWELL_API_DEFINE(void,SWELL_InitiateDragDropOfFileList,(HWND, RECT *srcrect, const char **srclist, int srccount, HICON icon))
1060 SWELL_API_DEFINE(void, SWELL_FinishDragDrop, ()) // cancels any outstanding InitiateDragDrop
1064 // r=NULL to "free" handle
1065 // otherwise r is in hwndPar coordinates
1066 SWELL_API_DEFINE(void,SWELL_DrawFocusRect,(HWND hwndPar, RECT *rct, void **handle))
1069 #ifdef SWELL_TARGET_OSX
1070 SWELL_API_DEFINE(void,SWELL_SetWindowRepre,(HWND hwnd, const char *fn, bool isDirty)) // sets the represented file and edited state
1071 SWELL_API_DEFINE(void,SWELL_PostQuitMessage,(void *sender))
1072 #endif
1075 ** Functions used by swell-dlggen.h and swell-menugen.h
1076 ** No need to really dig into these unless you're working on swell or debugging..
1079 SWELL_API_DEFINE(void, SWELL_MakeSetCurParms,(float xscale, float yscale, float xtrans, float ytrans, HWND parent, bool doauto, bool dosizetofit))
1081 SWELL_API_DEFINE(HWND, SWELL_MakeButton,(int def, const char *label, int idx, int x, int y, int w, int h, int flags))
1082 SWELL_API_DEFINE(HWND, SWELL_MakeEditField,(int idx, int x, int y, int w, int h, int flags))
1083 SWELL_API_DEFINE(HWND, SWELL_MakeLabel,(int align, const char *label, int idx, int x, int y, int w, int h, int flags))
1084 SWELL_API_DEFINE(HWND, SWELL_MakeControl,(const char *cname, int idx, const char *classname, int style, int x, int y, int w, int h, int exstyle))
1085 SWELL_API_DEFINE(HWND, SWELL_MakeCombo,(int idx, int x, int y, int w, int h, int flags))
1086 SWELL_API_DEFINE(HWND, SWELL_MakeGroupBox,(const char *name, int idx, int x, int y, int w, int h, int style))
1087 SWELL_API_DEFINE(HWND, SWELL_MakeCheckBox,(const char *name, int idx, int x, int y, int w, int h, int flags))
1088 SWELL_API_DEFINE(HWND, SWELL_MakeListBox,(int idx, int x, int y, int w, int h, int styles))
1090 SWELL_API_DEFINE(void, SWELL_Menu_AddMenuItem,(HMENU hMenu, const char *name, int idx, unsigned int flags))
1091 SWELL_API_DEFINE(int, SWELL_GenerateMenuFromList,(HMENU hMenu, const void *list, int listsz)) // list is SWELL_MenuGen_Entry
1093 SWELL_API_DEFINE(void, SWELL_GenerateDialogFromList, (const void *list, int listsz))
1096 SWELL_API_DEFINE(unsigned int, _controlfp,(unsigned int flag, unsigned int mask))
1098 SWELL_API_DEFINE(void,SWELL_Internal_PostMessage_Init,())
1101 SWELL_API_DEFINE(HCURSOR,SWELL_LoadCursorFromFile,(const char *fn))
1102 SWELL_API_DEFINE(void,SWELL_SetWindowWantRaiseAmt,(HWND h, int amt))
1103 SWELL_API_DEFINE(int,SWELL_GetWindowWantRaiseAmt,(HWND))
1105 SWELL_API_DEFINE(void,SWELL_SetListViewFastClickMask,(HWND hList, int mask))
1108 SWELL_API_DEFINE(void,GetTempPath,(int sz, char *buf))
1110 #ifndef SWELL_TARGET_OSX
1111 SWELL_API_DEFINE(void,SWELL_initargs,(int *argc, char ***argv))
1112 SWELL_API_DEFINE(void,SWELL_RunMessageLoop,())
1113 SWELL_API_DEFINE(HWND,SWELL_CreateXBridgeWindow,(HWND viewpar, void **wref, RECT*))
1114 #endif
1116 SWELL_API_DEFINE(bool,SWELL_GenerateGUID,(void *g))
1118 SWELL_API_DEFINE(BOOL,EnumChildWindows,(HWND hwnd, BOOL (*cwEnumFunc)(HWND,LPARAM),LPARAM lParam))
1121 SWELL_API_DEFINE(BOOL,SWELL_IsGroupBox,(HWND))
1122 SWELL_API_DEFINE(BOOL,SWELL_IsButton,(HWND))
1123 SWELL_API_DEFINE(BOOL,SWELL_IsStaticText,(HWND))
1124 SWELL_API_DEFINE(void,SWELL_GetDesiredControlSize,(HWND hwnd, RECT *r))
1126 SWELL_API_DEFINE(int,AddFontResourceEx,(LPCTSTR str, DWORD fl, void *pdv))
1128 #ifdef SWELL_TARGET_OSX
1129 SWELL_API_DEFINE(void,SWELL_DisableAppNap,(int disable))
1130 SWELL_API_DEFINE(int,SWELL_GetOSXVersion,())
1131 #endif
1133 SWELL_API_DEFINE(void,SWELL_Register_Cursor_Resource,(const char *idx, const char *name, int hotspot_x, int hotspot_y))
1135 #ifndef SWELL_TARGET_OSX
1136 SWELL_API_DEFINE(bool, SWELL_ChooseColor, (HWND, int *, int ncustom, int *custom))
1137 SWELL_API_DEFINE(bool, SWELL_ChooseFont, (HWND, LOGFONT*))
1138 #endif
1140 SWELL_API_DEFINE(bool, IsWindowEnabled, (HWND))
1142 #endif // _WDL_SWELL_H_API_DEFINED_