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 
21 #include <memory>
22 #include <toolkit/helper/convert.hxx>
23 #include <toolkit/helper/vclunohelper.hxx>
24 #include <SectionView.hxx>
25 #include <UITools.hxx>
26 #include <Formula.hxx>
27 #include <FunctionHelper.hxx>
28 #include <reportformula.hxx>
29 
30 #include <tools/diagnose_ex.h>
31 
32 #include <vcl/settings.hxx>
33 #include <vcl/syswin.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/unohelp.hxx>
36 #include <vcl/window.hxx>
37 
38 #include <com/sun/star/lang/NullPointerException.hpp>
39 #include <com/sun/star/beans/NamedValue.hpp>
40 #include <com/sun/star/beans/PropertyAttribute.hpp>
41 #include <svx/svdpool.hxx>
42 
43 #include <editeng/charscaleitem.hxx>
44 #include <editeng/brushitem.hxx>
45 #include <editeng/fontitem.hxx>
46 #include <editeng/emphasismarkitem.hxx>
47 #include <editeng/postitem.hxx>
48 #include <editeng/udlnitem.hxx>
49 #include <editeng/crossedoutitem.hxx>
50 #include <editeng/contouritem.hxx>
51 #include <editeng/langitem.hxx>
52 #include <editeng/wghtitem.hxx>
53 #include <editeng/fhgtitem.hxx>
54 #include <editeng/shdditem.hxx>
55 #include <editeng/escapementitem.hxx>
56 #include <editeng/wrlmitem.hxx>
57 #include <editeng/cmapitem.hxx>
58 #include <editeng/kernitem.hxx>
59 #include <editeng/blinkitem.hxx>
60 #include <editeng/flstitem.hxx>
61 #include <editeng/autokernitem.hxx>
62 #include <editeng/colritem.hxx>
63 #include <editeng/justifyitem.hxx>
64 #include <svx/drawitem.hxx>
65 #include <editeng/twolinesitem.hxx>
66 #include <editeng/charreliefitem.hxx>
67 #include <editeng/charrotateitem.hxx>
68 #include <editeng/charhiddenitem.hxx>
69 #include <editeng/memberids.h>
70 #include <svx/xgrscit.hxx>
71 #include <svx/svditer.hxx>
72 #include <svx/xtable.hxx>
73 #include <svx/svdview.hxx>
74 #include <svx/svdpage.hxx>
75 #include <svx/svxdlg.hxx>
76 #include <svx/unoprov.hxx>
77 #include <svx/svxids.hrc>
78 
79 #include <unotools/charclass.hxx>
80 #include <svtools/ctrltool.hxx>
81 #include <svl/itempool.hxx>
82 #include <svl/itemset.hxx>
83 #include <svl/sharedstringpool.hxx>
84 
85 #include <comphelper/propmultiplex.hxx>
86 #include <comphelper/namedvaluecollection.hxx>
87 
88 #include <connectivity/dbexception.hxx>
89 #include <connectivity/dbtools.hxx>
90 
91 #include <com/sun/star/style/VerticalAlignment.hpp>
92 #include <com/sun/star/report/XShape.hpp>
93 #include <com/sun/star/sdb/XParametersSupplier.hpp>
94 #include <com/sun/star/sdb/SQLContext.hpp>
95 #include <i18nlangtag/languagetag.hxx>
96 #include <dlgpage.hxx>
97 #include <strings.hxx>
98 #include <core_resource.hxx>
99 #include <RptObject.hxx>
100 #include <RptDef.hxx>
101 #include <strings.hrc>
102 #include <ReportDefinition.hxx>
103 #include <RptModel.hxx>
104 
105 #include <svx/xflbckit.hxx>
106 #include <svx/xflbmpit.hxx>
107 #include <svx/xflbmsli.hxx>
108 #include <svx/xflbmsxy.hxx>
109 #include <svx/xflbmtit.hxx>
110 #include <svx/xflboxy.hxx>
111 #include <svx/xflbstit.hxx>
112 #include <svx/xflbtoxy.hxx>
113 
114 #include <svx/xbtmpit.hxx>
115 #include <svx/xfillit0.hxx>
116 #include <svx/xfltrit.hxx>
117 #include <svx/xflclit.hxx>
118 #include <svx/xflgrit.hxx>
119 #include <svx/xflhtit.hxx>
120 #include <svx/xflftrit.hxx>
121 #include <svx/xsflclit.hxx>
122 
123 #define ITEMID_FONT                     XATTR_FILL_LAST + 1
124 #define ITEMID_FONTHEIGHT               XATTR_FILL_LAST + 2
125 #define ITEMID_LANGUAGE                 XATTR_FILL_LAST + 3
126 
127 #define ITEMID_POSTURE                  XATTR_FILL_LAST + 4
128 #define ITEMID_WEIGHT                   XATTR_FILL_LAST + 5
129 #define ITEMID_SHADOWED                 XATTR_FILL_LAST + 6
130 #define ITEMID_WORDLINEMODE             XATTR_FILL_LAST + 7
131 #define ITEMID_CONTOUR                  XATTR_FILL_LAST + 8
132 #define ITEMID_CROSSEDOUT               XATTR_FILL_LAST + 9
133 #define ITEMID_UNDERLINE                XATTR_FILL_LAST + 10
134 
135 #define ITEMID_COLOR                    XATTR_FILL_LAST + 11
136 #define ITEMID_KERNING                  XATTR_FILL_LAST + 12
137 #define ITEMID_CASEMAP                  XATTR_FILL_LAST + 13
138 
139 #define ITEMID_ESCAPEMENT               XATTR_FILL_LAST + 14
140 #define ITEMID_FONTLIST                 XATTR_FILL_LAST + 15
141 #define ITEMID_AUTOKERN                 XATTR_FILL_LAST + 16
142 #define ITEMID_COLOR_TABLE              XATTR_FILL_LAST + 17
143 #define ITEMID_BLINK                    XATTR_FILL_LAST + 18
144 #define ITEMID_EMPHASISMARK             XATTR_FILL_LAST + 19
145 #define ITEMID_TWOLINES                 XATTR_FILL_LAST + 20
146 #define ITEMID_CHARROTATE               XATTR_FILL_LAST + 21
147 #define ITEMID_CHARSCALE_W              XATTR_FILL_LAST + 22
148 #define ITEMID_CHARRELIEF               XATTR_FILL_LAST + 23
149 #define ITEMID_CHARHIDDEN               XATTR_FILL_LAST + 24
150 #define ITEMID_BRUSH                    XATTR_FILL_LAST + 25
151 #define ITEMID_HORJUSTIFY               XATTR_FILL_LAST + 26
152 #define ITEMID_VERJUSTIFY               XATTR_FILL_LAST + 27
153 #define ITEMID_FONT_ASIAN               XATTR_FILL_LAST + 28
154 #define ITEMID_FONTHEIGHT_ASIAN         XATTR_FILL_LAST + 29
155 #define ITEMID_LANGUAGE_ASIAN           XATTR_FILL_LAST + 30
156 #define ITEMID_POSTURE_ASIAN            XATTR_FILL_LAST + 31
157 #define ITEMID_WEIGHT_ASIAN             XATTR_FILL_LAST + 32
158 #define ITEMID_FONT_COMPLEX             XATTR_FILL_LAST + 33
159 #define ITEMID_FONTHEIGHT_COMPLEX       XATTR_FILL_LAST + 34
160 #define ITEMID_LANGUAGE_COMPLEX         XATTR_FILL_LAST + 35
161 #define ITEMID_POSTURE_COMPLEX          XATTR_FILL_LAST + 36
162 #define ITEMID_WEIGHT_COMPLEX           XATTR_FILL_LAST + 37
163 
164 #define WESTERN 0
165 #define ASIAN   1
166 #define COMPLEX 2
167 
168 namespace rptui
169 {
170 using namespace ::com::sun::star;
171 using namespace formula;
172 
adjustSectionName(const uno::Reference<report::XGroup> & _xGroup,sal_Int32 _nPos)173 void adjustSectionName(const uno::Reference< report::XGroup >& _xGroup,sal_Int32 _nPos)
174 {
175     OSL_ENSURE(_xGroup.is(),"Group is NULL -> GPF");
176     if ( _xGroup->getHeaderOn() && _xGroup->getHeader()->getName().isEmpty() )
177     {
178         OUString sName = RptResId(RID_STR_GROUPHEADER) + OUString::number(_nPos);
179         _xGroup->getHeader()->setName(sName);
180     }
181 
182     if ( _xGroup->getFooterOn() && _xGroup->getFooter()->getName().isEmpty() )
183     {
184         OUString sName = RptResId(RID_STR_GROUPFOOTER) + OUString::number(_nPos);
185         _xGroup->getFooter()->setName(sName);
186     }
187 }
188 
addStyleListener(const uno::Reference<report::XReportDefinition> & _xReportDefinition,::comphelper::OPropertyChangeListener * _pListener)189 ::rtl::Reference< comphelper::OPropertyChangeMultiplexer> addStyleListener(const uno::Reference< report::XReportDefinition >& _xReportDefinition,::comphelper::OPropertyChangeListener* _pListener)
190 {
191     ::rtl::Reference< comphelper::OPropertyChangeMultiplexer> pRet;
192     if ( _xReportDefinition.is() )
193     {
194         uno::Reference<beans::XPropertySet> xPageStyle(getUsedStyle(_xReportDefinition),uno::UNO_QUERY);
195         if ( xPageStyle.is() )
196         {
197             pRet = new comphelper::OPropertyChangeMultiplexer(_pListener,xPageStyle);
198             pRet->addProperty(PROPERTY_LEFTMARGIN);
199             pRet->addProperty(PROPERTY_RIGHTMARGIN);
200             pRet->addProperty(PROPERTY_PAPERSIZE);
201             pRet->addProperty(PROPERTY_BACKCOLOR);
202         }
203     }
204     return pRet;
205 }
206 
207 
208 namespace
209 {
210 
lcl_getReportControlFont(const uno::Reference<report::XReportControlFormat> & _rxReportControlFormat,awt::FontDescriptor & _out_rControlFont,sal_uInt16 _nWichFont)211     vcl::Font lcl_getReportControlFont( const uno::Reference<report::XReportControlFormat >& _rxReportControlFormat, awt::FontDescriptor& _out_rControlFont ,sal_uInt16 _nWichFont)
212     {
213         if ( !_rxReportControlFormat.is() )
214             throw uno::RuntimeException();
215 
216         switch(_nWichFont)
217         {
218             case WESTERN:
219                 _out_rControlFont = _rxReportControlFormat->getFontDescriptor();
220                 break;
221             case ASIAN:
222                 _out_rControlFont = _rxReportControlFormat->getFontDescriptorAsian();
223                 break;
224             case COMPLEX:
225                 _out_rControlFont = _rxReportControlFormat->getFontDescriptorComplex();
226                 break;
227 
228         }
229 
230         vcl::Font aDefaultFont = Application::GetDefaultDevice()->GetSettings().GetStyleSettings().GetAppFont();
231         return VCLUnoHelper::CreateFont( _out_rControlFont, aDefaultFont );
232     }
233 
234 
lcl_getReportControlFont(const uno::Reference<report::XReportControlFormat> & _rxReportControlFormat,sal_uInt16 _nWhich)235     vcl::Font lcl_getReportControlFont( const uno::Reference<report::XReportControlFormat >& _rxReportControlFormat,sal_uInt16 _nWhich )
236     {
237         awt::FontDescriptor aAwtFont;
238         return lcl_getReportControlFont( _rxReportControlFormat, aAwtFont, _nWhich );
239     }
240 
lcl_setFont(const uno::Reference<report::XReportControlFormat> & _rxReportControlFormat,SfxItemSet & _rItemSet,sal_uInt16 _nWhich,sal_uInt16 _nFont,sal_uInt16 _nFontHeight,sal_uInt16 _nLanguage,sal_uInt16 _nPosture,sal_uInt16 _nWeight)241     vcl::Font lcl_setFont(const uno::Reference<report::XReportControlFormat >& _rxReportControlFormat,
242         SfxItemSet& _rItemSet,sal_uInt16 _nWhich,sal_uInt16 _nFont, sal_uInt16 _nFontHeight,sal_uInt16 _nLanguage,sal_uInt16 _nPosture, sal_uInt16 _nWeight)
243     {
244         // fill it
245         awt::FontDescriptor aControlFont;
246         const vcl::Font aFont( lcl_getReportControlFont( _rxReportControlFormat, aControlFont,_nWhich ) );
247 
248         SvxFontItem aFontItem(_nFont);
249         aFontItem.PutValue( uno::makeAny( aControlFont ), 0 );
250         _rItemSet.Put(aFontItem);
251 
252         _rItemSet.Put(SvxFontHeightItem(OutputDevice::LogicToLogic(Size(0, aFont.GetFontHeight()), MapMode(MapUnit::MapPoint), MapMode(MapUnit::MapTwip)).Height(), 100, _nFontHeight));
253         lang::Locale aLocale;
254         switch(_nWhich)
255         {
256             default:
257                 aLocale = _rxReportControlFormat->getCharLocale();
258                 break;
259             case ASIAN:
260                 aLocale = _rxReportControlFormat->getCharLocaleAsian();
261                 break;
262             case COMPLEX:
263                 aLocale = _rxReportControlFormat->getCharLocaleComplex();
264                 break;
265         }
266 
267         _rItemSet.Put(SvxLanguageItem(LanguageTag(aLocale).makeFallback().getLanguageType(),_nLanguage));
268 
269         _rItemSet.Put(SvxPostureItem(aFont.GetItalic(),_nPosture));
270         _rItemSet.Put(SvxWeightItem(aFont.GetWeight(),_nWeight));
271         return aFont;
272     }
273 
lcl_fillShapeToItems(const uno::Reference<report::XShape> & _xShape,SfxItemSet & _rItemSet)274     void lcl_fillShapeToItems( const uno::Reference<report::XShape >& _xShape,SfxItemSet& _rItemSet )
275     {
276         uno::Reference< beans::XPropertySetInfo> xInfo = _xShape->getPropertySetInfo();
277         SvxUnoPropertyMapProvider aMap;
278         const SfxItemPropertyMap& rPropertyMap = aMap.GetPropertySet(SVXMAP_CUSTOMSHAPE, SdrObject::GetGlobalDrawObjectItemPool())->getPropertyMap();
279         for (const auto pProp : rPropertyMap.getPropertyEntries())
280         {
281             if ( xInfo->hasPropertyByName(pProp->aName) )
282             {
283                 const SfxPoolItem* pItem = _rItemSet.GetItem(pProp->nWID);
284                 if ( pItem )
285                 {
286                     ::std::unique_ptr<SfxPoolItem> pClone(pItem->CloneSetWhich(pProp->nWID));
287                     pClone->PutValue(_xShape->getPropertyValue(pProp->aName), pProp->nMemberId);
288                     _rItemSet.Put(std::move(pClone));
289                 }
290             }
291         }
292     }
293 
lcl_fillItemsToShape(const uno::Reference<report::XShape> & _xShape,const SfxItemSet & _rItemSet)294     void lcl_fillItemsToShape( const uno::Reference<report::XShape >& _xShape,const SfxItemSet& _rItemSet )
295     {
296         const uno::Reference< beans::XPropertySetInfo> xInfo = _xShape->getPropertySetInfo();
297         SvxUnoPropertyMapProvider aMap;
298         const SfxItemPropertyMap& rPropertyMap = aMap.GetPropertySet(SVXMAP_CUSTOMSHAPE, SdrObject::GetGlobalDrawObjectItemPool())->getPropertyMap();
299         for (const auto pProp : rPropertyMap.getPropertyEntries())
300         {
301             if ( SfxItemState::SET == _rItemSet.GetItemState(pProp->nWID) && xInfo->hasPropertyByName(pProp->aName) )
302             {
303                 if ( ( pProp->nFlags & beans::PropertyAttribute::READONLY ) != beans::PropertyAttribute::READONLY )
304                 {
305                     const SfxPoolItem* pItem = _rItemSet.GetItem(pProp->nWID);
306                     if ( pItem )
307                     {
308                         uno::Any aValue;
309                         pItem->QueryValue(aValue, pProp->nMemberId);
310                         try
311                         {
312                             _xShape->setPropertyValue(pProp->aName, aValue);
313                         }
314                         catch(uno::Exception&)
315                         { // shapes have a bug so we ignore this one.
316                         }
317                     }
318                 }
319             }
320         }
321     }
322 
lcl_CharPropertiesToItems(const uno::Reference<report::XReportControlFormat> & _rxReportControlFormat,SfxItemSet & _rItemSet)323     void lcl_CharPropertiesToItems( const uno::Reference<report::XReportControlFormat >& _rxReportControlFormat,
324         SfxItemSet& _rItemSet )
325     {
326         if ( !_rxReportControlFormat.is() )
327             throw lang::NullPointerException();
328 
329         uno::Reference< beans::XPropertySet > xSet(_rxReportControlFormat,uno::UNO_QUERY_THROW);
330 
331         // fill it
332         const vcl::Font aFont( lcl_setFont(_rxReportControlFormat, _rItemSet,WESTERN,ITEMID_FONT,ITEMID_FONTHEIGHT,ITEMID_LANGUAGE,ITEMID_POSTURE,ITEMID_WEIGHT ) );
333 
334         _rItemSet.Put(SvxShadowedItem(_rxReportControlFormat->getCharShadowed(),ITEMID_SHADOWED));
335         _rItemSet.Put(SvxWordLineModeItem(aFont.IsWordLineMode(),ITEMID_WORDLINEMODE));
336         _rItemSet.Put(SvxContourItem(_rxReportControlFormat->getCharContoured(),ITEMID_CONTOUR));
337         _rItemSet.Put(SvxAutoKernItem(_rxReportControlFormat->getCharAutoKerning(),ITEMID_AUTOKERN));
338         _rItemSet.Put(SvxCrossedOutItem(aFont.GetStrikeout(),ITEMID_CROSSEDOUT));
339         _rItemSet.Put(SvxCaseMapItem(static_cast<SvxCaseMap>(_rxReportControlFormat->getCharCaseMap()),ITEMID_CASEMAP));
340 
341         _rItemSet.Put(SvxEscapementItem(_rxReportControlFormat->getCharEscapement(),_rxReportControlFormat->getCharEscapementHeight(),ITEMID_ESCAPEMENT));
342         _rItemSet.Put(SvxBlinkItem(_rxReportControlFormat->getCharFlash(),ITEMID_BLINK));
343         _rItemSet.Put(SvxCharHiddenItem(_rxReportControlFormat->getCharHidden(),ITEMID_CHARHIDDEN));
344         _rItemSet.Put(SvxTwoLinesItem(_rxReportControlFormat->getCharCombineIsOn(),_rxReportControlFormat->getCharCombinePrefix().toChar(),_rxReportControlFormat->getCharCombineSuffix().toChar(),ITEMID_TWOLINES));
345         SvxUnderlineItem aUnderLineItem(aFont.GetUnderline(),ITEMID_UNDERLINE);
346         aUnderLineItem.SetColor(Color(ColorTransparency, _rxReportControlFormat->getCharUnderlineColor()));
347         _rItemSet.Put(aUnderLineItem);
348         _rItemSet.Put(SvxKerningItem(_rxReportControlFormat->getCharKerning(),ITEMID_KERNING));
349         _rItemSet.Put(SvxEmphasisMarkItem(static_cast<FontEmphasisMark>(_rxReportControlFormat->getCharEmphasis()),ITEMID_EMPHASISMARK));
350         _rItemSet.Put(SvxCharReliefItem(static_cast<FontRelief>(_rxReportControlFormat->getCharRelief()),ITEMID_CHARRELIEF));
351         _rItemSet.Put(SvxColorItem(::Color(ColorTransparency, _rxReportControlFormat->getCharColor()),ITEMID_COLOR));
352         _rItemSet.Put(SvxCharRotateItem(Degree10(_rxReportControlFormat->getCharRotation()),false,ITEMID_CHARROTATE));
353         _rItemSet.Put(SvxCharScaleWidthItem(_rxReportControlFormat->getCharScaleWidth(),ITEMID_CHARSCALE_W));
354 
355         SvxHorJustifyItem aHorJustifyItem(ITEMID_HORJUSTIFY);
356         aHorJustifyItem.PutValue(xSet->getPropertyValue(PROPERTY_PARAADJUST),MID_HORJUST_ADJUST);
357         _rItemSet.Put(aHorJustifyItem);
358         SvxVerJustifyItem aVerJustifyItem(ITEMID_VERJUSTIFY);
359         aVerJustifyItem.PutValue(xSet->getPropertyValue(PROPERTY_VERTICALALIGN),MID_HORJUST_ADJUST);
360         _rItemSet.Put(aVerJustifyItem);
361 
362         uno::Reference< report::XShape> xShape(_rxReportControlFormat,uno::UNO_QUERY);
363         if ( !xShape.is() )
364             _rItemSet.Put(SvxBrushItem(::Color(ColorTransparency, _rxReportControlFormat->getControlBackground()),ITEMID_BRUSH));
365 
366         lcl_setFont(_rxReportControlFormat, _rItemSet,ASIAN,ITEMID_FONT_ASIAN,ITEMID_FONTHEIGHT_ASIAN,ITEMID_LANGUAGE_ASIAN,ITEMID_POSTURE_ASIAN,ITEMID_WEIGHT_ASIAN );
367         lcl_setFont(_rxReportControlFormat, _rItemSet,COMPLEX,ITEMID_FONT_COMPLEX,ITEMID_FONTHEIGHT_COMPLEX,ITEMID_LANGUAGE_COMPLEX,ITEMID_POSTURE_COMPLEX,ITEMID_WEIGHT_COMPLEX );
368     }
369 
370 
lcl_pushBack(uno::Sequence<beans::NamedValue> & _out_rProperties,const OUString & _sName,const uno::Any & _rValue)371     void lcl_pushBack( uno::Sequence< beans::NamedValue >& _out_rProperties, const OUString& _sName, const uno::Any& _rValue )
372     {
373         sal_Int32 nLen( _out_rProperties.getLength() );
374         _out_rProperties.realloc( nLen + 1 );
375         _out_rProperties[ nLen ] = beans::NamedValue( _sName, _rValue );
376     }
377 
378 
lcl_initAwtFont(const vcl::Font & _rOriginalFont,const SfxItemSet & _rItemSet,awt::FontDescriptor & _out_rAwtFont,sal_uInt16 _nFont,sal_uInt16 _nFontHeight,sal_uInt16 _nPosture,sal_uInt16 _nWeight)379     void lcl_initAwtFont( const vcl::Font& _rOriginalFont, const SfxItemSet& _rItemSet, awt::FontDescriptor& _out_rAwtFont,
380         sal_uInt16 _nFont, sal_uInt16 _nFontHeight,sal_uInt16 _nPosture, sal_uInt16 _nWeight)
381     {
382         vcl::Font aNewFont( _rOriginalFont );
383         const SfxPoolItem* pItem( nullptr );
384         if ( SfxItemState::SET == _rItemSet.GetItemState( _nFont,true,&pItem) )
385             if ( auto pFontItem = dynamic_cast< const SvxFontItem *>( pItem ) )
386             {
387                 aNewFont.SetFamilyName(pFontItem->GetFamilyName());
388                 aNewFont.SetStyleName(pFontItem->GetStyleName());
389                 aNewFont.SetFamily(pFontItem->GetFamily());
390                 aNewFont.SetPitch(pFontItem->GetPitch());
391                 aNewFont.SetCharSet(pFontItem->GetCharSet());
392             }
393         if ( SfxItemState::SET == _rItemSet.GetItemState( _nFontHeight,true,&pItem) )
394             if ( auto pFontItem = dynamic_cast< const SvxFontHeightItem *>( pItem ) )
395             {
396                 aNewFont.SetFontHeight(OutputDevice::LogicToLogic(Size(0, pFontItem->GetHeight()), MapMode(MapUnit::MapTwip), MapMode(MapUnit::MapPoint)).Height());
397             }
398         if ( SfxItemState::SET == _rItemSet.GetItemState( _nPosture,true,&pItem) )
399             if ( auto pFontItem = dynamic_cast< const SvxPostureItem *>( pItem ) )
400             {
401                 aNewFont.SetItalic(pFontItem->GetPosture());
402             }
403         if ( SfxItemState::SET == _rItemSet.GetItemState( _nWeight,true,&pItem) )
404             if ( auto pFontItem = dynamic_cast< const SvxWeightItem *>( pItem ) )
405             {
406                 aNewFont.SetWeight(pFontItem->GetWeight());
407             }
408         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_WORDLINEMODE,true,&pItem) )
409             if ( auto pFontItem = dynamic_cast< const SvxWordLineModeItem *>( pItem ) )
410             {
411                 aNewFont.SetWordLineMode(pFontItem->GetValue());
412             }
413         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_CROSSEDOUT,true,&pItem) )
414             if ( auto pFontItem = dynamic_cast< const SvxCrossedOutItem *>( pItem ) )
415             {
416                 aNewFont.SetStrikeout(pFontItem->GetStrikeout());
417             }
418 
419         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_CHARROTATE,true,&pItem) )
420             if ( auto pRotateItem = dynamic_cast< const SvxCharRotateItem *>( pItem ) )
421             {
422                 aNewFont.SetOrientation(pRotateItem->GetValue());
423             }
424         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_CHARSCALE_W,true,&pItem) )
425             if ( auto pCharItem = dynamic_cast< const SvxCharScaleWidthItem *>( pItem ) )
426             {
427                 aNewFont.SetWidthType(vcl::unohelper::ConvertFontWidth(pCharItem->GetValue()));
428             }
429         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_UNDERLINE,true,&pItem) )
430             if ( auto pFontItem = dynamic_cast< const SvxUnderlineItem *>( pItem ) )
431             {
432                 aNewFont.SetUnderline(pFontItem->GetLineStyle());
433             }
434         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_COLOR,true,&pItem) )
435             if ( auto pFontItem = dynamic_cast< const SvxColorItem *>( pItem ) )
436             {
437                 aNewFont.SetColor(pFontItem->GetValue());
438             }
439 
440         _out_rAwtFont = VCLUnoHelper::CreateFontDescriptor( aNewFont );
441     }
442 
443 
lcl_itemsToCharProperties(const vcl::Font & _rOriginalControlFont,const vcl::Font & _rOriginalControlFontAsian,const vcl::Font & _rOriginalControlFontComplex,const SfxItemSet & _rItemSet,uno::Sequence<beans::NamedValue> & _out_rProperties)444     void lcl_itemsToCharProperties( const vcl::Font& _rOriginalControlFont,const vcl::Font& _rOriginalControlFontAsian,const vcl::Font& _rOriginalControlFontComplex, const SfxItemSet& _rItemSet, uno::Sequence< beans::NamedValue >& _out_rProperties )
445     {
446         const SfxPoolItem* pItem( nullptr );
447 
448         // create an AWT font
449         awt::FontDescriptor aAwtFont;
450         lcl_initAwtFont( _rOriginalControlFont, _rItemSet, aAwtFont,ITEMID_FONT,ITEMID_FONTHEIGHT,ITEMID_POSTURE, ITEMID_WEIGHT);
451         lcl_pushBack( _out_rProperties, "Font", uno::makeAny( aAwtFont ) );
452         lcl_initAwtFont( _rOriginalControlFontAsian, _rItemSet, aAwtFont,ITEMID_FONT_ASIAN,ITEMID_FONTHEIGHT_ASIAN,ITEMID_POSTURE_ASIAN, ITEMID_WEIGHT_ASIAN);
453         lcl_pushBack( _out_rProperties, "FontAsian", uno::makeAny( aAwtFont ) );
454         lcl_initAwtFont( _rOriginalControlFontComplex, _rItemSet, aAwtFont,ITEMID_FONT_COMPLEX,ITEMID_FONTHEIGHT_COMPLEX,ITEMID_POSTURE_COMPLEX, ITEMID_WEIGHT_COMPLEX);
455         lcl_pushBack( _out_rProperties, "FontComplex", uno::makeAny( aAwtFont ) );
456 
457         // properties which cannot be represented in an AWT font need to be preserved directly
458         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_SHADOWED,true,&pItem) )
459             if (auto pShadowedItem = dynamic_cast<const SvxShadowedItem *>( pItem ))
460                 lcl_pushBack( _out_rProperties, PROPERTY_CHARSHADOWED, uno::makeAny( pShadowedItem->GetValue() ) );
461         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_CONTOUR,true,&pItem) )
462             if (auto pContourItem = dynamic_cast<const SvxContourItem *>( pItem ))
463                 lcl_pushBack( _out_rProperties, PROPERTY_CHARCONTOURED, uno::makeAny( pContourItem->GetValue() ) );
464         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_UNDERLINE,true,&pItem) )
465             if (auto pUnderlineItem = dynamic_cast< const SvxUnderlineItem *>( pItem ))
466                 lcl_pushBack( _out_rProperties, PROPERTY_CHARUNDERLINECOLOR, uno::makeAny( pUnderlineItem->GetColor() ) );
467         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_HORJUSTIFY,true,&pItem) )
468             if (auto pJustifyItem = dynamic_cast< const SvxHorJustifyItem *>( pItem ))
469             {
470                 uno::Any aValue;
471                 pJustifyItem->QueryValue(aValue,MID_HORJUST_ADJUST);
472                 lcl_pushBack( _out_rProperties, PROPERTY_PARAADJUST, aValue );
473             }
474         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_VERJUSTIFY,true,&pItem) )
475             if (auto pJustifyItem = dynamic_cast< const SvxVerJustifyItem *>( pItem ))
476             {
477                 uno::Any aValue;
478                 pJustifyItem->QueryValue(aValue,MID_HORJUST_ADJUST);
479                 lcl_pushBack( _out_rProperties, PROPERTY_VERTICALALIGN, aValue );
480             }
481         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_CHARRELIEF,true,&pItem) )
482             if (auto pReliefItem = dynamic_cast< const SvxCharReliefItem *>( pItem ))
483                 lcl_pushBack( _out_rProperties, PROPERTY_CHARRELIEF, uno::makeAny( static_cast< sal_Int16 >( pReliefItem->GetEnumValue() ) ) );
484         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_CHARHIDDEN,true,&pItem) )
485             if (auto pHiddenItem = dynamic_cast< const SvxCharHiddenItem *>( pItem ))
486                 lcl_pushBack( _out_rProperties, PROPERTY_CHARHIDDEN, uno::makeAny( pHiddenItem->GetValue() ) );
487         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_AUTOKERN,true,&pItem) )
488             if (auto pKernItem = dynamic_cast< const SvxAutoKernItem *>( pItem ))
489                 lcl_pushBack( _out_rProperties, PROPERTY_CHARAUTOKERNING, uno::makeAny( pKernItem->GetValue() ) );
490         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_BRUSH,true,&pItem) )
491             if (auto pBrushItem = dynamic_cast< const SvxBrushItem *>( pItem ))
492                 lcl_pushBack( _out_rProperties, PROPERTY_CONTROLBACKGROUND, uno::makeAny( pBrushItem->GetColor() ) );
493         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_BLINK,true,&pItem) )
494             if (auto pBlinkItem = dynamic_cast< const SvxBlinkItem *>( pItem ))
495                 lcl_pushBack( _out_rProperties, PROPERTY_CHARFLASH, uno::makeAny( pBlinkItem->GetValue() ) );
496         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_EMPHASISMARK,true,&pItem) )
497             if (auto pMarkItem = dynamic_cast< const SvxEmphasisMarkItem *>( pItem ))
498                 lcl_pushBack( _out_rProperties, PROPERTY_CHAREMPHASIS, uno::makeAny( static_cast< sal_Int16 >( pMarkItem->GetEmphasisMark() ) ) );
499         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_TWOLINES,true,&pItem) )
500             if (auto pLinesItem = dynamic_cast< const SvxTwoLinesItem *>( pItem ))
501             {
502                 lcl_pushBack( _out_rProperties, PROPERTY_CHARCOMBINEISON, uno::makeAny( pLinesItem->GetValue() ) );
503                 lcl_pushBack( _out_rProperties, PROPERTY_CHARCOMBINEPREFIX, uno::makeAny( OUString( pLinesItem->GetStartBracket() ) ) );
504                 lcl_pushBack( _out_rProperties, PROPERTY_CHARCOMBINESUFFIX, uno::makeAny( OUString( pLinesItem->GetEndBracket() ) ) );
505             }
506         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_COLOR,true,&pItem) )
507             if (auto pColorItem = dynamic_cast< const SvxColorItem *>( pItem ))
508                 lcl_pushBack( _out_rProperties, PROPERTY_CHARCOLOR, uno::makeAny( pColorItem->GetValue() ) );
509         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_KERNING,true,&pItem) )
510             if (auto pKernItem = dynamic_cast< const SvxKerningItem *>( pItem ))
511                 lcl_pushBack( _out_rProperties, PROPERTY_CHARKERNING, uno::makeAny( pKernItem->GetValue() ) );
512         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_CASEMAP,true,&pItem) )
513             if (auto pCaseMapItem = dynamic_cast< const SvxCaseMapItem *>( pItem ))
514                 lcl_pushBack( _out_rProperties, PROPERTY_CHARCASEMAP, uno::makeAny( pCaseMapItem->GetEnumValue() ) );
515         struct Items {
516                 sal_uInt16 nWhich;
517                 OUString sPropertyName;
518         };
519         const Items pItems[] = { {ITEMID_LANGUAGE,OUString(PROPERTY_CHARLOCALE)}
520                                 ,{ITEMID_LANGUAGE_ASIAN,OUString(PROPERTY_CHARLOCALEASIAN)}
521                                 ,{ITEMID_LANGUAGE_COMPLEX,OUString(PROPERTY_CHARLOCALECOMPLEX)}
522         };
523         for(const auto & k : pItems)
524         {
525             if ( SfxItemState::SET == _rItemSet.GetItemState( k.nWhich,true,&pItem) )
526                 if (auto pLanguageItem = dynamic_cast< const SvxLanguageItem *>( pItem ))
527                 {
528                     lang::Locale aCharLocale( LanguageTag( pLanguageItem->GetLanguage()).getLocale());
529                     lcl_pushBack( _out_rProperties, k.sPropertyName, uno::makeAny( aCharLocale ) );
530                 }
531         }
532         if ( SfxItemState::SET == _rItemSet.GetItemState( ITEMID_ESCAPEMENT,true,&pItem) )
533             if (auto pEscapementItem = dynamic_cast< const SvxEscapementItem *>( pItem ))
534             {
535                 lcl_pushBack( _out_rProperties, PROPERTY_CHARESCAPEMENT, uno::makeAny( pEscapementItem->GetEsc() ) );
536                 lcl_pushBack( _out_rProperties, PROPERTY_CHARESCAPEMENTHEIGHT, uno::makeAny(static_cast<sal_Int8>(pEscapementItem->GetProportionalHeight())) );
537             }
538     }
539 
540 
541     template< class ATTRIBUTE_TYPE >
lcl_applyFontAttribute(const::comphelper::NamedValueCollection & _rAttrValues,const char * _pAttributeName,const uno::Reference<report::XReportControlFormat> & _rxReportControlFormat,void (SAL_CALL report::XReportControlFormat::* pSetter)(ATTRIBUTE_TYPE))542     void lcl_applyFontAttribute( const ::comphelper::NamedValueCollection& _rAttrValues, const char* _pAttributeName,
543         const uno::Reference<report::XReportControlFormat >& _rxReportControlFormat,
544         void (SAL_CALL report::XReportControlFormat::*pSetter)( ATTRIBUTE_TYPE ) )
545     {
546         ATTRIBUTE_TYPE aAttributeValue = ATTRIBUTE_TYPE();
547         if ( _rAttrValues.get_ensureType( _pAttributeName, aAttributeValue ) )
548             (_rxReportControlFormat.get()->*pSetter)( aAttributeValue );
549     }
550 
551 
lcl_applyFontAttribute(const::comphelper::NamedValueCollection & _rAttrValues,const char * _pAttributeName,const uno::Reference<report::XReportControlFormat> & _rxReportControlFormat,void (SAL_CALL report::XReportControlFormat::* pSetter)(const OUString &))552     void lcl_applyFontAttribute( const ::comphelper::NamedValueCollection& _rAttrValues, const char* _pAttributeName,
553         const uno::Reference<report::XReportControlFormat >& _rxReportControlFormat,
554         void (SAL_CALL report::XReportControlFormat::*pSetter)( const OUString& ) )
555     {
556         OUString aAttributeValue;
557         if ( _rAttrValues.get_ensureType( _pAttributeName, aAttributeValue ) )
558             (_rxReportControlFormat.get()->*pSetter)( aAttributeValue );
559     }
560 
561 
lcl_applyFontAttribute(const::comphelper::NamedValueCollection & _rAttrValues,const char * _pAttributeName,const uno::Reference<report::XReportControlFormat> & _rxReportControlFormat,void (SAL_CALL report::XReportControlFormat::* pSetter)(const lang::Locale &))562     void lcl_applyFontAttribute( const ::comphelper::NamedValueCollection& _rAttrValues, const char* _pAttributeName,
563         const uno::Reference<report::XReportControlFormat >& _rxReportControlFormat,
564         void (SAL_CALL report::XReportControlFormat::*pSetter)( const lang::Locale& ) )
565     {
566         lang::Locale aAttributeValue;
567         if ( _rAttrValues.get_ensureType( _pAttributeName, aAttributeValue ) )
568             (_rxReportControlFormat.get()->*pSetter)( aAttributeValue );
569     }
570 }
571 
572 
openCharDialog(const uno::Reference<report::XReportControlFormat> & _rxReportControlFormat,const uno::Reference<awt::XWindow> & _rxParentWindow,uno::Sequence<beans::NamedValue> & _out_rNewValues)573 bool openCharDialog( const uno::Reference<report::XReportControlFormat >& _rxReportControlFormat,
574         const uno::Reference< awt::XWindow>& _rxParentWindow, uno::Sequence< beans::NamedValue >& _out_rNewValues )
575 {
576     OSL_PRECOND( _rxReportControlFormat.is() && _rxParentWindow.is(), "openCharDialog: invalid parameters!" );
577     if ( !_rxReportControlFormat.is() || !_rxParentWindow.is() )
578         return false;
579 
580     _out_rNewValues = uno::Sequence< beans::NamedValue >();
581 
582 
583     // UNO->ItemSet
584     static SfxItemInfo aItemInfos[] =
585     {
586         { XATTR_FILLSTYLE,      true },
587         { XATTR_FILLCOLOR,      true },
588         { XATTR_FILLGRADIENT,       true },
589         { XATTR_FILLHATCH,      true },
590         { XATTR_FILLBITMAP,     true },
591         { XATTR_FILLTRANSPARENCE,       true },
592         { XATTR_GRADIENTSTEPCOUNT,      true },
593         { XATTR_FILLBMP_TILE,       true },
594         { XATTR_FILLBMP_POS,        true },
595         { XATTR_FILLBMP_SIZEX,      true },
596         { XATTR_FILLBMP_SIZEY,      true },
597         { XATTR_FILLFLOATTRANSPARENCE,  true },
598         { XATTR_SECONDARYFILLCOLOR,     true },
599         { XATTR_FILLBMP_SIZELOG,        true },
600         { XATTR_FILLBMP_TILEOFFSETX,    true },
601         { XATTR_FILLBMP_TILEOFFSETY,    true },
602         { XATTR_FILLBMP_STRETCH,        true },
603         { XATTR_FILLBMP_POSOFFSETX,     true },
604         { XATTR_FILLBMP_POSOFFSETY,     true },
605         { XATTR_FILLBACKGROUND,     true },
606 
607         { SID_ATTR_CHAR_FONT, true },
608         { SID_ATTR_CHAR_FONTHEIGHT, true },
609         { SID_ATTR_CHAR_LANGUAGE, true },
610         { SID_ATTR_CHAR_POSTURE, true },
611         { SID_ATTR_CHAR_WEIGHT, true },
612         { SID_ATTR_CHAR_SHADOWED, true },
613         { SID_ATTR_CHAR_WORDLINEMODE, true },
614         { SID_ATTR_CHAR_CONTOUR, true },
615         { SID_ATTR_CHAR_STRIKEOUT, true },
616         { SID_ATTR_CHAR_UNDERLINE, true },
617         { SID_ATTR_CHAR_COLOR, true },
618         { SID_ATTR_CHAR_KERNING, true },
619         { SID_ATTR_CHAR_CASEMAP, true },
620         { SID_ATTR_CHAR_ESCAPEMENT, true },
621         { SID_ATTR_CHAR_FONTLIST, true },
622         { SID_ATTR_CHAR_AUTOKERN, true },
623         { SID_COLOR_TABLE, true },
624         { SID_ATTR_FLASH, true },
625         { SID_ATTR_CHAR_EMPHASISMARK, true },
626         { SID_ATTR_CHAR_TWO_LINES, true },
627         { SID_ATTR_CHAR_ROTATED, true },
628         { SID_ATTR_CHAR_SCALEWIDTH, true },
629         { SID_ATTR_CHAR_RELIEF, true },
630         { SID_ATTR_CHAR_HIDDEN, true },
631         { SID_ATTR_BRUSH, true },
632         { SID_ATTR_ALIGN_HOR_JUSTIFY, true },
633         { SID_ATTR_ALIGN_VER_JUSTIFY, true },
634 
635         // Asian
636         { SID_ATTR_CHAR_CJK_FONT, true },
637         { SID_ATTR_CHAR_CJK_FONTHEIGHT, true },
638         { SID_ATTR_CHAR_CJK_LANGUAGE, true },
639         { SID_ATTR_CHAR_CJK_POSTURE, true },
640         { SID_ATTR_CHAR_CJK_WEIGHT, true },
641         // Complex
642         { SID_ATTR_CHAR_CTL_FONT, true },
643         { SID_ATTR_CHAR_CTL_FONTHEIGHT, true },
644         { SID_ATTR_CHAR_CTL_LANGUAGE, true },
645         { SID_ATTR_CHAR_CTL_POSTURE, true },
646         { SID_ATTR_CHAR_CTL_WEIGHT, true }
647     };
648     FontList aFontList(Application::GetDefaultDevice());
649     XColorListRef pColorList( XColorList::CreateStdColorList() );
650     const Graphic aNullGraphic;
651     const ::Color aNullLineCol(COL_DEFAULT_SHAPE_STROKE); // #i121448# Use defined default color
652     const ::Color aNullFillCol(COL_DEFAULT_SHAPE_FILLING); // #i121448# Use defined default color
653     const XGradient aNullGrad(COL_BLACK, COL_WHITE);
654     const XHatch aNullHatch(aNullLineCol);
655     std::vector<SfxPoolItem*> pDefaults
656     {
657         new XFillStyleItem,
658         new XFillColorItem("", aNullFillCol),
659         new XFillGradientItem(aNullGrad),
660         new XFillHatchItem(aNullHatch),
661         new XFillBitmapItem(aNullGraphic),
662         new XFillTransparenceItem,
663         new XGradientStepCountItem,
664         new XFillBmpTileItem,
665         new XFillBmpPosItem,
666         new XFillBmpSizeXItem,
667         new XFillBmpSizeYItem,
668         new XFillFloatTransparenceItem(aNullGrad, false),
669         new XSecondaryFillColorItem("", aNullFillCol),
670         new XFillBmpSizeLogItem,
671         new XFillBmpTileOffsetXItem,
672         new XFillBmpTileOffsetYItem,
673         new XFillBmpStretchItem,
674         new XFillBmpPosOffsetXItem,
675         new XFillBmpPosOffsetYItem,
676         new XFillBackgroundItem,
677 
678         new SvxFontItem(ITEMID_FONT),
679         new SvxFontHeightItem(240,100,ITEMID_FONTHEIGHT),
680         new SvxLanguageItem(LANGUAGE_GERMAN,ITEMID_LANGUAGE),
681         new SvxPostureItem(ITALIC_NONE,ITEMID_POSTURE),
682         new SvxWeightItem(WEIGHT_NORMAL,ITEMID_WEIGHT),
683 
684         new SvxShadowedItem(false,ITEMID_SHADOWED),
685         new SvxWordLineModeItem(false,ITEMID_WORDLINEMODE),
686         new SvxContourItem(false,ITEMID_CONTOUR),
687         new SvxCrossedOutItem(STRIKEOUT_NONE,ITEMID_CROSSEDOUT),
688         new SvxUnderlineItem(LINESTYLE_NONE,ITEMID_UNDERLINE),
689 
690         new SvxColorItem(ITEMID_COLOR),
691         new SvxKerningItem(0,ITEMID_KERNING),
692         new SvxCaseMapItem(SvxCaseMap::NotMapped,ITEMID_CASEMAP),
693         new SvxEscapementItem(ITEMID_ESCAPEMENT),
694         new SvxFontListItem(&aFontList,ITEMID_FONTLIST),
695         new SvxAutoKernItem(false,ITEMID_AUTOKERN),
696         new SvxColorListItem(pColorList,ITEMID_COLOR_TABLE),
697         new SvxBlinkItem(false,ITEMID_BLINK),
698         new SvxEmphasisMarkItem(FontEmphasisMark::NONE,ITEMID_EMPHASISMARK),
699         new SvxTwoLinesItem(true,0,0,ITEMID_TWOLINES),
700         new SvxCharRotateItem(0_deg10,false,ITEMID_CHARROTATE),
701         new SvxCharScaleWidthItem(100,ITEMID_CHARSCALE_W),
702         new SvxCharReliefItem(FontRelief::NONE,ITEMID_CHARRELIEF),
703         new SvxCharHiddenItem(false,ITEMID_CHARHIDDEN),
704         new SvxBrushItem(ITEMID_BRUSH),
705         new SvxHorJustifyItem(ITEMID_HORJUSTIFY),
706         new SvxVerJustifyItem(ITEMID_VERJUSTIFY),
707 // Asian
708         new SvxFontItem(ITEMID_FONT_ASIAN),
709         new SvxFontHeightItem(240,100,ITEMID_FONTHEIGHT_ASIAN),
710         new SvxLanguageItem(LANGUAGE_GERMAN,ITEMID_LANGUAGE_ASIAN),
711         new SvxPostureItem(ITALIC_NONE,ITEMID_POSTURE_ASIAN),
712         new SvxWeightItem(WEIGHT_NORMAL,ITEMID_WEIGHT_ASIAN),
713 // Complex
714         new SvxFontItem(ITEMID_FONT_COMPLEX),
715         new SvxFontHeightItem(240,100,ITEMID_FONTHEIGHT_COMPLEX),
716         new SvxLanguageItem(LANGUAGE_GERMAN,ITEMID_LANGUAGE_COMPLEX),
717         new SvxPostureItem(ITALIC_NONE,ITEMID_POSTURE_COMPLEX),
718         new SvxWeightItem(WEIGHT_NORMAL,ITEMID_WEIGHT_COMPLEX)
719 
720     };
721 
722     OSL_ASSERT( pDefaults.size() == SAL_N_ELEMENTS(aItemInfos) );
723 
724     static const sal_uInt16 pRanges[] =
725     {
726         XATTR_FILL_FIRST, ITEMID_WEIGHT_COMPLEX,
727         0
728     };
729 
730     rtl::Reference<SfxItemPool> pPool(new SfxItemPool("ReportCharProperties", XATTR_FILL_FIRST,ITEMID_WEIGHT_COMPLEX, aItemInfos, &pDefaults));
731     // not needed for font height pPool->SetDefaultMetric( MapUnit::Map100thMM );  // ripped, don't understand why
732     pPool->FreezeIdRanges();                        // the same
733     bool bSuccess = false;
734     try
735     {
736         SfxItemSet aDescriptor( *pPool, pRanges );
737         lcl_CharPropertiesToItems( _rxReportControlFormat, aDescriptor );
738 
739         {   // want the dialog to be destroyed before our set
740             ORptPageDialog aDlg(Application::GetFrameWeld(_rxParentWindow), &aDescriptor, "CharDialog");
741             uno::Reference< report::XShape > xShape( _rxReportControlFormat, uno::UNO_QUERY );
742             if ( xShape.is() )
743                 aDlg.RemoveTabPage("background");
744             bSuccess = aDlg.run() == RET_OK;
745             if ( bSuccess )
746             {
747                 lcl_itemsToCharProperties( lcl_getReportControlFont( _rxReportControlFormat,WESTERN ),
748                     lcl_getReportControlFont( _rxReportControlFormat,ASIAN ),
749                     lcl_getReportControlFont( _rxReportControlFormat,COMPLEX ), *aDlg.GetOutputItemSet(), _out_rNewValues );
750             }
751         }
752     }
753     catch(uno::Exception&)
754     {
755         DBG_UNHANDLED_EXCEPTION("reportdesign");
756     }
757 
758     pPool.clear();
759     for (SfxPoolItem* pDefault : pDefaults)
760         delete pDefault;
761 
762     return bSuccess;
763 }
764 
openAreaDialog(const uno::Reference<report::XShape> & _xShape,const uno::Reference<awt::XWindow> & _rxParentWindow)765 bool openAreaDialog( const uno::Reference<report::XShape >& _xShape,const uno::Reference< awt::XWindow>& _rxParentWindow )
766 {
767     OSL_PRECOND( _xShape.is() && _rxParentWindow.is(), "openAreaDialog: invalid parameters!" );
768     if ( !_xShape.is() || !_rxParentWindow.is() )
769         return false;
770 
771     std::shared_ptr<rptui::OReportModel> pModel  = ::reportdesign::OReportDefinition::getSdrModel(_xShape->getSection()->getReportDefinition());
772 
773     weld::Window* pParent = Application::GetFrameWeld(_rxParentWindow);
774 
775     bool bSuccess = false;
776     try
777     {
778         SfxItemPool& rItemPool = pModel->GetItemPool();
779         SfxItemSet aDescriptor( rItemPool, {{rItemPool.GetFirstWhich(),rItemPool.GetLastWhich()}} );
780         lcl_fillShapeToItems(_xShape, aDescriptor);
781 
782         {   // want the dialog to be destroyed before our set
783             SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
784             ScopedVclPtr<AbstractSvxAreaTabDialog> pDialog(pFact->CreateSvxAreaTabDialog(pParent, &aDescriptor, pModel.get(), true));
785             if ( RET_OK == pDialog->Execute() )
786             {
787                 bSuccess = true;
788                 lcl_fillItemsToShape(_xShape,*pDialog->GetOutputItemSet());
789             }
790         }
791     }
792     catch(uno::Exception&)
793     {
794         DBG_UNHANDLED_EXCEPTION("reportdesign");
795     }
796 
797     return bSuccess;
798 }
799 
800 
applyCharacterSettings(const uno::Reference<report::XReportControlFormat> & _rxReportControlFormat,const uno::Sequence<beans::NamedValue> & _rSettings)801 void applyCharacterSettings( const uno::Reference< report::XReportControlFormat >& _rxReportControlFormat, const uno::Sequence< beans::NamedValue >& _rSettings )
802 {
803     ::comphelper::NamedValueCollection aSettings( _rSettings );
804 
805     try
806     {
807         awt::FontDescriptor aAwtFont;
808         if ( aSettings.get( "Font" ) >>= aAwtFont )
809         {
810             OUString sTemp = aAwtFont.Name;
811             aAwtFont.Name.clear(); // hack to
812             _rxReportControlFormat->setFontDescriptor( aAwtFont );
813             _rxReportControlFormat->setCharFontName( sTemp );
814         }
815         if ( aSettings.get( "FontAsian" ) >>= aAwtFont )
816         {
817             OUString sTemp = aAwtFont.Name;
818             aAwtFont.Name.clear(); // hack to
819             _rxReportControlFormat->setFontDescriptorAsian( aAwtFont );
820             _rxReportControlFormat->setCharFontNameAsian( sTemp );
821         }
822         if ( aSettings.get( "FontComplex" ) >>= aAwtFont )
823         {
824             OUString sTemp = aAwtFont.Name;
825             aAwtFont.Name.clear(); // hack to
826             _rxReportControlFormat->setFontDescriptorComplex( aAwtFont );
827             _rxReportControlFormat->setCharFontNameComplex( sTemp );
828         }
829 
830         lcl_applyFontAttribute( aSettings, PROPERTY_CHARSHADOWED, _rxReportControlFormat, &report::XReportControlFormat::setCharShadowed );
831         lcl_applyFontAttribute( aSettings, PROPERTY_CHARCONTOURED, _rxReportControlFormat, &report::XReportControlFormat::setCharContoured );
832         lcl_applyFontAttribute( aSettings, PROPERTY_CHARUNDERLINECOLOR, _rxReportControlFormat, &report::XReportControlFormat::setCharUnderlineColor );
833         lcl_applyFontAttribute( aSettings, PROPERTY_PARAADJUST, _rxReportControlFormat, &report::XReportControlFormat::setParaAdjust );
834         lcl_applyFontAttribute( aSettings, PROPERTY_VERTICALALIGN, _rxReportControlFormat, &report::XReportControlFormat::setVerticalAlign );
835         lcl_applyFontAttribute( aSettings, PROPERTY_CHARRELIEF, _rxReportControlFormat, &report::XReportControlFormat::setCharRelief );
836         lcl_applyFontAttribute( aSettings, PROPERTY_CHARHIDDEN, _rxReportControlFormat, &report::XReportControlFormat::setCharHidden );
837         lcl_applyFontAttribute( aSettings, PROPERTY_CHARAUTOKERNING, _rxReportControlFormat, &report::XReportControlFormat::setCharAutoKerning );
838         lcl_applyFontAttribute( aSettings, PROPERTY_CONTROLBACKGROUND, _rxReportControlFormat, &report::XReportControlFormat::setControlBackground );
839         lcl_applyFontAttribute( aSettings, PROPERTY_CHARFLASH, _rxReportControlFormat, &report::XReportControlFormat::setCharFlash );
840         lcl_applyFontAttribute( aSettings, PROPERTY_CHAREMPHASIS, _rxReportControlFormat, &report::XReportControlFormat::setCharEmphasis );
841         lcl_applyFontAttribute( aSettings, PROPERTY_CHARCOMBINEISON, _rxReportControlFormat, &report::XReportControlFormat::setCharCombineIsOn );
842         lcl_applyFontAttribute( aSettings, PROPERTY_CHARCOMBINEPREFIX, _rxReportControlFormat, &report::XReportControlFormat::setCharCombinePrefix );
843         lcl_applyFontAttribute( aSettings, PROPERTY_CHARCOMBINESUFFIX, _rxReportControlFormat, &report::XReportControlFormat::setCharCombineSuffix );
844         lcl_applyFontAttribute( aSettings, PROPERTY_CHARCOLOR, _rxReportControlFormat, &report::XReportControlFormat::setCharColor );
845         lcl_applyFontAttribute( aSettings, PROPERTY_CHARKERNING, _rxReportControlFormat, &report::XReportControlFormat::setCharKerning );
846         lcl_applyFontAttribute( aSettings, PROPERTY_CHARCASEMAP, _rxReportControlFormat, &report::XReportControlFormat::setCharCaseMap );
847         lcl_applyFontAttribute( aSettings, PROPERTY_CHARLOCALE, _rxReportControlFormat, &report::XReportControlFormat::setCharLocale );
848         lcl_applyFontAttribute( aSettings, PROPERTY_CHARESCAPEMENT, _rxReportControlFormat, &report::XReportControlFormat::setCharEscapement );
849         lcl_applyFontAttribute( aSettings, PROPERTY_CHARESCAPEMENTHEIGHT, _rxReportControlFormat, &report::XReportControlFormat::setCharEscapementHeight );
850         lcl_applyFontAttribute( aSettings, PROPERTY_CHARLOCALEASIAN, _rxReportControlFormat, &report::XReportControlFormat::setCharLocaleAsian );
851         lcl_applyFontAttribute( aSettings, PROPERTY_CHARLOCALECOMPLEX, _rxReportControlFormat, &report::XReportControlFormat::setCharLocaleComplex );
852     }
853     catch( const uno::Exception& )
854     {
855         DBG_UNHANDLED_EXCEPTION("reportdesign");
856     }
857 }
858 
notifySystemWindow(vcl::Window const * _pWindow,vcl::Window * _pToRegister,const::comphelper::mem_fun1_t<TaskPaneList,vcl::Window * > & rMemFunc)859 void notifySystemWindow(vcl::Window const * _pWindow, vcl::Window* _pToRegister, const ::comphelper::mem_fun1_t<TaskPaneList,vcl::Window*>& rMemFunc)
860 {
861     OSL_ENSURE(_pWindow,"Window can not be null!");
862     SystemWindow* pSystemWindow = _pWindow ? _pWindow->GetSystemWindow() : nullptr;
863     if ( pSystemWindow )
864     {
865         rMemFunc( pSystemWindow->GetTaskPaneList(), _pToRegister );
866     }
867 }
868 
isOver(const tools::Rectangle & _rRect,SdrPage const & _rPage,SdrView const & _rView,bool _bAllObjects,SdrObject const * _pIgnore,sal_Int16 _nIgnoreType)869 SdrObject* isOver(const tools::Rectangle& _rRect, SdrPage const & _rPage, SdrView const & _rView, bool _bAllObjects, SdrObject const * _pIgnore, sal_Int16 _nIgnoreType)
870 {
871     SdrObject* pOverlappedObj = nullptr;
872     SdrObjListIter aIter(&_rPage,SdrIterMode::DeepNoGroups);
873 
874     while( !pOverlappedObj )
875     {
876         SdrObject* pObjIter = aIter.Next();
877         if( !pObjIter )
878             break;
879         if ( _pIgnore != pObjIter
880             && (_bAllObjects || !_rView.IsObjMarked(pObjIter))
881             && (dynamic_cast<OUnoObject*>(pObjIter) != nullptr || dynamic_cast<OOle2Obj*>(pObjIter) != nullptr))
882         {
883             if (_nIgnoreType == ISOVER_IGNORE_CUSTOMSHAPES && pObjIter->GetObjIdentifier() == OBJ_CUSTOMSHAPE)
884             {
885                 continue;
886             }
887 
888             if (dynamic_cast<OUnoObject*>(pObjIter) != nullptr || dynamic_cast<OOle2Obj*>(pObjIter) != nullptr)
889             {
890                 tools::Rectangle aRect = _rRect.GetIntersection(pObjIter->GetLastBoundRect());
891                 if ( !aRect.IsEmpty() && (aRect.Left() != aRect.Right() && aRect.Top() != aRect.Bottom() ) )
892                     pOverlappedObj = pObjIter;
893             }
894         }
895     }
896     return pOverlappedObj;
897 }
898 
checkArrayForOccurrence(SdrObject const * _pObjToCheck,std::unique_ptr<SdrUnoObj,SdrObjectFreeOp> _pIgnore[],int _nListLength)899 static bool checkArrayForOccurrence(SdrObject const * _pObjToCheck, std::unique_ptr<SdrUnoObj, SdrObjectFreeOp> _pIgnore[], int _nListLength)
900 {
901     for(int i=0;i<_nListLength;i++)
902     {
903         SdrObject *pIgnore = _pIgnore[i].get();
904         if (pIgnore == _pObjToCheck)
905         {
906             return true;
907         }
908     }
909     return false;
910 }
911 
isOver(const tools::Rectangle & _rRect,SdrPage const & _rPage,SdrView const & _rView,bool _bAllObjects,std::unique_ptr<SdrUnoObj,SdrObjectFreeOp> _pIgnoreList[],int _nIgnoreListLength)912 SdrObject* isOver(const tools::Rectangle& _rRect,SdrPage const & _rPage,SdrView const & _rView,bool _bAllObjects, std::unique_ptr<SdrUnoObj, SdrObjectFreeOp> _pIgnoreList[], int _nIgnoreListLength)
913 {
914     SdrObject* pOverlappedObj = nullptr;
915     SdrObjListIter aIter(&_rPage,SdrIterMode::DeepNoGroups);
916 
917     while( !pOverlappedObj )
918     {
919         SdrObject* pObjIter = aIter.Next();
920         if( !pObjIter )
921             break;
922         if (checkArrayForOccurrence(pObjIter, _pIgnoreList, _nIgnoreListLength))
923         {
924             continue;
925         }
926 
927         if ( (_bAllObjects || !_rView.IsObjMarked(pObjIter))
928              && (dynamic_cast<OUnoObject*>(pObjIter) != nullptr || dynamic_cast<OOle2Obj*>(pObjIter) != nullptr) )
929         {
930             tools::Rectangle aRect = _rRect.GetIntersection(pObjIter->GetLastBoundRect());
931             if ( !aRect.IsEmpty() && (aRect.Left() != aRect.Right() && aRect.Top() != aRect.Bottom() ) )
932                 pOverlappedObj = pObjIter;
933         }
934     }
935     return pOverlappedObj;
936 }
937 
938 
isOver(SdrObject const * _pObj,SdrPage const & _rPage,SdrView const & _rView)939 SdrObject* isOver(SdrObject const * _pObj,SdrPage const & _rPage,SdrView const & _rView)
940 {
941     SdrObject* pOverlappedObj = nullptr;
942     if (dynamic_cast<OUnoObject const *>(_pObj) != nullptr || dynamic_cast<OOle2Obj const *>(_pObj) != nullptr) // this doesn't need to be done for shapes
943     {
944         tools::Rectangle aRect = _pObj->GetCurrentBoundRect();
945         pOverlappedObj = isOver(aRect,_rPage,_rView,false/*_bUnMarkedObjects*/,_pObj);
946     }
947     return pOverlappedObj;
948 }
949 
950 
getParameterNames(const uno::Reference<sdbc::XRowSet> & _rxRowSet)951 uno::Sequence< OUString > getParameterNames( const uno::Reference< sdbc::XRowSet >& _rxRowSet )
952 {
953     uno::Sequence< OUString > aNames;
954 
955     try
956     {
957         uno::Reference< sdb::XParametersSupplier > xSuppParams( _rxRowSet, uno::UNO_QUERY_THROW );
958         uno::Reference< container::XIndexAccess > xParams( xSuppParams->getParameters() );
959         if ( xParams.is() )
960         {
961             sal_Int32 count( xParams->getCount() );
962             aNames.realloc( count );
963 
964             uno::Reference< beans::XPropertySet > xParam;
965             OUString sParamName;
966             for ( sal_Int32 i=0; i<count; ++i )
967             {
968                 xParam.set( xParams->getByIndex(i), uno::UNO_QUERY_THROW );
969                 OSL_VERIFY( xParam->getPropertyValue( PROPERTY_NAME ) >>= sParamName );
970                 aNames[i] = sParamName;
971             }
972         }
973     }
974     catch( const uno::Exception& )
975     {
976         DBG_UNHANDLED_EXCEPTION("reportdesign");
977     }
978 
979     return aNames;
980 }
981 
getRectangleFromControl(SdrObject * _pControl)982 tools::Rectangle getRectangleFromControl(SdrObject* _pControl)
983 {
984     if (_pControl)
985     {
986         uno::Reference< report::XReportComponent > xComponent( _pControl->getUnoShape(), uno::UNO_QUERY);
987         if (xComponent.is())
988         {
989             tools::Rectangle aRect(VCLPoint(xComponent->getPosition()),VCLSize(xComponent->getSize()));
990             aRect.setHeight(aRect.getHeight() + 1);
991             aRect.setWidth(aRect.getWidth() + 1);
992             return aRect;
993         }
994     }
995     return tools::Rectangle();
996 }
997 
998 // check overlapping
correctOverlapping(SdrObject * _pControl,OReportSection const & _aReportSection,bool _bInsert)999 void correctOverlapping(SdrObject* _pControl,OReportSection const & _aReportSection,bool _bInsert)
1000 {
1001     OSectionView& rSectionView = _aReportSection.getSectionView();
1002     uno::Reference< report::XReportComponent> xComponent(_pControl->getUnoShape(),uno::UNO_QUERY);
1003     tools::Rectangle aRect = getRectangleFromControl(_pControl);
1004 
1005     bool bOverlapping = true;
1006     while ( bOverlapping )
1007     {
1008         SdrObject* pOverlappedObj = isOver(aRect,*_aReportSection.getPage(),rSectionView,true, _pControl);
1009         bOverlapping = pOverlappedObj != nullptr;
1010         if ( bOverlapping )
1011         {
1012             const tools::Rectangle& aLogicRect = pOverlappedObj->GetLogicRect();
1013             aRect.Move(0,aLogicRect.Top() + aLogicRect.getHeight() - aRect.Top());
1014             xComponent->setPositionY(aRect.Top());
1015         }
1016     }
1017     if (_bInsert) // now insert objects
1018         rSectionView.InsertObjectAtView(_pControl,*rSectionView.GetSdrPageView(), SdrInsertFlags::ADDMARK);
1019 }
1020 
setZoomFactor(const Fraction & _aZoom,vcl::Window & _rWindow)1021 void setZoomFactor(const Fraction& _aZoom, vcl::Window& _rWindow)
1022 {
1023     MapMode aMapMode( _rWindow.GetMapMode() );
1024     aMapMode.SetScaleX(_aZoom);
1025     aMapMode.SetScaleY(_aZoom);
1026     _rWindow.SetMapMode(aMapMode);
1027 }
1028 
openDialogFormula_nothrow(OUString & _in_out_rFormula,const css::uno::Reference<css::uno::XComponentContext> & _xContext,const uno::Reference<awt::XWindow> & _xInspectorWindow,const css::uno::Reference<css::beans::XPropertySet> & _xRowSet)1029 bool openDialogFormula_nothrow( OUString& _in_out_rFormula
1030                                , const css::uno::Reference< css::uno::XComponentContext >& _xContext
1031                                , const uno::Reference< awt::XWindow>& _xInspectorWindow
1032                                , const css::uno::Reference < css::beans::XPropertySet >& _xRowSet
1033                                )
1034 {
1035     OSL_PRECOND( _xInspectorWindow.is(), "openDialogFormula_nothrow: invalid parameters!" );
1036     if ( !_xInspectorWindow.is() )
1037         return false;
1038     bool bSuccess = false;
1039     ::dbtools::SQLExceptionInfo aErrorInfo;
1040     uno::Reference< awt::XWindow > xInspectorWindow;
1041     uno::Reference< lang::XMultiComponentFactory > xFactory;
1042     uno::Reference<lang::XMultiServiceFactory> xServiceFactory;
1043     try
1044     {
1045         xFactory = _xContext->getServiceManager();
1046         xServiceFactory.set(xFactory,uno::UNO_QUERY);
1047 
1048         uno::Reference< report::meta::XFunctionManager> xMgr(xFactory->createInstanceWithContext("org.libreoffice.report.pentaho.SOFunctionManager",_xContext),uno::UNO_QUERY);
1049         if ( xMgr.is() )
1050         {
1051             auto pFormulaManager = std::make_shared<FunctionManager>(xMgr);
1052             ReportFormula aFormula( _in_out_rFormula );
1053 
1054             LanguageTag aLangTag(LANGUAGE_SYSTEM);
1055             CharClass aCC(_xContext, aLangTag);
1056             svl::SharedStringPool aStringPool(aCC);
1057 
1058             FormulaDialog aDlg(
1059                 Application::GetFrameWeld(_xInspectorWindow), xServiceFactory, pFormulaManager,
1060                 aFormula.getUndecoratedContent(), _xRowSet, aStringPool);
1061 
1062             bSuccess = aDlg.run() == RET_OK;
1063             if ( bSuccess )
1064             {
1065                 OUString sFormula = aDlg.getCurrentFormula();
1066                 if ( sFormula[0] == '=' )
1067                     _in_out_rFormula = OUString::Concat("rpt:") + sFormula.subView(1);
1068                 else
1069                     _in_out_rFormula = "rpt:" + sFormula;
1070             }
1071         }
1072     }
1073     catch (const sdb::SQLContext& e) { aErrorInfo = e; }
1074     catch (const sdbc::SQLWarning& e) { aErrorInfo = e; }
1075     catch (const sdbc::SQLException& e) { aErrorInfo = e; }
1076     catch( const uno::Exception& )
1077     {
1078         TOOLS_WARN_EXCEPTION( "reportdesign", "GeometryHandler::impl_dialogFilter_nothrow" );
1079     }
1080 
1081     if ( aErrorInfo.isValid() )
1082         ::dbtools::showError( aErrorInfo, xInspectorWindow, _xContext );
1083 
1084     return bSuccess;
1085 }
1086 
1087 } // namespace rptui
1088 
1089 
1090 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1091