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 (!pSh)
124 return;
125
126 if (!IsFieldEdit()) // insert new field
127 {
128 SwInsertField_Data aData(nTypeId, nSubType, rPar1, rPar2, nFormatId, nullptr, cSeparator, bIsAutomaticLanguage );
129 //#i26566# provide parent for SwWrtShell::StartInputFieldDlg
130 aData.m_pParent = &GetDialogController()->GetOKButton();
132
133 uno::Reference< frame::XDispatchRecorder > xRecorder =
135 if ( xRecorder.is() )
136 {
137 bool bRecordDB = SwFieldTypesEnum::Database == nTypeId ||
142
143 SfxRequest aReq(pView->GetViewFrame(),
144 bRecordDB ? FN_INSERT_DBFIELD : FN_INSERT_FIELD);
145 if(bRecordDB)
146 {
147 sal_Int32 nIdx{ 0 };
149 (FN_INSERT_DBFIELD,rPar1.getToken(0, DB_DELIM, nIdx)));
151 (FN_PARAM_1,rPar1.getToken(0, DB_DELIM, nIdx)));
153 (FN_PARAM_3, o3tl::toInt32(o3tl::getToken(rPar1, 0, DB_DELIM, nIdx))));
155 (FN_PARAM_2,rPar1.getToken(0, DB_DELIM, nIdx)));
156 }
157 else
158 {
161 (FN_PARAM_3, OUString(cSeparator)));
163 }
164 aReq.AppendItem(SfxUInt16Item(FN_PARAM_FIELD_TYPE , static_cast<sal_uInt16>(nTypeId)));
165 aReq.AppendItem(SfxStringItem(FN_PARAM_FIELD_CONTENT, rPar2));
167 aReq.Done();
168 }
169
170 }
171 else // change field
172 {
173 std::unique_ptr<SwField> pTmpField = m_pCurField->CopyField();
174
175 OUString sPar1(rPar1);
176 OUString sPar2(rPar2);
177 switch( nTypeId )
178 {
181 nSubType = static_cast< sal_uInt16 >(((nTypeId == SwFieldTypesEnum::Date) ? DATEFLD : TIMEFLD) |
182 ((nSubType == DATE_VAR) ? 0 : FIXEDFLD));
183 break;
184
189 {
190 sal_Int32 nPos = 0;
192
193 aData.sDataSource = rPar1.getToken(0, DB_DELIM, nPos);
194 aData.sCommand = rPar1.getToken(0, DB_DELIM, nPos);
195 aData.nCommandType = o3tl::toInt32(o3tl::getToken(rPar1, 0, DB_DELIM, nPos));
196 sPar1 = rPar1.copy(nPos);
197
198 static_cast<SwDBNameInfField*>(pTmpField.get())->SetDBData(aData);
199 }
200 break;
201
203 {
205 sal_Int32 nIdx{ 0 };
206 aData.sDataSource = rPar1.getToken(0, DB_DELIM, nIdx);
207 aData.sCommand = rPar1.getToken(0, DB_DELIM, nIdx);
208 aData.nCommandType = o3tl::toInt32(o3tl::getToken(rPar1, 0, DB_DELIM, nIdx));
209 OUString sColumn = rPar1.getToken(0, DB_DELIM, nIdx);
210
211 auto pOldType = static_cast<SwDBFieldType*>(pTmpField->GetTyp());
212 auto pType = static_cast<SwDBFieldType*>(pSh->InsertFieldType(SwDBFieldType(pSh->GetDoc(), sColumn, aData)));
213 if(auto pFormatField = pOldType->FindFormatForField(m_pCurField))
214 {
215 pFormatField->RegisterToFieldType(*pType);
216 pTmpField->ChgTyp(pType);
217 }
218 }
219 break;
220
222 {
223 SwSetExpFieldType* pTyp = static_cast<SwSetExpFieldType*>(pTmpField->GetTyp());
224 pTyp->SetOutlineLvl( static_cast< sal_uInt8 >(nSubType & 0xff));
225 pTyp->SetDelimiter(OUString(cSeparator));
226
228 }
229 break;
230
232 {
233 // User- or SetField ?
234 if (m_aMgr.GetFieldType(SwFieldIds::User, sPar1) == nullptr &&
235 !(pTmpField->GetSubType() & INP_TXT)) // SETEXPFLD
236 {
237 SwSetExpField* pField = static_cast<SwSetExpField*>(pTmpField.get());
238 pField->SetPromptText(sPar2);
239 sPar2 = pField->GetPar2();
240 }
241 }
242 break;
244 {
245 if( nSubType == nsSwDocInfoSubType::DI_CUSTOM )
246 {
247 SwDocInfoField* pDocInfo = static_cast<SwDocInfoField*>( pTmpField.get() );
248 pDocInfo->SetName( rPar1 );
249 }
250 }
251 break;
252 default: break;
253 }
254
255 pSh->StartAllAction();
256
257 pTmpField->SetSubType(nSubType);
258 pTmpField->SetAutomaticLanguage(bIsAutomaticLanguage);
259
260 m_aMgr.UpdateCurField( nFormatId, sPar1, sPar2, std::move(pTmpField) );
261
263
264 switch (nTypeId)
265 {
269 break;
270 default: break;
271 }
272
274 pSh->EndAllAction();
275 }
276}
277
279{
280 if (rLst1.n_children())
281 m_aLstStrArr[ 0 ] = rLst1.get_selected_text();
282 else
283 m_aLstStrArr[ 0 ].clear();
284 m_aLstStrArr[ 1 ].clear();
285 m_aLstStrArr[ 2 ].clear();
286}
287
289{
290 sal_Int32 nPos = 0;
291 if (rLst1.n_children() && !m_aLstStrArr[ 0 ].isEmpty() &&
292 -1 != ( nPos = rLst1.find_text(m_aLstStrArr[ 0 ] ) ) )
293 rLst1.select( nPos );
294}
295
296// Insert new fields
297IMPL_LINK( SwFieldPage, TreeViewInsertHdl, weld::TreeView&, rBox, bool )
298{
299 InsertHdl(&rBox);
300 return true;
301}
302
304{
305 if (SwFieldDlg *pDlg = dynamic_cast<SwFieldDlg*>(GetDialogController()))
306 {
307 pDlg->InsertHdl();
308
309 if (pBtn)
310 pBtn->grab_focus(); // because of InputField-Dlg
311 }
312 else
313 {
314 SwFieldEditDlg *pEditDlg = static_cast<SwFieldEditDlg*>(GetDialogController());
315 pEditDlg->InsertHdl();
316 }
317}
318
319// enable/disable "Insert"-Button
321{
322 if (SwFieldDlg *pDlg = dynamic_cast<SwFieldDlg*>(GetDialogController()))
323 {
324 if (pDlg->GetCurTabPage() == this)
325 pDlg->EnableInsert(bEnable);
326 }
327 else
328 {
329 SwFieldEditDlg *pEditDlg = static_cast<SwFieldEditDlg*>(GetDialogController());
330 pEditDlg->EnableInsert(bEnable);
331 }
332
333 m_bInsert = bEnable;
334}
335
337{
338 InsertHdl(nullptr);
339 return true;
340}
341
343{
344 m_pWrtShell = pShell;
345 m_aMgr.SetWrtShell( pShell );
346}
347
348/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const css::uno::Reference< css::frame::XDispatchRecorder > & GetRecorder() const
static SAL_WARN_UNUSED_RESULT 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:548
Definition: doc.hxx:195
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:345
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:1571
void EvalExpFields(SwWrtShell *pSh)
Definition: fldmgr.cxx:1770
SwFieldType * GetFieldType(SwFieldIds nResId, size_t nField=0) const
Definition: fldmgr.cxx:417
void SetWrtShell(SwWrtShell *pShell)
Definition: fldmgr.hxx:124
bool InsertField(SwInsertField_Data &rData)
Definition: fldmgr.cxx:897
SwField * GetCurField()
Definition: fldmgr.cxx:432
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:342
void Init()
Definition: fldpage.cxx:64
bool m_bRefresh
Definition: fldpage.hxx:40
void SavePos(const weld::TreeView &rLst1)
Definition: fldpage.cxx:278
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:288
void InsertHdl(weld::Widget *)
Definition: fldpage.cxx:303
SwWrtShell * m_pWrtShell
Definition: fldpage.hxx:34
void EnableInsert(bool bEnable)
Definition: fldpage.cxx:320
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:502
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:1022
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:422
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:212
#define FN_INSERT_FIELD
Definition: cmdid.h:208
#define FN_PARAM_FIELD_SUBTYPE
Definition: cmdid.h:820
#define FN_PARAM_FIELD_FORMAT
Definition: cmdid.h:821
#define FN_PARAM_FIELD_TYPE
Definition: cmdid.h:819
SwFieldTypesEnum
List of FieldTypes at UI.
Definition: fldbas.hxx:95
@ FIXEDFLD
Definition: fldbas.hxx:230
@ DATEFLD
Definition: fldbas.hxx:231
@ TIMEFLD
Definition: fldbas.hxx:232
@ INP_TXT
Definition: fldbas.hxx:219
@ DATE_VAR
Definition: flddat.hxx:33
IMPL_LINK(SwFieldPage, TreeViewInsertHdl, weld::TreeView &, rBox, bool)
Definition: fldpage.cxx:297
IMPL_LINK_NOARG(SwFieldPage, NumFormatHdl, weld::TreeView &, bool)
Definition: fldpage.cxx:336
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:206
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:414