#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"

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 NPNetscapeFuncs * | g_pNavigatorFuncs |
| static NPPluginFuncs * | g_pluginFuncs |
| #define ALLOC_CHUNK_SIZE 131072 |
| #define ID_ABOUT (IDBASE+4) |
| #define ID_COPYIMAGE (IDBASE+1) |
| #define ID_COPYLINKLOC (IDBASE+7) |
| #define ID_COPYURL (IDBASE+2) |
| #define ID_FREEZE (IDBASE+5) |
| #define ID_PROPERTIES (IDBASE+10) |
| #define ID_RESTARTANIM (IDBASE+6) |
| #define ID_SAVEAS (IDBASE+0) |
| #define ID_SHOWERROR (IDBASE+9) |
| #define ID_STOPANIM (IDBASE+8) |
| #define ID_VIEWIMAGE (IDBASE+3) |
| #define IDBASE 47000 |
Definition at line 25 of file npmngplg.c.
| #define IDC_HAND MAKEINTRESOURCE(32649) |
Referenced by NPP_Initialize().
| #define MAXLEN_TARGET 100 |
| #define MAXLEN_TEXT 5000 |
| #define MAXLEN_URL 300 |
| #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" |
| #define MOUSE_POLL_INTERVAL 100 |
Referenced by PluginWindowProc().
| #define SCROLLLINE 40 |
| #define STATE_INIT 0 |
| #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 |
| #define STATE_VALIDFRAME 2 |
Definition at line 53 of file npmngplg.c.
Referenced by callback_refresh(), DlgProcProp(), and NPP_Print().
| 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 }


| 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 }

| 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 }


| 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 }


| 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 }


| 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 }

| 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 }


| 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 }


| 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 }
