1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SW_INC_AUTHFLD_HXX
20 #define INCLUDED_SW_INC_AUTHFLD_HXX
26 #include <boost/ptr_container/ptr_vector.hpp>
27 #include <sal/log.hxx>
31 OUString aAuthFields
[AUTH_FIELD_END
];
34 SwAuthEntry() : nRefCount(0){}
35 SwAuthEntry( const SwAuthEntry
& rCopy
);
36 bool operator==(const SwAuthEntry
& rComp
);
38 inline OUString
GetAuthorField(ToxAuthorityField ePos
) const;
39 inline void SetAuthorField(ToxAuthorityField ePos
,
40 const OUString
& rField
);
42 void AddRef() { ++nRefCount
; }
43 void RemoveRef() { --nRefCount
; }
44 sal_uInt16
GetRefCount() { return nRefCount
; }
49 ToxAuthorityField eField
;
52 eField(AUTH_FIELD_END
),
53 bSortAscending(true){}
56 class SwAuthorityField
;
57 typedef boost::ptr_vector
<SwTOXSortKey
> SortKeyArr
;
58 typedef boost::ptr_vector
<SwAuthEntry
> SwAuthDataArr
;
60 class SW_DLLPUBLIC SwAuthorityFieldType
: public SwFieldType
63 SwAuthDataArr m_DataArr
;
64 std::vector
<sal_IntPtr
> m_SequArr
;
65 SortKeyArr m_SortKeyArr
;
66 sal_Unicode m_cPrefix
;
67 sal_Unicode m_cSuffix
;
68 bool m_bIsSequence
:1;
69 bool m_bSortByDocument
:1;
70 LanguageType m_eLanguage
;
71 OUString m_sSortAlgorithm
;
74 virtual void Modify( const SfxPoolItem
* pOld
, const SfxPoolItem
*pNew
) SAL_OVERRIDE
;
77 SwAuthorityFieldType(SwDoc
* pDoc
);
78 virtual ~SwAuthorityFieldType();
80 virtual SwFieldType
* Copy() const SAL_OVERRIDE
;
82 virtual bool QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhichId
) const SAL_OVERRIDE
;
83 virtual bool PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhichId
) SAL_OVERRIDE
;
85 inline void SetDoc(SwDoc
* pNewDoc
) { m_pDoc
= pNewDoc
; }
86 SwDoc
* GetDoc(){ return m_pDoc
; }
87 void RemoveField(sal_IntPtr nHandle
);
88 sal_IntPtr
AddField(const OUString
& rFieldContents
);
89 bool AddField(sal_IntPtr nHandle
);
90 void DelSequenceArray()
95 const SwAuthEntry
* GetEntryByHandle(sal_IntPtr nHandle
) const;
97 void GetAllEntryIdentifiers( std::vector
<OUString
>& rToFill
) const;
98 const SwAuthEntry
* GetEntryByIdentifier(const OUString
& rIdentifier
) const;
100 bool ChangeEntryContent(const SwAuthEntry
* pNewEntry
);
102 sal_uInt16
AppendField(const SwAuthEntry
& rInsert
);
103 sal_IntPtr
GetHandle(sal_uInt16 nPos
);
105 sal_uInt16
GetSequencePos(sal_IntPtr nHandle
);
107 bool IsSequence() const {return m_bIsSequence
;}
108 void SetSequence(bool bSet
)
111 m_bIsSequence
= bSet
;
114 void SetPreSuffix( sal_Unicode cPre
, sal_Unicode cSuf
)
119 sal_Unicode
GetPrefix() const { return m_cPrefix
;}
120 sal_Unicode
GetSuffix() const { return m_cSuffix
;}
122 bool IsSortByDocument() const {return m_bSortByDocument
;}
123 void SetSortByDocument(bool bSet
)
126 m_bSortByDocument
= bSet
;
129 sal_uInt16
GetSortKeyCount() const ;
130 const SwTOXSortKey
* GetSortKey(sal_uInt16 nIdx
) const ;
131 void SetSortKeys(sal_uInt16 nKeyCount
, SwTOXSortKey nKeys
[]);
134 static OUString
GetAuthFieldName(ToxAuthorityField eType
);
135 static OUString
GetAuthTypeName(ToxAuthorityType eType
);
137 LanguageType
GetLanguage() const {return m_eLanguage
;}
138 void SetLanguage(LanguageType nLang
) {m_eLanguage
= nLang
;}
140 OUString
GetSortAlgorithm() const {return m_sSortAlgorithm
;}
141 void SetSortAlgorithm(const OUString
& rSet
) {m_sSortAlgorithm
= rSet
;}
145 class SwAuthorityField
: public SwField
147 sal_IntPtr m_nHandle
;
148 mutable sal_IntPtr m_nTempSequencePos
;
150 virtual OUString
Expand() const SAL_OVERRIDE
;
151 virtual SwField
* Copy() const SAL_OVERRIDE
;
154 /// For internal use only, in general continue using ExpandField() instead.
155 OUString
ConditionalExpand(ToxAuthorityField eField
) const;
158 SW_DLLPUBLIC OUString
ExpandCitation(ToxAuthorityField eField
) const;
160 SwAuthorityField(SwAuthorityFieldType
* pType
, const OUString
& rFieldContents
);
161 SwAuthorityField(SwAuthorityFieldType
* pType
, sal_IntPtr nHandle
);
162 virtual ~SwAuthorityField();
164 OUString
GetFieldText(ToxAuthorityField eField
) const;
166 virtual void SetPar1(const OUString
& rStr
) SAL_OVERRIDE
;
167 virtual SwFieldType
* ChgTyp( SwFieldType
* ) SAL_OVERRIDE
;
169 virtual bool QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhichId
) const SAL_OVERRIDE
;
170 virtual bool PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhichId
) SAL_OVERRIDE
;
172 sal_IntPtr
GetHandle() const { return m_nHandle
; }
174 virtual OUString
GetDescription() const SAL_OVERRIDE
;
177 inline OUString
SwAuthEntry::GetAuthorField(ToxAuthorityField ePos
) const
179 SAL_WARN_IF(AUTH_FIELD_END
<= ePos
, "sw", "wrong index");
180 return aAuthFields
[ePos
];
182 inline void SwAuthEntry::SetAuthorField(ToxAuthorityField ePos
, const OUString
& rField
)
184 SAL_WARN_IF(AUTH_FIELD_END
<= ePos
, "sw", "wrong index");
185 if(AUTH_FIELD_END
> ePos
)
186 aAuthFields
[ePos
] = rField
;
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */