npmngplg.c File Reference

#include <windows.h>
#include <commdlg.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <stdarg.h>
#include "resource.h"
#include "libmng.h"
#include "jversion.h"
#include "zlib.h"
#include "npapidefs.h"

Include dependency graph for npmngplg.c:

Go to the source code of this file.

Data Structures

struct  PluginInstance

Defines

#define MNGPLG_CMS
#define IDBASE   47000
#define ID_SAVEAS   (IDBASE+0)
#define ID_COPYIMAGE   (IDBASE+1)
#define ID_COPYURL   (IDBASE+2)
#define ID_VIEWIMAGE   (IDBASE+3)
#define ID_ABOUT   (IDBASE+4)
#define ID_FREEZE   (IDBASE+5)
#define ID_RESTARTANIM   (IDBASE+6)
#define ID_COPYLINKLOC   (IDBASE+7)
#define ID_STOPANIM   (IDBASE+8)
#define ID_SHOWERROR   (IDBASE+9)
#define ID_PROPERTIES   (IDBASE+10)
#define MNGPLGVERS   "1.0.1"
#define STATE_INIT   0
#define STATE_LOADING   1
#define STATE_VALIDFRAME   2
#define STATE_LOADED   3
#define MAXLEN_TEXT   5000
#define MAXLEN_URL   300
#define MAXLEN_TARGET   100
#define MNGPLG_CALLBACK   MNG_DECL
#define IDC_HAND   MAKEINTRESOURCE(32649)
#define SCROLLLINE   40
#define ALLOC_CHUNK_SIZE   131072
#define MOUSE_POLL_INTERVAL   100

Functions

LRESULT CALLBACK DlgProcAbout (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK DlgProcProp (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK PluginWindowProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
void set_scrollbars (PluginInstance *This)
static const char * NPN_UserAgent (NPP instance)
static NPError NPN_GetURL (NPP instance, const char *url, const char *target)
BOOL APIENTRY DllMain (HANDLE hModule, DWORD reason, LPVOID lpReserved)
static void warn (PluginInstance *This, char *fmt,...)
static void set_error (PluginInstance *This, char *fmt,...)
static mng_ptr MNG_DECL memallocfunc (mng_size_t n)
static void MNG_DECL memfreefunc (mng_ptr p, mng_size_t n)
static mng_bool MNG_DECL callback_openstream (mng_handle mng)
static mng_bool MNG_DECL callback_closestream (mng_handle mng)
static mng_bool MNG_DECL callback_readdata (mng_handle mng, mng_ptr pBuf, mng_uint32 Buflen, mng_uint32 *pRead)
static mng_bool MNG_DECL callback_processheader (mng_handle mng, mng_uint32 iWidth, mng_uint32 iHeight)
static mng_ptr MNG_DECL callback_getcanvasline (mng_handle mng, mng_uint32 iLinenr)
static mng_bool MNG_DECL callback_refresh (mng_handle mng, mng_uint32 iLeft, mng_uint32 iTop, mng_uint32 iRight, mng_uint32 iBottom)
static mng_uint32
MNG_DECL 
callback_gettickcount (mng_handle mng)
static mng_bool MNG_DECL callback_settimer (mng_handle mng, mng_uint32 iMsecs)
static mng_bool MNG_DECL callback_processtext (mng_handle mng, mng_uint8 iType, mng_pchar zKeyword, mng_pchar zText, mng_pchar zLanguage, mng_pchar zTranslation)
static int file_exists (const char *fn)
static void handle_read_error (PluginInstance *This, mng_retcode rv)
static int init_color_management (PluginInstance *This)
static int my_init_mng (PluginInstance *This)
static NPError NPP_Initialize (void)
static void NPP_Shutdown (void)
static unsigned char gethex (const char *s)
static void hexcolor2rgb (const char *s, mng_uint16 *r, mng_uint16 *g, mng_uint16 *b)
static void find_window_size (PluginInstance *This)
static void scrollmsg (PluginInstance *This, UINT msg, int code, short int pos)
static NPError NPP_New (NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char *argn[], char *argv[], NPSavedData *saved)
static void BeforeDestroyWindow (PluginInstance *This)
static NPError NPP_Destroy (NPP instance, NPSavedData **save)
static NPError NPP_SetWindow (NPP instance, NPWindow *window)
static NPError NPP_NewStream (NPP instance, NPMIMEType type, NPStream *stream, NPBool seekable, uint16 *stype)
static int32 NPP_WriteReady (NPP instance, NPStream *stream)
static int32 NPP_Write (NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
static NPError NPP_DestroyStream (NPP instance, NPStream *stream, NPError reason)
static void NPP_StreamAsFile (NPP instance, NPStream *stream, const char *fname)
static void NPP_Print (NPP instance, NPPrint *printInfo)
static void NPP_URLNotify (NPP instance, const char *url, NPReason reason, void *notifyData)
static void url2filename (char *fn, char *url)
static void escapeformenu (unsigned char *s1)
static char * get_imagetype_name (mng_imgtype t)
static void SaveImage (PluginInstance *This)
static void CopyToClipboard (PluginInstance *This, unsigned char *mem, int size, UINT format)
static void AboutDialog (PluginInstance *This)
static void PropDialog (PluginInstance *This)
static void display_last_error (PluginInstance *This)
static void DynamicMNG_FireEvent (PluginInstance *This, mng_uint8 eventtype, POINTS pos)
static void ContextMenu (PluginInstance *This, HWND hwnd)
static JRIGlobalRef Private_GetJavaClass (void)
NPError WINAPI NP_GetEntryPoints (NPPluginFuncs *pFuncs)
NPError WINAPI NP_Initialize (NPNetscapeFuncs *pFuncs)
NPError WINAPI NP_Shutdown ()

Variables

static const char * gInstanceLookupString = "pdata"
static HMODULE g_hInst = NULL
static HCURSOR hcurHandNS
static HFONT hfontMsg
static NPNetscapeFuncsg_pNavigatorFuncs
static NPPluginFuncsg_pluginFuncs


Define Documentation

#define ALLOC_CHUNK_SIZE   131072

Definition at line 994 of file npmngplg.c.

Referenced by NPP_Write().

#define ID_ABOUT   (IDBASE+4)

Definition at line 30 of file npmngplg.c.

Referenced by ContextMenu().

#define ID_COPYIMAGE   (IDBASE+1)

Definition at line 27 of file npmngplg.c.

Referenced by ContextMenu().

#define ID_COPYLINKLOC   (IDBASE+7)

Definition at line 33 of file npmngplg.c.

Referenced by ContextMenu().

#define ID_COPYURL   (IDBASE+2)

Definition at line 28 of file npmngplg.c.

Referenced by ContextMenu().

#define ID_FREEZE   (IDBASE+5)

Definition at line 31 of file npmngplg.c.

Referenced by ContextMenu().

#define ID_PROPERTIES   (IDBASE+10)

Definition at line 36 of file npmngplg.c.

Referenced by ContextMenu().

#define ID_RESTARTANIM   (IDBASE+6)

Definition at line 32 of file npmngplg.c.

Referenced by ContextMenu().

#define ID_SAVEAS   (IDBASE+0)

Definition at line 26 of file npmngplg.c.

Referenced by ContextMenu().

#define ID_SHOWERROR   (IDBASE+9)

Definition at line 35 of file npmngplg.c.

Referenced by ContextMenu().

#define ID_STOPANIM   (IDBASE+8)

Definition at line 34 of file npmngplg.c.

Referenced by ContextMenu().

#define ID_VIEWIMAGE   (IDBASE+3)

Definition at line 29 of file npmngplg.c.

Referenced by ContextMenu().

#define IDBASE   47000

Definition at line 25 of file npmngplg.c.

#define IDC_HAND   MAKEINTRESOURCE(32649)

Referenced by NPP_Initialize().

#define MAXLEN_TARGET   100

Definition at line 60 of file npmngplg.c.

Referenced by NPP_New().

#define MAXLEN_TEXT   5000

Definition at line 57 of file npmngplg.c.

Referenced by callback_processtext().

#define MAXLEN_URL   300

Definition at line 59 of file npmngplg.c.

Referenced by NPP_New().

#define MNGPLG_CALLBACK   MNG_DECL

Definition at line 215 of file npmngplg.c.

#define MNGPLG_CMS

Definition at line 22 of file npmngplg.c.

#define MNGPLGVERS   "1.0.1"

Definition at line 38 of file npmngplg.c.

Referenced by DlgProcAbout().

#define MOUSE_POLL_INTERVAL   100

Referenced by PluginWindowProc().

#define SCROLLLINE   40

Definition at line 693 of file npmngplg.c.

Referenced by scrollmsg().

#define STATE_INIT   0

Definition at line 51 of file npmngplg.c.

Referenced by NPP_New().

#define STATE_LOADED   3

Definition at line 54 of file npmngplg.c.

Referenced by callback_closestream(), callback_readdata(), ContextMenu(), handle_read_error(), NPP_DestroyStream(), and SaveImage().

#define STATE_LOADING   1

Definition at line 52 of file npmngplg.c.

Referenced by NPP_NewStream(), and PluginWindowProc().

#define STATE_VALIDFRAME   2

Definition at line 53 of file npmngplg.c.

Referenced by callback_refresh(), DlgProcProp(), and NPP_Print().


Function Documentation

static void AboutDialog ( PluginInstance This  )  [static]

Definition at line 1344 of file npmngplg.c.

References DlgProcAbout(), PluginInstance::fhWnd, and g_hInst.

Referenced by ContextMenu().

01345 {
01346     DialogBoxParam(g_hInst,"ABOUTDLG",This->fhWnd,(DLGPROC)DlgProcAbout,(LPARAM)This);
01347 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void BeforeDestroyWindow ( PluginInstance This  )  [static]

Definition at line 827 of file npmngplg.c.

References PluginInstance::fDefaultWindowProc, PluginInstance::fhWnd, PluginInstance::mouse_captured, NULL, PluginInstance::timer2_set, and PluginInstance::timer_set.

Referenced by NPP_Destroy(), and NPP_SetWindow().

00828 {
00829     if(This->timer_set) {
00830         KillTimer(This->fhWnd,1);
00831         This->timer_set=0;
00832     }
00833     if(This->timer2_set) {
00834         KillTimer(This->fhWnd,2);
00835         This->timer2_set=0;
00836     }
00837     if(This->mouse_captured) {
00838         ReleaseCapture();
00839         This->mouse_captured=0;
00840     }
00841 
00842     SetWindowLong( This->fhWnd, GWL_WNDPROC, (LONG)This->fDefaultWindowProc); // unsubclass
00843     This->fDefaultWindowProc = NULL;
00844     This->fhWnd = NULL;
00845 }

Here is the caller graph for this function:

static mng_bool MNG_DECL callback_closestream ( mng_handle  mng  )  [static]

Definition at line 236 of file npmngplg.c.

References PluginInstance::loadstate, mng_get_userdata(), MNG_TRUE, and STATE_LOADED.

Referenced by my_init_mng().

00237 {
00238     PluginInstance *This;
00239     This = (PluginInstance*) mng_get_userdata(mng);
00240     This->loadstate = STATE_LOADED;  // this is probably redundant
00241 
00242     return MNG_TRUE;
00243 }

Here is the call graph for this function:

Here is the caller graph for this function:

static mng_ptr MNG_DECL callback_getcanvasline ( mng_handle  mng,
mng_uint32  iLinenr 
) [static]

Definition at line 330 of file npmngplg.c.

References PluginInstance::diblinesize, PluginInstance::lpdibbits, PluginInstance::lpdibinfo, and mng_get_userdata().

Referenced by my_init_mng().

00331 {
00332     unsigned char *pp;
00333 
00334     PluginInstance *This;
00335     This = (PluginInstance*) mng_get_userdata(mng);
00336     pp = (&This->lpdibbits[(This->lpdibinfo->biHeight-1-iLinenr)*This->diblinesize]);
00337     return (mng_ptr) pp;
00338 }

Here is the call graph for this function:

Here is the caller graph for this function:

static mng_uint32 MNG_DECL callback_gettickcount ( mng_handle  mng  )  [static]

Definition at line 371 of file npmngplg.c.

References GetTickCount().

Referenced by my_init_mng().

00372 {
00373     return GetTickCount();
00374 }

Here is the call graph for this function:

Here is the caller graph for this function:

static mng_bool MNG_DECL callback_openstream ( mng_handle  mng  )  [static]

Definition at line 229 of file npmngplg.c.

References MNG_TRUE.

Referenced by my_init_mng().

00230 {
00231 //  PluginInstance *This;
00232 //  This = (PluginInstance*) mng_get_userdata(mng);
00233     return MNG_TRUE;
00234 }

Here is the caller graph for this function:

static mng_bool MNG_DECL callback_processheader ( mng_handle  mng,
mng_uint32  iWidth,
mng_uint32  iHeight 
) [static]

Definition at line 300 of file npmngplg.c.

References PluginInstance::diblinesize, PluginInstance::dibsize, PluginInstance::lpdib, PluginInstance::lpdibbits, PluginInstance::lpdibinfo, MNG_CANVAS_BGR8, mng_get_userdata(), mng_set_canvasstyle(), MNG_TRUE, and set_scrollbars().

Referenced by my_init_mng().

00301 {
00302     PluginInstance *This;
00303     This = (PluginInstance*) mng_get_userdata(mng);
00304 
00305     This->diblinesize = (((iWidth * 24)+31)/32)*4;
00306     This->dibsize = sizeof(BITMAPINFOHEADER) + This->diblinesize*iHeight;
00307     This->lpdib = calloc(This->dibsize,1);
00308     This->lpdibinfo = (LPBITMAPINFOHEADER)This->lpdib;
00309     This->lpdibbits = &This->lpdib[sizeof(BITMAPINFOHEADER)];
00310     ZeroMemory((void*)This->lpdib,sizeof(BITMAPINFOHEADER));
00311     This->lpdibinfo->biSize = sizeof(BITMAPINFOHEADER);
00312     This->lpdibinfo->biWidth = iWidth;
00313     This->lpdibinfo->biHeight = iHeight;
00314     This->lpdibinfo->biPlanes = 1;
00315     This->lpdibinfo->biBitCount = 24;
00316 
00317     mng_set_canvasstyle (mng, MNG_CANVAS_BGR8);
00318 
00319 /*  if(This->fhWnd) {
00320         if((int)iWidth > This->windowwidth || (int)iHeight > This->windowheight) {
00321             This->scrolling=1;
00322         }
00323     } */
00324 
00325     set_scrollbars(This);
00326     return MNG_TRUE;
00327 }

Here is the call graph for this function:

Here is the caller graph for this function:

static mng_bool MNG_DECL callback_processtext ( mng_handle  mng,
mng_uint8  iType,
mng_pchar  zKeyword,
mng_pchar  zText,
mng_pchar  zLanguage,
mng_pchar  zTranslation 
) [static]

Definition at line 394 of file npmngplg.c.

References MAXLEN_TEXT, mng_get_userdata(), MNG_TRUE, and PluginInstance::textdata.

Referenced by my_init_mng().

00397 {
00398     PluginInstance *This;
00399     int pos,i;
00400 
00401     This = (PluginInstance*) mng_get_userdata(mng);
00402 
00403     if(!This->textdata) {
00404         This->textdata=(char*)malloc(MAXLEN_TEXT+10);
00405         if(!This->textdata) return MNG_TRUE;
00406         lstrcpy(This->textdata,"");
00407     }
00408 
00409     pos=lstrlen(This->textdata);
00410     if(pos>=(MAXLEN_TEXT-10)) return MNG_TRUE;
00411 
00412     if(pos>0) {    /* separate items with a blank line */
00413         This->textdata[pos++]='\r';
00414         This->textdata[pos++]='\n';
00415         This->textdata[pos++]='\r';
00416         This->textdata[pos++]='\n';
00417     }
00418 
00419     for(i=0;zKeyword[i];i++) {
00420         if(pos<MAXLEN_TEXT)
00421             This->textdata[pos++]=zKeyword[i];
00422     }
00423     This->textdata[pos++]=':';
00424     This->textdata[pos++]=' ';
00425 
00426     for(i=0;zText[i];i++) {
00427         if(pos<MAXLEN_TEXT) {
00428             if(zText[i]=='\n') {
00429                 This->textdata[pos++]='\r';
00430             }
00431             This->textdata[pos++]=zText[i];
00432         }
00433     }
00434     This->textdata[pos++]='\0';
00435 
00436     return MNG_TRUE;
00437 }

Here is the call graph for this function:

Here is the caller graph for this function:

static mng_bool MNG_DECL callback_readdata ( mng_handle  mng,
mng_ptr  pBuf,
mng_uint32  Buflen,
mng_uint32 *  pRead 
) [static]

Definition at line 246 of file npmngplg.c.

References PluginInstance::bytesloaded, PluginInstance::byteswanted, PluginInstance::libmngpos, PluginInstance::loadstate, mng_get_userdata(), MNG_TRUE, PluginInstance::mngdata, and STATE_LOADED.

Referenced by my_init_mng().

00248 {
00249     int n;
00250     PluginInstance *This;
00251     This = (PluginInstance*) mng_get_userdata(mng);
00252 
00253 #ifdef MNGPLG_TRACE
00254     fprintf(tracefile,"readdata callback buflen=%d loadstate=%d bytesloaded=%d libmngpos=%d\n",
00255         Buflen,This->loadstate,This->bytesloaded, This->libmngpos);
00256 #endif
00257 
00258 
00259     // do we have enough data available?
00260     if(This->bytesloaded - This->libmngpos >= Buflen) {
00261         CopyMemory(pBuf,&This->mngdata[This->libmngpos],Buflen);
00262         (*pRead)= Buflen;
00263         This->libmngpos += Buflen;
00264 
00265 #ifdef MNGPLG_TRACE
00266     fprintf(tracefile,"returning full: %d\n",Buflen);
00267 #endif
00268         This->byteswanted=0;
00269         return MNG_TRUE;
00270     }
00271     else if(This->loadstate>=STATE_LOADED) {
00272         // We don't have the data it asked for, but we're at the end
00273         // of file, so send it anyway...?
00274 
00275         n=This->bytesloaded-This->libmngpos;
00276 
00277         if(n>0) {
00278             CopyMemory(pBuf,&This->mngdata[This->libmngpos],n);
00279             This->libmngpos+=n;
00280         }
00281         (*pRead)=n;
00282         // so what do we return?
00283 #ifdef MNGPLG_TRACE
00284     fprintf(tracefile,"returning partial: %d\n",n);
00285 #endif
00286         This->byteswanted=0;
00287         return MNG_TRUE;
00288     }
00289 
00290     // else we don't yet have the data it's requesting
00291 #ifdef MNGPLG_TRACE
00292     fprintf(tracefile,"returning 0\n");
00293 #endif
00294     (*pRead)=0;
00295     This->byteswanted=Buflen;
00296     return MNG_TRUE;
00297 }

Here is the call graph for this function:

Here is the caller graph for this function:

static mng_bool MNG_DECL callback_refresh ( mng_handle  mng,
mng_uint32  iLeft,
mng_uint32  iTop,
mng_uint32  iRight,
mng_uint32  iBottom 
) [static]

Definition at line 340 of file npmngplg.c.

References PluginInstance::fhWnd, PluginInstance::loadstate, mng_get_userdata(), MNG_TRUE, NULL, PluginInstance::paintedyet, STATE_VALIDFRAME, PluginInstance::xscrollpos, and PluginInstance::yscrollpos.

Referenced by my_init_mng().

00342 {
00343     PluginInstance *This;
00344     RECT rect;
00345 
00346     This = (PluginInstance*) mng_get_userdata(mng);
00347 
00348     if(This->loadstate<STATE_VALIDFRAME) {
00349         This->loadstate=STATE_VALIDFRAME;
00350     }
00351 
00352     if(This->fhWnd) {
00353         if(This->paintedyet) {
00354             rect.left= iLeft      - This->xscrollpos;
00355             rect.top= iTop        - This->yscrollpos;
00356             rect.right= iLeft+iRight;
00357             rect.bottom= iTop+iBottom;
00358 
00359             InvalidateRect(This->fhWnd,&rect,FALSE);
00360         }
00361         else {
00362             // Make sure the first paint clears the whole plugin window
00363             InvalidateRect(This->fhWnd,NULL,TRUE);
00364             This->paintedyet=1;
00365         }
00366         UpdateWindow(This->fhWnd);
00367     }
00368     return MNG_TRUE;
00369 }

Here is the call graph for this function:

Here is the caller graph for this function:

static mng_bool MNG_DECL callback_settimer ( mng_handle  mng,
mng_uint32  iMsecs 
) [static]

Definition at line 377 of file npmngplg.c.

References PluginInstance::fhWnd, PluginInstance::frozen, mng_get_userdata(), MNG_TRUE, NULL, SetTimer(), PluginInstance::timer_set, and warn().

Referenced by my_init_mng().

00378 {
00379     PluginInstance *This;
00380     This = (PluginInstance*) mng_get_userdata(mng);
00381 
00382     if(This->fhWnd) {
00383         if(!SetTimer(This->fhWnd,1,(UINT)iMsecs,NULL)) {
00384             warn(This,"Unable to create a timer for animation");
00385             This->frozen=1;
00386             //return MNG_FALSE;
00387             return MNG_TRUE;
00388         }
00389         This->timer_set=1;
00390     }
00391     return MNG_TRUE;
00392 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void ContextMenu ( PluginInstance This,
HWND  hwnd 
) [static]

Definition at line 1380 of file npmngplg.c.

References AboutDialog(), CopyToClipboard(), PluginInstance::dibsize, display_last_error(), PluginInstance::errorflag, escapeformenu(), PluginInstance::fhWnd, PluginInstance::frozen, handle_read_error(), ID_ABOUT, ID_COPYIMAGE, ID_COPYLINKLOC, ID_COPYURL, ID_FREEZE, ID_PROPERTIES, ID_RESTARTANIM, ID_SAVEAS, ID_SHOWERROR, ID_STOPANIM, ID_VIEWIMAGE, PluginInstance::instance, PluginInstance::islink, PluginInstance::linkurl, PluginInstance::loadstate, PluginInstance::lpdib, PluginInstance::mng, mng_display_freeze(), mng_display_reset(), mng_display_resume(), NPN_GetURL(), NULL, PropDialog(), SaveImage(), STATE_LOADED, PluginInstance::timer_set, PluginInstance::url, url2filename(), and warn().

Referenced by PluginWindowProc().

01381 {
01382     int cmd;
01383     HMENU menu;
01384     POINT pt;
01385     unsigned char buf[MAX_PATH], buf2[200];
01386 
01387     pt.x=0; pt.y=0;
01388     GetCursorPos(&pt);
01389 
01390     // create context menu dynamically
01391     menu=CreatePopupMenu();
01392     if(This->errorflag) {
01393         AppendMenu(menu,MF_ENABLED,ID_SHOWERROR,"SHOW ERROR MESSAGE");
01394         AppendMenu(menu,MF_SEPARATOR,0,NULL);
01395     }
01396 
01397     AppendMenu(menu,(This->loadstate>=STATE_LOADED?MF_ENABLED:MF_GRAYED),ID_SAVEAS,"Save Image &As...");
01398     AppendMenu(menu,(This->lpdib?MF_ENABLED:MF_GRAYED),ID_COPYIMAGE,"&Copy Image");
01399     AppendMenu(menu,MF_ENABLED,ID_COPYURL,"Cop&y Image Location");
01400     if(This->islink) {
01401         AppendMenu(menu,MF_ENABLED,ID_COPYLINKLOC,"Copy Link Location");
01402     }
01403 
01404     url2filename(buf,This->url);
01405     escapeformenu(buf);
01406     if(lstrlen(buf)) {
01407         wsprintf(buf2,"View Image (%s)",buf);
01408     }
01409     else {
01410         wsprintf(buf2,"View Image");
01411     }
01412     AppendMenu(menu,MF_ENABLED,ID_VIEWIMAGE,buf2);
01413 
01414 
01415     AppendMenu(menu,MF_SEPARATOR,0,NULL);
01416     // AppendMenu(menu,(This->mng?MF_ENABLED:MF_GRAYED),ID_STOPANIM,"Stop Animation");
01417 
01418 
01419     AppendMenu(menu,(This->mng?MF_ENABLED:MF_GRAYED)|
01420         (This->frozen?MF_CHECKED:MF_UNCHECKED),ID_FREEZE,"&Freeze Animation");
01421 
01422     // AppendMenu(menu,(This->mng?MF_ENABLED:MF_GRAYED),ID_RESTARTANIM,"Restart Animation");
01423 
01424     AppendMenu(menu,MF_SEPARATOR,0,NULL);
01425 
01426     AppendMenu(menu,MF_ENABLED,ID_PROPERTIES,"Properties...");
01427 
01428     AppendMenu(menu,MF_ENABLED,ID_ABOUT,"About MNG Plug-in...");
01429 
01430     cmd=TrackPopupMenuEx(menu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_NONOTIFY|TPM_RETURNCMD|
01431         TPM_RIGHTBUTTON,pt.x,pt.y,hwnd,NULL);
01432 
01433     DestroyMenu(menu);
01434 
01435     switch(cmd) {
01436 
01437     case ID_STOPANIM:
01438         if(This->mng) {
01439             KillTimer(This->fhWnd,1);
01440             This->timer_set=0;
01441             mng_display_freeze(This->mng);
01442         }
01443         break;
01444 
01445     case ID_FREEZE:
01446         This->frozen = !This->frozen;
01447         if(This->frozen) {
01448             KillTimer(This->fhWnd,1);
01449             This->timer_set=0;
01450             mng_display_freeze(This->mng);
01451         }
01452         else {
01453             handle_read_error(This, mng_display_resume(This->mng) );
01454 
01455         }
01456         break;
01457 
01458     case ID_RESTARTANIM:
01459         if(!This->frozen) {
01460             KillTimer(This->fhWnd,1);
01461             This->timer_set=0;
01462             mng_display_freeze(This->mng);
01463         }
01464         This->frozen=1;
01465         mng_display_reset(This->mng);
01466         This->frozen=0;
01467         handle_read_error(This, mng_display_resume(This->mng) );
01468         break;
01469 
01470     case ID_SAVEAS:
01471         SaveImage(This);
01472         break;
01473     case ID_COPYIMAGE:
01474         if(This->lpdib) {
01475             CopyToClipboard(This,(unsigned char*)This->lpdib,This->dibsize,CF_DIB);
01476         }
01477         else {
01478             warn(This,"No image to copy");
01479         }
01480         break;
01481     case ID_COPYURL:
01482         CopyToClipboard(This,This->url,lstrlen(This->url)+1,CF_TEXT);
01483         break;
01484     case ID_COPYLINKLOC:
01485         if(This->islink) {
01486             CopyToClipboard(This,This->linkurl,lstrlen(This->linkurl)+1,CF_TEXT);
01487         }
01488         break;
01489     case ID_VIEWIMAGE:
01490         if(lstrlen(This->url)) 
01491             NPN_GetURL(This->instance,This->url,"_self");
01492         break;
01493     case ID_PROPERTIES:
01494         PropDialog(This);
01495         break;
01496     case ID_ABOUT:
01497         AboutDialog(This);
01498         break;
01499     case ID_SHOWERROR:
01500         display_last_error(This);
01501         break;
01502     }
01503 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void CopyToClipboard ( PluginInstance This,
unsigned char *  mem,
int  size,
UINT  format 
) [static]

Definition at line 1312 of file npmngplg.c.

References NULL, and warn().

Referenced by ContextMenu().

01313 {
01314     HGLOBAL hClip;
01315     LPVOID lpClip;
01316 
01317     if(!mem) return;
01318 
01319     if(!OpenClipboard(NULL)) {
01320         warn(This,"Can't open the clipboard");
01321         return;
01322     }
01323 
01324     if(EmptyClipboard()) {
01325         hClip=GlobalAlloc(GMEM_ZEROINIT|GMEM_MOVEABLE|GMEM_DDESHARE,size);
01326         lpClip=GlobalLock(hClip);
01327         if(lpClip) {
01328             CopyMemory(lpClip,mem,size);
01329             GlobalUnlock(hClip);
01330             if(!SetClipboardData(format,hClip)) {
01331                 warn(This,"Can't set clipboard data");
01332             }
01333         }
01334         else {
01335             warn(This,"Can't allocate memory for clipboard");
01336         }
01337     }
01338     else {
01339         warn(This,"Can't clear the clipboard");
01340     }
01341     CloseClipboard();
01342 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void display_last_error ( PluginInstance This  )  [static]

Definition at line 1355 of file npmngplg.c.

References PluginInstance::errorflag, PluginInstance::errormsg, and warn().

Referenced by ContextMenu(), and PluginWindowProc().

01356 {
01357     if(This->errorflag) {
01358         warn(This,"%s",This->errormsg);
01359     }
01360 }

Here is the call graph for this function:

Here is the caller graph for this function:

static LRESULT CALLBACK DlgProcAbout ( HWND  hWnd,
UINT  Msg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 1810 of file npmngplg.c.

References g_hInst, IDC_PRGINFO, mng_version_text(), and MNGPLGVERS.

Referenced by AboutDialog().

01811 {
01812     char buf[4096],buf2[1024],buf3[300];
01813 
01814     switch(Msg) {
01815     case WM_INITDIALOG:
01816         {
01817             //DWORD tabs[1];
01818 
01819             PluginInstance *This=(PluginInstance*)lParam;
01820 
01821             //tabs[0]= 60;
01822             //SendDlgItemMessage(hWnd,IDC_IMGINFO,EM_SETTABSTOPS,(WPARAM)1,(LPARAM)tabs);
01823 
01824             wsprintf(buf,"MNGPLG Plug-in, Version %s\r\n%s"
01825 #ifdef _DEBUG
01826                 " DEBUG BUILD"
01827 #endif
01828                 "\r\nCopyright (C) 2000-2002 by Jason Summers\r\n\r\n",MNGPLGVERS,__DATE__);
01829 
01830             wsprintf(buf2,"Based on libmng by Gerard Juyn.\r\n");
01831             lstrcat(buf,buf2);
01832 
01833             wsprintf(buf2,"libmng version: %s\r\n\r\n",mng_version_text());
01834             lstrcat(buf,buf2);
01835 
01836             wsprintf(buf2,"Uses the zlib compression library.\r\n");
01837             lstrcat(buf,buf2);
01838             wsprintf(buf2,"zlib version: %s\r\n\r\n",zlibVersion());
01839             lstrcat(buf,buf2);
01840 
01841             wsprintf(buf2,"This software is based in part on the work of the "
01842                 "Independent JPEG Group.\r\n");
01843             lstrcat(buf,buf2);
01844             // This really only gives the version of the libjpeg header used when
01845             // compiling this plugin, but I don't know how to query libjpeg for its
01846             // version.
01847             wsprintf(buf2,"IJG JPEG library version: %s\r\n%s\r\n\r\n",JVERSION,JCOPYRIGHT);
01848             lstrcat(buf,buf2);
01849 
01850 #ifdef MNGPLG_CMS
01851             wsprintf(buf2,"Uses the lcms color management library by Mart� Maria. "
01852                 "lcms is distributed under the terms of the GNU LESSER GENERAL PUBLIC LICENSE. "
01853                 "See the file COPYING-LCMS.\r\n\r\n");
01854             lstrcat(buf,buf2);
01855 #endif
01856 
01857             if(GetModuleFileName(g_hInst,buf3,260)) {
01858                 wsprintf(buf2,"MNGPLG location: %s\r\n",buf3);
01859                 lstrcat(buf,buf2);
01860             }
01861 
01862             SetDlgItemText(hWnd,IDC_PRGINFO,buf);
01863 
01864         }
01865         return(TRUE);
01866     case WM_CLOSE:
01867         EndDialog(hWnd,0);
01868         return(TRUE);
01869     case WM_COMMAND:
01870         switch(wParam) {
01871         case IDOK:
01872         case IDCANCEL:
01873             EndDialog(hWnd,0);
01874             return(TRUE);
01875         }
01876     }
01877     return(FALSE);
01878 }

Here is the call graph for this function:

Here is the caller graph for this function:

static LRESULT CALLBACK DlgProcProp ( HWND  hWnd,
UINT  Msg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 1724 of file npmngplg.c.

References PluginInstance::bytesalloc, PluginInstance::dibsize, PluginInstance::filesize, PluginInstance::fMode, get_imagetype_name(), IDC_IMGINFO, IDC_MNGTEXT, PluginInstance::islink, PluginInstance::linktarget, PluginInstance::linkurl, PluginInstance::loadstate, PluginInstance::lpdib, PluginInstance::lpdibinfo, PluginInstance::mng, mng_get_framecount(), mng_get_imagetype(), mng_get_layercount(), mng_get_playtime(), mng_get_sigtype(), mng_get_simplicity(), PluginInstance::mngdata, NP_EMBED, STATE_VALIDFRAME, PluginInstance::textdata, PluginInstance::url, PluginInstance::windowheight, and PluginInstance::windowwidth.

Referenced by PropDialog().

01725 {
01726     char buf[4096],buf2[1024];
01727 
01728     switch(Msg) {
01729     case WM_INITDIALOG:
01730         {
01731             DWORD tabs[1];
01732 
01733             PluginInstance *This=(PluginInstance*)lParam;
01734 
01735             tabs[0]= 60;
01736             SendDlgItemMessage(hWnd,IDC_IMGINFO,EM_SETTABSTOPS,(WPARAM)1,(LPARAM)tabs);
01737 
01738             wsprintf(buf,"URL:\t%s\r\n",This->url);
01739 
01740             if(This->lpdib) {
01741                 wsprintf(buf2,"Dimensions:\t%d x %d\r\n",This->lpdibinfo->biWidth,
01742                     This->lpdibinfo->biHeight);
01743                 lstrcat(buf,buf2);
01744             }
01745 
01746             if(This->lpdib && This->fMode==NP_EMBED) {
01747                 wsprintf(buf2,"Window:\t%d x %d\r\n",This->windowwidth,
01748                     This->windowheight);
01749                 lstrcat(buf,buf2);
01750             }
01751 
01752             if(This->filesize) {
01753                 wsprintf(buf2,"File size:\t%u bytes\r\n",This->filesize);
01754                 lstrcat(buf,buf2);
01755             }
01756 
01757 #ifdef _DEBUG
01758             if(This->mngdata && This->lpdib && This->bytesalloc && This->dibsize) {
01759                 // note this doesn't include memory used by libmng
01760                 wsprintf(buf2,"Memory used:\t%u bytes\r\n",
01761                     This->bytesalloc + This->dibsize);
01762                 lstrcat(buf,buf2);
01763             }
01764 #endif
01765 
01766             if(This->islink) {
01767                 wsprintf(buf2,"Link to:\t%s\r\n",This->linkurl);
01768                 lstrcat(buf,buf2);
01769                 if(strcmp(This->linktarget,"_self")) {
01770                     wsprintf(buf2,"Link target:\t%s\r\n",This->linktarget);
01771                     lstrcat(buf,buf2);
01772                 }
01773             }
01774 
01775             if(This->loadstate >= STATE_VALIDFRAME) {
01776                 wsprintf(buf2,"Signature:\t%s\r\n",get_imagetype_name(mng_get_sigtype(This->mng)));
01777                 lstrcat(buf,buf2);
01778                 wsprintf(buf2,"Image type:\t%s\r\n",get_imagetype_name(mng_get_imagetype(This->mng)));
01779                 lstrcat(buf,buf2);
01780                 wsprintf(buf2,"Simplicity:\t0x%08x\r\n",mng_get_simplicity(This->mng));
01781                 lstrcat(buf,buf2);
01782                 wsprintf(buf2,"Frame count:\t%u\r\n",mng_get_framecount(This->mng));
01783                 lstrcat(buf,buf2);
01784                 wsprintf(buf2,"Layer count:\t%u\r\n",mng_get_layercount(This->mng));
01785                 lstrcat(buf,buf2);
01786                 wsprintf(buf2,"Play time:\t%u\r\n",mng_get_playtime(This->mng));
01787                 lstrcat(buf,buf2);
01788             }
01789 
01790             SetDlgItemText(hWnd,IDC_IMGINFO,buf);
01791 
01792             if(This->textdata)
01793                 SetDlgItemText(hWnd,IDC_MNGTEXT,This->textdata);
01794         }
01795         return(TRUE);
01796     case WM_CLOSE:
01797         EndDialog(hWnd,0);
01798         return(TRUE);
01799     case WM_COMMAND:
01800         switch(wParam) {
01801         case IDOK:
01802         case IDCANCEL:
01803             EndDialog(hWnd,0);
01804             return(TRUE);
01805         }
01806     }
01807     return(FALSE);
01808 }

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL APIENTRY DllMain ( HANDLE  hModule,
DWORD  reason,
LPVOID  lpReserved 
)

Definition at line 151 of file npmngplg.c.

References g_hInst.

00152 {
00153     switch(reason) {
00154     case DLL_PROCESS_ATTACH:
00155         g_hInst=hModule;
00156         break;
00157     case DLL_THREAD_ATTACH:
00158         break;
00159     case DLL_THREAD_DETACH:
00160         break;
00161     case DLL_PROCESS_DETACH:
00162         break;
00163     }
00164     return TRUE;
00165 }

static void DynamicMNG_FireEvent ( PluginInstance This,
mng_uint8  eventtype,
POINTS  pos 
) [static]

Definition at line 1362 of file npmngplg.c.

References PluginInstance::dynamicmng, PluginInstance::mng, MNG_FALSE, PluginInstance::xscrollpos, and PluginInstance::yscrollpos.

Referenced by PluginWindowProc().

01363 {
01364     mng_retcode r;
01365     if(!This->mng) return;
01366     if(This->dynamicmng ==  0) return;
01367     if(This->dynamicmng == -1) {
01368         r=mng_status_dynamic(This->mng);
01369         if(r==MNG_FALSE) {
01370             return;
01371         }
01372         else {
01373             This->dynamicmng=1;
01374         }
01375     }
01376     mng_trapevent(This->mng, eventtype, pos.x+This->xscrollpos, pos.y+This->yscrollpos);
01377 }

Here is the caller graph for this function:

static void escapeformenu ( unsigned char *  s1  )  [static]

Definition at line 1211 of file npmngplg.c.

Referenced by ContextMenu().

01212 {
01213     int f, t, len;
01214     unsigned char s2[200];
01215 
01216     t=0;
01217     len=lstrlen(s1); if(len>50) len=50;
01218     for(f=0;f<len;f++) {
01219         if(s1[f]=='&') {
01220             s2[t++]='&';
01221             s2[t++]='&';
01222         }
01223         else if(s1[f]<32) {
01224             s2[t++]='_';
01225         }
01226         else {
01227             s2[t++]=s1[f];
01228         }
01229     }
01230     s2[t]='\0';
01231     lstrcpy(s1,s2);
01232 }

Here is the caller graph for this function:

static int file_exists ( const char *  fn  )  [static]

Definition at line 453 of file npmngplg.c.

References NULL.

00454 {
00455    HANDLE h;
00456 
00457    // try to open with no access
00458    h=CreateFile(fn,0,FILE_SHARE_READ,NULL,OPEN_EXISTING,
00459       FILE_ATTRIBUTE_NORMAL,NULL);
00460    if(h == INVALID_HANDLE_VALUE) { return 0; }
00461    CloseHandle(h);
00462    return 1;
00463 }

static void find_window_size ( PluginInstance This  )  [static]

Definition at line 632 of file npmngplg.c.

References PluginInstance::fhWnd, PluginInstance::scrolling, PluginInstance::windowheight, and PluginInstance::windowwidth.

Referenced by NPP_SetWindow(), and PluginWindowProc().

00633 {
00634     RECT r;
00635     if(This->scrolling) {  // make sure scrollbars exist if needed
00636         ShowScrollBar(This->fhWnd,SB_BOTH,TRUE);
00637     }
00638     GetClientRect(This->fhWnd, &r);
00639     This->windowwidth=r.right;
00640     This->windowheight=r.bottom;
00641 }

Here is the caller graph for this function:

static char* get_imagetype_name ( mng_imgtype  t  )  [static]

Definition at line 1235 of file npmngplg.c.

References mng_it_jng, mng_it_mng, and mng_it_png.

Referenced by DlgProcProp().

01236 {
01237     switch(t) {
01238     case mng_it_mng: return "MNG";
01239     case mng_it_png: return "PNG";
01240     case mng_it_jng: return "JNG";
01241     }
01242     return "Unknown";
01243 }

Here is the caller graph for this function:

static unsigned char gethex ( const char *  s  )  [static]

Definition at line 609 of file npmngplg.c.

Referenced by hexcolor2rgb().

00610 {
00611     int v[2];
00612     int i;
00613 
00614     v[0]=v[1]=0; 
00615     for(i=0;i<2;i++) {
00616         if(s[i]>='a' && s[i]<='f') v[i]=s[i]-87;
00617         if(s[i]>='A' && s[i]<='F') v[i]=s[i]-55;
00618         if(s[i]>='0' && s[i]<='9') v[i]=s[i]-48;
00619     }
00620     return (unsigned char)(v[0]*16+v[1]);
00621 }

Here is the caller graph for this function:

static void handle_read_error ( PluginInstance This,
mng_retcode  rv 
) [static]

Definition at line 465 of file npmngplg.c.

References PluginInstance::loadstate, PluginInstance::mng, mng_getlasterror(), MNG_INVALIDSIG, MNG_NEEDMOREDATA, MNG_NEEDTIMERWAIT, MNG_NOERROR, mng_uint32(), PluginInstance::needresume, set_error(), and STATE_LOADED.

Referenced by ContextMenu(), my_init_mng(), NPP_DestroyStream(), NPP_Write(), and PluginWindowProc().

00466 {
00467     mng_int8     iSeverity;
00468     mng_chunkid  iChunkname;
00469     mng_uint32   iChunkseq;
00470     mng_int32    iExtra1;
00471     mng_int32    iExtra2;
00472     mng_pchar    zErrortext;
00473 
00474 #ifdef MNGPLG_TRACE
00475     fprintf(tracefile,"returned: %d\n",rv);
00476 #endif
00477 
00478     switch(rv) {
00479     case MNG_NOERROR: case MNG_NEEDTIMERWAIT:
00480         break;
00481 
00482     case MNG_NEEDMOREDATA:
00483         if(This->loadstate>=STATE_LOADED) {
00484             set_error(This,"Unexpected end of file");
00485         }
00486         else {
00487             This->needresume=1;
00488         }
00489         break;
00490 
00491     case MNG_INVALIDSIG:
00492         set_error(This,"Invalid or missing MNG file (maybe a 404 Not Found error)");
00493         break;
00494 
00495     default:
00496 
00497         mng_getlasterror(This->mng, &iSeverity,&iChunkname,&iChunkseq,&iExtra1,
00498             &iExtra2,&zErrortext);
00499 
00500         if(zErrortext) {
00501             set_error(This,"Error reported by libmng (%d)\r\n\r\n%s",(int)rv,zErrortext);
00502         }
00503         else {
00504             set_error(This,"Error %d reported by libmng",(int)rv);
00505         }
00506     }
00507 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void hexcolor2rgb ( const char *  s,
mng_uint16 r,
mng_uint16 g,
mng_uint16 b 
) [static]

Definition at line 623 of file npmngplg.c.

References gethex().

Referenced by NPP_New().

00624 {
00625     if(lstrlen(s)!=7) return;
00626     if(s[0]!='#') return;
00627     (*r)= gethex(&s[1]); (*r)= ((*r)<<8)|(*r);
00628     (*g)= gethex(&s[3]); (*g)= ((*g)<<8)|(*g);
00629     (*b)= gethex(&s[5]); (*b)= ((*b)<<8)|(*b);
00630 }

Here is the call graph for this function:

Here is the caller graph for this function:

static int init_color_management ( PluginInstance This  )  [static]

Definition at line 511 of file npmngplg.c.

References PluginInstance::mng, and mng_set_outputsrgb().

Referenced by my_init_mng().

00512 {
00513     mng_set_outputsrgb(This->mng);
00514     return 1;
00515 }

Here is the call graph for this function:

Here is the caller graph for this function:

static mng_ptr MNG_DECL memallocfunc ( mng_size_t  n  )  [static]

Definition at line 217 of file npmngplg.c.

Referenced by my_init_mng().

00218 {
00219     return (mng_ptr) calloc(n,1);
00220 }

Here is the caller graph for this function:

static void MNG_DECL memfreefunc ( mng_ptr  p,
mng_size_t  n 
) [static]

Definition at line 223 of file npmngplg.c.

Referenced by my_init_mng().

00224 {
00225     free((void*)p);
00226 }

Here is the caller graph for this function:

static int my_init_mng ( PluginInstance This  )  [static]

Definition at line 520 of file npmngplg.c.

References callback_closestream(), callback_getcanvasline(), callback_gettickcount(), callback_openstream(), callback_processheader(), callback_processtext(), callback_readdata(), callback_refresh(), callback_settimer(), handle_read_error(), init_color_management(), memallocfunc(), memfreefunc(), PluginInstance::mng, mng_initialize(), mng_readdisplay(), mng_set_bgcolor(), mng_set_suspensionmode(), mng_setcb_closestream(), mng_setcb_getcanvasline(), mng_setcb_gettickcount(), mng_setcb_openstream(), mng_setcb_processheader(), mng_setcb_processtext(), mng_setcb_readdata(), mng_setcb_refresh(), mng_setcb_settimer(), MNG_TRUE, NULL, and warn().

Referenced by NPP_NewStream().

00521 {
00522     mng_retcode rv;
00523     int err;
00524 
00525     This->mng = mng_initialize((mng_ptr)This,memallocfunc,memfreefunc,NULL);
00526     //(mng_memalloc)  (mng_memfree)
00527 
00528 #ifdef MNGPLG_CMS
00529     init_color_management(This);
00530 #endif
00531 
00532     err=0;
00533     rv=mng_setcb_openstream    (This->mng, callback_openstream   ); if(rv) err++;
00534     rv=mng_setcb_closestream   (This->mng, callback_closestream  ); if(rv) err++;
00535     rv=mng_setcb_readdata      (This->mng, callback_readdata     ); if(rv) err++;
00536     rv=mng_setcb_processheader (This->mng, callback_processheader); if(rv) err++;
00537     rv=mng_setcb_getcanvasline (This->mng, callback_getcanvasline); if(rv) err++;
00538     rv=mng_setcb_refresh       (This->mng, callback_refresh      ); if(rv) err++;
00539     rv=mng_setcb_gettickcount  (This->mng, callback_gettickcount ); if(rv) err++;
00540     rv=mng_setcb_settimer      (This->mng, callback_settimer     ); if(rv) err++;
00541     rv=mng_setcb_processtext   (This->mng, callback_processtext  ); if(rv) err++;
00542 
00543 #ifdef MNGPLG_TRACE
00544     rv=mng_setcb_traceproc     (This->mng, callback_traceproc    ); if(rv) err++;
00545 #endif
00546     if(err) {
00547         warn(This,"Error setting libmng callback functions");
00548         return 0;
00549     }
00550 
00551     rv= mng_set_suspensionmode (This->mng,MNG_TRUE);
00552     if(rv) {
00553         warn(This,"Error setting suspension mode");
00554         return 0;
00555     }
00556 
00557     // if the web page author provided a bgcolor, use it
00558     if(This->force_bgcolor) {
00559         rv=mng_set_bgcolor (This->mng, This->bg_r, This->bg_g, This->bg_b);
00560     }
00561 
00562 #ifdef MNGPLG_TRACE
00563     fprintf(tracefile,"initial readdisplay\n");
00564 #endif
00565 
00566     handle_read_error(This, mng_readdisplay(This->mng) );
00567     return 1;
00568 }

Here is the call graph for this function:

Here is the caller graph for this function:

NPError WINAPI NP_GetEntryPoints ( NPPluginFuncs pFuncs  ) 

Definition at line 1889 of file npmngplg.c.

References NPPluginFuncs::asfile, NPPluginFuncs::destroy, NPPluginFuncs::destroystream, NPPluginFuncs::event, NPPluginFuncs::newp, NPPluginFuncs::newstream, NP_VERSION_MAJOR, NP_VERSION_MINOR, NPERR_INVALID_FUNCTABLE_ERROR, NPERR_NO_ERROR, NPP_Destroy(), NPP_DestroyStream(), NPP_New(), NPP_NewStream(), NPP_Print(), NPP_SetWindow(), NPP_StreamAsFile(), NPP_Write(), NPP_WriteReady(), NULL, NPPluginFuncs::print, NPPluginFuncs::setwindow, NPPluginFuncs::version, NPPluginFuncs::write, and NPPluginFuncs::writeready.

01890 {
01891     if(!pFuncs) return NPERR_INVALID_FUNCTABLE_ERROR;
01892 
01893     pFuncs->version       = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
01894     pFuncs->newp          = NPP_New;
01895     pFuncs->destroy       = NPP_Destroy;
01896     pFuncs->setwindow     = NPP_SetWindow;
01897     pFuncs->newstream     = NPP_NewStream;
01898     pFuncs->destroystream = NPP_DestroyStream;
01899     pFuncs->asfile        = NPP_StreamAsFile;
01900     pFuncs->writeready    = NPP_WriteReady;
01901     pFuncs->write         = NPP_Write;
01902     pFuncs->print         = NPP_Print;
01903     pFuncs->event         = NULL;
01904 
01905     g_pluginFuncs         = pFuncs;
01906 
01907     return NPERR_NO_ERROR;
01908 }

Here is the call graph for this function:

NPError WINAPI NP_Initialize ( NPNetscapeFuncs pFuncs  ) 

Definition at line 1910 of file npmngplg.c.

References NPPluginFuncs::javaClass, NP_VERSION_MAJOR, NPERR_INCOMPATIBLE_VERSION_ERROR, NPERR_INVALID_FUNCTABLE_ERROR, NPP_Initialize(), NPP_URLNotify(), NPVERS_HAS_LIVECONNECT, NPVERS_HAS_NOTIFICATION, Private_GetJavaClass(), NPPluginFuncs::urlnotify, and NPNetscapeFuncs::version.

01911 {
01912     int navMinorVers;
01913 
01914     if(!pFuncs) return NPERR_INVALID_FUNCTABLE_ERROR;
01915 
01916     g_pNavigatorFuncs = pFuncs; // save it for future reference 
01917 
01918     if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR)
01919         return NPERR_INCOMPATIBLE_VERSION_ERROR;
01920 
01921     navMinorVers = g_pNavigatorFuncs->version & 0xFF;
01922     if(navMinorVers>=NPVERS_HAS_NOTIFICATION)
01923         g_pluginFuncs->urlnotify = NPP_URLNotify;
01924     if( navMinorVers>=NPVERS_HAS_LIVECONNECT)
01925         g_pluginFuncs->javaClass = Private_GetJavaClass();
01926 
01927     return NPP_Initialize();
01928 }

Here is the call graph for this function:

NPError WINAPI NP_Shutdown (  ) 

Definition at line 1930 of file npmngplg.c.

References NPERR_NO_ERROR, NPP_Shutdown(), and NULL.

01931 {
01932     NPP_Shutdown();
01933 
01934     g_pNavigatorFuncs = NULL;
01935     return NPERR_NO_ERROR;
01936 }

Here is the call graph for this function:

static NPError NPN_GetURL ( NPP  instance,
const char *  url,
const char *  target 
) [static]

Definition at line 142 of file npmngplg.c.

References NPNetscapeFuncs::geturl.

Referenced by ContextMenu(), and PluginWindowProc().

00143 {
00144     return g_pNavigatorFuncs->geturl(instance, url, target);
00145 }

Here is the caller graph for this function:

static const char* NPN_UserAgent ( NPP  instance  )  [static]

Definition at line 137 of file npmngplg.c.

References NPNetscapeFuncs::uagent.

00138 {
00139     return g_pNavigatorFuncs->uagent(instance);
00140 }

static NPError NPP_Destroy ( NPP  instance,
NPSavedData **  save 
) [static]

Definition at line 847 of file npmngplg.c.

References BeforeDestroyWindow(), PluginInstance::bkgdbrush, PluginInstance::bytesalloc, PluginInstance::dynamicmng, PluginInstance::fhWnd, PluginInstance::lpdib, PluginInstance::mng, mng_cleanup(), PluginInstance::mngdata, NPERR_INVALID_INSTANCE_ERROR, NPERR_NO_ERROR, NULL, NPP_t::pdata, and PluginInstance::textdata.

Referenced by NP_GetEntryPoints().

00848 {
00849     PluginInstance* This;
00850 
00851     if (instance == NULL) return NPERR_INVALID_INSTANCE_ERROR;
00852     This = (PluginInstance*) instance->pdata;
00853 
00854     if(!This) return NPERR_INVALID_INSTANCE_ERROR;
00855 
00856     if(This->mng) {
00857         This->dynamicmng=0;
00858         mng_cleanup(&This->mng); 
00859         This->mng=0;
00860     }
00861     if(This->lpdib) {
00862         free(This->lpdib);
00863         This->lpdib=NULL;
00864     }
00865     if(This->mngdata) {
00866         free(This->mngdata);
00867         This->mngdata=NULL;
00868         This->bytesalloc=0;
00869     }
00870     if(This->textdata) {
00871         free(This->textdata);
00872         This->textdata=NULL;
00873     }
00874 
00875     if( This->fhWnd ) { // un-subclass the plugin window
00876         BeforeDestroyWindow(This);
00877     }
00878 
00879     if(This->bkgdbrush) DeleteObject((HGDIOBJ)This->bkgdbrush);
00880 
00881     if(This) {
00882         if(instance->pdata) free(instance->pdata);
00883         instance->pdata = NULL;
00884     }
00885 
00886     return NPERR_NO_ERROR;
00887 }

Here is the call graph for this function:

Here is the caller graph for this function:

static NPError NPP_DestroyStream ( NPP  instance,
NPStream stream,
NPError  reason 
) [static]

Definition at line 1051 of file npmngplg.c.

References PluginInstance::bytesloaded, PluginInstance::fhWnd, PluginInstance::filesize, handle_read_error(), PluginInstance::loadstate, PluginInstance::mng, mng_display_resume(), PluginInstance::needresume, NPERR_INVALID_INSTANCE_ERROR, NPERR_NO_ERROR, NPRES_DONE, NPP_t::pdata, set_error(), STATE_LOADED, and PluginInstance::timer_set.

Referenced by NP_GetEntryPoints().

01052 {
01053     PluginInstance* This;
01054     if(!instance) return NPERR_INVALID_INSTANCE_ERROR;
01055 
01056     This = (PluginInstance*) instance->pdata;
01057 //  if(reason==NPRES_DONE) {
01058     This->filesize = This->bytesloaded;
01059     This->loadstate = STATE_LOADED;
01060 //  }
01061 
01062     if(reason!=NPRES_DONE) {
01063         set_error(This,"Image load failed or was canceled (%d)",(int)reason);
01064         This->needresume=0;
01065         if(This->timer_set) { KillTimer(This->fhWnd,1); This->timer_set=0; }
01066         return NPERR_NO_ERROR;
01067     }
01068 
01069 #ifdef MNGPLG_TRACE
01070     fprintf(tracefile,"NPP_DestroyStream reason=%d needresume=%d\n",reason,This->needresume);
01071 #endif
01072 
01073     if(This->needresume) {
01074         This->needresume=0;
01075 //      handle_read_error(This, mng_read_resume(This->mng) );
01076         handle_read_error(This, mng_display_resume(This->mng) );
01077 //      This->needresume=0;
01078     }
01079 
01080     return NPERR_NO_ERROR;
01081 }

Here is the call graph for this function:

Here is the caller graph for this function:

static NPError NPP_Initialize ( void   )  [static]

Definition at line 571 of file npmngplg.c.

References g_hInst, hcurHandNS, hfontMsg, IDC_HAND, NPERR_NO_ERROR, NULL, and warn().

Referenced by NP_Initialize().

00572 {
00573     if(!g_hInst) {
00574         warn(NULL,"MNG plugin error: Cannot load resources");
00575     }
00576 
00577 #ifdef MNGPLG_TRACE
00578     tracefile=fopen("c:\\temp\\mngtrace.txt","w");
00579 #endif
00580 
00581 #ifndef IDC_HAND
00582 #define IDC_HAND MAKEINTRESOURCE(32649)
00583 #endif
00584     hcurHandNS = LoadCursor(NULL,IDC_HAND);
00585     if(!hcurHandNS) {
00586         hcurHandNS=LoadCursor(g_hInst,"CURHAND_NS");
00587     }
00588 
00589     hfontMsg=CreateFont(-12,0,0,0,FW_DONTCARE,TRUE,0,0,ANSI_CHARSET,
00590         OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DRAFT_QUALITY,
00591         VARIABLE_PITCH|FF_SWISS,"Arial");
00592     return NPERR_NO_ERROR;
00593 }

Here is the call graph for this function:

Here is the caller graph for this function:

static NPError NPP_New ( NPMIMEType  pluginType,
NPP  instance,
uint16  mode,
int16  argc,
char *  argn[],
char *  argv[],
NPSavedData saved 
) [static]

Definition at line 750 of file npmngplg.c.

References PluginInstance::bg_b, PluginInstance::bg_g, PluginInstance::bg_r, PluginInstance::bkgdbrush, PluginInstance::dibsize, PluginInstance::dynamicmng, PluginInstance::errorflag, PluginInstance::errormsg, PluginInstance::fDefaultWindowProc, PluginInstance::fhWnd, PluginInstance::filesize, PluginInstance::fMode, PluginInstance::force_bgcolor, PluginInstance::frozen, PluginInstance::fWindow, hcurHandNS, hexcolor2rgb(), PluginInstance::instance, PluginInstance::islink, PluginInstance::linkcursor, PluginInstance::linktarget, PluginInstance::linkurl, PluginInstance::loadstate, PluginInstance::lpdib, MAXLEN_TARGET, MAXLEN_URL, PluginInstance::mng, PluginInstance::mouse_captured, PluginInstance::mouse_over_mng, PluginInstance::needresume, NP_FULL, NPERR_INVALID_INSTANCE_ERROR, NPERR_NO_ERROR, NPERR_OUT_OF_MEMORY_ERROR, NULL, PluginInstance::paintedyet, NPP_t::pdata, PluginInstance::scrolling, STATE_INIT, PluginInstance::timer2_set, PluginInstance::timer_set, PluginInstance::url, PluginInstance::windowheight, PluginInstance::windowwidth, PluginInstance::xscrollpos, and PluginInstance::yscrollpos.

Referenced by NP_GetEntryPoints().

00752 {
00753     PluginInstance* This;
00754     int i;
00755     
00756     if (instance == NULL) {
00757         return NPERR_INVALID_INSTANCE_ERROR;
00758     }
00759     instance->pdata = calloc(sizeof(PluginInstance),1);
00760 
00761 
00762     This = (PluginInstance*) instance->pdata;
00763     if (This == NULL) {
00764         return NPERR_OUT_OF_MEMORY_ERROR;
00765     }
00766 
00767     This->force_bgcolor=1;
00768     This->bg_r = This->bg_g = This->bg_b = 0xffff;
00769 
00770     /* record some info for later lookup */
00771     This->fWindow = NULL;
00772     This->fMode = mode;
00773     
00774     This->fhWnd = NULL;
00775     This->fDefaultWindowProc = NULL;
00776     This->instance = instance;  /* save the instance id for reverse lookups */
00777     This->scrolling = (mode==NP_FULL);
00778     This->xscrollpos = This->yscrollpos = 0;
00779     This->windowwidth = This->windowheight = 0;
00780 
00781     This->loadstate = STATE_INIT;
00782     This->paintedyet = 0;
00783     This->mng=0;
00784     This->lpdib=NULL;
00785     lstrcpy(This->url,"");
00786     This->frozen=0;
00787     This->needresume=0;
00788     This->errorflag=0;
00789     lstrcpy(This->errormsg,"");
00790 
00791     This->dibsize = This->filesize = 0;
00792 
00793     lstrcpy(This->linkurl,"");
00794     lstrcpy(This->linktarget,"_self");
00795     This->islink=0;
00796     
00797     This->timer_set=0;
00798     This->timer2_set=0;
00799     This->dynamicmng= -1;
00800     This->mouse_over_mng=0;
00801     This->mouse_captured=0;
00802 
00803     This->linkcursor = hcurHandNS;
00804 
00805     // examine the <embed> tag arguments
00806     for(i=0;i<argc;i++) {
00807         if(!_stricmp(argn[i],"bgcolor")) {
00808             This->force_bgcolor=1;
00809             hexcolor2rgb(argv[i],&This->bg_r,&This->bg_g,&This->bg_b);
00810         }
00811         else if(!_stricmp(argn[i],"href")) {
00812             lstrcpyn(This->linkurl,argv[i],MAXLEN_URL);
00813             This->islink=1;
00814         }
00815         else if(!_stricmp(argn[i],"target")) {
00816             lstrcpyn(This->linktarget,argv[i],MAXLEN_TARGET);
00817         }
00818     }
00819 
00820     This->bkgdbrush=NULL;
00821     if(This->force_bgcolor)
00822         This->bkgdbrush=CreateSolidBrush(RGB(This->bg_r,This->bg_g,This->bg_b));
00823 
00824     return NPERR_NO_ERROR;
00825 }

Here is the call graph for this function:

Here is the caller graph for this function:

static NPError NPP_NewStream ( NPP  instance,
NPMIMEType  type,
NPStream stream,
NPBool  seekable,
uint16 stype 
) [static]

Definition at line 949 of file npmngplg.c.

References PluginInstance::bytesalloc, PluginInstance::bytesloaded, PluginInstance::byteswanted, NPStream::end, PluginInstance::libmngpos, PluginInstance::loadstate, PluginInstance::mngdata, my_init_mng(), NP_NORMAL, NPERR_GENERIC_ERROR, NPERR_INVALID_INSTANCE_ERROR, NPERR_NO_ERROR, NULL, NPP_t::pdata, STATE_LOADING, PluginInstance::textdata, NPStream::url, and PluginInstance::url.

Referenced by NP_GetEntryPoints().

00950                                          {
00951     PluginInstance* This;
00952 
00953     if(instance==NULL)
00954         return NPERR_INVALID_INSTANCE_ERROR;
00955 
00956     This = (PluginInstance*) instance->pdata;
00957     if(!This)
00958         return NPERR_GENERIC_ERROR;
00959 
00960     /* save the URL for later */
00961     lstrcpyn(This->url,stream->url,MAX_PATH);
00962 
00963 
00964     This->libmngpos=0;
00965     This->bytesloaded=0;
00966     This->bytesalloc=0;
00967     This->byteswanted=0;
00968     This->mngdata=NULL;
00969     This->textdata=NULL;
00970 
00971     // if we know the total length of the stream in advance 
00972     // (most of the time we will, hopefully), allocate that amount.
00973     if(stream->end > 0) {
00974         This->mngdata = malloc(stream->end);
00975         This->bytesalloc= stream->end;
00976     }
00977 
00978     my_init_mng(This);
00979 
00980     This->loadstate=STATE_LOADING;
00981 
00982     (*stype)=NP_NORMAL;
00983 
00984     return NPERR_NO_ERROR;
00985 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void NPP_Print ( NPP  instance,
NPPrint printInfo 
) [static]

Definition at line 1090 of file npmngplg.c.

References NPPrint::embedPrint, NPPrint::fullPrint, NPWindow::height, PluginInstance::loadstate, PluginInstance::lpdib, PluginInstance::lpdibbits, PluginInstance::lpdibinfo, NPPrint::mode, NP_FULL, NULL, NPP_t::pdata, NPEmbedPrint::platformPrint, NPFullPrint::platformPrint, NPFullPrint::pluginPrinted, NPPrint::print, NPFullPrint::printOne, STATE_VALIDFRAME, NPNetscapeFuncs::version, NPWindow::width, NPEmbedPrint::window, NPWindow::x, and NPWindow::y.

Referenced by NP_GetEntryPoints().

01091 {
01092     PluginInstance* This;
01093     if (instance == NULL) return;
01094     This = (PluginInstance*) instance->pdata;
01095 
01096     if(printInfo == NULL) {
01097         // Some browsers (Netscape) set printInfo to NULL to tell the plugin
01098         // to print in full page mode (this may be a bug).
01099         // PrintFullPage();  -- full page printing not implemented
01100         return;
01101     }
01102     
01103     if (printInfo->mode == NP_FULL) {
01104         /* the plugin is full-page, and the browser is giving it a chance
01105          * to print in the manner of its choosing */
01106         void* platformPrint = printInfo->print.fullPrint.platformPrint;
01107         NPBool printOne =  printInfo->print.fullPrint.printOne;
01108         
01109         /* Setting this to FALSE and returning *should* cause the browser to
01110          * call NPP_Print again, this time with mode=NP_EMBED.
01111          * However, that doesn't happen with any browser I've ever seen :-(.
01112          * Instead of the following line, you will probably need to implement
01113          * printing yourself.  You also might as well set pluginPrinted to TRUE,
01114          * though every browser I've tested ignores it. */
01115         printInfo->print.fullPrint.pluginPrinted = FALSE;
01116         /*  or */
01117         /*  PrintFullPage();
01118          *  printInfo->print.fullPrint.pluginPrinted = TRUE;  */
01119     }
01120     else {  // we are embedded, and the browser had provided a printer context
01121         HDC pdc;
01122         int prevstretchmode;
01123         NPWindow* printWindow;
01124         
01125         if(This->loadstate < STATE_VALIDFRAME) return;
01126 
01127         printWindow= &(printInfo->print.embedPrint.window);
01128 
01129         /* embedPrint.platformPrint is a Windows device context in disguise */
01130 
01131         /* The definition of NPWindow changed between API verion 0.9 and 0.11,
01132          * increasing in size from 28 to 32 bytes. This normally makes it
01133          * impossible for version 0.9 browsers to print version 0.11 plugins
01134          * (because the platformPrint field ends up at the wrong offset) --
01135          * unless the plugin takes special care to detect this situation.
01136          * To work around it, if we are compiled with API 0.11 or higher,
01137          * and the browser is version 0.9 or earlier, we look for the HDC
01138          * 4 bytes earlier, at offset 28 instead of 32 (of the embedPrint
01139          * sub-structure).
01140          */
01141 
01142         if(sizeof(NPWindow)>28 &&     /* i.e. is plugin API >= 0.11? */
01143                  HIBYTE(g_pNavigatorFuncs->version)==0 &&
01144                  LOBYTE(g_pNavigatorFuncs->version)<=9) {
01145             char *tmpc;
01146             HDC  *tmph;
01147 
01148             tmpc= (char*)&(printInfo->print.embedPrint);
01149             tmph= (HDC*)&tmpc[28];
01150             pdc=  *tmph;
01151         }
01152         else {
01153             pdc= (HDC) (printInfo->print.embedPrint.platformPrint);
01154         }
01155 
01156         if(!This->lpdib) return;
01157 
01158         prevstretchmode=SetStretchBltMode(pdc,COLORONCOLOR);
01159         StretchDIBits(pdc,
01160             printWindow->x,printWindow->y,
01161             printWindow->width,printWindow->height, /* dest coords */
01162             0,0,This->lpdibinfo->biWidth, This->lpdibinfo->biHeight,   /* source coords */
01163             This->lpdibbits, (LPBITMAPINFO)This->lpdib,
01164             DIB_RGB_COLORS,SRCCOPY);
01165         if(prevstretchmode) SetStretchBltMode(pdc,prevstretchmode);
01166     }
01167     return;
01168 }

Here is the caller graph for this function:

static NPError NPP_SetWindow ( NPP  instance,
NPWindow window 
) [static]

Definition at line 890 of file npmngplg.c.

References BeforeDestroyWindow(), PluginInstance::fDefaultWindowProc, PluginInstance::fhWnd, find_window_size(), PluginInstance::fWindow, gInstanceLookupString, NPERR_INVALID_INSTANCE_ERROR, NPERR_NO_ERROR, NULL, NPP_t::pdata, PluginWindowProc(), set_scrollbars(), and NPWindow::window.

Referenced by NP_GetEntryPoints().

00891 {
00892     NPError result = NPERR_NO_ERROR;
00893     PluginInstance* This;
00894 
00895     if (instance == NULL) return NPERR_INVALID_INSTANCE_ERROR;
00896 
00897     This = (PluginInstance*) instance->pdata;
00898 
00899     if( This->fhWnd != NULL ) {   /* If we already have a window... */
00900 
00901         if( (window == NULL) || ( window->window == NULL ) ) {
00902             /* There is now no window to use. get rid of the old
00903              * one and exit. */
00904             BeforeDestroyWindow(This);
00905             This->fWindow=window;
00906             return NPERR_NO_ERROR;
00907         }
00908 
00909         else if ( This->fhWnd == (HWND) window->window ) {
00910             /* The new window is the same as the old one. Redraw and get out. */
00911             This->fWindow=window;
00912 
00913             InvalidateRect( This->fhWnd, NULL, FALSE );
00914             /* UpdateWindow( This->fhWnd ); */
00915             return NPERR_NO_ERROR;
00916         }
00917         else {
00918             /* Unsubclass the old window, so that we can subclass the new
00919              * one later. */
00920             BeforeDestroyWindow(This);
00921         }
00922     }
00923     else if( (window == NULL) || ( window->window == NULL ) ) {
00924         /* We can just get out of here if there is no current
00925          * window and there is no new window to use. */
00926         This->fWindow=window;
00927 
00928         return NPERR_NO_ERROR;
00929     }
00930 
00931     /* Subclass the new window so that we can begin drawing and
00932      * receiving window messages. */
00933     This->fDefaultWindowProc = (WNDPROC)SetWindowLong( (HWND)window->window, GWL_WNDPROC, (LONG)PluginWindowProc);
00934     This->fhWnd = (HWND) window->window;
00935     SetProp( This->fhWnd, gInstanceLookupString, (HANDLE)This);
00936 
00937     This->fWindow = window;
00938     find_window_size(This);
00939 
00940     set_scrollbars(This);
00941 
00942     InvalidateRect( This->fhWnd, NULL, TRUE );
00943     UpdateWindow( This->fhWnd );
00944 
00945     return result;
00946 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void NPP_Shutdown ( void   )  [static]

Definition at line 596 of file npmngplg.c.

References hfontMsg, and NULL.

Referenced by NP_Shutdown().

00597 {
00598 #ifdef MNGPLG_TRACE
00599     if(tracefile) {
00600         fclose(tracefile);
00601         tracefile=NULL;
00602     }
00603 #endif
00604     if(hfontMsg) DeleteObject((HGDIOBJ)hfontMsg);
00605     return;
00606 }

Here is the caller graph for this function:

static void NPP_StreamAsFile ( NPP  instance,
NPStream stream,
const char *  fname 
) [static]

Definition at line 1084 of file npmngplg.c.

Referenced by NP_GetEntryPoints().

01085 {
01086     return;
01087 }

Here is the caller graph for this function:

static void NPP_URLNotify ( NPP  instance,
const char *  url,
NPReason  reason,
void *  notifyData 
) [static]

Definition at line 1175 of file npmngplg.c.

Referenced by NP_Initialize().

01176 {
01177     return;
01178 }

Here is the caller graph for this function:

static int32 NPP_Write ( NPP  instance,
NPStream stream,
int32  offset,
int32  len,
void *  buffer 
) [static]

Definition at line 996 of file npmngplg.c.

References ALLOC_CHUNK_SIZE, PluginInstance::bytesalloc, PluginInstance::bytesloaded, PluginInstance::byteswanted, handle_read_error(), PluginInstance::libmngpos, PluginInstance::mng, mng_display_resume(), PluginInstance::mngdata, PluginInstance::needresume, NPP_t::pdata, and warn().

Referenced by NP_GetEntryPoints().

00997 {
00998     PluginInstance* This;
00999 
01000 #ifdef MNGPLG_TRACE
01001     fprintf(tracefile,"NPP_Write offs=%d len=%d\n",offset,len);
01002 #endif
01003 
01004 
01005     if(!instance) return -1;
01006     This = (PluginInstance*) instance->pdata;
01007     if(!This) return -1;
01008     if(len<1) return len;
01009 
01010     if(offset+len > (int)This->bytesalloc) {  // oops, overflowed our memory buffer
01011         This->bytesalloc += ALLOC_CHUNK_SIZE;
01012         if(This->mngdata) {
01013             This->mngdata=realloc(This->mngdata, This->bytesalloc);
01014         }
01015         else {  // first time
01016             This->mngdata=malloc(This->bytesalloc);
01017         }
01018         if(!This->mngdata) {
01019             warn(This,"Cannot allocate memory for image (%d,%d,%p",offset,len,buffer);
01020             return -1;
01021         }
01022     }
01023 
01024     // now we should have enough room to copy the data to memory
01025 
01026     CopyMemory(&This->mngdata[offset],buffer,len);
01027 
01028     This->bytesloaded = offset+len;
01029 
01030     // now, check if it's time to call mng_read_resume
01031     if(This->needresume &&
01032         (This->bytesloaded >= (This->libmngpos + This->byteswanted)) )
01033     {
01034         This->needresume=0;
01035 //      handle_read_error(This, mng_read_resume(This->mng) );
01036 
01037 #ifdef MNGPLG_TRACE
01038     fprintf(tracefile,"NPP_Write display_resume bytesloaded=%d libmngpos=%d byteswanted=%d\n",
01039         This->bytesloaded,This->libmngpos,This->byteswanted);
01040 #endif
01041 
01042         handle_read_error(This, mng_display_resume(This->mng) );
01043     }
01044 
01045 
01046     return len; // The number of bytes accepted -- we always accept them all.
01047 }

Here is the call graph for this function:

Here is the caller graph for this function:

static int32 NPP_WriteReady ( NPP  instance,
NPStream stream 
) [static]

Definition at line 987 of file npmngplg.c.

Referenced by NP_GetEntryPoints().

00988 {
00989     /* Number of bytes ready to accept in NPP_Write() */
00990     /* We can handle any amount, so just return some really big number. */
00991     return (int32)0X0FFFFFFF;
00992 }

Here is the caller graph for this function:

static LRESULT CALLBACK PluginWindowProc ( HWND  hWnd,
UINT  Msg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 1509 of file npmngplg.c.

References PluginInstance::bkgdbrush, PluginInstance::bytesloaded, ContextMenu(), display_last_error(), PluginInstance::dynamicmng, DynamicMNG_FireEvent(), PluginInstance::errorflag, PluginInstance::fDefaultWindowProc, PluginInstance::fhWnd, find_window_size(), gInstanceLookupString, handle_read_error(), hdc, hfontMsg, PluginInstance::instance, PluginInstance::islink, PluginInstance::linkcursor, PluginInstance::linktarget, PluginInstance::linkurl, PluginInstance::loadstate, PluginInstance::lpdib, PluginInstance::lpdibinfo, PluginInstance::mng, mng_display_resume(), PluginInstance::mouse_captured, PluginInstance::mouse_over_mng, MOUSE_POLL_INTERVAL, PluginInstance::needresume, NPN_GetURL(), NULL, scrollmsg(), set_scrollbars(), SetTimer(), STATE_LOADING, PluginInstance::timer2_set, PluginInstance::timer_set, PluginInstance::xscrollpos, and PluginInstance::yscrollpos.

Referenced by NPP_SetWindow().

01510 {
01511     PluginInstance* This;
01512     HDC hdc;
01513     RECT rect;
01514         
01515     This = (PluginInstance*) GetProp(hWnd, gInstanceLookupString);
01516 
01517     if(!This) return DefWindowProc( hWnd, Msg, wParam, lParam);
01518 
01519     switch(Msg) {
01520 
01521     case WM_ERASEBKGND:
01522         {
01523             HBRUSH br;
01524             hdc= (HDC)wParam;
01525 
01526             if(This->bkgdbrush)
01527                 br=This->bkgdbrush;
01528             else
01529                 br=GetStockObject(GRAY_BRUSH);
01530 
01531             GetClientRect(hWnd,&rect);
01532             FillRect(hdc,&rect,br);
01533             return 1;
01534         }
01535 
01536     case WM_HSCROLL:
01537     case WM_VSCROLL:
01538         scrollmsg(This,Msg,(int)(LOWORD(wParam)),(short int)(HIWORD(wParam)));
01539         return 0;
01540 
01541     case WM_SIZE:
01542         find_window_size(This);
01543         set_scrollbars(This);
01544         return 0;
01545 
01546 
01547     case WM_CONTEXTMENU: case WM_RBUTTONUP:
01548         ContextMenu(This, hWnd);
01549         return 0;
01550 
01551 
01552     case WM_SETCURSOR:
01553         if(LOWORD(lParam)==HTCLIENT) {
01554             if(This->islink) {
01555                 SetCursor(This->linkcursor);
01556                 return 1;
01557             }
01558         }
01559         break;
01560 
01561     case WM_LBUTTONDOWN:
01562         SetCapture(This->fhWnd);
01563         This->mouse_captured=1;
01564 
01565         if(This->dynamicmng && This->mng && !This->errorflag) {
01566             DynamicMNG_FireEvent(This,4,MAKEPOINTS(lParam));
01567         }
01568         return 0;
01569         
01570     case WM_LBUTTONUP:
01571         {
01572             RECT rc;
01573             POINT pt;
01574 
01575             if(This->mouse_captured) {
01576                 ReleaseCapture();
01577                 This->mouse_captured=0;
01578             }
01579             if(This->dynamicmng && This->mng && !This->errorflag) {
01580                 DynamicMNG_FireEvent(This,5,MAKEPOINTS(lParam));
01581             }
01582 
01583             // if mouse is not over image, don't follow links, etc.
01584             GetWindowRect(This->fhWnd,&rc);
01585             GetCursorPos(&pt);
01586             if(!PtInRect(&rc,pt)) return 0;
01587 
01588             if(This->islink) {
01589                 NPN_GetURL(This->instance,This->linkurl,This->linktarget);
01590                 return 0;
01591             }
01592             else if(This->errorflag) {
01593                 display_last_error(This);
01594             }
01595         }
01596         return 0;
01597 
01598     case WM_MOUSEMOVE:
01599 
01600         if(This->dynamicmng && This->mng && This->lpdib && !This->errorflag) {
01601             POINTS pos;
01602             int overimage;
01603 
01604             pos=MAKEPOINTS(lParam);
01605             overimage=0;
01606             if(pos.x>=0 && pos.x<This->lpdibinfo->biWidth && pos.y>=0 && pos.y<This->lpdibinfo->biHeight) {
01607                 overimage=1;
01608             }
01609 
01610             if(overimage) {
01611                 if(This->mouse_over_mng) {
01612                     // mouse is still over image: mouse move event
01613                     DynamicMNG_FireEvent(This,2,pos);  // 2=mouse move
01614                 }
01615                 else {
01616                     // mouse wasn't over the image but now it is: mouse-enter event
01617                     DynamicMNG_FireEvent(This,1,pos); // mouse enter
01618                 }
01619             }
01620             else { // mouse not now over image
01621                 if(This->mouse_over_mng) { // ... but it used to be
01622                     pos.x=0; pos.y=0;
01623                     DynamicMNG_FireEvent(This,3,pos); // 3=mouse leave
01624                 }
01625             }
01626 
01627             This->mouse_over_mng=overimage; // remember for next time
01628 
01629             if(This->mouse_over_mng && (This->dynamicmng==1) ) {
01630 #define MOUSE_POLL_INTERVAL  100    // milliseconds
01631                 SetTimer(This->fhWnd,2,MOUSE_POLL_INTERVAL,NULL);
01632                 This->timer2_set=0;
01633             }
01634         }
01635         return 0;
01636 
01637     case WM_PAINT:
01638         {
01639             PAINTSTRUCT paintStruct;
01640             HDC hdc;
01641             RECT rect2;
01642 
01643             hdc = BeginPaint( hWnd, &paintStruct );
01644             SetWindowOrgEx(hdc,This->xscrollpos,This->yscrollpos,NULL);
01645 
01646             GetClientRect(hWnd,&rect);
01647             if(This) {
01648                 if(This->errorflag || !This->lpdib) {
01649                     SelectObject(hdc,hfontMsg);
01650                     Rectangle(hdc,rect.left,rect.top,rect.right,rect.bottom);
01651                     rect2.left=rect.left+2;
01652                     rect2.top=rect.top+2;
01653                     rect2.right=rect.right-2;
01654                     rect2.bottom=rect.bottom-2;
01655                     if(This->errorflag) {
01656                         DrawText(hdc,"MNG PLUG-IN ERROR!",-1,&rect2,DT_LEFT|DT_WORDBREAK);
01657                     }
01658                     else {
01659                         if(This->loadstate>=STATE_LOADING) {
01660                             DrawText(hdc,"MNG image loading...",-1,&rect2,DT_LEFT|DT_WORDBREAK);
01661                         }
01662                         else {
01663                             DrawText(hdc,"MNG plug-in",-1,&rect2,DT_LEFT|DT_WORDBREAK);
01664                         }
01665                     }
01666                 }
01667                 else if(This->lpdib) {
01668                     StretchDIBits(hdc,
01669                         0,0,This->lpdibinfo->biWidth,This->lpdibinfo->biHeight,
01670                         0,0,This->lpdibinfo->biWidth,This->lpdibinfo->biHeight,
01671                         &((BYTE*)(This->lpdib))[sizeof(BITMAPINFOHEADER)],
01672                         (LPBITMAPINFO)This->lpdib,DIB_RGB_COLORS,SRCCOPY);
01673                 }
01674             }
01675 
01676 
01677             EndPaint( hWnd, &paintStruct );
01678         }
01679         return 0;
01680 
01681     case WM_TIMER:
01682         switch(wParam) {
01683         case 1: // the main animation timer
01684             KillTimer(hWnd,1);
01685             This->timer_set=0;
01686 
01687 #ifdef MNGPLG_TRACE
01688             fprintf(tracefile,"WM_TIMER display_resume bytesloaded=%d\n",This->bytesloaded);
01689 #endif
01690 
01691             if(This->mng) {
01692                 if(!This->needresume) {
01693                     handle_read_error(This, mng_display_resume(This->mng) );
01694                 }
01695             }
01696             return 0;
01697 
01698         case 2: // timer for polling mouse position
01699             {
01700                 RECT rc;
01701                 POINT pt;
01702                 POINTS pos;
01703 
01704                 GetWindowRect(hWnd,&rc);
01705                 GetCursorPos(&pt);
01706                 if(!PtInRect(&rc,pt)) {
01707                     KillTimer(hWnd,2);
01708                     pos.x=0; pos.y=0;
01709                     DynamicMNG_FireEvent(This,3,pos); // 3=mouse leave
01710                     This->mouse_over_mng=0;
01711                 }
01712             }
01713             return 0;
01714         }
01715         break;
01716 
01717     }
01718 
01719     /* Forward unprocessed messages on to their original destination
01720      * (the window proc we replaced) */
01721     return This->fDefaultWindowProc(hWnd, Msg, wParam, lParam);
01722 }

Here is the call graph for this function:

Here is the caller graph for this function:

static JRIGlobalRef Private_GetJavaClass ( void   )  [static]

Definition at line 1884 of file npmngplg.c.

References NULL.

Referenced by NP_Initialize().

01885 {
01886     return NULL;
01887 }

Here is the caller graph for this function:

static void PropDialog ( PluginInstance This  )  [static]

Definition at line 1349 of file npmngplg.c.

References DlgProcProp(), PluginInstance::fhWnd, and g_hInst.

Referenced by ContextMenu().

01350 {
01351     //if(This->textdata)
01352     DialogBoxParam(g_hInst,"PROPDLG",This->fhWnd,(DLGPROC)DlgProcProp,(LPARAM)This);
01353 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void SaveImage ( PluginInstance This  )  [static]

Definition at line 1247 of file npmngplg.c.

References PluginInstance::bytesloaded, PluginInstance::fhWnd, PluginInstance::filesize, PluginInstance::loadstate, PluginInstance::mng, mng_get_sigtype(), mng_it_jng, mng_it_png, PluginInstance::mngdata, NULL, ofn, STATE_LOADED, PluginInstance::url, url2filename(), and warn().

Referenced by ContextMenu().

01248 {
01249     OPENFILENAME ofn;
01250     char fn[MAX_PATH];
01251     HANDLE hfile;
01252     BOOL b;
01253     mng_imgtype t;
01254     DWORD byteswritten;
01255 
01256     if(!This->mng || This->loadstate<STATE_LOADED ||
01257         This->bytesloaded != This->filesize)
01258     {
01259         warn(This,"Image not loaded -- can't save");
01260         return;
01261     }
01262 
01263     if(lstrlen(This->url)) {
01264         url2filename(fn,This->url);
01265     }
01266     else {
01267         lstrcpy(fn,"");
01268     }
01269 
01270     ZeroMemory(&ofn,sizeof(OPENFILENAME));
01271     ofn.lStructSize=sizeof(OPENFILENAME);
01272     ofn.hwndOwner=This->fhWnd;
01273     ofn.nFilterIndex=1;
01274     ofn.lpstrTitle="Save Image As...";
01275     ofn.lpstrFile=fn;
01276     ofn.nMaxFile=MAX_PATH;
01277     ofn.Flags=OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT;
01278 
01279     t=mng_get_sigtype(This->mng);
01280     if(t==mng_it_png) {
01281         ofn.lpstrDefExt="png";  // FIXME also give an option of MNG
01282         ofn.lpstrFilter="PNG (*.png)\0*.png\0\0";
01283     }
01284     else if(t==mng_it_jng) {
01285         ofn.lpstrDefExt="jng";  // FIXME also give an option of MNG
01286         ofn.lpstrFilter="JNG (*.jng)\0*.jng\0\0";
01287     }
01288     else {
01289         ofn.lpstrFilter="MNG (*.mng)\0*.mng\0\0";
01290         ofn.lpstrDefExt="mng";
01291     }
01292 
01293     if(GetSaveFileName(&ofn)) {
01294         // save to filename: ofn.lpstrFile
01295         hfile=CreateFile(ofn.lpstrFile,GENERIC_WRITE,FILE_SHARE_READ,
01296             NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
01297         if(hfile==INVALID_HANDLE_VALUE) {
01298             warn(This,"Unable to write file");
01299         }
01300         else {
01301             b=WriteFile(hfile, This->mngdata, This->filesize,
01302                 &byteswritten,NULL);
01303             if(!b || byteswritten != This->filesize) {
01304                 warn(This,"Error writing file");
01305             }
01306             CloseHandle(hfile);
01307         }
01308     }
01309 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void scrollmsg ( PluginInstance This,
UINT  msg,
int  code,
short int  pos 
) [static]

Definition at line 695 of file npmngplg.c.

References dx, dy, PluginInstance::fhWnd, PluginInstance::lpdib, PluginInstance::lpdibinfo, NULL, PluginInstance::scrolling, SCROLLLINE, set_scrollbars(), PluginInstance::windowheight, PluginInstance::windowwidth, PluginInstance::xscrollpos, and PluginInstance::yscrollpos.

Referenced by PluginWindowProc().

00696 {
00697     int page;
00698     int dx, dy;     // amount of scrolling
00699     int x_orig, y_orig;
00700 
00701     if(!This->scrolling) return;
00702     if(!This->lpdib) return;
00703 
00704     x_orig=This->xscrollpos;
00705     y_orig=This->yscrollpos;
00706 
00707     if(msg==WM_HSCROLL) {
00708         page=This->windowwidth-15;
00709         if(page<SCROLLLINE) page=SCROLLLINE;
00710 
00711         switch(code) {
00712         case SB_LINELEFT: This->xscrollpos-=SCROLLLINE; break;
00713         case SB_LINERIGHT: This->xscrollpos+=SCROLLLINE; break;
00714         case SB_PAGELEFT: This->xscrollpos-=page; break;
00715         case SB_PAGERIGHT: This->xscrollpos+=page; break;
00716         case SB_LEFT: This->xscrollpos=0; break;
00717         case SB_RIGHT: This->xscrollpos=This->lpdibinfo->biWidth; break;
00718         case SB_THUMBTRACK: This->xscrollpos=pos; break;
00719         default: return;
00720         }
00721         set_scrollbars(This);
00722     }
00723     else if(msg==WM_VSCROLL) {
00724         page=This->windowheight-15;
00725         if(page<SCROLLLINE) page=SCROLLLINE;
00726 
00727         switch(code) {
00728         case SB_LINEUP: This->yscrollpos-=SCROLLLINE; break;
00729         case SB_LINEDOWN: This->yscrollpos+=SCROLLLINE; break;
00730         case SB_PAGEUP: This->yscrollpos-=page; break;
00731         case SB_PAGEDOWN: This->yscrollpos+=page; break;
00732         case SB_TOP: This->yscrollpos=0; break;
00733         case SB_BOTTOM: This->yscrollpos=This->lpdibinfo->biHeight; break;
00734         case SB_THUMBTRACK: This->yscrollpos=pos; break;
00735         default: return;
00736         }
00737         set_scrollbars(This);
00738     }
00739 
00740     dx= x_orig - This->xscrollpos;
00741     dy= y_orig - This->yscrollpos;
00742 
00743     if(dx || dy) {  // if any change
00744         // GetClientRect(This->fhWnd,&cliprect);
00745         ScrollWindowEx(This->fhWnd,dx,dy,NULL,NULL /*&cliprect*/,NULL,NULL,SW_INVALIDATE);
00746     }
00747 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_error ( PluginInstance This,
char *  fmt,
  ... 
) [static]

Definition at line 187 of file npmngplg.c.

References PluginInstance::errorflag, PluginInstance::errormsg, PluginInstance::fhWnd, PluginInstance::lpdib, NULL, PluginInstance::xscrollpos, and PluginInstance::yscrollpos.

Referenced by handle_read_error(), and NPP_DestroyStream().

00188 {
00189     va_list ap;
00190     char buf[2048];
00191     HWND hwnd;
00192 
00193     va_start(ap, fmt);
00194     wvsprintf(buf,fmt, ap);
00195     va_end(ap);
00196 
00197     if(This) hwnd= This->fhWnd;
00198     else hwnd=NULL;
00199 
00200     This->errorflag=1;
00201     lstrcpyn(This->errormsg,buf,256);
00202 
00203     if(This->lpdib) {
00204         free(This->lpdib);
00205         This->lpdib=NULL;
00206     }
00207     This->xscrollpos = This->yscrollpos = 0;
00208 
00209     if(This->fhWnd)
00210         InvalidateRect(This->fhWnd,NULL,TRUE);
00211 }

Here is the caller graph for this function:

static void set_scrollbars ( PluginInstance This  ) 

Definition at line 643 of file npmngplg.c.

References PluginInstance::fhWnd, PluginInstance::lpdib, PluginInstance::lpdibinfo, PluginInstance::scrolling, PluginInstance::windowheight, PluginInstance::windowwidth, PluginInstance::xscrollpos, and PluginInstance::yscrollpos.

Referenced by callback_processheader(), NPP_SetWindow(), PluginWindowProc(), and scrollmsg().

00644 {
00645     SCROLLINFO si;
00646     int maxpos;
00647 
00648     if(!This->scrolling) return;
00649     if(!This->fhWnd) return;
00650 
00651     ZeroMemory(&si,sizeof(SCROLLINFO));
00652     si.cbSize = sizeof(SCROLLINFO);
00653 
00654     // horizontal
00655     if(This->lpdib) {
00656         maxpos=This->lpdibinfo->biWidth-This->windowwidth;
00657         if(maxpos<0) maxpos=0;
00658         if(This->xscrollpos>maxpos) This->xscrollpos=maxpos;
00659         if(This->xscrollpos<0) This->xscrollpos=0;
00660         
00661         si.fMask = SIF_ALL|SIF_DISABLENOSCROLL;
00662         si.nMin  = 0;
00663         si.nMax  = This->lpdibinfo->biWidth -1;
00664         si.nPage = This->windowwidth;
00665         si.nPos  = This->xscrollpos;
00666     }
00667     else {  // no image to display
00668         si.fMask = SIF_ALL|SIF_DISABLENOSCROLL;
00669         si.nMin  = 0;
00670         si.nMax  = 0;
00671         si.nPage = 1;
00672         si.nPos  = 0;
00673     }
00674     SetScrollInfo(This->fhWnd,SB_HORZ,&si,TRUE);
00675 
00676     // vertical
00677     if(This->lpdib) {
00678         maxpos=This->lpdibinfo->biHeight-This->windowheight;
00679         if(maxpos<0) maxpos=0;
00680         if(This->yscrollpos>maxpos) This->yscrollpos=maxpos;
00681         if(This->yscrollpos<0) This->yscrollpos=0;
00682 
00683         si.fMask = SIF_ALL|SIF_DISABLENOSCROLL;
00684         si.nMin  = 0;
00685         si.nMax  = This->lpdibinfo->biHeight -1;
00686         si.nPage = This->windowheight;
00687         si.nPos  = This->yscrollpos;
00688     }
00689     SetScrollInfo(This->fhWnd,SB_VERT,&si,TRUE);
00690 }

Here is the caller graph for this function:

static void url2filename ( char *  fn,
char *  url 
) [static]

Definition at line 1187 of file npmngplg.c.

Referenced by ContextMenu(), and SaveImage().

01188 {
01189     int title,ext,i;
01190 
01191     lstrcpy(fn,"");
01192     ext=0;   /* position of the file extention */
01193     title=0; /* position of the base filename */
01194     for(i=0;url[i];i++) {
01195         if(url[i]=='.') ext=i+1;
01196         if(url[i]=='/') title=i+1;
01197         if(url[i]=='\\') title=i+1;  // handle Microsoft's bogus file: "URLs"
01198         if(url[i]==':') title=i+1;
01199         if(url[i]=='=') title=i+1;
01200     }
01201 
01202     if (!_stricmp(&url[ext],"mng") ||
01203         !_stricmp(&url[ext],"jng") ||
01204         !_stricmp(&url[ext],"png") )
01205     {
01206         lstrcpyn(fn,&url[title],MAX_PATH);
01207     }
01208 }

Here is the caller graph for this function:

static void warn ( PluginInstance This,
char *  fmt,
  ... 
) [static]

Definition at line 170 of file npmngplg.c.

References PluginInstance::fhWnd, and NULL.

Referenced by callback_settimer(), ContextMenu(), CopyToClipboard(), display_last_error(), my_init_mng(), NPP_Initialize(), NPP_Write(), and SaveImage().

00171 {
00172     va_list ap;
00173     char buf[2048];
00174     HWND hwnd;
00175 
00176     va_start(ap, fmt);
00177     wvsprintf(buf,fmt, ap);
00178     va_end(ap);
00179 
00180     if(This) hwnd= This->fhWnd;
00181     else hwnd=NULL;
00182 
00183     MessageBox(hwnd,buf,"MNG Plug-in",MB_OK|MB_ICONWARNING);
00184 }

Here is the caller graph for this function:


Variable Documentation

HMODULE g_hInst = NULL [static]

Definition at line 120 of file npmngplg.c.

Referenced by AboutDialog(), DlgProcAbout(), DllMain(), NPP_Initialize(), and PropDialog().

NPPluginFuncs* g_pluginFuncs [static]

Definition at line 135 of file npmngplg.c.

NPNetscapeFuncs* g_pNavigatorFuncs [static]

Definition at line 134 of file npmngplg.c.

const char* gInstanceLookupString = "pdata" [static]

Definition at line 119 of file npmngplg.c.

Referenced by NPP_SetWindow(), and PluginWindowProc().

HCURSOR hcurHandNS [static]

Definition at line 121 of file npmngplg.c.

Referenced by NPP_Initialize(), and NPP_New().

HFONT hfontMsg [static]

Definition at line 122 of file npmngplg.c.

Referenced by NPP_Initialize(), NPP_Shutdown(), and PluginWindowProc().


Generated on Mon Feb 25 17:49:30 2008 for libmng.1010. by  doxygen 1.5.3