1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
,
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()
83 const uno::Reference
< container::XIndexContainer
>&
84 SvxMSConvertOCXControls::GetFormComps()
86 if( !xFormComps
.is() )
91 uno::Reference
< form::XFormsSupplier
> xFormsSupplier( xDrawPage
,
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
);
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() )
114 uno::Reference
< uno::XInterface
> xCreate
=
115 rServiceFactory
->createInstance(
116 "com.sun.star.form.component.Form" );
119 uno::Reference
< beans::XPropertySet
> xFormPropSet( xCreate
,
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
,
130 OSL_ENSURE( xForms
.is(), "XForms not available" );
133 xForms
->insertByIndex( xForms
->getCount(), aTmp
);
135 xFormComps
= uno::Reference
< container::XIndexContainer
>
136 (xCreate
, uno::UNO_QUERY
);
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */