📄 sumatrapdf.cpp.svn-base
字号:
if (win->dm) { RenderQueue_RemoveForDisplayModel(win->dm); cancelRenderingForDisplayModel(win->dm); } delete win->dm; if (win->pdfsync) { delete win->pdfsync; win->pdfsync = NULL; } if (win->stopFindStatusThreadEvent) { CloseHandle(win->stopFindStatusThreadEvent); win->stopFindStatusThreadEvent = NULL; } if (win->findStatusThread) { CloseHandle(win->findStatusThread); win->findStatusThread = NULL; } win->dm = NULL; WindowInfo_Dib_Deinit(win); WindowInfo_DoubleBuffer_Delete(win); free(win->title); win->title = NULL; delete win;}static WindowInfo* WindowInfo_FindByHwnd(HWND hwnd){ WindowInfo *win = gWindowList; while (win) { if (hwnd == win->hwndFrame) return win; if (hwnd == win->hwndCanvas) return win; if (hwnd == win->hwndReBar) return win; if (hwnd == win->hwndFindBox) return win; if (hwnd == win->hwndFindStatus) return win; if (hwnd == win->hwndPageBox) return win; win = win->next; } return NULL;}static WindowInfo *WindowInfo_New(HWND hwndFrame) { WindowInfo * win = WindowInfo_FindByHwnd(hwndFrame); assert(!win); win = new WindowInfo(); if (!win) return NULL; if (!WindowInfo_Dib_Init(win)) goto Error; win->state = WS_ABOUT; win->hwndFrame = hwndFrame; win->mouseAction = MA_IDLE; return win;Error: WindowInfo_Delete(win); return NULL;}static void WindowInfoList_Add(WindowInfo *win) { win->next = gWindowList; gWindowList = win;}static bool WindowInfoList_ExistsWithError(void) { WindowInfo *cur = gWindowList; while (cur) { if (WS_ERROR_LOADING_PDF == cur->state) return true; cur = cur->next; } return false;}static void WindowInfoList_Remove(WindowInfo *to_remove) { assert(to_remove); if (!to_remove) return; if (gWindowList == to_remove) { gWindowList = to_remove->next; return; } WindowInfo* curr = gWindowList; while (curr) { if (to_remove == curr->next) { curr->next = to_remove->next; return; } curr = curr->next; }}static void WindowInfoList_DeleteAll(void) { WindowInfo* curr = gWindowList; while (curr) { WindowInfo* next = curr->next; WindowInfo_Delete(curr); curr = next; } gWindowList = NULL;}static int WindowInfoList_Len(void) { int len = 0; WindowInfo* curr = gWindowList; while (curr) { ++len; curr = curr->next; } return len;}// Find the first windows showing a given PDF file WindowInfo* WindowInfoList_Find(LPTSTR file) { WindowInfo* curr = gWindowList; while (curr) { if (str_eq(curr->watcher.filepath(), file)) return curr; curr = curr->next; } return NULL;}static void WindowInfo_UpdateFindbox(WindowInfo *win) { InvalidateRect(win->hwndToolbar, NULL, true); if (!win->dm) { // Avoid focus on Find box SetClassLong(win->hwndFindBox, GCL_HCURSOR, (LONG)gCursorArrow); HideCaret(NULL); } else { SetClassLong(win->hwndFindBox, GCL_HCURSOR, (LONG)gCursorIBeam); ShowCaret(NULL); }}static void WindowInfo_RedrawAll(WindowInfo *win, bool update=false) { InvalidateRect(win->hwndCanvas, NULL, false); if (update) UpdateWindow(win->hwndCanvas);}static bool FileCloseMenuEnabled(void) { WindowInfo* win = gWindowList; while (win) { if (win->state == WS_SHOWING_PDF) return true; win = win->next; } return false;}bool TbIsSepId(int cmdId) { return (IDB_SEPARATOR == cmdId) || (IDB_SEPARATOR2 == cmdId);} static void ToolbarUpdateStateForWindow(WindowInfo *win) { const LPARAM enable = (LPARAM)MAKELONG(1,0); const LPARAM disable = (LPARAM)MAKELONG(0,0); for (size_t i=0; i < TOOLBAR_BUTTONS_COUNT; i++) { int cmdId = gToolbarButtons[i].cmdId; if (TbIsSepId(cmdId)) continue; // Assume the button is enabled. LPARAM buttonState = enable; if (gRestrictedUse && gToolbarButtons[i].flags & TBF_RESTRICTED) // If restricted, disable buttonState = disable; else if (WS_SHOWING_PDF != win->state) { // If no file open, only enable open button. if (IDM_OPEN != cmdId) buttonState = disable; } else // Figure out what to show. { switch( cmdId ) { case IDM_FIND_NEXT: case IDM_FIND_PREV: // TODO: Update on whether there's more to find, not just on whether there is text. wchar_t findBoxText[2]; GetWindowTextW(win->hwndFindBox, findBoxText, 2); if (findBoxText[0] == '\0') buttonState = disable; break; case IDM_GOTO_NEXT_PAGE: if (win->dm->currentPageNo() == win->dm->pageCount()) buttonState = disable; break; case IDM_GOTO_PREV_PAGE: if (win->dm->currentPageNo() == 1) buttonState = disable; break; } } SendMessage(win->hwndToolbar, TB_ENABLEBUTTON, cmdId, buttonState); }}static void MenuUpdateBookmarksStateForWindow(WindowInfo *win) { HMENU hmenu = GetMenu(win->hwndFrame); bool enabled = true; if (WS_SHOWING_PDF != win->state) { enabled = false; } else { if (!win->dm || !win->dm->hasTocTree()) enabled = false; } if (!enabled) { EnableMenuItem(hmenu, IDM_VIEW_BOOKMARKS, MF_BYCOMMAND | MF_GRAYED); return; } EnableMenuItem(hmenu, IDM_VIEW_BOOKMARKS, MF_BYCOMMAND | MF_ENABLED); if (win->dm->_showToc) CheckMenuItem(hmenu, IDM_VIEW_BOOKMARKS, MF_BYCOMMAND | MF_CHECKED); else CheckMenuItem(hmenu, IDM_VIEW_BOOKMARKS, MF_BYCOMMAND | MF_UNCHECKED);}static void MenuUpdateShowToolbarStateForWindow(WindowInfo *win) { HMENU hmenu = GetMenu(win->hwndFrame); if (gGlobalPrefs.m_showToolbar) CheckMenuItem(hmenu, IDM_VIEW_SHOW_HIDE_TOOLBAR, MF_BYCOMMAND | MF_CHECKED); else CheckMenuItem(hmenu, IDM_VIEW_SHOW_HIDE_TOOLBAR, MF_BYCOMMAND | MF_UNCHECKED);}static void MenuUpdateEnableAutoUpdateStateForWindow(WindowInfo *win) { HMENU hmenu = GetMenu(win->hwndFrame); if (gGlobalPrefs.m_enableAutoUpdate) CheckMenuItem(hmenu, IDM_ENABLE_AUTO_UPDATE, MF_BYCOMMAND | MF_CHECKED); else CheckMenuItem(hmenu, IDM_ENABLE_AUTO_UPDATE, MF_BYCOMMAND | MF_UNCHECKED);}// show which language is being used via check in Language/* menustatic void MenuUpdateLanguage(WindowInfo *win) { HMENU hmenu = GetMenu(win->hwndFrame); for (int i = 0; i < LANGS_COUNT; i++) { const char *langName = g_langs[i]._langName; int langMenuId = g_langs[i]._langId; if (str_eq(CurrLangNameGet(), langName)) CheckMenuItem(hmenu, langMenuId, MF_BYCOMMAND | MF_CHECKED); else CheckMenuItem(hmenu, langMenuId, MF_BYCOMMAND | MF_UNCHECKED); }}static void MenuUpdateStateForWindow(WindowInfo *win) { static UINT menusToDisableIfNoPdf[] = { IDM_VIEW_ROTATE_LEFT, IDM_VIEW_ROTATE_RIGHT, IDM_GOTO_NEXT_PAGE, IDM_GOTO_PREV_PAGE, IDM_GOTO_FIRST_PAGE, IDM_GOTO_LAST_PAGE, IDM_GOTO_PAGE, IDM_SAVEAS }; bool fileCloseEnabled = FileCloseMenuEnabled(); HMENU hmenu = GetMenu(win->hwndFrame); if (fileCloseEnabled) EnableMenuItem(hmenu, IDM_CLOSE, MF_BYCOMMAND | MF_ENABLED); else EnableMenuItem(hmenu, IDM_CLOSE, MF_BYCOMMAND | MF_GRAYED); bool filePrintEnabled = false; if (win->dm && win->dm->pdfEngine && win->dm->pdfEngine->printingAllowed()) filePrintEnabled = true; if (filePrintEnabled) EnableMenuItem(hmenu, IDM_PRINT, MF_BYCOMMAND | MF_ENABLED); else EnableMenuItem(hmenu, IDM_PRINT, MF_BYCOMMAND | MF_GRAYED); MenuUpdateBookmarksStateForWindow(win); MenuUpdateShowToolbarStateForWindow(win); MenuUpdateLanguage(win); MenuUpdateDisplayMode(win); MenuUpdateZoom(win); MenuUpdateFullscreen(win); MenuUpdateEnableAutoUpdateStateForWindow(win); for (size_t i = 0; i < dimof(menusToDisableIfNoPdf); i++) { UINT menuId = menusToDisableIfNoPdf[i]; if (WS_SHOWING_PDF == win->state) EnableMenuItem(hmenu, menuId, MF_BYCOMMAND | MF_ENABLED); else EnableMenuItem(hmenu, menuId, MF_BYCOMMAND | MF_GRAYED); } /* Hide scrollbars if not showing a PDF */ /* TODO: doesn't really fit the name of the function */ if (WS_SHOWING_PDF == win->state) { if (win->dm->needHScroll()) ShowScrollBar(win->hwndCanvas, SB_HORZ, TRUE); if (win->dm->needVScroll() || (DM_SINGLE_PAGE == win->dm->displayMode() && win->dm->pageCount() > 1)) ShowScrollBar(win->hwndCanvas, SB_VERT, TRUE); } else { ShowScrollBar(win->hwndCanvas, SB_BOTH, FALSE); win_set_texta(win->hwndFrame, APP_NAME_STR); }}/* Disable/enable menu items and toolbar buttons depending on wheter a given window shows a PDF file or not. */static void MenuToolbarUpdateStateForAllWindows(void) { WindowInfo* win = gWindowList; while (win) { MenuUpdateStateForWindow(win); ToolbarUpdateStateForWindow(win); win = win->next; }}#define MIN_WIN_DX 50#define MAX_WIN_DX 4096#define MIN_WIN_DY 50#define MAX_WIN_DY 4096static WindowInfo* WindowInfo_CreateEmpty(void) { HWND hwndFrame, hwndCanvas; WindowInfo* win; /* TODO: maybe adjustement of size and position should be outside of this function */ int winPosX = CW_USEDEFAULT; int winPosY = CW_USEDEFAULT; if (DEFAULT_WIN_POS != gGlobalPrefs.m_windowPosX) { winPosX = gGlobalPrefs.m_windowPosX; if (winPosX < 0) { winPosX = CW_USEDEFAULT; winPosY = CW_USEDEFAULT; } else { winPosY = gGlobalPrefs.m_windowPosY; if (winPosY < 0) { winPosX = CW_USEDEFAULT; winPosY = CW_USEDEFAULT; } } } int winDx = DEF_PAGE_DX; if (DEFAULT_WIN_POS != gGlobalPrefs.m_windowDx) { winDx = gGlobalPrefs.m_windowDx; if (winDx < MIN_WIN_DX || winDx > MAX_WIN_DX) winDx = DEF_PAGE_DX; } int winDy = DEF_PAGE_DY; if (DEFAULT_WIN_POS != gGlobalPrefs.m_windowDy) { winDy = gGlobalPrefs.m_windowDy; if (winDy < MIN_WIN_DY || winDy > MAX_WIN_DY) winDy = DEF_PAGE_DY; } #if FANCY_UI hwndFrame = CreateWindowEx(// WS_EX_TOOLWINDOW, 0,// WS_OVERLAPPEDWINDOW,// WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE, //WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_HSCROLL | WS_VSCROLL, FRAME_CLASS_NAME, windowTitle, WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT, winDx, winDy, NULL, NULL, ghinst, NULL);#else hwndFrame = CreateWindow( FRAME_CLASS_NAME, windowTitle, WS_OVERLAPPEDWINDOW, winPosX, winPosY, winDx, winDy, NULL, NULL, ghinst, NULL);#endif if (!hwndFrame) return NULL; win = WindowInfo_New(hwndFrame); hwndCanvas = CreateWindowEx( WS_EX_STATICEDGE, CANVAS_CLASS_NAME, NULL, WS_CHILD | WS_HSCROLL | WS_VSCROLL, 0, 0, 0, 0, /* position and size determined in OnSize */ hwndFrame, NULL, ghinst, NULL); if (!hwndCanvas) return NULL; // hide scrollbars to avoid showing/hiding on empty window ShowScrollBar(hwndCanvas, SB_BOTH, FALSE); WindowInfo_RebuildMenu(win); assert(win->hMenu); BOOL ok = SetMenu(hwndFrame, win->hMenu); assert(ok); win->hwndCanvas = hwndCanvas; CreateToolbar(win, ghinst); CreateTocBox(win, ghinst); WindowInfo_UpdateFindbox(win); win->stopFindStatusThreadEvent = CreateEvent(NULL, TRUE, FALSE, NULL); return win;}static void RecalcSelectionPosition (WindowInfo *win) { SelectionOnPage * selOnPage = win->selectionOnPage; RectD
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -