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