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 SW_AUTHFLD_HXX
20 : #define SW_AUTHFLD_HXX
21 :
22 : #include "swdllapi.h"
23 : #include <fldbas.hxx>
24 : #include <toxe.hxx>
25 : #include <vector>
26 : #include <boost/ptr_container/ptr_vector.hpp>
27 :
28 0 : class SwAuthEntry
29 : {
30 : String aAuthFields[AUTH_FIELD_END];
31 : sal_uInt16 nRefCount;
32 : public:
33 0 : SwAuthEntry() : nRefCount(0){}
34 : SwAuthEntry( const SwAuthEntry& rCopy );
35 : sal_Bool operator==(const SwAuthEntry& rComp);
36 :
37 : inline const String& GetAuthorField(ToxAuthorityField ePos)const;
38 : inline void SetAuthorField(ToxAuthorityField ePos,
39 : const String& rField);
40 :
41 0 : void AddRef() { ++nRefCount; }
42 0 : void RemoveRef() { --nRefCount; }
43 0 : sal_uInt16 GetRefCount() { return nRefCount; }
44 : };
45 :
46 : struct SwTOXSortKey
47 : {
48 : ToxAuthorityField eField;
49 : sal_Bool bSortAscending;
50 0 : SwTOXSortKey() :
51 : eField(AUTH_FIELD_END),
52 0 : bSortAscending(sal_True){}
53 : };
54 :
55 : class SwAuthorityField;
56 : typedef boost::ptr_vector<SwTOXSortKey> SortKeyArr;
57 : typedef boost::ptr_vector<SwAuthEntry> SwAuthDataArr;
58 :
59 : class SW_DLLPUBLIC SwAuthorityFieldType : public SwFieldType
60 : {
61 : SwDoc* m_pDoc;
62 : SwAuthDataArr m_DataArr;
63 : std::vector<sal_IntPtr> m_SequArr;
64 : SortKeyArr m_SortKeyArr;
65 : sal_Unicode m_cPrefix;
66 : sal_Unicode m_cSuffix;
67 : sal_Bool m_bIsSequence :1;
68 : sal_Bool m_bSortByDocument :1;
69 : LanguageType m_eLanguage;
70 : String m_sSortAlgorithm;
71 :
72 : protected:
73 : virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew );
74 :
75 : public:
76 : SwAuthorityFieldType(SwDoc* pDoc);
77 : ~SwAuthorityFieldType();
78 :
79 : virtual SwFieldType* Copy() const;
80 :
81 : virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId ) const;
82 : virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId );
83 :
84 2 : inline void SetDoc(SwDoc* pNewDoc) { m_pDoc = pNewDoc; }
85 0 : SwDoc* GetDoc(){ return m_pDoc; }
86 : void RemoveField(sal_IntPtr nHandle);
87 : sal_IntPtr AddField(const String& rFieldContents);
88 : sal_Bool AddField(sal_IntPtr nHandle);
89 0 : void DelSequenceArray()
90 : {
91 0 : m_SequArr.clear();
92 0 : }
93 :
94 : const SwAuthEntry* GetEntryByHandle(sal_IntPtr nHandle) const;
95 :
96 : void GetAllEntryIdentifiers( std::vector<String>& rToFill )const;
97 : const SwAuthEntry* GetEntryByIdentifier(const String& rIdentifier)const;
98 :
99 : bool ChangeEntryContent(const SwAuthEntry* pNewEntry);
100 : // import interface
101 : sal_uInt16 AppendField(const SwAuthEntry& rInsert);
102 : sal_IntPtr GetHandle(sal_uInt16 nPos);
103 :
104 : sal_uInt16 GetSequencePos(sal_IntPtr nHandle);
105 :
106 0 : sal_Bool IsSequence() const {return m_bIsSequence;}
107 0 : void SetSequence(sal_Bool bSet)
108 : {
109 0 : DelSequenceArray();
110 0 : m_bIsSequence = bSet;
111 0 : }
112 :
113 0 : void SetPreSuffix( sal_Unicode cPre, sal_Unicode cSuf)
114 : {
115 0 : m_cPrefix = cPre;
116 0 : m_cSuffix = cSuf;
117 0 : }
118 0 : sal_Unicode GetPrefix() const { return m_cPrefix;}
119 0 : sal_Unicode GetSuffix() const { return m_cSuffix;}
120 :
121 0 : sal_Bool IsSortByDocument() const {return m_bSortByDocument;}
122 0 : void SetSortByDocument(sal_Bool bSet)
123 : {
124 0 : DelSequenceArray();
125 0 : m_bSortByDocument = bSet;
126 0 : }
127 :
128 : sal_uInt16 GetSortKeyCount() const ;
129 : const SwTOXSortKey* GetSortKey(sal_uInt16 nIdx) const ;
130 : void SetSortKeys(sal_uInt16 nKeyCount, SwTOXSortKey nKeys[]);
131 :
132 : //initui.cxx
133 : static const String& GetAuthFieldName(ToxAuthorityField eType);
134 : static const String& GetAuthTypeName(ToxAuthorityType eType);
135 :
136 1 : LanguageType GetLanguage() const {return m_eLanguage;}
137 2 : void SetLanguage(LanguageType nLang) {m_eLanguage = nLang;}
138 :
139 1 : const String& GetSortAlgorithm()const {return m_sSortAlgorithm;}
140 2 : void SetSortAlgorithm(const String& rSet) {m_sSortAlgorithm = rSet;}
141 :
142 : };
143 :
144 : class SwAuthorityField : public SwField
145 : {
146 : sal_IntPtr m_nHandle;
147 : mutable sal_IntPtr m_nTempSequencePos;
148 :
149 : virtual String Expand() const;
150 : virtual SwField* Copy() const;
151 :
152 : public:
153 : SwAuthorityField(SwAuthorityFieldType* pType, const String& rFieldContents);
154 : SwAuthorityField(SwAuthorityFieldType* pType, sal_IntPtr nHandle);
155 : ~SwAuthorityField();
156 :
157 : const String& GetFieldText(ToxAuthorityField eField) const;
158 :
159 : virtual void SetPar1(const OUString& rStr);
160 : virtual SwFieldType* ChgTyp( SwFieldType* );
161 :
162 : virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId ) const;
163 : virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId );
164 :
165 0 : sal_IntPtr GetHandle() const { return m_nHandle; }
166 :
167 : virtual String GetDescription() const;
168 : };
169 :
170 : // --- inlines -----------------------------------------------------------
171 0 : inline const String& SwAuthEntry::GetAuthorField(ToxAuthorityField ePos)const
172 : {
173 : OSL_ENSURE(AUTH_FIELD_END > ePos, "wrong index");
174 0 : return aAuthFields[ePos];
175 : }
176 0 : inline void SwAuthEntry::SetAuthorField(ToxAuthorityField ePos, const String& rField)
177 : {
178 : OSL_ENSURE(AUTH_FIELD_END > ePos, "wrong index");
179 0 : if(AUTH_FIELD_END > ePos)
180 0 : aAuthFields[ePos] = rField;
181 0 : }
182 :
183 : #endif
184 :
185 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|