bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / view / drviews8.cxx
blob17c070993c8ffd30b62833489998e84b4ed609cd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "DrawViewShell.hxx"
22 #include "ViewShellHint.hxx"
24 #include <toolkit/helper/vclunohelper.hxx>
25 #include <sfx2/dispatch.hxx>
26 #include <svx/svxids.hrc>
27 #include <vcl/msgbox.hxx>
28 #include <svx/svddef.hxx>
29 #include <sfx2/bindings.hxx>
30 #include <sfx2/request.hxx>
31 #include <sfx2/viewfrm.hxx>
32 #include <svx/svdograf.hxx>
33 #include <svx/svdpagv.hxx>
35 #include "app.hrc"
36 #include "strings.hrc"
38 #include "sdresid.hxx"
39 #include "Window.hxx"
40 #include "drawview.hxx"
41 #include "zoomlist.hxx"
42 #include <osl/mutex.hxx>
43 #include <tools/helpers.hxx>
44 #include <vcl/svapp.hxx>
46 namespace sd {
48 void DrawViewShell::ScannerEvent( const ::com::sun::star::lang::EventObject& )
50 if( mxScannerManager.is() )
52 const ::com::sun::star::scanner::ScannerContext aContext( mxScannerManager->getAvailableScanners().getConstArray()[ 0 ] );
53 const ::com::sun::star::scanner::ScanError eError = mxScannerManager->getError( aContext );
55 if( ::com::sun::star::scanner::ScanError_ScanErrorNone == eError )
57 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap > xBitmap( mxScannerManager->getBitmap( aContext ) );
59 if( xBitmap.is() )
61 const BitmapEx aScanBmp( VCLUnoHelper::GetBitmap( xBitmap ) );
63 if( !!aScanBmp )
65 const SolarMutexGuard aGuard;
66 SdrPage* pPage = mpDrawView->GetSdrPageView()->GetPage();
67 Size aBmpSize( aScanBmp.GetPrefSize() ), aPageSize( pPage->GetSize() );
68 const MapMode aMap100( MAP_100TH_MM );
70 if( !aBmpSize.Width() || !aBmpSize.Height() )
71 aBmpSize = aScanBmp.GetSizePixel();
73 if( aScanBmp.GetPrefMapMode().GetMapUnit() == MAP_PIXEL )
74 aBmpSize = GetActiveWindow()->PixelToLogic( aBmpSize, aMap100 );
75 else
76 aBmpSize = OutputDevice::LogicToLogic( aBmpSize, aScanBmp.GetPrefMapMode(), aMap100 );
78 aPageSize.Width() -= pPage->GetLftBorder() + pPage->GetRgtBorder();
79 aPageSize.Height() -= pPage->GetUppBorder() + pPage->GetLwrBorder();
81 if( ( ( aBmpSize.Height() > aPageSize.Height() ) || ( aBmpSize.Width() > aPageSize.Width() ) ) && aBmpSize.Height() && aPageSize.Height() )
83 double fGrfWH = (double) aBmpSize.Width() / aBmpSize.Height();
84 double fWinWH = (double) aPageSize.Width() / aPageSize.Height();
86 if( fGrfWH < fWinWH )
88 aBmpSize.Width() = FRound( aPageSize.Height() * fGrfWH );
89 aBmpSize.Height()= aPageSize.Height();
91 else if( fGrfWH > 0.F )
93 aBmpSize.Width() = aPageSize.Width();
94 aBmpSize.Height()= FRound( aPageSize.Width() / fGrfWH );
98 Point aPnt ( ( aPageSize.Width() - aBmpSize.Width() ) >> 1, ( aPageSize.Height() - aBmpSize.Height() ) >> 1 );
99 aPnt += Point( pPage->GetLftBorder(), pPage->GetUppBorder() );
100 Rectangle aRect( aPnt, aBmpSize );
101 SdrGrafObj* pGrafObj = NULL;
102 bool bInsertNewObject = true;
104 if( GetView()->AreObjectsMarked() )
106 const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
108 if( rMarkList.GetMarkCount() == 1 )
110 SdrMark* pMark = rMarkList.GetMark(0);
111 SdrObject* pObj = pMark->GetMarkedSdrObj();
113 if( pObj->ISA( SdrGrafObj ) )
115 pGrafObj = static_cast< SdrGrafObj* >( pObj );
117 if( pGrafObj->IsEmptyPresObj() )
119 bInsertNewObject = false;
120 pGrafObj->SetEmptyPresObj(false);
121 pGrafObj->SetOutlinerParaObject(NULL);
122 pGrafObj->SetGraphic( Graphic( aScanBmp ) );
128 if( bInsertNewObject )
130 pGrafObj = new SdrGrafObj( Graphic( aScanBmp ), aRect );
131 SdrPageView* pPV = GetView()->GetSdrPageView();
132 GetView()->InsertObjectAtView( pGrafObj, *pPV, SdrInsertFlags::SETDEFLAYER );
139 SfxBindings& rBindings = GetViewFrame()->GetBindings();
140 rBindings.Invalidate( SID_TWAIN_SELECT );
141 rBindings.Invalidate( SID_TWAIN_TRANSFER );
144 } // end of namespace sd
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */