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 .
21 #include "DrawViewShell.hxx"
23 #include "ViewShellHint.hxx"
25 #include <toolkit/unohlp.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <svx/svxids.hrc>
28 #include <vcl/msgbox.hxx>
29 #include <svx/svddef.hxx>
30 #include <sfx2/bindings.hxx>
31 #include <sfx2/request.hxx>
32 #include <sfx2/viewfrm.hxx>
33 #include <svx/svdograf.hxx>
34 #include <svx/svdpagv.hxx>
37 #include "strings.hrc"
39 #include "sdresid.hxx"
41 #include "drawview.hxx"
42 #include "zoomlist.hxx"
43 #include <osl/mutex.hxx>
44 #include <tools/helpers.hxx>
45 #include <vcl/svapp.hxx>
49 void DrawViewShell::ScannerEvent( const ::com::sun::star::lang::EventObject
& )
51 if( mxScannerManager
.is() )
53 const ::com::sun::star::scanner::ScannerContext
aContext( mxScannerManager
->getAvailableScanners().getConstArray()[ 0 ] );
54 const ::com::sun::star::scanner::ScanError eError
= mxScannerManager
->getError( aContext
);
56 if( ::com::sun::star::scanner::ScanError_ScanErrorNone
== eError
)
58 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XBitmap
> xBitmap( mxScannerManager
->getBitmap( aContext
) );
62 const BitmapEx
aScanBmp( VCLUnoHelper::GetBitmap( xBitmap
) );
66 const SolarMutexGuard aGuard
;
67 SdrPage
* pPage
= mpDrawView
->GetSdrPageView()->GetPage();
68 Size
aBmpSize( aScanBmp
.GetPrefSize() ), aPageSize( pPage
->GetSize() );
69 const MapMode
aMap100( MAP_100TH_MM
);
71 if( !aBmpSize
.Width() || !aBmpSize
.Height() )
72 aBmpSize
= aScanBmp
.GetSizePixel();
74 if( aScanBmp
.GetPrefMapMode().GetMapUnit() == MAP_PIXEL
)
75 aBmpSize
= GetActiveWindow()->PixelToLogic( aBmpSize
, aMap100
);
77 aBmpSize
= OutputDevice::LogicToLogic( aBmpSize
, aScanBmp
.GetPrefMapMode(), aMap100
);
79 aPageSize
.Width() -= pPage
->GetLftBorder() + pPage
->GetRgtBorder();
80 aPageSize
.Height() -= pPage
->GetUppBorder() + pPage
->GetLwrBorder();
82 if( ( ( aBmpSize
.Height() > aPageSize
.Height() ) || ( aBmpSize
.Width() > aPageSize
.Width() ) ) && aBmpSize
.Height() && aPageSize
.Height() )
84 double fGrfWH
= (double) aBmpSize
.Width() / aBmpSize
.Height();
85 double fWinWH
= (double) aPageSize
.Width() / aPageSize
.Height();
89 aBmpSize
.Width() = FRound( aPageSize
.Height() * fGrfWH
);
90 aBmpSize
.Height()= aPageSize
.Height();
92 else if( fGrfWH
> 0.F
)
94 aBmpSize
.Width() = aPageSize
.Width();
95 aBmpSize
.Height()= FRound( aPageSize
.Width() / fGrfWH
);
99 Point
aPnt ( ( aPageSize
.Width() - aBmpSize
.Width() ) >> 1, ( aPageSize
.Height() - aBmpSize
.Height() ) >> 1 );
100 aPnt
+= Point( pPage
->GetLftBorder(), pPage
->GetUppBorder() );
101 Rectangle
aRect( aPnt
, aBmpSize
);
102 SdrGrafObj
* pGrafObj
= NULL
;
103 sal_Bool bInsertNewObject
= sal_True
;
105 if( GetView()->AreObjectsMarked() )
107 const SdrMarkList
& rMarkList
= mpDrawView
->GetMarkedObjectList();
109 if( rMarkList
.GetMarkCount() == 1 )
111 SdrMark
* pMark
= rMarkList
.GetMark(0);
112 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
114 if( pObj
->ISA( SdrGrafObj
) )
116 pGrafObj
= static_cast< SdrGrafObj
* >( pObj
);
118 if( pGrafObj
->IsEmptyPresObj() )
120 bInsertNewObject
= sal_False
;
121 pGrafObj
->SetEmptyPresObj(sal_False
);
122 pGrafObj
->SetOutlinerParaObject(NULL
);
123 pGrafObj
->SetGraphic( Graphic( aScanBmp
) );
129 if( bInsertNewObject
)
131 pGrafObj
= new SdrGrafObj( Graphic( aScanBmp
), aRect
);
132 SdrPageView
* pPV
= GetView()->GetSdrPageView();
133 GetView()->InsertObjectAtView( pGrafObj
, *pPV
, SDRINSERT_SETDEFLAYER
);
140 SfxBindings
& rBindings
= GetViewFrame()->GetBindings();
141 rBindings
.Invalidate( SID_TWAIN_SELECT
);
142 rBindings
.Invalidate( SID_TWAIN_TRANSFER
);
145 } // end of namespace sd
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */