swell-cocoa: support GWL_USERDATA on combo/popup boxes -- from fee287f5
[wdl/wdl-tale.git] / WDL / swell / swell-internal.h
blob05d6f87ccb4284483517a13e00aa71b92257d7b4
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 #ifndef _SWELL_INTERNAL_H_
22 #define _SWELL_INTERNAL_H_
24 #include "../ptrlist.h"
26 struct SWELL_ListView_Rec
28 char *txt;
29 int image_idx;
32 class SWELL_ListView_Row
34 public:
35 SWELL_ListView_Row() : m_param(0), m_tmp(0) { }
36 ~SWELL_ListView_Row()
38 for (int x = 0; x < m_cols.GetSize(); x ++)
40 free(m_cols.Get()[x].txt);
42 m_cols.Resize(0);
44 int get_num_cols() const { return m_cols.GetSize(); }
45 char *get_col_txt(int x) const { return x >= 0 && x < m_cols.GetSize() ? m_cols.Get()[x].txt : NULL; }
46 void add_col(const char *p) { SWELL_ListView_Rec r = { p ? strdup(p) : NULL }; m_cols.Add(r); }
47 void set_col_txt(int x, const char *p)
49 if (WDL_NORMALLY(x >= 0 && x < m_cols.GetSize()))
51 free(m_cols.Get()[x].txt);
52 m_cols.Get()[x].txt = p ? strdup(p) : NULL;
55 int get_img_idx(int x) const { return x >= 0 && x < m_cols.GetSize() ? m_cols.Get()[x].image_idx : 0; }
56 void set_img_idx(int x, int index)
58 if (WDL_NORMALLY(x >= 0 && x < m_cols.GetSize()))
59 m_cols.Get()[x].image_idx = index;
61 WDL_TypedBuf<SWELL_ListView_Rec> m_cols;
63 LPARAM m_param;
64 int m_tmp; // Cocoa uses this temporarily, generic uses it as a mask (1= selected)
67 struct HTREEITEM__;
69 #ifdef SWELL_TARGET_OSX
71 #if 0
72 // at some point we should enable this and use it in most SWELL APIs that call Cocoa code...
73 #define SWELL_BEGIN_TRY @try {
74 #define SWELL_END_TRY(x) } @catch (NSException *ex) { NSLog(@"SWELL exception in %s:%d :: %@:%@\n",__FILE__,__LINE__,[ex name], [ex reason]); x }
75 #else
76 #define SWELL_BEGIN_TRY
77 #define SWELL_END_TRY(x)
78 #endif
80 #define __SWELL_PREFIX_CLASSNAME3(a,b) a##b
81 #define __SWELL_PREFIX_CLASSNAME2(a,b) __SWELL_PREFIX_CLASSNAME3(a,b)
82 #define __SWELL_PREFIX_CLASSNAME(cname) __SWELL_PREFIX_CLASSNAME2(SWELL_APP_PREFIX,cname)
84 // this defines interfaces to internal swell classes
85 #define SWELL_hwndChild __SWELL_PREFIX_CLASSNAME(_hwnd)
86 #define SWELL_hwndCarbonHost __SWELL_PREFIX_CLASSNAME(_hwndcarbonhost)
88 #define SWELL_ModelessWindow __SWELL_PREFIX_CLASSNAME(_modelesswindow)
89 #define SWELL_ModalDialog __SWELL_PREFIX_CLASSNAME(_dialogbox)
91 #define SWELL_TextField __SWELL_PREFIX_CLASSNAME(_textfield)
92 #define SWELL_ListView __SWELL_PREFIX_CLASSNAME(_listview)
93 #define SWELL_TreeView __SWELL_PREFIX_CLASSNAME(_treeview)
94 #define SWELL_TabView __SWELL_PREFIX_CLASSNAME(_tabview)
95 #define SWELL_ProgressView __SWELL_PREFIX_CLASSNAME(_progind)
96 #define SWELL_TextView __SWELL_PREFIX_CLASSNAME(_textview)
97 #define SWELL_BoxView __SWELL_PREFIX_CLASSNAME(_box)
98 #define SWELL_Button __SWELL_PREFIX_CLASSNAME(_button)
99 #define SWELL_PopUpButton __SWELL_PREFIX_CLASSNAME(_pub)
100 #define SWELL_ComboBox __SWELL_PREFIX_CLASSNAME(_cbox)
102 #define SWELL_StatusCell __SWELL_PREFIX_CLASSNAME(_statuscell)
103 #define SWELL_ListViewCell __SWELL_PREFIX_CLASSNAME(_listviewcell)
104 #define SWELL_ODListViewCell __SWELL_PREFIX_CLASSNAME(_ODlistviewcell)
105 #define SWELL_ODButtonCell __SWELL_PREFIX_CLASSNAME(_ODbuttoncell)
106 #define SWELL_ImageButtonCell __SWELL_PREFIX_CLASSNAME(_imgbuttoncell)
108 #define SWELL_FocusRectWnd __SWELL_PREFIX_CLASSNAME(_drawfocusrectwnd)
110 #define SWELL_DataHold __SWELL_PREFIX_CLASSNAME(_sdh)
111 #define SWELL_ThreadTmp __SWELL_PREFIX_CLASSNAME(_thread)
112 #define SWELL_PopupMenuRecv __SWELL_PREFIX_CLASSNAME(_trackpopupmenurecv)
114 #define SWELL_TimerFuncTarget __SWELL_PREFIX_CLASSNAME(_tft)
115 #define SWELL_MetalNotificationHandler __SWELL_PREFIX_CLASSNAME(_mnfh)
117 #define SWELL_Menu __SWELL_PREFIX_CLASSNAME(_menu)
119 #ifdef __OBJC__
121 #ifndef MAC_OS_X_VERSION_10_7
122 typedef struct _NSDraggingSession NSDraggingSession;
123 #endif
125 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
126 typedef int NSInteger;
127 typedef unsigned int NSUInteger;
128 #endif
130 @interface SWELL_Menu : NSMenu
133 -(void)dealloc;
134 - (id)copyWithZone:(NSZone *)zone;
135 @end
137 @interface SWELL_DataHold : NSObject
139 @public
140 void *m_data;
142 -(id) initWithVal:(void *)val;
143 -(void *) getValue;
144 @end
146 @interface SWELL_TimerFuncTarget : NSObject
148 TIMERPROC m_cb;
149 HWND m_hwnd;
150 UINT_PTR m_timerid;
152 -(id) initWithId:(UINT_PTR)tid hwnd:(HWND)h callback:(TIMERPROC)cb;
153 -(void)SWELL_Timer:(id)sender;
154 @end
156 typedef struct OwnedWindowListRec
158 NSWindow *hwnd;
159 struct OwnedWindowListRec *_next;
160 } OwnedWindowListRec;
162 typedef struct WindowPropRec
164 char *name; // either <64k or a strdup'd name
165 void *data;
166 struct WindowPropRec *_next;
167 } WindowPropRec;
171 @interface SWELL_TextField : NSTextField
173 @public
174 bool m_last_dark_mode;
175 bool m_ctlcolor_set;
176 bool m_disable_menu;
177 LONG_PTR m_userdata;
179 - (id) init;
180 - (void)setNeedsDisplay:(BOOL)flag;
181 - (void)setNeedsDisplayInRect:(NSRect)rect;
182 - (void)drawRect:(NSRect)rect;
183 - (void)initColors:(int)darkmode; // -1 to not update darkmode but trigger update of colors
184 - (void)swellDisableContextMenu:(bool)dis;
185 - (NSMenu *)textView:(NSTextView *)view menu:(NSMenu *)menu forEvent:(NSEvent *)event atIndex:(NSUInteger)charIndex;
186 -(LONG_PTR)getSwellUserData;
187 -(void)setSwellUserData:(LONG_PTR)val;
188 @end
190 @interface SWELL_TabView : NSTabView
192 NSInteger m_tag;
193 id m_dest;
195 @end
197 @interface SWELL_ProgressView : NSProgressIndicator
199 NSInteger m_tag;
201 @end
203 @interface SWELL_ListViewCell : NSTextFieldCell
206 -(NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
207 - (NSRect)drawingRectForBounds:(NSRect)rect;
208 @end
210 @interface SWELL_StatusCell : SWELL_ListViewCell
212 NSImage *status;
213 bool m_always_indent;
215 -(id)initNewCell:(bool)always_indent;
216 -(void)setStatusImage:(NSImage *)img;
217 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
218 @end
220 @interface SWELL_TreeView : NSOutlineView
222 @public
223 bool m_fakerightmouse;
224 LONG style;
225 WDL_PtrList<HTREEITEM__> *m_items;
226 NSColor *m_fgColor;
227 NSMutableArray *m_selColors;
229 -(id) init;
230 -(void) dealloc;
231 -(bool) findItem:(HTREEITEM)item parOut:(HTREEITEM__ **)par idxOut:(int *)idx;
232 -(void)mouseDown:(NSEvent *)theEvent;
233 -(void)mouseDragged:(NSEvent *)theEvent;
234 -(void)mouseUp:(NSEvent *)theEvent;
235 - (void)rightMouseUp:(NSEvent *)theEvent;
236 - (void)highlightSelectionInClipRect:(NSRect)theClipRect;
238 // data source
239 -(NSInteger) outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item;
240 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item;
241 - (id)outlineView:(NSOutlineView *)outlineView
242 child:(NSInteger)index
243 ofItem:(id)item;
244 - (id)outlineView:(NSOutlineView *)outlineView
245 objectValueForTableColumn:(NSTableColumn *)tableColumn
246 byItem:(id)item;
250 - (BOOL)outlineView:(NSOutlineView *)outlineView
251 writeItems:(NSArray *)items
252 toPasteboard:(NSPasteboard *)pasteboard;
253 - (BOOL)outlineView:(NSOutlineView *)outlineView
254 acceptDrop:(id<NSDraggingInfo>)info
255 item:(id)item
256 childIndex:(NSInteger)index;
257 - (void)outlineView:(NSOutlineView *)outlineView
258 draggingSession:(NSDraggingSession *)session
259 endedAtPoint:(NSPoint)screenPoint
260 operation:(NSDragOperation)operation;
261 - (void)outlineView:(NSOutlineView *)outlineView
262 draggingSession:(NSDraggingSession *)session
263 willBeginAtPoint:(NSPoint)screenPoint
264 forItems:(NSArray *)draggedItems;
265 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView
266 validateDrop:(id<NSDraggingInfo>)info
267 proposedItem:(id)item
268 proposedChildIndex:(NSInteger)index;
270 @end
272 @interface SWELL_ListView : NSTableView
274 int m_leftmousemovecnt;
275 bool m_fakerightmouse;
276 @public
277 LONG style;
278 int ownermode_cnt;
279 int m_start_item;
280 int m_start_subitem;
281 int m_start_item_clickmode;
283 int m_lbMode;
284 WDL_PtrList<SWELL_ListView_Row> *m_items;
285 WDL_PtrList<NSTableColumn> *m_cols;
286 WDL_PtrList<HGDIOBJ__> *m_status_imagelist;
287 int m_status_imagelist_type;
288 int m_fastClickMask;
289 NSColor *m_fgColor;
290 NSMutableArray *m_selColors;
292 // these are for the new yosemite mouse handling code
293 int m_last_plainly_clicked_item, m_last_shift_clicked_item;
295 bool m_subitem_images;
297 -(LONG)getSwellStyle;
298 -(void)setSwellStyle:(LONG)st;
299 -(int)getSwellNotificationMode;
300 -(void)setSwellNotificationMode:(int)lbMode;
301 -(NSInteger)columnAtPoint:(NSPoint)pt;
302 -(int)getColumnPos:(int)idx; // get current position of column that was originally at idx
303 -(int)getColumnIdx:(int)pos; // get original index of column that is currently at position
305 -(BOOL)accessibilityPerformShowMenu;
306 @end
308 @interface SWELL_ImageButtonCell : NSButtonCell
311 - (NSRect)drawTitle:(NSAttributedString *)title withFrame:(NSRect)frame inView:(NSView *)controlView;
312 @end
314 @interface SWELL_ODButtonCell : NSButtonCell
317 @end
319 @interface SWELL_ODListViewCell : NSCell
321 SWELL_ListView *m_ownctl;
322 int m_lastidx;
324 -(void)setOwnerControl:(SWELL_ListView *)t;
325 -(void)setItemIdx:(int)idx;
326 @end
328 @interface SWELL_Button : NSButton
330 void *m_swellGDIimage;
331 LONG_PTR m_userdata;
332 int m_radioflags; // =4096 if not a checkbox/radiobox. &2=new group, &1=radio
334 -(int)swellGetRadioFlags;
335 -(void)swellSetRadioFlags:(int)f;
336 -(LONG_PTR)getSwellUserData;
337 -(void)setSwellUserData:(LONG_PTR)val;
338 -(void)setSwellGDIImage:(void *)par;
339 -(void *)getSwellGDIImage;
340 @end
342 @interface SWELL_TextView : NSTextView
344 NSInteger m_tag;
345 bool m_disable_menu;
347 -(id)init;
348 -(NSInteger) tag;
349 -(void) setTag:(NSInteger)tag;
350 - (void)swellDisableContextMenu:(bool)dis;
351 - (bool)swellWantsContextMenu;
352 @end
354 @interface SWELL_BoxView : NSBox
356 NSInteger m_tag;
357 @public
358 int m_etch_mode; // if nonzero, SS_ETCHEDHORZ etc
360 -(NSInteger) tag;
361 -(void) setTag:(NSInteger)tag;
362 -(void) drawRect:(NSRect)r;
363 -(int) swellIsEtchBox;
364 @end
366 @interface SWELL_FocusRectWnd : NSView
369 @end
371 @interface SWELL_ThreadTmp : NSObject
373 @public
374 void *a, *b;
376 -(void)bla:(id)obj;
377 @end
381 @interface SWELL_hwndChild : NSView // <NSDraggingSource>
383 @public
384 int m_enabled; // -1 if preventing focus
385 DLGPROC m_dlgproc;
386 WNDPROC m_wndproc;
387 LONG_PTR m_userdata;
388 LONG_PTR m_extradata[32];
389 NSInteger m_tag;
390 int m_isfakerightmouse;
391 char m_hashaddestroy; // 2 = WM_DESTROY has finished completely
392 HMENU m_menu;
393 BOOL m_flip;
394 bool m_supports_ddrop;
395 bool m_paintctx_used;
396 HDC m_paintctx_hdc;
397 WindowPropRec *m_props;
398 NSRect m_paintctx_rect;
399 BOOL m_isopaque;
400 char m_titlestr[1024];
401 unsigned int m_create_windowflags;
402 NSOpenGLContext *m_glctx;
403 char m_isdirty; // &1=self needs redraw, &2=children may need redraw
404 char m_allow_nomiddleman;
405 id m_lastTopLevelOwner; // save a copy of the owner, if any
406 id m_access_cacheptrs[6];
407 const char *m_classname;
409 // only used if not SWELL_NO_METAL
410 char m_use_metal; // 1=normal mode, 2=full pipeline (GetDC() etc support). -1 is for non-metal async layered mode. -2 for non-metal non-async layered
412 // metal state (if used)
413 char m_metal_dc_dirty; // used to track state during paint or getdc/releasedc. set to 1 if dirty, 2 if GetDC() but no write yet
414 char m_metal_gravity; // &1=resizing left, &2=resizing top
415 bool m_metal_retina; // last-retina-state, triggered to true by StretchBlt() with a 2:1 ratio
417 bool m_metal_in_needref_list;
418 RECT m_metal_in_needref_rect;
419 NSRect m_metal_lastframe;
421 id m_metal_texture; // id<MTLTexture> -- owned if in full pipeline mode, otherwise reference to m_metal_drawable
422 id m_metal_drawable; // id<CAMetalDrawable> -- only used in normal mode
423 id m_metal_device; // id<MTLDevice> -- set to last-used-device
424 int m_metal_devicelist_updcnt;
427 - (id)initChild:(SWELL_DialogResourceIndex *)resstate Parent:(NSView *)parent dlgProc:(DLGPROC)dlgproc Param:(LPARAM)par;
428 - (LRESULT)onSwellMessage:(UINT)msg p1:(WPARAM)wParam p2:(LPARAM)lParam;
429 -(HANDLE)swellExtendedDragOp:(id <NSDraggingInfo>)sender retGlob:(BOOL)retG;
430 - (const char *)onSwellGetText;
431 -(void)onSwellSetText:(const char *)buf;
432 -(LONG)swellGetExtendedStyle;
433 -(void)swellSetExtendedStyle:(LONG)st;
434 -(HMENU)swellGetMenu;
435 -(BOOL)swellHasBeenDestroyed;
436 -(void)swellSetMenu:(HMENU)menu;
437 -(LONG_PTR)getSwellUserData;
438 -(void)setSwellUserData:(LONG_PTR)val;
439 -(void)setOpaque:(bool)isOpaque;
440 -(LPARAM)getSwellExtraData:(int)idx;
441 -(void)setSwellExtraData:(int)idx value:(LPARAM)val;
442 -(void)setSwellWindowProc:(WNDPROC)val;
443 -(WNDPROC)getSwellWindowProc;
444 -(void)setSwellDialogProc:(DLGPROC)val;
445 -(DLGPROC)getSwellDialogProc;
447 - (NSArray*) namesOfPromisedFilesDroppedAtDestination:(NSURL*)droplocation;
449 -(void) getSwellPaintInfo:(PAINTSTRUCT *)ps;
450 - (int)swellCapChangeNotify;
451 -(unsigned int)swellCreateWindowFlags;
453 -(bool)swellCanPostMessage;
454 -(int)swellEnumProps:(PROPENUMPROCEX)proc lp:(LPARAM)lParam;
455 -(void *)swellGetProp:(const char *)name wantRemove:(BOOL)rem;
456 -(int)swellSetProp:(const char *)name value:(void *)val ;
457 -(NSOpenGLContext *)swellGetGLContext;
458 - (void) setEnabledSwellNoFocus;
459 -(const char *)getSwellClass;
461 // NSAccessibility
463 // attribute methods
464 //- (NSArray *)accessibilityAttributeNames;
465 - (id)accessibilityAttributeValue:(NSString *)attribute;
466 //- (BOOL)accessibilityIsAttributeSettable:(NSString *)attribute;
467 //- (void)accessibilitySetValue:(id)value forAttribute:(NSString *)attribute;
469 // parameterized attribute methods
470 //- (NSArray *)accessibilityParameterizedAttributeNames;
471 //- (id)accessibilityAttributeValue:(NSString *)attribute forParameter:(id)parameter;
473 // action methods
474 //- (NSArray *)accessibilityActionNames;
475 //- (NSString *)accessibilityActionDescription:(NSString *)action;
476 //- (void)accessibilityPerformAction:(NSString *)action;
478 // Return YES if the UIElement doesn't show up to the outside world - i.e. its parent should return the UIElement's children as its own - cutting the UIElement out. E.g. NSControls are ignored when they are single-celled.
479 - (BOOL)accessibilityIsIgnored;
481 // Returns the deepest descendant of the UIElement hierarchy that contains the point. You can assume the point has already been determined to lie within the receiver. Override this method to do deeper hit testing within a UIElement - e.g. a NSMatrix would test its cells. The point is bottom-left relative screen coordinates.
482 - (id)accessibilityHitTest:(NSPoint)point;
484 // Returns the UI Element that has the focus. You can assume that the search for the focus has already been narrowed down to the reciever. Override this method to do a deeper search with a UIElement - e.g. a NSMatrix would determine if one of its cells has the focus.
485 - (id)accessibilityFocusedUIElement;
487 -(void) swellOnControlDoubleClick:(id)sender;
489 #ifdef MAC_OS_X_VERSION_10_8
490 // for radio button with the OSX 10.8+ SDK, see comment in SWELL_MakeControl
491 -(void) onSwellCommand0:(id)sender;
492 -(void) onSwellCommand2:(id)sender;
493 -(void) onSwellCommand3:(id)sender;
494 -(void) onSwellCommand4:(id)sender;
495 -(void) onSwellCommand5:(id)sender;
496 -(void) onSwellCommand6:(id)sender;
497 -(void) onSwellCommand7:(id)sender;
498 #endif
500 -(BOOL) swellWantsMetal;
501 -(void) swellDrawMetal:(const RECT *)forRect;
502 @end
504 @interface SWELL_ModelessWindow : NSWindow
506 @public
507 NSSize lastFrameSize;
508 id m_owner;
509 OwnedWindowListRec *m_ownedwnds;
510 BOOL m_enabled;
511 int m_wantraiseamt;
512 bool m_wantInitialKeyWindowOnShow;
513 bool m_lastZoom;
515 - (id)initModeless:(SWELL_DialogResourceIndex *)resstate Parent:(HWND)parent dlgProc:(DLGPROC)dlgproc Param:(LPARAM)par outputHwnd:(HWND *)hwndOut forceStyles:(unsigned int)smask;
516 - (id)initModelessForChild:(HWND)child owner:(HWND)owner styleMask:(unsigned int)smask;
517 - (void)keyDown:(NSEvent *)event;
518 - (void)swellDestroyAllOwnedWindows;
519 - (void)swellRemoveOwnedWindow:(NSWindow *)wnd;
520 - (void)swellAddOwnedWindow:(NSWindow*)wnd;
521 - (void)swellSetOwner:(id)owner;
522 - (id)swellGetOwner;
523 - (void **)swellGetOwnerWindowHead;
524 -(void)swellDoDestroyStuff;
525 -(void)swellResetOwnedWindowLevels;
527 -(void)toggleFullScreen:(id)sender;
528 @end
530 @interface SWELL_ModalDialog : NSPanel
532 NSSize lastFrameSize;
533 id m_owner;
534 OwnedWindowListRec *m_ownedwnds;
536 int m_rv;
537 bool m_hasrv;
538 BOOL m_enabled;
539 bool m_lastZoom;
541 - (id)initDialogBox:(SWELL_DialogResourceIndex *)resstate Parent:(HWND)parent dlgProc:(DLGPROC)dlgproc Param:(LPARAM)par;
542 - (void)swellDestroyAllOwnedWindows;
543 - (void)swellRemoveOwnedWindow:(NSWindow *)wnd;
544 - (void)swellAddOwnedWindow:(NSWindow*)wnd;
545 - (void)swellSetOwner:(id)owner;
546 - (id)swellGetOwner;
547 - (void **)swellGetOwnerWindowHead;
548 -(void)swellDoDestroyStuff;
550 -(void)swellSetModalRetVal:(int)r;
551 -(int)swellGetModalRetVal;
552 -(bool)swellHasModalRetVal;
553 @end
555 #ifndef SWELL_NO_METAL
556 void swell_removeMetalDirty(SWELL_hwndChild *slf);
557 void swell_updateAllMetalDirty(void);
558 void swell_addMetalDirty(SWELL_hwndChild *slf, const RECT *r, bool isReleaseDC=false);
559 HDC SWELL_CreateMetalDC(SWELL_hwndChild *);
560 #endif
563 @interface SWELL_hwndCarbonHost : SWELL_hwndChild
564 #ifdef MAC_OS_X_VERSION_10_7
565 <NSWindowDelegate>
566 #endif
568 @public
569 NSWindow *m_cwnd;
571 bool m_whileresizing;
572 void* m_wndhandler; // won't compile if declared EventHandlerRef, wtf
573 void* m_ctlhandler; // not sure if these need to be separate but cant hurt
574 bool m_wantallkeys;
576 -(BOOL)swellIsCarbonHostingView;
577 -(void)swellDoRepos;
578 @end
581 @interface SWELL_PopupMenuRecv : NSObject
583 int m_act;
584 HWND cbwnd;
586 -(id) initWithWnd:(HWND)wnd;
587 -(void) onSwellCommand:(id)sender;
588 -(int) isCommand;
589 - (void)menuNeedsUpdate:(NSMenu *)menu;
591 @end
593 @interface SWELL_PopUpButton : NSPopUpButton
595 LONG m_style;
596 LONG_PTR m_userdata;
598 -(id)init;
599 -(void)setSwellStyle:(LONG)style;
600 -(LONG)getSwellStyle;
601 -(LONG_PTR)getSwellUserData;
602 -(void)setSwellUserData:(LONG_PTR)val;
603 @end
605 @interface SWELL_ComboBox : NSComboBox
607 @public
608 LONG m_style;
609 LONG_PTR m_userdata;
610 WDL_PtrList<char> *m_ids;
611 int m_ignore_selchg; // used to track the last set selection state, to avoid getting feedback notifications
612 bool m_disable_menu;
614 -(id)init;
615 -(void)dealloc;
616 -(void)setSwellStyle:(LONG)style;
617 -(LONG)getSwellStyle;
618 - (void)swellDisableContextMenu:(bool)dis;
619 - (NSMenu *)textView:(NSTextView *)view menu:(NSMenu *)menu forEvent:(NSEvent *)event atIndex:(NSUInteger)charIndex;
620 -(LONG_PTR)getSwellUserData;
621 -(void)setSwellUserData:(LONG_PTR)val;
622 @end
626 // GDI internals
628 #ifndef __AVAILABILITYMACROS__
629 #error __AVAILABILITYMACROS__ not defined, include AvailabilityMacros.h!
630 #endif
632 // 10.4 doesn't support CoreText, so allow ATSUI if targetting 10.4 SDK
633 #ifndef MAC_OS_X_VERSION_10_5
634 // 10.4 SDK
635 #define SWELL_NO_CORETEXT
636 #define SWELL_ATSUI_TEXT_SUPPORT
637 #elif !defined(__LP64__)
638 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
639 #ifndef MAC_OS_X_VERSION_10_9 // not sure when ATSUI was dropped completely, definitely gone in 10.13!
640 #define SWELL_ATSUI_TEXT_SUPPORT
641 #endif
642 #endif
643 #endif
645 #ifndef MAC_OS_X_VERSION_10_11
646 // metal requires a recent SDK
647 #define SWELL_NO_METAL
648 #endif
650 struct HGDIOBJ__
652 int type;
654 int additional_refcnt; // refcnt of 0 means one owner (if >0, additional owners)
656 // used by pen/brush
657 CGColorRef color;
658 int wid;
659 int color_int;
660 NSImage *bitmapptr;
662 NSMutableDictionary *__old_fontdict; // unused, for ABI compat
664 // if ATSUI used, meaning IsCoreTextSupported() returned false
665 ATSUStyle atsui_font_style;
667 float font_rotation;
669 bool _infreelist;
670 struct HGDIOBJ__ *_next;
672 // if using CoreText to draw text
673 void *ct_FontRef;
676 struct HDC__ {
677 CGContextRef ctx;
678 void *ownedData; // always use via SWELL_GetContextFrameBuffer() (which performs necessary alignment)
679 void *metal_ctx; // SWELL_hwndChild, only used if not SWELL_NO_METAL
680 HGDIOBJ__ *curpen;
681 HGDIOBJ__ *curbrush;
682 HGDIOBJ__ *curfont;
684 NSColor *__old_nstextcol; // provided for ABI compat, but unused
685 int cur_text_color_int; // text color as int
687 int curbkcol;
688 int curbkmode;
689 float lastpos_x,lastpos_y;
691 void *GLgfxctx; // optionally set
692 bool _infreelist;
693 struct HDC__ *_next;
695 CGColorRef curtextcol; // text color as CGColor
702 // some extras so we can call functions available only on some OSX versions without warnings, and with the correct types
703 #define SWELL_DelegateExtensions __SWELL_PREFIX_CLASSNAME(_delext)
704 #define SWELL_ViewExtensions __SWELL_PREFIX_CLASSNAME(_viewext)
705 #define SWELL_AppExtensions __SWELL_PREFIX_CLASSNAME(_appext)
706 #define SWELL_WindowExtensions __SWELL_PREFIX_CLASSNAME(_wndext)
707 #define SWELL_TableColumnExtensions __SWELL_PREFIX_CLASSNAME(_tcolext)
709 @interface SWELL_WindowExtensions : NSWindow
710 -(void)setCollectionBehavior:(NSUInteger)a;
711 @end
712 @interface SWELL_ViewExtensions : NSView
713 -(void)_recursiveDisplayRectIfNeededIgnoringOpacity:(NSRect)rect isVisibleRect:(BOOL)vr rectIsVisibleRectForView:(NSView*)v topView:(NSView *)v2;
714 @end
716 @interface SWELL_DelegateExtensions : NSObject
717 -(bool)swellPostMessage:(HWND)dest msg:(int)message wp:(WPARAM)wParam lp:(LPARAM)lParam;
718 -(void)swellPostMessageClearQ:(HWND)dest;
719 -(void)swellPostMessageTick:(id)sender;
720 @end
722 @interface SWELL_AppExtensions : NSApplication
723 -(NSUInteger)presentationOptions;
724 -(void)setPresentationOptions:(NSUInteger)o;
725 @end
726 @interface SWELL_TableColumnExtensions : NSTableColumn
727 -(BOOL)isHidden;
728 -(void)setHidden:(BOOL)h;
729 @end
734 #else
735 // compat when compiling targetting OSX but not in objectiveC mode
736 struct SWELL_DataHold;
737 #endif // !__OBJC__
739 // 10.4 sdk just uses "float"
740 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
741 #ifdef __LP64__
742 typedef double CGFloat;
743 #else
744 typedef float CGFloat;
745 #endif
747 #endif
750 #define NSPOINT_TO_INTS(pt) (int)floor((pt).x+0.5), (int)floor((pt).y+0.5)
752 #ifdef __OBJC__
753 static WDL_STATICFUNC_UNUSED void NSPOINT_TO_POINT(POINT *p, const NSPoint &pt)
755 p->x = (int)floor(pt.x+0.5);
756 p->y = (int)floor((pt).y+0.5);
758 static WDL_STATICFUNC_UNUSED void NSRECT_TO_RECT(RECT *r, const NSRect &tr)
760 r->left=(int)floor(tr.origin.x+0.5);
761 r->right=(int)floor(tr.origin.x+tr.size.width+0.5);
762 r->top=(int)floor(tr.origin.y+0.5);
763 r->bottom=(int)floor(tr.origin.y+tr.size.height+0.5);
765 #endif
768 #ifdef SWELL_IMPLEMENT_GETOSXVERSION
770 SWELL_IMPLEMENT_GETOSXVERSION int SWELL_GetOSXVersion()
772 static SInt32 v;
773 if (!v)
775 if (NSAppKitVersionNumber >= 1266.0)
777 if (NSAppKitVersionNumber >= 2299.0)
778 v = 0x1300;
779 else if (NSAppKitVersionNumber >= 2100.0)
780 v = 0x1200;
781 else if (NSAppKitVersionNumber >= 2022.0)
782 v = 0x1100;
783 else if (NSAppKitVersionNumber >= 1894.0)
784 v = 0x10e0;
785 else if (NSAppKitVersionNumber >= 1639.10)
786 v = 0x10d0;
787 else if (NSAppKitVersionNumber >= 1560)
788 v = 0x10c0;
789 else if (NSAppKitVersionNumber >= 1404.0)
790 v = 0x10b0;
791 else
792 v = 0x10a0; // 10.10+ Gestalt(gsv) return 0x109x, so we bump this to 0x10a0
794 else
796 SInt32 a = 0x1040;
797 Gestalt(gestaltSystemVersion,&a);
798 v=a;
801 return v;
804 #endif
807 #elif defined(SWELL_TARGET_GDK)
810 #ifdef SWELL_SUPPORT_GTK
811 #include <gtk/gtk.h>
812 #endif
814 #include <gdk/gdk.h>
815 #include <gdk/gdkkeysyms.h>
816 #include <gdk/gdkx.h>
819 #else
820 // generic
822 #endif // end generic
824 struct HTREEITEM__
826 HTREEITEM__();
827 ~HTREEITEM__();
828 bool FindItem(HTREEITEM it, HTREEITEM__ **parOut, int *idxOut);
830 #ifdef SWELL_TARGET_OSX
831 SWELL_DataHold *m_dh;
832 #else
833 int m_state; // TVIS_EXPANDED, for ex
834 #endif
836 bool m_haschildren;
837 char *m_value;
838 WDL_PtrList<HTREEITEM__> m_children; // only used in tree mode
839 LPARAM m_param;
843 #ifndef SWELL_TARGET_OSX
845 #include "../wdlstring.h"
847 #ifdef SWELL_LICE_GDI
848 #include "../lice/lice.h"
849 #endif
850 #include "../assocarray.h"
852 LRESULT SwellDialogDefaultWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
855 #ifdef SWELL_TARGET_GDK
856 typedef GdkWindow *SWELL_OSWINDOW;
857 #else
858 typedef void *SWELL_OSWINDOW; // maps to the HWND__ itself on visible, non-GDK, top level windows
859 #endif
861 struct HWND__
863 HWND__(HWND par, int wID=0, const RECT *wndr=NULL, const char *label=NULL, bool visible=false, WNDPROC wndproc=NULL, DLGPROC dlgproc=NULL, HWND ownerWindow=NULL);
864 ~HWND__(); // DO NOT USE!!! We would make this private but it breaks PtrList using it on gcc.
866 // using this API prevents the HWND from being valid -- it'll still get its resources destroyed via DestroyWindow() though.
867 // DestroyWindow() does cleanup, then the final Release().
868 void Retain() { m_refcnt++; }
869 void Release() { if (!--m_refcnt) delete this; }
871 const char *m_classname;
873 SWELL_OSWINDOW m_oswindow;
875 WDL_FastString m_title;
877 HWND__ *m_children, *m_parent, *m_next, *m_prev;
878 HWND__ *m_owner, *m_owned_list, *m_owned_next, *m_owned_prev;
879 HWND__ *m_focused_child; // only valid if hwnd itself is in focus chain, and must be validated before accessed
880 RECT m_position;
881 UINT m_id;
882 int m_style, m_exstyle;
883 INT_PTR m_userdata;
884 WNDPROC m_wndproc;
885 DLGPROC m_dlgproc;
886 INT_PTR m_extra[64];
887 INT_PTR m_private_data; // used by internal controls
889 bool m_visible;
890 char m_hashaddestroy; // 1 in destroy, 2 full destroy
891 bool m_enabled;
892 bool m_wantfocus;
894 bool m_israised;
895 bool m_has_had_position;
896 bool m_is_maximized; // only valid if m_oswindow is set
897 int m_oswindow_fullscreen; // may contain preserved style flags
899 int m_refcnt;
900 int m_oswindow_private; // private state for generic-gtk or whatever
902 HMENU m_menu;
903 HFONT m_font;
905 WDL_StringKeyedArray<void *> m_props;
907 #ifdef SWELL_LICE_GDI
908 void *m_paintctx; // temporarily set for calls to WM_PAINT
910 bool m_child_invalidated; // if a child is invalidated
911 bool m_invalidated; // set to true on direct invalidate. todo RECT instead?
913 LICE_IBitmap *m_backingstore; // if NULL, unused (probably only should use on top level windows, but support caching?)
914 #endif
917 struct HMENU__
919 HMENU__() { m_refcnt=1; sel_vis = -1; }
921 void Retain() { m_refcnt++; }
922 void Release() { if (!--m_refcnt) delete this; }
924 WDL_PtrList<MENUITEMINFO> items;
925 int sel_vis; // for mouse/keyboard nav
926 int m_refcnt;
928 HMENU__ *Duplicate();
929 static void freeMenuItem(void *p);
931 private:
932 ~HMENU__() { items.Empty(true,freeMenuItem); }
936 struct HGDIOBJ__
938 int type;
939 int additional_refcnt; // refcnt of 0 means one owner (if >0, additional owners)
941 int color;
942 int wid;
944 float alpha;
946 struct HGDIOBJ__ *_next;
947 bool _infreelist;
948 void *typedata; // font: FT_Face, bitmap: LICE_IBitmap
952 struct HDC__ {
953 #ifdef SWELL_LICE_GDI
954 LICE_IBitmap *surface; // owned by context. can be (and usually is, if clipping is desired) LICE_SubBitmap
955 POINT surface_offs; // offset drawing into surface by this amount
957 RECT dirty_rect; // in surface coordinates, used for GetWindowDC()/GetDC()/etc
958 bool dirty_rect_valid;
959 #else
960 void *ownedData; // for mem contexts, support a null rendering
961 #endif
963 HGDIOBJ__ *curpen;
964 HGDIOBJ__ *curbrush;
965 HGDIOBJ__ *curfont;
967 int cur_text_color_int; // text color as int
969 int curbkcol;
970 int curbkmode;
971 float lastpos_x,lastpos_y;
973 struct HDC__ *_next;
974 bool _infreelist;
977 HWND DialogBoxIsActive(void);
978 bool DestroyPopupMenus(void);
979 bool PopupMenuIsActive(void);
980 HWND ChildWindowFromPoint(HWND h, POINT p);
981 HWND GetFocusIncludeMenus();
983 void SWELL_RunEvents();
985 bool swell_isOSwindowmenu(SWELL_OSWINDOW osw);
987 void swell_on_toplevel_raise(SWELL_OSWINDOW wnd); // called by swell-generic-gdk when a window is focused
989 HWND swell_oswindow_to_hwnd(SWELL_OSWINDOW w);
990 void swell_oswindow_focus(HWND hwnd);
991 void swell_oswindow_update_style(HWND hwnd, LONG oldstyle);
992 void swell_oswindow_update_enable(HWND hwnd);
993 void swell_oswindow_update_text(HWND hwnd);
994 void swell_oswindow_begin_resize(SWELL_OSWINDOW wnd);
995 void swell_oswindow_resize(SWELL_OSWINDOW wnd, int reposflag, RECT f);
996 void swell_oswindow_postresize(HWND hwnd, RECT f);
997 void swell_oswindow_invalidate(HWND hwnd, const RECT *r);
998 void swell_oswindow_destroy(HWND hwnd);
999 void swell_oswindow_manage(HWND hwnd, bool wantfocus);
1000 void swell_oswindow_maximize(HWND, bool wantmax); // false=restore
1001 void swell_oswindow_updatetoscreen(HWND hwnd, RECT *rect);
1002 HWND swell_window_wants_all_input(); // window with an active drag of menubar will have this set, to route all mouse events to nonclient area of window
1003 int swell_delegate_menu_message(HWND src, LPARAM lParam, int msg, bool screencoords); // menubar/menus delegate to submenus during drag.
1005 void swell_dlg_destroyspare();
1007 extern bool swell_is_likely_capslock; // only used when processing dit events for a-zA-Z
1008 extern const char *g_swell_appname;
1009 extern SWELL_OSWINDOW SWELL_focused_oswindow; // top level window which has focus (might not map to a HWND__!)
1010 extern HWND swell_captured_window;
1011 extern HWND SWELL_topwindows; // front of list = most recently active
1013 int swell_is_app_inactive(); // returns >0 if definitely inactive, -1 if maybe
1015 #ifdef _DEBUG
1016 void VALIDATE_HWND_LIST(HWND list, HWND par);
1017 #else
1018 #define VALIDATE_HWND_LIST(list, par) do { } while (0)
1019 #endif
1022 #endif // !OSX
1024 HDC SWELL_CreateGfxContext(void *);
1026 // GDP internals
1027 #define TYPE_PEN 1
1028 #define TYPE_BRUSH 2
1029 #define TYPE_FONT 3
1030 #define TYPE_BITMAP 4
1032 typedef struct
1034 void *instptr;
1035 #ifdef __APPLE__
1036 void *bundleinstptr;
1037 #endif
1038 int refcnt;
1040 #ifndef SWELL_EXTRA_MINIMAL
1041 int (*SWELL_dllMain)(HINSTANCE, DWORD,LPVOID); //last parm=SWELLAPI_GetFunc
1042 BOOL (*dllMain)(HINSTANCE, DWORD, LPVOID);
1043 #endif
1044 void *lastSymbolRequested;
1045 } SWELL_HINSTANCE;
1048 enum
1050 INTERNAL_OBJECT_START= 0x1000001,
1051 INTERNAL_OBJECT_THREAD,
1052 INTERNAL_OBJECT_EVENT,
1053 INTERNAL_OBJECT_FILE,
1054 INTERNAL_OBJECT_EXTERNALSOCKET, // socket not owned by us
1055 INTERNAL_OBJECT_SOCKETEVENT,
1056 INTERNAL_OBJECT_NSTASK,
1057 INTERNAL_OBJECT_PID,
1058 INTERNAL_OBJECT_END
1061 typedef struct
1063 int type; // INTERNAL_OBJECT_*
1064 int count; // reference count
1065 } SWELL_InternalObjectHeader;
1067 typedef struct
1069 SWELL_InternalObjectHeader hdr;
1070 DWORD (*threadProc)(LPVOID);
1071 void *threadParm;
1072 pthread_t pt;
1073 DWORD retv;
1074 bool done;
1075 } SWELL_InternalObjectHeader_Thread;
1077 typedef struct
1079 SWELL_InternalObjectHeader hdr;
1081 pthread_mutex_t mutex;
1082 pthread_cond_t cond;
1084 bool isSignal;
1085 bool isManualReset;
1087 } SWELL_InternalObjectHeader_Event;
1090 // used for both INTERNAL_OBJECT_EXTERNALSOCKET and INTERNAL_OBJECT_SOCKETEVENT.
1091 // if EXTERNALSOCKET, socket[1] ignored and autoReset ignored.
1092 typedef struct
1094 SWELL_InternalObjectHeader hdr;
1095 int socket[2];
1096 bool autoReset;
1097 } SWELL_InternalObjectHeader_SocketEvent;
1099 typedef struct
1101 SWELL_InternalObjectHeader hdr;
1103 FILE *fp;
1104 } SWELL_InternalObjectHeader_File;
1106 typedef struct
1108 SWELL_InternalObjectHeader hdr;
1109 void *task;
1110 } SWELL_InternalObjectHeader_NSTask;
1112 typedef struct
1114 SWELL_InternalObjectHeader hdr;
1115 int pid;
1116 int done, result;
1117 } SWELL_InternalObjectHeader_PID;
1119 bool IsRightClickEmulateEnabled();
1121 #ifdef SWELL_INTERNAL_HTREEITEM_IMPL
1123 HTREEITEM__::HTREEITEM__()
1125 m_param=0;
1126 m_value=0;
1127 m_haschildren=false;
1128 #ifdef SWELL_TARGET_OSX
1129 m_dh = [[SWELL_DataHold alloc] initWithVal:this];
1130 #else
1131 m_state=0;
1132 #endif
1134 HTREEITEM__::~HTREEITEM__()
1136 free(m_value);
1137 m_children.Empty(true);
1138 #ifdef SWELL_TARGET_OSX
1139 if (m_dh)
1141 m_dh->m_data = NULL;
1142 [m_dh release];
1144 #endif
1148 bool HTREEITEM__::FindItem(HTREEITEM it, HTREEITEM__ **parOut, int *idxOut)
1150 int a=m_children.Find((HTREEITEM__*)it);
1151 if (a>=0)
1153 if (parOut) *parOut=this;
1154 if (idxOut) *idxOut=a;
1155 return true;
1157 int x;
1158 const int n=m_children.GetSize();
1159 for (x = 0; x < n; x ++)
1161 if (m_children.Get(x)->FindItem(it,parOut,idxOut)) return true;
1163 return false;
1166 #endif
1168 #ifdef SWELL_INTERNAL_MERGESORT_IMPL
1170 static int __listview_sortfunc(void *p1, void *p2, int (*compar)(LPARAM val1, LPARAM val2, LPARAM userval), LPARAM userval)
1172 SWELL_ListView_Row *a = *(SWELL_ListView_Row **)p1;
1173 SWELL_ListView_Row *b = *(SWELL_ListView_Row **)p2;
1174 return compar(a->m_param,b->m_param,userval);
1178 static void __listview_mergesort_internal(void *base, size_t nmemb, size_t size,
1179 int (*compar)(LPARAM val1, LPARAM val2, LPARAM userval),
1180 LPARAM parm,
1181 char *tmpspace)
1183 char *b1,*b2;
1184 size_t n1, n2;
1186 if (nmemb < 2) return;
1188 n1 = nmemb / 2;
1189 b1 = (char *) base;
1190 n2 = nmemb - n1;
1191 b2 = b1 + (n1 * size);
1193 if (nmemb>2)
1195 __listview_mergesort_internal(b1, n1, size, compar, parm, tmpspace);
1196 __listview_mergesort_internal(b2, n2, size, compar, parm, tmpspace);
1199 char *p = tmpspace;
1203 if (__listview_sortfunc(b1, b2, compar,parm) > 0)
1205 memcpy(p, b2, size);
1206 b2 += size;
1207 n2--;
1209 else
1211 memcpy(p, b1, size);
1212 b1 += size;
1213 n1--;
1215 p += size;
1217 while (n1 > 0 && n2 > 0);
1219 if (n1 > 0) memcpy(p, b1, n1 * size);
1220 memcpy(base, tmpspace, (nmemb - n2) * size);
1224 #endif
1226 #ifndef SWELL_TARGET_OSX
1228 #define SWELL_GENERIC_THEMESIZEDEFS(f,fd) \
1229 f(default_font_size, 12) \
1230 f(menubar_height, 17) \
1231 f(menubar_font_size, 13) \
1232 f(menubar_spacing_width, 8) \
1233 f(menubar_margin_width, 6) \
1234 f(scrollbar_width, 14) \
1235 f(smscrollbar_width, 16) \
1236 f(scrollbar_min_thumb_height, 4) \
1237 f(combo_height, 20) \
1240 #define SWELL_GENERIC_THEMEDEFS(f,fd) \
1241 SWELL_GENERIC_THEMESIZEDEFS(f,fd) \
1242 f(_3dface,RGB(192,192,192)) \
1243 f(_3dshadow,RGB(96,96,96)) \
1244 f(_3dhilight,RGB(224,224,224)) \
1245 f(_3ddkshadow,RGB(48,48,48)) \
1246 fd(button_bg,RGB(192,192,192),_3dface) \
1247 f(button_text,RGB(0,0,0)) \
1248 f(button_text_disabled, RGB(128,128,128)) \
1249 fd(button_shadow, RGB(96,96,96), _3dshadow) \
1250 fd(button_hilight, RGB(224,224,224), _3dhilight) \
1251 f(checkbox_text,RGB(0,0,0)) \
1252 f(checkbox_text_disabled, RGB(128,128,128)) \
1253 f(checkbox_fg, RGB(0,0,0)) \
1254 f(checkbox_inter, RGB(192,192,192)) \
1255 f(checkbox_bg, RGB(255,255,255)) \
1256 f(scrollbar,RGB(32,32,32)) \
1257 f(scrollbar_fg, RGB(160,160,160)) \
1258 f(scrollbar_bg, RGB(224,224,224)) \
1259 f(edit_cursor,RGB(0,128,255)) \
1260 f(edit_bg,RGB(255,255,255)) \
1261 f(edit_bg_disabled,RGB(224,224,224)) \
1262 f(edit_text,RGB(0,0,0)) \
1263 f(edit_text_disabled, RGB(128,128,128)) \
1264 f(edit_bg_sel,RGB(128,192,255)) \
1265 f(edit_text_sel,RGB(255,255,255)) \
1266 fd(edit_hilight, RGB(224,224,224), _3dhilight) \
1267 fd(edit_shadow, RGB(96,96,96), _3dshadow) \
1268 f(info_bk,RGB(255,240,200)) \
1269 f(info_text,RGB(0,0,0)) \
1270 fd(menu_bg, RGB(192,192,192), _3dface) \
1271 fd(menu_shadow, RGB(96,96,96), _3dshadow) \
1272 fd(menu_hilight, RGB(224,224,224), _3dhilight) \
1273 fd(menu_text, RGB(0,0,0), button_text) \
1274 fd(menu_text_disabled, RGB(224,224,224), _3dhilight) \
1275 fd(menu_bg_sel, RGB(0,0,0), menu_text) \
1276 fd(menu_text_sel, RGB(224,224,224), menu_bg) \
1277 f(menu_scroll, RGB(64,64,64)) \
1278 fd(menu_scroll_arrow, RGB(96,96,96), _3dshadow) \
1279 fd(menu_submenu_arrow, RGB(96,96,96), menu_text) \
1280 fd(menu_submenu_arrow_sel, RGB(96,96,96), menu_bg) \
1281 fd(menubar_bg, RGB(192,192,192), menu_bg) \
1282 fd(menubar_bg_inactive, RGB(192,192,192), menubar_bg) \
1283 fd(menubar_text, RGB(0,0,0), menu_text) \
1284 fd(menubar_text_inactive, RGB(0,0,0), menubar_text) \
1285 fd(menubar_text_disabled, RGB(224,224,224), menu_text_disabled) \
1286 fd(menubar_bg_sel, RGB(0,0,0), menu_bg_sel) \
1287 fd(menubar_text_sel, RGB(224,224,224), menu_text_sel) \
1288 f(trackbar_track, RGB(224,224,224)) \
1289 f(trackbar_mark, RGB(96,96,96)) \
1290 f(trackbar_knob, RGB(48,48,48)) \
1291 f(progress,RGB(0,128,255)) \
1292 fd(label_text, RGB(0,0,0), button_text) \
1293 fd(label_text_disabled, RGB(128,128,128), button_text_disabled) \
1294 fd(combo_text, RGB(0,0,0), button_text) \
1295 fd(combo_text_disabled, RGB(128,128,128), button_text_disabled) \
1296 fd(combo_bg, RGB(192,192,192), _3dface) \
1297 f(combo_bg2, RGB(255,255,255)) \
1298 fd(combo_shadow, RGB(96,96,96), _3dshadow) \
1299 fd(combo_hilight, RGB(224,224,224), _3dhilight) \
1300 fd(combo_arrow, RGB(96,96,96), _3dshadow) \
1301 fd(combo_arrow_press, RGB(224,224,224), _3dhilight) \
1302 f(listview_bg, RGB(255,255,255)) \
1303 f(listview_bg_sel, RGB(128,128, 255)) \
1304 f(listview_text, RGB(0,0,0)) \
1305 fd(listview_text_sel, RGB(255,255,255), listview_text) \
1306 fd(listview_bg_sel_inactive, RGB(200,200,200), listview_bg_sel) \
1307 fd(listview_text_sel_inactive, RGB(0,0,0), listview_text_sel) \
1308 fd(listview_grid, RGB(224,224,224), _3dhilight) \
1309 f(listview_hdr_arrow,RGB(96,96,96)) \
1310 fd(listview_shadow, RGB(96,96,96), _3dshadow) \
1311 fd(listview_hilight, RGB(224,224,224), _3dhilight) \
1312 fd(listview_hdr_shadow, RGB(96,96,96), _3dshadow) \
1313 fd(listview_hdr_hilight, RGB(224,224,224), _3dhilight) \
1314 fd(listview_hdr_bg, RGB(192,192,192), _3dface) \
1315 fd(listview_hdr_text, RGB(0,0,0), button_text) \
1316 f(treeview_text,RGB( 0,0,0)) \
1317 f(treeview_bg, RGB(255,255,255)) \
1318 f(treeview_bg_sel, RGB(128,128,255)) \
1319 f(treeview_text_sel, RGB(255,255,255)) \
1320 fd(treeview_bg_sel_inactive, RGB(200,200,200), treeview_bg_sel) \
1321 fd(treeview_text_sel_inactive, RGB(0,0,0), treeview_text_sel) \
1322 f(treeview_arrow, RGB(96,96,96)) \
1323 fd(treeview_shadow, RGB(96,96,96), _3dshadow) \
1324 fd(treeview_hilight, RGB(224,224,224), _3dhilight) \
1325 fd(tab_shadow, RGB(96,96,96), _3dshadow) \
1326 fd(tab_hilight, RGB(224,224,224), _3dhilight) \
1327 fd(tab_text, RGB(0,0,0), button_text) \
1328 f(focusrect,RGB(255,0,0)) \
1329 f(group_text,RGB(0,0,0)) \
1330 fd(group_shadow, RGB(96,96,96), _3dshadow) \
1331 fd(group_hilight, RGB(224,224,224), _3dhilight) \
1332 f(focus_hilight, RGB(140,190,233)) \
1336 struct swell_colortheme {
1337 #define __def_theme_ent(x,c) int x;
1338 #define __def_theme_ent_fb(x,c,fb) int x;
1339 SWELL_GENERIC_THEMEDEFS(__def_theme_ent,__def_theme_ent_fb)
1340 #undef __def_theme_ent
1341 #undef __def_theme_ent_fb
1344 #define SWELL_UI_SCALE(x) (((x)*g_swell_ui_scale)/256)
1345 void swell_scaling_init(bool no_auto_hidpi);
1346 extern int g_swell_ui_scale;
1347 extern swell_colortheme g_swell_ctheme;
1348 extern const char *g_swell_deffont_face;
1349 HFONT SWELL_GetDefaultFont(void);
1351 #endif
1354 static WDL_STATICFUNC_UNUSED int ext_valid_for_extlist(const char *thisext, const char *extlist)
1356 if (!thisext || *thisext != '.' || !extlist) return -1;
1357 int txlen = (int)strlen(thisext), witem = 0;
1358 while (*extlist)
1360 while (*extlist) extlist++; // description
1361 extlist++;
1363 while (*extlist)
1365 while (*extlist == ' ' || *extlist == ';') extlist++;
1366 if (*extlist == '*')
1368 if (!strnicmp(extlist+1,thisext,txlen) &&
1369 (extlist[1+txlen] == ';' ||extlist[1+txlen] == 0))
1370 return witem;
1372 while (*extlist && *extlist != ';') extlist++;
1373 if (*extlist) extlist++;
1376 while (*extlist) extlist++;
1377 extlist++;
1378 witem++;
1380 return -1;
1383 #endif