⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plugin.c

📁 Evc编的一个在wince5.0上运行的flash播放器
💻 C
📖 第 1 页 / 共 2 页
字号:
		}
		if (status & FLASH_PARSE_WAKEUP) {
			flashWakeUp((XtPointer)This, 0);
		}
		if (status & FLASH_PARSE_EOM) {
			/*l->url = "";*/
		}
	}

	return len;		/* The number of bytes accepted */
}

static void
getUrl( char * url, char *target, void *client_data)
{
	NPP instance;

	instance = (NPP)client_data;
	NPN_GetURL(instance, url, target );
}

static void
getSwf(char *url, int level, void *client_data)
{
	PluginInstance* This;
	NPP instance;
	LoadCtxt *l;

	instance = (NPP)client_data;
	if (instance == 0) return;

	This = (PluginInstance*) instance->pdata;
	if (This == 0) return;

	l = (LoadCtxt *)malloc(sizeof(LoadCtxt));
	l->next = This->loading;
	This->loading = l;
	l->level = level;
	l->data = 0;
	l->size = 0;
	l->url = strdup(url);

	NPN_GetURL(instance, url, 0);
} 

static void
cursorOnOff( int on, void *client_data)
{
	PluginInstance* This;
	NPP instance;

	instance = (NPP)client_data;
	if (instance == 0) return;

	This = (PluginInstance*) instance->pdata;
	if (This == 0) return;

	if (on && !This->cursorOver) {
		XDefineCursor(This->dpy, This->win, This->buttonCursor);
		This->cursorOver = 1;
	}
	if (!on && This->cursorOver) {
		XUndefineCursor(This->dpy, This->win);
		This->cursorOver = 0;
	}
	XFlush(This->dpy);
}

NPError 
NPP_DestroyStream(NPP instance, NPStream *stream, NPError reason)
{
	PluginInstance* This;
	LoadCtxt *l,*prev;

	if (instance == NULL)
		return NPERR_INVALID_INSTANCE_ERROR;

	if (reason != NPERR_NO_ERROR)
		return NPERR_INVALID_INSTANCE_ERROR;

	This = (PluginInstance*) instance->pdata;

	if (This == 0) return NPERR_INVALID_INSTANCE_ERROR;

	if (This->fh == 0) {
		return NPERR_INVALID_INSTANCE_ERROR;
	}

	for(l = This->loading; l; l = l->next) {
		if (l->url && strstr(stream->url, l->url)) {
			free(l->data);
			l->data = 0;
			free(l->url);
			l->url = 0;
			break;
		}
	}

	if (!This->gInitDone && This->dpy) {
		FlashGraphicInitX11(This);
		XtAddEventHandler(This->widget, FLASH_XEVENT_MASK,
				  True, (XtEventHandler) flashEvent, (XtPointer)This);
		This->gInitDone = 1;

		flashWakeUp((XtPointer)This, 0);
	}

	return NPERR_NO_ERROR;
}


void 
NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname)
{
	PluginInstance* This;
	if (instance != NULL)
		This = (PluginInstance*) instance->pdata;
}


void 
NPP_Print(NPP instance, NPPrint* printInfo)
{
	if(printInfo == NULL)
		return;

	if (instance != NULL) {
		PluginInstance* This = (PluginInstance*) instance->pdata;
	
		if (printInfo->mode == NP_FULL) {
		    /*
		     * PLUGIN DEVELOPERS:
		     *	If your plugin would like to take over
		     *	printing completely when it is in full-screen mode,
		     *	set printInfo->pluginPrinted to TRUE and print your
		     *	plugin as you see fit.  If your plugin wants Netscape
		     *	to handle printing in this case, set
		     *	printInfo->pluginPrinted to FALSE (the default) and
		     *	do nothing.  If you do want to handle printing
		     *	yourself, printOne is true if the print button
		     *	(as opposed to the print menu) was clicked.
		     *	On the Macintosh, platformPrint is a THPrint; on
		     *	Windows, platformPrint is a structure
		     *	(defined in npapi.h) containing the printer name, port,
		     *	etc.
		     */

			void* platformPrint =
				printInfo->print.fullPrint.platformPrint;
			NPBool printOne =
				printInfo->print.fullPrint.printOne;
			
			/* Do the default*/
			printInfo->print.fullPrint.pluginPrinted = FALSE;
		}
		else {	/* If not fullscreen, we must be embedded */
		    /*
		     * PLUGIN DEVELOPERS:
		     *	If your plugin is embedded, or is full-screen
		     *	but you returned false in pluginPrinted above, NPP_Print
		     *	will be called with mode == NP_EMBED.  The NPWindow
		     *	in the printInfo gives the location and dimensions of
		     *	the embedded plugin on the printed page.  On the
		     *	Macintosh, platformPrint is the printer port; on
		     *	Windows, platformPrint is the handle to the printing
		     *	device context.
		     */

			NPWindow* printWindow =
				&(printInfo->print.embedPrint.window);
			void* platformPrint =
				printInfo->print.embedPrint.platformPrint;
		}
	}
}

static
long parseAttributes(int16 n, char *argn[], char *argv[])
{
	int16 i;
	int c;
	long attributes;

	attributes = 0;
	for(i=0; i<n; i++)
	{
		if (!strcasecmp(argn[i],"loop")) {
			if (!strcasecmp(argv[i],"true")) {
				attributes |= PLAYER_LOOP;
			}
		}
		if (!strcasecmp(argn[i],"menu")) {
			if (!strcasecmp(argv[i],"true")) {
				attributes |= PLAYER_MENU;
			}
		}
		if (!strcasecmp(argn[i],"quality")) {
			if (!strcasecmp(argv[i],"high")
			 || !strcasecmp(argv[i],"autohigh")) {
				attributes |= PLAYER_QUALITY;
			}
		}
	}
	return attributes;
}

static long
FlashExecX11(PluginInstance *This, long flag, XEvent *event, struct timeval *wakeDate)
{
    FlashEvent fe;
    long wu;

    if (flag & FLASH_EVENT) {
	int keycode;
	KeySym keysym;

        // X to Flash event structure conversion
        switch (event->type) {
        case ButtonPress:
            fe.type = FeButtonPress;
            break;
        case ButtonRelease:
            fe.type = FeButtonRelease;
            break;
        case MotionNotify:
            fe.type = FeMouseMove;
            fe.x = event->xmotion.x;
            fe.y = event->xmotion.y;
	    XSetInputFocus(This->dpy,This->win, RevertToParent, CurrentTime);
            break;
        case Expose:
            fe.type = FeRefresh;
	    if (!This->gInitDone) return 0;
	    XSetFunction(This->dpy,This->gc,GXcopy);
	    XCopyArea(This->dpy,This->canvas,This->win,This->gc,
		      0,0, This->fd.width,This->fd.height, 0,0);
	    XFlush(This->dpy);
	    return 0;
            break;
	case KeyPress:
		keycode = event->xkey.keycode;
		keysym = XLookupKeysym((XKeyEvent*)event, 0);
		fe.type = FeKeyPress;
		fe.key = 0;
		switch (keysym) {
			case XK_Up:
			    fe.key = FeKeyUp;
			    break;
			case XK_Down:
			    fe.key = FeKeyDown;
			    break;
			case XK_Left:
			    fe.key = FeKeyLeft;
			    break;
			case XK_Right:
			    fe.key = FeKeyRight;
			    break;
			case XK_Return:
			    fe.key = FeKeyEnter;
			    break;
		}
	    break;
	default:
            fe.type = FeNone;
	    return 0;
            break;
        }
    }

    return FlashExec(This->fh,flag,&fe,wakeDate);
}

static long
FlashGraphicInitX11(PluginInstance *This)
{
    XWindowAttributes 		 wattr;
    XPixmapFormatValues 	*pf;
    Visual 			*visual;
    int				 nItems;
    int				 n;
    struct shmid_ds		 buf;
    int				 targetWidth;
    int 			 targetHeight;
    long			 bpl;	// Bytes per line
    long			 bpp;	// Bytes per pixel
    long			 pad;	// Scanline pad in byte

    // Platform dependent members
    Window			 target;	// Target window
    Cursor		 	 buttonCursor;	// Window cursor (a hand if over a button)
    Display			*dpy;		// X11 Display
    GC		 		 gc;		// X11 Graphic context
    Pixmap			 canvas;	// Graphic buffer
    XShmSegmentInfo		 segInfo;	// Shared memory information

    dpy = This->dpy;
    target = This->win;

    // Get Window dimension
    XGetWindowAttributes(dpy, target, &wattr);

    // Get first visual, don't care about others, really !
    visual = wattr.visual;

#if PRINT
	printf("BitmapPad  = %d\n", BitmapPad(dpy));
	printf("BitmapUnit = %d\n", BitmapUnit(dpy));
	printf("Depth      = %d\n", DefaultDepth(dpy,DefaultScreen(dpy)));
	printf("RedMask    = %x\n", visual->red_mask);
	printf("GreenMask  = %x\n", visual->green_mask);
	printf("BlueMask   = %x\n", visual->blue_mask);
	printf("Bits/RGB   = %d\n", visual->bits_per_rgb);
#endif

	// Get screen info

	for(pf=XListPixmapFormats(dpy, &n); n--; pf++) {
		if (pf->depth == DefaultDepth(dpy, DefaultScreen(dpy))) {
			bpp = pf->bits_per_pixel/8;
			pad = pf->scanline_pad/8;
		}
#if PRINT
		printf("----------------\n");
		printf("Depth          = %d\n", pf->depth);
		printf("Bits Per Pixel = %d\n", pf->bits_per_pixel);
		printf("Scanline Pad   = %d\n", pf->scanline_pad);
#endif
	}

	targetWidth = wattr.width;
	targetHeight = wattr.height;

#if PRINT
	printf("Target Width  = %d\n", targetWidth);
	printf("Target Height = %d\n", targetHeight);
#endif

	if (bpp) {
		bpl = (targetWidth*bpp + pad-1)/pad*pad;
	} else {
		bpl = (targetWidth/8 + pad-1)/pad*pad;
	}

	XSelectInput(dpy, target, FLASH_XEVENT_MASK);

	// Prepare data for Direct Graphics
	segInfo.readOnly = False;
	segInfo.shmid = shmget (IPC_PRIVATE,targetHeight*bpl,IPC_CREAT|0777);
	if (segInfo.shmid <0) {
		perror("shmget");
		fprintf(stderr,"Size = %d x %d\n", targetWidth, targetHeight);
	}
	segInfo.shmaddr = (char*)shmat (segInfo.shmid, 0, 0);
	if ((long)segInfo.shmaddr == -1) {
		perror("shmat");
	}
	XShmAttach(dpy, &segInfo);
#ifdef linux
	// Warning : this does NOT work properly on Solaris
	// Special Linux shm behaviour is used here
	// When number of attached clients falls down to zero
	// the shm is removed. This is convenient when it crashes.
	if (shmctl(segInfo.shmid, IPC_RMID, &buf) < 0) {
		perror("shmctl");
	}
#endif
	XSync(dpy, False);

	This->fd.pixels = (char*)segInfo.shmaddr;
        This->fd.width = targetWidth;
        This->fd.height = targetHeight;
        This->fd.bpl = bpl;
        This->fd.depth = pf->depth;

	canvas = XShmCreatePixmap(dpy,target,segInfo.shmaddr,&segInfo,targetWidth,targetHeight,DefaultDepth(dpy, DefaultScreen(dpy)));
	XSync(dpy, False);

	This->canvas = canvas;

	This->buttonCursor = XCreateFontCursor(dpy, XC_hand2);
	XFlush(dpy);

	This->cursorOver = 0;

        return FlashGraphicInit(This->fh, &This->fd);
}

static void
FlashCopyX11(PluginInstance *This)
{
    if (!This->gInitDone) return;
    XSetFunction(This->dpy,This->gc,GXcopy);
    XCopyArea(This->dpy,This->canvas,This->win,This->gc,
              This->fd.clip_x,This->fd.clip_y,
	      This->fd.clip_width,This->fd.clip_height,
              This->fd.clip_x,This->fd.clip_y
	      );
    XFlush(This->dpy);
    This->fd.flash_refresh = 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -