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 : using namespace ::rtl;
32 :
33 : #define C2U(cChar) rtl::OUString(cChar)
34 :
35 : static char sWW8_form[] = "WW-Standard";
36 :
37 73 : SvxMSConvertOCXControls::SvxMSConvertOCXControls( const uno::Reference< frame::XModel >& rxModel) : mxModel(rxModel)
38 : {
39 73 : }
40 :
41 73 : SvxMSConvertOCXControls::~SvxMSConvertOCXControls()
42 : {
43 73 : }
44 :
45 : const uno::Reference< drawing::XDrawPage >&
46 0 : SvxMSConvertOCXControls::GetDrawPage()
47 : {
48 0 : if( !xDrawPage.is() && mxModel.is() )
49 : {
50 : uno::Reference< drawing::XDrawPageSupplier > xTxtDoc(mxModel,
51 0 : uno::UNO_QUERY);
52 : OSL_ENSURE(xTxtDoc.is(),"no XDrawPageSupplier from XModel");
53 0 : xDrawPage = xTxtDoc->getDrawPage();
54 0 : OSL_ENSURE( xDrawPage.is(), "no XDrawPage" );
55 : }
56 :
57 0 : return xDrawPage;
58 : }
59 :
60 :
61 : const uno::Reference< lang::XMultiServiceFactory >&
62 0 : SvxMSConvertOCXControls::GetServiceFactory()
63 : {
64 0 : if( !xServiceFactory.is() && mxModel.is() )
65 : {
66 : xServiceFactory = uno::Reference< lang::XMultiServiceFactory >
67 0 : (mxModel, uno::UNO_QUERY);
68 : OSL_ENSURE( xServiceFactory.is(),
69 : "no XMultiServiceFactory from doc Model" );
70 : }
71 :
72 0 : return xServiceFactory;
73 : }
74 :
75 0 : const uno::Reference< drawing::XShapes >& SvxMSConvertOCXControls::GetShapes()
76 : {
77 0 : if( !xShapes.is() )
78 : {
79 0 : GetDrawPage();
80 0 : if( xDrawPage.is() )
81 : {
82 :
83 : xShapes = uno::Reference< drawing::XShapes >(xDrawPage,
84 0 : uno::UNO_QUERY);
85 : OSL_ENSURE( xShapes.is(), "UNO_QUERY failed for XShapes from XDrawPage" );
86 : }
87 : }
88 0 : return xShapes;
89 : }
90 :
91 : const uno::Reference< container::XIndexContainer >&
92 0 : SvxMSConvertOCXControls::GetFormComps()
93 : {
94 0 : if( !xFormComps.is() )
95 : {
96 0 : GetDrawPage();
97 0 : if( xDrawPage.is() )
98 : {
99 : uno::Reference< form::XFormsSupplier > xFormsSupplier( xDrawPage,
100 0 : uno::UNO_QUERY );
101 : OSL_ENSURE( xFormsSupplier.is(),
102 : "UNO_QUERY failed for XFormsSupplier from XDrawPage" );
103 :
104 : uno::Reference< container::XNameContainer > xNameCont =
105 0 : xFormsSupplier->getForms();
106 :
107 : // Das Formular bekommt einen Namen wie "WW-Standard[n]" und
108 : // wird in jedem Fall neu angelegt.
109 0 : UniString sName( sWW8_form, RTL_TEXTENCODING_MS_1252 );
110 0 : sal_uInt16 n = 0;
111 :
112 0 : while( xNameCont->hasByName( sName ) )
113 : {
114 0 : sName.AssignAscii( sWW8_form );
115 0 : sName += String::CreateFromInt32( ++n );
116 : }
117 :
118 : const uno::Reference< lang::XMultiServiceFactory > &rServiceFactory
119 0 : = GetServiceFactory();
120 0 : if( !rServiceFactory.is() )
121 0 : return xFormComps;
122 :
123 : uno::Reference< uno::XInterface > xCreate =
124 0 : rServiceFactory->createInstance(C2U(
125 0 : "com.sun.star.form.component.Form"));
126 0 : if( xCreate.is() )
127 : {
128 : uno::Reference< beans::XPropertySet > xFormPropSet( xCreate,
129 0 : uno::UNO_QUERY );
130 :
131 0 : uno::Any aTmp(&sName,getCppuType((OUString *)0));
132 0 : xFormPropSet->setPropertyValue( C2U("Name"), aTmp );
133 :
134 0 : uno::Reference< form::XForm > xForm( xCreate, uno::UNO_QUERY );
135 : OSL_ENSURE(xForm.is(), "no Form?");
136 :
137 : uno::Reference< container::XIndexContainer > xForms( xNameCont,
138 0 : uno::UNO_QUERY );
139 : OSL_ENSURE( xForms.is(), "XForms not available" );
140 :
141 : aTmp.setValue( &xForm,
142 0 : ::getCppuType((uno::Reference < form::XForm >*)0));
143 0 : xForms->insertByIndex( xForms->getCount(), aTmp );
144 :
145 : xFormComps = uno::Reference< container::XIndexContainer >
146 0 : (xCreate, uno::UNO_QUERY);
147 0 : }
148 : }
149 : }
150 :
151 0 : return xFormComps;
152 : }
153 :
154 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|