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_SW_SOURCE_UIBASE_INC_FLDMGR_HXX
20 : #define INCLUDED_SW_SOURCE_UIBASE_INC_FLDMGR_HXX
21 :
22 : #include "swdllapi.h"
23 : #include "swtypes.hxx"
24 : #include <com/sun/star/uno/Reference.h>
25 : #include <com/sun/star/uno/Any.h>
26 : #include <vector>
27 : #include <vcl/vclptr.hxx>
28 :
29 : namespace com{namespace sun{namespace star{
30 : namespace container{
31 : class XNameAccess;
32 : }
33 : namespace text{
34 : class XNumberingTypeInfo;
35 : }
36 : }}}
37 :
38 : class SwWrtShell;
39 : class SwField;
40 : class SwFieldType;
41 : class SwPaM;
42 : class SbModule;
43 : class SvxMacroItem;
44 : class SvNumberFormatter;
45 : namespace vcl { class Window; }
46 :
47 : // the groups of fields
48 : enum SwFieldGroups
49 : {
50 : GRP_DOC,
51 : GRP_FKT,
52 : GRP_REF,
53 : GRP_REG,
54 : GRP_DB,
55 : GRP_VAR
56 : };
57 :
58 : struct SwFieldGroupRgn
59 : {
60 : sal_uInt16 nStart;
61 : sal_uInt16 nEnd;
62 : };
63 :
64 : // the field manager handles the insertation of fields
65 : // with command strings
66 0 : struct SwInsertField_Data
67 : {
68 : sal_uInt16 m_nTypeId;
69 : sal_uInt16 m_nSubType;
70 : const OUString m_sPar1;
71 : const OUString m_sPar2;
72 : sal_uLong m_nFormatId;
73 : SwWrtShell* m_pSh;
74 : sal_Unicode m_cSeparator;
75 : bool m_bIsAutomaticLanguage;
76 : ::com::sun::star::uno::Any m_aDBDataSource;
77 : ::com::sun::star::uno::Any m_aDBConnection;
78 : ::com::sun::star::uno::Any m_aDBColumn;
79 : VclPtr<vcl::Window> m_pParent; // parent dialog used for SwWrtShell::StartInputFieldDlg()
80 :
81 0 : SwInsertField_Data(sal_uInt16 nType, sal_uInt16 nSub, const OUString& rPar1, const OUString& rPar2,
82 : sal_uLong nFormatId, SwWrtShell* pShell = NULL, sal_Unicode cSep = ' ', bool bIsAutoLanguage = true) :
83 : m_nTypeId(nType),
84 : m_nSubType(nSub),
85 : m_sPar1(rPar1),
86 : m_sPar2(rPar2),
87 : m_nFormatId(nFormatId),
88 : m_pSh(pShell),
89 : m_cSeparator(cSep),
90 : m_bIsAutomaticLanguage(bIsAutoLanguage),
91 0 : m_pParent(0) {}
92 :
93 : SwInsertField_Data() :
94 : m_pSh(0),
95 : m_cSeparator(' '),
96 : m_bIsAutomaticLanguage(true){}
97 : };
98 :
99 : class SW_DLLPUBLIC SwFieldMgr
100 : {
101 : private:
102 : SwField* pCurField;
103 : SbModule* pModule;
104 : const SvxMacroItem* pMacroItem;
105 : SwWrtShell* pWrtShell; // can be ZERO too!
106 : OUString aCurPar1;
107 : OUString aCurPar2;
108 : OUString sCurFrame;
109 :
110 : OUString sMacroPath;
111 : OUString sMacroName;
112 :
113 : sal_uLong nCurFormat;
114 : bool bEvalExp;
115 :
116 : SAL_DLLPRIVATE sal_uInt16 GetCurrLanguage() const;
117 :
118 : com::sun::star::uno::Reference<com::sun::star::container::XNameAccess> xDBContext;
119 : com::sun::star::uno::Reference<com::sun::star::text::XNumberingTypeInfo> xNumberingInfo;
120 : SAL_DLLPRIVATE com::sun::star::uno::Reference<com::sun::star::text::XNumberingTypeInfo> GetNumberingInfo()const;
121 :
122 : public:
123 : explicit SwFieldMgr(SwWrtShell* pSh = 0);
124 : ~SwFieldMgr();
125 :
126 0 : void SetWrtShell( SwWrtShell* pShell )
127 0 : { pWrtShell = pShell; }
128 :
129 : // insert field using TypeID (TYP_ ...)
130 : bool InsertField( const SwInsertField_Data& rData );
131 :
132 : // change the current field directly
133 : void UpdateCurField(sal_uLong nFormat,
134 : const OUString& rPar1,
135 : const OUString& rPar2,
136 : SwField * _pField = 0); // #111840#
137 :
138 0 : OUString GetCurFieldPar1() const { return aCurPar1; }
139 0 : OUString GetCurFieldPar2() const { return aCurPar2; }
140 : inline sal_uLong GetCurFieldFormat() const;
141 :
142 : // determine a field
143 : SwField* GetCurField();
144 :
145 : void InsertFieldType(SwFieldType& rType);
146 :
147 : bool ChooseMacro(const OUString &rSelMacro = OUString());
148 : void SetMacroPath(const OUString& rPath);
149 0 : inline OUString GetMacroPath() const { return sMacroPath; }
150 0 : inline OUString GetMacroName() const { return sMacroName; }
151 : inline void SetMacroModule(SbModule* pMod) { pModule = pMod; }
152 :
153 : // previous and next of the same type
154 : bool GoNextPrev( bool bNext = true, SwFieldType* pTyp = 0 );
155 0 : bool GoNext( SwFieldType* pTyp = 0 ) { return GoNextPrev( true, pTyp ); }
156 0 : bool GoPrev( SwFieldType* pTyp = 0 ) { return GoNextPrev( false, pTyp ); }
157 :
158 : // query values from database fields (BASIC )
159 : // String GetDataBaseFieldValue(const String &rDBName, const String &rFieldName, SwWrtShell* pSh);
160 : bool IsDBNumeric(const OUString& rDBName, const OUString& rTableQryName,
161 : bool bIsTable, const OUString& rFieldName);
162 :
163 : // organise RefMark with names
164 : bool CanInsertRefMark( const OUString& rStr );
165 :
166 : // access to field types via ResId
167 : size_t GetFieldTypeCount(sal_uInt16 nResId = USHRT_MAX) const;
168 : SwFieldType* GetFieldType(sal_uInt16 nResId, size_t nField = 0) const;
169 : SwFieldType* GetFieldType(sal_uInt16 nResId, const OUString& rName) const;
170 :
171 : void RemoveFieldType(sal_uInt16 nResId, const OUString& rName);
172 :
173 : // access via TypeId from the dialog
174 : // Ids for a range of fields
175 : static const SwFieldGroupRgn& GetGroupRange(bool bHtmlMode, sal_uInt16 nGrpId);
176 : static sal_uInt16 GetGroup(bool bHtmlMode, sal_uInt16 nTypeId, sal_uInt16 nSubType = 0);
177 :
178 : // the current field's TypeId
179 : sal_uInt16 GetCurTypeId() const;
180 :
181 : // TypeId for a concrete position in the list
182 : static sal_uInt16 GetTypeId(sal_uInt16 nPos);
183 : // name of the type in the list of fields
184 : static OUString GetTypeStr(sal_uInt16 nPos);
185 :
186 : // Pos in the list of fields
187 : static sal_uInt16 GetPos(sal_uInt16 nTypeId);
188 :
189 : // subtypes to a type
190 : bool GetSubTypes(sal_uInt16 nId, std::vector<OUString>& rToFill);
191 :
192 : // format to a type
193 : sal_uInt16 GetFormatCount(sal_uInt16 nTypeId, bool bIsText, bool bHtmlMode = false) const;
194 : OUString GetFormatStr(sal_uInt16 nTypeId, sal_uLong nFormatId) const;
195 : sal_uInt16 GetFormatId(sal_uInt16 nTypeId, sal_uLong nFormatId) const;
196 : sal_uLong GetDefaultFormat(sal_uInt16 nTypeId, bool bIsText, SvNumberFormatter* pFormatter, double* pVal = 0L);
197 :
198 : // turn off evaluation of expression fields for insertation
199 : // of many expressino fields (see labels)
200 :
201 : inline void SetEvalExpFields(bool bEval);
202 : void EvalExpFields(SwWrtShell* pSh = NULL);
203 : };
204 :
205 0 : inline void SwFieldMgr::SetEvalExpFields(bool bEval)
206 0 : { bEvalExp = bEval; }
207 :
208 : inline sal_uLong SwFieldMgr::GetCurFieldFormat() const
209 : { return nCurFormat; }
210 :
211 : #endif
212 :
213 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|