Resolves: tdf#148743 TOC->Edit Index->Assign Styles; Styles aren't sorted
[LibreOffice.git] / sw / source / ui / index / cnttab.cxx
blobdc31fdd5d156d05b9f31c78d1982f9e0b5eeb697
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 <sal/config.h>
22 #include <o3tl/safeint.hxx>
23 #include <sal/log.hxx>
24 #include <svl/style.hxx>
25 #include <vcl/weld.hxx>
26 #include <svl/stritem.hxx>
27 #include <unotools/pathoptions.hxx>
28 #include <sfx2/viewfrm.hxx>
29 #include <sfx2/dispatch.hxx>
30 #include <sfx2/docfile.hxx>
31 #include <sfx2/sfxdlg.hxx>
32 #include <svx/dialogs.hrc>
33 #include <svx/flagsdef.hxx>
34 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
35 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
36 #include <svtools/indexentryres.hxx>
37 #include <toolkit/helper/vclunohelper.hxx>
38 #include <column.hxx>
39 #include <fmtfsize.hxx>
40 #include <authfld.hxx>
41 #include <swtypes.hxx>
42 #include <wrtsh.hxx>
43 #include <view.hxx>
44 #include <cnttab.hxx>
45 #include <swuicnttab.hxx>
46 #include <poolfmt.hxx>
47 #include <strings.hrc>
48 #include <uitool.hxx>
49 #include <fmtcol.hxx>
50 #include <fldbas.hxx>
51 #include <expfld.hxx>
52 #include <unotools.hxx>
53 #include <docsh.hxx>
54 #include <swmodule.hxx>
55 #include <modcfg.hxx>
56 #include <iodetect.hxx>
58 #include <cmdid.h>
59 #include <cnttab.hrc>
60 #include <SwStyleNameMapper.hxx>
61 #include <sfx2/filedlghelper.hxx>
62 #include <toxwrap.hxx>
63 #include <chpfld.hxx>
65 #include <cmath>
66 #include <memory>
67 #include <string_view>
68 #include <vector>
69 #include <numeric>
72 using namespace ::com::sun::star;
73 using namespace ::com::sun::star::lang;
74 using namespace ::com::sun::star::uno;
75 using namespace com::sun::star::ui::dialogs;
76 using namespace ::sfx2;
77 #include <svtools/editbrowsebox.hxx>
79 const sal_Unicode aDeliStart = '['; // for the form
80 const sal_Unicode aDeliEnd = ']'; // for the form
82 static OUString lcl_CreateAutoMarkFileDlg(weld::Window* pParent, const OUString& rURL,
83 const OUString& rFileString, bool bOpen)
85 OUString sRet;
87 FileDialogHelper aDlgHelper( bOpen ?
88 TemplateDescription::FILEOPEN_SIMPLE : TemplateDescription::FILESAVE_AUTOEXTENSION,
89 FileDialogFlags::NONE, pParent);
90 uno::Reference < XFilePicker3 > xFP = aDlgHelper.GetFilePicker();
92 xFP->appendFilter( rFileString, "*.sdi" );
93 xFP->setCurrentFilter( rFileString ) ;
95 if( !rURL.isEmpty() )
96 xFP->setDisplayDirectory( rURL );
97 else
99 SvtPathOptions aPathOpt;
100 xFP->setDisplayDirectory( aPathOpt.GetUserConfigPath() );
103 if( aDlgHelper.Execute() == ERRCODE_NONE )
105 sRet = xFP->getSelectedFiles().getConstArray()[0];
108 return sRet;
111 namespace {
113 struct AutoMarkEntry
115 OUString sSearch;
116 OUString sAlternative;
117 OUString sPrimKey;
118 OUString sSecKey;
119 OUString sComment;
120 bool bCase;
121 bool bWord;
123 AutoMarkEntry() :
124 bCase(false),
125 bWord(false){}
130 typedef ::svt::EditBrowseBox SwEntryBrowseBox_Base;
132 namespace {
134 class SwEntryBrowseBox : public SwEntryBrowseBox_Base
136 VclPtr<svt::EditControl> m_aCellEdit;
137 VclPtr<svt::CheckBoxControl> m_aCellCheckBox;
139 OUString m_sYes;
140 OUString m_sNo;
142 std::vector<std::unique_ptr<AutoMarkEntry>> m_Entries;
144 ::svt::CellControllerRef m_xController;
145 ::svt::CellControllerRef m_xCheckController;
147 sal_Int32 m_nCurrentRow;
148 bool m_bModified;
150 protected:
151 virtual bool SeekRow( sal_Int32 nRow ) override;
152 virtual void PaintCell(OutputDevice& rDev, const tools::Rectangle& rRect, sal_uInt16 nColId) const override;
153 virtual void InitController(::svt::CellControllerRef& rController, sal_Int32 nRow, sal_uInt16 nCol) override;
154 virtual ::svt::CellController* GetController(sal_Int32 nRow, sal_uInt16 nCol) override;
155 virtual bool SaveModified() override;
157 std::vector<tools::Long> GetOptimalColWidths() const;
159 public:
160 SwEntryBrowseBox(const css::uno::Reference<css::awt::XWindow> &rParent);
161 virtual ~SwEntryBrowseBox() override;
162 virtual void dispose() override;
163 void ReadEntries(SvStream& rInStr);
164 void WriteEntries(SvStream& rOutStr);
166 bool IsModified()const override;
168 virtual OUString GetCellText( sal_Int32 nRow, sal_uInt16 nColumn ) const override;
169 virtual void Resize() override;
170 virtual Size GetOptimalSize() const override;
173 class SwAutoMarkDlg_Impl : public weld::GenericDialogController
175 OUString sAutoMarkURL;
176 bool bCreateMode;
178 std::unique_ptr<weld::Button> m_xOKPB;
179 std::unique_ptr<weld::Container> m_xTable;
180 css::uno::Reference<css::awt::XWindow> m_xTableCtrlParent;
181 VclPtr<SwEntryBrowseBox> m_xEntriesBB;
183 DECL_LINK(OkHdl, weld::Button&, void);
184 public:
185 SwAutoMarkDlg_Impl(weld::Window* pParent, const OUString& rAutoMarkURL,
186 bool bCreate);
187 virtual ~SwAutoMarkDlg_Impl() override;
192 sal_uInt16 CurTOXType::GetFlatIndex() const
194 return static_cast< sal_uInt16 >( (eType == TOX_USER && nIndex)
195 ? TOX_AUTHORITIES + nIndex : eType );
198 SwMultiTOXTabDialog::SwMultiTOXTabDialog(weld::Widget* pParent, const SfxItemSet& rSet,
199 SwWrtShell &rShell, SwTOXBase* pCurTOX,
200 sal_uInt16 nToxType, bool bGlobal)
201 : SfxTabDialogController(pParent, "modules/swriter/ui/tocdialog.ui", "TocDialog", &rSet)
202 , m_pMgr( new SwTOXMgr( &rShell ) )
203 , m_rWrtShell(rShell)
204 , m_pParamTOXBase(pCurTOX)
205 , m_sUserDefinedIndex(SwResId(STR_USER_DEFINED_INDEX))
206 , m_nInitialTOXType(nToxType)
207 , m_bEditTOX(false)
208 , m_bExampleCreated(false)
209 , m_bGlobalFlag(bGlobal)
210 , m_xShowExampleCB(m_xBuilder->weld_check_button("showexample"))
212 m_eCurrentTOXType.eType = TOX_CONTENT;
213 m_eCurrentTOXType.nIndex = 0;
215 const sal_uInt16 nUserTypeCount = m_rWrtShell.GetTOXTypeCount(TOX_USER);
216 m_vTypeData.resize(nUserTypeCount + 6);
217 //the standard user index is on position TOX_USER
218 //all user indexes follow after position TOX_AUTHORITIES
219 if(pCurTOX)
221 m_bEditTOX = true;
223 for(int i = m_vTypeData.size() - 1; i > -1; i--)
225 m_vTypeData[i].m_pxIndexSections.reset(new SwIndexSections_Impl);
226 if(pCurTOX)
228 m_eCurrentTOXType.eType = pCurTOX->GetType();
229 sal_uInt16 nArrayIndex = static_cast< sal_uInt16 >(m_eCurrentTOXType.eType);
230 if(m_eCurrentTOXType.eType == TOX_USER)
232 //which user type is it?
233 for(sal_uInt16 nUser = 0; nUser < nUserTypeCount; nUser++)
235 const SwTOXType* pTemp = m_rWrtShell.GetTOXType(TOX_USER, nUser);
236 if(pCurTOX->GetTOXType() == pTemp)
238 m_eCurrentTOXType.nIndex = nUser;
239 nArrayIndex = static_cast< sal_uInt16 >(nUser > 0 ? TOX_AUTHORITIES + nUser : TOX_USER);
240 break;
244 m_vTypeData[nArrayIndex].m_pForm.reset(new SwForm(pCurTOX->GetTOXForm()));
245 m_vTypeData[nArrayIndex].m_pDescription = CreateTOXDescFromTOXBase(pCurTOX);
246 if(TOX_AUTHORITIES == m_eCurrentTOXType.eType)
248 const SwAuthorityFieldType* pFType = static_cast<const SwAuthorityFieldType*>(
249 m_rWrtShell.GetFieldType(SwFieldIds::TableOfAuthorities, OUString()));
250 if(pFType)
252 OUString sBrackets;
253 if(pFType->GetPrefix())
254 sBrackets += OUStringChar(pFType->GetPrefix());
255 if(pFType->GetSuffix())
256 sBrackets += OUStringChar(pFType->GetSuffix());
257 m_vTypeData[nArrayIndex].m_pDescription->SetAuthBrackets(sBrackets);
258 m_vTypeData[nArrayIndex].m_pDescription->SetAuthSequence(pFType->IsSequence());
260 else
262 m_vTypeData[nArrayIndex].m_pDescription->SetAuthBrackets("[]");
267 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
268 AddTabPage("index", SwTOXSelectTabPage::Create, nullptr);
269 AddTabPage("styles", SwTOXStylesTabPage::Create, nullptr);
270 AddTabPage("columns", SwColumnPage::Create, nullptr);
271 AddTabPage("background", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_BKG), nullptr);
272 AddTabPage("entries", SwTOXEntryTabPage::Create, nullptr);
273 if (!pCurTOX)
274 SetCurPageId("index");
276 m_xShowExampleCB->connect_toggled(LINK(this, SwMultiTOXTabDialog, ShowPreviewHdl));
277 m_xShowExampleCB->set_active(SW_MOD()->GetModuleConfig()->IsShowIndexPreview());
279 ShowPreview();
282 SwMultiTOXTabDialog::~SwMultiTOXTabDialog()
284 SW_MOD()->GetModuleConfig()->SetShowIndexPreview(m_xShowExampleCB->get_active());
287 void SwMultiTOXTabDialog::PageCreated(const OString& rId, SfxTabPage &rPage)
289 if (rId == "background")
291 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
292 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, static_cast<sal_uInt32>(SvxBackgroundTabFlags::SHOW_SELECTOR)));
293 rPage.PageCreated(aSet);
295 else if (rId == "columns")
297 const SwFormatFrameSize& rSize = GetInputSetImpl()->Get(RES_FRM_SIZE);
299 static_cast<SwColumnPage&>(rPage).SetPageWidth(rSize.GetWidth());
301 else if (rId == "entries")
302 static_cast<SwTOXEntryTabPage&>(rPage).SetWrtShell(m_rWrtShell);
303 else if (rId == "index")
305 static_cast<SwTOXSelectTabPage&>(rPage).SetWrtShell(m_rWrtShell);
306 if(USHRT_MAX != m_nInitialTOXType)
307 static_cast<SwTOXSelectTabPage&>(rPage).SelectType(static_cast<TOXTypes>(m_nInitialTOXType));
311 short SwMultiTOXTabDialog::Ok()
313 short nRet = SfxTabDialogController::Ok();
314 SwTOXDescription& rDesc = GetTOXDescription(m_eCurrentTOXType);
315 SwTOXBase aNewDef(*m_rWrtShell.GetDefaultTOXBase( m_eCurrentTOXType.eType, true ));
317 const sal_uInt16 nIndex = m_eCurrentTOXType.GetFlatIndex();
318 if(m_vTypeData[nIndex].m_pForm)
320 rDesc.SetForm(*m_vTypeData[nIndex].m_pForm);
321 aNewDef.SetTOXForm(*m_vTypeData[nIndex].m_pForm);
323 rDesc.ApplyTo(aNewDef);
324 if(!m_bGlobalFlag)
325 m_pMgr->UpdateOrInsertTOX(
326 rDesc, nullptr, GetOutputItemSet());
327 else if(m_bEditTOX)
328 m_pMgr->UpdateOrInsertTOX(
329 rDesc, &m_pParamTOXBase, GetOutputItemSet());
331 if(!m_eCurrentTOXType.nIndex)
332 m_rWrtShell.SetDefaultTOXBase(aNewDef);
334 return nRet;
337 SwForm* SwMultiTOXTabDialog::GetForm(CurTOXType eType)
339 const sal_uInt16 nIndex = eType.GetFlatIndex();
340 if(!m_vTypeData[nIndex].m_pForm)
341 m_vTypeData[nIndex].m_pForm.reset(new SwForm(eType.eType));
342 return m_vTypeData[nIndex].m_pForm.get();
345 SwTOXDescription& SwMultiTOXTabDialog::GetTOXDescription(CurTOXType eType)
347 const sal_uInt16 nIndex = eType.GetFlatIndex();
348 if(!m_vTypeData[nIndex].m_pDescription)
350 const SwTOXBase* pDef = m_rWrtShell.GetDefaultTOXBase( eType.eType );
351 if(pDef)
352 m_vTypeData[nIndex].m_pDescription = CreateTOXDescFromTOXBase(pDef);
353 else
355 m_vTypeData[nIndex].m_pDescription.reset(new SwTOXDescription(eType.eType));
356 if(eType.eType == TOX_USER)
357 m_vTypeData[nIndex].m_pDescription->SetTitle(m_sUserDefinedIndex);
358 else
359 m_vTypeData[nIndex].m_pDescription->SetTitle(
360 m_rWrtShell.GetTOXType(eType.eType, 0)->GetTypeName());
362 if(TOX_AUTHORITIES == eType.eType)
364 const SwAuthorityFieldType* pFType = static_cast<const SwAuthorityFieldType*>(
365 m_rWrtShell.GetFieldType(SwFieldIds::TableOfAuthorities, OUString()));
366 if(pFType)
368 m_vTypeData[nIndex].m_pDescription->SetAuthBrackets(OUStringChar(pFType->GetPrefix()) +
369 OUStringChar(pFType->GetSuffix()));
370 m_vTypeData[nIndex].m_pDescription->SetAuthSequence(pFType->IsSequence());
372 else
374 m_vTypeData[nIndex].m_pDescription->SetAuthBrackets("[]");
377 else if(TOX_INDEX == eType.eType)
378 m_vTypeData[nIndex].m_pDescription->SetMainEntryCharStyle(SwResId(STR_POOLCHR_IDX_MAIN_ENTRY));
381 return *m_vTypeData[nIndex].m_pDescription;
384 std::unique_ptr<SwTOXDescription> SwMultiTOXTabDialog::CreateTOXDescFromTOXBase(
385 const SwTOXBase*pCurTOX)
387 std::unique_ptr<SwTOXDescription> pDesc(new SwTOXDescription(pCurTOX->GetType()));
388 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
389 pDesc->SetStyleNames(pCurTOX->GetStyleNames(i), i);
390 pDesc->SetAutoMarkURL(m_rWrtShell.GetTOIAutoMarkURL());
391 pDesc->SetTitle(pCurTOX->GetTitle());
393 pDesc->SetContentOptions(pCurTOX->GetCreateType());
394 if(pDesc->GetTOXType() == TOX_INDEX)
395 pDesc->SetIndexOptions(pCurTOX->GetOptions());
396 pDesc->SetMainEntryCharStyle(pCurTOX->GetMainEntryCharStyle());
397 if(pDesc->GetTOXType() != TOX_INDEX)
398 pDesc->SetLevel(static_cast<sal_uInt8>(pCurTOX->GetLevel()));
399 pDesc->SetCreateFromObjectNames(pCurTOX->IsFromObjectNames());
400 pDesc->SetSequenceName(pCurTOX->GetSequenceName());
401 pDesc->SetCaptionDisplay(pCurTOX->GetCaptionDisplay());
402 pDesc->SetFromChapter(pCurTOX->IsFromChapter());
403 pDesc->SetReadonly(pCurTOX->IsProtected());
404 pDesc->SetOLEOptions(pCurTOX->GetOLEOptions());
405 pDesc->SetLevelFromChapter(pCurTOX->IsLevelFromChapter());
406 pDesc->SetLanguage(pCurTOX->GetLanguage());
407 pDesc->SetSortAlgorithm(pCurTOX->GetSortAlgorithm());
408 return pDesc;
411 void SwMultiTOXTabDialog::ShowPreview()
413 if (m_xShowExampleCB->get_active())
415 if(!m_xExampleFrame && !m_bExampleCreated)
417 m_bExampleCreated = true;
418 OUString sTemplate("internal/idxexample.odt");
420 SvtPathOptions aOpt;
421 bool bExist = aOpt.SearchFile( sTemplate, SvtPathOptions::Paths::Template );
423 if(!bExist)
425 OUString sInfo(SwResId(STR_FILE_NOT_FOUND));
426 sInfo = sInfo.replaceFirst( "%1", sTemplate );
427 sInfo = sInfo.replaceFirst( "%2", aOpt.GetTemplatePath() );
428 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(m_xDialog.get(),
429 VclMessageType::Info, VclButtonsType::Ok,
430 sInfo));
431 xInfoBox->run();
433 else
435 Link<SwOneExampleFrame&,void> aLink(LINK(this, SwMultiTOXTabDialog, CreateExample_Hdl));
436 m_xExampleFrame.reset(new SwOneExampleFrame(EX_SHOW_ONLINE_LAYOUT | EX_LOCALIZE_TOC_STRINGS, &aLink, &sTemplate));
437 m_xExampleFrameWin.reset(new weld::CustomWeld(*m_xBuilder, "example", *m_xExampleFrame));
439 m_xShowExampleCB->set_visible(m_xExampleFrame != nullptr);
443 if (m_xExampleFrame)
445 const bool bSetViewWindow = m_xShowExampleCB->get_active();
446 if (bSetViewWindow)
447 m_xExampleFrame->Show();
448 else
449 m_xExampleFrame->Hide();
453 IMPL_LINK_NOARG(SwMultiTOXTabDialog, ShowPreviewHdl, weld::Toggleable&, void)
455 ShowPreview();
456 m_xDialog->resize_to_request();
459 bool SwMultiTOXTabDialog::IsNoNum(SwWrtShell& rSh, const OUString& rName)
461 SwTextFormatColl* pColl = rSh.GetParaStyle(rName);
462 if(pColl && ! pColl->IsAssignedToListLevelOfOutlineStyle())
463 return true;
465 const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(
466 rName, SwGetPoolIdFromName::TxtColl);
467 return nId != USHRT_MAX &&
468 ! rSh.GetTextCollFromPool(nId)->IsAssignedToListLevelOfOutlineStyle();
471 namespace {
473 class SwAddStylesDlg_Impl : public SfxDialogController
475 OUString* pStyleArr;
477 std::unique_ptr<weld::Button> m_xOk;
478 std::unique_ptr<weld::Button> m_xLeftPB;
479 std::unique_ptr<weld::Button> m_xRightPB;
480 std::unique_ptr<weld::TreeView> m_xHeaderTree;
482 DECL_LINK(OkHdl, weld::Button&, void);
483 DECL_LINK(LeftRightHdl, weld::Button&, void);
484 DECL_LINK(KeyInput, const KeyEvent&, bool);
485 DECL_LINK(TreeSizeAllocHdl, const Size&, void);
486 DECL_LINK(RadioToggleOnHdl, const weld::TreeView::iter_col&, void);
487 DECL_LINK(HeaderBarClick, int, void);
489 public:
490 SwAddStylesDlg_Impl(weld::Window* pParent, SwWrtShell const & rWrtSh, OUString rStringArr[]);
495 SwAddStylesDlg_Impl::SwAddStylesDlg_Impl(weld::Window* pParent,
496 SwWrtShell const & rWrtSh, OUString rStringArr[])
497 : SfxDialogController(pParent, "modules/swriter/ui/assignstylesdialog.ui", "AssignStylesDialog")
498 , pStyleArr(rStringArr)
499 , m_xOk(m_xBuilder->weld_button("ok"))
500 , m_xLeftPB(m_xBuilder->weld_button("left"))
501 , m_xRightPB(m_xBuilder->weld_button("right"))
502 , m_xHeaderTree(m_xBuilder->weld_tree_view("styles"))
504 m_xOk->connect_clicked(LINK(this, SwAddStylesDlg_Impl, OkHdl));
505 m_xLeftPB->connect_clicked(LINK(this, SwAddStylesDlg_Impl, LeftRightHdl));
506 m_xRightPB->connect_clicked(LINK(this, SwAddStylesDlg_Impl, LeftRightHdl));
508 m_xHeaderTree->connect_size_allocate(LINK(this, SwAddStylesDlg_Impl, TreeSizeAllocHdl));
509 m_xHeaderTree->enable_toggle_buttons(weld::ColumnToggleType::Radio);
510 m_xHeaderTree->connect_toggled(LINK(this, SwAddStylesDlg_Impl, RadioToggleOnHdl));
511 m_xHeaderTree->connect_column_clicked(LINK(this, SwAddStylesDlg_Impl, HeaderBarClick));
513 std::vector<int> aWidths
515 o3tl::narrowing<int>(m_xHeaderTree->get_approximate_digit_width() * 30)
517 int nPadding = m_xHeaderTree->get_approximate_digit_width() * 2;
518 OUString sTitle(m_xHeaderTree->get_column_title(1));
519 for (sal_uInt16 i = 0; i <= MAXLEVEL; ++i)
521 sTitle = OUString::number(i);
522 m_xHeaderTree->set_column_title(i + 1, sTitle);
523 aWidths.push_back(m_xHeaderTree->get_pixel_size(sTitle).Width() + nPadding);
525 m_xHeaderTree->set_column_fixed_widths(aWidths);
526 auto nWidth = std::accumulate(aWidths.begin(), aWidths.end(),
527 Application::GetSettings().GetStyleSettings().GetScrollBarSize());
528 m_xHeaderTree->set_size_request(nWidth, m_xHeaderTree->get_height_rows(15));
530 int nRow(0);
531 for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
533 const OUString &rStyles{rStringArr[i]};
534 if (rStyles.isEmpty())
535 continue;
536 sal_Int32 nPos(0);
539 OUString sEntry = rStyles.getToken(0, TOX_STYLE_DELIMITER, nPos);
540 m_xHeaderTree->append_text(sEntry);
541 for (sal_uInt16 j = 0; j <= MAXLEVEL; ++j)
543 TriState eState = i == j - 1 ? TRISTATE_TRUE : TRISTATE_FALSE;
544 m_xHeaderTree->set_toggle(nRow, eState, j + 1);
546 ++nRow;
547 } while (nPos>=0);
549 // now the other styles
551 const sal_uInt16 nSz = rWrtSh.GetTextFormatCollCount();
552 for (sal_uInt16 j = 0; j < nSz; ++j)
554 const SwTextFormatColl& rColl = rWrtSh.GetTextFormatColl(j);
555 if (rColl.IsDefault())
556 continue;
558 const OUString aName = rColl.GetName();
559 if (!aName.isEmpty())
561 bool bEntry = false;
562 int nChildren = m_xHeaderTree->n_children();
563 for (int i = 0; i < nChildren; ++i)
565 if (m_xHeaderTree->get_text(i, 0) == aName)
567 bEntry = true;
568 break;
571 if (!bEntry)
573 m_xHeaderTree->append_text(aName);
574 for (sal_uInt16 k = 0; k <= MAXLEVEL; ++k)
576 TriState eState = k == 0 ? TRISTATE_TRUE : TRISTATE_FALSE;
577 m_xHeaderTree->set_toggle(nRow, eState, k + 1);
579 ++nRow;
584 m_xHeaderTree->make_sorted();
585 m_xHeaderTree->set_sort_column(0);
586 m_xHeaderTree->set_sort_order(true);
587 m_xHeaderTree->set_sort_indicator(TRISTATE_TRUE, 0);
589 m_xHeaderTree->select(0);
590 m_xHeaderTree->connect_key_release(LINK(this, SwAddStylesDlg_Impl, KeyInput));
593 IMPL_LINK(SwAddStylesDlg_Impl, HeaderBarClick, int, nColumn, void)
595 bool bSortAtoZ = m_xHeaderTree->get_sort_order();
597 //set new arrow positions in headerbar
598 if (nColumn == m_xHeaderTree->get_sort_column())
600 bSortAtoZ = !bSortAtoZ;
601 m_xHeaderTree->set_sort_order(bSortAtoZ);
604 if (nColumn != -1)
606 //sort lists
607 m_xHeaderTree->set_sort_indicator(bSortAtoZ ? TRISTATE_TRUE : TRISTATE_FALSE, nColumn);
611 IMPL_LINK(SwAddStylesDlg_Impl, TreeSizeAllocHdl, const Size&, rSize, void)
613 auto nWidth = rSize.Width() - Application::GetSettings().GetStyleSettings().GetScrollBarSize();
615 std::vector<int> aWidths { 0 };
616 int nPadding = m_xHeaderTree->get_approximate_digit_width() * 2;
617 for (sal_uInt16 i = 0; i <= MAXLEVEL; ++i)
619 OUString sTitle(m_xHeaderTree->get_column_title(i + 1));
620 aWidths.push_back(m_xHeaderTree->get_pixel_size(sTitle).Width() + nPadding);
622 auto nOtherWidth = std::accumulate(aWidths.begin(), aWidths.end(), 0);
623 aWidths[0] = nWidth - nOtherWidth;
624 m_xHeaderTree->set_column_fixed_widths(aWidths);
627 IMPL_LINK(SwAddStylesDlg_Impl, RadioToggleOnHdl, const weld::TreeView::iter_col&, rRowCol, void)
629 for (sal_uInt16 i = 0; i <= MAXLEVEL; ++i)
631 TriState eState = rRowCol.second == i + 1 ? TRISTATE_TRUE : TRISTATE_FALSE;
632 m_xHeaderTree->set_toggle(rRowCol.first, eState, i + 1);
636 IMPL_LINK(SwAddStylesDlg_Impl, KeyInput, const KeyEvent&, rKEvt, bool)
638 vcl::KeyCode aCode = rKEvt.GetKeyCode();
639 bool bHandled = false;
641 if (aCode.GetCode() == KEY_ADD || aCode.GetCode() == KEY_RIGHT)
643 LeftRightHdl(*m_xRightPB);
644 bHandled = true;
646 else if (aCode.GetCode() == KEY_SUBTRACT || aCode.GetCode() == KEY_LEFT)
648 LeftRightHdl(*m_xLeftPB);
649 bHandled = true;
652 return bHandled;
655 IMPL_LINK_NOARG(SwAddStylesDlg_Impl, OkHdl, weld::Button&, void)
657 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
658 pStyleArr[i].clear();
660 int nChildren = m_xHeaderTree->n_children();
661 for (int i = 0; i < nChildren; ++i)
663 int nToggleColumn = 0;
664 for (sal_uInt16 j = 0; j <= MAXLEVEL; ++j)
666 if (m_xHeaderTree->get_toggle(i, j + 1) == TRISTATE_TRUE)
668 nToggleColumn = j;
669 break;
672 if (nToggleColumn)
674 int nLevel = nToggleColumn - 1;
675 if(!pStyleArr[nLevel].isEmpty())
676 pStyleArr[nLevel] += OUStringChar(TOX_STYLE_DELIMITER);
677 pStyleArr[nLevel] += m_xHeaderTree->get_text(i, 0);
681 //TODO write back style names
682 m_xDialog->response(RET_OK);
685 IMPL_LINK(SwAddStylesDlg_Impl, LeftRightHdl, weld::Button&, rBtn, void)
687 bool bLeft = &rBtn == m_xLeftPB.get();
688 int nEntry = m_xHeaderTree->get_selected_index();
689 if (nEntry == -1)
690 return;
692 int nToggleColumn = 0;
693 for (sal_uInt16 j = 0; j <= MAXLEVEL; ++j)
695 if (m_xHeaderTree->get_toggle(nEntry, j + 1) == TRISTATE_TRUE)
697 nToggleColumn = j;
698 break;
702 if (bLeft)
704 if (nToggleColumn)
705 --nToggleColumn;
707 else
709 if (nToggleColumn < MAXLEVEL)
710 ++nToggleColumn;
713 for (sal_uInt16 j = 0; j <= MAXLEVEL; ++j)
715 m_xHeaderTree->set_toggle(nEntry, j == nToggleColumn ? TRISTATE_TRUE : TRISTATE_FALSE, j + 1);
719 SwTOXSelectTabPage::SwTOXSelectTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rAttrSet)
720 : SfxTabPage(pPage, pController, "modules/swriter/ui/tocindexpage.ui", "TocIndexPage", &rAttrSet)
721 , sAutoMarkType(SwResId(STR_AUTOMARK_TYPE))
722 , m_bWaitingInitialSettings(true)
723 , m_xTitleED(m_xBuilder->weld_entry("title"))
724 , m_xTypeFT(m_xBuilder->weld_label("typeft"))
725 , m_xTypeLB(m_xBuilder->weld_combo_box("type"))
726 , m_xReadOnlyCB(m_xBuilder->weld_check_button("readonly"))
727 , m_xAreaFrame(m_xBuilder->weld_widget("areaframe"))
728 , m_xAreaLB(m_xBuilder->weld_combo_box("scope"))
729 , m_xLevelFT(m_xBuilder->weld_label("levelft"))
730 , m_xLevelNF(m_xBuilder->weld_spin_button("level"))
731 , m_xCreateFrame(m_xBuilder->weld_widget("createframe"))
732 , m_xFromHeadingsCB(m_xBuilder->weld_check_button("fromheadings"))
733 , m_xStylesCB(m_xBuilder->weld_check_button("stylescb"))
734 , m_xAddStylesCB(m_xBuilder->weld_check_button("addstylescb"))
735 , m_xAddStylesPB(m_xBuilder->weld_button("styles"))
736 , m_xFromTablesCB(m_xBuilder->weld_check_button("fromtables"))
737 , m_xFromFramesCB(m_xBuilder->weld_check_button("fromframes"))
738 , m_xFromGraphicsCB(m_xBuilder->weld_check_button("fromgraphics"))
739 , m_xFromOLECB(m_xBuilder->weld_check_button("fromoles"))
740 , m_xLevelFromChapterCB(m_xBuilder->weld_check_button("uselevel"))
741 , m_xFromCaptionsRB(m_xBuilder->weld_radio_button("captions"))
742 , m_xFromObjectNamesRB(m_xBuilder->weld_radio_button("objnames"))
743 , m_xCaptionSequenceFT(m_xBuilder->weld_label("categoryft"))
744 , m_xCaptionSequenceLB(m_xBuilder->weld_combo_box("category"))
745 , m_xDisplayTypeFT(m_xBuilder->weld_label("displayft"))
746 , m_xDisplayTypeLB(m_xBuilder->weld_combo_box("display"))
747 , m_xTOXMarksCB(m_xBuilder->weld_check_button("indexmarks"))
748 , m_xIdxOptionsFrame(m_xBuilder->weld_widget("optionsframe"))
749 , m_xCollectSameCB(m_xBuilder->weld_check_button("combinesame"))
750 , m_xUseFFCB(m_xBuilder->weld_check_button("useff"))
751 , m_xUseDashCB(m_xBuilder->weld_check_button("usedash"))
752 , m_xCaseSensitiveCB(m_xBuilder->weld_check_button("casesens"))
753 , m_xInitialCapsCB(m_xBuilder->weld_check_button("initcaps"))
754 , m_xKeyAsEntryCB(m_xBuilder->weld_check_button("keyasentry"))
755 , m_xFromFileCB(m_xBuilder->weld_check_button("fromfile"))
756 , m_xAutoMarkPB(m_xBuilder->weld_menu_button("file"))
757 , m_xFromObjCLB(m_xBuilder->weld_tree_view("objects"))
758 , m_xFromObjFrame(m_xBuilder->weld_widget("objectframe"))
759 , m_xSequenceCB(m_xBuilder->weld_check_button("numberentries"))
760 , m_xBracketLB(m_xBuilder->weld_combo_box("brackets"))
761 , m_xAuthorityFrame(m_xBuilder->weld_widget("authframe"))
762 , m_xSortFrame(m_xBuilder->weld_widget("sortframe"))
763 , m_xLanguageLB(new SvxLanguageBox(m_xBuilder->weld_combo_box("lang")))
764 , m_xSortAlgorithmLB(m_xBuilder->weld_combo_box("keytype"))
766 sAddStyleUser = m_xStylesCB->get_label();
767 pIndexEntryWrapper.reset(new IndexEntrySupplierWrapper());
769 m_xLanguageLB->SetLanguageList( SvxLanguageListFlags::ALL | SvxLanguageListFlags::ONLY_KNOWN,
770 false );
772 //Default mode is arranged to be the tallest mode
773 //of alphabetical index, lock that size in now
774 LanguageHdl(nullptr); //fill sort algorithm list
775 Size aPrefSize(m_xContainer->get_preferred_size());
776 m_xContainer->set_size_request(aPrefSize.Width(), aPrefSize.Height());
778 sAddStyleContent = m_xAddStylesCB->get_label();
780 m_xFromObjCLB->enable_toggle_buttons(weld::ColumnToggleType::Check);
782 for (size_t i = 0; i < SAL_N_ELEMENTS(RES_SRCTYPES); ++i)
784 OUString sId(OUString::number(static_cast<sal_uInt32>(RES_SRCTYPES[i].second)));
785 m_xFromObjCLB->append();
786 m_xFromObjCLB->set_toggle(i, TRISTATE_FALSE);
787 m_xFromObjCLB->set_text(i, SwResId(RES_SRCTYPES[i].first), 0);
788 m_xFromObjCLB->set_id(i, sId);
790 m_xFromObjCLB->set_size_request(-1, std::max<int>(m_xFromObjCLB->get_preferred_size().Height(),
791 m_xFromObjCLB->get_height_rows(SAL_N_ELEMENTS(RES_SRCTYPES))) + 2);
793 SetExchangeSupport();
794 m_xTypeLB->connect_changed(LINK(this, SwTOXSelectTabPage, TOXTypeHdl));
796 m_xAddStylesPB->connect_clicked(LINK(this, SwTOXSelectTabPage, AddStylesHdl));
798 m_xAutoMarkPB->connect_toggled(LINK(this, SwTOXSelectTabPage, MenuEnableHdl));
799 m_xAutoMarkPB->connect_selected(LINK(this, SwTOXSelectTabPage, MenuExecuteHdl));
801 Link<weld::Toggleable&,void> aLk = LINK(this, SwTOXSelectTabPage, CheckBoxHdl);
802 m_xAddStylesCB->connect_toggled(aLk);
803 m_xFromHeadingsCB->connect_toggled(aLk);
804 m_xTOXMarksCB->connect_toggled(aLk);
805 m_xFromFileCB->connect_toggled(aLk);
806 m_xCollectSameCB->connect_toggled(aLk);
807 m_xUseFFCB->connect_toggled(aLk);
808 m_xUseDashCB->connect_toggled(aLk);
809 m_xInitialCapsCB->connect_toggled(aLk);
810 m_xKeyAsEntryCB->connect_toggled(aLk);
812 m_xTitleED->connect_changed(LINK(this, SwTOXSelectTabPage, ModifyEntryHdl));
813 m_xLevelNF->connect_value_changed(LINK(this, SwTOXSelectTabPage, ModifySpinHdl));
814 m_xSortAlgorithmLB->connect_changed(LINK(this, SwTOXSelectTabPage, ModifyListBoxHdl));
816 aLk = LINK(this, SwTOXSelectTabPage, RadioButtonHdl);
817 m_xFromCaptionsRB->connect_toggled(aLk);
818 m_xFromObjectNamesRB->connect_toggled(aLk);
819 RadioButtonHdl(*m_xFromCaptionsRB);
821 m_xLanguageLB->connect_changed(LINK(this, SwTOXSelectTabPage, LanguageListBoxHdl));
822 m_xTypeLB->set_active(0);
823 m_xTitleED->save_value();
826 SwTOXSelectTabPage::~SwTOXSelectTabPage()
828 pIndexRes.reset();
829 pIndexEntryWrapper.reset();
830 m_xLanguageLB.reset();
833 void SwTOXSelectTabPage::SetWrtShell(SwWrtShell const & rSh)
835 const sal_uInt16 nUserTypeCount = rSh.GetTOXTypeCount(TOX_USER);
836 if(nUserTypeCount <= 1)
837 return;
839 //insert all new user indexes names after the standard user index
840 sal_Int32 nPos = m_xTypeLB->find_id(OUString::number(sal_uInt32(TO_USER))) + 1;
841 for (sal_uInt16 nUser = 1; nUser < nUserTypeCount; nUser++)
843 sal_uInt32 nEntryData = nUser << 8;
844 nEntryData |= TO_USER;
845 OUString sId(OUString::number(nEntryData));
846 m_xTypeLB->insert(nPos++, rSh.GetTOXType(TOX_USER, nUser)->GetTypeName(),
847 &sId, nullptr, nullptr);
851 bool SwTOXSelectTabPage::FillItemSet( SfxItemSet* )
853 return true;
856 static tools::Long lcl_TOXTypesToUserData(CurTOXType eType)
858 sal_uInt16 nRet = TOX_INDEX;
859 switch(eType.eType)
861 case TOX_INDEX : nRet = TO_INDEX; break;
862 case TOX_USER :
864 nRet = eType.nIndex << 8;
865 nRet |= TO_USER;
867 break;
868 case TOX_CONTENT : nRet = TO_CONTENT; break;
869 case TOX_ILLUSTRATIONS:nRet = TO_ILLUSTRATION; break;
870 case TOX_OBJECTS : nRet = TO_OBJECT; break;
871 case TOX_TABLES : nRet = TO_TABLE; break;
872 case TOX_AUTHORITIES : nRet = TO_AUTHORITIES; break;
873 case TOX_BIBLIOGRAPHY : nRet = TO_BIBLIOGRAPHY; break;
874 case TOX_CITATION :break;
876 return nRet;
879 void SwTOXSelectTabPage::SelectType(TOXTypes eSet)
881 CurTOXType eCurType (eSet);
883 sal_uInt32 nData = lcl_TOXTypesToUserData(eCurType);
884 m_xTypeLB->set_active_id(OUString::number(nData));
885 m_xTypeFT->set_sensitive(false);
886 m_xTypeLB->set_sensitive(false);
887 TOXTypeHdl(*m_xTypeLB);
890 static CurTOXType lcl_UserData2TOXTypes(sal_uInt16 nData)
892 CurTOXType eRet;
894 switch(nData&0xff)
896 case TO_INDEX : eRet.eType = TOX_INDEX; break;
897 case TO_USER :
899 eRet.eType = TOX_USER;
900 eRet.nIndex = (nData&0xff00) >> 8;
902 break;
903 case TO_CONTENT : eRet.eType = TOX_CONTENT; break;
904 case TO_ILLUSTRATION: eRet.eType = TOX_ILLUSTRATIONS; break;
905 case TO_OBJECT : eRet.eType = TOX_OBJECTS; break;
906 case TO_TABLE : eRet.eType = TOX_TABLES; break;
907 case TO_AUTHORITIES : eRet.eType = TOX_AUTHORITIES; break;
908 case TO_BIBLIOGRAPHY : eRet.eType = TOX_BIBLIOGRAPHY; break;
909 default: OSL_FAIL("what a type?");
911 return eRet;
914 void SwTOXSelectTabPage::ApplyTOXDescription()
916 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
917 const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
918 SwTOXDescription& rDesc = pTOXDlg->GetTOXDescription(aCurType);
919 m_xReadOnlyCB->set_active(rDesc.IsReadonly());
920 if (!m_xTitleED->get_value_changed_from_saved())
922 if (rDesc.GetTitle())
923 m_xTitleED->set_text(*rDesc.GetTitle());
924 else
925 m_xTitleED->set_text(OUString());
926 m_xTitleED->save_value();
929 m_xAreaLB->set_active(rDesc.IsFromChapter() ? 1 : 0);
931 if (aCurType.eType != TOX_INDEX)
932 m_xLevelNF->set_value(rDesc.GetLevel()); //content, user
934 SwTOXElement nCreateType = rDesc.GetContentOptions();
936 //user + content
937 bool bHasStyleNames = false;
939 for( sal_uInt16 i = 0; i < MAXLEVEL; i++)
940 if(!rDesc.GetStyleNames(i).isEmpty())
942 bHasStyleNames = true;
943 break;
945 m_xAddStylesCB->set_active(bHasStyleNames && (nCreateType & SwTOXElement::Template));
947 m_xFromOLECB->set_active( bool(nCreateType & SwTOXElement::Ole) );
948 m_xFromTablesCB->set_active( bool(nCreateType & SwTOXElement::Table) );
949 m_xFromGraphicsCB->set_active( bool(nCreateType & SwTOXElement::Graphic) );
950 m_xFromFramesCB->set_active( bool(nCreateType & SwTOXElement::Frame) );
952 m_xLevelFromChapterCB->set_active(rDesc.IsLevelFromChapter());
954 //all but illustration and table
955 m_xTOXMarksCB->set_active( bool(nCreateType & SwTOXElement::Mark) );
957 //content
958 if(TOX_CONTENT == aCurType.eType)
960 m_xFromHeadingsCB->set_active( bool(nCreateType & SwTOXElement::OutlineLevel) );
961 m_xAddStylesCB->set_label(sAddStyleContent);
962 m_xAddStylesPB->set_sensitive(m_xAddStylesCB->get_active());
964 //index only
965 else if(TOX_INDEX == aCurType.eType)
967 const SwTOIOptions nIndexOptions = rDesc.GetIndexOptions();
968 m_xCollectSameCB->set_active( bool(nIndexOptions & SwTOIOptions::SameEntry) );
969 m_xUseFFCB->set_active( bool(nIndexOptions & SwTOIOptions::FF) );
970 m_xUseDashCB->set_active( bool(nIndexOptions & SwTOIOptions::Dash) );
971 if (m_xUseFFCB->get_active())
972 m_xUseDashCB->set_sensitive(false);
973 else if (m_xUseDashCB->get_active())
974 m_xUseFFCB->set_sensitive(false);
976 m_xCaseSensitiveCB->set_active( bool(nIndexOptions & SwTOIOptions::CaseSensitive) );
977 m_xInitialCapsCB->set_active( bool(nIndexOptions & SwTOIOptions::InitialCaps) );
978 m_xKeyAsEntryCB->set_active( bool(nIndexOptions & SwTOIOptions::KeyAsEntry) );
980 else if (TOX_ILLUSTRATIONS == aCurType.eType || TOX_TABLES == aCurType.eType)
982 m_xFromObjectNamesRB->set_active(rDesc.IsCreateFromObjectNames());
983 m_xFromCaptionsRB->set_active(!rDesc.IsCreateFromObjectNames());
984 OUString sName(rDesc.GetSequenceName());
985 int nIndex = m_xCaptionSequenceLB->find_text(sName);
986 if (nIndex != -1)
987 m_xCaptionSequenceLB->set_active(nIndex);
988 m_xDisplayTypeLB->set_active(static_cast<sal_Int32>(rDesc.GetCaptionDisplay()));
989 if (m_xDisplayTypeLB->get_active() == -1)
990 m_xDisplayTypeLB->set_active(0);
991 RadioButtonHdl(*m_xFromCaptionsRB);
994 else if(TOX_OBJECTS == aCurType.eType)
996 SwTOOElements nOLEData = rDesc.GetOLEOptions();
997 for (int nFromObj = 0, nCount = m_xFromObjCLB->n_children(); nFromObj < nCount; ++nFromObj)
999 SwTOOElements nData = static_cast<SwTOOElements>(m_xFromObjCLB->get_id(nFromObj).toInt32());
1000 m_xFromObjCLB->set_toggle(nFromObj, bool(nData & nOLEData) ? TRISTATE_TRUE : TRISTATE_FALSE);
1003 else if(TOX_AUTHORITIES == aCurType.eType)
1005 const OUString& sBrackets(rDesc.GetAuthBrackets());
1006 if(sBrackets.isEmpty() || sBrackets == " ")
1007 m_xBracketLB->set_active(0);
1008 else
1009 m_xBracketLB->set_active_text(sBrackets);
1010 m_xSequenceCB->set_active(rDesc.IsAuthSequence());
1012 m_xAutoMarkPB->set_sensitive(m_xFromFileCB->get_active());
1014 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
1015 aStyleArr[i] = rDesc.GetStyleNames(i);
1017 m_xLanguageLB->set_active_id(rDesc.GetLanguage());
1018 LanguageHdl(nullptr);
1019 for (int nCnt = 0, nEntryCount = m_xSortAlgorithmLB->get_count(); nCnt < nEntryCount; ++nCnt)
1021 const OUString& rEntryData = m_xSortAlgorithmLB->get_id(nCnt);
1022 if (rEntryData == rDesc.GetSortAlgorithm())
1024 m_xSortAlgorithmLB->set_active(nCnt);
1025 break;
1030 void SwTOXSelectTabPage::FillTOXDescription()
1032 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
1033 CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
1034 SwTOXDescription& rDesc = pTOXDlg->GetTOXDescription(aCurType);
1035 rDesc.SetTitle(m_xTitleED->get_text());
1036 rDesc.SetFromChapter(1 == m_xAreaLB->get_active());
1037 SwTOXElement nContentOptions = SwTOXElement::NONE;
1038 if (m_xTOXMarksCB->get_visible() && m_xTOXMarksCB->get_active())
1039 nContentOptions |= SwTOXElement::Mark;
1041 SwTOIOptions nIndexOptions = rDesc.GetIndexOptions()&SwTOIOptions::AlphaDelimiter;
1042 switch(rDesc.GetTOXType())
1044 case TOX_CONTENT:
1045 if(m_xFromHeadingsCB->get_active())
1046 nContentOptions |= SwTOXElement::OutlineLevel;
1047 break;
1048 case TOX_USER:
1050 rDesc.SetTOUName(m_xTypeLB->get_active_text());
1052 if(m_xFromOLECB->get_active())
1053 nContentOptions |= SwTOXElement::Ole;
1054 if(m_xFromTablesCB->get_active())
1055 nContentOptions |= SwTOXElement::Table;
1056 if(m_xFromFramesCB->get_active())
1057 nContentOptions |= SwTOXElement::Frame;
1058 if(m_xFromGraphicsCB->get_active())
1059 nContentOptions |= SwTOXElement::Graphic;
1061 break;
1062 case TOX_INDEX:
1064 nContentOptions = SwTOXElement::Mark;
1066 if(m_xCollectSameCB->get_active())
1067 nIndexOptions |= SwTOIOptions::SameEntry;
1068 if(m_xUseFFCB->get_active())
1069 nIndexOptions |= SwTOIOptions::FF;
1070 if(m_xUseDashCB->get_active())
1071 nIndexOptions |= SwTOIOptions::Dash;
1072 if(m_xCaseSensitiveCB->get_active())
1073 nIndexOptions |= SwTOIOptions::CaseSensitive;
1074 if(m_xInitialCapsCB->get_active())
1075 nIndexOptions |= SwTOIOptions::InitialCaps;
1076 if(m_xKeyAsEntryCB->get_active())
1077 nIndexOptions |= SwTOIOptions::KeyAsEntry;
1078 if(m_xFromFileCB->get_active())
1079 rDesc.SetAutoMarkURL(sAutoMarkURL);
1080 else
1081 rDesc.SetAutoMarkURL(OUString());
1083 break;
1084 case TOX_ILLUSTRATIONS:
1085 case TOX_TABLES :
1086 rDesc.SetCreateFromObjectNames(m_xFromObjectNamesRB->get_active());
1087 rDesc.SetSequenceName(m_xCaptionSequenceLB->get_active_text());
1088 rDesc.SetCaptionDisplay(static_cast<SwCaptionDisplay>(m_xDisplayTypeLB->get_active()));
1089 break;
1090 case TOX_OBJECTS:
1092 SwTOOElements nOLEData = SwTOOElements::NONE;
1093 for (int i = 0, nCount = m_xFromObjCLB->n_children(); i < nCount; ++i)
1095 if (m_xFromObjCLB->get_toggle(i) == TRISTATE_TRUE)
1097 SwTOOElements nData = static_cast<SwTOOElements>(m_xFromObjCLB->get_id(i).toInt32());
1098 nOLEData |= nData;
1101 rDesc.SetOLEOptions(nOLEData);
1103 break;
1104 case TOX_AUTHORITIES:
1105 case TOX_BIBLIOGRAPHY :
1107 if (m_xBracketLB->get_active())
1108 rDesc.SetAuthBrackets(m_xBracketLB->get_active_text());
1109 else
1110 rDesc.SetAuthBrackets(OUString());
1111 rDesc.SetAuthSequence(m_xSequenceCB->get_active());
1113 break;
1114 case TOX_CITATION :
1115 break;
1118 rDesc.SetLevelFromChapter( m_xLevelFromChapterCB->get_visible() &&
1119 m_xLevelFromChapterCB->get_active());
1120 if (m_xTOXMarksCB->get_active() && m_xTOXMarksCB->get_visible())
1121 nContentOptions |= SwTOXElement::Mark;
1122 if (m_xFromHeadingsCB->get_active() && m_xFromHeadingsCB->get_visible())
1123 nContentOptions |= SwTOXElement::OutlineLevel;
1124 if (m_xAddStylesCB->get_active() && m_xAddStylesCB->get_visible())
1125 nContentOptions |= SwTOXElement::Template;
1127 rDesc.SetContentOptions(nContentOptions);
1128 rDesc.SetIndexOptions(nIndexOptions);
1129 rDesc.SetLevel(m_xLevelNF->get_value());
1131 rDesc.SetReadonly(m_xReadOnlyCB->get_active());
1133 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
1134 rDesc.SetStyleNames(aStyleArr[i], i);
1136 rDesc.SetLanguage(m_xLanguageLB->get_active_id());
1137 const OUString& rEntryData = m_xSortAlgorithmLB->get_active_id();
1138 rDesc.SetSortAlgorithm(rEntryData);
1141 void SwTOXSelectTabPage::Reset( const SfxItemSet* )
1143 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
1144 SwWrtShell& rSh = pTOXDlg->GetWrtShell();
1145 const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
1146 sal_uInt32 nData = lcl_TOXTypesToUserData(aCurType);
1147 m_xTypeLB->set_active_id(OUString::number(nData));
1149 sAutoMarkURL = INetURLObject::decode( rSh.GetTOIAutoMarkURL(),
1150 INetURLObject::DecodeMechanism::Unambiguous );
1151 m_xFromFileCB->set_active(!sAutoMarkURL.isEmpty());
1153 m_xCaptionSequenceLB->clear();
1154 const size_t nCount = rSh.GetFieldTypeCount(SwFieldIds::SetExp);
1155 for (size_t i = 0; i < nCount; ++i)
1157 SwFieldType *pType = rSh.GetFieldType( i, SwFieldIds::SetExp );
1158 if( pType->Which() == SwFieldIds::SetExp &&
1159 static_cast<SwSetExpFieldType *>( pType)->GetType() & nsSwGetSetExpType::GSE_SEQ )
1160 m_xCaptionSequenceLB->append_text(pType->GetName());
1163 if(pTOXDlg->IsTOXEditMode())
1165 m_xTypeFT->set_sensitive(false);
1166 m_xTypeLB->set_sensitive(false);
1169 if(!m_bWaitingInitialSettings)
1171 // save current values into the proper TOXDescription
1172 FillTOXDescription();
1174 m_bWaitingInitialSettings = false;
1176 TOXTypeHdl(*m_xTypeLB);
1177 CheckBoxHdl(*m_xAddStylesCB);
1180 void SwTOXSelectTabPage::ActivatePage( const SfxItemSet& )
1182 //nothing to do
1185 DeactivateRC SwTOXSelectTabPage::DeactivatePage(SfxItemSet* _pSet)
1187 if (_pSet)
1188 _pSet->Put(SfxUInt16Item(FN_PARAM_TOX_TYPE, m_xTypeLB->get_active_id().toUInt32()));
1189 FillTOXDescription();
1190 return DeactivateRC::LeavePage;
1193 std::unique_ptr<SfxTabPage> SwTOXSelectTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
1195 return std::make_unique<SwTOXSelectTabPage>(pPage, pController, *rAttrSet);
1198 IMPL_LINK(SwTOXSelectTabPage, TOXTypeHdl, weld::ComboBox&, rBox, void)
1200 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
1201 const sal_uInt16 nType = rBox.get_active_id().toUInt32();
1202 CurTOXType eCurType = lcl_UserData2TOXTypes(nType);
1203 pTOXDlg->SetCurrentTOXType(eCurType);
1205 m_xAreaLB->set_visible( 0 != (nType & (TO_CONTENT|TO_ILLUSTRATION|TO_USER|TO_INDEX|TO_TABLE|TO_OBJECT)) );
1206 m_xLevelFT->set_visible( 0 != (nType & (TO_CONTENT)) );
1207 m_xLevelNF->set_visible( 0 != (nType & (TO_CONTENT)) );
1208 m_xLevelFromChapterCB->set_visible( 0 != (nType & (TO_USER)) );
1209 m_xAreaFrame->set_visible( 0 != (nType & (TO_CONTENT|TO_ILLUSTRATION|TO_USER|TO_INDEX|TO_TABLE|TO_OBJECT)) );
1211 m_xFromHeadingsCB->set_visible( 0 != (nType & (TO_CONTENT)) );
1212 m_xAddStylesCB->set_visible( 0 != (nType & (TO_CONTENT|TO_USER)) );
1213 m_xAddStylesPB->set_visible( 0 != (nType & (TO_CONTENT|TO_USER)) );
1215 m_xFromTablesCB->set_visible( 0 != (nType & (TO_USER)) );
1216 m_xFromFramesCB->set_visible( 0 != (nType & (TO_USER)) );
1217 m_xFromGraphicsCB->set_visible( 0 != (nType & (TO_USER)) );
1218 m_xFromOLECB->set_visible( 0 != (nType & (TO_USER)) );
1220 m_xFromCaptionsRB->set_visible( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
1221 m_xFromObjectNamesRB->set_visible( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
1223 m_xTOXMarksCB->set_visible( 0 != (nType & (TO_CONTENT|TO_USER)) );
1225 m_xCreateFrame->set_visible( 0 != (nType & (TO_CONTENT|TO_ILLUSTRATION|TO_USER|TO_TABLE)) );
1226 m_xCaptionSequenceFT->set_visible( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
1227 m_xCaptionSequenceLB->set_visible( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
1228 m_xDisplayTypeFT->set_visible( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
1229 m_xDisplayTypeLB->set_visible( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
1231 m_xAuthorityFrame->set_visible( 0 != (nType & TO_AUTHORITIES) );
1233 bool bEnableSortLanguage = 0 != (nType & (TO_INDEX|TO_AUTHORITIES));
1234 m_xSortFrame->set_visible(bEnableSortLanguage);
1236 if( nType & TO_ILLUSTRATION )
1238 OUString sName(SwStyleNameMapper::GetUIName(RES_POOLCOLL_LABEL_FIGURE, OUString()));
1239 m_xCaptionSequenceLB->set_active_text(sName);
1241 else if( nType & TO_TABLE )
1243 OUString sName(SwStyleNameMapper::GetUIName(RES_POOLCOLL_LABEL_TABLE, OUString()));
1244 m_xCaptionSequenceLB->set_active_text(sName);
1246 else if( nType & TO_USER )
1248 m_xAddStylesCB->set_label(sAddStyleUser);
1251 m_xIdxOptionsFrame->set_visible( 0 != (nType & TO_INDEX) );
1253 //object index
1254 m_xFromObjFrame->set_visible( 0 != (nType & TO_OBJECT) );
1256 //set control values from the proper TOXDescription
1258 ApplyTOXDescription();
1260 ModifyHdl();
1263 void SwTOXSelectTabPage::ModifyHdl()
1265 if(!m_bWaitingInitialSettings)
1267 FillTOXDescription();
1268 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
1269 pTOXDlg->CreateOrUpdateExample(pTOXDlg->GetCurrentTOXType().eType, TOX_PAGE_SELECT);
1273 IMPL_LINK_NOARG(SwTOXSelectTabPage, ModifyListBoxHdl, weld::ComboBox&, void)
1275 ModifyHdl();
1278 IMPL_LINK_NOARG(SwTOXSelectTabPage, ModifyEntryHdl, weld::Entry&, void)
1280 ModifyHdl();
1283 IMPL_LINK_NOARG(SwTOXSelectTabPage, ModifySpinHdl, weld::SpinButton&, void)
1285 ModifyHdl();
1288 IMPL_LINK(SwTOXSelectTabPage, CheckBoxHdl, weld::Toggleable&, rButton, void)
1290 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
1291 const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
1292 if(TOX_CONTENT == aCurType.eType)
1294 //at least one of the three CheckBoxes must be checked
1295 if (!m_xAddStylesCB->get_active() && !m_xFromHeadingsCB->get_active() && !m_xTOXMarksCB->get_active())
1297 //TODO: InfoBox?
1298 rButton.set_active(true);
1300 m_xAddStylesPB->set_sensitive(m_xAddStylesCB->get_active());
1302 if (TOX_USER == aCurType.eType)
1304 m_xAddStylesPB->set_sensitive(m_xAddStylesCB->get_active());
1306 else if (TOX_INDEX == aCurType.eType)
1308 m_xAutoMarkPB->set_sensitive(m_xFromFileCB->get_active());
1309 m_xUseFFCB->set_sensitive(m_xCollectSameCB->get_active() && !m_xUseDashCB->get_active());
1310 m_xUseDashCB->set_sensitive(m_xCollectSameCB->get_active() && !m_xUseFFCB->get_active());
1311 m_xCaseSensitiveCB->set_sensitive(m_xCollectSameCB->get_active());
1313 ModifyHdl();
1316 IMPL_LINK_NOARG(SwTOXSelectTabPage, RadioButtonHdl, weld::Toggleable&, void)
1318 bool bEnable = m_xFromCaptionsRB->get_active();
1319 m_xCaptionSequenceFT->set_sensitive(bEnable);
1320 m_xCaptionSequenceLB->set_sensitive(bEnable);
1321 m_xDisplayTypeFT->set_sensitive(bEnable);
1322 m_xDisplayTypeLB->set_sensitive(bEnable);
1323 ModifyHdl();
1326 IMPL_LINK(SwTOXSelectTabPage, LanguageListBoxHdl, weld::ComboBox&, rBox, void)
1328 LanguageHdl(&rBox);
1331 void SwTOXSelectTabPage::LanguageHdl(const weld::ComboBox* pBox)
1333 lang::Locale aLcl( LanguageTag( m_xLanguageLB->get_active_id() ).getLocale() );
1334 Sequence< OUString > aSeq = pIndexEntryWrapper->GetAlgorithmList( aLcl );
1336 if( !pIndexRes )
1337 pIndexRes.reset(new IndexEntryResource());
1339 OUString sOldString = m_xSortAlgorithmLB->get_active_id();
1340 m_xSortAlgorithmLB->clear();
1342 sal_Int32 nEnd = aSeq.getLength();
1343 for( sal_Int32 nCnt = 0; nCnt < nEnd; ++nCnt )
1345 const OUString sAlg(aSeq[ nCnt ]);
1346 const OUString sUINm = pIndexRes->GetTranslation( sAlg );
1347 m_xSortAlgorithmLB->append(sAlg, sUINm);
1348 if( sAlg == sOldString )
1349 m_xSortAlgorithmLB->set_active(nCnt);
1352 if (m_xSortAlgorithmLB->get_active() == -1)
1353 m_xSortAlgorithmLB->set_active(0);
1355 if (pBox)
1356 ModifyHdl();
1359 IMPL_LINK_NOARG(SwTOXSelectTabPage, AddStylesHdl, weld::Button&, void)
1361 SwAddStylesDlg_Impl aDlg(GetFrameWeld(), static_cast<SwMultiTOXTabDialog*>(GetDialogController())->GetWrtShell(),
1362 aStyleArr);
1363 aDlg.run();
1364 ModifyHdl();
1367 IMPL_LINK_NOARG(SwTOXSelectTabPage, MenuEnableHdl, weld::Toggleable&, void)
1369 m_xAutoMarkPB->set_item_sensitive("edit", !sAutoMarkURL.isEmpty());
1372 IMPL_LINK(SwTOXSelectTabPage, MenuExecuteHdl, const OString&, rIdent, void)
1374 const OUString sSaveAutoMarkURL = sAutoMarkURL;
1376 if (rIdent == "open")
1378 sAutoMarkURL = lcl_CreateAutoMarkFileDlg(GetFrameWeld(),
1379 sAutoMarkURL, sAutoMarkType, true);
1381 else if (rIdent == "new" || rIdent == "edit")
1383 bool bNew = (rIdent == "new");
1384 if (bNew)
1386 sAutoMarkURL = lcl_CreateAutoMarkFileDlg(GetFrameWeld(),
1387 sAutoMarkURL, sAutoMarkType, false);
1388 if (sAutoMarkURL.isEmpty())
1389 return;
1392 SwAutoMarkDlg_Impl aAutoMarkDlg(GetFrameWeld(), sAutoMarkURL, bNew);
1393 if (RET_OK != aAutoMarkDlg.run() && bNew)
1394 sAutoMarkURL = sSaveAutoMarkURL;
1398 class SwTOXWidget
1400 protected:
1401 Link<SwTOXWidget&,void> aGetFocusLink;
1402 public:
1403 virtual WindowType GetType() const = 0;
1404 virtual void GrabFocus() = 0;
1405 virtual void Hide() = 0;
1406 virtual void set_grid_left_attach(int nPos) = 0;
1407 virtual void get_extents_relative_to(weld::Widget& rRelative, int& x, int& y, int& width, int& height) = 0;
1408 void SetGetFocusHdl(const Link<SwTOXWidget&,void>& rLink) { aGetFocusLink = rLink; }
1409 virtual ~SwTOXWidget() {}
1412 class SwTOXEdit : public SwTOXWidget
1414 std::unique_ptr<weld::Builder> m_xBuilder;
1415 SwFormToken aFormToken;
1416 Link<SwTOXEdit&,void> aModifiedLink;
1417 Link<SwTOXEdit&,void> aPrevNextControlLink;
1418 bool bNextControl;
1419 SwTokenWindow* m_pParent;
1420 std::unique_ptr<weld::Entry> m_xEntry;
1422 DECL_LINK(ModifyHdl, weld::Entry&, void);
1423 public:
1424 SwTOXEdit(SwTokenWindow* pTokenWin, const SwFormToken& rToken)
1425 : m_xBuilder(Application::CreateBuilder(pTokenWin->get_child_container(), "modules/swriter/ui/toxentrywidget.ui"))
1426 , aFormToken(rToken)
1427 , bNextControl(false)
1428 , m_pParent(pTokenWin)
1429 , m_xEntry(m_xBuilder->weld_entry("entry"))
1431 m_xEntry->connect_changed(LINK(this, SwTOXEdit, ModifyHdl));
1432 m_xEntry->connect_key_press(LINK(this, SwTOXEdit, KeyInputHdl));
1433 m_xEntry->connect_focus_in(LINK(this, SwTOXEdit, FocusInHdl));
1434 m_xEntry->set_tooltip_text(m_pParent->CreateQuickHelp(rToken));
1437 virtual ~SwTOXEdit() override
1439 m_pParent->get_child_container()->move(m_xEntry.get(), nullptr);
1442 virtual WindowType GetType() const override
1444 return WindowType::EDIT;
1447 virtual void GrabFocus() override
1449 m_xEntry->grab_focus();
1452 virtual void Hide() override
1454 m_xEntry->hide();
1457 void Show()
1459 m_xEntry->show();
1462 void SetAccessibleName(const OUString& rName)
1464 m_xEntry->set_accessible_name(rName);
1467 virtual void set_grid_left_attach(int nPos) override
1469 m_xEntry->set_grid_left_attach(nPos);
1472 virtual void get_extents_relative_to(weld::Widget& rRelative, int& x, int& y, int& width, int& height) override
1474 m_xEntry->get_extents_relative_to(rRelative, x, y, width, height);
1477 OUString GetText() const
1479 return m_xEntry->get_text();
1482 void SetText(const OUString& rText)
1484 m_xEntry->set_text(rText);
1487 void get_selection_bounds(int& rStartPos, int& rEndPos)
1489 m_xEntry->get_selection_bounds(rStartPos, rEndPos);
1492 void select_region(int nStartPos, int nEndPos)
1494 m_xEntry->select_region(nStartPos, nEndPos);
1497 void SetModifyHdl(const Link<SwTOXEdit&,void>& rLink)
1499 aModifiedLink = rLink;
1502 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
1503 DECL_LINK(FocusInHdl, weld::Widget&, void);
1505 bool IsNextControl() const { return bNextControl; }
1506 void SetPrevNextLink(const Link<SwTOXEdit&,void>& rLink) { aPrevNextControlLink = rLink; }
1508 const SwFormToken& GetFormToken()
1510 aFormToken.sText = m_xEntry->get_text();
1511 return aFormToken;
1514 void SetCharStyleName(const OUString& rSet, sal_uInt16 nPoolId)
1516 aFormToken.sCharStyleName = rSet;
1517 aFormToken.nPoolId = nPoolId;
1520 void AdjustSize();
1523 IMPL_LINK_NOARG(SwTOXEdit, ModifyHdl, weld::Entry&, void)
1525 aModifiedLink.Call(*this);
1528 IMPL_LINK(SwTOXEdit, KeyInputHdl, const KeyEvent&, rKEvt, bool)
1530 bool bCall = false;
1531 int nStartPos, nEndPos;
1532 bool bStartIsEnd = !m_xEntry->get_selection_bounds(nStartPos, nEndPos);
1533 int nMin = std::min(nStartPos, nEndPos);
1534 const sal_Int32 nTextLen = GetText().getLength();
1535 if ((bStartIsEnd && !nMin) || nMin == nTextLen)
1537 vcl::KeyCode aCode = rKEvt.GetKeyCode();
1538 if (aCode.GetCode() == KEY_RIGHT && nMin == nTextLen)
1540 bNextControl = true;
1541 bCall = true;
1543 else if (aCode.GetCode() == KEY_LEFT && !nMin)
1545 bNextControl = false;
1546 bCall = true;
1548 else if ( (aCode.GetCode() == KEY_F3) && aCode.IsShift() && !aCode.IsMod1() && !aCode.IsMod2() )
1550 if (m_pParent)
1552 m_pParent->SetFocus2theAllBtn();
1555 if (bCall && aPrevNextControlLink.IsSet())
1556 aPrevNextControlLink.Call(*this);
1557 else
1558 bCall = false;
1561 return bCall;
1564 IMPL_LINK_NOARG(SwTOXEdit, FocusInHdl, weld::Widget&, void)
1566 aGetFocusLink.Call(*this);
1569 void SwTOXEdit::AdjustSize()
1571 auto nWidth = m_xEntry->get_pixel_size(GetText()).Width();
1572 float fChars = nWidth / m_xEntry->get_approximate_digit_width();
1573 m_xEntry->set_width_chars(std::max(1.0f, std::ceil(fChars)));
1576 class SwTOXButton : public SwTOXWidget
1578 std::unique_ptr<weld::Builder> m_xBuilder;
1579 SwFormToken aFormToken;
1580 Link<SwTOXButton&,void> aPrevNextControlLink;
1581 bool bNextControl;
1582 SwTokenWindow* m_pParent;
1583 std::unique_ptr<weld::ToggleButton> m_xButton;
1584 public:
1585 SwTOXButton(SwTokenWindow* pTokenWin, const SwFormToken& rToken)
1586 : m_xBuilder(Application::CreateBuilder(pTokenWin->get_child_container(), "modules/swriter/ui/toxbuttonwidget.ui"))
1587 , aFormToken(rToken)
1588 , bNextControl(false)
1589 , m_pParent(pTokenWin)
1590 , m_xButton(m_xBuilder->weld_toggle_button("button"))
1592 m_xButton->connect_key_press(LINK(this, SwTOXButton, KeyInputHdl));
1593 m_xButton->connect_focus_in(LINK(this, SwTOXButton, FocusInHdl));
1594 m_xButton->set_tooltip_text(m_pParent->CreateQuickHelp(rToken));
1597 virtual ~SwTOXButton() override
1599 m_pParent->get_child_container()->move(m_xButton.get(), nullptr);
1602 virtual WindowType GetType() const override
1604 return WindowType::PUSHBUTTON;
1607 virtual void GrabFocus() override
1609 m_xButton->grab_focus();
1612 virtual void Hide() override
1614 m_xButton->hide();
1617 void Show()
1619 m_xButton->show();
1622 void SetAccessibleName(const OUString& rName)
1624 m_xButton->set_accessible_name(rName);
1627 virtual void set_grid_left_attach(int nPos) override
1629 m_xButton->set_grid_left_attach(nPos);
1632 void get_extents_relative_to(weld::Widget& rRelative, int& x, int& y, int& width, int& height) override
1634 m_xButton->get_extents_relative_to(rRelative, x, y, width, height);
1637 void Check(bool bCheck = true)
1639 m_xButton->set_active(bCheck);
1642 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
1643 DECL_LINK(FocusInHdl, weld::Widget&, void);
1645 bool IsNextControl() const {return bNextControl;}
1646 void SetPrevNextLink(const Link<SwTOXButton&,void>& rLink) {aPrevNextControlLink = rLink;}
1647 const SwFormToken& GetFormToken() const {return aFormToken;}
1649 void SetCharStyleName(const OUString& rSet, sal_uInt16 nPoolId)
1651 aFormToken.sCharStyleName = rSet;
1652 aFormToken.nPoolId = nPoolId;
1655 void SetTabPosition(SwTwips nSet)
1656 { aFormToken.nTabStopPosition = nSet; }
1658 void SetFillChar( sal_Unicode cSet )
1659 { aFormToken.cTabFillChar = cSet; }
1661 void SetTabAlign(SvxTabAdjust eAlign)
1662 { aFormToken.eTabAlign = eAlign;}
1664 //---> i89791
1665 //used for entry number format, in TOC only
1666 //needed for different UI dialog position
1667 void SetEntryNumberFormat(sal_uInt16 nSet) {
1668 switch(nSet)
1670 default:
1671 case 0:
1672 aFormToken.nChapterFormat = CF_NUMBER;
1673 break;
1674 case 1:
1675 aFormToken.nChapterFormat = CF_NUM_NOPREPST_TITLE;
1676 break;
1680 void SetChapterInfo(sal_uInt16 nSet) {
1681 switch(nSet)
1683 default:
1684 case 0:
1685 aFormToken.nChapterFormat = CF_NUM_NOPREPST_TITLE;
1686 break;
1687 case 1:
1688 aFormToken.nChapterFormat = CF_TITLE;
1689 break;
1690 case 2:
1691 aFormToken.nChapterFormat = CF_NUMBER_NOPREPST;
1692 break;
1696 void SetOutlineLevel( sal_uInt16 nSet ) { aFormToken.nOutlineLevel = nSet;}//i53420
1698 void SetText(const OUString& rText)
1700 m_xButton->set_label(rText);
1703 void SetLinkEnd()
1705 OSL_ENSURE(TOKEN_LINK_START == aFormToken.eTokenType,
1706 "call SetLinkEnd for link start only!");
1707 aFormToken.eTokenType = TOKEN_LINK_END;
1708 aFormToken.sText = SwForm::GetFormLinkEnd();
1709 SetText(aFormToken.sText);
1712 void SetLinkStart()
1714 OSL_ENSURE(TOKEN_LINK_END == aFormToken.eTokenType,
1715 "call SetLinkStart for link start only!");
1716 aFormToken.eTokenType = TOKEN_LINK_START;
1717 aFormToken.sText = SwForm::GetFormLinkStt();
1718 SetText(aFormToken.sText);
1722 IMPL_LINK(SwTOXButton, KeyInputHdl, const KeyEvent&, rKEvt, bool)
1724 bool bCall = false;
1725 vcl::KeyCode aCode = rKEvt.GetKeyCode();
1726 if (aCode.GetCode() == KEY_RIGHT)
1728 bNextControl = true;
1729 bCall = true;
1731 else if (aCode.GetCode() == KEY_LEFT)
1733 bNextControl = false;
1734 bCall = true;
1736 else if (aCode.GetCode() == KEY_DELETE)
1738 m_pParent->RemoveControl(this, true);
1739 //this is invalid here
1740 return true;
1742 else if ( (aCode.GetCode() == KEY_F3) && aCode.IsShift() && !aCode.IsMod1() && !aCode.IsMod2() )
1744 if (m_pParent)
1746 m_pParent->SetFocus2theAllBtn();
1749 if (bCall && aPrevNextControlLink.IsSet())
1750 aPrevNextControlLink.Call(*this);
1751 else
1752 bCall = false;
1753 return bCall;
1756 IMPL_LINK_NOARG(SwTOXButton, FocusInHdl, weld::Widget&, void)
1758 aGetFocusLink.Call(*this);
1761 namespace
1763 const TranslateId STR_AUTH_FIELD_ARY[] =
1765 STR_AUTH_FIELD_IDENTIFIER,
1766 STR_AUTH_FIELD_AUTHORITY_TYPE,
1767 STR_AUTH_FIELD_ADDRESS,
1768 STR_AUTH_FIELD_ANNOTE,
1769 STR_AUTH_FIELD_AUTHOR,
1770 STR_AUTH_FIELD_BOOKTITLE,
1771 STR_AUTH_FIELD_CHAPTER,
1772 STR_AUTH_FIELD_EDITION,
1773 STR_AUTH_FIELD_EDITOR,
1774 STR_AUTH_FIELD_HOWPUBLISHED,
1775 STR_AUTH_FIELD_INSTITUTION,
1776 STR_AUTH_FIELD_JOURNAL,
1777 STR_AUTH_FIELD_MONTH,
1778 STR_AUTH_FIELD_NOTE,
1779 STR_AUTH_FIELD_NUMBER,
1780 STR_AUTH_FIELD_ORGANIZATIONS,
1781 STR_AUTH_FIELD_PAGES,
1782 STR_AUTH_FIELD_PUBLISHER,
1783 STR_AUTH_FIELD_SCHOOL,
1784 STR_AUTH_FIELD_SERIES,
1785 STR_AUTH_FIELD_TITLE,
1786 STR_AUTH_FIELD_TYPE,
1787 STR_AUTH_FIELD_VOLUME,
1788 STR_AUTH_FIELD_YEAR,
1789 STR_AUTH_FIELD_URL,
1790 STR_AUTH_FIELD_CUSTOM1,
1791 STR_AUTH_FIELD_CUSTOM2,
1792 STR_AUTH_FIELD_CUSTOM3,
1793 STR_AUTH_FIELD_CUSTOM4,
1794 STR_AUTH_FIELD_CUSTOM5,
1795 STR_AUTH_FIELD_ISBN,
1796 STR_AUTH_FIELD_LOCAL_URL,
1800 SwTOXEntryTabPage::SwTOXEntryTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rAttrSet)
1801 : SfxTabPage(pPage, pController, "modules/swriter/ui/tocentriespage.ui", "TocEntriesPage", &rAttrSet)
1802 , sDelimStr(SwResId(STR_DELIM))
1803 , sNoCharStyle(SwResId(STR_NO_CHAR_STYLE))
1804 , m_pCurrentForm(nullptr)
1805 , bInLevelHdl(false)
1806 , m_xTypeFT(m_xBuilder->weld_label("typeft"))
1807 , m_xLevelFT(m_xBuilder->weld_label("levelft"))
1808 , m_xLevelLB(m_xBuilder->weld_tree_view("level"))
1809 , m_xAllLevelsPB(m_xBuilder->weld_button("all"))
1810 , m_xEntryNoPB(m_xBuilder->weld_button("chapterno"))
1811 , m_xEntryPB(m_xBuilder->weld_button("entrytext"))
1812 , m_xTabPB(m_xBuilder->weld_button("tabstop"))
1813 , m_xChapterInfoPB(m_xBuilder->weld_button("chapterinfo"))
1814 , m_xPageNoPB(m_xBuilder->weld_button("pageno"))
1815 , m_xHyperLinkPB(m_xBuilder->weld_button("hyperlink"))
1816 , m_xFieldBox(m_xBuilder->weld_widget("fieldbox"))
1817 , m_xAuthFieldsLB(m_xBuilder->weld_combo_box("authfield"))
1818 , m_xAuthInsertPB(m_xBuilder->weld_button("insert"))
1819 , m_xAuthRemovePB(m_xBuilder->weld_button("remove"))
1820 , m_xCharStyleLB(m_xBuilder->weld_combo_box("charstyle"))
1821 , m_xEditStylePB(m_xBuilder->weld_button("edit"))
1822 , m_xChapterEntryFT(m_xBuilder->weld_label("chapterentryft"))
1823 , m_xChapterEntryLB(m_xBuilder->weld_combo_box("chapterentry"))
1824 , m_xNumberFormatFT(m_xBuilder->weld_label("numberformatft"))
1825 , m_xNumberFormatLB(m_xBuilder->weld_combo_box("numberformat"))
1826 , m_xEntryOutlineLevelFT(m_xBuilder->weld_label("entryoutlinelevelft"))
1827 , m_xEntryOutlineLevelNF(m_xBuilder->weld_spin_button("entryoutlinelevel"))
1828 , m_xFillCharFT(m_xBuilder->weld_label("fillcharft"))
1829 , m_xFillCharCB(m_xBuilder->weld_combo_box("fillchar"))
1830 , m_xTabPosFT(m_xBuilder->weld_label("tabstopposft"))
1831 , m_xTabPosMF(m_xBuilder->weld_metric_spin_button("tabstoppos", FieldUnit::CM))
1832 , m_xAutoRightCB(m_xBuilder->weld_check_button("alignright"))
1833 , m_xFormatFrame(m_xBuilder->weld_widget("formatframe"))
1834 , m_xMainEntryStyleFT(m_xBuilder->weld_label("mainstyleft"))
1835 , m_xMainEntryStyleLB(m_xBuilder->weld_combo_box("mainstyle"))
1836 , m_xAlphaDelimCB(m_xBuilder->weld_check_button("alphadelim"))
1837 , m_xCommaSeparatedCB(m_xBuilder->weld_check_button("commasep"))
1838 , m_xRelToStyleCB(m_xBuilder->weld_check_button("reltostyle"))
1839 , m_xSortingFrame(m_xBuilder->weld_widget("sortingframe"))
1840 , m_xSortDocPosRB(m_xBuilder->weld_radio_button("sortpos"))
1841 , m_xSortContentRB(m_xBuilder->weld_radio_button("sortcontents"))
1842 , m_xSortKeyFrame(m_xBuilder->weld_widget("sortkeyframe"))
1843 , m_xFirstKeyLB(m_xBuilder->weld_combo_box("key1lb"))
1844 , m_xFirstSortUpRB(m_xBuilder->weld_radio_button("up1cb"))
1845 , m_xFirstSortDownRB(m_xBuilder->weld_radio_button("down1cb"))
1846 , m_xSecondKeyLB(m_xBuilder->weld_combo_box("key2lb"))
1847 , m_xSecondSortUpRB(m_xBuilder->weld_radio_button("up2cb"))
1848 , m_xSecondSortDownRB(m_xBuilder->weld_radio_button("down2cb"))
1849 , m_xThirdKeyLB(m_xBuilder->weld_combo_box("key3lb"))
1850 , m_xThirdSortUpRB(m_xBuilder->weld_radio_button("up3cb"))
1851 , m_xThirdSortDownRB(m_xBuilder->weld_radio_button("down3cb"))
1852 , m_xTokenWIN(new SwTokenWindow(m_xBuilder->weld_container("token")))
1854 const OUString sNoCharSortKey(SwResId(STR_NOSORTKEY));
1856 sAuthTypeStr = m_xTypeFT->get_label();
1857 sLevelStr = m_xLevelFT->get_label();
1858 m_xAuthFieldsLB->make_sorted();
1859 m_xTokenWIN->SetTabPage(this);
1861 aLastTOXType.eType = TOXTypes(USHRT_MAX);
1862 aLastTOXType.nIndex = 0;
1864 SetExchangeSupport();
1865 m_xEntryNoPB->connect_clicked(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
1866 m_xEntryPB->connect_clicked(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
1867 m_xChapterInfoPB->connect_clicked(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
1868 m_xPageNoPB->connect_clicked(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
1869 m_xTabPB->connect_clicked(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
1870 m_xHyperLinkPB->connect_clicked(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
1871 m_xEditStylePB->connect_clicked(LINK(this, SwTOXEntryTabPage, EditStyleHdl));
1872 m_xLevelLB->connect_changed(LINK(this, SwTOXEntryTabPage, LevelHdl));
1873 m_xTokenWIN->SetButtonSelectedHdl(LINK(this, SwTOXEntryTabPage, TokenSelectedHdl));
1874 m_xTokenWIN->SetModifyHdl(LINK(this, SwTOXEntryTabPage, ModifyHdl));
1875 m_xCharStyleLB->connect_changed(LINK(this, SwTOXEntryTabPage, StyleSelectHdl));
1876 m_xCharStyleLB->append_text(sNoCharStyle);
1877 m_xChapterEntryLB->connect_changed(LINK(this, SwTOXEntryTabPage, ChapterInfoHdl));
1878 m_xEntryOutlineLevelNF->connect_value_changed(LINK(this, SwTOXEntryTabPage, ChapterInfoOutlineHdl));
1879 m_xNumberFormatLB->connect_changed(LINK(this, SwTOXEntryTabPage, NumberFormatHdl));
1881 m_xTabPosMF->connect_value_changed(LINK(this, SwTOXEntryTabPage, TabPosHdl));
1882 m_xFillCharCB->connect_changed(LINK(this, SwTOXEntryTabPage, FillCharHdl));
1883 m_xAutoRightCB->connect_toggled(LINK(this, SwTOXEntryTabPage, AutoRightHdl));
1884 m_xAuthInsertPB->connect_clicked(LINK(this, SwTOXEntryTabPage, RemoveInsertAuthHdl));
1885 m_xAuthRemovePB->connect_clicked(LINK(this, SwTOXEntryTabPage, RemoveInsertAuthHdl));
1886 m_xSortDocPosRB->connect_toggled(LINK(this, SwTOXEntryTabPage, SortKeyHdl));
1887 m_xSortContentRB->connect_toggled(LINK(this, SwTOXEntryTabPage, SortKeyHdl));
1888 m_xAllLevelsPB->connect_clicked(LINK(this, SwTOXEntryTabPage, AllLevelsHdl));
1890 m_xAlphaDelimCB->connect_toggled(LINK(this, SwTOXEntryTabPage, ModifyClickHdl));
1891 m_xCommaSeparatedCB->connect_toggled(LINK(this, SwTOXEntryTabPage, ModifyClickHdl));
1892 m_xRelToStyleCB->connect_toggled(LINK(this, SwTOXEntryTabPage, ModifyClickHdl));
1894 FieldUnit aMetric = ::GetDfltMetric(false);
1895 ::SetFieldUnit(*m_xTabPosMF, aMetric);
1897 m_xSortDocPosRB->set_active(true);
1899 m_xFillCharCB->set_entry_max_length(1);
1900 m_xFillCharCB->append_text(OUString(' '));
1901 m_xFillCharCB->append_text(OUString('.'));
1902 m_xFillCharCB->append_text(OUString('-'));
1903 m_xFillCharCB->append_text(OUString('_'));
1904 m_xFillCharCB->append_text(OUString(u'\x2024')); // ONE DOT LEADER
1905 m_xFillCharCB->append_text(OUString(u'\x2025')); // TWO DOT LEADER
1906 m_xFillCharCB->append_text(OUString(u'\x2026')); // HORIZONTAL ELLIPSIS
1908 m_xEditStylePB->set_sensitive(false);
1910 //fill the types in
1911 for (sal_uInt16 i = 0; i < AUTH_FIELD_END; ++i)
1913 OUString sId(OUString::number(i));
1914 m_xAuthFieldsLB->append(sId, SwResId(STR_AUTH_FIELD_ARY[i]));
1917 m_xFirstKeyLB->append(OUString::number(USHRT_MAX), sNoCharSortKey);
1918 m_xSecondKeyLB->append(OUString::number(USHRT_MAX), sNoCharSortKey);
1919 m_xThirdKeyLB->append(OUString::number(USHRT_MAX), sNoCharSortKey);
1921 for (sal_uInt16 i = 0; i < AUTH_FIELD_END; ++i)
1923 const OUString sTmp(m_xAuthFieldsLB->get_text(i));
1924 const OUString sEntryData(m_xAuthFieldsLB->get_id(i));
1925 m_xFirstKeyLB->append(sEntryData, sTmp);
1926 m_xSecondKeyLB->append(sEntryData, sTmp);
1927 m_xThirdKeyLB->append(sEntryData, sTmp);
1929 m_xFirstKeyLB->set_active(0);
1930 m_xSecondKeyLB->set_active(0);
1931 m_xThirdKeyLB->set_active(0);
1933 // lock size of dialog. Determine the field box's widest possible
1934 // configuration (tdf#149186) before doing so.
1935 int nFieldBoxWidth = 0;
1936 for (int eType = TOX_CITATION; eType >= TOX_INDEX; --eType)
1938 ShowHideControls(eType);
1939 nFieldBoxWidth = std::max<int>(m_xFieldBox->get_preferred_size().Width(), nFieldBoxWidth);
1941 m_xFieldBox->set_size_request(nFieldBoxWidth, -1);
1942 Size aPrefSize(m_xContainer->get_preferred_size());
1943 m_xFieldBox->set_size_request(-1, -1);
1944 m_xContainer->set_size_request(aPrefSize.Width(), aPrefSize.Height());
1947 SwTOXEntryTabPage::~SwTOXEntryTabPage()
1949 m_xTokenWIN.reset();
1952 IMPL_LINK_NOARG(SwTOXEntryTabPage, ModifyClickHdl, weld::Toggleable&, void)
1954 OnModify(true);
1957 IMPL_LINK_NOARG(SwTOXEntryTabPage, ModifyHdl, LinkParamNone*, void)
1959 OnModify(false);
1962 // bAllLevels is used as signal to change all levels of the example
1963 void SwTOXEntryTabPage::OnModify(bool bAllLevels)
1965 UpdateDescriptor();
1967 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
1968 if (pTOXDlg)
1970 sal_uInt16 nCurLevel = m_xLevelLB->get_selected_index() + 1;
1971 if (aLastTOXType.eType == TOX_CONTENT && bAllLevels)
1972 nCurLevel = USHRT_MAX;
1973 pTOXDlg->CreateOrUpdateExample(
1974 pTOXDlg->GetCurrentTOXType().eType, TOX_PAGE_ENTRY, nCurLevel);
1978 bool SwTOXEntryTabPage::FillItemSet( SfxItemSet* )
1980 // nothing to do
1981 return true;
1984 void SwTOXEntryTabPage::Reset( const SfxItemSet* )
1986 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
1987 const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
1988 m_pCurrentForm = pTOXDlg->GetForm(aCurType);
1989 if(TOX_INDEX == aCurType.eType)
1991 SwTOXDescription& rDesc = pTOXDlg->GetTOXDescription(aCurType);
1992 const OUString& sMainEntryCharStyle = rDesc.GetMainEntryCharStyle();
1993 if(!sMainEntryCharStyle.isEmpty())
1995 if (m_xMainEntryStyleLB->find_text(sMainEntryCharStyle) == -1)
1996 m_xMainEntryStyleLB->append_text(sMainEntryCharStyle);
1997 m_xMainEntryStyleLB->set_active_text(sMainEntryCharStyle);
1999 else
2000 m_xMainEntryStyleLB->set_active_text(sNoCharStyle);
2001 m_xAlphaDelimCB->set_active( bool(rDesc.GetIndexOptions() & SwTOIOptions::AlphaDelimiter) );
2003 m_xRelToStyleCB->set_active(m_pCurrentForm->IsRelTabPos());
2004 m_xCommaSeparatedCB->set_active(m_pCurrentForm->IsCommaSeparated());
2007 void SwTOXEntryTabPage::ShowHideControls(int eType)
2009 bool bToxIsAuthorities = TOX_AUTHORITIES == eType;
2010 bool bToxIsIndex = TOX_INDEX == eType;
2011 bool bToxIsContent = TOX_CONTENT == eType;
2012 bool bToxSupportsLinks = TOX_CONTENT == eType ||
2013 TOX_ILLUSTRATIONS == eType ||
2014 TOX_TABLES == eType ||
2015 TOX_OBJECTS == eType ||
2016 TOX_USER == eType;
2018 //show or hide controls
2019 m_xEntryNoPB->set_visible(bToxIsContent);
2020 m_xHyperLinkPB->set_visible(bToxSupportsLinks);
2021 m_xRelToStyleCB->set_visible(!bToxIsAuthorities);
2022 m_xChapterInfoPB->set_visible(!bToxIsContent && !bToxIsAuthorities);
2023 m_xEntryPB->set_visible(!bToxIsAuthorities);
2024 m_xPageNoPB->set_visible(!bToxIsAuthorities);
2025 m_xAuthFieldsLB->set_visible(bToxIsAuthorities);
2026 m_xAuthInsertPB->set_visible(bToxIsAuthorities);
2027 m_xAuthRemovePB->set_visible(bToxIsAuthorities);
2029 m_xFormatFrame->set_visible(!bToxIsAuthorities);
2031 m_xSortingFrame->set_visible(bToxIsAuthorities);
2032 m_xSortKeyFrame->set_visible(bToxIsAuthorities);
2034 m_xMainEntryStyleFT->set_visible(bToxIsIndex);
2035 m_xMainEntryStyleLB->set_visible(bToxIsIndex);
2036 m_xAlphaDelimCB->set_visible(bToxIsIndex);
2037 m_xCommaSeparatedCB->set_visible(bToxIsIndex);
2040 void SwTOXEntryTabPage::ActivatePage( const SfxItemSet& /*rSet*/)
2042 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
2043 const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
2045 m_pCurrentForm = pTOXDlg->GetForm(aCurType);
2046 if( !( aLastTOXType == aCurType ))
2048 bool bToxIsAuthorities = TOX_AUTHORITIES == aCurType.eType;
2049 bool bToxIsIndex = TOX_INDEX == aCurType.eType;
2051 m_xLevelLB->clear();
2052 for(sal_uInt16 i = 1; i < m_pCurrentForm->GetFormMax(); i++)
2054 if(bToxIsAuthorities)
2055 m_xLevelLB->append_text( SwAuthorityFieldType::GetAuthTypeName(
2056 static_cast<ToxAuthorityType>(i - 1)) );
2057 else if( bToxIsIndex )
2059 if(i == 1)
2060 m_xLevelLB->append_text( sDelimStr );
2061 else
2062 m_xLevelLB->append_text( OUString::number(i - 1) );
2064 else
2065 m_xLevelLB->append_text(OUString::number(i));
2067 if(bToxIsAuthorities)
2069 SwWrtShell& rSh = pTOXDlg->GetWrtShell();
2070 const SwAuthorityFieldType* pFType = static_cast<const SwAuthorityFieldType*>(
2071 rSh.GetFieldType(SwFieldIds::TableOfAuthorities, OUString()));
2072 if(pFType)
2074 if(pFType->IsSortByDocument())
2075 m_xSortDocPosRB->set_active(true);
2076 else
2078 m_xSortContentRB->set_active(true);
2079 const sal_uInt16 nKeyCount = pFType->GetSortKeyCount();
2080 if(0 < nKeyCount)
2082 const SwTOXSortKey* pKey = pFType->GetSortKey(0);
2083 m_xFirstKeyLB->set_active_id(OUString::number(pKey->eField));
2084 m_xFirstSortUpRB->set_active(pKey->bSortAscending);
2085 m_xFirstSortDownRB->set_active(!pKey->bSortAscending);
2087 if(1 < nKeyCount)
2089 const SwTOXSortKey* pKey = pFType->GetSortKey(1);
2090 m_xSecondKeyLB->set_active_id(OUString::number(pKey->eField));
2091 m_xSecondSortUpRB->set_active(pKey->bSortAscending);
2092 m_xSecondSortDownRB->set_active(!pKey->bSortAscending);
2094 if(2 < nKeyCount)
2096 const SwTOXSortKey* pKey = pFType->GetSortKey(2);
2097 m_xThirdKeyLB->set_active_id(OUString::number(pKey->eField));
2098 m_xThirdSortUpRB->set_active(pKey->bSortAscending);
2099 m_xThirdSortDownRB->set_active(!pKey->bSortAscending);
2103 SortKeyHdl(m_xSortDocPosRB->get_active() ? *m_xSortDocPosRB : *m_xSortContentRB);
2104 m_xLevelFT->set_label(sAuthTypeStr);
2106 else
2107 m_xLevelFT->set_label(sLevelStr);
2109 m_xLevelLB->select(bToxIsIndex ? 1 : 0);
2111 //show or hide controls
2112 ShowHideControls(aCurType.eType);
2114 aLastTOXType = aCurType;
2116 //invalidate PatternWindow
2117 m_xTokenWIN->SetInvalid();
2118 LevelHdl(*m_xLevelLB);
2121 void SwTOXEntryTabPage::UpdateDescriptor()
2123 WriteBackLevel();
2124 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
2125 SwTOXDescription& rDesc = pTOXDlg->GetTOXDescription(aLastTOXType);
2126 if(TOX_INDEX == aLastTOXType.eType)
2128 const OUString sTemp(m_xMainEntryStyleLB->get_active_text());
2129 rDesc.SetMainEntryCharStyle(sNoCharStyle == sTemp ? OUString(): sTemp);
2130 SwTOIOptions nIdxOptions = rDesc.GetIndexOptions() & ~SwTOIOptions::AlphaDelimiter;
2131 if (m_xAlphaDelimCB->get_active())
2132 nIdxOptions |= SwTOIOptions::AlphaDelimiter;
2133 rDesc.SetIndexOptions(nIdxOptions);
2135 else if (TOX_AUTHORITIES == aLastTOXType.eType)
2137 rDesc.SetSortByDocument(m_xSortDocPosRB->get_active());
2138 SwTOXSortKey aKey1, aKey2, aKey3;
2139 aKey1.eField = static_cast<ToxAuthorityField>(m_xFirstKeyLB->get_active_id().toInt32());
2140 aKey1.bSortAscending = m_xFirstSortUpRB->get_active();
2141 aKey2.eField = static_cast<ToxAuthorityField>(m_xSecondKeyLB->get_active_id().toInt32());
2142 aKey2.bSortAscending = m_xSecondSortUpRB->get_active();
2143 aKey3.eField = static_cast<ToxAuthorityField>(m_xThirdKeyLB->get_active_id().toInt32());
2144 aKey3.bSortAscending = m_xThirdSortUpRB->get_active();
2146 rDesc.SetSortKeys(aKey1, aKey2, aKey3);
2148 SwForm* pCurrentForm = pTOXDlg->GetForm(aLastTOXType);
2149 if (m_xRelToStyleCB->get_visible())
2150 pCurrentForm->SetRelTabPos(m_xRelToStyleCB->get_active());
2151 if (m_xCommaSeparatedCB->get_visible())
2152 pCurrentForm->SetCommaSeparated(m_xCommaSeparatedCB->get_active());
2155 DeactivateRC SwTOXEntryTabPage::DeactivatePage( SfxItemSet* /*pSet*/)
2157 UpdateDescriptor();
2158 return DeactivateRC::LeavePage;
2161 std::unique_ptr<SfxTabPage> SwTOXEntryTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
2163 return std::make_unique<SwTOXEntryTabPage>(pPage, pController, *rAttrSet);
2166 IMPL_LINK_NOARG(SwTOXEntryTabPage, EditStyleHdl, weld::Button&, void)
2168 if (m_xCharStyleLB->get_active() != -1)
2170 SfxStringItem aStyle(SID_STYLE_EDIT, m_xCharStyleLB->get_active_text());
2171 SfxUInt16Item aFamily(SID_STYLE_FAMILY, sal_uInt16(SfxStyleFamily::Char));
2172 static_cast<SwMultiTOXTabDialog*>(GetDialogController())->GetWrtShell().
2173 GetView().GetViewFrame()->GetDispatcher()->ExecuteList(SID_STYLE_EDIT,
2174 SfxCallMode::SYNCHRON,
2175 { &aStyle, &aFamily });
2179 IMPL_LINK(SwTOXEntryTabPage, RemoveInsertAuthHdl, weld::Button&, rButton, void)
2181 bool bInsert = &rButton == m_xAuthInsertPB.get();
2182 if(bInsert)
2184 sal_Int32 nSelPos = m_xAuthFieldsLB->get_active();
2185 const OUString sToInsert(m_xAuthFieldsLB->get_active_text());
2186 SwFormToken aInsert(TOKEN_AUTHORITY);
2187 aInsert.nAuthorityField = m_xAuthFieldsLB->get_id(nSelPos).toUInt32();
2188 m_xTokenWIN->InsertAtSelection(aInsert);
2189 m_xAuthFieldsLB->remove_text(sToInsert);
2190 m_xAuthFieldsLB->set_active(nSelPos ? nSelPos - 1 : 0);
2192 else
2194 SwTOXWidget* pCtrl = m_xTokenWIN->GetActiveControl();
2195 OSL_ENSURE(WindowType::EDIT != pCtrl->GetType(), "Remove should be disabled");
2196 if (WindowType::EDIT != pCtrl->GetType())
2198 //fill it into the ListBox
2199 const SwFormToken& rToken = static_cast<SwTOXButton*>(pCtrl)->GetFormToken();
2200 PreTokenButtonRemoved(rToken);
2201 m_xTokenWIN->RemoveControl(static_cast<SwTOXButton*>(pCtrl));
2204 ModifyHdl(nullptr);
2207 void SwTOXEntryTabPage::PreTokenButtonRemoved(const SwFormToken& rToken)
2209 //fill it into the ListBox
2210 sal_uInt32 nData = rToken.nAuthorityField;
2211 m_xAuthFieldsLB->append(OUString::number(nData), SwResId(STR_AUTH_FIELD_ARY[nData]));
2214 void SwTOXEntryTabPage::SetFocus2theAllBtn()
2216 m_xAllLevelsPB->grab_focus();
2219 // This function initializes the default value in the Token
2220 // put here the UI dependent initializations
2221 IMPL_LINK(SwTOXEntryTabPage, InsertTokenHdl, weld::Button&, rBtn, void)
2223 FormTokenType eTokenType = TOKEN_ENTRY_NO;
2224 OUString sCharStyle;
2225 sal_uInt16 nChapterFormat = CF_NUMBER; // i89791
2226 if (&rBtn == m_xEntryNoPB.get())
2228 eTokenType = TOKEN_ENTRY_NO;
2230 else if (&rBtn == m_xEntryPB.get())
2232 if( TOX_CONTENT == m_pCurrentForm->GetTOXType() )
2234 eTokenType = TOKEN_ENTRY_TEXT;
2236 else
2238 eTokenType = TOKEN_ENTRY;
2241 else if (&rBtn == m_xChapterInfoPB.get())
2243 eTokenType = TOKEN_CHAPTER_INFO;
2244 nChapterFormat = CF_NUM_NOPREPST_TITLE; // i89791
2246 else if (&rBtn == m_xPageNoPB.get())
2248 eTokenType = TOKEN_PAGE_NUMS;
2250 else if (&rBtn == m_xHyperLinkPB.get())
2252 eTokenType = TOKEN_LINK_START;
2253 sCharStyle = SwResId(STR_POOLCHR_TOXJUMP);
2255 else if (&rBtn == m_xTabPB.get())
2257 eTokenType = TOKEN_TAB_STOP;
2259 SwFormToken aInsert(eTokenType);
2260 aInsert.sCharStyleName = sCharStyle;
2261 aInsert.nTabStopPosition = 0;
2262 aInsert.nChapterFormat = nChapterFormat; // i89791
2263 m_xTokenWIN->InsertAtSelection(aInsert);
2264 ModifyHdl(nullptr);
2267 IMPL_LINK_NOARG(SwTOXEntryTabPage, AllLevelsHdl, weld::Button&, void)
2269 //get current level
2270 //write it into all levels
2271 if(m_xTokenWIN->IsValid())
2273 const OUString sNewToken = m_xTokenWIN->GetPattern();
2274 for(sal_uInt16 i = 1; i < m_pCurrentForm->GetFormMax(); i++)
2275 m_pCurrentForm->SetPattern(i, sNewToken);
2277 OnModify(true);
2281 void SwTOXEntryTabPage::WriteBackLevel()
2283 if(m_xTokenWIN->IsValid())
2285 const OUString sNewToken = m_xTokenWIN->GetPattern();
2286 const sal_uInt16 nLastLevel = m_xTokenWIN->GetLastLevel();
2287 if(nLastLevel != USHRT_MAX)
2288 m_pCurrentForm->SetPattern(nLastLevel + 1, sNewToken);
2292 IMPL_LINK(SwTOXEntryTabPage, LevelHdl, weld::TreeView&, rBox, void)
2294 if(bInLevelHdl)
2295 return;
2296 bInLevelHdl = true;
2297 WriteBackLevel();
2299 const sal_uInt16 nLevel = rBox.get_selected_index();
2300 m_xTokenWIN->SetForm(*m_pCurrentForm, nLevel);
2301 if(TOX_AUTHORITIES == m_pCurrentForm->GetTOXType())
2303 //fill the types in
2304 m_xAuthFieldsLB->clear();
2305 for( sal_uInt32 i = 0; i < AUTH_FIELD_END; i++)
2307 m_xAuthFieldsLB->append(OUString::number(i), SwResId(STR_AUTH_FIELD_ARY[i]));
2310 // #i21237#
2311 SwFormTokens aPattern = m_pCurrentForm->GetPattern(nLevel + 1);
2313 for(const auto& aToken : aPattern)
2315 if(TOKEN_AUTHORITY == aToken.eTokenType)
2317 sal_uInt32 nSearch = aToken.nAuthorityField;
2318 int nLstBoxPos = m_xAuthFieldsLB->find_id(OUString::number(nSearch));
2319 OSL_ENSURE(nLstBoxPos != -1, "Entry not found?");
2320 m_xAuthFieldsLB->remove(nLstBoxPos);
2323 m_xAuthFieldsLB->set_active(0);
2325 bInLevelHdl = false;
2326 rBox.grab_focus();
2329 IMPL_LINK_NOARG(SwTOXEntryTabPage, SortKeyHdl, weld::Toggleable&, void)
2331 bool bEnable = m_xSortContentRB->get_active();
2332 m_xSortKeyFrame->set_sensitive(bEnable);
2335 IMPL_LINK(SwTOXEntryTabPage, TokenSelectedHdl, SwFormToken&, rToken, void)
2337 if (!rToken.sCharStyleName.isEmpty())
2338 m_xCharStyleLB->set_active_text(rToken.sCharStyleName);
2339 else
2340 m_xCharStyleLB->set_active_text(sNoCharStyle);
2342 const OUString sEntry = m_xCharStyleLB->get_active_text();
2343 m_xEditStylePB->set_sensitive(sEntry != sNoCharStyle);
2345 if(rToken.eTokenType == TOKEN_CHAPTER_INFO)
2347 //---> i89791
2348 switch(rToken.nChapterFormat)
2350 default:
2351 m_xChapterEntryLB->set_active(-1);//to alert the user
2352 break;
2353 case CF_NUM_NOPREPST_TITLE:
2354 m_xChapterEntryLB->set_active(0);
2355 break;
2356 case CF_TITLE:
2357 m_xChapterEntryLB->set_active(1);
2358 break;
2359 case CF_NUMBER_NOPREPST:
2360 m_xChapterEntryLB->set_active(2);
2361 break;
2363 //i53420
2365 m_xEntryOutlineLevelNF->set_value(rToken.nOutlineLevel);
2368 //i53420
2369 if(rToken.eTokenType == TOKEN_ENTRY_NO)
2371 m_xEntryOutlineLevelNF->set_value(rToken.nOutlineLevel);
2372 const sal_uInt16 nFormat =
2373 rToken.nChapterFormat == CF_NUM_NOPREPST_TITLE ? 1 : 0;
2374 m_xNumberFormatLB->set_active(nFormat);
2377 bool bTabStop = TOKEN_TAB_STOP == rToken.eTokenType;
2378 m_xFillCharFT->set_visible(bTabStop);
2379 m_xFillCharCB->set_visible(bTabStop);
2380 m_xTabPosFT->set_visible(bTabStop);
2381 m_xTabPosMF->set_visible(bTabStop);
2382 m_xAutoRightCB->set_visible(bTabStop);
2383 m_xAutoRightCB->set_sensitive(bTabStop);
2384 if(bTabStop)
2386 m_xTabPosMF->set_value(m_xTabPosMF->normalize(rToken.nTabStopPosition), FieldUnit::TWIP);
2387 m_xAutoRightCB->set_active(SvxTabAdjust::End == rToken.eTabAlign);
2388 m_xFillCharCB->set_entry_text(OUString(rToken.cTabFillChar));
2389 m_xTabPosFT->set_sensitive(!m_xAutoRightCB->get_active());
2390 m_xTabPosMF->set_sensitive(!m_xAutoRightCB->get_active());
2392 else
2394 m_xTabPosMF->set_sensitive(false);
2397 bool bIsChapterInfo = rToken.eTokenType == TOKEN_CHAPTER_INFO;
2398 bool bIsEntryNumber = rToken.eTokenType == TOKEN_ENTRY_NO;
2399 m_xChapterEntryFT->set_visible( bIsChapterInfo );
2400 m_xChapterEntryLB->set_visible( bIsChapterInfo );
2401 m_xEntryOutlineLevelFT->set_visible( bIsChapterInfo || bIsEntryNumber );
2402 m_xEntryOutlineLevelNF->set_visible( bIsChapterInfo || bIsEntryNumber );
2403 m_xNumberFormatFT->set_visible( bIsEntryNumber );
2404 m_xNumberFormatLB->set_visible( bIsEntryNumber );
2406 //now enable the visible buttons
2407 //- inserting the same type of control is not allowed
2408 //- some types of controls can only appear once (EntryText EntryNumber)
2410 if (m_xEntryNoPB->get_visible())
2412 m_xEntryNoPB->set_sensitive(TOKEN_ENTRY_NO != rToken.eTokenType );
2414 if (m_xEntryPB->get_visible())
2416 m_xEntryPB->set_sensitive(TOKEN_ENTRY_TEXT != rToken.eTokenType &&
2417 !m_xTokenWIN->Contains(TOKEN_ENTRY_TEXT)
2418 && !m_xTokenWIN->Contains(TOKEN_ENTRY));
2421 if (m_xChapterInfoPB->get_visible())
2423 m_xChapterInfoPB->set_sensitive(TOKEN_CHAPTER_INFO != rToken.eTokenType);
2425 if (m_xPageNoPB->get_visible())
2427 m_xPageNoPB->set_sensitive(TOKEN_PAGE_NUMS != rToken.eTokenType &&
2428 !m_xTokenWIN->Contains(TOKEN_PAGE_NUMS));
2430 if (m_xTabPB->get_visible())
2432 m_xTabPB->set_sensitive(!bTabStop);
2434 if (m_xHyperLinkPB->get_visible())
2436 m_xHyperLinkPB->set_sensitive(TOKEN_LINK_START != rToken.eTokenType &&
2437 TOKEN_LINK_END != rToken.eTokenType);
2439 //table of authorities
2440 if (m_xAuthInsertPB->get_visible())
2442 bool bText = TOKEN_TEXT == rToken.eTokenType;
2443 m_xAuthInsertPB->set_sensitive(bText && !m_xAuthFieldsLB->get_active_text().isEmpty());
2444 m_xAuthRemovePB->set_sensitive(!bText);
2448 IMPL_LINK(SwTOXEntryTabPage, StyleSelectHdl, weld::ComboBox&, rBox, void)
2450 OUString sEntry = rBox.get_active_text();
2451 const sal_uInt16 nId = rBox.get_active_id().toUInt32();
2452 const bool bEqualsNoCharStyle = sEntry == sNoCharStyle;
2453 m_xEditStylePB->set_sensitive(!bEqualsNoCharStyle);
2454 if (bEqualsNoCharStyle)
2455 sEntry.clear();
2456 SwTOXWidget* pCtrl = m_xTokenWIN->GetActiveControl();
2457 OSL_ENSURE(pCtrl, "no active control?");
2458 if(pCtrl)
2460 if(WindowType::EDIT == pCtrl->GetType())
2461 static_cast<SwTOXEdit*>(pCtrl)->SetCharStyleName(sEntry, nId);
2462 else
2463 static_cast<SwTOXButton*>(pCtrl)->SetCharStyleName(sEntry, nId);
2466 ModifyHdl(nullptr);
2469 IMPL_LINK(SwTOXEntryTabPage, ChapterInfoHdl, weld::ComboBox&, rBox, void)
2471 int nPos = rBox.get_active();
2472 if (nPos != -1)
2474 SwTOXWidget* pCtrl = m_xTokenWIN->GetActiveControl();
2475 OSL_ENSURE(pCtrl, "no active control?");
2476 if(pCtrl && WindowType::EDIT != pCtrl->GetType())
2477 static_cast<SwTOXButton*>(pCtrl)->SetChapterInfo(nPos);
2478 ModifyHdl(nullptr);
2482 IMPL_LINK(SwTOXEntryTabPage, ChapterInfoOutlineHdl, weld::SpinButton&, rEdit, void)
2484 const sal_uInt16 nLevel = rEdit.get_value();
2486 SwTOXWidget* pCtrl = m_xTokenWIN->GetActiveControl();
2487 OSL_ENSURE(pCtrl, "no active control?");
2488 if(pCtrl && WindowType::EDIT != pCtrl->GetType())
2489 static_cast<SwTOXButton*>(pCtrl)->SetOutlineLevel(nLevel);
2491 ModifyHdl(nullptr);
2494 IMPL_LINK(SwTOXEntryTabPage, NumberFormatHdl, weld::ComboBox&, rBox, void)
2496 const sal_Int32 nPos = rBox.get_active();
2497 if (nPos != -1)
2499 SwTOXWidget* pCtrl = m_xTokenWIN->GetActiveControl();
2500 OSL_ENSURE(pCtrl, "no active control?");
2501 if(pCtrl && WindowType::EDIT != pCtrl->GetType())
2503 static_cast<SwTOXButton*>(pCtrl)->SetEntryNumberFormat(nPos);//i89791
2505 ModifyHdl(nullptr);
2509 IMPL_LINK(SwTOXEntryTabPage, TabPosHdl, weld::MetricSpinButton&, rEdit, void)
2511 SwTOXWidget* pCtrl = m_xTokenWIN->GetActiveControl();
2512 OSL_ENSURE(pCtrl && WindowType::EDIT != pCtrl->GetType() &&
2513 TOKEN_TAB_STOP == static_cast<SwTOXButton*>(pCtrl)->GetFormToken().eTokenType,
2514 "no active style::TabStop control?");
2515 if( pCtrl && WindowType::EDIT != pCtrl->GetType() )
2517 static_cast<SwTOXButton*>(pCtrl)->SetTabPosition( static_cast< SwTwips >(
2518 rEdit.denormalize(rEdit.get_value(FieldUnit::TWIP))));
2520 ModifyHdl(nullptr);
2523 IMPL_LINK(SwTOXEntryTabPage, FillCharHdl, weld::ComboBox&, rBox, void)
2525 SwTOXWidget* pCtrl = m_xTokenWIN->GetActiveControl();
2526 OSL_ENSURE(pCtrl && WindowType::EDIT != pCtrl->GetType() &&
2527 TOKEN_TAB_STOP == static_cast<SwTOXButton*>(pCtrl)->GetFormToken().eTokenType,
2528 "no active style::TabStop control?");
2529 if (pCtrl && WindowType::EDIT != pCtrl->GetType())
2531 sal_Unicode cSet;
2532 if (!rBox.get_active_text().isEmpty())
2533 cSet = rBox.get_active_text()[0];
2534 else
2535 cSet = ' ';
2536 static_cast<SwTOXButton*>(pCtrl)->SetFillChar( cSet );
2538 ModifyHdl(nullptr);
2541 IMPL_LINK(SwTOXEntryTabPage, AutoRightHdl, weld::Toggleable&, rBox, void)
2543 //the most right style::TabStop is usually right aligned
2544 SwTOXWidget* pCurCtrl = m_xTokenWIN->GetActiveControl();
2545 OSL_ENSURE(WindowType::EDIT != pCurCtrl->GetType() &&
2546 static_cast<SwTOXButton*>(pCurCtrl)->GetFormToken().eTokenType == TOKEN_TAB_STOP,
2547 "no style::TabStop selected!");
2549 const SwFormToken& rToken = static_cast<SwTOXButton*>(pCurCtrl)->GetFormToken();
2550 bool bChecked = rBox.get_active();
2551 if(rToken.eTokenType == TOKEN_TAB_STOP)
2552 static_cast<SwTOXButton*>(pCurCtrl)->SetTabAlign(
2553 bChecked ? SvxTabAdjust::End : SvxTabAdjust::Left);
2554 m_xTabPosFT->set_sensitive(!bChecked);
2555 m_xTabPosMF->set_sensitive(!bChecked);
2556 ModifyHdl(nullptr);
2559 void SwTOXEntryTabPage::SetWrtShell(SwWrtShell& rSh)
2561 SwDocShell* pDocSh = rSh.GetView().GetDocShell();
2562 ::FillCharStyleListBox(*m_xCharStyleLB, pDocSh, true, true);
2563 const OUString sDefault(SwResId(STR_POOLCHR_STANDARD));
2564 for (int i = 0, nCount = m_xCharStyleLB->get_count(); i < nCount; ++i)
2566 const OUString sEntry = m_xCharStyleLB->get_text(i);
2567 if(sDefault != sEntry)
2569 m_xMainEntryStyleLB->append(m_xCharStyleLB->get_id(i), sEntry);
2572 m_xMainEntryStyleLB->set_active_text(SwStyleNameMapper::GetUIName(
2573 RES_POOLCHR_IDX_MAIN_ENTRY, OUString()));
2576 const TranslateId STR_TOKEN_ARY[] =
2578 STR_TOKEN_ENTRY_NO,
2579 STR_TOKEN_ENTRY, //mapped from original STR_TOKEN_ENTRY_TEXT,
2580 STR_TOKEN_ENTRY,
2581 STR_TOKEN_TAB_STOP,
2583 STR_TOKEN_PAGE_NUMS,
2584 STR_TOKEN_CHAPTER_INFO,
2585 STR_TOKEN_LINK_START,
2586 STR_TOKEN_LINK_END,
2587 STR_TOKEN_AUTHORITY
2590 const TranslateId STR_TOKEN_HELP_ARY[] =
2592 STR_TOKEN_HELP_ENTRY_NO,
2593 STR_TOKEN_HELP_ENTRY, // mapped from original STR_TOKEN_HELP_ENTRY_TEXT,
2594 STR_TOKEN_HELP_ENTRY,
2595 STR_TOKEN_HELP_TAB_STOP,
2596 STR_TOKEN_HELP_TEXT,
2597 STR_TOKEN_HELP_PAGE_NUMS,
2598 STR_TOKEN_HELP_CHAPTER_INFO,
2599 STR_TOKEN_HELP_LINK_START,
2600 STR_TOKEN_HELP_LINK_END,
2601 STR_TOKEN_HELP_AUTHORITY
2604 SwTokenWindow::SwTokenWindow(std::unique_ptr<weld::Container> xParent)
2605 : m_pForm(nullptr)
2606 , m_nLevel(0)
2607 , m_bValid(false)
2608 , m_sCharStyle(SwResId(STR_CHARSTYLE))
2609 , m_pActiveCtrl(nullptr)
2610 , m_aAdjustPositionsIdle("SwTokenWindow m_aAdjustPositionsIdle")
2611 , m_pParent(nullptr)
2612 , m_xParentWidget(std::move(xParent))
2613 , m_xBuilder(Application::CreateBuilder(m_xParentWidget.get(), "modules/swriter/ui/tokenwidget.ui"))
2614 , m_xContainer(m_xBuilder->weld_container("TokenWidget"))
2615 , m_xLeftScrollWin(m_xBuilder->weld_button("left"))
2616 , m_xCtrlParentWin(m_xBuilder->weld_container("ctrl"))
2617 , m_xScrollWin(m_xBuilder->weld_scrolled_window("scrollwin"))
2618 , m_xRightScrollWin(m_xBuilder->weld_button("right"))
2620 m_xScrollWin->connect_hadjustment_changed(LINK(this, SwTokenWindow, ScrollHdl));
2621 m_xCtrlParentWin->connect_size_allocate(LINK(this, SwTokenWindow, AdjustPositionsHdl));
2623 for (sal_uInt32 i = 0; i < TOKEN_END; ++i)
2625 TranslateId pTextId = STR_TOKEN_ARY[i];
2626 if (pTextId)
2627 m_aButtonTexts[i] = SwResId(pTextId);
2629 TranslateId pHelpId = STR_TOKEN_HELP_ARY[i];
2630 m_aButtonHelpTexts[i] = SwResId(pHelpId);
2633 m_sAccessibleName = SwResId(STR_STRUCTURE);
2634 m_sAdditionalAccnameString1 = SwResId(STR_ADDITIONAL_ACCNAME_STRING1);
2635 m_sAdditionalAccnameString2 = SwResId(STR_ADDITIONAL_ACCNAME_STRING2);
2636 m_sAdditionalAccnameString3 = SwResId(STR_ADDITIONAL_ACCNAME_STRING3);
2638 Link<weld::Button&,void> aLink(LINK(this, SwTokenWindow, ScrollBtnHdl));
2639 m_xLeftScrollWin->connect_clicked(aLink);
2640 m_xRightScrollWin->connect_clicked(aLink);
2643 SwTokenWindow::~SwTokenWindow()
2647 void SwTokenWindow::SetForm(SwForm& rForm, sal_uInt16 nL)
2649 SetActiveControl(nullptr);
2650 m_bValid = true;
2652 if (m_pForm)
2654 //apply current level settings to the form
2655 m_aControlList.clear();
2658 m_nLevel = nL;
2659 m_pForm = &rForm;
2660 //now the display
2661 if(m_nLevel < MAXLEVEL || rForm.GetTOXType() == TOX_AUTHORITIES)
2663 // #i21237#
2664 SwFormTokens aPattern = m_pForm->GetPattern(m_nLevel + 1);
2665 bool bLastWasText = false; //assure alternating text - code - text
2667 SwTOXWidget* pSetActiveControl = nullptr;
2668 for (const auto& aToken : aPattern) // #i21237#
2670 if(TOKEN_TEXT == aToken.eTokenType)
2672 SAL_WARN_IF(bLastWasText, "sw", "text following text is invalid");
2673 SwTOXWidget* pCtrl = InsertItem(aToken.sText, aToken);
2674 bLastWasText = true;
2675 if (!GetActiveControl())
2676 SetActiveControl(pCtrl);
2678 else
2680 if( !bLastWasText )
2682 SwFormToken aTemp(TOKEN_TEXT);
2683 SwTOXWidget* pCtrl = InsertItem(OUString(), aTemp);
2684 if(!pSetActiveControl)
2685 pSetActiveControl = pCtrl;
2688 OUString sForm;
2689 switch( aToken.eTokenType )
2691 case TOKEN_ENTRY_NO: sForm = SwForm::GetFormEntryNum(); break;
2692 case TOKEN_ENTRY_TEXT: sForm = SwForm::GetFormEntryText(); break;
2693 case TOKEN_ENTRY: sForm = SwForm::GetFormEntry(); break;
2694 case TOKEN_TAB_STOP: sForm = SwForm::GetFormTab(); break;
2695 case TOKEN_PAGE_NUMS: sForm = SwForm::GetFormPageNums(); break;
2696 case TOKEN_CHAPTER_INFO: sForm = SwForm::GetFormChapterMark(); break;
2697 case TOKEN_LINK_START: sForm = SwForm::GetFormLinkStt(); break;
2698 case TOKEN_LINK_END: sForm = SwForm::GetFormLinkEnd(); break;
2699 case TOKEN_AUTHORITY: sForm = SwForm::GetFormAuth(); break;
2700 default:; //prevent warning
2703 InsertItem( sForm, aToken );
2704 bLastWasText = false;
2707 if(!bLastWasText)
2709 SwFormToken aTemp(TOKEN_TEXT);
2710 SwTOXWidget* pCtrl = InsertItem(OUString(), aTemp);
2711 if(!pSetActiveControl)
2712 pSetActiveControl = pCtrl;
2714 SetActiveControl(pSetActiveControl);
2716 AdjustScrolling();
2719 void SwTokenWindow::SetActiveControl(SwTOXWidget* pSet)
2721 if (pSet == m_pActiveCtrl)
2722 return;
2724 m_pActiveCtrl = pSet;
2725 if( !m_pActiveCtrl )
2726 return;
2728 m_pActiveCtrl->GrabFocus();
2729 //it must be a SwTOXEdit
2730 const SwFormToken* pFToken;
2731 if( WindowType::EDIT == m_pActiveCtrl->GetType() )
2732 pFToken = &static_cast<SwTOXEdit*>(m_pActiveCtrl)->GetFormToken();
2733 else
2734 pFToken = &static_cast<SwTOXButton*>(m_pActiveCtrl)->GetFormToken();
2736 SwFormToken aTemp( *pFToken );
2737 m_aButtonSelectedHdl.Call( aTemp );
2740 SwTOXWidget* SwTokenWindow::InsertItem(const OUString& rText, const SwFormToken& rToken)
2742 SwTOXWidget* pRet = nullptr;
2744 if (TOKEN_TEXT == rToken.eTokenType)
2746 SwTOXEdit* pEdit = new SwTOXEdit(this, rToken);
2747 pEdit->set_grid_left_attach(m_aControlList.size());
2749 m_aControlList.emplace_back(pEdit);
2751 pEdit->SetText(rText);
2752 sal_uInt32 nIndex = GetControlIndex( TOKEN_TEXT );
2753 OUString strName(m_sAccessibleName + OUString::number(nIndex));
2754 if ( nIndex == 1 )
2756 /*Press left or right arrow to choose the structure controls*/
2757 strName += " (" + m_sAdditionalAccnameString2 + ", "
2758 /*Press Ctrl+Alt+A to move focus for more operations*/
2759 + m_sAdditionalAccnameString1 + ", "
2760 /*Press Ctrl+Alt+B to move focus back to the current structure control*/
2761 + m_sAdditionalAccnameString3 + ")";
2763 pEdit->SetAccessibleName(strName);
2764 pEdit->AdjustSize();
2765 pEdit->SetModifyHdl(LINK(this, SwTokenWindow, EditResize ));
2766 pEdit->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemHdl));
2767 pEdit->SetGetFocusHdl(LINK(this, SwTokenWindow, TbxFocusHdl));
2768 pEdit->Show();
2769 pRet = pEdit;
2771 else
2773 SwTOXButton* pButton = new SwTOXButton(this, rToken);
2774 pButton->set_grid_left_attach(m_aControlList.size());
2776 m_aControlList.emplace_back(pButton);
2778 pButton->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemBtnHdl));
2779 pButton->SetGetFocusHdl(LINK(this, SwTokenWindow, TbxFocusBtnHdl));
2781 if(TOKEN_AUTHORITY != rToken.eTokenType)
2782 pButton->SetText(m_aButtonTexts[rToken.eTokenType]);
2783 else
2785 //use the first two chars as symbol
2786 OUString sTmp(SwAuthorityFieldType::GetAuthFieldName(
2787 static_cast<ToxAuthorityField>(rToken.nAuthorityField)));
2788 pButton->SetText(sTmp.copy(0, 2));
2791 sal_uInt32 nIndex = GetControlIndex( rToken.eTokenType );
2792 OUString sAccName = m_aButtonHelpTexts[rToken.eTokenType];
2793 if ( nIndex )
2795 sAccName += " " + OUString::number(nIndex);
2797 pButton->SetAccessibleName( sAccName );
2799 pButton->Show();
2800 pRet = pButton;
2803 return pRet;
2806 void SwTokenWindow::InsertAtSelection(const SwFormToken& rToken)
2808 OSL_ENSURE(m_pActiveCtrl, "no active control!");
2810 if(!m_pActiveCtrl)
2811 return;
2813 SwFormToken aToInsertToken(rToken);
2815 if(TOKEN_LINK_START == aToInsertToken.eTokenType)
2817 //determine if start or end of hyperlink is appropriate
2818 //eventually change a following link start into a link end
2819 // groups of LS LE should be ignored
2820 // <insert>
2821 //LS <insert>
2822 //LE <insert>
2823 //<insert> LS
2824 //<insert> LE
2825 //<insert>
2826 bool bPreStartLinkFound = false;
2827 bool bPreEndLinkFound = false;
2829 const SwTOXWidget* pControl = nullptr;
2830 const SwTOXWidget* pExchange = nullptr;
2832 auto it = m_aControlList.cbegin();
2833 for( ; it != m_aControlList.cend() && m_pActiveCtrl != it->get(); ++it )
2835 pControl = it->get();
2837 if( WindowType::EDIT != pControl->GetType())
2839 const SwFormToken& rNewToken =
2840 static_cast<const SwTOXButton*>(pControl)->GetFormToken();
2842 if( TOKEN_LINK_START == rNewToken.eTokenType )
2844 bPreStartLinkFound = true;
2845 pExchange = nullptr;
2847 else if(TOKEN_LINK_END == rNewToken.eTokenType)
2849 if( bPreStartLinkFound )
2850 bPreStartLinkFound = false;
2851 else
2853 bPreEndLinkFound = false;
2854 pExchange = pControl;
2860 bool bPostLinkStartFound = false;
2862 if(!bPreStartLinkFound && !bPreEndLinkFound)
2864 for( ; it != m_aControlList.cend(); ++it )
2866 pControl = it->get();
2868 if( pControl != m_pActiveCtrl &&
2869 WindowType::EDIT != pControl->GetType())
2871 const SwFormToken& rNewToken =
2872 static_cast<const SwTOXButton*>(pControl)->GetFormToken();
2874 if( TOKEN_LINK_START == rNewToken.eTokenType )
2876 if(bPostLinkStartFound)
2877 break;
2878 bPostLinkStartFound = true;
2879 pExchange = pControl;
2881 else if(TOKEN_LINK_END == rNewToken.eTokenType )
2883 if(bPostLinkStartFound)
2885 bPostLinkStartFound = false;
2886 pExchange = nullptr;
2888 break;
2894 if(bPreStartLinkFound)
2896 aToInsertToken.eTokenType = TOKEN_LINK_END;
2897 aToInsertToken.sText = m_aButtonTexts[TOKEN_LINK_END];
2900 if(bPostLinkStartFound)
2902 OSL_ENSURE(pExchange, "no control to exchange?");
2903 if(pExchange)
2905 const_cast<SwTOXButton*>(static_cast<const SwTOXButton*>(pExchange))->SetLinkEnd();
2906 const_cast<SwTOXButton*>(static_cast<const SwTOXButton*>(pExchange))->SetText(m_aButtonTexts[TOKEN_LINK_END]);
2910 if(bPreEndLinkFound)
2912 OSL_ENSURE(pExchange, "no control to exchange?");
2914 if(pExchange)
2916 const_cast<SwTOXButton*>(static_cast<const SwTOXButton*>(pExchange))->SetLinkStart();
2917 const_cast<SwTOXButton*>(static_cast<const SwTOXButton*>(pExchange))->SetText(m_aButtonTexts[TOKEN_LINK_START]);
2922 //if the active control is text then insert a new button at the selection
2923 //else replace the button
2924 auto iterActive = std::find_if(m_aControlList.begin(), m_aControlList.end(),
2925 [this](const auto& rControl)
2927 SwTOXWidget* pCtrl = rControl.get();
2928 return pCtrl == m_pActiveCtrl;
2931 assert(iterActive != m_aControlList.end());
2932 if (iterActive == m_aControlList.end())
2933 return;
2935 if (WindowType::EDIT == m_pActiveCtrl->GetType())
2937 ++iterActive;
2939 int nStartPos, nEndPos;
2940 static_cast<SwTOXEdit*>(m_pActiveCtrl)->get_selection_bounds(nStartPos, nEndPos);
2942 const OUString sEditText = static_cast<SwTOXEdit*>(m_pActiveCtrl)->GetText();
2943 const OUString sLeft = sEditText.copy( 0, std::min(nStartPos, nEndPos) );
2944 const OUString sRight = sEditText.copy( std::max(nStartPos, nEndPos) );
2946 static_cast<SwTOXEdit*>(m_pActiveCtrl)->SetText(sLeft);
2947 static_cast<SwTOXEdit*>(m_pActiveCtrl)->AdjustSize();
2949 SwFormToken aTmpToken(TOKEN_TEXT);
2950 SwTOXEdit* pEdit = new SwTOXEdit(this, aTmpToken);
2951 iterActive = m_aControlList.emplace(iterActive, pEdit);
2953 pEdit->SetText(sRight);
2954 sal_uInt32 nIndex = GetControlIndex( TOKEN_TEXT );
2955 OUString strName(m_sAccessibleName + OUString::number(nIndex));
2956 if ( nIndex == 1)
2958 /*Press left or right arrow to choose the structure controls*/
2959 strName += " (" + m_sAdditionalAccnameString2 + ", "
2960 /*Press Ctrl+Alt+A to move focus for more operations*/
2961 + m_sAdditionalAccnameString1 + ", "
2962 /*Press Ctrl+Alt+B to move focus back to the current structure control*/
2963 + m_sAdditionalAccnameString3 + ")";
2965 pEdit->SetAccessibleName(strName);
2966 pEdit->AdjustSize();
2967 pEdit->SetModifyHdl(LINK(this, SwTokenWindow, EditResize ));
2968 pEdit->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemHdl));
2969 pEdit->SetGetFocusHdl(LINK(this, SwTokenWindow, TbxFocusHdl));
2970 pEdit->Show();
2972 else
2974 m_pActiveCtrl->Hide();
2975 m_pActiveCtrl = nullptr;
2976 iterActive = m_aControlList.erase(iterActive);
2979 //now the new button
2980 SwTOXButton* pButton = new SwTOXButton(this, aToInsertToken);
2981 m_aControlList.emplace(iterActive, pButton);
2983 pButton->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemBtnHdl));
2984 pButton->SetGetFocusHdl(LINK(this, SwTokenWindow, TbxFocusBtnHdl));
2986 if (TOKEN_AUTHORITY != aToInsertToken.eTokenType)
2988 pButton->SetText(m_aButtonTexts[aToInsertToken.eTokenType]);
2990 else
2992 //use the first two chars as symbol
2993 OUString sTmp(SwAuthorityFieldType::GetAuthFieldName(
2994 static_cast<ToxAuthorityField>(aToInsertToken.nAuthorityField)));
2995 pButton->SetText(sTmp.copy(0, 2));
2998 pButton->Check();
2999 pButton->Show();
3000 SetActiveControl(pButton);
3002 AdjustPositions();
3005 void SwTokenWindow::RemoveControl(const SwTOXButton* pDel, bool bInternalCall)
3007 if (bInternalCall && TOX_AUTHORITIES == m_pForm->GetTOXType())
3008 m_pParent->PreTokenButtonRemoved(pDel->GetFormToken());
3010 auto it = std::find_if(m_aControlList.begin(), m_aControlList.end(),
3011 [pDel](const auto& rControl)
3013 SwTOXWidget* pCtrl = rControl.get();
3014 return pCtrl == pDel;
3016 assert(it != m_aControlList.end()); //Control does not exist!
3017 if (it == m_aControlList.end())
3018 return;
3020 // the two neighbours of the box must be merged
3021 // the properties of the right one will be lost
3022 assert(it != m_aControlList.begin() && it != m_aControlList.end() - 1); //Button at first or last position?
3023 if (it == m_aControlList.begin() || it == m_aControlList.end() - 1)
3024 return;
3026 auto itLeft = it, itRight = it;
3027 --itLeft;
3028 ++itRight;
3029 SwTOXWidget* pLeftEdit = itLeft->get();
3030 SwTOXWidget* pRightEdit = itRight->get();
3032 static_cast<SwTOXEdit*>(pLeftEdit)->SetText(static_cast<SwTOXEdit*>(pLeftEdit)->GetText() +
3033 static_cast<SwTOXEdit*>(pRightEdit)->GetText());
3034 static_cast<SwTOXEdit*>(pLeftEdit)->AdjustSize();
3036 m_pActiveCtrl->Hide();
3037 m_pActiveCtrl = nullptr;
3039 m_aControlList.erase(itRight);
3040 m_aControlList.erase(it);
3042 SetActiveControl(pLeftEdit);
3043 AdjustPositions();
3044 m_aModifyHdl.Call(nullptr);
3047 IMPL_LINK_NOARG(SwTokenWindow, AdjustPositionsHdl, const Size&, void)
3049 AdjustScrolling();
3052 void SwTokenWindow::AdjustPositions()
3054 for (size_t i = 0; i < m_aControlList.size(); ++i)
3055 m_aControlList[i]->set_grid_left_attach(i);
3056 AdjustScrolling();
3059 void SwTokenWindow::MoveControls(tools::Long nOffset)
3061 m_xScrollWin->hadjustment_set_value(nOffset);
3064 IMPL_LINK_NOARG(SwTokenWindow, ScrollHdl, weld::ScrolledWindow&, void)
3066 AdjustScrolling();
3069 void SwTokenWindow::AdjustScrolling()
3071 if (m_aControlList.size() <= 1)
3072 return;
3074 //validate scroll buttons
3076 auto nLeft = m_xScrollWin->hadjustment_get_value();
3077 auto nSpace = m_xScrollWin->hadjustment_get_page_size();
3078 auto nWidth = m_xScrollWin->hadjustment_get_upper();
3080 bool bEnable = nWidth > nSpace;
3082 //the active control must be visible
3083 if (bEnable && m_pActiveCtrl)
3085 int x, y, width, height;
3086 m_pActiveCtrl->get_extents_relative_to(*m_xCtrlParentWin, x, y, width, height);
3088 if (x < nLeft || x + width > nLeft + nSpace)
3090 MoveControls(x);
3091 nLeft = x;
3094 m_xLeftScrollWin->set_sensitive(nLeft > 0);
3095 m_xRightScrollWin->set_sensitive(nLeft + nSpace < nWidth);
3097 else
3099 //if the control fits into the space then the first control must be at position 0
3100 m_xRightScrollWin->set_sensitive(false);
3101 m_xLeftScrollWin->set_sensitive(false);
3105 IMPL_LINK(SwTokenWindow, ScrollBtnHdl, weld::Button&, rBtn, void)
3107 if (m_aControlList.empty())
3108 return;
3110 const auto nSpace = m_xScrollWin->hadjustment_get_page_size();
3111 const auto nWidth = m_xScrollWin->hadjustment_get_upper();
3112 const auto nLeft = m_xScrollWin->hadjustment_get_value();
3114 tools::Long nMove = nLeft;
3115 if (&rBtn == m_xLeftScrollWin.get())
3117 //find the first completely visible control (left edge visible)
3118 auto it = std::find_if(m_aControlList.begin(), m_aControlList.end(),
3119 [this, nLeft](const auto& rControl)
3121 SwTOXWidget* pCtrl = rControl.get();
3123 int x, y, width, height;
3124 pCtrl->get_extents_relative_to(*m_xCtrlParentWin, x, y, width, height);
3126 return x >= nLeft;
3128 if (it != m_aControlList.end())
3130 if (it == m_aControlList.begin())
3132 nMove = 0;
3134 else
3136 //move the left neighbor to the start position
3137 auto itLeft = it;
3138 --itLeft;
3139 SwTOXWidget* pLeft = itLeft->get();
3141 int x, y, width, height;
3142 pLeft->get_extents_relative_to(*m_xCtrlParentWin, x, y, width, height);
3144 nMove = x;
3148 else
3150 //find the first completely visible control (right edge visible)
3151 auto it = std::find_if(m_aControlList.rbegin(), m_aControlList.rend(),
3152 [this, nLeft, nSpace](const auto& rControl) {
3153 SwTOXWidget* pCtrl = rControl.get();
3155 int x, y, width, height;
3156 pCtrl->get_extents_relative_to(*m_xCtrlParentWin, x, y, width, height);
3158 auto nXPos = x + width;
3159 return nXPos <= nLeft + nSpace;
3161 if (it != m_aControlList.rend() && it != m_aControlList.rbegin())
3163 //move the right neighbor to the right edge right aligned
3164 auto itRight = it;
3165 --itRight;
3166 SwTOXWidget* pRight = itRight->get();
3168 int x, y, width, height;
3169 pRight->get_extents_relative_to(*m_xCtrlParentWin, x, y, width, height);
3171 nMove = x + width - nSpace;
3174 //move it left until it's completely visible
3177 if (nMove != nLeft)
3179 // move the complete list
3180 MoveControls(nMove);
3181 m_xLeftScrollWin->set_sensitive(nMove > 0);
3182 m_xRightScrollWin->set_sensitive(nMove + nSpace < nWidth);
3186 OUString SwTokenWindow::GetPattern() const
3188 OUStringBuffer sRet;
3190 for (const auto& elem : m_aControlList)
3192 const SwTOXWidget* pCtrl = elem.get();
3194 const SwFormToken &rNewToken = pCtrl->GetType() == WindowType::EDIT
3195 ? const_cast<SwTOXEdit*>(static_cast<const SwTOXEdit*>(pCtrl))->GetFormToken()
3196 : static_cast<const SwTOXButton*>(pCtrl)->GetFormToken();
3198 //TODO: prevent input of TOX_STYLE_DELIMITER in KeyInput
3199 sRet.append(rNewToken.GetString());
3202 return sRet.makeStringAndClear();
3205 // Check if a control of the specified TokenType is already contained in the list
3206 bool SwTokenWindow::Contains(FormTokenType eSearchFor) const
3208 bool bRet = false;
3210 for (const auto& elem : m_aControlList)
3212 const SwTOXWidget* pCtrl = elem.get();
3213 const SwFormToken &rNewToken = pCtrl->GetType() == WindowType::EDIT
3214 ? const_cast<SwTOXEdit*>(static_cast<const SwTOXEdit*>(pCtrl))->GetFormToken()
3215 : static_cast<const SwTOXButton*>(pCtrl)->GetFormToken();
3217 if (eSearchFor == rNewToken.eTokenType)
3219 bRet = true;
3220 break;
3224 return bRet;
3227 OUString SwTokenWindow::CreateQuickHelp(const SwFormToken& rToken)
3229 OUString sEntry;
3230 if (rToken.eTokenType != TOKEN_AUTHORITY)
3231 sEntry = m_aButtonHelpTexts[rToken.eTokenType];
3232 else
3234 sEntry += SwAuthorityFieldType::GetAuthFieldName(
3235 static_cast<ToxAuthorityField>(rToken.nAuthorityField));
3238 if (rToken.eTokenType != TOKEN_TAB_STOP)
3240 if (!rToken.sCharStyleName.isEmpty())
3242 sEntry += " " + m_sCharStyle + rToken.sCharStyleName;
3246 return sEntry;
3249 IMPL_LINK(SwTokenWindow, EditResize, SwTOXEdit&, rEdit, void)
3251 rEdit.AdjustSize();
3252 AdjustPositions();
3253 m_aModifyHdl.Call(nullptr);
3256 IMPL_LINK(SwTokenWindow, NextItemHdl, SwTOXEdit&, rEdit, void)
3258 auto it = std::find_if(m_aControlList.begin(), m_aControlList.end(),
3259 [&rEdit](const auto& rControl)
3261 SwTOXWidget* pCtrl = rControl.get();
3262 return pCtrl == &rEdit;
3265 if (it == m_aControlList.end())
3266 return;
3268 auto itTest = it;
3269 ++itTest;
3271 if ((it != m_aControlList.begin() && !rEdit.IsNextControl()) ||
3272 (itTest != m_aControlList.end() && rEdit.IsNextControl()))
3274 auto iterFocus = it;
3275 rEdit.IsNextControl() ? ++iterFocus : --iterFocus;
3277 SwTOXWidget *pCtrlFocus = iterFocus->get();
3278 pCtrlFocus->GrabFocus();
3279 static_cast<SwTOXButton*>(pCtrlFocus)->Check();
3281 AdjustScrolling();
3285 IMPL_LINK(SwTokenWindow, TbxFocusHdl, SwTOXWidget&, rControl, void)
3287 SwTOXEdit* pEdit = static_cast<SwTOXEdit*>(&rControl);
3288 for (const auto& aControl : m_aControlList)
3290 SwTOXWidget* pCtrl = aControl.get();
3291 if (pCtrl && pCtrl->GetType() != WindowType::EDIT)
3292 static_cast<SwTOXButton*>(pCtrl)->Check(false);
3295 SetActiveControl(pEdit);
3298 IMPL_LINK(SwTokenWindow, NextItemBtnHdl, SwTOXButton&, rBtn, void )
3300 auto it = std::find_if(m_aControlList.begin(), m_aControlList.end(),
3301 [&rBtn](const auto& rControl)
3303 SwTOXWidget* pCtrl = rControl.get();
3304 return pCtrl == &rBtn;
3307 if (it == m_aControlList.end())
3308 return;
3310 auto itTest = it;
3311 ++itTest;
3313 if (rBtn.IsNextControl() && (itTest == m_aControlList.end() || !rBtn.IsNextControl()))
3314 return;
3316 bool isNext = rBtn.IsNextControl();
3318 auto iterFocus = it;
3319 isNext ? ++iterFocus : --iterFocus;
3321 SwTOXWidget* pCtrlFocus = iterFocus->get();
3322 pCtrlFocus->GrabFocus();
3323 int nStartPos(0), nEndPos(0);
3325 if (!isNext)
3327 const sal_Int32 nLen = static_cast<SwTOXEdit*>(pCtrlFocus)->GetText().getLength();
3329 nStartPos = nLen;
3330 nEndPos = nLen;
3333 static_cast<SwTOXEdit*>(pCtrlFocus)->select_region(nStartPos, nEndPos);
3335 rBtn.Check(false);
3337 AdjustScrolling();
3340 IMPL_LINK(SwTokenWindow, TbxFocusBtnHdl, SwTOXWidget&, rControl, void)
3342 SwTOXButton* pBtn = static_cast<SwTOXButton*>(&rControl);
3343 for (const auto& aControl : m_aControlList)
3345 SwTOXWidget* pControl = aControl.get();
3347 if (pControl && WindowType::EDIT != pControl->GetType())
3348 static_cast<SwTOXButton*>(pControl)->Check(pBtn == pControl);
3351 SetActiveControl(pBtn);
3354 void SwTokenWindow::SetFocus2theAllBtn()
3356 if (m_pParent)
3358 m_pParent->SetFocus2theAllBtn();
3362 sal_uInt32 SwTokenWindow::GetControlIndex(FormTokenType eType) const
3364 //there are only one entry-text button and only one page-number button,
3365 //so we need not add index for these two buttons.
3366 if ( eType == TOKEN_ENTRY_TEXT || eType == TOKEN_PAGE_NUMS )
3368 return 0;
3371 sal_uInt32 nIndex = 0;
3372 for (const auto& elem : m_aControlList)
3374 const SwTOXWidget* pControl = elem.get();
3376 const SwFormToken& rNewToken = WindowType::EDIT == pControl->GetType()
3377 ? const_cast<SwTOXEdit*>(static_cast<const SwTOXEdit*>(pControl))->GetFormToken()
3378 : static_cast<const SwTOXButton*>(pControl)->GetFormToken();
3380 if(eType == rNewToken.eTokenType)
3382 ++nIndex;
3386 return nIndex;
3389 SwTOXStylesTabPage::SwTOXStylesTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rAttrSet)
3390 : SfxTabPage(pPage, pController, "modules/swriter/ui/tocstylespage.ui", "TocStylesPage", &rAttrSet)
3391 , m_xLevelLB(m_xBuilder->weld_tree_view("levels"))
3392 , m_xAssignBT(m_xBuilder->weld_button("assign"))
3393 , m_xParaLayLB(m_xBuilder->weld_tree_view("styles"))
3394 , m_xStdBT(m_xBuilder->weld_button("default"))
3395 , m_xEditStyleBT(m_xBuilder->weld_button("edit"))
3397 m_xParaLayLB->make_sorted();
3398 auto nHeight = m_xLevelLB->get_height_rows(16);
3399 m_xLevelLB->set_size_request(-1, nHeight);
3400 m_xParaLayLB->set_size_request(-1, nHeight);
3402 SetExchangeSupport();
3404 m_xEditStyleBT->connect_clicked(LINK(this, SwTOXStylesTabPage, EditStyleHdl));
3405 m_xAssignBT->connect_clicked(LINK(this, SwTOXStylesTabPage, AssignHdl));
3406 m_xStdBT->connect_clicked(LINK(this, SwTOXStylesTabPage, StdHdl));
3407 m_xParaLayLB->connect_changed(LINK(this, SwTOXStylesTabPage, EnableSelectHdl));
3408 m_xLevelLB->connect_changed(LINK(this, SwTOXStylesTabPage, EnableSelectHdl));
3409 m_xParaLayLB->connect_row_activated(LINK(this, SwTOXStylesTabPage, DoubleClickHdl));
3412 SwTOXStylesTabPage::~SwTOXStylesTabPage()
3416 bool SwTOXStylesTabPage::FillItemSet( SfxItemSet* )
3418 return true;
3421 void SwTOXStylesTabPage::Reset( const SfxItemSet* rSet )
3423 ActivatePage(*rSet);
3426 void SwTOXStylesTabPage::ActivatePage( const SfxItemSet& )
3428 m_pCurrentForm.reset(new SwForm(GetForm()));
3430 // not hyperlink for user directories
3431 const sal_uInt16 nSize = m_pCurrentForm->GetFormMax();
3433 // display form pattern without title
3435 m_xLevelLB->freeze();
3436 m_xLevelLB->clear();
3437 // display 1st TemplateEntry
3438 OUString aStr( SwResId( STR_TITLE ));
3439 if( !m_pCurrentForm->GetTemplate( 0 ).isEmpty() )
3441 aStr += " " + OUStringChar(aDeliStart)
3442 + m_pCurrentForm->GetTemplate( 0 )
3443 + OUStringChar(aDeliEnd);
3445 m_xLevelLB->append_text(aStr);
3447 for( sal_uInt16 i=1; i < nSize; ++i )
3449 if( TOX_INDEX == m_pCurrentForm->GetTOXType() &&
3450 FORM_ALPHA_DELIMITER == i )
3452 aStr = SwResId(STR_ALPHA);
3454 else
3456 aStr = SwResId(STR_LEVEL) + OUString::number(
3457 TOX_INDEX == m_pCurrentForm->GetTOXType() ? i - 1 : i );
3459 if( !m_pCurrentForm->GetTemplate( i ).isEmpty() )
3461 aStr += " " + OUStringChar(aDeliStart)
3462 + m_pCurrentForm->GetTemplate( i )
3463 + OUStringChar(aDeliEnd);
3465 m_xLevelLB->append_text(aStr);
3467 m_xLevelLB->thaw();
3469 // initialise templates
3470 SwWrtShell& rSh = static_cast<SwMultiTOXTabDialog*>(GetDialogController())->GetWrtShell();
3471 const sal_uInt16 nSz = rSh.GetTextFormatCollCount();
3473 m_xParaLayLB->freeze();
3474 m_xParaLayLB->clear();
3475 for( sal_uInt16 i = 0; i < nSz; ++i )
3477 const SwTextFormatColl *pColl = &rSh.GetTextFormatColl( i );
3478 if( !pColl->IsDefault() )
3479 m_xParaLayLB->append_text( pColl->GetName() );
3482 // query pool collections and set them for the directory
3483 for( sal_uInt16 i = 0; i < m_pCurrentForm->GetFormMax(); ++i )
3485 aStr = m_pCurrentForm->GetTemplate( i );
3486 if (!aStr.isEmpty() && m_xParaLayLB->find_text(aStr) == -1)
3487 m_xParaLayLB->append_text(aStr);
3489 m_xParaLayLB->thaw();
3491 EnableSelectHdl(*m_xParaLayLB);
3494 DeactivateRC SwTOXStylesTabPage::DeactivatePage( SfxItemSet* /*pSet*/ )
3496 GetForm() = *m_pCurrentForm;
3497 return DeactivateRC::LeavePage;
3500 std::unique_ptr<SfxTabPage> SwTOXStylesTabPage::Create(weld::Container* pPage, weld::DialogController* pController,
3501 const SfxItemSet* rAttrSet)
3503 return std::make_unique<SwTOXStylesTabPage>(pPage, pController, *rAttrSet);
3506 IMPL_LINK_NOARG(SwTOXStylesTabPage, EditStyleHdl, weld::Button&, void)
3508 if (m_xParaLayLB->get_selected_index() != -1)
3510 SfxStringItem aStyle(SID_STYLE_EDIT, m_xParaLayLB->get_selected_text());
3511 SfxUInt16Item aFamily(SID_STYLE_FAMILY, sal_uInt16(SfxStyleFamily::Para));
3512 SwWrtShell& rSh = static_cast<SwMultiTOXTabDialog*>(GetDialogController())->GetWrtShell();
3513 rSh.GetView().GetViewFrame()->GetDispatcher()->ExecuteList(SID_STYLE_EDIT,
3514 SfxCallMode::SYNCHRON,
3515 { &aStyle, &aFamily });
3519 // allocate templates
3520 IMPL_LINK_NOARG(SwTOXStylesTabPage, AssignHdl, weld::Button&, void)
3522 auto nLevPos = m_xLevelLB->get_selected_index();
3523 auto nTemplPos = m_xParaLayLB->get_selected_index();
3524 if (nLevPos == -1 || nTemplPos == -1)
3525 return;
3527 const OUString aStr(m_xLevelLB->get_text(nLevPos).getToken(0, aDeliStart)
3528 + OUStringChar(aDeliStart)
3529 + m_xParaLayLB->get_selected_text()
3530 + OUStringChar(aDeliEnd));
3532 m_pCurrentForm->SetTemplate(nLevPos, m_xParaLayLB->get_selected_text());
3534 m_xLevelLB->remove(nLevPos);
3535 m_xLevelLB->insert_text(nLevPos, aStr);
3536 m_xLevelLB->select_text(aStr);
3537 Modify();
3540 IMPL_LINK_NOARG(SwTOXStylesTabPage, StdHdl, weld::Button&, void)
3542 const auto nPos = m_xLevelLB->get_selected_index();
3543 if (nPos != -1)
3545 const OUString aStr(m_xLevelLB->get_text(nPos).getToken(0, aDeliStart));
3546 m_xLevelLB->remove(nPos);
3547 m_xLevelLB->insert_text(nPos, aStr);
3548 m_xLevelLB->select_text(aStr);
3549 m_pCurrentForm->SetTemplate(nPos, OUString());
3550 Modify();
3554 IMPL_LINK_NOARG(SwTOXStylesTabPage, DoubleClickHdl, weld::TreeView&, bool)
3556 const OUString aTmpName(m_xParaLayLB->get_selected_text());
3557 SwWrtShell& rSh = static_cast<SwMultiTOXTabDialog*>(GetDialogController())->GetWrtShell();
3559 if(m_xParaLayLB->get_selected_index() != -1 &&
3560 (m_xLevelLB->get_selected_index() == 0 || SwMultiTOXTabDialog::IsNoNum(rSh, aTmpName)))
3561 AssignHdl(*m_xAssignBT);
3563 return true;
3566 // enable only when selected
3567 IMPL_LINK_NOARG(SwTOXStylesTabPage, EnableSelectHdl, weld::TreeView&, void)
3569 m_xStdBT->set_sensitive(m_xLevelLB->get_selected_index() != -1);
3571 SwWrtShell& rSh = static_cast<SwMultiTOXTabDialog*>(GetDialogController())->GetWrtShell();
3572 const OUString aTmpName(m_xParaLayLB->get_selected_text());
3573 m_xAssignBT->set_sensitive(m_xParaLayLB->get_selected_index() != -1 &&
3574 m_xLevelLB->get_selected_index() != -1 &&
3575 (m_xLevelLB->get_selected_index() == 0 || SwMultiTOXTabDialog::IsNoNum(rSh, aTmpName)));
3576 m_xEditStyleBT->set_sensitive(m_xParaLayLB->get_selected_index() != -1);
3579 void SwTOXStylesTabPage::Modify()
3581 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
3582 if (pTOXDlg)
3584 GetForm() = *m_pCurrentForm;
3585 pTOXDlg->CreateOrUpdateExample(pTOXDlg->GetCurrentTOXType().eType, TOX_PAGE_STYLES);
3589 #define ITEM_SEARCH 1
3590 #define ITEM_ALTERNATIVE 2
3591 #define ITEM_PRIM_KEY 3
3592 #define ITEM_SEC_KEY 4
3593 #define ITEM_COMMENT 5
3594 #define ITEM_CASE 6
3595 #define ITEM_WORDONLY 7
3597 SwEntryBrowseBox::SwEntryBrowseBox(const css::uno::Reference<css::awt::XWindow> &rParent)
3598 : SwEntryBrowseBox_Base(VCLUnoHelper::GetWindow(rParent), EditBrowseBoxFlags::NONE, WB_TABSTOP | WB_BORDER,
3599 BrowserMode::KEEPHIGHLIGHT |
3600 BrowserMode::COLUMNSELECTION |
3601 BrowserMode::MULTISELECTION |
3602 BrowserMode::TRACKING_TIPS |
3603 BrowserMode::HLINES |
3604 BrowserMode::VLINES |
3605 BrowserMode::AUTO_VSCROLL|
3606 BrowserMode::HIDECURSOR )
3607 , m_aCellEdit(VclPtr<svt::EditControl>::Create(&GetDataWindow()))
3608 , m_aCellCheckBox(VclPtr<svt::CheckBoxControl>::Create(&GetDataWindow()))
3609 , m_nCurrentRow(0)
3610 , m_bModified(false)
3612 OUString sSearch = SwResId(STR_AUTOMARK_SEARCHTERM);
3613 OUString sAlternative = SwResId(STR_AUTOMARK_ALTERNATIVE);
3614 OUString sPrimKey = SwResId(STR_AUTOMARK_KEY1);
3615 OUString sSecKey = SwResId(STR_AUTOMARK_KEY2);
3616 OUString sComment = SwResId(STR_AUTOMARK_COMMENT);
3617 OUString sCaseSensitive = SwResId(STR_AUTOMARK_CASESENSITIVE);
3618 OUString sWordOnly = SwResId(STR_AUTOMARK_WORDONLY);
3619 m_sYes = SwResId(STR_AUTOMARK_YES);
3620 m_sNo = SwResId(STR_AUTOMARK_NO);
3622 m_aCellCheckBox->EnableTriState(false);
3623 m_xController = new ::svt::EditCellController(m_aCellEdit.get());
3624 m_xCheckController = new ::svt::CheckBoxCellController(m_aCellCheckBox.get());
3626 // HACK: BrowseBox doesn't invalidate its children, how it should be.
3627 // That's why WB_CLIPCHILDREN is reset in order to enforce the
3628 // children' invalidation
3629 WinBits aStyle = GetStyle();
3630 if( aStyle & WB_CLIPCHILDREN )
3632 aStyle &= ~WB_CLIPCHILDREN;
3633 SetStyle( aStyle );
3636 const OUString* aTitles[7] =
3638 &sSearch,
3639 &sAlternative,
3640 &sPrimKey,
3641 &sSecKey,
3642 &sComment,
3643 &sCaseSensitive,
3644 &sWordOnly
3647 tools::Long nWidth = GetSizePixel().Width();
3648 nWidth /=7;
3649 --nWidth;
3650 for(sal_uInt16 i = 1; i < 8; i++)
3651 InsertDataColumn( i, *aTitles[i - 1], nWidth );
3654 SwEntryBrowseBox::~SwEntryBrowseBox()
3656 disposeOnce();
3659 void SwEntryBrowseBox::dispose()
3661 m_aCellEdit.disposeAndClear();
3662 m_aCellCheckBox.disposeAndClear();
3663 SwEntryBrowseBox_Base::dispose();
3666 void SwEntryBrowseBox::Resize()
3668 SwEntryBrowseBox_Base::Resize();
3670 tools::Long nWidth = GetSizePixel().Width();
3671 std::vector<tools::Long> aWidths = GetOptimalColWidths();
3672 tools::Long nNaturalWidth(std::accumulate(aWidths.begin(), aWidths.end(), 0));
3673 tools::Long nExcess = ((nWidth - nNaturalWidth) / aWidths.size()) - 1;
3675 for (size_t i = 0; i < aWidths.size(); ++i)
3676 SetColumnWidth(i+1, aWidths[i] + nExcess);
3679 std::vector<tools::Long> SwEntryBrowseBox::GetOptimalColWidths() const
3681 std::vector<tools::Long> aWidths;
3683 tools::Long nStandardColMinWidth = approximate_digit_width() * 15;
3684 tools::Long nYesNoWidth = approximate_digit_width() * 5;
3685 nYesNoWidth = std::max(nYesNoWidth, GetTextWidth(m_sYes));
3686 nYesNoWidth = std::max(nYesNoWidth, GetTextWidth(m_sNo));
3687 for (sal_uInt16 i = 1; i < 6; i++)
3689 tools::Long nColWidth = std::max(nStandardColMinWidth,
3690 GetTextWidth(GetColumnTitle(i)));
3691 nColWidth += 12;
3692 aWidths.push_back(nColWidth);
3695 for (sal_uInt16 i = 6; i < 8; i++)
3697 tools::Long nColWidth = std::max(nYesNoWidth,
3698 GetTextWidth(GetColumnTitle(i)));
3699 nColWidth += 12;
3700 aWidths.push_back(nColWidth);
3703 return aWidths;
3706 Size SwEntryBrowseBox::GetOptimalSize() const
3708 Size aSize = LogicToPixel(Size(276 , 175), MapMode(MapUnit::MapAppFont));
3710 std::vector<tools::Long> aWidths = GetOptimalColWidths();
3712 tools::Long nWidth(std::accumulate(aWidths.begin(), aWidths.end(), 0));
3714 aSize.setWidth( std::max(aSize.Width(), nWidth) );
3716 return aSize;
3719 bool SwEntryBrowseBox::SeekRow( sal_Int32 nRow )
3721 m_nCurrentRow = nRow;
3722 return true;
3725 OUString SwEntryBrowseBox::GetCellText(sal_Int32 nRow, sal_uInt16 nColumn) const
3727 OUString pRet;
3728 if (o3tl::make_unsigned(nRow) < m_Entries.size())
3730 const AutoMarkEntry* pEntry = m_Entries[ nRow ].get();
3731 switch(nColumn)
3733 case ITEM_SEARCH : pRet = pEntry->sSearch; break;
3734 case ITEM_ALTERNATIVE : pRet = pEntry->sAlternative; break;
3735 case ITEM_PRIM_KEY : pRet = pEntry->sPrimKey; break;
3736 case ITEM_SEC_KEY : pRet = pEntry->sSecKey; break;
3737 case ITEM_COMMENT : pRet = pEntry->sComment; break;
3738 case ITEM_CASE : pRet = pEntry->bCase ? m_sYes : m_sNo; break;
3739 case ITEM_WORDONLY : pRet = pEntry->bWord ? m_sYes : m_sNo; break;
3742 return pRet;
3745 void SwEntryBrowseBox::PaintCell(OutputDevice& rDev,
3746 const tools::Rectangle& rRect, sal_uInt16 nColumnId) const
3748 const DrawTextFlags nStyle = DrawTextFlags::Clip | DrawTextFlags::Center;
3749 rDev.DrawText( rRect, GetCellText( m_nCurrentRow, nColumnId ), nStyle );
3752 ::svt::CellController* SwEntryBrowseBox::GetController(sal_Int32 /*nRow*/, sal_uInt16 nCol)
3754 return nCol < ITEM_CASE ? m_xController.get() : m_xCheckController.get();
3757 bool SwEntryBrowseBox::SaveModified()
3759 m_bModified = true;
3760 const size_t nRow = GetCurRow();
3761 const sal_uInt16 nCol = GetCurColumnId();
3763 OUString sNew;
3764 bool bVal = false;
3765 ::svt::CellController* pController = nullptr;
3766 if(nCol < ITEM_CASE)
3768 pController = m_xController.get();
3769 sNew = static_cast< ::svt::EditCellController*>(pController)->GetEditImplementation()->GetText( LINEEND_LF );
3771 else
3773 pController = m_xCheckController.get();
3774 bVal = static_cast< ::svt::CheckBoxCellController*>(pController)->GetCheckBox().get_active();
3776 const bool bAddEntry = nRow >= m_Entries.size();
3777 std::unique_ptr<AutoMarkEntry> xNewEntry(bAddEntry ? new AutoMarkEntry : nullptr);
3778 AutoMarkEntry* pEntry = bAddEntry ? xNewEntry.get() : m_Entries[nRow].get();
3779 switch(nCol)
3781 case ITEM_SEARCH : pEntry->sSearch = sNew; break;
3782 case ITEM_ALTERNATIVE : pEntry->sAlternative = sNew; break;
3783 case ITEM_PRIM_KEY : pEntry->sPrimKey = sNew; break;
3784 case ITEM_SEC_KEY : pEntry->sSecKey = sNew; break;
3785 case ITEM_COMMENT : pEntry->sComment = sNew; break;
3786 case ITEM_CASE : pEntry->bCase = bVal; break;
3787 case ITEM_WORDONLY : pEntry->bWord = bVal; break;
3789 if (bAddEntry)
3791 m_Entries.push_back(std::move(xNewEntry));
3792 RowInserted(nRow, 1, true, true);
3793 if(nCol < ITEM_WORDONLY)
3795 pController->SaveValue();
3796 GoToRow( nRow );
3799 return true;
3802 void SwEntryBrowseBox::InitController(
3803 ::svt::CellControllerRef& rController, sal_Int32 nRow, sal_uInt16 nCol)
3805 const OUString rText = GetCellText( nRow, nCol );
3806 if(nCol < ITEM_CASE)
3808 rController = m_xController;
3809 ::svt::CellController* pController = m_xController.get();
3810 static_cast< ::svt::EditCellController*>(pController)->GetEditImplementation()->SetText( rText );
3812 else
3814 rController = m_xCheckController;
3815 ::svt::CellController* pController = m_xCheckController.get();
3816 static_cast< ::svt::CheckBoxCellController*>(pController)->GetCheckBox().set_active(
3817 rText == m_sYes );
3821 void SwEntryBrowseBox::ReadEntries(SvStream& rInStr)
3823 AutoMarkEntry* pToInsert = nullptr;
3824 // tdf#108910, tdf#125496 - read index entries using the appropriate character set
3825 rtl_TextEncoding eTEnc = SwIoSystem::GetTextEncoding(rInStr);
3826 if (eTEnc == RTL_TEXTENCODING_DONTKNOW)
3827 eTEnc = osl_getThreadTextEncoding();
3828 while (rInStr.good())
3830 OUString sLine;
3831 rInStr.ReadByteStringLine( sLine, eTEnc );
3833 // # -> comment
3834 // ; -> delimiter between entries ->
3835 // Format: TextToSearchFor;AlternativeString;PrimaryKey;SecondaryKey
3836 // Leading and trailing blanks are ignored
3837 if( !sLine.isEmpty() )
3839 //comments are contained in separate lines but are put into the struct of the following data
3840 //line (if available)
3841 if( '#' != sLine[0] )
3843 if( !pToInsert )
3844 pToInsert = new AutoMarkEntry;
3846 sal_Int32 nSttPos = 0;
3847 pToInsert->sSearch = sLine.getToken(0, ';', nSttPos );
3848 pToInsert->sAlternative = sLine.getToken(0, ';', nSttPos );
3849 pToInsert->sPrimKey = sLine.getToken(0, ';', nSttPos );
3850 pToInsert->sSecKey = sLine.getToken(0, ';', nSttPos );
3852 OUString sStr = sLine.getToken(0, ';', nSttPos );
3853 pToInsert->bCase = !sStr.isEmpty() && sStr != "0";
3855 sStr = sLine.getToken(0, ';', nSttPos );
3856 pToInsert->bWord = !sStr.isEmpty() && sStr != "0";
3858 m_Entries.push_back(std::unique_ptr<AutoMarkEntry>(pToInsert));
3859 pToInsert = nullptr;
3861 else
3863 if(pToInsert)
3864 m_Entries.push_back(std::unique_ptr<AutoMarkEntry>(pToInsert));
3865 pToInsert = new AutoMarkEntry;
3866 pToInsert->sComment = sLine.copy(1);
3870 if( pToInsert )
3871 m_Entries.push_back(std::unique_ptr<AutoMarkEntry>(pToInsert));
3872 RowInserted(0, m_Entries.size() + 1);
3875 void SwEntryBrowseBox::WriteEntries(SvStream& rOutStr)
3877 //check if the current controller is modified
3878 const sal_uInt16 nCol = GetCurColumnId();
3879 ::svt::CellController* pController;
3880 if(nCol < ITEM_CASE)
3881 pController = m_xController.get();
3882 else
3883 pController = m_xCheckController.get();
3884 if (pController->IsValueChangedFromSaved())
3885 GoToColumnId(nCol + (nCol < ITEM_CASE ? 1 : -1 ));
3887 for(const std::unique_ptr<AutoMarkEntry> & rpEntry : m_Entries)
3889 AutoMarkEntry* pEntry = rpEntry.get();
3890 if(!pEntry->sComment.isEmpty())
3892 // tdf#108910, tdf#125496 - write index entries using the utf8 text encoding
3893 rOutStr.WriteByteStringLine( OUStringConcatenation("#" + pEntry->sComment), RTL_TEXTENCODING_UTF8 );
3896 OUString sWrite( pEntry->sSearch + ";" +
3897 pEntry->sAlternative + ";" +
3898 pEntry->sPrimKey + ";" +
3899 pEntry->sSecKey + ";" +
3900 (pEntry->bCase ? std::u16string_view(u"1") : std::u16string_view(u"0")) +
3901 ";" +
3902 (pEntry->bWord ? std::u16string_view(u"1") : std::u16string_view(u"0")) );
3904 if( sWrite.getLength() > 5 )
3905 // tdf#108910, tdf#125496 - write index entries using the utf8 text encoding
3906 rOutStr.WriteByteStringLine( sWrite, RTL_TEXTENCODING_UTF8 );
3910 bool SwEntryBrowseBox::IsModified()const
3912 if(m_bModified)
3913 return true;
3915 //check if the current controller is modified
3916 const sal_uInt16 nCol = GetCurColumnId();
3917 ::svt::CellController* pController;
3918 if(nCol < ITEM_CASE)
3919 pController = m_xController.get();
3920 else
3921 pController = m_xCheckController.get();
3922 return pController->IsValueChangedFromSaved();
3925 SwAutoMarkDlg_Impl::SwAutoMarkDlg_Impl(weld::Window* pParent, const OUString& rAutoMarkURL,
3926 bool bCreate)
3927 : GenericDialogController(pParent, "modules/swriter/ui/createautomarkdialog.ui", "CreateAutomarkDialog")
3928 , sAutoMarkURL(rAutoMarkURL)
3929 , bCreateMode(bCreate)
3930 , m_xOKPB(m_xBuilder->weld_button("ok"))
3931 , m_xTable(m_xBuilder->weld_container("area"))
3932 , m_xTableCtrlParent(m_xTable->CreateChildFrame())
3933 , m_xEntriesBB(VclPtr<SwEntryBrowseBox>::Create(m_xTableCtrlParent))
3935 m_xEntriesBB->Show();
3936 m_xOKPB->connect_clicked(LINK(this, SwAutoMarkDlg_Impl, OkHdl));
3938 m_xDialog->set_title(m_xDialog->get_title() + ": " + sAutoMarkURL);
3939 bool bError = false;
3940 if( bCreateMode )
3941 m_xEntriesBB->RowInserted(0);
3942 else
3944 SfxMedium aMed( sAutoMarkURL, StreamMode::STD_READ );
3945 if( aMed.GetInStream() && !aMed.GetInStream()->GetError() )
3946 m_xEntriesBB->ReadEntries( *aMed.GetInStream() );
3947 else
3948 bError = true;
3951 Size aPrefSize = m_xEntriesBB->GetOptimalSize();
3952 m_xTable->set_size_request(aPrefSize.Width(), aPrefSize.Height());
3954 if (bError)
3955 m_xDialog->response(RET_CANCEL);
3958 SwAutoMarkDlg_Impl::~SwAutoMarkDlg_Impl()
3960 m_xEntriesBB.disposeAndClear();
3961 m_xTableCtrlParent->dispose();
3962 m_xTableCtrlParent.clear();
3965 IMPL_LINK_NOARG(SwAutoMarkDlg_Impl, OkHdl, weld::Button&, void)
3967 bool bError = false;
3968 if (m_xEntriesBB->IsModified() || bCreateMode)
3970 SfxMedium aMed( sAutoMarkURL,
3971 bCreateMode ? StreamMode::WRITE
3972 : StreamMode::WRITE| StreamMode::TRUNC );
3973 SvStream* pStrm = aMed.GetOutStream();
3974 // tdf#108910, tdf#125496 - write index entries using the utf8 text encoding
3975 pStrm->SetStreamCharSet( RTL_TEXTENCODING_UTF8 );
3976 if( !pStrm->GetError() )
3978 m_xEntriesBB->WriteEntries( *pStrm );
3979 aMed.Commit();
3981 else
3982 bError = true;
3984 if (!bError)
3985 m_xDialog->response(RET_OK);
3988 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */