/src/libreoffice/sd/source/ui/view/drviews8.cxx
Line | Count | Source |
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> |
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> |
29 | | |
30 | | #include <Window.hxx> |
31 | | #include <drawview.hxx> |
32 | | #include <tools/helpers.hxx> |
33 | | #include <vcl/svapp.hxx> |
34 | | |
35 | | namespace sd { |
36 | | |
37 | | void DrawViewShell::ScannerEvent() |
38 | 0 | { |
39 | 0 | if( mxScannerManager.is() ) |
40 | 0 | { |
41 | 0 | const css::scanner::ScannerContext aContext( mxScannerManager->getAvailableScanners().getConstArray()[ 0 ] ); |
42 | 0 | const css::scanner::ScanError eError = mxScannerManager->getError( aContext ); |
43 | |
|
44 | 0 | if( css::scanner::ScanError_ScanErrorNone == eError ) |
45 | 0 | { |
46 | 0 | const css::uno::Reference< css::awt::XBitmap > xBitmap( mxScannerManager->getBitmap( aContext ) ); |
47 | |
|
48 | 0 | if( xBitmap.is() ) |
49 | 0 | { |
50 | 0 | const Bitmap aScanBmp( VCLUnoHelper::GetBitmap( xBitmap ) ); |
51 | |
|
52 | 0 | if( !aScanBmp.IsEmpty() ) |
53 | 0 | { |
54 | 0 | const SolarMutexGuard aGuard; |
55 | 0 | SdrPage* pPage = mpDrawView->GetSdrPageView()->GetPage(); |
56 | 0 | Size aBmpSize( aScanBmp.GetPrefSize() ), aPageSize( pPage->GetSize() ); |
57 | 0 | const MapMode aMap100( MapUnit::Map100thMM ); |
58 | |
|
59 | 0 | if( !aBmpSize.Width() || !aBmpSize.Height() ) |
60 | 0 | aBmpSize = aScanBmp.GetSizePixel(); |
61 | |
|
62 | 0 | if( aScanBmp.GetPrefMapMode().GetMapUnit() == MapUnit::MapPixel ) |
63 | 0 | aBmpSize = GetActiveWindow()->PixelToLogic( aBmpSize, aMap100 ); |
64 | 0 | else |
65 | 0 | aBmpSize = OutputDevice::LogicToLogic( aBmpSize, aScanBmp.GetPrefMapMode(), aMap100 ); |
66 | |
|
67 | 0 | aPageSize.AdjustWidth( -(pPage->GetLeftBorder() + pPage->GetRightBorder()) ); |
68 | 0 | aPageSize.AdjustHeight( -(pPage->GetUpperBorder() + pPage->GetLowerBorder()) ); |
69 | |
|
70 | 0 | if( ( ( aBmpSize.Height() > aPageSize.Height() ) || ( aBmpSize.Width() > aPageSize.Width() ) ) && aBmpSize.Height() && aPageSize.Height() ) |
71 | 0 | { |
72 | 0 | double fGrfWH = static_cast<double>(aBmpSize.Width()) / aBmpSize.Height(); |
73 | 0 | double fWinWH = static_cast<double>(aPageSize.Width()) / aPageSize.Height(); |
74 | |
|
75 | 0 | if( fGrfWH < fWinWH ) |
76 | 0 | { |
77 | 0 | aBmpSize.setWidth( basegfx::fround<::tools::Long>( aPageSize.Height() * fGrfWH ) ); |
78 | 0 | aBmpSize.setHeight( aPageSize.Height() ); |
79 | 0 | } |
80 | 0 | else if( fGrfWH > 0.F ) |
81 | 0 | { |
82 | 0 | aBmpSize.setWidth( aPageSize.Width() ); |
83 | 0 | aBmpSize.setHeight( basegfx::fround<::tools::Long>( aPageSize.Width() / fGrfWH ) ); |
84 | 0 | } |
85 | 0 | } |
86 | |
|
87 | 0 | Point aPnt ( ( aPageSize.Width() - aBmpSize.Width() ) >> 1, ( aPageSize.Height() - aBmpSize.Height() ) >> 1 ); |
88 | 0 | aPnt += Point( pPage->GetLeftBorder(), pPage->GetUpperBorder() ); |
89 | 0 | ::tools::Rectangle aRect( aPnt, aBmpSize ); |
90 | 0 | bool bInsertNewObject = true; |
91 | |
|
92 | 0 | const SdrMarkList& rMarkList = GetView()->GetMarkedObjectList(); |
93 | 0 | if( rMarkList.GetMarkCount() != 0 ) |
94 | 0 | { |
95 | |
|
96 | 0 | if( rMarkList.GetMarkCount() == 1 ) |
97 | 0 | { |
98 | 0 | SdrMark* pMark = rMarkList.GetMark(0); |
99 | 0 | SdrObject* pObj = pMark->GetMarkedSdrObj(); |
100 | |
|
101 | 0 | if( auto pGrafObj = dynamic_cast< SdrGrafObj *>( pObj ) ) |
102 | 0 | { |
103 | 0 | if( pGrafObj->IsEmptyPresObj() ) |
104 | 0 | { |
105 | 0 | bInsertNewObject = false; |
106 | 0 | pGrafObj->SetEmptyPresObj(false); |
107 | 0 | pGrafObj->SetOutlinerParaObject(std::nullopt); |
108 | 0 | pGrafObj->SetGraphic( Graphic( aScanBmp ) ); |
109 | 0 | } |
110 | 0 | } |
111 | 0 | } |
112 | 0 | } |
113 | |
|
114 | 0 | if( bInsertNewObject ) |
115 | 0 | { |
116 | 0 | rtl::Reference<SdrGrafObj> pGrafObj = new SdrGrafObj( |
117 | 0 | GetView()->getSdrModelFromSdrView(), |
118 | 0 | Graphic(aScanBmp), |
119 | 0 | aRect); |
120 | 0 | SdrPageView* pPV = GetView()->GetSdrPageView(); |
121 | 0 | GetView()->InsertObjectAtView( pGrafObj.get(), *pPV, SdrInsertFlags::SETDEFLAYER ); |
122 | 0 | } |
123 | 0 | } |
124 | 0 | } |
125 | 0 | } |
126 | 0 | } |
127 | |
|
128 | 0 | SfxBindings& rBindings = GetViewFrame()->GetBindings(); |
129 | 0 | rBindings.Invalidate( SID_TWAIN_SELECT ); |
130 | 0 | rBindings.Invalidate( SID_TWAIN_TRANSFER ); |
131 | 0 | } |
132 | | |
133 | | } // end of namespace sd |
134 | | |
135 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |