2010-10-12 15:51:52 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-27 16:10:40 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2004-09-20 12:36:40 +00:00
|
|
|
|
2006-09-16 18:22:07 +00:00
|
|
|
|
2004-09-20 12:36:40 +00:00
|
|
|
#include "PreviewRenderer.hxx"
|
|
|
|
|
|
|
|
#include "DrawDocShell.hxx"
|
|
|
|
#include "drawdoc.hxx"
|
|
|
|
#include "drawview.hxx"
|
|
|
|
#include "sdpage.hxx"
|
|
|
|
#include "ViewShell.hxx"
|
|
|
|
#include <vcl/virdev.hxx>
|
|
|
|
#include <svx/svdpagv.hxx>
|
|
|
|
#include <svx/svdoutl.hxx>
|
2010-01-08 18:32:51 +01:00
|
|
|
#include <editeng/eeitem.hxx>
|
|
|
|
#include <editeng/editstat.hxx>
|
2006-11-14 13:37:41 +00:00
|
|
|
#include <vcl/svapp.hxx>
|
2010-03-18 14:37:10 +01:00
|
|
|
#include <tools/diagnose_ex.h>
|
2010-06-02 11:01:47 +02:00
|
|
|
#include <svx/sdr/contact/viewobjectcontact.hxx>
|
|
|
|
#include <svx/sdr/contact/viewcontact.hxx>
|
2004-09-20 12:36:40 +00:00
|
|
|
|
2010-02-18 15:20:15 +01:00
|
|
|
using namespace ::com::sun::star;
|
|
|
|
using namespace ::com::sun::star::uno;
|
2004-09-20 12:36:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace sd {
|
|
|
|
|
2006-04-26 19:53:47 +00:00
|
|
|
const int PreviewRenderer::snSubstitutionTextSize = 11;
|
2004-09-20 12:36:40 +00:00
|
|
|
const int PreviewRenderer::snFrameWidth = 1;
|
|
|
|
|
2010-06-02 11:01:47 +02:00
|
|
|
namespace {
|
|
|
|
/** This incarnation of the ViewObjectContactRedirector filters away all
|
|
|
|
PageObj objects, unconditionally.
|
|
|
|
*/
|
|
|
|
class ViewRedirector : public ::sdr::contact::ViewObjectContactRedirector
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ViewRedirector (void);
|
|
|
|
virtual ~ViewRedirector (void);
|
|
|
|
virtual drawinglayer::primitive2d::Primitive2DSequence createRedirectedPrimitive2DSequence(
|
|
|
|
const sdr::contact::ViewObjectContact& rOriginal,
|
|
|
|
const sdr::contact::DisplayInfo& rDisplayInfo);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//===== PreviewRenderer =======================================================
|
|
|
|
|
2008-04-03 13:52:57 +00:00
|
|
|
PreviewRenderer::PreviewRenderer (
|
|
|
|
OutputDevice* pTemplate,
|
|
|
|
const bool bHasFrame)
|
2004-09-20 12:36:40 +00:00
|
|
|
: mpPreviewDevice (new VirtualDevice()),
|
|
|
|
mpView(NULL),
|
|
|
|
mpDocShellOfView(NULL),
|
2008-04-03 13:52:57 +00:00
|
|
|
maFrameColor (svtools::ColorConfig().GetColorValue(svtools::DOCBOUNDARIES).nColor),
|
|
|
|
mbHasFrame(bHasFrame)
|
2004-09-20 12:36:40 +00:00
|
|
|
{
|
|
|
|
if (pTemplate != NULL)
|
|
|
|
{
|
|
|
|
mpPreviewDevice->SetDigitLanguage (pTemplate->GetDigitLanguage());
|
|
|
|
mpPreviewDevice->SetBackground(pTemplate->GetBackground());
|
|
|
|
}
|
|
|
|
else
|
2010-03-03 13:21:37 +01:00
|
|
|
{
|
|
|
|
mpPreviewDevice->SetBackground(Wallpaper(
|
|
|
|
Application::GetSettings().GetStyleSettings().GetWindowColor()));
|
|
|
|
}
|
2004-09-20 12:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PreviewRenderer::~PreviewRenderer (void)
|
|
|
|
{
|
|
|
|
if (mpDocShellOfView != NULL)
|
|
|
|
EndListening (*mpDocShellOfView);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Image PreviewRenderer::RenderPage (
|
|
|
|
const SdPage* pPage,
|
2008-04-03 13:52:57 +00:00
|
|
|
const sal_Int32 nWidth,
|
2009-05-07 12:38:03 +00:00
|
|
|
const String& rSubstitutionText,
|
2010-06-02 11:01:47 +02:00
|
|
|
const bool bObeyHighContrastMode,
|
|
|
|
const bool bDisplayPresentationObjects)
|
2004-09-20 12:36:40 +00:00
|
|
|
{
|
2006-04-26 19:53:47 +00:00
|
|
|
if (pPage != NULL)
|
|
|
|
{
|
2008-04-03 13:52:57 +00:00
|
|
|
const Size aPageModelSize (pPage->GetSize());
|
|
|
|
const double nAspectRatio (
|
2006-04-26 19:53:47 +00:00
|
|
|
double(aPageModelSize.Width()) / double(aPageModelSize.Height()));
|
2008-04-03 13:52:57 +00:00
|
|
|
const sal_Int32 nFrameWidth (mbHasFrame ? snFrameWidth : 0);
|
|
|
|
const sal_Int32 nHeight (sal::static_int_cast<sal_Int32>(
|
|
|
|
(nWidth - 2*nFrameWidth) / nAspectRatio + 2*nFrameWidth + 0.5));
|
2010-06-02 11:01:47 +02:00
|
|
|
return RenderPage (
|
|
|
|
pPage,
|
|
|
|
Size(nWidth,nHeight),
|
|
|
|
rSubstitutionText,
|
|
|
|
bObeyHighContrastMode,
|
|
|
|
bDisplayPresentationObjects);
|
2006-04-26 19:53:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return Image();
|
2004-09-20 12:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Image PreviewRenderer::RenderPage (
|
|
|
|
const SdPage* pPage,
|
|
|
|
Size aPixelSize,
|
2009-05-07 12:38:03 +00:00
|
|
|
const String& rSubstitutionText,
|
2010-06-02 11:01:47 +02:00
|
|
|
const bool bObeyHighContrastMode,
|
|
|
|
const bool bDisplayPresentationObjects)
|
2004-09-20 12:36:40 +00:00
|
|
|
{
|
|
|
|
Image aPreview;
|
|
|
|
|
2006-04-26 19:53:47 +00:00
|
|
|
if (pPage != NULL)
|
2004-09-20 12:36:40 +00:00
|
|
|
{
|
2006-04-26 19:53:47 +00:00
|
|
|
try
|
2005-07-07 12:38:40 +00:00
|
|
|
{
|
2010-06-02 11:01:47 +02:00
|
|
|
if (Initialize(pPage, aPixelSize, bObeyHighContrastMode))
|
2006-04-26 19:53:47 +00:00
|
|
|
{
|
2010-06-02 11:01:47 +02:00
|
|
|
PaintPage(pPage, bDisplayPresentationObjects);
|
|
|
|
PaintSubstitutionText(rSubstitutionText);
|
2006-04-26 19:53:47 +00:00
|
|
|
PaintFrame();
|
|
|
|
|
|
|
|
Size aSize (mpPreviewDevice->GetOutputSizePixel());
|
|
|
|
aPreview = mpPreviewDevice->GetBitmap (
|
|
|
|
mpPreviewDevice->PixelToLogic(Point(0,0)),
|
|
|
|
mpPreviewDevice->PixelToLogic(aSize));
|
|
|
|
|
|
|
|
Cleanup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const com::sun::star::uno::Exception&)
|
|
|
|
{
|
2010-03-18 14:37:10 +01:00
|
|
|
DBG_UNHANDLED_EXCEPTION();
|
2006-04-26 19:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return aPreview;
|
|
|
|
}
|
2005-07-07 12:38:40 +00:00
|
|
|
|
|
|
|
|
2006-04-26 19:53:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
Image PreviewRenderer::RenderSubstitution (
|
|
|
|
const Size& rPreviewPixelSize,
|
|
|
|
const String& rSubstitutionText)
|
|
|
|
{
|
|
|
|
Image aPreview;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Set size.
|
|
|
|
mpPreviewDevice->SetOutputSizePixel(rPreviewPixelSize);
|
|
|
|
|
|
|
|
// Adjust contrast mode.
|
2010-03-03 13:21:37 +01:00
|
|
|
const bool bUseContrast (
|
|
|
|
Application::GetSettings().GetStyleSettings().GetHighContrastMode());
|
2006-04-26 19:53:47 +00:00
|
|
|
mpPreviewDevice->SetDrawMode (bUseContrast
|
|
|
|
? ViewShell::OUTPUT_DRAWMODE_CONTRAST
|
|
|
|
: ViewShell::OUTPUT_DRAWMODE_COLOR);
|
|
|
|
|
2010-06-02 11:01:47 +02:00
|
|
|
// Set a map mode that makes a typical substitution text completely
|
2006-04-26 19:53:47 +00:00
|
|
|
// visible.
|
|
|
|
MapMode aMapMode (mpPreviewDevice->GetMapMode());
|
|
|
|
aMapMode.SetMapUnit(MAP_100TH_MM);
|
2010-03-03 13:21:37 +01:00
|
|
|
const double nFinalScale (25.0 * rPreviewPixelSize.Width() / 28000.0);
|
2006-04-26 19:53:47 +00:00
|
|
|
aMapMode.SetScaleX(nFinalScale);
|
|
|
|
aMapMode.SetScaleY(nFinalScale);
|
2008-04-03 13:52:57 +00:00
|
|
|
const sal_Int32 nFrameWidth (mbHasFrame ? snFrameWidth : 0);
|
2006-04-26 19:53:47 +00:00
|
|
|
aMapMode.SetOrigin(mpPreviewDevice->PixelToLogic(
|
2008-04-03 13:52:57 +00:00
|
|
|
Point(nFrameWidth,nFrameWidth),aMapMode));
|
2006-04-26 19:53:47 +00:00
|
|
|
mpPreviewDevice->SetMapMode (aMapMode);
|
|
|
|
|
|
|
|
// Clear the background.
|
2010-03-03 13:21:37 +01:00
|
|
|
const Rectangle aPaintRectangle (
|
2006-04-26 19:53:47 +00:00
|
|
|
Point(0,0),
|
|
|
|
mpPreviewDevice->GetOutputSizePixel());
|
2011-01-17 11:41:00 +01:00
|
|
|
mpPreviewDevice->EnableMapMode(sal_False);
|
2006-04-26 19:53:47 +00:00
|
|
|
mpPreviewDevice->SetLineColor();
|
|
|
|
svtools::ColorConfig aColorConfig;
|
|
|
|
mpPreviewDevice->SetFillColor(aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor);
|
|
|
|
mpPreviewDevice->DrawRect (aPaintRectangle);
|
2011-01-17 11:41:00 +01:00
|
|
|
mpPreviewDevice->EnableMapMode(sal_True);
|
2006-04-26 19:53:47 +00:00
|
|
|
|
|
|
|
// Paint substitution text and a frame around it.
|
|
|
|
PaintSubstitutionText (rSubstitutionText);
|
|
|
|
PaintFrame();
|
|
|
|
|
2010-03-03 13:21:37 +01:00
|
|
|
const Size aSize (mpPreviewDevice->GetOutputSizePixel());
|
2006-04-26 19:53:47 +00:00
|
|
|
aPreview = mpPreviewDevice->GetBitmap (
|
|
|
|
mpPreviewDevice->PixelToLogic(Point(0,0)),
|
|
|
|
mpPreviewDevice->PixelToLogic(aSize));
|
2005-07-07 12:38:40 +00:00
|
|
|
}
|
|
|
|
catch (const com::sun::star::uno::Exception&)
|
|
|
|
{
|
2010-03-18 14:37:10 +01:00
|
|
|
DBG_UNHANDLED_EXCEPTION();
|
2004-09-20 12:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return aPreview;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool PreviewRenderer::Initialize (
|
|
|
|
const SdPage* pPage,
|
2009-05-07 12:38:03 +00:00
|
|
|
const Size& rPixelSize,
|
|
|
|
const bool bObeyHighContrastMode)
|
2004-09-20 12:36:40 +00:00
|
|
|
{
|
2012-12-09 22:41:45 +01:00
|
|
|
if (pPage == NULL)
|
|
|
|
return false;
|
2004-09-20 12:36:40 +00:00
|
|
|
|
2012-12-09 22:41:45 +01:00
|
|
|
SdrModel* pModel = pPage->GetModel();
|
|
|
|
if (pModel == NULL)
|
|
|
|
return false;
|
2004-09-20 12:36:40 +00:00
|
|
|
|
2012-12-09 22:41:45 +01:00
|
|
|
SetupOutputSize(*pPage, rPixelSize);
|
2004-09-20 12:36:40 +00:00
|
|
|
|
2012-12-09 22:41:45 +01:00
|
|
|
SdDrawDocument* pDocument
|
|
|
|
= static_cast<SdDrawDocument*>(pPage->GetModel());
|
|
|
|
DrawDocShell* pDocShell = pDocument->GetDocSh();
|
2004-09-20 12:36:40 +00:00
|
|
|
|
2012-12-09 22:41:45 +01:00
|
|
|
// Create view
|
|
|
|
ProvideView (pDocShell);
|
|
|
|
if (mpView.get() == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Adjust contrast mode.
|
|
|
|
bool bUseContrast (bObeyHighContrastMode
|
|
|
|
&& Application::GetSettings().GetStyleSettings().GetHighContrastMode());
|
|
|
|
mpPreviewDevice->SetDrawMode (bUseContrast
|
|
|
|
? ViewShell::OUTPUT_DRAWMODE_CONTRAST
|
|
|
|
: ViewShell::OUTPUT_DRAWMODE_COLOR);
|
|
|
|
mpPreviewDevice->SetSettings(Application::GetSettings());
|
|
|
|
|
|
|
|
// Tell the view to show the given page.
|
|
|
|
SdPage* pNonConstPage = const_cast<SdPage*>(pPage);
|
|
|
|
if (pPage->IsMasterPage())
|
|
|
|
{
|
|
|
|
mpView->ShowSdrPage(mpView->GetModel()->GetMasterPage(pPage->GetPageNum()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mpView->ShowSdrPage(pNonConstPage);
|
2004-09-20 12:36:40 +00:00
|
|
|
}
|
|
|
|
|
2012-12-09 22:41:45 +01:00
|
|
|
// Make sure that a page view exists.
|
|
|
|
SdrPageView* pPageView = mpView->GetSdrPageView();
|
|
|
|
|
|
|
|
if (pPageView == NULL)
|
|
|
|
return false;
|
|
|
|
|
2012-10-19 15:27:03 +00:00
|
|
|
// #i121224# No need to set SetApplicationBackgroundColor (which is the color
|
|
|
|
// of the area 'behind' the page (formally called 'Wiese') since the page previews
|
|
|
|
// produced exactly cover the page's area, so it would never be visible. What
|
|
|
|
// needs to be set is the ApplicationDocumentColor which is derived from
|
|
|
|
// svtools::DOCCOLOR normally
|
|
|
|
Color aApplicationDocumentColor;
|
|
|
|
|
|
|
|
if (pPageView->GetApplicationDocumentColor() == COL_AUTO)
|
|
|
|
{
|
|
|
|
svtools::ColorConfig aColorConfig;
|
|
|
|
aApplicationDocumentColor = aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aApplicationDocumentColor = pPageView->GetApplicationDocumentColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
pPageView->SetApplicationDocumentColor(aApplicationDocumentColor);
|
|
|
|
SdrOutliner& rOutliner(pDocument->GetDrawOutliner(NULL));
|
|
|
|
rOutliner.SetBackgroundColor(aApplicationDocumentColor);
|
2012-12-09 22:41:45 +01:00
|
|
|
rOutliner.SetDefaultLanguage(pDocument->GetLanguage(EE_CHAR_LANGUAGE));
|
2012-10-19 15:27:03 +00:00
|
|
|
mpPreviewDevice->SetBackground(Wallpaper(aApplicationDocumentColor));
|
2012-12-09 22:41:45 +01:00
|
|
|
mpPreviewDevice->Erase();
|
|
|
|
|
|
|
|
return true;
|
2004-09-20 12:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PreviewRenderer::Cleanup (void)
|
|
|
|
{
|
2006-11-14 13:37:41 +00:00
|
|
|
mpView->HideSdrPage();
|
2004-09-20 12:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-04-26 19:53:47 +00:00
|
|
|
|
2010-06-02 11:01:47 +02:00
|
|
|
void PreviewRenderer::PaintPage (
|
|
|
|
const SdPage* pPage,
|
|
|
|
const bool bDisplayPresentationObjects)
|
2004-09-20 12:36:40 +00:00
|
|
|
{
|
|
|
|
// Paint the page.
|
|
|
|
Rectangle aPaintRectangle (Point(0,0), pPage->GetSize());
|
|
|
|
Region aRegion (aPaintRectangle);
|
2005-07-07 12:38:40 +00:00
|
|
|
|
2006-04-26 19:53:47 +00:00
|
|
|
// Turn off online spelling and redlining.
|
|
|
|
SdrOutliner* pOutliner = NULL;
|
2011-01-17 11:41:00 +01:00
|
|
|
sal_uLong nSavedControlWord (0);
|
2006-04-26 19:53:47 +00:00
|
|
|
if (mpDocShellOfView!=NULL && mpDocShellOfView->GetDoc()!=NULL)
|
|
|
|
{
|
|
|
|
pOutliner = &mpDocShellOfView->GetDoc()->GetDrawOutliner();
|
2010-06-02 11:01:47 +02:00
|
|
|
nSavedControlWord = pOutliner->GetControlWord();
|
|
|
|
pOutliner->SetControlWord((nSavedControlWord & ~EE_CNTRL_ONLINESPELLING));
|
2006-04-26 19:53:47 +00:00
|
|
|
}
|
|
|
|
|
2010-06-02 11:01:47 +02:00
|
|
|
// Use a special redirector to prevent PresObj shapes from being painted.
|
|
|
|
boost::scoped_ptr<ViewRedirector> pRedirector;
|
|
|
|
if ( ! bDisplayPresentationObjects)
|
|
|
|
pRedirector.reset(new ViewRedirector());
|
|
|
|
|
2005-07-07 12:38:40 +00:00
|
|
|
try
|
|
|
|
{
|
2010-06-02 11:01:47 +02:00
|
|
|
mpView->CompleteRedraw(mpPreviewDevice.get(), aRegion, pRedirector.get());
|
2005-07-07 12:38:40 +00:00
|
|
|
}
|
|
|
|
catch (const ::com::sun::star::uno::Exception&)
|
|
|
|
{
|
2010-03-18 14:37:10 +01:00
|
|
|
DBG_UNHANDLED_EXCEPTION();
|
2005-07-07 12:38:40 +00:00
|
|
|
}
|
2006-04-26 19:53:47 +00:00
|
|
|
|
|
|
|
// Restore the previous online spelling and redlining states.
|
|
|
|
if (pOutliner != NULL)
|
2010-06-02 11:01:47 +02:00
|
|
|
pOutliner->SetControlWord(nSavedControlWord);
|
2004-09-20 12:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PreviewRenderer::PaintSubstitutionText (const String& rSubstitutionText)
|
|
|
|
{
|
|
|
|
if (rSubstitutionText.Len() > 0)
|
|
|
|
{
|
|
|
|
// Set the font size.
|
|
|
|
const Font& rOriginalFont (mpPreviewDevice->GetFont());
|
2006-04-26 19:53:47 +00:00
|
|
|
Font aFont (mpPreviewDevice->GetSettings().GetStyleSettings().GetAppFont());
|
|
|
|
sal_Int32 nHeight (mpPreviewDevice->PixelToLogic(Size(0,snSubstitutionTextSize)).Height());
|
|
|
|
aFont.SetHeight(nHeight);
|
2004-09-20 12:36:40 +00:00
|
|
|
mpPreviewDevice->SetFont (aFont);
|
|
|
|
|
|
|
|
// Paint the substitution text.
|
|
|
|
Rectangle aTextBox (
|
|
|
|
Point(0,0),
|
|
|
|
mpPreviewDevice->PixelToLogic(
|
|
|
|
mpPreviewDevice->GetOutputSizePixel()));
|
2011-01-17 11:41:00 +01:00
|
|
|
sal_uInt16 nTextStyle =
|
2004-09-20 12:36:40 +00:00
|
|
|
TEXT_DRAW_CENTER
|
|
|
|
| TEXT_DRAW_VCENTER
|
|
|
|
| TEXT_DRAW_MULTILINE
|
|
|
|
| TEXT_DRAW_WORDBREAK;
|
|
|
|
mpPreviewDevice->DrawText (aTextBox, rSubstitutionText, nTextStyle);
|
|
|
|
|
|
|
|
// Restore the font.
|
|
|
|
mpPreviewDevice->SetFont (rOriginalFont);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PreviewRenderer::PaintFrame (void)
|
|
|
|
{
|
2008-04-03 13:52:57 +00:00
|
|
|
if (mbHasFrame)
|
|
|
|
{
|
|
|
|
// Paint a frame arround the preview.
|
|
|
|
Rectangle aPaintRectangle (
|
|
|
|
Point(0,0),
|
|
|
|
mpPreviewDevice->GetOutputSizePixel());
|
2011-01-17 11:41:00 +01:00
|
|
|
mpPreviewDevice->EnableMapMode(sal_False);
|
2008-04-03 13:52:57 +00:00
|
|
|
mpPreviewDevice->SetLineColor(maFrameColor);
|
|
|
|
mpPreviewDevice->SetFillColor();
|
|
|
|
mpPreviewDevice->DrawRect(aPaintRectangle);
|
2011-01-17 11:41:00 +01:00
|
|
|
mpPreviewDevice->EnableMapMode(sal_True);
|
2008-04-03 13:52:57 +00:00
|
|
|
}
|
2004-09-20 12:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PreviewRenderer::SetupOutputSize (
|
2008-04-03 13:52:57 +00:00
|
|
|
const SdPage& rPage,
|
2004-09-20 12:36:40 +00:00
|
|
|
const Size& rFramePixelSize)
|
|
|
|
{
|
|
|
|
// First set the map mode to some arbitrary scale that is numerically
|
|
|
|
// stable.
|
|
|
|
MapMode aMapMode (mpPreviewDevice->GetMapMode());
|
2010-03-15 13:50:38 +01:00
|
|
|
aMapMode.SetMapUnit(MAP_PIXEL);
|
2004-09-20 12:36:40 +00:00
|
|
|
|
|
|
|
// Adapt it to the desired width.
|
2008-04-03 13:52:57 +00:00
|
|
|
const Size aPageModelSize (rPage.GetSize());
|
2010-03-15 13:50:38 +01:00
|
|
|
if (aPageModelSize.Width()>0 || aPageModelSize.Height()>0)
|
|
|
|
{
|
|
|
|
const sal_Int32 nFrameWidth (mbHasFrame ? snFrameWidth : 0);
|
|
|
|
aMapMode.SetScaleX(
|
|
|
|
Fraction(rFramePixelSize.Width()-2*nFrameWidth-1, aPageModelSize.Width()));
|
|
|
|
aMapMode.SetScaleY(
|
|
|
|
Fraction(rFramePixelSize.Height()-2*nFrameWidth-1, aPageModelSize.Height()));
|
|
|
|
aMapMode.SetOrigin(mpPreviewDevice->PixelToLogic(Point(nFrameWidth,nFrameWidth),aMapMode));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We should never get here.
|
|
|
|
OSL_ASSERT(false);
|
|
|
|
aMapMode.SetScaleX(1.0);
|
|
|
|
aMapMode.SetScaleY(1.0);
|
|
|
|
}
|
2004-09-20 12:36:40 +00:00
|
|
|
mpPreviewDevice->SetMapMode (aMapMode);
|
|
|
|
mpPreviewDevice->SetOutputSizePixel(rFramePixelSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PreviewRenderer::ProvideView (DrawDocShell* pDocShell)
|
|
|
|
{
|
|
|
|
if (pDocShell != mpDocShellOfView)
|
|
|
|
{
|
|
|
|
// Destroy the view that is connected to the current doc shell.
|
|
|
|
mpView.reset (NULL);
|
|
|
|
|
|
|
|
// Switch our attention, i.e. listening for DYING events, to
|
|
|
|
// the new doc shell.
|
|
|
|
if (mpDocShellOfView != NULL)
|
|
|
|
EndListening (*mpDocShellOfView);
|
|
|
|
mpDocShellOfView = pDocShell;
|
|
|
|
if (mpDocShellOfView != NULL)
|
|
|
|
StartListening (*mpDocShellOfView);
|
|
|
|
}
|
|
|
|
if (mpView.get() == NULL)
|
|
|
|
{
|
|
|
|
mpView.reset (new DrawView (pDocShell, mpPreviewDevice.get(), NULL));
|
|
|
|
}
|
2010-02-18 15:20:15 +01:00
|
|
|
mpView->SetPreviewRenderer(true);
|
2010-02-19 11:59:56 +01:00
|
|
|
#if 1
|
|
|
|
mpView->SetPageVisible(false);
|
|
|
|
mpView->SetPageBorderVisible(true);
|
|
|
|
mpView->SetBordVisible(false);
|
2012-12-09 22:41:45 +01:00
|
|
|
mpView->SetGridVisible(false);
|
|
|
|
mpView->SetHlplVisible(false);
|
|
|
|
mpView->SetGlueVisible(false);
|
|
|
|
|
2010-02-19 11:59:56 +01:00
|
|
|
#else
|
|
|
|
// This works in the slide sorter but prevents the master page
|
|
|
|
// background being painted in the list of current master pages in the
|
|
|
|
// task manager.
|
2010-02-18 15:20:15 +01:00
|
|
|
mpView->SetPagePaintingAllowed(false);
|
2010-02-19 11:59:56 +01:00
|
|
|
#endif
|
2004-09-20 12:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Image PreviewRenderer::ScaleBitmap (
|
|
|
|
const BitmapEx& rBitmapEx,
|
|
|
|
int nWidth)
|
|
|
|
{
|
|
|
|
Image aPreview;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
// Adjust contrast mode.
|
|
|
|
bool bUseContrast = Application::GetSettings().GetStyleSettings().
|
|
|
|
GetHighContrastMode();
|
|
|
|
mpPreviewDevice->SetDrawMode (bUseContrast
|
|
|
|
? ViewShell::OUTPUT_DRAWMODE_CONTRAST
|
|
|
|
: ViewShell::OUTPUT_DRAWMODE_COLOR);
|
|
|
|
|
|
|
|
// Set output size.
|
|
|
|
Size aSize (rBitmapEx.GetSizePixel());
|
|
|
|
if (aSize.Width() <= 0)
|
|
|
|
break;
|
|
|
|
Size aFrameSize (
|
|
|
|
nWidth,
|
|
|
|
(long)((nWidth*1.0 * aSize.Height()) / aSize.Width() + 0.5));
|
|
|
|
Size aPreviewSize (aFrameSize.Width()-2,aFrameSize.Height()-2);
|
|
|
|
MapMode aMapMode (mpPreviewDevice->GetMapMode());
|
|
|
|
aMapMode.SetMapUnit(MAP_PIXEL);
|
|
|
|
aMapMode.SetOrigin (Point());
|
|
|
|
aMapMode.SetScaleX (1.0);
|
|
|
|
aMapMode.SetScaleY (1.0);
|
|
|
|
mpPreviewDevice->SetMapMode (aMapMode);
|
|
|
|
mpPreviewDevice->SetOutputSize (aFrameSize);
|
|
|
|
|
|
|
|
// Paint a frame arround the preview.
|
|
|
|
mpPreviewDevice->SetLineColor (maFrameColor);
|
|
|
|
mpPreviewDevice->SetFillColor ();
|
|
|
|
mpPreviewDevice->DrawRect (Rectangle(Point(0,0), aFrameSize));
|
|
|
|
|
|
|
|
// Paint the bitmap scaled to the desired width.
|
|
|
|
BitmapEx aScaledBitmap (rBitmapEx.GetBitmap());
|
2012-10-29 16:20:25 +00:00
|
|
|
aScaledBitmap.Scale (aPreviewSize, BMP_SCALE_BESTQUALITY);
|
2004-09-20 12:36:40 +00:00
|
|
|
mpPreviewDevice->DrawBitmap (
|
|
|
|
Point(1,1),
|
|
|
|
aPreviewSize,
|
|
|
|
aScaledBitmap.GetBitmap());
|
|
|
|
|
|
|
|
// Get the resulting bitmap.
|
|
|
|
aPreview = mpPreviewDevice->GetBitmap (Point(0,0), aFrameSize);
|
|
|
|
}
|
|
|
|
while (false);
|
|
|
|
|
|
|
|
return aPreview;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-09-30 06:36:06 +00:00
|
|
|
void PreviewRenderer::Notify(SfxBroadcaster&, const SfxHint& rHint)
|
2004-09-20 12:36:40 +00:00
|
|
|
{
|
|
|
|
if (rHint.IsA(TYPE(SfxSimpleHint))
|
|
|
|
&& mpDocShellOfView != NULL)
|
|
|
|
{
|
|
|
|
const SfxSimpleHint* pSimpleHint = PTR_CAST(SfxSimpleHint, &rHint);
|
|
|
|
if (pSimpleHint != NULL
|
|
|
|
&& pSimpleHint->GetId() == SFX_HINT_DYING)
|
|
|
|
{
|
|
|
|
// The doc shell is dying. Our view uses its item pool and
|
|
|
|
// has to be destroyed as well. The next call to
|
|
|
|
// ProvideView will create a new one (for another
|
|
|
|
// doc shell, of course.)
|
|
|
|
mpView.reset (NULL);
|
|
|
|
mpDocShellOfView = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-06-02 11:01:47 +02:00
|
|
|
|
|
|
|
//===== ViewRedirector ========================================================
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
ViewRedirector::ViewRedirector (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ViewRedirector::~ViewRedirector (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
drawinglayer::primitive2d::Primitive2DSequence ViewRedirector::createRedirectedPrimitive2DSequence(
|
|
|
|
const sdr::contact::ViewObjectContact& rOriginal,
|
|
|
|
const sdr::contact::DisplayInfo& rDisplayInfo)
|
|
|
|
{
|
|
|
|
SdrObject* pObject = rOriginal.GetViewContact().TryToGetSdrObject();
|
|
|
|
|
|
|
|
if (pObject==NULL || pObject->GetPage() == NULL)
|
|
|
|
{
|
|
|
|
// not a SdrObject visualisation (maybe e.g. page) or no page
|
|
|
|
return sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(
|
|
|
|
rOriginal,
|
|
|
|
rDisplayInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool bDoCreateGeometry (pObject->GetPage()->checkVisibility( rOriginal, rDisplayInfo, true));
|
|
|
|
|
|
|
|
if ( ! bDoCreateGeometry
|
|
|
|
&& (pObject->GetObjInventor() != SdrInventor || pObject->GetObjIdentifier() != OBJ_PAGE))
|
|
|
|
{
|
|
|
|
return drawinglayer::primitive2d::Primitive2DSequence();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pObject->IsEmptyPresObj())
|
|
|
|
return drawinglayer::primitive2d::Primitive2DSequence();
|
|
|
|
|
|
|
|
return sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(
|
|
|
|
rOriginal,
|
|
|
|
rDisplayInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end of anonymous namespace
|
|
|
|
|
|
|
|
|
2004-09-20 12:36:40 +00:00
|
|
|
} // end of namespace ::sd
|
2010-10-12 15:51:52 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|