Mercurial > dwindows
comparison mac/dw.m @ 1773:da7786b8573f
Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 15 Jul 2012 05:35:30 +0000 |
parents | 5e16351b01d2 |
children | 4cc999e757a3 |
comparison
equal
deleted
inserted
replaced
1772:5e16351b01d2 | 1773:da7786b8573f |
---|---|
3 * A GTK like implementation of the MacOS GUI using Cocoa | 3 * A GTK like implementation of the MacOS GUI using Cocoa |
4 * | 4 * |
5 * (C) 2011-2012 Brian Smith <brian@dbsoft.org> | 5 * (C) 2011-2012 Brian Smith <brian@dbsoft.org> |
6 * (C) 2011 Mark Hessling <mark@rexx.org> | 6 * (C) 2011 Mark Hessling <mark@rexx.org> |
7 * | 7 * |
8 * Requires 10.5 or later. | 8 * Requires 10.5 or later.f |
9 * clang -std=c99 -g -o dwtest -D__MAC__ -I. dwtest.c mac/dw.m -framework Cocoa -framework WebKit | 9 * clang -std=c99 -g -o dwtest -D__MAC__ -I. dwtest.c mac/dw.m -framework Cocoa -framework WebKit |
10 */ | 10 */ |
11 #import <Cocoa/Cocoa.h> | 11 #import <Cocoa/Cocoa.h> |
12 #import <WebKit/WebKit.h> | 12 #import <WebKit/WebKit.h> |
13 #include "dw.h" | 13 #include "dw.h" |
314 } | 314 } |
315 /* Motion notify event */ | 315 /* Motion notify event */ |
316 case 5: | 316 case 5: |
317 { | 317 { |
318 int (* API motionfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; | 318 int (* API motionfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; |
319 int buttonmask = DWOSMinor > 5 ? (int)[NSEvent pressedMouseButtons] : 0; | |
320 id view = [[[event window] contentView] superview]; | 319 id view = [[[event window] contentView] superview]; |
321 NSPoint p = [view convertPoint:[event locationInWindow] toView:object]; | 320 NSPoint p = [view convertPoint:[event locationInWindow] toView:object]; |
322 | 321 SEL spmb = NSSelectorFromString(@"pressedMouseButtons"); |
323 if(DWOSMinor < 6) | 322 IMP ipmb = [[NSEvent class] respondsToSelector:spmb] ? [[NSEvent class] methodForSelector:spmb] : 0; |
324 { | 323 int buttonmask = ipmb ? (int)ipmb([NSEvent class], spmb) : (1 << [event buttonNumber]); |
325 buttonmask = (1 << [event buttonNumber]); | 324 |
326 } | |
327 | |
328 return motionfunc(object, (int)p.x, (int)p.y, buttonmask, handler->data); | 325 return motionfunc(object, (int)p.x, (int)p.y, buttonmask, handler->data); |
329 } | 326 } |
330 /* Window close event */ | 327 /* Window close event */ |
331 case 6: | 328 case 6: |
332 { | 329 { |
591 _DWLastDrawable = bltinfo->dest; | 588 _DWLastDrawable = bltinfo->dest; |
592 } | 589 } |
593 if([bltsrc isMemberOfClass:[NSBitmapImageRep class]]) | 590 if([bltsrc isMemberOfClass:[NSBitmapImageRep class]]) |
594 { | 591 { |
595 NSBitmapImageRep *rep = bltsrc; | 592 NSBitmapImageRep *rep = bltsrc; |
596 NSImage *image; | 593 NSImage *image = [NSImage alloc]; |
597 | 594 SEL siwc = NSSelectorFromString(@"initWithCGImage"); |
598 if(DWOSMinor > 5) | 595 |
599 { | 596 if([image respondsToSelector:siwc]) |
600 image = [[NSImage alloc] initWithCGImage:[rep CGImage] size:NSZeroSize]; | 597 { |
598 IMP iiwc = [image methodForSelector:siwc]; | |
599 image = iiwc(image, siwc, [rep CGImage], NSZeroSize); | |
601 } | 600 } |
602 else | 601 else |
603 { | 602 { |
604 image = [[NSImage alloc] initWithSize:[rep size]]; | 603 image = [image initWithSize:[rep size]]; |
605 [image addRepresentation:rep]; | 604 [image addRepresentation:rep]; |
606 } | 605 } |
607 if(bltinfo->srcwidth != -1) | 606 if(bltinfo->srcwidth != -1) |
608 { | 607 { |
609 [image drawInRect:NSMakeRect(bltinfo->xdest, bltinfo->ydest, bltinfo->width, bltinfo->height) | 608 [image drawInRect:NSMakeRect(bltinfo->xdest, bltinfo->ydest, bltinfo->width, bltinfo->height) |
1873 -(int)lastQueryPoint { return lastQueryPoint; } | 1872 -(int)lastQueryPoint { return lastQueryPoint; } |
1874 -(void)setLastQueryPoint:(int)input { lastQueryPoint = input; } | 1873 -(void)setLastQueryPoint:(int)input { lastQueryPoint = input; } |
1875 -(void)clear { if(data) { [data removeAllObjects]; while([titles count]) { [titles removePointerAtIndex:0]; } } lastAddPoint = 0; } | 1874 -(void)clear { if(data) { [data removeAllObjects]; while([titles count]) { [titles removePointerAtIndex:0]; } } lastAddPoint = 0; } |
1876 -(void)setup | 1875 -(void)setup |
1877 { | 1876 { |
1877 SEL swopa = NSSelectorFromString(@"weakObjectsPointerArray"); | |
1878 | |
1879 if(![[NSPointerArray class] respondsToSelector:swopa]) | |
1880 swopa = NSSelectorFromString(@"pointerArrayWithWeakObjects"); | |
1881 if(![[NSPointerArray class] respondsToSelector:swopa]) | |
1882 return; | |
1883 | |
1884 IMP iwopa = [[NSPointerArray class] methodForSelector:swopa]; | |
1885 | |
1886 titles = iwopa([NSPointerArray class], swopa); | |
1887 [titles retain]; | |
1878 tvcols = [[[NSMutableArray alloc] init] retain]; | 1888 tvcols = [[[NSMutableArray alloc] init] retain]; |
1879 data = [[[NSMutableArray alloc] init] retain]; | 1889 data = [[[NSMutableArray alloc] init] retain]; |
1880 types = [[[NSMutableArray alloc] init] retain]; | 1890 types = [[[NSMutableArray alloc] init] retain]; |
1881 titles = [[NSPointerArray pointerArrayWithWeakObjects] retain]; | 1891 |
1882 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectionChanged:) name:NSTableViewSelectionDidChangeNotification object:self]; | 1892 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectionChanged:) name:NSTableViewSelectionDidChangeNotification object:self]; |
1883 } | 1893 } |
1884 -(NSSize)getsize | 1894 -(NSSize)getsize |
1885 { | 1895 { |
1886 int cwidth = 0, cheight = 0; | 1896 int cwidth = 0, cheight = 0; |
3259 { | 3269 { |
3260 /* Create the File Open Dialog class. */ | 3270 /* Create the File Open Dialog class. */ |
3261 NSOpenPanel* openDlg = [NSOpenPanel openPanel]; | 3271 NSOpenPanel* openDlg = [NSOpenPanel openPanel]; |
3262 | 3272 |
3263 if(path) | 3273 if(path) |
3264 [openDlg setDirectoryURL:[NSURL fileURLWithPath:[NSString stringWithUTF8String:path]]]; | 3274 { |
3275 SEL ssdu = NSSelectorFromString(@"setDirectoryURL"); | |
3276 | |
3277 if([openDlg respondsToSelector:ssdu]) | |
3278 { | |
3279 IMP isdu = [openDlg methodForSelector:ssdu]; | |
3280 isdu(openDlg, ssdu, [NSURL fileURLWithPath:[NSString stringWithUTF8String:path]]); | |
3281 } | |
3282 } | |
3265 | 3283 |
3266 /* Enable the selection of files in the dialog. */ | 3284 /* Enable the selection of files in the dialog. */ |
3267 if(flags == DW_FILE_OPEN) | 3285 if(flags == DW_FILE_OPEN) |
3268 { | 3286 { |
3269 [openDlg setCanChooseFiles:YES]; | 3287 [openDlg setCanChooseFiles:YES]; |
3307 { | 3325 { |
3308 /* Create the File Save Dialog class. */ | 3326 /* Create the File Save Dialog class. */ |
3309 NSSavePanel* saveDlg = [NSSavePanel savePanel]; | 3327 NSSavePanel* saveDlg = [NSSavePanel savePanel]; |
3310 | 3328 |
3311 if(path) | 3329 if(path) |
3312 [saveDlg setDirectoryURL:[NSURL fileURLWithPath:[NSString stringWithUTF8String:path]]]; | 3330 { |
3331 SEL ssdu = NSSelectorFromString(@"setDirectoryURL"); | |
3332 | |
3333 if([saveDlg respondsToSelector:ssdu]) | |
3334 { | |
3335 IMP isdu = [saveDlg methodForSelector:ssdu]; | |
3336 isdu(saveDlg, ssdu, [NSURL fileURLWithPath:[NSString stringWithUTF8String:path]]); | |
3337 } | |
3338 } | |
3313 if(file) | 3339 if(file) |
3314 [saveDlg setNameFieldStringValue:[NSString stringWithUTF8String:file]]; | 3340 { |
3341 SEL ssnfsv = NSSelectorFromString(@"setNameFieldStringValue"); | |
3342 | |
3343 if([saveDlg respondsToSelector:ssnfsv]) | |
3344 { | |
3345 IMP isnfsv = [saveDlg methodForSelector:ssnfsv]; | |
3346 isnfsv(saveDlg, ssnfsv, [NSString stringWithUTF8String:file]); | |
3347 } | |
3348 } | |
3315 | 3349 |
3316 /* Enable the creation of directories in the dialog. */ | 3350 /* Enable the creation of directories in the dialog. */ |
3317 [saveDlg setCanCreateDirectories:YES]; | 3351 [saveDlg setCanCreateDirectories:YES]; |
3318 | 3352 |
3319 /* Handle file types */ | 3353 /* Handle file types */ |
3369 * Text. | 3403 * Text. |
3370 */ | 3404 */ |
3371 void dw_clipboard_set_text( char *str, int len) | 3405 void dw_clipboard_set_text( char *str, int len) |
3372 { | 3406 { |
3373 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; | 3407 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; |
3374 | 3408 SEL scc = NSSelectorFromString(@"clearContents"); |
3375 /* Only in Snow Leopard */ | 3409 |
3376 if(DWOSMinor > 5) | 3410 if([pasteboard respondsToSelector:scc]) |
3377 { | 3411 { |
3378 [pasteboard clearContents]; | 3412 IMP icc = [pasteboard methodForSelector:scc]; |
3413 icc(pasteboard, scc); | |
3379 } | 3414 } |
3380 | 3415 |
3381 [pasteboard setString:[ NSString stringWithUTF8String:str ] forType:NSStringPboardType]; | 3416 [pasteboard setString:[ NSString stringWithUTF8String:str ] forType:NSStringPboardType]; |
3382 } | 3417 } |
3383 | 3418 |
8346 */ | 8381 */ |
8347 void API dw_window_set_style(HWND handle, ULONG style, ULONG mask) | 8382 void API dw_window_set_style(HWND handle, ULONG style, ULONG mask) |
8348 { | 8383 { |
8349 id object = handle; | 8384 id object = handle; |
8350 | 8385 |
8351 if(DWOSMinor > 5 && [object isMemberOfClass:[DWWindow class]]) | 8386 if([object isMemberOfClass:[DWWindow class]]) |
8352 { | 8387 { |
8353 DWWindow *window = object; | 8388 DWWindow *window = object; |
8354 int currentstyle = (int)[window styleMask]; | 8389 SEL sssm = NSSelectorFromString(@"setStyleMask"); |
8355 int tmp; | 8390 |
8356 | 8391 if([window respondsToSelector:sssm]) |
8357 tmp = currentstyle | (int)mask; | 8392 { |
8358 tmp ^= mask; | 8393 IMP issm = [window methodForSelector:sssm]; |
8359 tmp |= style; | 8394 int currentstyle = (int)[window styleMask]; |
8360 | 8395 int tmp; |
8361 [window setStyleMask:tmp]; | 8396 |
8397 tmp = currentstyle | (int)mask; | |
8398 tmp ^= mask; | |
8399 tmp |= style; | |
8400 | |
8401 issm(window, sssm, tmp); | |
8402 } | |
8362 } | 8403 } |
8363 else if([object isKindOfClass:[NSTextField class]]) | 8404 else if([object isKindOfClass:[NSTextField class]]) |
8364 { | 8405 { |
8365 NSTextField *tf = object; | 8406 NSTextField *tf = object; |
8366 | 8407 |