comparison dwt/program/Program.d @ 122:2e671fa40eec

Ported dwt.dnd, dwt.opengl, dwt.printing and dwt.program
author Jacob Carlborg <doob@me.com>
date Wed, 31 Dec 2008 21:01:13 +0100
parents e1c48e37e0f5
children 07399639c0c8
comparison
equal deleted inserted replaced
121:e1c48e37e0f5 122:2e671fa40eec
219 vector.addElement(getProgram(bundle)); 219 vector.addElement(getProgram(bundle));
220 } 220 }
221 } 221 }
222 } 222 }
223 } 223 }
224 vector.dup; 224 return vector.dup;
225 } finally { 225 } finally {
226 pool.release(); 226 pool.release();
227 } 227 }
228 } 228 }
229 229
243 public static bool launch (String fileName) { 243 public static bool launch (String fileName) {
244 if (fileName is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); 244 if (fileName is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
245 NSAutoreleasePool pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); 245 NSAutoreleasePool pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
246 try { 246 try {
247 NSString unescapedStr = NSString.stringWith("%"); //$NON-NLS-1$ 247 NSString unescapedStr = NSString.stringWith("%"); //$NON-NLS-1$
248 if (fileName.indexOf(':') is -1) { 248 if (dwt.dwthelper.utils.indexOf(fileName, ':') is -1) {
249 fileName = PREFIX_FILE + fileName; 249 fileName = PREFIX_FILE ~ fileName;
250 } else { 250 } else {
251 String lowercaseName = fileName.toLowerCase (); 251 String lowercaseName = fileName.toLowerCase ();
252 if (lowercaseName.startsWith (PREFIX_HTTP) || lowercaseName.startsWith (PREFIX_HTTPS)) { 252 if (lowercaseName.startsWith (PREFIX_HTTP) || lowercaseName.startsWith (PREFIX_HTTPS)) {
253 unescapedStr = NSString.stringWith("%#"); //$NON-NLS-1$ 253 unescapedStr = NSString.stringWith("%#"); //$NON-NLS-1$
254 } 254 }
255 } 255 }
256 NSString fullPath = NSString.stringWith(fileName); 256 NSString fullPath = NSString.stringWith(fileName);
257 CFStringRef ptr = OS.CFURLCreateStringByAddingPercentEscapes(null, fullPath.id, unescapedStr.id, null, OS.kCFStringEncodingUTF8); 257 CFStringRef ptr = OS.CFURLCreateStringByAddingPercentEscapes(null, cast(CFStringRef) fullPath.id, cast(CFStringRef) unescapedStr.id, null, OS.kCFStringEncodingUTF8);
258 NSString escapedString = new NSString(ptr); 258 NSString escapedString = new NSString(cast(objc.id)ptr);
259 NSWorkspace workspace = NSWorkspace.sharedWorkspace(); 259 NSWorkspace workspace = NSWorkspace.sharedWorkspace();
260 bool result = workspace.openURL(NSURL.URLWithString(escapedString)); 260 bool result = workspace.openURL(NSURL.URLWithString(escapedString));
261 OS.CFRelease(ptr); 261 OS.CFRelease(ptr);
262 return result; 262 return result;
263 } finally { 263 } finally {
282 if (fileName is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 282 if (fileName is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
283 NSAutoreleasePool pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); 283 NSAutoreleasePool pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
284 try { 284 try {
285 NSWorkspace workspace = NSWorkspace.sharedWorkspace(); 285 NSWorkspace workspace = NSWorkspace.sharedWorkspace();
286 NSString fullPath = NSString.stringWith(fileName); 286 NSString fullPath = NSString.stringWith(fileName);
287 if (fileName.indexOf(':') is -1) { 287 if (dwt.dwthelper.utils.indexOf(fileName, ':') is -1) {
288 return workspace.openFile(fullPath, NSString.stringWith(name)); 288 return workspace.openFile(fullPath, NSString.stringWith(name));
289 } 289 }
290 NSString unescapedStr = NSString.stringWith("%"); //$NON-NLS-1$ 290 NSString unescapedStr = NSString.stringWith("%"); //$NON-NLS-1$
291 String lowercaseName = fileName.toLowerCase (); 291 String lowercaseName = fileName.toLowerCase ();
292 if (lowercaseName.startsWith (PREFIX_HTTP) || lowercaseName.startsWith (PREFIX_HTTPS)) { 292 if (lowercaseName.startsWith (PREFIX_HTTP) || lowercaseName.startsWith (PREFIX_HTTPS)) {
293 unescapedStr = NSString.stringWith("%#"); //$NON-NLS-1$ 293 unescapedStr = NSString.stringWith("%#"); //$NON-NLS-1$
294 } 294 }
295 CFStringRef ptr = OS.CFURLCreateStringByAddingPercentEscapes(0, fullPath.id, unescapedStr.id, 0, OS.kCFStringEncodingUTF8); 295 CFStringRef ptr = OS.CFURLCreateStringByAddingPercentEscapes(null, cast(CFStringRef) fullPath.id, cast(CFStringRef) unescapedStr.id, null, OS.kCFStringEncodingUTF8);
296 NSString escapedString = new NSString(ptr); 296 NSString escapedString = new NSString(cast(objc.id) ptr);
297 NSArray urls = NSArray.arrayWithObject(NSURL.URLWithString(escapedString)); 297 NSArray urls = NSArray.arrayWithObject(NSURL.URLWithString(escapedString));
298 OS.CFRelease(ptr); 298 OS.CFRelease(ptr);
299 return workspace.openURLs(urls, NSString.stringWith(identifier), 0, null, 0); 299 return workspace.openURLs(urls, NSString.stringWith(identifier), NSWorkspaceLaunchOptions.init, null, null);
300 } finally { 300 } finally {
301 pool.release(); 301 pool.release();
302 } 302 }
303 } 303 }
304 304
325 NSSize size = NSSize(); 325 NSSize size = NSSize();
326 size.width = size.height = 16; 326 size.width = size.height = 16;
327 nsImage.setSize(size); 327 nsImage.setSize(size);
328 NSBitmapImageRep imageRep = null; 328 NSBitmapImageRep imageRep = null;
329 NSImageRep rep = nsImage.bestRepresentationForDevice(null); 329 NSImageRep rep = nsImage.bestRepresentationForDevice(null);
330 if (rep.isKindOfClass(OS.class_NSBitmapImageRep)) { 330 if (rep.isKindOfClass(cast(objc.Class) OS.class_NSBitmapImageRep)) {
331 imageRep = new NSBitmapImageRep(rep.id); 331 imageRep = new NSBitmapImageRep(rep.id);
332 } 332 }
333 if (imageRep !is null) { 333 if (imageRep !is null) {
334 int width = cast(int)/*64*/imageRep.pixelsWide(); 334 int width = cast(int)/*64*/imageRep.pixelsWide();
335 int height = cast(int)/*64*/imageRep.pixelsHigh(); 335 int height = cast(int)/*64*/imageRep.pixelsHigh();
336 int bpr = cast(int)/*64*/imageRep.bytesPerRow(); 336 int bpr = cast(int)/*64*/imageRep.bytesPerRow();
337 int bpp = cast(int)/*64*/imageRep.bitsPerPixel(); 337 int bpp = cast(int)/*64*/imageRep.bitsPerPixel();
338 int dataSize = height * bpr; 338 int dataSize = height * bpr;
339 byte[] srcData = new byte[dataSize]; 339 byte[] srcData = new byte[dataSize];
340 OS.memmove(srcData, imageRep.bitmapData(), dataSize); 340 OS.memmove(srcData.ptr, imageRep.bitmapData(), dataSize);
341 //TODO check color info 341 //TODO check color info
342 PaletteData palette = new PaletteData(0xFF000000, 0xFF0000, 0xFF00); 342 PaletteData palette = new PaletteData(0xFF000000, 0xFF0000, 0xFF00);
343 ImageData data = new ImageData(width, height, bpp, palette, 4, srcData); 343 ImageData data = new ImageData(width, height, bpp, palette, 4, srcData);
344 data.bytesPerLine = bpr; 344 data.bytesPerLine = bpr;
345 data.alphaData = new byte[width * height]; 345 data.alphaData = new byte[width * height];
380 */ 380 */
381 public int opEquals(Object other) { 381 public int opEquals(Object other) {
382 if (this is other) return true; 382 if (this is other) return true;
383 if (cast(Program) other) { 383 if (cast(Program) other) {
384 final Program program = cast(Program) other; 384 final Program program = cast(Program) other;
385 return name.equals(program.name); 385 return name == program.name;
386 } 386 }
387 return false; 387 return false;
388 } 388 }
389 389
390 alias opEquals equals; 390 alias opEquals equals;