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 <tools/shl.hxx>
23 : #include <swmodule.hxx>
24 : #include <svtools/accessibilityoptions.hxx>
25 : #include <svx/svdpagv.hxx>
26 : #include <fmtanchr.hxx>
27 : #include <frmfmt.hxx>
28 :
29 : #include <svx/svdoutl.hxx>
30 :
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 0 : void SwViewImp::StartAction()
47 : {
48 0 : if ( HasDrawView() )
49 : {
50 0 : SET_CURR_SHELL( GetShell() );
51 0 : if ( pSh->ISA(SwFEShell) )
52 0 : ((SwFEShell*)pSh)->HideChainMarker(); // might have changed
53 : }
54 0 : }
55 :
56 0 : void SwViewImp::EndAction()
57 : {
58 0 : if ( HasDrawView() )
59 : {
60 0 : SET_CURR_SHELL( GetShell() );
61 0 : if ( pSh->ISA(SwFEShell) )
62 0 : ((SwFEShell*)pSh)->SetChainMarker(); // might have changed
63 : }
64 0 : }
65 :
66 0 : void SwViewImp::LockPaint()
67 : {
68 0 : if ( HasDrawView() )
69 : {
70 0 : bResetHdlHiddenPaint = !GetDrawView()->areMarkHandlesHidden();
71 0 : GetDrawView()->hideMarkHandles();
72 : }
73 : else
74 : {
75 0 : bResetHdlHiddenPaint = false;
76 : }
77 0 : }
78 :
79 0 : void SwViewImp::UnlockPaint()
80 : {
81 0 : if ( bResetHdlHiddenPaint )
82 0 : GetDrawView()->showMarkHandles();
83 0 : }
84 :
85 0 : 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 0 : if ( HasDrawView() )
93 : {
94 : //change the draw mode in high contrast mode
95 0 : OutputDevice* pOutDev = GetShell()->GetOut();
96 0 : sal_uLong nOldDrawMode = pOutDev->GetDrawMode();
97 0 : if( GetShell()->GetWin() &&
98 0 : 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 0 : Color aOldOutlinerBackgrdColor;
110 : // set default horizontal text direction on painting <hell> or
111 : // <heaven>.
112 0 : EEHorizontalTextDirection aOldEEHoriTextDir = EE_HTEXTDIR_L2R;
113 0 : const IDocumentDrawModelAccess* pIDDMA = GetShell()->getIDocumentDrawModelAccess();
114 0 : if ( (_nLayerID == pIDDMA->GetHellId()) ||
115 0 : (_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 0 : if ( _pPageBackgrdColor )
120 : {
121 : aOldOutlinerBackgrdColor =
122 0 : GetDrawView()->GetModel()->GetDrawOutliner().GetBackgroundColor();
123 0 : GetDrawView()->GetModel()->GetDrawOutliner().SetBackgroundColor( *_pPageBackgrdColor );
124 : }
125 :
126 : aOldEEHoriTextDir =
127 0 : GetDrawView()->GetModel()->GetDrawOutliner().GetDefaultHorizontalTextDirection();
128 : EEHorizontalTextDirection aEEHoriTextDirOfPage =
129 0 : _bIsPageRightToLeft ? EE_HTEXTDIR_R2L : EE_HTEXTDIR_L2R;
130 0 : GetDrawView()->GetModel()->GetDrawOutliner().SetDefaultHorizontalTextDirection( aEEHoriTextDirOfPage );
131 : }
132 :
133 0 : pOutDev->Push( PUSH_LINECOLOR ); // #114231#
134 0 : 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 0 : GetPageView()->DrawLayer( _nLayerID, pOutDev, pRedirector, aPaintRect.SVRect() );
141 0 : pOutDev->Pop();
142 :
143 : // reset background color of the outliner & default horiz. text dir.
144 0 : if ( (_nLayerID == pIDDMA->GetHellId()) ||
145 0 : (_nLayerID == pIDDMA->GetHeavenId()) )
146 : {
147 0 : GetDrawView()->GetModel()->GetDrawOutliner().SetBackgroundColor( aOldOutlinerBackgrdColor );
148 0 : GetDrawView()->GetModel()->GetDrawOutliner().SetDefaultHorizontalTextDirection( aOldEEHoriTextDir );
149 : }
150 :
151 0 : pOutDev->SetDrawMode( nOldDrawMode );
152 : }
153 0 : }
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, sal_False ) )
171 : {
172 0 : SwRect aTmp;
173 0 : ::CalcClipRect( pO, aTmp, sal_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 0 : void SwViewImp::NotifySizeChg( const Size &rNewSz )
187 : {
188 0 : if ( !HasDrawView() )
189 0 : return;
190 :
191 0 : if ( GetPageView() )
192 0 : GetPageView()->GetPage()->SetSize( rNewSz );
193 :
194 : // Limitation of the work area
195 0 : const Rectangle aRect( Point( DOCUMENTBORDER, DOCUMENTBORDER ), rNewSz );
196 0 : const Rectangle &rOldWork = GetDrawView()->GetWorkArea();
197 0 : bool bCheckDrawObjs = false;
198 0 : if ( aRect != rOldWork )
199 : {
200 0 : if ( rOldWork.Bottom() > aRect.Bottom() || rOldWork.Right() > aRect.Right())
201 0 : bCheckDrawObjs = true;
202 0 : GetDrawView()->SetWorkArea( aRect );
203 : }
204 0 : if ( !bCheckDrawObjs )
205 0 : return;
206 :
207 : OSL_ENSURE( pSh->getIDocumentDrawModelAccess()->GetDrawModel(), "NotifySizeChg without DrawModel" );
208 0 : SdrPage* pPage = pSh->getIDocumentDrawModelAccess()->GetDrawModel()->GetPage( 0 );
209 0 : const sal_uLong nObjs = pPage->GetObjCount();
210 0 : for( sal_uLong nObj = 0; nObj < nObjs; ++nObj )
211 : {
212 0 : SdrObject *pObj = pPage->GetObj( nObj );
213 0 : if( !pObj->ISA(SwVirtFlyDrawObj) )
214 : {
215 : // Objects not anchored to the frame, do not need to be adjusted
216 0 : 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 0 : if( !pCont || !pCont->ISA(SwDrawContact) )
221 0 : continue;
222 :
223 0 : const SwFrm *pAnchor = ((SwDrawContact*)pCont)->GetAnchorFrm();
224 0 : if ( !pAnchor || pAnchor->IsInFly() || !pAnchor->IsValid() ||
225 0 : !pAnchor->GetUpper() || !pAnchor->FindPageFrm() ||
226 0 : (FLY_AS_CHAR == pCont->GetFmt()->GetAnchor().GetAnchorId()) )
227 : {
228 0 : continue;
229 : }
230 :
231 : // no move for drawing objects in header/footer
232 0 : if ( pAnchor->FindFooterOrHeader() )
233 : {
234 0 : continue;
235 : }
236 :
237 0 : const Rectangle aBound( pObj->GetCurrentBoundRect() );
238 0 : if ( !aRect.IsInside( aBound ) )
239 : {
240 0 : Size aSz;
241 0 : if ( aBound.Left() > aRect.Right() )
242 0 : aSz.Width() = (aRect.Right() - aBound.Left()) - MINFLY;
243 0 : if ( aBound.Top() > aRect.Bottom() )
244 0 : aSz.Height() = (aRect.Bottom() - aBound.Top()) - MINFLY;
245 0 : if ( aSz.Width() || aSz.Height() )
246 0 : pObj->Move( aSz );
247 :
248 : // Don't let large objects dissappear to the top
249 0 : aSz.Width() = aSz.Height() = 0;
250 0 : if ( aBound.Bottom() < aRect.Top() )
251 0 : aSz.Width() = (aBound.Bottom() - aRect.Top()) - MINFLY;
252 0 : if ( aBound.Right() < aRect.Left() )
253 0 : aSz.Height() = (aBound.Right() - aRect.Left()) - MINFLY;
254 0 : if ( aSz.Width() || aSz.Height() )
255 0 : pObj->Move( aSz );
256 : }
257 : }
258 : }
259 : }
260 :
261 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|