Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "sal/config.h"
21 :
22 : #include "editeng/forbiddencharacterstable.hxx"
23 : #include <com/sun/star/embed/XEmbeddedObject.hpp>
24 : #include <com/sun/star/embed/EmbedStates.hpp>
25 : #include "officecfg/Office/Common.hxx"
26 : #include <svx/svdetc.hxx>
27 : #include <svx/svdmodel.hxx>
28 : #include <svx/svdtrans.hxx>
29 : #include "svx/svdglob.hxx"
30 : #include "svx/svdstr.hrc"
31 : #include "svx/svdviter.hxx"
32 : #include <svx/svdview.hxx>
33 : #include <svx/svdoutl.hxx>
34 : #include <vcl/bmpacc.hxx>
35 : #include <editeng/editdata.hxx>
36 : #include <editeng/eeitem.hxx>
37 : #include <svl/itemset.hxx>
38 : #include <svl/whiter.hxx>
39 : #include "editeng/fontitem.hxx"
40 : #include <editeng/colritem.hxx>
41 : #include <editeng/fhgtitem.hxx>
42 : #include <svx/xgrad.hxx>
43 : #include <svx/xfillit0.hxx>
44 : #include <svx/xflclit.hxx>
45 : #include <svx/xflhtit.hxx>
46 : #include <svx/xbtmpit.hxx>
47 : #include <svx/xflgrit.hxx>
48 : #include <svx/svdoole2.hxx>
49 : #include <svl/itempool.hxx>
50 : #include <unotools/localedatawrapper.hxx>
51 : #include <com/sun/star/lang/Locale.hpp>
52 : #include <i18nlangtag/lang.h>
53 : #include <unotools/syslocale.hxx>
54 : #include <svx/xflbckit.hxx>
55 : #include <svx/extrusionbar.hxx>
56 : #include <svx/fontworkbar.hxx>
57 : #include <vcl/svapp.hxx>
58 : #include <svx/sdr/contact/viewcontact.hxx>
59 : #include <svx/svdpage.hxx>
60 : #include <svx/svdotable.hxx>
61 : #include <svx/sdrhittesthelper.hxx>
62 :
63 : using namespace ::com::sun::star;
64 :
65 : /******************************************************************************
66 : * Global data of the DrawingEngine
67 : ******************************************************************************/
68 :
69 68 : SdrGlobalData::SdrGlobalData() :
70 : pSysLocale(NULL),
71 : pLocaleData(NULL),
72 : pOutliner(NULL),
73 : pDefaults(NULL),
74 : pResMgr(NULL),
75 68 : nExchangeFormat(0)
76 : {
77 :
78 68 : svx::ExtrusionBar::RegisterInterface();
79 68 : svx::FontworkBar::RegisterInterface();
80 68 : }
81 :
82 0 : const SvtSysLocale* SdrGlobalData::GetSysLocale()
83 : {
84 0 : if ( !pSysLocale )
85 0 : pSysLocale = new SvtSysLocale;
86 0 : return pSysLocale;
87 : }
88 0 : const LocaleDataWrapper* SdrGlobalData::GetLocaleData()
89 : {
90 0 : if ( !pLocaleData )
91 0 : pLocaleData = GetSysLocale()->GetLocaleDataPtr();
92 0 : return pLocaleData;
93 : }
94 : ////////////////////////////////////////////////////////////////////////////////////////////////////
95 :
96 68 : OLEObjCache::OLEObjCache()
97 68 : : std::vector<SdrOle2Obj*>()
98 : {
99 68 : nSize = officecfg::Office::Common::Cache::DrawingEngine::OLE_Objects::get();
100 68 : pTimer = new AutoTimer();
101 68 : Link aLink = LINK(this, OLEObjCache, UnloadCheckHdl);
102 :
103 68 : pTimer->SetTimeoutHdl(aLink);
104 68 : pTimer->SetTimeout(20000);
105 68 : pTimer->Start();
106 :
107 68 : aLink.Call(pTimer);
108 68 : }
109 :
110 0 : OLEObjCache::~OLEObjCache()
111 : {
112 0 : pTimer->Stop();
113 0 : delete pTimer;
114 0 : }
115 :
116 335 : void OLEObjCache::UnloadOnDemand()
117 : {
118 335 : if ( nSize < size() )
119 : {
120 : // more objects than configured cache size try to remove objects
121 : // of course not the freshly inserted one at nIndex=0
122 0 : sal_uIntPtr nCount2 = size();
123 0 : sal_uIntPtr nIndex = nCount2-1;
124 0 : while( nIndex && nCount2 > nSize )
125 : {
126 0 : SdrOle2Obj* pUnloadObj = (*this)[nIndex--];
127 0 : if ( pUnloadObj )
128 : {
129 : try
130 : {
131 : // it is important to get object without reinitialization to avoid reentrance
132 0 : uno::Reference< embed::XEmbeddedObject > xUnloadObj = pUnloadObj->GetObjRef_NoInit();
133 :
134 0 : sal_Bool bUnload = SdrOle2Obj::CanUnloadRunningObj( xUnloadObj, pUnloadObj->GetAspect() );
135 :
136 : // check whether the object can be unloaded before looking for the parent objects
137 0 : if ( xUnloadObj.is() && bUnload )
138 : {
139 0 : uno::Reference< frame::XModel > xUnloadModel( xUnloadObj->getComponent(), uno::UNO_QUERY );
140 0 : if ( xUnloadModel.is() )
141 : {
142 0 : for ( sal_uIntPtr nCheckInd = 0; nCheckInd < size(); nCheckInd++ )
143 : {
144 0 : SdrOle2Obj* pCacheObj = (*this)[nCheckInd];
145 0 : if ( pCacheObj && pCacheObj != pUnloadObj )
146 : {
147 0 : uno::Reference< frame::XModel > xParentModel = pCacheObj->GetParentXModel();
148 0 : if ( xUnloadModel == xParentModel )
149 0 : bUnload = sal_False; // the object has running embedded objects
150 : }
151 : }
152 0 : }
153 : }
154 :
155 0 : if ( bUnload && UnloadObj(pUnloadObj) )
156 : // object was successfully unloaded
157 0 : nCount2--;
158 : }
159 0 : catch( uno::Exception& )
160 : {}
161 : }
162 : }
163 : }
164 335 : }
165 :
166 805 : void OLEObjCache::InsertObj(SdrOle2Obj* pObj)
167 : {
168 805 : if ( !empty() )
169 : {
170 787 : SdrOle2Obj* pExistingObj = front();
171 787 : if ( pObj == pExistingObj )
172 : // the object is already on the top, nothing has to be changed
173 1406 : return;
174 : }
175 :
176 : // get the old position of the object to know whether it is already in container
177 102 : iterator it = std::find( begin(), end(), pObj );
178 102 : bool bFound = it != end();
179 :
180 102 : if( it != end() )
181 32 : erase( it );
182 : // insert object into first position
183 102 : insert(begin(), pObj);
184 :
185 102 : if ( !bFound )
186 : {
187 : // a new object was inserted, recalculate the cache
188 70 : UnloadOnDemand();
189 : }
190 : }
191 :
192 78 : void OLEObjCache::RemoveObj(SdrOle2Obj* pObj)
193 : {
194 78 : iterator it = std::find( begin(), end(), pObj );
195 78 : if( it != end() )
196 70 : erase( it );
197 78 : }
198 :
199 0 : sal_Bool OLEObjCache::UnloadObj(SdrOle2Obj* pObj)
200 : {
201 0 : sal_Bool bUnloaded = sal_False;
202 0 : if (pObj)
203 : {
204 : //#i80528# The old mechanism is completely useless, only taking into account if
205 : // in all views the GrafDraft feature is used. This will nearly never have been the
206 : // case since no one ever used this option.
207 : //
208 : // A much better (and working) criteria would be the VOC contact count.
209 : // The question is what will happen when i make it work now suddenly? I
210 : // will try it for 2.4.
211 0 : const sdr::contact::ViewContact& rViewContact = pObj->GetViewContact();
212 0 : const bool bVisible(rViewContact.HasViewObjectContacts(true));
213 :
214 0 : if(!bVisible)
215 : {
216 0 : bUnloaded = pObj->Unload();
217 : }
218 : }
219 :
220 0 : return bUnloaded;
221 : }
222 :
223 530 : IMPL_LINK(OLEObjCache, UnloadCheckHdl, AutoTimer*, /*pTim*/)
224 : {
225 265 : UnloadOnDemand();
226 265 : return 0;
227 : }
228 :
229 : ////////////////////////////////////////////////////////////////////////////////////////////////////
230 :
231 0 : void SdrLinkList::Clear()
232 : {
233 0 : unsigned nAnz=GetLinkCount();
234 0 : for (unsigned i=0; i<nAnz; i++) {
235 0 : delete aList[i];
236 : }
237 0 : aList.clear();
238 0 : }
239 :
240 670 : unsigned SdrLinkList::FindEntry(const Link& rLink) const
241 : {
242 670 : unsigned nAnz=GetLinkCount();
243 878 : for (unsigned i=0; i<nAnz; i++) {
244 467 : if (GetLink(i)==rLink) return i;
245 : }
246 411 : return 0xFFFF;
247 : }
248 :
249 411 : void SdrLinkList::InsertLink(const Link& rLink, unsigned nPos)
250 : {
251 411 : unsigned nFnd=FindEntry(rLink);
252 411 : if (nFnd==0xFFFF) {
253 411 : if (rLink.IsSet()) {
254 411 : if(nPos==0xFFFF)
255 411 : aList.push_back(new Link(rLink));
256 : else
257 0 : aList.insert(aList.begin() + nPos, new Link(rLink));
258 : } else {
259 : OSL_FAIL("SdrLinkList::InsertLink(): Tried to insert a link that was not set already.");
260 : }
261 : } else {
262 : OSL_FAIL("SdrLinkList::InsertLink(): Link already in place.");
263 : }
264 411 : }
265 :
266 259 : void SdrLinkList::RemoveLink(const Link& rLink)
267 : {
268 259 : unsigned nFnd=FindEntry(rLink);
269 259 : if (nFnd!=0xFFFF) {
270 259 : Link* pLink = aList[nFnd];
271 259 : aList.erase( aList.begin() + nFnd );
272 259 : delete pLink;
273 : } else {
274 : OSL_FAIL("SdrLinkList::RemoveLink(): Link not found.");
275 : }
276 259 : }
277 :
278 : ////////////////////////////////////////////////////////////////////////////////////////////////////
279 :
280 1921 : bool GetDraftFillColor(const SfxItemSet& rSet, Color& rCol)
281 : {
282 1921 : XFillStyle eFill=((XFillStyleItem&)rSet.Get(XATTR_FILLSTYLE)).GetValue();
283 1921 : bool bRetval = false;
284 :
285 1921 : switch(eFill)
286 : {
287 : case XFILL_SOLID:
288 : {
289 622 : rCol = ((XFillColorItem&)rSet.Get(XATTR_FILLCOLOR)).GetColorValue();
290 622 : bRetval = true;
291 :
292 622 : break;
293 : }
294 : case XFILL_HATCH:
295 : {
296 0 : Color aCol1(((XFillHatchItem&)rSet.Get(XATTR_FILLHATCH)).GetHatchValue().GetColor());
297 0 : Color aCol2(COL_WHITE);
298 :
299 : // when hatched background is activated, use object fill color as hatch color
300 0 : sal_Bool bFillHatchBackground = ((const XFillBackgroundItem&)(rSet.Get(XATTR_FILLBACKGROUND))).GetValue();
301 0 : if(bFillHatchBackground)
302 : {
303 0 : aCol2 = ((const XFillColorItem&)(rSet.Get(XATTR_FILLCOLOR))).GetColorValue();
304 : }
305 :
306 0 : const basegfx::BColor aAverageColor(basegfx::average(aCol1.getBColor(), aCol2.getBColor()));
307 0 : rCol = Color(aAverageColor);
308 0 : bRetval = true;
309 :
310 0 : break;
311 : }
312 : case XFILL_GRADIENT: {
313 0 : const XGradient& rGrad=((XFillGradientItem&)rSet.Get(XATTR_FILLGRADIENT)).GetGradientValue();
314 0 : Color aCol1(rGrad.GetStartColor());
315 0 : Color aCol2(rGrad.GetEndColor());
316 0 : const basegfx::BColor aAverageColor(basegfx::average(aCol1.getBColor(), aCol2.getBColor()));
317 0 : rCol = Color(aAverageColor);
318 0 : bRetval = true;
319 :
320 0 : break;
321 : }
322 : case XFILL_BITMAP:
323 : {
324 0 : Bitmap aBitmap(((XFillBitmapItem&)rSet.Get(XATTR_FILLBITMAP)).GetGraphicObject().GetGraphic().GetBitmapEx().GetBitmap());
325 0 : const Size aSize(aBitmap.GetSizePixel());
326 0 : const sal_uInt32 nWidth = aSize.Width();
327 0 : const sal_uInt32 nHeight = aSize.Height();
328 0 : BitmapReadAccess* pAccess = aBitmap.AcquireReadAccess();
329 :
330 0 : if(pAccess && nWidth > 0 && nHeight > 0)
331 : {
332 0 : sal_uInt32 nRt(0L);
333 0 : sal_uInt32 nGn(0L);
334 0 : sal_uInt32 nBl(0L);
335 0 : const sal_uInt32 nMaxSteps(8L);
336 0 : const sal_uInt32 nXStep((nWidth > nMaxSteps) ? nWidth / nMaxSteps : 1L);
337 0 : const sal_uInt32 nYStep((nHeight > nMaxSteps) ? nHeight / nMaxSteps : 1L);
338 0 : sal_uInt32 nAnz(0L);
339 :
340 0 : for(sal_uInt32 nY(0L); nY < nHeight; nY += nYStep)
341 : {
342 0 : for(sal_uInt32 nX(0L); nX < nWidth; nX += nXStep)
343 : {
344 0 : const BitmapColor& rCol2 = pAccess->GetColor(nY, nX);
345 :
346 0 : nRt += rCol2.GetRed();
347 0 : nGn += rCol2.GetGreen();
348 0 : nBl += rCol2.GetBlue();
349 0 : nAnz++;
350 0 : }
351 : }
352 :
353 0 : nRt /= nAnz;
354 0 : nGn /= nAnz;
355 0 : nBl /= nAnz;
356 :
357 0 : rCol = Color(sal_uInt8(nRt), sal_uInt8(nGn), sal_uInt8(nBl));
358 :
359 0 : bRetval = true;
360 : }
361 :
362 0 : if(pAccess)
363 : {
364 0 : aBitmap.ReleaseAccess(pAccess);
365 : }
366 :
367 0 : break;
368 : }
369 1299 : default: break;
370 : }
371 :
372 1921 : return bRetval;
373 : }
374 :
375 : ////////////////////////////////////////////////////////////////////////////////////////////////////
376 :
377 66 : SdrEngineDefaults::SdrEngineDefaults():
378 132 : aFontName( OutputDevice::GetDefaultFont( DEFAULTFONT_SERIF, LANGUAGE_SYSTEM, DEFAULTFONT_FLAGS_ONLYONE ).GetName() ),
379 : eFontFamily(FAMILY_ROMAN),
380 : aFontColor(COL_AUTO),
381 : nFontHeight(847), // 847/100mm = ca. 24 Point
382 : eMapUnit(MAP_100TH_MM),
383 132 : aMapFraction(1,1)
384 : {
385 66 : }
386 :
387 4564 : SdrEngineDefaults& SdrEngineDefaults::GetDefaults()
388 : {
389 4564 : SdrGlobalData& rGlobalData=GetSdrGlobalData();
390 4564 : if (rGlobalData.pDefaults==NULL) {
391 66 : rGlobalData.pDefaults=new SdrEngineDefaults;
392 : }
393 4564 : return *rGlobalData.pDefaults;
394 : }
395 :
396 : ////////////////////////////////////////////////////////////////////////////////////////////////////
397 :
398 13162 : SdrOutliner* SdrMakeOutliner( sal_uInt16 nOutlinerMode, SdrModel* pModel )
399 : {
400 13162 : SfxItemPool* pPool = &pModel->GetItemPool();
401 13162 : SdrOutliner* pOutl = new SdrOutliner( pPool, nOutlinerMode );
402 13162 : pOutl->SetEditTextObjectPool( pPool );
403 13162 : pOutl->SetStyleSheetPool( (SfxStyleSheetPool*) pModel->GetStyleSheetPool() );
404 13162 : pOutl->SetDefTab( pModel->GetDefaultTabulator() );
405 13162 : pOutl->SetForbiddenCharsTable( pModel->GetForbiddenCharsTable() );
406 13162 : pOutl->SetAsianCompressionMode( pModel->GetCharCompressType() );
407 13162 : pOutl->SetKernAsianPunctuation( pModel->IsKernAsianPunctuation() );
408 13162 : pOutl->SetAddExtLeading( pModel->IsAddExtLeading() );
409 :
410 13162 : return pOutl;
411 : }
412 :
413 : ////////////////////////////////////////////////////////////////////////////////////////////////////
414 :
415 :
416 1692 : SdrLinkList& ImpGetUserMakeObjHdl()
417 : {
418 1692 : SdrGlobalData& rGlobalData=GetSdrGlobalData();
419 1692 : return rGlobalData.aUserMakeObjHdl;
420 : }
421 :
422 468 : SdrLinkList& ImpGetUserMakeObjUserDataHdl()
423 : {
424 468 : SdrGlobalData& rGlobalData=GetSdrGlobalData();
425 468 : return rGlobalData.aUserMakeObjUserDataHdl;
426 : }
427 :
428 : ////////////////////////////////////////////////////////////////////////////////////////////////////
429 :
430 1804 : ResMgr* ImpGetResMgr()
431 : {
432 1804 : SdrGlobalData& rGlobalData = GetSdrGlobalData();
433 :
434 1804 : if(!rGlobalData.pResMgr)
435 : {
436 : rGlobalData.pResMgr =
437 30 : ResMgr::CreateResMgr( "svx", Application::GetSettings().GetUILanguageTag() );
438 : }
439 :
440 1804 : return rGlobalData.pResMgr;
441 : }
442 :
443 : ////////////////////////////////////////////////////////////////////////////////////////////////////
444 :
445 1749 : String ImpGetResStr(sal_uInt16 nResID)
446 : {
447 1749 : return String(ResId(nResID, *ImpGetResMgr()));
448 : }
449 :
450 : ////////////////////////////////////////////////////////////////////////////////////////////////////
451 :
452 : namespace sdr
453 : {
454 0 : String GetResourceString(sal_uInt16 nResID)
455 : {
456 0 : return ImpGetResStr( nResID );
457 : }
458 : }
459 :
460 : ////////////////////////////////////////////////////////////////////////////////////////////////////
461 :
462 0 : sal_Bool SearchOutlinerItems(const SfxItemSet& rSet, sal_Bool bInklDefaults, sal_Bool* pbOnlyEE)
463 : {
464 0 : sal_Bool bHas=sal_False;
465 0 : sal_Bool bOnly=sal_True;
466 0 : bool bLookOnly=pbOnlyEE!=NULL;
467 0 : SfxWhichIter aIter(rSet);
468 0 : sal_uInt16 nWhich=aIter.FirstWhich();
469 0 : while (((bLookOnly && bOnly) || !bHas) && nWhich!=0) {
470 : // For bInklDefaults, the entire Which range is decisive,
471 : // in other cases only the set items are.
472 : // Disabled and DontCare are regarded as holes in the Which range.
473 0 : SfxItemState eState=rSet.GetItemState(nWhich);
474 0 : if ((eState==SFX_ITEM_DEFAULT && bInklDefaults) || eState==SFX_ITEM_SET) {
475 0 : if (nWhich<EE_ITEMS_START || nWhich>EE_ITEMS_END) bOnly=sal_False;
476 0 : else bHas=sal_True;
477 : }
478 0 : nWhich=aIter.NextWhich();
479 : }
480 0 : if (!bHas) bOnly=sal_False;
481 0 : if (pbOnlyEE!=NULL) *pbOnlyEE=bOnly;
482 0 : return bHas;
483 : }
484 :
485 0 : sal_uInt16* RemoveWhichRange(const sal_uInt16* pOldWhichTable, sal_uInt16 nRangeBeg, sal_uInt16 nRangeEnd)
486 : {
487 : // Six possible cases (per range):
488 : // [Beg..End] Range, to delete
489 : // [b..e] [b..e] [b..e] Cases 1,3,2: doesn't matter, delete, doesn't matter + Ranges
490 : // [b........e] [b........e] Cases 4,5 : shrink range | in
491 : // [b......................e] Case 6 : splitting + pOldWhichTable
492 0 : sal_uInt16 nAnz=0;
493 0 : while (pOldWhichTable[nAnz]!=0) nAnz++;
494 0 : nAnz++; // nAnz should now be an odd number (0 for end of array)
495 : DBG_ASSERT((nAnz&1)==1,"RemoveWhichRange: WhichTable doesn't have an odd number of entries.");
496 0 : sal_uInt16 nAlloc=nAnz;
497 : // check necessary size of new array
498 0 : sal_uInt16 nNum=nAnz-1;
499 0 : while (nNum!=0) {
500 0 : nNum-=2;
501 0 : sal_uInt16 nBeg=pOldWhichTable[nNum];
502 0 : sal_uInt16 nEnd=pOldWhichTable[nNum+1];
503 0 : if (nEnd<nRangeBeg) /*nCase=1*/ ;
504 0 : else if (nBeg>nRangeEnd) /* nCase=2 */ ;
505 0 : else if (nBeg>=nRangeBeg && nEnd<=nRangeEnd) /* nCase=3 */ nAlloc-=2;
506 0 : else if (nEnd<=nRangeEnd) /* nCase=4 */;
507 0 : else if (nBeg>=nRangeBeg) /* nCase=5*/ ;
508 0 : else /* nCase=6 */ nAlloc+=2;
509 : }
510 :
511 0 : sal_uInt16* pNewWhichTable=new sal_uInt16[nAlloc];
512 0 : memcpy(pNewWhichTable,pOldWhichTable,nAlloc*sizeof(sal_uInt16));
513 0 : pNewWhichTable[nAlloc-1]=0; // in case 3, there's no 0 at the end.
514 : // now remove the unwanted ranges
515 0 : nNum=nAlloc-1;
516 0 : while (nNum!=0) {
517 0 : nNum-=2;
518 0 : sal_uInt16 nBeg=pNewWhichTable[nNum];
519 0 : sal_uInt16 nEnd=pNewWhichTable[nNum+1];
520 0 : unsigned nCase=0;
521 0 : if (nEnd<nRangeBeg) nCase=1;
522 0 : else if (nBeg>nRangeEnd) nCase=2;
523 0 : else if (nBeg>=nRangeBeg && nEnd<=nRangeEnd) nCase=3;
524 0 : else if (nEnd<=nRangeEnd) nCase=4;
525 0 : else if (nBeg>=nRangeBeg) nCase=5;
526 0 : else nCase=6;
527 0 : switch (nCase) {
528 : case 3: {
529 0 : unsigned nTailBytes=(nAnz-(nNum+2))*sizeof(sal_uInt16);
530 0 : memcpy(&pNewWhichTable[nNum],&pNewWhichTable[nNum+2],nTailBytes);
531 0 : nAnz-=2; // remember: array is now smaller
532 0 : } break;
533 0 : case 4: pNewWhichTable[nNum+1]=nRangeBeg-1; break;
534 0 : case 5: pNewWhichTable[nNum]=nRangeEnd+1; break;
535 : case 6: {
536 0 : unsigned nTailBytes=(nAnz-(nNum+2))*sizeof(sal_uInt16);
537 0 : memcpy(&pNewWhichTable[nNum+4],&pNewWhichTable[nNum+2],nTailBytes);
538 0 : nAnz+=2; // remember:array is now larger
539 0 : pNewWhichTable[nNum+2]=nRangeEnd+1;
540 0 : pNewWhichTable[nNum+3]=pNewWhichTable[nNum+1];
541 0 : pNewWhichTable[nNum+1]=nRangeBeg-1;
542 0 : } break;
543 : } // switch
544 : }
545 0 : return pNewWhichTable;
546 : }
547 :
548 : ////////////////////////////////////////////////////////////////////////////////////////////////////
549 :
550 0 : SvdProgressInfo::SvdProgressInfo( Link *_pLink )
551 : {
552 : DBG_ASSERT(_pLink!=NULL,"SvdProgressInfo(): No Link stated!");
553 :
554 0 : pLink = _pLink;
555 0 : nSumActionCount = 0;
556 0 : nSumCurAction = 0;
557 :
558 0 : nObjCount = 0;
559 0 : nCurObj = 0;
560 :
561 0 : nActionCount = 0;
562 0 : nCurAction = 0;
563 :
564 0 : nInsertCount = 0;
565 0 : nCurInsert = 0;
566 0 : }
567 :
568 0 : void SvdProgressInfo::Init( sal_uIntPtr _nSumActionCount, sal_uIntPtr _nObjCount )
569 : {
570 0 : nSumActionCount = _nSumActionCount;
571 0 : nObjCount = _nObjCount;
572 0 : }
573 :
574 0 : sal_Bool SvdProgressInfo::ReportActions( sal_uIntPtr nAnzActions )
575 : {
576 0 : nSumCurAction += nAnzActions;
577 0 : nCurAction += nAnzActions;
578 0 : if(nCurAction > nActionCount)
579 0 : nCurAction = nActionCount;
580 :
581 0 : return pLink->Call(NULL) == 1L;
582 : }
583 :
584 0 : sal_Bool SvdProgressInfo::ReportInserts( sal_uIntPtr nAnzInserts )
585 : {
586 0 : nSumCurAction += nAnzInserts;
587 0 : nCurInsert += nAnzInserts;
588 :
589 0 : return pLink->Call(NULL) == 1L;
590 : }
591 :
592 0 : sal_Bool SvdProgressInfo::ReportRescales( sal_uIntPtr nAnzRescales )
593 : {
594 0 : nSumCurAction += nAnzRescales;
595 0 : return pLink->Call(NULL) == 1L;
596 : }
597 :
598 0 : void SvdProgressInfo::SetActionCount( sal_uIntPtr _nActionCount )
599 : {
600 0 : nActionCount = _nActionCount;
601 0 : }
602 :
603 0 : void SvdProgressInfo::SetInsertCount( sal_uIntPtr _nInsertCount )
604 : {
605 0 : nInsertCount = _nInsertCount;
606 0 : }
607 :
608 0 : sal_Bool SvdProgressInfo::SetNextObject()
609 : {
610 0 : nActionCount = 0;
611 0 : nCurAction = 0;
612 :
613 0 : nInsertCount = 0;
614 0 : nCurInsert = 0;
615 :
616 0 : nCurObj++;
617 0 : return ReportActions(0);
618 : }
619 :
620 0 : void SvdProgressInfo::ReportError()
621 : {
622 0 : pLink->Call((void *)1L);
623 0 : }
624 :
625 : ////////////////////////////////////////////////////////////////////////////////////////////////////
626 : // #i101872# isolate GetTextEditBackgroundColor to tooling; it will anyways only be used as long
627 : // as text edit is not running on overlay
628 :
629 : namespace
630 : {
631 0 : bool impGetSdrObjListFillColor(
632 : const SdrObjList& rList,
633 : const Point& rPnt,
634 : const SdrPageView& rTextEditPV,
635 : const SetOfByte& rVisLayers,
636 : Color& rCol)
637 : {
638 0 : if(!rList.GetModel())
639 0 : return false;
640 :
641 0 : bool bRet(false);
642 0 : bool bMaster(rList.GetPage() ? rList.GetPage()->IsMasterPage() : false);
643 :
644 0 : for(sal_uIntPtr no(rList.GetObjCount()); !bRet && no > 0; )
645 : {
646 0 : no--;
647 0 : SdrObject* pObj = rList.GetObj(no);
648 0 : SdrObjList* pOL = pObj->GetSubList();
649 :
650 0 : if(pOL)
651 : {
652 : // group object
653 0 : bRet = impGetSdrObjListFillColor(*pOL, rPnt, rTextEditPV, rVisLayers, rCol);
654 : }
655 : else
656 : {
657 0 : SdrTextObj* pText = dynamic_cast< SdrTextObj * >(pObj);
658 :
659 : // Exclude zero master page object (i.e. background shape) from color query
660 0 : if(pText
661 0 : && pObj->IsClosedObj()
662 0 : && (!bMaster || (!pObj->IsNotVisibleAsMaster() && 0 != no))
663 0 : && pObj->GetCurrentBoundRect().IsInside(rPnt)
664 0 : && !pText->IsHideContour()
665 0 : && SdrObjectPrimitiveHit(*pObj, rPnt, 0, rTextEditPV, &rVisLayers, false))
666 : {
667 0 : bRet = GetDraftFillColor(pObj->GetMergedItemSet(), rCol);
668 : }
669 : }
670 : }
671 :
672 0 : return bRet;
673 : }
674 :
675 0 : bool impGetSdrPageFillColor(
676 : const SdrPage& rPage,
677 : const Point& rPnt,
678 : const SdrPageView& rTextEditPV,
679 : const SetOfByte& rVisLayers,
680 : Color& rCol,
681 : bool bSkipBackgroundShape)
682 : {
683 0 : if(!rPage.GetModel())
684 0 : return false;
685 :
686 0 : bool bRet(impGetSdrObjListFillColor(rPage, rPnt, rTextEditPV, rVisLayers, rCol));
687 :
688 0 : if(!bRet && !rPage.IsMasterPage())
689 : {
690 0 : if(rPage.TRG_HasMasterPage())
691 : {
692 0 : SetOfByte aSet(rVisLayers);
693 0 : aSet &= rPage.TRG_GetMasterPageVisibleLayers();
694 0 : SdrPage& rMasterPage = rPage.TRG_GetMasterPage();
695 :
696 : // Don't fall back to background shape on
697 : // master pages. This is later handled by
698 : // GetBackgroundColor, and is necessary to cater for
699 : // the silly ordering: 1. shapes, 2. master page
700 : // shapes, 3. page background, 4. master page
701 : // background.
702 0 : bRet = impGetSdrPageFillColor(rMasterPage, rPnt, rTextEditPV, aSet, rCol, true);
703 : }
704 : }
705 :
706 : // Only now determine background color from background shapes
707 0 : if(!bRet && !bSkipBackgroundShape)
708 : {
709 0 : rCol = rPage.GetPageBackgroundColor();
710 0 : return true;
711 : }
712 :
713 0 : return bRet;
714 : }
715 :
716 0 : Color impCalcBackgroundColor(
717 : const Rectangle& rArea,
718 : const SdrPageView& rTextEditPV,
719 : const SdrPage& rPage)
720 : {
721 0 : svtools::ColorConfig aColorConfig;
722 0 : Color aBackground(aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor);
723 0 : const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
724 :
725 0 : if(!rStyleSettings.GetHighContrastMode())
726 : {
727 : // search in page
728 0 : const sal_uInt16 SPOTCOUNT(5);
729 0 : Point aSpotPos[SPOTCOUNT];
730 0 : Color aSpotColor[SPOTCOUNT];
731 0 : sal_uIntPtr nHeight( rArea.GetSize().Height() );
732 0 : sal_uIntPtr nWidth( rArea.GetSize().Width() );
733 0 : sal_uIntPtr nWidth14 = nWidth / 4;
734 0 : sal_uIntPtr nHeight14 = nHeight / 4;
735 0 : sal_uIntPtr nWidth34 = ( 3 * nWidth ) / 4;
736 0 : sal_uIntPtr nHeight34 = ( 3 * nHeight ) / 4;
737 :
738 : sal_uInt16 i;
739 0 : for ( i = 0; i < SPOTCOUNT; i++ )
740 : {
741 : // five spots are used
742 0 : switch ( i )
743 : {
744 : case 0 :
745 : {
746 : // Center-Spot
747 0 : aSpotPos[i] = rArea.Center();
748 : }
749 0 : break;
750 :
751 : case 1 :
752 : {
753 : // TopLeft-Spot
754 0 : aSpotPos[i] = rArea.TopLeft();
755 0 : aSpotPos[i].X() += nWidth14;
756 0 : aSpotPos[i].Y() += nHeight14;
757 : }
758 0 : break;
759 :
760 : case 2 :
761 : {
762 : // TopRight-Spot
763 0 : aSpotPos[i] = rArea.TopLeft();
764 0 : aSpotPos[i].X() += nWidth34;
765 0 : aSpotPos[i].Y() += nHeight14;
766 : }
767 0 : break;
768 :
769 : case 3 :
770 : {
771 : // BottomLeft-Spot
772 0 : aSpotPos[i] = rArea.TopLeft();
773 0 : aSpotPos[i].X() += nWidth14;
774 0 : aSpotPos[i].Y() += nHeight34;
775 : }
776 0 : break;
777 :
778 : case 4 :
779 : {
780 : // BottomRight-Spot
781 0 : aSpotPos[i] = rArea.TopLeft();
782 0 : aSpotPos[i].X() += nWidth34;
783 0 : aSpotPos[i].Y() += nHeight34;
784 : }
785 0 : break;
786 :
787 : }
788 :
789 0 : aSpotColor[i] = Color( COL_WHITE );
790 0 : impGetSdrPageFillColor(rPage, aSpotPos[i], rTextEditPV, rTextEditPV.GetVisibleLayers(), aSpotColor[i], false);
791 : }
792 :
793 : sal_uInt16 aMatch[SPOTCOUNT];
794 :
795 0 : for ( i = 0; i < SPOTCOUNT; i++ )
796 : {
797 : // were same spot colors found?
798 0 : aMatch[i] = 0;
799 :
800 0 : for ( sal_uInt16 j = 0; j < SPOTCOUNT; j++ )
801 : {
802 0 : if( j != i )
803 : {
804 0 : if( aSpotColor[i] == aSpotColor[j] )
805 : {
806 0 : aMatch[i]++;
807 : }
808 : }
809 : }
810 : }
811 :
812 : // highest weight to center spot
813 0 : aBackground = aSpotColor[0];
814 :
815 0 : for ( sal_uInt16 nMatchCount = SPOTCOUNT - 1; nMatchCount > 1; nMatchCount-- )
816 : {
817 : // which spot color was found most?
818 0 : for ( i = 0; i < SPOTCOUNT; i++ )
819 : {
820 0 : if( aMatch[i] == nMatchCount )
821 : {
822 0 : aBackground = aSpotColor[i];
823 0 : nMatchCount = 1; // break outer for-loop
824 0 : break;
825 : }
826 : }
827 : }
828 : }
829 :
830 0 : return aBackground;
831 : }
832 : } // end of anonymous namespace
833 :
834 0 : Color GetTextEditBackgroundColor(const SdrObjEditView& rView)
835 : {
836 0 : svtools::ColorConfig aColorConfig;
837 0 : Color aBackground(aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor);
838 0 : const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
839 :
840 0 : if(!rStyleSettings.GetHighContrastMode())
841 : {
842 0 : bool bFound(false);
843 0 : SdrTextObj* pText = dynamic_cast< SdrTextObj * >(rView.GetTextEditObject());
844 :
845 0 : if(pText && pText->IsClosedObj())
846 : {
847 0 : ::sdr::table::SdrTableObj* pTable = dynamic_cast< ::sdr::table::SdrTableObj * >( pText );
848 :
849 0 : if( pTable )
850 0 : bFound = GetDraftFillColor(pTable->GetActiveCellItemSet(), aBackground );
851 :
852 0 : if( !bFound )
853 0 : bFound=GetDraftFillColor(pText->GetMergedItemSet(), aBackground);
854 : }
855 :
856 0 : if(!bFound && pText)
857 : {
858 0 : SdrPageView* pTextEditPV = rView.GetTextEditPageView();
859 :
860 0 : if(pTextEditPV)
861 : {
862 0 : Point aPvOfs(pText->GetTextEditOffset());
863 0 : const SdrPage* pPg = pTextEditPV->GetPage();
864 :
865 0 : if(pPg)
866 : {
867 0 : Rectangle aSnapRect( pText->GetSnapRect() );
868 0 : aSnapRect.Move(aPvOfs.X(), aPvOfs.Y());
869 :
870 0 : return impCalcBackgroundColor(aSnapRect, *pTextEditPV, *pPg);
871 : }
872 : }
873 : }
874 : }
875 :
876 0 : return aBackground;
877 258 : }
878 :
879 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|