1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: macrofld.cxx,v $
10 * $Revision: 1.13.214.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <hintids.hxx>
37 #include <docufld.hxx>
39 #include <unofldmid.h>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/uri/XUriReferenceFactory.hpp>
43 #include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
44 #include <comphelper/processfactory.hxx>
46 using namespace ::com::sun::star
;
47 using ::rtl::OUString
;
48 /*--------------------------------------------------------------------
49 Beschreibung: MacroFeldtypen
50 --------------------------------------------------------------------*/
52 SwMacroFieldType::SwMacroFieldType(SwDoc
* pDocument
)
53 : SwFieldType( RES_MACROFLD
),
58 SwFieldType
* SwMacroFieldType::Copy() const
60 SwMacroFieldType
* pType
= new SwMacroFieldType(pDoc
);
64 /*--------------------------------------------------------------------
65 Beschreibung: Das Macrofeld selbst
66 --------------------------------------------------------------------*/
68 SwMacroField::SwMacroField(SwMacroFieldType
* pInitType
,
69 const String
& rLibAndName
, const String
& rTxt
) :
70 SwField(pInitType
), aMacro(rLibAndName
), aText(rTxt
), bIsScriptURL(FALSE
)
72 bIsScriptURL
= isScriptURL(aMacro
);
75 String
SwMacroField::Expand() const
76 { // Button malen anstatt von
80 SwField
* SwMacroField::Copy() const
82 return new SwMacroField((SwMacroFieldType
*)GetTyp(), aMacro
, aText
);
85 String
SwMacroField::GetCntnt(BOOL bName
) const
89 String
aStr(GetTyp()->GetName());
97 String
SwMacroField::GetLibName() const
99 // if it is a Scripting Framework macro return an empty string
107 USHORT nPos
= aMacro
.Len();
109 for (USHORT i
= 0; i
< 3 && nPos
> 0; i
++)
110 while (aMacro
.GetChar(--nPos
) != '.' && nPos
> 0) ;
112 return aMacro
.Copy(0, nPos
);
115 DBG_ASSERT(0, "Kein Macroname vorhanden");
119 String
SwMacroField::GetMacroName() const
125 return aMacro
.Copy( 0 );
129 USHORT nPos
= aMacro
.Len();
131 for (USHORT i
= 0; i
< 3 && nPos
> 0; i
++)
132 while (aMacro
.GetChar(--nPos
) != '.' && nPos
> 0) ;
134 return aMacro
.Copy( ++nPos
);
138 DBG_ASSERT(0, "Kein Macroname vorhanden");
142 SvxMacro
SwMacroField::GetSvxMacro() const
146 return SvxMacro(aMacro
, String(), EXTENDED_STYPE
);
150 return SvxMacro(GetMacroName(), GetLibName(), STARBASIC
);
154 /*--------------------------------------------------------------------
155 Beschreibung: LibName und MacroName
156 --------------------------------------------------------------------*/
158 void SwMacroField::SetPar1(const String
& rStr
)
161 bIsScriptURL
= isScriptURL(aMacro
);
164 const String
& SwMacroField::GetPar1() const
169 /*--------------------------------------------------------------------
170 Beschreibung: Macrotext
171 --------------------------------------------------------------------*/
173 void SwMacroField::SetPar2(const String
& rStr
)
178 String
SwMacroField::GetPar2() const
183 /*-----------------05.03.98 13:38-------------------
185 --------------------------------------------------*/
186 BOOL
SwMacroField::QueryValue( uno::Any
& rAny
, USHORT nWhichId
) const
190 case FIELD_PROP_PAR1
:
191 rAny
<<= OUString(GetMacroName());
193 case FIELD_PROP_PAR2
:
194 rAny
<<= OUString(aText
);
196 case FIELD_PROP_PAR3
:
197 rAny
<<= OUString(GetLibName());
199 case FIELD_PROP_PAR4
:
200 rAny
<<= bIsScriptURL
? OUString(GetMacroName()): OUString();
203 DBG_ERROR("illegal property");
207 /*-----------------05.03.98 13:38-------------------
209 --------------------------------------------------*/
210 BOOL
SwMacroField::PutValue( const uno::Any
& rAny
, USHORT nWhichId
)
215 case FIELD_PROP_PAR1
:
216 CreateMacroString( aMacro
, ::GetString(rAny
, sTmp
), GetLibName());
218 case FIELD_PROP_PAR2
:
219 ::GetString( rAny
, aText
);
221 case FIELD_PROP_PAR3
:
222 CreateMacroString(aMacro
, GetMacroName(), ::GetString(rAny
, sTmp
) );
224 case FIELD_PROP_PAR4
:
225 ::GetString(rAny
, aMacro
);
226 bIsScriptURL
= isScriptURL(aMacro
);
229 DBG_ERROR("illegal property");
235 // create an internally used macro name from the library and macro name parts
236 void SwMacroField::CreateMacroString(
238 const String
& rMacroName
,
239 const String
& rLibraryName
)
241 // concatenate library and name; use dot only if both strings have content
242 rMacro
= rLibraryName
;
243 if ( rLibraryName
.Len() > 0 && rMacroName
.Len() > 0 )
245 rMacro
+= rMacroName
;
248 BOOL
SwMacroField::isScriptURL( const String
& str
)
250 uno::Reference
< lang::XMultiServiceFactory
> xSMgr
=
251 ::comphelper::getProcessServiceFactory();
253 uno::Reference
< uri::XUriReferenceFactory
>
254 xFactory( xSMgr
->createInstance(
255 OUString::createFromAscii(
256 "com.sun.star.uri.UriReferenceFactory" ) ), uno::UNO_QUERY
);
260 uno::Reference
< uri::XVndSunStarScriptUrl
>
261 xUrl( xFactory
->parse( str
), uno::UNO_QUERY
);