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