LibreOffice Module sw (master) 1
fldpage.cxx
Go to the documentation of this file.
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
20#include <svl/stritem.hxx>
21#include <sfx2/request.hxx>
22#include <sfx2/htmlmode.hxx>
23#include <sfx2/viewfrm.hxx>
24#include <dbfld.hxx>
25#include <flddat.hxx>
26#include <fmtfld.hxx>
27#include <viewopt.hxx>
28#include <fldedt.hxx>
29#include <docsh.hxx>
30#include <swmodule.hxx>
31#include <view.hxx>
32#include <wrtsh.hxx>
33#include <expfld.hxx>
34#include <fldtdlg.hxx>
35#include "fldpage.hxx"
36#include <docufld.hxx>
37#include <cmdid.h>
38#include <sfx2/bindings.hxx>
39#include <o3tl/string_view.hxx>
40
41using namespace ::com::sun::star;
42
43// note: pAttrSet may be null if the dialog is restored on startup
44SwFieldPage::SwFieldPage(weld::Container* pPage, weld::DialogController* pController, const OUString& rUIXMLDescription,
45 const OString& rID, const SfxItemSet *pAttrSet)
46 : SfxTabPage(pPage, pController, rUIXMLDescription, rID, pAttrSet)
47 , m_pCurField(nullptr)
48 , m_pWrtShell(nullptr)
49 , m_nTypeSel(-1)
50 , m_nSelectionSel(-1)
51 , m_bFieldEdit(false)
52 , m_bInsert(true)
53 , m_bFieldDlgHtmlMode(false)
54 , m_bRefresh(false)
55 , m_bFirstHTMLInit(true)
56{
57}
58
60{
61}
62
63// initialise TabPage
65{
66 SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current());
67 bool bNewMode = 0 != (::GetHtmlMode(pDocSh) & HTMLMODE_ON);
68
69 m_bFieldEdit = nullptr == dynamic_cast<SwFieldDlg*>(GetDialogController());
70
71 // newly initialise FieldManager. important for
72 // Dok-Switch (fldtdlg:ReInitTabPage)
74
75 if( bNewMode == m_bFieldDlgHtmlMode )
76 return;
77
78 m_bFieldDlgHtmlMode = bNewMode;
79
80 // initialise Rangelistbox
82 return;
83
84 m_bFirstHTMLInit = false;
86 if(! pSh)
87 pSh = ::GetActiveWrtShell();
88 if(pSh)
89 {
90 SwDoc* pDoc = pSh->GetDoc();
92 "HTML_ON", 1));
94 "HTML_OFF", 1));
95 }
96}
97
98// newly initialise page
100{
102}
103
104// complete reset; edit new field
105void SwFieldPage::EditNewField( bool bOnlyActivate )
106{
107 if (!bOnlyActivate)
108 m_nTypeSel = -1;
109 m_nSelectionSel = -1;
110 m_bRefresh = true;
111 Reset(nullptr);
112 m_bRefresh = false;
113}
114
115// insert field
116void SwFieldPage::InsertField(SwFieldTypesEnum nTypeId, sal_uInt16 nSubType, const OUString& rPar1,
117 const OUString& rPar2, sal_uInt32 nFormatId,
118 sal_Unicode cSeparator, bool bIsAutomaticLanguage)
119{
120 SwView* pView = GetActiveView();
122
123 if (!IsFieldEdit()) // insert new field
124 {
125 SwInsertField_Data aData(nTypeId, nSubType, rPar1, rPar2, nFormatId, nullptr, cSeparator, bIsAutomaticLanguage );
126 //#i26566# provide parent for SwWrtShell::StartInputFieldDlg
127 aData.m_pParent = &GetDialogController()->GetOKButton();
129
130 uno::Reference< frame::XDispatchRecorder > xRecorder =
132 if ( xRecorder.is() )
133 {
134 bool bRecordDB = SwFieldTypesEnum::Database == nTypeId ||
139
140 SfxRequest aReq( pView->GetViewFrame(),
141 bRecordDB ? FN_INSERT_DBFIELD : FN_INSERT_FIELD );
142 if(bRecordDB)
143 {
144 sal_Int32 nIdx{ 0 };
146 (FN_INSERT_DBFIELD,rPar1.getToken(0, DB_DELIM, nIdx)));
148 (FN_PARAM_1,rPar1.getToken(0, DB_DELIM, nIdx)));
150 (FN_PARAM_3, o3tl::toInt32(o3tl::getToken(rPar1, 0, DB_DELIM, nIdx))));
152 (FN_PARAM_2,rPar1.getToken(0, DB_DELIM, nIdx)));
153 }
154 else
155 {
158 (FN_PARAM_3, OUString(cSeparator)));
160 }
161 aReq.AppendItem(SfxUInt16Item(FN_PARAM_FIELD_TYPE , static_cast<sal_uInt16>(nTypeId)));
162 aReq.AppendItem(SfxStringItem(FN_PARAM_FIELD_CONTENT, rPar2));
164 aReq.Done();
165 }
166
167 }
168 else // change field
169 {
170 std::unique_ptr<SwField> pTmpField = m_pCurField->CopyField();
171
172 OUString sPar1(rPar1);
173 OUString sPar2(rPar2);
174 switch( nTypeId )
175 {
178 nSubType = static_cast< sal_uInt16 >(((nTypeId == SwFieldTypesEnum::Date) ? DATEFLD : TIMEFLD) |
179 ((nSubType == DATE_VAR) ? 0 : FIXEDFLD));
180 break;
181
186 {
187 sal_Int32 nPos = 0;
189
190 aData.sDataSource = rPar1.getToken(0, DB_DELIM, nPos);
191 aData.sCommand = rPar1.getToken(0, DB_DELIM, nPos);
192 aData.nCommandType = o3tl::toInt32(o3tl::getToken(rPar1, 0, DB_DELIM, nPos));
193 sPar1 = rPar1.copy(nPos);
194
195 static_cast<SwDBNameInfField*>(pTmpField.get())->SetDBData(aData);
196 }
197 break;
198
200 {
202 sal_Int32 nIdx{ 0 };
203 aData.sDataSource = rPar1.getToken(0, DB_DELIM, nIdx);
204 aData.sCommand = rPar1.getToken(0, DB_DELIM, nIdx);
205 aData.nCommandType = o3tl::toInt32(o3tl::getToken(rPar1, 0, DB_DELIM, nIdx));
206 OUString sColumn = rPar1.getToken(0, DB_DELIM, nIdx);
207
208 auto pOldType = static_cast<SwDBFieldType*>(pTmpField->GetTyp());
209 auto pType = static_cast<SwDBFieldType*>(pSh->InsertFieldType(SwDBFieldType(pSh->GetDoc(), sColumn, aData)));
210 if(auto pFormatField = pOldType->FindFormatForField(m_pCurField))
211 {
212 pFormatField->RegisterToFieldType(*pType);
213 pTmpField->ChgTyp(pType);
214 }
215 }
216 break;
217
219 {
220 SwSetExpFieldType* pTyp = static_cast<SwSetExpFieldType*>(pTmpField->GetTyp());
221 pTyp->SetOutlineLvl( static_cast< sal_uInt8 >(nSubType & 0xff));
222 pTyp->SetDelimiter(OUString(cSeparator));
223
225 }
226 break;
227
229 {
230 // User- or SetField ?
231 if (m_aMgr.GetFieldType(SwFieldIds::User, sPar1) == nullptr &&
232 !(pTmpField->GetSubType() & INP_TXT)) // SETEXPFLD
233 {
234 SwSetExpField* pField = static_cast<SwSetExpField*>(pTmpField.get());
235 pField->SetPromptText(sPar2);
236 sPar2 = pField->GetPar2();
237 }
238 }
239 break;
241 {
242 if( nSubType == nsSwDocInfoSubType::DI_CUSTOM )
243 {
244 SwDocInfoField* pDocInfo = static_cast<SwDocInfoField*>( pTmpField.get() );
245 pDocInfo->SetName( rPar1 );
246 }
247 }
248 break;
249 default: break;
250 }
251
252 pSh->StartAllAction();
253
254 pTmpField->SetSubType(nSubType);
255 pTmpField->SetAutomaticLanguage(bIsAutomaticLanguage);
256
257 m_aMgr.UpdateCurField( nFormatId, sPar1, sPar2, std::move(pTmpField) );
258
260
261 switch (nTypeId)
262 {
266 break;
267 default: break;
268 }
269
271 pSh->EndAllAction();
272 }
273}
274
276{
277 if (rLst1.n_children())
278 m_aLstStrArr[ 0 ] = rLst1.get_selected_text();
279 else
280 m_aLstStrArr[ 0 ].clear();
281 m_aLstStrArr[ 1 ].clear();
282 m_aLstStrArr[ 2 ].clear();
283}
284
286{
287 sal_Int32 nPos = 0;
288 if (rLst1.n_children() && !m_aLstStrArr[ 0 ].isEmpty() &&
289 -1 != ( nPos = rLst1.find_text(m_aLstStrArr[ 0 ] ) ) )
290 rLst1.select( nPos );
291}
292
293// Insert new fields
294IMPL_LINK( SwFieldPage, TreeViewInsertHdl, weld::TreeView&, rBox, bool )
295{
296 InsertHdl(&rBox);
297 return true;
298}
299
301{
302 if (SwFieldDlg *pDlg = dynamic_cast<SwFieldDlg*>(GetDialogController()))
303 {
304 pDlg->InsertHdl();
305
306 if (pBtn)
307 pBtn->grab_focus(); // because of InputField-Dlg
308 }
309 else
310 {
311 SwFieldEditDlg *pEditDlg = static_cast<SwFieldEditDlg*>(GetDialogController());
312 pEditDlg->InsertHdl();
313 }
314}
315
316// enable/disable "Insert"-Button
318{
319 if (SwFieldDlg *pDlg = dynamic_cast<SwFieldDlg*>(GetDialogController()))
320 {
321 if (pDlg->GetCurTabPage() == this)
322 pDlg->EnableInsert(bEnable);
323 }
324 else
325 {
326 SwFieldEditDlg *pEditDlg = static_cast<SwFieldEditDlg*>(GetDialogController());
327 pEditDlg->EnableInsert(bEnable);
328 }
329
330 m_bInsert = bEnable;
331}
332
334{
335 InsertHdl(nullptr);
336 return true;
337}
338
340{
341 m_pWrtShell = pShell;
342 m_aMgr.SetWrtShell( pShell );
343}
344
345/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const css::uno::Reference< css::frame::XDispatchRecorder > & GetRecorder() const
static SfxObjectShell * Current()
virtual weld::Button & GetOKButton() const=0
void AppendItem(const SfxPoolItem &)
void Done(bool bRemove=false)
virtual void Reset(const SfxItemSet *)
SfxOkDialogController * GetDialogController() const
SfxBindings & GetBindings()
SfxViewFrame * GetViewFrame() const
void SetName(const OUString &rName)
Definition: docufld.hxx:540
Definition: doc.hxx:194
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
void SetUndoNoResetModified()
Definition: edws.cxx:80
SwFieldType * InsertFieldType(const SwFieldType &)
insert field type
Definition: edfld.cxx:338
void EndAllAction()
Definition: edws.cxx:97
void InsertHdl()
Definition: fldedt.cxx:238
void EnableInsert(bool bEnable)
Definition: fldedt.cxx:231
void UpdateCurField(sal_uInt32 nFormat, const OUString &rPar1, const OUString &rPar2, std::unique_ptr< SwField > _pField=nullptr)
Definition: fldmgr.cxx:1536
void EvalExpFields(SwWrtShell *pSh)
Definition: fldmgr.cxx:1735
SwFieldType * GetFieldType(SwFieldIds nResId, size_t nField=0) const
Definition: fldmgr.cxx:415
void SetWrtShell(SwWrtShell *pShell)
Definition: fldmgr.hxx:124
bool InsertField(SwInsertField_Data &rData)
Definition: fldmgr.cxx:895
SwField * GetCurField()
Definition: fldmgr.cxx:430
void InsertField(SwFieldTypesEnum nTypeId, sal_uInt16 nSubType, const OUString &rPar1, const OUString &rPar2, sal_uInt32 nFormatId, sal_Unicode cDelim=' ', bool bIsAutomaticLanguage=true)
Definition: fldpage.cxx:116
void SetWrtShell(SwWrtShell *m_pWrtShell)
Definition: fldpage.cxx:339
void Init()
Definition: fldpage.cxx:64
bool m_bRefresh
Definition: fldpage.hxx:40
void SavePos(const weld::TreeView &rLst1)
Definition: fldpage.cxx:275
bool m_bInsert
Definition: fldpage.hxx:38
virtual ~SwFieldPage() override
Definition: fldpage.cxx:59
void EditNewField(bool bOnlyActivate=false)
Definition: fldpage.cxx:105
OUString m_aLstStrArr[coLBCount]
Definition: fldpage.hxx:31
bool IsFieldEdit() const
Definition: fldpage.hxx:62
bool m_bFieldEdit
Definition: fldpage.hxx:37
SwField * m_pCurField
Definition: fldpage.hxx:33
void RestorePos(weld::TreeView &rLst1)
Definition: fldpage.cxx:285
void InsertHdl(weld::Widget *)
Definition: fldpage.cxx:300
SwWrtShell * m_pWrtShell
Definition: fldpage.hxx:34
void EnableInsert(bool bEnable)
Definition: fldpage.cxx:317
SwFieldMgr m_aMgr
Definition: fldpage.hxx:32
bool m_bFieldDlgHtmlMode
Definition: fldpage.hxx:39
virtual void Activate() override
Definition: fldpage.cxx:99
sal_Int32 m_nTypeSel
Definition: fldpage.hxx:35
sal_Int32 m_nSelectionSel
Definition: fldpage.hxx:36
SwFieldPage(weld::Container *pPage, weld::DialogController *pController, const OUString &rUIXMLDescription, const OString &rID, const SfxItemSet *pAttrSet)
Definition: fldpage.cxx:44
bool m_bFirstHTMLInit
Definition: fldpage.hxx:41
std::unique_ptr< SwField > CopyField() const
Definition: fldbas.cxx:504
void SetOutlineLvl(sal_uInt8 n)
Definition: expfld.hxx:184
void SetDelimiter(const OUString &s)
Definition: expfld.hxx:182
virtual OUString GetPar2() const override
Query formula.
Definition: expfld.cxx:1028
void SetPromptText(const OUString &rStr)
Definition: expfld.hxx:260
SwDoc * GetDoc() const
Definition: viewsh.hxx:290
Definition: view.hxx:146
SwWrtShell * GetWrtShellPtr() const
Definition: view.hxx:417
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
virtual int find_text(const OUString &rText) const=0
virtual OUString get_selected_text() const=0
virtual int n_children() const=0
virtual void select(int pos)=0
virtual void grab_focus()=0
#define FN_INSERT_DBFIELD
Definition: cmdid.h:209
#define FN_INSERT_FIELD
Definition: cmdid.h:205
#define FN_PARAM_FIELD_SUBTYPE
Definition: cmdid.h:804
#define FN_PARAM_FIELD_FORMAT
Definition: cmdid.h:805
#define FN_PARAM_FIELD_TYPE
Definition: cmdid.h:803
SwFieldTypesEnum
List of FieldTypes at UI.
Definition: fldbas.hxx:94
@ FIXEDFLD
Definition: fldbas.hxx:229
@ DATEFLD
Definition: fldbas.hxx:230
@ TIMEFLD
Definition: fldbas.hxx:231
@ INP_TXT
Definition: fldbas.hxx:218
@ DATE_VAR
Definition: flddat.hxx:33
IMPL_LINK(SwFieldPage, TreeViewInsertHdl, weld::TreeView &, rBox, bool)
Definition: fldpage.cxx:294
IMPL_LINK_NOARG(SwFieldPage, NumFormatHdl, weld::TreeView &, bool)
Definition: fldpage.cxx:333
HTMLMODE_ON
sal_uInt16 nPos
constexpr OUStringLiteral aData
Definition: ww8scan.hxx:48
const SwDocInfoSubType DI_CUSTOM
Definition: docufld.hxx:80
const SwGetSetExpType GSE_SEQ
Sequence.
Definition: fldbas.hxx:205
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
SwView * GetActiveView()
Definition: swmodul1.cxx:116
SwWrtShell * GetActiveWrtShell()
Definition: swmodul1.cxx:108
#define DB_DELIM
Definition: swtypes.hxx:130
unsigned char sal_uInt8
sal_uInt16 sal_Unicode
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:332