1*5b190011SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*5b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*5b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*5b190011SAndrew Rist * distributed with this work for additional information 6*5b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*5b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*5b190011SAndrew Rist * "License"); you may not use this file except in compliance 9*5b190011SAndrew Rist * with the License. You may obtain a copy of the License at 10*5b190011SAndrew Rist * 11*5b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*5b190011SAndrew Rist * 13*5b190011SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*5b190011SAndrew Rist * software distributed under the License is distributed on an 15*5b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*5b190011SAndrew Rist * KIND, either express or implied. See the License for the 17*5b190011SAndrew Rist * specific language governing permissions and limitations 18*5b190011SAndrew Rist * under the License. 19*5b190011SAndrew Rist * 20*5b190011SAndrew Rist *************************************************************/ 21*5b190011SAndrew Rist 22*5b190011SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sd.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "PreviewRenderer.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include "DrawDocShell.hxx" 30cdf0e10cSrcweir #include "drawdoc.hxx" 31cdf0e10cSrcweir #include "drawview.hxx" 32cdf0e10cSrcweir #include "sdpage.hxx" 33cdf0e10cSrcweir #include "ViewShell.hxx" 34cdf0e10cSrcweir #include <vcl/virdev.hxx> 35cdf0e10cSrcweir #include <svx/svdpagv.hxx> 36cdf0e10cSrcweir #include <svx/svdoutl.hxx> 37cdf0e10cSrcweir #include <editeng/eeitem.hxx> 38cdf0e10cSrcweir #include <editeng/editstat.hxx> 39cdf0e10cSrcweir #include <tools/link.hxx> 40cdf0e10cSrcweir #include <vcl/svapp.hxx> 41cdf0e10cSrcweir #include <tools/diagnose_ex.h> 42cdf0e10cSrcweir #include <svx/sdr/contact/viewobjectcontact.hxx> 43cdf0e10cSrcweir #include <svx/sdr/contact/viewcontact.hxx> 44cdf0e10cSrcweir 45cdf0e10cSrcweir using namespace ::com::sun::star; 46cdf0e10cSrcweir using namespace ::com::sun::star::uno; 47cdf0e10cSrcweir 48cdf0e10cSrcweir 49cdf0e10cSrcweir namespace sd { 50cdf0e10cSrcweir 51cdf0e10cSrcweir const int PreviewRenderer::snSubstitutionTextSize = 11; 52cdf0e10cSrcweir const int PreviewRenderer::snFrameWidth = 1; 53cdf0e10cSrcweir 54cdf0e10cSrcweir namespace { 55cdf0e10cSrcweir /** This incarnation of the ViewObjectContactRedirector filters away all 56cdf0e10cSrcweir PageObj objects, unconditionally. 57cdf0e10cSrcweir */ 58cdf0e10cSrcweir class ViewRedirector : public ::sdr::contact::ViewObjectContactRedirector 59cdf0e10cSrcweir { 60cdf0e10cSrcweir public: 61cdf0e10cSrcweir ViewRedirector (void); 62cdf0e10cSrcweir virtual ~ViewRedirector (void); 63cdf0e10cSrcweir virtual drawinglayer::primitive2d::Primitive2DSequence createRedirectedPrimitive2DSequence( 64cdf0e10cSrcweir const sdr::contact::ViewObjectContact& rOriginal, 65cdf0e10cSrcweir const sdr::contact::DisplayInfo& rDisplayInfo); 66cdf0e10cSrcweir }; 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir 70cdf0e10cSrcweir 71cdf0e10cSrcweir 72cdf0e10cSrcweir //===== PreviewRenderer ======================================================= 73cdf0e10cSrcweir 74cdf0e10cSrcweir PreviewRenderer::PreviewRenderer ( 75cdf0e10cSrcweir OutputDevice* pTemplate, 76cdf0e10cSrcweir const bool bHasFrame) 77cdf0e10cSrcweir : mpPreviewDevice (new VirtualDevice()), 78cdf0e10cSrcweir mpView(NULL), 79cdf0e10cSrcweir mpDocShellOfView(NULL), 80cdf0e10cSrcweir mnWidthOfView(0), 81cdf0e10cSrcweir maFrameColor (svtools::ColorConfig().GetColorValue(svtools::DOCBOUNDARIES).nColor), 82cdf0e10cSrcweir mbHasFrame(bHasFrame) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir if (pTemplate != NULL) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir mpPreviewDevice->SetDigitLanguage (pTemplate->GetDigitLanguage()); 87cdf0e10cSrcweir mpPreviewDevice->SetBackground(pTemplate->GetBackground()); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir else 90cdf0e10cSrcweir { 91cdf0e10cSrcweir mpPreviewDevice->SetBackground(Wallpaper( 92cdf0e10cSrcweir Application::GetSettings().GetStyleSettings().GetWindowColor())); 93cdf0e10cSrcweir } 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir 97cdf0e10cSrcweir 98cdf0e10cSrcweir 99cdf0e10cSrcweir PreviewRenderer::~PreviewRenderer (void) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir if (mpDocShellOfView != NULL) 102cdf0e10cSrcweir EndListening (*mpDocShellOfView); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir 106cdf0e10cSrcweir 107cdf0e10cSrcweir 108cdf0e10cSrcweir Image PreviewRenderer::RenderPage ( 109cdf0e10cSrcweir const SdPage* pPage, 110cdf0e10cSrcweir const sal_Int32 nWidth, 111cdf0e10cSrcweir const String& rSubstitutionText, 112cdf0e10cSrcweir const bool bObeyHighContrastMode, 113cdf0e10cSrcweir const bool bDisplayPresentationObjects) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir if (pPage != NULL) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir const Size aPageModelSize (pPage->GetSize()); 118cdf0e10cSrcweir const double nAspectRatio ( 119cdf0e10cSrcweir double(aPageModelSize.Width()) / double(aPageModelSize.Height())); 120cdf0e10cSrcweir const sal_Int32 nFrameWidth (mbHasFrame ? snFrameWidth : 0); 121cdf0e10cSrcweir const sal_Int32 nHeight (sal::static_int_cast<sal_Int32>( 122cdf0e10cSrcweir (nWidth - 2*nFrameWidth) / nAspectRatio + 2*nFrameWidth + 0.5)); 123cdf0e10cSrcweir return RenderPage ( 124cdf0e10cSrcweir pPage, 125cdf0e10cSrcweir Size(nWidth,nHeight), 126cdf0e10cSrcweir rSubstitutionText, 127cdf0e10cSrcweir bObeyHighContrastMode, 128cdf0e10cSrcweir bDisplayPresentationObjects); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir else 131cdf0e10cSrcweir return Image(); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir 135cdf0e10cSrcweir 136cdf0e10cSrcweir 137cdf0e10cSrcweir Image PreviewRenderer::RenderPage ( 138cdf0e10cSrcweir const SdPage* pPage, 139cdf0e10cSrcweir Size aPixelSize, 140cdf0e10cSrcweir const String& rSubstitutionText, 141cdf0e10cSrcweir const bool bObeyHighContrastMode, 142cdf0e10cSrcweir const bool bDisplayPresentationObjects) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir Image aPreview; 145cdf0e10cSrcweir 146cdf0e10cSrcweir if (pPage != NULL) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir try 149cdf0e10cSrcweir { 150cdf0e10cSrcweir if (Initialize(pPage, aPixelSize, bObeyHighContrastMode)) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir PaintPage(pPage, bDisplayPresentationObjects); 153cdf0e10cSrcweir PaintSubstitutionText(rSubstitutionText); 154cdf0e10cSrcweir PaintFrame(); 155cdf0e10cSrcweir 156cdf0e10cSrcweir Size aSize (mpPreviewDevice->GetOutputSizePixel()); 157cdf0e10cSrcweir aPreview = mpPreviewDevice->GetBitmap ( 158cdf0e10cSrcweir mpPreviewDevice->PixelToLogic(Point(0,0)), 159cdf0e10cSrcweir mpPreviewDevice->PixelToLogic(aSize)); 160cdf0e10cSrcweir 161cdf0e10cSrcweir Cleanup(); 162cdf0e10cSrcweir } 163cdf0e10cSrcweir } 164cdf0e10cSrcweir catch (const com::sun::star::uno::Exception&) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir } 169cdf0e10cSrcweir 170cdf0e10cSrcweir return aPreview; 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir 174cdf0e10cSrcweir 175cdf0e10cSrcweir 176cdf0e10cSrcweir Image PreviewRenderer::RenderSubstitution ( 177cdf0e10cSrcweir const Size& rPreviewPixelSize, 178cdf0e10cSrcweir const String& rSubstitutionText) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir Image aPreview; 181cdf0e10cSrcweir 182cdf0e10cSrcweir try 183cdf0e10cSrcweir { 184cdf0e10cSrcweir // Set size. 185cdf0e10cSrcweir mpPreviewDevice->SetOutputSizePixel(rPreviewPixelSize); 186cdf0e10cSrcweir 187cdf0e10cSrcweir // Adjust contrast mode. 188cdf0e10cSrcweir const bool bUseContrast ( 189cdf0e10cSrcweir Application::GetSettings().GetStyleSettings().GetHighContrastMode()); 190cdf0e10cSrcweir mpPreviewDevice->SetDrawMode (bUseContrast 191cdf0e10cSrcweir ? ViewShell::OUTPUT_DRAWMODE_CONTRAST 192cdf0e10cSrcweir : ViewShell::OUTPUT_DRAWMODE_COLOR); 193cdf0e10cSrcweir 194cdf0e10cSrcweir // Set a map mode that makes a typical substitution text completely 195cdf0e10cSrcweir // visible. 196cdf0e10cSrcweir MapMode aMapMode (mpPreviewDevice->GetMapMode()); 197cdf0e10cSrcweir aMapMode.SetMapUnit(MAP_100TH_MM); 198cdf0e10cSrcweir const double nFinalScale (25.0 * rPreviewPixelSize.Width() / 28000.0); 199cdf0e10cSrcweir aMapMode.SetScaleX(nFinalScale); 200cdf0e10cSrcweir aMapMode.SetScaleY(nFinalScale); 201cdf0e10cSrcweir const sal_Int32 nFrameWidth (mbHasFrame ? snFrameWidth : 0); 202cdf0e10cSrcweir aMapMode.SetOrigin(mpPreviewDevice->PixelToLogic( 203cdf0e10cSrcweir Point(nFrameWidth,nFrameWidth),aMapMode)); 204cdf0e10cSrcweir mpPreviewDevice->SetMapMode (aMapMode); 205cdf0e10cSrcweir 206cdf0e10cSrcweir // Clear the background. 207cdf0e10cSrcweir const Rectangle aPaintRectangle ( 208cdf0e10cSrcweir Point(0,0), 209cdf0e10cSrcweir mpPreviewDevice->GetOutputSizePixel()); 210cdf0e10cSrcweir mpPreviewDevice->EnableMapMode(sal_False); 211cdf0e10cSrcweir mpPreviewDevice->SetLineColor(); 212cdf0e10cSrcweir svtools::ColorConfig aColorConfig; 213cdf0e10cSrcweir mpPreviewDevice->SetFillColor(aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor); 214cdf0e10cSrcweir mpPreviewDevice->DrawRect (aPaintRectangle); 215cdf0e10cSrcweir mpPreviewDevice->EnableMapMode(sal_True); 216cdf0e10cSrcweir 217cdf0e10cSrcweir // Paint substitution text and a frame around it. 218cdf0e10cSrcweir PaintSubstitutionText (rSubstitutionText); 219cdf0e10cSrcweir PaintFrame(); 220cdf0e10cSrcweir 221cdf0e10cSrcweir const Size aSize (mpPreviewDevice->GetOutputSizePixel()); 222cdf0e10cSrcweir aPreview = mpPreviewDevice->GetBitmap ( 223cdf0e10cSrcweir mpPreviewDevice->PixelToLogic(Point(0,0)), 224cdf0e10cSrcweir mpPreviewDevice->PixelToLogic(aSize)); 225cdf0e10cSrcweir } 226cdf0e10cSrcweir catch (const com::sun::star::uno::Exception&) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir return aPreview; 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir 235cdf0e10cSrcweir 236cdf0e10cSrcweir 237cdf0e10cSrcweir bool PreviewRenderer::Initialize ( 238cdf0e10cSrcweir const SdPage* pPage, 239cdf0e10cSrcweir const Size& rPixelSize, 240cdf0e10cSrcweir const bool bObeyHighContrastMode) 241cdf0e10cSrcweir { 242cdf0e10cSrcweir bool bSuccess = false; 243cdf0e10cSrcweir do 244cdf0e10cSrcweir { 245cdf0e10cSrcweir if (pPage == NULL) 246cdf0e10cSrcweir break; 247cdf0e10cSrcweir 248cdf0e10cSrcweir SdrModel* pModel = pPage->GetModel(); 249cdf0e10cSrcweir if (pModel == NULL) 250cdf0e10cSrcweir break; 251cdf0e10cSrcweir 252cdf0e10cSrcweir SetupOutputSize(*pPage, rPixelSize); 253cdf0e10cSrcweir 254cdf0e10cSrcweir SdDrawDocument* pDocument 255cdf0e10cSrcweir = static_cast<SdDrawDocument*>(pPage->GetModel()); 256cdf0e10cSrcweir DrawDocShell* pDocShell = pDocument->GetDocSh(); 257cdf0e10cSrcweir 258cdf0e10cSrcweir // Create view 259cdf0e10cSrcweir ProvideView (pDocShell); 260cdf0e10cSrcweir if (mpView.get() == NULL) 261cdf0e10cSrcweir break; 262cdf0e10cSrcweir 263cdf0e10cSrcweir // Adjust contrast mode. 264cdf0e10cSrcweir bool bUseContrast (bObeyHighContrastMode 265cdf0e10cSrcweir && Application::GetSettings().GetStyleSettings().GetHighContrastMode()); 266cdf0e10cSrcweir mpPreviewDevice->SetDrawMode (bUseContrast 267cdf0e10cSrcweir ? ViewShell::OUTPUT_DRAWMODE_CONTRAST 268cdf0e10cSrcweir : ViewShell::OUTPUT_DRAWMODE_COLOR); 269cdf0e10cSrcweir mpPreviewDevice->SetSettings(Application::GetSettings()); 270cdf0e10cSrcweir 271cdf0e10cSrcweir // Tell the view to show the given page. 272cdf0e10cSrcweir SdPage* pNonConstPage = const_cast<SdPage*>(pPage); 273cdf0e10cSrcweir if (pPage->IsMasterPage()) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir mpView->ShowSdrPage(mpView->GetModel()->GetMasterPage(pPage->GetPageNum())); 276cdf0e10cSrcweir } 277cdf0e10cSrcweir else 278cdf0e10cSrcweir { 279cdf0e10cSrcweir mpView->ShowSdrPage(pNonConstPage); 280cdf0e10cSrcweir } 281cdf0e10cSrcweir 282cdf0e10cSrcweir // Make sure that a page view exists. 283cdf0e10cSrcweir SdrPageView* pPageView = mpView->GetSdrPageView(); 284cdf0e10cSrcweir if (pPageView == NULL) 285cdf0e10cSrcweir break; 286cdf0e10cSrcweir // Set background color of page view and outliner. 287cdf0e10cSrcweir svtools::ColorConfig aColorConfig; 288cdf0e10cSrcweir const Color aPageBackgroundColor(pPage->GetPageBackgroundColor(pPageView)); 289cdf0e10cSrcweir pPageView->SetApplicationBackgroundColor(aPageBackgroundColor); 290cdf0e10cSrcweir SdrOutliner& rOutliner (pDocument->GetDrawOutliner(NULL)); 291cdf0e10cSrcweir rOutliner.SetBackgroundColor(aPageBackgroundColor); 292cdf0e10cSrcweir rOutliner.SetDefaultLanguage(pDocument->GetLanguage(EE_CHAR_LANGUAGE)); 293cdf0e10cSrcweir mpView->SetApplicationBackgroundColor( 294cdf0e10cSrcweir Color(aColorConfig.GetColorValue(svtools::APPBACKGROUND).nColor)); 295cdf0e10cSrcweir mpPreviewDevice->SetBackground(Wallpaper(aPageBackgroundColor)); 296cdf0e10cSrcweir mpPreviewDevice->Erase(); 297cdf0e10cSrcweir 298cdf0e10cSrcweir bSuccess = true; 299cdf0e10cSrcweir } 300cdf0e10cSrcweir while (false); 301cdf0e10cSrcweir 302cdf0e10cSrcweir return bSuccess; 303cdf0e10cSrcweir } 304cdf0e10cSrcweir 305cdf0e10cSrcweir 306cdf0e10cSrcweir 307cdf0e10cSrcweir 308cdf0e10cSrcweir void PreviewRenderer::Cleanup (void) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir mpView->HideSdrPage(); 311cdf0e10cSrcweir } 312cdf0e10cSrcweir 313cdf0e10cSrcweir 314cdf0e10cSrcweir 315cdf0e10cSrcweir 316cdf0e10cSrcweir void PreviewRenderer::PaintPage ( 317cdf0e10cSrcweir const SdPage* pPage, 318cdf0e10cSrcweir const bool bDisplayPresentationObjects) 319cdf0e10cSrcweir { 320cdf0e10cSrcweir // Paint the page. 321cdf0e10cSrcweir Rectangle aPaintRectangle (Point(0,0), pPage->GetSize()); 322cdf0e10cSrcweir Region aRegion (aPaintRectangle); 323cdf0e10cSrcweir 324cdf0e10cSrcweir // Turn off online spelling and redlining. 325cdf0e10cSrcweir SdrOutliner* pOutliner = NULL; 326cdf0e10cSrcweir sal_uLong nSavedControlWord (0); 327cdf0e10cSrcweir if (mpDocShellOfView!=NULL && mpDocShellOfView->GetDoc()!=NULL) 328cdf0e10cSrcweir { 329cdf0e10cSrcweir pOutliner = &mpDocShellOfView->GetDoc()->GetDrawOutliner(); 330cdf0e10cSrcweir nSavedControlWord = pOutliner->GetControlWord(); 331cdf0e10cSrcweir pOutliner->SetControlWord((nSavedControlWord & ~EE_CNTRL_ONLINESPELLING)); 332cdf0e10cSrcweir } 333cdf0e10cSrcweir 334cdf0e10cSrcweir // Use a special redirector to prevent PresObj shapes from being painted. 335cdf0e10cSrcweir boost::scoped_ptr<ViewRedirector> pRedirector; 336cdf0e10cSrcweir if ( ! bDisplayPresentationObjects) 337cdf0e10cSrcweir pRedirector.reset(new ViewRedirector()); 338cdf0e10cSrcweir 339cdf0e10cSrcweir try 340cdf0e10cSrcweir { 341cdf0e10cSrcweir mpView->CompleteRedraw(mpPreviewDevice.get(), aRegion, pRedirector.get()); 342cdf0e10cSrcweir } 343cdf0e10cSrcweir catch (const ::com::sun::star::uno::Exception&) 344cdf0e10cSrcweir { 345cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 346cdf0e10cSrcweir } 347cdf0e10cSrcweir 348cdf0e10cSrcweir // Restore the previous online spelling and redlining states. 349cdf0e10cSrcweir if (pOutliner != NULL) 350cdf0e10cSrcweir pOutliner->SetControlWord(nSavedControlWord); 351cdf0e10cSrcweir } 352cdf0e10cSrcweir 353cdf0e10cSrcweir 354cdf0e10cSrcweir 355cdf0e10cSrcweir 356cdf0e10cSrcweir void PreviewRenderer::PaintSubstitutionText (const String& rSubstitutionText) 357cdf0e10cSrcweir { 358cdf0e10cSrcweir if (rSubstitutionText.Len() > 0) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir // Set the font size. 361cdf0e10cSrcweir const Font& rOriginalFont (mpPreviewDevice->GetFont()); 362cdf0e10cSrcweir Font aFont (mpPreviewDevice->GetSettings().GetStyleSettings().GetAppFont()); 363cdf0e10cSrcweir sal_Int32 nHeight (mpPreviewDevice->PixelToLogic(Size(0,snSubstitutionTextSize)).Height()); 364cdf0e10cSrcweir aFont.SetHeight(nHeight); 365cdf0e10cSrcweir mpPreviewDevice->SetFont (aFont); 366cdf0e10cSrcweir 367cdf0e10cSrcweir // Paint the substitution text. 368cdf0e10cSrcweir Rectangle aTextBox ( 369cdf0e10cSrcweir Point(0,0), 370cdf0e10cSrcweir mpPreviewDevice->PixelToLogic( 371cdf0e10cSrcweir mpPreviewDevice->GetOutputSizePixel())); 372cdf0e10cSrcweir sal_uInt16 nTextStyle = 373cdf0e10cSrcweir TEXT_DRAW_CENTER 374cdf0e10cSrcweir | TEXT_DRAW_VCENTER 375cdf0e10cSrcweir | TEXT_DRAW_MULTILINE 376cdf0e10cSrcweir | TEXT_DRAW_WORDBREAK; 377cdf0e10cSrcweir mpPreviewDevice->DrawText (aTextBox, rSubstitutionText, nTextStyle); 378cdf0e10cSrcweir 379cdf0e10cSrcweir // Restore the font. 380cdf0e10cSrcweir mpPreviewDevice->SetFont (rOriginalFont); 381cdf0e10cSrcweir } 382cdf0e10cSrcweir } 383cdf0e10cSrcweir 384cdf0e10cSrcweir 385cdf0e10cSrcweir 386cdf0e10cSrcweir 387cdf0e10cSrcweir void PreviewRenderer::PaintFrame (void) 388cdf0e10cSrcweir { 389cdf0e10cSrcweir if (mbHasFrame) 390cdf0e10cSrcweir { 391cdf0e10cSrcweir // Paint a frame arround the preview. 392cdf0e10cSrcweir Rectangle aPaintRectangle ( 393cdf0e10cSrcweir Point(0,0), 394cdf0e10cSrcweir mpPreviewDevice->GetOutputSizePixel()); 395cdf0e10cSrcweir mpPreviewDevice->EnableMapMode(sal_False); 396cdf0e10cSrcweir mpPreviewDevice->SetLineColor(maFrameColor); 397cdf0e10cSrcweir mpPreviewDevice->SetFillColor(); 398cdf0e10cSrcweir mpPreviewDevice->DrawRect(aPaintRectangle); 399cdf0e10cSrcweir mpPreviewDevice->EnableMapMode(sal_True); 400cdf0e10cSrcweir } 401cdf0e10cSrcweir } 402cdf0e10cSrcweir 403cdf0e10cSrcweir 404cdf0e10cSrcweir 405cdf0e10cSrcweir 406cdf0e10cSrcweir void PreviewRenderer::SetupOutputSize ( 407cdf0e10cSrcweir const SdPage& rPage, 408cdf0e10cSrcweir const Size& rFramePixelSize) 409cdf0e10cSrcweir { 410cdf0e10cSrcweir // First set the map mode to some arbitrary scale that is numerically 411cdf0e10cSrcweir // stable. 412cdf0e10cSrcweir MapMode aMapMode (mpPreviewDevice->GetMapMode()); 413cdf0e10cSrcweir aMapMode.SetMapUnit(MAP_PIXEL); 414cdf0e10cSrcweir 415cdf0e10cSrcweir // Adapt it to the desired width. 416cdf0e10cSrcweir const Size aPageModelSize (rPage.GetSize()); 417cdf0e10cSrcweir if (aPageModelSize.Width()>0 || aPageModelSize.Height()>0) 418cdf0e10cSrcweir { 419cdf0e10cSrcweir const sal_Int32 nFrameWidth (mbHasFrame ? snFrameWidth : 0); 420cdf0e10cSrcweir aMapMode.SetScaleX( 421cdf0e10cSrcweir Fraction(rFramePixelSize.Width()-2*nFrameWidth-1, aPageModelSize.Width())); 422cdf0e10cSrcweir aMapMode.SetScaleY( 423cdf0e10cSrcweir Fraction(rFramePixelSize.Height()-2*nFrameWidth-1, aPageModelSize.Height())); 424cdf0e10cSrcweir aMapMode.SetOrigin(mpPreviewDevice->PixelToLogic(Point(nFrameWidth,nFrameWidth),aMapMode)); 425cdf0e10cSrcweir } 426cdf0e10cSrcweir else 427cdf0e10cSrcweir { 428cdf0e10cSrcweir // We should never get here. 429cdf0e10cSrcweir OSL_ASSERT(false); 430cdf0e10cSrcweir aMapMode.SetScaleX(1.0); 431cdf0e10cSrcweir aMapMode.SetScaleY(1.0); 432cdf0e10cSrcweir } 433cdf0e10cSrcweir mpPreviewDevice->SetMapMode (aMapMode); 434cdf0e10cSrcweir mpPreviewDevice->SetOutputSizePixel(rFramePixelSize); 435cdf0e10cSrcweir } 436cdf0e10cSrcweir 437cdf0e10cSrcweir 438cdf0e10cSrcweir 439cdf0e10cSrcweir 440cdf0e10cSrcweir void PreviewRenderer::ProvideView (DrawDocShell* pDocShell) 441cdf0e10cSrcweir { 442cdf0e10cSrcweir if (pDocShell != mpDocShellOfView) 443cdf0e10cSrcweir { 444cdf0e10cSrcweir // Destroy the view that is connected to the current doc shell. 445cdf0e10cSrcweir mpView.reset (NULL); 446cdf0e10cSrcweir 447cdf0e10cSrcweir // Switch our attention, i.e. listening for DYING events, to 448cdf0e10cSrcweir // the new doc shell. 449cdf0e10cSrcweir if (mpDocShellOfView != NULL) 450cdf0e10cSrcweir EndListening (*mpDocShellOfView); 451cdf0e10cSrcweir mpDocShellOfView = pDocShell; 452cdf0e10cSrcweir if (mpDocShellOfView != NULL) 453cdf0e10cSrcweir StartListening (*mpDocShellOfView); 454cdf0e10cSrcweir } 455cdf0e10cSrcweir if (mpView.get() == NULL) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir mpView.reset (new DrawView (pDocShell, mpPreviewDevice.get(), NULL)); 458cdf0e10cSrcweir } 459cdf0e10cSrcweir mpView->SetPreviewRenderer(true); 460cdf0e10cSrcweir #if 1 461cdf0e10cSrcweir mpView->SetPageVisible(false); 462cdf0e10cSrcweir mpView->SetPageBorderVisible(true); 463cdf0e10cSrcweir mpView->SetBordVisible(false); 464cdf0e10cSrcweir #else 465cdf0e10cSrcweir // This works in the slide sorter but prevents the master page 466cdf0e10cSrcweir // background being painted in the list of current master pages in the 467cdf0e10cSrcweir // task manager. 468cdf0e10cSrcweir mpView->SetPagePaintingAllowed(false); 469cdf0e10cSrcweir #endif 470cdf0e10cSrcweir } 471cdf0e10cSrcweir 472cdf0e10cSrcweir 473cdf0e10cSrcweir 474cdf0e10cSrcweir 475cdf0e10cSrcweir Image PreviewRenderer::ScaleBitmap ( 476cdf0e10cSrcweir const BitmapEx& rBitmapEx, 477cdf0e10cSrcweir int nWidth) 478cdf0e10cSrcweir { 479cdf0e10cSrcweir Image aPreview; 480cdf0e10cSrcweir 481cdf0e10cSrcweir do 482cdf0e10cSrcweir { 483cdf0e10cSrcweir // Adjust contrast mode. 484cdf0e10cSrcweir bool bUseContrast = Application::GetSettings().GetStyleSettings(). 485cdf0e10cSrcweir GetHighContrastMode(); 486cdf0e10cSrcweir mpPreviewDevice->SetDrawMode (bUseContrast 487cdf0e10cSrcweir ? ViewShell::OUTPUT_DRAWMODE_CONTRAST 488cdf0e10cSrcweir : ViewShell::OUTPUT_DRAWMODE_COLOR); 489cdf0e10cSrcweir 490cdf0e10cSrcweir // Set output size. 491cdf0e10cSrcweir Size aSize (rBitmapEx.GetSizePixel()); 492cdf0e10cSrcweir if (aSize.Width() <= 0) 493cdf0e10cSrcweir break; 494cdf0e10cSrcweir Size aFrameSize ( 495cdf0e10cSrcweir nWidth, 496cdf0e10cSrcweir (long)((nWidth*1.0 * aSize.Height()) / aSize.Width() + 0.5)); 497cdf0e10cSrcweir Size aPreviewSize (aFrameSize.Width()-2,aFrameSize.Height()-2); 498cdf0e10cSrcweir MapMode aMapMode (mpPreviewDevice->GetMapMode()); 499cdf0e10cSrcweir aMapMode.SetMapUnit(MAP_PIXEL); 500cdf0e10cSrcweir aMapMode.SetOrigin (Point()); 501cdf0e10cSrcweir aMapMode.SetScaleX (1.0); 502cdf0e10cSrcweir aMapMode.SetScaleY (1.0); 503cdf0e10cSrcweir mpPreviewDevice->SetMapMode (aMapMode); 504cdf0e10cSrcweir mpPreviewDevice->SetOutputSize (aFrameSize); 505cdf0e10cSrcweir 506cdf0e10cSrcweir // Paint a frame arround the preview. 507cdf0e10cSrcweir mpPreviewDevice->SetLineColor (maFrameColor); 508cdf0e10cSrcweir mpPreviewDevice->SetFillColor (); 509cdf0e10cSrcweir mpPreviewDevice->DrawRect (Rectangle(Point(0,0), aFrameSize)); 510cdf0e10cSrcweir 511cdf0e10cSrcweir // Paint the bitmap scaled to the desired width. 512cdf0e10cSrcweir BitmapEx aScaledBitmap (rBitmapEx.GetBitmap()); 513cdf0e10cSrcweir aScaledBitmap.Scale (aPreviewSize, BMP_SCALE_INTERPOLATE); 514cdf0e10cSrcweir mpPreviewDevice->DrawBitmap ( 515cdf0e10cSrcweir Point(1,1), 516cdf0e10cSrcweir aPreviewSize, 517cdf0e10cSrcweir aScaledBitmap.GetBitmap()); 518cdf0e10cSrcweir 519cdf0e10cSrcweir // Get the resulting bitmap. 520cdf0e10cSrcweir aPreview = mpPreviewDevice->GetBitmap (Point(0,0), aFrameSize); 521cdf0e10cSrcweir } 522cdf0e10cSrcweir while (false); 523cdf0e10cSrcweir 524cdf0e10cSrcweir return aPreview; 525cdf0e10cSrcweir } 526cdf0e10cSrcweir 527cdf0e10cSrcweir 528cdf0e10cSrcweir 529cdf0e10cSrcweir 530cdf0e10cSrcweir void PreviewRenderer::Notify(SfxBroadcaster&, const SfxHint& rHint) 531cdf0e10cSrcweir { 532cdf0e10cSrcweir if (rHint.IsA(TYPE(SfxSimpleHint)) 533cdf0e10cSrcweir && mpDocShellOfView != NULL) 534cdf0e10cSrcweir { 535cdf0e10cSrcweir const SfxSimpleHint* pSimpleHint = PTR_CAST(SfxSimpleHint, &rHint); 536cdf0e10cSrcweir if (pSimpleHint != NULL 537cdf0e10cSrcweir && pSimpleHint->GetId() == SFX_HINT_DYING) 538cdf0e10cSrcweir { 539cdf0e10cSrcweir // The doc shell is dying. Our view uses its item pool and 540cdf0e10cSrcweir // has to be destroyed as well. The next call to 541cdf0e10cSrcweir // ProvideView will create a new one (for another 542cdf0e10cSrcweir // doc shell, of course.) 543cdf0e10cSrcweir mpView.reset (NULL); 544cdf0e10cSrcweir mpDocShellOfView = NULL; 545cdf0e10cSrcweir } 546cdf0e10cSrcweir } 547cdf0e10cSrcweir } 548cdf0e10cSrcweir 549cdf0e10cSrcweir 550cdf0e10cSrcweir 551cdf0e10cSrcweir 552cdf0e10cSrcweir //===== ViewRedirector ======================================================== 553cdf0e10cSrcweir 554cdf0e10cSrcweir namespace { 555cdf0e10cSrcweir 556cdf0e10cSrcweir ViewRedirector::ViewRedirector (void) 557cdf0e10cSrcweir { 558cdf0e10cSrcweir } 559cdf0e10cSrcweir 560cdf0e10cSrcweir 561cdf0e10cSrcweir 562cdf0e10cSrcweir 563cdf0e10cSrcweir ViewRedirector::~ViewRedirector (void) 564cdf0e10cSrcweir { 565cdf0e10cSrcweir } 566cdf0e10cSrcweir 567cdf0e10cSrcweir 568cdf0e10cSrcweir 569cdf0e10cSrcweir 570cdf0e10cSrcweir drawinglayer::primitive2d::Primitive2DSequence ViewRedirector::createRedirectedPrimitive2DSequence( 571cdf0e10cSrcweir const sdr::contact::ViewObjectContact& rOriginal, 572cdf0e10cSrcweir const sdr::contact::DisplayInfo& rDisplayInfo) 573cdf0e10cSrcweir { 574cdf0e10cSrcweir SdrObject* pObject = rOriginal.GetViewContact().TryToGetSdrObject(); 575cdf0e10cSrcweir 576cdf0e10cSrcweir if (pObject==NULL || pObject->GetPage() == NULL) 577cdf0e10cSrcweir { 578cdf0e10cSrcweir // not a SdrObject visualisation (maybe e.g. page) or no page 579cdf0e10cSrcweir return sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence( 580cdf0e10cSrcweir rOriginal, 581cdf0e10cSrcweir rDisplayInfo); 582cdf0e10cSrcweir } 583cdf0e10cSrcweir 584cdf0e10cSrcweir const bool bDoCreateGeometry (pObject->GetPage()->checkVisibility( rOriginal, rDisplayInfo, true)); 585cdf0e10cSrcweir 586cdf0e10cSrcweir if ( ! bDoCreateGeometry 587cdf0e10cSrcweir && (pObject->GetObjInventor() != SdrInventor || pObject->GetObjIdentifier() != OBJ_PAGE)) 588cdf0e10cSrcweir { 589cdf0e10cSrcweir return drawinglayer::primitive2d::Primitive2DSequence(); 590cdf0e10cSrcweir } 591cdf0e10cSrcweir 592cdf0e10cSrcweir if (pObject->IsEmptyPresObj()) 593cdf0e10cSrcweir return drawinglayer::primitive2d::Primitive2DSequence(); 594cdf0e10cSrcweir 595cdf0e10cSrcweir return sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence( 596cdf0e10cSrcweir rOriginal, 597cdf0e10cSrcweir rDisplayInfo); 598cdf0e10cSrcweir } 599cdf0e10cSrcweir 600cdf0e10cSrcweir } // end of anonymous namespace 601cdf0e10cSrcweir 602cdf0e10cSrcweir 603cdf0e10cSrcweir } // end of namespace ::sd 604