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