Mark some visible strings in ui files as translatable
[LibreOffice.git] / sw / source / ui / fldui / fldref.cxx
blob4eaa24f48c9f4e7dcdfe66c001ab7788543dd7ef
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <swtypes.hxx>
21 #include <IMark.hxx>
22 #include <expfld.hxx>
23 #include <swmodule.hxx>
24 #include "fldref.hxx"
25 #include <frmatr.hxx>
26 #include <reffld.hxx>
27 #include <wrtsh.hxx>
29 #include <fldref.hrc>
30 #include <strings.hrc>
31 #include <SwNodeNum.hxx>
32 #include <IDocumentMarkAccess.hxx>
33 #include <unotools/syslocaleoptions.hxx>
34 #include <unotools/charclass.hxx>
35 #include <osl/diagnose.h>
37 #include <comphelper/string.hxx>
38 #include <editeng/frmdiritem.hxx>
39 #include <o3tl/safeint.hxx>
40 #include <o3tl/string_view.hxx>
41 #include <vcl/settings.hxx>
44 static sal_uInt16 nFieldDlgFormatSel = 0;
46 #define USER_DATA_VERSION_1 "1"
47 #define USER_DATA_VERSION USER_DATA_VERSION_1
49 namespace {
51 enum FMT_REF_IDX
53 FMT_REF_PAGE_IDX = 0,
54 FMT_REF_CHAPTER_IDX = 1,
55 FMT_REF_TEXT_IDX = 2,
56 FMT_REF_UPDOWN_IDX = 3,
57 FMT_REF_PAGE_PGDSC_IDX = 4,
58 FMT_REF_ONLYNUMBER_IDX = 5,
59 FMT_REF_ONLYCAPTION_IDX = 6,
60 FMT_REF_ONLYSEQNO_IDX = 7,
61 FMT_REF_NUMBER_IDX = 8,
62 FMT_REF_NUMBER_NO_CONTEXT_IDX = 9,
63 FMT_REF_NUMBER_FULL_CONTEXT_IDX = 10
68 SwFieldRefPage::SwFieldRefPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *const pCoreSet )
69 : SwFieldPage(pPage, pController, u"modules/swriter/ui/fldrefpage.ui"_ustr, u"FieldRefPage"_ustr, pCoreSet)
70 , mpSavedSelectedTextNode(nullptr)
71 , mnSavedSelectedPos(0)
72 , m_xTypeLB(m_xBuilder->weld_tree_view(u"type"_ustr))
73 , m_xSelection(m_xBuilder->weld_widget(u"selectframe"_ustr))
74 , m_xSelectionLB(m_xBuilder->weld_tree_view(u"select"_ustr))
75 , m_xSelectionToolTipLB(m_xBuilder->weld_tree_view(u"selecttip"_ustr))
76 , m_xFormat(m_xBuilder->weld_widget(u"formatframe"_ustr))
77 , m_xFormatLB(m_xBuilder->weld_tree_view(u"format"_ustr))
78 , m_xNameFT(m_xBuilder->weld_label(u"nameft"_ustr))
79 , m_xNameED(m_xBuilder->weld_entry(u"name"_ustr))
80 , m_xValueED(m_xBuilder->weld_entry(u"value"_ustr))
81 , m_xFilterED(m_xBuilder->weld_entry(u"filter"_ustr))
82 , m_xStylerefFlags(m_xBuilder->weld_widget(u"stylerefflagsframe"_ustr))
83 , m_xStylerefFromBottomCB(m_xBuilder->weld_check_button(u"stylereffrombottomcheckbox"_ustr))
84 , m_xStylerefHideNonNumericalCB(m_xBuilder->weld_check_button(u"stylerefhidenonnumericalcheckbox"_ustr))
86 m_xSelectionLB->make_sorted();
87 // #i83479#
88 for (auto const& aID : FLD_REF_PAGE_TYPES)
90 m_xTypeLB->append_text(SwResId(aID));
91 m_xFormatLB->append_text(SwResId(aID));
94 m_sBookmarkText = m_xTypeLB->get_text(0);
95 m_sFootnoteText = m_xTypeLB->get_text(1);
96 m_sEndnoteText = m_xTypeLB->get_text(2);
97 // #i83479#
98 m_sHeadingText = m_xTypeLB->get_text(3);
99 m_sNumItemText = m_xTypeLB->get_text(4);
100 m_sStyleText = m_xTypeLB->get_text(5);
102 auto nHeight = m_xTypeLB->get_height_rows(8);
103 auto nWidth = m_xTypeLB->get_approximate_digit_width() * FIELD_COLUMN_WIDTH;
104 m_xTypeLB->set_size_request(nWidth * 1.33, nHeight);
105 m_xFormatLB->set_size_request(nWidth * 1.33, nHeight);
106 m_xSelection->set_size_request(nWidth * 2, nHeight);
107 nHeight = m_xTypeLB->get_height_rows(8);
108 m_xSelectionToolTipLB->set_size_request(nHeight, nWidth*2);
110 m_xTypeLB->clear();
112 m_xNameED->connect_changed(LINK(this, SwFieldRefPage, ModifyHdl));
113 m_xFilterED->connect_changed( LINK( this, SwFieldRefPage, ModifyHdl_Impl ) );
115 m_xTypeLB->connect_row_activated(LINK(this, SwFieldRefPage, TreeViewInsertHdl));
116 m_xTypeLB->connect_selection_changed(LINK(this, SwFieldRefPage, TypeHdl));
117 m_xSelectionLB->connect_selection_changed(LINK(this, SwFieldRefPage, SubTypeListBoxHdl));
118 m_xSelectionLB->connect_row_activated(LINK(this, SwFieldRefPage, TreeViewInsertHdl));
119 m_xFormatLB->connect_row_activated(LINK(this, SwFieldRefPage, TreeViewInsertHdl));
120 m_xFormatLB->connect_selection_changed(LINK(this, SwFieldRefPage, FormatHdl));
122 // #i83479#
123 m_xSelectionToolTipLB->connect_selection_changed(
124 LINK(this, SwFieldRefPage, SubTypeTreeListBoxHdl));
125 m_xSelectionToolTipLB->connect_row_activated( LINK(this, SwFieldRefPage, TreeViewInsertHdl) );
126 m_xFilterED->grab_focus();
128 // uitests
129 m_xTypeLB->set_buildable_name(m_xTypeLB->get_buildable_name() + "-ref");
130 m_xNameED->set_buildable_name(m_xNameED->get_buildable_name() + "-ref");
131 m_xValueED->set_buildable_name(m_xValueED->get_buildable_name() + "-ref");
132 m_xSelectionLB->set_buildable_name(m_xSelectionLB->get_buildable_name() + "-ref");
133 m_xFormatLB->set_buildable_name(m_xFormatLB->get_buildable_name() + "-ref");
136 SwFieldRefPage::~SwFieldRefPage()
140 IMPL_LINK_NOARG(SwFieldRefPage, ModifyHdl_Impl, weld::Entry&, void)
142 UpdateSubType(comphelper::string::strip(m_xFilterED->get_text(), ' '));
143 // tdf#135938 - refresh cross-reference name after filter selection has changed
144 SubTypeHdl();
147 // #i83479#
148 void SwFieldRefPage::SaveSelectedTextNode()
150 mpSavedSelectedTextNode = nullptr;
151 mnSavedSelectedPos = 0;
152 if ( !m_xSelectionToolTipLB->get_visible() )
153 return;
155 int nEntry = m_xSelectionToolTipLB->get_selected_index();
156 if (nEntry == -1)
157 return;
159 const sal_uInt16 nTypeId = m_xTypeLB->get_id(GetTypeSel()).toUInt32();
161 if ( nTypeId == REFFLDFLAG_HEADING )
163 mnSavedSelectedPos = m_xSelectionToolTipLB->get_id(nEntry).toUInt32();
164 if ( mnSavedSelectedPos < maOutlineNodes.size() )
166 mpSavedSelectedTextNode = maOutlineNodes[mnSavedSelectedPos];
169 else if ( nTypeId == REFFLDFLAG_NUMITEM )
171 mnSavedSelectedPos = m_xSelectionToolTipLB->get_id(nEntry).toUInt32();
172 if ( mnSavedSelectedPos < maNumItems.size() )
174 mpSavedSelectedTextNode = maNumItems[mnSavedSelectedPos]->GetTextNode();
179 void SwFieldRefPage::Reset(const SfxItemSet* )
181 if (!IsFieldEdit())
183 SavePos(*m_xTypeLB);
184 // #i83479#
185 SaveSelectedTextNode();
187 SetSelectionSel(-1);
188 SetTypeSel(-1);
189 Init(); // general initialisation
191 // initialise TypeListBox
192 m_xTypeLB->freeze();
193 m_xTypeLB->clear();
195 // fill Type-Listbox
197 // set/insert reference
198 const SwFieldGroupRgn& rRg = SwFieldMgr::GetGroupRange(IsFieldDlgHtmlMode(), GetGroup());
200 for (short i = rRg.nStart; i < rRg.nEnd; ++i)
202 const SwFieldTypesEnum nTypeId = SwFieldMgr::GetTypeId(i);
204 if (!IsFieldEdit() || nTypeId != SwFieldTypesEnum::SetRef)
206 m_xTypeLB->append(OUString::number(static_cast<sal_uInt16>(nTypeId)), SwFieldMgr::GetTypeStr(i));
210 // #i83479#
211 // entries for headings and numbered items
212 m_xTypeLB->append(OUString::number(REFFLDFLAG_HEADING), m_sHeadingText);
213 m_xTypeLB->append(OUString::number(REFFLDFLAG_NUMITEM), m_sNumItemText);
215 // fill up with the sequence types
216 SwWrtShell *pSh = GetWrtShell();
217 if (!pSh)
218 pSh = ::GetActiveWrtShell();
219 if (!pSh)
220 return;
222 // tdf#148432 in LTR UI override the navigator treeview direction based on
223 // the first page directionality
224 if (!AllSettings::GetLayoutRTL())
226 const SwPageDesc& rDesc = pSh->GetPageDesc(0);
227 const SvxFrameDirectionItem& rFrameDir = rDesc.GetMaster().GetFrameDir();
228 m_xSelectionToolTipLB->set_direction(rFrameDir.GetValue() == SvxFrameDirection::Horizontal_RL_TB);
231 const size_t nFieldTypeCnt = pSh->GetFieldTypeCount(SwFieldIds::SetExp);
233 OSL_ENSURE( nFieldTypeCnt < o3tl::make_unsigned(REFFLDFLAG), "<SwFieldRefPage::Reset> - Item index will overlap flags!" );
235 for (size_t n = 0; n < nFieldTypeCnt; ++n)
237 SwSetExpFieldType* pType = static_cast<SwSetExpFieldType*>(pSh->GetFieldType(n, SwFieldIds::SetExp));
239 if ((nsSwGetSetExpType::GSE_SEQ & pType->GetType()) && pType->HasWriterListeners() && pSh->IsUsed(*pType))
241 m_xTypeLB->append(OUString::number(REFFLDFLAG | n), pType->GetName());
245 // text marks - now always (because of globaldocuments)
246 m_xTypeLB->append(OUString::number(REFFLDFLAG_BOOKMARK), m_sBookmarkText);
248 // footnotes:
249 if( pSh->HasFootnotes() )
251 m_xTypeLB->append(OUString::number(REFFLDFLAG_FOOTNOTE), m_sFootnoteText);
254 // endnotes:
255 if ( pSh->HasFootnotes(true) )
257 m_xTypeLB->append(OUString::number(REFFLDFLAG_ENDNOTE), m_sEndnoteText);
260 // stylerefs
261 m_xTypeLB->append(OUString::number(REFFLDFLAG_STYLE), m_sStyleText);
263 m_xTypeLB->thaw();
265 // select old Pos
266 if (!IsFieldEdit())
267 RestorePos(*m_xTypeLB);
269 nFieldDlgFormatSel = 0;
271 sal_uInt16 nFormatBoxPosition = USHRT_MAX;
272 if( !IsFieldEdit() )
274 sal_Int32 nIdx{ 0 };
275 const OUString sUserData = GetUserData();
276 if(!IsRefresh() && o3tl::equalsIgnoreAsciiCase(o3tl::getToken(sUserData, 0, ';', nIdx),
277 u"" USER_DATA_VERSION_1))
279 const sal_uInt16 nVal = static_cast< sal_uInt16 >(o3tl::toInt32(o3tl::getToken(sUserData, 0, ';', nIdx)));
280 if(nVal != USHRT_MAX)
282 for(sal_Int32 i = 0, nEntryCount = m_xTypeLB->n_children(); i < nEntryCount; ++i)
284 if (nVal == m_xTypeLB->get_id(i).toUInt32())
286 m_xTypeLB->select(i);
287 break;
290 if (nIdx>=0 && nIdx<sUserData.getLength())
292 nFormatBoxPosition = static_cast< sal_uInt16 >(o3tl::toInt32(o3tl::getToken(sUserData, 0, ';', nIdx)));
297 TypeHdl(*m_xTypeLB);
298 if (!IsFieldEdit() && nFormatBoxPosition < m_xFormatLB->n_children())
300 m_xFormatLB->select(nFormatBoxPosition);
302 if (IsFieldEdit())
304 m_xTypeLB->save_value();
305 m_xSelectionLB->save_value();
306 m_xFormatLB->save_value();
307 m_xNameED->save_value();
308 m_xValueED->save_value();
309 m_xFilterED->set_text(OUString());
310 m_xStylerefFromBottomCB->save_state();
311 m_xStylerefHideNonNumericalCB->save_state();
315 IMPL_LINK_NOARG(SwFieldRefPage, TypeHdl, weld::TreeView&, void)
317 // save old ListBoxPos
318 const sal_Int32 nOld = GetTypeSel();
320 // current ListBoxPos
321 SetTypeSel(m_xTypeLB->get_selected_index());
323 if(GetTypeSel() == -1)
325 if (IsFieldEdit())
327 // select positions
328 OUString sName;
329 sal_uInt16 nFlag = 0;
331 switch( GetCurField()->GetSubType() )
333 case REF_BOOKMARK:
335 // #i83479#
336 SwGetRefField* pRefField = dynamic_cast<SwGetRefField*>(GetCurField());
337 if ( pRefField &&
338 pRefField->IsRefToHeadingCrossRefBookmark() )
340 sName = m_sHeadingText;
341 nFlag = REFFLDFLAG_HEADING;
343 else if ( pRefField &&
344 pRefField->IsRefToNumItemCrossRefBookmark() )
346 sName = m_sNumItemText;
347 nFlag = REFFLDFLAG_NUMITEM;
349 else
351 sName = m_sBookmarkText;
352 nFlag = REFFLDFLAG_BOOKMARK;
355 break;
357 case REF_FOOTNOTE:
358 sName = m_sFootnoteText;
359 nFlag = REFFLDFLAG_FOOTNOTE;
360 break;
362 case REF_ENDNOTE:
363 sName = m_sEndnoteText;
364 nFlag = REFFLDFLAG_ENDNOTE;
365 break;
367 case REF_SETREFATTR:
368 sName = SwResId(STR_GETREFFLD);
369 nFlag = REF_SETREFATTR;
370 break;
372 case REF_SEQUENCEFLD:
374 SwGetRefField const*const pRefField(dynamic_cast<SwGetRefField*>(GetCurField()));
375 if (pRefField)
377 sName = pRefField->GetSetRefName();
379 nFlag = REFFLDFLAG;
380 break;
383 case REF_STYLE:
385 SwGetRefField const*const pRefField(dynamic_cast<SwGetRefField*>(GetCurField()));
386 if (pRefField)
388 sName = pRefField->GetPar1();
390 nFlag = REFFLDFLAG_STYLE;
391 break;
395 if (m_xTypeLB->find_text(sName) == -1) // reference to deleted mark
397 m_xTypeLB->append(OUString::number(nFlag), sName);
400 m_xTypeLB->select_text(sName);
401 SetTypeSel(m_xTypeLB->get_selected_index());
403 else
405 SetTypeSel(0);
406 m_xTypeLB->select(0);
410 if (nOld == GetTypeSel())
411 return;
413 sal_uInt16 nTypeId = m_xTypeLB->get_id(GetTypeSel()).toUInt32();
415 bool bName = false;
416 nFieldDlgFormatSel = 0;
418 if ( ( !IsFieldEdit() || m_xSelectionLB->n_children() ) &&
419 nOld != -1 )
421 m_xNameED->set_text(OUString());
422 m_xValueED->set_text(OUString());
423 m_xFilterED->set_text(OUString());
426 // fill selection-ListBox
427 UpdateSubType(comphelper::string::strip(m_xFilterED->get_text(), ' '));
429 switch (nTypeId)
431 case static_cast<sal_uInt16>(SwFieldTypesEnum::GetRef):
432 if (nOld != -1 && REFFLDFLAG & m_xTypeLB->get_id(nOld).toUInt32())
433 // the old one stays
434 nFieldDlgFormatSel = m_xFormatLB->get_selected_index();
435 bName = true;
436 break;
438 case static_cast<sal_uInt16>(SwFieldTypesEnum::SetRef):
439 bName = true;
440 break;
442 case REFFLDFLAG_BOOKMARK:
443 bName = true;
444 [[fallthrough]];
445 default:
446 if( REFFLDFLAG & nTypeId )
448 const sal_uInt16 nOldId = nOld != -1 ? m_xTypeLB->get_id(nOld).toUInt32() : 0;
449 if( nOldId & REFFLDFLAG || nOldId == static_cast<sal_uInt16>(SwFieldTypesEnum::GetRef) )
450 // then the old one stays
451 nFieldDlgFormatSel = m_xFormatLB->get_selected_index();
453 break;
456 m_xNameED->set_sensitive(bName);
457 m_xNameFT->set_sensitive(bName);
459 // fill Format-Listbox
460 sal_Int32 nSize = FillFormatLB(nTypeId);
461 bool bFormat = nSize != 0;
462 m_xFormat->set_sensitive(bFormat);
464 SubTypeHdl();
465 ModifyHdl(*m_xNameED);
466 ModifyHdl(*m_xFilterED);
469 IMPL_LINK_NOARG(SwFieldRefPage, SubTypeTreeListBoxHdl, weld::TreeView&, void)
471 SubTypeHdl();
474 IMPL_LINK_NOARG(SwFieldRefPage, SubTypeListBoxHdl, weld::TreeView&, void)
476 SubTypeHdl();
479 IMPL_LINK_NOARG(SwFieldRefPage, FormatHdl, weld::TreeView&, void)
481 SubTypeHdl();
484 void SwFieldRefPage::SubTypeHdl()
486 sal_uInt16 nTypeId = m_xTypeLB->get_id(GetTypeSel()).toUInt32();
488 sal_uInt16 nFormat = m_xFormatLB->get_selected_id().toUInt32();
489 m_xStylerefHideNonNumericalCB->set_visible(nFormat == FMT_REF_NUMBER_IDX
490 || nFormat == FMT_REF_NUMBER_NO_CONTEXT_IDX
491 || nFormat == FMT_REF_NUMBER_FULL_CONTEXT_IDX);
492 m_xStylerefFlags->set_visible(nTypeId == REFFLDFLAG_STYLE);
494 switch(nTypeId)
496 case static_cast<sal_uInt16>(SwFieldTypesEnum::GetRef):
497 if (!IsFieldEdit() || m_xSelectionLB->get_selected_index() != -1)
499 m_xNameED->set_text(m_xSelectionLB->get_selected_text());
500 ModifyHdl(*m_xNameED);
502 break;
504 case static_cast<sal_uInt16>(SwFieldTypesEnum::SetRef):
506 SwWrtShell *pSh = GetWrtShell();
507 if(!pSh)
508 pSh = ::GetActiveWrtShell();
509 if(pSh)
511 m_xValueED->set_text(pSh->GetSelText());
515 break;
516 // #i83479#
517 case REFFLDFLAG_HEADING:
518 case REFFLDFLAG_NUMITEM:
520 int nEntry = m_xSelectionToolTipLB->get_selected_index();
521 if (nEntry != -1)
522 m_xNameED->set_text(m_xSelectionToolTipLB->get_text(nEntry));
524 break;
526 default:
527 if (!IsFieldEdit() || m_xSelectionLB->get_selected_index() != -1)
528 m_xNameED->set_text(m_xSelectionLB->get_selected_text());
529 break;
533 // renew types in SelectionLB after filtering
534 void SwFieldRefPage::UpdateSubType(const OUString& filterString)
536 SwWrtShell *pSh = GetWrtShell();
537 if (!pSh)
538 pSh = ::GetActiveWrtShell();
539 if (!pSh)
540 return;
542 SwGetRefField const*const pRefField(dynamic_cast<SwGetRefField*>(GetCurField()));
543 const sal_uInt16 nTypeId = m_xTypeLB->get_id(GetTypeSel()).toUInt32();
545 OUString sOldSel;
546 // #i83479#
547 if ( m_xSelectionLB->get_visible() )
549 const sal_Int32 nSelectionSel = m_xSelectionLB->get_selected_index();
550 if (nSelectionSel != -1)
551 sOldSel = m_xSelectionLB->get_text(nSelectionSel);
553 if (IsFieldEdit() && pRefField && sOldSel.isEmpty())
554 sOldSel = OUString::number( pRefField->GetSeqNo() + 1 );
556 m_xSelectionLB->freeze();
557 m_xSelectionLB->clear();
559 if (REFFLDFLAG & nTypeId)
561 if (nTypeId == REFFLDFLAG_FOOTNOTE || nTypeId == REFFLDFLAG_ENDNOTE)
563 m_xSelectionLB->thaw();
564 m_xSelectionLB->make_unsorted();
565 m_xSelectionLB->freeze();
567 // #i83479#
568 else if (nTypeId != REFFLDFLAG_HEADING && nTypeId != REFFLDFLAG_NUMITEM)
570 m_xSelectionLB->thaw();
571 m_xSelectionLB->make_sorted();
572 m_xSelectionLB->freeze();
576 // #i83479#
577 m_xSelectionToolTipLB->freeze();
578 m_xSelectionToolTipLB->clear();
579 OUString m_sSelectionToolTipLBId;
580 bool bShowSelectionToolTipLB( false );
582 if( REFFLDFLAG & nTypeId )
584 if (nTypeId == REFFLDFLAG_BOOKMARK) // text marks!
586 // get all text marks
587 IDocumentMarkAccess* const pMarkAccess = pSh->getIDocumentMarkAccess();
588 for(auto ppMark = pMarkAccess->getBookmarksBegin();
589 ppMark != pMarkAccess->getBookmarksEnd();
590 ++ppMark)
592 const ::sw::mark::MarkBase* pBkmk = *ppMark;
593 if(IDocumentMarkAccess::MarkType::BOOKMARK == IDocumentMarkAccess::GetType(*pBkmk))
595 bool isSubstring = MatchSubstring(pBkmk->GetName(), filterString);
596 if(isSubstring)
598 m_xSelectionLB->append_text( pBkmk->GetName() );
602 if (IsFieldEdit() && pRefField)
603 sOldSel = pRefField->GetSetRefName();
605 else if (nTypeId == REFFLDFLAG_FOOTNOTE)
607 SwSeqFieldList aArr;
608 const size_t nCnt = pSh->GetSeqFootnoteList( aArr );
610 for( size_t n = 0; n < nCnt; ++n )
612 bool isSubstring = MatchSubstring(aArr[ n ].sDlgEntry, filterString);
613 if(isSubstring)
615 m_xSelectionLB->append_text( aArr[ n ].sDlgEntry );
617 if (IsFieldEdit() && pRefField && pRefField->GetSeqNo() == aArr[ n ].nSeqNo)
618 sOldSel = aArr[n].sDlgEntry;
621 else if (nTypeId == REFFLDFLAG_ENDNOTE)
623 SwSeqFieldList aArr;
624 const size_t nCnt = pSh->GetSeqFootnoteList( aArr, true );
626 for( size_t n = 0; n < nCnt; ++n )
628 bool isSubstring = MatchSubstring(aArr[ n ].sDlgEntry, filterString);
629 if(isSubstring)
631 m_xSelectionLB->append_text( aArr[ n ].sDlgEntry );
633 if (IsFieldEdit() && pRefField && pRefField->GetSeqNo() == aArr[ n ].nSeqNo)
634 sOldSel = aArr[n].sDlgEntry;
637 // #i83479#
638 else if ( nTypeId == REFFLDFLAG_HEADING )
640 bShowSelectionToolTipLB = true;
642 const IDocumentOutlineNodes* pIDoc( pSh->getIDocumentOutlineNodesAccess() );
643 pIDoc->getOutlineNodes( maOutlineNodes );
644 bool bCertainTextNodeSelected( false );
645 for ( size_t nOutlIdx = 0; nOutlIdx < maOutlineNodes.size(); ++nOutlIdx )
647 if (!pIDoc->isOutlineInLayout(nOutlIdx, *pSh->GetLayout()))
649 continue; // skip it
651 bool isSubstring = MatchSubstring(pIDoc->getOutlineText(nOutlIdx, pSh->GetLayout(), true, true, false), filterString);
652 if(isSubstring)
654 OUString sId(OUString::number(nOutlIdx));
655 m_xSelectionToolTipLB->append(sId,
656 pIDoc->getOutlineText(nOutlIdx, pSh->GetLayout(), true, true, false));
657 if ((IsFieldEdit() && pRefField
658 && pRefField->GetReferencedTextNode(nullptr, nullptr) == maOutlineNodes[nOutlIdx])
659 || mpSavedSelectedTextNode == maOutlineNodes[nOutlIdx])
661 m_sSelectionToolTipLBId = sId;
662 sOldSel.clear();
663 bCertainTextNodeSelected = true;
665 else if ( !bCertainTextNodeSelected && mnSavedSelectedPos == nOutlIdx )
667 m_sSelectionToolTipLBId = sId;
668 sOldSel.clear();
673 else if ( nTypeId == REFFLDFLAG_NUMITEM )
675 bShowSelectionToolTipLB = true;
677 const IDocumentListItems* pIDoc( pSh->getIDocumentListItemsAccess() );
678 pIDoc->getNumItems( maNumItems );
679 bool bCertainTextNodeSelected( false );
680 for ( size_t nNumItemIdx = 0; nNumItemIdx < maNumItems.size(); ++nNumItemIdx )
682 if (!pIDoc->isNumberedInLayout(*maNumItems[nNumItemIdx], *pSh->GetLayout()))
684 continue; // skip it
686 bool isSubstring = MatchSubstring(pIDoc->getListItemText(*maNumItems[nNumItemIdx], *pSh->GetLayout()), filterString);
687 if(isSubstring)
689 OUString sId(OUString::number(nNumItemIdx));
690 m_xSelectionToolTipLB->append(sId,
691 pIDoc->getListItemText(*maNumItems[nNumItemIdx], *pSh->GetLayout()));
692 if ((IsFieldEdit() && pRefField
693 && pRefField->GetReferencedTextNode(nullptr, nullptr) == maNumItems[nNumItemIdx]->GetTextNode())
694 || mpSavedSelectedTextNode == maNumItems[nNumItemIdx]->GetTextNode())
696 m_sSelectionToolTipLBId = sId;
697 sOldSel.clear();
698 bCertainTextNodeSelected = true;
700 else if ( !bCertainTextNodeSelected && mnSavedSelectedPos == nNumItemIdx )
702 m_sSelectionToolTipLBId = sId;
703 sOldSel.clear();
708 else if (nTypeId == REFFLDFLAG_STYLE)
710 const IDocumentOutlineNodes* pIDoc(pSh->getIDocumentOutlineNodesAccess());
711 pIDoc->getOutlineNodes(maOutlineNodes);
713 SfxStyleSheetBasePool* pStyleSheetPool
714 = pSh->GetDoc()->GetDocShell()->GetStyleSheetPool();
715 auto stylesheetIterator
716 = pStyleSheetPool->CreateIterator(SfxStyleFamily::Para, SfxStyleSearchBits::Used);
718 SfxStyleSheetBase* pStyle = stylesheetIterator->First();
719 while (pStyle != nullptr)
721 bool isSubstring = MatchSubstring(pStyle->GetName(), filterString);
723 if (isSubstring)
725 m_xSelectionLB->append_text(pStyle->GetName());
728 pStyle = stylesheetIterator->Next();
731 if (IsFieldEdit() && pRefField) {
732 sOldSel = pRefField->GetPar1();
733 m_xStylerefFromBottomCB->set_active((pRefField->GetFlags() & REFFLDFLAG_STYLE_FROM_BOTTOM) == REFFLDFLAG_STYLE_FROM_BOTTOM);
734 m_xStylerefHideNonNumericalCB->set_active((pRefField->GetFlags() & REFFLDFLAG_STYLE_HIDE_NON_NUMERICAL) == REFFLDFLAG_STYLE_HIDE_NON_NUMERICAL);
737 else
739 // get the fields to Seq-FieldType:
741 SwSetExpFieldType* pType = static_cast<SwSetExpFieldType*>(pSh->GetFieldType(
742 nTypeId & ~REFFLDFLAG, SwFieldIds::SetExp ));
743 if( pType )
745 SwSeqFieldList aArr;
746 // old selection should be kept in non-edit mode
747 if(IsFieldEdit())
748 sOldSel.clear();
750 const size_t nCnt = pType->GetSeqFieldList(aArr, pSh->GetLayout());
751 for( size_t n = 0; n < nCnt; ++n )
753 bool isSubstring = MatchSubstring(aArr[ n ].sDlgEntry, filterString);
754 if(isSubstring)
756 m_xSelectionLB->append_text( aArr[ n ].sDlgEntry );
758 if (IsFieldEdit() && pRefField && sOldSel.isEmpty() &&
759 aArr[ n ].nSeqNo == pRefField->GetSeqNo())
760 sOldSel = aArr[ n ].sDlgEntry;
763 if (IsFieldEdit() && pRefField && sOldSel.isEmpty())
764 sOldSel = OUString::number( pRefField->GetSeqNo() + 1);
768 else
770 std::vector<OUString> aLst;
771 GetFieldMgr().GetSubTypes(static_cast<SwFieldTypesEnum>(nTypeId), aLst);
772 for(const OUString & i : aLst)
774 bool isSubstring = MatchSubstring( i , filterString );
775 if(isSubstring)
777 m_xSelectionLB->append_text(i);
781 if (IsFieldEdit() && pRefField)
782 sOldSel = pRefField->GetSetRefName();
785 // #i83479#
786 m_xSelectionLB->thaw();
787 m_xSelectionToolTipLB->thaw();
788 if (!m_sSelectionToolTipLBId.isEmpty())
789 m_xSelectionToolTipLB->select_id(m_sSelectionToolTipLBId);
790 m_xSelectionToolTipLB->set_visible( bShowSelectionToolTipLB );
791 m_xSelectionLB->set_visible( !bShowSelectionToolTipLB );
792 if ( bShowSelectionToolTipLB )
794 bool bHasChildren = m_xSelectionToolTipLB->n_children() != 0;
795 m_xSelection->set_sensitive(bHasChildren);
797 int nEntry = m_xSelectionToolTipLB->get_selected_index();
798 if (nEntry != -1)
799 m_xSelectionToolTipLB->scroll_to_row(nEntry);
800 else if (bHasChildren)
801 m_xSelectionToolTipLB->select(0);
803 if (IsFieldEdit() && nEntry == -1)
805 m_xNameED->set_text(sOldSel);
808 else
810 // enable or disable
811 bool bEnable = m_xSelectionLB->n_children() != 0;
812 m_xSelection->set_sensitive( bEnable );
814 if ( bEnable )
816 m_xSelectionLB->select_text(sOldSel);
817 if (m_xSelectionLB->get_selected_index() == -1 && !IsFieldEdit())
818 m_xSelectionLB->select(0);
821 if (IsFieldEdit() && m_xSelectionLB->get_selected_index() == -1) // in case the reference was already deleted...
822 m_xNameED->set_text(sOldSel);
826 bool SwFieldRefPage::MatchSubstring( const OUString& rListString, const OUString& rSubstr )
828 if(rSubstr.isEmpty())
829 return true;
830 OUString aListString = GetAppCharClass().lowercase(rListString);
831 OUString aSubstr = GetAppCharClass().lowercase(rSubstr);
832 return aListString.indexOf(aSubstr) >= 0;
835 const TranslateId FMT_REF_ARY[] =
837 FMT_REF_PAGE,
838 FMT_REF_CHAPTER,
839 FMT_REF_TEXT,
840 FMT_REF_UPDOWN,
841 FMT_REF_PAGE_PGDSC,
842 FMT_REF_ONLYNUMBER,
843 FMT_REF_ONLYCAPTION,
844 FMT_REF_ONLYSEQNO,
845 FMT_REF_NUMBER,
846 FMT_REF_NUMBER_NO_CONTEXT,
847 FMT_REF_NUMBER_FULL_CONTEXT
850 sal_Int32 SwFieldRefPage::FillFormatLB(sal_uInt16 nTypeId)
852 OUString sOldSel;
854 sal_Int32 nFormatSel = m_xFormatLB->get_selected_index();
855 if (nFormatSel != -1)
856 sOldSel = m_xFormatLB->get_text(nFormatSel);
858 // fill Format-Listbox
859 m_xFormatLB->clear();
861 // reference has less that the annotation
862 sal_uInt16 nSize( 0 );
863 sal_uInt16 nOffset( 0 );
864 bool bAddCrossRefFormats( false );
865 switch (nTypeId)
867 // #i83479#
868 case REFFLDFLAG_HEADING:
869 case REFFLDFLAG_NUMITEM:
870 bAddCrossRefFormats = true;
871 [[fallthrough]];
873 case static_cast<sal_uInt16>(SwFieldTypesEnum::GetRef):
874 case REFFLDFLAG_BOOKMARK:
875 case REFFLDFLAG_FOOTNOTE:
876 case REFFLDFLAG_ENDNOTE:
877 nSize = FMT_REF_PAGE_PGDSC_IDX + 1;
878 break;
879 case REFFLDFLAG_STYLE:
880 nOffset = FMT_REF_TEXT_IDX;
881 nSize = FMT_REF_UPDOWN_IDX + 1 - nOffset;
882 bAddCrossRefFormats = true;
883 break;
885 default:
886 // #i83479#
888 if ( REFFLDFLAG & nTypeId )
890 nSize = FMT_REF_ONLYSEQNO_IDX + 1;
892 else
894 nSize = GetFieldMgr().GetFormatCount( static_cast<SwFieldTypesEnum>(nTypeId), IsFieldDlgHtmlMode() );
896 break;
899 if (REFFLDFLAG & nTypeId)
900 nTypeId = static_cast<sal_uInt16>(SwFieldTypesEnum::GetRef);
902 SwFieldTypesEnum nFieldType = static_cast<SwFieldTypesEnum>(nTypeId);
903 for (sal_uInt16 i = nOffset; i < nSize + nOffset; i++)
905 OUString sId(OUString::number(GetFieldMgr().GetFormatId( nFieldType, i )));
906 m_xFormatLB->append(sId, GetFieldMgr().GetFormatStr(nFieldType, i));
908 // #i83479#
910 sal_uInt16 nExtraSize( 0 );
911 if ( bAddCrossRefFormats )
913 sal_uInt16 nFormat = FMT_REF_NUMBER_IDX;
914 OUString sId(OUString::number(GetFieldMgr().GetFormatId(nFieldType, nFormat)));
915 m_xFormatLB->append(sId, GetFieldMgr().GetFormatStr( nFieldType, nFormat ));
916 nFormat = FMT_REF_NUMBER_NO_CONTEXT_IDX;
917 sId = OUString::number(GetFieldMgr().GetFormatId(nFieldType, nFormat));
918 m_xFormatLB->append(sId, GetFieldMgr().GetFormatStr( nFieldType, nFormat ));
919 nFormat = FMT_REF_NUMBER_FULL_CONTEXT_IDX;
920 sId = OUString::number(GetFieldMgr().GetFormatId(nFieldType, nFormat));
921 m_xFormatLB->append(sId, GetFieldMgr().GetFormatStr( nFieldType, nFormat ));
922 nExtraSize = 3;
925 // extra list items optionally, depending from reference-language
926 SvtSysLocaleOptions aSysLocaleOptions;
927 static const LanguageTag& rLang = aSysLocaleOptions.GetRealLanguageTag();
929 if (rLang.getLanguage() == "hu")
931 for (sal_uInt16 i = 0; i < nSize; i++)
933 OUString sId(OUString::number(GetFieldMgr().GetFormatId( nFieldType, i + std::size(FMT_REF_ARY))));
934 m_xFormatLB->append(sId, SwResId(FMT_REF_WITH_LOWERCASE_HU_ARTICLE) + GetFieldMgr().GetFormatStr( nFieldType, i ));
936 nExtraSize += nSize;
938 if ( bAddCrossRefFormats )
940 sal_uInt16 nFormat = FMT_REF_NUMBER_IDX + std::size(FMT_REF_ARY);
941 OUString sId(OUString::number(GetFieldMgr().GetFormatId(nFieldType, nFormat)));
942 m_xFormatLB->append(sId, SwResId(FMT_REF_WITH_LOWERCASE_HU_ARTICLE) + GetFieldMgr().GetFormatStr( nFieldType, nFormat % std::size(FMT_REF_ARY)));
943 nFormat = FMT_REF_NUMBER_NO_CONTEXT_IDX + std::size(FMT_REF_ARY);
944 sId = OUString::number(GetFieldMgr().GetFormatId(nFieldType, nFormat));
945 m_xFormatLB->append(sId, SwResId(FMT_REF_WITH_LOWERCASE_HU_ARTICLE) + GetFieldMgr().GetFormatStr( nFieldType, nFormat % std::size(FMT_REF_ARY)));
946 nFormat = FMT_REF_NUMBER_FULL_CONTEXT_IDX + std::size(FMT_REF_ARY);
947 sId = OUString::number(GetFieldMgr().GetFormatId(nFieldType, nFormat));
948 m_xFormatLB->append(sId, SwResId(FMT_REF_WITH_LOWERCASE_HU_ARTICLE) + GetFieldMgr().GetFormatStr( nFieldType, nFormat % std::size(FMT_REF_ARY)));
949 nExtraSize += 3;
951 // uppercase article
952 for (sal_uInt16 i = 0; i < nSize; i++)
954 OUString sId(OUString::number(GetFieldMgr().GetFormatId( nFieldType, i + 2 * std::size(FMT_REF_ARY))));
955 m_xFormatLB->append(sId, SwResId(FMT_REF_WITH_UPPERCASE_HU_ARTICLE) + GetFieldMgr().GetFormatStr( nFieldType, i ));
957 nExtraSize += nSize;
958 if ( bAddCrossRefFormats )
960 sal_uInt16 nFormat = FMT_REF_NUMBER_IDX + 2 * std::size(FMT_REF_ARY);
961 OUString sId(OUString::number(GetFieldMgr().GetFormatId(nFieldType, nFormat)));
962 m_xFormatLB->append(sId, SwResId(FMT_REF_WITH_UPPERCASE_HU_ARTICLE) + GetFieldMgr().GetFormatStr( nFieldType, nFormat % std::size(FMT_REF_ARY)));
963 nFormat = FMT_REF_NUMBER_NO_CONTEXT_IDX + 2 * std::size(FMT_REF_ARY);
964 sId = OUString::number(GetFieldMgr().GetFormatId(nFieldType, nFormat));
965 m_xFormatLB->append(sId, SwResId(FMT_REF_WITH_UPPERCASE_HU_ARTICLE) + GetFieldMgr().GetFormatStr( nFieldType, nFormat % std::size(FMT_REF_ARY)));
966 nFormat = FMT_REF_NUMBER_FULL_CONTEXT_IDX + 2 * std::size(FMT_REF_ARY);
967 sId = OUString::number(GetFieldMgr().GetFormatId(nFieldType, nFormat));
968 m_xFormatLB->append(sId, SwResId(FMT_REF_WITH_UPPERCASE_HU_ARTICLE) + GetFieldMgr().GetFormatStr( nFieldType, nFormat % std::size(FMT_REF_ARY)));
969 nExtraSize += 3;
973 nSize += nExtraSize;
975 // select a certain entry
976 if (nSize)
978 if (!IsFieldEdit())
979 m_xFormatLB->select_text(sOldSel);
980 else
981 m_xFormatLB->select_text(SwResId(FMT_REF_ARY[GetCurField()->GetFormat() % std::size(FMT_REF_ARY)]));
983 if (m_xFormatLB->get_selected_index() == -1)
985 if (nFieldDlgFormatSel < m_xFormatLB->n_children())
986 m_xFormatLB->select(nFieldDlgFormatSel);
987 else
988 m_xFormatLB->select(0);
992 return nSize;
995 // Modify
996 IMPL_LINK_NOARG(SwFieldRefPage, ModifyHdl, weld::Entry&, void)
998 OUString aName(m_xNameED->get_text());
999 const bool bEmptyName = aName.isEmpty();
1001 bool bEnable = true;
1002 sal_uInt16 nTypeId = m_xTypeLB->get_id(GetTypeSel()).toUInt32();
1004 if ((nTypeId == static_cast<sal_uInt16>(SwFieldTypesEnum::SetRef) && !GetFieldMgr().CanInsertRefMark(aName)) ||
1005 (bEmptyName && (nTypeId == static_cast<sal_uInt16>(SwFieldTypesEnum::GetRef) || nTypeId == static_cast<sal_uInt16>(SwFieldTypesEnum::SetRef) ||
1006 nTypeId == REFFLDFLAG_BOOKMARK)))
1007 bEnable = false;
1009 EnableInsert(bEnable, IsCurrentPage());
1011 m_xSelectionLB->select_text(aName);
1014 bool SwFieldRefPage::FillItemSet(SfxItemSet* )
1016 bool bModified = false;
1017 sal_uInt16 nTypeId = m_xTypeLB->get_id(GetTypeSel()).toUInt32();
1019 sal_uInt16 nSubType = 0;
1020 const sal_Int32 nEntryPos = m_xFormatLB->get_selected_index();
1021 const sal_uInt32 nFormat = (nEntryPos == -1)
1022 ? 0 : m_xFormatLB->get_id(nEntryPos).toUInt32();
1024 OUString aVal(m_xValueED->get_text());
1025 OUString aName(m_xNameED->get_text());
1027 switch(nTypeId)
1029 case static_cast<sal_uInt16>(SwFieldTypesEnum::GetRef):
1030 nSubType = REF_SETREFATTR;
1031 break;
1033 case static_cast<sal_uInt16>(SwFieldTypesEnum::SetRef):
1035 SwFieldType* pType = GetFieldMgr().GetFieldType(SwFieldIds::SetExp, aName);
1037 if(!pType) // Only insert when the name doesn't exist yet
1039 m_xSelectionLB->append_text(aName);
1040 m_xSelection->set_sensitive(true);
1042 break;
1046 SwGetRefField const*const pRefField(dynamic_cast<SwGetRefField*>(GetCurField()));
1048 SwWrtShell *pSh = GetWrtShell();
1049 if(!pSh)
1050 pSh = ::GetActiveWrtShell();
1052 if (pSh && REFFLDFLAG & nTypeId)
1054 if (nTypeId == REFFLDFLAG_BOOKMARK) // text marks!
1056 aName = m_xNameED->get_text();
1057 nTypeId = static_cast<sal_uInt16>(SwFieldTypesEnum::GetRef);
1058 nSubType = REF_BOOKMARK;
1060 else if (REFFLDFLAG_FOOTNOTE == nTypeId) // footnotes
1062 SwSeqFieldList aArr;
1063 SeqFieldLstElem aElem( m_xSelectionLB->get_selected_text(), 0 );
1065 size_t nPos = 0;
1067 nTypeId = static_cast<sal_uInt16>(SwFieldTypesEnum::GetRef);
1068 nSubType = REF_FOOTNOTE;
1069 aName.clear();
1071 if (pSh->GetSeqFootnoteList(aArr) && aArr.SeekEntry(aElem, &nPos))
1073 aVal = OUString::number( aArr[nPos].nSeqNo );
1075 if (IsFieldEdit() && pRefField && aArr[nPos].nSeqNo == pRefField->GetSeqNo())
1076 bModified = true; // can happen with fields of which the references were deleted
1078 else if (IsFieldEdit() && pRefField)
1079 aVal = OUString::number( pRefField->GetSeqNo() );
1081 else if (REFFLDFLAG_ENDNOTE == nTypeId) // endnotes
1083 SwSeqFieldList aArr;
1084 SeqFieldLstElem aElem( m_xSelectionLB->get_selected_text(), 0 );
1086 size_t nPos = 0;
1088 nTypeId = static_cast<sal_uInt16>(SwFieldTypesEnum::GetRef);
1089 nSubType = REF_ENDNOTE;
1090 aName.clear();
1092 if (pSh->GetSeqFootnoteList(aArr, true) && aArr.SeekEntry(aElem, &nPos))
1094 aVal = OUString::number( aArr[nPos].nSeqNo );
1096 if (IsFieldEdit() && pRefField && aArr[nPos].nSeqNo == pRefField->GetSeqNo())
1097 bModified = true; // can happen with fields of which the reference was deleted
1099 else if (IsFieldEdit() && pRefField)
1100 aVal = OUString::number( pRefField->GetSeqNo() );
1102 // #i83479#
1103 else if ( nTypeId == REFFLDFLAG_HEADING )
1105 int nEntry = m_xSelectionToolTipLB->get_selected_index();
1106 OSL_ENSURE( nEntry != -1,
1107 "<SwFieldRefPage::FillItemSet(..)> - no entry selected in selection tool tip listbox!" );
1108 if (nEntry != -1)
1110 const size_t nOutlIdx(m_xSelectionToolTipLB->get_id(nEntry).toUInt32());
1111 pSh->getIDocumentOutlineNodesAccess()->getOutlineNodes( maOutlineNodes );
1112 if ( nOutlIdx < maOutlineNodes.size() )
1114 ::sw::mark::MarkBase const * const pMark = pSh->getIDocumentMarkAccess()->getMarkForTextNode(
1115 *(maOutlineNodes[nOutlIdx]),
1116 IDocumentMarkAccess::MarkType::CROSSREF_HEADING_BOOKMARK);
1117 aName = pMark->GetName();
1118 nTypeId = static_cast<sal_uInt16>(SwFieldTypesEnum::GetRef);
1119 nSubType = REF_BOOKMARK;
1123 else if ( nTypeId == REFFLDFLAG_NUMITEM )
1125 int nEntry = m_xSelectionToolTipLB->get_selected_index();
1126 OSL_ENSURE( nEntry != -1,
1127 "<SwFieldRefPage::FillItemSet(..)> - no entry selected in selection tool tip listbox!" );
1128 if (nEntry != -1)
1130 const size_t nNumItemIdx(m_xSelectionToolTipLB->get_id(nEntry).toUInt32());
1131 pSh->getIDocumentListItemsAccess()->getNumItems(maNumItems);
1132 if ( nNumItemIdx < maNumItems.size() )
1134 ::sw::mark::MarkBase const * const pMark = pSh->getIDocumentMarkAccess()->getMarkForTextNode(
1135 *(maNumItems[nNumItemIdx]->GetTextNode()),
1136 IDocumentMarkAccess::MarkType::CROSSREF_NUMITEM_BOOKMARK);
1137 aName = pMark->GetName();
1138 nTypeId = static_cast<sal_uInt16>(SwFieldTypesEnum::GetRef);
1139 nSubType = REF_BOOKMARK;
1143 else if (nTypeId == REFFLDFLAG_STYLE)
1145 int nEntry = m_xSelectionLB->get_selected_index();
1146 if (nEntry != -1)
1148 aName = m_xSelectionLB->get_text(nEntry);
1149 nTypeId = static_cast<sal_uInt16>(SwFieldTypesEnum::GetRef);
1150 nSubType = REF_STYLE;
1151 sal_uInt16 nVal = REFFLDFLAG_STYLE;
1153 if (m_xStylerefFromBottomCB->get_active()) {
1154 nVal |= REFFLDFLAG_STYLE_FROM_BOTTOM;
1157 if (m_xStylerefHideNonNumericalCB->get_active()) {
1158 nVal |= REFFLDFLAG_STYLE_HIDE_NON_NUMERICAL;
1161 aVal = OUString::number(nVal);
1162 } else {
1163 SAL_WARN("sw.ui", "<SwFieldRefPage::FillItemSet(..)> no entry selected in selection listbox!");
1166 else // SequenceFields
1168 // get fields for Seq-FieldType:
1169 SwSetExpFieldType* pType = static_cast<SwSetExpFieldType*>(pSh->GetFieldType(
1170 nTypeId & ~REFFLDFLAG, SwFieldIds::SetExp ));
1171 if( pType )
1173 SwSeqFieldList aArr;
1174 SeqFieldLstElem aElem( m_xSelectionLB->get_selected_text(), 0 );
1176 size_t nPos = 0;
1178 nTypeId = static_cast<sal_uInt16>(SwFieldTypesEnum::GetRef);
1179 nSubType = REF_SEQUENCEFLD;
1180 aName = pType->GetName();
1182 if (pType->GetSeqFieldList(aArr, pSh->GetLayout())
1183 && aArr.SeekEntry(aElem, &nPos))
1185 aVal = OUString::number( aArr[nPos].nSeqNo );
1187 if (IsFieldEdit() && pRefField && aArr[nPos].nSeqNo == pRefField->GetSeqNo())
1188 bModified = true; // can happen with fields of which the reference was deleted
1190 else if (IsFieldEdit() && pRefField)
1191 aVal = OUString::number( pRefField->GetSeqNo() );
1196 if (IsFieldEdit() && nTypeId == static_cast<sal_uInt16>(SwFieldTypesEnum::GetRef))
1198 aVal = OUString::number(nSubType) + "|" + aVal;
1201 if (!IsFieldEdit() || bModified ||
1202 m_xNameED->get_value_changed_from_saved() ||
1203 m_xValueED->get_value_changed_from_saved() ||
1204 m_xTypeLB->get_value_changed_from_saved() ||
1205 m_xSelectionLB->get_value_changed_from_saved() ||
1206 m_xFormatLB->get_value_changed_from_saved() ||
1207 (nSubType == REF_STYLE
1208 && (m_xStylerefFromBottomCB->get_state_changed_from_saved() || m_xStylerefHideNonNumericalCB->get_state_changed_from_saved())))
1210 InsertField( static_cast<SwFieldTypesEnum>(nTypeId), nSubType, aName, aVal, nFormat );
1213 ModifyHdl(*m_xNameED); // enable/disable insert if applicable
1215 return false;
1218 std::unique_ptr<SfxTabPage> SwFieldRefPage::Create( weld::Container* pPage, weld::DialogController* pController,
1219 const SfxItemSet *const pAttrSet)
1221 return std::make_unique<SwFieldRefPage>(pPage, pController, pAttrSet);
1224 sal_uInt16 SwFieldRefPage::GetGroup()
1226 return GRP_REF;
1229 void SwFieldRefPage::FillUserData()
1231 const sal_Int32 nEntryPos = m_xTypeLB->get_selected_index();
1232 const sal_uInt16 nTypeSel = ( -1 == nEntryPos )
1233 ? USHRT_MAX
1234 : m_xTypeLB->get_id(nEntryPos).toUInt32();
1235 const sal_Int32 nFormatEntryPos = m_xFormatLB->get_selected_index();
1236 const sal_uInt32 nFormatSel = -1 == nFormatEntryPos ? USHRT_MAX : nFormatEntryPos;
1237 SetUserData( USER_DATA_VERSION ";" +
1238 OUString::number( nTypeSel ) + ";" +
1239 OUString::number( nFormatSel ));
1242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */