not part of the build yet, unix plugin sdk

This commit is contained in:
serge@netscape.com
2002-09-13 04:26:59 +00:00
parent a525273f19
commit e1aa17ca12
14 changed files with 589 additions and 253 deletions
@@ -45,11 +45,11 @@
#define MIME_TYPES_HANDLED "application/scriptable-plugin"
#define PLUGIN_NAME "Scriptable Example Plugin for Mozilla"
#define PLUGIN_DESCRIPTION "Scriptable Example Plugin for Mozilla"
#define PLUGIN_DESCRIPTION MIME_TYPES_HANDLED":scr:"PLUGIN_NAME
char* NPP_GetMIMEDescription(void)
{
return(MIME_TYPES_HANDLED);
return(PLUGIN_DESCRIPTION);
}
//////////////////////////////////////
@@ -92,6 +92,8 @@ nsPluginInstance::nsPluginInstance(NPP aInstance) : nsPluginInstanceBase(),
mInstance(aInstance),
mInitialized(FALSE),
mWindow(0),
mXtwidget(0),
mFontInfo(0),
mScriptablePeer(NULL)
{
mString[0] = '\0';
@@ -128,15 +130,23 @@ void nsPluginInstance::draw()
unsigned int w = 3 * mWidth/4;
int x = (mWidth - w)/2; // center
int y = h/2;
XDrawRectangle(mDisplay, mWindow, mGC, x, y, w, h);
XClearArea(mDisplay, mWindow, 0, 0, 0, 0, False);
if (x >= 0 && y >= 0) {
GC gc = XCreateGC(mDisplay, mWindow, 0, NULL);
if (!gc)
return;
XDrawRectangle(mDisplay, mWindow, gc, x, y, w, h);
if (mString[0]) {
int l = strlen(mString);
int fmba = mFontInfo->max_bounds.ascent;
int fmbd = mFontInfo->max_bounds.descent;
int fh = fmba + fmbd;
y += fh;
x += 32;
XDrawString(mDisplay, mWindow, mGC, x, y, mString, l);
XDrawString(mDisplay, mWindow, gc, x, y, mString, l);
}
XFreeGC(mDisplay, gc);
}
}
NPBool nsPluginInstance::init(NPWindow* aWindow)
@@ -144,34 +154,47 @@ NPBool nsPluginInstance::init(NPWindow* aWindow)
if(aWindow == NULL)
return FALSE;
NPSetWindowCallbackStruct *ws_info = (NPSetWindowCallbackStruct *)aWindow->ws_info;
mWindow = (Window) aWindow->window;
if (SetWindow(aWindow))
mInitialized = TRUE;
return mInitialized;
}
NPError nsPluginInstance::SetWindow(NPWindow* aWindow)
{
if(aWindow == NULL)
return FALSE;
mX = aWindow->x;
mY = aWindow->y;
mWidth = aWindow->width;
mHeight = aWindow->height;
if (mWindow != (Window) aWindow->window) {
mWindow = (Window) aWindow->window;
NPSetWindowCallbackStruct *ws_info = (NPSetWindowCallbackStruct *)aWindow->ws_info;
mDisplay = ws_info->display;
mVisual = ws_info->visual;
mDepth = ws_info->depth;
mColormap = ws_info->colormap;
mFontInfo = XLoadQueryFont(mDisplay, "9x15");
if (!mFontInfo) {
printf("Cannot open 9X15 font\n");
return FALSE;
}
mGC = XCreateGC(mDisplay, mWindow, 0, NULL);
if (!mFontInfo) {
if (!(mFontInfo = XLoadQueryFont(mDisplay, "9x15")))
printf("Cannot open 9X15 font\n");
}
// add xt event handler
Widget xtwidget = XtWindowToWidget(mDisplay, mWindow);
if (xtwidget) {
if (xtwidget && mXtwidget != xtwidget) {
mXtwidget = xtwidget;
long event_mask = ExposureMask;
XSelectInput(mDisplay, mWindow, event_mask);
XtAddEventHandler(xtwidget, event_mask, False, (XtEventHandler)xt_event_handler, this);
}
mInitialized = TRUE;
}
draw();
return TRUE;
}
void nsPluginInstance::shut()
{
mInitialized = FALSE;
@@ -210,37 +233,22 @@ NPError nsPluginInstance::GetValue(NPPVariable aVariable, void *aValue)
{
NPError rv = NPERR_NO_ERROR;
switch (aVariable) {
case NPPVpluginScriptableInstance: {
if (aVariable == NPPVpluginScriptableInstance) {
// addref happens in getter, so we don't addref here
nsISimplePlugin * scriptablePeer = getScriptablePeer();
nsIScriptablePluginSample * scriptablePeer = getScriptablePeer();
if (scriptablePeer) {
*(nsISupports **)aValue = scriptablePeer;
} else
rv = NPERR_OUT_OF_MEMORY_ERROR;
}
break;
case NPPVpluginScriptableIID: {
static nsIID scriptableIID = NS_ISIMPLEPLUGIN_IID;
else if (aVariable == NPPVpluginScriptableIID) {
static nsIID scriptableIID = NS_ISCRIPTABLEPLUGINSAMPLE_IID;
nsIID* ptr = (nsIID *)NPN_MemAlloc(sizeof(nsIID));
if (ptr) {
*ptr = scriptableIID;
*(nsIID **)aValue = ptr;
} else
rv = NPERR_OUT_OF_MEMORY_ERROR;
}
break;
case NPPVpluginNameString:
*((char **)aValue) = PLUGIN_NAME;
break;
case NPPVpluginDescriptionString:
*((char **)aValue) = PLUGIN_DESCRIPTION;
break;
default:
break;
}
return rv;