// Synchronization command format: // [<DDECOMMAND_SYNC>(["<pdffile>",]"<srcfile>",<line>,<col>[,<newwindow>,<setfocus>])] static const WCHAR *HandleSyncCmd(const WCHAR *cmd, DDEACK& ack) { ScopedMem<WCHAR> pdfFile, srcFile; BOOL line = 0, col = 0, newWindow = 0, setFocus = 0; const WCHAR *next = str::Parse(cmd, L"[" DDECOMMAND_SYNC L"(\"%S\",%? \"%S\",%u,%u)]", &pdfFile, &srcFile, &line, &col); if (!next) next = str::Parse(cmd, L"[" DDECOMMAND_SYNC L"(\"%S\",%? \"%S\",%u,%u,%u,%u)]", &pdfFile, &srcFile, &line, &col, &newWindow, &setFocus); // allow to omit the pdffile path, so that editors don't have to know about // multi-file projects (requires that the PDF has already been opened) if (!next) { pdfFile.Set(NULL); next = str::Parse(cmd, L"[" DDECOMMAND_SYNC L"(\"%S\",%u,%u)]", &srcFile, &line, &col); if (!next) next = str::Parse(cmd, L"[" DDECOMMAND_SYNC L"(\"%S\",%u,%u,%u,%u)]", &srcFile, &line, &col, &newWindow, &setFocus); } if (!next) return NULL; WindowInfo *win = NULL; if (pdfFile) { // check if the PDF is already opened win = FindWindowInfoByFile(pdfFile); // if not then open it if (newWindow || !win) { LoadArgs args(pdfFile, !newWindow ? win : NULL); win = LoadDocument(args); } else if (win && !win->IsDocLoaded()) { ReloadDocument(win); } } else { // check if any opened PDF has sync information for the source file win = FindWindowInfoBySyncFile(srcFile); if (newWindow) { LoadArgs args(win->loadedFilePath); win = LoadDocument(args); } } if (!win || !win->IsDocLoaded()) return next; if (!win->pdfsync) return next; ack.fAck = 1; assert(win->IsDocLoaded()); UINT page; Vec<RectI> rects; int ret = win->pdfsync->SourceToDoc(srcFile, line, col, &page, rects); ShowForwardSearchResult(win, srcFile, line, col, ret, page, rects); if (setFocus) win->Focus(); return next; }
static WindowInfo *LoadOnStartup(const WCHAR *filePath, CommandLineInfo& i, bool isFirstWin) { LoadArgs args(filePath); args.showWin = !(i.printDialog && i.exitWhenDone) && !gPluginMode; WindowInfo *win = LoadDocument(args); if (!win) return win; if (win->IsDocLoaded() && i.destName && isFirstWin) { win->linkHandler->GotoNamedDest(i.destName); } else if (win->IsDocLoaded() && i.pageNumber > 0 && isFirstWin) { if (win->ctrl->ValidPageNo(i.pageNumber)) win->ctrl->GoToPage(i.pageNumber, false); } if (i.hwndPluginParent) MakePluginWindow(*win, i.hwndPluginParent); if (!win->IsDocLoaded() || !isFirstWin) return win; if (i.enterPresentation || i.enterFullScreen) { if (i.enterPresentation && win->isFullScreen || i.enterFullScreen && win->presentation) ExitFullScreen(*win); EnterFullScreen(*win, i.enterPresentation); } if (i.startView != DM_AUTOMATIC) SwitchToDisplayMode(win, i.startView); if (i.startZoom != INVALID_ZOOM) ZoomToSelection(win, i.startZoom); if ((i.startScroll.x != -1 || i.startScroll.y != -1) && win->AsFixed()) { DisplayModel *dm = win->AsFixed(); ScrollState ss = dm->GetScrollState(); ss.x = i.startScroll.x; ss.y = i.startScroll.y; dm->SetScrollState(ss); } if (i.forwardSearchOrigin && i.forwardSearchLine && win->AsFixed() && win->AsFixed()->pdfSync) { UINT page; Vec<RectI> rects; ScopedMem<WCHAR> sourcePath(path::Normalize(i.forwardSearchOrigin)); int ret = win->AsFixed()->pdfSync->SourceToDoc(sourcePath, i.forwardSearchLine, 0, &page, rects); ShowForwardSearchResult(win, sourcePath, i.forwardSearchLine, 0, ret, page, rects); } return win; }