xref: /aoo42x/main/svx/source/svdraw/svdetc.cxx (revision 87bc88d3)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f6e50924SAndrew Rist  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19f6e50924SAndrew Rist  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include "editeng/forbiddencharacterstable.hxx"
27cdf0e10cSrcweir #include <com/sun/star/embed/XEmbeddedObject.hpp>
28cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp>
29cdf0e10cSrcweir #include <svx/svdetc.hxx>
30cdf0e10cSrcweir #include "svx/svditext.hxx"
31cdf0e10cSrcweir #include <svx/svdmodel.hxx>
32cdf0e10cSrcweir #include <svx/svdtrans.hxx>
33cdf0e10cSrcweir #include "svx/svdglob.hxx"
34cdf0e10cSrcweir #include "svx/svdstr.hrc"
35cdf0e10cSrcweir #include "svx/svdviter.hxx"
36cdf0e10cSrcweir #include <svx/svdview.hxx>
37cdf0e10cSrcweir #include <svx/svdoutl.hxx>
38cdf0e10cSrcweir #include <vcl/bmpacc.hxx>
39cdf0e10cSrcweir #include <editeng/eeitem.hxx>
40cdf0e10cSrcweir #include <svl/itemset.hxx>
41cdf0e10cSrcweir #include <tools/config.hxx>
42cdf0e10cSrcweir #include <unotools/cacheoptions.hxx>
43cdf0e10cSrcweir #include <svl/whiter.hxx>
44cdf0e10cSrcweir #include <tools/bigint.hxx>
45cdf0e10cSrcweir #include "editeng/fontitem.hxx"
46cdf0e10cSrcweir #include <editeng/colritem.hxx>
47cdf0e10cSrcweir #include <editeng/fhgtitem.hxx>
48cdf0e10cSrcweir #include <svx/xgrad.hxx>
49cdf0e10cSrcweir #include <svx/xfillit0.hxx>
50cdf0e10cSrcweir #include <svx/xflclit.hxx>
51cdf0e10cSrcweir #include <svx/xflhtit.hxx>
52cdf0e10cSrcweir #include <svx/xbtmpit.hxx>
53cdf0e10cSrcweir #include <svx/xflgrit.hxx>
54cdf0e10cSrcweir #include <svx/svdoole2.hxx>
55cdf0e10cSrcweir #include <svl/itempool.hxx>
56cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx>
57cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
58cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
59cdf0e10cSrcweir #include <i18npool/lang.h>
60cdf0e10cSrcweir #include <unotools/charclass.hxx>
61cdf0e10cSrcweir #include <unotools/syslocale.hxx>
62cdf0e10cSrcweir #include <svx/xflbckit.hxx>
63cdf0e10cSrcweir #include <svx/extrusionbar.hxx>
64cdf0e10cSrcweir #include <svx/fontworkbar.hxx>
65cdf0e10cSrcweir #include <vcl/svapp.hxx> //add CHINA001
66cdf0e10cSrcweir #include <svx/sdr/contact/viewcontact.hxx>
67cdf0e10cSrcweir #include <svx/svdpage.hxx>
68cdf0e10cSrcweir #include <svx/svdotable.hxx>
69cdf0e10cSrcweir #include <svx/sdrhittesthelper.hxx>
70cdf0e10cSrcweir 
71cdf0e10cSrcweir using namespace ::com::sun::star;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir /******************************************************************************
74cdf0e10cSrcweir * Globale Daten der DrawingEngine
75cdf0e10cSrcweir ******************************************************************************/
76cdf0e10cSrcweir 
SdrGlobalData()77cdf0e10cSrcweir SdrGlobalData::SdrGlobalData() :
78cdf0e10cSrcweir     pSysLocale(NULL),
79cdf0e10cSrcweir     pCharClass(NULL),
80cdf0e10cSrcweir     pLocaleData(NULL),
81cdf0e10cSrcweir 	pOutliner(NULL),
82cdf0e10cSrcweir 	pDefaults(NULL),
83cdf0e10cSrcweir 	pResMgr(NULL),
84cdf0e10cSrcweir 	nExchangeFormat(0)
85cdf0e10cSrcweir {
86cdf0e10cSrcweir     //pSysLocale = new SvtSysLocale;
87cdf0e10cSrcweir     //pCharClass = pSysLocale->GetCharClassPtr();
88cdf0e10cSrcweir     //pLocaleData = pSysLocale->GetLocaleDataPtr();
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	svx::ExtrusionBar::RegisterInterface();
91cdf0e10cSrcweir 	svx::FontworkBar::RegisterInterface();
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
~SdrGlobalData()94cdf0e10cSrcweir SdrGlobalData::~SdrGlobalData()
95cdf0e10cSrcweir {
96cdf0e10cSrcweir 	delete pOutliner;
97cdf0e10cSrcweir 	delete pDefaults;
98cdf0e10cSrcweir 	delete pResMgr;
99cdf0e10cSrcweir     //! do NOT delete pCharClass and pLocaleData
100cdf0e10cSrcweir     delete pSysLocale;
101cdf0e10cSrcweir }
GetSysLocale()102cdf0e10cSrcweir const SvtSysLocale*         SdrGlobalData::GetSysLocale()
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     if ( !pSysLocale )
105cdf0e10cSrcweir         pSysLocale = new SvtSysLocale;
106cdf0e10cSrcweir     return pSysLocale;
107cdf0e10cSrcweir }
GetCharClass()108cdf0e10cSrcweir const CharClass*            SdrGlobalData::GetCharClass()
109cdf0e10cSrcweir {
110cdf0e10cSrcweir     if ( !pCharClass )
111cdf0e10cSrcweir         pCharClass = GetSysLocale()->GetCharClassPtr();
112cdf0e10cSrcweir     return pCharClass;
113cdf0e10cSrcweir }
GetLocaleData()114cdf0e10cSrcweir const LocaleDataWrapper*    SdrGlobalData::GetLocaleData()
115cdf0e10cSrcweir {
116cdf0e10cSrcweir     if ( !pLocaleData )
117cdf0e10cSrcweir         pLocaleData = GetSysLocale()->GetLocaleDataPtr();
118cdf0e10cSrcweir     return pLocaleData;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
121cdf0e10cSrcweir 
OLEObjCache()122cdf0e10cSrcweir OLEObjCache::OLEObjCache()
123cdf0e10cSrcweir :	Container( 0 )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir 	SvtCacheOptions aCacheOptions;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	nSize = aCacheOptions.GetDrawingEngineOLE_Objects();
128cdf0e10cSrcweir 	pTimer = new AutoTimer();
129cdf0e10cSrcweir     Link aLink = LINK(this, OLEObjCache, UnloadCheckHdl);
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     pTimer->SetTimeoutHdl(aLink);
132cdf0e10cSrcweir     pTimer->SetTimeout(20000);
133cdf0e10cSrcweir     pTimer->Start();
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	aLink.Call(pTimer);
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
~OLEObjCache()138cdf0e10cSrcweir OLEObjCache::~OLEObjCache()
139cdf0e10cSrcweir {
140cdf0e10cSrcweir 	pTimer->Stop();
141cdf0e10cSrcweir 	delete pTimer;
142cdf0e10cSrcweir }
143cdf0e10cSrcweir 
UnloadOnDemand()144cdf0e10cSrcweir void OLEObjCache::UnloadOnDemand()
145cdf0e10cSrcweir {
146cdf0e10cSrcweir     if ( nSize < Count() )
147cdf0e10cSrcweir 	{
148cdf0e10cSrcweir         // more objects than configured cache size try to remove objects
149cdf0e10cSrcweir         // of course not the freshly inserted one at nIndex=0
150cdf0e10cSrcweir         sal_uIntPtr nCount2 = Count();
151cdf0e10cSrcweir         sal_uIntPtr nIndex = nCount2-1;
152cdf0e10cSrcweir         while( nIndex && nCount2 > nSize )
153cdf0e10cSrcweir 		{
154cdf0e10cSrcweir             SdrOle2Obj* pUnloadObj = (SdrOle2Obj*) GetObject(nIndex--);
155cdf0e10cSrcweir             if ( pUnloadObj )
156cdf0e10cSrcweir             {
157cdf0e10cSrcweir                 try
158cdf0e10cSrcweir                 {
159cdf0e10cSrcweir                     // it is important to get object without reinitialization to avoid reentrance
160cdf0e10cSrcweir                     uno::Reference< embed::XEmbeddedObject > xUnloadObj = pUnloadObj->GetObjRef_NoInit();
161cdf0e10cSrcweir 
162cdf0e10cSrcweir                     sal_Bool bUnload = SdrOle2Obj::CanUnloadRunningObj( xUnloadObj, pUnloadObj->GetAspect() );
163cdf0e10cSrcweir 
164cdf0e10cSrcweir                     // check whether the object can be unloaded before looking for the parent objects
165cdf0e10cSrcweir                     if ( xUnloadObj.is() && bUnload )
166cdf0e10cSrcweir                     {
167cdf0e10cSrcweir                         uno::Reference< frame::XModel > xUnloadModel( xUnloadObj->getComponent(), uno::UNO_QUERY );
168cdf0e10cSrcweir                         if ( xUnloadModel.is() )
169cdf0e10cSrcweir                         {
170cdf0e10cSrcweir                             for ( sal_uIntPtr nCheckInd = 0; nCheckInd < Count(); nCheckInd++ )
171cdf0e10cSrcweir                             {
172cdf0e10cSrcweir                                 SdrOle2Obj* pCacheObj = (SdrOle2Obj*) GetObject(nCheckInd);
173cdf0e10cSrcweir                                 if ( pCacheObj && pCacheObj != pUnloadObj )
174cdf0e10cSrcweir                                 {
175cdf0e10cSrcweir                                     uno::Reference< frame::XModel > xParentModel = pCacheObj->GetParentXModel();
176cdf0e10cSrcweir                                     if ( xUnloadModel == xParentModel )
177cdf0e10cSrcweir                                         bUnload = sal_False; // the object has running embedded objects
178cdf0e10cSrcweir                                 }
179cdf0e10cSrcweir                             }
180cdf0e10cSrcweir                         }
181cdf0e10cSrcweir                     }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir                     if ( bUnload && UnloadObj(pUnloadObj) )
184cdf0e10cSrcweir                         // object was successfully unloaded
185cdf0e10cSrcweir                         nCount2--;
186cdf0e10cSrcweir                 }
187cdf0e10cSrcweir                 catch( uno::Exception& )
188cdf0e10cSrcweir                 {}
189cdf0e10cSrcweir             }
190cdf0e10cSrcweir 		}
191cdf0e10cSrcweir 	}
192cdf0e10cSrcweir }
193cdf0e10cSrcweir 
SetSize(sal_uIntPtr nNewSize)194cdf0e10cSrcweir void OLEObjCache::SetSize(sal_uIntPtr nNewSize)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir 	nSize = nNewSize;
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
InsertObj(SdrOle2Obj * pObj)199cdf0e10cSrcweir void OLEObjCache::InsertObj(SdrOle2Obj* pObj)
200cdf0e10cSrcweir {
201cdf0e10cSrcweir 	if ( Count() )
202cdf0e10cSrcweir 	{
203cdf0e10cSrcweir 		SdrOle2Obj* pExistingObj = (SdrOle2Obj*)GetObject( 0 );
204cdf0e10cSrcweir 		if ( pObj == pExistingObj )
205cdf0e10cSrcweir 			// the object is already on the top, nothing has to be changed
206cdf0e10cSrcweir 			return;
207cdf0e10cSrcweir 	}
208cdf0e10cSrcweir 
209cdf0e10cSrcweir     // get the old position of the object to know whether it is already in container
210cdf0e10cSrcweir     sal_uIntPtr nOldPos = GetPos( pObj );
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     // insert object into first position
213cdf0e10cSrcweir 	Remove( nOldPos );
214cdf0e10cSrcweir 	Insert(pObj, (sal_uIntPtr) 0L);
215cdf0e10cSrcweir 
216cdf0e10cSrcweir     if ( nOldPos == CONTAINER_ENTRY_NOTFOUND )
217cdf0e10cSrcweir     {
218cdf0e10cSrcweir         // a new object was inserted, recalculate the cache
219cdf0e10cSrcweir         UnloadOnDemand();
220cdf0e10cSrcweir     }
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
RemoveObj(SdrOle2Obj * pObj)223cdf0e10cSrcweir void OLEObjCache::RemoveObj(SdrOle2Obj* pObj)
224cdf0e10cSrcweir {
225cdf0e10cSrcweir     Remove(pObj);
226cdf0e10cSrcweir }
227cdf0e10cSrcweir 
UnloadObj(SdrOle2Obj * pObj)228cdf0e10cSrcweir sal_Bool OLEObjCache::UnloadObj(SdrOle2Obj* pObj)
229cdf0e10cSrcweir {
230cdf0e10cSrcweir 	sal_Bool bUnloaded = sal_False;
231cdf0e10cSrcweir 	if (pObj)
232cdf0e10cSrcweir 	{
233cdf0e10cSrcweir         //#i80528# The old mechanism is completely useless, only taking into account if
234cdf0e10cSrcweir         // in all views the GrafDraft feature is used. This will nearly never have been the
235cdf0e10cSrcweir         // case since no one ever used this option.
236cdf0e10cSrcweir         //
237cdf0e10cSrcweir         // A much better (and working) criteria would be the VOC contact count.
238cdf0e10cSrcweir         // The quesion is what will happen whe i make it work now suddenly? I
239cdf0e10cSrcweir         // will try it for 2.4.
240cdf0e10cSrcweir     	const sdr::contact::ViewContact& rViewContact = pObj->GetViewContact();
241cdf0e10cSrcweir 		const bool bVisible(rViewContact.HasViewObjectContacts(true));
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 		if(!bVisible)
244cdf0e10cSrcweir         {
245cdf0e10cSrcweir     		bUnloaded = pObj->Unload();
246cdf0e10cSrcweir         }
247cdf0e10cSrcweir 	}
248cdf0e10cSrcweir 
249cdf0e10cSrcweir 	return bUnloaded;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir IMPL_LINK(OLEObjCache, UnloadCheckHdl, AutoTimer*, /*pTim*/)
253cdf0e10cSrcweir {
254cdf0e10cSrcweir     UnloadOnDemand();
255cdf0e10cSrcweir     return 0;
256cdf0e10cSrcweir }
257cdf0e10cSrcweir 
DoSort(sal_uIntPtr a,sal_uIntPtr b) const258cdf0e10cSrcweir void ContainerSorter::DoSort(sal_uIntPtr a, sal_uIntPtr b) const
259cdf0e10cSrcweir {
260cdf0e10cSrcweir 	sal_uIntPtr nAnz=rCont.Count();
261cdf0e10cSrcweir 	if (b>nAnz) b=nAnz;
262cdf0e10cSrcweir 	if (b>0) b--;
263cdf0e10cSrcweir 	if (a<b) ImpSubSort(a,b);
264cdf0e10cSrcweir }
265cdf0e10cSrcweir 
Is1stLessThan2nd(const void *,const void *) const266cdf0e10cSrcweir void ContainerSorter::Is1stLessThan2nd(const void* /*pElem1*/, const void* /*pElem2*/) const
267cdf0e10cSrcweir {
268cdf0e10cSrcweir }
269cdf0e10cSrcweir 
ImpSubSort(long nL,long nR) const270cdf0e10cSrcweir void ContainerSorter::ImpSubSort(long nL, long nR) const
271cdf0e10cSrcweir {
272cdf0e10cSrcweir 	long i,j;
273cdf0e10cSrcweir 	const void* pX;
274cdf0e10cSrcweir 	void* pI;
275cdf0e10cSrcweir 	void* pJ;
276cdf0e10cSrcweir 	i=nL;
277cdf0e10cSrcweir 	j=nR;
278cdf0e10cSrcweir 	pX=rCont.GetObject((nL+nR)/2);
279cdf0e10cSrcweir 	do {
280cdf0e10cSrcweir 		pI=rCont.Seek(i);
281cdf0e10cSrcweir 		while (pI!=pX && Compare(pI,pX)<0) { i++; pI=rCont.Next(); }
282cdf0e10cSrcweir 		pJ=rCont.Seek(j);
283cdf0e10cSrcweir 		while (pJ!=pX && Compare(pX,pJ)<0) { j--; pJ=rCont.Prev(); }
284cdf0e10cSrcweir 		if (i<=j) {
285cdf0e10cSrcweir 			rCont.Replace(pJ,i);
286cdf0e10cSrcweir 			rCont.Replace(pI,j);
287cdf0e10cSrcweir 			i++;
288cdf0e10cSrcweir 			j--;
289cdf0e10cSrcweir 		}
290cdf0e10cSrcweir 	} while (i<=j);
291cdf0e10cSrcweir 	if (nL<j) ImpSubSort(nL,j);
292cdf0e10cSrcweir 	if (i<nR) ImpSubSort(i,nR);
293cdf0e10cSrcweir }
294cdf0e10cSrcweir 
295cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
296cdf0e10cSrcweir 
297cdf0e10cSrcweir class ImpUShortContainerSorter: public ContainerSorter {
298cdf0e10cSrcweir public:
ImpUShortContainerSorter(Container & rNewCont)299cdf0e10cSrcweir 	ImpUShortContainerSorter(Container& rNewCont): ContainerSorter(rNewCont) {}
300cdf0e10cSrcweir 	virtual int Compare(const void* pElem1, const void* pElem2) const;
301cdf0e10cSrcweir };
302cdf0e10cSrcweir 
Compare(const void * pElem1,const void * pElem2) const303cdf0e10cSrcweir int ImpUShortContainerSorter::Compare(const void* pElem1, const void* pElem2) const
304cdf0e10cSrcweir {
305cdf0e10cSrcweir 	sal_uInt16 n1=sal_uInt16(sal_uIntPtr(pElem1));
306cdf0e10cSrcweir 	sal_uInt16 n2=sal_uInt16(sal_uIntPtr(pElem2));
307cdf0e10cSrcweir 	return n1<n2 ? -1 : n1>n2 ? 1 : 0;
308cdf0e10cSrcweir }
309cdf0e10cSrcweir 
Sort()310cdf0e10cSrcweir void UShortCont::Sort()
311cdf0e10cSrcweir {
312cdf0e10cSrcweir 	ImpUShortContainerSorter aSorter(aArr);
313cdf0e10cSrcweir 	aSorter.DoSort();
314cdf0e10cSrcweir }
315cdf0e10cSrcweir 
316cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
317cdf0e10cSrcweir 
318cdf0e10cSrcweir class ImpClipMerk {
319cdf0e10cSrcweir 	Region aClip;
320cdf0e10cSrcweir 	FASTBOOL   bClip;
321cdf0e10cSrcweir public:
ImpClipMerk(const OutputDevice & rOut)322cdf0e10cSrcweir 	ImpClipMerk(const OutputDevice& rOut): aClip(rOut.GetClipRegion()),bClip(rOut.IsClipRegion()) {}
Restore(OutputDevice & rOut)323cdf0e10cSrcweir 	void Restore(OutputDevice& rOut)
324cdf0e10cSrcweir 	{
325cdf0e10cSrcweir 		// Kein Clipping in die Metafileaufzeichnung
326cdf0e10cSrcweir 		GDIMetaFile* pMtf=rOut.GetConnectMetaFile();
327cdf0e10cSrcweir 		if (pMtf!=NULL && (!pMtf->IsRecord() || pMtf->IsPause())) pMtf=NULL;
328cdf0e10cSrcweir 		if (pMtf!=NULL) pMtf->Pause(sal_True);
329cdf0e10cSrcweir 		if (bClip) rOut.SetClipRegion(aClip);
330cdf0e10cSrcweir 		else rOut.SetClipRegion();
331cdf0e10cSrcweir 		if (pMtf!=NULL) pMtf->Pause(sal_False);
332cdf0e10cSrcweir 	}
333cdf0e10cSrcweir };
334cdf0e10cSrcweir 
335cdf0e10cSrcweir class ImpColorMerk {
336cdf0e10cSrcweir 	Color aLineColor;
337cdf0e10cSrcweir 	Color aFillColor;
338cdf0e10cSrcweir 	Color aBckgrdColor;
339cdf0e10cSrcweir 	Font  aFont;
340cdf0e10cSrcweir public:
ImpColorMerk(const OutputDevice & rOut)341cdf0e10cSrcweir 	ImpColorMerk(const OutputDevice& rOut):
342cdf0e10cSrcweir 		aLineColor( rOut.GetLineColor() ),
343cdf0e10cSrcweir 		aFillColor( rOut.GetFillColor() ),
344cdf0e10cSrcweir 		aBckgrdColor( rOut.GetBackground().GetColor() ),
345cdf0e10cSrcweir 		aFont (rOut.GetFont()) {}
346cdf0e10cSrcweir 
ImpColorMerk(const OutputDevice & rOut,sal_uInt16 nMode)347cdf0e10cSrcweir 	ImpColorMerk(const OutputDevice& rOut, sal_uInt16 nMode)
348cdf0e10cSrcweir 	{
349cdf0e10cSrcweir 		if ( (nMode & SDRHDC_SAVEPEN) == SDRHDC_SAVEPEN )
350cdf0e10cSrcweir 			aLineColor = rOut.GetLineColor();
351cdf0e10cSrcweir 
352cdf0e10cSrcweir 		if ( (nMode & SDRHDC_SAVEBRUSH) == SDRHDC_SAVEBRUSH)
353cdf0e10cSrcweir 		{
354cdf0e10cSrcweir 			aFillColor = rOut.GetFillColor();
355cdf0e10cSrcweir 			aBckgrdColor = rOut.GetBackground().GetColor();
356cdf0e10cSrcweir 		}
357cdf0e10cSrcweir 
358cdf0e10cSrcweir 		if ( (nMode & SDRHDC_SAVEFONT) == SDRHDC_SAVEFONT)
359cdf0e10cSrcweir 			aFont=rOut.GetFont();
360cdf0e10cSrcweir 	}
361cdf0e10cSrcweir 
Restore(OutputDevice & rOut,sal_uInt16 nMode=SDRHDC_SAVEPENANDBRUSHANDFONT)362cdf0e10cSrcweir 	void Restore(OutputDevice& rOut, sal_uInt16 nMode=SDRHDC_SAVEPENANDBRUSHANDFONT)
363cdf0e10cSrcweir 	{
364cdf0e10cSrcweir 		if ( (nMode & SDRHDC_SAVEPEN) == SDRHDC_SAVEPEN)
365cdf0e10cSrcweir 			rOut.SetLineColor( aLineColor );
366cdf0e10cSrcweir 
367cdf0e10cSrcweir 		if ( (nMode & SDRHDC_SAVEBRUSH) == SDRHDC_SAVEBRUSH)
368cdf0e10cSrcweir 		{
369cdf0e10cSrcweir 			rOut.SetFillColor( aFillColor );
370cdf0e10cSrcweir 			rOut.SetBackground( Wallpaper( aBckgrdColor ) );
371cdf0e10cSrcweir 		}
372cdf0e10cSrcweir 		if ((nMode & SDRHDC_SAVEFONT) ==SDRHDC_SAVEFONT)
373cdf0e10cSrcweir 		{
374cdf0e10cSrcweir 			if (!rOut.GetFont().IsSameInstance(aFont))
375cdf0e10cSrcweir 			{
376cdf0e10cSrcweir 				rOut.SetFont(aFont);
377cdf0e10cSrcweir 			}
378cdf0e10cSrcweir 		}
379cdf0e10cSrcweir 	}
380cdf0e10cSrcweir 
GetLineColor() const381cdf0e10cSrcweir 	const Color& GetLineColor() const { return aLineColor; }
382cdf0e10cSrcweir };
383cdf0e10cSrcweir 
ImpSdrHdcMerk(const OutputDevice & rOut,sal_uInt16 nNewMode,FASTBOOL bAutoMerk)384cdf0e10cSrcweir ImpSdrHdcMerk::ImpSdrHdcMerk(const OutputDevice& rOut, sal_uInt16 nNewMode, FASTBOOL bAutoMerk):
385cdf0e10cSrcweir 	pFarbMerk(NULL),
386cdf0e10cSrcweir 	pClipMerk(NULL),
387cdf0e10cSrcweir 	pLineColorMerk(NULL),
388cdf0e10cSrcweir 	nMode(nNewMode)
389cdf0e10cSrcweir {
390cdf0e10cSrcweir 	if (bAutoMerk) Save(rOut);
391cdf0e10cSrcweir }
392cdf0e10cSrcweir 
~ImpSdrHdcMerk()393cdf0e10cSrcweir ImpSdrHdcMerk::~ImpSdrHdcMerk()
394cdf0e10cSrcweir {
395cdf0e10cSrcweir 	if (pFarbMerk!=NULL) delete pFarbMerk;
396cdf0e10cSrcweir 	if (pClipMerk!=NULL) delete pClipMerk;
397cdf0e10cSrcweir 	if (pLineColorMerk !=NULL) delete pLineColorMerk;
398cdf0e10cSrcweir }
399cdf0e10cSrcweir 
Save(const OutputDevice & rOut)400cdf0e10cSrcweir void ImpSdrHdcMerk::Save(const OutputDevice& rOut)
401cdf0e10cSrcweir {
402cdf0e10cSrcweir 	if (pFarbMerk!=NULL)
403cdf0e10cSrcweir 	{
404cdf0e10cSrcweir 		delete pFarbMerk;
405cdf0e10cSrcweir 		pFarbMerk=NULL;
406cdf0e10cSrcweir 	}
407cdf0e10cSrcweir 	if (pClipMerk!=NULL)
408cdf0e10cSrcweir 	{
409cdf0e10cSrcweir 		delete pClipMerk;
410cdf0e10cSrcweir 		pClipMerk=NULL;
411cdf0e10cSrcweir 	}
412cdf0e10cSrcweir 	if (pLineColorMerk !=NULL)
413cdf0e10cSrcweir 	{
414cdf0e10cSrcweir 		delete pLineColorMerk ;
415cdf0e10cSrcweir 		pLineColorMerk =NULL;
416cdf0e10cSrcweir 	}
417cdf0e10cSrcweir 	if ((nMode & SDRHDC_SAVECLIPPING) ==SDRHDC_SAVECLIPPING)
418cdf0e10cSrcweir 		pClipMerk=new ImpClipMerk(rOut);
419cdf0e10cSrcweir 
420cdf0e10cSrcweir 	sal_uInt16 nCol=nMode & SDRHDC_SAVEPENANDBRUSHANDFONT;
421cdf0e10cSrcweir 
422cdf0e10cSrcweir 	if (nCol==SDRHDC_SAVEPEN)
423cdf0e10cSrcweir 		pLineColorMerk=new Color( rOut.GetLineColor() );
424cdf0e10cSrcweir 	else if (nCol==SDRHDC_SAVEPENANDBRUSHANDFONT)
425cdf0e10cSrcweir 		pFarbMerk=new ImpColorMerk(rOut);
426cdf0e10cSrcweir 	else if (nCol!=0)
427cdf0e10cSrcweir 		pFarbMerk=new ImpColorMerk(rOut,nCol);
428cdf0e10cSrcweir }
429cdf0e10cSrcweir 
Restore(OutputDevice & rOut,sal_uInt16 nMask) const430cdf0e10cSrcweir void ImpSdrHdcMerk::Restore(OutputDevice& rOut, sal_uInt16 nMask) const
431cdf0e10cSrcweir {
432cdf0e10cSrcweir 	nMask&=nMode; // nur restaurieren, was auch gesichert wurde
433cdf0e10cSrcweir 
434cdf0e10cSrcweir 	if ((nMask & SDRHDC_SAVECLIPPING) ==SDRHDC_SAVECLIPPING && pClipMerk!=NULL)
435cdf0e10cSrcweir 		pClipMerk->Restore(rOut);
436cdf0e10cSrcweir 
437cdf0e10cSrcweir 	sal_uInt16 nCol=nMask & SDRHDC_SAVEPENANDBRUSHANDFONT;
438cdf0e10cSrcweir 
439cdf0e10cSrcweir 	if (nCol==SDRHDC_SAVEPEN)
440cdf0e10cSrcweir 	{
441cdf0e10cSrcweir 		if (pLineColorMerk!=NULL)
442cdf0e10cSrcweir 			rOut.SetLineColor(*pLineColorMerk);
443cdf0e10cSrcweir 		else if (pFarbMerk!=NULL)
444cdf0e10cSrcweir 			rOut.SetLineColor( pFarbMerk->GetLineColor() );
445cdf0e10cSrcweir 	} else if (nCol!=0 && pFarbMerk!=NULL)
446cdf0e10cSrcweir 		pFarbMerk->Restore(rOut,nCol);
447cdf0e10cSrcweir }
448cdf0e10cSrcweir 
449cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
450cdf0e10cSrcweir 
Clear()451cdf0e10cSrcweir void SdrLinkList::Clear()
452cdf0e10cSrcweir {
453cdf0e10cSrcweir 	unsigned nAnz=GetLinkCount();
454cdf0e10cSrcweir 	for (unsigned i=0; i<nAnz; i++) {
455cdf0e10cSrcweir 		delete (Link*)aList.GetObject(i);
456cdf0e10cSrcweir 	}
457cdf0e10cSrcweir 	aList.Clear();
458cdf0e10cSrcweir }
459cdf0e10cSrcweir 
FindEntry(const Link & rLink) const460cdf0e10cSrcweir unsigned SdrLinkList::FindEntry(const Link& rLink) const
461cdf0e10cSrcweir {
462cdf0e10cSrcweir 	unsigned nAnz=GetLinkCount();
463cdf0e10cSrcweir 	for (unsigned i=0; i<nAnz; i++) {
464cdf0e10cSrcweir 		if (GetLink(i)==rLink) return i;
465cdf0e10cSrcweir 	}
466cdf0e10cSrcweir 	return 0xFFFF;
467cdf0e10cSrcweir }
468cdf0e10cSrcweir 
InsertLink(const Link & rLink,unsigned nPos)469cdf0e10cSrcweir void SdrLinkList::InsertLink(const Link& rLink, unsigned nPos)
470cdf0e10cSrcweir {
471cdf0e10cSrcweir 	unsigned nFnd=FindEntry(rLink);
472cdf0e10cSrcweir 	if (nFnd==0xFFFF) {
473cdf0e10cSrcweir 		if (rLink.IsSet()) {
474cdf0e10cSrcweir 			aList.Insert(new Link(rLink),nPos);
475cdf0e10cSrcweir 		} else {
476cdf0e10cSrcweir 			DBG_ERROR("SdrLinkList::InsertLink(): Versuch, einen nicht gesetzten Link einzufuegen");
477cdf0e10cSrcweir 		}
478cdf0e10cSrcweir 	} else {
479cdf0e10cSrcweir 		DBG_ERROR("SdrLinkList::InsertLink(): Link schon vorhanden");
480cdf0e10cSrcweir 	}
481cdf0e10cSrcweir }
482cdf0e10cSrcweir 
RemoveLink(const Link & rLink)483cdf0e10cSrcweir void SdrLinkList::RemoveLink(const Link& rLink)
484cdf0e10cSrcweir {
485cdf0e10cSrcweir 	unsigned nFnd=FindEntry(rLink);
486cdf0e10cSrcweir 	if (nFnd!=0xFFFF) {
487cdf0e10cSrcweir 		Link* pLink=(Link*)aList.Remove(nFnd);
488cdf0e10cSrcweir 		delete pLink;
489cdf0e10cSrcweir 	} else {
490cdf0e10cSrcweir 		DBG_ERROR("SdrLinkList::RemoveLink(): Link nicht gefunden");
491cdf0e10cSrcweir 	}
492cdf0e10cSrcweir }
493cdf0e10cSrcweir 
494cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
495cdf0e10cSrcweir // #98988# Re-implement GetDraftFillColor(...)
496cdf0e10cSrcweir 
GetDraftFillColor(const SfxItemSet & rSet,Color & rCol)497cdf0e10cSrcweir FASTBOOL GetDraftFillColor(const SfxItemSet& rSet, Color& rCol)
498cdf0e10cSrcweir {
499cdf0e10cSrcweir 	XFillStyle eFill=((XFillStyleItem&)rSet.Get(XATTR_FILLSTYLE)).GetValue();
500cdf0e10cSrcweir 	FASTBOOL bRetval(sal_False);
501cdf0e10cSrcweir 
502cdf0e10cSrcweir 	switch(eFill)
503cdf0e10cSrcweir 	{
504cdf0e10cSrcweir 		case XFILL_SOLID:
505cdf0e10cSrcweir 		{
506cdf0e10cSrcweir 			rCol = ((XFillColorItem&)rSet.Get(XATTR_FILLCOLOR)).GetColorValue();
507cdf0e10cSrcweir 			bRetval = sal_True;
508cdf0e10cSrcweir 
509cdf0e10cSrcweir 			break;
510cdf0e10cSrcweir 		}
511cdf0e10cSrcweir 		case XFILL_HATCH:
512cdf0e10cSrcweir 		{
513cdf0e10cSrcweir 			Color aCol1(((XFillHatchItem&)rSet.Get(XATTR_FILLHATCH)).GetHatchValue().GetColor());
514cdf0e10cSrcweir 			Color aCol2(COL_WHITE);
515cdf0e10cSrcweir 
516cdf0e10cSrcweir 			// #97870# when hatch background is activated, use object fill color as hatch color
517cdf0e10cSrcweir 			sal_Bool bFillHatchBackground = ((const XFillBackgroundItem&)(rSet.Get(XATTR_FILLBACKGROUND))).GetValue();
518cdf0e10cSrcweir 			if(bFillHatchBackground)
519cdf0e10cSrcweir 			{
520cdf0e10cSrcweir 				aCol2 = ((const XFillColorItem&)(rSet.Get(XATTR_FILLCOLOR))).GetColorValue();
521cdf0e10cSrcweir 			}
522cdf0e10cSrcweir 
523cdf0e10cSrcweir             const basegfx::BColor aAverageColor(basegfx::average(aCol1.getBColor(), aCol2.getBColor()));
524cdf0e10cSrcweir 			rCol = Color(aAverageColor);
525cdf0e10cSrcweir 			bRetval = sal_True;
526cdf0e10cSrcweir 
527cdf0e10cSrcweir 			break;
528cdf0e10cSrcweir 		}
529cdf0e10cSrcweir 		case XFILL_GRADIENT: {
530cdf0e10cSrcweir 			const XGradient& rGrad=((XFillGradientItem&)rSet.Get(XATTR_FILLGRADIENT)).GetGradientValue();
531cdf0e10cSrcweir 			Color aCol1(rGrad.GetStartColor());
532cdf0e10cSrcweir 			Color aCol2(rGrad.GetEndColor());
533cdf0e10cSrcweir             const basegfx::BColor aAverageColor(basegfx::average(aCol1.getBColor(), aCol2.getBColor()));
534cdf0e10cSrcweir 			rCol = Color(aAverageColor);
535cdf0e10cSrcweir 			bRetval = sal_True;
536cdf0e10cSrcweir 
537cdf0e10cSrcweir 			break;
538cdf0e10cSrcweir 		}
539cdf0e10cSrcweir 		case XFILL_BITMAP:
540cdf0e10cSrcweir 		{
54170d3707aSArmin Le Grand 			Bitmap aBitmap(((XFillBitmapItem&)rSet.Get(XATTR_FILLBITMAP)).GetGraphicObject().GetGraphic().GetBitmapEx().GetBitmap());
54270d3707aSArmin Le Grand 			const Size aSize(aBitmap.GetSizePixel());
543cdf0e10cSrcweir 			const sal_uInt32 nWidth = aSize.Width();
544cdf0e10cSrcweir 			const sal_uInt32 nHeight = aSize.Height();
545cdf0e10cSrcweir 			BitmapReadAccess* pAccess = aBitmap.AcquireReadAccess();
546cdf0e10cSrcweir 
547cdf0e10cSrcweir 			if(pAccess && nWidth > 0 && nHeight > 0)
548cdf0e10cSrcweir 			{
549cdf0e10cSrcweir 				sal_uInt32 nRt(0L);
550cdf0e10cSrcweir 				sal_uInt32 nGn(0L);
551cdf0e10cSrcweir 				sal_uInt32 nBl(0L);
552cdf0e10cSrcweir 				const sal_uInt32 nMaxSteps(8L);
553cdf0e10cSrcweir 				const sal_uInt32 nXStep((nWidth > nMaxSteps) ? nWidth / nMaxSteps : 1L);
554cdf0e10cSrcweir 				const sal_uInt32 nYStep((nHeight > nMaxSteps) ? nHeight / nMaxSteps : 1L);
555cdf0e10cSrcweir 				sal_uInt32 nAnz(0L);
556cdf0e10cSrcweir 
557cdf0e10cSrcweir 				for(sal_uInt32 nY(0L); nY < nHeight; nY += nYStep)
558cdf0e10cSrcweir 				{
559cdf0e10cSrcweir 					for(sal_uInt32 nX(0L); nX < nWidth; nX += nXStep)
560cdf0e10cSrcweir 					{
561*87bc88d3SHerbert Dürr 						const BitmapColor& rCol2 = pAccess->GetColor(nY, nX);
562cdf0e10cSrcweir 
563cdf0e10cSrcweir 						nRt += rCol2.GetRed();
564cdf0e10cSrcweir 						nGn += rCol2.GetGreen();
565cdf0e10cSrcweir 						nBl += rCol2.GetBlue();
566cdf0e10cSrcweir 						nAnz++;
567cdf0e10cSrcweir 					}
568cdf0e10cSrcweir 				}
569cdf0e10cSrcweir 
570cdf0e10cSrcweir 				nRt /= nAnz;
571cdf0e10cSrcweir 				nGn /= nAnz;
572cdf0e10cSrcweir 				nBl /= nAnz;
573cdf0e10cSrcweir 
574cdf0e10cSrcweir 				rCol = Color(sal_uInt8(nRt), sal_uInt8(nGn), sal_uInt8(nBl));
575cdf0e10cSrcweir 
576cdf0e10cSrcweir 				bRetval = sal_True;
577cdf0e10cSrcweir 			}
578cdf0e10cSrcweir 
579cdf0e10cSrcweir 			if(pAccess)
580cdf0e10cSrcweir 			{
581cdf0e10cSrcweir 				aBitmap.ReleaseAccess(pAccess);
582cdf0e10cSrcweir 			}
583cdf0e10cSrcweir 
584cdf0e10cSrcweir 			break;
585cdf0e10cSrcweir 		}
586cdf0e10cSrcweir 		default: break;
587cdf0e10cSrcweir 	}
588cdf0e10cSrcweir 
589cdf0e10cSrcweir 	return bRetval;
590cdf0e10cSrcweir }
591cdf0e10cSrcweir 
592cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
593cdf0e10cSrcweir 
SdrEngineDefaults()594cdf0e10cSrcweir SdrEngineDefaults::SdrEngineDefaults():
595cdf0e10cSrcweir 	aFontName( OutputDevice::GetDefaultFont( DEFAULTFONT_SERIF, LANGUAGE_SYSTEM, DEFAULTFONT_FLAGS_ONLYONE ).GetName() ),
596cdf0e10cSrcweir 	eFontFamily(FAMILY_ROMAN),
597cdf0e10cSrcweir 	aFontColor(COL_AUTO),
598cdf0e10cSrcweir 	nFontHeight(847),			  // 847/100mm = ca. 24 Point
599cdf0e10cSrcweir 	eMapUnit(MAP_100TH_MM),
600cdf0e10cSrcweir 	aMapFraction(1,1)
601cdf0e10cSrcweir {
602cdf0e10cSrcweir }
603cdf0e10cSrcweir 
GetDefaults()604cdf0e10cSrcweir SdrEngineDefaults& SdrEngineDefaults::GetDefaults()
605cdf0e10cSrcweir {
606cdf0e10cSrcweir 	SdrGlobalData& rGlobalData=GetSdrGlobalData();
607cdf0e10cSrcweir 	if (rGlobalData.pDefaults==NULL) {
608cdf0e10cSrcweir 		rGlobalData.pDefaults=new SdrEngineDefaults;
609cdf0e10cSrcweir 	}
610cdf0e10cSrcweir 	return *rGlobalData.pDefaults;
611cdf0e10cSrcweir }
612cdf0e10cSrcweir 
613cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
614cdf0e10cSrcweir 
LanguageHasChanged()615cdf0e10cSrcweir void SdrEngineDefaults::LanguageHasChanged()
616cdf0e10cSrcweir {
617cdf0e10cSrcweir 	SdrGlobalData& rGlobalData=GetSdrGlobalData();
618cdf0e10cSrcweir 	if (rGlobalData.pResMgr!=NULL) {
619cdf0e10cSrcweir 		delete rGlobalData.pResMgr;
620cdf0e10cSrcweir 		rGlobalData.pResMgr=NULL;
621cdf0e10cSrcweir 	}
622cdf0e10cSrcweir }
623cdf0e10cSrcweir 
624cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
625cdf0e10cSrcweir 
SdrMakeOutliner(sal_uInt16 nOutlinerMode,SdrModel * pModel)626cdf0e10cSrcweir SdrOutliner* SdrMakeOutliner( sal_uInt16 nOutlinerMode, SdrModel* pModel )
627cdf0e10cSrcweir {
628cdf0e10cSrcweir 	//SdrEngineDefaults& rDefaults = SdrEngineDefaults::GetDefaults();
629cdf0e10cSrcweir 
630cdf0e10cSrcweir 	SfxItemPool* pPool = &pModel->GetItemPool();
631cdf0e10cSrcweir 	SdrOutliner* pOutl = new SdrOutliner( pPool, nOutlinerMode );
632cdf0e10cSrcweir 	pOutl->SetEditTextObjectPool( pPool );
633cdf0e10cSrcweir 	pOutl->SetStyleSheetPool( (SfxStyleSheetPool*) pModel->GetStyleSheetPool() );
634cdf0e10cSrcweir 	pOutl->SetDefTab( pModel->GetDefaultTabulator() );
635cdf0e10cSrcweir 	pOutl->SetForbiddenCharsTable( pModel->GetForbiddenCharsTable() );
636cdf0e10cSrcweir 	pOutl->SetAsianCompressionMode( pModel->GetCharCompressType() );
637cdf0e10cSrcweir 	pOutl->SetKernAsianPunctuation( pModel->IsKernAsianPunctuation() );
638cdf0e10cSrcweir     pOutl->SetAddExtLeading( pModel->IsAddExtLeading() );
639cdf0e10cSrcweir 
640cdf0e10cSrcweir 	return pOutl;
641cdf0e10cSrcweir }
642cdf0e10cSrcweir 
643cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
644cdf0e10cSrcweir 
645cdf0e10cSrcweir 
ImpGetUserMakeObjHdl()646cdf0e10cSrcweir SdrLinkList& ImpGetUserMakeObjHdl()
647cdf0e10cSrcweir {
648cdf0e10cSrcweir 	SdrGlobalData& rGlobalData=GetSdrGlobalData();
649cdf0e10cSrcweir 	return rGlobalData.aUserMakeObjHdl;
650cdf0e10cSrcweir }
651cdf0e10cSrcweir 
ImpGetUserMakeObjUserDataHdl()652cdf0e10cSrcweir SdrLinkList& ImpGetUserMakeObjUserDataHdl()
653cdf0e10cSrcweir {
654cdf0e10cSrcweir 	SdrGlobalData& rGlobalData=GetSdrGlobalData();
655cdf0e10cSrcweir 	return rGlobalData.aUserMakeObjUserDataHdl;
656cdf0e10cSrcweir }
657cdf0e10cSrcweir 
658cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
659cdf0e10cSrcweir 
ImpGetResMgr()660cdf0e10cSrcweir ResMgr* ImpGetResMgr()
661cdf0e10cSrcweir {
662cdf0e10cSrcweir 	SdrGlobalData& rGlobalData = GetSdrGlobalData();
663cdf0e10cSrcweir 
664cdf0e10cSrcweir 	if(!rGlobalData.pResMgr)
665cdf0e10cSrcweir 	{
666cdf0e10cSrcweir 		ByteString aName("svx");
667cdf0e10cSrcweir 		rGlobalData.pResMgr =
668cdf0e10cSrcweir             ResMgr::CreateResMgr( aName.GetBuffer(), Application::GetSettings().GetUILocale() );
669cdf0e10cSrcweir 	}
670cdf0e10cSrcweir 
671cdf0e10cSrcweir 	return rGlobalData.pResMgr;
672cdf0e10cSrcweir }
673cdf0e10cSrcweir 
674cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
675cdf0e10cSrcweir 
ImpGetResStr(sal_uInt16 nResID)676cdf0e10cSrcweir String ImpGetResStr(sal_uInt16 nResID)
677cdf0e10cSrcweir {
678cdf0e10cSrcweir 	return String(ResId(nResID, *ImpGetResMgr()));
679cdf0e10cSrcweir }
680cdf0e10cSrcweir 
681cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
682cdf0e10cSrcweir 
683cdf0e10cSrcweir namespace sdr
684cdf0e10cSrcweir {
GetResourceString(sal_uInt16 nResID)685cdf0e10cSrcweir String GetResourceString(sal_uInt16 nResID)
686cdf0e10cSrcweir {
687cdf0e10cSrcweir 	return ImpGetResStr( nResID );
688cdf0e10cSrcweir }
689cdf0e10cSrcweir }
690cdf0e10cSrcweir 
691cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
692cdf0e10cSrcweir 
SearchOutlinerItems(const SfxItemSet & rSet,sal_Bool bInklDefaults,sal_Bool * pbOnlyEE)693cdf0e10cSrcweir sal_Bool SearchOutlinerItems(const SfxItemSet& rSet, sal_Bool bInklDefaults, sal_Bool* pbOnlyEE)
694cdf0e10cSrcweir {
695cdf0e10cSrcweir 	sal_Bool bHas=sal_False;
696cdf0e10cSrcweir 	sal_Bool bOnly=sal_True;
697cdf0e10cSrcweir 	sal_Bool bLookOnly=pbOnlyEE!=NULL;
698cdf0e10cSrcweir 	SfxWhichIter aIter(rSet);
699cdf0e10cSrcweir 	sal_uInt16 nWhich=aIter.FirstWhich();
700cdf0e10cSrcweir 	while (((bLookOnly && bOnly) || !bHas) && nWhich!=0) {
701cdf0e10cSrcweir 		// bei bInklDefaults ist der gesamte Which-Range
702cdf0e10cSrcweir 		// ausschlaggebend, ansonsten nur die gesetzten Items
703cdf0e10cSrcweir 		// Disabled und DontCare wird als Loch im Which-Range betrachtet
704cdf0e10cSrcweir 		SfxItemState eState=rSet.GetItemState(nWhich);
705cdf0e10cSrcweir 		if ((eState==SFX_ITEM_DEFAULT && bInklDefaults) || eState==SFX_ITEM_SET) {
706cdf0e10cSrcweir 			if (nWhich<EE_ITEMS_START || nWhich>EE_ITEMS_END) bOnly=sal_False;
707cdf0e10cSrcweir 			else bHas=sal_True;
708cdf0e10cSrcweir 		}
709cdf0e10cSrcweir 		nWhich=aIter.NextWhich();
710cdf0e10cSrcweir 	}
711cdf0e10cSrcweir 	if (!bHas) bOnly=sal_False;
712cdf0e10cSrcweir 	if (pbOnlyEE!=NULL) *pbOnlyEE=bOnly;
713cdf0e10cSrcweir 	return bHas;
714cdf0e10cSrcweir }
715cdf0e10cSrcweir 
RemoveWhichRange(const sal_uInt16 * pOldWhichTable,sal_uInt16 nRangeBeg,sal_uInt16 nRangeEnd)716cdf0e10cSrcweir sal_uInt16* RemoveWhichRange(const sal_uInt16* pOldWhichTable, sal_uInt16 nRangeBeg, sal_uInt16 nRangeEnd)
717cdf0e10cSrcweir {
718cdf0e10cSrcweir 	// insgesamt sind 6 Faelle moeglich (je Range):
719cdf0e10cSrcweir 	//		   [Beg..End]		   zu entfernender Range
720cdf0e10cSrcweir 	// [b..e]	 [b..e]    [b..e]  Fall 1,3,2: egal, ganz weg, egal  + Ranges
721cdf0e10cSrcweir 	// [b........e]  [b........e]  Fall 4,5  : Bereich verkleinern	 | in
722cdf0e10cSrcweir 	// [b......................e]  Fall 6	 : Splitting			 + pOldWhichTable
723cdf0e10cSrcweir 	sal_uInt16 nAnz=0;
724cdf0e10cSrcweir 	while (pOldWhichTable[nAnz]!=0) nAnz++;
725cdf0e10cSrcweir 	nAnz++; // nAnz muesste nun in jedem Fall eine ungerade Zahl sein (0 am Ende des Arrays)
726cdf0e10cSrcweir 	DBG_ASSERT((nAnz&1)==1,"Joe: RemoveWhichRange: WhichTable hat keine ungerade Anzahl von Eintraegen");
727cdf0e10cSrcweir 	sal_uInt16 nAlloc=nAnz;
728cdf0e10cSrcweir 	// benoetigte Groesse des neuen Arrays ermitteln
729cdf0e10cSrcweir 	sal_uInt16 nNum=nAnz-1;
730cdf0e10cSrcweir 	while (nNum!=0) {
731cdf0e10cSrcweir 		nNum-=2;
732cdf0e10cSrcweir 		sal_uInt16 nBeg=pOldWhichTable[nNum];
733cdf0e10cSrcweir 		sal_uInt16 nEnd=pOldWhichTable[nNum+1];
734cdf0e10cSrcweir 		if (nEnd<nRangeBeg)  /*nCase=1*/ ;
735cdf0e10cSrcweir 		else if (nBeg>nRangeEnd) /* nCase=2 */ ;
736cdf0e10cSrcweir 		else if (nBeg>=nRangeBeg && nEnd<=nRangeEnd) /* nCase=3 */ nAlloc-=2;
737cdf0e10cSrcweir 		else if (nEnd<=nRangeEnd) /* nCase=4 */;
738cdf0e10cSrcweir 		else if (nBeg>=nRangeBeg) /* nCase=5*/ ;
739cdf0e10cSrcweir 		else /* nCase=6 */ nAlloc+=2;
740cdf0e10cSrcweir 	}
741cdf0e10cSrcweir 
742cdf0e10cSrcweir 	sal_uInt16* pNewWhichTable=new sal_uInt16[nAlloc];
743cdf0e10cSrcweir 	memcpy(pNewWhichTable,pOldWhichTable,nAlloc*sizeof(sal_uInt16));
744cdf0e10cSrcweir 	pNewWhichTable[nAlloc-1]=0; // im Falle 3 fehlt die 0 am Ende
745cdf0e10cSrcweir 	// nun die unerwuenschten Ranges entfernen
746cdf0e10cSrcweir 	nNum=nAlloc-1;
747cdf0e10cSrcweir 	while (nNum!=0) {
748cdf0e10cSrcweir 		nNum-=2;
749cdf0e10cSrcweir 		sal_uInt16 nBeg=pNewWhichTable[nNum];
750cdf0e10cSrcweir 		sal_uInt16 nEnd=pNewWhichTable[nNum+1];
751cdf0e10cSrcweir 		unsigned nCase=0;
752cdf0e10cSrcweir 		if (nEnd<nRangeBeg) nCase=1;
753cdf0e10cSrcweir 		else if (nBeg>nRangeEnd) nCase=2;
754cdf0e10cSrcweir 		else if (nBeg>=nRangeBeg && nEnd<=nRangeEnd) nCase=3;
755cdf0e10cSrcweir 		else if (nEnd<=nRangeEnd) nCase=4;
756cdf0e10cSrcweir 		else if (nBeg>=nRangeBeg) nCase=5;
757cdf0e10cSrcweir 		else nCase=6;
758cdf0e10cSrcweir 		switch (nCase) {
759cdf0e10cSrcweir 			case 3: {
760cdf0e10cSrcweir 				unsigned nTailBytes=(nAnz-(nNum+2))*sizeof(sal_uInt16);
761cdf0e10cSrcweir 				memcpy(&pNewWhichTable[nNum],&pNewWhichTable[nNum+2],nTailBytes);
762cdf0e10cSrcweir 				nAnz-=2; // Merken: Array hat sich verkleinert
763cdf0e10cSrcweir 			} break;
764cdf0e10cSrcweir 			case 4: pNewWhichTable[nNum+1]=nRangeBeg-1; break;
765cdf0e10cSrcweir 			case 5: pNewWhichTable[nNum]=nRangeEnd+1;	  break;
766cdf0e10cSrcweir 			case 6: {
767cdf0e10cSrcweir 				unsigned nTailBytes=(nAnz-(nNum+2))*sizeof(sal_uInt16);
768cdf0e10cSrcweir 				memcpy(&pNewWhichTable[nNum+4],&pNewWhichTable[nNum+2],nTailBytes);
769cdf0e10cSrcweir 				nAnz+=2; // Merken: Array hat sich vergroessert
770cdf0e10cSrcweir 				pNewWhichTable[nNum+2]=nRangeEnd+1;
771cdf0e10cSrcweir 				pNewWhichTable[nNum+3]=pNewWhichTable[nNum+1];
772cdf0e10cSrcweir 				pNewWhichTable[nNum+1]=nRangeBeg-1;
773cdf0e10cSrcweir 			} break;
774cdf0e10cSrcweir 		} // switch
775cdf0e10cSrcweir 	}
776cdf0e10cSrcweir 	return pNewWhichTable;
777cdf0e10cSrcweir }
778cdf0e10cSrcweir 
779cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
780cdf0e10cSrcweir 
SvdProgressInfo(Link * _pLink)781cdf0e10cSrcweir SvdProgressInfo::SvdProgressInfo( Link *_pLink )
782cdf0e10cSrcweir {
783cdf0e10cSrcweir 	DBG_ASSERT(_pLink!=NULL,"SvdProgressInfo(): Kein Link angegeben!!");
784cdf0e10cSrcweir 
785cdf0e10cSrcweir 	pLink = _pLink;
786cdf0e10cSrcweir 	nSumActionCount = 0;
787cdf0e10cSrcweir 	nSumCurAction	= 0;
788cdf0e10cSrcweir 
789cdf0e10cSrcweir 	nObjCount = 0;
790cdf0e10cSrcweir 	nCurObj   = 0;
791cdf0e10cSrcweir 
792cdf0e10cSrcweir 	nActionCount = 0;
793cdf0e10cSrcweir 	nCurAction	 = 0;
794cdf0e10cSrcweir 
795cdf0e10cSrcweir 	nInsertCount = 0;
796cdf0e10cSrcweir 	nCurInsert	 = 0;
797cdf0e10cSrcweir }
798cdf0e10cSrcweir 
Init(sal_uIntPtr _nSumActionCount,sal_uIntPtr _nObjCount)799cdf0e10cSrcweir void SvdProgressInfo::Init( sal_uIntPtr _nSumActionCount, sal_uIntPtr _nObjCount )
800cdf0e10cSrcweir {
801cdf0e10cSrcweir 	nSumActionCount = _nSumActionCount;
802cdf0e10cSrcweir 	nObjCount = _nObjCount;
803cdf0e10cSrcweir }
804cdf0e10cSrcweir 
ReportActions(sal_uIntPtr nAnzActions)805cdf0e10cSrcweir sal_Bool SvdProgressInfo::ReportActions( sal_uIntPtr nAnzActions )
806cdf0e10cSrcweir {
807cdf0e10cSrcweir 	nSumCurAction += nAnzActions;
808cdf0e10cSrcweir 	nCurAction += nAnzActions;
809cdf0e10cSrcweir 	if(nCurAction > nActionCount)
810cdf0e10cSrcweir 		nCurAction = nActionCount;
811cdf0e10cSrcweir 
812cdf0e10cSrcweir 	return pLink->Call(NULL) == 1L;
813cdf0e10cSrcweir }
814cdf0e10cSrcweir 
ReportInserts(sal_uIntPtr nAnzInserts)815cdf0e10cSrcweir sal_Bool SvdProgressInfo::ReportInserts( sal_uIntPtr nAnzInserts )
816cdf0e10cSrcweir {
817cdf0e10cSrcweir 	nSumCurAction += nAnzInserts;
818cdf0e10cSrcweir 	nCurInsert += nAnzInserts;
819cdf0e10cSrcweir 
820cdf0e10cSrcweir 	return pLink->Call(NULL) == 1L;
821cdf0e10cSrcweir }
822cdf0e10cSrcweir 
ReportRescales(sal_uIntPtr nAnzRescales)823cdf0e10cSrcweir sal_Bool SvdProgressInfo::ReportRescales( sal_uIntPtr nAnzRescales )
824cdf0e10cSrcweir {
825cdf0e10cSrcweir 	nSumCurAction += nAnzRescales;
826cdf0e10cSrcweir 	return pLink->Call(NULL) == 1L;
827cdf0e10cSrcweir }
828cdf0e10cSrcweir 
SetActionCount(sal_uIntPtr _nActionCount)829cdf0e10cSrcweir void SvdProgressInfo::SetActionCount( sal_uIntPtr _nActionCount )
830cdf0e10cSrcweir {
831cdf0e10cSrcweir 	nActionCount = _nActionCount;
832cdf0e10cSrcweir }
833cdf0e10cSrcweir 
SetInsertCount(sal_uIntPtr _nInsertCount)834cdf0e10cSrcweir void SvdProgressInfo::SetInsertCount( sal_uIntPtr _nInsertCount )
835cdf0e10cSrcweir {
836cdf0e10cSrcweir 	nInsertCount = _nInsertCount;
837cdf0e10cSrcweir }
838cdf0e10cSrcweir 
SetNextObject()839cdf0e10cSrcweir sal_Bool SvdProgressInfo::SetNextObject()
840cdf0e10cSrcweir {
841cdf0e10cSrcweir 	nActionCount = 0;
842cdf0e10cSrcweir 	nCurAction	 = 0;
843cdf0e10cSrcweir 
844cdf0e10cSrcweir 	nInsertCount = 0;
845cdf0e10cSrcweir 	nCurInsert	 = 0;
846cdf0e10cSrcweir 
847cdf0e10cSrcweir 	nCurObj++;
848cdf0e10cSrcweir 	return ReportActions(0);
849cdf0e10cSrcweir }
850cdf0e10cSrcweir 
ReportError()851cdf0e10cSrcweir void SvdProgressInfo::ReportError()
852cdf0e10cSrcweir {
853cdf0e10cSrcweir 	pLink->Call((void *)1L);
854cdf0e10cSrcweir }
855cdf0e10cSrcweir 
856cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
857cdf0e10cSrcweir // #i101872# isolate GetTextEditBackgroundColor to tooling; it woll anyways only be used as long
858cdf0e10cSrcweir // as text edit is not running on overlay
859cdf0e10cSrcweir 
860cdf0e10cSrcweir namespace
861cdf0e10cSrcweir {
impGetSdrObjListFillColor(const SdrObjList & rList,const Point & rPnt,const SdrPageView & rTextEditPV,const SetOfByte & rVisLayers,Color & rCol)862cdf0e10cSrcweir     bool impGetSdrObjListFillColor(
863cdf0e10cSrcweir         const SdrObjList& rList,
864cdf0e10cSrcweir         const Point& rPnt,
865cdf0e10cSrcweir         const SdrPageView& rTextEditPV,
866cdf0e10cSrcweir         const SetOfByte& rVisLayers,
867cdf0e10cSrcweir         Color& rCol)
868cdf0e10cSrcweir     {
869cdf0e10cSrcweir 	    if(!rList.GetModel())
870cdf0e10cSrcweir             return false;
871cdf0e10cSrcweir 
872cdf0e10cSrcweir 	    bool bRet(false);
873cdf0e10cSrcweir 	    bool bMaster(rList.GetPage() ? rList.GetPage()->IsMasterPage() : false);
874cdf0e10cSrcweir 
875cdf0e10cSrcweir 	    for(sal_uIntPtr no(rList.GetObjCount()); !bRet && no > 0; )
876cdf0e10cSrcweir         {
877cdf0e10cSrcweir 		    no--;
878cdf0e10cSrcweir 		    SdrObject* pObj = rList.GetObj(no);
879cdf0e10cSrcweir 		    SdrObjList* pOL = pObj->GetSubList();
880cdf0e10cSrcweir 
881cdf0e10cSrcweir             if(pOL)
882cdf0e10cSrcweir             {
883cdf0e10cSrcweir                 // group object
884cdf0e10cSrcweir 			    bRet = impGetSdrObjListFillColor(*pOL, rPnt, rTextEditPV, rVisLayers, rCol);
885cdf0e10cSrcweir 		    }
886cdf0e10cSrcweir             else
887cdf0e10cSrcweir             {
888cdf0e10cSrcweir         		SdrTextObj* pText = dynamic_cast< SdrTextObj * >(pObj);
889cdf0e10cSrcweir 
890cdf0e10cSrcweir                 // #108867# Exclude zero master page object (i.e. background shape) from color query
891cdf0e10cSrcweir 			    if(pText
892cdf0e10cSrcweir                     && pObj->IsClosedObj()
893cdf0e10cSrcweir                     && (!bMaster || (!pObj->IsNotVisibleAsMaster() && 0 != no))
894cdf0e10cSrcweir                     && pObj->GetCurrentBoundRect().IsInside(rPnt)
895cdf0e10cSrcweir                     && !pText->IsHideContour()
896cdf0e10cSrcweir                     && SdrObjectPrimitiveHit(*pObj, rPnt, 0, rTextEditPV, &rVisLayers, false))
897cdf0e10cSrcweir 			    {
898cdf0e10cSrcweir             	    bRet = GetDraftFillColor(pObj->GetMergedItemSet(), rCol);
899cdf0e10cSrcweir 			    }
900cdf0e10cSrcweir 		    }
901cdf0e10cSrcweir 	    }
902cdf0e10cSrcweir 
903cdf0e10cSrcweir         return bRet;
904cdf0e10cSrcweir     }
905cdf0e10cSrcweir 
impGetSdrPageFillColor(const SdrPage & rPage,const Point & rPnt,const SdrPageView & rTextEditPV,const SetOfByte & rVisLayers,Color & rCol,bool bSkipBackgroundShape)906cdf0e10cSrcweir     bool impGetSdrPageFillColor(
907cdf0e10cSrcweir         const SdrPage& rPage,
908cdf0e10cSrcweir         const Point& rPnt,
909cdf0e10cSrcweir         const SdrPageView& rTextEditPV,
910cdf0e10cSrcweir         const SetOfByte& rVisLayers,
911cdf0e10cSrcweir         Color& rCol,
912cdf0e10cSrcweir         bool bSkipBackgroundShape)
913cdf0e10cSrcweir     {
914cdf0e10cSrcweir 	    if(!rPage.GetModel())
915cdf0e10cSrcweir 		    return false;
916cdf0e10cSrcweir 
917cdf0e10cSrcweir 	    bool bRet(impGetSdrObjListFillColor(rPage, rPnt, rTextEditPV, rVisLayers, rCol));
918cdf0e10cSrcweir 
919cdf0e10cSrcweir 	    if(!bRet && !rPage.IsMasterPage())
920cdf0e10cSrcweir 	    {
921cdf0e10cSrcweir 		    if(rPage.TRG_HasMasterPage())
922cdf0e10cSrcweir 		    {
923cdf0e10cSrcweir 			    SetOfByte aSet(rVisLayers);
924cdf0e10cSrcweir 			    aSet &= rPage.TRG_GetMasterPageVisibleLayers();
925cdf0e10cSrcweir 			    SdrPage& rMasterPage = rPage.TRG_GetMasterPage();
926cdf0e10cSrcweir 
927cdf0e10cSrcweir 			    // #108867# Don't fall back to background shape on
928cdf0e10cSrcweir                 // master pages. This is later handled by
929cdf0e10cSrcweir                 // GetBackgroundColor, and is necessary to cater for
930cdf0e10cSrcweir                 // the silly ordering: 1. shapes, 2. master page
931cdf0e10cSrcweir                 // shapes, 3. page background, 4. master page
932cdf0e10cSrcweir                 // background.
933cdf0e10cSrcweir 			    bRet = impGetSdrPageFillColor(rMasterPage, rPnt, rTextEditPV, aSet, rCol, true);
934cdf0e10cSrcweir 		    }
935cdf0e10cSrcweir 	    }
936cdf0e10cSrcweir 
937cdf0e10cSrcweir         // #108867# Only now determine background color from background shapes
938cdf0e10cSrcweir         if(!bRet && !bSkipBackgroundShape)
939cdf0e10cSrcweir         {
940cdf0e10cSrcweir             rCol = rPage.GetPageBackgroundColor();
941cdf0e10cSrcweir 		    return true;
942cdf0e10cSrcweir         }
943cdf0e10cSrcweir 
944cdf0e10cSrcweir 	    return bRet;
945cdf0e10cSrcweir     }
946cdf0e10cSrcweir 
impCalcBackgroundColor(const Rectangle & rArea,const SdrPageView & rTextEditPV,const SdrPage & rPage)947cdf0e10cSrcweir     Color impCalcBackgroundColor(
948cdf0e10cSrcweir         const Rectangle& rArea,
949cdf0e10cSrcweir         const SdrPageView& rTextEditPV,
950cdf0e10cSrcweir         const SdrPage& rPage)
951cdf0e10cSrcweir     {
952cdf0e10cSrcweir         svtools::ColorConfig aColorConfig;
953cdf0e10cSrcweir         Color aBackground(aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor);
954cdf0e10cSrcweir 	    const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
955cdf0e10cSrcweir 
956cdf0e10cSrcweir 	    if(!rStyleSettings.GetHighContrastMode())
957cdf0e10cSrcweir 	    {
958cdf0e10cSrcweir             // search in page
959cdf0e10cSrcweir             const sal_uInt16 SPOTCOUNT(5);
960cdf0e10cSrcweir             Point aSpotPos[SPOTCOUNT];
961cdf0e10cSrcweir             Color aSpotColor[SPOTCOUNT];
962cdf0e10cSrcweir             sal_uIntPtr nHeight( rArea.GetSize().Height() );
963cdf0e10cSrcweir             sal_uIntPtr nWidth( rArea.GetSize().Width() );
964cdf0e10cSrcweir             sal_uIntPtr nWidth14  = nWidth / 4;
965cdf0e10cSrcweir             sal_uIntPtr nHeight14 = nHeight / 4;
966cdf0e10cSrcweir             sal_uIntPtr nWidth34  = ( 3 * nWidth ) / 4;
967cdf0e10cSrcweir             sal_uIntPtr nHeight34 = ( 3 * nHeight ) / 4;
968cdf0e10cSrcweir 
969cdf0e10cSrcweir             sal_uInt16 i;
970cdf0e10cSrcweir             for ( i = 0; i < SPOTCOUNT; i++ )
971cdf0e10cSrcweir             {
972cdf0e10cSrcweir                 // five spots are used
973cdf0e10cSrcweir                 switch ( i )
974cdf0e10cSrcweir                 {
975cdf0e10cSrcweir                     case 0 :
976cdf0e10cSrcweir                     {
977cdf0e10cSrcweir                         // Center-Spot
978cdf0e10cSrcweir                         aSpotPos[i] = rArea.Center();
979cdf0e10cSrcweir                     }
980cdf0e10cSrcweir                     break;
981cdf0e10cSrcweir 
982cdf0e10cSrcweir                     case 1 :
983cdf0e10cSrcweir                     {
984cdf0e10cSrcweir                         // TopLeft-Spot
985cdf0e10cSrcweir                         aSpotPos[i] = rArea.TopLeft();
986cdf0e10cSrcweir                         aSpotPos[i].X() += nWidth14;
987cdf0e10cSrcweir                         aSpotPos[i].Y() += nHeight14;
988cdf0e10cSrcweir                     }
989cdf0e10cSrcweir                     break;
990cdf0e10cSrcweir 
991cdf0e10cSrcweir                     case 2 :
992cdf0e10cSrcweir                     {
993cdf0e10cSrcweir                         // TopRight-Spot
994cdf0e10cSrcweir                         aSpotPos[i] = rArea.TopLeft();
995cdf0e10cSrcweir                         aSpotPos[i].X() += nWidth34;
996cdf0e10cSrcweir                         aSpotPos[i].Y() += nHeight14;
997cdf0e10cSrcweir                     }
998cdf0e10cSrcweir                     break;
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir                     case 3 :
1001cdf0e10cSrcweir                     {
1002cdf0e10cSrcweir                         // BottomLeft-Spot
1003cdf0e10cSrcweir                         aSpotPos[i] = rArea.TopLeft();
1004cdf0e10cSrcweir                         aSpotPos[i].X() += nWidth14;
1005cdf0e10cSrcweir                         aSpotPos[i].Y() += nHeight34;
1006cdf0e10cSrcweir                     }
1007cdf0e10cSrcweir                     break;
1008cdf0e10cSrcweir 
1009cdf0e10cSrcweir                     case 4 :
1010cdf0e10cSrcweir                     {
1011cdf0e10cSrcweir                         // BottomRight-Spot
1012cdf0e10cSrcweir                         aSpotPos[i] = rArea.TopLeft();
1013cdf0e10cSrcweir                         aSpotPos[i].X() += nWidth34;
1014cdf0e10cSrcweir                         aSpotPos[i].Y() += nHeight34;
1015cdf0e10cSrcweir                     }
1016cdf0e10cSrcweir                     break;
1017cdf0e10cSrcweir 
1018cdf0e10cSrcweir                 }
1019cdf0e10cSrcweir 
1020cdf0e10cSrcweir                 aSpotColor[i] = Color( COL_WHITE );
1021cdf0e10cSrcweir                 impGetSdrPageFillColor(rPage, aSpotPos[i], rTextEditPV, rTextEditPV.GetVisibleLayers(), aSpotColor[i], false);
1022cdf0e10cSrcweir             }
1023cdf0e10cSrcweir 
1024cdf0e10cSrcweir             sal_uInt16 aMatch[SPOTCOUNT];
1025cdf0e10cSrcweir 
1026cdf0e10cSrcweir             for ( i = 0; i < SPOTCOUNT; i++ )
1027cdf0e10cSrcweir             {
1028cdf0e10cSrcweir                 // were same spot colors found?
1029cdf0e10cSrcweir                 aMatch[i] = 0;
1030cdf0e10cSrcweir 
1031cdf0e10cSrcweir                 for ( sal_uInt16 j = 0; j < SPOTCOUNT; j++ )
1032cdf0e10cSrcweir                 {
1033cdf0e10cSrcweir                     if( j != i )
1034cdf0e10cSrcweir                     {
1035cdf0e10cSrcweir                         if( aSpotColor[i] == aSpotColor[j] )
1036cdf0e10cSrcweir                         {
1037cdf0e10cSrcweir                             aMatch[i]++;
1038cdf0e10cSrcweir                         }
1039cdf0e10cSrcweir                     }
1040cdf0e10cSrcweir                 }
1041cdf0e10cSrcweir             }
1042cdf0e10cSrcweir 
1043cdf0e10cSrcweir             // highest weight to center spot
1044cdf0e10cSrcweir             aBackground = aSpotColor[0];
1045cdf0e10cSrcweir 
1046cdf0e10cSrcweir             for ( sal_uInt16 nMatchCount = SPOTCOUNT - 1; nMatchCount > 1; nMatchCount-- )
1047cdf0e10cSrcweir             {
1048cdf0e10cSrcweir                 // which spot color was found most?
1049cdf0e10cSrcweir                 for ( i = 0; i < SPOTCOUNT; i++ )
1050cdf0e10cSrcweir                 {
1051cdf0e10cSrcweir                     if( aMatch[i] == nMatchCount )
1052cdf0e10cSrcweir                     {
1053cdf0e10cSrcweir                         aBackground = aSpotColor[i];
1054cdf0e10cSrcweir                         nMatchCount = 1;   // break outer for-loop
1055cdf0e10cSrcweir                         break;
1056cdf0e10cSrcweir                     }
1057cdf0e10cSrcweir                 }
1058cdf0e10cSrcweir             }
1059cdf0e10cSrcweir 	    }
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir         return aBackground;
1062cdf0e10cSrcweir     }
1063cdf0e10cSrcweir } // end of anonymous namespace
1064cdf0e10cSrcweir 
GetTextEditBackgroundColor(const SdrObjEditView & rView)1065cdf0e10cSrcweir Color GetTextEditBackgroundColor(const SdrObjEditView& rView)
1066cdf0e10cSrcweir {
1067cdf0e10cSrcweir     svtools::ColorConfig aColorConfig;
1068cdf0e10cSrcweir     Color aBackground(aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor);
1069cdf0e10cSrcweir 	const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1070cdf0e10cSrcweir 
1071cdf0e10cSrcweir 	if(!rStyleSettings.GetHighContrastMode())
1072cdf0e10cSrcweir 	{
1073cdf0e10cSrcweir 		bool bFound(false);
1074cdf0e10cSrcweir 		SdrTextObj* pText = dynamic_cast< SdrTextObj * >(rView.GetTextEditObject());
1075cdf0e10cSrcweir 
1076cdf0e10cSrcweir         if(pText && pText->IsClosedObj())
1077cdf0e10cSrcweir 		{
1078cdf0e10cSrcweir 			::sdr::table::SdrTableObj* pTable = dynamic_cast< ::sdr::table::SdrTableObj * >( pText );
1079cdf0e10cSrcweir 
1080cdf0e10cSrcweir             if( pTable )
1081cdf0e10cSrcweir 				bFound = GetDraftFillColor(pTable->GetActiveCellItemSet(), aBackground );
1082cdf0e10cSrcweir 
1083cdf0e10cSrcweir 			if( !bFound )
1084cdf0e10cSrcweir 				bFound=GetDraftFillColor(pText->GetMergedItemSet(), aBackground);
1085cdf0e10cSrcweir 		}
1086cdf0e10cSrcweir 
1087cdf0e10cSrcweir         if(!bFound && pText)
1088cdf0e10cSrcweir 		{
1089cdf0e10cSrcweir             SdrPageView* pTextEditPV = rView.GetTextEditPageView();
1090cdf0e10cSrcweir 
1091cdf0e10cSrcweir             if(pTextEditPV)
1092cdf0e10cSrcweir 		    {
1093cdf0e10cSrcweir 			    Point aPvOfs(pText->GetTextEditOffset());
1094cdf0e10cSrcweir 			    const SdrPage* pPg = pTextEditPV->GetPage();
1095cdf0e10cSrcweir 
1096cdf0e10cSrcweir 			    if(pPg)
1097cdf0e10cSrcweir 			    {
1098cdf0e10cSrcweir 				    Rectangle aSnapRect( pText->GetSnapRect() );
1099cdf0e10cSrcweir 				    aSnapRect.Move(aPvOfs.X(), aPvOfs.Y());
1100cdf0e10cSrcweir 
1101cdf0e10cSrcweir 				    return impCalcBackgroundColor(aSnapRect, *pTextEditPV, *pPg);
1102cdf0e10cSrcweir 			    }
1103cdf0e10cSrcweir             }
1104cdf0e10cSrcweir         }
1105cdf0e10cSrcweir     }
1106cdf0e10cSrcweir 
1107cdf0e10cSrcweir     return aBackground;
1108cdf0e10cSrcweir }
1109cdf0e10cSrcweir 
1110cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
1111cdf0e10cSrcweir // eof
1112