Ejemplo n.º 1
0
void OnMenuProperties(SumatraWindow& win)
{
    if (win.AsWindowInfo())
        ShowProperties(win.AsWindowInfo()->hwndFrame, GetDocForWindow(win), win.AsWindowInfo()->dm);
    else if (win.AsEbookWindow())
        ShowProperties(win.AsEbookWindow()->hwndFrame, GetDocForWindow(win), NULL);
}
Ejemplo n.º 2
0
Doc GetDocForWindow(SumatraWindow& win)
{
    if (win.AsWindowInfo()) {
        WindowInfo *iwin = win.AsWindowInfo();
        if (!iwin->IsDocLoaded())
            return Doc();
        return Doc(iwin->dm->engine, iwin->dm->engineType);
    }
    if (win.AsEbookWindow()) {
        EbookWindow *ewin = win.AsEbookWindow();
        return ewin->ebookController->GetDoc();
    }
    CrashIf(true);
    return Doc();
}
Ejemplo n.º 3
0
void OpenMobiInWindow(Doc doc, SumatraWindow& winToReplace)
{
    const TCHAR *fullPath = doc.GetFilePath();
    DisplayState *ds = gFileHistory.Find(fullPath);

    if (gGlobalPrefs.rememberOpenedFiles) {
        ds = gFileHistory.MarkFileLoaded(fullPath);
        if (gGlobalPrefs.showStartPage && ds) {
            // TODO: do it on a background thread?
            CreateThumbnailForDoc(doc, *ds);
        }
        SavePrefs();
    }

    int startReparseIdx = -1;
    if (ds)
        startReparseIdx = ds->reparseIdx;

    // Add the file also to Windows' recently used documents (this doesn't
    // happen automatically on drag&drop, reopening from history, etc.)
    if (HasPermission(Perm_DiskAccess) && !gPluginMode)
        SHAddToRecentDocs(SHARD_PATH, fullPath);

    ScopedMem<TCHAR> winTitle(str::Format(_T("%s - %s"), path::GetBaseName(fullPath), SUMATRA_WINDOW_TITLE));

    if (winToReplace.AsEbookWindow()) {
        EbookWindow *mw = winToReplace.AsEbookWindow();
        CrashIf(!mw);
        mw->ebookController->SetDoc(doc);
        win::SetText(mw->hwndFrame, winTitle);
        // TODO: if we have window position/last position for this file, restore it
        return;
    }

    RectI windowPos = gGlobalPrefs.windowPos;
    if (!windowPos.IsEmpty())
        EnsureAreaVisibility(windowPos);
    else
        windowPos = GetDefaultWindowPos();

    if (ds && !ds->windowPos.IsEmpty()) {
        // Make sure it doesn't have a position like outside of the screen etc.
        windowPos = ShiftRectToWorkArea(ds->windowPos);
    }

    WindowInfo *winInfo = winToReplace.AsWindowInfo();
    bool wasMaximized = false;
    if (winInfo && winInfo->hwndFrame)
        wasMaximized = IsZoomed(winInfo->hwndFrame);
    CloseDocumentAndDeleteWindowInfo(winInfo);

    HWND hwnd = CreateWindow(
            MOBI_FRAME_CLASS_NAME, SUMATRA_WINDOW_TITLE,
            WS_OVERLAPPEDWINDOW,
            windowPos.x, windowPos.y, windowPos.dx, windowPos.dy,
            NULL, NULL,
            ghinst, NULL);
    if (!hwnd)
        return;
    if (HasPermission(Perm_DiskAccess) && !gPluginMode)
        DragAcceptFiles(hwnd, TRUE);
    if (Touch::SupportsGestures()) {
        GESTURECONFIG gc = { 0, GC_ALLGESTURES, 0 };
        Touch::SetGestureConfig(hwnd, 0, 1, &gc, sizeof(GESTURECONFIG));
    }

    EbookWindow *win = new EbookWindow();
    win->ebookControls = CreateEbookControls(hwnd);
    win->hwndWrapper = win->ebookControls->mainWnd;
    win->ebookController = new EbookController(win->ebookControls);
    win->hwndFrame = hwnd;

    gEbookWindows.Append(win);
    win::SetText(win->hwndFrame, winTitle);
    SetMenu(hwnd, BuildMenu(win));

    ShowWindow(hwnd, wasMaximized ? SW_SHOWMAXIMIZED : SW_SHOW);
    win->ebookController->SetDoc(doc, startReparseIdx);
}
Ejemplo n.º 4
0
void OpenMobiInWindow(Doc doc, SumatraWindow& winToReplace)
{
    const WCHAR *fullPath = doc.GetFilePath();
    DisplayState *ds = gFileHistory.Find(fullPath);

    if (doc.IsNone()) {
        // TODO: a hack. In LoadDocumentOld(), if current window IsAboutWindow(),
        // we set loadedFilePath to prevent a crash if multiple ebook files are
        // dropped on about window. We need to undo that in case of failure
        // or else the window will be stuck in an invalid state (not about window
        // but not a document window either)
        WindowInfo *w = winToReplace.AsWindowInfo();
        if (str::Eq(w->loadedFilePath, doc.GetFilePath())) {
            free(w->loadedFilePath);
            w->loadedFilePath = NULL;
            // this is now about window. We don't want to show it if we're already
            // showing other windows (the scenario: dragging ebook file on a window
            // showing a document, we create invisible window for this document and
            // we don't want to show empty window if loading fails
            if (gEbookWindows.Count() > 0 || gWindows.Count() > 1) {
                CloseWindow(w, false);
                if (gFileHistory.MarkFileInexistent(fullPath))
                    prefs::Save();
                // TODO: notify the use that loading failed (e.g. show a notification)
                return;
            }
        }
        // TODO: notify the user that loading failed (e.g. show a notification)

        // TODO: this is not a great solution. In case of opening
        // file from cmd-line, we create a window but don't show it
        // if loading afils, we have to show the window. If window
        // is already visible, this is a no-op
        ShowWindow(winToReplace.HwndFrame(), SW_SHOW);
        if (gFileHistory.MarkFileInexistent(fullPath))
            prefs::Save();
        return;
    }

    if (gGlobalPrefs->rememberOpenedFiles) {
        ds = gFileHistory.MarkFileLoaded(fullPath);
        if (gGlobalPrefs->showStartPage) {
            // TODO: do it on a background thread?
            CreateThumbnailForDoc(doc, *ds);
        }
        prefs::Save();
    }

    int startReparseIdx = -1;
    if (ds && gGlobalPrefs->rememberStatePerDocument && !ds->useDefaultState)
        startReparseIdx = ds->reparseIdx;

    // Add the file also to Windows' recently used documents (this doesn't
    // happen automatically on drag&drop, reopening from history, etc.)
    if (HasPermission(Perm_DiskAccess) && !gPluginMode)
        SHAddToRecentDocs(SHARD_PATH, fullPath);

    ScopedMem<WCHAR> winTitle(str::Format(L"%s - %s", path::GetBaseName(fullPath), SUMATRA_WINDOW_TITLE));

    if (winToReplace.AsEbookWindow()) {
        EbookWindow *mw = winToReplace.AsEbookWindow();
        CrashIf(!mw);
        mw->ebookController->SetDoc(doc);
        win::SetText(mw->hwndFrame, winTitle);
        // TODO: if we have window position/last position for this file, restore it
        return;
    }

    RectI windowPos = gGlobalPrefs->windowPos;
    if (!windowPos.IsEmpty())
        EnsureAreaVisibility(windowPos);
    else
        windowPos = GetDefaultWindowPos();

    if (ds && !ds->windowPos.IsEmpty()) {
        // Make sure it doesn't have a position like outside of the screen etc.
        windowPos = ShiftRectToWorkArea(ds->windowPos);
    }

    WindowInfo *winInfo = winToReplace.AsWindowInfo();
    bool wasMaximized = false;
    if (winInfo && winInfo->hwndFrame) {
        wasMaximized = IsZoomed(winInfo->hwndFrame);
        // hide the window instead of destroying it so that
        // windows doesn't set a window from a different
        // process as foreground window instead of the once
        // created below
        ShowWindow(winInfo->hwndFrame, SW_HIDE);
    }

    HWND hwnd = CreateWindow(
            MOBI_FRAME_CLASS_NAME, SUMATRA_WINDOW_TITLE,
            WS_OVERLAPPEDWINDOW,
            windowPos.x, windowPos.y, windowPos.dx, windowPos.dy,
            NULL, NULL,
            ghinst, NULL);
    if (!hwnd) {
        CloseDocumentAndDeleteWindowInfo(winInfo);
        return;
    }
    if (HasPermission(Perm_DiskAccess) && !gPluginMode)
        DragAcceptFiles(hwnd, TRUE);
    if (Touch::SupportsGestures()) {
        GESTURECONFIG gc = { 0, GC_ALLGESTURES, 0 };
        Touch::SetGestureConfig(hwnd, 0, 1, &gc, sizeof(GESTURECONFIG));
    }

    EbookWindow *win = new EbookWindow();
    win->ebookControls = CreateEbookControls(hwnd);
    win->hwndWrapper = win->ebookControls->mainWnd;
    win->ebookController = new EbookController(win->ebookControls);
    win->hwndFrame = hwnd;

    gEbookWindows.Append(win);
    win::SetText(win->hwndFrame, winTitle);
    SetMenu(hwnd, BuildMenu(win));

    ShowWindow(hwnd, wasMaximized ? SW_SHOWMAXIMIZED : SW_SHOW);
    win->ebookController->SetDoc(doc, startReparseIdx);

    CloseDocumentAndDeleteWindowInfo(winInfo);
}