1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23 #ifndef _SFXMACITEM_HXX
24 #define _SFXMACITEM_HXX
25
26 // class SvxMacroItem ----------------------------------------------------
27
28 #include "svl/svldllapi.h"
29 #include <svl/poolitem.hxx>
30 #include <tools/rtti.hxx>
31 #include <tools/debug.hxx>
32 #include <tools/string.hxx>
33
34 #ifndef _TABLE_HXX
35 #include <tools/table.hxx>
36 #endif
37
38 class SvStream;
39
40 #define SVX_MACRO_LANGUAGE_JAVASCRIPT "JavaScript"
41 #define SVX_MACRO_LANGUAGE_STARBASIC "StarBasic"
42 #define SVX_MACRO_LANGUAGE_SF "Script"
43
44 DBG_NAMEEX(SvxMacroItem)
45
46 // -----------------------------------------------------------------------
47
48 //Ein Macro
49
50 enum ScriptType
51 {
52 STARBASIC,
53 JAVASCRIPT,
54 EXTENDED_STYPE
55 };
56
57 // Basisklasse fuer SjJSbxObject mit virtuellem Destruktor
58 class SjJSbxObjectBase
59 {
60 public:
61 virtual ~SjJSbxObjectBase();
62 virtual SjJSbxObjectBase* Clone( void );
63 //virtual SjJSbxObjectBase& operator=( const SjJSbxObjectBase& rBase );
64 };
65
66 class SjJSbxObject;
67
68 class SVL_DLLPUBLIC SvxMacro
69 {
70 String aMacName;
71 String aLibName;
72 // Fuer JavaScript muss ein Function-Objekt gehalten werden
73 SjJSbxObjectBase* pFunctionObject;
74 ScriptType eType;
75
76 public:
77
78 SvxMacro( const String &rMacName, const String &rLanguage);
79
80 SvxMacro( const String &rMacName, const String &rLibName,
81 ScriptType eType); // = STARBASIC entfernt
82
83 SvxMacro( SjJSbxObjectBase* _pFunctionObject, const String &rSource );
84 ~SvxMacro(); // noetig fuer pFunctionObject
85
GetLibName() const86 const String &GetLibName() const { return aLibName; }
GetMacName() const87 const String &GetMacName() const { return aMacName; }
88 String GetLanguage()const;
89
GetScriptType() const90 ScriptType GetScriptType() const { return eType; }
91
HasMacro() const92 sal_Bool HasMacro() const { return aMacName.Len() ? sal_True : sal_False; }
93
94 #ifdef SOLAR_JAVA
95 // JavaScript-Function-Objekt holen
96 // ACHTUNG: Implementation in SJ, Source/JScript/sjimpl.cxx
97 SjJSbxObjectBase* GetFunctionObject( SjJSbxObject* pParent );
98 #endif
99
100 SvxMacro& operator=( const SvxMacro& rBase );
101 };
102
SvxMacro(const String & rMacName,const String & rLibName,ScriptType eTyp)103 inline SvxMacro::SvxMacro( const String &rMacName, const String &rLibName,
104 ScriptType eTyp )
105 : aMacName( rMacName ), aLibName( rLibName ), pFunctionObject(NULL), eType( eTyp )
106 {}
107
SvxMacro(SjJSbxObjectBase * _pFunctionObject,const String & rSource)108 inline SvxMacro::SvxMacro( SjJSbxObjectBase* _pFunctionObject, const String &rSource )
109 : aMacName( rSource ), pFunctionObject( _pFunctionObject ), eType( JAVASCRIPT )
110 {}
111
112 //Macro Table, zerstoert die Pointer im DTor!
113
114 DECLARE_TABLE( _SvxMacroTableDtor, SvxMacro* )
115
116 #define SVX_MACROTBL_VERSION31 0
117 #define SVX_MACROTBL_VERSION40 1
118
119 #define SVX_MACROTBL_AKTVERSION SVX_MACROTBL_VERSION40
120
121 class SVL_DLLPUBLIC SvxMacroTableDtor : public _SvxMacroTableDtor
122 {
123 public:
124 inline SvxMacroTableDtor( const sal_uInt16 nInitSz = 0, const sal_uInt16 nReSz = 1 );
SvxMacroTableDtor(const SvxMacroTableDtor & rCpy)125 inline SvxMacroTableDtor( const SvxMacroTableDtor &rCpy ) : _SvxMacroTableDtor() { *this = rCpy; }
~SvxMacroTableDtor()126 inline ~SvxMacroTableDtor() { DelDtor(); }
127 SvxMacroTableDtor& operator=( const SvxMacroTableDtor &rCpy );
128
129 // loescht alle Eintraege
130 void DelDtor();
131
132 SvStream& Read( SvStream &, sal_uInt16 nVersion = SVX_MACROTBL_AKTVERSION );
133 SvStream& Write( SvStream & ) const;
134
GetVersion() const135 sal_uInt16 GetVersion() const { return SVX_MACROTBL_AKTVERSION; }
136 };
137
SvxMacroTableDtor(const sal_uInt16 nInitSz,const sal_uInt16 nReSz)138 inline SvxMacroTableDtor::SvxMacroTableDtor( const sal_uInt16 nInitSz,
139 const sal_uInt16 nReSz)
140 : _SvxMacroTableDtor( nInitSz, nReSz )
141 {}
142
143 /*
144 [Beschreibung]
145 Dieses Item beschreibt eine Makro-Tabelle.
146 */
147
148 class SVL_DLLPUBLIC SvxMacroItem: public SfxPoolItem
149 {
150 public:
151 TYPEINFO();
152
153 inline SvxMacroItem ( const sal_uInt16 nId /*= ITEMID_MACRO*/ );
154
155 // "pure virtual Methoden" vom SfxPoolItem
156 virtual int operator==( const SfxPoolItem& ) const;
157 virtual SfxItemPresentation GetPresentation( SfxItemPresentation ePres,
158 SfxMapUnit eCoreMetric,
159 SfxMapUnit ePresMetric,
160 XubString &rText,
161 const IntlWrapper * = 0 ) const;
162 virtual SfxPoolItem* Clone( SfxItemPool *pPool = 0 ) const;
163 virtual SfxPoolItem* Create(SvStream &, sal_uInt16) const;
164 virtual SvStream& Store(SvStream &, sal_uInt16 nItemVersion ) const;
165 virtual sal_uInt16 GetVersion( sal_uInt16 nFileFormatVersion ) const;
166
GetMacroTable() const167 inline const SvxMacroTableDtor& GetMacroTable() const { return aMacroTable;}
SetMacroTable(const SvxMacroTableDtor & rTbl)168 inline void SetMacroTable( const SvxMacroTableDtor& rTbl ) { aMacroTable = rTbl; }
169
170 inline const SvxMacro& GetMacro( sal_uInt16 nEvent ) const;
171 inline sal_Bool HasMacro( sal_uInt16 nEvent ) const;
172 void SetMacro( sal_uInt16 nEvent, const SvxMacro& );
173 inline sal_Bool DelMacro( sal_uInt16 nEvent );
174
175 private:
176 SvxMacroTableDtor aMacroTable;
177
178 inline SvxMacroItem( const SvxMacroItem& );
179 SvxMacroItem &operator=( const SvxMacroItem & );
180 };
181
SvxMacroItem(const sal_uInt16 nId)182 inline SvxMacroItem::SvxMacroItem( const sal_uInt16 nId )
183 : SfxPoolItem( nId )
184 {}
SvxMacroItem(const SvxMacroItem & rCpy)185 inline SvxMacroItem::SvxMacroItem( const SvxMacroItem &rCpy )
186 : SfxPoolItem( rCpy ),
187 aMacroTable( rCpy.GetMacroTable() )
188 {}
189
HasMacro(sal_uInt16 nEvent) const190 inline sal_Bool SvxMacroItem::HasMacro( sal_uInt16 nEvent ) const
191 {
192 return aMacroTable.IsKeyValid( nEvent );
193 }
GetMacro(sal_uInt16 nEvent) const194 inline const SvxMacro& SvxMacroItem::GetMacro( sal_uInt16 nEvent ) const
195 {
196 return *(aMacroTable.Get(nEvent));
197 }
DelMacro(sal_uInt16 nEvent)198 inline sal_Bool SvxMacroItem::DelMacro( sal_uInt16 nEvent )
199 {
200 SvxMacro *pMacro = aMacroTable.Remove( nEvent );
201 delete pMacro;
202 return ( pMacro != 0 );
203 }
204
205 #endif
206