LibreOffice Module sw (master)  1
scrptfld.cxx
Go to the documentation of this file.
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 <docufld.hxx>
21 #include <unofldmid.h>
22 #include <strings.hrc>
23 #include <o3tl/any.hxx>
24 #include <swtypes.hxx>
25 
26 using namespace ::com::sun::star;
27 
29  : SwFieldType( SwFieldIds::Script ), m_pDoc( pD )
30 {}
31 
32 std::unique_ptr<SwFieldType> SwScriptFieldType::Copy() const
33 {
34  return std::make_unique<SwScriptFieldType>( m_pDoc );
35 }
36 
38  const OUString& rType, const OUString& rCode,
39  bool bURL )
40  : SwField( pInitType ), m_sType( rType ), m_sCode( rCode ), m_bCodeURL( bURL )
41 {
42 }
43 
45 {
46  return SwResId(STR_SCRIPT);
47 }
48 
49 OUString SwScriptField::ExpandImpl(SwRootFrame const*const) const
50 {
51  return OUString();
52 }
53 
54 std::unique_ptr<SwField> SwScriptField::Copy() const
55 {
56  return std::make_unique<SwScriptField>( static_cast<SwScriptFieldType*>(GetTyp()), m_sType, m_sCode, m_bCodeURL );
57 }
58 
60 void SwScriptField::SetPar1( const OUString& rStr )
61 {
62  m_sType = rStr;
63 }
64 
65 OUString SwScriptField::GetPar1() const
66 {
67  return m_sType;
68 }
69 
71 void SwScriptField::SetPar2( const OUString& rStr )
72 {
73  m_sCode = rStr;
74 }
75 
76 OUString SwScriptField::GetPar2() const
77 {
78  return m_sCode;
79 }
80 
81 bool SwScriptField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
82 {
83  switch( nWhichId )
84  {
85  case FIELD_PROP_PAR1:
86  rAny <<= m_sType;
87  break;
88  case FIELD_PROP_PAR2:
89  rAny <<= m_sCode;
90  break;
91  case FIELD_PROP_BOOL1:
92  rAny <<= m_bCodeURL;
93  break;
94  default:
95  assert(false);
96  }
97  return true;
98 }
99 
100 bool SwScriptField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
101 {
102  switch( nWhichId )
103  {
104  case FIELD_PROP_PAR1:
105  rAny >>= m_sType;
106  break;
107  case FIELD_PROP_PAR2:
108  rAny >>= m_sCode;
109  break;
110  case FIELD_PROP_BOOL1:
111  m_bCodeURL = *o3tl::doAccess<bool>(rAny);
112  break;
113  default:
114  assert(false);
115  }
116  return true;
117 }
118 
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual std::unique_ptr< SwFieldType > Copy() const override
Definition: scrptfld.cxx:32
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:233
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich) override
Definition: scrptfld.cxx:100
Base class of all fields.
Definition: fldbas.hxx:279
Definition: doc.hxx:185
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const override
Definition: scrptfld.cxx:49
virtual OUString GetPar1() const override
Type.
Definition: scrptfld.cxx:65
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
OUString m_sCode
Code as text.
Definition: docufld.hxx:692
OUString m_sType
Type of Code (Java/VBScript/...)
Definition: docufld.hxx:691
SwFieldIds
Definition: fldbas.hxx:38
virtual OUString GetPar2() const override
Text.
Definition: scrptfld.cxx:76
OUString SwResId(const char *pId)
Definition: swmodule.cxx:191
virtual OUString GetDescription() const override
Definition: scrptfld.cxx:44
SwFieldType * GetTyp() const
Definition: fldbas.hxx:382
#define FIELD_PROP_BOOL1
Definition: unofldmid.h:28
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const override
Definition: scrptfld.cxx:81
virtual void SetPar1(const OUString &rStr) override
set type
Definition: scrptfld.cxx:60
#define FIELD_PROP_PAR1
Definition: unofldmid.h:23
#define FIELD_PROP_PAR2
Definition: unofldmid.h:24
virtual std::unique_ptr< SwField > Copy() const override
Definition: scrptfld.cxx:54
bool m_bCodeURL
Code contains URL of a script.
Definition: docufld.hxx:695
virtual void SetPar2(const OUString &rStr) override
set code
Definition: scrptfld.cxx:71
SwScriptFieldType(SwDoc *pDoc)
Definition: scrptfld.cxx:28
SwDoc *const m_pDoc
Definition: docufld.hxx:682
SwScriptField(SwScriptFieldType *, const OUString &rType, const OUString &rCode, bool bURL)
Definition: scrptfld.cxx:37