1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svdetc.cxx,v $
10 * $Revision: 1.35.18.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include "forbiddencharacterstable.hxx"
34 #include <com/sun/star/embed/XEmbeddedObject.hpp>
35 #include <com/sun/star/embed/EmbedStates.hpp>
36 #include <svx/svdetc.hxx>
37 #include "svditext.hxx"
38 #include <svx/svdmodel.hxx>
39 #include <svx/svdtrans.hxx>
40 #include "svdglob.hxx"
42 #include "svdviter.hxx"
43 #include <svx/svdview.hxx>
44 #include <svx/svdoutl.hxx>
45 #include <vcl/bmpacc.hxx>
46 #include <svx/eeitem.hxx>
47 #include <svtools/itemset.hxx>
48 #include <tools/config.hxx>
49 #include <svtools/cacheoptions.hxx>
50 #include <svtools/whiter.hxx>
51 #include <tools/bigint.hxx>
52 #include "fontitem.hxx"
53 #include <svx/colritem.hxx>
54 #include <svx/fhgtitem.hxx>
55 #include <svx/xgrad.hxx>
56 #include <svx/xfillit0.hxx>
57 #include <svx/xflclit.hxx>
58 #include <svx/xflhtit.hxx>
59 #include <svx/xbtmpit.hxx>
60 #include <svx/xflgrit.hxx>
61 #include <svx/svdoole2.hxx>
62 #include <svtools/itempool.hxx>
63 #include <unotools/localedatawrapper.hxx>
64 #include <com/sun/star/lang/Locale.hpp>
65 #include <comphelper/processfactory.hxx>
66 #include <i18npool/lang.h>
67 #include <unotools/charclass.hxx>
68 #include <svtools/syslocale.hxx>
69 #include <svx/xflbckit.hxx>
70 #include <svx/extrusionbar.hxx>
71 #include <svx/fontworkbar.hxx>
72 #include <vcl/svapp.hxx> //add CHINA001
73 #include <svx/sdr/contact/viewcontact.hxx>
74 #include <svx/svdpage.hxx>
75 #include <svx/svdotable.hxx>
76 #include <svx/sdrhittesthelper.hxx>
78 using namespace ::com::sun::star
;
80 /******************************************************************************
81 * Globale Daten der DrawingEngine
82 ******************************************************************************/
84 SdrGlobalData::SdrGlobalData() :
93 //pSysLocale = new SvtSysLocale;
94 //pCharClass = pSysLocale->GetCharClassPtr();
95 //pLocaleData = pSysLocale->GetLocaleDataPtr();
97 svx::ExtrusionBar::RegisterInterface();
98 svx::FontworkBar::RegisterInterface();
101 SdrGlobalData::~SdrGlobalData()
106 //! do NOT delete pCharClass and pLocaleData
109 const SvtSysLocale
* SdrGlobalData::GetSysLocale()
112 pSysLocale
= new SvtSysLocale
;
115 const CharClass
* SdrGlobalData::GetCharClass()
118 pCharClass
= GetSysLocale()->GetCharClassPtr();
121 const LocaleDataWrapper
* SdrGlobalData::GetLocaleData()
124 pLocaleData
= GetSysLocale()->GetLocaleDataPtr();
127 ////////////////////////////////////////////////////////////////////////////////////////////////////
129 OLEObjCache::OLEObjCache()
132 SvtCacheOptions aCacheOptions
;
134 nSize
= aCacheOptions
.GetDrawingEngineOLE_Objects();
135 pTimer
= new AutoTimer();
136 Link aLink
= LINK(this, OLEObjCache
, UnloadCheckHdl
);
138 pTimer
->SetTimeoutHdl(aLink
);
139 pTimer
->SetTimeout(20000);
145 OLEObjCache::~OLEObjCache()
151 void OLEObjCache::UnloadOnDemand()
153 if ( nSize
< Count() )
155 // more objects than configured cache size try to remove objects
156 // of course not the freshly inserted one at nIndex=0
157 ULONG nCount2
= Count();
158 ULONG nIndex
= nCount2
-1;
159 while( nIndex
&& nCount2
> nSize
)
161 SdrOle2Obj
* pUnloadObj
= (SdrOle2Obj
*) GetObject(nIndex
--);
166 // it is important to get object without reinitialization to avoid reentrance
167 uno::Reference
< embed::XEmbeddedObject
> xUnloadObj
= pUnloadObj
->GetObjRef_NoInit();
169 sal_Bool bUnload
= SdrOle2Obj::CanUnloadRunningObj( xUnloadObj
, pUnloadObj
->GetAspect() );
171 // check whether the object can be unloaded before looking for the parent objects
172 if ( xUnloadObj
.is() && bUnload
)
174 uno::Reference
< frame::XModel
> xUnloadModel( xUnloadObj
->getComponent(), uno::UNO_QUERY
);
175 if ( xUnloadModel
.is() )
177 for ( ULONG nCheckInd
= 0; nCheckInd
< Count(); nCheckInd
++ )
179 SdrOle2Obj
* pCacheObj
= (SdrOle2Obj
*) GetObject(nCheckInd
);
180 if ( pCacheObj
&& pCacheObj
!= pUnloadObj
)
182 uno::Reference
< frame::XModel
> xParentModel
= pCacheObj
->GetParentXModel();
183 if ( xUnloadModel
== xParentModel
)
184 bUnload
= sal_False
; // the object has running embedded objects
190 if ( bUnload
&& UnloadObj(pUnloadObj
) )
191 // object was successfully unloaded
194 catch( uno::Exception
& )
201 void OLEObjCache::SetSize(ULONG nNewSize
)
206 void OLEObjCache::InsertObj(SdrOle2Obj
* pObj
)
210 SdrOle2Obj
* pExistingObj
= (SdrOle2Obj
*)GetObject( 0 );
211 if ( pObj
== pExistingObj
)
212 // the object is already on the top, nothing has to be changed
216 // get the old position of the object to know whether it is already in container
217 ULONG nOldPos
= GetPos( pObj
);
219 // insert object into first position
221 Insert(pObj
, (ULONG
) 0L);
223 if ( nOldPos
== CONTAINER_ENTRY_NOTFOUND
)
225 // a new object was inserted, recalculate the cache
230 void OLEObjCache::RemoveObj(SdrOle2Obj
* pObj
)
235 BOOL
OLEObjCache::UnloadObj(SdrOle2Obj
* pObj
)
237 BOOL bUnloaded
= FALSE
;
240 //#i80528# The old mechanism is completely useless, only taking into account if
241 // in all views the GrafDraft feature is used. This will nearly never have been the
242 // case since no one ever used this option.
244 // A much better (and working) criteria would be the VOC contact count.
245 // The quesion is what will happen whe i make it work now suddenly? I
246 // will try it for 2.4.
247 const sdr::contact::ViewContact
& rViewContact
= pObj
->GetViewContact();
248 const bool bVisible(rViewContact
.HasViewObjectContacts(true));
252 bUnloaded
= pObj
->Unload();
259 IMPL_LINK(OLEObjCache
, UnloadCheckHdl
, AutoTimer
*, /*pTim*/)
265 void ContainerSorter::DoSort(ULONG a
, ULONG b
) const
267 ULONG nAnz
=rCont
.Count();
270 if (a
<b
) ImpSubSort(a
,b
);
273 void ContainerSorter::Is1stLessThan2nd(const void* /*pElem1*/, const void* /*pElem2*/) const
277 void ContainerSorter::ImpSubSort(long nL
, long nR
) const
285 pX
=rCont
.GetObject((nL
+nR
)/2);
288 while (pI
!=pX
&& Compare(pI
,pX
)<0) { i
++; pI
=rCont
.Next(); }
290 while (pJ
!=pX
&& Compare(pX
,pJ
)<0) { j
--; pJ
=rCont
.Prev(); }
298 if (nL
<j
) ImpSubSort(nL
,j
);
299 if (i
<nR
) ImpSubSort(i
,nR
);
302 ////////////////////////////////////////////////////////////////////////////////////////////////////
304 class ImpUShortContainerSorter
: public ContainerSorter
{
306 ImpUShortContainerSorter(Container
& rNewCont
): ContainerSorter(rNewCont
) {}
307 virtual int Compare(const void* pElem1
, const void* pElem2
) const;
310 int ImpUShortContainerSorter::Compare(const void* pElem1
, const void* pElem2
) const
312 USHORT n1
=USHORT(ULONG(pElem1
));
313 USHORT n2
=USHORT(ULONG(pElem2
));
314 return n1
<n2
? -1 : n1
>n2
? 1 : 0;
317 void UShortCont::Sort()
319 ImpUShortContainerSorter
aSorter(aArr
);
323 ////////////////////////////////////////////////////////////////////////////////////////////////////
329 ImpClipMerk(const OutputDevice
& rOut
): aClip(rOut
.GetClipRegion()),bClip(rOut
.IsClipRegion()) {}
330 void Restore(OutputDevice
& rOut
)
332 // Kein Clipping in die Metafileaufzeichnung
333 GDIMetaFile
* pMtf
=rOut
.GetConnectMetaFile();
334 if (pMtf
!=NULL
&& (!pMtf
->IsRecord() || pMtf
->IsPause())) pMtf
=NULL
;
335 if (pMtf
!=NULL
) pMtf
->Pause(TRUE
);
336 if (bClip
) rOut
.SetClipRegion(aClip
);
337 else rOut
.SetClipRegion();
338 if (pMtf
!=NULL
) pMtf
->Pause(FALSE
);
348 ImpColorMerk(const OutputDevice
& rOut
):
349 aLineColor( rOut
.GetLineColor() ),
350 aFillColor( rOut
.GetFillColor() ),
351 aBckgrdColor( rOut
.GetBackground().GetColor() ),
352 aFont (rOut
.GetFont()) {}
354 ImpColorMerk(const OutputDevice
& rOut
, USHORT nMode
)
356 if ( (nMode
& SDRHDC_SAVEPEN
) == SDRHDC_SAVEPEN
)
357 aLineColor
= rOut
.GetLineColor();
359 if ( (nMode
& SDRHDC_SAVEBRUSH
) == SDRHDC_SAVEBRUSH
)
361 aFillColor
= rOut
.GetFillColor();
362 aBckgrdColor
= rOut
.GetBackground().GetColor();
365 if ( (nMode
& SDRHDC_SAVEFONT
) == SDRHDC_SAVEFONT
)
366 aFont
=rOut
.GetFont();
369 void Restore(OutputDevice
& rOut
, USHORT nMode
=SDRHDC_SAVEPENANDBRUSHANDFONT
)
371 if ( (nMode
& SDRHDC_SAVEPEN
) == SDRHDC_SAVEPEN
)
372 rOut
.SetLineColor( aLineColor
);
374 if ( (nMode
& SDRHDC_SAVEBRUSH
) == SDRHDC_SAVEBRUSH
)
376 rOut
.SetFillColor( aFillColor
);
377 rOut
.SetBackground( Wallpaper( aBckgrdColor
) );
379 if ((nMode
& SDRHDC_SAVEFONT
) ==SDRHDC_SAVEFONT
)
381 if (!rOut
.GetFont().IsSameInstance(aFont
))
388 const Color
& GetLineColor() const { return aLineColor
; }
391 ImpSdrHdcMerk::ImpSdrHdcMerk(const OutputDevice
& rOut
, USHORT nNewMode
, FASTBOOL bAutoMerk
):
394 pLineColorMerk(NULL
),
397 if (bAutoMerk
) Save(rOut
);
400 ImpSdrHdcMerk::~ImpSdrHdcMerk()
402 if (pFarbMerk
!=NULL
) delete pFarbMerk
;
403 if (pClipMerk
!=NULL
) delete pClipMerk
;
404 if (pLineColorMerk
!=NULL
) delete pLineColorMerk
;
407 void ImpSdrHdcMerk::Save(const OutputDevice
& rOut
)
419 if (pLineColorMerk
!=NULL
)
421 delete pLineColorMerk
;
422 pLineColorMerk
=NULL
;
424 if ((nMode
& SDRHDC_SAVECLIPPING
) ==SDRHDC_SAVECLIPPING
)
425 pClipMerk
=new ImpClipMerk(rOut
);
427 USHORT nCol
=nMode
& SDRHDC_SAVEPENANDBRUSHANDFONT
;
429 if (nCol
==SDRHDC_SAVEPEN
)
430 pLineColorMerk
=new Color( rOut
.GetLineColor() );
431 else if (nCol
==SDRHDC_SAVEPENANDBRUSHANDFONT
)
432 pFarbMerk
=new ImpColorMerk(rOut
);
434 pFarbMerk
=new ImpColorMerk(rOut
,nCol
);
437 void ImpSdrHdcMerk::Restore(OutputDevice
& rOut
, USHORT nMask
) const
439 nMask
&=nMode
; // nur restaurieren, was auch gesichert wurde
441 if ((nMask
& SDRHDC_SAVECLIPPING
) ==SDRHDC_SAVECLIPPING
&& pClipMerk
!=NULL
)
442 pClipMerk
->Restore(rOut
);
444 USHORT nCol
=nMask
& SDRHDC_SAVEPENANDBRUSHANDFONT
;
446 if (nCol
==SDRHDC_SAVEPEN
)
448 if (pLineColorMerk
!=NULL
)
449 rOut
.SetLineColor(*pLineColorMerk
);
450 else if (pFarbMerk
!=NULL
)
451 rOut
.SetLineColor( pFarbMerk
->GetLineColor() );
452 } else if (nCol
!=0 && pFarbMerk
!=NULL
)
453 pFarbMerk
->Restore(rOut
,nCol
);
456 ////////////////////////////////////////////////////////////////////////////////////////////////////
458 void SdrLinkList::Clear()
460 unsigned nAnz
=GetLinkCount();
461 for (unsigned i
=0; i
<nAnz
; i
++) {
462 delete (Link
*)aList
.GetObject(i
);
467 unsigned SdrLinkList::FindEntry(const Link
& rLink
) const
469 unsigned nAnz
=GetLinkCount();
470 for (unsigned i
=0; i
<nAnz
; i
++) {
471 if (GetLink(i
)==rLink
) return i
;
476 void SdrLinkList::InsertLink(const Link
& rLink
, unsigned nPos
)
478 unsigned nFnd
=FindEntry(rLink
);
481 aList
.Insert(new Link(rLink
),nPos
);
483 DBG_ERROR("SdrLinkList::InsertLink(): Versuch, einen nicht gesetzten Link einzufuegen");
486 DBG_ERROR("SdrLinkList::InsertLink(): Link schon vorhanden");
490 void SdrLinkList::RemoveLink(const Link
& rLink
)
492 unsigned nFnd
=FindEntry(rLink
);
494 Link
* pLink
=(Link
*)aList
.Remove(nFnd
);
497 DBG_ERROR("SdrLinkList::RemoveLink(): Link nicht gefunden");
501 ////////////////////////////////////////////////////////////////////////////////////////////////////
502 // #98988# Re-implement GetDraftFillColor(...)
504 FASTBOOL
GetDraftFillColor(const SfxItemSet
& rSet
, Color
& rCol
)
506 XFillStyle eFill
=((XFillStyleItem
&)rSet
.Get(XATTR_FILLSTYLE
)).GetValue();
507 FASTBOOL
bRetval(FALSE
);
513 rCol
= ((XFillColorItem
&)rSet
.Get(XATTR_FILLCOLOR
)).GetColorValue();
520 Color
aCol1(((XFillHatchItem
&)rSet
.Get(XATTR_FILLHATCH
)).GetHatchValue().GetColor());
521 Color
aCol2(COL_WHITE
);
523 // #97870# when hatch background is activated, use object fill color as hatch color
524 sal_Bool bFillHatchBackground
= ((const XFillBackgroundItem
&)(rSet
.Get(XATTR_FILLBACKGROUND
))).GetValue();
525 if(bFillHatchBackground
)
527 aCol2
= ((const XFillColorItem
&)(rSet
.Get(XATTR_FILLCOLOR
))).GetColorValue();
530 const basegfx::BColor
aAverageColor(basegfx::average(aCol1
.getBColor(), aCol2
.getBColor()));
531 rCol
= Color(aAverageColor
);
536 case XFILL_GRADIENT
: {
537 const XGradient
& rGrad
=((XFillGradientItem
&)rSet
.Get(XATTR_FILLGRADIENT
)).GetGradientValue();
538 Color
aCol1(rGrad
.GetStartColor());
539 Color
aCol2(rGrad
.GetEndColor());
540 const basegfx::BColor
aAverageColor(basegfx::average(aCol1
.getBColor(), aCol2
.getBColor()));
541 rCol
= Color(aAverageColor
);
548 const Bitmap
& rBitmap
= ((XFillBitmapItem
&)rSet
.Get(XATTR_FILLBITMAP
)).GetBitmapValue().GetBitmap();
549 const Size
aSize(rBitmap
.GetSizePixel());
550 const sal_uInt32 nWidth
= aSize
.Width();
551 const sal_uInt32 nHeight
= aSize
.Height();
552 Bitmap
aBitmap(rBitmap
);
553 BitmapReadAccess
* pAccess
= aBitmap
.AcquireReadAccess();
555 if(pAccess
&& nWidth
> 0 && nHeight
> 0)
560 const sal_uInt32
nMaxSteps(8L);
561 const sal_uInt32
nXStep((nWidth
> nMaxSteps
) ? nWidth
/ nMaxSteps
: 1L);
562 const sal_uInt32
nYStep((nHeight
> nMaxSteps
) ? nHeight
/ nMaxSteps
: 1L);
565 for(sal_uInt32
nY(0L); nY
< nHeight
; nY
+= nYStep
)
567 for(sal_uInt32
nX(0L); nX
< nWidth
; nX
+= nXStep
)
569 const BitmapColor
& rCol2
= (pAccess
->HasPalette())
570 ? pAccess
->GetPaletteColor((BYTE
)pAccess
->GetPixel(nY
, nX
))
571 : pAccess
->GetPixel(nY
, nX
);
573 nRt
+= rCol2
.GetRed();
574 nGn
+= rCol2
.GetGreen();
575 nBl
+= rCol2
.GetBlue();
584 rCol
= Color(UINT8(nRt
), UINT8(nGn
), UINT8(nBl
));
591 aBitmap
.ReleaseAccess(pAccess
);
602 ////////////////////////////////////////////////////////////////////////////////////////////////////
604 SdrEngineDefaults::SdrEngineDefaults():
605 aFontName( OutputDevice::GetDefaultFont( DEFAULTFONT_SERIF
, LANGUAGE_SYSTEM
, DEFAULTFONT_FLAGS_ONLYONE
).GetName() ),
606 eFontFamily(FAMILY_ROMAN
),
607 aFontColor(COL_AUTO
),
608 nFontHeight(847), // 847/100mm = ca. 24 Point
609 eMapUnit(MAP_100TH_MM
),
614 SdrEngineDefaults
& SdrEngineDefaults::GetDefaults()
616 SdrGlobalData
& rGlobalData
=GetSdrGlobalData();
617 if (rGlobalData
.pDefaults
==NULL
) {
618 rGlobalData
.pDefaults
=new SdrEngineDefaults
;
620 return *rGlobalData
.pDefaults
;
623 ////////////////////////////////////////////////////////////////////////////////////////////////////
625 void SdrEngineDefaults::LanguageHasChanged()
627 SdrGlobalData
& rGlobalData
=GetSdrGlobalData();
628 if (rGlobalData
.pResMgr
!=NULL
) {
629 delete rGlobalData
.pResMgr
;
630 rGlobalData
.pResMgr
=NULL
;
634 ////////////////////////////////////////////////////////////////////////////////////////////////////
636 SdrOutliner
* SdrMakeOutliner( USHORT nOutlinerMode
, SdrModel
* pModel
)
638 //SdrEngineDefaults& rDefaults = SdrEngineDefaults::GetDefaults();
640 SfxItemPool
* pPool
= &pModel
->GetItemPool();
641 SdrOutliner
* pOutl
= new SdrOutliner( pPool
, nOutlinerMode
);
642 pOutl
->SetEditTextObjectPool( pPool
);
643 pOutl
->SetStyleSheetPool( (SfxStyleSheetPool
*) pModel
->GetStyleSheetPool() );
644 pOutl
->SetDefTab( pModel
->GetDefaultTabulator() );
645 pOutl
->SetForbiddenCharsTable( pModel
->GetForbiddenCharsTable() );
646 pOutl
->SetAsianCompressionMode( pModel
->GetCharCompressType() );
647 pOutl
->SetKernAsianPunctuation( pModel
->IsKernAsianPunctuation() );
648 pOutl
->SetAddExtLeading( pModel
->IsAddExtLeading() );
653 ////////////////////////////////////////////////////////////////////////////////////////////////////
656 SdrLinkList
& ImpGetUserMakeObjHdl()
658 SdrGlobalData
& rGlobalData
=GetSdrGlobalData();
659 return rGlobalData
.aUserMakeObjHdl
;
662 SdrLinkList
& ImpGetUserMakeObjUserDataHdl()
664 SdrGlobalData
& rGlobalData
=GetSdrGlobalData();
665 return rGlobalData
.aUserMakeObjUserDataHdl
;
668 ////////////////////////////////////////////////////////////////////////////////////////////////////
670 ResMgr
* ImpGetResMgr()
672 SdrGlobalData
& rGlobalData
= GetSdrGlobalData();
674 if(!rGlobalData
.pResMgr
)
676 ByteString
aName("svx");
677 rGlobalData
.pResMgr
=
678 ResMgr::CreateResMgr( aName
.GetBuffer(), Application::GetSettings().GetUILocale() );
681 return rGlobalData
.pResMgr
;
684 ////////////////////////////////////////////////////////////////////////////////////////////////////
686 String
ImpGetResStr(sal_uInt16 nResID
)
688 return String(ResId(nResID
, *ImpGetResMgr()));
691 ////////////////////////////////////////////////////////////////////////////////////////////////////
695 String
GetResourceString(sal_uInt16 nResID
)
697 return ImpGetResStr( nResID
);
701 ////////////////////////////////////////////////////////////////////////////////////////////////////
703 BOOL
SearchOutlinerItems(const SfxItemSet
& rSet
, BOOL bInklDefaults
, BOOL
* pbOnlyEE
)
707 BOOL bLookOnly
=pbOnlyEE
!=NULL
;
708 SfxWhichIter
aIter(rSet
);
709 USHORT nWhich
=aIter
.FirstWhich();
710 while (((bLookOnly
&& bOnly
) || !bHas
) && nWhich
!=0) {
711 // bei bInklDefaults ist der gesamte Which-Range
712 // ausschlaggebend, ansonsten nur die gesetzten Items
713 // Disabled und DontCare wird als Loch im Which-Range betrachtet
714 SfxItemState eState
=rSet
.GetItemState(nWhich
);
715 if ((eState
==SFX_ITEM_DEFAULT
&& bInklDefaults
) || eState
==SFX_ITEM_SET
) {
716 if (nWhich
<EE_ITEMS_START
|| nWhich
>EE_ITEMS_END
) bOnly
=FALSE
;
719 nWhich
=aIter
.NextWhich();
721 if (!bHas
) bOnly
=FALSE
;
722 if (pbOnlyEE
!=NULL
) *pbOnlyEE
=bOnly
;
726 USHORT
* RemoveWhichRange(const USHORT
* pOldWhichTable
, USHORT nRangeBeg
, USHORT nRangeEnd
)
728 // insgesamt sind 6 Faelle moeglich (je Range):
729 // [Beg..End] zu entfernender Range
730 // [b..e] [b..e] [b..e] Fall 1,3,2: egal, ganz weg, egal + Ranges
731 // [b........e] [b........e] Fall 4,5 : Bereich verkleinern | in
732 // [b......................e] Fall 6 : Splitting + pOldWhichTable
734 while (pOldWhichTable
[nAnz
]!=0) nAnz
++;
735 nAnz
++; // nAnz muesste nun in jedem Fall eine ungerade Zahl sein (0 am Ende des Arrays)
736 DBG_ASSERT((nAnz
&1)==1,"Joe: RemoveWhichRange: WhichTable hat keine ungerade Anzahl von Eintraegen");
738 // benoetigte Groesse des neuen Arrays ermitteln
742 USHORT nBeg
=pOldWhichTable
[nNum
];
743 USHORT nEnd
=pOldWhichTable
[nNum
+1];
744 if (nEnd
<nRangeBeg
) /*nCase=1*/ ;
745 else if (nBeg
>nRangeEnd
) /* nCase=2 */ ;
746 else if (nBeg
>=nRangeBeg
&& nEnd
<=nRangeEnd
) /* nCase=3 */ nAlloc
-=2;
747 else if (nEnd
<=nRangeEnd
) /* nCase=4 */;
748 else if (nBeg
>=nRangeBeg
) /* nCase=5*/ ;
749 else /* nCase=6 */ nAlloc
+=2;
752 USHORT
* pNewWhichTable
=new USHORT
[nAlloc
];
753 memcpy(pNewWhichTable
,pOldWhichTable
,nAlloc
*sizeof(USHORT
));
754 pNewWhichTable
[nAlloc
-1]=0; // im Falle 3 fehlt die 0 am Ende
755 // nun die unerwuenschten Ranges entfernen
759 USHORT nBeg
=pNewWhichTable
[nNum
];
760 USHORT nEnd
=pNewWhichTable
[nNum
+1];
762 if (nEnd
<nRangeBeg
) nCase
=1;
763 else if (nBeg
>nRangeEnd
) nCase
=2;
764 else if (nBeg
>=nRangeBeg
&& nEnd
<=nRangeEnd
) nCase
=3;
765 else if (nEnd
<=nRangeEnd
) nCase
=4;
766 else if (nBeg
>=nRangeBeg
) nCase
=5;
770 unsigned nTailBytes
=(nAnz
-(nNum
+2))*sizeof(USHORT
);
771 memcpy(&pNewWhichTable
[nNum
],&pNewWhichTable
[nNum
+2],nTailBytes
);
772 nAnz
-=2; // Merken: Array hat sich verkleinert
774 case 4: pNewWhichTable
[nNum
+1]=nRangeBeg
-1; break;
775 case 5: pNewWhichTable
[nNum
]=nRangeEnd
+1; break;
777 unsigned nTailBytes
=(nAnz
-(nNum
+2))*sizeof(USHORT
);
778 memcpy(&pNewWhichTable
[nNum
+4],&pNewWhichTable
[nNum
+2],nTailBytes
);
779 nAnz
+=2; // Merken: Array hat sich vergroessert
780 pNewWhichTable
[nNum
+2]=nRangeEnd
+1;
781 pNewWhichTable
[nNum
+3]=pNewWhichTable
[nNum
+1];
782 pNewWhichTable
[nNum
+1]=nRangeBeg
-1;
786 return pNewWhichTable
;
789 ////////////////////////////////////////////////////////////////////////////////////////////////////
791 SvdProgressInfo::SvdProgressInfo( Link
*_pLink
)
793 DBG_ASSERT(_pLink
!=NULL
,"SvdProgressInfo(): Kein Link angegeben!!");
809 void SvdProgressInfo::Init( ULONG _nSumActionCount
, ULONG _nObjCount
)
811 nSumActionCount
= _nSumActionCount
;
812 nObjCount
= _nObjCount
;
815 BOOL
SvdProgressInfo::ReportActions( ULONG nAnzActions
)
817 nSumCurAction
+= nAnzActions
;
818 nCurAction
+= nAnzActions
;
819 if(nCurAction
> nActionCount
)
820 nCurAction
= nActionCount
;
822 return pLink
->Call(NULL
) == 1L;
825 BOOL
SvdProgressInfo::ReportInserts( ULONG nAnzInserts
)
827 nSumCurAction
+= nAnzInserts
;
828 nCurInsert
+= nAnzInserts
;
830 return pLink
->Call(NULL
) == 1L;
833 BOOL
SvdProgressInfo::ReportRescales( ULONG nAnzRescales
)
835 nSumCurAction
+= nAnzRescales
;
836 return pLink
->Call(NULL
) == 1L;
839 void SvdProgressInfo::SetActionCount( ULONG _nActionCount
)
841 nActionCount
= _nActionCount
;
844 void SvdProgressInfo::SetInsertCount( ULONG _nInsertCount
)
846 nInsertCount
= _nInsertCount
;
849 BOOL
SvdProgressInfo::SetNextObject()
858 return ReportActions(0);
861 void SvdProgressInfo::ReportError()
863 pLink
->Call((void *)1L);
866 ////////////////////////////////////////////////////////////////////////////////////////////////////
867 // #i101872# isolate GetTextEditBackgroundColor to tooling; it woll anyways only be used as long
868 // as text edit is not running on overlay
872 bool impGetSdrObjListFillColor(
873 const SdrObjList
& rList
,
875 const SdrPageView
& rTextEditPV
,
876 const SetOfByte
& rVisLayers
,
879 if(!rList
.GetModel())
883 bool bMaster(rList
.GetPage() ? rList
.GetPage()->IsMasterPage() : false);
885 for(ULONG
no(rList
.GetObjCount()); !bRet
&& no
> 0; )
888 SdrObject
* pObj
= rList
.GetObj(no
);
889 SdrObjList
* pOL
= pObj
->GetSubList();
894 bRet
= impGetSdrObjListFillColor(*pOL
, rPnt
, rTextEditPV
, rVisLayers
, rCol
);
898 SdrTextObj
* pText
= dynamic_cast< SdrTextObj
* >(pObj
);
900 // #108867# Exclude zero master page object (i.e. background shape) from color query
902 && pObj
->IsClosedObj()
903 && (!bMaster
|| (!pObj
->IsNotVisibleAsMaster() && 0 != no
))
904 && pObj
->GetCurrentBoundRect().IsInside(rPnt
)
905 && !pText
->IsHideContour()
906 && SdrObjectPrimitiveHit(*pObj
, rPnt
, 0, rTextEditPV
, &rVisLayers
, false))
908 bRet
= GetDraftFillColor(pObj
->GetMergedItemSet(), rCol
);
916 bool impGetSdrPageFillColor(
917 const SdrPage
& rPage
,
919 const SdrPageView
& rTextEditPV
,
920 const SetOfByte
& rVisLayers
,
922 bool bSkipBackgroundShape
)
924 if(!rPage
.GetModel())
927 bool bRet(impGetSdrObjListFillColor(rPage
, rPnt
, rTextEditPV
, rVisLayers
, rCol
));
929 if(!bRet
&& !rPage
.IsMasterPage())
931 if(rPage
.TRG_HasMasterPage())
933 SetOfByte
aSet(rVisLayers
);
934 aSet
&= rPage
.TRG_GetMasterPageVisibleLayers();
935 SdrPage
& rMasterPage
= rPage
.TRG_GetMasterPage();
937 // #108867# Don't fall back to background shape on
938 // master pages. This is later handled by
939 // GetBackgroundColor, and is necessary to cater for
940 // the silly ordering: 1. shapes, 2. master page
941 // shapes, 3. page background, 4. master page
943 bRet
= impGetSdrPageFillColor(rMasterPage
, rPnt
, rTextEditPV
, aSet
, rCol
, true);
947 // #108867# Only now determine background color from background shapes
948 if(!bRet
&& !bSkipBackgroundShape
)
950 rCol
= rPage
.GetPageBackgroundColor();
957 Color
impCalcBackgroundColor(
958 const Rectangle
& rArea
,
959 const SdrPageView
& rTextEditPV
,
960 const SdrPage
& rPage
)
962 svtools::ColorConfig aColorConfig
;
963 Color
aBackground(aColorConfig
.GetColorValue(svtools::DOCCOLOR
).nColor
);
964 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
966 if(!rStyleSettings
.GetHighContrastMode())
969 const USHORT
SPOTCOUNT(5);
970 Point aSpotPos
[SPOTCOUNT
];
971 Color aSpotColor
[SPOTCOUNT
];
972 ULONG
nHeight( rArea
.GetSize().Height() );
973 ULONG
nWidth( rArea
.GetSize().Width() );
974 ULONG nWidth14
= nWidth
/ 4;
975 ULONG nHeight14
= nHeight
/ 4;
976 ULONG nWidth34
= ( 3 * nWidth
) / 4;
977 ULONG nHeight34
= ( 3 * nHeight
) / 4;
980 for ( i
= 0; i
< SPOTCOUNT
; i
++ )
982 // five spots are used
988 aSpotPos
[i
] = rArea
.Center();
995 aSpotPos
[i
] = rArea
.TopLeft();
996 aSpotPos
[i
].X() += nWidth14
;
997 aSpotPos
[i
].Y() += nHeight14
;
1004 aSpotPos
[i
] = rArea
.TopLeft();
1005 aSpotPos
[i
].X() += nWidth34
;
1006 aSpotPos
[i
].Y() += nHeight14
;
1013 aSpotPos
[i
] = rArea
.TopLeft();
1014 aSpotPos
[i
].X() += nWidth14
;
1015 aSpotPos
[i
].Y() += nHeight34
;
1022 aSpotPos
[i
] = rArea
.TopLeft();
1023 aSpotPos
[i
].X() += nWidth34
;
1024 aSpotPos
[i
].Y() += nHeight34
;
1030 aSpotColor
[i
] = Color( COL_WHITE
);
1031 impGetSdrPageFillColor(rPage
, aSpotPos
[i
], rTextEditPV
, rTextEditPV
.GetVisibleLayers(), aSpotColor
[i
], false);
1034 USHORT aMatch
[SPOTCOUNT
];
1036 for ( i
= 0; i
< SPOTCOUNT
; i
++ )
1038 // were same spot colors found?
1041 for ( USHORT j
= 0; j
< SPOTCOUNT
; j
++ )
1045 if( aSpotColor
[i
] == aSpotColor
[j
] )
1053 // highest weight to center spot
1054 aBackground
= aSpotColor
[0];
1056 for ( USHORT nMatchCount
= SPOTCOUNT
- 1; nMatchCount
> 1; nMatchCount
-- )
1058 // which spot color was found most?
1059 for ( i
= 0; i
< SPOTCOUNT
; i
++ )
1061 if( aMatch
[i
] == nMatchCount
)
1063 aBackground
= aSpotColor
[i
];
1064 nMatchCount
= 1; // break outer for-loop
1073 } // end of anonymous namespace
1075 Color
GetTextEditBackgroundColor(const SdrObjEditView
& rView
)
1077 svtools::ColorConfig aColorConfig
;
1078 Color
aBackground(aColorConfig
.GetColorValue(svtools::DOCCOLOR
).nColor
);
1079 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
1081 if(!rStyleSettings
.GetHighContrastMode())
1084 SdrTextObj
* pText
= dynamic_cast< SdrTextObj
* >(rView
.GetTextEditObject());
1086 if(pText
&& pText
->IsClosedObj())
1088 ::sdr::table::SdrTableObj
* pTable
= dynamic_cast< ::sdr::table::SdrTableObj
* >( pText
);
1091 bFound
= GetDraftFillColor(pTable
->GetActiveCellItemSet(), aBackground
);
1094 bFound
=GetDraftFillColor(pText
->GetMergedItemSet(), aBackground
);
1097 if(!bFound
&& pText
)
1099 SdrPageView
* pTextEditPV
= rView
.GetTextEditPageView();
1103 Point
aPvOfs(pText
->GetTextEditOffset());
1104 const SdrPage
* pPg
= pTextEditPV
->GetPage();
1108 Rectangle
aSnapRect( pText
->GetSnapRect() );
1109 aSnapRect
.Move(aPvOfs
.X(), aPvOfs
.Y());
1111 return impCalcBackgroundColor(aSnapRect
, *pTextEditPV
, *pPg
);
1120 ////////////////////////////////////////////////////////////////////////////////////////////////////