Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / filter / source / msfilter / msocximex.cxx
blob75ba2678e4c86a9859930770315ca34d64b60367
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/beans/XPropertySet.hpp>
21 #include <com/sun/star/drawing/XDrawPage.hpp>
22 #include <com/sun/star/drawing/XShapes.hpp>
23 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 #include <com/sun/star/container/XIndexContainer.hpp>
25 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
26 #include <com/sun/star/form/XFormsSupplier.hpp>
27 #include <com/sun/star/form/XForm.hpp>
28 #include <osl/diagnose.h>
29 #include <filter/msfilter/msocximex.hxx>
31 using namespace ::com::sun::star;
33 OUString const sWW8_form( "WW-Standard" );
35 SvxMSConvertOCXControls::SvxMSConvertOCXControls( const uno::Reference< frame::XModel >& rxModel) : mxModel(rxModel)
39 SvxMSConvertOCXControls::~SvxMSConvertOCXControls()
43 void SvxMSConvertOCXControls::GetDrawPage()
45 if( !xDrawPage.is() && mxModel.is() )
47 uno::Reference< drawing::XDrawPageSupplier > xTxtDoc(mxModel,
48 uno::UNO_QUERY);
49 OSL_ENSURE(xTxtDoc.is(),"no XDrawPageSupplier from XModel");
50 xDrawPage = xTxtDoc->getDrawPage();
51 OSL_ENSURE( xDrawPage.is(), "no XDrawPage" );
56 const uno::Reference< lang::XMultiServiceFactory >&
57 SvxMSConvertOCXControls::GetServiceFactory()
59 if( !xServiceFactory.is() && mxModel.is() )
61 xServiceFactory = uno::Reference< lang::XMultiServiceFactory >
62 (mxModel, uno::UNO_QUERY);
63 OSL_ENSURE( xServiceFactory.is(),
64 "no XMultiServiceFactory from doc Model" );
67 return xServiceFactory;
70 const uno::Reference< drawing::XShapes >& SvxMSConvertOCXControls::GetShapes()
72 if( !xShapes.is() )
74 GetDrawPage();
75 if( xDrawPage.is() )
77 xShapes = xDrawPage;
80 return xShapes;
83 const uno::Reference< container::XIndexContainer >&
84 SvxMSConvertOCXControls::GetFormComps()
86 if( !xFormComps.is() )
88 GetDrawPage();
89 if( xDrawPage.is() )
91 uno::Reference< form::XFormsSupplier > xFormsSupplier( xDrawPage,
92 uno::UNO_QUERY );
93 OSL_ENSURE( xFormsSupplier.is(),
94 "UNO_QUERY failed for XFormsSupplier from XDrawPage" );
96 uno::Reference< container::XNameContainer > xNameCont =
97 xFormsSupplier->getForms();
99 // The form gets a new name like "WW-Standard[n]" and will
100 // created new in any case.
101 OUString sName( sWW8_form );
102 sal_uInt16 n = 0;
104 while( xNameCont->hasByName( sName ) )
106 sName = sWW8_form + OUString::number( ++n );
109 const uno::Reference< lang::XMultiServiceFactory > &rServiceFactory
110 = GetServiceFactory();
111 if( !rServiceFactory.is() )
112 return xFormComps;
114 uno::Reference< uno::XInterface > xCreate =
115 rServiceFactory->createInstance(
116 "com.sun.star.form.component.Form" );
117 if( xCreate.is() )
119 uno::Reference< beans::XPropertySet > xFormPropSet( xCreate,
120 uno::UNO_QUERY );
122 uno::Any aTmp(&sName,cppu::UnoType<OUString>::get());
123 xFormPropSet->setPropertyValue( "Name", aTmp );
125 uno::Reference< form::XForm > xForm( xCreate, uno::UNO_QUERY );
126 OSL_ENSURE(xForm.is(), "no Form?");
128 uno::Reference< container::XIndexContainer > xForms( xNameCont,
129 uno::UNO_QUERY );
130 OSL_ENSURE( xForms.is(), "XForms not available" );
132 aTmp <<= xForm;
133 xForms->insertByIndex( xForms->getCount(), aTmp );
135 xFormComps = uno::Reference< container::XIndexContainer >
136 (xCreate, uno::UNO_QUERY);
141 return xFormComps;
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */