moz_main.c.svn-base
来自「SumatraPDF是一款小型开源的pdf阅读工具。虽然玲珑小巧(只有800多K」· SVN-BASE 代码 · 共 882 行 · 第 1/2 页
SVN-BASE
882 行
MozWinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){ pdfmoz_t *moz = (pdfmoz_t*) GetWindowLongPtr(hwnd, GWLP_USERDATA); char buf[256]; int x = (signed short) LOWORD(lParam); int y = (signed short) HIWORD(lParam); int i, h; SCROLLINFO si; PAINTSTRUCT ps; HDC hdc; RECT rc; RECT pad; WORD sendmsg; float zoom; GetClientRect(hwnd, &rc); h = rc.bottom - rc.top; if (strlen(moz->error)) { if (msg == WM_PAINT) { hdc = BeginPaint(hwnd, &ps); FillRect(hdc, &rc, GetStockBrush(WHITE_BRUSH)); rc.top += 10; rc.bottom -= 10; rc.left += 10; rc.right -= 10; DrawText(hdc, moz->error, strlen(moz->error), &rc, 0); // DT_SINGLELINE|DT_CENTER|DT_VCENTER); EndPaint(hwnd, &ps); } if (msg == WM_MOUSEMOVE) { SetCursor(moz->arrow); } return 0; } switch (msg) { case WM_PAINT: GetClientRect(moz->hwnd, &rc); si.cbSize = sizeof(si); si.fMask = SIF_ALL; GetScrollInfo(hwnd, SB_VERT, &si); decodescroll(moz, si.nPos); /* evict out-of-range images and pages */ for (i = 0; i < moz->pagecount; i++) { if (i < moz->scrollpage - 2 || i > moz->scrollpage + 6) { if (moz->pages[i].page) { pdf_droppage(moz->pages[i].page); moz->pages[i].page = nil; } } if (i < moz->scrollpage - 1 || i > moz->scrollpage + 3) { if (moz->pages[i].image) { fz_droppixmap(moz->pages[i].image); moz->pages[i].image = nil; } } } i = moz->scrollpage; pdfmoz_loadpage(moz, i); if (moz->error[0]) return 0; pdfmoz_drawpage(moz, i); if (moz->error[0]) return 0; y = -moz->scrollyofs; while (y < h && i < moz->pagecount) { pdfmoz_loadpage(moz, i); if (moz->error[0]) return 0; pdfmoz_drawpage(moz, i); if (moz->error[0]) return 0; y += moz->pages[i].image->h; i ++; } hdc = BeginPaint(hwnd, &ps); pad.left = rc.left; pad.right = rc.right; i = moz->scrollpage; y = -moz->scrollyofs; while (y < h && i < moz->pagecount) { drawimage(hdc, moz, moz->pages[i].image, y); y += moz->pages[i].image->h; i ++; pad.top = y; pad.bottom = y + PAD; FillRect(hdc, &pad, moz->graybrush); y += PAD; } if (y < h) { pad.top = y; pad.bottom = h; FillRect(hdc, &pad, moz->graybrush); } EndPaint(hwnd, &ps); return 0; case WM_SIZE: ShowScrollBar(moz->hwnd, SB_VERT, TRUE); GetClientRect(moz->hwnd, &rc); si.cbSize = sizeof(si); si.fMask = SIF_POS | SIF_RANGE | SIF_PAGE; si.nPos = 0; si.nMin = 0; si.nMax = 0; // si.nPage = MAX(30, rc.bottom - rc.top - 30); si.nPage = rc.bottom - rc.top; for (i = 0; i < moz->pagecount; i++) { zoom = (rc.right - rc.left) / (float) moz->pages[i].w; moz->pages[i].px = zoom * moz->pages[i].h + PAD; if (moz->scrollpage == i) { si.nPos = si.nMax; if (moz->pages[i].image) { si.nPos += moz->pages[i].px * moz->scrollyofs / moz->pages[i].image->h + 1; } } if (moz->pages[i].image) { fz_droppixmap(moz->pages[i].image); moz->pages[i].image = nil; } si.nMax += moz->pages[i].px; } si.nMax --; SetScrollInfo(moz->hwnd, SB_VERT, &si, TRUE); break; case WM_MOUSEMOVE: pdfmoz_onmouse(moz, x, y, 0); break; case WM_LBUTTONDOWN: SetFocus(hwnd); pdfmoz_onmouse(moz, x, y, 1); break; case WM_VSCROLL: si.cbSize = sizeof(si); si.fMask = SIF_ALL; GetScrollInfo(hwnd, SB_VERT, &si); switch (LOWORD(wParam)) { case SB_BOTTOM: si.nPos = si.nMax; break; case SB_TOP: si.nPos = 0; break; case SB_LINEUP: si.nPos -= 50; break; case SB_LINEDOWN: si.nPos += 50; break; case SB_PAGEUP: si.nPos -= si.nPage; break; case SB_PAGEDOWN: si.nPos += si.nPage; break; case SB_THUMBTRACK: si.nPos = si.nTrackPos; break; case SB_THUMBPOSITION: si.nPos = si.nTrackPos; break; } si.fMask = SIF_POS; si.nPos = MAX(0, MIN(si.nPos, si.nMax)); SetScrollInfo(hwnd, SB_VERT, &si, TRUE); InvalidateRect(moz->hwnd, NULL, FALSE); decodescroll(moz, si.nPos); sprintf(buf, "Page %d of %d", moz->scrollpage + 1, moz->pagecount); NPN_Status(moz->inst, buf); return 0; case WM_MOUSEWHEEL: if ((signed short)HIWORD(wParam) > 0) SendMessage(hwnd, WM_VSCROLL, MAKELONG(SB_LINEUP, 0), 0); else SendMessage(hwnd, WM_VSCROLL, MAKELONG(SB_LINEDOWN, 0), 0); break; case WM_KEYDOWN: sendmsg = 0xFFFF; switch (wParam) { case VK_UP: sendmsg = SB_LINEUP; break; case VK_PRIOR: sendmsg = SB_PAGEUP; break; case ' ': case VK_NEXT: sendmsg = SB_PAGEDOWN; break; case '\r': case VK_DOWN: sendmsg = SB_LINEDOWN; break; case VK_HOME: sendmsg = SB_TOP; break; case VK_END: sendmsg = SB_BOTTOM; break; } if (sendmsg != 0xFFFF) SendMessage(hwnd, WM_VSCROLL, MAKELONG(sendmsg, 0), 0); /* ick! someone eats events instead of bubbling... not my fault! */ break; default: break; } return moz->winproc(hwnd, msg, wParam, lParam);}NPErrorNPP_New(NPMIMEType mime, NPP inst, uint16 mode, int16 argc, char *argn[], char *argv[], NPSavedData *saved){ pdfmoz_t *moz; //MSG("NPP_New"); moz = fz_malloc(sizeof(pdfmoz_t)); if (!moz) return NPERR_OUT_OF_MEMORY_ERROR; memset(moz, 0, sizeof(pdfmoz_t)); sprintf(moz->error, "MuPDF is loading the file..."); moz->inst = inst; moz->arrow = LoadCursor(NULL, IDC_ARROW); moz->hand = LoadCursor(NULL, IDC_HAND); moz->wait = LoadCursor(NULL, IDC_WAIT); moz->dibinf = fz_malloc(sizeof(BITMAPINFO) + 12); if (!moz->dibinf) return NPERR_OUT_OF_MEMORY_ERROR; moz->dibinf->bmiHeader.biSize = sizeof(moz->dibinf->bmiHeader); moz->dibinf->bmiHeader.biPlanes = 1; moz->dibinf->bmiHeader.biBitCount = 24; moz->dibinf->bmiHeader.biCompression = BI_RGB; moz->dibinf->bmiHeader.biXPelsPerMeter = 2834; moz->dibinf->bmiHeader.biYPelsPerMeter = 2834; moz->dibinf->bmiHeader.biClrUsed = 0; moz->dibinf->bmiHeader.biClrImportant = 0; moz->dibinf->bmiHeader.biClrUsed = 0; moz->graybrush = CreateSolidBrush(RGB(0x70,0x70,0x70)); inst->pdata = moz; return NPERR_NO_ERROR;}NPErrorNPP_Destroy(NPP inst, NPSavedData **saved){ pdfmoz_t *moz = inst->pdata; int i; //MSG("NPP_Destroy"); inst->pdata = NULL; DeleteObject(moz->graybrush); DestroyCursor(moz->arrow); DestroyCursor(moz->hand); DestroyCursor(moz->wait); fz_free(moz->dibinf); for (i = 0; i < moz->pagecount; i++) { if (moz->pages[i].obj) fz_dropobj(moz->pages[i].obj); if (moz->pages[i].page) pdf_droppage(moz->pages[i].page); if (moz->pages[i].image) fz_droppixmap(moz->pages[i].image); } fz_free(moz->pages); if (moz->xref) { if (moz->xref->store) { pdf_dropstore(moz->xref->store); moz->xref->store = nil; } pdf_closexref(moz->xref); } fz_free(moz); return NPERR_NO_ERROR;}NPErrorNPP_SetWindow(NPP inst, NPWindow *npwin){ pdfmoz_t *moz = inst->pdata; if (moz->hwnd != npwin->window) { moz->hwnd = npwin->window; SetWindowLongPtr(moz->hwnd, GWLP_USERDATA, (LONG_PTR)moz); moz->winproc = (WNDPROC) SetWindowLongPtr(moz->hwnd, GWLP_WNDPROC, (LONG_PTR)MozWinProc); } SetFocus(moz->hwnd); return NPERR_NO_ERROR;}NPErrorNPP_NewStream(NPP inst, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype){ //MSG("NPP_NewStream"); *stype = NP_ASFILE; return NPERR_NO_ERROR;}NPErrorNPP_DestroyStream(NPP inst, NPStream* stream, NPReason reason){ //MSG("NPP_DestroyStream"); return NPERR_NO_ERROR;}int32NPP_WriteReady(NPP inst, NPStream* stream){ //MSG("NPP_WriteReady"); return 2147483647;}int32NPP_Write(NPP inst, NPStream* stream, int32 offset, int32 len, void* buffer){ //MSG("NPP_Write"); return len;}voidNPP_StreamAsFile(NPP inst, NPStream* stream, const char* fname){ pdfmoz_t *moz = inst->pdata; //MSG("NPP_StreamAsFile"); pdfmoz_open(moz, (char*)fname);}voidNPP_Print(NPP inst, NPPrint* platformPrint){ MSG("Sorry, printing is not supported.");}int16NPP_HandleEvent(NPP inst, void* event){ MSG("handle event\n"); return 0;}voidNPP_URLNotify(NPP inst, const char* url, NPReason reason, void* notifyData){ MSG("notify url\n");}NPErrorNPP_GetValue(void* inst, NPPVariable variable, void *value){ return NPERR_NO_ERROR;}NPErrorNPP_SetValue(void* inst, NPNVariable variable, void *value){ return NPERR_NO_ERROR;}void* NPP_GetJavaClass(void){ return 0;}NPErrorNPP_Initialize(void){ // MSG("NPP_Initialize"); return NPERR_NO_ERROR;}voidNPP_Shutdown(void){ // MSG("NPP_Shutdown");}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?