xref: /aoo41x/main/svx/source/svdraw/svdpntv.cxx (revision e6f63103)
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_svx.hxx"
26 #include <com/sun/star/awt/XWindow.hpp>
27 #include <svx/svdpntv.hxx>
28 #include <vcl/msgbox.hxx>
29 #include <svx/sdrpaintwindow.hxx>
30 #include <svtools/grfmgr.hxx>
31 #include <svx/svdmodel.hxx>
32 
33 #ifdef DBG_UTIL
34 #include <svdibrow.hxx>
35 #endif
36 #include <svx/svdpage.hxx>
37 #include <svx/svdpagv.hxx>
38 #include <svl/smplhint.hxx>
39 
40 #include <svx/svdpntv.hxx>
41 #include <editeng/editdata.hxx>
42 #include <svx/svdmrkv.hxx>
43 #include <svx/svdpagv.hxx>
44 #include <svx/svdpage.hxx>
45 #include <svx/svdmodel.hxx>
46 #include <svx/svdundo.hxx>
47 #include <svx/svdview.hxx>
48 #include <svx/svdglue.hxx>
49 #include <svx/svdobj.hxx>
50 #include <svx/svdograf.hxx>
51 #include <svx/svdattrx.hxx>
52 #include "svdibrow.hxx"
53 #include "svx/svditer.hxx"
54 #include <svx/svdouno.hxx>
55 #include <svx/sdr/overlay/overlayobjectlist.hxx>
56 #include <svx/sdr/overlay/overlayrollingrectangle.hxx>
57 #include <svx/sdr/overlay/overlaymanager.hxx>
58 #include <svx/svdglue.hxx>
59 #include <svx/svdobj.hxx>
60 #include <svx/svdview.hxx>
61 #include <svx/sxlayitm.hxx>
62 #include <svl/itemiter.hxx>
63 #include <editeng/eeitem.hxx>
64 #include <svl/whiter.hxx>
65 #include <svl/style.hxx>
66 #include <svx/sdrpagewindow.hxx>
67 #include <svx/svdouno.hxx>
68 #include <vcl/svapp.hxx>
69 #include <com/sun/star/awt/XWindow.hpp>
70 #include <com/sun/star/awt/PosSize.hpp>
71 #include <com/sun/star/awt/XControl.hpp>
72 #include <svx/sdr/contact/objectcontact.hxx>
73 #include <svx/sdr/animation/objectanimator.hxx>
74 #include <svx/sdr/contact/viewcontact.hxx>
75 #include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
76 #include <basegfx/matrix/b2dhommatrixtools.hxx>
77 
78 using namespace ::rtl;
79 using namespace ::com::sun::star;
80 
81 ////////////////////////////////////////////////////////////////////////////////////////////////////
82 // #114409#-3 Migrate Encirclement
83 class ImplEncirclementOverlay
84 {
85 	// The OverlayObjects
86 	::sdr::overlay::OverlayObjectList				maObjects;
87 
88 	// The remembered second position in logical coodinates
89 	basegfx::B2DPoint								maSecondPosition;
90 
91 public:
92 	ImplEncirclementOverlay(const SdrPaintView& rView, const basegfx::B2DPoint& rStartPos);
93 	~ImplEncirclementOverlay();
94 
95 	void SetSecondPosition(const basegfx::B2DPoint& rNewPosition);
96 };
97 
ImplEncirclementOverlay(const SdrPaintView & rView,const basegfx::B2DPoint & rStartPos)98 ImplEncirclementOverlay::ImplEncirclementOverlay(const SdrPaintView& rView, const basegfx::B2DPoint& rStartPos)
99 :	maSecondPosition(rStartPos)
100 {
101 	for(sal_uInt32 a(0L); a < rView.PaintWindowCount(); a++)
102 	{
103 		SdrPaintWindow* pCandidate = rView.GetPaintWindow(a);
104 		::sdr::overlay::OverlayManager* pTargetOverlay = pCandidate->GetOverlayManager();
105 
106 		if(pTargetOverlay)
107 		{
108 			::sdr::overlay::OverlayRollingRectangleStriped* aNew = new ::sdr::overlay::OverlayRollingRectangleStriped(
109 				rStartPos, rStartPos, false);
110 			pTargetOverlay->add(*aNew);
111 			maObjects.append(*aNew);
112 		}
113 	}
114 }
115 
~ImplEncirclementOverlay()116 ImplEncirclementOverlay::~ImplEncirclementOverlay()
117 {
118 	// The OverlayObjects are cleared using the destructor of OverlayObjectList.
119 	// That destructor calls clear() at the list which removes all objects from the
120 	// OverlayManager and deletes them.
121 }
122 
SetSecondPosition(const basegfx::B2DPoint & rNewPosition)123 void ImplEncirclementOverlay::SetSecondPosition(const basegfx::B2DPoint& rNewPosition)
124 {
125 	if(rNewPosition != maSecondPosition)
126 	{
127 		// apply to OverlayObjects
128 		for(sal_uInt32 a(0L); a < maObjects.count(); a++)
129 		{
130 			::sdr::overlay::OverlayRollingRectangleStriped& rCandidate = (::sdr::overlay::OverlayRollingRectangleStriped&)maObjects.getOverlayObject(a);
131 			rCandidate.setSecondPosition(rNewPosition);
132 		}
133 
134 		// remember new position
135 		maSecondPosition = rNewPosition;
136 	}
137 }
138 
139 ////////////////////////////////////////////////////////////////////////////////////////////////////
140 // interface to SdrPaintWindow
141 
FindPaintWindow(const OutputDevice & rOut) const142 SdrPaintWindow* SdrPaintView::FindPaintWindow(const OutputDevice& rOut) const
143 {
144 	for(SdrPaintWindowVector::const_iterator a = maPaintWindows.begin(); a != maPaintWindows.end(); a++)
145 	{
146 		if(&((*a)->GetOutputDevice()) == &rOut)
147 		{
148 			return *a;
149 		}
150 	}
151 
152 	return 0L;
153 }
154 
GetPaintWindow(sal_uInt32 nIndex) const155 SdrPaintWindow* SdrPaintView::GetPaintWindow(sal_uInt32 nIndex) const
156 {
157 	if(nIndex < maPaintWindows.size())
158 	{
159 		return maPaintWindows[nIndex];
160 	}
161 
162 	return 0L;
163 }
164 
AppendPaintWindow(SdrPaintWindow & rNew)165 void SdrPaintView::AppendPaintWindow(SdrPaintWindow& rNew)
166 {
167 	maPaintWindows.push_back(&rNew);
168 }
169 
RemovePaintWindow(SdrPaintWindow & rOld)170 SdrPaintWindow* SdrPaintView::RemovePaintWindow(SdrPaintWindow& rOld)
171 {
172 	SdrPaintWindow* pRetval = 0L;
173 	const SdrPaintWindowVector::iterator aFindResult = ::std::find(maPaintWindows.begin(), maPaintWindows.end(), &rOld);
174 
175 	if(aFindResult != maPaintWindows.end())
176 	{
177 		// remember return value, aFindResult is no longer valid after deletion
178 		pRetval = *aFindResult;
179 		maPaintWindows.erase(aFindResult);
180 	}
181 
182 	return pRetval;
183 }
184 
GetFirstOutputDevice() const185 OutputDevice* SdrPaintView::GetFirstOutputDevice() const
186 {
187 	if(PaintWindowCount())
188 	{
189 		return &(GetPaintWindow(0)->GetOutputDevice());
190 	}
191 
192 	return 0L;
193 }
194 
195 ////////////////////////////////////////////////////////////////////////////////////////////////////
196 
197 TYPEINIT1( SvxViewHint, SfxHint );
198 
SvxViewHint(HintType eHintType)199 SvxViewHint::SvxViewHint (HintType eHintType)
200     : meHintType(eHintType)
201 {
202 }
203 
GetHintType(void) const204 SvxViewHint::HintType SvxViewHint::GetHintType (void) const
205 {
206     return meHintType;
207 }
208 
209 
210 ////////////////////////////////////////////////////////////////////////////////////////////////////
211 
convertMetafileToBitmapEx(const GDIMetaFile & rMtf,const basegfx::B2DRange & rTargetRange,const sal_uInt32 nMaximumQuadraticPixels)212 BitmapEx convertMetafileToBitmapEx(
213     const GDIMetaFile& rMtf,
214     const basegfx::B2DRange& rTargetRange,
215     const sal_uInt32 nMaximumQuadraticPixels)
216 {
217     BitmapEx aBitmapEx;
218 
219     if(rMtf.GetActionCount())
220     {
221 		const drawinglayer::primitive2d::Primitive2DReference aMtf(
222 			new drawinglayer::primitive2d::MetafilePrimitive2D(
223 				basegfx::tools::createScaleTranslateB2DHomMatrix(
224                     rTargetRange.getRange(),
225                     rTargetRange.getMinimum()),
226 				rMtf));
227         aBitmapEx = convertPrimitive2DSequenceToBitmapEx(
228     		drawinglayer::primitive2d::Primitive2DSequence(&aMtf, 1),
229             rTargetRange,
230             nMaximumQuadraticPixels);
231     }
232 
233     return aBitmapEx;
234 }
235 
236 ////////////////////////////////////////////////////////////////////////////////////////////////////
237 
238 TYPEINIT2(SdrPaintView,SfxListener,SfxRepeatTarget);
239 
240 DBG_NAME(SdrPaintView);
241 
ImpClearVars()242 void SdrPaintView::ImpClearVars()
243 {
244 #ifdef DBG_UTIL
245 	pItemBrowser=NULL;
246 #endif
247 	bPageVisible=sal_True;
248 	bPageBorderVisible=sal_True;
249 	bBordVisible=sal_True;
250 	bGridVisible=sal_True;
251 	bGridFront	=sal_False;
252 	bHlplVisible=sal_True;
253 	bHlplFront	=sal_True;
254 	bGlueVisible=sal_False;
255 	bGlueVisible2=sal_False;
256 	bGlueVisible3=sal_False;
257 	bGlueVisible4=sal_False;
258 	bSwapAsynchron=sal_False;
259 	bPrintPreview=sal_False;
260 	mbPreviewRenderer=sal_False;
261 
262 	eAnimationMode = SDR_ANIMATION_ANIMATE;
263     bAnimationPause = sal_False;
264 
265 	nHitTolPix=2;
266 	nMinMovPix=3;
267 	nHitTolLog=0;
268 	nMinMovLog=0;
269 	pActualOutDev=NULL;
270 	pDragWin=NULL;
271 	bRestoreColors=sal_True;
272 	pDefaultStyleSheet=NULL;
273 	bSomeObjChgdFlag=sal_False;
274     nGraphicManagerDrawMode = GRFMGR_DRAW_STANDARD;
275 	aComeBackTimer.SetTimeout(1);
276 	aComeBackTimer.SetTimeoutHdl(LINK(this,SdrPaintView,ImpComeBackHdl));
277 	String aNam;	// System::GetUserName() just return an empty string
278 
279 	if (pMod)
280 		SetDefaultStyleSheet(pMod->GetDefaultStyleSheet(), sal_True);
281 
282 	aNam.ToUpperAscii();
283 
284 	maGridColor = Color( COL_BLACK );
285 	BrkEncirclement();
286 }
287 
SdrPaintView(SdrModel * pModel1,OutputDevice * pOut)288 SdrPaintView::SdrPaintView(SdrModel* pModel1, OutputDevice* pOut)
289 :	mpEncirclementOverlay(0L),
290 	mpPageView(0L),
291 	aDefaultAttr(pModel1->GetItemPool()),
292 	mbBufferedOutputAllowed(false),
293 	mbBufferedOverlayAllowed(false),
294 	mbPagePaintingAllowed(true),
295     mbHideOle(false),
296     mbHideChart(false),
297     mbHideDraw(false),
298     mbHideFormControl(false)
299 {
300 	DBG_CTOR(SdrPaintView,NULL);
301 	pMod=pModel1;
302 	ImpClearVars();
303 
304 	if(pOut)
305 	{
306 		AddWindowToPaintView(pOut);
307 	}
308 
309 	// Flag zur Visualisierung von Gruppen
310 	bVisualizeEnteredGroup = sal_True;
311 
312 	maColorConfig.AddListener(this);
313 	onChangeColorConfig();
314 }
315 
~SdrPaintView()316 SdrPaintView::~SdrPaintView()
317 {
318 	DBG_DTOR(SdrPaintView,NULL);
319 	if (pDefaultStyleSheet)
320 		EndListening(*pDefaultStyleSheet);
321 
322 	maColorConfig.RemoveListener(this);
323 	ClearPageView();
324 
325 #ifdef DBG_UTIL
326 	if(pItemBrowser)
327 	{
328 		delete pItemBrowser;
329 	}
330 #endif
331 
332 	// delete existing SdrPaintWindows
333 	while(!maPaintWindows.empty())
334 	{
335 		delete maPaintWindows.back();
336 		maPaintWindows.pop_back();
337 	}
338 
339 	// #114409#-3 Migrate HelpLine
340 	BrkEncirclement();
341 }
342 
343 ////////////////////////////////////////////////////////////////////////////////////////////////////
344 
Notify(SfxBroadcaster & rBC,const SfxHint & rHint)345 void __EXPORT SdrPaintView::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
346 {
347 	//If the stylesheet has been destroyed
348     if (&rBC == pDefaultStyleSheet)
349     {
350         if (rHint.ISA(SfxSimpleHint) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING)
351             pDefaultStyleSheet = NULL;
352         return;
353     }
354 
355 	sal_Bool bObjChg=!bSomeObjChgdFlag; // sal_True= auswerten fuer ComeBack-Timer
356 	if (bObjChg) {
357 		SdrHint* pSdrHint=PTR_CAST(SdrHint,&rHint);
358 		if (pSdrHint!=NULL) {
359 			SdrHintKind eKind=pSdrHint->GetKind();
360 			if (eKind==HINT_OBJCHG || eKind==HINT_OBJINSERTED || eKind==HINT_OBJREMOVED) {
361 				if (bObjChg) {
362 					bSomeObjChgdFlag=sal_True;
363 					aComeBackTimer.Start();
364 				}
365 			}
366 			if (eKind==HINT_PAGEORDERCHG) {
367 				const SdrPage* pPg=pSdrHint->GetPage();
368 
369 				if(pPg && !pPg->IsInserted())
370 				{
371 					if(mpPageView && mpPageView->GetPage() == pPg)
372 					{
373 						HideSdrPage();
374 					}
375 				}
376 			}
377 		}
378 	}
379 }
380 
ConfigurationChanged(::utl::ConfigurationBroadcaster *,sal_uInt32)381 void SdrPaintView::ConfigurationChanged( ::utl::ConfigurationBroadcaster* , sal_uInt32 )
382 {
383 	onChangeColorConfig();
384 	InvalidateAllWin();
385 }
386 
387 ////////////////////////////////////////////////////////////////////////////////////////////////////
388 
IMPL_LINK_INLINE_START(SdrPaintView,ImpComeBackHdl,Timer *,EMPTYARG)389 IMPL_LINK_INLINE_START(SdrPaintView,ImpComeBackHdl,Timer*,EMPTYARG)
390 {
391 	if (bSomeObjChgdFlag) {
392 		bSomeObjChgdFlag=sal_False;
393 		ModelHasChanged();
394 	}
395 	return 0;
396 }
IMPL_LINK_INLINE_END(SdrPaintView,ImpComeBackHdl,Timer *,pTimer)397 IMPL_LINK_INLINE_END(SdrPaintView,ImpComeBackHdl,Timer*,pTimer)
398 
399 void SdrPaintView::FlushComeBackTimer() const
400 {
401 	if (bSomeObjChgdFlag) {
402 		// casting auf nonconst
403 		((SdrPaintView*)this)->ImpComeBackHdl(&((SdrPaintView*)this)->aComeBackTimer);
404 		((SdrPaintView*)this)->aComeBackTimer.Stop();
405 	}
406 }
407 
ModelHasChanged()408 void SdrPaintView::ModelHasChanged()
409 {
410 	// Auch alle PageViews benachrichtigen
411 	if(mpPageView && !mpPageView->GetPage()->IsInserted())
412 	{
413 		HideSdrPage();
414 	}
415 
416 	// test mpPageView here again, HideSdrPage() may have invalidated it.
417 	if(mpPageView)
418 	{
419 		mpPageView->ModelHasChanged();
420 	}
421 
422 #ifdef DBG_UTIL
423 	if(pItemBrowser)
424 	{
425 		pItemBrowser->SetDirty();
426 	}
427 #endif
428 }
429 
430 ////////////////////////////////////////////////////////////////////////////////////////////////////
431 
IsAction() const432 sal_Bool SdrPaintView::IsAction() const
433 {
434 	return IsEncirclement();
435 }
436 
MovAction(const Point & rPnt)437 void SdrPaintView::MovAction(const Point& rPnt)
438 {
439 	if (IsEncirclement())
440 	{
441 		MovEncirclement(rPnt);
442 	}
443 }
444 
EndAction()445 void SdrPaintView::EndAction()
446 {
447 	if(IsEncirclement())
448 	{
449 		EndEncirclement();
450 	}
451 }
452 
BckAction()453 void SdrPaintView::BckAction()
454 {
455 	BrkEncirclement();
456 }
457 
BrkAction()458 void SdrPaintView::BrkAction()
459 {
460 	BrkEncirclement();
461 }
462 
TakeActionRect(Rectangle & rRect) const463 void SdrPaintView::TakeActionRect(Rectangle& rRect) const
464 {
465 	if(IsEncirclement())
466 	{
467 		rRect = Rectangle(aDragStat.GetStart(),aDragStat.GetNow());
468 	}
469 }
470 
471 ////////////////////////////////////////////////////////////////////////////////////////////////////
472 // info about TextEdit. Default is sal_False.
IsTextEdit() const473 bool SdrPaintView::IsTextEdit() const
474 {
475 	return false;
476 }
477 
478 // info about TextEditPageView. Default is 0L.
GetTextEditPageView() const479 SdrPageView* SdrPaintView::GetTextEditPageView() const
480 {
481 	return 0L;
482 }
483 
484 ////////////////////////////////////////////////////////////////////////////////////////////////////
485 
ImpGetMinMovLogic(short nMinMov,const OutputDevice * pOut) const486 sal_uInt16 SdrPaintView::ImpGetMinMovLogic(short nMinMov, const OutputDevice* pOut) const
487 {
488 	if (nMinMov>=0) return sal_uInt16(nMinMov);
489 	if (pOut==NULL)
490 	{
491 		pOut = GetFirstOutputDevice();
492 	}
493 	if (pOut!=NULL) {
494 		return short(-pOut->PixelToLogic(Size(nMinMov,0)).Width());
495 	} else {
496 		return 0;
497 	}
498 }
499 
ImpGetHitTolLogic(short nHitTol,const OutputDevice * pOut) const500 sal_uInt16 SdrPaintView::ImpGetHitTolLogic(short nHitTol, const OutputDevice* pOut) const
501 {
502 	if (nHitTol>=0) return sal_uInt16(nHitTol);
503 	if (pOut==NULL)
504 	{
505 		pOut = GetFirstOutputDevice();
506 	}
507 	if (pOut!=NULL) {
508 		return short(-pOut->PixelToLogic(Size(nHitTol,0)).Width());
509 	} else {
510 		return 0;
511 	}
512 }
513 
TheresNewMapMode()514 void SdrPaintView::TheresNewMapMode()
515 {
516 	if (pActualOutDev!=NULL) {
517 		nHitTolLog=(sal_uInt16)((OutputDevice*)pActualOutDev)->PixelToLogic(Size(nHitTolPix,0)).Width();
518 		nMinMovLog=(sal_uInt16)((OutputDevice*)pActualOutDev)->PixelToLogic(Size(nMinMovPix,0)).Width();
519 	}
520 }
521 
SetActualWin(const OutputDevice * pWin)522 void SdrPaintView::SetActualWin(const OutputDevice* pWin)
523 {
524 	pActualOutDev=pWin;
525 	TheresNewMapMode();
526 }
527 
528 ////////////////////////////////////////////////////////////////////////////////////////////////////
529 
BegEncirclement(const Point & rPnt)530 void SdrPaintView::BegEncirclement(const Point& rPnt)
531 {
532 	BrkAction();
533 
534 	DBG_ASSERT(0L == mpEncirclementOverlay, "SdrSnapView::BegSetPageOrg: There exists a ImplPageOriginOverlay (!)");
535 	basegfx::B2DPoint aStartPos(rPnt.X(), rPnt.Y());
536 	mpEncirclementOverlay = new ImplEncirclementOverlay(*this, aStartPos);
537 
538 	aDragStat.Reset(rPnt);
539 	aDragStat.SetMinMove(ImpGetMinMovLogic(-2,0L));
540 	aDragStat.NextPoint();
541 }
542 
MovEncirclement(const Point & rPnt)543 void SdrPaintView::MovEncirclement(const Point& rPnt)
544 {
545 	if(IsEncirclement() && aDragStat.CheckMinMoved(rPnt))
546 	{
547 		aDragStat.NextMove(rPnt);
548 
549 		DBG_ASSERT(mpEncirclementOverlay, "SdrSnapView::MovSetPageOrg: no ImplPageOriginOverlay (!)");
550 		basegfx::B2DPoint aNewPos(rPnt.X(), rPnt.Y());
551 		mpEncirclementOverlay->SetSecondPosition(aNewPos);
552 	}
553 }
554 
EndEncirclement(sal_Bool bNoJustify)555 Rectangle SdrPaintView::EndEncirclement(sal_Bool bNoJustify)
556 {
557 	Rectangle aRetval;
558 
559 	if(IsEncirclement())
560 	{
561 		if(aDragStat.IsMinMoved())
562 		{
563 			aRetval = Rectangle(aDragStat.GetStart(), aDragStat.GetNow());
564 
565 			if(!bNoJustify)
566 			{
567 				aRetval.Justify();
568 			}
569 		}
570 
571 		// cleanup
572 		BrkEncirclement();
573 	}
574 
575 	return aRetval;
576 }
577 
BrkEncirclement()578 void SdrPaintView::BrkEncirclement()
579 {
580 	if(IsEncirclement())
581 	{
582 		DBG_ASSERT(mpEncirclementOverlay, "SdrSnapView::MovSetPageOrg: no ImplPageOriginOverlay (!)");
583 		delete mpEncirclementOverlay;
584 		mpEncirclementOverlay = 0L;
585 	}
586 }
587 
588 ////////////////////////////////////////////////////////////////////////////////////////////////////
589 
ClearPageView()590 void SdrPaintView::ClearPageView()
591 {
592 	BrkAction();
593 
594 	if(mpPageView)
595 	{
596 		InvalidateAllWin();
597 		delete mpPageView;
598 		mpPageView = 0L;
599 	}
600 }
601 
ShowSdrPage(SdrPage * pPage)602 SdrPageView* SdrPaintView::ShowSdrPage(SdrPage* pPage)
603 {
604 	if(pPage && (!mpPageView || mpPageView->GetPage() != pPage))
605 	{
606 		if(mpPageView)
607 		{
608 			InvalidateAllWin();
609 			delete mpPageView;
610 		}
611 
612 		mpPageView = new SdrPageView(pPage, *((SdrView*)this));
613 		mpPageView->Show();
614 	}
615 
616 	return mpPageView;
617 }
618 
HideSdrPage()619 void SdrPaintView::HideSdrPage()
620 {
621 	if(mpPageView)
622 	{
623 		mpPageView->Hide();
624 		delete mpPageView;
625 		mpPageView = 0L;
626 	}
627 }
628 
AddWindowToPaintView(OutputDevice * pNewWin)629 void SdrPaintView::AddWindowToPaintView(OutputDevice* pNewWin)
630 {
631 	DBG_ASSERT(pNewWin, "SdrPaintView::AddWindowToPaintView: No OutputDevice(!)");
632 	SdrPaintWindow* pNewPaintWindow = new SdrPaintWindow(*this, *pNewWin);
633 	AppendPaintWindow(*pNewPaintWindow);
634 
635 	if(mpPageView)
636 	{
637 		mpPageView->AddPaintWindowToPageView(*pNewPaintWindow);
638 	}
639 
640 #ifdef DBG_UTIL
641 	if (pItemBrowser!=NULL)
642 		pItemBrowser->ForceParent();
643 #endif
644 }
645 
DeleteWindowFromPaintView(OutputDevice * pOldWin)646 void SdrPaintView::DeleteWindowFromPaintView(OutputDevice* pOldWin)
647 {
648 	DBG_ASSERT(pOldWin, "SdrPaintView::DeleteWindowFromPaintView: No OutputDevice(!)");
649 	SdrPaintWindow* pCandidate = FindPaintWindow(*pOldWin);
650 
651 	if(pCandidate)
652 	{
653 		if(mpPageView)
654 		{
655 			mpPageView->RemovePaintWindowFromPageView(*pCandidate);
656 		}
657 
658 		RemovePaintWindow(*pCandidate);
659 		delete pCandidate;
660 	}
661 
662 #ifdef DBG_UTIL
663 	if (pItemBrowser!=NULL)
664 		pItemBrowser->ForceParent();
665 #endif
666 }
667 
SetLayerVisible(const XubString & rName,sal_Bool bShow)668 void SdrPaintView::SetLayerVisible(const XubString& rName, sal_Bool bShow)
669 {
670 	if(mpPageView)
671 	{
672 		mpPageView->SetLayerVisible(rName,bShow);
673 	}
674 
675 	InvalidateAllWin();
676 }
677 
IsLayerVisible(const XubString & rName) const678 bool SdrPaintView::IsLayerVisible(const XubString& rName) const
679 {
680 	if(mpPageView)
681 	{
682 		return mpPageView->IsLayerVisible(rName);
683 	}
684 
685 	return false;
686 }
687 
SetAllLayersVisible(sal_Bool bShow)688 void SdrPaintView::SetAllLayersVisible(sal_Bool bShow)
689 {
690 	if(mpPageView)
691 	{
692 		mpPageView->SetAllLayersVisible(bShow);
693 	}
694 
695 	InvalidateAllWin();
696 }
697 
SetLayerLocked(const XubString & rName,sal_Bool bLock)698 void SdrPaintView::SetLayerLocked(const XubString& rName, sal_Bool bLock)
699 {
700 	if(mpPageView)
701 	{
702 		mpPageView->SetLayerLocked(rName,bLock);
703 	}
704 }
705 
IsLayerLocked(const XubString & rName) const706 bool SdrPaintView::IsLayerLocked(const XubString& rName) const
707 {
708 	if(mpPageView)
709 	{
710 		return mpPageView->IsLayerLocked(rName);
711 	}
712 
713 	return false;
714 }
715 
SetAllLayersLocked(sal_Bool bLock)716 void SdrPaintView::SetAllLayersLocked(sal_Bool bLock)
717 {
718 	if(mpPageView)
719 	{
720 		mpPageView->SetAllLayersLocked(bLock);
721 	}
722 }
723 
SetLayerPrintable(const XubString & rName,sal_Bool bPrn)724 void SdrPaintView::SetLayerPrintable(const XubString& rName, sal_Bool bPrn)
725 {
726 	if(mpPageView)
727 	{
728 		mpPageView->SetLayerPrintable(rName,bPrn);
729 	}
730 }
731 
IsLayerPrintable(const XubString & rName) const732 bool SdrPaintView::IsLayerPrintable(const XubString& rName) const
733 {
734 	if(mpPageView)
735 	{
736 		return mpPageView->IsLayerPrintable(rName);
737 	}
738 
739 	return false;
740 }
741 
SetAllLayersPrintable(sal_Bool bPrn)742 void SdrPaintView::SetAllLayersPrintable(sal_Bool bPrn)
743 {
744 	if(mpPageView)
745 	{
746 		mpPageView->SetAllLayersPrintable(bPrn);
747 	}
748 }
749 
PrePaint()750 void SdrPaintView::PrePaint()
751 {
752 	if(mpPageView)
753 	{
754 		mpPageView->PrePaint();
755 	}
756 }
757 
PostPaint()758 void SdrPaintView::PostPaint()
759 {
760 	if(mpPageView)
761 	{
762 		mpPageView->PostPaint();
763 	}
764 }
765 
766 ////////////////////////////////////////////////////////////////////////////////////////////////////
767 // #define SVX_REPAINT_TIMER_TEST
768 
CompleteRedraw(OutputDevice * pOut,const Region & rReg,sdr::contact::ViewObjectContactRedirector * pRedirector)769 void SdrPaintView::CompleteRedraw(OutputDevice* pOut, const Region& rReg, sdr::contact::ViewObjectContactRedirector* pRedirector)
770 {
771 #ifdef SVX_REPAINT_TIMER_TEST
772 #define REMEMBERED_TIMES_COUNT	(10)
773 	static bool bDoTimerTest(false);
774 	static bool bTimesInited(false);
775 	static sal_uInt32 nRepeatCount(10L);
776 	static double fLastTimes[REMEMBERED_TIMES_COUNT];
777 	const sal_uInt32 nStartTime(Time::GetSystemTicks());
778 	sal_uInt32 count(1L);
779 	sal_uInt32 a;
780 
781 	if(bDoTimerTest)
782 	{
783 		count = nRepeatCount;
784 	}
785 
786 	for(a = 0L; a < count; a++)
787 	{
788 #endif // SVX_REPAINT_TIMER_TEST
789 
790 	// #i74769# check if pOut is a win and has a ClipRegion. If Yes, the Region
791 	// rReg may be made more granular (fine) with using it. Normally, rReg
792 	// does come from Window::Paint() anyways and thus is based on a single
793 	// rectangle which was derived from exactly that repaint region
794 	Region aOptimizedRepaintRegion(rReg);
795 
796 	if(pOut && OUTDEV_WINDOW == pOut->GetOutDevType())
797 	{
798 		Window* pWindow = (Window*)pOut;
799 
800 		if(pWindow->IsInPaint())
801 		{
802 			if(!pWindow->GetPaintRegion().IsEmpty())
803 			{
804 				aOptimizedRepaintRegion.Intersect(pWindow->GetPaintRegion());
805 
806 #ifdef DBG_UTIL
807 				// #i74769# test-paint repaint region
808 				static bool bDoPaintForVisualControl(false);
809 
810                 if(bDoPaintForVisualControl)
811 				{
812                     RectangleVector aRectangles;
813                     aOptimizedRepaintRegion.GetRegionRectangles(aRectangles);
814 
815                     pWindow->SetLineColor(COL_LIGHTGREEN);
816                     pWindow->SetFillColor();
817 
818                     for(RectangleVector::const_iterator aRectIter(aRectangles.begin()); aRectIter != aRectangles.end(); aRectIter++)
819                     {
820                         pWindow->DrawRect(*aRectIter);
821                     }
822 
823 					//RegionHandle aRegionHandle(aOptimizedRepaintRegion.BeginEnumRects());
824 					//Rectangle aRegionRectangle;
825 					//
826 					//while(aOptimizedRepaintRegion.GetEnumRects(aRegionHandle, aRegionRectangle))
827 					//{
828 					//	pWindow->SetLineColor(COL_LIGHTGREEN);
829 					//	pWindow->SetFillColor();
830 					//	pWindow->DrawRect(aRegionRectangle);
831 					//}
832                     //
833 					//aOptimizedRepaintRegion.EndEnumRects(aRegionHandle);
834 				}
835 #endif
836 			}
837 		}
838 	}
839 
840 	SdrPaintWindow* pPaintWindow = BeginCompleteRedraw(pOut);
841 	OSL_ENSURE(pPaintWindow, "SdrPaintView::CompleteRedraw: No OutDev (!)");
842 
843 	DoCompleteRedraw(*pPaintWindow, aOptimizedRepaintRegion, pRedirector);
844 	EndCompleteRedraw(*pPaintWindow, true);
845 
846 #ifdef SVX_REPAINT_TIMER_TEST
847 	}
848 
849 	if(bDoTimerTest)
850 	{
851 		const sal_uInt32 nStopTime(Time::GetSystemTicks());
852 		const sal_uInt32 nNeededTime(nStopTime - nStartTime);
853 		const double fTimePerPaint((double)nNeededTime / (double)nRepeatCount);
854 
855 		if(!bTimesInited)
856 		{
857 			for(a = 0L; a < REMEMBERED_TIMES_COUNT; a++)
858 			{
859 				fLastTimes[a] = fTimePerPaint;
860 			}
861 
862 			bTimesInited = true;
863 		}
864 		else
865 		{
866 			for(a = 1L; a < REMEMBERED_TIMES_COUNT; a++)
867 			{
868 				fLastTimes[a - 1L] = fLastTimes[a];
869 			}
870 
871 			fLastTimes[REMEMBERED_TIMES_COUNT - 1L] = fTimePerPaint;
872 		}
873 
874 		double fAddedTimes(0.0);
875 
876 		for(a = 0L; a < REMEMBERED_TIMES_COUNT; a++)
877 		{
878 			fAddedTimes += fLastTimes[a];
879 		}
880 
881 		const double fAverageTimePerPaint(fAddedTimes / (double)REMEMBERED_TIMES_COUNT);
882 
883 		fprintf(stderr, "-----------(start result)----------\n");
884 		fprintf(stderr, "StartTime : %u, StopTime: %u, NeededTime: %u, TimePerPaint: %f\n", nStartTime, nStopTime, nNeededTime, fTimePerPaint);
885 		fprintf(stderr, "Remembered times: ");
886 
887 		for(a = 0L; a < REMEMBERED_TIMES_COUNT; a++)
888 		{
889 			fprintf(stderr, "%d: %f ", a, fLastTimes[a]);
890 		}
891 
892 		fprintf(stderr, "\n");
893 		fprintf(stderr, "AverageTimePerPaint: %f\n", fAverageTimePerPaint);
894 		fprintf(stderr, "-----------(stop result)----------\n");
895 	}
896 #endif // SVX_REPAINT_TIMER_TEST
897 }
898 
899 ////////////////////////////////////////////////////////////////////////////////////////////////////
900 // #i72889#
901 
BeginCompleteRedraw(OutputDevice * pOut)902 SdrPaintWindow* SdrPaintView::BeginCompleteRedraw(OutputDevice* pOut)
903 {
904 	OSL_ENSURE(pOut, "SdrPaintView::BeginCompleteRedraw: No OutDev (!)");
905 	SdrPaintWindow* pPaintWindow = FindPaintWindow(*pOut);
906 
907 	if(pPaintWindow)
908 	{
909 		// draw preprocessing, only for known devices
910 		// prepare PreRendering
911 		pPaintWindow->PreparePreRenderDevice();
912 	}
913 	else
914 	{
915 		// None of the known OutputDevices is the target of this paint, use
916 		// a temporary SdrPaintWindow for this Redraw.
917 		pPaintWindow = new SdrPaintWindow(*this, *pOut);
918 		pPaintWindow->setTemporaryTarget(true);
919 	}
920 
921 	return pPaintWindow;
922 }
923 
DoCompleteRedraw(SdrPaintWindow & rPaintWindow,const Region & rReg,sdr::contact::ViewObjectContactRedirector * pRedirector)924 void SdrPaintView::DoCompleteRedraw(SdrPaintWindow& rPaintWindow, const Region& rReg, sdr::contact::ViewObjectContactRedirector* pRedirector)
925 {
926 	// redraw all PageViews with the target. This may expand the RedrawRegion
927 	// at the PaintWindow, plus taking care of FormLayer expansion
928 	if(mpPageView)
929 	{
930 		mpPageView->CompleteRedraw(rPaintWindow, rReg, pRedirector);
931 	}
932 }
933 
EndCompleteRedraw(SdrPaintWindow & rPaintWindow,bool bPaintFormLayer)934 void SdrPaintView::EndCompleteRedraw(SdrPaintWindow& rPaintWindow, bool bPaintFormLayer)
935 {
936 	if(rPaintWindow.getTemporaryTarget())
937 	{
938 		// get rid of temp target again
939 		delete (&rPaintWindow);
940 	}
941 	else
942 	{
943 		// draw postprocessing, only for known devices
944 		// it is necessary to always paint FormLayer
945         if(bPaintFormLayer)
946         {
947 		    ImpFormLayerDrawing(rPaintWindow);
948         }
949 
950 		// look for active TextEdit. As long as this cannot be painted to a VDev,
951 		// it cannot get part of buffering. In that case, output evtl. prerender
952 		// early and paint text edit to window.
953 		if(IsTextEdit() && GetSdrPageView())
954 		{
955 			static_cast< SdrView* >(this)->TextEditDrawing(rPaintWindow);
956 		}
957 
958 		// draw Overlay, also to PreRender device if exists
959 		rPaintWindow.DrawOverlay(rPaintWindow.GetRedrawRegion());
960 
961 		// output PreRendering
962 		rPaintWindow.OutputPreRenderDevice(rPaintWindow.GetRedrawRegion());
963 	}
964 }
965 
966 ////////////////////////////////////////////////////////////////////////////////////////////////////
967 
BeginDrawLayers(OutputDevice * pOut,const Region & rReg,bool bDisableIntersect)968 SdrPaintWindow* SdrPaintView::BeginDrawLayers(OutputDevice* pOut, const Region& rReg, bool bDisableIntersect)
969 {
970 	// #i74769# use BeginCompleteRedraw() as common base
971 	SdrPaintWindow* pPaintWindow = BeginCompleteRedraw(pOut);
972 	OSL_ENSURE(pPaintWindow, "SdrPaintView::BeginDrawLayers: No SdrPaintWindow (!)");
973 
974 	if(mpPageView)
975 	{
976 		SdrPageWindow* pKnownTarget = mpPageView->FindPageWindow(*pPaintWindow);
977 
978 		if(pKnownTarget)
979 		{
980 			// #i74769# check if pOut is a win and has a ClipRegion. If Yes, the Region
981 			// rReg may be made more granular (fine) with using it. Normally, rReg
982 			// does come from Window::Paint() anyways and thus is based on a single
983 			// rectangle which was derived from exactly that repaint region
984 			Region aOptimizedRepaintRegion(rReg);
985 
986 			// #i76114# Intersecting the region with the Window's paint region is disabled
987 			// for print preview in Calc, because the intersection can be empty (if the paint
988 			// region is outside of the table area of the page), and then no clip region
989 			// would be set.
990 			if(pOut && OUTDEV_WINDOW == pOut->GetOutDevType() && !bDisableIntersect)
991 			{
992 				Window* pWindow = (Window*)pOut;
993 
994 				if(pWindow->IsInPaint())
995 				{
996 					if(!pWindow->GetPaintRegion().IsEmpty())
997 					{
998 						aOptimizedRepaintRegion.Intersect(pWindow->GetPaintRegion());
999 
1000 #ifdef DBG_UTIL
1001 						// #i74769# test-paint repaint region
1002 						static bool bDoPaintForVisualControl(false);
1003 
1004                         if(bDoPaintForVisualControl)
1005 						{
1006                             RectangleVector aRectangles;
1007                             aOptimizedRepaintRegion.GetRegionRectangles(aRectangles);
1008 
1009                             pWindow->SetLineColor(COL_LIGHTGREEN);
1010                             pWindow->SetFillColor();
1011 
1012                             for(RectangleVector::const_iterator aRectIter(aRectangles.begin()); aRectIter != aRectangles.end(); aRectIter++)
1013                             {
1014                                 pWindow->DrawRect(*aRectIter);
1015                             }
1016 
1017 							//RegionHandle aRegionHandle(aOptimizedRepaintRegion.BeginEnumRects());
1018 							//Rectangle aRegionRectangle;
1019 							//
1020 							//while(aOptimizedRepaintRegion.GetEnumRects(aRegionHandle, aRegionRectangle))
1021 							//{
1022 							//	pWindow->SetLineColor(COL_LIGHTGREEN);
1023 							//	pWindow->SetFillColor();
1024 							//	pWindow->DrawRect(aRegionRectangle);
1025 							//}
1026                             //
1027 							//aOptimizedRepaintRegion.EndEnumRects(aRegionHandle);
1028 						}
1029 #endif
1030 					}
1031 				}
1032 			}
1033 
1034 			// prepare redraw
1035 			pKnownTarget->PrepareRedraw(aOptimizedRepaintRegion);
1036 
1037 			// remember prepared SdrPageWindow
1038 			mpPageView->setPreparedPageWindow(pKnownTarget);
1039 		}
1040 	}
1041 
1042 	return pPaintWindow;
1043 }
1044 
EndDrawLayers(SdrPaintWindow & rPaintWindow,bool bPaintFormLayer)1045 void SdrPaintView::EndDrawLayers(SdrPaintWindow& rPaintWindow, bool bPaintFormLayer)
1046 {
1047 	// #i74769# use EndCompleteRedraw() as common base
1048 	EndCompleteRedraw(rPaintWindow, bPaintFormLayer);
1049 
1050 	if(mpPageView)
1051 	{
1052 		// forget prepared SdrPageWindow
1053 		mpPageView->setPreparedPageWindow(0);
1054 	}
1055 }
1056 
1057 ////////////////////////////////////////////////////////////////////////////////////////////////////
1058 
ImpFormLayerDrawing(SdrPaintWindow & rPaintWindow) const1059 void SdrPaintView::ImpFormLayerDrawing(SdrPaintWindow& rPaintWindow) const
1060 {
1061 	if(mpPageView)
1062 	{
1063 		SdrPageWindow* pKnownTarget = mpPageView->FindPageWindow(rPaintWindow);
1064 
1065 		if(pKnownTarget)
1066 		{
1067 			const SdrModel& rModel = *(GetModel());
1068 			const SdrLayerAdmin& rLayerAdmin = rModel.GetLayerAdmin();
1069 			const SdrLayerID nControlLayerId = rLayerAdmin.GetLayerID(rLayerAdmin.GetControlLayerName(), sal_False);
1070 
1071 			// BUFFERED use GetTargetOutputDevice() now, it may be targeted to VDevs, too
1072 			// need to set PreparedPageWindow to make DrawLayer use the correct ObjectContact
1073 			mpPageView->setPreparedPageWindow(pKnownTarget);
1074 			mpPageView->DrawLayer(nControlLayerId, &rPaintWindow.GetTargetOutputDevice());
1075 			mpPageView->setPreparedPageWindow(0);
1076 		}
1077 	}
1078 }
1079 
1080 ////////////////////////////////////////////////////////////////////////////////////////////////////
1081 
KeyInput(const KeyEvent &,Window *)1082 sal_Bool SdrPaintView::KeyInput(const KeyEvent& /*rKEvt*/, Window* /*pWin*/)
1083 {
1084 	return sal_False;
1085 }
1086 
GlueInvalidate() const1087 void SdrPaintView::GlueInvalidate() const
1088 {
1089 	const sal_uInt32 nWindowCount(PaintWindowCount());
1090 
1091 	for(sal_uInt32 nWinNum(0L); nWinNum < nWindowCount; nWinNum++)
1092 	{
1093 		SdrPaintWindow* pPaintWindow = GetPaintWindow(nWinNum);
1094 
1095 		if(pPaintWindow->OutputToWindow())
1096 		{
1097 			OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
1098 
1099 			if(mpPageView)
1100 			{
1101 				const SdrObjList* pOL=mpPageView->GetObjList();
1102 				sal_uIntPtr nObjAnz=pOL->GetObjCount();
1103 				for (sal_uIntPtr nObjNum=0; nObjNum<nObjAnz; nObjNum++) {
1104 					const SdrObject* pObj=pOL->GetObj(nObjNum);
1105 					const SdrGluePointList* pGPL=pObj->GetGluePointList();
1106 					if (pGPL!=NULL && pGPL->GetCount()!=0) {
1107 						pGPL->Invalidate((Window&)rOutDev, pObj);
1108 					}
1109 				}
1110 			}
1111 		}
1112 	}
1113 }
1114 
InvalidateAllWin()1115 void SdrPaintView::InvalidateAllWin()
1116 {
1117 	const sal_uInt32 nWindowCount(PaintWindowCount());
1118 
1119 	for(sal_uInt32 a(0L); a < nWindowCount; a++)
1120 	{
1121 		SdrPaintWindow* pPaintWindow = GetPaintWindow(a);
1122 
1123 		if(pPaintWindow->OutputToWindow())
1124 		{
1125 			InvalidateOneWin((Window&)pPaintWindow->GetOutputDevice());
1126 		}
1127 	}
1128 }
1129 
InvalidateAllWin(const Rectangle & rRect,sal_Bool bPlus1Pix)1130 void SdrPaintView::InvalidateAllWin(const Rectangle& rRect, sal_Bool bPlus1Pix)
1131 {
1132 	const sal_uInt32 nWindowCount(PaintWindowCount());
1133 
1134 	for(sal_uInt32 a(0L); a < nWindowCount; a++)
1135 	{
1136 		SdrPaintWindow* pPaintWindow = GetPaintWindow(a);
1137 
1138 		if(pPaintWindow->OutputToWindow())
1139 		{
1140 			OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
1141 			Rectangle aRect(rRect);
1142 
1143 			if(bPlus1Pix)
1144 			{
1145 				Size aPixSiz(1,1);
1146 				Size aSiz(rOutDev.PixelToLogic(aPixSiz));
1147 				aRect.Left	()-=aSiz.Width();
1148 				aRect.Top	()-=aSiz.Height();
1149 				aRect.Right ()+=aSiz.Width();
1150 				aRect.Bottom()+=aSiz.Height();
1151 			}
1152 
1153 			Point aOrg(rOutDev.GetMapMode().GetOrigin());
1154 			aOrg.X()=-aOrg.X(); aOrg.Y()=-aOrg.Y();
1155 			Rectangle aOutRect(aOrg, rOutDev.GetOutputSize());
1156 
1157 			if (aRect.IsOver(aOutRect))
1158 			{
1159 				InvalidateOneWin((Window&)rOutDev, aRect);
1160 			}
1161 		}
1162 	}
1163 }
1164 
InvalidateOneWin(Window & rWin)1165 void SdrPaintView::InvalidateOneWin(Window& rWin)
1166 {
1167 	// #111096#
1168 	// do not erase background, that causes flicker (!)
1169 	rWin.Invalidate(INVALIDATE_NOERASE);
1170 }
1171 
InvalidateOneWin(Window & rWin,const Rectangle & rRect)1172 void SdrPaintView::InvalidateOneWin(Window& rWin, const Rectangle& rRect)
1173 {
1174 	// #111096#
1175 	// do not erase background, that causes flicker (!)
1176 	rWin.Invalidate(rRect, INVALIDATE_NOERASE);
1177 }
1178 
LeaveOneGroup()1179 void SdrPaintView::LeaveOneGroup()
1180 {
1181 	if(mpPageView)
1182 	{
1183 		mpPageView->LeaveOneGroup();
1184 	}
1185 }
1186 
LeaveAllGroup()1187 void SdrPaintView::LeaveAllGroup()
1188 {
1189 	if(mpPageView)
1190 	{
1191 		mpPageView->LeaveAllGroup();
1192 	}
1193 }
1194 
IsGroupEntered() const1195 bool SdrPaintView::IsGroupEntered() const
1196 {
1197 	if(mpPageView)
1198 	{
1199 		return (mpPageView->GetEnteredLevel() != 0);
1200 	}
1201 
1202 	return false;
1203 }
1204 
SetNotPersistDefaultAttr(const SfxItemSet & rAttr,sal_Bool)1205 void SdrPaintView::SetNotPersistDefaultAttr(const SfxItemSet& rAttr, sal_Bool /*bReplaceAll*/)
1206 {
1207 	// bReplaceAll hat hier keinerlei Wirkung
1208 	sal_Bool bMeasure=ISA(SdrView) && ((SdrView*)this)->IsMeasureTool();
1209 	const SfxPoolItem *pPoolItem=NULL;
1210 	if (rAttr.GetItemState(SDRATTR_LAYERID,sal_True,&pPoolItem)==SFX_ITEM_SET) {
1211 		SdrLayerID nLayerId=((const SdrLayerIdItem*)pPoolItem)->GetValue();
1212 		const SdrLayer* pLayer=pMod->GetLayerAdmin().GetLayerPerID(nLayerId);
1213 		if (pLayer!=NULL) {
1214 			if (bMeasure) aMeasureLayer=pLayer->GetName();
1215 			else aAktLayer=pLayer->GetName();
1216 		}
1217 	}
1218 	if (rAttr.GetItemState(SDRATTR_LAYERNAME,sal_True,&pPoolItem)==SFX_ITEM_SET) {
1219 		if (bMeasure) aMeasureLayer=((const SdrLayerNameItem*)pPoolItem)->GetValue();
1220 		else aAktLayer=((const SdrLayerNameItem*)pPoolItem)->GetValue();
1221 	}
1222 }
1223 
MergeNotPersistDefaultAttr(SfxItemSet & rAttr,sal_Bool) const1224 void SdrPaintView::MergeNotPersistDefaultAttr(SfxItemSet& rAttr, sal_Bool /*bOnlyHardAttr*/) const
1225 {
1226 	// bOnlyHardAttr hat hier keinerlei Wirkung
1227 	sal_Bool bMeasure=ISA(SdrView) && ((SdrView*)this)->IsMeasureTool();
1228 	const XubString& aNam=bMeasure?aMeasureLayer:aAktLayer;
1229 	rAttr.Put(SdrLayerNameItem(aNam));
1230 	SdrLayerID nLayer=pMod->GetLayerAdmin().GetLayerID(aNam,sal_True);
1231 	if (nLayer!=SDRLAYER_NOTFOUND) {
1232 		rAttr.Put(SdrLayerIdItem(nLayer));
1233 	}
1234 }
1235 
SetDefaultAttr(const SfxItemSet & rAttr,sal_Bool bReplaceAll)1236 void SdrPaintView::SetDefaultAttr(const SfxItemSet& rAttr, sal_Bool bReplaceAll)
1237 {
1238 #ifdef DBG_UTIL
1239 	{
1240 		sal_Bool bHasEEFeatureItems=sal_False;
1241 		SfxItemIter aIter(rAttr);
1242 		const SfxPoolItem* pItem=aIter.FirstItem();
1243 		while (!bHasEEFeatureItems && pItem!=NULL) {
1244 			if (!IsInvalidItem(pItem)) {
1245 				sal_uInt16 nW=pItem->Which();
1246 				if (nW>=EE_FEATURE_START && nW<=EE_FEATURE_END) bHasEEFeatureItems=sal_True;
1247 			}
1248 			pItem=aIter.NextItem();
1249 		}
1250 
1251 		if(bHasEEFeatureItems)
1252 		{
1253 			String aMessage;
1254 			aMessage.AppendAscii("SdrPaintView::SetDefaultAttr(): Das setzen von EE_FEATURE-Items an der SdrView macht keinen Sinn! Es fuehrt nur zu Overhead und nicht mehr lesbaren Dokumenten.");
1255 			InfoBox(NULL, aMessage).Execute();
1256 		}
1257 	}
1258 #endif
1259 	if (bReplaceAll) aDefaultAttr.Set(rAttr);
1260 	else aDefaultAttr.Put(rAttr,sal_False); // FALSE= InvalidItems nicht als Default, sondern als "Loecher" betrachten
1261 	SetNotPersistDefaultAttr(rAttr,bReplaceAll);
1262 #ifdef DBG_UTIL
1263 	if (pItemBrowser!=NULL) pItemBrowser->SetDirty();
1264 #endif
1265 }
1266 
SetDefaultStyleSheet(SfxStyleSheet * pStyleSheet,sal_Bool bDontRemoveHardAttr)1267 void SdrPaintView::SetDefaultStyleSheet(SfxStyleSheet* pStyleSheet, sal_Bool bDontRemoveHardAttr)
1268 {
1269 	if (pDefaultStyleSheet)
1270         EndListening(*pDefaultStyleSheet);
1271     pDefaultStyleSheet=pStyleSheet;
1272     if (pDefaultStyleSheet)
1273         StartListening(*pDefaultStyleSheet);
1274 
1275 	if (pStyleSheet!=NULL && !bDontRemoveHardAttr) {
1276 		SfxWhichIter aIter(pStyleSheet->GetItemSet());
1277 		sal_uInt16 nWhich=aIter.FirstWhich();
1278 		while (nWhich!=0) {
1279 			if (pStyleSheet->GetItemSet().GetItemState(nWhich,sal_True)==SFX_ITEM_SET) {
1280 				aDefaultAttr.ClearItem(nWhich);
1281 			}
1282 			nWhich=aIter.NextWhich();
1283 		}
1284 	}
1285 #ifdef DBG_UTIL
1286 	if (pItemBrowser!=NULL) pItemBrowser->SetDirty();
1287 #endif
1288 }
1289 
1290 /* new interface src537 */
GetAttributes(SfxItemSet & rTargetSet,sal_Bool bOnlyHardAttr) const1291 sal_Bool SdrPaintView::GetAttributes(SfxItemSet& rTargetSet, sal_Bool bOnlyHardAttr) const
1292 {
1293 	if(bOnlyHardAttr || !pDefaultStyleSheet)
1294 	{
1295 		rTargetSet.Put(aDefaultAttr, sal_False);
1296 	}
1297 	else
1298 	{
1299 		// sonst DefStyleSheet dazumergen
1300 		rTargetSet.Put(pDefaultStyleSheet->GetItemSet(), sal_False);
1301 		rTargetSet.Put(aDefaultAttr, sal_False);
1302 	}
1303 	MergeNotPersistDefaultAttr(rTargetSet, bOnlyHardAttr);
1304 	return sal_True;
1305 }
1306 
SetAttributes(const SfxItemSet & rSet,sal_Bool bReplaceAll)1307 sal_Bool SdrPaintView::SetAttributes(const SfxItemSet& rSet, sal_Bool bReplaceAll)
1308 {
1309 	SetDefaultAttr(rSet,bReplaceAll);
1310 	return sal_True;
1311 }
1312 
GetStyleSheet() const1313 SfxStyleSheet* SdrPaintView::GetStyleSheet() const // SfxStyleSheet* SdrPaintView::GetStyleSheet(sal_Bool& rOk) const
1314 {
1315 	//rOk=sal_True;
1316 	return GetDefaultStyleSheet();
1317 }
1318 
SetStyleSheet(SfxStyleSheet * pStyleSheet,sal_Bool bDontRemoveHardAttr)1319 sal_Bool SdrPaintView::SetStyleSheet(SfxStyleSheet* pStyleSheet, sal_Bool bDontRemoveHardAttr)
1320 {
1321 	SetDefaultStyleSheet(pStyleSheet,bDontRemoveHardAttr);
1322 	return sal_True;
1323 }
1324 
1325 ////////////////////////////////////////////////////////////////////////////////////////////////////
1326 
1327 #ifdef DBG_UTIL
ShowItemBrowser(sal_Bool bShow)1328 void SdrPaintView::ShowItemBrowser(sal_Bool bShow)
1329 {
1330 	if (bShow) {
1331 		if (pItemBrowser==NULL) {
1332 			pItemBrowser=new SdrItemBrowser(*(SdrView*)this);
1333 			pItemBrowser->SetFloatingMode(sal_True);
1334 		}
1335 		pItemBrowser->Show();
1336 		pItemBrowser->GrabFocus();
1337 	} else {
1338 		if (pItemBrowser!=NULL) {
1339 			pItemBrowser->Hide();
1340 			delete pItemBrowser;
1341 			pItemBrowser=NULL;
1342 		}
1343 	}
1344 }
1345 #endif
1346 
MakeVisible(const Rectangle & rRect,Window & rWin)1347 void SdrPaintView::MakeVisible(const Rectangle& rRect, Window& rWin)
1348 {
1349 	MapMode aMap(rWin.GetMapMode());
1350 	Size aActualSize(rWin.GetOutputSize());
1351 
1352 	if( aActualSize.Height() > 0 && aActualSize.Width() > 0 )
1353 	{
1354 		Size aNewSize(rRect.GetSize());
1355 		sal_Bool bNewScale=sal_False;
1356 		sal_Bool bNeedMoreX=aNewSize.Width()>aActualSize.Width();
1357 		sal_Bool bNeedMoreY=aNewSize.Height()>aActualSize.Height();
1358 		if (bNeedMoreX || bNeedMoreY)
1359 		{
1360 			bNewScale=sal_True;
1361 			// Neuen MapMode (Size+Org) setzen und dabei alles invalidieren
1362 			Fraction aXFact(aNewSize.Width(),aActualSize.Width());
1363 			Fraction aYFact(aNewSize.Height(),aActualSize.Height());
1364 			if (aYFact>aXFact) aXFact=aYFact;
1365 			aXFact*=aMap.GetScaleX();
1366 			aXFact.ReduceInaccurate(10); // Um Ueberlaeufe und BigInt-Mapping zu vermeiden
1367 			aMap.SetScaleX(aXFact);
1368 			aMap.SetScaleY(aYFact);
1369 			rWin.SetMapMode(aMap);
1370 			aActualSize=rWin.GetOutputSize();
1371 		}
1372 		Point aOrg(aMap.GetOrigin());
1373 		long dx=0,dy=0;
1374 		long l=-aOrg.X();
1375 		long r=-aOrg.X()+aActualSize.Width()-1;
1376 		long o=-aOrg.Y();
1377 		long u=-aOrg.Y()+aActualSize.Height()-1;
1378 		if (l>rRect.Left()) dx=rRect.Left()-l;
1379 		else if (r<rRect.Right()) dx=rRect.Right()-r;
1380 		if (o>rRect.Top()) dy=rRect.Top()-o;
1381 		else if (u<rRect.Bottom()) dy=rRect.Bottom()-u;
1382 		aMap.SetOrigin(Point(aOrg.X()-dx,aOrg.Y()-dy));
1383 		if (!bNewScale) {
1384 			if (dx!=0 || dy!=0) {
1385 				rWin.Scroll(-dx,-dy);
1386 				rWin.SetMapMode(aMap);
1387 				rWin.Update();
1388 			}
1389 		} else {
1390 			rWin.SetMapMode(aMap);
1391 			InvalidateOneWin(rWin);
1392 		}
1393 	}
1394 }
1395 
DoConnect(SdrOle2Obj *)1396 void SdrPaintView::DoConnect(SdrOle2Obj* /*pOleObj*/)
1397 {
1398 }
1399 
SetAnimationEnabled(sal_Bool bEnable)1400 void SdrPaintView::SetAnimationEnabled( sal_Bool bEnable )
1401 {
1402 	SetAnimationMode( bEnable ? SDR_ANIMATION_ANIMATE : SDR_ANIMATION_DISABLE );
1403 }
1404 
SetAnimationPause(bool bSet)1405 void SdrPaintView::SetAnimationPause( bool bSet )
1406 {
1407 	if((bool)bAnimationPause != bSet)
1408 	{
1409 		bAnimationPause = bSet;
1410 
1411 		if(mpPageView)
1412 		{
1413 			for(sal_uInt32 b(0L); b < mpPageView->PageWindowCount(); b++)
1414 			{
1415 				const SdrPageWindow& rPageWindow = *(mpPageView->GetPageWindow(b));
1416 				sdr::contact::ObjectContact& rObjectContact = rPageWindow.GetObjectContact();
1417 				sdr::animation::primitiveAnimator& rAnimator = rObjectContact.getPrimitiveAnimator();
1418 
1419 				if(rAnimator.IsPaused() != bSet)
1420 				{
1421 					rAnimator.SetPaused(bSet);
1422 				}
1423 			}
1424 		}
1425 	}
1426 }
1427 
SetAnimationMode(const SdrAnimationMode eMode)1428 void SdrPaintView::SetAnimationMode( const SdrAnimationMode eMode )
1429 {
1430 	eAnimationMode = eMode;
1431 }
1432 
VisAreaChanged(const OutputDevice * pOut)1433 void SdrPaintView::VisAreaChanged(const OutputDevice* pOut)
1434 {
1435 	if(mpPageView)
1436 	{
1437 		if (pOut)
1438 		{
1439 			SdrPageWindow* pWindow = mpPageView->FindPageWindow(*((OutputDevice*)pOut));
1440 
1441 			if(pWindow)
1442 			{
1443 				VisAreaChanged(*pWindow);
1444 			}
1445 		}
1446 		else
1447 		{
1448 			for(sal_uInt32 a(0L); a < mpPageView->PageWindowCount(); a++)
1449 			{
1450 				VisAreaChanged(*mpPageView->GetPageWindow(a));
1451 			}
1452 		}
1453 	}
1454 }
1455 
VisAreaChanged(const SdrPageWindow &)1456 void SdrPaintView::VisAreaChanged(const SdrPageWindow& /*rWindow*/)
1457 {
1458     // notify SfxListener
1459     Broadcast(SvxViewHint(SvxViewHint::SVX_HINT_VIEWCHANGED));
1460 }
1461 
getColorConfig() const1462 const svtools::ColorConfig& SdrPaintView::getColorConfig() const
1463 {
1464 	return maColorConfig;
1465 }
1466 
onChangeColorConfig()1467 void SdrPaintView::onChangeColorConfig()
1468 {
1469     SetGridColor( Color( maColorConfig.GetColorValue( svtools::DRAWGRID ).nColor ) );
1470 }
1471 
SetGridColor(Color aColor)1472 void SdrPaintView::SetGridColor( Color aColor )
1473 {
1474 	maGridColor = aColor;
1475 }
1476 
GetGridColor() const1477 Color SdrPaintView::GetGridColor() const
1478 {
1479 	return maGridColor;
1480 }
1481 
1482 // #103834# Set background color for svx at SdrPageViews
SetApplicationBackgroundColor(Color aBackgroundColor)1483 void SdrPaintView::SetApplicationBackgroundColor(Color aBackgroundColor)
1484 {
1485 	if(mpPageView)
1486 	{
1487 		mpPageView->SetApplicationBackgroundColor(aBackgroundColor);
1488 	}
1489 }
1490 
1491 // #103911# Set document color for svx at SdrPageViews
SetApplicationDocumentColor(Color aDocumentColor)1492 void SdrPaintView::SetApplicationDocumentColor(Color aDocumentColor)
1493 {
1494 	if(mpPageView)
1495 	{
1496 		mpPageView->SetApplicationDocumentColor(aDocumentColor);
1497 	}
1498 }
1499 
1500 // #114898#
IsBufferedOutputAllowed() const1501 bool SdrPaintView::IsBufferedOutputAllowed() const
1502 {
1503 	return (mbBufferedOutputAllowed && maDrawinglayerOpt.IsPaintBuffer());
1504 }
1505 
1506 // #114898#
SetBufferedOutputAllowed(bool bNew)1507 void SdrPaintView::SetBufferedOutputAllowed(bool bNew)
1508 {
1509 	if(bNew != (bool)mbBufferedOutputAllowed)
1510 	{
1511 		mbBufferedOutputAllowed = bNew;
1512 	}
1513 }
1514 
IsBufferedOverlayAllowed() const1515 bool SdrPaintView::IsBufferedOverlayAllowed() const
1516 {
1517 	return (mbBufferedOverlayAllowed && maDrawinglayerOpt.IsOverlayBuffer());
1518 }
1519 
SetBufferedOverlayAllowed(bool bNew)1520 void SdrPaintView::SetBufferedOverlayAllowed(bool bNew)
1521 {
1522 	if(bNew != (bool)mbBufferedOverlayAllowed)
1523 	{
1524 		mbBufferedOverlayAllowed = bNew;
1525 	}
1526 }
1527 
IsPagePaintingAllowed() const1528 sal_Bool SdrPaintView::IsPagePaintingAllowed() const
1529 {
1530 	return mbPagePaintingAllowed;
1531 }
1532 
SetPagePaintingAllowed(bool bNew)1533 void SdrPaintView::SetPagePaintingAllowed(bool bNew)
1534 {
1535 	if(bNew != (bool)mbPagePaintingAllowed)
1536 	{
1537 		mbPagePaintingAllowed = bNew;
1538 	}
1539 }
1540 
1541 // #i38135# Sets the timer for Object animations and restarts.
SetAnimationTimer(sal_uInt32 nTime)1542 void SdrPaintView::SetAnimationTimer(sal_uInt32 nTime)
1543 {
1544 	if(mpPageView)
1545 	{
1546 		// first, reset all timers at all windows to 0L
1547 		for(sal_uInt32 a(0L); a < mpPageView->PageWindowCount(); a++)
1548 		{
1549 			const SdrPageWindow& rPageWindow = *mpPageView->GetPageWindow(a);
1550 			sdr::contact::ObjectContact& rObjectContact = rPageWindow.GetObjectContact();
1551 			sdr::animation::primitiveAnimator& rAnimator = rObjectContact.getPrimitiveAnimator();
1552 			rAnimator.SetTime(nTime);
1553 		}
1554 	}
1555 }
1556 
1557 // eof
1558