Line data Source code
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 <svx/svdmodel.hxx>
21 : #include <svx/svdpage.hxx>
22 : #include <swmodule.hxx>
23 : #include <svtools/accessibilityoptions.hxx>
24 : #include <svx/svdpagv.hxx>
25 : #include <fmtanchr.hxx>
26 : #include <frmfmt.hxx>
27 :
28 : #include <svx/svdoutl.hxx>
29 :
30 : #include "drawdoc.hxx"
31 : #include "fesh.hxx"
32 : #include "pagefrm.hxx"
33 : #include "rootfrm.hxx"
34 : #include "viewimp.hxx"
35 : #include "dflyobj.hxx"
36 : #include "viewopt.hxx"
37 : #include "printdata.hxx"
38 : #include "dcontact.hxx"
39 : #include "dview.hxx"
40 : #include "flyfrm.hxx"
41 : #include <vcl/svapp.hxx>
42 : #include <vcl/settings.hxx>
43 :
44 : #include <IDocumentDrawModelAccess.hxx>
45 :
46 123882 : void SwViewImp::StartAction()
47 : {
48 123882 : if ( HasDrawView() )
49 : {
50 123882 : SET_CURR_SHELL( GetShell() );
51 123882 : if ( pSh->ISA(SwFEShell) )
52 123882 : ((SwFEShell*)pSh)->HideChainMarker(); // might have changed
53 : }
54 123882 : }
55 :
56 73477 : void SwViewImp::EndAction()
57 : {
58 73477 : if ( HasDrawView() )
59 : {
60 73477 : SET_CURR_SHELL( GetShell() );
61 73477 : if ( pSh->ISA(SwFEShell) )
62 73477 : ((SwFEShell*)pSh)->SetChainMarker(); // might have changed
63 : }
64 73477 : }
65 :
66 24666 : void SwViewImp::LockPaint()
67 : {
68 24666 : if ( HasDrawView() )
69 : {
70 24666 : bResetHdlHiddenPaint = !GetDrawView()->areMarkHandlesHidden();
71 24666 : GetDrawView()->hideMarkHandles();
72 : }
73 : else
74 : {
75 0 : bResetHdlHiddenPaint = false;
76 : }
77 24666 : }
78 :
79 24666 : void SwViewImp::UnlockPaint()
80 : {
81 24666 : if ( bResetHdlHiddenPaint )
82 24666 : GetDrawView()->showMarkHandles();
83 24666 : }
84 :
85 25552 : void SwViewImp::PaintLayer( const SdrLayerID _nLayerID,
86 : SwPrintData const*const pPrintData,
87 : const SwRect& aPaintRect,
88 : const Color* _pPageBackgrdColor,
89 : const bool _bIsPageRightToLeft,
90 : sdr::contact::ViewObjectContactRedirector* pRedirector ) const
91 : {
92 25552 : if ( HasDrawView() )
93 : {
94 : //change the draw mode in high contrast mode
95 25552 : OutputDevice* pOutDev = GetShell()->GetOut();
96 25552 : sal_uLong nOldDrawMode = pOutDev->GetDrawMode();
97 75436 : if( GetShell()->GetWin() &&
98 25552 : Application::GetSettings().GetStyleSettings().GetHighContrastMode() &&
99 0 : (!GetShell()->IsPreview()||SW_MOD()->GetAccessibilityOptions().GetIsForPagePreviews()))
100 : {
101 : pOutDev->SetDrawMode( nOldDrawMode | DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL |
102 0 : DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT );
103 : }
104 :
105 : // For correct handling of accessibility, high contrast, the
106 : // page background color is set as the background color at the
107 : // outliner of the draw view. Only necessary for the layers
108 : // hell and heaven
109 25552 : Color aOldOutlinerBackgrdColor;
110 : // set default horizontal text direction on painting <hell> or
111 : // <heaven>.
112 25552 : EEHorizontalTextDirection aOldEEHoriTextDir = EE_HTEXTDIR_L2R;
113 25552 : const IDocumentDrawModelAccess* pIDDMA = GetShell()->getIDocumentDrawModelAccess();
114 38328 : if ( (_nLayerID == pIDDMA->GetHellId()) ||
115 12776 : (_nLayerID == pIDDMA->GetHeavenId()) )
116 : {
117 : OSL_ENSURE( _pPageBackgrdColor,
118 : "incorrect usage of SwViewImp::PaintLayer: pPageBackgrdColor have to be set for painting layer <hell> or <heaven>");
119 25552 : if ( _pPageBackgrdColor )
120 : {
121 : aOldOutlinerBackgrdColor =
122 25552 : GetDrawView()->GetModel()->GetDrawOutliner().GetBackgroundColor();
123 25552 : GetDrawView()->GetModel()->GetDrawOutliner().SetBackgroundColor( *_pPageBackgrdColor );
124 : }
125 :
126 : aOldEEHoriTextDir =
127 25552 : GetDrawView()->GetModel()->GetDrawOutliner().GetDefaultHorizontalTextDirection();
128 : EEHorizontalTextDirection aEEHoriTextDirOfPage =
129 25552 : _bIsPageRightToLeft ? EE_HTEXTDIR_R2L : EE_HTEXTDIR_L2R;
130 25552 : GetDrawView()->GetModel()->GetDrawOutliner().SetDefaultHorizontalTextDirection( aEEHoriTextDirOfPage );
131 : }
132 :
133 25552 : pOutDev->Push( PushFlags::LINECOLOR ); // #114231#
134 25552 : if (pPrintData)
135 : {
136 : // hide drawings but not form controls (form controls are handled elsewhere)
137 0 : SdrView &rSdrView = const_cast< SdrView & >(GetPageView()->GetView());
138 0 : rSdrView.setHideDraw( !pPrintData->IsPrintDraw() );
139 : }
140 25552 : GetPageView()->DrawLayer( _nLayerID, pOutDev, pRedirector, aPaintRect.SVRect() );
141 25552 : pOutDev->Pop();
142 :
143 : // reset background color of the outliner & default horiz. text dir.
144 38328 : if ( (_nLayerID == pIDDMA->GetHellId()) ||
145 12776 : (_nLayerID == pIDDMA->GetHeavenId()) )
146 : {
147 25552 : GetDrawView()->GetModel()->GetDrawOutliner().SetBackgroundColor( aOldOutlinerBackgrdColor );
148 25552 : GetDrawView()->GetModel()->GetDrawOutliner().SetDefaultHorizontalTextDirection( aOldEEHoriTextDir );
149 : }
150 :
151 25552 : pOutDev->SetDrawMode( nOldDrawMode );
152 : }
153 25552 : }
154 :
155 : #define FUZZY_EDGE 400
156 :
157 0 : bool SwViewImp::IsDragPossible( const Point &rPoint )
158 : {
159 0 : if ( !HasDrawView() )
160 0 : return false;
161 :
162 0 : const SdrMarkList &rMrkList = GetDrawView()->GetMarkedObjectList();
163 :
164 0 : if( !rMrkList.GetMarkCount() )
165 0 : return false;
166 :
167 0 : SdrObject *pO = rMrkList.GetMark(rMrkList.GetMarkCount()-1)->GetMarkedSdrObj();
168 :
169 0 : SwRect aRect;
170 0 : if( pO && ::CalcClipRect( pO, aRect, false ) )
171 : {
172 0 : SwRect aTmp;
173 0 : ::CalcClipRect( pO, aTmp, true );
174 0 : aRect.Union( aTmp );
175 : }
176 : else
177 0 : aRect = GetShell()->GetLayout()->Frm();
178 :
179 0 : aRect.Top( aRect.Top() - FUZZY_EDGE );
180 0 : aRect.Bottom( aRect.Bottom() + FUZZY_EDGE );
181 0 : aRect.Left( aRect.Left() - FUZZY_EDGE );
182 0 : aRect.Right( aRect.Right() + FUZZY_EDGE );
183 0 : return aRect.IsInside( rPoint );
184 : }
185 :
186 8274 : void SwViewImp::NotifySizeChg( const Size &rNewSz )
187 : {
188 8274 : if ( !HasDrawView() )
189 14698 : return;
190 :
191 1324 : if ( GetPageView() )
192 1324 : GetPageView()->GetPage()->SetSize( rNewSz );
193 :
194 : // Limitation of the work area
195 1324 : const Rectangle aDocRect( Point( DOCUMENTBORDER, DOCUMENTBORDER ), rNewSz );
196 1324 : const Rectangle &rOldWork = GetDrawView()->GetWorkArea();
197 1324 : bool bCheckDrawObjs = false;
198 1324 : if ( aDocRect != rOldWork )
199 : {
200 1288 : if ( rOldWork.Bottom() > aDocRect.Bottom() || rOldWork.Right() > aDocRect.Right())
201 526 : bCheckDrawObjs = true;
202 1288 : GetDrawView()->SetWorkArea( aDocRect );
203 : }
204 1324 : if ( !bCheckDrawObjs )
205 798 : return;
206 :
207 : OSL_ENSURE( pSh->getIDocumentDrawModelAccess()->GetDrawModel(), "NotifySizeChg without DrawModel" );
208 526 : SdrPage* pPage = pSh->getIDocumentDrawModelAccess()->GetDrawModel()->GetPage( 0 );
209 526 : const size_t nObjs = pPage->GetObjCount();
210 5228 : for( size_t nObj = 0; nObj < nObjs; ++nObj )
211 : {
212 4702 : SdrObject *pObj = pPage->GetObj( nObj );
213 4702 : if( !pObj->ISA(SwVirtFlyDrawObj) )
214 : {
215 : // Objects not anchored to the frame, do not need to be adjusted
216 1572 : const SwContact *pCont = (SwContact*)GetUserCall(pObj);
217 : // this function might be called by the InsertDocument, when
218 : // a PageDesc-Attribute is set on a node. Then the SdrObject
219 : // must not have an UserCall.
220 1572 : if( !pCont || !pCont->ISA(SwDrawContact) )
221 1598 : continue;
222 :
223 1436 : const SwFrm *pAnchor = ((SwDrawContact*)pCont)->GetAnchorFrm();
224 4176 : if ( !pAnchor || pAnchor->IsInFly() || !pAnchor->IsValid() ||
225 5462 : !pAnchor->GetUpper() || !pAnchor->FindPageFrm() ||
226 1340 : (FLY_AS_CHAR == pCont->GetFmt()->GetAnchor().GetAnchorId()) )
227 : {
228 102 : continue;
229 : }
230 : else
231 : {
232 : // Actually this should never happen but currently layouting
233 : // is broken. So don't move anchors, if the page is invalid.
234 : // This should be turned into an DBG_ASSERT, once layouting is fixed!
235 1334 : const SwPageFrm *pPageFrm = pAnchor->FindPageFrm();
236 1334 : if (!pPageFrm || pPageFrm->IsInvalid() ) {
237 : SAL_WARN( "sw.resizeview", "Trying to move anchor from invalid page - fix layouting!" );
238 56 : continue;
239 : }
240 : }
241 :
242 : // no move for drawing objects in header/footer
243 1278 : if ( pAnchor->FindFooterOrHeader() )
244 : {
245 1168 : continue;
246 : }
247 :
248 110 : const Rectangle aObjBound( pObj->GetCurrentBoundRect() );
249 110 : if ( !aDocRect.IsInside( aObjBound ) )
250 : {
251 22 : Size aSz;
252 22 : if ( aObjBound.Left() > aDocRect.Right() )
253 0 : aSz.Width() = (aDocRect.Right() - aObjBound.Left()) - MINFLY;
254 22 : if ( aObjBound.Top() > aDocRect.Bottom() )
255 0 : aSz.Height() = (aDocRect.Bottom() - aObjBound.Top()) - MINFLY;
256 22 : if ( aSz.Width() || aSz.Height() )
257 0 : pObj->Move( aSz );
258 :
259 : // Don't let large objects dissappear to the top
260 22 : aSz.Width() = aSz.Height() = 0;
261 22 : if ( aObjBound.Right() < aDocRect.Left() )
262 0 : aSz.Width() = (aDocRect.Left() - aObjBound.Right()) + MINFLY;
263 22 : if ( aObjBound.Bottom() < aDocRect.Top() )
264 0 : aSz.Height() = (aDocRect.Top() - aObjBound.Bottom()) + MINFLY;
265 22 : if ( aSz.Width() || aSz.Height() )
266 0 : pObj->Move( aSz );
267 : }
268 : }
269 : }
270 270 : }
271 :
272 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|