/src/libreoffice/sfx2/source/doc/objembed.cxx
Line | Count | Source (jump to first uncovered line) |
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 <sfx2/objsh.hxx> |
21 | | #include <sfx2/app.hxx> |
22 | | #include <objshimp.hxx> |
23 | | #include <sfx2/event.hxx> |
24 | | #include <sfx2/sfxbasemodel.hxx> |
25 | | |
26 | | #include <comphelper/fileformat.h> |
27 | | #include <tools/fract.hxx> |
28 | | #include <vcl/transfer.hxx> |
29 | | #include <vcl/outdev.hxx> |
30 | | #include <vcl/gdimtf.hxx> |
31 | | |
32 | | using namespace ::com::sun::star; |
33 | | |
34 | | |
35 | | Printer* SfxObjectShell::GetDocumentPrinter() |
36 | 8.34k | { |
37 | 8.34k | SfxObjectShell* pParent = GetParentShell(GetModel()); |
38 | 8.34k | if ( pParent ) |
39 | 0 | return pParent->GetDocumentPrinter(); |
40 | 8.34k | return nullptr; |
41 | 8.34k | } |
42 | | |
43 | | |
44 | | OutputDevice* SfxObjectShell::GetDocumentRefDev() |
45 | 4.17k | { |
46 | 4.17k | SfxObjectShell* pParent = GetParentShell(GetModel()); |
47 | 4.17k | if ( pParent ) |
48 | 0 | return pParent->GetDocumentRefDev(); |
49 | 4.17k | return nullptr; |
50 | 4.17k | } |
51 | | |
52 | | |
53 | | void SfxObjectShell::OnDocumentPrinterChanged( Printer* /*pNewPrinter*/ ) |
54 | 0 | { |
55 | | // virtual method |
56 | 0 | } |
57 | | |
58 | | |
59 | | tools::Rectangle SfxObjectShell::GetVisArea( sal_uInt16 nAspect ) const |
60 | 28.6k | { |
61 | 28.6k | if( nAspect == ASPECT_CONTENT ) |
62 | 28.6k | return pImpl->m_aVisArea; |
63 | 0 | else if( nAspect == ASPECT_THUMBNAIL ) |
64 | 0 | { |
65 | 0 | tools::Rectangle aRect; |
66 | 0 | aRect.SetSize( OutputDevice::LogicToLogic( Size( 5000, 5000 ), |
67 | 0 | MapMode(MapUnit::Map100thMM), MapMode(GetMapUnit()))); |
68 | 0 | return aRect; |
69 | 0 | } |
70 | 0 | return tools::Rectangle(); |
71 | 28.6k | } |
72 | | |
73 | | |
74 | | const tools::Rectangle& SfxObjectShell::GetVisArea() const |
75 | 14.8k | { |
76 | 14.8k | pImpl->m_aVisArea = GetVisArea( ASPECT_CONTENT ); |
77 | 14.8k | return pImpl->m_aVisArea; |
78 | 14.8k | } |
79 | | |
80 | | |
81 | | void SfxObjectShell::SetVisArea( const tools::Rectangle & rVisArea ) |
82 | 173k | { |
83 | 173k | if( pImpl->m_aVisArea != rVisArea ) |
84 | 159k | { |
85 | 159k | pImpl->m_aVisArea = rVisArea; |
86 | 159k | if ( GetCreateMode() == SfxObjectCreateMode::EMBEDDED ) |
87 | 154k | { |
88 | 154k | if (IsEnableSetModified() |
89 | | // Base forms use EMBEDDED but they actually live in their own |
90 | | // frame - resizing that shouldn't set it to modified. |
91 | 154k | && pImpl->pBaseModel |
92 | 154k | && pImpl->pBaseModel->getIdentifier() != "com.sun.star.sdb.FormDesign") |
93 | 114k | { |
94 | 114k | SetModified(); |
95 | 114k | } |
96 | | |
97 | 154k | SfxGetpApp()->NotifyEvent(SfxEventHint( SfxEventHintId::VisAreaChanged, GlobalEventConfig::GetEventName(GlobalEventId::VISAREACHANGED), this)); |
98 | 154k | } |
99 | 159k | } |
100 | 173k | } |
101 | | |
102 | | |
103 | | void SfxObjectShell::SetVisAreaSize( const Size & rVisSize ) |
104 | 4.16k | { |
105 | 4.16k | SetVisArea( tools::Rectangle( GetVisArea().TopLeft(), rVisSize ) ); |
106 | 4.16k | } |
107 | | |
108 | | |
109 | | MapUnit SfxObjectShell::GetMapUnit() const |
110 | 25.0k | { |
111 | 25.0k | return pImpl->m_nMapUnit; |
112 | 25.0k | } |
113 | | |
114 | | |
115 | | void SfxObjectShell::SetMapUnit( MapUnit nMapUnit ) |
116 | 122k | { |
117 | 122k | pImpl->m_nMapUnit = nMapUnit; |
118 | 122k | } |
119 | | |
120 | | |
121 | | void SfxObjectShell::FillTransferableObjectDescriptor( TransferableObjectDescriptor& rDesc ) const |
122 | 0 | { |
123 | 0 | SotClipboardFormatId nClipFormat; |
124 | 0 | FillClass( &rDesc.maClassName, &nClipFormat, &rDesc.maTypeName, SOFFICE_FILEFORMAT_CURRENT ); |
125 | |
|
126 | 0 | rDesc.mnViewAspect = ASPECT_CONTENT; |
127 | 0 | rDesc.maSize = OutputDevice::LogicToLogic(GetVisArea().GetSize(), MapMode(GetMapUnit()), MapMode(MapUnit::Map100thMM)); |
128 | 0 | rDesc.maDragStartPos = Point(); |
129 | 0 | rDesc.maDisplayName.clear(); |
130 | 0 | } |
131 | | |
132 | | void SfxObjectShell::DoDraw( OutputDevice* pDev, |
133 | | const Point & rObjPos, |
134 | | const Size & rSize, |
135 | | const JobSetup & rSetup, |
136 | | sal_uInt16 nAspect, |
137 | | bool bOutputForScreen ) |
138 | 0 | { |
139 | 0 | if (!rSize.Width() || !rSize.Height()) |
140 | 0 | return; |
141 | | |
142 | 0 | MapMode aMod = pDev->GetMapMode(); |
143 | 0 | Size aSize = GetVisArea( nAspect ).GetSize(); |
144 | 0 | MapMode aWilliMode( GetMapUnit() ); |
145 | 0 | aSize = pDev->LogicToLogic( aSize, &aWilliMode, &aMod ); |
146 | 0 | if( aSize.Width() && aSize.Height() ) |
147 | 0 | { |
148 | 0 | Fraction aXF( rSize.Width(), aSize.Width() ); |
149 | 0 | Fraction aYF( rSize.Height(), aSize.Height() ); |
150 | |
|
151 | 0 | DoDraw_Impl(pDev, rObjPos, aXF, aYF, rSetup, nAspect, bOutputForScreen); |
152 | 0 | } |
153 | 0 | } |
154 | | |
155 | | void SfxObjectShell::DoDraw_Impl( OutputDevice* pDev, |
156 | | const Point & rViewPos, |
157 | | const Fraction & rScaleX, |
158 | | const Fraction & rScaleY, |
159 | | const JobSetup & rSetup, |
160 | | sal_uInt16 nAspect, |
161 | | bool bOutputForScreen ) |
162 | 0 | { |
163 | 0 | tools::Rectangle aVisArea = GetVisArea( nAspect ); |
164 | | // MapUnit of the target |
165 | 0 | MapMode aMapMode( GetMapUnit() ); |
166 | 0 | aMapMode.SetScaleX( rScaleX ); |
167 | 0 | aMapMode.SetScaleY( rScaleY ); |
168 | | |
169 | | // Target in Pixels |
170 | 0 | Point aOrg = pDev->LogicToLogic( rViewPos, nullptr, &aMapMode ); |
171 | 0 | Point aDelta = aOrg - aVisArea.TopLeft(); |
172 | | |
173 | | // Origin moved according to the viewable area |
174 | | // Origin set with Scale |
175 | 0 | aMapMode.SetOrigin( aDelta ); |
176 | | |
177 | | // Secure the Device settings |
178 | 0 | pDev->Push(); |
179 | |
|
180 | 0 | vcl::Region aRegion; |
181 | 0 | if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER ) |
182 | 0 | { |
183 | 0 | aRegion = pDev->GetClipRegion(); |
184 | 0 | aRegion = pDev->LogicToPixel( aRegion ); |
185 | 0 | } |
186 | 0 | pDev->SetRelativeMapMode( aMapMode ); |
187 | |
|
188 | 0 | GDIMetaFile * pMtf = pDev->GetConnectMetaFile(); |
189 | 0 | if( pMtf ) |
190 | 0 | { |
191 | 0 | if( pMtf->IsRecord() && pDev->GetOutDevType() != OUTDEV_PRINTER ) |
192 | 0 | pMtf->Stop(); |
193 | 0 | else |
194 | 0 | pMtf = nullptr; |
195 | 0 | } |
196 | 0 | if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER ) |
197 | 0 | { |
198 | 0 | aRegion = pDev->PixelToLogic( aRegion ); |
199 | 0 | pDev->SetClipRegion( aRegion ); |
200 | 0 | } |
201 | 0 | if( pMtf ) |
202 | 0 | pMtf->Record( pDev ); |
203 | |
|
204 | 0 | Draw( pDev, rSetup, nAspect, bOutputForScreen ); |
205 | | |
206 | | // Restore Device settings |
207 | 0 | pDev->Pop(); |
208 | |
|
209 | 0 | } |
210 | | |
211 | | comphelper::EmbeddedObjectContainer& SfxObjectShell::GetEmbeddedObjectContainer() const |
212 | 182k | { |
213 | 182k | if ( !pImpl->mxObjectContainer ) |
214 | 66.9k | pImpl->mxObjectContainer.reset(new comphelper::EmbeddedObjectContainer( const_cast<SfxObjectShell*>(this)->GetStorage(), GetModel() )); |
215 | 182k | return *pImpl->mxObjectContainer; |
216 | 182k | } |
217 | | |
218 | | void SfxObjectShell::ClearEmbeddedObjects() |
219 | 0 | { |
220 | | // frees all space taken by embedded objects |
221 | 0 | pImpl->mxObjectContainer.reset(); |
222 | 0 | } |
223 | | |
224 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |