1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <sal/config.h>
21 
22 #include <vector>
23 
24 #include <ReportDefinition.hxx>
25 
26 #include <FixedLine.hxx>
27 #include <FixedText.hxx>
28 #include <FormattedField.hxx>
29 #include <Functions.hxx>
30 #include <Groups.hxx>
31 #include <ImageControl.hxx>
32 #include <ReportComponent.hxx>
33 #include <ReportHelperImpl.hxx>
34 #include <RptDef.hxx>
35 #include <RptModel.hxx>
36 #include <Section.hxx>
37 #include <Shape.hxx>
38 #include <Tools.hxx>
39 #include <UndoEnv.hxx>
40 #include <strings.hrc>
41 #include <core_resource.hxx>
42 #include <strings.hxx>
43 
44 #include <com/sun/star/beans/PropertyAttribute.hpp>
45 #include <com/sun/star/beans/XMultiPropertyStates.hpp>
46 #include <com/sun/star/chart2/data/DatabaseDataProvider.hpp>
47 #include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp>
48 #include <com/sun/star/document/DocumentProperties.hpp>
49 #include <com/sun/star/document/IndexedPropertyValues.hpp>
50 #include <com/sun/star/document/EventObject.hpp>
51 #include <com/sun/star/document/XEventListener.hpp>
52 #include <com/sun/star/document/XExporter.hpp>
53 #include <com/sun/star/document/XFilter.hpp>
54 #include <com/sun/star/document/XImporter.hpp>
55 #include <com/sun/star/embed/Aspects.hpp>
56 #include <com/sun/star/embed/ElementModes.hpp>
57 #include <com/sun/star/embed/EmbedMapUnits.hpp>
58 #include <com/sun/star/embed/EntryInitModes.hpp>
59 #include <com/sun/star/embed/XEmbedPersist.hpp>
60 #include <com/sun/star/embed/XTransactedObject.hpp>
61 #include <com/sun/star/embed/StorageFactory.hpp>
62 #include <com/sun/star/frame/Desktop.hpp>
63 #include <com/sun/star/io/IOException.hpp>
64 #include <com/sun/star/io/XActiveDataSource.hpp>
65 #include <com/sun/star/io/XSeekable.hpp>
66 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
67 #include <com/sun/star/report/GroupKeepTogether.hpp>
68 #include <com/sun/star/report/ReportPrintOption.hpp>
69 #include <com/sun/star/sdb/CommandType.hpp>
70 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
71 #include <com/sun/star/style/GraphicLocation.hpp>
72 #include <com/sun/star/style/NumberingType.hpp>
73 #include <com/sun/star/style/PageStyleLayout.hpp>
74 #include <com/sun/star/style/XStyle.hpp>
75 #include <com/sun/star/table/BorderLine2.hpp>
76 #include <com/sun/star/table/ShadowFormat.hpp>
77 #include <com/sun/star/task/InteractionHandler.hpp>
78 #include <com/sun/star/task/XStatusIndicator.hpp>
79 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
80 #include <com/sun/star/ui/UIConfigurationManager.hpp>
81 #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
82 #include <com/sun/star/util/CloseVetoException.hpp>
83 #include <com/sun/star/util/NumberFormatsSupplier.hpp>
84 #include <com/sun/star/xml/AttributeData.hpp>
85 #include <com/sun/star/xml/sax/Writer.hpp>
86 
87 #include <comphelper/broadcasthelper.hxx>
88 #include <comphelper/documentconstants.hxx>
89 #include <comphelper/genericpropertyset.hxx>
90 #include <unotools/mediadescriptor.hxx>
91 #include <comphelper/namecontainer.hxx>
92 #include <comphelper/namedvaluecollection.hxx>
93 #include <comphelper/numberedcollection.hxx>
94 #include <comphelper/proparrhlp.hxx>
95 #include <comphelper/propertysetinfo.hxx>
96 #include <comphelper/propertystatecontainer.hxx>
97 #include <comphelper/seqstream.hxx>
98 #include <comphelper/sequence.hxx>
99 #include <comphelper/servicehelper.hxx>
100 #include <comphelper/storagehelper.hxx>
101 #include <comphelper/uno3.hxx>
102 #include <connectivity/CommonTools.hxx>
103 #include <connectivity/dbconversion.hxx>
104 #include <connectivity/dbtools.hxx>
105 #include <cppuhelper/exc_hlp.hxx>
106 #include <cppuhelper/implbase.hxx>
107 #include <cppuhelper/interfacecontainer.h>
108 #include <cppuhelper/supportsservice.hxx>
109 #include <cppuhelper/typeprovider.hxx>
110 #include <dbaccess/dbaundomanager.hxx>
111 #include <editeng/paperinf.hxx>
112 #include <framework/titlehelper.hxx>
113 #include <svl/itempool.hxx>
114 #include <svl/undo.hxx>
115 #include <svx/svdlayer.hxx>
116 #include <svx/unofill.hxx>
117 #include <svx/xmleohlp.hxx>
118 #include <svx/xmlgrhlp.hxx>
119 #include <tools/debug.hxx>
120 #include <tools/diagnose_ex.h>
121 #include <unotools/moduleoptions.hxx>
122 #include <unotools/saveopt.hxx>
123 #include <unotools/streamwrap.hxx>
124 #include <vcl/svapp.hxx>
125 #include <vcl/virdev.hxx>
126 
127 //  page styles
128 #define SC_UNO_PAGE_LEFTBORDER      "LeftBorder"
129 #define SC_UNO_PAGE_RIGHTBORDER     "RightBorder"
130 #define SC_UNO_PAGE_BOTTBORDER      "BottomBorder"
131 #define SC_UNO_PAGE_TOPBORDER       "TopBorder"
132 #define SC_UNO_PAGE_LEFTBRDDIST     "LeftBorderDistance"
133 #define SC_UNO_PAGE_RIGHTBRDDIST    "RightBorderDistance"
134 #define SC_UNO_PAGE_BOTTBRDDIST     "BottomBorderDistance"
135 #define SC_UNO_PAGE_TOPBRDDIST      "TopBorderDistance"
136 #define SC_UNO_PAGE_BORDERDIST      "BorderDistance"
137 #define SC_UNO_PAGE_SHADOWFORM      "ShadowFormat"
138 #define SC_UNO_PAGE_PAPERTRAY       "PrinterPaperTray"
139 #define SC_UNO_PAGE_SCALEVAL        "PageScale"
140 #define SC_UNO_PAGE_SCALETOPAG      "ScaleToPages"
141 #define SC_UNO_PAGE_SCALETOX        "ScaleToPagesX"
142 #define SC_UNO_PAGE_SCALETOY        "ScaleToPagesY"
143 #define SC_UNO_PAGE_HDRBACKCOL      "HeaderBackColor"
144 #define SC_UNO_PAGE_HDRBACKTRAN     "HeaderBackTransparent"
145 #define SC_UNO_PAGE_HDRGRFFILT      "HeaderBackGraphicFilter"
146 #define SC_UNO_PAGE_HDRGRFLOC       "HeaderBackGraphicLocation"
147 #define SC_UNO_PAGE_HDRGRF          "HeaderBackGraphic"
148 #define SC_UNO_PAGE_HDRLEFTBOR      "HeaderLeftBorder"
149 #define SC_UNO_PAGE_HDRRIGHTBOR     "HeaderRightBorder"
150 #define SC_UNO_PAGE_HDRBOTTBOR      "HeaderBottomBorder"
151 #define SC_UNO_PAGE_HDRTOPBOR       "HeaderTopBorder"
152 #define SC_UNO_PAGE_HDRLEFTBDIS     "HeaderLeftBorderDistance"
153 #define SC_UNO_PAGE_HDRRIGHTBDIS    "HeaderRightBorderDistance"
154 #define SC_UNO_PAGE_HDRBOTTBDIS     "HeaderBottomBorderDistance"
155 #define SC_UNO_PAGE_HDRTOPBDIS      "HeaderTopBorderDistance"
156 #define SC_UNO_PAGE_HDRBRDDIST      "HeaderBorderDistance"
157 #define SC_UNO_PAGE_HDRSHADOW       "HeaderShadowFormat"
158 #define SC_UNO_PAGE_HDRLEFTMAR      "HeaderLeftMargin"
159 #define SC_UNO_PAGE_HDRRIGHTMAR     "HeaderRightMargin"
160 #define SC_UNO_PAGE_HDRBODYDIST     "HeaderBodyDistance"
161 #define SC_UNO_PAGE_HDRHEIGHT       "HeaderHeight"
162 #define SC_UNO_PAGE_HDRON           "HeaderIsOn"
163 #define SC_UNO_PAGE_HDRDYNAMIC      "HeaderIsDynamicHeight"
164 #define SC_UNO_PAGE_HDRSHARED       "HeaderIsShared"
165 #define SC_UNO_PAGE_FTRBACKCOL      "FooterBackColor"
166 #define SC_UNO_PAGE_FTRBACKTRAN     "FooterBackTransparent"
167 #define SC_UNO_PAGE_FTRGRFFILT      "FooterBackGraphicFilter"
168 #define SC_UNO_PAGE_FTRGRFLOC       "FooterBackGraphicLocation"
169 #define SC_UNO_PAGE_FTRGRF          "FooterBackGraphic"
170 #define SC_UNO_PAGE_FTRLEFTBOR      "FooterLeftBorder"
171 #define SC_UNO_PAGE_FTRRIGHTBOR     "FooterRightBorder"
172 #define SC_UNO_PAGE_FTRBOTTBOR      "FooterBottomBorder"
173 #define SC_UNO_PAGE_FTRTOPBOR       "FooterTopBorder"
174 #define SC_UNO_PAGE_FTRLEFTBDIS     "FooterLeftBorderDistance"
175 #define SC_UNO_PAGE_FTRRIGHTBDIS    "FooterRightBorderDistance"
176 #define SC_UNO_PAGE_FTRBOTTBDIS     "FooterBottomBorderDistance"
177 #define SC_UNO_PAGE_FTRTOPBDIS      "FooterTopBorderDistance"
178 #define SC_UNO_PAGE_FTRBRDDIST      "FooterBorderDistance"
179 #define SC_UNO_PAGE_FTRSHADOW       "FooterShadowFormat"
180 #define SC_UNO_PAGE_FTRLEFTMAR      "FooterLeftMargin"
181 #define SC_UNO_PAGE_FTRRIGHTMAR     "FooterRightMargin"
182 #define SC_UNO_PAGE_FTRBODYDIST     "FooterBodyDistance"
183 #define SC_UNO_PAGE_FTRHEIGHT       "FooterHeight"
184 #define SC_UNO_PAGE_FTRON           "FooterIsOn"
185 #define SC_UNO_PAGE_FTRDYNAMIC      "FooterIsDynamicHeight"
186 #define SC_UNO_PAGE_FTRSHARED       "FooterIsShared"
187 
188 namespace reportdesign
189 {
190     using namespace com::sun::star;
191     using namespace rptui;
192 
lcl_setModelReadOnly(const uno::Reference<embed::XStorage> & _xStorage,std::shared_ptr<rptui::OReportModel> const & _rModel)193 static void lcl_setModelReadOnly(const uno::Reference< embed::XStorage >& _xStorage,std::shared_ptr<rptui::OReportModel> const & _rModel)
194 {
195     uno::Reference<beans::XPropertySet> xProp(_xStorage,uno::UNO_QUERY);
196     sal_Int32 nOpenMode = embed::ElementModes::READ;
197     if ( xProp.is() )
198         xProp->getPropertyValue("OpenMode") >>= nOpenMode;
199 
200     _rModel->SetReadOnly((nOpenMode & embed::ElementModes::WRITE) != embed::ElementModes::WRITE);
201 }
lcl_stripLoadArguments(utl::MediaDescriptor & _rDescriptor,uno::Sequence<beans::PropertyValue> & _rArgs)202 static void lcl_stripLoadArguments( utl::MediaDescriptor& _rDescriptor, uno::Sequence< beans::PropertyValue >& _rArgs )
203 {
204     _rDescriptor.erase( "StatusIndicator" );
205     _rDescriptor.erase( "InteractionHandler" );
206     _rDescriptor.erase( "Model" );
207     _rDescriptor >> _rArgs;
208 }
209 
lcl_extractAndStartStatusIndicator(const utl::MediaDescriptor & _rDescriptor,uno::Reference<task::XStatusIndicator> & _rxStatusIndicator,uno::Sequence<uno::Any> & _rCallArgs)210 static void lcl_extractAndStartStatusIndicator( const utl::MediaDescriptor& _rDescriptor, uno::Reference< task::XStatusIndicator >& _rxStatusIndicator,
211     uno::Sequence< uno::Any >& _rCallArgs )
212 {
213     try
214     {
215         _rxStatusIndicator = _rDescriptor.getUnpackedValueOrDefault( utl::MediaDescriptor::PROP_STATUSINDICATOR(), _rxStatusIndicator );
216         if ( _rxStatusIndicator.is() )
217         {
218             _rxStatusIndicator->start( OUString(), sal_Int32(1000000) );
219 
220             sal_Int32 nLength = _rCallArgs.getLength();
221             _rCallArgs.realloc( nLength + 1 );
222             _rCallArgs[ nLength ] <<= _rxStatusIndicator;
223         }
224     }
225     catch (const uno::Exception&)
226     {
227         OSL_FAIL( "lcl_extractAndStartStatusIndicator: caught an exception!" );
228     }
229 }
230 
231 typedef ::comphelper::OPropertyStateContainer       OStyle_PBASE;
232 class OStyle;
233 typedef ::comphelper::OPropertyArrayUsageHelper <   OStyle
234                                                 >   OStyle_PABASE;
235 typedef ::cppu::WeakImplHelper< style::XStyle, beans::XMultiPropertyStates> TStyleBASE;
236 
237 class OStyle :   public ::comphelper::OMutexAndBroadcastHelper
238                 ,public TStyleBASE
239                 ,public OStyle_PBASE
240                 ,public OStyle_PABASE
241 {
242     awt::Size m_aSize;
243 
244 protected:
245     void getPropertyDefaultByHandle( sal_Int32 _nHandle, uno::Any& _rDefault ) const override;
~OStyle()246     virtual ~OStyle() override {}
247 public:
248     OStyle();
249 
250 
251     DECLARE_XINTERFACE( )
252 
253     // XPropertySet
254     css::uno::Reference<css::beans::XPropertySetInfo>  SAL_CALL getPropertySetInfo() override;
255     ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
256     ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override;
257 
258     // XStyle
259     sal_Bool SAL_CALL isUserDefined(  ) override;
260     sal_Bool SAL_CALL isInUse(  ) override;
261     OUString SAL_CALL getParentStyle(  ) override;
262     void SAL_CALL setParentStyle( const OUString& aParentStyle ) override;
263 
264     // XNamed
265     OUString SAL_CALL getName(  ) override;
266     void SAL_CALL setName( const OUString& aName ) override;
267 
268     // XMultiPropertyState
getPropertyStates(const uno::Sequence<OUString> & aPropertyNames)269     uno::Sequence< beans::PropertyState > SAL_CALL getPropertyStates( const uno::Sequence< OUString >& aPropertyNames ) override
270     {
271         return OStyle_PBASE::getPropertyStates(aPropertyNames);
272     }
273     void SAL_CALL setAllPropertiesToDefault(  ) override;
274     void SAL_CALL setPropertiesToDefault( const uno::Sequence< OUString >& aPropertyNames ) override;
275     uno::Sequence< uno::Any > SAL_CALL getPropertyDefaults( const uno::Sequence< OUString >& aPropertyNames ) override;
276 };
277 
OStyle()278 OStyle::OStyle()
279 :OStyle_PBASE(m_aBHelper)
280 ,m_aSize(21000,29700)
281 {
282     const ::Size aDefaultSize = SvxPaperInfo::GetDefaultPaperSize( MapUnit::Map100thMM );
283     m_aSize.Height = aDefaultSize.Height();
284     m_aSize.Width = aDefaultSize.Width();
285 
286     const sal_Int32 nMargin = 2000;
287     const sal_Int32 nBound = beans::PropertyAttribute::BOUND;
288     const sal_Int32 nMayBeVoid = beans::PropertyAttribute::MAYBEVOID;
289 
290     sal_Int32 i = 0;
291     registerPropertyNoMember( PROPERTY_NAME, ++i, nBound, cppu::UnoType<OUString>::get(), css::uno::Any(OUString("Default")) );
292 
293     registerPropertyNoMember(PROPERTY_BACKCOLOR,                    ++i,nBound, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny(COL_TRANSPARENT));
294 
295     registerPropertyNoMember(PROPERTY_BACKGRAPHICLOCATION,  ++i,nBound, cppu::UnoType<style::GraphicLocation>::get(), css::uno::Any(style::GraphicLocation_NONE));
296     registerPropertyNoMember(PROPERTY_BACKTRANSPARENT,  ++i,nBound,cppu::UnoType<bool>::get(), css::uno::Any(true));
297     registerPropertyNoMember(SC_UNO_PAGE_BORDERDIST,  ++i,nBound, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
298     registerPropertyNoMember(SC_UNO_PAGE_BOTTBORDER,  ++i,nBound, cppu::UnoType<table::BorderLine2>::get(), css::uno::Any(table::BorderLine2()));
299     registerPropertyNoMember(SC_UNO_PAGE_BOTTBRDDIST, ++i,nBound, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
300     registerPropertyNoMember(PROPERTY_BOTTOMMARGIN, ++i,nBound, cppu::UnoType<sal_Int32>::get(), css::uno::Any(nMargin));
301     registerPropertyNoMember("DisplayName",       ++i,nBound, cppu::UnoType<OUString>::get(), css::uno::Any(OUString()));
302     registerPropertyNoMember(SC_UNO_PAGE_FTRBACKCOL,  ++i,nBound, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny(COL_TRANSPARENT));
303     registerPropertyNoMember(SC_UNO_PAGE_FTRGRFFILT,  ++i,nBound, cppu::UnoType<OUString>::get(), css::uno::Any(OUString()));
304     registerPropertyNoMember(SC_UNO_PAGE_FTRGRFLOC,   ++i,nBound, cppu::UnoType<style::GraphicLocation>::get(), css::uno::Any(style::GraphicLocation_NONE));
305     registerPropertyNoMember(SC_UNO_PAGE_FTRGRF,      ++i,nBound|nMayBeVoid, cppu::UnoType<graphic::XGraphic>::get(), css::uno::Any(uno::Reference<graphic::XGraphic>()));
306     registerPropertyNoMember(SC_UNO_PAGE_FTRBACKTRAN, ++i,nBound,cppu::UnoType<bool>::get(), css::uno::Any(true));
307     registerPropertyNoMember(SC_UNO_PAGE_FTRBODYDIST, ++i,nBound, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
308     registerPropertyNoMember(SC_UNO_PAGE_FTRBRDDIST,  ++i,nBound, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
309     registerPropertyNoMember(SC_UNO_PAGE_FTRBOTTBOR,  ++i,nBound, cppu::UnoType<table::BorderLine2>::get(), css::uno::Any(table::BorderLine2()));
310     registerPropertyNoMember(SC_UNO_PAGE_FTRBOTTBDIS, ++i,nBound, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
311     registerPropertyNoMember(SC_UNO_PAGE_FTRHEIGHT,   ++i,nBound, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
312     registerPropertyNoMember(SC_UNO_PAGE_FTRDYNAMIC,  ++i,nBound,cppu::UnoType<bool>::get(), css::uno::Any(false));
313     registerPropertyNoMember(SC_UNO_PAGE_FTRON,       ++i,nBound,cppu::UnoType<bool>::get(), css::uno::Any(false));
314     registerPropertyNoMember(SC_UNO_PAGE_FTRSHARED,   ++i,nBound,cppu::UnoType<bool>::get(), css::uno::Any(false));
315     registerPropertyNoMember(SC_UNO_PAGE_FTRLEFTBOR,  ++i,nBound, cppu::UnoType<table::BorderLine2>::get(), css::uno::Any(table::BorderLine2()));
316     registerPropertyNoMember(SC_UNO_PAGE_FTRLEFTBDIS, ++i,nBound, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
317     registerPropertyNoMember(SC_UNO_PAGE_FTRLEFTMAR,  ++i,nBound, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
318     registerPropertyNoMember(SC_UNO_PAGE_FTRRIGHTBOR, ++i,nBound, cppu::UnoType<table::BorderLine2>::get(), css::uno::Any(table::BorderLine2()));
319     registerPropertyNoMember(SC_UNO_PAGE_FTRRIGHTBDIS,++i,nBound, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
320     registerPropertyNoMember(SC_UNO_PAGE_FTRRIGHTMAR, ++i,nBound, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
321     registerPropertyNoMember(SC_UNO_PAGE_FTRSHADOW,   ++i,nBound, cppu::UnoType<table::ShadowFormat>::get(), css::uno::Any(table::ShadowFormat()));
322     registerPropertyNoMember(SC_UNO_PAGE_FTRTOPBOR,   ++i,nBound, cppu::UnoType<table::BorderLine2>::get(), css::uno::Any(table::BorderLine2()));
323     registerPropertyNoMember(SC_UNO_PAGE_FTRTOPBDIS,  ++i,nBound, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
324 
325     registerPropertyNoMember(SC_UNO_PAGE_HDRBACKCOL,  ++i,nBound|nMayBeVoid, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny(COL_TRANSPARENT));
326     registerPropertyNoMember(SC_UNO_PAGE_HDRGRFFILT,  ++i,nBound|nMayBeVoid, cppu::UnoType<OUString>::get(), css::uno::Any(OUString()));
327     registerPropertyNoMember(SC_UNO_PAGE_HDRGRFLOC,   ++i,nBound|nMayBeVoid, cppu::UnoType<style::GraphicLocation>::get(), css::uno::Any(style::GraphicLocation_NONE));
328     registerPropertyNoMember(SC_UNO_PAGE_HDRGRF,      ++i,nBound|nMayBeVoid, cppu::UnoType<graphic::XGraphic>::get(), css::uno::Any(uno::Reference<graphic::XGraphic>()));
329     registerPropertyNoMember(SC_UNO_PAGE_HDRBACKTRAN, ++i,nBound|nMayBeVoid,cppu::UnoType<bool>::get(), css::uno::Any(true));
330     registerPropertyNoMember(SC_UNO_PAGE_HDRBODYDIST, ++i,nBound|nMayBeVoid, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
331     registerPropertyNoMember(SC_UNO_PAGE_HDRBRDDIST,  ++i,nBound|nMayBeVoid, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
332     registerPropertyNoMember(SC_UNO_PAGE_HDRBOTTBOR,  ++i,nBound|nMayBeVoid, cppu::UnoType<table::BorderLine2>::get(), css::uno::Any(table::BorderLine2()));
333     registerPropertyNoMember(SC_UNO_PAGE_HDRBOTTBDIS, ++i,nBound|nMayBeVoid, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
334     registerPropertyNoMember(SC_UNO_PAGE_HDRHEIGHT,   ++i,nBound|nMayBeVoid, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
335     registerPropertyNoMember(SC_UNO_PAGE_HDRDYNAMIC,  ++i,nBound|nMayBeVoid,cppu::UnoType<bool>::get(), css::uno::Any(false));
336     registerPropertyNoMember(SC_UNO_PAGE_HDRON,       ++i,nBound|nMayBeVoid,cppu::UnoType<bool>::get(), css::uno::Any(false));
337     registerPropertyNoMember(SC_UNO_PAGE_HDRSHARED,   ++i,nBound|nMayBeVoid,cppu::UnoType<bool>::get(), css::uno::Any(false));
338     registerPropertyNoMember(SC_UNO_PAGE_HDRLEFTBOR,  ++i,nBound|nMayBeVoid, cppu::UnoType<table::BorderLine2>::get(), css::uno::Any(table::BorderLine2()));
339     registerPropertyNoMember(SC_UNO_PAGE_HDRLEFTBDIS, ++i,nBound|nMayBeVoid, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
340     registerPropertyNoMember(SC_UNO_PAGE_HDRLEFTMAR,  ++i,nBound|nMayBeVoid, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
341     registerPropertyNoMember(SC_UNO_PAGE_HDRRIGHTBOR, ++i,nBound|nMayBeVoid, cppu::UnoType<table::BorderLine2>::get(), css::uno::Any(table::BorderLine2()));
342     registerPropertyNoMember(SC_UNO_PAGE_HDRRIGHTBDIS,++i,nBound|nMayBeVoid, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
343     registerPropertyNoMember(SC_UNO_PAGE_HDRRIGHTMAR, ++i,nBound|nMayBeVoid, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
344     registerPropertyNoMember(SC_UNO_PAGE_HDRSHADOW,   ++i,nBound|nMayBeVoid, cppu::UnoType<table::ShadowFormat>::get(), css::uno::Any(table::ShadowFormat()));
345     registerPropertyNoMember(SC_UNO_PAGE_HDRTOPBOR,   ++i,nBound|nMayBeVoid, cppu::UnoType<table::BorderLine2>::get(), css::uno::Any(table::BorderLine2()));
346     registerPropertyNoMember(SC_UNO_PAGE_HDRTOPBDIS,  ++i,nBound|nMayBeVoid, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
347 
348     registerProperty(PROPERTY_HEIGHT,       ++i,nBound,&m_aSize.Height,     ::cppu::UnoType<sal_Int32>::get() );
349     registerPropertyNoMember(PROPERTY_ISLANDSCAPE,                  ++i,nBound,         cppu::UnoType<bool>::get(), css::uno::Any(false));
350     registerPropertyNoMember(SC_UNO_PAGE_LEFTBORDER,  ++i,nBound, cppu::UnoType<table::BorderLine2>::get(), css::uno::Any(table::BorderLine2()));
351     registerPropertyNoMember(SC_UNO_PAGE_LEFTBRDDIST, ++i,nBound, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
352     registerPropertyNoMember(PROPERTY_LEFTMARGIN,   ++i,beans::PropertyAttribute::BOUND,        ::cppu::UnoType<sal_Int32>::get(), css::uno::Any(nMargin));
353     registerPropertyNoMember(PROPERTY_NUMBERINGTYPE,                ++i,nBound, cppu::UnoType<sal_Int16>::get(), css::uno::Any(style::NumberingType::ARABIC));
354     registerPropertyNoMember(SC_UNO_PAGE_SCALEVAL,    ++i,nBound, cppu::UnoType<sal_Int16>::get(), css::uno::makeAny<sal_Int16>(0));
355     registerPropertyNoMember(PROPERTY_PAGESTYLELAYOUT,              ++i,nBound, cppu::UnoType<style::PageStyleLayout>::get(), css::uno::Any(style::PageStyleLayout_ALL));
356     registerPropertyNoMember(SC_UNO_PAGE_PAPERTRAY,   ++i,nBound, cppu::UnoType<OUString>::get(), css::uno::Any(OUString("[From printer settings]")));
357     registerPropertyNoMember(SC_UNO_PAGE_RIGHTBORDER, ++i,nBound, cppu::UnoType<table::BorderLine2>::get(), css::uno::Any(table::BorderLine2()));
358     registerPropertyNoMember(SC_UNO_PAGE_RIGHTBRDDIST,++i,nBound, cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
359     registerPropertyNoMember(PROPERTY_RIGHTMARGIN,  ++i,beans::PropertyAttribute::BOUND,::cppu::UnoType<sal_Int32>::get(), css::uno::Any(nMargin));
360     registerPropertyNoMember(SC_UNO_PAGE_SCALETOPAG,  ++i,nBound, cppu::UnoType<sal_Int16>::get(), css::uno::makeAny<sal_Int16>(0));
361     registerPropertyNoMember(SC_UNO_PAGE_SCALETOX,    ++i,nBound, cppu::UnoType<sal_Int16>::get(), css::uno::makeAny<sal_Int16>(0));
362     registerPropertyNoMember(SC_UNO_PAGE_SCALETOY,    ++i,nBound, cppu::UnoType<sal_Int16>::get(), css::uno::makeAny<sal_Int16>(0));
363     registerPropertyNoMember(SC_UNO_PAGE_SHADOWFORM,  ++i,nBound, cppu::UnoType<table::ShadowFormat>::get(), css::uno::Any(table::ShadowFormat()));
364     registerProperty(PROPERTY_PAPERSIZE,                    ++i,beans::PropertyAttribute::BOUND,&m_aSize, cppu::UnoType<awt::Size>::get() );
365     registerPropertyNoMember(SC_UNO_PAGE_TOPBORDER,   ++i,nBound, cppu::UnoType<table::BorderLine2>::get(), css::uno::Any(table::BorderLine2()));
366     registerPropertyNoMember(SC_UNO_PAGE_TOPBRDDIST,  ++i,nBound,::cppu::UnoType<sal_Int32>::get(), css::uno::makeAny<sal_Int32>(0));
367     registerPropertyNoMember(PROPERTY_TOPMARGIN,    ++i,nBound,::cppu::UnoType<sal_Int32>::get(), css::uno::Any(nMargin));
368     registerPropertyNoMember("UserDefinedAttributes",     ++i,nBound, cppu::UnoType<container::XNameContainer>::get(), css::uno::Any(comphelper::NameContainer_createInstance(cppu::UnoType<xml::AttributeData>::get())));
369     registerProperty(PROPERTY_WIDTH,        ++i,nBound,&m_aSize.Width, cppu::UnoType<sal_Int32>::get() );
370     registerPropertyNoMember("PrinterName",               ++i,nBound, cppu::UnoType<OUString>::get(), css::uno::Any(OUString()));
371     registerPropertyNoMember("PrinterSetup",              ++i,nBound,cppu::UnoType<uno::Sequence<sal_Int8>>::get(), css::uno::Any(uno::Sequence<sal_Int8>()));
372 
373 
374 }
375 
IMPLEMENT_FORWARD_XINTERFACE2(OStyle,TStyleBASE,OStyle_PBASE)376 IMPLEMENT_FORWARD_XINTERFACE2(OStyle,TStyleBASE,OStyle_PBASE)
377 
378 uno::Reference< beans::XPropertySetInfo>  SAL_CALL OStyle::getPropertySetInfo()
379 {
380     return createPropertySetInfo( getInfoHelper() );
381 }
382 
getPropertyDefaultByHandle(sal_Int32,uno::Any &) const383 void OStyle::getPropertyDefaultByHandle( sal_Int32 /*_nHandle*/, uno::Any& /*_rDefault*/ ) const
384 {
385 }
386 
getInfoHelper()387 ::cppu::IPropertyArrayHelper& OStyle::getInfoHelper()
388 {
389     return *getArrayHelper();
390 }
391 
createArrayHelper() const392 ::cppu::IPropertyArrayHelper* OStyle::createArrayHelper( ) const
393 {
394     uno::Sequence< beans::Property > aProps;
395     describeProperties(aProps);
396     return new ::cppu::OPropertyArrayHelper(aProps);
397 }
398 
399 // XStyle
isUserDefined()400 sal_Bool SAL_CALL OStyle::isUserDefined(  )
401 {
402     return false;
403 }
404 
isInUse()405 sal_Bool SAL_CALL OStyle::isInUse(  )
406 {
407     return true;
408 }
409 
getParentStyle()410 OUString SAL_CALL OStyle::getParentStyle(  )
411 {
412     return OUString();
413 }
414 
setParentStyle(const OUString &)415 void SAL_CALL OStyle::setParentStyle( const OUString& /*aParentStyle*/ )
416 {
417 }
418 
419 // XNamed
getName()420 OUString SAL_CALL OStyle::getName(  )
421 {
422     OUString sName;
423     getPropertyValue(PROPERTY_NAME) >>= sName;
424     return sName;
425 }
426 
setName(const OUString & aName)427 void SAL_CALL OStyle::setName( const OUString& aName )
428 {
429     setPropertyValue(PROPERTY_NAME,uno::makeAny(aName));
430 }
431 
setAllPropertiesToDefault()432 void SAL_CALL OStyle::setAllPropertiesToDefault(  )
433 {
434 }
435 
setPropertiesToDefault(const uno::Sequence<OUString> & aPropertyNames)436 void SAL_CALL OStyle::setPropertiesToDefault( const uno::Sequence< OUString >& aPropertyNames )
437 {
438     for(const OUString& rName : aPropertyNames)
439         setPropertyToDefault(rName);
440 }
441 
getPropertyDefaults(const uno::Sequence<OUString> & aPropertyNames)442 uno::Sequence< uno::Any > SAL_CALL OStyle::getPropertyDefaults( const uno::Sequence< OUString >& aPropertyNames )
443 {
444     uno::Sequence< uno::Any > aRet(aPropertyNames.getLength());
445     std::transform(aPropertyNames.begin(), aPropertyNames.end(), aRet.begin(),
446         [this](const OUString& rName) -> uno::Any { return getPropertyDefault(rName); });
447     return aRet;
448 }
449 
450 struct OReportDefinitionImpl
451 {
452     uno::WeakReference< uno::XInterface >                   m_xParent;
453     ::comphelper::OInterfaceContainerHelper2                      m_aStorageChangeListeners;
454     ::comphelper::OInterfaceContainerHelper2                      m_aCloseListener;
455     ::comphelper::OInterfaceContainerHelper2                      m_aModifyListeners;
456     ::comphelper::OInterfaceContainerHelper2                      m_aLegacyEventListeners;
457     ::comphelper::OInterfaceContainerHelper2                      m_aDocEventListeners;
458     ::std::vector< uno::Reference< frame::XController> >    m_aControllers;
459     uno::Sequence< beans::PropertyValue >                   m_aArgs;
460 
461     uno::Reference< report::XGroups >                       m_xGroups;
462     uno::Reference< report::XSection>                       m_xReportHeader;
463     uno::Reference< report::XSection>                       m_xReportFooter;
464     uno::Reference< report::XSection>                       m_xPageHeader;
465     uno::Reference< report::XSection>                       m_xPageFooter;
466     uno::Reference< report::XSection>                       m_xDetail;
467     uno::Reference< embed::XStorage >                       m_xStorage;
468     uno::Reference< frame::XController >                    m_xCurrentController;
469     uno::Reference< container::XIndexAccess >               m_xViewData;
470     uno::Reference< container::XNameAccess >                m_xStyles;
471     uno::Reference< container::XNameAccess>                 m_xXMLNamespaceMap;
472     uno::Reference< container::XNameAccess>                 m_xGradientTable;
473     uno::Reference< container::XNameAccess>                 m_xHatchTable;
474     uno::Reference< container::XNameAccess>                 m_xBitmapTable;
475     uno::Reference< container::XNameAccess>                 m_xTransparencyGradientTable;
476     uno::Reference< container::XNameAccess>                 m_xDashTable;
477     uno::Reference< container::XNameAccess>                 m_xMarkerTable;
478     uno::Reference< report::XFunctions >                    m_xFunctions;
479     uno::Reference< ui::XUIConfigurationManager2>           m_xUIConfigurationManager;
480     uno::Reference< util::XNumberFormatsSupplier>           m_xNumberFormatsSupplier;
481     uno::Reference< sdbc::XConnection>                      m_xActiveConnection;
482     uno::Reference< frame::XTitle >                         m_xTitleHelper;
483     uno::Reference< frame::XUntitledNumbers >               m_xNumberedControllers;
484     uno::Reference< document::XDocumentProperties >         m_xDocumentProperties;
485 
486     std::shared_ptr< ::comphelper::EmbeddedObjectContainer>
487                                                             m_pObjectContainer;
488     std::shared_ptr<rptui::OReportModel>                m_pReportModel;
489     ::rtl::Reference< ::dbaui::UndoManager >                m_pUndoManager;
490     OUString                                         m_sCaption;
491     OUString                                         m_sCommand;
492     OUString                                         m_sFilter;
493     OUString                                         m_sMimeType;
494     OUString                                         m_sIdentifier;
495     OUString                                         m_sDataSourceName;
496     awt::Size                                               m_aVisualAreaSize;
497     ::sal_Int64                                             m_nAspect;
498     ::sal_Int16                                             m_nGroupKeepTogether;
499     ::sal_Int16                                             m_nPageHeaderOption;
500     ::sal_Int16                                             m_nPageFooterOption;
501     ::sal_Int32                                             m_nCommandType;
502     bool                                                    m_bControllersLocked;
503     bool                                                    m_bModified;
504     bool                                                    m_bEscapeProcessing;
505     bool                                                    m_bSetModifiedEnabled;
506 
OReportDefinitionImplreportdesign::OReportDefinitionImpl507     explicit OReportDefinitionImpl(::osl::Mutex& _aMutex)
508     :m_aStorageChangeListeners(_aMutex)
509     ,m_aCloseListener(_aMutex)
510     ,m_aModifyListeners(_aMutex)
511     ,m_aLegacyEventListeners(_aMutex)
512     ,m_aDocEventListeners(_aMutex)
513     ,m_sMimeType(MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII)
514     ,m_sIdentifier(SERVICE_REPORTDEFINITION)
515     // default visual area is 8 x 7 cm
516     ,m_aVisualAreaSize( 8000, 7000 )
517     ,m_nAspect(embed::Aspects::MSOLE_CONTENT)
518     ,m_nGroupKeepTogether(0)
519     ,m_nPageHeaderOption(0)
520     ,m_nPageFooterOption(0)
521     ,m_nCommandType(sdb::CommandType::TABLE)
522     ,m_bControllersLocked(false)
523     ,m_bModified(false)
524     ,m_bEscapeProcessing(true)
525     ,m_bSetModifiedEnabled( true )
526     {}
527 };
528 
OReportDefinition(uno::Reference<uno::XComponentContext> const & _xContext)529 OReportDefinition::OReportDefinition(uno::Reference< uno::XComponentContext > const & _xContext)
530 :   ::cppu::BaseMutex(),
531     ReportDefinitionBase(m_aMutex),
532     ReportDefinitionPropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,uno::Sequence< OUString >()),
533     ::comphelper::IEmbeddedHelper(),
534     m_aProps(new OReportComponentProperties(_xContext)),
535     m_pImpl(new OReportDefinitionImpl(m_aMutex))
536 {
537     m_aProps->m_sName  = RptResId(RID_STR_REPORT);
538     osl_atomic_increment(&m_refCount);
539     {
540         init();
541         m_pImpl->m_xGroups = new OGroups(this,m_aProps->m_xContext);
542         m_pImpl->m_xDetail = OSection::createOSection(this,m_aProps->m_xContext);
543         m_pImpl->m_xDetail->setName(RptResId(RID_STR_DETAIL));
544     }
545     osl_atomic_decrement( &m_refCount );
546 }
547 
OReportDefinition(uno::Reference<uno::XComponentContext> const & _xContext,const uno::Reference<lang::XMultiServiceFactory> & _xFactory,uno::Reference<drawing::XShape> & _xShape)548 OReportDefinition::OReportDefinition(
549     uno::Reference< uno::XComponentContext > const & _xContext,
550     const uno::Reference< lang::XMultiServiceFactory>& _xFactory,
551     uno::Reference< drawing::XShape >& _xShape)
552 :   ::cppu::BaseMutex(),
553     ReportDefinitionBase(m_aMutex),
554     ReportDefinitionPropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,uno::Sequence< OUString >()),
555     ::comphelper::IEmbeddedHelper(),
556     m_aProps(new OReportComponentProperties(_xContext)),
557     m_pImpl(new OReportDefinitionImpl(m_aMutex))
558 {
559     m_aProps->m_sName  = RptResId(RID_STR_REPORT);
560     m_aProps->m_xFactory = _xFactory;
561     osl_atomic_increment(&m_refCount);
562     {
563         m_aProps->setShape(_xShape,this,m_refCount);
564         init();
565         m_pImpl->m_xGroups = new OGroups(this,m_aProps->m_xContext);
566         m_pImpl->m_xDetail = OSection::createOSection(this,m_aProps->m_xContext);
567         m_pImpl->m_xDetail->setName(RptResId(RID_STR_DETAIL));
568     }
569     osl_atomic_decrement( &m_refCount );
570 }
571 
~OReportDefinition()572 OReportDefinition::~OReportDefinition()
573 {
574     if ( !ReportDefinitionBase::rBHelper.bInDispose && !ReportDefinitionBase::rBHelper.bDisposed )
575     {
576         acquire();
577         dispose();
578     }
579 }
580 
IMPLEMENT_FORWARD_REFCOUNT(OReportDefinition,ReportDefinitionBase)581 IMPLEMENT_FORWARD_REFCOUNT( OReportDefinition, ReportDefinitionBase )
582 void OReportDefinition::init()
583 {
584     try
585     {
586         m_pImpl->m_pReportModel.reset(new OReportModel(this));
587         m_pImpl->m_pReportModel->GetItemPool().FreezeIdRanges();
588         m_pImpl->m_pReportModel->SetScaleUnit( MapUnit::Map100thMM );
589         SdrLayerAdmin& rAdmin = m_pImpl->m_pReportModel->GetLayerAdmin();
590         rAdmin.NewLayer("front", sal_uInt8(RPT_LAYER_FRONT));
591         rAdmin.NewLayer("back", sal_uInt8(RPT_LAYER_BACK));
592         rAdmin.NewLayer("HiddenLayer", sal_uInt8(RPT_LAYER_HIDDEN));
593 
594         m_pImpl->m_pUndoManager = new ::dbaui::UndoManager( *this, m_aMutex );
595         m_pImpl->m_pReportModel->SetSdrUndoManager( &m_pImpl->m_pUndoManager->GetSfxUndoManager() );
596 
597         m_pImpl->m_xFunctions = new OFunctions(this,m_aProps->m_xContext);
598         if ( !m_pImpl->m_xStorage.is() )
599             m_pImpl->m_xStorage = ::comphelper::OStorageHelper::GetTemporaryStorage();
600 
601         uno::Reference<beans::XPropertySet> xStorProps(m_pImpl->m_xStorage,uno::UNO_QUERY);
602         if ( xStorProps.is())
603         {
604             OUString sMediaType;
605             xStorProps->getPropertyValue("MediaType") >>= sMediaType;
606             if ( sMediaType.isEmpty() )
607                 xStorProps->setPropertyValue("MediaType",uno::makeAny<OUString>(MIMETYPE_OASIS_OPENDOCUMENT_REPORT_ASCII));
608         }
609         m_pImpl->m_pObjectContainer.reset( new comphelper::EmbeddedObjectContainer(m_pImpl->m_xStorage , static_cast<cppu::OWeakObject*>(this) ) );
610     }
611     catch (const uno::Exception&)
612     {
613         DBG_UNHANDLED_EXCEPTION("reportdesign");
614     }
615 }
616 
dispose()617 void SAL_CALL OReportDefinition::dispose()
618 {
619     ReportDefinitionPropertySet::dispose();
620     cppu::WeakComponentImplHelperBase::dispose();
621 }
622 
disposing()623 void SAL_CALL OReportDefinition::disposing()
624 {
625     notifyEvent("OnUnload");
626 
627     uno::Reference< frame::XModel > xHoldAlive( this );
628 
629     lang::EventObject aDisposeEvent( static_cast< ::cppu::OWeakObject* >( this ) );
630     m_pImpl->m_aModifyListeners.disposeAndClear( aDisposeEvent );
631     m_pImpl->m_aCloseListener.disposeAndClear( aDisposeEvent );
632     m_pImpl->m_aLegacyEventListeners.disposeAndClear( aDisposeEvent );
633     m_pImpl->m_aDocEventListeners.disposeAndClear( aDisposeEvent );
634     m_pImpl->m_aStorageChangeListeners.disposeAndClear( aDisposeEvent );
635 
636     // SYNCHRONIZED --->
637     {
638     SolarMutexGuard aSolarGuard;
639     osl::MutexGuard aGuard(m_aMutex);
640 
641     m_pImpl->m_aControllers.clear();
642 
643     ::comphelper::disposeComponent(m_pImpl->m_xGroups);
644     m_pImpl->m_xReportHeader.clear();
645     m_pImpl->m_xReportFooter.clear();
646     m_pImpl->m_xPageHeader.clear();
647     m_pImpl->m_xPageFooter.clear();
648     m_pImpl->m_xDetail.clear();
649     ::comphelper::disposeComponent(m_pImpl->m_xFunctions);
650 
651     //::comphelper::disposeComponent(m_pImpl->m_xStorage);
652         // don't dispose, this currently is the task of either the ref count going to
653         // 0, or of the embedded object (if we're embedded, which is the only possible
654         // case so far)
655         // #i78366#
656     m_pImpl->m_xStorage.clear();
657     m_pImpl->m_xViewData.clear();
658     m_pImpl->m_xCurrentController.clear();
659     m_pImpl->m_xNumberFormatsSupplier.clear();
660     m_pImpl->m_xStyles.clear();
661     m_pImpl->m_xXMLNamespaceMap.clear();
662     m_pImpl->m_xGradientTable.clear();
663     m_pImpl->m_xHatchTable.clear();
664     m_pImpl->m_xBitmapTable.clear();
665     m_pImpl->m_xTransparencyGradientTable.clear();
666     m_pImpl->m_xDashTable.clear();
667     m_pImpl->m_xMarkerTable.clear();
668     m_pImpl->m_xUIConfigurationManager.clear();
669     m_pImpl->m_pReportModel.reset();
670     m_pImpl->m_pObjectContainer.reset();
671     m_pImpl->m_aArgs.realloc(0);
672     m_pImpl->m_xTitleHelper.clear();
673     m_pImpl->m_xNumberedControllers.clear();
674     }
675     // <--- SYNCHRONIZED
676 }
677 
678 
getImplementationName_Static()679 OUString OReportDefinition::getImplementationName_Static(  )
680 {
681     return "com.sun.star.comp.report.OReportDefinition";
682 }
683 
getImplementationName()684 OUString SAL_CALL OReportDefinition::getImplementationName(  )
685 {
686     return getImplementationName_Static();
687 }
688 
getSupportedServiceNames_Static()689 uno::Sequence< OUString > OReportDefinition::getSupportedServiceNames_Static(  )
690 {
691     uno::Sequence< OUString > aServices { SERVICE_REPORTDEFINITION };
692 
693     return aServices;
694 }
695 
getSupportedServiceNames()696 uno::Sequence< OUString > SAL_CALL OReportDefinition::getSupportedServiceNames(  )
697 {
698     // first collect the services which are supported by our aggregate
699     uno::Sequence< OUString > aSupported;
700     if ( m_aProps->m_xServiceInfo.is() )
701         aSupported = m_aProps->m_xServiceInfo->getSupportedServiceNames();
702 
703     // append our own service, if necessary
704     if ( ::comphelper::findValue( aSupported, SERVICE_REPORTDEFINITION ) == -1 )
705     {
706         sal_Int32 nLen = aSupported.getLength();
707         aSupported.realloc( nLen + 1 );
708         aSupported[ nLen ] = SERVICE_REPORTDEFINITION;
709     }
710 
711     // outta here
712     return aSupported;
713 }
714 
supportsService(const OUString & _rServiceName)715 sal_Bool SAL_CALL OReportDefinition::supportsService( const OUString& _rServiceName )
716 {
717     return cppu::supportsService(this, _rServiceName);
718 }
719 
queryInterface(const uno::Type & _rType)720 uno::Any SAL_CALL OReportDefinition::queryInterface( const uno::Type& _rType )
721 {
722     uno::Any aReturn = ReportDefinitionBase::queryInterface(_rType);
723     if ( !aReturn.hasValue() )
724         aReturn = ReportDefinitionPropertySet::queryInterface(_rType);
725 
726     return aReturn.hasValue() ? aReturn : (m_aProps->m_xProxy.is() ? m_aProps->m_xProxy->queryAggregation(_rType) : aReturn);
727 }
getTypes()728 uno::Sequence< uno::Type > SAL_CALL OReportDefinition::getTypes(  )
729 {
730     if ( m_aProps->m_xTypeProvider.is() )
731         return ::comphelper::concatSequences(
732             ReportDefinitionBase::getTypes(),
733             m_aProps->m_xTypeProvider->getTypes()
734         );
735     return ReportDefinitionBase::getTypes();
736 }
737 
create(uno::Reference<uno::XComponentContext> const & xContext)738 uno::Reference< uno::XInterface > OReportDefinition::create(uno::Reference< uno::XComponentContext > const & xContext)
739 {
740     return *(new OReportDefinition(xContext));
741 }
742 
743 // XReportDefinition
getCaption()744 OUString SAL_CALL OReportDefinition::getCaption()
745 {
746     ::osl::MutexGuard aGuard(m_aMutex);
747     return m_pImpl->m_sCaption;
748 }
749 
setCaption(const OUString & _caption)750 void SAL_CALL OReportDefinition::setCaption( const OUString& _caption )
751 {
752     set(PROPERTY_CAPTION,_caption,m_pImpl->m_sCaption);
753 }
754 
getGroupKeepTogether()755 ::sal_Int16 SAL_CALL OReportDefinition::getGroupKeepTogether()
756 {
757     ::osl::MutexGuard aGuard(m_aMutex);
758     return m_pImpl->m_nGroupKeepTogether;
759 }
760 
setGroupKeepTogether(::sal_Int16 _groupkeeptogether)761 void SAL_CALL OReportDefinition::setGroupKeepTogether( ::sal_Int16 _groupkeeptogether )
762 {
763     if ( _groupkeeptogether < report::GroupKeepTogether::PER_PAGE || _groupkeeptogether > report::GroupKeepTogether::PER_COLUMN )
764         throwIllegallArgumentException("css::report::GroupKeepTogether"
765                         ,*this
766                         ,1);
767     set(PROPERTY_GROUPKEEPTOGETHER,_groupkeeptogether,m_pImpl->m_nGroupKeepTogether);
768 }
769 
getPageHeaderOption()770 ::sal_Int16 SAL_CALL OReportDefinition::getPageHeaderOption()
771 {
772     ::osl::MutexGuard aGuard(m_aMutex);
773     return m_pImpl->m_nPageHeaderOption;
774 }
775 
setPageHeaderOption(::sal_Int16 _pageheaderoption)776 void SAL_CALL OReportDefinition::setPageHeaderOption( ::sal_Int16 _pageheaderoption )
777 {
778     if ( _pageheaderoption < report::ReportPrintOption::ALL_PAGES || _pageheaderoption > report::ReportPrintOption::NOT_WITH_REPORT_HEADER_FOOTER )
779         throwIllegallArgumentException("css::report::ReportPrintOption"
780                         ,*this
781                         ,1);
782     set(PROPERTY_PAGEHEADEROPTION,_pageheaderoption,m_pImpl->m_nPageHeaderOption);
783 }
784 
getPageFooterOption()785 ::sal_Int16 SAL_CALL OReportDefinition::getPageFooterOption()
786 {
787     ::osl::MutexGuard aGuard(m_aMutex);
788     return m_pImpl->m_nPageFooterOption;
789 }
790 
setPageFooterOption(::sal_Int16 _pagefooteroption)791 void SAL_CALL OReportDefinition::setPageFooterOption( ::sal_Int16 _pagefooteroption )
792 {
793     if ( _pagefooteroption < report::ReportPrintOption::ALL_PAGES || _pagefooteroption > report::ReportPrintOption::NOT_WITH_REPORT_HEADER_FOOTER )
794         throwIllegallArgumentException("css::report::ReportPrintOption"
795                         ,*this
796                         ,1);
797     set(PROPERTY_PAGEFOOTEROPTION,_pagefooteroption,m_pImpl->m_nPageFooterOption);
798 }
799 
getCommand()800 OUString SAL_CALL OReportDefinition::getCommand()
801 {
802     ::osl::MutexGuard aGuard(m_aMutex);
803     return m_pImpl->m_sCommand;
804 }
805 
setCommand(const OUString & _command)806 void SAL_CALL OReportDefinition::setCommand( const OUString& _command )
807 {
808     set(PROPERTY_COMMAND,_command,m_pImpl->m_sCommand);
809 }
810 
getCommandType()811 ::sal_Int32 SAL_CALL OReportDefinition::getCommandType()
812 {
813     ::osl::MutexGuard aGuard(m_aMutex);
814     return m_pImpl->m_nCommandType;
815 }
816 
setCommandType(::sal_Int32 _commandtype)817 void SAL_CALL OReportDefinition::setCommandType( ::sal_Int32 _commandtype )
818 {
819     if ( _commandtype < sdb::CommandType::TABLE || _commandtype > sdb::CommandType::COMMAND )
820         throwIllegallArgumentException("css::sdb::CommandType"
821                         ,*this
822                         ,1);
823     set(PROPERTY_COMMANDTYPE,_commandtype,m_pImpl->m_nCommandType);
824 }
825 
getFilter()826 OUString SAL_CALL OReportDefinition::getFilter()
827 {
828     ::osl::MutexGuard aGuard(m_aMutex);
829     return m_pImpl->m_sFilter;
830 }
831 
setFilter(const OUString & _filter)832 void SAL_CALL OReportDefinition::setFilter( const OUString& _filter )
833 {
834     set(PROPERTY_FILTER,_filter,m_pImpl->m_sFilter);
835 }
836 
getEscapeProcessing()837 sal_Bool SAL_CALL OReportDefinition::getEscapeProcessing()
838 {
839     ::osl::MutexGuard aGuard(m_aMutex);
840     return m_pImpl->m_bEscapeProcessing;
841 }
842 
setEscapeProcessing(sal_Bool _escapeprocessing)843 void SAL_CALL OReportDefinition::setEscapeProcessing( sal_Bool _escapeprocessing )
844 {
845     set(PROPERTY_ESCAPEPROCESSING,_escapeprocessing,m_pImpl->m_bEscapeProcessing);
846 }
847 
getReportHeaderOn()848 sal_Bool SAL_CALL OReportDefinition::getReportHeaderOn()
849 {
850     ::osl::MutexGuard aGuard(m_aMutex);
851     return m_pImpl->m_xReportHeader.is();
852 }
853 
setReportHeaderOn(sal_Bool _reportheaderon)854 void SAL_CALL OReportDefinition::setReportHeaderOn( sal_Bool _reportheaderon )
855 {
856     if ( bool(_reportheaderon) != m_pImpl->m_xReportHeader.is() )
857     {
858         setSection(PROPERTY_REPORTHEADERON,_reportheaderon,RptResId(RID_STR_REPORT_HEADER),m_pImpl->m_xReportHeader);
859     }
860 }
861 
getReportFooterOn()862 sal_Bool SAL_CALL OReportDefinition::getReportFooterOn()
863 {
864     ::osl::MutexGuard aGuard(m_aMutex);
865     return m_pImpl->m_xReportFooter.is();
866 }
867 
setReportFooterOn(sal_Bool _reportfooteron)868 void SAL_CALL OReportDefinition::setReportFooterOn( sal_Bool _reportfooteron )
869 {
870     if ( bool(_reportfooteron) != m_pImpl->m_xReportFooter.is() )
871     {
872         setSection(PROPERTY_REPORTFOOTERON,_reportfooteron,RptResId(RID_STR_REPORT_FOOTER),m_pImpl->m_xReportFooter);
873     }
874 }
875 
getPageHeaderOn()876 sal_Bool SAL_CALL OReportDefinition::getPageHeaderOn()
877 {
878     ::osl::MutexGuard aGuard(m_aMutex);
879     return m_pImpl->m_xPageHeader.is();
880 }
881 
setPageHeaderOn(sal_Bool _pageheaderon)882 void SAL_CALL OReportDefinition::setPageHeaderOn( sal_Bool _pageheaderon )
883 {
884     if ( bool(_pageheaderon) != m_pImpl->m_xPageHeader.is() )
885     {
886         setSection(PROPERTY_PAGEHEADERON,_pageheaderon,RptResId(RID_STR_PAGE_HEADER),m_pImpl->m_xPageHeader);
887     }
888 }
889 
getPageFooterOn()890 sal_Bool SAL_CALL OReportDefinition::getPageFooterOn()
891 {
892     ::osl::MutexGuard aGuard(m_aMutex);
893     return m_pImpl->m_xPageFooter.is();
894 }
895 
setPageFooterOn(sal_Bool _pagefooteron)896 void SAL_CALL OReportDefinition::setPageFooterOn( sal_Bool _pagefooteron )
897 {
898     if ( bool(_pagefooteron) != m_pImpl->m_xPageFooter.is() )
899     {
900         setSection(PROPERTY_PAGEFOOTERON,_pagefooteron,RptResId(RID_STR_PAGE_FOOTER),m_pImpl->m_xPageFooter);
901     }
902 }
903 
getGroups()904 uno::Reference< report::XGroups > SAL_CALL OReportDefinition::getGroups()
905 {
906     ::osl::MutexGuard aGuard(m_aMutex);
907     return m_pImpl->m_xGroups;
908 }
909 
getReportHeader()910 uno::Reference< report::XSection > SAL_CALL OReportDefinition::getReportHeader()
911 {
912     ::osl::MutexGuard aGuard(m_aMutex);
913     if ( !m_pImpl->m_xReportHeader.is() )
914         throw container::NoSuchElementException();
915     return m_pImpl->m_xReportHeader;
916 }
917 
getPageHeader()918 uno::Reference< report::XSection > SAL_CALL OReportDefinition::getPageHeader()
919 {
920     ::osl::MutexGuard aGuard(m_aMutex);
921     if ( !m_pImpl->m_xPageHeader.is() )
922         throw container::NoSuchElementException();
923     return m_pImpl->m_xPageHeader;
924 }
925 
getDetail()926 uno::Reference< report::XSection > SAL_CALL OReportDefinition::getDetail()
927 {
928     ::osl::MutexGuard aGuard(m_aMutex);
929     return m_pImpl->m_xDetail;
930 }
931 
getPageFooter()932 uno::Reference< report::XSection > SAL_CALL OReportDefinition::getPageFooter()
933 {
934     ::osl::MutexGuard aGuard(m_aMutex);
935     if ( !m_pImpl->m_xPageFooter.is() )
936         throw container::NoSuchElementException();
937     return m_pImpl->m_xPageFooter;
938 }
939 
getReportFooter()940 uno::Reference< report::XSection > SAL_CALL OReportDefinition::getReportFooter()
941 {
942     ::osl::MutexGuard aGuard(m_aMutex);
943     if ( !m_pImpl->m_xReportFooter.is() )
944         throw container::NoSuchElementException();
945     return m_pImpl->m_xReportFooter;
946 }
947 
getEventBroadcaster()948 uno::Reference< document::XEventBroadcaster > SAL_CALL OReportDefinition::getEventBroadcaster(  )
949 {
950     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
951     return this;
952 }
953 
954 // XReportComponent
955 REPORTCOMPONENT_MASTERDETAIL(OReportDefinition,*m_aProps)
956 REPORTCOMPONENT_IMPL(OReportDefinition,*m_aProps)
957 REPORTCOMPONENT_IMPL2(OReportDefinition,*m_aProps)
958 
getPropertySetInfo()959 uno::Reference< beans::XPropertySetInfo > SAL_CALL OReportDefinition::getPropertySetInfo(  )
960 {
961     return ReportDefinitionPropertySet::getPropertySetInfo();
962 }
963 
setPropertyValue(const OUString & aPropertyName,const uno::Any & aValue)964 void SAL_CALL OReportDefinition::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
965 {
966     ReportDefinitionPropertySet::setPropertyValue( aPropertyName, aValue );
967 }
968 
getPropertyValue(const OUString & PropertyName)969 uno::Any SAL_CALL OReportDefinition::getPropertyValue( const OUString& PropertyName )
970 {
971     return ReportDefinitionPropertySet::getPropertyValue( PropertyName);
972 }
973 
addPropertyChangeListener(const OUString & aPropertyName,const uno::Reference<beans::XPropertyChangeListener> & xListener)974 void SAL_CALL OReportDefinition::addPropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener )
975 {
976     ReportDefinitionPropertySet::addPropertyChangeListener( aPropertyName, xListener );
977 }
978 
removePropertyChangeListener(const OUString & aPropertyName,const uno::Reference<beans::XPropertyChangeListener> & aListener)979 void SAL_CALL OReportDefinition::removePropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener )
980 {
981     ReportDefinitionPropertySet::removePropertyChangeListener( aPropertyName, aListener );
982 }
983 
addVetoableChangeListener(const OUString & PropertyName,const uno::Reference<beans::XVetoableChangeListener> & aListener)984 void SAL_CALL OReportDefinition::addVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
985 {
986     ReportDefinitionPropertySet::addVetoableChangeListener( PropertyName, aListener );
987 }
988 
removeVetoableChangeListener(const OUString & PropertyName,const uno::Reference<beans::XVetoableChangeListener> & aListener)989 void SAL_CALL OReportDefinition::removeVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
990 {
991     ReportDefinitionPropertySet::removeVetoableChangeListener( PropertyName, aListener );
992 }
993 
994 // XChild
getParent()995 uno::Reference< uno::XInterface > SAL_CALL OReportDefinition::getParent(  )
996 {
997     ::osl::MutexGuard aGuard(m_aMutex);
998     uno::Reference< container::XChild > xChild;
999     comphelper::query_aggregation(m_aProps->m_xProxy,xChild);
1000     if ( xChild.is() )
1001         return xChild->getParent();
1002     return m_pImpl->m_xParent;
1003 }
1004 
setParent(const uno::Reference<uno::XInterface> & Parent)1005 void SAL_CALL OReportDefinition::setParent( const uno::Reference< uno::XInterface >& Parent )
1006 {
1007     ::osl::MutexGuard aGuard(m_aMutex);
1008     m_aProps->m_xParent = uno::Reference< container::XChild >(Parent,uno::UNO_QUERY);
1009     m_pImpl->m_xParent = Parent;
1010     uno::Reference< container::XChild > xChild;
1011     comphelper::query_aggregation(m_aProps->m_xProxy,xChild);
1012     if ( xChild.is() )
1013         xChild->setParent(Parent);
1014 }
1015 
1016 // XCloneable
createClone()1017 uno::Reference< util::XCloneable > SAL_CALL OReportDefinition::createClone(  )
1018 {
1019     OSL_FAIL("Not yet implemented correctly");
1020     uno::Reference< report::XReportComponent> xSource = this;
1021     uno::Reference< report::XReportDefinition> xSet(cloneObject(xSource,m_aProps->m_xFactory,SERVICE_REPORTDEFINITION),uno::UNO_QUERY_THROW);
1022     return xSet.get();
1023 }
1024 
setSection(const OUString & _sProperty,bool _bOn,const OUString & _sName,uno::Reference<report::XSection> & _member)1025 void OReportDefinition::setSection(  const OUString& _sProperty
1026                             ,bool _bOn
1027                             ,const OUString& _sName
1028                             ,uno::Reference< report::XSection>& _member)
1029 {
1030     BoundListeners l;
1031     {
1032         ::osl::MutexGuard aGuard(m_aMutex);
1033         prepareSet(_sProperty, uno::makeAny(_member), uno::makeAny(_bOn), &l);
1034 
1035         // create section if needed
1036         if ( _bOn && !_member.is() )
1037             _member = OSection::createOSection(this, getContext(), _sProperty == PROPERTY_PAGEHEADERON || _sProperty == PROPERTY_PAGEFOOTERON);
1038         else if ( !_bOn )
1039             ::comphelper::disposeComponent(_member);
1040 
1041         if ( _member.is() )
1042             _member->setName(_sName);
1043     }
1044     l.notify();
1045 }
1046 
1047 // XCloseBroadcaster
addCloseListener(const uno::Reference<util::XCloseListener> & _xListener)1048 void SAL_CALL OReportDefinition::addCloseListener( const uno::Reference< util::XCloseListener >& _xListener )
1049 {
1050     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1051     if ( _xListener.is() )
1052         m_pImpl->m_aCloseListener.addInterface(_xListener);
1053 }
1054 
removeCloseListener(const uno::Reference<util::XCloseListener> & _xListener)1055 void SAL_CALL OReportDefinition::removeCloseListener( const uno::Reference< util::XCloseListener >& _xListener )
1056 {
1057     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1058     m_pImpl->m_aCloseListener.removeInterface(_xListener);
1059 }
1060 
1061 // XCloseable
close(sal_Bool bDeliverOwnership)1062 void SAL_CALL OReportDefinition::close(sal_Bool bDeliverOwnership)
1063 {
1064     SolarMutexGuard aSolarGuard;
1065 
1066     ::osl::ResettableMutexGuard aGuard(m_aMutex);
1067     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1068     // notify our container listeners
1069     lang::EventObject aEvt( static_cast< ::cppu::OWeakObject* >( this ) );
1070     aGuard.clear();
1071     m_pImpl->m_aCloseListener.forEach<util::XCloseListener>(
1072         [&aEvt, &bDeliverOwnership] (uno::Reference<util::XCloseListener> const& xListener) {
1073             return xListener->queryClosing(aEvt, bDeliverOwnership);
1074         });
1075     aGuard.reset();
1076 
1077 
1078     ::std::vector< uno::Reference< frame::XController> > aCopy = m_pImpl->m_aControllers;
1079     for (auto& rxController : aCopy)
1080     {
1081         if ( rxController.is() )
1082         {
1083             try
1084             {
1085                 uno::Reference< util::XCloseable> xFrame( rxController->getFrame(), uno::UNO_QUERY );
1086                 if ( xFrame.is() )
1087                     xFrame->close( bDeliverOwnership );
1088             }
1089             catch (const util::CloseVetoException&) { throw; }
1090             catch (const uno::Exception&)
1091             {
1092                 OSL_FAIL( "ODatabaseDocument::impl_closeControllerFrames: caught an unexpected exception!" );
1093             }
1094         }
1095     }
1096 
1097     aGuard.clear();
1098     m_pImpl->m_aCloseListener.notifyEach(&util::XCloseListener::notifyClosing,aEvt);
1099     aGuard.reset();
1100 
1101     dispose();
1102 }
1103 
1104 // XModel
attachResource(const OUString &,const uno::Sequence<beans::PropertyValue> & _aArguments)1105 sal_Bool SAL_CALL OReportDefinition::attachResource( const OUString& /*_rURL*/, const uno::Sequence< beans::PropertyValue >& _aArguments )
1106 {
1107     // LLA: we had a deadlock problem in our context, so we get the SolarMutex earlier.
1108     SolarMutexGuard aSolarGuard;
1109 
1110     ::osl::MutexGuard aGuard(m_aMutex);
1111     ::connectivity::checkDisposed( ReportDefinitionBase::rBHelper.bDisposed );
1112     utl::MediaDescriptor aDescriptor( _aArguments );
1113 
1114     m_pImpl->m_pUndoManager->GetSfxUndoManager().EnableUndo( false );
1115     try
1116     {
1117         fillArgs(aDescriptor);
1118         m_pImpl->m_pReportModel->SetModified(false);
1119     }
1120     catch (...)
1121     {
1122         m_pImpl->m_pUndoManager->GetSfxUndoManager().EnableUndo( true );
1123         throw;
1124     }
1125     m_pImpl->m_pUndoManager->GetSfxUndoManager().EnableUndo( true );
1126     return true;
1127 }
1128 
fillArgs(utl::MediaDescriptor & _aDescriptor)1129 void OReportDefinition::fillArgs(utl::MediaDescriptor& _aDescriptor)
1130 {
1131     uno::Sequence<beans::PropertyValue> aComponentData;
1132     aComponentData = _aDescriptor.getUnpackedValueOrDefault("ComponentData",aComponentData);
1133     if ( aComponentData.hasElements() && (!m_pImpl->m_xActiveConnection.is() || !m_pImpl->m_xNumberFormatsSupplier.is()) )
1134     {
1135         ::comphelper::SequenceAsHashMap aComponentDataMap( aComponentData );
1136         m_pImpl->m_xActiveConnection = aComponentDataMap.getUnpackedValueOrDefault("ActiveConnection",m_pImpl->m_xActiveConnection);
1137         m_pImpl->m_xNumberFormatsSupplier = dbtools::getNumberFormats(m_pImpl->m_xActiveConnection);
1138     }
1139     if ( !m_pImpl->m_xNumberFormatsSupplier.is() )
1140     {
1141         m_pImpl->m_xNumberFormatsSupplier.set( util::NumberFormatsSupplier::createWithDefaultLocale( m_aProps->m_xContext ) );
1142     }
1143     lcl_stripLoadArguments( _aDescriptor, m_pImpl->m_aArgs );
1144     OUString sCaption;
1145     sCaption = _aDescriptor.getUnpackedValueOrDefault("DocumentTitle",sCaption);
1146     setCaption(sCaption);
1147 }
1148 
getURL()1149 OUString SAL_CALL OReportDefinition::getURL(  )
1150 {
1151     return OUString();
1152 }
1153 
getArgs()1154 uno::Sequence< beans::PropertyValue > SAL_CALL OReportDefinition::getArgs(  )
1155 {
1156     ::osl::MutexGuard aGuard(m_aMutex);
1157     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1158     return m_pImpl->m_aArgs;
1159 }
1160 
connectController(const uno::Reference<frame::XController> & _xController)1161 void SAL_CALL OReportDefinition::connectController( const uno::Reference< frame::XController >& _xController )
1162 {
1163     ::osl::MutexGuard aGuard(m_aMutex);
1164     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1165     m_pImpl->m_aControllers.push_back(_xController);
1166     sal_Int32 nCount;
1167     if ( _xController.is() && m_pImpl->m_xViewData.is() && ( nCount = m_pImpl->m_xViewData->getCount()) != 0)
1168     {
1169         _xController->restoreViewData(m_pImpl->m_xViewData->getByIndex(nCount - 1));
1170     }
1171 }
1172 
disconnectController(const uno::Reference<frame::XController> & _xController)1173 void SAL_CALL OReportDefinition::disconnectController( const uno::Reference< frame::XController >& _xController )
1174 {
1175     ::osl::MutexGuard aGuard(m_aMutex);
1176     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1177     ::std::vector< uno::Reference< frame::XController> >::iterator aFind = ::std::find(m_pImpl->m_aControllers.begin(),m_pImpl->m_aControllers.end(),_xController);
1178     if ( aFind != m_pImpl->m_aControllers.end() )
1179         m_pImpl->m_aControllers.erase(aFind);
1180     if ( m_pImpl->m_xCurrentController == _xController )
1181         m_pImpl->m_xCurrentController.clear();
1182 }
1183 
lockControllers()1184 void SAL_CALL OReportDefinition::lockControllers(  )
1185 {
1186     ::osl::MutexGuard aGuard(m_aMutex);
1187     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1188     m_pImpl->m_bControllersLocked = true;
1189 }
1190 
unlockControllers()1191 void SAL_CALL OReportDefinition::unlockControllers(  )
1192 {
1193     ::osl::MutexGuard aGuard(m_aMutex);
1194     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1195     m_pImpl->m_bControllersLocked = false;
1196 }
1197 
hasControllersLocked()1198 sal_Bool SAL_CALL OReportDefinition::hasControllersLocked(  )
1199 {
1200     ::osl::MutexGuard aGuard(m_aMutex);
1201     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1202     return m_pImpl->m_bControllersLocked;
1203 }
1204 
getCurrentController()1205 uno::Reference< frame::XController > SAL_CALL OReportDefinition::getCurrentController(  )
1206 {
1207     ::osl::MutexGuard aGuard(m_aMutex);
1208     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1209     return m_pImpl->m_xCurrentController;
1210 }
1211 
setCurrentController(const uno::Reference<frame::XController> & _xController)1212 void SAL_CALL OReportDefinition::setCurrentController( const uno::Reference< frame::XController >& _xController )
1213 {
1214     ::osl::MutexGuard aGuard(m_aMutex);
1215     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1216     if ( ::std::find(m_pImpl->m_aControllers.begin(),m_pImpl->m_aControllers.end(),_xController) == m_pImpl->m_aControllers.end() )
1217         throw container::NoSuchElementException();
1218     m_pImpl->m_xCurrentController = _xController;
1219 }
1220 
getCurrentSelection()1221 uno::Reference< uno::XInterface > SAL_CALL OReportDefinition::getCurrentSelection(  )
1222 {
1223     return uno::Reference< uno::XInterface >();
1224 }
1225 
impl_loadFromStorage_nolck_throw(const uno::Reference<embed::XStorage> & _xStorageToLoadFrom,const uno::Sequence<beans::PropertyValue> & _aMediaDescriptor)1226 void OReportDefinition::impl_loadFromStorage_nolck_throw( const uno::Reference< embed::XStorage >& _xStorageToLoadFrom,
1227         const uno::Sequence< beans::PropertyValue >& _aMediaDescriptor )
1228 {
1229     m_pImpl->m_xStorage = _xStorageToLoadFrom;
1230 
1231     utl::MediaDescriptor aDescriptor( _aMediaDescriptor );
1232     fillArgs(aDescriptor);
1233     aDescriptor.createItemIfMissing("Storage",uno::makeAny(_xStorageToLoadFrom));
1234 
1235     uno::Sequence< uno::Any > aDelegatorArguments(_aMediaDescriptor.getLength());
1236     uno::Any* pIter = aDelegatorArguments.getArray();
1237     uno::Any* pEnd  = pIter + aDelegatorArguments.getLength();
1238     for(sal_Int32 i = 0;pIter != pEnd;++pIter,++i)
1239     {
1240         *pIter <<= _aMediaDescriptor[i];
1241     }
1242     sal_Int32 nPos = aDelegatorArguments.getLength();
1243     aDelegatorArguments.realloc(nPos+1);
1244     beans::PropertyValue aPropVal;
1245     aPropVal.Name = "Storage";
1246     aPropVal.Value <<= _xStorageToLoadFrom;
1247     aDelegatorArguments[nPos] <<= aPropVal;
1248 
1249     rptui::OXUndoEnvironment& rEnv = m_pImpl->m_pReportModel->GetUndoEnv();
1250     rptui::OXUndoEnvironment::OUndoEnvLock aLock(rEnv);
1251     {
1252         uno::Reference< document::XFilter > xFilter(
1253             m_aProps->m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.comp.report.OReportFilter",aDelegatorArguments,m_aProps->m_xContext),
1254             uno::UNO_QUERY_THROW );
1255 
1256         uno::Reference< document::XImporter> xImporter(xFilter,uno::UNO_QUERY_THROW);
1257         uno::Reference<XComponent> xComponent(static_cast<OWeakObject*>(this),uno::UNO_QUERY);
1258         xImporter->setTargetDocument(xComponent);
1259 
1260         utl::MediaDescriptor aTemp;
1261         aTemp << aDelegatorArguments;
1262         xFilter->filter(aTemp.getAsConstPropertyValueList());
1263 
1264         lcl_setModelReadOnly(m_pImpl->m_xStorage,m_pImpl->m_pReportModel);
1265         m_pImpl->m_pObjectContainer->SwitchPersistence(m_pImpl->m_xStorage);
1266     }
1267 }
1268 
1269 // XStorageBasedDocument
loadFromStorage(const uno::Reference<embed::XStorage> & _xStorageToLoadFrom,const uno::Sequence<beans::PropertyValue> & _aMediaDescriptor)1270 void SAL_CALL OReportDefinition::loadFromStorage( const uno::Reference< embed::XStorage >& _xStorageToLoadFrom
1271                                                  , const uno::Sequence< beans::PropertyValue >& _aMediaDescriptor )
1272 {
1273     ::osl::MutexGuard aGuard(m_aMutex);
1274     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1275 
1276     impl_loadFromStorage_nolck_throw( _xStorageToLoadFrom, _aMediaDescriptor );
1277 }
1278 
storeToStorage(const uno::Reference<embed::XStorage> & _xStorageToSaveTo,const uno::Sequence<beans::PropertyValue> & _aMediaDescriptor)1279 void SAL_CALL OReportDefinition::storeToStorage( const uno::Reference< embed::XStorage >& _xStorageToSaveTo, const uno::Sequence< beans::PropertyValue >& _aMediaDescriptor )
1280 {
1281     if ( !_xStorageToSaveTo.is() )
1282         throw lang::IllegalArgumentException(RptResId(RID_STR_ARGUMENT_IS_NULL),*this,1);
1283 
1284     SolarMutexGuard aSolarGuard;
1285     ::osl::MutexGuard aGuard(m_aMutex);
1286     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1287     // create XStatusIndicator
1288     uno::Reference<task::XStatusIndicator> xStatusIndicator;
1289     uno::Sequence< uno::Any > aDelegatorArguments;
1290     utl::MediaDescriptor aDescriptor( _aMediaDescriptor );
1291     lcl_extractAndStartStatusIndicator( aDescriptor, xStatusIndicator, aDelegatorArguments );
1292 
1293     // properties
1294     uno::Sequence < beans::PropertyValue > aProps;
1295 
1296     // export sub streams for package, else full stream into a file
1297     uno::Reference< beans::XPropertySet> xProp(_xStorageToSaveTo,uno::UNO_QUERY);
1298     if ( xProp.is() )
1299     {
1300         static const char sPropName[] = "MediaType";
1301         OUString sOldMediaType;
1302         xProp->getPropertyValue(sPropName) >>= sOldMediaType;
1303         if ( !xProp->getPropertyValue(sPropName).hasValue() || sOldMediaType.isEmpty() || MIMETYPE_OASIS_OPENDOCUMENT_REPORT_ASCII != sOldMediaType )
1304             xProp->setPropertyValue( sPropName, uno::makeAny<OUString>(MIMETYPE_OASIS_OPENDOCUMENT_REPORT_ASCII) );
1305     }
1306 
1307     /** property map for export info set */
1308     comphelper::PropertyMapEntry const aExportInfoMap[] =
1309     {
1310         { OUString("UsePrettyPrinting") , 0, cppu::UnoType<sal_Bool>::get(),          beans::PropertyAttribute::MAYBEVOID, 0 },
1311         { OUString("StreamName")        , 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0 },
1312         { OUString("StreamRelPath")     , 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0 },
1313         { OUString("BaseURI")           , 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0 },
1314         { OUString(), 0, css::uno::Type(), 0, 0 }
1315     };
1316     uno::Reference< beans::XPropertySet > xInfoSet( comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aExportInfoMap ) ) );
1317 
1318     SvtSaveOptions aSaveOpt;
1319     xInfoSet->setPropertyValue("UsePrettyPrinting", uno::makeAny(aSaveOpt.IsPrettyPrinting()));
1320     if ( aSaveOpt.IsSaveRelFSys() )
1321     {
1322         const OUString sVal( aDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_DOCUMENTBASEURL(),OUString()) );
1323         xInfoSet->setPropertyValue("BaseURI", uno::makeAny(sVal));
1324     }
1325     const OUString sHierarchicalDocumentName( aDescriptor.getUnpackedValueOrDefault("HierarchicalDocumentName",OUString()) );
1326     xInfoSet->setPropertyValue("StreamRelPath", uno::makeAny(sHierarchicalDocumentName));
1327 
1328 
1329     sal_Int32 nArgsLen = aDelegatorArguments.getLength();
1330     aDelegatorArguments.realloc(nArgsLen+1);
1331     aDelegatorArguments[nArgsLen++] <<= xInfoSet;
1332 
1333     uno::Reference< document::XEmbeddedObjectResolver > xObjectResolver;
1334     uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler;
1335     rtl::Reference<SvXMLGraphicHelper> xGraphicHelper = SvXMLGraphicHelper::Create(_xStorageToSaveTo,SvXMLGraphicHelperMode::Write);
1336     xGraphicStorageHandler = xGraphicHelper.get();
1337     xGraphicHelper.clear();
1338     xObjectResolver = SvXMLEmbeddedObjectHelper::Create( _xStorageToSaveTo,*this, SvXMLEmbeddedObjectHelperMode::Write ).get();
1339 
1340     aDelegatorArguments.realloc(nArgsLen+2);
1341     aDelegatorArguments[nArgsLen++] <<= xGraphicStorageHandler;
1342     aDelegatorArguments[nArgsLen++] <<= xObjectResolver;
1343 
1344     uno::Reference<XComponent> xCom(static_cast<OWeakObject*>(this),uno::UNO_QUERY);
1345     // Try to write to settings.xml, meta.xml, and styles.xml; only really care about success of
1346     // write to content.xml (keeping logic of commit 94ccba3eebc83b58e74e18f0e028c6a995ce6aa6)
1347     xInfoSet->setPropertyValue("StreamName", uno::makeAny(OUString("settings.xml")));
1348     WriteThroughComponent(xCom, "settings.xml", "com.sun.star.comp.report.XMLSettingsExporter",
1349                           aDelegatorArguments, aProps, _xStorageToSaveTo);
1350 
1351     xInfoSet->setPropertyValue("StreamName", uno::makeAny(OUString("meta.xml")));
1352     WriteThroughComponent(xCom, "meta.xml", "com.sun.star.comp.report.XMLMetaExporter",
1353                           aDelegatorArguments, aProps, _xStorageToSaveTo);
1354 
1355     xInfoSet->setPropertyValue("StreamName", uno::makeAny(OUString("styles.xml")));
1356     WriteThroughComponent(xCom, "styles.xml", "com.sun.star.comp.report.XMLStylesExporter",
1357                           aDelegatorArguments, aProps, _xStorageToSaveTo);
1358 
1359     xInfoSet->setPropertyValue("StreamName", uno::makeAny(OUString("content.xml")));
1360     bool bOk = WriteThroughComponent(xCom, "content.xml", "com.sun.star.comp.report.ExportFilter",
1361                                      aDelegatorArguments, aProps, _xStorageToSaveTo);
1362 
1363     uno::Any aImage;
1364     uno::Reference< embed::XVisualObject > xCurrentController(getCurrentController(),uno::UNO_QUERY);
1365     if ( xCurrentController.is() )
1366     {
1367         xCurrentController->setVisualAreaSize(m_pImpl->m_nAspect,m_pImpl->m_aVisualAreaSize);
1368         aImage = xCurrentController->getPreferredVisualRepresentation( m_pImpl->m_nAspect ).Data;
1369     }
1370     if ( aImage.hasValue() )
1371     {
1372         uno::Sequence<sal_Int8> aSeq;
1373         aImage >>= aSeq;
1374         uno::Reference<io::XInputStream> xStream = new ::comphelper::SequenceInputStream( aSeq );
1375         m_pImpl->m_pObjectContainer->InsertGraphicStreamDirectly(xStream, "report", "image/png");
1376     }
1377 
1378     if (bOk)
1379     {
1380         bool bPersist = false;
1381         if ( _xStorageToSaveTo == m_pImpl->m_xStorage )
1382             bPersist = m_pImpl->m_pObjectContainer->StoreChildren(true,false);
1383         else
1384             bPersist = m_pImpl->m_pObjectContainer->StoreAsChildren(true,true,_xStorageToSaveTo);
1385 
1386         if( bPersist )
1387             m_pImpl->m_pObjectContainer->SetPersistentEntries(m_pImpl->m_xStorage);
1388         try
1389         {
1390             uno::Reference<embed::XTransactedObject> xTransact(_xStorageToSaveTo,uno::UNO_QUERY);
1391             if ( xTransact.is() )
1392                 xTransact->commit();
1393         }
1394         catch (const uno::Exception&)
1395         {
1396             OSL_FAIL("Exception Caught: Could not commit report storage!");
1397             throw io::IOException();
1398         }
1399 
1400         if ( _xStorageToSaveTo == m_pImpl->m_xStorage )
1401             setModified(false);
1402     }
1403     if ( xStatusIndicator.is() )
1404         xStatusIndicator->end();
1405 }
1406 
switchToStorage(const uno::Reference<embed::XStorage> & xStorage)1407 void SAL_CALL OReportDefinition::switchToStorage(
1408         const uno::Reference< embed::XStorage >& xStorage)
1409 {
1410     if (!xStorage.is())
1411         throw lang::IllegalArgumentException(RptResId(RID_STR_ARGUMENT_IS_NULL),*this,1);
1412     {
1413         ::osl::MutexGuard aGuard(m_aMutex);
1414         ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1415         m_pImpl->m_xStorage = xStorage;
1416         lcl_setModelReadOnly(m_pImpl->m_xStorage,m_pImpl->m_pReportModel);
1417         m_pImpl->m_pObjectContainer->SwitchPersistence(m_pImpl->m_xStorage);
1418     }
1419     // notify our container listeners
1420     m_pImpl->m_aStorageChangeListeners.forEach<document::XStorageChangeListener>(
1421         [this, &xStorage] (uno::Reference<document::XStorageChangeListener> const& xListener) {
1422             return xListener->notifyStorageChange(static_cast<OWeakObject*>(this), xStorage);
1423         });
1424 }
1425 
getDocumentStorage()1426 uno::Reference< embed::XStorage > SAL_CALL OReportDefinition::getDocumentStorage(  )
1427 {
1428     ::osl::MutexGuard aGuard(m_aMutex);
1429     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1430     return m_pImpl->m_xStorage;
1431 }
1432 
addStorageChangeListener(const uno::Reference<document::XStorageChangeListener> & xListener)1433 void SAL_CALL OReportDefinition::addStorageChangeListener( const uno::Reference< document::XStorageChangeListener >& xListener )
1434 {
1435     ::osl::MutexGuard aGuard(m_aMutex);
1436     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1437     if ( xListener.is() )
1438         m_pImpl->m_aStorageChangeListeners.addInterface(xListener);
1439 }
1440 
removeStorageChangeListener(const uno::Reference<document::XStorageChangeListener> & xListener)1441 void SAL_CALL OReportDefinition::removeStorageChangeListener( const uno::Reference< document::XStorageChangeListener >& xListener )
1442 {
1443     ::osl::MutexGuard aGuard(m_aMutex);
1444     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1445     m_pImpl->m_aStorageChangeListeners.removeInterface(xListener);
1446 }
1447 
WriteThroughComponent(const uno::Reference<lang::XComponent> & xComponent,const sal_Char * pStreamName,const sal_Char * pServiceName,const uno::Sequence<uno::Any> & rArguments,const uno::Sequence<beans::PropertyValue> & rMediaDesc,const uno::Reference<embed::XStorage> & _xStorageToSaveTo)1448 bool OReportDefinition::WriteThroughComponent(
1449     const uno::Reference<lang::XComponent> & xComponent,
1450     const sal_Char* pStreamName,
1451     const sal_Char* pServiceName,
1452     const uno::Sequence<uno::Any> & rArguments,
1453     const uno::Sequence<beans::PropertyValue> & rMediaDesc,
1454     const uno::Reference<embed::XStorage>& _xStorageToSaveTo)
1455 {
1456     OSL_ENSURE( nullptr != pStreamName, "Need stream name!" );
1457     OSL_ENSURE( nullptr != pServiceName, "Need service name!" );
1458 
1459     // open stream
1460     OUString sStreamName = OUString::createFromAscii( pStreamName );
1461     uno::Reference<io::XStream> xStream = _xStorageToSaveTo->openStreamElement( sStreamName,embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
1462     if ( !xStream.is() )
1463         return false;
1464     uno::Reference<io::XOutputStream> xOutputStream = xStream->getOutputStream();
1465     OSL_ENSURE(xOutputStream.is(), "Can't create output stream in package!");
1466     if ( ! xOutputStream.is() )
1467         return false;
1468 
1469     uno::Reference<beans::XPropertySet> xStreamProp(xOutputStream,uno::UNO_QUERY);
1470     OSL_ENSURE(xStreamProp.is(),"No valid property set for the output stream!");
1471 
1472     uno::Reference<io::XSeekable> xSeek(xStreamProp,uno::UNO_QUERY);
1473     if ( xSeek.is() )
1474     {
1475         xSeek->seek(0);
1476     }
1477 
1478     xStreamProp->setPropertyValue( "MediaType", uno::Any(OUString("text/xml")) );
1479 
1480     // encrypt all streams
1481     xStreamProp->setPropertyValue( "UseCommonStoragePasswordEncryption",
1482                                        uno::makeAny( true ) );
1483 
1484     // set buffer and create outputstream
1485 
1486     // write the stuff
1487     bool bRet = WriteThroughComponent(
1488         xOutputStream, xComponent,
1489         pServiceName, rArguments, rMediaDesc );
1490     // finally, commit stream.
1491     return bRet;
1492 }
1493 
WriteThroughComponent(const uno::Reference<io::XOutputStream> & xOutputStream,const uno::Reference<lang::XComponent> & xComponent,const sal_Char * pServiceName,const uno::Sequence<uno::Any> & rArguments,const uno::Sequence<beans::PropertyValue> & rMediaDesc)1494 bool OReportDefinition::WriteThroughComponent(
1495     const uno::Reference<io::XOutputStream> & xOutputStream,
1496     const uno::Reference<lang::XComponent> & xComponent,
1497     const sal_Char* pServiceName,
1498     const uno::Sequence<uno::Any> & rArguments,
1499     const uno::Sequence<beans::PropertyValue> & rMediaDesc)
1500 {
1501     OSL_ENSURE( xOutputStream.is(), "I really need an output stream!" );
1502     OSL_ENSURE( xComponent.is(), "Need component!" );
1503     OSL_ENSURE( nullptr != pServiceName, "Need component name!" );
1504 
1505     // get component
1506     uno::Reference< xml::sax::XWriter > xSaxWriter(
1507         xml::sax::Writer::create(m_aProps->m_xContext) );
1508 
1509     // connect XML writer to output stream
1510     xSaxWriter->setOutputStream( xOutputStream );
1511 
1512     // prepare arguments (prepend doc handler to given arguments)
1513     uno::Sequence<uno::Any> aArgs( 1 + rArguments.getLength() );
1514     aArgs[0] <<= xSaxWriter;
1515     std::copy(rArguments.begin(), rArguments.end(), std::next(aArgs.begin()));
1516 
1517     // get filter component
1518     uno::Reference< document::XExporter > xExporter(
1519         m_aProps->m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
1520             OUString::createFromAscii(pServiceName), aArgs,m_aProps->m_xContext), uno::UNO_QUERY);
1521     OSL_ENSURE( xExporter.is(),
1522             "can't instantiate export filter component" );
1523     if( !xExporter.is() )
1524         return false;
1525 
1526     // connect model and filter
1527     xExporter->setSourceDocument( xComponent );
1528 
1529     // filter!
1530     uno::Reference<document::XFilter> xFilter( xExporter, uno::UNO_QUERY );
1531     return xFilter->filter( rMediaDesc );
1532 }
1533 
1534 // XLoadable
initNew()1535 void SAL_CALL OReportDefinition::initNew(  )
1536 {
1537      setPageHeaderOn( true );
1538      setPageFooterOn( true );
1539 }
1540 
load(const uno::Sequence<beans::PropertyValue> & _rArguments)1541 void SAL_CALL OReportDefinition::load( const uno::Sequence< beans::PropertyValue >& _rArguments )
1542 {
1543     ::osl::MutexGuard aGuard(m_aMutex);
1544     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1545 
1546     // TODO: this code is pretty similar to what happens in ODatabaseModelImpl::getOrCreateRootStorage,
1547     //       perhaps we can share code here.
1548 
1549     ::comphelper::NamedValueCollection aArguments( _rArguments );
1550 
1551     // the source for the to-be-created storage: either a URL, or a stream
1552     uno::Reference< io::XInputStream > xStream;
1553     OUString sURL;
1554 
1555     if ( aArguments.has( "Stream" ) )
1556     {
1557         aArguments.get_ensureType( "Stream", xStream );
1558         aArguments.remove( "Stream" );
1559     }
1560     else if ( aArguments.has( "InputStream" ) )
1561     {
1562         aArguments.get_ensureType( "InputStream", xStream );
1563         aArguments.remove( "InputStream" );
1564     }
1565 
1566     if ( aArguments.has( "FileName" ) )
1567     {
1568         aArguments.get_ensureType( "FileName", sURL );
1569         aArguments.remove( "FileName" );
1570     }
1571     else if ( aArguments.has( "URL" ) )
1572     {
1573         aArguments.get_ensureType( "URL", sURL );
1574         aArguments.remove( "URL" );
1575     }
1576 
1577     uno::Any aStorageSource;
1578     if ( xStream.is() )
1579         aStorageSource <<= xStream;
1580     else if ( !sURL.isEmpty() )
1581         aStorageSource <<= sURL;
1582     else
1583         throw lang::IllegalArgumentException(
1584             "No input source (URL or InputStream) found.",
1585                 // TODO: resource
1586             *this,
1587             1
1588         );
1589 
1590     uno::Reference< lang::XSingleServiceFactory > xStorageFactory( embed::StorageFactory::create( m_aProps->m_xContext ) );
1591 
1592     // open read-write per default, unless told otherwise in the MediaDescriptor
1593     uno::Reference< embed::XStorage > xDocumentStorage;
1594     const sal_Int32 nOpenModes[2] = {
1595         embed::ElementModes::READWRITE,
1596         embed::ElementModes::READ
1597     };
1598     size_t nFirstOpenMode = 0;
1599     if ( aArguments.has( "ReadOnly" ) )
1600     {
1601         bool bReadOnly = false;
1602         aArguments.get_ensureType( "ReadOnly", bReadOnly );
1603         nFirstOpenMode = bReadOnly ? 1 : 0;
1604     }
1605     const size_t nLastOpenMode = SAL_N_ELEMENTS( nOpenModes ) - 1;
1606     for ( size_t i=nFirstOpenMode; i <= nLastOpenMode; ++i )
1607     {
1608         uno::Sequence< uno::Any > aStorageCreationArgs(2);
1609         aStorageCreationArgs[0] = aStorageSource;
1610         aStorageCreationArgs[1] <<= nOpenModes[i];
1611 
1612         try
1613         {
1614             xDocumentStorage.set( xStorageFactory->createInstanceWithArguments( aStorageCreationArgs ), uno::UNO_QUERY_THROW );
1615         }
1616         catch (const uno::Exception&)
1617         {
1618             if ( i == nLastOpenMode )
1619             {
1620                 css::uno::Any anyEx = cppu::getCaughtException();
1621                 throw lang::WrappedTargetException(
1622                     "An error occurred while creating the document storage.",
1623                         // TODO: resource
1624                     *this,
1625                     anyEx
1626                 );
1627             }
1628         }
1629     }
1630 
1631     if ( !xDocumentStorage.is() )
1632     {
1633         throw uno::RuntimeException();
1634     }
1635 
1636     if (!aArguments.has("DocumentBaseURL") && !sURL.isEmpty())
1637     {
1638         aArguments.put("DocumentBaseURL", sURL);
1639     }
1640 
1641     impl_loadFromStorage_nolck_throw( xDocumentStorage, aArguments.getPropertyValues() );
1642     // TODO: do we need to take ownership of the storage? In opposite to loadFromStorage, we created the storage
1643     // ourself here, and perhaps this means we're also responsible for it ...?
1644 }
1645 
1646 // XVisualObject
setVisualAreaSize(::sal_Int64 _nAspect,const awt::Size & _aSize)1647 void SAL_CALL OReportDefinition::setVisualAreaSize( ::sal_Int64 _nAspect, const awt::Size& _aSize )
1648 {
1649     ::osl::MutexGuard aGuard(m_aMutex);
1650     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1651     bool bChanged =
1652             (m_pImpl->m_aVisualAreaSize.Width != _aSize.Width ||
1653              m_pImpl->m_aVisualAreaSize.Height != _aSize.Height);
1654     m_pImpl->m_aVisualAreaSize = _aSize;
1655     if( bChanged )
1656             setModified( true );
1657     m_pImpl->m_nAspect = _nAspect;
1658 }
1659 
getVisualAreaSize(::sal_Int64)1660 awt::Size SAL_CALL OReportDefinition::getVisualAreaSize( ::sal_Int64 /*_nAspect*/ )
1661 {
1662     ::osl::MutexGuard aGuard(m_aMutex);
1663     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1664     return m_pImpl->m_aVisualAreaSize;
1665 }
1666 
getPreferredVisualRepresentation(::sal_Int64)1667 embed::VisualRepresentation SAL_CALL OReportDefinition::getPreferredVisualRepresentation( ::sal_Int64 /*_nAspect*/ )
1668 {
1669     ::osl::MutexGuard aGuard(m_aMutex);
1670     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1671     embed::VisualRepresentation aResult;
1672     OUString sMimeType;
1673     uno::Reference<io::XInputStream> xStream = m_pImpl->m_pObjectContainer->GetGraphicStream("report", &sMimeType);
1674     if ( xStream.is() )
1675     {
1676         uno::Sequence<sal_Int8> aSeq;
1677         xStream->readBytes(aSeq,xStream->available());
1678         xStream->closeInput();
1679         aResult.Data <<= aSeq;
1680         aResult.Flavor.MimeType = sMimeType;
1681         aResult.Flavor.DataType = cppu::UnoType<decltype(aSeq)>::get();
1682     }
1683 
1684     return aResult;
1685 }
1686 
getMapUnit(::sal_Int64)1687 ::sal_Int32 SAL_CALL OReportDefinition::getMapUnit( ::sal_Int64 /*nAspect*/ )
1688 {
1689     return embed::EmbedMapUnits::ONE_100TH_MM;
1690 }
1691 
1692 // XModifiable
disableSetModified()1693 sal_Bool SAL_CALL OReportDefinition::disableSetModified(  )
1694 {
1695     ::osl::MutexGuard aGuard( m_aMutex );
1696     ::connectivity::checkDisposed( ReportDefinitionBase::rBHelper.bDisposed );
1697 
1698     const bool bWasEnabled = m_pImpl->m_bSetModifiedEnabled;
1699     m_pImpl->m_bSetModifiedEnabled = false;
1700     return bWasEnabled;
1701 }
1702 
enableSetModified()1703 sal_Bool SAL_CALL OReportDefinition::enableSetModified(  )
1704 {
1705     ::osl::MutexGuard aGuard( m_aMutex );
1706     ::connectivity::checkDisposed( ReportDefinitionBase::rBHelper.bDisposed );
1707 
1708     const bool bWasEnabled = m_pImpl->m_bSetModifiedEnabled;
1709     m_pImpl->m_bSetModifiedEnabled = true;
1710     return bWasEnabled;
1711 }
1712 
isSetModifiedEnabled()1713 sal_Bool SAL_CALL OReportDefinition::isSetModifiedEnabled(  )
1714 {
1715     ::osl::MutexGuard aGuard( m_aMutex );
1716     ::connectivity::checkDisposed( ReportDefinitionBase::rBHelper.bDisposed );
1717 
1718     return m_pImpl->m_bSetModifiedEnabled;
1719 }
1720 
1721 // XModifiable
isModified()1722 sal_Bool SAL_CALL OReportDefinition::isModified(  )
1723 {
1724     ::osl::MutexGuard aGuard(m_aMutex);
1725     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1726     return m_pImpl->m_bModified;
1727 }
1728 
setModified(sal_Bool _bModified)1729 void SAL_CALL OReportDefinition::setModified( sal_Bool _bModified )
1730 {
1731     osl::ClearableMutexGuard aGuard(m_aMutex);
1732     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1733 
1734     if ( !m_pImpl->m_bSetModifiedEnabled )
1735         return;
1736 
1737     if ( m_pImpl->m_pReportModel->IsReadOnly() && _bModified )
1738         throw beans::PropertyVetoException();
1739     if ( m_pImpl->m_bModified != bool(_bModified) )
1740     {
1741         m_pImpl->m_bModified = _bModified;
1742         if ( m_pImpl->m_pReportModel->IsChanged() != bool(_bModified) )
1743             m_pImpl->m_pReportModel->SetChanged(_bModified);
1744 
1745         lang::EventObject aEvent(*this);
1746         aGuard.clear();
1747         m_pImpl->m_aModifyListeners.notifyEach(&util::XModifyListener::modified,aEvent);
1748         notifyEvent("OnModifyChanged");
1749     }
1750 }
1751 
1752 // XModifyBroadcaster
addModifyListener(const uno::Reference<util::XModifyListener> & _xListener)1753 void SAL_CALL OReportDefinition::addModifyListener( const uno::Reference< util::XModifyListener >& _xListener )
1754 {
1755     ::osl::MutexGuard aGuard(m_aMutex);
1756     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1757     if ( _xListener.is() )
1758         m_pImpl->m_aModifyListeners.addInterface(_xListener);
1759 }
1760 
removeModifyListener(const uno::Reference<util::XModifyListener> & _xListener)1761 void SAL_CALL OReportDefinition::removeModifyListener( const uno::Reference< util::XModifyListener >& _xListener )
1762 {
1763     ::osl::MutexGuard aGuard(m_aMutex);
1764     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1765     m_pImpl->m_aModifyListeners.removeInterface(_xListener);
1766 }
1767 
notifyEvent(const OUString & _sEventName)1768 void OReportDefinition::notifyEvent(const OUString& _sEventName)
1769 {
1770     try
1771     {
1772         osl::ClearableMutexGuard aGuard(m_aMutex);
1773         ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1774         document::EventObject aEvt(*this, _sEventName);
1775         aGuard.clear();
1776         m_pImpl->m_aLegacyEventListeners.notifyEach(&document::XEventListener::notifyEvent,aEvt);
1777     }
1778     catch (const uno::Exception&)
1779     {
1780     }
1781 
1782     notifyDocumentEvent(_sEventName, nullptr, css::uno::Any());
1783 }
1784 
1785 // document::XDocumentEventBroadcaster
notifyDocumentEvent(const OUString & rEventName,const uno::Reference<frame::XController2> & rViewController,const uno::Any & rSupplement)1786 void SAL_CALL OReportDefinition::notifyDocumentEvent( const OUString& rEventName, const uno::Reference< frame::XController2 >& rViewController, const uno::Any& rSupplement )
1787 {
1788     try
1789     {
1790         osl::ClearableMutexGuard aGuard(m_aMutex);
1791         ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1792         document::DocumentEvent aEvt(*this, rEventName, rViewController, rSupplement);
1793         aGuard.clear();
1794         m_pImpl->m_aDocEventListeners.notifyEach(&document::XDocumentEventListener::documentEventOccured,aEvt);
1795     }
1796     catch (const uno::Exception&)
1797     {
1798     }
1799 }
1800 
addDocumentEventListener(const uno::Reference<document::XDocumentEventListener> & rListener)1801 void SAL_CALL OReportDefinition::addDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& rListener )
1802 {
1803     ::osl::MutexGuard aGuard(m_aMutex);
1804     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1805     if ( rListener.is() )
1806         m_pImpl->m_aDocEventListeners.addInterface(rListener);
1807 }
1808 
removeDocumentEventListener(const uno::Reference<document::XDocumentEventListener> & rListener)1809 void SAL_CALL OReportDefinition::removeDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& rListener )
1810 {
1811     ::osl::MutexGuard aGuard(m_aMutex);
1812     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1813     m_pImpl->m_aDocEventListeners.removeInterface(rListener);
1814 }
1815 
1816 // document::XEventBroadcaster
addEventListener(const uno::Reference<document::XEventListener> & _xListener)1817 void SAL_CALL OReportDefinition::addEventListener(const uno::Reference< document::XEventListener >& _xListener )
1818 {
1819     ::osl::MutexGuard aGuard(m_aMutex);
1820     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1821     if ( _xListener.is() )
1822         m_pImpl->m_aLegacyEventListeners.addInterface(_xListener);
1823 }
1824 
removeEventListener(const uno::Reference<document::XEventListener> & _xListener)1825 void SAL_CALL OReportDefinition::removeEventListener( const uno::Reference< document::XEventListener >& _xListener )
1826 {
1827     ::osl::MutexGuard aGuard(m_aMutex);
1828     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1829     m_pImpl->m_aLegacyEventListeners.removeInterface(_xListener);
1830 }
1831 
1832 // document::XViewDataSupplier
getViewData()1833 uno::Reference< container::XIndexAccess > SAL_CALL OReportDefinition::getViewData(  )
1834 {
1835     ::osl::MutexGuard aGuard(m_aMutex);
1836     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1837     if ( !m_pImpl->m_xViewData.is() )
1838     {
1839         m_pImpl->m_xViewData = document::IndexedPropertyValues::create(m_aProps->m_xContext);
1840         uno::Reference< container::XIndexContainer > xContainer(m_pImpl->m_xViewData,uno::UNO_QUERY);
1841         for (const auto& rxController : m_pImpl->m_aControllers)
1842         {
1843             if ( rxController.is() )
1844             {
1845                 try
1846                 {
1847                     xContainer->insertByIndex(xContainer->getCount(), rxController->getViewData());
1848                 }
1849                 catch (const uno::Exception&)
1850                 {
1851                 }
1852             }
1853         }
1854 
1855     }
1856     return m_pImpl->m_xViewData;
1857 }
1858 
setViewData(const uno::Reference<container::XIndexAccess> & Data)1859 void SAL_CALL OReportDefinition::setViewData( const uno::Reference< container::XIndexAccess >& Data )
1860 {
1861     ::osl::MutexGuard aGuard(m_aMutex);
1862     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1863     m_pImpl->m_xViewData = Data;
1864 }
1865 
getFunctions()1866 uno::Reference< report::XFunctions > SAL_CALL OReportDefinition::getFunctions()
1867 {
1868     ::osl::MutexGuard aGuard(m_aMutex);
1869     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1870     return m_pImpl->m_xFunctions;
1871 }
1872 
getUIConfigurationManager()1873 uno::Reference< ui::XUIConfigurationManager > SAL_CALL OReportDefinition::getUIConfigurationManager(  )
1874 {
1875     return uno::Reference< ui::XUIConfigurationManager >( getUIConfigurationManager2(), uno::UNO_QUERY_THROW );
1876 }
1877 
getUIConfigurationManager2()1878 uno::Reference< ui::XUIConfigurationManager2 > OReportDefinition::getUIConfigurationManager2(  )
1879 {
1880     ::osl::MutexGuard aGuard(m_aMutex);
1881     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1882 
1883     if ( !m_pImpl->m_xUIConfigurationManager.is() )
1884     {
1885         m_pImpl->m_xUIConfigurationManager = ui::UIConfigurationManager::create(m_aProps->m_xContext);
1886 
1887         uno::Reference< embed::XStorage > xConfigStorage;
1888         // initialize ui configuration manager with document substorage
1889         m_pImpl->m_xUIConfigurationManager->setStorage( xConfigStorage );
1890     }
1891 
1892     return m_pImpl->m_xUIConfigurationManager;
1893 }
1894 
getDocumentSubStorage(const OUString & aStorageName,sal_Int32 nMode)1895 uno::Reference< embed::XStorage > SAL_CALL OReportDefinition::getDocumentSubStorage( const OUString& aStorageName, sal_Int32 nMode )
1896 {
1897     ::osl::MutexGuard aGuard(m_aMutex);
1898     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1899     return m_pImpl->m_xStorage->openStorageElement(aStorageName, nMode);
1900 }
1901 
getDocumentSubStoragesNames()1902 uno::Sequence< OUString > SAL_CALL OReportDefinition::getDocumentSubStoragesNames(  )
1903 {
1904     ::osl::MutexGuard aGuard(m_aMutex);
1905     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1906     uno::Reference<container::XNameAccess> xNameAccess = m_pImpl->m_xStorage;
1907     return xNameAccess.is() ? xNameAccess->getElementNames() : uno::Sequence< OUString >();
1908 }
1909 
getMimeType()1910 OUString SAL_CALL OReportDefinition::getMimeType()
1911 {
1912     ::osl::MutexGuard aGuard(m_aMutex);
1913     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1914     return m_pImpl->m_sMimeType;
1915 }
1916 
setMimeType(const OUString & _mimetype)1917 void SAL_CALL OReportDefinition::setMimeType( const OUString& _mimetype )
1918 {
1919     ::osl::MutexGuard aGuard(m_aMutex);
1920     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1921     uno::Sequence< OUString > aList = getAvailableMimeTypes();
1922     if ( ::std::find(aList.begin(), aList.end(), _mimetype) == aList.end() )
1923         throwIllegallArgumentException("getAvailableMimeTypes()"
1924                         ,*this
1925                         ,1);
1926     set(PROPERTY_MIMETYPE,_mimetype,m_pImpl->m_sMimeType);
1927 }
1928 
getAvailableMimeTypes()1929 uno::Sequence< OUString > SAL_CALL OReportDefinition::getAvailableMimeTypes(  )
1930 {
1931     uno::Sequence< OUString > s_aList(2);
1932     s_aList[0] = MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII;
1933     s_aList[1] = MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII;
1934     return s_aList;
1935 }
1936 
1937 // css::XUnoTunnel
getSomething(const uno::Sequence<sal_Int8> & rId)1938 sal_Int64 SAL_CALL OReportDefinition::getSomething( const uno::Sequence< sal_Int8 >& rId )
1939 {
1940     sal_Int64 nRet = 0;
1941     if (isUnoTunnelId<OReportDefinition>(rId) )
1942         nRet = reinterpret_cast<sal_Int64>(this);
1943     else
1944     {
1945         uno::Reference< lang::XUnoTunnel> xUnoTunnel(m_pImpl->m_xNumberFormatsSupplier,uno::UNO_QUERY);
1946         if ( xUnoTunnel.is() )
1947             nRet = xUnoTunnel->getSomething(rId);
1948     }
1949     if ( !nRet )
1950     {
1951         uno::Reference< lang::XUnoTunnel> xTunnel;
1952         ::comphelper::query_aggregation(m_aProps->m_xProxy,xTunnel);
1953         if ( xTunnel.is() )
1954             nRet = xTunnel->getSomething(rId);
1955     }
1956 
1957     return nRet;
1958 }
1959 
getImplementationId()1960 uno::Sequence< sal_Int8 > SAL_CALL OReportDefinition::getImplementationId(  )
1961 {
1962     return css::uno::Sequence<sal_Int8>();
1963 }
1964 
getUnoTunnelId()1965 uno::Sequence< sal_Int8 > OReportDefinition::getUnoTunnelId()
1966 {
1967     static ::cppu::OImplementationId implId;
1968 
1969     return implId.getImplementationId();
1970 }
1971 
getContext()1972 uno::Reference< uno::XComponentContext > OReportDefinition::getContext()
1973 {
1974     ::osl::MutexGuard aGuard(m_aMutex);
1975     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1976     return m_aProps->m_xContext;
1977 }
1978 
getSdrModel(const uno::Reference<report::XReportDefinition> & _xReportDefinition)1979 std::shared_ptr<rptui::OReportModel> OReportDefinition::getSdrModel(const uno::Reference< report::XReportDefinition >& _xReportDefinition)
1980 {
1981     std::shared_ptr<rptui::OReportModel> pReportModel;
1982     auto pReportDefinition = comphelper::getUnoTunnelImplementation<OReportDefinition>(_xReportDefinition);
1983     if (pReportDefinition)
1984         pReportModel = pReportDefinition->m_pImpl->m_pReportModel;
1985     return pReportModel;
1986 }
1987 
getSdrModelFromUnoModel() const1988 SdrModel& OReportDefinition::getSdrModelFromUnoModel() const
1989 {
1990     OSL_ENSURE(m_pImpl->m_pReportModel.get(), "No SdrModel in ReportDesign, should not happen");
1991     return *m_pImpl->m_pReportModel;
1992 }
1993 
createInstanceWithArguments(const OUString & aServiceSpecifier,const uno::Sequence<uno::Any> & _aArgs)1994 uno::Reference< uno::XInterface > SAL_CALL OReportDefinition::createInstanceWithArguments( const OUString& aServiceSpecifier, const uno::Sequence< uno::Any >& _aArgs)
1995 {
1996     ::osl::MutexGuard aGuard(m_aMutex);
1997     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
1998 
1999     uno::Reference< uno::XInterface > xRet;
2000     if ( aServiceSpecifier.startsWith( "com.sun.star.document.ImportEmbeddedObjectResolver") )
2001     {
2002         uno::Reference< embed::XStorage > xStorage;
2003         for(const uno::Any& rArg : _aArgs)
2004         {
2005             beans::NamedValue aValue;
2006             rArg >>= aValue;
2007             if ( aValue.Name == "Storage" )
2008                 aValue.Value >>= xStorage;
2009         }
2010         m_pImpl->m_pObjectContainer->SwitchPersistence(xStorage);
2011         xRet = static_cast< ::cppu::OWeakObject* >(SvXMLEmbeddedObjectHelper::Create( xStorage,*this, SvXMLEmbeddedObjectHelperMode::Read ).get());
2012     }
2013     return xRet;
2014 }
2015 
createInstance(const OUString & aServiceSpecifier)2016 uno::Reference< uno::XInterface > SAL_CALL OReportDefinition::createInstance( const OUString& aServiceSpecifier )
2017 {
2018     ::osl::MutexGuard aGuard(m_aMutex);
2019     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2020     uno::Reference< drawing::XShape > xShape;
2021     if ( aServiceSpecifier.startsWith( "com.sun.star.report." ) )
2022     {
2023         if ( aServiceSpecifier == SERVICE_SHAPE )
2024             xShape.set(SvxUnoDrawMSFactory::createInstance("com.sun.star.drawing.CustomShape"),uno::UNO_QUERY_THROW);
2025         else if (   aServiceSpecifier == SERVICE_FORMATTEDFIELD
2026             ||      aServiceSpecifier == SERVICE_FIXEDTEXT
2027             ||      aServiceSpecifier == SERVICE_FIXEDLINE
2028             ||      aServiceSpecifier == SERVICE_IMAGECONTROL )
2029             xShape.set(SvxUnoDrawMSFactory::createInstance("com.sun.star.drawing.ControlShape"),uno::UNO_QUERY_THROW);
2030         else
2031             xShape.set(SvxUnoDrawMSFactory::createInstance("com.sun.star.drawing.OLE2Shape"),uno::UNO_QUERY_THROW);
2032     }
2033     else if ( aServiceSpecifier.startsWith( "com.sun.star.form.component." ) )
2034     {
2035         xShape.set(m_aProps->m_xContext->getServiceManager()->createInstanceWithContext(aServiceSpecifier,m_aProps->m_xContext),uno::UNO_QUERY);
2036     }
2037     else if ( aServiceSpecifier == "com.sun.star.style.PageStyle" ||
2038               aServiceSpecifier == "com.sun.star.style.FrameStyle" ||
2039               aServiceSpecifier == "com.sun.star.style.GraphicStyle"
2040               )
2041     {
2042         uno::Reference< style::XStyle> xStyle = new OStyle();
2043         xStyle->setName("Default");
2044         return xStyle.get();
2045     }
2046     else if ( aServiceSpecifier == "com.sun.star.document.Settings" )
2047     {
2048         uno::Reference<beans::XPropertySet> xProp = new OStyle();
2049 
2050         return xProp.get();
2051     }
2052     else if ( aServiceSpecifier == "com.sun.star.drawing.Defaults" )
2053     {
2054         uno::Reference<beans::XPropertySet> xProp = new OStyle();
2055         return xProp.get();
2056     }
2057     else if ( aServiceSpecifier == "com.sun.star.drawing.GradientTable" )
2058     {
2059         if ( !m_pImpl->m_xGradientTable.is() )
2060             m_pImpl->m_xGradientTable.set(SvxUnoGradientTable_createInstance(m_pImpl->m_pReportModel.get()),uno::UNO_QUERY);
2061         return m_pImpl->m_xGradientTable;
2062     }
2063     else if ( aServiceSpecifier == "com.sun.star.drawing.HatchTable" )
2064     {
2065         if ( !m_pImpl->m_xHatchTable.is() )
2066             m_pImpl->m_xHatchTable.set(SvxUnoHatchTable_createInstance(m_pImpl->m_pReportModel.get()),uno::UNO_QUERY);
2067         return m_pImpl->m_xHatchTable;
2068     }
2069     else if ( aServiceSpecifier == "com.sun.star.drawing.BitmapTable"  )
2070     {
2071         if ( !m_pImpl->m_xBitmapTable.is() )
2072             m_pImpl->m_xBitmapTable.set(SvxUnoBitmapTable_createInstance(m_pImpl->m_pReportModel.get()),uno::UNO_QUERY);
2073         return m_pImpl->m_xBitmapTable;
2074     }
2075     else if ( aServiceSpecifier == "com.sun.star.drawing.TransparencyGradientTable" )
2076     {
2077         if ( !m_pImpl->m_xTransparencyGradientTable.is() )
2078             m_pImpl->m_xTransparencyGradientTable.set(SvxUnoTransGradientTable_createInstance(m_pImpl->m_pReportModel.get()),uno::UNO_QUERY);
2079         return m_pImpl->m_xTransparencyGradientTable;
2080     }
2081     else if ( aServiceSpecifier == "com.sun.star.drawing.DashTable" )
2082     {
2083         if ( !m_pImpl->m_xDashTable.is() )
2084             m_pImpl->m_xDashTable.set(SvxUnoDashTable_createInstance(m_pImpl->m_pReportModel.get()),uno::UNO_QUERY);
2085         return m_pImpl->m_xDashTable;
2086     }
2087     else if( aServiceSpecifier == "com.sun.star.drawing.MarkerTable" )
2088     {
2089         if( !m_pImpl->m_xMarkerTable.is() )
2090             m_pImpl->m_xMarkerTable.set(SvxUnoMarkerTable_createInstance( m_pImpl->m_pReportModel.get() ),uno::UNO_QUERY);
2091         return m_pImpl->m_xMarkerTable;
2092     }
2093     else if ( aServiceSpecifier == "com.sun.star.document.ImportEmbeddedObjectResolver" )
2094         return static_cast< ::cppu::OWeakObject* >(SvXMLEmbeddedObjectHelper::Create( m_pImpl->m_xStorage,*this, SvXMLEmbeddedObjectHelperMode::Read ).get());
2095     else if ( aServiceSpecifier == "com.sun.star.document.ExportEmbeddedObjectResolver" )
2096         return static_cast< ::cppu::OWeakObject* >(SvXMLEmbeddedObjectHelper::Create( m_pImpl->m_xStorage,*this, SvXMLEmbeddedObjectHelperMode::Write ).get());
2097     else if (aServiceSpecifier == "com.sun.star.document.ImportGraphicStorageHandler")
2098     {
2099         rtl::Reference<SvXMLGraphicHelper> xGraphicHelper = SvXMLGraphicHelper::Create(m_pImpl->m_xStorage,SvXMLGraphicHelperMode::Write);
2100         uno::Reference< uno::XInterface> xRet(static_cast< ::cppu::OWeakObject* >(xGraphicHelper.get()));
2101         return xRet;
2102     }
2103     else if (aServiceSpecifier == "com.sun.star.document.ExportGraphicStorageHandler")
2104     {
2105         rtl::Reference<SvXMLGraphicHelper> xGraphicHelper = SvXMLGraphicHelper::Create(m_pImpl->m_xStorage,SvXMLGraphicHelperMode::Write);
2106         uno::Reference< uno::XInterface> xRet(static_cast< ::cppu::OWeakObject* >(xGraphicHelper.get()));
2107         return xRet;
2108     }
2109     else if ( aServiceSpecifier == "com.sun.star.chart2.data.DataProvider" )
2110     {
2111         uno::Reference<chart2::data::XDatabaseDataProvider> xDataProvider(chart2::data::DatabaseDataProvider::createWithConnection( m_aProps->m_xContext, m_pImpl->m_xActiveConnection ));
2112         xDataProvider->setRowLimit(10);
2113         uno::Reference< container::XChild > xChild(xDataProvider,uno::UNO_QUERY);
2114         if ( xChild.is() )
2115             xChild->setParent(*this);
2116         return uno::Reference< uno::XInterface >(xDataProvider,uno::UNO_QUERY);
2117     }
2118     else if ( aServiceSpecifier == "com.sun.star.xml.NamespaceMap" )
2119     {
2120         if ( !m_pImpl->m_xXMLNamespaceMap.is() )
2121             m_pImpl->m_xXMLNamespaceMap = comphelper::NameContainer_createInstance( cppu::UnoType<OUString>::get() ).get();
2122         return m_pImpl->m_xXMLNamespaceMap;
2123     }
2124     else
2125         xShape.set(SvxUnoDrawMSFactory::createInstance( aServiceSpecifier ),uno::UNO_QUERY_THROW);
2126 
2127     return m_pImpl->m_pReportModel->createShape(aServiceSpecifier,xShape);
2128 }
2129 
getAvailableServiceNames()2130 uno::Sequence< OUString > SAL_CALL OReportDefinition::getAvailableServiceNames()
2131 {
2132     static const OUStringLiteral aSvxComponentServiceNameList[] =
2133     {
2134         "com.sun.star.form.component.FixedText",
2135         "com.sun.star.form.component.DatabaseImageControl",
2136         "com.sun.star.style.PageStyle",
2137         "com.sun.star.style.GraphicStyle",
2138         "com.sun.star.style.FrameStyle",
2139         "com.sun.star.drawing.Defaults",
2140         "com.sun.star.document.ImportEmbeddedObjectResolver",
2141         "com.sun.star.document.ExportEmbeddedObjectResolver",
2142         "com.sun.star.document.ImportGraphicStorageHandler",
2143         "com.sun.star.document.ExportGraphicStorageHandler",
2144         "com.sun.star.chart2.data.DataProvider",
2145         "com.sun.star.xml.NamespaceMap",
2146         "com.sun.star.document.Settings",
2147         "com.sun.star.drawing.GradientTable",
2148         "com.sun.star.drawing.HatchTable",
2149         "com.sun.star.drawing.BitmapTable",
2150         "com.sun.star.drawing.TransparencyGradientTable",
2151         "com.sun.star.drawing.DashTable",
2152         "com.sun.star.drawing.MarkerTable"
2153     };
2154 
2155     static const sal_uInt16 nSvxComponentServiceNameListCount = SAL_N_ELEMENTS(aSvxComponentServiceNameList);
2156 
2157     uno::Sequence< OUString > aSeq( nSvxComponentServiceNameListCount );
2158     OUString* pStrings = aSeq.getArray();
2159     for( sal_uInt16 nIdx = 0; nIdx < nSvxComponentServiceNameListCount; nIdx++ )
2160         pStrings[nIdx] = aSvxComponentServiceNameList[nIdx];
2161 
2162     uno::Sequence< OUString > aParentSeq( SvxUnoDrawMSFactory::getAvailableServiceNames() );
2163     return comphelper::concatSequences( aParentSeq, aSeq );
2164 }
2165 
2166 // XShape
getPosition()2167 awt::Point SAL_CALL OReportDefinition::getPosition(  )
2168 {
2169     ::osl::MutexGuard aGuard(m_aMutex);
2170     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2171     if ( m_aProps->m_xShape.is() )
2172         return m_aProps->m_xShape->getPosition();
2173     return awt::Point(m_aProps->m_nPosX,m_aProps->m_nPosY);
2174 }
2175 
setPosition(const awt::Point & aPosition)2176 void SAL_CALL OReportDefinition::setPosition( const awt::Point& aPosition )
2177 {
2178     ::osl::MutexGuard aGuard(m_aMutex);
2179     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2180     if ( m_aProps->m_xShape.is() )
2181         m_aProps->m_xShape->setPosition(aPosition);
2182     set(PROPERTY_POSITIONX,aPosition.X,m_aProps->m_nPosX);
2183     set(PROPERTY_POSITIONY,aPosition.Y,m_aProps->m_nPosY);
2184 }
2185 
getSize()2186 awt::Size SAL_CALL OReportDefinition::getSize(  )
2187 {
2188     ::osl::MutexGuard aGuard(m_aMutex);
2189     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2190     if ( m_aProps->m_xShape.is() )
2191         return m_aProps->m_xShape->getSize();
2192     return awt::Size(m_aProps->m_nWidth,m_aProps->m_nHeight);
2193 }
2194 
setSize(const awt::Size & aSize)2195 void SAL_CALL OReportDefinition::setSize( const awt::Size& aSize )
2196 {
2197     ::osl::MutexGuard aGuard(m_aMutex);
2198     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2199     if ( m_aProps->m_xShape.is() )
2200         m_aProps->m_xShape->setSize(aSize);
2201     set(PROPERTY_WIDTH,aSize.Width,m_aProps->m_nWidth);
2202     set(PROPERTY_HEIGHT,aSize.Height,m_aProps->m_nHeight);
2203 }
2204 
2205 
2206 // XShapeDescriptor
getShapeType()2207 OUString SAL_CALL OReportDefinition::getShapeType(  )
2208 {
2209     ::osl::MutexGuard aGuard(m_aMutex);
2210     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2211     if ( m_aProps->m_xShape.is() )
2212         return m_aProps->m_xShape->getShapeType();
2213     return "com.sun.star.drawing.OLE2Shape";
2214 }
2215 
2216 typedef ::cppu::WeakImplHelper< container::XNameContainer,
2217                              container::XIndexAccess
2218                             > TStylesBASE;
2219 class OStylesHelper:
2220     public cppu::BaseMutex, public TStylesBASE
2221 {
2222     typedef ::std::map< OUString, uno::Any  , ::comphelper::UStringMixLess> TStyleElements;
2223     TStyleElements                                  m_aElements;
2224     ::std::vector<TStyleElements::iterator>         m_aElementsPos;
2225     uno::Type const                                 m_aType;
2226 
2227 protected:
~OStylesHelper()2228     virtual ~OStylesHelper() override {}
2229 public:
2230     explicit OStylesHelper(const uno::Type& rType = cppu::UnoType<container::XElementAccess>::get());
2231     OStylesHelper(const OStylesHelper&) = delete;
2232     OStylesHelper& operator=(const OStylesHelper&) = delete;
2233 
2234     // XNameContainer
2235     virtual void SAL_CALL insertByName( const OUString& aName, const uno::Any& aElement ) override;
2236     virtual void SAL_CALL removeByName( const OUString& Name ) override;
2237 
2238     // XNameReplace
2239     virtual void SAL_CALL replaceByName( const OUString& aName, const uno::Any& aElement ) override;
2240 
2241     // container::XElementAccess
2242     virtual uno::Type SAL_CALL getElementType(  ) override;
2243     virtual sal_Bool SAL_CALL hasElements(  ) override;
2244     // container::XIndexAccess
2245     virtual sal_Int32 SAL_CALL getCount(  ) override;
2246     virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
2247 
2248     // container::XNameAccess
2249     virtual uno::Any SAL_CALL getByName( const OUString& aName ) override;
2250     virtual uno::Sequence< OUString > SAL_CALL getElementNames(  ) override;
2251     virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
2252 };
2253 
OStylesHelper(const uno::Type & rType)2254 OStylesHelper::OStylesHelper(const uno::Type& rType)
2255     : cppu::BaseMutex()
2256     , m_aType(rType)
2257 {
2258 }
2259 ;
2260 
2261 // container::XElementAccess
getElementType()2262 uno::Type SAL_CALL OStylesHelper::getElementType(  )
2263 {
2264     return m_aType;
2265 }
2266 
hasElements()2267 sal_Bool SAL_CALL OStylesHelper::hasElements(  )
2268 {
2269     ::osl::MutexGuard aGuard(m_aMutex);
2270     return !m_aElementsPos.empty();
2271 }
2272 
2273 // container::XIndexAccess
getCount()2274 sal_Int32 SAL_CALL OStylesHelper::getCount(  )
2275 {
2276     ::osl::MutexGuard aGuard(m_aMutex);
2277     return m_aElementsPos.size();
2278 }
2279 
getByIndex(sal_Int32 Index)2280 uno::Any SAL_CALL OStylesHelper::getByIndex( sal_Int32 Index )
2281 {
2282     ::osl::MutexGuard aGuard(m_aMutex);
2283     if ( Index < 0 || Index >= static_cast<sal_Int32>(m_aElementsPos.size()) )
2284         throw lang::IndexOutOfBoundsException();
2285     return m_aElementsPos[Index]->second;
2286 }
2287 
2288 // container::XNameAccess
getByName(const OUString & aName)2289 uno::Any SAL_CALL OStylesHelper::getByName( const OUString& aName )
2290 {
2291     ::osl::MutexGuard aGuard(m_aMutex);
2292     TStyleElements::const_iterator aFind = m_aElements.find(aName);
2293     if ( aFind == m_aElements.end() )
2294         throw container::NoSuchElementException();
2295     return aFind->second;
2296 }
2297 
getElementNames()2298 uno::Sequence< OUString > SAL_CALL OStylesHelper::getElementNames(  )
2299 {
2300     ::osl::MutexGuard aGuard(m_aMutex);
2301     uno::Sequence< OUString > aNameList(m_aElementsPos.size());
2302 
2303     OUString* pStringArray = aNameList.getArray();
2304     for(const auto& rIter : m_aElementsPos)
2305     {
2306         *pStringArray = rIter->first;
2307         ++pStringArray;
2308     }
2309 
2310     return aNameList;
2311 }
2312 
hasByName(const OUString & aName)2313 sal_Bool SAL_CALL OStylesHelper::hasByName( const OUString& aName )
2314 {
2315     ::osl::MutexGuard aGuard(m_aMutex);
2316     return m_aElements.find(aName) != m_aElements.end();
2317 }
2318 
2319 // XNameContainer
insertByName(const OUString & aName,const uno::Any & aElement)2320 void SAL_CALL OStylesHelper::insertByName( const OUString& aName, const uno::Any& aElement )
2321 {
2322     ::osl::MutexGuard aGuard(m_aMutex);
2323     if ( m_aElements.find(aName) != m_aElements.end() )
2324         throw container::ElementExistException();
2325 
2326     if ( !aElement.isExtractableTo(m_aType) )
2327         throw lang::IllegalArgumentException();
2328 
2329     m_aElementsPos.push_back(m_aElements.emplace(aName,aElement).first);
2330 }
2331 
removeByName(const OUString & aName)2332 void SAL_CALL OStylesHelper::removeByName( const OUString& aName )
2333 {
2334     ::osl::MutexGuard aGuard(m_aMutex);
2335     TStyleElements::const_iterator aFind = m_aElements.find(aName);
2336     if ( aFind != m_aElements.end() )
2337         throw container::NoSuchElementException();
2338     m_aElementsPos.erase(::std::find(m_aElementsPos.begin(),m_aElementsPos.end(),aFind));
2339     m_aElements.erase(aFind);
2340 }
2341 
2342 // XNameReplace
replaceByName(const OUString & aName,const uno::Any & aElement)2343 void SAL_CALL OStylesHelper::replaceByName( const OUString& aName, const uno::Any& aElement )
2344 {
2345     ::osl::MutexGuard aGuard(m_aMutex);
2346     TStyleElements::iterator aFind = m_aElements.find(aName);
2347     if ( aFind == m_aElements.end() )
2348         throw container::NoSuchElementException();
2349     if ( !aElement.isExtractableTo(m_aType) )
2350         throw lang::IllegalArgumentException();
2351     aFind->second = aElement;
2352 }
2353 
getStyleFamilies()2354 uno::Reference< container::XNameAccess > SAL_CALL OReportDefinition::getStyleFamilies(  )
2355 {
2356     ::osl::MutexGuard aGuard(m_aMutex);
2357     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2358     if ( !m_pImpl->m_xStyles.is() )
2359     {
2360         m_pImpl->m_xStyles = new OStylesHelper();
2361         uno::Reference< container::XNameContainer> xStyles(m_pImpl->m_xStyles,uno::UNO_QUERY);
2362 
2363         uno::Reference< container::XNameContainer> xPageStyles = new OStylesHelper(cppu::UnoType<style::XStyle>::get());
2364         xStyles->insertByName("PageStyles",uno::makeAny(xPageStyles));
2365         uno::Reference< style::XStyle> xPageStyle(createInstance("com.sun.star.style.PageStyle"),uno::UNO_QUERY);
2366         xPageStyles->insertByName(xPageStyle->getName(),uno::makeAny(xPageStyle));
2367 
2368         uno::Reference< container::XNameContainer> xFrameStyles = new OStylesHelper(cppu::UnoType<style::XStyle>::get());
2369         xStyles->insertByName("FrameStyles",uno::makeAny(xFrameStyles));
2370         uno::Reference< style::XStyle> xFrameStyle(createInstance("com.sun.star.style.FrameStyle"),uno::UNO_QUERY);
2371         xFrameStyles->insertByName(xFrameStyle->getName(),uno::makeAny(xFrameStyle));
2372 
2373         uno::Reference< container::XNameContainer> xGraphicStyles = new OStylesHelper(cppu::UnoType<style::XStyle>::get());
2374         xStyles->insertByName("graphics",uno::makeAny(xGraphicStyles));
2375         uno::Reference< style::XStyle> xGraphicStyle(createInstance("com.sun.star.style.GraphicStyle"),uno::UNO_QUERY);
2376         xGraphicStyles->insertByName(xGraphicStyle->getName(),uno::makeAny(xGraphicStyle));
2377     }
2378     return m_pImpl->m_xStyles;
2379 }
getIdentifier()2380 OUString SAL_CALL  OReportDefinition::getIdentifier(  )
2381 {
2382     ::osl::MutexGuard aGuard(m_aMutex);
2383     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2384     return m_pImpl->m_sIdentifier;
2385 }
2386 
setIdentifier(const OUString & Identifier)2387 void SAL_CALL OReportDefinition::setIdentifier( const OUString& Identifier )
2388 {
2389     ::osl::MutexGuard aGuard(m_aMutex);
2390     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2391     m_pImpl->m_sIdentifier = Identifier;
2392 }
2393 
2394 // XNumberFormatsSupplier
getNumberFormatSettings()2395 uno::Reference< beans::XPropertySet > SAL_CALL OReportDefinition::getNumberFormatSettings(  )
2396 {
2397     ::osl::MutexGuard aGuard(m_aMutex);
2398     if ( m_pImpl->m_xNumberFormatsSupplier.is() )
2399         return m_pImpl->m_xNumberFormatsSupplier->getNumberFormatSettings();
2400     return uno::Reference< beans::XPropertySet >();
2401 }
2402 
getNumberFormats()2403 uno::Reference< util::XNumberFormats > SAL_CALL OReportDefinition::getNumberFormats(  )
2404 {
2405     ::osl::MutexGuard aGuard(m_aMutex);
2406     if ( m_pImpl->m_xNumberFormatsSupplier.is() )
2407         return m_pImpl->m_xNumberFormatsSupplier->getNumberFormats();
2408     return uno::Reference< util::XNumberFormats >();
2409 }
2410 
getEmbeddedObjectContainer() const2411 ::comphelper::EmbeddedObjectContainer& OReportDefinition::getEmbeddedObjectContainer() const
2412 {
2413     return *m_pImpl->m_pObjectContainer;
2414 }
2415 
getStorage() const2416 uno::Reference< embed::XStorage > OReportDefinition::getStorage() const
2417 {
2418     return m_pImpl->m_xStorage;
2419 }
2420 
getInteractionHandler() const2421 uno::Reference< task::XInteractionHandler > OReportDefinition::getInteractionHandler() const
2422 {
2423     uno::Reference< task::XInteractionHandler > xRet(
2424         task::InteractionHandler::createWithParent(m_aProps->m_xContext, nullptr), uno::UNO_QUERY_THROW);
2425     return xRet;
2426 }
2427 
getActiveConnection()2428 uno::Reference< sdbc::XConnection > SAL_CALL OReportDefinition::getActiveConnection()
2429 {
2430     ::osl::MutexGuard aGuard(m_aMutex);
2431     return m_pImpl->m_xActiveConnection;
2432 }
2433 
setActiveConnection(const uno::Reference<sdbc::XConnection> & _activeconnection)2434 void SAL_CALL OReportDefinition::setActiveConnection( const uno::Reference< sdbc::XConnection >& _activeconnection )
2435 {
2436     if ( !_activeconnection.is() )
2437         throw lang::IllegalArgumentException();
2438     set(PROPERTY_ACTIVECONNECTION,_activeconnection,m_pImpl->m_xActiveConnection);
2439 }
2440 
getDataSourceName()2441 OUString SAL_CALL OReportDefinition::getDataSourceName()
2442 {
2443     osl::MutexGuard g(m_aMutex);
2444     return m_pImpl->m_sDataSourceName;
2445 }
2446 
setDataSourceName(const OUString & the_value)2447 void SAL_CALL OReportDefinition::setDataSourceName(const OUString& the_value)
2448 {
2449     set(PROPERTY_DATASOURCENAME,the_value,m_pImpl->m_sDataSourceName);
2450 }
2451 
isEnableSetModified() const2452 bool OReportDefinition::isEnableSetModified() const
2453 {
2454     return true;
2455 }
2456 
getDocumentBaseURL() const2457 OUString OReportDefinition::getDocumentBaseURL() const
2458 {
2459     // TODO: should this be in getURL()? not sure...
2460     uno::Reference<frame::XModel> const xParent(
2461         const_cast<OReportDefinition*>(this)->getParent(), uno::UNO_QUERY);
2462     if (xParent.is())
2463     {
2464         return xParent->getURL();
2465     }
2466 
2467     ::osl::MutexGuard aGuard(m_aMutex);
2468     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2469     for (beans::PropertyValue const& it : std::as_const(m_pImpl->m_aArgs))
2470     {
2471         if (it.Name == "DocumentBaseURL")
2472             return it.Value.get<OUString>();
2473     }
2474 
2475     return OUString();
2476 }
2477 
impl_getTitleHelper_throw()2478 uno::Reference< frame::XTitle > OReportDefinition::impl_getTitleHelper_throw()
2479 {
2480     SolarMutexGuard aSolarGuard;
2481 
2482     ::osl::MutexGuard aGuard(m_aMutex);
2483     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2484 
2485     if ( ! m_pImpl->m_xTitleHelper.is ())
2486     {
2487         uno::Reference< frame::XDesktop2 >    xDesktop = frame::Desktop::create(m_aProps->m_xContext);
2488         uno::Reference< frame::XModel >       xThis(static_cast< frame::XModel* >(this), uno::UNO_QUERY_THROW);
2489 
2490         ::framework::TitleHelper* pHelper = new ::framework::TitleHelper( m_aProps->m_xContext );
2491         m_pImpl->m_xTitleHelper.set(static_cast< ::cppu::OWeakObject* >(pHelper), uno::UNO_QUERY_THROW);
2492         pHelper->setOwner                   (xThis   );
2493         pHelper->connectWithUntitledNumbers (uno::Reference<frame::XUntitledNumbers>(xDesktop, uno::UNO_QUERY_THROW));
2494     }
2495 
2496     return m_pImpl->m_xTitleHelper;
2497 }
2498 
impl_getUntitledHelper_throw()2499 uno::Reference< frame::XUntitledNumbers > OReportDefinition::impl_getUntitledHelper_throw()
2500 {
2501     SolarMutexGuard aSolarGuard;
2502 
2503     ::osl::MutexGuard aGuard(m_aMutex);
2504     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2505 
2506     if ( ! m_pImpl->m_xNumberedControllers.is ())
2507     {
2508         uno::Reference< frame::XModel >    xThis(static_cast< frame::XModel* >(this), uno::UNO_QUERY_THROW);
2509         ::comphelper::NumberedCollection*  pHelper = new ::comphelper::NumberedCollection();
2510         m_pImpl->m_xNumberedControllers.set(static_cast< ::cppu::OWeakObject* >(pHelper), uno::UNO_QUERY_THROW);
2511 
2512         pHelper->setOwner          (xThis);
2513         pHelper->setUntitledPrefix (" : ");
2514     }
2515 
2516     return m_pImpl->m_xNumberedControllers;
2517 }
2518 
2519 // css.frame.XTitle
getTitle()2520 OUString SAL_CALL OReportDefinition::getTitle()
2521 {
2522     // SYNCHRONIZED ->
2523     SolarMutexGuard aSolarGuard;
2524 
2525     ::osl::MutexGuard aGuard(m_aMutex);
2526     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2527 
2528     return impl_getTitleHelper_throw()->getTitle ();
2529 }
2530 
2531 // css.frame.XTitle
setTitle(const OUString & sTitle)2532 void SAL_CALL OReportDefinition::setTitle( const OUString& sTitle )
2533 {
2534     // SYNCHRONIZED ->
2535     SolarMutexGuard aSolarGuard;
2536 
2537     ::osl::MutexGuard aGuard(m_aMutex);
2538     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2539 
2540     impl_getTitleHelper_throw()->setTitle (sTitle);
2541 }
2542 
2543 // css.frame.XTitleChangeBroadcaster
addTitleChangeListener(const uno::Reference<frame::XTitleChangeListener> & xListener)2544 void SAL_CALL OReportDefinition::addTitleChangeListener( const uno::Reference< frame::XTitleChangeListener >& xListener )
2545 {
2546     // SYNCHRONIZED ->
2547     SolarMutexGuard aSolarGuard;
2548 
2549     ::osl::MutexGuard aGuard(m_aMutex);
2550     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2551 
2552     uno::Reference< frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper_throw(), uno::UNO_QUERY);
2553     if (xBroadcaster.is ())
2554         xBroadcaster->addTitleChangeListener (xListener);
2555 }
2556 
2557 // css.frame.XTitleChangeBroadcaster
removeTitleChangeListener(const uno::Reference<frame::XTitleChangeListener> & xListener)2558 void SAL_CALL OReportDefinition::removeTitleChangeListener( const uno::Reference< frame::XTitleChangeListener >& xListener )
2559 {
2560     // SYNCHRONIZED ->
2561     SolarMutexGuard aSolarGuard;
2562 
2563     ::osl::MutexGuard aGuard(m_aMutex);
2564     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2565 
2566     uno::Reference< frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper_throw(), uno::UNO_QUERY);
2567     if (xBroadcaster.is ())
2568         xBroadcaster->removeTitleChangeListener (xListener);
2569 }
2570 
2571 // css.frame.XUntitledNumbers
leaseNumber(const uno::Reference<uno::XInterface> & xComponent)2572 ::sal_Int32 SAL_CALL OReportDefinition::leaseNumber( const uno::Reference< uno::XInterface >& xComponent )
2573 {
2574     // object already disposed?
2575     SolarMutexGuard aSolarGuard;
2576     ::osl::MutexGuard aGuard(m_aMutex);
2577     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2578 
2579     return impl_getUntitledHelper_throw()->leaseNumber (xComponent);
2580 }
2581 
2582 // css.frame.XUntitledNumbers
releaseNumber(::sal_Int32 nNumber)2583 void SAL_CALL OReportDefinition::releaseNumber( ::sal_Int32 nNumber )
2584 {
2585     // object already disposed?
2586     SolarMutexGuard aSolarGuard;
2587     ::osl::MutexGuard aGuard(m_aMutex);
2588     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2589 
2590     impl_getUntitledHelper_throw()->releaseNumber (nNumber);
2591 }
2592 
2593 // css.frame.XUntitledNumbers
releaseNumberForComponent(const uno::Reference<uno::XInterface> & xComponent)2594 void SAL_CALL OReportDefinition::releaseNumberForComponent( const uno::Reference< uno::XInterface >& xComponent )
2595 {
2596     // object already disposed?
2597     SolarMutexGuard aSolarGuard;
2598     ::osl::MutexGuard aGuard(m_aMutex);
2599     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2600 
2601     impl_getUntitledHelper_throw()->releaseNumberForComponent (xComponent);
2602 }
2603 
2604 // css.frame.XUntitledNumbers
getUntitledPrefix()2605 OUString SAL_CALL OReportDefinition::getUntitledPrefix()
2606 {
2607     // object already disposed?
2608     SolarMutexGuard aSolarGuard;
2609     ::osl::MutexGuard aGuard(m_aMutex);
2610     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2611 
2612     return impl_getUntitledHelper_throw()->getUntitledPrefix ();
2613 }
2614 
getDocumentProperties()2615 uno::Reference< document::XDocumentProperties > SAL_CALL OReportDefinition::getDocumentProperties(  )
2616 {
2617     ::osl::MutexGuard aGuard(m_aMutex);
2618     ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed);
2619     if ( !m_pImpl->m_xDocumentProperties.is() )
2620     {
2621         m_pImpl->m_xDocumentProperties.set(document::DocumentProperties::create(m_aProps->m_xContext));
2622     }
2623     return m_pImpl->m_xDocumentProperties;
2624 }
2625 
getTransferData(const datatransfer::DataFlavor & aFlavor)2626 uno::Any SAL_CALL OReportDefinition::getTransferData( const datatransfer::DataFlavor& aFlavor )
2627 {
2628     uno::Any aResult;
2629     if( !isDataFlavorSupported( aFlavor ) )
2630     {
2631         throw datatransfer::UnsupportedFlavorException(aFlavor.MimeType, static_cast< ::cppu::OWeakObject* >( this ));
2632     }
2633 
2634     try
2635     {
2636         aResult = getPreferredVisualRepresentation(0).Data;
2637     }
2638     catch (const uno::Exception &)
2639     {
2640         DBG_UNHANDLED_EXCEPTION("reportdesign");
2641     }
2642 
2643 
2644     return aResult;
2645 }
2646 
getTransferDataFlavors()2647 uno::Sequence< datatransfer::DataFlavor > SAL_CALL OReportDefinition::getTransferDataFlavors(  )
2648 {
2649     uno::Sequence< datatransfer::DataFlavor > aRet(1);
2650 
2651     aRet[0] = datatransfer::DataFlavor( "image/png",
2652         "PNG",
2653         cppu::UnoType<uno::Sequence< sal_Int8 >>::get() );
2654 
2655     return aRet;
2656 }
2657 
isDataFlavorSupported(const datatransfer::DataFlavor & aFlavor)2658 sal_Bool SAL_CALL OReportDefinition::isDataFlavorSupported( const datatransfer::DataFlavor& aFlavor )
2659 {
2660     return aFlavor.MimeType == "image/png";
2661 }
2662 
2663 
getUndoManager()2664 uno::Reference< document::XUndoManager > SAL_CALL OReportDefinition::getUndoManager(  )
2665 {
2666     ::osl::MutexGuard aGuard( m_aMutex );
2667     return m_pImpl->m_pUndoManager.get();
2668 }
2669 
2670 }// namespace reportdesign
2671 
2672 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
2673