Merge branch 'master' of http://www-dev.cockos.com/wdl/WDL into next
[wdl/wdl-ol.git] / WDL / swell / swell-internal.h
blob43120799c2c3033dcaf445edd51141a59e49709c
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 class SWELL_ListView_Row
28 public:
29 SWELL_ListView_Row() : m_param(0), m_imageidx(0), m_tmp(0) { }
30 ~SWELL_ListView_Row() { m_vals.Empty(true,free); }
31 WDL_PtrList<char> m_vals;
33 LPARAM m_param;
34 int m_imageidx;
35 int m_tmp; // Cocoa uses this temporarily, generic uses it as a mask (1= selected)
38 struct HTREEITEM__;
40 #ifdef SWELL_TARGET_OSX
42 #if 0
43 // at some point we should enable this and use it in most SWELL APIs that call Cocoa code...
44 #define SWELL_BEGIN_TRY @try {
45 #define SWELL_END_TRY(x) } @catch (NSException *ex) { NSLog(@"SWELL exception in %s:%d :: %@:%@\n",__FILE__,__LINE__,[ex name], [ex reason]); x }
46 #else
47 #define SWELL_BEGIN_TRY
48 #define SWELL_END_TRY(x)
49 #endif
51 #define __SWELL_PREFIX_CLASSNAME3(a,b) a##b
52 #define __SWELL_PREFIX_CLASSNAME2(a,b) __SWELL_PREFIX_CLASSNAME3(a,b)
53 #define __SWELL_PREFIX_CLASSNAME(cname) __SWELL_PREFIX_CLASSNAME2(SWELL_APP_PREFIX,cname)
55 // this defines interfaces to internal swell classes
56 #define SWELL_hwndChild __SWELL_PREFIX_CLASSNAME(_hwnd)
57 #define SWELL_hwndCarbonHost __SWELL_PREFIX_CLASSNAME(_hwndcarbonhost)
59 #define SWELL_ModelessWindow __SWELL_PREFIX_CLASSNAME(_modelesswindow)
60 #define SWELL_ModalDialog __SWELL_PREFIX_CLASSNAME(_dialogbox)
62 #define SWELL_TextField __SWELL_PREFIX_CLASSNAME(_textfield)
63 #define SWELL_ListView __SWELL_PREFIX_CLASSNAME(_listview)
64 #define SWELL_TreeView __SWELL_PREFIX_CLASSNAME(_treeview)
65 #define SWELL_TabView __SWELL_PREFIX_CLASSNAME(_tabview)
66 #define SWELL_ProgressView __SWELL_PREFIX_CLASSNAME(_progind)
67 #define SWELL_TextView __SWELL_PREFIX_CLASSNAME(_textview)
68 #define SWELL_BoxView __SWELL_PREFIX_CLASSNAME(_box)
69 #define SWELL_Button __SWELL_PREFIX_CLASSNAME(_button)
70 #define SWELL_PopUpButton __SWELL_PREFIX_CLASSNAME(_pub)
71 #define SWELL_ComboBox __SWELL_PREFIX_CLASSNAME(_cbox)
73 #define SWELL_StatusCell __SWELL_PREFIX_CLASSNAME(_statuscell)
74 #define SWELL_ListViewCell __SWELL_PREFIX_CLASSNAME(_listviewcell)
75 #define SWELL_ODListViewCell __SWELL_PREFIX_CLASSNAME(_ODlistviewcell)
76 #define SWELL_ODButtonCell __SWELL_PREFIX_CLASSNAME(_ODbuttoncell)
77 #define SWELL_ImageButtonCell __SWELL_PREFIX_CLASSNAME(_imgbuttoncell)
79 #define SWELL_FocusRectWnd __SWELL_PREFIX_CLASSNAME(_drawfocusrectwnd)
81 #define SWELL_DataHold __SWELL_PREFIX_CLASSNAME(_sdh)
82 #define SWELL_ThreadTmp __SWELL_PREFIX_CLASSNAME(_thread)
83 #define SWELL_PopupMenuRecv __SWELL_PREFIX_CLASSNAME(_trackpopupmenurecv)
85 #define SWELL_TimerFuncTarget __SWELL_PREFIX_CLASSNAME(_tft)
88 #define SWELL_Menu __SWELL_PREFIX_CLASSNAME(_menu)
90 #ifdef __OBJC__
93 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
94 typedef int NSInteger;
95 typedef unsigned int NSUInteger;
96 #endif
98 @interface SWELL_Menu : NSMenu
101 -(void)dealloc;
102 - (id)copyWithZone:(NSZone *)zone;
103 @end
105 @interface SWELL_DataHold : NSObject
107 void *m_data;
109 -(id) initWithVal:(void *)val;
110 -(void *) getValue;
111 @end
113 @interface SWELL_TimerFuncTarget : NSObject
115 TIMERPROC m_cb;
116 HWND m_hwnd;
117 UINT_PTR m_timerid;
119 -(id) initWithId:(UINT_PTR)tid hwnd:(HWND)h callback:(TIMERPROC)cb;
120 -(void)SWELL_Timer:(id)sender;
121 @end
123 typedef struct OwnedWindowListRec
125 NSWindow *hwnd;
126 struct OwnedWindowListRec *_next;
127 } OwnedWindowListRec;
129 typedef struct WindowPropRec
131 char *name; // either <64k or a strdup'd name
132 void *data;
133 struct WindowPropRec *_next;
134 } WindowPropRec;
138 @interface SWELL_TextField : NSTextField
139 - (void)setNeedsDisplay:(BOOL)flag;
140 - (void)setNeedsDisplayInRect:(NSRect)rect;
141 @end
143 @interface SWELL_TabView : NSTabView
145 NSInteger m_tag;
146 id m_dest;
148 @end
150 @interface SWELL_ProgressView : NSProgressIndicator
152 NSInteger m_tag;
154 @end
156 @interface SWELL_ListViewCell : NSTextFieldCell
159 @end
161 @interface SWELL_StatusCell : NSTextFieldCell
163 NSImage *status;
165 @end
167 @interface SWELL_TreeView : NSOutlineView
169 @public
170 bool m_fakerightmouse;
171 LONG style;
172 WDL_PtrList<HTREEITEM__> *m_items;
173 NSColor *m_fgColor;
174 NSMutableArray *m_selColors;
176 @end
178 @interface SWELL_ListView : NSTableView
180 int m_leftmousemovecnt;
181 bool m_fakerightmouse;
182 @public
183 LONG style;
184 int ownermode_cnt;
185 int m_start_item;
186 int m_start_subitem;
187 int m_start_item_clickmode;
189 int m_lbMode;
190 WDL_PtrList<SWELL_ListView_Row> *m_items;
191 WDL_PtrList<NSTableColumn> *m_cols;
192 WDL_PtrList<HGDIOBJ__> *m_status_imagelist;
193 int m_status_imagelist_type;
194 int m_fastClickMask;
195 NSColor *m_fgColor;
196 NSMutableArray *m_selColors;
198 // these are for the new yosemite mouse handling code
199 int m_last_plainly_clicked_item, m_last_shift_clicked_item;
202 -(LONG)getSwellStyle;
203 -(void)setSwellStyle:(LONG)st;
204 -(int)getSwellNotificationMode;
205 -(void)setSwellNotificationMode:(int)lbMode;
206 -(NSInteger)columnAtPoint:(NSPoint)pt;
207 -(int)getColumnPos:(int)idx; // get current position of column that was originally at idx
208 -(int)getColumnIdx:(int)pos; // get original index of column that is currently at position
209 @end
211 @interface SWELL_ImageButtonCell : NSButtonCell
214 - (NSRect)drawTitle:(NSAttributedString *)title withFrame:(NSRect)frame inView:(NSView *)controlView;
215 @end
217 @interface SWELL_ODButtonCell : NSButtonCell
220 @end
222 @interface SWELL_ODListViewCell : NSCell
224 SWELL_ListView *m_ownctl;
225 int m_lastidx;
227 -(void)setOwnerControl:(SWELL_ListView *)t;
228 -(void)setItemIdx:(int)idx;
229 @end
231 @interface SWELL_Button : NSButton
233 void *m_swellGDIimage;
234 LONG_PTR m_userdata;
235 int m_radioflags;
237 -(int)swellGetRadioFlags;
238 -(void)swellSetRadioFlags:(int)f;
239 -(LONG_PTR)getSwellUserData;
240 -(void)setSwellUserData:(LONG_PTR)val;
241 -(void)setSwellGDIImage:(void *)par;
242 -(void *)getSwellGDIImage;
243 @end
245 @interface SWELL_TextView : NSTextView
247 NSInteger m_tag;
249 -(NSInteger) tag;
250 -(void) setTag:(NSInteger)tag;
251 @end
253 @interface SWELL_BoxView : NSBox
255 NSInteger m_tag;
257 -(NSInteger) tag;
258 -(void) setTag:(NSInteger)tag;
259 @end
261 @interface SWELL_FocusRectWnd : NSView
264 @end
266 @interface SWELL_ThreadTmp : NSObject
268 @public
269 void *a, *b;
271 -(void)bla:(id)obj;
272 @end
276 @interface SWELL_hwndChild : NSView // <NSDraggingSource>
278 @public
279 int m_enabled; // -1 if preventing focus
280 DLGPROC m_dlgproc;
281 WNDPROC m_wndproc;
282 LONG_PTR m_userdata;
283 LONG_PTR m_extradata[32];
284 NSInteger m_tag;
285 int m_isfakerightmouse;
286 char m_hashaddestroy; // 2 = WM_DESTROY has finished completely
287 HMENU m_menu;
288 BOOL m_flip;
289 bool m_supports_ddrop;
290 bool m_paintctx_used;
291 HDC m_paintctx_hdc;
292 WindowPropRec *m_props;
293 NSRect m_paintctx_rect;
294 BOOL m_isopaque;
295 char m_titlestr[1024];
296 unsigned int m_create_windowflags;
297 NSOpenGLContext *m_glctx;
298 char m_isdirty; // &1=self needs redraw, &2=children may need redraw
299 char m_allow_nomiddleman;
300 id m_lastTopLevelOwner; // save a copy of the owner, if any
301 id m_access_cacheptrs[6];
303 - (id)initChild:(SWELL_DialogResourceIndex *)resstate Parent:(NSView *)parent dlgProc:(DLGPROC)dlgproc Param:(LPARAM)par;
304 - (LRESULT)onSwellMessage:(UINT)msg p1:(WPARAM)wParam p2:(LPARAM)lParam;
305 -(HANDLE)swellExtendedDragOp:(id <NSDraggingInfo>)sender retGlob:(BOOL)retG;
306 - (const char *)onSwellGetText;
307 -(void)onSwellSetText:(const char *)buf;
308 -(LONG)swellGetExtendedStyle;
309 -(void)swellSetExtendedStyle:(LONG)st;
310 -(HMENU)swellGetMenu;
311 -(BOOL)swellHasBeenDestroyed;
312 -(void)swellSetMenu:(HMENU)menu;
313 -(LONG_PTR)getSwellUserData;
314 -(void)setSwellUserData:(LONG_PTR)val;
315 -(void)setOpaque:(bool)isOpaque;
316 -(LPARAM)getSwellExtraData:(int)idx;
317 -(void)setSwellExtraData:(int)idx value:(LPARAM)val;
318 -(void)setSwellWindowProc:(WNDPROC)val;
319 -(WNDPROC)getSwellWindowProc;
320 -(void)setSwellDialogProc:(DLGPROC)val;
321 -(DLGPROC)getSwellDialogProc;
323 - (NSArray*) namesOfPromisedFilesDroppedAtDestination:(NSURL*)droplocation;
325 -(void) getSwellPaintInfo:(PAINTSTRUCT *)ps;
326 - (int)swellCapChangeNotify;
327 -(unsigned int)swellCreateWindowFlags;
329 -(bool)swellCanPostMessage;
330 -(int)swellEnumProps:(PROPENUMPROCEX)proc lp:(LPARAM)lParam;
331 -(void *)swellGetProp:(const char *)name wantRemove:(BOOL)rem;
332 -(int)swellSetProp:(const char *)name value:(void *)val ;
333 -(NSOpenGLContext *)swellGetGLContext;
335 // NSAccessibility
337 // attribute methods
338 //- (NSArray *)accessibilityAttributeNames;
339 - (id)accessibilityAttributeValue:(NSString *)attribute;
340 //- (BOOL)accessibilityIsAttributeSettable:(NSString *)attribute;
341 //- (void)accessibilitySetValue:(id)value forAttribute:(NSString *)attribute;
343 // parameterized attribute methods
344 //- (NSArray *)accessibilityParameterizedAttributeNames;
345 //- (id)accessibilityAttributeValue:(NSString *)attribute forParameter:(id)parameter;
347 // action methods
348 //- (NSArray *)accessibilityActionNames;
349 //- (NSString *)accessibilityActionDescription:(NSString *)action;
350 //- (void)accessibilityPerformAction:(NSString *)action;
352 // 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.
353 - (BOOL)accessibilityIsIgnored;
355 // 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.
356 - (id)accessibilityHitTest:(NSPoint)point;
358 // 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.
359 - (id)accessibilityFocusedUIElement;
364 @end
366 @interface SWELL_ModelessWindow : NSWindow
368 @public
369 NSSize lastFrameSize;
370 id m_owner;
371 OwnedWindowListRec *m_ownedwnds;
372 BOOL m_enabled;
373 int m_wantraiseamt;
374 bool m_wantInitialKeyWindowOnShow;
376 - (id)initModeless:(SWELL_DialogResourceIndex *)resstate Parent:(HWND)parent dlgProc:(DLGPROC)dlgproc Param:(LPARAM)par outputHwnd:(HWND *)hwndOut forceStyles:(unsigned int)smask;
377 - (id)initModelessForChild:(HWND)child owner:(HWND)owner styleMask:(unsigned int)smask;
378 - (void)swellDestroyAllOwnedWindows;
379 - (void)swellRemoveOwnedWindow:(NSWindow *)wnd;
380 - (void)swellSetOwner:(id)owner;
381 - (id)swellGetOwner;
382 - (void **)swellGetOwnerWindowHead;
383 -(void)swellDoDestroyStuff;
384 -(void)swellResetOwnedWindowLevels;
385 @end
387 @interface SWELL_ModalDialog : NSPanel
389 NSSize lastFrameSize;
390 id m_owner;
391 OwnedWindowListRec *m_ownedwnds;
393 int m_rv;
394 bool m_hasrv;
395 BOOL m_enabled;
397 - (id)initDialogBox:(SWELL_DialogResourceIndex *)resstate Parent:(HWND)parent dlgProc:(DLGPROC)dlgproc Param:(LPARAM)par;
398 - (void)swellDestroyAllOwnedWindows;
399 - (void)swellRemoveOwnedWindow:(NSWindow *)wnd;
400 - (void)swellSetOwner:(id)owner;
401 - (id)swellGetOwner;
402 - (void **)swellGetOwnerWindowHead;
403 -(void)swellDoDestroyStuff;
405 -(void)swellSetModalRetVal:(int)r;
406 -(int)swellGetModalRetVal;
407 -(bool)swellHasModalRetVal;
408 @end
411 @interface SWELL_hwndCarbonHost : SWELL_hwndChild
412 #ifdef MAC_OS_X_VERSION_10_7
413 <NSWindowDelegate>
414 #endif
416 @public
417 NSWindow *m_cwnd;
419 bool m_whileresizing;
420 void* m_wndhandler; // won't compile if declared EventHandlerRef, wtf
421 void* m_ctlhandler; // not sure if these need to be separate but cant hurt
422 bool m_wantallkeys;
424 -(BOOL)swellIsCarbonHostingView;
425 -(void)swellDoRepos;
426 @end
429 @interface SWELL_PopupMenuRecv : NSObject
431 int m_act;
432 HWND cbwnd;
434 -(id) initWithWnd:(HWND)wnd;
435 -(void) onSwellCommand:(id)sender;
436 -(int) isCommand;
437 - (void)menuNeedsUpdate:(NSMenu *)menu;
439 @end
441 @interface SWELL_PopUpButton : NSPopUpButton
443 LONG m_style;
445 -(void)setSwellStyle:(LONG)style;
446 -(LONG)getSwellStyle;
447 @end
449 @interface SWELL_ComboBox : NSComboBox
451 @public
452 LONG m_style;
453 WDL_PtrList<char> *m_ids;
455 -(id)init;
456 -(void)dealloc;
457 -(void)setSwellStyle:(LONG)style;
458 -(LONG)getSwellStyle;
459 @end
463 // GDI internals
465 #ifndef __AVAILABILITYMACROS__
466 #error __AVAILABILITYMACROS__ not defined, include AvailabilityMacros.h!
467 #endif
469 // 10.4 doesn't support CoreText, so allow ATSUI if targetting 10.4 SDK
470 #ifndef MAC_OS_X_VERSION_10_5
471 // 10.4 SDK
472 #define SWELL_NO_CORETEXT
473 #define SWELL_ATSUI_TEXT_SUPPORT
474 #else
476 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
477 #ifndef __LP64__
478 #define SWELL_ATSUI_TEXT_SUPPORT
479 #endif
480 #endif
482 #endif
484 struct HGDIOBJ__
486 int type;
488 int additional_refcnt; // refcnt of 0 means one owner (if >0, additional owners)
490 // used by pen/brush
491 CGColorRef color;
492 int wid;
493 NSImage *bitmapptr;
495 NSMutableDictionary *__old_fontdict; // unused, for ABI compat
497 // if ATSUI used, meaning IsCoreTextSupported() returned false
498 ATSUStyle atsui_font_style;
500 float font_rotation;
502 bool _infreelist;
503 struct HGDIOBJ__ *_next;
505 // if using CoreText to draw text
506 void *ct_FontRef;
507 char font_quality;
510 struct HDC__ {
511 CGContextRef ctx;
512 void *ownedData; // always use via SWELL_GetContextFrameBuffer() (which performs necessary alignment)
513 HGDIOBJ__ *curpen;
514 HGDIOBJ__ *curbrush;
515 HGDIOBJ__ *curfont;
517 NSColor *__old_nstextcol; // provided for ABI compat, but unused
518 int cur_text_color_int; // text color as int
520 int curbkcol;
521 int curbkmode;
522 float lastpos_x,lastpos_y;
524 void *GLgfxctx; // optionally set
525 bool _infreelist;
526 struct HDC__ *_next;
528 CGColorRef curtextcol; // text color as CGColor
535 // some extras so we can call functions available only on some OSX versions without warnings, and with the correct types
536 #define SWELL_DelegateExtensions __SWELL_PREFIX_CLASSNAME(_delext)
537 #define SWELL_ViewExtensions __SWELL_PREFIX_CLASSNAME(_viewext)
538 #define SWELL_AppExtensions __SWELL_PREFIX_CLASSNAME(_appext)
539 #define SWELL_WindowExtensions __SWELL_PREFIX_CLASSNAME(_wndext)
540 #define SWELL_TableColumnExtensions __SWELL_PREFIX_CLASSNAME(_tcolext)
542 @interface SWELL_WindowExtensions : NSWindow
543 -(void)setCollectionBehavior:(NSUInteger)a;
544 @end
545 @interface SWELL_ViewExtensions : NSView
546 -(void)_recursiveDisplayRectIfNeededIgnoringOpacity:(NSRect)rect isVisibleRect:(BOOL)vr rectIsVisibleRectForView:(NSView*)v topView:(NSView *)v2;
547 @end
549 @interface SWELL_DelegateExtensions : NSObject
550 -(bool)swellPostMessage:(HWND)dest msg:(int)message wp:(WPARAM)wParam lp:(LPARAM)lParam;
551 -(void)swellPostMessageClearQ:(HWND)dest;
552 -(void)swellPostMessageTick:(id)sender;
553 @end
555 @interface SWELL_AppExtensions : NSApplication
556 -(NSUInteger)presentationOptions;
557 -(void)setPresentationOptions:(NSUInteger)o;
558 @end
559 @interface SWELL_TableColumnExtensions : NSTableColumn
560 -(BOOL)isHidden;
561 -(void)setHidden:(BOOL)h;
562 @end
567 #else
568 // compat when compiling targetting OSX but not in objectiveC mode
569 struct SWELL_DataHold;
570 #endif // !__OBJC__
572 // 10.4 sdk just uses "float"
573 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
574 #ifdef __LP64__
575 typedef double CGFloat;
576 #else
577 typedef float CGFloat;
578 #endif
580 #endif
583 #elif defined(SWELL_TARGET_GDK)
585 #include <gdk/gdk.h>
586 #include <gdk/gdkkeysyms.h>
587 #include <gdk/gdkx.h>
590 #else
591 // generic
593 #endif // end generic
595 struct HTREEITEM__
597 HTREEITEM__();
598 ~HTREEITEM__();
599 bool FindItem(HTREEITEM it, HTREEITEM__ **parOut, int *idxOut);
601 #ifdef SWELL_TARGET_OSX
602 SWELL_DataHold *m_dh;
603 #else
604 int m_state; // TVIS_EXPANDED, for ex
605 #endif
607 bool m_haschildren;
608 char *m_value;
609 WDL_PtrList<HTREEITEM__> m_children; // only used in tree mode
610 LPARAM m_param;
615 #ifndef SWELL_TARGET_OSX
617 #include "../wdlstring.h"
619 #ifdef SWELL_LICE_GDI
620 #include "../lice/lice.h"
621 #endif
622 #include "../assocarray.h"
624 LRESULT SwellDialogDefaultWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
627 #ifdef SWELL_TARGET_GDK
628 typedef GdkWindow *SWELL_OSWINDOW;
629 #else
630 typedef void *SWELL_OSWINDOW; // maps to the HWND__ itself on visible, non-GDK, top level windows
631 #endif
633 struct HWND__
635 HWND__(HWND par, int wID=0, RECT *wndr=NULL, const char *label=NULL, bool visible=false, WNDPROC wndproc=NULL, DLGPROC dlgproc=NULL, HWND ownerWindow=NULL);
636 ~HWND__(); // DO NOT USE!!! We would make this private but it breaks PtrList using it on gcc.
638 // using this API prevents the HWND from being valid -- it'll still get its resources destroyed via DestroyWindow() though.
639 // DestroyWindow() does cleanup, then the final Release().
640 void Retain() { m_refcnt++; }
641 void Release() { if (!--m_refcnt) delete this; }
643 const char *m_classname;
645 SWELL_OSWINDOW m_oswindow;
647 WDL_FastString m_title;
649 HWND__ *m_children, *m_parent, *m_next, *m_prev;
650 HWND__ *m_owner, *m_owned_list, *m_owned_next, *m_owned_prev;
651 HWND__ *m_focused_child; // only valid if hwnd itself is in focus chain, and must be validated before accessed
652 RECT m_position;
653 UINT m_id;
654 int m_style, m_exstyle;
655 INT_PTR m_userdata;
656 WNDPROC m_wndproc;
657 DLGPROC m_dlgproc;
658 INT_PTR m_extra[64];
659 INT_PTR m_private_data; // used by internal controls
661 bool m_visible;
662 char m_hashaddestroy; // 1 in destroy, 2 full destroy
663 bool m_enabled;
664 bool m_wantfocus;
666 bool m_israised;
667 bool m_has_had_position;
668 bool m_oswindow_fullscreen;
670 int m_refcnt;
671 int m_oswindow_private; // private state for generic-gtk or whatever
673 HMENU m_menu;
674 HFONT m_font;
676 WDL_StringKeyedArray<void *> m_props;
678 #ifdef SWELL_LICE_GDI
679 void *m_paintctx; // temporarily set for calls to WM_PAINT
681 bool m_child_invalidated; // if a child is invalidated
682 bool m_invalidated; // set to true on direct invalidate. todo RECT instead?
684 LICE_IBitmap *m_backingstore; // if NULL, unused (probably only should use on top level windows, but support caching?)
685 #endif
688 struct HMENU__
690 HMENU__() { m_refcnt=1; sel_vis = -1; }
692 void Retain() { m_refcnt++; }
693 void Release() { if (!--m_refcnt) delete this; }
695 WDL_PtrList<MENUITEMINFO> items;
696 int sel_vis; // for mouse/keyboard nav
697 int m_refcnt;
699 HMENU__ *Duplicate();
700 static void freeMenuItem(void *p);
702 private:
703 ~HMENU__() { items.Empty(true,freeMenuItem); }
707 struct HGDIOBJ__
709 int type;
710 int additional_refcnt; // refcnt of 0 means one owner (if >0, additional owners)
712 int color;
713 int wid;
715 float alpha;
717 struct HGDIOBJ__ *_next;
718 bool _infreelist;
719 void *typedata; // font: FT_Face, bitmap: LICE_IBitmap
723 struct HDC__ {
724 #ifdef SWELL_LICE_GDI
725 LICE_IBitmap *surface; // owned by context. can be (and usually is, if clipping is desired) LICE_SubBitmap
726 POINT surface_offs; // offset drawing into surface by this amount
728 RECT dirty_rect; // in surface coordinates, used for GetWindowDC()/GetDC()/etc
729 bool dirty_rect_valid;
730 #else
731 void *ownedData; // for mem contexts, support a null rendering
732 #endif
734 HGDIOBJ__ *curpen;
735 HGDIOBJ__ *curbrush;
736 HGDIOBJ__ *curfont;
738 int cur_text_color_int; // text color as int
740 int curbkcol;
741 int curbkmode;
742 float lastpos_x,lastpos_y;
744 struct HDC__ *_next;
745 bool _infreelist;
748 HWND DialogBoxIsActive(void);
749 void DestroyPopupMenus(void);
750 HWND ChildWindowFromPoint(HWND h, POINT p);
751 bool IsWindowEnabled(HWND hwnd);
752 HWND GetFocusIncludeMenus();
754 void SWELL_RunEvents();
756 bool swell_isOSwindowmenu(SWELL_OSWINDOW osw);
758 bool swell_is_virtkey_char(int c);
760 void swell_on_toplevel_raise(SWELL_OSWINDOW wnd); // called by swell-generic-gdk when a window is focused
762 HWND swell_oswindow_to_hwnd(SWELL_OSWINDOW w);
763 void swell_oswindow_focus(HWND hwnd);
764 void swell_oswindow_update_style(HWND hwnd, LONG oldstyle);
765 void swell_oswindow_update_enable(HWND hwnd);
766 void swell_oswindow_update_text(HWND hwnd);
767 void swell_oswindow_begin_resize(SWELL_OSWINDOW wnd);
768 void swell_oswindow_resize(SWELL_OSWINDOW wnd, int reposflag, RECT f);
769 void swell_oswindow_postresize(HWND hwnd, RECT f);
770 void swell_oswindow_invalidate(HWND hwnd, const RECT *r);
771 void swell_oswindow_destroy(HWND hwnd);
772 void swell_oswindow_manage(HWND hwnd, bool wantfocus);
773 void swell_oswindow_updatetoscreen(HWND hwnd, RECT *rect);
774 void swell_dlg_destroyspare();
776 extern bool swell_is_likely_capslock; // only used when processing dit events for a-zA-Z
777 extern const char *g_swell_appname;
778 extern SWELL_OSWINDOW SWELL_focused_oswindow; // top level window which has focus (might not map to a HWND__!)
779 extern HWND swell_captured_window;
780 extern HWND SWELL_topwindows; // front of list = most recently active
781 extern bool swell_app_is_inactive;
783 #ifdef _DEBUG
784 void VALIDATE_HWND_LIST(HWND list, HWND par);
785 #else
786 #define VALIDATE_HWND_LIST(list, par) do { } while (0)
787 #endif
790 #endif // !OSX
792 HDC SWELL_CreateGfxContext(void *);
794 // GDP internals
795 #define TYPE_PEN 1
796 #define TYPE_BRUSH 2
797 #define TYPE_FONT 3
798 #define TYPE_BITMAP 4
800 typedef struct
802 void *instptr;
803 #ifdef __APPLE__
804 void *bundleinstptr;
805 #endif
806 int refcnt;
808 int (*SWELL_dllMain)(HINSTANCE, DWORD,LPVOID); //last parm=SWELLAPI_GetFunc
809 BOOL (*dllMain)(HINSTANCE, DWORD, LPVOID);
810 void *lastSymbolRequested;
811 } SWELL_HINSTANCE;
814 enum
816 INTERNAL_OBJECT_START= 0x1000001,
817 INTERNAL_OBJECT_THREAD,
818 INTERNAL_OBJECT_EVENT,
819 INTERNAL_OBJECT_FILE,
820 INTERNAL_OBJECT_EXTERNALSOCKET, // socket not owned by us
821 INTERNAL_OBJECT_SOCKETEVENT,
822 INTERNAL_OBJECT_NSTASK,
823 INTERNAL_OBJECT_END
826 typedef struct
828 int type; // INTERNAL_OBJECT_*
829 int count; // reference count
830 } SWELL_InternalObjectHeader;
832 typedef struct
834 SWELL_InternalObjectHeader hdr;
835 DWORD (*threadProc)(LPVOID);
836 void *threadParm;
837 pthread_t pt;
838 DWORD retv;
839 bool done;
840 } SWELL_InternalObjectHeader_Thread;
842 typedef struct
844 SWELL_InternalObjectHeader hdr;
846 pthread_mutex_t mutex;
847 pthread_cond_t cond;
849 bool isSignal;
850 bool isManualReset;
852 } SWELL_InternalObjectHeader_Event;
855 // used for both INTERNAL_OBJECT_EXTERNALSOCKET and INTERNAL_OBJECT_SOCKETEVENT.
856 // if EXTERNALSOCKET, socket[1] ignored and autoReset ignored.
857 typedef struct
859 SWELL_InternalObjectHeader hdr;
860 int socket[2];
861 bool autoReset;
862 } SWELL_InternalObjectHeader_SocketEvent;
864 typedef struct
866 SWELL_InternalObjectHeader hdr;
868 FILE *fp;
869 } SWELL_InternalObjectHeader_File;
871 typedef struct
873 SWELL_InternalObjectHeader hdr;
874 void *task;
875 } SWELL_InternalObjectHeader_NSTask;
878 bool IsRightClickEmulateEnabled();
880 #ifdef SWELL_INTERNAL_HTREEITEM_IMPL
882 HTREEITEM__::HTREEITEM__()
884 m_param=0;
885 m_value=0;
886 m_haschildren=false;
887 #ifdef SWELL_TARGET_OSX
888 m_dh = [[SWELL_DataHold alloc] initWithVal:this];
889 #else
890 m_state=0;
891 #endif
893 HTREEITEM__::~HTREEITEM__()
895 free(m_value);
896 m_children.Empty(true);
897 #ifdef SWELL_TARGET_OSX
898 [m_dh release];
899 #endif
903 bool HTREEITEM__::FindItem(HTREEITEM it, HTREEITEM__ **parOut, int *idxOut)
905 int a=m_children.Find((HTREEITEM__*)it);
906 if (a>=0)
908 if (parOut) *parOut=this;
909 if (idxOut) *idxOut=a;
910 return true;
912 int x;
913 const int n=m_children.GetSize();
914 for (x = 0; x < n; x ++)
916 if (m_children.Get(x)->FindItem(it,parOut,idxOut)) return true;
918 return false;
921 #endif
923 #ifdef SWELL_INTERNAL_MERGESORT_IMPL
925 static int __listview_sortfunc(void *p1, void *p2, int (*compar)(LPARAM val1, LPARAM val2, LPARAM userval), LPARAM userval)
927 SWELL_ListView_Row *a = *(SWELL_ListView_Row **)p1;
928 SWELL_ListView_Row *b = *(SWELL_ListView_Row **)p2;
929 return compar(a->m_param,b->m_param,userval);
933 static void __listview_mergesort_internal(void *base, size_t nmemb, size_t size,
934 int (*compar)(LPARAM val1, LPARAM val2, LPARAM userval),
935 LPARAM parm,
936 char *tmpspace)
938 char *b1,*b2;
939 size_t n1, n2;
941 if (nmemb < 2) return;
943 n1 = nmemb / 2;
944 b1 = (char *) base;
945 n2 = nmemb - n1;
946 b2 = b1 + (n1 * size);
948 if (nmemb>2)
950 __listview_mergesort_internal(b1, n1, size, compar, parm, tmpspace);
951 __listview_mergesort_internal(b2, n2, size, compar, parm, tmpspace);
954 char *p = tmpspace;
958 if (__listview_sortfunc(b1, b2, compar,parm) > 0)
960 memcpy(p, b2, size);
961 b2 += size;
962 n2--;
964 else
966 memcpy(p, b1, size);
967 b1 += size;
968 n1--;
970 p += size;
972 while (n1 > 0 && n2 > 0);
974 if (n1 > 0) memcpy(p, b1, n1 * size);
975 memcpy(base, tmpspace, (nmemb - n2) * size);
979 #endif
981 #ifndef SWELL_TARGET_OSX
983 #define SWELL_GENERIC_THEMESIZEDEFS(f,fd) \
984 f(default_font_size, 12) \
985 f(menubar_height, 17) \
986 f(menubar_font_size, 13) \
987 f(menubar_spacing_width, 8) \
988 f(menubar_margin_width, 6) \
989 f(scrollbar_width, 14) \
990 f(scrollbar_min_thumb_height, 4) \
991 f(combo_height, 20) \
994 #define SWELL_GENERIC_THEMEDEFS(f,fd) \
995 SWELL_GENERIC_THEMESIZEDEFS(f,fd) \
996 f(_3dface,RGB(192,192,192)) \
997 f(_3dshadow,RGB(96,96,96)) \
998 f(_3dhilight,RGB(224,224,224)) \
999 f(_3ddkshadow,RGB(48,48,48)) \
1000 fd(button_bg,RGB(192,192,192),_3dface) \
1001 f(button_text,RGB(0,0,0)) \
1002 f(button_text_disabled, RGB(128,128,128)) \
1003 fd(button_shadow, RGB(96,96,96), _3dshadow) \
1004 fd(button_hilight, RGB(224,224,224), _3dhilight) \
1005 f(checkbox_text,RGB(0,0,0)) \
1006 f(checkbox_text_disabled, RGB(128,128,128)) \
1007 f(checkbox_fg, RGB(0,0,0)) \
1008 f(checkbox_inter, RGB(192,192,192)) \
1009 f(checkbox_bg, RGB(255,255,255)) \
1010 f(scrollbar,RGB(32,32,32)) \
1011 f(scrollbar_fg, RGB(160,160,160)) \
1012 f(scrollbar_bg, RGB(224,224,224)) \
1013 f(edit_cursor,RGB(0,128,255)) \
1014 f(edit_bg,RGB(255,255,255)) \
1015 f(edit_bg_disabled,RGB(224,224,224)) \
1016 f(edit_text,RGB(0,0,0)) \
1017 f(edit_text_disabled, RGB(128,128,128)) \
1018 f(edit_bg_sel,RGB(128,192,255)) \
1019 f(edit_text_sel,RGB(255,255,255)) \
1020 fd(edit_hilight, RGB(224,224,224), _3dhilight) \
1021 fd(edit_shadow, RGB(96,96,96), _3dshadow) \
1022 f(info_bk,RGB(255,240,200)) \
1023 f(info_text,RGB(0,0,0)) \
1024 fd(menu_bg, RGB(192,192,192), _3dface) \
1025 fd(menu_shadow, RGB(96,96,96), _3dshadow) \
1026 fd(menu_hilight, RGB(224,224,224), _3dhilight) \
1027 fd(menu_text, RGB(0,0,0), button_text) \
1028 fd(menu_text_disabled, RGB(224,224,224), _3dhilight) \
1029 fd(menu_bg_sel, RGB(0,0,0), menu_text) \
1030 fd(menu_text_sel, RGB(224,224,224), menu_bg) \
1031 f(menu_scroll, RGB(64,64,64)) \
1032 fd(menu_scroll_arrow, RGB(96,96,96), _3dshadow) \
1033 fd(menu_submenu_arrow, RGB(96,96,96), _3dshadow) \
1034 fd(menubar_bg, RGB(192,192,192), menu_bg) \
1035 fd(menubar_text, RGB(0,0,0), menu_text) \
1036 fd(menubar_text_disabled, RGB(224,224,224), menu_text_disabled) \
1037 fd(menubar_bg_sel, RGB(0,0,0), menu_bg_sel) \
1038 fd(menubar_text_sel, RGB(224,224,224), menu_text_sel) \
1039 f(trackbar_track, RGB(224,224,224)) \
1040 f(trackbar_mark, RGB(96,96,96)) \
1041 f(trackbar_knob, RGB(48,48,48)) \
1042 f(progress,RGB(0,128,255)) \
1043 fd(label_text, RGB(0,0,0), button_text) \
1044 fd(label_text_disabled, RGB(128,128,128), button_text_disabled) \
1045 fd(combo_text, RGB(0,0,0), button_text) \
1046 fd(combo_text_disabled, RGB(128,128,128), button_text_disabled) \
1047 fd(combo_bg, RGB(192,192,192), _3dface) \
1048 f(combo_bg2, RGB(255,255,255)) \
1049 fd(combo_shadow, RGB(96,96,96), _3dshadow) \
1050 fd(combo_hilight, RGB(224,224,224), _3dhilight) \
1051 fd(combo_arrow, RGB(96,96,96), _3dshadow) \
1052 fd(combo_arrow_press, RGB(224,224,224), _3dhilight) \
1053 f(listview_bg, RGB(255,255,255)) \
1054 f(listview_bg_sel, RGB(128,128, 255)) \
1055 f(listview_text, RGB(0,0,0)) \
1056 fd(listview_text_sel, RGB(0,0,0), listview_text) \
1057 fd(listview_grid, RGB(224,224,224), _3dhilight) \
1058 f(listview_hdr_arrow,RGB(96,96,96)) \
1059 fd(listview_hdr_shadow, RGB(96,96,96), _3dshadow) \
1060 fd(listview_hdr_hilight, RGB(224,224,224), _3dhilight) \
1061 fd(listview_hdr_bg, RGB(192,192,192), _3dface) \
1062 fd(listview_hdr_text, RGB(0,0,0), button_text) \
1063 f(treeview_text,RGB( 0,0,0)) \
1064 f(treeview_bg, RGB(255,255,255)) \
1065 f(treeview_bg_sel, RGB(128,128,255)) \
1066 f(treeview_text_sel, RGB(0,0,0)) \
1067 f(treeview_arrow, RGB(96,96,96)) \
1068 fd(tab_shadow, RGB(96,96,96), _3dshadow) \
1069 fd(tab_hilight, RGB(224,224,224), _3dhilight) \
1070 fd(tab_text, RGB(0,0,0), button_text) \
1071 f(focusrect,RGB(255,0,0)) \
1072 f(group_text,RGB(0,0,0)) \
1073 fd(group_shadow, RGB(96,96,96), _3dshadow) \
1074 fd(group_hilight, RGB(224,224,224), _3dhilight) \
1075 f(focus_hilight, RGB(192,192,255)) \
1079 struct swell_colortheme {
1080 #define __def_theme_ent(x,c) int x;
1081 #define __def_theme_ent_fb(x,c,fb) int x;
1082 SWELL_GENERIC_THEMEDEFS(__def_theme_ent,__def_theme_ent_fb)
1083 #undef __def_theme_ent
1084 #undef __def_theme_ent_fb
1087 #define SWELL_UI_SCALE(x) (((x)*g_swell_ui_scale)/256)
1088 extern int g_swell_ui_scale;
1089 extern swell_colortheme g_swell_ctheme;
1090 extern const char *g_swell_deffont_face;
1092 #endif
1094 #endif