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 _FLDMGR_HXX
20 : #define _FLDMGR_HXX
21 :
22 : #include <tools/string.hxx>
23 : #include "swdllapi.h"
24 : #include "swtypes.hxx"
25 : #include <com/sun/star/uno/Reference.h>
26 : #include <com/sun/star/uno/Any.h>
27 : #include <vector>
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 : class Window;
46 :
47 : /*--------------------------------------------------------------------
48 : Description: the groups of fields
49 : --------------------------------------------------------------------*/
50 : enum SwFldGroups
51 : {
52 : GRP_DOC,
53 : GRP_FKT,
54 : GRP_REF,
55 : GRP_REG,
56 : GRP_DB,
57 : GRP_VAR
58 : };
59 :
60 : struct SwFldGroupRgn
61 : {
62 : sal_uInt16 nStart;
63 : sal_uInt16 nEnd;
64 : };
65 :
66 : /*--------------------------------------------------------------------
67 : Description: the field manager handles the insertation of fields
68 : with command strings
69 : --------------------------------------------------------------------*/
70 0 : struct SwInsertFld_Data
71 : {
72 : sal_uInt16 nTypeId;
73 : sal_uInt16 nSubType;
74 : const String sPar1;
75 : const String sPar2;
76 : sal_uLong nFormatId;
77 : SwWrtShell* pSh;
78 : sal_Unicode cSeparator;
79 : sal_Bool bIsAutomaticLanguage;
80 : ::com::sun::star::uno::Any aDBDataSource;
81 : ::com::sun::star::uno::Any aDBConnection;
82 : ::com::sun::star::uno::Any aDBColumn;
83 : Window* pParent; // parent dialog used for SwWrtShell::StartInputFldDlg()
84 :
85 0 : SwInsertFld_Data(sal_uInt16 nType, sal_uInt16 nSub, const String& rPar1, const String& rPar2,
86 : sal_uLong nFmtId, SwWrtShell* pShell = NULL, sal_Unicode cSep = ' ', sal_Bool bIsAutoLanguage = sal_True) :
87 : nTypeId(nType),
88 : nSubType(nSub),
89 : sPar1(rPar1),
90 : sPar2(rPar2),
91 : nFormatId(nFmtId),
92 : pSh(pShell),
93 : cSeparator(cSep),
94 : bIsAutomaticLanguage(bIsAutoLanguage),
95 0 : pParent(0) {}
96 :
97 : SwInsertFld_Data() :
98 : pSh(0),
99 : cSeparator(' '),
100 : bIsAutomaticLanguage(sal_True){}
101 :
102 : };
103 :
104 : class SW_DLLPUBLIC SwFldMgr
105 : {
106 : private:
107 : SwField* pCurFld;
108 : SbModule* pModule;
109 : const SvxMacroItem* pMacroItem;
110 : SwWrtShell* pWrtShell; // can be ZERO too!
111 : String aCurPar1;
112 : String aCurPar2;
113 : String sCurFrame;
114 :
115 : String sMacroPath;
116 : String sMacroName;
117 :
118 : sal_uLong nCurFmt;
119 : sal_Bool bEvalExp;
120 :
121 : SW_DLLPRIVATE sal_uInt16 GetCurrLanguage() const;
122 :
123 : com::sun::star::uno::Reference<com::sun::star::container::XNameAccess> xDBContext;
124 : com::sun::star::uno::Reference<com::sun::star::text::XNumberingTypeInfo> xNumberingInfo;
125 : SW_DLLPRIVATE com::sun::star::uno::Reference<com::sun::star::text::XNumberingTypeInfo> GetNumberingInfo()const;
126 :
127 : public:
128 : SwFldMgr(SwWrtShell* pSh = 0);
129 : ~SwFldMgr();
130 :
131 0 : void SetWrtShell( SwWrtShell* pShell )
132 0 : { pWrtShell = pShell; }
133 :
134 : // insert field using TypeID (TYP_ ...)
135 : sal_Bool InsertFld( const SwInsertFld_Data& rData, SwPaM* pPam = 0 );
136 :
137 : // change the current field directly
138 : void UpdateCurFld(sal_uLong nFormat,
139 : const String& rPar1,
140 : const String& rPar2,
141 : SwField * _pField = 0); // #111840#
142 :
143 : inline const String& GetCurFldPar1() const;
144 : inline const String& GetCurFldPar2() const;
145 : inline sal_uLong GetCurFldFmt() const;
146 :
147 : // determine a field
148 : SwField* GetCurFld();
149 :
150 : void InsertFldType(SwFieldType& rType);
151 :
152 : sal_Bool ChooseMacro(const String &rSelMacro = aEmptyStr);
153 : void SetMacroPath(const String& rPath);
154 0 : inline const String& GetMacroPath() const { return (sMacroPath); }
155 0 : inline const String& GetMacroName() const { return (sMacroName); }
156 : inline void SetMacroModule(SbModule* pMod) { pModule = pMod; }
157 :
158 : // previous and next of the same type
159 : sal_Bool GoNextPrev( sal_Bool bNext = sal_True, SwFieldType* pTyp = 0 );
160 0 : sal_Bool GoNext( SwFieldType* pTyp = 0 ) { return GoNextPrev( sal_True, pTyp ); }
161 0 : sal_Bool GoPrev( SwFieldType* pTyp = 0 ) { return GoNextPrev( sal_False, pTyp ); }
162 :
163 : // query values from database fields (BASIC )
164 : // String GetDataBaseFieldValue(const String &rDBName, const String &rFieldName, SwWrtShell* pSh);
165 : sal_Bool IsDBNumeric(const String& rDBName, const String& rTblQryName,
166 : sal_Bool bIsTable, const String& rFldName);
167 :
168 : // organise RefMark with names
169 : sal_Bool CanInsertRefMark( const String& rStr );
170 :
171 :
172 : // access to field types via ResId
173 : sal_uInt16 GetFldTypeCount(sal_uInt16 nResId = USHRT_MAX) const;
174 : SwFieldType* GetFldType(sal_uInt16 nResId, sal_uInt16 nId = 0) const;
175 : SwFieldType* GetFldType(sal_uInt16 nResId, const String& rName) const;
176 :
177 : void RemoveFldType(sal_uInt16 nResId, const String& rName);
178 :
179 : // access via TypeId from the dialog
180 : // Ids for a range of fields
181 : const SwFldGroupRgn& GetGroupRange(sal_Bool bHtmlMode, sal_uInt16 nGrpId) const;
182 : sal_uInt16 GetGroup(sal_Bool bHtmlMode, sal_uInt16 nTypeId, sal_uInt16 nSubType = 0) const;
183 :
184 : // the current field's TypeId
185 : sal_uInt16 GetCurTypeId() const;
186 :
187 : // TypeId for a concrete position in the list
188 : static sal_uInt16 GetTypeId(sal_uInt16 nPos);
189 : // name of the type in the list of fields
190 : static const String& GetTypeStr(sal_uInt16 nPos);
191 :
192 : // Pos in the list of fields
193 : static sal_uInt16 GetPos(sal_uInt16 nTypeId);
194 :
195 : // subtypes to a type
196 : sal_Bool GetSubTypes(sal_uInt16 nId, std::vector<rtl::OUString>& rToFill);
197 :
198 : // format to a type
199 : sal_uInt16 GetFormatCount(sal_uInt16 nTypeId, sal_Bool bIsText, sal_Bool bHtmlMode = sal_False) const;
200 : String GetFormatStr(sal_uInt16 nTypeId, sal_uLong nFormatId) const;
201 : sal_uInt16 GetFormatId(sal_uInt16 nTypeId, sal_uLong nFormatId) const;
202 : sal_uLong GetDefaultFormat(sal_uInt16 nTypeId, sal_Bool bIsText, SvNumberFormatter* pFormatter, double* pVal = 0L);
203 :
204 : // turn off evaluation of expression fields for insertation
205 : // of many expressino fields (see labels)
206 : //
207 : inline void SetEvalExpFlds(sal_Bool bEval);
208 : void EvalExpFlds(SwWrtShell* pSh = NULL);
209 : };
210 :
211 0 : inline void SwFldMgr::SetEvalExpFlds(sal_Bool bEval)
212 0 : { bEvalExp = bEval; }
213 :
214 0 : inline const String& SwFldMgr::GetCurFldPar1() const
215 0 : { return aCurPar1; }
216 :
217 0 : inline const String& SwFldMgr::GetCurFldPar2() const
218 0 : { return aCurPar2; }
219 :
220 : inline sal_uLong SwFldMgr::GetCurFldFmt() const
221 : { return nCurFmt; }
222 :
223 : #endif
224 :
225 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|