LibreOffice Module sd (master) 1
drviews8.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <DrawViewShell.hxx>
21
22#include <com/sun/star/scanner/XScannerManager2.hpp>
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>
29
30#include <Window.hxx>
31#include <drawview.hxx>
32#include <tools/helpers.hxx>
33#include <vcl/svapp.hxx>
34
35namespace sd {
36
38{
39 if( mxScannerManager.is() )
40 {
41 const css::scanner::ScannerContext aContext( mxScannerManager->getAvailableScanners().getConstArray()[ 0 ] );
42 const css::scanner::ScanError eError = mxScannerManager->getError( aContext );
43
44 if( css::scanner::ScanError_ScanErrorNone == eError )
45 {
46 const css::uno::Reference< css::awt::XBitmap > xBitmap( mxScannerManager->getBitmap( aContext ) );
47
48 if( xBitmap.is() )
49 {
50 const BitmapEx aScanBmp( VCLUnoHelper::GetBitmap( xBitmap ) );
51
52 if( !aScanBmp.IsEmpty() )
53 {
54 const SolarMutexGuard aGuard;
55 SdrPage* pPage = mpDrawView->GetSdrPageView()->GetPage();
56 Size aBmpSize( aScanBmp.GetPrefSize() ), aPageSize( pPage->GetSize() );
57 const MapMode aMap100( MapUnit::Map100thMM );
58
59 if( !aBmpSize.Width() || !aBmpSize.Height() )
60 aBmpSize = aScanBmp.GetSizePixel();
61
62 if( aScanBmp.GetPrefMapMode().GetMapUnit() == MapUnit::MapPixel )
63 aBmpSize = GetActiveWindow()->PixelToLogic( aBmpSize, aMap100 );
64 else
65 aBmpSize = OutputDevice::LogicToLogic( aBmpSize, aScanBmp.GetPrefMapMode(), aMap100 );
66
67 aPageSize.AdjustWidth( -(pPage->GetLeftBorder() + pPage->GetRightBorder()) );
68 aPageSize.AdjustHeight( -(pPage->GetUpperBorder() + pPage->GetLowerBorder()) );
69
70 if( ( ( aBmpSize.Height() > aPageSize.Height() ) || ( aBmpSize.Width() > aPageSize.Width() ) ) && aBmpSize.Height() && aPageSize.Height() )
71 {
72 double fGrfWH = static_cast<double>(aBmpSize.Width()) / aBmpSize.Height();
73 double fWinWH = static_cast<double>(aPageSize.Width()) / aPageSize.Height();
74
75 if( fGrfWH < fWinWH )
76 {
77 aBmpSize.setWidth( FRound( aPageSize.Height() * fGrfWH ) );
78 aBmpSize.setHeight( aPageSize.Height() );
79 }
80 else if( fGrfWH > 0.F )
81 {
82 aBmpSize.setWidth( aPageSize.Width() );
83 aBmpSize.setHeight( FRound( aPageSize.Width() / fGrfWH ) );
84 }
85 }
86
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;
91
92 if( GetView()->AreObjectsMarked() )
93 {
94 const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
95
96 if( rMarkList.GetMarkCount() == 1 )
97 {
98 SdrMark* pMark = rMarkList.GetMark(0);
99 SdrObject* pObj = pMark->GetMarkedSdrObj();
100
101 if( auto pGrafObj = dynamic_cast< SdrGrafObj *>( pObj ) )
102 {
103 if( pGrafObj->IsEmptyPresObj() )
104 {
105 bInsertNewObject = false;
106 pGrafObj->SetEmptyPresObj(false);
107 pGrafObj->SetOutlinerParaObject(std::nullopt);
108 pGrafObj->SetGraphic( Graphic( aScanBmp ) );
109 }
110 }
111 }
112 }
113
114 if( bInsertNewObject )
115 {
117 GetView()->getSdrModelFromSdrView(),
118 Graphic(aScanBmp),
119 aRect);
121 GetView()->InsertObjectAtView( pGrafObj.get(), *pPV, SdrInsertFlags::SETDEFLAYER );
122 }
123 }
124 }
125 }
126 }
127
128 SfxBindings& rBindings = GetViewFrame()->GetBindings();
129 rBindings.Invalidate( SID_TWAIN_SELECT );
130 rBindings.Invalidate( SID_TWAIN_TRANSFER );
131}
132
133} // end of namespace sd
134
135/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsEmpty() const
const MapMode & GetPrefMapMode() const
const Size & GetPrefSize() const
const Size & GetSizePixel() const
MapUnit GetMapUnit() const
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
bool InsertObjectAtView(SdrObject *pObj, SdrPageView &rPV, SdrInsertFlags nOptions=SdrInsertFlags::NONE)
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
SdrObject * GetMarkedSdrObj() const
void SetEmptyPresObj(bool bEpt)
Size GetSize() const
sal_Int32 GetUpperBorder() const
sal_Int32 GetRightBorder() const
sal_Int32 GetLeftBorder() const
sal_Int32 GetLowerBorder() const
SdrPageView * GetSdrPageView() const
void Invalidate(sal_uInt16 nId)
SfxBindings & GetBindings()
constexpr tools::Long Height() const
tools::Long AdjustHeight(tools::Long n)
tools::Long AdjustWidth(tools::Long n)
constexpr tools::Long Width() const
static BitmapEx GetBitmap(const css::uno::Reference< css::awt::XBitmap > &rxBitmap)
css::uno::Reference< css::scanner::XScannerManager2 > mxScannerManager
std::unique_ptr< DrawView > mpDrawView
void ScannerEvent()
Definition: drviews8.cxx:37
::sd::Window * GetActiveWindow() const
The active window is usually the mpContentWindow.
Definition: ViewShell.hxx:155
::sd::View * GetView() const
Definition: ViewShell.hxx:144
SD_DLLPUBLIC SfxViewFrame * GetViewFrame() const
Definition: viewshel.cxx:118
Point PixelToLogic(const Point &rDevicePt) const
tools::Long FRound(double fVal)