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