forked from reaper-oss/sws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sws_util.mm
655 lines (593 loc) · 25 KB
/
sws_util.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
/******************************************************************************
/ sws_util.mm
/
/ Copyright (c) 2010 Tim Payne (SWS), Dominik Martin Drzic
/ Permission is hereby granted, free of charge, to any person obtaining a copy
/ of this software and associated documentation files (the "Software"), to deal
/ in the Software without restriction, including without limitation the rights to
/ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
/ of the Software, and to permit persons to whom the Software is furnished to
/ do so, subject to the following conditions:
/
/ The above copyright notice and this permission notice shall be included in all
/ copies or substantial portions of the Software.
/
/ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
/ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
/ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
/ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
/ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
/ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
/ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
/ OTHER DEALINGS IN THE SOFTWARE.
/
******************************************************************************/
#import <Cocoa/Cocoa.h>
#include "stdafx.h"
#include "../WDL/swell/swell-internal.h"
#include "../WDL/swell/swell-dlggen.h"
void SWS_GetDateString(int time, char* buf, int bufsize)
{
NSDate* macTime = [NSDate dateWithTimeIntervalSince1970:time];
NSDateFormatter *macTimeFmt = [[[NSDateFormatter alloc] init] autorelease];
[macTimeFmt setFormatterBehavior:NSDateFormatterBehavior10_4];
[macTimeFmt setDateStyle:NSDateFormatterShortStyle];
NSString* s = [macTimeFmt stringFromDate:macTime];
[s getCString:buf maxLength:bufsize encoding:NSUTF8StringEncoding];
}
void SWS_GetTimeString(int time, char* buf, int bufsize)
{
NSDate* macTime = [NSDate dateWithTimeIntervalSince1970:time];
NSDateFormatter *macTimeFmt = [[[NSDateFormatter alloc] init] autorelease];
[macTimeFmt setFormatterBehavior:NSDateFormatterBehavior10_4];
[macTimeFmt setTimeStyle:NSDateFormatterShortStyle];
NSString* s = [macTimeFmt stringFromDate:macTime];
[s getCString:buf maxLength:bufsize encoding:NSUTF8StringEncoding];
}
void SetColumnArrows(HWND h, int iSortCol)
{
if (!h || ![(id)h isKindOfClass:[SWELL_ListView class]]) return;
SWELL_ListView *v=(SWELL_ListView *)h;
if (!v->m_cols) return;
for (int i = 0; i < v->m_cols->GetSize(); i++)
{
if (i == abs(iSortCol)-1)
{
if (iSortCol > 0)
[v setIndicatorImage:[NSImage imageNamed:@"NSAscendingSortIndicator"] inTableColumn:v->m_cols->Get(i)];
else
[v setIndicatorImage:[NSImage imageNamed:@"NSDescendingSortIndicator"] inTableColumn:v->m_cols->Get(i)];
}
else
[v setIndicatorImage:0 inTableColumn:v->m_cols->Get(i)];
}
}
static int RGBfromNSColor(NSColor *col)
{
int r = (int) ([col redComponent] * 255.0 + 0.5) ;
int g = (int) ([col greenComponent] * 255.0 + 0.5) ;
int b = (int) ([col blueComponent] * 255.0 + 0.5) ;
if (r<0)r=0; else if (r>255) r=255;
if (g<0)g=0; else if (g>255) g=255;
if (b<0)b=0; else if (b>255) b=255;
return (r << 16) | (g << 8) | b;
}
int GetCustomColors(COLORREF custColors[])
{
NSColorPanel* cp = [NSColorPanel sharedColorPanel];
[[cp valueForKey:@"_colorSwatch"] performSelector:@selector(readColors)];
// Get the NSColorSwatch's internal mutable array of NSColors
NSMutableArray *colors = [[cp valueForKey:@"_colorSwatch"] valueForKey:@"colors"];
for (int i = 0; i < 16; i++)
{
NSColor* col = [colors objectAtIndex:i*10];
col = [col colorUsingColorSpaceName:@"NSCalibratedRGBColorSpace"];
custColors[i] = RGBfromNSColor(col);
}
return 0;
}
void SetCustomColors(COLORREF custColors[])
{
NSColorPanel* cp = [NSColorPanel sharedColorPanel];
[[cp valueForKey:@"_colorSwatch"] performSelector:@selector(readColors)];
// Get the NSColorSwatch's internal mutable array of NSColors
NSMutableArray *colors = [[cp valueForKey:@"_colorSwatch"] valueForKey:@"colors"];
for (int i = 0; i < 16; i++)
{
NSColor* col = [NSColor colorWithCalibratedRed:(custColors[i]>>16)/255.0 green:((custColors[i]&0xFF00)>>8)/255.0 blue:(custColors[i]&0xFF)/255.0 alpha:1.0];
[colors replaceObjectAtIndex:i*10 withObject:col];
}
[[cp valueForKey:@"_colorSwatch"] performSelector:@selector(writeColors)];
}
void ShowColorChooser(COLORREF initialCol)
{
NSColorPanel *colorPanel = [NSColorPanel sharedColorPanel];
NSColor* col = [NSColor colorWithCalibratedRed:(initialCol>>16)/255.0 green:((initialCol&0xFF00)>>8)/255.0 blue:(initialCol&0xFF)/255.0 alpha:1.0];
[colorPanel setColor:col];
[[NSApplication sharedApplication] orderFrontColorPanel:(id)g_hwndParent];
}
bool GetChosenColor(COLORREF* pColor)
{
if (![[NSColorPanel sharedColorPanel] isVisible])
{
if (pColor)
{
NSColor* col = [[NSColorPanel sharedColorPanel] color];
col = [col colorUsingColorSpaceName:@"NSCalibratedRGBColorSpace"];
*pColor = RGBfromNSColor(col);
}
return true;
}
return false;
}
void HideColorChooser()
{
ShowWindow((HWND)[NSColorPanel sharedColorPanel], SW_HIDE);
}
void EnableColumnResize(HWND h)
{
if (!h || ![(id)h isKindOfClass:[SWELL_ListView class]]) return;
SWELL_ListView *v=(SWELL_ListView *)h;
[v setAllowsColumnResizing:YES];
}
// Modified MakeCursorFromData from Cockos WDL (supports 32x32 unlike original function which supports 16x16)
static NSCursor* SWS_MakeCursorFromData(unsigned char* data, int hotspot_x, int hotspot_y)
{
NSCursor *c=NULL;
NSBitmapImageRep* bmp = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:0
pixelsWide:32
pixelsHigh:32
bitsPerSample:8
samplesPerPixel:2
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSCalibratedWhiteColorSpace
bytesPerRow:(32*2)
bitsPerPixel:16];
if (bmp)
{
unsigned char* p = [bmp bitmapData];
if (p)
{
int i;
for (i = 0; i < 32*32; ++i)
{
// tried 4 bits per sample and memcpy, didn't work
p[2*i] = (data[i]&0xF0) | data[i]>>4;
p[2*i+1] = (data[i]<<4) | (data[i]&0xf);
}
NSImage *img = [[NSImage alloc] init];
if (img)
{
[img addRepresentation:bmp];
NSPoint hs = NSMakePoint(hotspot_x, hotspot_y);
c = [[NSCursor alloc] initWithImage:img hotSpot:hs];
[img release];
}
}
[bmp release];
}
return c;
}
// Modified LoadCursor from Cockos WDL
// Supports these cursors:
// IDC_GRID_WARP
// IDC_ENV_PEN_GRID, IDC_ENV_PT_ADJ_VERT
// IDC_MISC_SPEAKER
// IDC_ZOOM_DRAG, IDC_ZOOM_IN, IDC_ZOOM_OUT, IDC_ZOOM_UNDO
HCURSOR SWS_LoadCursor(int id)
{
// bytemaps are (white<<4)|(alpha)
const unsigned char B = 0xF;
const unsigned char W = 0xFF;
//const unsigned char G = 0xF8;
static NSCursor* carr[8]; // set to NULL by compiler
NSCursor** pc=0;
int index = 0;
bool found = false;
if (!found && id == IDC_ENV_PEN_GRID) found = true; else if (!found) ++index;
if (!found && id == IDC_ENV_PT_ADJ_VERT) found = true; else if (!found) ++index;
if (!found && id == IDC_GRID_WARP) found = true; else if (!found) ++index;
if (!found && id == IDC_MISC_SPEAKER) found = true; else if (!found) ++index;
if (!found && id == IDC_ZOOM_DRAG) found = true; else if (!found) ++index;
if (!found && id == IDC_ZOOM_IN) found = true; else if (!found) ++index;
if (!found && id == IDC_ZOOM_OUT) found = true; else if (!found) ++index;
if (!found && id == IDC_ZOOM_UNDO) found = true; else if (!found) ++index;
if (!found)
return NULL;
pc = &carr[index];
if (!(*pc))
{
if (id == IDC_ENV_PEN_GRID)
{
static unsigned char p[32*32] =
{
0,0,0,0,0,0,0,0,0,0,0,0,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,B,W,B,0,0,0,B,0,0,B,0,0,B,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,B,W,W,B,B,0,0,B,0,0,B,0,0,B,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,B,W,W,B,B,0,0,0,B,0,0,B,0,0,B,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,B,W,W,B,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,B,W,W,B,B,0,0,0,0,0,B,0,0,B,0,0,B,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,B,W,W,B,B,0,0,0,0,0,0,B,0,0,B,0,0,B,0,0,0,0,0,0,0,0,
0,0,0,0,0,B,W,W,B,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,B,W,W,B,B,0,0,0,0,0,0,0,0,B,0,0,B,0,0,B,0,0,0,0,0,0,0,0,
0,0,0,B,W,W,B,B,0,0,0,0,0,0,0,0,0,B,0,0,B,0,0,B,0,0,0,0,0,0,0,0,
0,0,B,B,W,B,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,B,B,B,B,0,0,0,0,0,0,0,0,0,0,0,B,0,0,B,0,0,B,0,0,0,0,0,0,0,0,
0,B,B,B,B,0,0,0,0,0,B,B,0,0,0,0,0,B,0,0,B,0,0,B,0,0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,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
B,W,B,W,B,B,B,W,B,W,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,B,W,B,W,W,W,B,W,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,B,W,W,B,B,B,W,W,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,B,B,W,W,W,B,B,W,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,B,B,B,0,0,B,W,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,B,W,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,B,W,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,B,W,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,B,W,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
*pc = SWS_MakeCursorFromData(p, 5, 5);
}
}
return (HCURSOR)*pc;
}
void mouse_event(DWORD dwFlags, DWORD dx, DWORD dy, DWORD dwData, ULONG_PTR dwExtraInfo)
{
CGEventRef e = NULL;
int h = CGDisplayPixelsHigh(CGMainDisplayID());
switch(dwFlags)
{
case MOUSEEVENTF_LEFTDOWN: e = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, CGPointMake(dx, h-dy), kCGMouseButtonLeft); break;
case MOUSEEVENTF_LEFTUP: e = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseUp, CGPointMake(dx, h-dy), kCGMouseButtonLeft); break;
case MOUSEEVENTF_RIGHTDOWN: e = CGEventCreateMouseEvent(NULL, kCGEventRightMouseDown, CGPointMake(dx, h-dy), kCGMouseButtonRight); break;
case MOUSEEVENTF_RIGHTUP: e = CGEventCreateMouseEvent(NULL, kCGEventRightMouseUp, CGPointMake(dx, h-dy), kCGMouseButtonRight); break;
}
if (e)
{
CGEventPost(kCGHIDEventTap, e);
CFRelease(e);
}
}
//JFB List view code here == modified from Cockos WDL!
// Overrides some wdl's list view funcs to avoid cast issues
// (useful with native list views which are SWELL_ListView but that were not instanciated by the extension..)
int ListView_GetSelectedCountCast(HWND h)
{
if (!h) return 0;
// if (![(id)h isKindOfClass:[SWELL_ListView class]]) return 0;
SWELL_ListView *tv=(SWELL_ListView*)h;
return [tv numberOfSelectedRows];
}
int ListView_GetItemCountCast(HWND h)
{
if (!h) return 0;
// if (![(id)h isKindOfClass:[SWELL_ListView class]]) return 0;
SWELL_ListView *tv=(SWELL_ListView*)h;
if (tv->m_lbMode || !(tv->style & LVS_OWNERDATA))
{
if (!tv->m_items) return 0;
return tv->m_items->GetSize();
}
return tv->ownermode_cnt;
}
bool ListView_GetItemCast(HWND h, LVITEM *item)
{
if (!item) return false;
if ((item->mask&LVIF_TEXT)&&item->pszText && item->cchTextMax > 0) item->pszText[0]=0;
item->state=0;
if (!h) return false;
// if (![(id)h isKindOfClass:[SWELL_ListView class]]) return false;
SWELL_ListView *tv=(SWELL_ListView*)h;
if (tv->m_lbMode || !(tv->style & LVS_OWNERDATA))
{
if (!tv->m_items) return false;
SWELL_ListView_Row *row=tv->m_items->Get(item->iItem);
if (!row) return false;
if (item->mask & LVIF_PARAM) item->lParam=row->m_param;
if (item->mask & LVIF_TEXT) if (item->pszText && item->cchTextMax>0)
{
char *p=row->m_vals.Get(item->iSubItem);
lstrcpyn(item->pszText,p?p:"",item->cchTextMax);
}
if (item->mask & LVIF_STATE)
{
if (item->stateMask & (0xff<<16))
{
item->state|=row->m_imageidx<<16;
}
}
}
else
{
if (item->iItem <0 || item->iItem >= tv->ownermode_cnt) return false;
}
if (item->mask & LVIF_STATE)
{
if ((item->stateMask&LVIS_SELECTED) && [tv isRowSelected:item->iItem]) item->state|=LVIS_SELECTED;
if ((item->stateMask&LVIS_FOCUSED) && [tv selectedRow] == item->iItem) item->state|=LVIS_FOCUSED;
}
return true;
}
void ListView_GetItemTextCast(HWND hwnd, int item, int subitem, char *text, int textmax)
{
LVITEM it={LVIF_TEXT,item,subitem,0,0,text,textmax,};
ListView_GetItemCast(hwnd,&it);
}
void ListView_RedrawItemsCast(HWND h, int startitem, int enditem)
{
// if (!h || ![(id)h isKindOfClass:[SWELL_ListView class]]) return;
if (!h) return;
SWELL_ListView *tv=(SWELL_ListView*)h;
if (!tv->m_items) return;
[tv reloadData];
}
bool ListView_SetItemStateCast(HWND h, int ipos, int state, int statemask)
{
int doref=0;
// if (!h || ![(id)h isKindOfClass:[SWELL_ListView class]]) return false;
if (!h) return false;
SWELL_ListView *tv=(SWELL_ListView*)h;
static int _is_doing_all;
if (ipos == -1)
{
int x;
int n=ListView_GetItemCountCast(h);
_is_doing_all++;
for (x = 0; x < n; x ++)
ListView_SetItemStateCast(h,x,state,statemask);
_is_doing_all--;
ListView_RedrawItemsCast(h,0,n-1);
return true;
}
if (tv->m_lbMode || !(tv->style & LVS_OWNERDATA))
{
if (!tv->m_items) return false;
SWELL_ListView_Row *row=tv->m_items->Get(ipos);
if (!row) return false;
if (statemask & (0xff<<16))
{
if (row->m_imageidx!=((state>>16)&0xff))
{
row->m_imageidx=(state>>16)&0xff;
doref=1;
}
}
}
else
{
if (ipos<0 || ipos >= tv->ownermode_cnt) return 0;
}
bool didsel=false;
if (statemask & LVIS_SELECTED)
{
if (state & LVIS_SELECTED)
{
bool isSingle = tv->m_lbMode ? !(tv->style & LBS_EXTENDEDSEL) : !!(tv->style&LVS_SINGLESEL);
if (![tv isRowSelected:ipos]) { didsel=true; [tv selectRowIndexes:[NSIndexSet indexSetWithIndex:ipos] byExtendingSelection:isSingle?NO:YES]; }
}
else
{
if ([tv isRowSelected:ipos]) { didsel=true; [tv deselectRow:ipos]; }
}
}
if (statemask & LVIS_FOCUSED)
{
if (state&LVIS_FOCUSED)
{
}
else
{
}
}
if (!_is_doing_all)
{
if (didsel)
{
static int __rent;
if (!__rent)
{
__rent=1;
NMLISTVIEW nm={{(HWND)h,[tv tag],LVN_ITEMCHANGED},ipos,0,state,};
SendMessage(GetParent(h),WM_NOTIFY,[tv tag],(LPARAM)&nm);
__rent=0;
}
}
if (doref)
ListView_RedrawItemsCast(h,ipos,ipos);
}
return true;
}
BOOL IsWindowEnabled(HWND hwnd)
{
if (!hwnd) return FALSE;
SWELL_BEGIN_TRY
id bla=(id)hwnd;
if ([bla isKindOfClass:[NSWindow class]]) bla = [bla contentView];
if (bla && [bla respondsToSelector:@selector(isEnabled:)])
{
return [bla isEnabled] == YES ? TRUE : FALSE;
}
SWELL_END_TRY(;)
return FALSE;
}
void SWS_ShowTextScrollbar(HWND hwnd, bool show)
{
if (!hwnd) return;
DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE);
if (!show) dwStyle &= ~WS_HSCROLL;
else dwStyle |= WS_HSCROLL;
SetWindowLong(hwnd, GWL_STYLE, dwStyle);
SWELL_TextView *tv=(SWELL_TextView*)hwnd;
[tv setHorizontallyResizable:show?NO:YES];
NSScrollView *sc = [tv enclosingScrollView];
[sc setHasHorizontalScroller:show?YES:NO];
}