• R/O
  • HTTP
  • SSH
  • HTTPS

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

BathyScapheのTitleRulerAppearanceを手軽に変更するツール


File Info

Rev. c201d83a0a4843708e97b65f5a997a01ff728bfe
Tamaño 2,518 octetos
Tiempo 2012-04-03 00:30:51
Autor masakih
Log Message

[New] BathyScaphe 2.1.1に対応

Content

//
//  NSWorkspace-Extensions.m
//  IconSetComposer
//
//  Created by Hori,Masaki on 06/01/25.
//  Copyright 2006 __MyCompanyName__. All rights reserved.
//

#import "NSWorkspace-Extensions.h"

#import "NSAppleEventDescriptor-Extensions.h"

@implementation NSWorkspace(HMCocoaExtention)
-(BOOL)quitApplication:(NSString *)appName
{
    NSAppleEventDescriptor *targetDesc;
    NSAppleEventDescriptor *appleEvent;
	AppleEvent reply;
	NSAppleEventDescriptor *replyDesc;
	NSAppleEventDescriptor *anser;
    OSStatus err;
	
    targetDesc = [NSAppleEventDescriptor targetDescriptorWithAppName:appName];
    if(!targetDesc) return NO;
	
    appleEvent = [NSAppleEventDescriptor appleEventWithEventClass:kCoreEventClass
                                                          eventID:kAEQuitApplication
                                                 targetDescriptor:targetDesc
                                                         returnID:kAutoGenerateReturnID
                                                    transactionID:kAnyTransactionID];
    if(!appleEvent) return NO;
	
    err = AESendMessage( [appleEvent aeDesc], &reply, kAECanInteract + kAEWaitReply , kAEDefaultTimeout );
	if( err == procNotFound) {
		AEDisposeDesc(&reply);
		return YES;
	}
	if(err != noErr) return err;
	
	replyDesc = [[[NSAppleEventDescriptor allocWithZone:[self zone]] initWithAEDescNoCopy:&reply] autorelease];
	anser = [replyDesc paramDescriptorForKeyword:keyErrorNumber];
	err = (OSStatus)[[anser stringValue] floatValue];
	if(err != noErr) {
		anser = [replyDesc paramDescriptorForKeyword:keyErrorString];
		if(anser) NSLog(@"Target returned error. (%@)",[anser stringValue]);
	}
    return err == noErr;
}

//Import from BathyScaphe.
#pragma mark Icon Services Wrapper
- (NSImage *)systemIconForType:(OSType)iconType
{
    IconRef             iconRef;
    IconFamilyHandle    iconFamily;
    OSErr	result;
	
    result = GetIconRef(kOnSystemDisk, kSystemIconsCreator, iconType, &iconRef);
	
    if (result != noErr) {
        return nil;
    }
	
    result = IconRefToIconFamily(iconRef, kSelectorAllAvailableData, &iconFamily);
	
    if (result != noErr || !iconFamily) {
        return nil;
    }
	
    ReleaseIconRef(iconRef);
    
    NSData  *iconData;
    NSImage *iconImage = nil;
	
    iconData = [NSData dataWithBytes:*iconFamily length:GetHandleSize((Handle)iconFamily)];
    iconImage = [[[NSImage alloc] initWithData:iconData] autorelease];
	
	DisposeHandle((Handle)iconFamily);
    
    return iconImage;
}
@end