本文整理汇总了C++中DisplayModel类的典型用法代码示例。如果您正苦于以下问题:C++ DisplayModel类的具体用法?C++ DisplayModel怎么用?C++ DisplayModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DisplayModel类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnSelectionStart
void OnSelectionStart(WindowInfo* win, int x, int y, WPARAM key) {
UNUSED(key);
CrashIf(!win->AsFixed());
DeleteOldSelectionInfo(win, true);
win->selectionRect = RectI(x, y, 0, 0);
win->showSelection = true;
win->mouseAction = MouseAction::Selecting;
bool isShift = IsShiftPressed();
bool isCtrl = IsCtrlPressed();
// Ctrl+drag forces a rectangular selection
if (!isCtrl || isShift) {
DisplayModel* dm = win->AsFixed();
int pageNo = dm->GetPageNoByPoint(PointI(x, y));
if (dm->ValidPageNo(pageNo)) {
PointD pt = dm->CvtFromScreen(PointI(x, y), pageNo);
dm->textSelection->StartAt(pageNo, pt.x, pt.y);
win->mouseAction = MouseAction::SelectingText;
}
}
SetCapture(win->hwndCanvas);
SetTimer(win->hwndCanvas, SMOOTHSCROLL_TIMER_ID, SMOOTHSCROLL_DELAY_IN_MS, nullptr);
win->RepaintAsync();
}
示例2: OnSelectionEdgeAutoscroll
void OnSelectionEdgeAutoscroll(WindowInfo* win, int x, int y) {
int dx = 0, dy = 0;
if (x < SELECT_AUTOSCROLL_AREA_WIDTH)
dx = -SELECT_AUTOSCROLL_STEP_LENGTH;
else if (x > win->canvasRc.dx - SELECT_AUTOSCROLL_AREA_WIDTH)
dx = SELECT_AUTOSCROLL_STEP_LENGTH;
if (y < SELECT_AUTOSCROLL_AREA_WIDTH)
dy = -SELECT_AUTOSCROLL_STEP_LENGTH;
else if (y > win->canvasRc.dy - SELECT_AUTOSCROLL_AREA_WIDTH)
dy = SELECT_AUTOSCROLL_STEP_LENGTH;
CrashIf(NeedsSelectionEdgeAutoscroll(win, x, y) != (dx != 0 || dy != 0));
if (dx != 0 || dy != 0) {
CrashIf(!win->AsFixed());
DisplayModel* dm = win->AsFixed();
PointI oldOffset = dm->GetViewPort().TL();
win->MoveDocBy(dx, dy);
dx = dm->GetViewPort().x - oldOffset.x;
dy = dm->GetViewPort().y - oldOffset.y;
win->selectionRect.x -= dx;
win->selectionRect.y -= dy;
win->selectionRect.dx += dx;
win->selectionRect.dy += dy;
}
}
示例3: CrashIf
void WindowInfo::MoveDocBy(int dx, int dy)
{
CrashIf(!this->AsFixed());
if (!this->AsFixed()) return;
CrashIf(this->linkOnLastButtonDown);
if (this->linkOnLastButtonDown) return;
DisplayModel *dm = this->ctrl->AsFixed();
if (0 != dx)
dm->ScrollXBy(dx);
if (0 != dy)
dm->ScrollYBy(dy, false);
}
示例4: MakeRandomSelection
static void MakeRandomSelection(WindowInfo* win, int pageNo) {
DisplayModel* dm = win->AsFixed();
if (!dm->ValidPageNo(pageNo))
pageNo = 1;
if (!dm->ValidPageNo(pageNo))
return;
// try a random position in the page
int x = rand() % 640;
int y = rand() % 480;
if (dm->textSelection->IsOverGlyph(pageNo, x, y)) {
dm->textSelection->StartAt(pageNo, x, y);
dm->textSelection->SelectUpTo(pageNo, rand() % 640, rand() % 480);
}
}
示例5: args
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;
}
示例6: CrashIf
void StressTest::OnTimer(int timerIdGot)
{
CrashIf(timerId != timerIdGot);
KillTimer(win->hwndFrame, timerId);
if (!win->IsDocLoaded()) {
if (!GoToNextFile()) {
Finished(true);
return;
}
TickTimer();
return;
}
// chm documents aren't rendered and we block until we show them
// so we can assume previous page has been shown and go to next page
if (!win->AsFixed()) {
if (!GoToNextPage())
return;
goto Next;
}
// For non-image files, we detect if a page was rendered by checking the cache
// (but we don't wait more than 3 seconds).
// Image files are always fully rendered in WM_PAINT, so we know the page
// has already been rendered.
DisplayModel *dm = win->AsFixed();
bool didRender = gRenderCache.Exists(dm, currPage, dm->GetRotation());
if (!didRender && dm->ShouldCacheRendering(currPage)) {
double timeInMs = currPageRenderTime.GetTimeInMs();
if (timeInMs > 3.0 * 1000) {
if (!GoToNextPage())
return;
}
}
else if (!GoToNextPage()) {
return;
}
MakeRandomSelection(win, currPage);
Next:
TickTimer();
}
示例7: UpdateTextSelection
void UpdateTextSelection(WindowInfo* win, bool select) {
if (!win->AsFixed())
return;
DisplayModel* dm = win->AsFixed();
if (select) {
int pageNo = dm->GetPageNoByPoint(win->selectionRect.BR());
if (win->ctrl->ValidPageNo(pageNo)) {
PointD pt = dm->CvtFromScreen(win->selectionRect.BR(), pageNo);
dm->textSelection->SelectUpTo(pageNo, pt.x, pt.y);
}
}
DeleteOldSelectionInfo(win);
win->currentTab->selectionOnPage = SelectionOnPage::FromTextSelect(&dm->textSelection->result);
win->showSelection = win->currentTab->selectionOnPage != nullptr;
if (win->uia_provider)
win->uia_provider->OnSelectionChanged();
}
示例8: ZoomToSelection
void ZoomToSelection(WindowInfo* win, float factor, bool scrollToFit, bool relative) {
PointI pt;
bool zoomToPt = false;
if (win->AsFixed()) {
DisplayModel* dm = win->AsFixed();
// when not zooming to fit (which contradicts zooming to a specific point), ...
if (!relative && (ZOOM_FIT_PAGE == factor || ZOOM_FIT_CONTENT == factor) && scrollToFit) {
zoomToPt = false;
}
// either scroll towards the center of the current selection (if there is any) ...
else if (win->showSelection && win->currentTab->selectionOnPage) {
RectI selRect;
for (SelectionOnPage& sel : *win->currentTab->selectionOnPage) {
selRect = selRect.Union(sel.GetRect(dm));
}
ClientRect rc(win->hwndCanvas);
pt.x = 2 * selRect.x + selRect.dx - rc.dx / 2;
pt.y = 2 * selRect.y + selRect.dy - rc.dy / 2;
pt.x = limitValue(pt.x, selRect.x, selRect.x + selRect.dx);
pt.y = limitValue(pt.y, selRect.y, selRect.y + selRect.dy);
int pageNo = dm->GetPageNoByPoint(pt);
zoomToPt = dm->ValidPageNo(pageNo) && dm->PageVisible(pageNo);
}
// or towards the top-left-most part of the first visible page
else {
int page = dm->FirstVisiblePageNo();
PageInfo* pageInfo = dm->GetPageInfo(page);
if (pageInfo) {
RectI visible = pageInfo->pageOnScreen.Intersect(win->canvasRc);
pt = visible.TL();
int pageNo = dm->GetPageNoByPoint(pt);
zoomToPt = !visible.IsEmpty() && dm->ValidPageNo(pageNo) && dm->PageVisible(pageNo);
}
}
}
win->ctrl->SetZoomVirtual(factor * (relative ? win->ctrl->GetZoomVirtual(true) : 1), zoomToPt ? &pt : nullptr);
UpdateToolbarState(win);
}
示例9: OnSelectAll
void OnSelectAll(WindowInfo* win, bool textOnly) {
if (!HasPermission(Perm_CopySelection))
return;
if (IsFocused(win->hwndFindBox) || IsFocused(win->hwndPageBox)) {
Edit_SelectAll(GetFocus());
return;
}
if (win->AsChm()) {
win->AsChm()->SelectAll();
return;
}
if (!win->AsFixed())
return;
DisplayModel* dm = win->AsFixed();
if (textOnly) {
int pageNo;
for (pageNo = 1; !dm->GetPageInfo(pageNo)->shown; pageNo++)
;
dm->textSelection->StartAt(pageNo, 0);
for (pageNo = win->ctrl->PageCount(); !dm->GetPageInfo(pageNo)->shown; pageNo--)
;
dm->textSelection->SelectUpTo(pageNo, -1);
win->selectionRect = RectI::FromXY(INT_MIN / 2, INT_MIN / 2, INT_MAX, INT_MAX);
UpdateTextSelection(win);
} else {
DeleteOldSelectionInfo(win, true);
win->selectionRect = RectI::FromXY(INT_MIN / 2, INT_MIN / 2, INT_MAX, INT_MAX);
win->currentTab->selectionOnPage = SelectionOnPage::FromRectangle(dm, win->selectionRect);
}
win->showSelection = win->currentTab->selectionOnPage != nullptr;
win->RepaintAsync();
}
示例10: CopySelectionToClipboard
void CopySelectionToClipboard(WindowInfo* win) {
if (!win->currentTab || !win->currentTab->selectionOnPage)
return;
CrashIf(win->currentTab->selectionOnPage->size() == 0 && win->mouseAction != MouseAction::SelectingText);
if (win->currentTab->selectionOnPage->size() == 0)
return;
CrashIf(!win->AsFixed());
if (!win->AsFixed())
return;
if (!OpenClipboard(nullptr))
return;
EmptyClipboard();
DisplayModel* dm = win->AsFixed();
#ifndef DISABLE_DOCUMENT_RESTRICTIONS
if (!dm->GetEngine()->AllowsCopyingText())
win->ShowNotification(_TR("Copying text was denied (copying as image only)"));
else
#endif
if (!dm->GetEngine()->IsImageCollection()) {
AutoFreeW selText;
bool isTextSelection = dm->textSelection->result.len > 0;
if (isTextSelection) {
selText.Set(dm->textSelection->ExtractText(L"\r\n"));
} else {
WStrVec selections;
for (SelectionOnPage& sel : *win->currentTab->selectionOnPage) {
WCHAR* text = dm->GetTextInRegion(sel.pageNo, sel.rect);
if (text)
selections.Push(text);
}
selText.Set(selections.Join());
}
// don't copy empty text
if (!str::IsEmpty(selText.Get()))
CopyTextToClipboard(selText, true);
if (isTextSelection) {
// don't also copy the first line of a text selection as an image
CloseClipboard();
return;
}
}
/* also copy a screenshot of the current selection to the clipboard */
SelectionOnPage* selOnPage = &win->currentTab->selectionOnPage->at(0);
RenderedBitmap* bmp = dm->GetEngine()->RenderBitmap(selOnPage->pageNo, dm->GetZoomReal(), dm->GetRotation(),
&selOnPage->rect, RenderTarget::Export);
if (bmp)
CopyImageToClipboard(bmp->GetBitmap(), true);
delete bmp;
CloseClipboard();
}
示例11: OnMenuPrint
void OnMenuPrint(WindowInfo *win, bool waitForCompletion)
{
// we remember some printer settings per process
static ScopedMem<DEVMODE> defaultDevMode;
static PrintScaleAdv defaultScaleAdv = PrintScaleShrink;
static bool defaultAsImage = false;
bool printSelection = false;
Vec<PRINTPAGERANGE> ranges;
PRINTER_INFO_2 printerInfo = { 0 };
if (!HasPermission(Perm_PrinterAccess)) return;
DisplayModel *dm = win->dm;
assert(dm);
if (!dm) return;
if (!dm->engine || !dm->engine->AllowsPrinting())
return;
if (win->IsChm()) {
win->dm->AsChmEngine()->PrintCurrentPage();
return;
}
if (win->printThread) {
int res = MessageBox(win->hwndFrame, _TR("Printing is still in progress. Abort and start over?"), _TR("Printing in progress."), MB_ICONEXCLAMATION | MB_YESNO | (IsUIRightToLeft() ? MB_RTLREADING : 0));
if (res == IDNO)
return;
}
AbortPrinting(win);
PRINTDLGEX pd;
ZeroMemory(&pd, sizeof(PRINTDLGEX));
pd.lStructSize = sizeof(PRINTDLGEX);
pd.hwndOwner = win->hwndFrame;
pd.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_COLLATE;
if (!win->selectionOnPage)
pd.Flags |= PD_NOSELECTION;
pd.nCopies = 1;
/* by default print all pages */
pd.nPageRanges = 1;
pd.nMaxPageRanges = MAXPAGERANGES;
PRINTPAGERANGE *ppr = AllocArray<PRINTPAGERANGE>(MAXPAGERANGES);
pd.lpPageRanges = ppr;
ppr->nFromPage = 1;
ppr->nToPage = dm->PageCount();
pd.nMinPage = 1;
pd.nMaxPage = dm->PageCount();
pd.nStartPage = START_PAGE_GENERAL;
Print_Advanced_Data advanced(PrintRangeAll, defaultScaleAdv, defaultAsImage);
ScopedMem<DLGTEMPLATE> dlgTemplate; // needed for RTL languages
HPROPSHEETPAGE hPsp = CreatePrintAdvancedPropSheet(&advanced, dlgTemplate);
pd.lphPropertyPages = &hPsp;
pd.nPropertyPages = 1;
// restore remembered settings
if (defaultDevMode)
pd.hDevMode = GlobalMemDup(defaultDevMode.Get(), defaultDevMode.Get()->dmSize + defaultDevMode.Get()->dmDriverExtra);
if (PrintDlgEx(&pd) != S_OK) {
if (CommDlgExtendedError() != 0) {
/* if PrintDlg was cancelled then
CommDlgExtendedError is zero, otherwise it returns the
error code, which we could look at here if we wanted.
for now just warn the user that printing has stopped
becasue of an error */
MessageBox(win->hwndFrame, _TR("Couldn't initialize printer"), _TR("Printing problem."), MB_ICONEXCLAMATION | MB_OK | (IsUIRightToLeft() ? MB_RTLREADING : 0));
}
goto Exit;
}
if (pd.dwResultAction == PD_RESULT_PRINT || pd.dwResultAction == PD_RESULT_APPLY) {
// remember settings for this process
LPDEVMODE devMode = (LPDEVMODE)GlobalLock(pd.hDevMode);
if (devMode) {
defaultDevMode.Set((LPDEVMODE)memdup(devMode, devMode->dmSize + devMode->dmDriverExtra));
GlobalUnlock(pd.hDevMode);
}
defaultScaleAdv = advanced.scale;
defaultAsImage = advanced.asImage;
}
if (pd.dwResultAction != PD_RESULT_PRINT)
goto Exit;
if (pd.Flags & PD_CURRENTPAGE) {
PRINTPAGERANGE pr = { dm->CurrentPageNo(), dm->CurrentPageNo() };
ranges.Append(pr);
} else if (win->selectionOnPage && (pd.Flags & PD_SELECTION)) {
printSelection = true;
} else if (!(pd.Flags & PD_PAGENUMS)) {
PRINTPAGERANGE pr = { 1, dm->PageCount() };
ranges.Append(pr);
} else {
assert(pd.nPageRanges > 0);
for (DWORD i = 0; i < pd.nPageRanges; i++)
ranges.Append(pd.lpPageRanges[i]);
}
//.........这里部分代码省略.........
示例12: assert
void LinkHandler::ScrollTo(PageDestination *dest)
{
assert(owner && owner->linkHandler == this);
int pageNo = dest->GetDestPageNo();
if (pageNo <= 0)
return;
if (owner->dm->AsChmEngine()) {
owner->dm->AsChmEngine()->GoToDestination(dest);
return;
}
DisplayModel *dm = owner->dm;
PointI scroll(-1, 0);
RectD rect = dest->GetDestRect();
if (rect.IsEmpty()) {
// PDF: /XYZ top left
// scroll to rect.TL()
PointD scrollD = dm->engine->Transform(rect.TL(), pageNo, dm->ZoomReal(), dm->Rotation());
scroll = scrollD.Convert<int>();
// default values for the coordinates mean: keep the current position
if (DEST_USE_DEFAULT == rect.x)
scroll.x = -1;
if (DEST_USE_DEFAULT == rect.y) {
PageInfo *pageInfo = dm->GetPageInfo(dm->CurrentPageNo());
scroll.y = -(pageInfo->pageOnScreen.y - dm->GetWindowMargin()->top);
scroll.y = max(scroll.y, 0); // Adobe Reader never shows the previous page
}
}
else if (rect.dx != DEST_USE_DEFAULT && rect.dy != DEST_USE_DEFAULT) {
// PDF: /FitR left bottom right top
RectD rectD = dm->engine->Transform(rect, pageNo, dm->ZoomReal(), dm->Rotation());
scroll = rectD.TL().Convert<int>();
// Rect<float> rectF = dm->engine->Transform(rect, pageNo, 1.0, dm->rotation()).Convert<float>();
// zoom = 100.0f * min(owner->canvasRc.dx / rectF.dx, owner->canvasRc.dy / rectF.dy);
}
else if (rect.y != DEST_USE_DEFAULT) {
// PDF: /FitH top or /FitBH top
PointD scrollD = dm->engine->Transform(rect.TL(), pageNo, dm->ZoomReal(), dm->Rotation());
scroll.y = max(scrollD.Convert<int>().y, 0); // Adobe Reader never shows the previous page
// zoom = FitBH ? ZOOM_FIT_CONTENT : ZOOM_FIT_WIDTH
}
// else if (Fit || FitV) zoom = ZOOM_FIT_PAGE
// else if (FitB || FitBV) zoom = ZOOM_FIT_CONTENT
/* // ignore author-set zoom settings (at least as long as there's no way to overrule them)
if (zoom != INVALID_ZOOM) {
// TODO: adjust the zoom level before calculating the scrolling coordinates
dm->zoomTo(zoom);
UpdateToolbarState(owner);
}
// */
dm->GoToPage(pageNo, scroll.y, true, scroll.x);
}
示例13: OnMenuPrint
void OnMenuPrint(WindowInfo *win, bool waitForCompletion)
{
// we remember some printer settings per process
static ScopedMem<DEVMODE> defaultDevMode;
static PrintScaleAdv defaultScaleAdv = PrintScaleShrink;
static bool defaultAsImage = false;
static bool hasDefaults = false;
if (!hasDefaults) {
hasDefaults = true;
defaultAsImage = gGlobalPrefs->printerDefaults.printAsImage;
if (str::EqI(gGlobalPrefs->printerDefaults.printScale, "fit"))
defaultScaleAdv = PrintScaleFit;
else if (str::EqI(gGlobalPrefs->printerDefaults.printScale, "none"))
defaultScaleAdv = PrintScaleNone;
}
bool printSelection = false;
Vec<PRINTPAGERANGE> ranges;
PRINTER_INFO_2 printerInfo = { 0 };
if (!HasPermission(Perm_PrinterAccess))
return;
if (win->AsChm()) {
// the Print dialog allows access to the file system, so fall back
// to printing the entire document without dialog if that isn't desired
bool showUI = HasPermission(Perm_DiskAccess);
win->AsChm()->PrintCurrentPage(showUI);
return;
}
if (win->AsEbook()) {
// TODO: use EbookEngine for printing?
return;
}
CrashIf(!win->AsFixed());
if (!win->AsFixed()) return;
DisplayModel *dm = win->AsFixed();
#ifndef DISABLE_DOCUMENT_RESTRICTIONS
if (!dm->engine()->AllowsPrinting())
return;
#endif
if (win->printThread) {
int res = MessageBox(win->hwndFrame,
_TR("Printing is still in progress. Abort and start over?"),
_TR("Printing in progress."),
MB_ICONEXCLAMATION | MB_YESNO | MbRtlReadingMaybe());
if (res == IDNO)
return;
}
AbortPrinting(win);
// the Print dialog allows access to the file system, so fall back
// to printing the entire document without dialog if that isn't desired
if (!HasPermission(Perm_DiskAccess)) {
PrintFile(dm->engine());
return;
}
PRINTDLGEX pd;
ZeroMemory(&pd, sizeof(PRINTDLGEX));
pd.lStructSize = sizeof(PRINTDLGEX);
pd.hwndOwner = win->hwndFrame;
pd.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_COLLATE;
if (!win->selectionOnPage)
pd.Flags |= PD_NOSELECTION;
pd.nCopies = 1;
/* by default print all pages */
pd.nPageRanges = 1;
pd.nMaxPageRanges = MAXPAGERANGES;
PRINTPAGERANGE *ppr = AllocArray<PRINTPAGERANGE>(MAXPAGERANGES);
pd.lpPageRanges = ppr;
ppr->nFromPage = 1;
ppr->nToPage = dm->PageCount();
pd.nMinPage = 1;
pd.nMaxPage = dm->PageCount();
pd.nStartPage = START_PAGE_GENERAL;
Print_Advanced_Data advanced(PrintRangeAll, defaultScaleAdv, defaultAsImage);
ScopedMem<DLGTEMPLATE> dlgTemplate; // needed for RTL languages
HPROPSHEETPAGE hPsp = CreatePrintAdvancedPropSheet(&advanced, dlgTemplate);
pd.lphPropertyPages = &hPsp;
pd.nPropertyPages = 1;
// restore remembered settings
if (defaultDevMode) {
DEVMODE *p = defaultDevMode.Get();
pd.hDevMode = GlobalMemDup(p, p->dmSize + p->dmDriverExtra);
}
if (PrintDlgEx(&pd) != S_OK) {
if (CommDlgExtendedError() != 0) {
/* if PrintDlg was cancelled then
CommDlgExtendedError is zero, otherwise it returns the
error code, which we could look at here if we wanted.
for now just warn the user that printing has stopped
becasue of an error */
//.........这里部分代码省略.........