NSTextView and CFPlugIn
NSTextView and CFPlugIn
- Subject: NSTextView and CFPlugIn
- From: Nick Morris <email@hidden>
- Date: Sun, 9 May 2004 22:59:10 +0100
Hi,
I having problems with CFPlugIn, a subclass of NSTextView, and a
contextual menu!
I see from the archives that there have been numerous discussions on
this subject. I have read them all (well, the ones I can find!), I have
read the CFPlugIn details, I have read up on NSBundles, menus.h etc.
The problem.....
Before trying to construct the Plugin I decided to get the interface
working. I am using the SampleCMPlugin to generate the plugin as I
know (and can show from using the build as a plugin for the finder) it
works.
I have created a subclass of NSTextField so I can access mouse events
etc. The subclass loads the plugin (see below). I can access the
interface and call interface implementations (ExamineContext,
HandleSelection, PostMenuCleanup). However, I am at a loss of how to
incorporate the menu parts from the plugin in to the contextual menu (I
can add parts using standard cocoa methods).
I am also aware that there may be a problem with the loading of plugin
menus in to cocoa application and the use of
ContextualMenuSelect(menuRef, globalPoint, NO, 0, nil, &inSelection,
&outUserSelectionType, &outMenuID, &outMenuItem).
(Being terrible at carbon I have had problems with using
_NSGetCarbonMenu to get the menuRef).
Is the problem that I need to subclass menu and use that to handle the
laoding?
Sorry for the long post and I look forward to receiving your comments.
Thanks
Nick
Plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"
http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>PlugIn</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>0.0.1d1</string>
<key>CFPlugInDynamicRegistration</key>
<string>NO</string>
<key>CFPlugInFactories</key>
<dict>
<key>08427B16-A04C-11D8-B520-000A95863436</key>
<string>SampleCMPluginFactory</string>
</dict>
<key>CFPlugInTypes</key>
<dict>
<key>2F6522E9-3E66-11D5-80A7-003065B300BC</key>
<array>
<string>08427B16-A04C-11D8-B520-000A95863436</string>
</array>
</dict>
</dict>
</plist>
Keys in the plugin:
#define kSampleCMPluginFactoryID ( CFUUIDGetConstantUUIDWithBytes(
NULL, 0x08, 0x42, 0x7B, 0x16, 0xA0, 0x4C, 0x11, 0xD8, 0xB5, 0x20, 0x00,
0x0A, 0x95, 0x86, 0x34, 0x36))
#define kTestTypeID (CFUUIDGetConstantUUIDWithBytes(NULL,
0x2F,0x65,0x22,0xE9,0x3E,0x66,0x11,0xD5,0x80,0xA7,0x00,0x30,0x65,0xB3,0x
00,0xBC))
Keys in the NSTextView subclass:
#define kTestInterfaceID ( CFUUIDGetConstantUUIDWithBytes( NULL,
0x32,0x99,0x7B,0x62,0x3E,0x66,0x11,0xD5,0xBE,0xAB,0x00,0x30,0x65,0xB3,0x
00,0xBC))
// 32997B62-3E66-11D5-BEAB-003065B300BC
#define kTestTypeID (CFUUIDGetConstantUUIDWithBytes(NULL,
0x2F,0x65,0x22,0xE9,0x3E,0x66,0x11,0xD5,0x80,0xA7,0x00,0x30,0x65,0xB3,0x
00,0xBC))
// 2F6522E9-3E66-11D5-80A7-003065B300BC
#define kPlugInName "plugin.bundle"
Below is the activation/loading process for the plugin (CFPlugInRef
newPlugIn and the interface are stored as globals)
CFURLRef bundleURL;
CFURLRef plugInURL;
Boolean foundInterface = false;
Boolean didLoad = false;
bundleURL = CFBundleCopyBuiltInPlugInsURL( CFBundleGetMainBundle()
);
plugInURL = CFURLCreateCopyAppendingPathComponent( NULL, bundleURL,
CFSTR( kPlugInName ), FALSE );
newPlugIn = CFPlugInCreate( NULL, plugInURL );
CFRelease( bundleURL );
CFRelease( plugInURL );
didLoad = CFBundleLoadExecutable( newPlugIn );
if( newPlugIn )
{
CFArrayRef factories;
factories = CFPlugInFindFactoriesForPlugInTypeInPlugIn(
kTestTypeID, newPlugIn );
if ( factories != NULL )
{
CFIndex factoryCount;
CFIndex index;
factoryCount = CFArrayGetCount( factories );
if ( factoryCount > 0 )
{
for ( index = 0 ; (index < factoryCount) &&
(foundInterface == false) ; index++ )
{
CFUUIDRef factoryID;
factoryID = (CFUUIDRef) CFArrayGetValueAtIndex(
factories, index );
if ( factoryID )
{
IUnknownVTbl **iunknown;
iunknown = (IUnknownVTbl **)
CFPlugInInstanceCreate( NULL, factoryID, kTestTypeID );
if ( iunknown )
{
(*iunknown)->QueryInterface(iunknown,
CFUUIDGetUUIDBytes(kTestInterfaceID), (LPVOID *)(&interface));
(*iunknown)->Release(iunknown);
}
}
}
}
CFRelease( factories );
}
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.