xref: /trunk/main/sw/source/core/view/vdraw.cxx (revision 8873b33a)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #include <svx/svdmodel.hxx>
28 #include <svx/svdpage.hxx>
29 #include <tools/shl.hxx>
30 #include <swmodule.hxx>
31 #include <svtools/accessibilityoptions.hxx>
32 #include <svx/svdpagv.hxx>
33 #include <fmtanchr.hxx>
34 #include <frmfmt.hxx>
35 #include <svx/svdoutl.hxx>
36 #ifdef DBG_UTIL
37 #include <svx/fmglob.hxx>
38 #endif
39 #include "fesh.hxx"
40 #include "pagefrm.hxx"
41 #include "rootfrm.hxx"
42 #include "viewimp.hxx"
43 #include "dflyobj.hxx"
44 #include "viewopt.hxx"
45 #include "printdata.hxx"
46 #include "dcontact.hxx"
47 #include "dview.hxx"
48 #include "flyfrm.hxx"
49 #include <vcl/svapp.hxx>
50 #include <IDocumentDrawModelAccess.hxx>
51 #include <drawdoc.hxx>
52 
53 /*************************************************************************
54 |*	SwSaveHdl
55 |*
56 |*	Ersterstellung		MA 14. Feb. 95
57 |*	Letzte Aenderung	MA 02. Jun. 98
58 **************************************************************************/
59 //SwSaveHdl::SwSaveHdl( SwViewImp *pI ) :
60 //	pImp( pI ),
61 //	bXorVis( sal_False )
62 //{
63 	//if ( pImp->HasDrawView() )
64 	//{
65 	//	bXorVis = pImp->GetDrawView()->IsShownXorVisible( pImp->GetShell()->GetOut());
66 	//	if ( bXorVis )
67 	//		pImp->GetDrawView()->HideShownXor( pImp->GetShell()->GetOut() );
68 	//}
69 //}
70 
71 
72 //SwSaveHdl::~SwSaveHdl()
73 //{
74 	//if ( bXorVis )
75 	//	pImp->GetDrawView()->ShowShownXor( pImp->GetShell()->GetOut() );
76 //}
77 
78 
79 /*************************************************************************
80 |*	SwViewImp::StartAction(), EndAction()
81 |*
82 |*	Ersterstellung		MA 14. Feb. 95
83 |*	Letzte Aenderung	MA 14. Sep. 98
84 **************************************************************************/
85 
86 
StartAction()87 void SwViewImp::StartAction()
88 {
89 	if ( HasDrawView() )
90 	{
91 		SET_CURR_SHELL( GetShell() );
92 		if ( pSh->ISA(SwFEShell) )
93 			((SwFEShell*)pSh)->HideChainMarker();	//Kann sich geaendert haben
94 		//bResetXorVisibility = GetDrawView()->IsShownXorVisible( GetShell()->GetOut());
95 		//GetDrawView()->HideShownXor( GetShell()->GetOut() );
96 	}
97 }
98 
99 
100 
EndAction()101 void SwViewImp::EndAction()
102 {
103 	if ( HasDrawView() )
104 	{
105 		SET_CURR_SHELL( GetShell() );
106 		//if ( bResetXorVisibility )
107 		//	GetDrawView()->ShowShownXor( GetShell()->GetOut() );
108 		if ( pSh->ISA(SwFEShell) )
109 			((SwFEShell*)pSh)->SetChainMarker();	//Kann sich geaendert haben
110 	}
111 }
112 
113 /*************************************************************************
114 |*	SwViewImp::LockPaint(), UnlockPaint()
115 |*
116 |*	Ersterstellung		MA 11. Jun. 96
117 |*	Letzte Aenderung	MA 11. Jun. 96
118 **************************************************************************/
119 
120 
LockPaint()121 void SwViewImp::LockPaint()
122 {
123 	if ( HasDrawView() )
124 	{
125 		//HMHbShowHdlPaint = GetDrawView()->IsMarkHdlShown();
126 		//HMHif ( bShowHdlPaint )
127 		//HMH	GetDrawView()->HideMarkHdl();
128 		bResetHdlHiddenPaint = !GetDrawView()->areMarkHandlesHidden();
129 		GetDrawView()->hideMarkHandles();
130 	}
131 	else
132 	{
133 		//HMHbShowHdlPaint = sal_False;
134 		bResetHdlHiddenPaint = sal_False;
135 	}
136 }
137 
138 
139 
UnlockPaint()140 void SwViewImp::UnlockPaint()
141 {
142 	if ( bResetHdlHiddenPaint )
143 		GetDrawView()->showMarkHandles();
144 	//HMHif ( bShowHdlPaint )
145 	//HMH	GetDrawView()->ShowMarkHdl();
146 }
147 
148 
149 /*************************************************************************
150 |*	SwViewImp::PaintLayer(), PaintDispatcher()
151 |*
152 |*	Ersterstellung		MA 20. Dec. 94
153 |*	Letzte Aenderung	AMA 04. Jun. 98
154 **************************************************************************/
155 // OD 29.08.2002 #102450#
156 // add 3rd parameter <const Color* pPageBackgrdColor> for setting this
157 // color as the background color at the outliner of the draw view.
158 // OD 09.12.2002 #103045# - add 4th parameter for the horizontal text direction
159 // of the page in order to set the default horizontal text direction at the
160 // outliner of the draw view for painting layers <hell> and <heaven>.
161 // OD 25.06.2003 #108784# - correct type of 1st parameter
PaintLayer(const SdrLayerID _nLayerID,SwPrintData const * const pPrintData,const SwRect &,const Color * _pPageBackgrdColor,const bool _bIsPageRightToLeft,sdr::contact::ViewObjectContactRedirector * pRedirector) const162 void SwViewImp::PaintLayer( const SdrLayerID _nLayerID,
163                             SwPrintData const*const pPrintData,
164                             const SwRect& ,
165                             const Color* _pPageBackgrdColor,
166                             const bool _bIsPageRightToLeft,
167                             sdr::contact::ViewObjectContactRedirector* pRedirector ) const
168 {
169     if ( HasDrawView() )
170 	{
171         //change the draw mode in high contrast mode
172         OutputDevice* pOutDev = GetShell()->GetOut();
173         sal_uLong nOldDrawMode = pOutDev->GetDrawMode();
174         if( GetShell()->GetWin() &&
175             Application::GetSettings().GetStyleSettings().GetHighContrastMode() &&
176             (!GetShell()->IsPreView()||SW_MOD()->GetAccessibilityOptions().GetIsForPagePreviews()))
177         {
178             pOutDev->SetDrawMode( nOldDrawMode | DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL |
179                                 DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT );
180         }
181 
182         // OD 29.08.2002 #102450#
183         // For correct handling of accessibility, high contrast, the page background
184         // color is set as the background color at the outliner of the draw view.
185         // Only necessary for the layers hell and heaven
186         Color aOldOutlinerBackgrdColor;
187         // OD 09.12.2002 #103045# - set default horizontal text direction on
188         // painting <hell> or <heaven>.
189         EEHorizontalTextDirection aOldEEHoriTextDir = EE_HTEXTDIR_L2R;
190         const IDocumentDrawModelAccess* pIDDMA = GetShell()->getIDocumentDrawModelAccess();
191         if ( (_nLayerID == pIDDMA->GetHellId()) ||
192              (_nLayerID == pIDDMA->GetHeavenId()) )
193         {
194             ASSERT( _pPageBackgrdColor,
195                     "incorrect usage of SwViewImp::PaintLayer: pPageBackgrdColor have to be set for painting layer <hell> or <heaven>");
196             if ( _pPageBackgrdColor )
197             {
198                 aOldOutlinerBackgrdColor =
199                         GetDrawView()->GetModel()->GetDrawOutliner().GetBackgroundColor();
200                 GetDrawView()->GetModel()->GetDrawOutliner().SetBackgroundColor( *_pPageBackgrdColor );
201             }
202 
203             aOldEEHoriTextDir =
204                 GetDrawView()->GetModel()->GetDrawOutliner().GetDefaultHorizontalTextDirection();
205             EEHorizontalTextDirection aEEHoriTextDirOfPage =
206                 _bIsPageRightToLeft ? EE_HTEXTDIR_R2L : EE_HTEXTDIR_L2R;
207             GetDrawView()->GetModel()->GetDrawOutliner().SetDefaultHorizontalTextDirection( aEEHoriTextDirOfPage );
208         }
209 
210 		pOutDev->Push( PUSH_LINECOLOR ); // #114231#
211         if (pPrintData)
212         {
213             // hide drawings but not form controls (form controls are handled elsewhere)
214             SdrView &rSdrView = const_cast< SdrView & >(GetPageView()->GetView());
215             rSdrView.setHideDraw( !pPrintData->IsPrintDraw() );
216         }
217         GetPageView()->DrawLayer( _nLayerID, pOutDev, pRedirector );
218 		pOutDev->Pop();
219 
220         // OD 29.08.2002 #102450#
221         // reset background color of the outliner
222         // OD 09.12.2002 #103045# - reset default horizontal text direction
223         if ( (_nLayerID == pIDDMA->GetHellId()) ||
224              (_nLayerID == pIDDMA->GetHeavenId()) )
225         {
226             GetDrawView()->GetModel()->GetDrawOutliner().SetBackgroundColor( aOldOutlinerBackgrdColor );
227             GetDrawView()->GetModel()->GetDrawOutliner().SetDefaultHorizontalTextDirection( aOldEEHoriTextDir );
228         }
229 
230         pOutDev->SetDrawMode( nOldDrawMode );
231     }
232 }
233 
234 /*************************************************************************
235 |*	SwViewImp::IsDragPossible()
236 |*
237 |*	Ersterstellung		MA 19. Jan. 93
238 |*	Letzte Aenderung	MA 16. Jan. 95
239 **************************************************************************/
240 #define WIEDUWILLST 400
241 
IsDragPossible(const Point & rPoint)242 sal_Bool SwViewImp::IsDragPossible( const Point &rPoint )
243 {
244 	if ( !HasDrawView() )
245 		return sal_False;
246 
247 	const SdrMarkList &rMrkList = GetDrawView()->GetMarkedObjectList();
248 
249 	if( !rMrkList.GetMarkCount() )
250 		return sal_False;
251 
252 	SdrObject *pO = rMrkList.GetMark(rMrkList.GetMarkCount()-1)->GetMarkedSdrObj();
253 
254 	SwRect aRect;
255 	if( pO && ::CalcClipRect( pO, aRect, sal_False ) )
256 	{
257 		SwRect aTmp;
258 		::CalcClipRect( pO, aTmp, sal_True );
259 		aRect.Union( aTmp );
260 	}
261 	else
262 		aRect = GetShell()->GetLayout()->Frm();
263 
264 	aRect.Top(	  aRect.Top()	 - WIEDUWILLST );
265 	aRect.Bottom( aRect.Bottom() + WIEDUWILLST );
266 	aRect.Left(   aRect.Left()	 - WIEDUWILLST );
267 	aRect.Right(  aRect.Right()  + WIEDUWILLST );
268 	return aRect.IsInside( rPoint );
269 }
270 
271 /*************************************************************************
272 |*	SwViewImp::NotifySizeChg()
273 |*
274 |*	Ersterstellung		MA 23. Jun. 93
275 |*	Letzte Aenderung	MA 05. Oct. 98
276 **************************************************************************/
277 
NotifySizeChg(const Size & rNewSz)278 void SwViewImp::NotifySizeChg( const Size &rNewSz )
279 {
280 	if ( !HasDrawView() )
281 		return;
282 
283 	if ( GetPageView() )
284 		GetPageView()->GetPage()->SetSize( rNewSz );
285 
286 	//Begrenzung des Arbeitsbereiches.
287 	const Rectangle aRect( Point( DOCUMENTBORDER, DOCUMENTBORDER ), rNewSz );
288 	const Rectangle &rOldWork = GetDrawView()->GetWorkArea();
289 	sal_Bool bCheckDrawObjs = sal_False;
290 	if ( aRect != rOldWork )
291 	{
292 		if ( rOldWork.Bottom() > aRect.Bottom() || rOldWork.Right() > aRect.Right())
293 			bCheckDrawObjs = sal_True;
294 		GetDrawView()->SetWorkArea( aRect );
295 	}
296 	if ( !bCheckDrawObjs )
297 		return;
298 
299 	ASSERT( pSh->getIDocumentDrawModelAccess()->GetDrawModel(), "NotifySizeChg without DrawModel" );
300 	SdrPage* pPage = pSh->getIDocumentDrawModelAccess()->GetDrawModel()->GetPage( 0 );
301 	const sal_uLong nObjs = pPage->GetObjCount();
302 	for( sal_uLong nObj = 0; nObj < nObjs; ++nObj )
303 	{
304 		SdrObject *pObj = pPage->GetObj( nObj );
305 		if( !pObj->ISA(SwVirtFlyDrawObj) )
306 		{
307 			//Teilfix(26793): Objekte, die in Rahmen verankert sind, brauchen
308 			//nicht angepasst werden.
309             const SwContact *pCont = (SwContact*)GetUserCall(pObj);
310 			//JP - 16.3.00 Bug 73920: this function might be called by the
311 			//				InsertDocument, when a PageDesc-Attribute is
312 			//				set on a node. Then the SdrObject must not have
313 			//				an UserCall.
314             if( !pCont || !pCont->ISA(SwDrawContact) )
315 				continue;
316 
317             const SwFrm *pAnchor = ((SwDrawContact*)pCont)->GetAnchorFrm();
318 			if ( !pAnchor || pAnchor->IsInFly() || !pAnchor->IsValid() ||
319                  !pAnchor->GetUpper() || !pAnchor->FindPageFrm() ||
320                  (FLY_AS_CHAR == pCont->GetFmt()->GetAnchor().GetAnchorId()) )
321             {
322 				continue;
323             }
324 
325             // OD 19.06.2003 #108784# - no move for drawing objects in header/footer
326             if ( pAnchor->FindFooterOrHeader() )
327             {
328                 continue;
329             }
330 
331 			const Rectangle aBound( pObj->GetCurrentBoundRect() );
332 			if ( !aRect.IsInside( aBound ) )
333 			{
334 				Size aSz;
335 				if ( aBound.Left() > aRect.Right() )
336 					aSz.Width() = (aRect.Right() - aBound.Left()) - MINFLY;
337 				if ( aBound.Top() > aRect.Bottom() )
338 					aSz.Height() = (aRect.Bottom() - aBound.Top()) - MINFLY;
339 				if ( aSz.Width() || aSz.Height() )
340 					pObj->Move( aSz );
341 
342 				// Notanker: Grosse Objekte nicht nach oben verschwinden lassen.
343 				aSz.Width() = aSz.Height() = 0;
344 				if ( aBound.Bottom() < aRect.Top() )
345 					aSz.Width() = (aBound.Bottom() - aRect.Top()) - MINFLY;
346 				if ( aBound.Right() < aRect.Left() )
347 					aSz.Height() = (aBound.Right() - aRect.Left()) - MINFLY;
348 				if ( aSz.Width() || aSz.Height() )
349 					pObj->Move( aSz );
350 			}
351 		}
352 	}
353 }
354