1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <editeng/outlobj.hxx>
24 #include <toolkit/helper/vclunohelper.hxx>
25 #include <svx/svxids.hrc>
26 #include <sfx2/bindings.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <svx/svdograf.hxx>
29 #include <svx/svdpagv.hxx>
32 #include <drawview.hxx>
33 #include <tools/helpers.hxx>
34 #include <vcl/svapp.hxx>
38 void DrawViewShell::ScannerEvent()
40 if( mxScannerManager
.is() )
42 const css::scanner::ScannerContext
aContext( mxScannerManager
->getAvailableScanners().getConstArray()[ 0 ] );
43 const css::scanner::ScanError eError
= mxScannerManager
->getError( aContext
);
45 if( css::scanner::ScanError_ScanErrorNone
== eError
)
47 const css::uno::Reference
< css::awt::XBitmap
> xBitmap( mxScannerManager
->getBitmap( aContext
) );
51 const BitmapEx
aScanBmp( VCLUnoHelper::GetBitmap( xBitmap
) );
55 const SolarMutexGuard aGuard
;
56 SdrPage
* pPage
= mpDrawView
->GetSdrPageView()->GetPage();
57 Size
aBmpSize( aScanBmp
.GetPrefSize() ), aPageSize( pPage
->GetSize() );
58 const MapMode
aMap100( MapUnit::Map100thMM
);
60 if( !aBmpSize
.Width() || !aBmpSize
.Height() )
61 aBmpSize
= aScanBmp
.GetSizePixel();
63 if( aScanBmp
.GetPrefMapMode().GetMapUnit() == MapUnit::MapPixel
)
64 aBmpSize
= GetActiveWindow()->PixelToLogic( aBmpSize
, aMap100
);
66 aBmpSize
= OutputDevice::LogicToLogic( aBmpSize
, aScanBmp
.GetPrefMapMode(), aMap100
);
68 aPageSize
.AdjustWidth( -(pPage
->GetLeftBorder() + pPage
->GetRightBorder()) );
69 aPageSize
.AdjustHeight( -(pPage
->GetUpperBorder() + pPage
->GetLowerBorder()) );
71 if( ( ( aBmpSize
.Height() > aPageSize
.Height() ) || ( aBmpSize
.Width() > aPageSize
.Width() ) ) && aBmpSize
.Height() && aPageSize
.Height() )
73 double fGrfWH
= static_cast<double>(aBmpSize
.Width()) / aBmpSize
.Height();
74 double fWinWH
= static_cast<double>(aPageSize
.Width()) / aPageSize
.Height();
78 aBmpSize
.setWidth( FRound( aPageSize
.Height() * fGrfWH
) );
79 aBmpSize
.setHeight( aPageSize
.Height() );
81 else if( fGrfWH
> 0.F
)
83 aBmpSize
.setWidth( aPageSize
.Width() );
84 aBmpSize
.setHeight( FRound( aPageSize
.Width() / fGrfWH
) );
88 Point
aPnt ( ( aPageSize
.Width() - aBmpSize
.Width() ) >> 1, ( aPageSize
.Height() - aBmpSize
.Height() ) >> 1 );
89 aPnt
+= Point( pPage
->GetLeftBorder(), pPage
->GetUpperBorder() );
90 ::tools::Rectangle
aRect( aPnt
, aBmpSize
);
91 bool bInsertNewObject
= true;
93 if( GetView()->AreObjectsMarked() )
95 const SdrMarkList
& rMarkList
= mpDrawView
->GetMarkedObjectList();
97 if( rMarkList
.GetMarkCount() == 1 )
99 SdrMark
* pMark
= rMarkList
.GetMark(0);
100 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
102 if( auto pGrafObj
= dynamic_cast< SdrGrafObj
*>( pObj
) )
104 if( pGrafObj
->IsEmptyPresObj() )
106 bInsertNewObject
= false;
107 pGrafObj
->SetEmptyPresObj(false);
108 pGrafObj
->SetOutlinerParaObject(nullptr);
109 pGrafObj
->SetGraphic( Graphic( aScanBmp
) );
115 if( bInsertNewObject
)
117 auto pGrafObj
= new SdrGrafObj(
118 GetView()->getSdrModelFromSdrView(),
121 SdrPageView
* pPV
= GetView()->GetSdrPageView();
122 GetView()->InsertObjectAtView( pGrafObj
, *pPV
, SdrInsertFlags::SETDEFLAYER
);
129 SfxBindings
& rBindings
= GetViewFrame()->GetBindings();
130 rBindings
.Invalidate( SID_TWAIN_SELECT
);
131 rBindings
.Invalidate( SID_TWAIN_TRANSFER
);
134 } // end of namespace sd
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */