cid#1607171 Data race condition
[LibreOffice.git] / sd / source / ui / view / drviews8.cxx
blob0ca9af3e536a000c3dac828ddc31fdc9d5d6ce4c
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 <com/sun/star/scanner/XScannerManager2.hpp>
23 #include <toolkit/helper/vclunohelper.hxx>
24 #include <svx/svxids.hrc>
25 #include <sfx2/bindings.hxx>
26 #include <sfx2/viewfrm.hxx>
27 #include <svx/svdograf.hxx>
28 #include <svx/svdpagv.hxx>
30 #include <Window.hxx>
31 #include <drawview.hxx>
32 #include <tools/helpers.hxx>
33 #include <vcl/svapp.hxx>
35 namespace sd {
37 void DrawViewShell::ScannerEvent()
39 if( mxScannerManager.is() )
41 const css::scanner::ScannerContext aContext( mxScannerManager->getAvailableScanners().getConstArray()[ 0 ] );
42 const css::scanner::ScanError eError = mxScannerManager->getError( aContext );
44 if( css::scanner::ScanError_ScanErrorNone == eError )
46 const css::uno::Reference< css::awt::XBitmap > xBitmap( mxScannerManager->getBitmap( aContext ) );
48 if( xBitmap.is() )
50 const BitmapEx aScanBmp( VCLUnoHelper::GetBitmap( xBitmap ) );
52 if( !aScanBmp.IsEmpty() )
54 const SolarMutexGuard aGuard;
55 SdrPage* pPage = mpDrawView->GetSdrPageView()->GetPage();
56 Size aBmpSize( aScanBmp.GetPrefSize() ), aPageSize( pPage->GetSize() );
57 const MapMode aMap100( MapUnit::Map100thMM );
59 if( !aBmpSize.Width() || !aBmpSize.Height() )
60 aBmpSize = aScanBmp.GetSizePixel();
62 if( aScanBmp.GetPrefMapMode().GetMapUnit() == MapUnit::MapPixel )
63 aBmpSize = GetActiveWindow()->PixelToLogic( aBmpSize, aMap100 );
64 else
65 aBmpSize = OutputDevice::LogicToLogic( aBmpSize, aScanBmp.GetPrefMapMode(), aMap100 );
67 aPageSize.AdjustWidth( -(pPage->GetLeftBorder() + pPage->GetRightBorder()) );
68 aPageSize.AdjustHeight( -(pPage->GetUpperBorder() + pPage->GetLowerBorder()) );
70 if( ( ( aBmpSize.Height() > aPageSize.Height() ) || ( aBmpSize.Width() > aPageSize.Width() ) ) && aBmpSize.Height() && aPageSize.Height() )
72 double fGrfWH = static_cast<double>(aBmpSize.Width()) / aBmpSize.Height();
73 double fWinWH = static_cast<double>(aPageSize.Width()) / aPageSize.Height();
75 if( fGrfWH < fWinWH )
77 aBmpSize.setWidth( basegfx::fround<::tools::Long>( aPageSize.Height() * fGrfWH ) );
78 aBmpSize.setHeight( aPageSize.Height() );
80 else if( fGrfWH > 0.F )
82 aBmpSize.setWidth( aPageSize.Width() );
83 aBmpSize.setHeight( basegfx::fround<::tools::Long>( aPageSize.Width() / fGrfWH ) );
87 Point aPnt ( ( aPageSize.Width() - aBmpSize.Width() ) >> 1, ( aPageSize.Height() - aBmpSize.Height() ) >> 1 );
88 aPnt += Point( pPage->GetLeftBorder(), pPage->GetUpperBorder() );
89 ::tools::Rectangle aRect( aPnt, aBmpSize );
90 bool bInsertNewObject = true;
92 const SdrMarkList& rMarkList = GetView()->GetMarkedObjectList();
93 if( rMarkList.GetMarkCount() != 0 )
96 if( rMarkList.GetMarkCount() == 1 )
98 SdrMark* pMark = rMarkList.GetMark(0);
99 SdrObject* pObj = pMark->GetMarkedSdrObj();
101 if( auto pGrafObj = dynamic_cast< SdrGrafObj *>( pObj ) )
103 if( pGrafObj->IsEmptyPresObj() )
105 bInsertNewObject = false;
106 pGrafObj->SetEmptyPresObj(false);
107 pGrafObj->SetOutlinerParaObject(std::nullopt);
108 pGrafObj->SetGraphic( Graphic( aScanBmp ) );
114 if( bInsertNewObject )
116 rtl::Reference<SdrGrafObj> pGrafObj = new SdrGrafObj(
117 GetView()->getSdrModelFromSdrView(),
118 Graphic(aScanBmp),
119 aRect);
120 SdrPageView* pPV = GetView()->GetSdrPageView();
121 GetView()->InsertObjectAtView( pGrafObj.get(), *pPV, SdrInsertFlags::SETDEFLAYER );
128 SfxBindings& rBindings = GetViewFrame()->GetBindings();
129 rBindings.Invalidate( SID_TWAIN_SELECT );
130 rBindings.Invalidate( SID_TWAIN_TRANSFER );
133 } // end of namespace sd
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */