Line data Source code
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 <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 <filter/msfilter/msocximex.hxx>
29 :
30 : using namespace ::com::sun::star;
31 :
32 190 : OUString sWW8_form( "WW-Standard" );
33 :
34 1212 : SvxMSConvertOCXControls::SvxMSConvertOCXControls( const uno::Reference< frame::XModel >& rxModel) : mxModel(rxModel)
35 : {
36 1212 : }
37 :
38 1210 : SvxMSConvertOCXControls::~SvxMSConvertOCXControls()
39 : {
40 1210 : }
41 :
42 : const uno::Reference< drawing::XDrawPage >&
43 4 : SvxMSConvertOCXControls::GetDrawPage()
44 : {
45 4 : if( !xDrawPage.is() && mxModel.is() )
46 : {
47 : uno::Reference< drawing::XDrawPageSupplier > xTxtDoc(mxModel,
48 4 : uno::UNO_QUERY);
49 : OSL_ENSURE(xTxtDoc.is(),"no XDrawPageSupplier from XModel");
50 4 : xDrawPage = xTxtDoc->getDrawPage();
51 4 : OSL_ENSURE( xDrawPage.is(), "no XDrawPage" );
52 : }
53 :
54 4 : return xDrawPage;
55 : }
56 :
57 :
58 : const uno::Reference< lang::XMultiServiceFactory >&
59 14 : SvxMSConvertOCXControls::GetServiceFactory()
60 : {
61 14 : if( !xServiceFactory.is() && mxModel.is() )
62 : {
63 8 : xServiceFactory = uno::Reference< lang::XMultiServiceFactory >
64 4 : (mxModel, uno::UNO_QUERY);
65 : OSL_ENSURE( xServiceFactory.is(),
66 : "no XMultiServiceFactory from doc Model" );
67 : }
68 :
69 14 : return xServiceFactory;
70 : }
71 :
72 0 : const uno::Reference< drawing::XShapes >& SvxMSConvertOCXControls::GetShapes()
73 : {
74 0 : if( !xShapes.is() )
75 : {
76 0 : GetDrawPage();
77 0 : if( xDrawPage.is() )
78 : {
79 :
80 0 : xShapes = uno::Reference< drawing::XShapes >(xDrawPage,
81 0 : uno::UNO_QUERY);
82 : OSL_ENSURE( xShapes.is(), "UNO_QUERY failed for XShapes from XDrawPage" );
83 : }
84 : }
85 0 : return xShapes;
86 : }
87 :
88 : const uno::Reference< container::XIndexContainer >&
89 10 : SvxMSConvertOCXControls::GetFormComps()
90 : {
91 10 : if( !xFormComps.is() )
92 : {
93 4 : GetDrawPage();
94 4 : if( xDrawPage.is() )
95 : {
96 : uno::Reference< form::XFormsSupplier > xFormsSupplier( xDrawPage,
97 4 : uno::UNO_QUERY );
98 : OSL_ENSURE( xFormsSupplier.is(),
99 : "UNO_QUERY failed for XFormsSupplier from XDrawPage" );
100 :
101 : uno::Reference< container::XNameContainer > xNameCont =
102 8 : xFormsSupplier->getForms();
103 :
104 : // The form gets a new name like "WW-Standard[n]" and will
105 : // created new in any case.
106 8 : OUString sName( sWW8_form );
107 4 : sal_uInt16 n = 0;
108 :
109 8 : while( xNameCont->hasByName( sName ) )
110 : {
111 0 : sName = sWW8_form;
112 0 : sName += OUString::number( ++n );
113 : }
114 :
115 : const uno::Reference< lang::XMultiServiceFactory > &rServiceFactory
116 4 : = GetServiceFactory();
117 4 : if( !rServiceFactory.is() )
118 0 : return xFormComps;
119 :
120 : uno::Reference< uno::XInterface > xCreate =
121 4 : rServiceFactory->createInstance(
122 8 : "com.sun.star.form.component.Form" );
123 4 : if( xCreate.is() )
124 : {
125 : uno::Reference< beans::XPropertySet > xFormPropSet( xCreate,
126 4 : uno::UNO_QUERY );
127 :
128 8 : uno::Any aTmp(&sName,cppu::UnoType<OUString>::get());
129 4 : xFormPropSet->setPropertyValue( "Name", aTmp );
130 :
131 8 : uno::Reference< form::XForm > xForm( xCreate, uno::UNO_QUERY );
132 : OSL_ENSURE(xForm.is(), "no Form?");
133 :
134 : uno::Reference< container::XIndexContainer > xForms( xNameCont,
135 8 : uno::UNO_QUERY );
136 : OSL_ENSURE( xForms.is(), "XForms not available" );
137 :
138 : aTmp.setValue( &xForm,
139 4 : cppu::UnoType<form::XForm>::get());
140 4 : xForms->insertByIndex( xForms->getCount(), aTmp );
141 :
142 8 : xFormComps = uno::Reference< container::XIndexContainer >
143 8 : (xCreate, uno::UNO_QUERY);
144 4 : }
145 : }
146 : }
147 :
148 10 : return xFormComps;
149 570 : }
150 :
151 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|