2002-06-14 09:44:29 -06:00
|
|
|
//
|
|
|
|
// CelestiaOpenGLView.m
|
|
|
|
// celestia
|
|
|
|
//
|
|
|
|
// Created by Bob Ippolito on Tue May 28 2002.
|
|
|
|
// Copyright (c) 2002 Chris Laurel. All rights reserved.
|
|
|
|
//
|
|
|
|
#import "CelestiaOpenGLView.h"
|
2002-08-01 15:29:05 -06:00
|
|
|
#import "CelestiaAppCore.h"
|
2002-06-14 09:44:29 -06:00
|
|
|
#import <OpenGL/gl.h>
|
2006-05-14 11:48:05 -06:00
|
|
|
#import <OpenGL/glext.h>
|
2006-11-02 19:37:35 -07:00
|
|
|
#import <OpenGL/CGLTypes.h>
|
2006-05-14 11:48:05 -06:00
|
|
|
|
|
|
|
#ifndef ATI_FSAA_LEVEL
|
|
|
|
#define ATI_FSAA_LEVEL 510
|
|
|
|
#endif
|
2002-06-14 09:44:29 -06:00
|
|
|
|
2002-08-01 15:29:05 -06:00
|
|
|
#define CEL_LEFT_BUTTON 1
|
|
|
|
#define CEL_MIDDLE_BUTTON 2
|
|
|
|
#define CEL_RIGHT_BUTTON 4
|
|
|
|
|
|
|
|
//static CelestiaAppCore* appCore = nil;
|
|
|
|
//static NSPoint lastLoc = NSMakePoint(0.0, 0.0);
|
|
|
|
|
2002-06-14 09:44:29 -06:00
|
|
|
@implementation CelestiaOpenGLView
|
2003-03-16 00:38:04 -07:00
|
|
|
|
2004-12-18 13:54:50 -07:00
|
|
|
- (id) initWithCoder: (NSCoder *) coder
|
2006-05-14 11:48:05 -06:00
|
|
|
{
|
2004-12-18 13:54:50 -07:00
|
|
|
NSOpenGLPixelFormatAttribute attrs[] =
|
2002-08-01 15:29:05 -06:00
|
|
|
{
|
2004-12-18 13:54:50 -07:00
|
|
|
NSOpenGLPFADoubleBuffer,
|
2004-12-22 12:49:02 -07:00
|
|
|
NSOpenGLPFADepthSize,
|
2007-05-25 20:18:34 -06:00
|
|
|
(NSOpenGLPixelFormatAttribute)32,
|
2004-12-18 13:54:50 -07:00
|
|
|
nil
|
|
|
|
} ;
|
|
|
|
|
|
|
|
NSOpenGLPixelFormat* pixFmt ;
|
|
|
|
long swapInterval ;
|
2002-08-01 15:29:05 -06:00
|
|
|
|
2004-12-18 13:54:50 -07:00
|
|
|
self = [super initWithCoder: coder] ;
|
2004-12-22 12:49:02 -07:00
|
|
|
if (self)
|
|
|
|
{
|
2006-05-14 11:48:05 -06:00
|
|
|
pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes: attrs];
|
2004-12-18 13:54:50 -07:00
|
|
|
|
2004-12-22 12:49:02 -07:00
|
|
|
if (pixFmt)
|
|
|
|
{
|
|
|
|
[self setPixelFormat: pixFmt] ;
|
|
|
|
[pixFmt release];
|
2004-12-18 13:54:50 -07:00
|
|
|
|
2006-11-19 08:33:27 -07:00
|
|
|
if (0 == CGLEnable([[self openGLContext] CGLContextObj], 313))
|
2006-11-02 19:37:35 -07:00
|
|
|
{
|
|
|
|
NSLog(@"Multithreaded OpenGL enabled.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSLog(@"Multithreaded OpenGL not supported on your system.");
|
|
|
|
}
|
2006-11-19 08:33:27 -07:00
|
|
|
|
2004-12-22 12:49:02 -07:00
|
|
|
swapInterval = 1 ;
|
2004-12-18 13:54:50 -07:00
|
|
|
|
2004-12-22 12:49:02 -07:00
|
|
|
[[self openGLContext]
|
|
|
|
setValues: &swapInterval
|
|
|
|
forParameter: NSOpenGLCPSwapInterval ] ;
|
|
|
|
}
|
2006-05-14 11:48:05 -06:00
|
|
|
else
|
|
|
|
{
|
|
|
|
[self release];
|
|
|
|
return nil;
|
|
|
|
}
|
2004-12-22 12:49:02 -07:00
|
|
|
}
|
2006-05-14 11:48:05 -06:00
|
|
|
|
2004-12-18 13:54:50 -07:00
|
|
|
return self;
|
2002-08-01 15:29:05 -06:00
|
|
|
}
|
2004-12-22 12:49:02 -07:00
|
|
|
|
2006-05-14 11:48:05 -06:00
|
|
|
- (void)setAASamples: (unsigned int)aaSamples
|
|
|
|
{
|
|
|
|
if (aaSamples > 1)
|
|
|
|
{
|
|
|
|
const char *glRenderer = (const char *) glGetString(GL_RENDERER);
|
|
|
|
|
|
|
|
if (strstr(glRenderer, "ATI"))
|
|
|
|
{
|
|
|
|
[[self openGLContext] setValues: (const long *)&aaSamples
|
|
|
|
forParameter: ATI_FSAA_LEVEL];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSOpenGLPixelFormat *pixFmt;
|
|
|
|
NSOpenGLContext *context;
|
|
|
|
|
|
|
|
NSOpenGLPixelFormatAttribute fsaaAttrs[] =
|
|
|
|
{
|
|
|
|
NSOpenGLPFADoubleBuffer,
|
|
|
|
NSOpenGLPFADepthSize,
|
2007-05-25 20:18:34 -06:00
|
|
|
(NSOpenGLPixelFormatAttribute)32,
|
2006-05-14 11:48:05 -06:00
|
|
|
NSOpenGLPFASampleBuffers,
|
|
|
|
(NSOpenGLPixelFormatAttribute)1,
|
|
|
|
NSOpenGLPFASamples,
|
|
|
|
(NSOpenGLPixelFormatAttribute)1,
|
|
|
|
nil
|
|
|
|
};
|
|
|
|
|
|
|
|
fsaaAttrs[6] = aaSamples;
|
|
|
|
|
|
|
|
pixFmt =
|
|
|
|
[[NSOpenGLPixelFormat alloc] initWithAttributes: fsaaAttrs];
|
|
|
|
|
|
|
|
if (pixFmt)
|
|
|
|
{
|
|
|
|
context = [[NSOpenGLContext alloc] initWithFormat: pixFmt
|
|
|
|
shareContext: nil];
|
|
|
|
[pixFmt release];
|
|
|
|
|
|
|
|
if (context)
|
|
|
|
{
|
2006-11-19 08:33:27 -07:00
|
|
|
// The following silently fails if not supported
|
|
|
|
CGLEnable([context CGLContextObj], 313);
|
|
|
|
|
2006-05-14 11:48:05 -06:00
|
|
|
long swapInterval = 1;
|
|
|
|
[context setValues: &swapInterval
|
|
|
|
forParameter: NSOpenGLCPSwapInterval];
|
|
|
|
[self setOpenGLContext: context];
|
|
|
|
[context setView: self];
|
|
|
|
[context makeCurrentContext];
|
|
|
|
[context release];
|
|
|
|
|
|
|
|
glEnable(GL_MULTISAMPLE_ARB);
|
|
|
|
// GL_NICEST enables Quincunx on supported NVIDIA cards,
|
|
|
|
// but smears text.
|
|
|
|
// glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-16 00:38:04 -07:00
|
|
|
|
|
|
|
- (BOOL) isFlipped {return YES;}
|
|
|
|
|
2006-06-29 10:20:53 -06:00
|
|
|
- (void) viewDidMoveToWindow
|
|
|
|
{
|
|
|
|
[[self window] setAcceptsMouseMovedEvents: YES];
|
|
|
|
}
|
|
|
|
|
2003-06-08 11:32:48 -06:00
|
|
|
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
|
|
|
|
{
|
|
|
|
CelestiaSelection* selection;
|
|
|
|
NSString* selectionName;
|
|
|
|
NSPoint location = [self convertPoint: [theEvent locationInWindow] fromView: self];
|
|
|
|
NSPoint location2 = [self convertPoint: [theEvent locationInWindow] fromView: nil];
|
|
|
|
CelestiaAppCore *appCore = [CelestiaAppCore sharedAppCore];
|
|
|
|
|
2005-05-28 11:30:52 -06:00
|
|
|
[appCore charEntered: 8 withModifiers:0];
|
2003-06-08 11:32:48 -06:00
|
|
|
[appCore mouseButtonDown:location modifiers:[appCore toCelestiaModifiers:NULL buttons:CEL_LEFT_BUTTON]];
|
|
|
|
[appCore mouseButtonUp:location2 modifiers:[appCore toCelestiaModifiers:NULL buttons:CEL_LEFT_BUTTON]];
|
|
|
|
|
|
|
|
selection = [[appCore simulation] selection];
|
|
|
|
selectionName = [[[appCore simulation] selection] briefName];
|
|
|
|
if ([selectionName isEqualToString: @""])
|
|
|
|
{
|
|
|
|
[appCore mouseButtonDown:location modifiers:[appCore toCelestiaModifiers:NULL buttons:CEL_LEFT_BUTTON]];
|
|
|
|
[appCore mouseButtonUp:location2 modifiers:[appCore toCelestiaModifiers:NULL buttons:CEL_LEFT_BUTTON]];
|
|
|
|
selection = [[appCore simulation] selection];
|
|
|
|
selectionName = [[[appCore simulation] selection] name];
|
|
|
|
}
|
|
|
|
if ([selectionName isEqualToString: @""]) return NULL;
|
|
|
|
[[[self menu] itemAtIndex: 0] setTitle: selectionName ];
|
|
|
|
[[[self menu] itemAtIndex: 0] setEnabled: YES ];
|
2004-12-18 13:54:50 -07:00
|
|
|
[ controller addSurfaceMenu: [self menu] ];
|
2003-11-29 16:28:25 -07:00
|
|
|
// [ [self menu] setAutoenablesItems: NO ];
|
2003-06-08 11:32:48 -06:00
|
|
|
return [self menu];
|
|
|
|
}
|
|
|
|
|
2002-08-01 15:29:05 -06:00
|
|
|
- (void) keyDown: (NSEvent*)theEvent
|
|
|
|
{
|
2003-03-16 00:38:04 -07:00
|
|
|
CelestiaAppCore *appCore = [CelestiaAppCore sharedAppCore];
|
2005-05-28 11:30:52 -06:00
|
|
|
NSString *eventChars = [theEvent characters];
|
|
|
|
if (!eventChars || [eventChars length] == 0)
|
|
|
|
{
|
|
|
|
eventChars = [theEvent charactersIgnoringModifiers];
|
|
|
|
if (!eventChars || [eventChars length] == 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
unichar key = [eventChars characterAtIndex: 0];
|
|
|
|
int modifiers = [appCore toCelestiaModifiers: [theEvent modifierFlags] buttons: 0];
|
2003-06-08 11:32:48 -06:00
|
|
|
|
|
|
|
if (key == 127)
|
2005-05-28 11:30:52 -06:00
|
|
|
key = 8; // delete = backspace
|
|
|
|
else if ( key == NSDeleteFunctionKey || key == NSClearLineFunctionKey )
|
2003-06-08 11:32:48 -06:00
|
|
|
key = 127; // del = delete
|
2005-05-28 11:30:52 -06:00
|
|
|
|
2004-01-10 22:45:24 -07:00
|
|
|
if ( (key<128) && ((key < '0') || (key>'9') || !([theEvent modifierFlags] & NSNumericPadKeyMask)) )
|
2005-05-28 11:30:52 -06:00
|
|
|
[ appCore charEntered: key
|
|
|
|
withModifiers: modifiers];
|
|
|
|
|
2003-12-19 11:59:03 -07:00
|
|
|
[ appCore keyDown: [appCore toCelestiaKey: theEvent]
|
2005-05-28 11:30:52 -06:00
|
|
|
withModifiers: modifiers ];
|
2002-08-01 15:29:05 -06:00
|
|
|
}
|
2003-03-16 00:38:04 -07:00
|
|
|
|
2002-08-01 15:29:05 -06:00
|
|
|
- (void) keyUp: (NSEvent*)theEvent
|
|
|
|
{
|
2003-03-16 00:38:04 -07:00
|
|
|
CelestiaAppCore *appCore = [CelestiaAppCore sharedAppCore];
|
|
|
|
// if ( [[theEvent characters] characterAtIndex: 0] >= 128 )
|
2003-12-19 11:59:03 -07:00
|
|
|
// [ appCore keyUp: [appCore toCelestiaKey: theEvent] ];
|
|
|
|
[ appCore keyUp: [appCore toCelestiaKey: theEvent]
|
|
|
|
withModifiers: [appCore toCelestiaModifiers: [theEvent modifierFlags] buttons: 0] ];
|
2003-03-16 00:38:04 -07:00
|
|
|
// NSLog(@"keyUp: %@",theEvent);
|
2002-08-01 15:29:05 -06:00
|
|
|
}
|
2003-03-16 00:38:04 -07:00
|
|
|
|
2002-08-01 15:29:05 -06:00
|
|
|
- (void) mouseDown: (NSEvent*)theEvent
|
|
|
|
{
|
2004-12-22 12:49:02 -07:00
|
|
|
[ [self window] makeFirstResponder: self ];
|
|
|
|
|
|
|
|
NSPoint location = [self convertPoint: [theEvent locationInWindow] fromView: nil];
|
2002-08-01 15:29:05 -06:00
|
|
|
CelestiaAppCore *appCore = [CelestiaAppCore sharedAppCore];
|
|
|
|
[appCore mouseButtonDown:location modifiers:[appCore toCelestiaModifiers:[theEvent modifierFlags] buttons:CEL_LEFT_BUTTON]];
|
|
|
|
}
|
2003-03-16 00:38:04 -07:00
|
|
|
|
2002-08-01 15:29:05 -06:00
|
|
|
- (void) mouseUp: (NSEvent*)theEvent
|
|
|
|
{
|
2006-09-07 09:12:04 -06:00
|
|
|
if ( [theEvent modifierFlags] & NSAlternateKeyMask )
|
|
|
|
{
|
|
|
|
[self otherMouseUp: theEvent];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-08-01 15:29:05 -06:00
|
|
|
NSPoint location = [self convertPoint: [theEvent locationInWindow] fromView: nil];
|
|
|
|
CelestiaAppCore *appCore = [CelestiaAppCore sharedAppCore];
|
|
|
|
[appCore mouseButtonUp:location modifiers:[appCore toCelestiaModifiers:[theEvent modifierFlags] buttons:CEL_LEFT_BUTTON]];
|
|
|
|
}
|
2006-06-29 10:20:53 -06:00
|
|
|
|
2002-08-01 15:29:05 -06:00
|
|
|
- (void) mouseDragged: (NSEvent*) theEvent
|
|
|
|
{
|
2003-03-16 00:38:04 -07:00
|
|
|
if ( [theEvent modifierFlags] & NSAlternateKeyMask )
|
|
|
|
{
|
|
|
|
[self rightMouseDragged: theEvent];
|
|
|
|
return;
|
|
|
|
}
|
2006-06-29 10:20:53 -06:00
|
|
|
|
2002-08-01 15:29:05 -06:00
|
|
|
CelestiaAppCore *appCore = [CelestiaAppCore sharedAppCore];
|
|
|
|
[appCore mouseMove:NSMakePoint([theEvent deltaX], [theEvent deltaY]) modifiers:[appCore toCelestiaModifiers:[theEvent modifierFlags] buttons:CEL_LEFT_BUTTON]];
|
|
|
|
}
|
2006-06-29 10:20:53 -06:00
|
|
|
|
|
|
|
- (void) mouseMoved: (NSEvent*)theEvent
|
|
|
|
{
|
|
|
|
CelestiaAppCore *appCore = [CelestiaAppCore sharedAppCore];
|
|
|
|
NSPoint location = [self convertPoint: [theEvent locationInWindow] fromView: nil];
|
|
|
|
[appCore mouseMove: location];
|
|
|
|
}
|
|
|
|
|
2002-08-01 15:29:05 -06:00
|
|
|
- (void) rightMouseDown: (NSEvent*)theEvent
|
|
|
|
{
|
|
|
|
NSPoint location = [self convertPoint: [theEvent locationInWindow] fromView: nil];
|
|
|
|
CelestiaAppCore *appCore = [CelestiaAppCore sharedAppCore];
|
|
|
|
[appCore mouseButtonDown:location modifiers:[appCore toCelestiaModifiers:[theEvent modifierFlags] buttons:CEL_RIGHT_BUTTON]];
|
|
|
|
}
|
2006-06-29 10:20:53 -06:00
|
|
|
|
2002-08-01 15:29:05 -06:00
|
|
|
- (void) rightMouseUp: (NSEvent*)theEvent
|
|
|
|
{
|
|
|
|
NSPoint location = [self convertPoint: [theEvent locationInWindow] fromView: nil];
|
|
|
|
CelestiaAppCore *appCore = [CelestiaAppCore sharedAppCore];
|
|
|
|
[appCore mouseButtonUp:location modifiers:[appCore toCelestiaModifiers:[theEvent modifierFlags] buttons:CEL_RIGHT_BUTTON]];
|
2004-12-22 12:49:02 -07:00
|
|
|
if([theEvent clickCount] > 0)
|
|
|
|
[super rightMouseDown:theEvent]; //...Force context menu to appear only on clicks (not drags)
|
2002-08-01 15:29:05 -06:00
|
|
|
}
|
2003-03-16 00:38:04 -07:00
|
|
|
|
2002-08-01 15:29:05 -06:00
|
|
|
- (void) rightMouseDragged: (NSEvent*) theEvent
|
|
|
|
{
|
|
|
|
CelestiaAppCore *appCore = [CelestiaAppCore sharedAppCore];
|
|
|
|
[appCore mouseMove:NSMakePoint([theEvent deltaX], [theEvent deltaY]) modifiers:[appCore toCelestiaModifiers:[theEvent modifierFlags] buttons:CEL_RIGHT_BUTTON]];
|
|
|
|
}
|
2003-03-16 00:38:04 -07:00
|
|
|
|
2006-09-07 09:12:04 -06:00
|
|
|
- (void) otherMouseDown: (NSEvent *) theEvent
|
|
|
|
{
|
|
|
|
NSPoint location = [self convertPoint: [theEvent locationInWindow] fromView: nil];
|
|
|
|
CelestiaAppCore *appCore = [CelestiaAppCore sharedAppCore];
|
|
|
|
[appCore mouseButtonDown:location modifiers:[appCore toCelestiaModifiers:[theEvent modifierFlags] buttons:CEL_MIDDLE_BUTTON]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) otherMouseUp: (NSEvent *) theEvent
|
|
|
|
{
|
|
|
|
NSPoint location = [self convertPoint: [theEvent locationInWindow] fromView: nil];
|
|
|
|
CelestiaAppCore *appCore = [CelestiaAppCore sharedAppCore];
|
|
|
|
[appCore mouseButtonUp:location modifiers:[appCore toCelestiaModifiers:[theEvent modifierFlags] buttons:CEL_MIDDLE_BUTTON]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) otherMouseDragged: (NSEvent *) theEvent
|
|
|
|
{
|
|
|
|
CelestiaAppCore *appCore = [CelestiaAppCore sharedAppCore];
|
|
|
|
[appCore mouseMove:NSMakePoint([theEvent deltaX], [theEvent deltaY]) modifiers:[appCore toCelestiaModifiers:[theEvent modifierFlags] buttons:CEL_MIDDLE_BUTTON]];
|
|
|
|
}
|
|
|
|
|
2003-03-16 00:38:04 -07:00
|
|
|
- (void) scrollWheel: (NSEvent*)theEvent
|
|
|
|
{
|
|
|
|
CelestiaAppCore *appCore = [CelestiaAppCore sharedAppCore];
|
2004-12-22 12:49:02 -07:00
|
|
|
[ appCore mouseWheel: [theEvent deltaY]
|
2003-03-16 00:38:04 -07:00
|
|
|
modifiers: [appCore toCelestiaModifiers: [theEvent modifierFlags] buttons: 0] ];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) acceptsFirstResponder: (NSEvent*)theEvent
|
|
|
|
{
|
2004-12-18 13:54:50 -07:00
|
|
|
// NSLog(@"CelestiaOpenGLView acceptsFirstResponder" );
|
2003-03-16 00:38:04 -07:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) becomeFirstResponder
|
|
|
|
{
|
2004-12-18 13:54:50 -07:00
|
|
|
// NSLog(@"CelestiaOpenGLView becomeFirstResponder" );
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) resignFirstResponder
|
|
|
|
{
|
|
|
|
// NSLog(@"CelestiaOpenGLView resignFirstResponder" );
|
2003-03-16 00:38:04 -07:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2002-08-01 15:29:05 -06:00
|
|
|
- (BOOL) acceptsFirstMouse: (NSEvent*)theEvent
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2002-06-14 09:44:29 -06:00
|
|
|
- (void) drawRect: (NSRect) rect
|
|
|
|
{
|
2005-02-04 23:49:44 -07:00
|
|
|
NSOpenGLContext *oglContext;
|
|
|
|
oglContext = [self openGLContext];
|
|
|
|
if (oglContext != nil)
|
|
|
|
{
|
|
|
|
[controller display];
|
|
|
|
[oglContext flushBuffer];
|
|
|
|
}
|
2002-06-14 09:44:29 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) update
|
|
|
|
{
|
2005-02-04 23:49:44 -07:00
|
|
|
[controller setDirty];
|
|
|
|
[super update];
|
2002-06-14 09:44:29 -06:00
|
|
|
}
|
|
|
|
|
2003-03-16 00:38:04 -07:00
|
|
|
- (void) writeStringToPasteboard: (NSPasteboard *) pb
|
|
|
|
{
|
|
|
|
NSString *value;
|
|
|
|
[pb declareTypes:
|
|
|
|
[NSArray arrayWithObject: NSStringPboardType] owner: self];
|
2005-02-04 23:49:44 -07:00
|
|
|
CelestiaAppCore *appCore = [CelestiaAppCore sharedAppCore];
|
|
|
|
value = [appCore currentURL];
|
|
|
|
[ pb setString: value forType: NSStringPboardType ];
|
2003-03-16 00:38:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) readStringFromPasteboard: (NSPasteboard *) pb
|
|
|
|
{
|
2004-12-18 13:54:50 -07:00
|
|
|
NSString *value = nil;
|
2003-03-16 00:38:04 -07:00
|
|
|
NSString *type = [pb availableTypeFromArray:
|
2004-12-18 13:54:50 -07:00
|
|
|
[NSArray arrayWithObjects: NSURLPboardType, NSFilenamesPboardType, NSStringPboardType, nil ]];
|
2005-04-23 08:18:32 -06:00
|
|
|
//NSLog(@"read paste");
|
2003-03-16 00:38:04 -07:00
|
|
|
if ( type != nil )
|
|
|
|
{
|
2003-11-29 16:28:25 -07:00
|
|
|
CelestiaAppCore *appCore = [CelestiaAppCore sharedAppCore];
|
2004-12-18 13:54:50 -07:00
|
|
|
// value = [ pb stringForType: NSURLPboardType ];
|
|
|
|
value = [ pb stringForType: NSStringPboardType ];
|
|
|
|
if (value != nil )
|
|
|
|
{
|
|
|
|
NSLog(value);
|
|
|
|
if ( [value rangeOfString:@"cel:" options: (NSCaseInsensitiveSearch|NSAnchoredSearch) ].location == 0 )
|
|
|
|
[appCore goToUrl: value ];
|
|
|
|
else
|
|
|
|
[appCore runScript: value ];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value = [[NSURL URLWithString: (NSString*) [((NSArray*)[ pb propertyListForType: type ]) objectAtIndex: 0 ]] path];
|
|
|
|
NSLog(value);
|
2005-01-02 17:17:50 -07:00
|
|
|
[controller runScript: value ];
|
2004-12-18 13:54:50 -07:00
|
|
|
|
|
|
|
return NO;
|
|
|
|
if (value != nil)
|
|
|
|
{
|
|
|
|
value = [ pb stringForType: NSFilenamesPboardType ];
|
|
|
|
if (value != nil )
|
|
|
|
{
|
|
|
|
NSLog(value);
|
2005-01-02 17:17:50 -07:00
|
|
|
[controller runScript: value ];
|
2004-12-18 13:54:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-03-16 00:38:04 -07:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
- (unsigned int) draggingEntered: (id <NSDraggingInfo>) sender
|
|
|
|
{
|
|
|
|
NSPasteboard *pb = [sender draggingPasteboard];
|
|
|
|
NSString *type = [pb availableTypeFromArray:
|
2004-12-18 13:54:50 -07:00
|
|
|
[NSArray arrayWithObjects: NSStringPboardType, NSFilenamesPboardType, nil ]];
|
2005-04-23 08:18:32 -06:00
|
|
|
// NSLog(@"dragentered");
|
2003-03-16 00:38:04 -07:00
|
|
|
if ( type != nil )
|
|
|
|
{
|
|
|
|
return NSDragOperationCopy;
|
|
|
|
}
|
|
|
|
return NSDragOperationNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
|
|
|
|
{
|
|
|
|
NSPasteboard *pb = [sender draggingPasteboard];
|
|
|
|
return [ self readStringFromPasteboard: pb ];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction) paste: (id) sender
|
|
|
|
{
|
|
|
|
NSPasteboard *pb = [NSPasteboard generalPasteboard];
|
|
|
|
[ self readStringFromPasteboard: pb ];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction) copy: (id) sender
|
|
|
|
{
|
|
|
|
NSPasteboard *pb = [NSPasteboard generalPasteboard];
|
|
|
|
[ self writeStringToPasteboard: pb ];
|
|
|
|
}
|
|
|
|
|
2002-06-14 09:44:29 -06:00
|
|
|
@end
|