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 : #ifndef INCLUDED_SVL_MACITEM_HXX
20 : #define INCLUDED_SVL_MACITEM_HXX
21 :
22 : // class SvxMacroItem ----------------------------------------------------
23 :
24 : #include <rtl/ustring.hxx>
25 : #include <svl/svldllapi.h>
26 : #include <svl/poolitem.hxx>
27 : #include <tools/rtti.hxx>
28 : #include <map>
29 :
30 : class SvStream;
31 :
32 : #define SVX_MACRO_LANGUAGE_JAVASCRIPT "JavaScript"
33 : #define SVX_MACRO_LANGUAGE_STARBASIC "StarBasic"
34 : #define SVX_MACRO_LANGUAGE_SF "Script"
35 :
36 : enum ScriptType
37 : {
38 : STARBASIC,
39 : JAVASCRIPT,
40 : EXTENDED_STYPE
41 : };
42 :
43 1843 : class SVL_DLLPUBLIC SvxMacro
44 : {
45 : OUString aMacName;
46 : OUString aLibName;
47 : ScriptType eType;
48 :
49 : public:
50 :
51 : SvxMacro( const OUString &rMacName, const OUString &rLanguage);
52 :
53 : SvxMacro( const OUString &rMacName, const OUString &rLibName,
54 : ScriptType eType); // = STARBASIC removes
55 :
56 0 : const OUString &GetLibName() const { return aLibName; }
57 0 : const OUString &GetMacName() const { return aMacName; }
58 : OUString GetLanguage()const;
59 :
60 0 : ScriptType GetScriptType() const { return eType; }
61 :
62 952 : bool HasMacro() const { return !aMacName.isEmpty(); }
63 :
64 : SvxMacro& operator=( const SvxMacro& rBase );
65 : };
66 :
67 0 : inline SvxMacro::SvxMacro( const OUString &rMacName, const OUString &rLibName,
68 : ScriptType eTyp )
69 0 : : aMacName( rMacName ), aLibName( rLibName ), eType( eTyp )
70 0 : {}
71 :
72 : // Macro Table, destroys the pointers in the DTor!
73 : typedef std::map<sal_uInt16, SvxMacro> SvxMacroTable;
74 :
75 : #define SVX_MACROTBL_VERSION31 0
76 : #define SVX_MACROTBL_VERSION40 1
77 :
78 : #define SVX_MACROTBL_AKTVERSION SVX_MACROTBL_VERSION40
79 :
80 160 : class SVL_DLLPUBLIC SvxMacroTableDtor
81 : {
82 : private:
83 : SvxMacroTable aSvxMacroTable;
84 : public:
85 150 : inline SvxMacroTableDtor() {}
86 10 : inline SvxMacroTableDtor( const SvxMacroTableDtor &rCpy ) : aSvxMacroTable(rCpy.aSvxMacroTable) { }
87 :
88 : SvxMacroTableDtor& operator=( const SvxMacroTableDtor &rCpy );
89 : bool operator==( const SvxMacroTableDtor& rOther ) const;
90 :
91 : // deletes all entries
92 : void clear() { aSvxMacroTable.clear(); }
93 :
94 : SvStream& Read( SvStream &, sal_uInt16 nVersion = SVX_MACROTBL_AKTVERSION );
95 : SvStream& Write( SvStream & ) const;
96 :
97 0 : static sal_uInt16 GetVersion() { return SVX_MACROTBL_AKTVERSION; }
98 :
99 0 : SvxMacroTable::iterator begin() { return aSvxMacroTable.begin(); }
100 : SvxMacroTable::const_iterator begin() const { return aSvxMacroTable.begin(); }
101 0 : SvxMacroTable::iterator end() { return aSvxMacroTable.end(); }
102 : SvxMacroTable::const_iterator end () const { return aSvxMacroTable.end(); }
103 0 : SvxMacroTable::size_type size() const { return aSvxMacroTable.size(); }
104 29 : bool empty() const { return aSvxMacroTable.empty(); }
105 :
106 : // returns NULL if no entry exists, or a pointer to the internal value
107 : const SvxMacro* Get(sal_uInt16 nEvent) const;
108 : // returns NULL if no entry exists, or a pointer to the internal value
109 : SvxMacro* Get(sal_uInt16 nEvent);
110 : // return true if the key exists
111 : bool IsKeyValid(sal_uInt16 nEvent) const;
112 : // This stores a copy of the rMacro parameter
113 : SvxMacro& Insert(sal_uInt16 nEvent, const SvxMacro& rMacro);
114 : // If the entry exists, remove it from the map and release it's storage
115 : bool Erase(sal_uInt16 nEvent);
116 : };
117 :
118 :
119 : /*
120 : This item describes a Macro table.
121 : */
122 :
123 181 : class SVL_DLLPUBLIC SvxMacroItem: public SfxPoolItem
124 : {
125 : public:
126 : TYPEINFO_OVERRIDE();
127 :
128 : explicit inline SvxMacroItem ( const sal_uInt16 nId );
129 :
130 : // "pure virtual methods" of SfxPoolItem
131 : virtual bool operator==( const SfxPoolItem& ) const SAL_OVERRIDE;
132 : virtual bool GetPresentation( SfxItemPresentation ePres,
133 : SfxMapUnit eCoreMetric,
134 : SfxMapUnit ePresMetric,
135 : OUString &rText,
136 : const IntlWrapper * = 0 ) const SAL_OVERRIDE;
137 : virtual SfxPoolItem* Clone( SfxItemPool *pPool = 0 ) const SAL_OVERRIDE;
138 : virtual SfxPoolItem* Create(SvStream &, sal_uInt16) const SAL_OVERRIDE;
139 : virtual SvStream& Store(SvStream &, sal_uInt16 nItemVersion ) const SAL_OVERRIDE;
140 : virtual sal_uInt16 GetVersion( sal_uInt16 nFileFormatVersion ) const SAL_OVERRIDE;
141 :
142 4 : inline const SvxMacroTableDtor& GetMacroTable() const { return aMacroTable;}
143 0 : inline void SetMacroTable( const SvxMacroTableDtor& rTbl ) { aMacroTable = rTbl; }
144 :
145 : inline const SvxMacro& GetMacro( sal_uInt16 nEvent ) const;
146 : inline bool HasMacro( sal_uInt16 nEvent ) const;
147 : void SetMacro( sal_uInt16 nEvent, const SvxMacro& );
148 : inline bool DelMacro( sal_uInt16 nEvent );
149 :
150 : private:
151 : SvxMacroTableDtor aMacroTable;
152 :
153 : inline SvxMacroItem( const SvxMacroItem& );
154 : SvxMacroItem &operator=( const SvxMacroItem & ) SAL_DELETED_FUNCTION;
155 : };
156 :
157 122 : inline SvxMacroItem::SvxMacroItem( const sal_uInt16 nId )
158 122 : : SfxPoolItem( nId )
159 122 : {}
160 0 : inline SvxMacroItem::SvxMacroItem( const SvxMacroItem &rCpy )
161 : : SfxPoolItem( rCpy ),
162 0 : aMacroTable( rCpy.GetMacroTable() )
163 0 : {}
164 :
165 893 : inline bool SvxMacroItem::HasMacro( sal_uInt16 nEvent ) const
166 : {
167 893 : return aMacroTable.IsKeyValid( nEvent );
168 : }
169 0 : inline const SvxMacro& SvxMacroItem::GetMacro( sal_uInt16 nEvent ) const
170 : {
171 0 : return *(aMacroTable.Get(nEvent));
172 : }
173 : inline bool SvxMacroItem::DelMacro( sal_uInt16 nEvent )
174 : {
175 : return aMacroTable.Erase(nEvent);
176 : }
177 :
178 : #endif
179 :
180 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|