Re: [SOLVED] How to identify the host app is Carbon or Cocoa in a context menu plugin.
Re: [SOLVED] How to identify the host app is Carbon or Cocoa in a context menu plugin.
- Subject: Re: [SOLVED] How to identify the host app is Carbon or Cocoa in a context menu plugin.
- From: Satoshi Matsumoto <email@hidden>
- Date: Sat, 08 Jul 2006 05:55:56 +0900
- Thread-topic: [SOLVED] How to identify the host app is Carbon or Cocoa in a context menu plugin.
Hi, Rosyna
on 06.07.8 1:23 AM, Rosyna at email@hidden wrote:
> This will not work. Some carbon apps have inserted these keys into
> their info.plist because they thought it was necessary.
Ummmmm.
> You should never actually have to do this unless you have a really,
> really, really, really, really good reason.
The spec of the contextual menu was made on Class OS era. So it does not
take Cocoa apps into consideration. But the contextual menu works also in
Cocoa apps though we can't get the context information in the Cocoa apps (
the information of selected area).
But if the host app were a Cocoa, I can get the information of selected area
from the firstResponder of the keyWindow.
That is the reason why I should know the host app is Cocoa or not.
> If you *actually* have a legit reason, you can, however, call
> ProcessInformationCopyDictionary to get the flavor.
Thank you !!!!!!
Satoshi
on 06.07.8 1:23 AM, Rosyna at email@hidden wrote:
> This will not work. Some carbon apps have inserted these keys into
> their info.plist because they thought it was necessary.
>
> You should never actually have to do this unless you have a really,
> really, really, really, really good reason. I *have* to do it due to
> the way utility windows differ in behaviour between carbon and cocoa
> apps. Their cocoa behaviour is screwy as hell and I have to work
> around the screwiness. I am talking carbon in cocoa here, not the
> cocoa utility windows.
>
>
>
> If you *actually* have a legit reason, you can, however, call
> ProcessInformationCopyDictionary to get the flavor. However, the
> documentation in Processes.h has the values mislabeled (it says 4 is
> cocoa, but 3 is). Note that the carbon runtime can be started in a
> cocoa app and vice versa at any time. The code below only
> identificates the runloop as it was first started in the application.
>
> enum {
> kProcessCarbon=2,
> kProcessCocoa=3,
> };
>
> SInt32 Li_GetApplicationFlavor(void)
> {
> static SInt32 processFlavor=0;
>
> if (!processFlavor)
> {
> OSStatus err=noErr;
> ProcessSerialNumber psn;
> err=GetCurrentProcess(&psn);
>
> if (!err)
> {
> CFDictionaryRef
> processInfo=ProcessInformationCopyDictionary(&psn,
> kProcessDictionaryIncludeAllInformationMask);
>
> if (processInfo)
> {
> CFNumberRef
> flavaFlav=CFDictionaryGetValue(processInfo, CFSTR("Flavor"));
>
> if (flavaFlav)
> CFNumberGetValue(flavaFlav, kCFNumberSInt32Type,
> &processFlavor);
>
>
> CFRelease(processInfo);
> }
> }
>
> }
>
> return processFlavor;
>
> }
>
>
> Ack, at 7/7/06, Satoshi Matsumoto said:
>
>> I have noticed the only Cocoa apps have "NSPrincipalClass" and
>> "NSMainNibFile" in its info-plist file.
>>
>> This is my answer how to identifies the host app is Cocoa or not.
>>
>> BOOL isHostACocoaApp()
>> {
>> NSAutoreleasePool *localPool;
>> BOOL ret = NO;
>>
>> localPool = [[NSAutoreleasePool alloc] init];
>> if( NSApp == nil ) ret = NO;
>> else
>> {
>> NSBundle *bundle = [NSBundle mainBundle];
>> if( bundle )
>> {
>> NSDictionary *plist = [bundle infoDictionary];
>> NSString* primaryClass = [plist
>> objectForKey:@"NSPrincipalClass"];
>> NSString* mainNibFile = [plist objectForKey:@"NSMainNibFile"];
>> if (primaryClass && [primaryClass length] > 0 && mainNibFile &&
>> [mainNibFile length] > 0) ret =YES;
>> }
>> }
>> [localPool release];
>> return ret;
>> }
-----------------------------------------------------
Satoshi Matsumoto <email@hidden>
816-5 Odake, Odawara, Kanagawa, Japan 256-0802
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden