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 1448 : 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 entfernt
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 728 : 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, zerstoert die Pointer im DTor!
73 :
74 : typedef std::map<sal_uInt16, SvxMacro> SvxMacroTable;
75 :
76 : #define SVX_MACROTBL_VERSION31 0
77 : #define SVX_MACROTBL_VERSION40 1
78 :
79 : #define SVX_MACROTBL_AKTVERSION SVX_MACROTBL_VERSION40
80 :
81 268 : class SVL_DLLPUBLIC SvxMacroTableDtor
82 : {
83 : private:
84 : SvxMacroTable aSvxMacroTable;
85 : public:
86 242 : inline SvxMacroTableDtor() {}
87 28 : inline SvxMacroTableDtor( const SvxMacroTableDtor &rCpy ) : aSvxMacroTable(rCpy.aSvxMacroTable) { }
88 :
89 : SvxMacroTableDtor& operator=( const SvxMacroTableDtor &rCpy );
90 : int operator==( const SvxMacroTableDtor& rOther ) const;
91 :
92 : // loescht alle Eintraege
93 : void clear() { aSvxMacroTable.clear(); }
94 :
95 : SvStream& Read( SvStream &, sal_uInt16 nVersion = SVX_MACROTBL_AKTVERSION );
96 : SvStream& Write( SvStream & ) const;
97 :
98 0 : sal_uInt16 GetVersion() const { return SVX_MACROTBL_AKTVERSION; }
99 :
100 0 : SvxMacroTable::iterator begin() { return aSvxMacroTable.begin(); }
101 : SvxMacroTable::const_iterator begin() const { return aSvxMacroTable.begin(); }
102 0 : SvxMacroTable::iterator end() { return aSvxMacroTable.end(); }
103 : SvxMacroTable::const_iterator end () const { return aSvxMacroTable.end(); }
104 0 : SvxMacroTable::size_type size() const { return aSvxMacroTable.size(); }
105 52 : bool empty() const { return aSvxMacroTable.empty(); }
106 :
107 : // returns NULL if no entry exists, or a pointer to the internal value
108 : const SvxMacro* Get(sal_uInt16 nEvent) const;
109 : // returns NULL if no entry exists, or a pointer to the internal value
110 : SvxMacro* Get(sal_uInt16 nEvent);
111 : // return true if the key exists
112 : bool IsKeyValid(sal_uInt16 nEvent) const;
113 : // This stores a copy of the rMacro parameter
114 : SvxMacro& Insert(sal_uInt16 nEvent, const SvxMacro& rMacro);
115 : // If the entry exists, remove it from the map and release it's storage
116 : bool Erase(sal_uInt16 nEvent);
117 : };
118 :
119 :
120 : /*
121 : [Beschreibung]
122 : Dieses Item beschreibt eine Makro-Tabelle.
123 : */
124 :
125 278 : class SVL_DLLPUBLIC SvxMacroItem: public SfxPoolItem
126 : {
127 : public:
128 : TYPEINFO_OVERRIDE();
129 :
130 : explicit inline SvxMacroItem ( const sal_uInt16 nId );
131 :
132 : // "pure virtual Methoden" vom SfxPoolItem
133 : virtual bool operator==( const SfxPoolItem& ) const SAL_OVERRIDE;
134 : virtual bool GetPresentation( SfxItemPresentation ePres,
135 : SfxMapUnit eCoreMetric,
136 : SfxMapUnit ePresMetric,
137 : OUString &rText,
138 : const IntlWrapper * = 0 ) const SAL_OVERRIDE;
139 : virtual SfxPoolItem* Clone( SfxItemPool *pPool = 0 ) const SAL_OVERRIDE;
140 : virtual SfxPoolItem* Create(SvStream &, sal_uInt16) const SAL_OVERRIDE;
141 : virtual SvStream& Store(SvStream &, sal_uInt16 nItemVersion ) const SAL_OVERRIDE;
142 : virtual sal_uInt16 GetVersion( sal_uInt16 nFileFormatVersion ) const SAL_OVERRIDE;
143 :
144 22 : inline const SvxMacroTableDtor& GetMacroTable() const { return aMacroTable;}
145 0 : inline void SetMacroTable( const SvxMacroTableDtor& rTbl ) { aMacroTable = rTbl; }
146 :
147 : inline const SvxMacro& GetMacro( sal_uInt16 nEvent ) const;
148 : inline bool HasMacro( sal_uInt16 nEvent ) const;
149 : void SetMacro( sal_uInt16 nEvent, const SvxMacro& );
150 : inline bool DelMacro( sal_uInt16 nEvent );
151 :
152 : private:
153 : SvxMacroTableDtor aMacroTable;
154 :
155 : inline SvxMacroItem( const SvxMacroItem& );
156 : SvxMacroItem &operator=( const SvxMacroItem & );
157 : };
158 :
159 188 : inline SvxMacroItem::SvxMacroItem( const sal_uInt16 nId )
160 188 : : SfxPoolItem( nId )
161 188 : {}
162 2 : inline SvxMacroItem::SvxMacroItem( const SvxMacroItem &rCpy )
163 : : SfxPoolItem( rCpy ),
164 2 : aMacroTable( rCpy.GetMacroTable() )
165 2 : {}
166 :
167 720 : inline bool SvxMacroItem::HasMacro( sal_uInt16 nEvent ) const
168 : {
169 720 : return aMacroTable.IsKeyValid( nEvent );
170 : }
171 0 : inline const SvxMacro& SvxMacroItem::GetMacro( sal_uInt16 nEvent ) const
172 : {
173 0 : return *(aMacroTable.Get(nEvent));
174 : }
175 : inline bool SvxMacroItem::DelMacro( sal_uInt16 nEvent )
176 : {
177 : return aMacroTable.Erase(nEvent);
178 : }
179 :
180 : #endif
181 :
182 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|