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