1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20 #include <config_folders.h>
21
22 #include <sal/log.hxx>
23 #include <svl/style.hxx>
24 #include <vcl/help.hxx>
25 #include <vcl/weld.hxx>
26 #include <svl/stritem.hxx>
27 #include <svl/urihelper.hxx>
28 #include <unotools/pathoptions.hxx>
29 #include <sfx2/request.hxx>
30 #include <sfx2/viewfrm.hxx>
31 #include <sfx2/dispatch.hxx>
32 #include <sfx2/docfile.hxx>
33 #include <svx/dialogs.hrc>
34 #include <svx/svxdlg.hxx>
35 #include <svx/flagsdef.hxx>
36 #include <svx/svxids.hrc>
37 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
38 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
39 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
40 #include <svtools/indexentryres.hxx>
41 #include <toolkit/helper/vclunohelper.hxx>
42 #include <editeng/unolingu.hxx>
43 #include <column.hxx>
44 #include <fmtfsize.hxx>
45 #include <shellio.hxx>
46 #include <authfld.hxx>
47 #include <swtypes.hxx>
48 #include <wrtsh.hxx>
49 #include <view.hxx>
50 #include <basesh.hxx>
51 #include <outline.hxx>
52 #include <cnttab.hxx>
53 #include <swuicnttab.hxx>
54 #include <poolfmt.hxx>
55 #include <strings.hrc>
56 #include <uitool.hxx>
57 #include <fmtcol.hxx>
58 #include <fldbas.hxx>
59 #include <expfld.hxx>
60 #include <unotools.hxx>
61 #include <unotxdoc.hxx>
62 #include <docsh.hxx>
63 #include <swmodule.hxx>
64 #include <modcfg.hxx>
65
66 #include <cmdid.h>
67 #include <globals.hrc>
68 #include <cnttab.hrc>
69 #include <SwStyleNameMapper.hxx>
70 #include <sfx2/filedlghelper.hxx>
71 #include <toxwrap.hxx>
72 #include <chpfld.hxx>
73
74 #include <sfx2/app.hxx>
75
76 #include <unomid.h>
77
78 #include <cmath>
79 #include <memory>
80 #include <vector>
81 #include <numeric>
82
83
84 using namespace ::com::sun::star;
85 using namespace ::com::sun::star::lang;
86 using namespace ::com::sun::star::uno;
87 using namespace com::sun::star::ui::dialogs;
88 using namespace ::sfx2;
89 #include <svtools/editbrowsebox.hxx>
90
91 static const sal_Unicode aDeliStart = '['; // for the form
92 static const sal_Unicode aDeliEnd = ']'; // for the form
93
lcl_CreateAutoMarkFileDlg(weld::Window * pParent,const OUString & rURL,const OUString & rFileString,bool bOpen)94 static OUString lcl_CreateAutoMarkFileDlg(weld::Window* pParent, const OUString& rURL,
95 const OUString& rFileString, bool bOpen)
96 {
97 OUString sRet;
98
99 FileDialogHelper aDlgHelper( bOpen ?
100 TemplateDescription::FILEOPEN_SIMPLE : TemplateDescription::FILESAVE_AUTOEXTENSION,
101 FileDialogFlags::NONE, pParent);
102 uno::Reference < XFilePicker3 > xFP = aDlgHelper.GetFilePicker();
103
104 xFP->appendFilter( rFileString, "*.sdi" );
105 xFP->setCurrentFilter( rFileString ) ;
106
107 if( !rURL.isEmpty() )
108 xFP->setDisplayDirectory( rURL );
109 else
110 {
111 SvtPathOptions aPathOpt;
112 xFP->setDisplayDirectory( aPathOpt.GetUserConfigPath() );
113 }
114
115 if( aDlgHelper.Execute() == ERRCODE_NONE )
116 {
117 sRet = xFP->getSelectedFiles().getConstArray()[0];
118 }
119
120 return sRet;
121 }
122
123 struct AutoMarkEntry
124 {
125 OUString sSearch;
126 OUString sAlternative;
127 OUString sPrimKey;
128 OUString sSecKey;
129 OUString sComment;
130 bool bCase;
131 bool bWord;
132
AutoMarkEntryAutoMarkEntry133 AutoMarkEntry() :
134 bCase(false),
135 bWord(false){}
136 };
137
138 typedef ::svt::EditBrowseBox SwEntryBrowseBox_Base;
139
140 class SwEntryBrowseBox : public SwEntryBrowseBox_Base
141 {
142 VclPtr<Edit> m_aCellEdit;
143 VclPtr< ::svt::CheckBoxControl> m_aCellCheckBox;
144
145 OUString m_sSearch;
146 OUString m_sAlternative;
147 OUString m_sPrimKey;
148 OUString m_sSecKey;
149 OUString m_sComment;
150 OUString m_sCaseSensitive;
151 OUString m_sWordOnly;
152 OUString m_sYes;
153 OUString m_sNo;
154
155 std::vector<std::unique_ptr<AutoMarkEntry>> m_Entries;
156
157 ::svt::CellControllerRef m_xController;
158 ::svt::CellControllerRef m_xCheckController;
159
160 long m_nCurrentRow;
161 bool m_bModified;
162
163 protected:
164 virtual bool SeekRow( long nRow ) override;
165 virtual void PaintCell(OutputDevice& rDev, const tools::Rectangle& rRect, sal_uInt16 nColId) const override;
166 virtual void InitController(::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol) override;
167 virtual ::svt::CellController* GetController(long nRow, sal_uInt16 nCol) override;
168 virtual bool SaveModified() override;
169
170 std::vector<long> GetOptimalColWidths() const;
171
172 public:
173 SwEntryBrowseBox(const css::uno::Reference<css::awt::XWindow> &rParent);
174 virtual ~SwEntryBrowseBox() override;
175 virtual void dispose() override;
176 void ReadEntries(SvStream& rInStr);
177 void WriteEntries(SvStream& rOutStr);
178
179 bool IsModified()const override;
180
181 virtual OUString GetCellText( long nRow, sal_uInt16 nColumn ) const override;
182 virtual void Resize() override;
183 virtual Size GetOptimalSize() const override;
184 };
185
186 class SwAutoMarkDlg_Impl : public weld::GenericDialogController
187 {
188 OUString sAutoMarkURL;
189 bool bCreateMode;
190
191 std::unique_ptr<weld::Button> m_xOKPB;
192 std::unique_ptr<weld::Container> m_xTable;
193 css::uno::Reference<css::awt::XWindow> m_xTableCtrlParent;
194 VclPtr<SwEntryBrowseBox> m_xEntriesBB;
195
196 DECL_LINK(OkHdl, weld::Button&, void);
197 public:
198 SwAutoMarkDlg_Impl(weld::Window* pParent, const OUString& rAutoMarkURL,
199 bool bCreate);
200 virtual ~SwAutoMarkDlg_Impl() override;
201 };
202
GetFlatIndex() const203 sal_uInt16 CurTOXType::GetFlatIndex() const
204 {
205 return static_cast< sal_uInt16 >( (eType == TOX_USER && nIndex)
206 ? TOX_AUTHORITIES + nIndex : eType );
207 }
208
SwMultiTOXTabDialog(weld::Window * pParent,const SfxItemSet & rSet,SwWrtShell & rShell,SwTOXBase * pCurTOX,sal_uInt16 nToxType,bool bGlobal)209 SwMultiTOXTabDialog::SwMultiTOXTabDialog(weld::Window* pParent, const SfxItemSet& rSet,
210 SwWrtShell &rShell, SwTOXBase* pCurTOX,
211 sal_uInt16 nToxType, bool bGlobal)
212 : SfxTabDialogController(pParent, "modules/swriter/ui/tocdialog.ui", "TocDialog", &rSet)
213 , m_pMgr( new SwTOXMgr( &rShell ) )
214 , m_rWrtShell(rShell)
215 , m_pParamTOXBase(pCurTOX)
216 , m_sUserDefinedIndex(SwResId(STR_USER_DEFINED_INDEX))
217 , m_nInitialTOXType(nToxType)
218 , m_bEditTOX(false)
219 , m_bExampleCreated(false)
220 , m_bGlobalFlag(bGlobal)
221 , m_xShowExampleCB(m_xBuilder->weld_check_button("showexample"))
222 {
223 m_eCurrentTOXType.eType = TOX_CONTENT;
224 m_eCurrentTOXType.nIndex = 0;
225
226 const sal_uInt16 nUserTypeCount = m_rWrtShell.GetTOXTypeCount(TOX_USER);
227 m_vTypeData.resize(nUserTypeCount + 6);
228 //the standard user index is on position TOX_USER
229 //all user indexes follow after position TOX_AUTHORITIES
230 if(pCurTOX)
231 {
232 m_bEditTOX = true;
233 }
234 for(int i = m_vTypeData.size() - 1; i > -1; i--)
235 {
236 m_vTypeData[i].m_pxIndexSections.reset(new SwIndexSections_Impl);
237 if(pCurTOX)
238 {
239 m_eCurrentTOXType.eType = pCurTOX->GetType();
240 sal_uInt16 nArrayIndex = static_cast< sal_uInt16 >(m_eCurrentTOXType.eType);
241 if(m_eCurrentTOXType.eType == TOX_USER)
242 {
243 //which user type is it?
244 for(sal_uInt16 nUser = 0; nUser < nUserTypeCount; nUser++)
245 {
246 const SwTOXType* pTemp = m_rWrtShell.GetTOXType(TOX_USER, nUser);
247 if(pCurTOX->GetTOXType() == pTemp)
248 {
249 m_eCurrentTOXType.nIndex = nUser;
250 nArrayIndex = static_cast< sal_uInt16 >(nUser > 0 ? TOX_AUTHORITIES + nUser : TOX_USER);
251 break;
252 }
253 }
254 }
255 m_vTypeData[nArrayIndex].m_pForm.reset(new SwForm(pCurTOX->GetTOXForm()));
256 m_vTypeData[nArrayIndex].m_pDescription = CreateTOXDescFromTOXBase(pCurTOX);
257 if(TOX_AUTHORITIES == m_eCurrentTOXType.eType)
258 {
259 const SwAuthorityFieldType* pFType = static_cast<const SwAuthorityFieldType*>(
260 m_rWrtShell.GetFieldType(SwFieldIds::TableOfAuthorities, OUString()));
261 if(pFType)
262 {
263 OUString sBrackets;
264 if(pFType->GetPrefix())
265 sBrackets += OUStringChar(pFType->GetPrefix());
266 if(pFType->GetSuffix())
267 sBrackets += OUStringChar(pFType->GetSuffix());
268 m_vTypeData[nArrayIndex].m_pDescription->SetAuthBrackets(sBrackets);
269 m_vTypeData[nArrayIndex].m_pDescription->SetAuthSequence(pFType->IsSequence());
270 }
271 else
272 {
273 m_vTypeData[nArrayIndex].m_pDescription->SetAuthBrackets("[]");
274 }
275 }
276 }
277 }
278 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
279 AddTabPage("index", SwTOXSelectTabPage::Create, nullptr);
280 AddTabPage("styles", SwTOXStylesTabPage::Create, nullptr);
281 AddTabPage("columns", SwColumnPage::Create, nullptr);
282 AddTabPage("background", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_BKG), nullptr);
283 AddTabPage("entries", SwTOXEntryTabPage::Create, nullptr);
284 if (!pCurTOX)
285 SetCurPageId("index");
286
287 m_xShowExampleCB->connect_toggled(LINK(this, SwMultiTOXTabDialog, ShowPreviewHdl));
288 m_xShowExampleCB->set_active(SW_MOD()->GetModuleConfig()->IsShowIndexPreview());
289
290 ShowPreviewHdl(*m_xShowExampleCB);
291 }
292
~SwMultiTOXTabDialog()293 SwMultiTOXTabDialog::~SwMultiTOXTabDialog()
294 {
295 SW_MOD()->GetModuleConfig()->SetShowIndexPreview(m_xShowExampleCB->get_active());
296 }
297
PageCreated(const OString & rId,SfxTabPage & rPage)298 void SwMultiTOXTabDialog::PageCreated(const OString& rId, SfxTabPage &rPage)
299 {
300 if (rId == "background")
301 {
302 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
303 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, static_cast<sal_uInt32>(SvxBackgroundTabFlags::SHOW_SELECTOR)));
304 rPage.PageCreated(aSet);
305 }
306 else if (rId == "columns")
307 {
308 const SwFormatFrameSize& rSize = GetInputSetImpl()->Get(RES_FRM_SIZE);
309
310 static_cast<SwColumnPage&>(rPage).SetPageWidth(rSize.GetWidth());
311 }
312 else if (rId == "entries")
313 static_cast<SwTOXEntryTabPage&>(rPage).SetWrtShell(m_rWrtShell);
314 else if (rId == "index")
315 {
316 static_cast<SwTOXSelectTabPage&>(rPage).SetWrtShell(m_rWrtShell);
317 if(USHRT_MAX != m_nInitialTOXType)
318 static_cast<SwTOXSelectTabPage&>(rPage).SelectType(static_cast<TOXTypes>(m_nInitialTOXType));
319 }
320 }
321
Ok()322 short SwMultiTOXTabDialog::Ok()
323 {
324 short nRet = SfxTabDialogController::Ok();
325 SwTOXDescription& rDesc = GetTOXDescription(m_eCurrentTOXType);
326 SwTOXBase aNewDef(*m_rWrtShell.GetDefaultTOXBase( m_eCurrentTOXType.eType, true ));
327
328 const sal_uInt16 nIndex = m_eCurrentTOXType.GetFlatIndex();
329 if(m_vTypeData[nIndex].m_pForm)
330 {
331 rDesc.SetForm(*m_vTypeData[nIndex].m_pForm);
332 aNewDef.SetTOXForm(*m_vTypeData[nIndex].m_pForm);
333 }
334 rDesc.ApplyTo(aNewDef);
335 if(!m_bGlobalFlag)
336 m_pMgr->UpdateOrInsertTOX(
337 rDesc, nullptr, GetOutputItemSet());
338 else if(m_bEditTOX)
339 m_pMgr->UpdateOrInsertTOX(
340 rDesc, &m_pParamTOXBase, GetOutputItemSet());
341
342 if(!m_eCurrentTOXType.nIndex)
343 m_rWrtShell.SetDefaultTOXBase(aNewDef);
344
345 return nRet;
346 }
347
GetForm(CurTOXType eType)348 SwForm* SwMultiTOXTabDialog::GetForm(CurTOXType eType)
349 {
350 const sal_uInt16 nIndex = eType.GetFlatIndex();
351 if(!m_vTypeData[nIndex].m_pForm)
352 m_vTypeData[nIndex].m_pForm.reset(new SwForm(eType.eType));
353 return m_vTypeData[nIndex].m_pForm.get();
354 }
355
GetTOXDescription(CurTOXType eType)356 SwTOXDescription& SwMultiTOXTabDialog::GetTOXDescription(CurTOXType eType)
357 {
358 const sal_uInt16 nIndex = eType.GetFlatIndex();
359 if(!m_vTypeData[nIndex].m_pDescription)
360 {
361 const SwTOXBase* pDef = m_rWrtShell.GetDefaultTOXBase( eType.eType );
362 if(pDef)
363 m_vTypeData[nIndex].m_pDescription = CreateTOXDescFromTOXBase(pDef);
364 else
365 {
366 m_vTypeData[nIndex].m_pDescription.reset(new SwTOXDescription(eType.eType));
367 if(eType.eType == TOX_USER)
368 m_vTypeData[nIndex].m_pDescription->SetTitle(m_sUserDefinedIndex);
369 else
370 m_vTypeData[nIndex].m_pDescription->SetTitle(
371 m_rWrtShell.GetTOXType(eType.eType, 0)->GetTypeName());
372 }
373 if(TOX_AUTHORITIES == eType.eType)
374 {
375 const SwAuthorityFieldType* pFType = static_cast<const SwAuthorityFieldType*>(
376 m_rWrtShell.GetFieldType(SwFieldIds::TableOfAuthorities, OUString()));
377 if(pFType)
378 {
379 m_vTypeData[nIndex].m_pDescription->SetAuthBrackets(OUStringChar(pFType->GetPrefix()) +
380 OUStringChar(pFType->GetSuffix()));
381 m_vTypeData[nIndex].m_pDescription->SetAuthSequence(pFType->IsSequence());
382 }
383 else
384 {
385 m_vTypeData[nIndex].m_pDescription->SetAuthBrackets("[]");
386 }
387 }
388 else if(TOX_INDEX == eType.eType)
389 m_vTypeData[nIndex].m_pDescription->SetMainEntryCharStyle(SwResId(STR_POOLCHR_IDX_MAIN_ENTRY));
390
391 }
392 return *m_vTypeData[nIndex].m_pDescription;
393 }
394
CreateTOXDescFromTOXBase(const SwTOXBase * pCurTOX)395 std::unique_ptr<SwTOXDescription> SwMultiTOXTabDialog::CreateTOXDescFromTOXBase(
396 const SwTOXBase*pCurTOX)
397 {
398 std::unique_ptr<SwTOXDescription> pDesc(new SwTOXDescription(pCurTOX->GetType()));
399 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
400 pDesc->SetStyleNames(pCurTOX->GetStyleNames(i), i);
401 pDesc->SetAutoMarkURL(m_rWrtShell.GetTOIAutoMarkURL());
402 pDesc->SetTitle(pCurTOX->GetTitle());
403
404 pDesc->SetContentOptions(pCurTOX->GetCreateType());
405 if(pDesc->GetTOXType() == TOX_INDEX)
406 pDesc->SetIndexOptions(pCurTOX->GetOptions());
407 pDesc->SetMainEntryCharStyle(pCurTOX->GetMainEntryCharStyle());
408 if(pDesc->GetTOXType() != TOX_INDEX)
409 pDesc->SetLevel(static_cast<sal_uInt8>(pCurTOX->GetLevel()));
410 pDesc->SetCreateFromObjectNames(pCurTOX->IsFromObjectNames());
411 pDesc->SetSequenceName(pCurTOX->GetSequenceName());
412 pDesc->SetCaptionDisplay(pCurTOX->GetCaptionDisplay());
413 pDesc->SetFromChapter(pCurTOX->IsFromChapter());
414 pDesc->SetReadonly(pCurTOX->IsProtected());
415 pDesc->SetOLEOptions(pCurTOX->GetOLEOptions());
416 pDesc->SetLevelFromChapter(pCurTOX->IsLevelFromChapter());
417 pDesc->SetLanguage(pCurTOX->GetLanguage());
418 pDesc->SetSortAlgorithm(pCurTOX->GetSortAlgorithm());
419 return pDesc;
420 }
421
IMPL_LINK_NOARG(SwMultiTOXTabDialog,ShowPreviewHdl,weld::ToggleButton &,void)422 IMPL_LINK_NOARG(SwMultiTOXTabDialog, ShowPreviewHdl, weld::ToggleButton&, void)
423 {
424 if (m_xShowExampleCB->get_active())
425 {
426 if(!m_xExampleFrame && !m_bExampleCreated)
427 {
428 m_bExampleCreated = true;
429 OUString sTemplate("internal/idxexample.odt");
430
431 SvtPathOptions aOpt;
432 bool bExist = aOpt.SearchFile( sTemplate, SvtPathOptions::PATH_TEMPLATE );
433
434 if(!bExist)
435 {
436 OUString sInfo(SwResId(STR_FILE_NOT_FOUND));
437 sInfo = sInfo.replaceFirst( "%1", sTemplate );
438 sInfo = sInfo.replaceFirst( "%2", aOpt.GetTemplatePath() );
439 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(m_xDialog.get(),
440 VclMessageType::Info, VclButtonsType::Ok,
441 sInfo));
442 xInfoBox->run();
443 }
444 else
445 {
446 Link<SwOneExampleFrame&,void> aLink(LINK(this, SwMultiTOXTabDialog, CreateExample_Hdl));
447 m_xExampleFrame.reset(new SwOneExampleFrame(EX_SHOW_ONLINE_LAYOUT | EX_LOCALIZE_TOC_STRINGS, &aLink, &sTemplate));
448 m_xExampleFrameWin.reset(new weld::CustomWeld(*m_xBuilder, "example", *m_xExampleFrame));
449 }
450 m_xShowExampleCB->set_visible(m_xExampleFrame != nullptr);
451 }
452 }
453
454 if (m_xExampleFrame)
455 {
456 const bool bSetViewWindow = m_xShowExampleCB->get_active();
457 if (bSetViewWindow)
458 m_xExampleFrame->Show();
459 else
460 m_xExampleFrame->Hide();
461 }
462
463 m_xDialog->resize_to_request();
464 }
465
IsNoNum(SwWrtShell & rSh,const OUString & rName)466 bool SwMultiTOXTabDialog::IsNoNum(SwWrtShell& rSh, const OUString& rName)
467 {
468 SwTextFormatColl* pColl = rSh.GetParaStyle(rName);
469 if(pColl && ! pColl->IsAssignedToListLevelOfOutlineStyle())
470 return true;
471
472 const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(
473 rName, SwGetPoolIdFromName::TxtColl);
474 return nId != USHRT_MAX &&
475 ! rSh.GetTextCollFromPool(nId)->IsAssignedToListLevelOfOutlineStyle();
476 }
477
478 class SwAddStylesDlg_Impl : public SfxDialogController
479 {
480 OUString* pStyleArr;
481
482 std::unique_ptr<weld::Button> m_xOk;
483 std::unique_ptr<weld::Button> m_xLeftPB;
484 std::unique_ptr<weld::Button> m_xRightPB;
485 std::unique_ptr<weld::TreeView> m_xHeaderTree;
486
487 DECL_LINK(OkHdl, weld::Button&, void);
488 DECL_LINK(LeftRightHdl, weld::Button&, void);
489 DECL_LINK(KeyInput, const KeyEvent&, bool);
490 DECL_LINK(TreeSizeAllocHdl, const Size&, void);
491 typedef std::pair<int, int> row_col;
492 DECL_LINK(RadioToggleOnHdl, const row_col&, void);
493
494 public:
495 SwAddStylesDlg_Impl(weld::Window* pParent, SwWrtShell const & rWrtSh, OUString rStringArr[]);
496 };
497
SwAddStylesDlg_Impl(weld::Window * pParent,SwWrtShell const & rWrtSh,OUString rStringArr[])498 SwAddStylesDlg_Impl::SwAddStylesDlg_Impl(weld::Window* pParent,
499 SwWrtShell const & rWrtSh, OUString rStringArr[])
500 : SfxDialogController(pParent, "modules/swriter/ui/assignstylesdialog.ui", "AssignStylesDialog")
501 , pStyleArr(rStringArr)
502 , m_xOk(m_xBuilder->weld_button("ok"))
503 , m_xLeftPB(m_xBuilder->weld_button("left"))
504 , m_xRightPB(m_xBuilder->weld_button("right"))
505 , m_xHeaderTree(m_xBuilder->weld_tree_view("styles"))
506 {
507 m_xOk->connect_clicked(LINK(this, SwAddStylesDlg_Impl, OkHdl));
508 m_xLeftPB->connect_clicked(LINK(this, SwAddStylesDlg_Impl, LeftRightHdl));
509 m_xRightPB->connect_clicked(LINK(this, SwAddStylesDlg_Impl, LeftRightHdl));
510 m_xHeaderTree->connect_size_allocate(LINK(this, SwAddStylesDlg_Impl, TreeSizeAllocHdl));
511
512 std::vector<int> aRadioColumns;
513 for (sal_uInt16 i = 0; i <= MAXLEVEL; ++i)
514 aRadioColumns.push_back(i + 1);
515 m_xHeaderTree->set_toggle_columns_as_radio(aRadioColumns);
516 m_xHeaderTree->connect_toggled(LINK(this, SwAddStylesDlg_Impl, RadioToggleOnHdl));
517
518 std::vector<int> aWidths;
519 aWidths.push_back(m_xHeaderTree->get_approximate_digit_width() * 30);
520 int nPadding = m_xHeaderTree->get_approximate_digit_width() * 2;
521 OUString sTitle(m_xHeaderTree->get_column_title(1));
522 for (sal_uInt16 i = 0; i <= MAXLEVEL; ++i)
523 {
524 sTitle = OUString::number(i);
525 m_xHeaderTree->set_column_title(i + 1, sTitle);
526 aWidths.push_back(m_xHeaderTree->get_pixel_size(sTitle).Width() + nPadding);
527 }
528 m_xHeaderTree->set_column_fixed_widths(aWidths);
529 auto nWidth = std::accumulate(aWidths.begin(), aWidths.end(), 0);
530 m_xHeaderTree->set_size_request(nWidth, m_xHeaderTree->get_height_rows(15));
531
532 int nRow(0);
533 for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
534 {
535 const OUString &rStyles{rStringArr[i]};
536 if (rStyles.isEmpty())
537 continue;
538 sal_Int32 nPos(0);
539 do
540 {
541 OUString sEntry = rStyles.getToken(0, TOX_STYLE_DELIMITER, nPos);
542 m_xHeaderTree->append_text(sEntry);
543 for (sal_uInt16 j = 0; j <= MAXLEVEL; ++j)
544 {
545 TriState eState = i == j - 1 ? TRISTATE_TRUE : TRISTATE_FALSE;
546 m_xHeaderTree->set_toggle(nRow, eState, j + 1);
547 }
548 ++nRow;
549 } while (nPos>=0);
550 }
551 // now the other styles
552
553 const sal_uInt16 nSz = rWrtSh.GetTextFormatCollCount();
554 for (sal_uInt16 j = 0; j < nSz; ++j)
555 {
556 const SwTextFormatColl& rColl = rWrtSh.GetTextFormatColl(j);
557 if (rColl.IsDefault())
558 continue;
559
560 const OUString aName = rColl.GetName();
561 if (!aName.isEmpty())
562 {
563 bool bEntry = false;
564 int nChildren = m_xHeaderTree->n_children();
565 for (int i = 0; i < nChildren; ++i)
566 {
567 if (m_xHeaderTree->get_text(i, 0) == aName)
568 {
569 bEntry = true;
570 break;
571 }
572 }
573 if (!bEntry)
574 {
575 m_xHeaderTree->append_text(aName);
576 for (sal_uInt16 k = 0; k <= MAXLEVEL; ++k)
577 {
578 TriState eState = k == 0 ? TRISTATE_TRUE : TRISTATE_FALSE;
579 m_xHeaderTree->set_toggle(nRow, eState, k + 1);
580 }
581 ++nRow;
582 }
583 }
584 }
585 m_xHeaderTree->make_sorted();
586 m_xHeaderTree->select(0);
587 m_xHeaderTree->connect_key_release(LINK(this, SwAddStylesDlg_Impl, KeyInput));
588 }
589
IMPL_LINK(SwAddStylesDlg_Impl,TreeSizeAllocHdl,const Size &,rSize,void)590 IMPL_LINK(SwAddStylesDlg_Impl, TreeSizeAllocHdl, const Size&, rSize, void)
591 {
592 auto nWidth = rSize.Width();
593
594 std::vector<int> aWidths;
595 aWidths.push_back(0);
596 int nPadding = m_xHeaderTree->get_approximate_digit_width() * 2;
597 for (sal_uInt16 i = 0; i <= MAXLEVEL; ++i)
598 {
599 OUString sTitle(m_xHeaderTree->get_column_title(i + 1));
600 aWidths.push_back(m_xHeaderTree->get_pixel_size(sTitle).Width() + nPadding);
601 }
602 auto nOtherWidth = std::accumulate(aWidths.begin(), aWidths.end(), 0);
603 aWidths[0] = nWidth - nOtherWidth;
604 m_xHeaderTree->set_column_fixed_widths(aWidths);
605 }
606
IMPL_LINK(SwAddStylesDlg_Impl,RadioToggleOnHdl,const row_col &,rRowCol,void)607 IMPL_LINK(SwAddStylesDlg_Impl, RadioToggleOnHdl, const row_col&, rRowCol, void)
608 {
609 for (sal_uInt16 i = 0; i <= MAXLEVEL; ++i)
610 {
611 TriState eState = rRowCol.second == i + 1 ? TRISTATE_TRUE : TRISTATE_FALSE;
612 m_xHeaderTree->set_toggle(rRowCol.first, eState, i + 1);
613 }
614 }
615
IMPL_LINK(SwAddStylesDlg_Impl,KeyInput,const KeyEvent &,rKEvt,bool)616 IMPL_LINK(SwAddStylesDlg_Impl, KeyInput, const KeyEvent&, rKEvt, bool)
617 {
618 vcl::KeyCode aCode = rKEvt.GetKeyCode();
619 bool bHandled = false;
620
621 if (aCode.GetCode() == KEY_ADD || aCode.GetCode() == KEY_RIGHT)
622 {
623 LeftRightHdl(*m_xRightPB);
624 bHandled = true;
625 }
626 else if (aCode.GetCode() == KEY_SUBTRACT || aCode.GetCode() == KEY_LEFT)
627 {
628 LeftRightHdl(*m_xLeftPB);
629 bHandled = true;
630 }
631
632 return bHandled;
633 }
634
IMPL_LINK_NOARG(SwAddStylesDlg_Impl,OkHdl,weld::Button &,void)635 IMPL_LINK_NOARG(SwAddStylesDlg_Impl, OkHdl, weld::Button&, void)
636 {
637 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
638 pStyleArr[i].clear();
639
640 int nChildren = m_xHeaderTree->n_children();
641 for (int i = 0; i < nChildren; ++i)
642 {
643 int nToggleColumn = 0;
644 for (sal_uInt16 j = 0; j <= MAXLEVEL; ++j)
645 {
646 if (m_xHeaderTree->get_toggle(i, j + 1) == TRISTATE_TRUE)
647 {
648 nToggleColumn = j;
649 break;
650 }
651 }
652 if (nToggleColumn)
653 {
654 int nLevel = nToggleColumn - 1;
655 if(!pStyleArr[nLevel].isEmpty())
656 pStyleArr[nLevel] += OUStringChar(TOX_STYLE_DELIMITER);
657 pStyleArr[nLevel] += m_xHeaderTree->get_text(i, 0);
658 }
659 }
660
661 //TODO write back style names
662 m_xDialog->response(RET_OK);
663 }
664
IMPL_LINK(SwAddStylesDlg_Impl,LeftRightHdl,weld::Button &,rBtn,void)665 IMPL_LINK(SwAddStylesDlg_Impl, LeftRightHdl, weld::Button&, rBtn, void)
666 {
667 bool bLeft = &rBtn == m_xLeftPB.get();
668 int nEntry = m_xHeaderTree->get_selected_index();
669 if (nEntry != -1)
670 {
671 int nToggleColumn = 0;
672 for (sal_uInt16 j = 0; j <= MAXLEVEL; ++j)
673 {
674 if (m_xHeaderTree->get_toggle(nEntry, j + 1) == TRISTATE_TRUE)
675 {
676 nToggleColumn = j;
677 break;
678 }
679 }
680
681 if (bLeft)
682 {
683 if (nToggleColumn)
684 --nToggleColumn;
685 }
686 else
687 {
688 if (nToggleColumn < MAXLEVEL)
689 ++nToggleColumn;
690 }
691
692 for (sal_uInt16 j = 0; j <= MAXLEVEL; ++j)
693 {
694 m_xHeaderTree->set_toggle(nEntry, j == nToggleColumn ? TRISTATE_TRUE : TRISTATE_FALSE, j + 1);
695 }
696 }
697 }
698
SwTOXSelectTabPage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet & rAttrSet)699 SwTOXSelectTabPage::SwTOXSelectTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rAttrSet)
700 : SfxTabPage(pPage, pController, "modules/swriter/ui/tocindexpage.ui", "TocIndexPage", &rAttrSet)
701 , sAutoMarkType(SwResId(STR_AUTOMARK_TYPE))
702 , m_bWaitingInitialSettings(true)
703 , m_xTitleED(m_xBuilder->weld_entry("title"))
704 , m_xTypeFT(m_xBuilder->weld_label("typeft"))
705 , m_xTypeLB(m_xBuilder->weld_combo_box("type"))
706 , m_xReadOnlyCB(m_xBuilder->weld_check_button("readonly"))
707 , m_xAreaFrame(m_xBuilder->weld_widget("areaframe"))
708 , m_xAreaLB(m_xBuilder->weld_combo_box("scope"))
709 , m_xLevelFT(m_xBuilder->weld_label("levelft"))
710 , m_xLevelNF(m_xBuilder->weld_spin_button("level"))
711 , m_xCreateFrame(m_xBuilder->weld_widget("createframe"))
712 , m_xFromHeadingsCB(m_xBuilder->weld_check_button("fromheadings"))
713 , m_xStylesCB(m_xBuilder->weld_check_button("stylescb"))
714 , m_xAddStylesCB(m_xBuilder->weld_check_button("addstylescb"))
715 , m_xAddStylesPB(m_xBuilder->weld_button("styles"))
716 , m_xFromTablesCB(m_xBuilder->weld_check_button("fromtables"))
717 , m_xFromFramesCB(m_xBuilder->weld_check_button("fromframes"))
718 , m_xFromGraphicsCB(m_xBuilder->weld_check_button("fromgraphics"))
719 , m_xFromOLECB(m_xBuilder->weld_check_button("fromoles"))
720 , m_xLevelFromChapterCB(m_xBuilder->weld_check_button("uselevel"))
721 , m_xFromCaptionsRB(m_xBuilder->weld_radio_button("captions"))
722 , m_xFromObjectNamesRB(m_xBuilder->weld_radio_button("objnames"))
723 , m_xCaptionSequenceFT(m_xBuilder->weld_label("categoryft"))
724 , m_xCaptionSequenceLB(m_xBuilder->weld_combo_box("category"))
725 , m_xDisplayTypeFT(m_xBuilder->weld_label("displayft"))
726 , m_xDisplayTypeLB(m_xBuilder->weld_combo_box("display"))
727 , m_xTOXMarksCB(m_xBuilder->weld_check_button("indexmarks"))
728 , m_xIdxOptionsFrame(m_xBuilder->weld_widget("optionsframe"))
729 , m_xCollectSameCB(m_xBuilder->weld_check_button("combinesame"))
730 , m_xUseFFCB(m_xBuilder->weld_check_button("useff"))
731 , m_xUseDashCB(m_xBuilder->weld_check_button("usedash"))
732 , m_xCaseSensitiveCB(m_xBuilder->weld_check_button("casesens"))
733 , m_xInitialCapsCB(m_xBuilder->weld_check_button("initcaps"))
734 , m_xKeyAsEntryCB(m_xBuilder->weld_check_button("keyasentry"))
735 , m_xFromFileCB(m_xBuilder->weld_check_button("fromfile"))
736 , m_xAutoMarkPB(m_xBuilder->weld_menu_button("file"))
737 , m_xFromObjCLB(m_xBuilder->weld_tree_view("objects"))
738 , m_xFromObjFrame(m_xBuilder->weld_widget("objectframe"))
739 , m_xSequenceCB(m_xBuilder->weld_check_button("numberentries"))
740 , m_xBracketLB(m_xBuilder->weld_combo_box("brackets"))
741 , m_xAuthorityFrame(m_xBuilder->weld_widget("authframe"))
742 , m_xSortFrame(m_xBuilder->weld_widget("sortframe"))
743 , m_xLanguageLB(new SvxLanguageBox(m_xBuilder->weld_combo_box("lang")))
744 , m_xSortAlgorithmLB(m_xBuilder->weld_combo_box("keytype"))
745 {
746 sAddStyleUser = m_xStylesCB->get_label();
747 pIndexEntryWrapper.reset(new IndexEntrySupplierWrapper());
748
749 m_xLanguageLB->SetLanguageList( SvxLanguageListFlags::ALL | SvxLanguageListFlags::ONLY_KNOWN,
750 false );
751
752 //Default mode is arranged to be the tallest mode
753 //of alphabetical index, lock that size in now
754 LanguageHdl(nullptr); //fill sort algorithm list
755 Size aPrefSize(m_xContainer->get_preferred_size());
756 m_xContainer->set_size_request(aPrefSize.Width(), aPrefSize.Height());
757
758 sAddStyleContent = m_xAddStylesCB->get_label();
759
760 std::vector<int> aWidths;
761 aWidths.push_back(m_xFromObjCLB->get_checkbox_column_width());
762 m_xFromObjCLB->set_column_fixed_widths(aWidths);
763
764 for (size_t i = 0; i < SAL_N_ELEMENTS(RES_SRCTYPES); ++i)
765 {
766 OUString sId(OUString::number(static_cast<sal_uInt32>(RES_SRCTYPES[i].second)));
767 m_xFromObjCLB->append();
768 m_xFromObjCLB->set_toggle(i, TRISTATE_FALSE, 0);
769 m_xFromObjCLB->set_text(i, SwResId(RES_SRCTYPES[i].first), 1);
770 m_xFromObjCLB->set_id(i, sId);
771 }
772
773 SetExchangeSupport();
774 m_xTypeLB->connect_changed(LINK(this, SwTOXSelectTabPage, TOXTypeHdl));
775
776 m_xAddStylesPB->connect_clicked(LINK(this, SwTOXSelectTabPage, AddStylesHdl));
777
778 m_xAutoMarkPB->connect_toggled(LINK(this, SwTOXSelectTabPage, MenuEnableHdl));
779 m_xAutoMarkPB->connect_selected(LINK(this, SwTOXSelectTabPage, MenuExecuteHdl));
780
781 Link<weld::ToggleButton&,void> aLk = LINK(this, SwTOXSelectTabPage, CheckBoxHdl);
782 m_xAddStylesCB->connect_toggled(aLk);
783 m_xFromHeadingsCB->connect_toggled(aLk);
784 m_xTOXMarksCB->connect_toggled(aLk);
785 m_xFromFileCB->connect_toggled(aLk);
786 m_xCollectSameCB->connect_toggled(aLk);
787 m_xUseFFCB->connect_toggled(aLk);
788 m_xUseDashCB->connect_toggled(aLk);
789 m_xInitialCapsCB->connect_toggled(aLk);
790 m_xKeyAsEntryCB->connect_toggled(aLk);
791
792 m_xTitleED->connect_changed(LINK(this, SwTOXSelectTabPage, ModifyEntryHdl));
793 m_xLevelNF->connect_value_changed(LINK(this, SwTOXSelectTabPage, ModifySpinHdl));
794 m_xSortAlgorithmLB->connect_changed(LINK(this, SwTOXSelectTabPage, ModifyListBoxHdl));
795
796 aLk = LINK(this, SwTOXSelectTabPage, RadioButtonHdl);
797 m_xFromCaptionsRB->connect_toggled(aLk);
798 m_xFromObjectNamesRB->connect_toggled(aLk);
799 RadioButtonHdl(*m_xFromCaptionsRB);
800
801 m_xLanguageLB->connect_changed(LINK(this, SwTOXSelectTabPage, LanguageListBoxHdl));
802 m_xTypeLB->set_active(0);
803 m_xTitleED->save_value();
804 }
805
~SwTOXSelectTabPage()806 SwTOXSelectTabPage::~SwTOXSelectTabPage()
807 {
808 pIndexRes.reset();
809 pIndexEntryWrapper.reset();
810 m_xLanguageLB.reset();
811 }
812
SetWrtShell(SwWrtShell const & rSh)813 void SwTOXSelectTabPage::SetWrtShell(SwWrtShell const & rSh)
814 {
815 const sal_uInt16 nUserTypeCount = rSh.GetTOXTypeCount(TOX_USER);
816 if(nUserTypeCount > 1)
817 {
818 //insert all new user indexes names after the standard user index
819 sal_Int32 nPos = m_xTypeLB->find_id(OUString::number(sal_uInt32(TO_USER))) + 1;
820 for (sal_uInt16 nUser = 1; nUser < nUserTypeCount; nUser++)
821 {
822 sal_uInt32 nEntryData = nUser << 8;
823 nEntryData |= TO_USER;
824 OUString sId(OUString::number(nEntryData));
825 m_xTypeLB->insert(nPos++, rSh.GetTOXType(TOX_USER, nUser)->GetTypeName(),
826 &sId, nullptr, nullptr);
827 }
828 }
829 }
830
FillItemSet(SfxItemSet *)831 bool SwTOXSelectTabPage::FillItemSet( SfxItemSet* )
832 {
833 return true;
834 }
835
lcl_TOXTypesToUserData(CurTOXType eType)836 static long lcl_TOXTypesToUserData(CurTOXType eType)
837 {
838 sal_uInt16 nRet = TOX_INDEX;
839 switch(eType.eType)
840 {
841 case TOX_INDEX : nRet = TO_INDEX; break;
842 case TOX_USER :
843 {
844 nRet = eType.nIndex << 8;
845 nRet |= TO_USER;
846 }
847 break;
848 case TOX_CONTENT : nRet = TO_CONTENT; break;
849 case TOX_ILLUSTRATIONS:nRet = TO_ILLUSTRATION; break;
850 case TOX_OBJECTS : nRet = TO_OBJECT; break;
851 case TOX_TABLES : nRet = TO_TABLE; break;
852 case TOX_AUTHORITIES : nRet = TO_AUTHORITIES; break;
853 case TOX_BIBLIOGRAPHY : nRet = TO_BIBLIOGRAPHY; break;
854 case TOX_CITATION :break;
855 }
856 return nRet;
857 }
858
SelectType(TOXTypes eSet)859 void SwTOXSelectTabPage::SelectType(TOXTypes eSet)
860 {
861 CurTOXType eCurType (eSet);
862
863 sal_uInt32 nData = lcl_TOXTypesToUserData(eCurType);
864 m_xTypeLB->set_active_id(OUString::number(nData));
865 m_xTypeFT->set_sensitive(false);
866 m_xTypeLB->set_sensitive(false);
867 TOXTypeHdl(*m_xTypeLB);
868 }
869
lcl_UserData2TOXTypes(sal_uInt16 nData)870 static CurTOXType lcl_UserData2TOXTypes(sal_uInt16 nData)
871 {
872 CurTOXType eRet;
873
874 switch(nData&0xff)
875 {
876 case TO_INDEX : eRet.eType = TOX_INDEX; break;
877 case TO_USER :
878 {
879 eRet.eType = TOX_USER;
880 eRet.nIndex = (nData&0xff00) >> 8;
881 }
882 break;
883 case TO_CONTENT : eRet.eType = TOX_CONTENT; break;
884 case TO_ILLUSTRATION: eRet.eType = TOX_ILLUSTRATIONS; break;
885 case TO_OBJECT : eRet.eType = TOX_OBJECTS; break;
886 case TO_TABLE : eRet.eType = TOX_TABLES; break;
887 case TO_AUTHORITIES : eRet.eType = TOX_AUTHORITIES; break;
888 case TO_BIBLIOGRAPHY : eRet.eType = TOX_BIBLIOGRAPHY; break;
889 default: OSL_FAIL("what a type?");
890 }
891 return eRet;
892 }
893
ApplyTOXDescription()894 void SwTOXSelectTabPage::ApplyTOXDescription()
895 {
896 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
897 const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
898 SwTOXDescription& rDesc = pTOXDlg->GetTOXDescription(aCurType);
899 m_xReadOnlyCB->set_active(rDesc.IsReadonly());
900 if (!m_xTitleED->get_value_changed_from_saved())
901 {
902 if (rDesc.GetTitle())
903 m_xTitleED->set_text(*rDesc.GetTitle());
904 else
905 m_xTitleED->set_text(OUString());
906 m_xTitleED->save_value();
907 }
908
909 m_xAreaLB->set_active(rDesc.IsFromChapter() ? 1 : 0);
910
911 if (aCurType.eType != TOX_INDEX)
912 m_xLevelNF->set_value(rDesc.GetLevel()); //content, user
913
914 SwTOXElement nCreateType = rDesc.GetContentOptions();
915
916 //user + content
917 bool bHasStyleNames = false;
918
919 for( sal_uInt16 i = 0; i < MAXLEVEL; i++)
920 if(!rDesc.GetStyleNames(i).isEmpty())
921 {
922 bHasStyleNames = true;
923 break;
924 }
925 m_xAddStylesCB->set_active(bHasStyleNames && (nCreateType & SwTOXElement::Template));
926
927 m_xFromOLECB->set_active( bool(nCreateType & SwTOXElement::Ole) );
928 m_xFromTablesCB->set_active( bool(nCreateType & SwTOXElement::Table) );
929 m_xFromGraphicsCB->set_active( bool(nCreateType & SwTOXElement::Graphic) );
930 m_xFromFramesCB->set_active( bool(nCreateType & SwTOXElement::Frame) );
931
932 m_xLevelFromChapterCB->set_active(rDesc.IsLevelFromChapter());
933
934 //all but illustration and table
935 m_xTOXMarksCB->set_active( bool(nCreateType & SwTOXElement::Mark) );
936
937 //content
938 if(TOX_CONTENT == aCurType.eType)
939 {
940 m_xFromHeadingsCB->set_active( bool(nCreateType & SwTOXElement::OutlineLevel) );
941 m_xAddStylesCB->set_label(sAddStyleContent);
942 m_xAddStylesPB->set_sensitive(m_xAddStylesCB->get_active());
943 }
944 //index only
945 else if(TOX_INDEX == aCurType.eType)
946 {
947 const SwTOIOptions nIndexOptions = rDesc.GetIndexOptions();
948 m_xCollectSameCB->set_active( bool(nIndexOptions & SwTOIOptions::SameEntry) );
949 m_xUseFFCB->set_active( bool(nIndexOptions & SwTOIOptions::FF) );
950 m_xUseDashCB->set_active( bool(nIndexOptions & SwTOIOptions::Dash) );
951 if (m_xUseFFCB->get_active())
952 m_xUseDashCB->set_sensitive(false);
953 else if (m_xUseDashCB->get_active())
954 m_xUseFFCB->set_sensitive(false);
955
956 m_xCaseSensitiveCB->set_active( bool(nIndexOptions & SwTOIOptions::CaseSensitive) );
957 m_xInitialCapsCB->set_active( bool(nIndexOptions & SwTOIOptions::InitialCaps) );
958 m_xKeyAsEntryCB->set_active( bool(nIndexOptions & SwTOIOptions::KeyAsEntry) );
959 }
960 else if (TOX_ILLUSTRATIONS == aCurType.eType || TOX_TABLES == aCurType.eType)
961 {
962 m_xFromObjectNamesRB->set_active(rDesc.IsCreateFromObjectNames());
963 m_xFromCaptionsRB->set_active(!rDesc.IsCreateFromObjectNames());
964 OUString sName(rDesc.GetSequenceName());
965 int nIndex = m_xCaptionSequenceLB->find_text(sName);
966 if (nIndex != -1)
967 m_xCaptionSequenceLB->set_active(nIndex);
968 m_xDisplayTypeLB->set_active(static_cast<sal_Int32>(rDesc.GetCaptionDisplay()));
969 if (m_xDisplayTypeLB->get_active() == -1)
970 m_xDisplayTypeLB->set_active(0);
971 RadioButtonHdl(*m_xFromCaptionsRB);
972
973 }
974 else if(TOX_OBJECTS == aCurType.eType)
975 {
976 SwTOOElements nOLEData = rDesc.GetOLEOptions();
977 for (int nFromObj = 0, nCount = m_xFromObjCLB->n_children(); nFromObj < nCount; ++nFromObj)
978 {
979 SwTOOElements nData = static_cast<SwTOOElements>(m_xFromObjCLB->get_id(nFromObj).toInt32());
980 m_xFromObjCLB->set_toggle(nFromObj, bool(nData & nOLEData) ? TRISTATE_TRUE : TRISTATE_FALSE, 0);
981 }
982 }
983 else if(TOX_AUTHORITIES == aCurType.eType)
984 {
985 const OUString& sBrackets(rDesc.GetAuthBrackets());
986 if(sBrackets.isEmpty() || sBrackets == " ")
987 m_xBracketLB->set_active(0);
988 else
989 m_xBracketLB->set_active_text(sBrackets);
990 m_xSequenceCB->set_active(rDesc.IsAuthSequence());
991 }
992 m_xAutoMarkPB->set_sensitive(m_xFromFileCB->get_active());
993
994 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
995 aStyleArr[i] = rDesc.GetStyleNames(i);
996
997 m_xLanguageLB->set_active_id(rDesc.GetLanguage());
998 LanguageHdl(nullptr);
999 for (int nCnt = 0, nEntryCount = m_xSortAlgorithmLB->get_count(); nCnt < nEntryCount; ++nCnt)
1000 {
1001 const OUString& rEntryData = m_xSortAlgorithmLB->get_id(nCnt);
1002 if (rEntryData == rDesc.GetSortAlgorithm())
1003 {
1004 m_xSortAlgorithmLB->set_active(nCnt);
1005 break;
1006 }
1007 }
1008 }
1009
FillTOXDescription()1010 void SwTOXSelectTabPage::FillTOXDescription()
1011 {
1012 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
1013 CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
1014 SwTOXDescription& rDesc = pTOXDlg->GetTOXDescription(aCurType);
1015 rDesc.SetTitle(m_xTitleED->get_text());
1016 rDesc.SetFromChapter(1 == m_xAreaLB->get_active());
1017 SwTOXElement nContentOptions = SwTOXElement::NONE;
1018 if (m_xTOXMarksCB->get_visible() && m_xTOXMarksCB->get_active())
1019 nContentOptions |= SwTOXElement::Mark;
1020
1021 SwTOIOptions nIndexOptions = rDesc.GetIndexOptions()&SwTOIOptions::AlphaDelimiter;
1022 switch(rDesc.GetTOXType())
1023 {
1024 case TOX_CONTENT:
1025 if(m_xFromHeadingsCB->get_active())
1026 nContentOptions |= SwTOXElement::OutlineLevel;
1027 break;
1028 case TOX_USER:
1029 {
1030 rDesc.SetTOUName(m_xTypeLB->get_active_text());
1031
1032 if(m_xFromOLECB->get_active())
1033 nContentOptions |= SwTOXElement::Ole;
1034 if(m_xFromTablesCB->get_active())
1035 nContentOptions |= SwTOXElement::Table;
1036 if(m_xFromFramesCB->get_active())
1037 nContentOptions |= SwTOXElement::Frame;
1038 if(m_xFromGraphicsCB->get_active())
1039 nContentOptions |= SwTOXElement::Graphic;
1040 }
1041 break;
1042 case TOX_INDEX:
1043 {
1044 nContentOptions = SwTOXElement::Mark;
1045
1046 if(m_xCollectSameCB->get_active())
1047 nIndexOptions |= SwTOIOptions::SameEntry;
1048 if(m_xUseFFCB->get_active())
1049 nIndexOptions |= SwTOIOptions::FF;
1050 if(m_xUseDashCB->get_active())
1051 nIndexOptions |= SwTOIOptions::Dash;
1052 if(m_xCaseSensitiveCB->get_active())
1053 nIndexOptions |= SwTOIOptions::CaseSensitive;
1054 if(m_xInitialCapsCB->get_active())
1055 nIndexOptions |= SwTOIOptions::InitialCaps;
1056 if(m_xKeyAsEntryCB->get_active())
1057 nIndexOptions |= SwTOIOptions::KeyAsEntry;
1058 if(m_xFromFileCB->get_active())
1059 rDesc.SetAutoMarkURL(sAutoMarkURL);
1060 else
1061 rDesc.SetAutoMarkURL(OUString());
1062 }
1063 break;
1064 case TOX_ILLUSTRATIONS:
1065 case TOX_TABLES :
1066 rDesc.SetCreateFromObjectNames(m_xFromObjectNamesRB->get_active());
1067 rDesc.SetSequenceName(m_xCaptionSequenceLB->get_active_text());
1068 rDesc.SetCaptionDisplay(static_cast<SwCaptionDisplay>(m_xDisplayTypeLB->get_active()));
1069 break;
1070 case TOX_OBJECTS:
1071 {
1072 SwTOOElements nOLEData = SwTOOElements::NONE;
1073 for (int i = 0, nCount = m_xFromObjCLB->n_children(); i < nCount; ++i)
1074 {
1075 if (m_xFromObjCLB->get_toggle(i, 0) == TRISTATE_TRUE)
1076 {
1077 SwTOOElements nData = static_cast<SwTOOElements>(m_xFromObjCLB->get_id(i).toInt32());
1078 nOLEData |= nData;
1079 }
1080 }
1081 rDesc.SetOLEOptions(nOLEData);
1082 }
1083 break;
1084 case TOX_AUTHORITIES:
1085 case TOX_BIBLIOGRAPHY :
1086 {
1087 if (m_xBracketLB->get_active())
1088 rDesc.SetAuthBrackets(m_xBracketLB->get_active_text());
1089 else
1090 rDesc.SetAuthBrackets(OUString());
1091 rDesc.SetAuthSequence(m_xSequenceCB->get_active());
1092 }
1093 break;
1094 case TOX_CITATION :
1095 break;
1096 }
1097
1098 rDesc.SetLevelFromChapter( m_xLevelFromChapterCB->get_visible() &&
1099 m_xLevelFromChapterCB->get_active());
1100 if (m_xTOXMarksCB->get_active() && m_xTOXMarksCB->get_visible())
1101 nContentOptions |= SwTOXElement::Mark;
1102 if (m_xFromHeadingsCB->get_active() && m_xFromHeadingsCB->get_visible())
1103 nContentOptions |= SwTOXElement::OutlineLevel;
1104 if (m_xAddStylesCB->get_active() && m_xAddStylesCB->get_visible())
1105 nContentOptions |= SwTOXElement::Template;
1106
1107 rDesc.SetContentOptions(nContentOptions);
1108 rDesc.SetIndexOptions(nIndexOptions);
1109 rDesc.SetLevel(m_xLevelNF->get_value());
1110
1111 rDesc.SetReadonly(m_xReadOnlyCB->get_active());
1112
1113 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
1114 rDesc.SetStyleNames(aStyleArr[i], i);
1115
1116 rDesc.SetLanguage(m_xLanguageLB->get_active_id());
1117 const OUString& rEntryData = m_xSortAlgorithmLB->get_active_id();
1118 rDesc.SetSortAlgorithm(rEntryData);
1119 }
1120
Reset(const SfxItemSet *)1121 void SwTOXSelectTabPage::Reset( const SfxItemSet* )
1122 {
1123 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
1124 SwWrtShell& rSh = pTOXDlg->GetWrtShell();
1125 const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
1126 sal_uInt32 nData = lcl_TOXTypesToUserData(aCurType);
1127 m_xTypeLB->set_active_id(OUString::number(nData));
1128
1129 sAutoMarkURL = INetURLObject::decode( rSh.GetTOIAutoMarkURL(),
1130 INetURLObject::DecodeMechanism::Unambiguous );
1131 m_xFromFileCB->set_active(!sAutoMarkURL.isEmpty());
1132
1133 m_xCaptionSequenceLB->clear();
1134 const size_t nCount = rSh.GetFieldTypeCount(SwFieldIds::SetExp);
1135 for (size_t i = 0; i < nCount; ++i)
1136 {
1137 SwFieldType *pType = rSh.GetFieldType( i, SwFieldIds::SetExp );
1138 if( pType->Which() == SwFieldIds::SetExp &&
1139 static_cast<SwSetExpFieldType *>( pType)->GetType() & nsSwGetSetExpType::GSE_SEQ )
1140 m_xCaptionSequenceLB->append_text(pType->GetName());
1141 }
1142
1143 if(pTOXDlg->IsTOXEditMode())
1144 {
1145 m_xTypeFT->set_sensitive(false);
1146 m_xTypeLB->set_sensitive(false);
1147 }
1148
1149 if(!m_bWaitingInitialSettings)
1150 {
1151 // save current values into the proper TOXDescription
1152 FillTOXDescription();
1153 }
1154 m_bWaitingInitialSettings = false;
1155
1156 TOXTypeHdl(*m_xTypeLB);
1157 CheckBoxHdl(*m_xAddStylesCB);
1158 }
1159
ActivatePage(const SfxItemSet &)1160 void SwTOXSelectTabPage::ActivatePage( const SfxItemSet& )
1161 {
1162 //nothing to do
1163 }
1164
DeactivatePage(SfxItemSet * _pSet)1165 DeactivateRC SwTOXSelectTabPage::DeactivatePage(SfxItemSet* _pSet)
1166 {
1167 if (_pSet)
1168 _pSet->Put(SfxUInt16Item(FN_PARAM_TOX_TYPE, m_xTypeLB->get_active_id().toUInt32()));
1169 FillTOXDescription();
1170 return DeactivateRC::LeavePage;
1171 }
1172
Create(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * rAttrSet)1173 std::unique_ptr<SfxTabPage> SwTOXSelectTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
1174 {
1175 return std::make_unique<SwTOXSelectTabPage>(pPage, pController, *rAttrSet);
1176 }
1177
IMPL_LINK(SwTOXSelectTabPage,TOXTypeHdl,weld::ComboBox &,rBox,void)1178 IMPL_LINK(SwTOXSelectTabPage, TOXTypeHdl, weld::ComboBox&, rBox, void)
1179 {
1180 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
1181 const sal_uInt16 nType = rBox.get_active_id().toUInt32();
1182 CurTOXType eCurType = lcl_UserData2TOXTypes(nType);
1183 pTOXDlg->SetCurrentTOXType(eCurType);
1184
1185 m_xAreaLB->set_visible( 0 != (nType & (TO_CONTENT|TO_ILLUSTRATION|TO_USER|TO_INDEX|TO_TABLE|TO_OBJECT)) );
1186 m_xLevelFT->set_visible( 0 != (nType & (TO_CONTENT)) );
1187 m_xLevelNF->set_visible( 0 != (nType & (TO_CONTENT)) );
1188 m_xLevelFromChapterCB->set_visible( 0 != (nType & (TO_USER)) );
1189 m_xAreaFrame->set_visible( 0 != (nType & (TO_CONTENT|TO_ILLUSTRATION|TO_USER|TO_INDEX|TO_TABLE|TO_OBJECT)) );
1190
1191 m_xFromHeadingsCB->set_visible( 0 != (nType & (TO_CONTENT)) );
1192 m_xAddStylesCB->set_visible( 0 != (nType & (TO_CONTENT|TO_USER)) );
1193 m_xAddStylesPB->set_visible( 0 != (nType & (TO_CONTENT|TO_USER)) );
1194
1195 m_xFromTablesCB->set_visible( 0 != (nType & (TO_USER)) );
1196 m_xFromFramesCB->set_visible( 0 != (nType & (TO_USER)) );
1197 m_xFromGraphicsCB->set_visible( 0 != (nType & (TO_USER)) );
1198 m_xFromOLECB->set_visible( 0 != (nType & (TO_USER)) );
1199
1200 m_xFromCaptionsRB->set_visible( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
1201 m_xFromObjectNamesRB->set_visible( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
1202
1203 m_xTOXMarksCB->set_visible( 0 != (nType & (TO_CONTENT|TO_USER)) );
1204
1205 m_xCreateFrame->set_visible( 0 != (nType & (TO_CONTENT|TO_ILLUSTRATION|TO_USER|TO_TABLE)) );
1206 m_xCaptionSequenceFT->set_visible( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
1207 m_xCaptionSequenceLB->set_visible( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
1208 m_xDisplayTypeFT->set_visible( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
1209 m_xDisplayTypeLB->set_visible( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
1210
1211 m_xAuthorityFrame->set_visible( 0 != (nType & TO_AUTHORITIES) );
1212
1213 bool bEnableSortLanguage = 0 != (nType & (TO_INDEX|TO_AUTHORITIES));
1214 m_xSortFrame->set_visible(bEnableSortLanguage);
1215
1216 if( nType & TO_ILLUSTRATION )
1217 {
1218 OUString sName(SwStyleNameMapper::GetUIName(RES_POOLCOLL_LABEL_FIGURE, OUString()));
1219 m_xCaptionSequenceLB->set_active_text(sName);
1220 }
1221 else if( nType & TO_TABLE )
1222 {
1223 OUString sName(SwStyleNameMapper::GetUIName(RES_POOLCOLL_LABEL_TABLE, OUString()));
1224 m_xCaptionSequenceLB->set_active_text(sName);
1225 }
1226 else if( nType & TO_USER )
1227 {
1228 m_xAddStylesCB->set_label(sAddStyleUser);
1229 }
1230
1231 m_xIdxOptionsFrame->set_visible( 0 != (nType & TO_INDEX) );
1232
1233 //object index
1234 m_xFromObjFrame->set_visible( 0 != (nType & TO_OBJECT) );
1235
1236 //set control values from the proper TOXDescription
1237 {
1238 ApplyTOXDescription();
1239 }
1240 ModifyHdl();
1241 }
1242
ModifyHdl()1243 void SwTOXSelectTabPage::ModifyHdl()
1244 {
1245 if(!m_bWaitingInitialSettings)
1246 {
1247 FillTOXDescription();
1248 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
1249 pTOXDlg->CreateOrUpdateExample(pTOXDlg->GetCurrentTOXType().eType, TOX_PAGE_SELECT);
1250 }
1251 }
1252
IMPL_LINK_NOARG(SwTOXSelectTabPage,ModifyListBoxHdl,weld::ComboBox &,void)1253 IMPL_LINK_NOARG(SwTOXSelectTabPage, ModifyListBoxHdl, weld::ComboBox&, void)
1254 {
1255 ModifyHdl();
1256 }
1257
IMPL_LINK_NOARG(SwTOXSelectTabPage,ModifyEntryHdl,weld::Entry &,void)1258 IMPL_LINK_NOARG(SwTOXSelectTabPage, ModifyEntryHdl, weld::Entry&, void)
1259 {
1260 ModifyHdl();
1261 }
1262
IMPL_LINK_NOARG(SwTOXSelectTabPage,ModifySpinHdl,weld::SpinButton &,void)1263 IMPL_LINK_NOARG(SwTOXSelectTabPage, ModifySpinHdl, weld::SpinButton&, void)
1264 {
1265 ModifyHdl();
1266 }
1267
IMPL_LINK(SwTOXSelectTabPage,CheckBoxHdl,weld::ToggleButton &,rButton,void)1268 IMPL_LINK(SwTOXSelectTabPage, CheckBoxHdl, weld::ToggleButton&, rButton, void)
1269 {
1270 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
1271 const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
1272 if(TOX_CONTENT == aCurType.eType)
1273 {
1274 //at least one of the three CheckBoxes must be checked
1275 if (!m_xAddStylesCB->get_active() && !m_xFromHeadingsCB->get_active() && !m_xTOXMarksCB->get_active())
1276 {
1277 //TODO: InfoBox?
1278 rButton.set_active(true);
1279 }
1280 m_xAddStylesPB->set_sensitive(m_xAddStylesCB->get_active());
1281 }
1282 if (TOX_USER == aCurType.eType)
1283 {
1284 m_xAddStylesPB->set_sensitive(m_xAddStylesCB->get_active());
1285 }
1286 else if (TOX_INDEX == aCurType.eType)
1287 {
1288 m_xAutoMarkPB->set_sensitive(m_xFromFileCB->get_active());
1289 m_xUseFFCB->set_sensitive(m_xCollectSameCB->get_active() && !m_xUseDashCB->get_active());
1290 m_xUseDashCB->set_sensitive(m_xCollectSameCB->get_active() && !m_xUseFFCB->get_active());
1291 m_xCaseSensitiveCB->set_sensitive(m_xCollectSameCB->get_active());
1292 }
1293 ModifyHdl();
1294 };
1295
IMPL_LINK_NOARG(SwTOXSelectTabPage,RadioButtonHdl,weld::ToggleButton &,void)1296 IMPL_LINK_NOARG(SwTOXSelectTabPage, RadioButtonHdl, weld::ToggleButton&, void)
1297 {
1298 bool bEnable = m_xFromCaptionsRB->get_active();
1299 m_xCaptionSequenceFT->set_sensitive(bEnable);
1300 m_xCaptionSequenceLB->set_sensitive(bEnable);
1301 m_xDisplayTypeFT->set_sensitive(bEnable);
1302 m_xDisplayTypeLB->set_sensitive(bEnable);
1303 ModifyHdl();
1304 }
1305
IMPL_LINK(SwTOXSelectTabPage,LanguageListBoxHdl,weld::ComboBox &,rBox,void)1306 IMPL_LINK(SwTOXSelectTabPage, LanguageListBoxHdl, weld::ComboBox&, rBox, void)
1307 {
1308 LanguageHdl(&rBox);
1309 }
1310
LanguageHdl(const weld::ComboBox * pBox)1311 void SwTOXSelectTabPage::LanguageHdl(const weld::ComboBox* pBox)
1312 {
1313 lang::Locale aLcl( LanguageTag( m_xLanguageLB->get_active_id() ).getLocale() );
1314 Sequence< OUString > aSeq = pIndexEntryWrapper->GetAlgorithmList( aLcl );
1315
1316 if( !pIndexRes )
1317 pIndexRes.reset(new IndexEntryResource());
1318
1319 OUString sOldString = m_xSortAlgorithmLB->get_active_id();
1320 m_xSortAlgorithmLB->clear();
1321
1322 sal_Int32 nEnd = aSeq.getLength();
1323 for( sal_Int32 nCnt = 0; nCnt < nEnd; ++nCnt )
1324 {
1325 const OUString sAlg(aSeq[ nCnt ]);
1326 const OUString sUINm = pIndexRes->GetTranslation( sAlg );
1327 m_xSortAlgorithmLB->append(sAlg, sUINm);
1328 if( sAlg == sOldString )
1329 m_xSortAlgorithmLB->set_active(nCnt);
1330 }
1331
1332 if (m_xSortAlgorithmLB->get_active() == -1)
1333 m_xSortAlgorithmLB->set_active(0);
1334
1335 if (pBox)
1336 ModifyHdl();
1337 };
1338
IMPL_LINK_NOARG(SwTOXSelectTabPage,AddStylesHdl,weld::Button &,void)1339 IMPL_LINK_NOARG(SwTOXSelectTabPage, AddStylesHdl, weld::Button&, void)
1340 {
1341 SwAddStylesDlg_Impl aDlg(GetFrameWeld(), static_cast<SwMultiTOXTabDialog*>(GetDialogController())->GetWrtShell(),
1342 aStyleArr);
1343 aDlg.run();
1344 ModifyHdl();
1345 }
1346
IMPL_LINK_NOARG(SwTOXSelectTabPage,MenuEnableHdl,weld::ToggleButton &,void)1347 IMPL_LINK_NOARG(SwTOXSelectTabPage, MenuEnableHdl, weld::ToggleButton&, void)
1348 {
1349 m_xAutoMarkPB->set_item_sensitive("edit", !sAutoMarkURL.isEmpty());
1350 }
1351
IMPL_LINK(SwTOXSelectTabPage,MenuExecuteHdl,const OString &,rIdent,void)1352 IMPL_LINK(SwTOXSelectTabPage, MenuExecuteHdl, const OString&, rIdent, void)
1353 {
1354 const OUString sSaveAutoMarkURL = sAutoMarkURL;
1355
1356 if (rIdent == "open")
1357 {
1358 sAutoMarkURL = lcl_CreateAutoMarkFileDlg(GetFrameWeld(),
1359 sAutoMarkURL, sAutoMarkType, true);
1360 }
1361 else if (rIdent == "new" || rIdent == "edit")
1362 {
1363 bool bNew = (rIdent == "new");
1364 if (bNew)
1365 {
1366 sAutoMarkURL = lcl_CreateAutoMarkFileDlg(GetFrameWeld(),
1367 sAutoMarkURL, sAutoMarkType, false);
1368 if (sAutoMarkURL.isEmpty())
1369 return;
1370 }
1371
1372 SwAutoMarkDlg_Impl aAutoMarkDlg(GetFrameWeld(), sAutoMarkURL, bNew);
1373 if (RET_OK != aAutoMarkDlg.run() && bNew)
1374 sAutoMarkURL = sSaveAutoMarkURL;
1375 }
1376 }
1377
1378 class SwTOXWidget
1379 {
1380 protected:
1381 Link<SwTOXWidget&,void> aGetFocusLink;
1382 public:
1383 virtual WindowType GetType() const = 0;
1384 virtual void GrabFocus() = 0;
1385 virtual void Hide() = 0;
1386 virtual void set_grid_left_attach(int nPos) = 0;
1387 virtual void get_extents_relative_to(weld::Widget& rRelative, int& x, int& y, int& width, int& height) = 0;
SetGetFocusHdl(const Link<SwTOXWidget &,void> & rLink)1388 void SetGetFocusHdl(const Link<SwTOXWidget&,void>& rLink) { aGetFocusLink = rLink; }
~SwTOXWidget()1389 virtual ~SwTOXWidget() {}
1390 };
1391
1392 class SwTOXEdit : public SwTOXWidget
1393 {
1394 std::unique_ptr<weld::Builder> m_xBuilder;
1395 SwFormToken aFormToken;
1396 Link<SwTOXEdit&,void> aModifiedLink;
1397 Link<SwTOXEdit&,void> aPrevNextControlLink;
1398 bool bNextControl;
1399 SwTokenWindow* m_pParent;
1400 std::unique_ptr<weld::Entry> m_xEntry;
1401
1402 DECL_LINK(ModifyHdl, weld::Entry&, void);
1403 public:
SwTOXEdit(SwTokenWindow * pTokenWin,const SwFormToken & rToken)1404 SwTOXEdit(SwTokenWindow* pTokenWin, const SwFormToken& rToken)
1405 : m_xBuilder(Application::CreateBuilder(pTokenWin->get_child_container(), "modules/swriter/ui/toxentrywidget.ui"))
1406 , aFormToken(rToken)
1407 , bNextControl(false)
1408 , m_pParent(pTokenWin)
1409 , m_xEntry(m_xBuilder->weld_entry("entry", true))
1410 {
1411 m_xEntry->connect_changed(LINK(this, SwTOXEdit, ModifyHdl));
1412 m_xEntry->connect_key_press(LINK(this, SwTOXEdit, KeyInputHdl));
1413 m_xEntry->connect_focus_in(LINK(this, SwTOXEdit, FocusInHdl));
1414 m_xEntry->set_tooltip_text(m_pParent->CreateQuickHelp(rToken));
1415 }
1416
GetType() const1417 virtual WindowType GetType() const override
1418 {
1419 return WindowType::EDIT;
1420 }
1421
GrabFocus()1422 virtual void GrabFocus() override
1423 {
1424 m_xEntry->grab_focus();
1425 }
1426
Hide()1427 virtual void Hide() override
1428 {
1429 m_xEntry->hide();
1430 }
1431
Show()1432 void Show()
1433 {
1434 m_xEntry->show();
1435 }
1436
SetAccessibleName(const OUString & rName)1437 void SetAccessibleName(const OUString& rName)
1438 {
1439 m_xEntry->set_accessible_name(rName);
1440 }
1441
set_grid_left_attach(int nPos)1442 virtual void set_grid_left_attach(int nPos) override
1443 {
1444 m_xEntry->set_grid_left_attach(nPos);
1445 }
1446
get_extents_relative_to(weld::Widget & rRelative,int & x,int & y,int & width,int & height)1447 virtual void get_extents_relative_to(weld::Widget& rRelative, int& x, int& y, int& width, int& height) override
1448 {
1449 m_xEntry->get_extents_relative_to(rRelative, x, y, width, height);
1450 }
1451
GetText() const1452 OUString GetText() const
1453 {
1454 return m_xEntry->get_text();
1455 }
1456
SetText(const OUString & rText)1457 void SetText(const OUString& rText)
1458 {
1459 m_xEntry->set_text(rText);
1460 }
1461
get_selection_bounds(int & rStartPos,int & rEndPos)1462 void get_selection_bounds(int& rStartPos, int& rEndPos)
1463 {
1464 m_xEntry->get_selection_bounds(rStartPos, rEndPos);
1465 }
1466
select_region(int nStartPos,int nEndPos)1467 void select_region(int nStartPos, int nEndPos)
1468 {
1469 m_xEntry->select_region(nStartPos, nEndPos);
1470 }
1471
SetModifyHdl(const Link<SwTOXEdit &,void> & rLink)1472 void SetModifyHdl(const Link<SwTOXEdit&,void>& rLink)
1473 {
1474 aModifiedLink = rLink;
1475 }
1476
1477 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
1478 DECL_LINK(FocusInHdl, weld::Widget&, void);
1479
IsNextControl() const1480 bool IsNextControl() const { return bNextControl; }
SetPrevNextLink(const Link<SwTOXEdit &,void> & rLink)1481 void SetPrevNextLink(const Link<SwTOXEdit&,void>& rLink) { aPrevNextControlLink = rLink; }
1482
GetFormToken()1483 const SwFormToken& GetFormToken()
1484 {
1485 aFormToken.sText = m_xEntry->get_text();
1486 return aFormToken;
1487 }
1488
SetCharStyleName(const OUString & rSet,sal_uInt16 nPoolId)1489 void SetCharStyleName(const OUString& rSet, sal_uInt16 nPoolId)
1490 {
1491 aFormToken.sCharStyleName = rSet;
1492 aFormToken.nPoolId = nPoolId;
1493 }
1494
1495 void AdjustSize();
1496 };
1497
IMPL_LINK_NOARG(SwTOXEdit,ModifyHdl,weld::Entry &,void)1498 IMPL_LINK_NOARG(SwTOXEdit, ModifyHdl, weld::Entry&, void)
1499 {
1500 aModifiedLink.Call(*this);
1501 }
1502
IMPL_LINK(SwTOXEdit,KeyInputHdl,const KeyEvent &,rKEvt,bool)1503 IMPL_LINK(SwTOXEdit, KeyInputHdl, const KeyEvent&, rKEvt, bool)
1504 {
1505 bool bCall = false;
1506 int nStartPos, nEndPos;
1507 bool bStartIsEnd = !m_xEntry->get_selection_bounds(nStartPos, nEndPos);
1508 int nMin = std::min(nStartPos, nEndPos);
1509 const sal_Int32 nTextLen = GetText().getLength();
1510 if ((bStartIsEnd && !nMin) || nMin == nTextLen)
1511 {
1512 vcl::KeyCode aCode = rKEvt.GetKeyCode();
1513 if (aCode.GetCode() == KEY_RIGHT && nMin == nTextLen)
1514 {
1515 bNextControl = true;
1516 bCall = true;
1517 }
1518 else if (aCode.GetCode() == KEY_LEFT && !nMin)
1519 {
1520 bNextControl = false;
1521 bCall = true;
1522 }
1523 else if ( (aCode.GetCode() == KEY_F3) && aCode.IsShift() && !aCode.IsMod1() && !aCode.IsMod2() )
1524 {
1525 if (m_pParent)
1526 {
1527 m_pParent->SetFocus2theAllBtn();
1528 }
1529 }
1530 if (bCall && aPrevNextControlLink.IsSet())
1531 aPrevNextControlLink.Call(*this);
1532 else
1533 bCall = false;
1534
1535 }
1536 return bCall;
1537 }
1538
IMPL_LINK_NOARG(SwTOXEdit,FocusInHdl,weld::Widget &,void)1539 IMPL_LINK_NOARG(SwTOXEdit, FocusInHdl, weld::Widget&, void)
1540 {
1541 aGetFocusLink.Call(*this);
1542 }
1543
AdjustSize()1544 void SwTOXEdit::AdjustSize()
1545 {
1546 auto nWidth = m_xEntry->get_pixel_size(GetText()).Width();
1547 float fChars = nWidth / m_xEntry->get_approximate_digit_width();
1548 m_xEntry->set_width_chars(std::max(1.0f, std::ceil(fChars)));
1549 }
1550
1551 class SwTOXButton : public SwTOXWidget
1552 {
1553 std::unique_ptr<weld::Builder> m_xBuilder;
1554 SwFormToken aFormToken;
1555 Link<SwTOXButton&,void> aPrevNextControlLink;
1556 bool bNextControl;
1557 SwTokenWindow* m_pParent;
1558 std::unique_ptr<weld::ToggleButton> m_xButton;
1559 public:
SwTOXButton(SwTokenWindow * pTokenWin,const SwFormToken & rToken)1560 SwTOXButton(SwTokenWindow* pTokenWin, const SwFormToken& rToken)
1561 : m_xBuilder(Application::CreateBuilder(pTokenWin->get_child_container(), "modules/swriter/ui/toxbuttonwidget.ui"))
1562 , aFormToken(rToken)
1563 , bNextControl(false)
1564 , m_pParent(pTokenWin)
1565 , m_xButton(m_xBuilder->weld_toggle_button("button", true))
1566 {
1567 m_xButton->connect_key_press(LINK(this, SwTOXButton, KeyInputHdl));
1568 m_xButton->connect_focus_in(LINK(this, SwTOXButton, FocusInHdl));
1569 m_xButton->set_tooltip_text(m_pParent->CreateQuickHelp(rToken));
1570 }
1571
GetType() const1572 virtual WindowType GetType() const override
1573 {
1574 return WindowType::PUSHBUTTON;
1575 }
1576
GrabFocus()1577 virtual void GrabFocus() override
1578 {
1579 m_xButton->grab_focus();
1580 }
1581
Hide()1582 virtual void Hide() override
1583 {
1584 m_xButton->hide();
1585 }
1586
Show()1587 void Show()
1588 {
1589 m_xButton->show();
1590 }
1591
SetAccessibleName(const OUString & rName)1592 void SetAccessibleName(const OUString& rName)
1593 {
1594 m_xButton->set_accessible_name(rName);
1595 }
1596
set_grid_left_attach(int nPos)1597 virtual void set_grid_left_attach(int nPos) override
1598 {
1599 m_xButton->set_grid_left_attach(nPos);
1600 }
1601
get_extents_relative_to(weld::Widget & rRelative,int & x,int & y,int & width,int & height)1602 void get_extents_relative_to(weld::Widget& rRelative, int& x, int& y, int& width, int& height) override
1603 {
1604 m_xButton->get_extents_relative_to(rRelative, x, y, width, height);
1605 }
1606
Check(bool bCheck=true)1607 void Check(bool bCheck = true)
1608 {
1609 m_xButton->set_active(bCheck);
1610 }
1611
1612 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
1613 DECL_LINK(FocusInHdl, weld::Widget&, void);
1614
IsNextControl() const1615 bool IsNextControl() const {return bNextControl;}
SetPrevNextLink(const Link<SwTOXButton &,void> & rLink)1616 void SetPrevNextLink(const Link<SwTOXButton&,void>& rLink) {aPrevNextControlLink = rLink;}
GetFormToken() const1617 const SwFormToken& GetFormToken() const {return aFormToken;}
1618
SetCharStyleName(const OUString & rSet,sal_uInt16 nPoolId)1619 void SetCharStyleName(const OUString& rSet, sal_uInt16 nPoolId)
1620 {
1621 aFormToken.sCharStyleName = rSet;
1622 aFormToken.nPoolId = nPoolId;
1623 }
1624
SetTabPosition(SwTwips nSet)1625 void SetTabPosition(SwTwips nSet)
1626 { aFormToken.nTabStopPosition = nSet; }
1627
SetFillChar(sal_Unicode cSet)1628 void SetFillChar( sal_Unicode cSet )
1629 { aFormToken.cTabFillChar = cSet; }
1630
SetTabAlign(SvxTabAdjust eAlign)1631 void SetTabAlign(SvxTabAdjust eAlign)
1632 { aFormToken.eTabAlign = eAlign;}
1633
1634 //---> i89791
1635 //used for entry number format, in TOC only
1636 //needed for different UI dialog position
SetEntryNumberFormat(sal_uInt16 nSet)1637 void SetEntryNumberFormat(sal_uInt16 nSet) {
1638 switch(nSet)
1639 {
1640 default:
1641 case 0:
1642 aFormToken.nChapterFormat = CF_NUMBER;
1643 break;
1644 case 1:
1645 aFormToken.nChapterFormat = CF_NUM_NOPREPST_TITLE;
1646 break;
1647 }
1648 }
1649
SetChapterInfo(sal_uInt16 nSet)1650 void SetChapterInfo(sal_uInt16 nSet) {
1651 switch(nSet)
1652 {
1653 default:
1654 case 0:
1655 aFormToken.nChapterFormat = CF_NUM_NOPREPST_TITLE;
1656 break;
1657 case 1:
1658 aFormToken.nChapterFormat = CF_TITLE;
1659 break;
1660 case 2:
1661 aFormToken.nChapterFormat = CF_NUMBER_NOPREPST;
1662 break;
1663 }
1664 }
1665
SetOutlineLevel(sal_uInt16 nSet)1666 void SetOutlineLevel( sal_uInt16 nSet ) { aFormToken.nOutlineLevel = nSet;}//i53420
1667
SetText(const OUString & rText)1668 void SetText(const OUString& rText)
1669 {
1670 m_xButton->set_label(rText);
1671 }
1672
SetLinkEnd()1673 void SetLinkEnd()
1674 {
1675 OSL_ENSURE(TOKEN_LINK_START == aFormToken.eTokenType,
1676 "call SetLinkEnd for link start only!");
1677 aFormToken.eTokenType = TOKEN_LINK_END;
1678 aFormToken.sText = SwForm::GetFormLinkEnd();
1679 SetText(aFormToken.sText);
1680 }
1681
SetLinkStart()1682 void SetLinkStart()
1683 {
1684 OSL_ENSURE(TOKEN_LINK_END == aFormToken.eTokenType,
1685 "call SetLinkStart for link start only!");
1686 aFormToken.eTokenType = TOKEN_LINK_START;
1687 aFormToken.sText = SwForm::GetFormLinkStt();
1688 SetText(aFormToken.sText);
1689 }
1690 };
1691
IMPL_LINK(SwTOXButton,KeyInputHdl,const KeyEvent &,rKEvt,bool)1692 IMPL_LINK(SwTOXButton, KeyInputHdl, const KeyEvent&, rKEvt, bool)
1693 {
1694 bool bCall = false;
1695 vcl::KeyCode aCode = rKEvt.GetKeyCode();
1696 if (aCode.GetCode() == KEY_RIGHT)
1697 {
1698 bNextControl = true;
1699 bCall = true;
1700 }
1701 else if (aCode.GetCode() == KEY_LEFT)
1702 {
1703 bNextControl = false;
1704 bCall = true;
1705 }
1706 else if (aCode.GetCode() == KEY_DELETE)
1707 {
1708 m_pParent->RemoveControl(this, true);
1709 //this is invalid here
1710 return true;
1711 }
1712 else if ( (aCode.GetCode() == KEY_F3) && aCode.IsShift() && !aCode.IsMod1() && !aCode.IsMod2() )
1713 {
1714 if (m_pParent)
1715 {
1716 m_pParent->SetFocus2theAllBtn();
1717 }
1718 }
1719 if (bCall && aPrevNextControlLink.IsSet())
1720 aPrevNextControlLink.Call(*this);
1721 else
1722 bCall = false;
1723 return bCall;
1724 }
1725
IMPL_LINK_NOARG(SwTOXButton,FocusInHdl,weld::Widget &,void)1726 IMPL_LINK_NOARG(SwTOXButton, FocusInHdl, weld::Widget&, void)
1727 {
1728 aGetFocusLink.Call(*this);
1729 }
1730
1731 namespace
1732 {
1733 const char* STR_AUTH_FIELD_ARY[] =
1734 {
1735 STR_AUTH_FIELD_IDENTIFIER,
1736 STR_AUTH_FIELD_AUTHORITY_TYPE,
1737 STR_AUTH_FIELD_ADDRESS,
1738 STR_AUTH_FIELD_ANNOTE,
1739 STR_AUTH_FIELD_AUTHOR,
1740 STR_AUTH_FIELD_BOOKTITLE,
1741 STR_AUTH_FIELD_CHAPTER,
1742 STR_AUTH_FIELD_EDITION,
1743 STR_AUTH_FIELD_EDITOR,
1744 STR_AUTH_FIELD_HOWPUBLISHED,
1745 STR_AUTH_FIELD_INSTITUTION,
1746 STR_AUTH_FIELD_JOURNAL,
1747 STR_AUTH_FIELD_MONTH,
1748 STR_AUTH_FIELD_NOTE,
1749 STR_AUTH_FIELD_NUMBER,
1750 STR_AUTH_FIELD_ORGANIZATIONS,
1751 STR_AUTH_FIELD_PAGES,
1752 STR_AUTH_FIELD_PUBLISHER,
1753 STR_AUTH_FIELD_SCHOOL,
1754 STR_AUTH_FIELD_SERIES,
1755 STR_AUTH_FIELD_TITLE,
1756 STR_AUTH_FIELD_TYPE,
1757 STR_AUTH_FIELD_VOLUME,
1758 STR_AUTH_FIELD_YEAR,
1759 STR_AUTH_FIELD_URL,
1760 STR_AUTH_FIELD_CUSTOM1,
1761 STR_AUTH_FIELD_CUSTOM2,
1762 STR_AUTH_FIELD_CUSTOM3,
1763 STR_AUTH_FIELD_CUSTOM4,
1764 STR_AUTH_FIELD_CUSTOM5,
1765 STR_AUTH_FIELD_ISBN
1766 };
1767 }
1768
SwTOXEntryTabPage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet & rAttrSet)1769 SwTOXEntryTabPage::SwTOXEntryTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rAttrSet)
1770 : SfxTabPage(pPage, pController, "modules/swriter/ui/tocentriespage.ui", "TocEntriesPage", &rAttrSet)
1771 , sDelimStr(SwResId(STR_DELIM))
1772 , sNoCharStyle(SwResId(STR_NO_CHAR_STYLE))
1773 , m_pCurrentForm(nullptr)
1774 , bInLevelHdl(false)
1775 , m_xTypeFT(m_xBuilder->weld_label("typeft"))
1776 , m_xLevelFT(m_xBuilder->weld_label("levelft"))
1777 , m_xLevelLB(m_xBuilder->weld_tree_view("level"))
1778 , m_xAllLevelsPB(m_xBuilder->weld_button("all"))
1779 , m_xEntryNoPB(m_xBuilder->weld_button("chapterno"))
1780 , m_xEntryPB(m_xBuilder->weld_button("entrytext"))
1781 , m_xTabPB(m_xBuilder->weld_button("tabstop"))
1782 , m_xChapterInfoPB(m_xBuilder->weld_button("chapterinfo"))
1783 , m_xPageNoPB(m_xBuilder->weld_button("pageno"))
1784 , m_xHyperLinkPB(m_xBuilder->weld_button("hyperlink"))
1785 , m_xAuthFieldsLB(m_xBuilder->weld_combo_box("authfield"))
1786 , m_xAuthInsertPB(m_xBuilder->weld_button("insert"))
1787 , m_xAuthRemovePB(m_xBuilder->weld_button("remove"))
1788 , m_xCharStyleLB(m_xBuilder->weld_combo_box("charstyle"))
1789 , m_xEditStylePB(m_xBuilder->weld_button("edit"))
1790 , m_xChapterEntryFT(m_xBuilder->weld_label("chapterentryft"))
1791 , m_xChapterEntryLB(m_xBuilder->weld_combo_box("chapterentry"))
1792 , m_xNumberFormatFT(m_xBuilder->weld_label("numberformatft"))
1793 , m_xNumberFormatLB(m_xBuilder->weld_combo_box("numberformat"))
1794 , m_xEntryOutlineLevelFT(m_xBuilder->weld_label("entryoutlinelevelft"))
1795 , m_xEntryOutlineLevelNF(m_xBuilder->weld_spin_button("entryoutlinelevel"))
1796 , m_xFillCharFT(m_xBuilder->weld_label("fillcharft"))
1797 , m_xFillCharCB(m_xBuilder->weld_combo_box("fillchar"))
1798 , m_xTabPosFT(m_xBuilder->weld_label("tabstopposft"))
1799 , m_xTabPosMF(m_xBuilder->weld_metric_spin_button("tabstoppos", FieldUnit::CM))
1800 , m_xAutoRightCB(m_xBuilder->weld_check_button("alignright"))
1801 , m_xFormatFrame(m_xBuilder->weld_widget("formatframe"))
1802 , m_xMainEntryStyleFT(m_xBuilder->weld_label("mainstyleft"))
1803 , m_xMainEntryStyleLB(m_xBuilder->weld_combo_box("mainstyle"))
1804 , m_xAlphaDelimCB(m_xBuilder->weld_check_button("alphadelim"))
1805 , m_xCommaSeparatedCB(m_xBuilder->weld_check_button("commasep"))
1806 , m_xRelToStyleCB(m_xBuilder->weld_check_button("reltostyle"))
1807 , m_xSortingFrame(m_xBuilder->weld_widget("sortingframe"))
1808 , m_xSortDocPosRB(m_xBuilder->weld_radio_button("sortpos"))
1809 , m_xSortContentRB(m_xBuilder->weld_radio_button("sortcontents"))
1810 , m_xSortKeyFrame(m_xBuilder->weld_widget("sortkeyframe"))
1811 , m_xFirstKeyLB(m_xBuilder->weld_combo_box("key1lb"))
1812 , m_xFirstSortUpRB(m_xBuilder->weld_radio_button("up1cb"))
1813 , m_xFirstSortDownRB(m_xBuilder->weld_radio_button("down1cb"))
1814 , m_xSecondKeyLB(m_xBuilder->weld_combo_box("key2lb"))
1815 , m_xSecondSortUpRB(m_xBuilder->weld_radio_button("up2cb"))
1816 , m_xSecondSortDownRB(m_xBuilder->weld_radio_button("down2cb"))
1817 , m_xThirdKeyLB(m_xBuilder->weld_combo_box("key3lb"))
1818 , m_xThirdSortUpRB(m_xBuilder->weld_radio_button("up3cb"))
1819 , m_xThirdSortDownRB(m_xBuilder->weld_radio_button("down3cb"))
1820 , m_xTokenWIN(new SwTokenWindow(m_xBuilder->weld_container("token")))
1821 {
1822 const OUString sNoCharSortKey(SwResId(STR_NOSORTKEY));
1823
1824 sAuthTypeStr = m_xTypeFT->get_label();
1825 sLevelStr = m_xLevelFT->get_label();
1826 m_xAuthFieldsLB->make_sorted();
1827 m_xTokenWIN->SetTabPage(this);
1828
1829 aLastTOXType.eType = TOXTypes(USHRT_MAX);
1830 aLastTOXType.nIndex = 0;
1831
1832 SetExchangeSupport();
1833 m_xEntryNoPB->connect_clicked(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
1834 m_xEntryPB->connect_clicked(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
1835 m_xChapterInfoPB->connect_clicked(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
1836 m_xPageNoPB->connect_clicked(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
1837 m_xTabPB->connect_clicked(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
1838 m_xHyperLinkPB->connect_clicked(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
1839 m_xEditStylePB->connect_clicked(LINK(this, SwTOXEntryTabPage, EditStyleHdl));
1840 m_xLevelLB->connect_changed(LINK(this, SwTOXEntryTabPage, LevelHdl));
1841 m_xTokenWIN->SetButtonSelectedHdl(LINK(this, SwTOXEntryTabPage, TokenSelectedHdl));
1842 m_xTokenWIN->SetModifyHdl(LINK(this, SwTOXEntryTabPage, ModifyHdl));
1843 m_xCharStyleLB->connect_changed(LINK(this, SwTOXEntryTabPage, StyleSelectHdl));
1844 m_xCharStyleLB->append_text(sNoCharStyle);
1845 m_xChapterEntryLB->connect_changed(LINK(this, SwTOXEntryTabPage, ChapterInfoHdl));
1846 m_xEntryOutlineLevelNF->connect_value_changed(LINK(this, SwTOXEntryTabPage, ChapterInfoOutlineHdl));
1847 m_xNumberFormatLB->connect_changed(LINK(this, SwTOXEntryTabPage, NumberFormatHdl));
1848
1849 m_xTabPosMF->connect_value_changed(LINK(this, SwTOXEntryTabPage, TabPosHdl));
1850 m_xFillCharCB->connect_changed(LINK(this, SwTOXEntryTabPage, FillCharHdl));
1851 m_xAutoRightCB->connect_toggled(LINK(this, SwTOXEntryTabPage, AutoRightHdl));
1852 m_xAuthInsertPB->connect_clicked(LINK(this, SwTOXEntryTabPage, RemoveInsertAuthHdl));
1853 m_xAuthRemovePB->connect_clicked(LINK(this, SwTOXEntryTabPage, RemoveInsertAuthHdl));
1854 m_xSortDocPosRB->connect_toggled(LINK(this, SwTOXEntryTabPage, SortKeyHdl));
1855 m_xSortContentRB->connect_toggled(LINK(this, SwTOXEntryTabPage, SortKeyHdl));
1856 m_xAllLevelsPB->connect_clicked(LINK(this, SwTOXEntryTabPage, AllLevelsHdl));
1857
1858 m_xAlphaDelimCB->connect_toggled(LINK(this, SwTOXEntryTabPage, ModifyClickHdl));
1859 m_xCommaSeparatedCB->connect_toggled(LINK(this, SwTOXEntryTabPage, ModifyClickHdl));
1860 m_xRelToStyleCB->connect_toggled(LINK(this, SwTOXEntryTabPage, ModifyClickHdl));
1861
1862 FieldUnit aMetric = ::GetDfltMetric(false);
1863 ::SetFieldUnit(*m_xTabPosMF, aMetric);
1864
1865 m_xSortDocPosRB->set_active(true);
1866
1867 m_xFillCharCB->set_entry_max_length(1);
1868 m_xFillCharCB->append_text(OUString(' '));
1869 m_xFillCharCB->append_text(OUString('.'));
1870 m_xFillCharCB->append_text(OUString('-'));
1871 m_xFillCharCB->append_text(OUString('_'));
1872 m_xFillCharCB->append_text(OUString(u'\x2024')); // ONE DOT LEADER
1873 m_xFillCharCB->append_text(OUString(u'\x2025')); // TWO DOT LEADER
1874 m_xFillCharCB->append_text(OUString(u'\x2026')); // HORIZONTAL ELLIPSIS
1875
1876 m_xEditStylePB->set_sensitive(false);
1877
1878 //fill the types in
1879 for (sal_uInt16 i = 0; i < AUTH_FIELD_END; ++i)
1880 {
1881 OUString sId(OUString::number(i));
1882 m_xAuthFieldsLB->append(sId, SwResId(STR_AUTH_FIELD_ARY[i]));
1883 }
1884
1885 m_xFirstKeyLB->append(OUString::number(USHRT_MAX), sNoCharSortKey);
1886 m_xSecondKeyLB->append(OUString::number(USHRT_MAX), sNoCharSortKey);
1887 m_xThirdKeyLB->append(OUString::number(USHRT_MAX), sNoCharSortKey);
1888
1889 for (sal_uInt16 i = 0; i < AUTH_FIELD_END; ++i)
1890 {
1891 const OUString sTmp(m_xAuthFieldsLB->get_text(i));
1892 const OUString sEntryData(m_xAuthFieldsLB->get_id(i));
1893 m_xFirstKeyLB->append(sEntryData, sTmp);
1894 m_xSecondKeyLB->append(sEntryData, sTmp);
1895 m_xThirdKeyLB->append(sEntryData, sTmp);
1896 }
1897 m_xFirstKeyLB->set_active(0);
1898 m_xSecondKeyLB->set_active(0);
1899 m_xThirdKeyLB->set_active(0);
1900
1901 //lock size
1902 Size aPrefSize(m_xContainer->get_preferred_size());
1903 m_xContainer->set_size_request(aPrefSize.Width(), aPrefSize.Height());
1904 }
1905
~SwTOXEntryTabPage()1906 SwTOXEntryTabPage::~SwTOXEntryTabPage()
1907 {
1908 m_xTokenWIN.reset();
1909 }
1910
IMPL_LINK_NOARG(SwTOXEntryTabPage,ModifyClickHdl,weld::ToggleButton &,void)1911 IMPL_LINK_NOARG(SwTOXEntryTabPage, ModifyClickHdl, weld::ToggleButton&, void)
1912 {
1913 OnModify(true);
1914 }
1915
IMPL_LINK_NOARG(SwTOXEntryTabPage,ModifyHdl,LinkParamNone *,void)1916 IMPL_LINK_NOARG(SwTOXEntryTabPage, ModifyHdl, LinkParamNone*, void)
1917 {
1918 OnModify(false);
1919 }
1920
1921 // bAllLevels is used as signal to change all levels of the example
OnModify(bool bAllLevels)1922 void SwTOXEntryTabPage::OnModify(bool bAllLevels)
1923 {
1924 UpdateDescriptor();
1925
1926 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
1927 if (pTOXDlg)
1928 {
1929 sal_uInt16 nCurLevel = m_xLevelLB->get_selected_index() + 1;
1930 if (aLastTOXType.eType == TOX_CONTENT && bAllLevels)
1931 nCurLevel = USHRT_MAX;
1932 pTOXDlg->CreateOrUpdateExample(
1933 pTOXDlg->GetCurrentTOXType().eType, TOX_PAGE_ENTRY, nCurLevel);
1934 }
1935 }
1936
FillItemSet(SfxItemSet *)1937 bool SwTOXEntryTabPage::FillItemSet( SfxItemSet* )
1938 {
1939 // nothing to do
1940 return true;
1941 }
1942
Reset(const SfxItemSet *)1943 void SwTOXEntryTabPage::Reset( const SfxItemSet* )
1944 {
1945 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
1946 const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
1947 m_pCurrentForm = pTOXDlg->GetForm(aCurType);
1948 if(TOX_INDEX == aCurType.eType)
1949 {
1950 SwTOXDescription& rDesc = pTOXDlg->GetTOXDescription(aCurType);
1951 const OUString& sMainEntryCharStyle = rDesc.GetMainEntryCharStyle();
1952 if(!sMainEntryCharStyle.isEmpty())
1953 {
1954 if (m_xMainEntryStyleLB->find_text(sMainEntryCharStyle) == -1)
1955 m_xMainEntryStyleLB->append_text(sMainEntryCharStyle);
1956 m_xMainEntryStyleLB->set_active_text(sMainEntryCharStyle);
1957 }
1958 else
1959 m_xMainEntryStyleLB->set_active_text(sNoCharStyle);
1960 m_xAlphaDelimCB->set_active( bool(rDesc.GetIndexOptions() & SwTOIOptions::AlphaDelimiter) );
1961 }
1962 m_xRelToStyleCB->set_active(m_pCurrentForm->IsRelTabPos());
1963 m_xCommaSeparatedCB->set_active(m_pCurrentForm->IsCommaSeparated());
1964 }
1965
ActivatePage(const SfxItemSet &)1966 void SwTOXEntryTabPage::ActivatePage( const SfxItemSet& /*rSet*/)
1967 {
1968 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
1969 const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
1970
1971 m_pCurrentForm = pTOXDlg->GetForm(aCurType);
1972 if( !( aLastTOXType == aCurType ))
1973 {
1974 bool bToxIsAuthorities = TOX_AUTHORITIES == aCurType.eType;
1975 bool bToxIsIndex = TOX_INDEX == aCurType.eType;
1976 bool bToxIsContent = TOX_CONTENT == aCurType.eType;
1977 bool bToxSupportsLinks = TOX_CONTENT == aCurType.eType ||
1978 TOX_ILLUSTRATIONS == aCurType.eType ||
1979 TOX_TABLES == aCurType.eType ||
1980 TOX_OBJECTS == aCurType.eType ||
1981 TOX_USER == aCurType.eType;
1982
1983 m_xLevelLB->clear();
1984 for(sal_uInt16 i = 1; i < m_pCurrentForm->GetFormMax(); i++)
1985 {
1986 if(bToxIsAuthorities)
1987 m_xLevelLB->append_text( SwAuthorityFieldType::GetAuthTypeName(
1988 static_cast<ToxAuthorityType>(i - 1)) );
1989 else if( bToxIsIndex )
1990 {
1991 if(i == 1)
1992 m_xLevelLB->append_text( sDelimStr );
1993 else
1994 m_xLevelLB->append_text( OUString::number(i - 1) );
1995 }
1996 else
1997 m_xLevelLB->append_text(OUString::number(i));
1998 }
1999 if(bToxIsAuthorities)
2000 {
2001 SwWrtShell& rSh = pTOXDlg->GetWrtShell();
2002 const SwAuthorityFieldType* pFType = static_cast<const SwAuthorityFieldType*>(
2003 rSh.GetFieldType(SwFieldIds::TableOfAuthorities, OUString()));
2004 if(pFType)
2005 {
2006 if(pFType->IsSortByDocument())
2007 m_xSortDocPosRB->set_active(true);
2008 else
2009 {
2010 m_xSortContentRB->set_active(true);
2011 const sal_uInt16 nKeyCount = pFType->GetSortKeyCount();
2012 if(0 < nKeyCount)
2013 {
2014 const SwTOXSortKey* pKey = pFType->GetSortKey(0);
2015 m_xFirstKeyLB->set_active_id(OUString::number(pKey->eField));
2016 m_xFirstSortUpRB->set_active(pKey->bSortAscending);
2017 m_xFirstSortDownRB->set_active(!pKey->bSortAscending);
2018 }
2019 if(1 < nKeyCount)
2020 {
2021 const SwTOXSortKey* pKey = pFType->GetSortKey(1);
2022 m_xSecondKeyLB->set_active_id(OUString::number(pKey->eField));
2023 m_xSecondSortUpRB->set_active(pKey->bSortAscending);
2024 m_xSecondSortDownRB->set_active(!pKey->bSortAscending);
2025 }
2026 if(2 < nKeyCount)
2027 {
2028 const SwTOXSortKey* pKey = pFType->GetSortKey(2);
2029 m_xThirdKeyLB->set_active_id(OUString::number(pKey->eField));
2030 m_xThirdSortUpRB->set_active(pKey->bSortAscending);
2031 m_xThirdSortDownRB->set_active(!pKey->bSortAscending);
2032 }
2033 }
2034 }
2035 SortKeyHdl(m_xSortDocPosRB->get_active() ? *m_xSortDocPosRB : *m_xSortContentRB);
2036 m_xLevelFT->set_label(sAuthTypeStr);
2037 }
2038 else
2039 m_xLevelFT->set_label(sLevelStr);
2040
2041 m_xLevelLB->select(bToxIsIndex ? 1 : 0);
2042
2043 //show or hide controls
2044 m_xEntryNoPB->set_visible(bToxIsContent);
2045 m_xHyperLinkPB->set_visible(bToxSupportsLinks);
2046 m_xRelToStyleCB->set_visible(!bToxIsAuthorities);
2047 m_xChapterInfoPB->set_visible(!bToxIsContent && !bToxIsAuthorities);
2048 m_xEntryPB->set_visible(!bToxIsAuthorities);
2049 m_xPageNoPB->set_visible(!bToxIsAuthorities);
2050 m_xAuthFieldsLB->set_visible(bToxIsAuthorities);
2051 m_xAuthInsertPB->set_visible(bToxIsAuthorities);
2052 m_xAuthRemovePB->set_visible(bToxIsAuthorities);
2053
2054 m_xFormatFrame->set_visible(!bToxIsAuthorities);
2055
2056 m_xSortingFrame->set_visible(bToxIsAuthorities);
2057 m_xSortKeyFrame->set_visible(bToxIsAuthorities);
2058
2059 m_xMainEntryStyleFT->set_visible(bToxIsIndex);
2060 m_xMainEntryStyleLB->set_visible(bToxIsIndex);
2061 m_xAlphaDelimCB->set_visible(bToxIsIndex);
2062 m_xCommaSeparatedCB->set_visible(bToxIsIndex);
2063 }
2064 aLastTOXType = aCurType;
2065
2066 //invalidate PatternWindow
2067 m_xTokenWIN->SetInvalid();
2068 LevelHdl(*m_xLevelLB);
2069 }
2070
UpdateDescriptor()2071 void SwTOXEntryTabPage::UpdateDescriptor()
2072 {
2073 WriteBackLevel();
2074 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
2075 SwTOXDescription& rDesc = pTOXDlg->GetTOXDescription(aLastTOXType);
2076 if(TOX_INDEX == aLastTOXType.eType)
2077 {
2078 const OUString sTemp(m_xMainEntryStyleLB->get_active_text());
2079 rDesc.SetMainEntryCharStyle(sNoCharStyle == sTemp ? OUString(): sTemp);
2080 SwTOIOptions nIdxOptions = rDesc.GetIndexOptions() & ~SwTOIOptions::AlphaDelimiter;
2081 if (m_xAlphaDelimCB->get_active())
2082 nIdxOptions |= SwTOIOptions::AlphaDelimiter;
2083 rDesc.SetIndexOptions(nIdxOptions);
2084 }
2085 else if (TOX_AUTHORITIES == aLastTOXType.eType)
2086 {
2087 rDesc.SetSortByDocument(m_xSortDocPosRB->get_active());
2088 SwTOXSortKey aKey1, aKey2, aKey3;
2089 aKey1.eField = static_cast<ToxAuthorityField>(m_xFirstKeyLB->get_active_id().toInt32());
2090 aKey1.bSortAscending = m_xFirstSortUpRB->get_active();
2091 aKey2.eField = static_cast<ToxAuthorityField>(m_xSecondKeyLB->get_active_id().toInt32());
2092 aKey2.bSortAscending = m_xSecondSortUpRB->get_active();
2093 aKey3.eField = static_cast<ToxAuthorityField>(m_xThirdKeyLB->get_active_id().toInt32());
2094 aKey3.bSortAscending = m_xThirdSortUpRB->get_active();
2095
2096 rDesc.SetSortKeys(aKey1, aKey2, aKey3);
2097 }
2098 SwForm* pCurrentForm = pTOXDlg->GetForm(aLastTOXType);
2099 if (m_xRelToStyleCB->get_visible())
2100 pCurrentForm->SetRelTabPos(m_xRelToStyleCB->get_active());
2101 if (m_xCommaSeparatedCB->get_visible())
2102 pCurrentForm->SetCommaSeparated(m_xCommaSeparatedCB->get_active());
2103 }
2104
DeactivatePage(SfxItemSet *)2105 DeactivateRC SwTOXEntryTabPage::DeactivatePage( SfxItemSet* /*pSet*/)
2106 {
2107 UpdateDescriptor();
2108 return DeactivateRC::LeavePage;
2109 }
2110
Create(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * rAttrSet)2111 std::unique_ptr<SfxTabPage> SwTOXEntryTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
2112 {
2113 return std::make_unique<SwTOXEntryTabPage>(pPage, pController, *rAttrSet);
2114 }
2115
IMPL_LINK_NOARG(SwTOXEntryTabPage,EditStyleHdl,weld::Button &,void)2116 IMPL_LINK_NOARG(SwTOXEntryTabPage, EditStyleHdl, weld::Button&, void)
2117 {
2118 if (m_xCharStyleLB->get_active() != -1)
2119 {
2120 SfxStringItem aStyle(SID_STYLE_EDIT, m_xCharStyleLB->get_active_text());
2121 SfxUInt16Item aFamily(SID_STYLE_FAMILY, sal_uInt16(SfxStyleFamily::Char));
2122 static_cast<SwMultiTOXTabDialog*>(GetDialogController())->GetWrtShell().
2123 GetView().GetViewFrame()->GetDispatcher()->ExecuteList(SID_STYLE_EDIT,
2124 SfxCallMode::SYNCHRON,
2125 { &aStyle, &aFamily });
2126 }
2127 }
2128
IMPL_LINK(SwTOXEntryTabPage,RemoveInsertAuthHdl,weld::Button &,rButton,void)2129 IMPL_LINK(SwTOXEntryTabPage, RemoveInsertAuthHdl, weld::Button&, rButton, void)
2130 {
2131 bool bInsert = &rButton == m_xAuthInsertPB.get();
2132 if(bInsert)
2133 {
2134 sal_Int32 nSelPos = m_xAuthFieldsLB->get_active();
2135 const OUString sToInsert(m_xAuthFieldsLB->get_active_text());
2136 SwFormToken aInsert(TOKEN_AUTHORITY);
2137 aInsert.nAuthorityField = m_xAuthFieldsLB->get_id(nSelPos).toUInt32();
2138 m_xTokenWIN->InsertAtSelection(aInsert);
2139 m_xAuthFieldsLB->remove_text(sToInsert);
2140 m_xAuthFieldsLB->set_active(nSelPos ? nSelPos - 1 : 0);
2141 }
2142 else
2143 {
2144 SwTOXWidget* pCtrl = m_xTokenWIN->GetActiveControl();
2145 OSL_ENSURE(WindowType::EDIT != pCtrl->GetType(), "Remove should be disabled");
2146 if (WindowType::EDIT != pCtrl->GetType())
2147 {
2148 //fill it into the ListBox
2149 const SwFormToken& rToken = static_cast<SwTOXButton*>(pCtrl)->GetFormToken();
2150 PreTokenButtonRemoved(rToken);
2151 m_xTokenWIN->RemoveControl(static_cast<SwTOXButton*>(pCtrl));
2152 }
2153 }
2154 ModifyHdl(nullptr);
2155 }
2156
PreTokenButtonRemoved(const SwFormToken & rToken)2157 void SwTOXEntryTabPage::PreTokenButtonRemoved(const SwFormToken& rToken)
2158 {
2159 //fill it into the ListBox
2160 sal_uInt32 nData = rToken.nAuthorityField;
2161 m_xAuthFieldsLB->append(OUString::number(nData), SwResId(STR_AUTH_FIELD_ARY[nData]));
2162 }
2163
SetFocus2theAllBtn()2164 void SwTOXEntryTabPage::SetFocus2theAllBtn()
2165 {
2166 m_xAllLevelsPB->grab_focus();
2167 }
2168
2169 // This function initializes the default value in the Token
2170 // put here the UI dependent initializations
IMPL_LINK(SwTOXEntryTabPage,InsertTokenHdl,weld::Button &,rBtn,void)2171 IMPL_LINK(SwTOXEntryTabPage, InsertTokenHdl, weld::Button&, rBtn, void)
2172 {
2173 OUString sText;
2174 FormTokenType eTokenType = TOKEN_ENTRY_NO;
2175 OUString sCharStyle;
2176 sal_uInt16 nChapterFormat = CF_NUMBER; // i89791
2177 if (&rBtn == m_xEntryNoPB.get())
2178 {
2179 sText = SwForm::GetFormEntryNum();
2180 eTokenType = TOKEN_ENTRY_NO;
2181 }
2182 else if (&rBtn == m_xEntryPB.get())
2183 {
2184 if( TOX_CONTENT == m_pCurrentForm->GetTOXType() )
2185 {
2186 sText = SwForm::GetFormEntryText();
2187 eTokenType = TOKEN_ENTRY_TEXT;
2188 }
2189 else
2190 {
2191 sText = SwForm::GetFormEntry();
2192 eTokenType = TOKEN_ENTRY;
2193 }
2194 }
2195 else if (&rBtn == m_xChapterInfoPB.get())
2196 {
2197 sText = SwForm::GetFormChapterMark();
2198 eTokenType = TOKEN_CHAPTER_INFO;
2199 nChapterFormat = CF_NUM_NOPREPST_TITLE; // i89791
2200 }
2201 else if (&rBtn == m_xPageNoPB.get())
2202 {
2203 sText = SwForm::GetFormPageNums();
2204 eTokenType = TOKEN_PAGE_NUMS;
2205 }
2206 else if (&rBtn == m_xHyperLinkPB.get())
2207 {
2208 sText = SwForm::GetFormLinkStt();
2209 eTokenType = TOKEN_LINK_START;
2210 sCharStyle = SwResId(STR_POOLCHR_TOXJUMP);
2211 }
2212 else if (&rBtn == m_xTabPB.get())
2213 {
2214 sText = SwForm::GetFormTab();
2215 eTokenType = TOKEN_TAB_STOP;
2216 }
2217 SwFormToken aInsert(eTokenType);
2218 aInsert.sCharStyleName = sCharStyle;
2219 aInsert.nTabStopPosition = 0;
2220 aInsert.nChapterFormat = nChapterFormat; // i89791
2221 m_xTokenWIN->InsertAtSelection(aInsert);
2222 ModifyHdl(nullptr);
2223 }
2224
IMPL_LINK_NOARG(SwTOXEntryTabPage,AllLevelsHdl,weld::Button &,void)2225 IMPL_LINK_NOARG(SwTOXEntryTabPage, AllLevelsHdl, weld::Button&, void)
2226 {
2227 //get current level
2228 //write it into all levels
2229 if(m_xTokenWIN->IsValid())
2230 {
2231 const OUString sNewToken = m_xTokenWIN->GetPattern();
2232 for(sal_uInt16 i = 1; i < m_pCurrentForm->GetFormMax(); i++)
2233 m_pCurrentForm->SetPattern(i, sNewToken);
2234
2235 OnModify(true);
2236 }
2237 }
2238
WriteBackLevel()2239 void SwTOXEntryTabPage::WriteBackLevel()
2240 {
2241 if(m_xTokenWIN->IsValid())
2242 {
2243 const OUString sNewToken = m_xTokenWIN->GetPattern();
2244 const sal_uInt16 nLastLevel = m_xTokenWIN->GetLastLevel();
2245 if(nLastLevel != USHRT_MAX)
2246 m_pCurrentForm->SetPattern(nLastLevel + 1, sNewToken);
2247 }
2248 }
2249
IMPL_LINK(SwTOXEntryTabPage,LevelHdl,weld::TreeView &,rBox,void)2250 IMPL_LINK(SwTOXEntryTabPage, LevelHdl, weld::TreeView&, rBox, void)
2251 {
2252 if(bInLevelHdl)
2253 return;
2254 bInLevelHdl = true;
2255 WriteBackLevel();
2256
2257 const sal_uInt16 nLevel = rBox.get_selected_index();
2258 m_xTokenWIN->SetForm(*m_pCurrentForm, nLevel);
2259 if(TOX_AUTHORITIES == m_pCurrentForm->GetTOXType())
2260 {
2261 //fill the types in
2262 m_xAuthFieldsLB->clear();
2263 for( sal_uInt32 i = 0; i < AUTH_FIELD_END; i++)
2264 {
2265 m_xAuthFieldsLB->append(OUString::number(i), SwResId(STR_AUTH_FIELD_ARY[i]));
2266 }
2267
2268 // #i21237#
2269 SwFormTokens aPattern = m_pCurrentForm->GetPattern(nLevel + 1);
2270
2271 for(const auto& aToken : aPattern)
2272 {
2273 if(TOKEN_AUTHORITY == aToken.eTokenType)
2274 {
2275 sal_uInt32 nSearch = aToken.nAuthorityField;
2276 int nLstBoxPos = m_xAuthFieldsLB->find_id(OUString::number(nSearch));
2277 OSL_ENSURE(nLstBoxPos != -1, "Entry not found?");
2278 m_xAuthFieldsLB->remove(nLstBoxPos);
2279 }
2280 }
2281 m_xAuthFieldsLB->set_active(0);
2282 }
2283 bInLevelHdl = false;
2284 rBox.grab_focus();
2285 }
2286
IMPL_LINK_NOARG(SwTOXEntryTabPage,SortKeyHdl,weld::ToggleButton &,void)2287 IMPL_LINK_NOARG(SwTOXEntryTabPage, SortKeyHdl, weld::ToggleButton&, void)
2288 {
2289 bool bEnable = m_xSortContentRB->get_active();
2290 m_xSortKeyFrame->set_sensitive(bEnable);
2291 }
2292
IMPL_LINK(SwTOXEntryTabPage,TokenSelectedHdl,SwFormToken &,rToken,void)2293 IMPL_LINK(SwTOXEntryTabPage, TokenSelectedHdl, SwFormToken&, rToken, void)
2294 {
2295 if (!rToken.sCharStyleName.isEmpty())
2296 m_xCharStyleLB->set_active_text(rToken.sCharStyleName);
2297 else
2298 m_xCharStyleLB->set_active_text(sNoCharStyle);
2299
2300 const OUString sEntry = m_xCharStyleLB->get_active_text();
2301 m_xEditStylePB->set_sensitive(sEntry != sNoCharStyle);
2302
2303 if(rToken.eTokenType == TOKEN_CHAPTER_INFO)
2304 {
2305 //---> i89791
2306 switch(rToken.nChapterFormat)
2307 {
2308 default:
2309 m_xChapterEntryLB->set_active(-1);//to alert the user
2310 break;
2311 case CF_NUM_NOPREPST_TITLE:
2312 m_xChapterEntryLB->set_active(0);
2313 break;
2314 case CF_TITLE:
2315 m_xChapterEntryLB->set_active(1);
2316 break;
2317 case CF_NUMBER_NOPREPST:
2318 m_xChapterEntryLB->set_active(2);
2319 break;
2320 }
2321 //i53420
2322
2323 m_xEntryOutlineLevelNF->set_value(rToken.nOutlineLevel);
2324 }
2325
2326 //i53420
2327 if(rToken.eTokenType == TOKEN_ENTRY_NO)
2328 {
2329 m_xEntryOutlineLevelNF->set_value(rToken.nOutlineLevel);
2330 const sal_uInt16 nFormat =
2331 rToken.nChapterFormat == CF_NUM_NOPREPST_TITLE ? 1 : 0;
2332 m_xNumberFormatLB->set_active(nFormat);
2333 }
2334
2335 bool bTabStop = TOKEN_TAB_STOP == rToken.eTokenType;
2336 m_xFillCharFT->set_visible(bTabStop);
2337 m_xFillCharCB->set_visible(bTabStop);
2338 m_xTabPosFT->set_visible(bTabStop);
2339 m_xTabPosMF->set_visible(bTabStop);
2340 m_xAutoRightCB->set_visible(bTabStop);
2341 m_xAutoRightCB->set_sensitive(bTabStop);
2342 if(bTabStop)
2343 {
2344 m_xTabPosMF->set_value(m_xTabPosMF->normalize(rToken.nTabStopPosition), FieldUnit::TWIP);
2345 m_xAutoRightCB->set_active(SvxTabAdjust::End == rToken.eTabAlign);
2346 m_xFillCharCB->set_entry_text(OUString(rToken.cTabFillChar));
2347 m_xTabPosFT->set_sensitive(!m_xAutoRightCB->get_active());
2348 m_xTabPosMF->set_sensitive(!m_xAutoRightCB->get_active());
2349 }
2350 else
2351 {
2352 m_xTabPosMF->set_sensitive(false);
2353 }
2354
2355 bool bIsChapterInfo = rToken.eTokenType == TOKEN_CHAPTER_INFO;
2356 bool bIsEntryNumber = rToken.eTokenType == TOKEN_ENTRY_NO;
2357 m_xChapterEntryFT->set_visible( bIsChapterInfo );
2358 m_xChapterEntryLB->set_visible( bIsChapterInfo );
2359 m_xEntryOutlineLevelFT->set_visible( bIsChapterInfo || bIsEntryNumber );
2360 m_xEntryOutlineLevelNF->set_visible( bIsChapterInfo || bIsEntryNumber );
2361 m_xNumberFormatFT->set_visible( bIsEntryNumber );
2362 m_xNumberFormatLB->set_visible( bIsEntryNumber );
2363
2364 //now enable the visible buttons
2365 //- inserting the same type of control is not allowed
2366 //- some types of controls can only appear once (EntryText EntryNumber)
2367
2368 if (m_xEntryNoPB->get_visible())
2369 {
2370 m_xEntryNoPB->set_sensitive(TOKEN_ENTRY_NO != rToken.eTokenType );
2371 }
2372 if (m_xEntryPB->get_visible())
2373 {
2374 m_xEntryPB->set_sensitive(TOKEN_ENTRY_TEXT != rToken.eTokenType &&
2375 !m_xTokenWIN->Contains(TOKEN_ENTRY_TEXT)
2376 && !m_xTokenWIN->Contains(TOKEN_ENTRY));
2377 }
2378
2379 if (m_xChapterInfoPB->get_visible())
2380 {
2381 m_xChapterInfoPB->set_sensitive(TOKEN_CHAPTER_INFO != rToken.eTokenType);
2382 }
2383 if (m_xPageNoPB->get_visible())
2384 {
2385 m_xPageNoPB->set_sensitive(TOKEN_PAGE_NUMS != rToken.eTokenType &&
2386 !m_xTokenWIN->Contains(TOKEN_PAGE_NUMS));
2387 }
2388 if (m_xTabPB->get_visible())
2389 {
2390 m_xTabPB->set_sensitive(!bTabStop);
2391 }
2392 if (m_xHyperLinkPB->get_visible())
2393 {
2394 m_xHyperLinkPB->set_sensitive(TOKEN_LINK_START != rToken.eTokenType &&
2395 TOKEN_LINK_END != rToken.eTokenType);
2396 }
2397 //table of authorities
2398 if (m_xAuthInsertPB->get_visible())
2399 {
2400 bool bText = TOKEN_TEXT == rToken.eTokenType;
2401 m_xAuthInsertPB->set_sensitive(bText && !m_xAuthFieldsLB->get_active_text().isEmpty());
2402 m_xAuthRemovePB->set_sensitive(!bText);
2403 }
2404 }
2405
IMPL_LINK(SwTOXEntryTabPage,StyleSelectHdl,weld::ComboBox &,rBox,void)2406 IMPL_LINK(SwTOXEntryTabPage, StyleSelectHdl, weld::ComboBox&, rBox, void)
2407 {
2408 OUString sEntry = rBox.get_active_text();
2409 const sal_uInt16 nId = rBox.get_active_id().toUInt32();
2410 const bool bEqualsNoCharStyle = sEntry == sNoCharStyle;
2411 m_xEditStylePB->set_sensitive(!bEqualsNoCharStyle);
2412 if (bEqualsNoCharStyle)
2413 sEntry.clear();
2414 SwTOXWidget* pCtrl = m_xTokenWIN->GetActiveControl();
2415 OSL_ENSURE(pCtrl, "no active control?");
2416 if(pCtrl)
2417 {
2418 if(WindowType::EDIT == pCtrl->GetType())
2419 static_cast<SwTOXEdit*>(pCtrl)->SetCharStyleName(sEntry, nId);
2420 else
2421 static_cast<SwTOXButton*>(pCtrl)->SetCharStyleName(sEntry, nId);
2422
2423 }
2424 ModifyHdl(nullptr);
2425 }
2426
IMPL_LINK(SwTOXEntryTabPage,ChapterInfoHdl,weld::ComboBox &,rBox,void)2427 IMPL_LINK(SwTOXEntryTabPage, ChapterInfoHdl, weld::ComboBox&, rBox, void)
2428 {
2429 int nPos = rBox.get_active();
2430 if (nPos != -1)
2431 {
2432 SwTOXWidget* pCtrl = m_xTokenWIN->GetActiveControl();
2433 OSL_ENSURE(pCtrl, "no active control?");
2434 if(pCtrl && WindowType::EDIT != pCtrl->GetType())
2435 static_cast<SwTOXButton*>(pCtrl)->SetChapterInfo(nPos);
2436 ModifyHdl(nullptr);
2437 }
2438 }
2439
IMPL_LINK(SwTOXEntryTabPage,ChapterInfoOutlineHdl,weld::SpinButton &,rEdit,void)2440 IMPL_LINK(SwTOXEntryTabPage, ChapterInfoOutlineHdl, weld::SpinButton&, rEdit, void)
2441 {
2442 const sal_uInt16 nLevel = rEdit.get_value();
2443
2444 SwTOXWidget* pCtrl = m_xTokenWIN->GetActiveControl();
2445 OSL_ENSURE(pCtrl, "no active control?");
2446 if(pCtrl && WindowType::EDIT != pCtrl->GetType())
2447 static_cast<SwTOXButton*>(pCtrl)->SetOutlineLevel(nLevel);
2448
2449 ModifyHdl(nullptr);
2450 }
2451
IMPL_LINK(SwTOXEntryTabPage,NumberFormatHdl,weld::ComboBox &,rBox,void)2452 IMPL_LINK(SwTOXEntryTabPage, NumberFormatHdl, weld::ComboBox&, rBox, void)
2453 {
2454 const sal_Int32 nPos = rBox.get_active();
2455 if (nPos != -1)
2456 {
2457 SwTOXWidget* pCtrl = m_xTokenWIN->GetActiveControl();
2458 OSL_ENSURE(pCtrl, "no active control?");
2459 if(pCtrl && WindowType::EDIT != pCtrl->GetType())
2460 {
2461 static_cast<SwTOXButton*>(pCtrl)->SetEntryNumberFormat(nPos);//i89791
2462 }
2463 ModifyHdl(nullptr);
2464 }
2465 }
2466
IMPL_LINK(SwTOXEntryTabPage,TabPosHdl,weld::MetricSpinButton &,rEdit,void)2467 IMPL_LINK(SwTOXEntryTabPage, TabPosHdl, weld::MetricSpinButton&, rEdit, void)
2468 {
2469 SwTOXWidget* pCtrl = m_xTokenWIN->GetActiveControl();
2470 OSL_ENSURE(pCtrl && WindowType::EDIT != pCtrl->GetType() &&
2471 TOKEN_TAB_STOP == static_cast<SwTOXButton*>(pCtrl)->GetFormToken().eTokenType,
2472 "no active style::TabStop control?");
2473 if( pCtrl && WindowType::EDIT != pCtrl->GetType() )
2474 {
2475 static_cast<SwTOXButton*>(pCtrl)->SetTabPosition( static_cast< SwTwips >(
2476 rEdit.denormalize(rEdit.get_value(FieldUnit::TWIP))));
2477 }
2478 ModifyHdl(nullptr);
2479 }
2480
IMPL_LINK(SwTOXEntryTabPage,FillCharHdl,weld::ComboBox &,rBox,void)2481 IMPL_LINK(SwTOXEntryTabPage, FillCharHdl, weld::ComboBox&, rBox, void)
2482 {
2483 SwTOXWidget* pCtrl = m_xTokenWIN->GetActiveControl();
2484 OSL_ENSURE(pCtrl && WindowType::EDIT != pCtrl->GetType() &&
2485 TOKEN_TAB_STOP == static_cast<SwTOXButton*>(pCtrl)->GetFormToken().eTokenType,
2486 "no active style::TabStop control?");
2487 if (pCtrl && WindowType::EDIT != pCtrl->GetType())
2488 {
2489 sal_Unicode cSet;
2490 if (!rBox.get_active_text().isEmpty())
2491 cSet = rBox.get_active_text()[0];
2492 else
2493 cSet = ' ';
2494 static_cast<SwTOXButton*>(pCtrl)->SetFillChar( cSet );
2495 }
2496 ModifyHdl(nullptr);
2497 }
2498
IMPL_LINK(SwTOXEntryTabPage,AutoRightHdl,weld::ToggleButton &,rBox,void)2499 IMPL_LINK(SwTOXEntryTabPage, AutoRightHdl, weld::ToggleButton&, rBox, void)
2500 {
2501 //the most right style::TabStop is usually right aligned
2502 SwTOXWidget* pCurCtrl = m_xTokenWIN->GetActiveControl();
2503 OSL_ENSURE(WindowType::EDIT != pCurCtrl->GetType() &&
2504 static_cast<SwTOXButton*>(pCurCtrl)->GetFormToken().eTokenType == TOKEN_TAB_STOP,
2505 "no style::TabStop selected!");
2506
2507 const SwFormToken& rToken = static_cast<SwTOXButton*>(pCurCtrl)->GetFormToken();
2508 bool bChecked = rBox.get_active();
2509 if(rToken.eTokenType == TOKEN_TAB_STOP)
2510 static_cast<SwTOXButton*>(pCurCtrl)->SetTabAlign(
2511 bChecked ? SvxTabAdjust::End : SvxTabAdjust::Left);
2512 m_xTabPosFT->set_sensitive(!bChecked);
2513 m_xTabPosMF->set_sensitive(!bChecked);
2514 ModifyHdl(nullptr);
2515 }
2516
SetWrtShell(SwWrtShell & rSh)2517 void SwTOXEntryTabPage::SetWrtShell(SwWrtShell& rSh)
2518 {
2519 SwDocShell* pDocSh = rSh.GetView().GetDocShell();
2520 ::FillCharStyleListBox(*m_xCharStyleLB, pDocSh, true, true);
2521 const OUString sDefault(SwResId(STR_POOLCOLL_STANDARD));
2522 for (int i = 0, nCount = m_xCharStyleLB->get_count(); i < nCount; ++i)
2523 {
2524 const OUString sEntry = m_xCharStyleLB->get_text(i);
2525 if(sDefault != sEntry)
2526 {
2527 m_xMainEntryStyleLB->append(m_xCharStyleLB->get_id(i), sEntry);
2528 }
2529 }
2530 m_xMainEntryStyleLB->set_active_text(SwStyleNameMapper::GetUIName(
2531 RES_POOLCHR_IDX_MAIN_ENTRY, OUString()));
2532 }
2533
2534 static const char* STR_TOKEN_ARY[] =
2535 {
2536 STR_TOKEN_ENTRY_NO,
2537 STR_TOKEN_ENTRY, //mapped from original STR_TOKEN_ENTRY_TEXT,
2538 STR_TOKEN_ENTRY,
2539 STR_TOKEN_TAB_STOP,
2540 nullptr,
2541 STR_TOKEN_PAGE_NUMS,
2542 STR_TOKEN_CHAPTER_INFO,
2543 STR_TOKEN_LINK_START,
2544 STR_TOKEN_LINK_END,
2545 STR_TOKEN_AUTHORITY
2546 };
2547
2548 static const char* STR_TOKEN_HELP_ARY[] =
2549 {
2550 STR_TOKEN_HELP_ENTRY_NO,
2551 STR_TOKEN_HELP_ENTRY, // mapped from original STR_TOKEN_HELP_ENTRY_TEXT,
2552 STR_TOKEN_HELP_ENTRY,
2553 STR_TOKEN_HELP_TAB_STOP,
2554 STR_TOKEN_HELP_TEXT,
2555 STR_TOKEN_HELP_PAGE_NUMS,
2556 STR_TOKEN_HELP_CHAPTER_INFO,
2557 STR_TOKEN_HELP_LINK_START,
2558 STR_TOKEN_HELP_LINK_END,
2559 STR_TOKEN_HELP_AUTHORITY
2560 };
2561
SwTokenWindow(std::unique_ptr<weld::Container> xParent)2562 SwTokenWindow::SwTokenWindow(std::unique_ptr<weld::Container> xParent)
2563 : m_pForm(nullptr)
2564 , m_nLevel(0)
2565 , m_bValid(false)
2566 , m_sCharStyle(SwResId(STR_CHARSTYLE))
2567 , m_pActiveCtrl(nullptr)
2568 , m_pParent(nullptr)
2569 , m_xParentWidget(std::move(xParent))
2570 , m_xBuilder(Application::CreateBuilder(m_xParentWidget.get(), "modules/swriter/ui/tokenwidget.ui"))
2571 , m_xContainer(m_xBuilder->weld_container("TokenWidget"))
2572 , m_xLeftScrollWin(m_xBuilder->weld_button("left"))
2573 , m_xCtrlParentWin(m_xBuilder->weld_container("ctrl"))
2574 , m_xScrollWin(m_xBuilder->weld_scrolled_window("scrollwin"))
2575 , m_xRightScrollWin(m_xBuilder->weld_button("right"))
2576 {
2577 m_xScrollWin->connect_hadjustment_changed(LINK(this, SwTokenWindow, ScrollHdl));
2578 m_xCtrlParentWin->set_size_request(-1, Edit::GetMinimumEditSize().Height());
2579 m_xCtrlParentWin->connect_size_allocate(LINK(this, SwTokenWindow, AdjustPositionsHdl));
2580
2581 for (sal_uInt32 i = 0; i < TOKEN_END; ++i)
2582 {
2583 const char* pTextId = STR_TOKEN_ARY[i];
2584 if (pTextId)
2585 m_aButtonTexts[i] = SwResId(pTextId);
2586
2587 const char* pHelpId = STR_TOKEN_HELP_ARY[i];
2588 m_aButtonHelpTexts[i] = SwResId(pHelpId);
2589 }
2590
2591 m_sAccessibleName = SwResId(STR_STRUCTURE);
2592 m_sAdditionalAccnameString1 = SwResId(STR_ADDITIONAL_ACCNAME_STRING1);
2593 m_sAdditionalAccnameString2 = SwResId(STR_ADDITIONAL_ACCNAME_STRING2);
2594 m_sAdditionalAccnameString3 = SwResId(STR_ADDITIONAL_ACCNAME_STRING3);
2595
2596 Link<weld::Button&,void> aLink(LINK(this, SwTokenWindow, ScrollBtnHdl));
2597 m_xLeftScrollWin->connect_clicked(aLink);
2598 m_xRightScrollWin->connect_clicked(aLink);
2599 }
2600
~SwTokenWindow()2601 SwTokenWindow::~SwTokenWindow()
2602 {
2603 }
2604
SetForm(SwForm & rForm,sal_uInt16 nL)2605 void SwTokenWindow::SetForm(SwForm& rForm, sal_uInt16 nL)
2606 {
2607 SetActiveControl(nullptr);
2608 m_bValid = true;
2609
2610 if (m_pForm)
2611 {
2612 //apply current level settings to the form
2613 m_aControlList.clear();
2614 }
2615
2616 m_nLevel = nL;
2617 m_pForm = &rForm;
2618 //now the display
2619 if(m_nLevel < MAXLEVEL || rForm.GetTOXType() == TOX_AUTHORITIES)
2620 {
2621 // #i21237#
2622 SwFormTokens aPattern = m_pForm->GetPattern(m_nLevel + 1);
2623 bool bLastWasText = false; //assure alternating text - code - text
2624
2625 SwTOXWidget* pSetActiveControl = nullptr;
2626 for (const auto& aToken : aPattern) // #i21237#
2627 {
2628 if(TOKEN_TEXT == aToken.eTokenType)
2629 {
2630 SAL_WARN_IF(bLastWasText, "sw", "text following text is invalid");
2631 SwTOXWidget* pCtrl = InsertItem(aToken.sText, aToken);
2632 bLastWasText = true;
2633 if (!GetActiveControl())
2634 SetActiveControl(pCtrl);
2635 }
2636 else
2637 {
2638 if( !bLastWasText )
2639 {
2640 SwFormToken aTemp(TOKEN_TEXT);
2641 SwTOXWidget* pCtrl = InsertItem(OUString(), aTemp);
2642 if(!pSetActiveControl)
2643 pSetActiveControl = pCtrl;
2644 }
2645
2646 OUString sForm;
2647 switch( aToken.eTokenType )
2648 {
2649 case TOKEN_ENTRY_NO: sForm = SwForm::GetFormEntryNum(); break;
2650 case TOKEN_ENTRY_TEXT: sForm = SwForm::GetFormEntryText(); break;
2651 case TOKEN_ENTRY: sForm = SwForm::GetFormEntry(); break;
2652 case TOKEN_TAB_STOP: sForm = SwForm::GetFormTab(); break;
2653 case TOKEN_PAGE_NUMS: sForm = SwForm::GetFormPageNums(); break;
2654 case TOKEN_CHAPTER_INFO: sForm = SwForm::GetFormChapterMark(); break;
2655 case TOKEN_LINK_START: sForm = SwForm::GetFormLinkStt(); break;
2656 case TOKEN_LINK_END: sForm = SwForm::GetFormLinkEnd(); break;
2657 case TOKEN_AUTHORITY: sForm = SwForm::GetFormAuth(); break;
2658 default:; //prevent warning
2659 }
2660
2661 InsertItem( sForm, aToken );
2662 bLastWasText = false;
2663 }
2664 }
2665 if(!bLastWasText)
2666 {
2667 SwFormToken aTemp(TOKEN_TEXT);
2668 SwTOXWidget* pCtrl = InsertItem(OUString(), aTemp);
2669 if(!pSetActiveControl)
2670 pSetActiveControl = pCtrl;
2671 }
2672 SetActiveControl(pSetActiveControl);
2673 }
2674 AdjustScrolling();
2675 }
2676
SetActiveControl(SwTOXWidget * pSet)2677 void SwTokenWindow::SetActiveControl(SwTOXWidget* pSet)
2678 {
2679 if (pSet != m_pActiveCtrl)
2680 {
2681 m_pActiveCtrl = pSet;
2682 if( m_pActiveCtrl )
2683 {
2684 m_pActiveCtrl->GrabFocus();
2685 //it must be a SwTOXEdit
2686 const SwFormToken* pFToken;
2687 if( WindowType::EDIT == m_pActiveCtrl->GetType() )
2688 pFToken = &static_cast<SwTOXEdit*>(m_pActiveCtrl)->GetFormToken();
2689 else
2690 pFToken = &static_cast<SwTOXButton*>(m_pActiveCtrl)->GetFormToken();
2691
2692 SwFormToken aTemp( *pFToken );
2693 m_aButtonSelectedHdl.Call( aTemp );
2694 }
2695 }
2696 }
2697
InsertItem(const OUString & rText,const SwFormToken & rToken)2698 SwTOXWidget* SwTokenWindow::InsertItem(const OUString& rText, const SwFormToken& rToken)
2699 {
2700 SwTOXWidget* pRet = nullptr;
2701
2702 if (TOKEN_TEXT == rToken.eTokenType)
2703 {
2704 SwTOXEdit* pEdit = new SwTOXEdit(this, rToken);
2705 pEdit->set_grid_left_attach(m_aControlList.size());
2706
2707 m_aControlList.emplace_back(pEdit);
2708
2709 pEdit->SetText(rText);
2710 sal_uInt32 nIndex = GetControlIndex( TOKEN_TEXT );
2711 OUString strName(m_sAccessibleName + OUString::number(nIndex));
2712 if ( nIndex == 1 )
2713 {
2714 /*Press left or right arrow to choose the structure controls*/
2715 strName += " (" + m_sAdditionalAccnameString2 + ", "
2716 /*Press Ctrl+Alt+A to move focus for more operations*/
2717 + m_sAdditionalAccnameString1 + ", "
2718 /*Press Ctrl+Alt+B to move focus back to the current structure control*/
2719 + m_sAdditionalAccnameString3 + ")";
2720 }
2721 pEdit->SetAccessibleName(strName);
2722 pEdit->AdjustSize();
2723 pEdit->SetModifyHdl(LINK(this, SwTokenWindow, EditResize ));
2724 pEdit->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemHdl));
2725 pEdit->SetGetFocusHdl(LINK(this, SwTokenWindow, TbxFocusHdl));
2726 pEdit->Show();
2727 pRet = pEdit;
2728 }
2729 else
2730 {
2731 SwTOXButton* pButton = new SwTOXButton(this, rToken);
2732 pButton->set_grid_left_attach(m_aControlList.size());
2733
2734 m_aControlList.emplace_back(pButton);
2735
2736 pButton->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemBtnHdl));
2737 pButton->SetGetFocusHdl(LINK(this, SwTokenWindow, TbxFocusBtnHdl));
2738
2739 if(TOKEN_AUTHORITY != rToken.eTokenType)
2740 pButton->SetText(m_aButtonTexts[rToken.eTokenType]);
2741 else
2742 {
2743 //use the first two chars as symbol
2744 OUString sTmp(SwAuthorityFieldType::GetAuthFieldName(
2745 static_cast<ToxAuthorityField>(rToken.nAuthorityField)));
2746 pButton->SetText(sTmp.copy(0, 2));
2747 }
2748
2749 sal_uInt32 nIndex = GetControlIndex( rToken.eTokenType );
2750 OUString sAccName = m_aButtonHelpTexts[rToken.eTokenType];
2751 if ( nIndex )
2752 {
2753 sAccName += " " + OUString::number(nIndex);
2754 }
2755 pButton->SetAccessibleName( sAccName );
2756
2757 pButton->Show();
2758 pRet = pButton;
2759 }
2760
2761 return pRet;
2762 }
2763
InsertAtSelection(const SwFormToken & rToken)2764 void SwTokenWindow::InsertAtSelection(const SwFormToken& rToken)
2765 {
2766 OSL_ENSURE(m_pActiveCtrl, "no active control!");
2767
2768 if(!m_pActiveCtrl)
2769 return;
2770
2771 SwFormToken aToInsertToken(rToken);
2772
2773 if(TOKEN_LINK_START == aToInsertToken.eTokenType)
2774 {
2775 //determine if start or end of hyperlink is appropriate
2776 //eventually change a following link start into a link end
2777 // groups of LS LE should be ignored
2778 // <insert>
2779 //LS <insert>
2780 //LE <insert>
2781 //<insert> LS
2782 //<insert> LE
2783 //<insert>
2784 bool bPreStartLinkFound = false;
2785 bool bPreEndLinkFound = false;
2786
2787 const SwTOXWidget* pControl = nullptr;
2788 const SwTOXWidget* pExchange = nullptr;
2789
2790 auto it = m_aControlList.cbegin();
2791 for( ; it != m_aControlList.cend() && m_pActiveCtrl != it->get(); ++it )
2792 {
2793 pControl = it->get();
2794
2795 if( WindowType::EDIT != pControl->GetType())
2796 {
2797 const SwFormToken& rNewToken =
2798 static_cast<const SwTOXButton*>(pControl)->GetFormToken();
2799
2800 if( TOKEN_LINK_START == rNewToken.eTokenType )
2801 {
2802 bPreStartLinkFound = true;
2803 pExchange = nullptr;
2804 }
2805 else if(TOKEN_LINK_END == rNewToken.eTokenType)
2806 {
2807 if( bPreStartLinkFound )
2808 bPreStartLinkFound = false;
2809 else
2810 {
2811 bPreEndLinkFound = false;
2812 pExchange = pControl;
2813 }
2814 }
2815 }
2816 }
2817
2818 bool bPostLinkStartFound = false;
2819
2820 if(!bPreStartLinkFound && !bPreEndLinkFound)
2821 {
2822 for( ; it != m_aControlList.cend(); ++it )
2823 {
2824 pControl = it->get();
2825
2826 if( pControl != m_pActiveCtrl &&
2827 WindowType::EDIT != pControl->GetType())
2828 {
2829 const SwFormToken& rNewToken =
2830 static_cast<const SwTOXButton*>(pControl)->GetFormToken();
2831
2832 if( TOKEN_LINK_START == rNewToken.eTokenType )
2833 {
2834 if(bPostLinkStartFound)
2835 break;
2836 bPostLinkStartFound = true;
2837 pExchange = pControl;
2838 }
2839 else if(TOKEN_LINK_END == rNewToken.eTokenType )
2840 {
2841 if(bPostLinkStartFound)
2842 {
2843 bPostLinkStartFound = false;
2844 pExchange = nullptr;
2845 }
2846 break;
2847 }
2848 }
2849 }
2850 }
2851
2852 if(bPreStartLinkFound)
2853 {
2854 aToInsertToken.eTokenType = TOKEN_LINK_END;
2855 aToInsertToken.sText = m_aButtonTexts[TOKEN_LINK_END];
2856 }
2857
2858 if(bPostLinkStartFound)
2859 {
2860 OSL_ENSURE(pExchange, "no control to exchange?");
2861 if(pExchange)
2862 {
2863 const_cast<SwTOXButton*>(static_cast<const SwTOXButton*>(pExchange))->SetLinkEnd();
2864 const_cast<SwTOXButton*>(static_cast<const SwTOXButton*>(pExchange))->SetText(m_aButtonTexts[TOKEN_LINK_END]);
2865 }
2866 }
2867
2868 if(bPreEndLinkFound)
2869 {
2870 OSL_ENSURE(pExchange, "no control to exchange?");
2871
2872 if(pExchange)
2873 {
2874 const_cast<SwTOXButton*>(static_cast<const SwTOXButton*>(pExchange))->SetLinkStart();
2875 const_cast<SwTOXButton*>(static_cast<const SwTOXButton*>(pExchange))->SetText(m_aButtonTexts[TOKEN_LINK_START]);
2876 }
2877 }
2878 }
2879
2880 //if the active control is text then insert a new button at the selection
2881 //else replace the button
2882 auto iterActive = std::find_if(m_aControlList.begin(), m_aControlList.end(),
2883 [this](const auto& rControl)
2884 {
2885 SwTOXWidget* pCtrl = rControl.get();
2886 return pCtrl == m_pActiveCtrl;
2887 });
2888
2889 assert(iterActive != m_aControlList.end());
2890 if (iterActive == m_aControlList.end())
2891 return;
2892
2893 if (WindowType::EDIT == m_pActiveCtrl->GetType())
2894 {
2895 ++iterActive;
2896
2897 int nStartPos, nEndPos;
2898 static_cast<SwTOXEdit*>(m_pActiveCtrl)->get_selection_bounds(nStartPos, nEndPos);
2899
2900 const OUString sEditText = static_cast<SwTOXEdit*>(m_pActiveCtrl)->GetText();
2901 const OUString sLeft = sEditText.copy( 0, std::min(nStartPos, nEndPos) );
2902 const OUString sRight = sEditText.copy( std::max(nStartPos, nEndPos) );
2903
2904 static_cast<SwTOXEdit*>(m_pActiveCtrl)->SetText(sLeft);
2905 static_cast<SwTOXEdit*>(m_pActiveCtrl)->AdjustSize();
2906
2907 SwFormToken aTmpToken(TOKEN_TEXT);
2908 SwTOXEdit* pEdit = new SwTOXEdit(this, aTmpToken);
2909 iterActive = m_aControlList.emplace(iterActive, pEdit);
2910
2911 pEdit->SetText(sRight);
2912 sal_uInt32 nIndex = GetControlIndex( TOKEN_TEXT );
2913 OUString strName(m_sAccessibleName + OUString::number(nIndex));
2914 if ( nIndex == 1)
2915 {
2916 /*Press left or right arrow to choose the structure controls*/
2917 strName += " (" + m_sAdditionalAccnameString2 + ", "
2918 /*Press Ctrl+Alt+A to move focus for more operations*/
2919 + m_sAdditionalAccnameString1 + ", "
2920 /*Press Ctrl+Alt+B to move focus back to the current structure control*/
2921 + m_sAdditionalAccnameString3 + ")";
2922 }
2923 pEdit->SetAccessibleName(strName);
2924 pEdit->AdjustSize();
2925 pEdit->SetModifyHdl(LINK(this, SwTokenWindow, EditResize ));
2926 pEdit->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemHdl));
2927 pEdit->SetGetFocusHdl(LINK(this, SwTokenWindow, TbxFocusHdl));
2928 pEdit->Show();
2929 }
2930 else
2931 {
2932 m_pActiveCtrl->Hide();
2933 m_pActiveCtrl = nullptr;
2934 iterActive = m_aControlList.erase(iterActive);
2935 }
2936
2937 //now the new button
2938 SwTOXButton* pButton = new SwTOXButton(this, aToInsertToken);
2939 m_aControlList.emplace(iterActive, pButton);
2940
2941 pButton->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemBtnHdl));
2942 pButton->SetGetFocusHdl(LINK(this, SwTokenWindow, TbxFocusBtnHdl));
2943
2944 if (TOKEN_AUTHORITY != aToInsertToken.eTokenType)
2945 {
2946 pButton->SetText(m_aButtonTexts[aToInsertToken.eTokenType]);
2947 }
2948 else
2949 {
2950 //use the first two chars as symbol
2951 OUString sTmp(SwAuthorityFieldType::GetAuthFieldName(
2952 static_cast<ToxAuthorityField>(aToInsertToken.nAuthorityField)));
2953 pButton->SetText(sTmp.copy(0, 2));
2954 }
2955
2956 pButton->Check();
2957 pButton->Show();
2958 SetActiveControl(pButton);
2959
2960 AdjustPositions();
2961 }
2962
RemoveControl(const SwTOXButton * pDel,bool bInternalCall)2963 void SwTokenWindow::RemoveControl(const SwTOXButton* pDel, bool bInternalCall)
2964 {
2965 if (bInternalCall && TOX_AUTHORITIES == m_pForm->GetTOXType())
2966 m_pParent->PreTokenButtonRemoved(pDel->GetFormToken());
2967
2968 auto it = std::find_if(m_aControlList.begin(), m_aControlList.end(),
2969 [pDel](const auto& rControl)
2970 {
2971 SwTOXWidget* pCtrl = rControl.get();
2972 return pCtrl == pDel;
2973 });
2974 assert(it != m_aControlList.end()); //Control does not exist!
2975 if (it == m_aControlList.end())
2976 return;
2977
2978 // the two neighbours of the box must be merged
2979 // the properties of the right one will be lost
2980 assert(it != m_aControlList.begin() && it != m_aControlList.end() - 1); //Button at first or last position?
2981 if (it == m_aControlList.begin() || it == m_aControlList.end() - 1)
2982 return;
2983
2984 auto itLeft = it, itRight = it;
2985 --itLeft;
2986 ++itRight;
2987 SwTOXWidget* pLeftEdit = itLeft->get();
2988 SwTOXWidget* pRightEdit = itRight->get();
2989
2990 static_cast<SwTOXEdit*>(pLeftEdit)->SetText(static_cast<SwTOXEdit*>(pLeftEdit)->GetText() +
2991 static_cast<SwTOXEdit*>(pRightEdit)->GetText());
2992 static_cast<SwTOXEdit*>(pLeftEdit)->AdjustSize();
2993
2994 m_pActiveCtrl->Hide();
2995 m_pActiveCtrl = nullptr;
2996
2997 m_aControlList.erase(itRight);
2998 m_aControlList.erase(it);
2999
3000 SetActiveControl(pLeftEdit);
3001 AdjustPositions();
3002 m_aModifyHdl.Call(nullptr);
3003 }
3004
IMPL_LINK_NOARG(SwTokenWindow,AdjustPositionsHdl,const Size &,void)3005 IMPL_LINK_NOARG(SwTokenWindow, AdjustPositionsHdl, const Size&, void)
3006 {
3007 AdjustScrolling();
3008 }
3009
AdjustPositions()3010 void SwTokenWindow::AdjustPositions()
3011 {
3012 for (size_t i = 0; i < m_aControlList.size(); ++i)
3013 m_aControlList[i]->set_grid_left_attach(i);
3014 AdjustScrolling();
3015 }
3016
MoveControls(long nOffset)3017 void SwTokenWindow::MoveControls(long nOffset)
3018 {
3019 m_xScrollWin->hadjustment_set_value(nOffset);
3020 }
3021
IMPL_LINK_NOARG(SwTokenWindow,ScrollHdl,weld::ScrolledWindow &,void)3022 IMPL_LINK_NOARG(SwTokenWindow, ScrollHdl, weld::ScrolledWindow&, void)
3023 {
3024 AdjustScrolling();
3025 }
3026
AdjustScrolling()3027 void SwTokenWindow::AdjustScrolling()
3028 {
3029 if (m_aControlList.size() > 1)
3030 {
3031 //validate scroll buttons
3032
3033 auto nLeft = m_xScrollWin->hadjustment_get_value();
3034 auto nSpace = m_xScrollWin->hadjustment_get_page_size();
3035 auto nWidth = m_xScrollWin->hadjustment_get_upper();
3036
3037 bool bEnable = nWidth > nSpace;
3038
3039 //the active control must be visible
3040 if (bEnable && m_pActiveCtrl)
3041 {
3042 int x, y, width, height;
3043 m_pActiveCtrl->get_extents_relative_to(*m_xCtrlParentWin, x, y, width, height);
3044
3045 if (x < nLeft || x + width > nLeft + nSpace)
3046 {
3047 MoveControls(x);
3048 nLeft = x;
3049 }
3050
3051 m_xLeftScrollWin->set_sensitive(nLeft > 0);
3052 m_xRightScrollWin->set_sensitive(nLeft + nSpace < nWidth);
3053 }
3054 else
3055 {
3056 //if the control fits into the space then the first control must be at position 0
3057 m_xRightScrollWin->set_sensitive(false);
3058 m_xLeftScrollWin->set_sensitive(false);
3059 }
3060 }
3061 }
3062
IMPL_LINK(SwTokenWindow,ScrollBtnHdl,weld::Button &,rBtn,void)3063 IMPL_LINK(SwTokenWindow, ScrollBtnHdl, weld::Button&, rBtn, void)
3064 {
3065 if (m_aControlList.empty())
3066 return;
3067
3068 const auto nSpace = m_xScrollWin->hadjustment_get_page_size();
3069 const auto nWidth = m_xScrollWin->hadjustment_get_upper();
3070 const auto nLeft = m_xScrollWin->hadjustment_get_value();
3071
3072 long nMove = nLeft;
3073 if (&rBtn == m_xLeftScrollWin.get())
3074 {
3075 //find the first completely visible control (left edge visible)
3076 auto it = std::find_if(m_aControlList.begin(), m_aControlList.end(),
3077 [this, nLeft](const auto& rControl)
3078 {
3079 SwTOXWidget* pCtrl = rControl.get();
3080
3081 int x, y, width, height;
3082 pCtrl->get_extents_relative_to(*m_xCtrlParentWin, x, y, width, height);
3083
3084 return x >= nLeft;
3085 });
3086 if (it != m_aControlList.end())
3087 {
3088 if (it == m_aControlList.begin())
3089 {
3090 nMove = 0;
3091 }
3092 else
3093 {
3094 //move the left neighbor to the start position
3095 auto itLeft = it;
3096 --itLeft;
3097 SwTOXWidget* pLeft = itLeft->get();
3098
3099 int x, y, width, height;
3100 pLeft->get_extents_relative_to(*m_xCtrlParentWin, x, y, width, height);
3101
3102 nMove = x;
3103 }
3104 }
3105 }
3106 else
3107 {
3108 //find the first completely visible control (right edge visible)
3109 auto it = std::find_if(m_aControlList.rbegin(), m_aControlList.rend(),
3110 [this, nLeft, nSpace](const auto& rControl) {
3111 SwTOXWidget* pCtrl = rControl.get();
3112
3113 int x, y, width, height;
3114 pCtrl->get_extents_relative_to(*m_xCtrlParentWin, x, y, width, height);
3115
3116 auto nXPos = x + width;
3117 return nXPos <= nLeft + nSpace;
3118 });
3119 if (it != m_aControlList.rend() && it != m_aControlList.rbegin())
3120 {
3121 //move the right neighbor to the right edge right aligned
3122 auto itRight = it;
3123 --itRight;
3124 SwTOXWidget* pRight = itRight->get();
3125
3126 int x, y, width, height;
3127 pRight->get_extents_relative_to(*m_xCtrlParentWin, x, y, width, height);
3128
3129 nMove = x + width - nSpace;
3130 }
3131
3132 //move it left until it's completely visible
3133 }
3134
3135 if (nMove != nLeft)
3136 {
3137 // move the complete list
3138 MoveControls(nMove);
3139 m_xLeftScrollWin->set_sensitive(nMove > 0);
3140 m_xRightScrollWin->set_sensitive(nMove + nSpace < nWidth);
3141 }
3142 }
3143
GetPattern() const3144 OUString SwTokenWindow::GetPattern() const
3145 {
3146 OUStringBuffer sRet;
3147
3148 for (const auto& elem : m_aControlList)
3149 {
3150 const SwTOXWidget* pCtrl = elem.get();
3151
3152 const SwFormToken &rNewToken = pCtrl->GetType() == WindowType::EDIT
3153 ? const_cast<SwTOXEdit*>(static_cast<const SwTOXEdit*>(pCtrl))->GetFormToken()
3154 : static_cast<const SwTOXButton*>(pCtrl)->GetFormToken();
3155
3156 //TODO: prevent input of TOX_STYLE_DELIMITER in KeyInput
3157 sRet.append(rNewToken.GetString());
3158 }
3159
3160 return sRet.makeStringAndClear();
3161 }
3162
3163 // Check if a control of the specified TokenType is already contained in the list
Contains(FormTokenType eSearchFor) const3164 bool SwTokenWindow::Contains(FormTokenType eSearchFor) const
3165 {
3166 bool bRet = false;
3167
3168 for (const auto& elem : m_aControlList)
3169 {
3170 const SwTOXWidget* pCtrl = elem.get();
3171 const SwFormToken &rNewToken = pCtrl->GetType() == WindowType::EDIT
3172 ? const_cast<SwTOXEdit*>(static_cast<const SwTOXEdit*>(pCtrl))->GetFormToken()
3173 : static_cast<const SwTOXButton*>(pCtrl)->GetFormToken();
3174
3175 if (eSearchFor == rNewToken.eTokenType)
3176 {
3177 bRet = true;
3178 break;
3179 }
3180 }
3181
3182 return bRet;
3183 }
3184
CreateQuickHelp(const SwFormToken & rToken)3185 OUString SwTokenWindow::CreateQuickHelp(const SwFormToken& rToken)
3186 {
3187 OUString sEntry;
3188 if (rToken.eTokenType != TOKEN_AUTHORITY)
3189 sEntry = m_aButtonHelpTexts[rToken.eTokenType];
3190 else
3191 {
3192 sEntry += SwAuthorityFieldType::GetAuthFieldName(
3193 static_cast<ToxAuthorityField>(rToken.nAuthorityField));
3194 }
3195
3196 if (rToken.eTokenType != TOKEN_TAB_STOP)
3197 {
3198 if (!rToken.sCharStyleName.isEmpty())
3199 {
3200 sEntry += " " + m_sCharStyle + rToken.sCharStyleName;
3201 }
3202 }
3203
3204 return sEntry;
3205 }
3206
IMPL_LINK(SwTokenWindow,EditResize,SwTOXEdit &,rEdit,void)3207 IMPL_LINK(SwTokenWindow, EditResize, SwTOXEdit&, rEdit, void)
3208 {
3209 rEdit.AdjustSize();
3210 AdjustPositions();
3211 m_aModifyHdl.Call(nullptr);
3212 }
3213
IMPL_LINK(SwTokenWindow,NextItemHdl,SwTOXEdit &,rEdit,void)3214 IMPL_LINK(SwTokenWindow, NextItemHdl, SwTOXEdit&, rEdit, void)
3215 {
3216 auto it = std::find_if(m_aControlList.begin(), m_aControlList.end(),
3217 [&rEdit](const auto& rControl)
3218 {
3219 SwTOXWidget* pCtrl = rControl.get();
3220 return pCtrl == &rEdit;
3221 });
3222
3223 if (it == m_aControlList.end())
3224 return;
3225
3226 auto itTest = it;
3227 ++itTest;
3228
3229 if ((it != m_aControlList.begin() && !rEdit.IsNextControl()) ||
3230 (itTest != m_aControlList.end() && rEdit.IsNextControl()))
3231 {
3232 auto iterFocus = it;
3233 rEdit.IsNextControl() ? ++iterFocus : --iterFocus;
3234
3235 SwTOXWidget *pCtrlFocus = iterFocus->get();
3236 pCtrlFocus->GrabFocus();
3237 static_cast<SwTOXButton*>(pCtrlFocus)->Check();
3238
3239 AdjustScrolling();
3240 }
3241 }
3242
IMPL_LINK(SwTokenWindow,TbxFocusHdl,SwTOXWidget &,rControl,void)3243 IMPL_LINK(SwTokenWindow, TbxFocusHdl, SwTOXWidget&, rControl, void)
3244 {
3245 SwTOXEdit* pEdit = static_cast<SwTOXEdit*>(&rControl);
3246 for (const auto& aControl : m_aControlList)
3247 {
3248 SwTOXWidget* pCtrl = aControl.get();
3249 if (pCtrl && pCtrl->GetType() != WindowType::EDIT)
3250 static_cast<SwTOXButton*>(pCtrl)->Check(false);
3251 }
3252
3253 SetActiveControl(pEdit);
3254 }
3255
IMPL_LINK(SwTokenWindow,NextItemBtnHdl,SwTOXButton &,rBtn,void)3256 IMPL_LINK(SwTokenWindow, NextItemBtnHdl, SwTOXButton&, rBtn, void )
3257 {
3258 auto it = std::find_if(m_aControlList.begin(), m_aControlList.end(),
3259 [&rBtn](const auto& rControl)
3260 {
3261 SwTOXWidget* pCtrl = rControl.get();
3262 return pCtrl == &rBtn;
3263 });
3264
3265 if (it == m_aControlList.end())
3266 return;
3267
3268 auto itTest = it;
3269 ++itTest;
3270
3271 if (!rBtn.IsNextControl() || (itTest != m_aControlList.end() && rBtn.IsNextControl()))
3272 {
3273 bool isNext = rBtn.IsNextControl();
3274
3275 auto iterFocus = it;
3276 isNext ? ++iterFocus : --iterFocus;
3277
3278 SwTOXWidget* pCtrlFocus = iterFocus->get();
3279 pCtrlFocus->GrabFocus();
3280 int nStartPos(0), nEndPos(0);
3281
3282 if (!isNext)
3283 {
3284 const sal_Int32 nLen = static_cast<SwTOXEdit*>(pCtrlFocus)->GetText().getLength();
3285
3286 nStartPos = nLen;
3287 nEndPos = nLen;
3288 }
3289
3290 static_cast<SwTOXEdit*>(pCtrlFocus)->select_region(nStartPos, nEndPos);
3291
3292 rBtn.Check(false);
3293
3294 AdjustScrolling();
3295 }
3296 }
3297
IMPL_LINK(SwTokenWindow,TbxFocusBtnHdl,SwTOXWidget &,rControl,void)3298 IMPL_LINK(SwTokenWindow, TbxFocusBtnHdl, SwTOXWidget&, rControl, void)
3299 {
3300 SwTOXButton* pBtn = static_cast<SwTOXButton*>(&rControl);
3301 for (const auto& aControl : m_aControlList)
3302 {
3303 SwTOXWidget* pControl = aControl.get();
3304
3305 if (pControl && WindowType::EDIT != pControl->GetType())
3306 static_cast<SwTOXButton*>(pControl)->Check(pBtn == pControl);
3307 }
3308
3309 SetActiveControl(pBtn);
3310 }
3311
SetFocus2theAllBtn()3312 void SwTokenWindow::SetFocus2theAllBtn()
3313 {
3314 if (m_pParent)
3315 {
3316 m_pParent->SetFocus2theAllBtn();
3317 }
3318 }
3319
GetControlIndex(FormTokenType eType) const3320 sal_uInt32 SwTokenWindow::GetControlIndex(FormTokenType eType) const
3321 {
3322 //there are only one entry-text button and only one page-number button,
3323 //so we need not add index for these two buttons.
3324 if ( eType == TOKEN_ENTRY_TEXT || eType == TOKEN_PAGE_NUMS )
3325 {
3326 return 0;
3327 }
3328
3329 sal_uInt32 nIndex = 0;
3330 for (const auto& elem : m_aControlList)
3331 {
3332 const SwTOXWidget* pControl = elem.get();
3333
3334 const SwFormToken& rNewToken = WindowType::EDIT == pControl->GetType()
3335 ? const_cast<SwTOXEdit*>(static_cast<const SwTOXEdit*>(pControl))->GetFormToken()
3336 : static_cast<const SwTOXButton*>(pControl)->GetFormToken();
3337
3338 if(eType == rNewToken.eTokenType)
3339 {
3340 ++nIndex;
3341 }
3342 }
3343
3344 return nIndex;
3345 }
3346
SwTOXStylesTabPage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet & rAttrSet)3347 SwTOXStylesTabPage::SwTOXStylesTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rAttrSet)
3348 : SfxTabPage(pPage, pController, "modules/swriter/ui/tocstylespage.ui", "TocStylesPage", &rAttrSet)
3349 , m_xLevelLB(m_xBuilder->weld_tree_view("levels"))
3350 , m_xAssignBT(m_xBuilder->weld_button("assign"))
3351 , m_xParaLayLB(m_xBuilder->weld_tree_view("styles"))
3352 , m_xStdBT(m_xBuilder->weld_button("default"))
3353 , m_xEditStyleBT(m_xBuilder->weld_button("edit"))
3354 {
3355 m_xParaLayLB->make_sorted();
3356 auto nHeight = m_xLevelLB->get_height_rows(16);
3357 m_xLevelLB->set_size_request(-1, nHeight);
3358 m_xParaLayLB->set_size_request(-1, nHeight);
3359
3360 SetExchangeSupport();
3361
3362 m_xEditStyleBT->connect_clicked(LINK(this, SwTOXStylesTabPage, EditStyleHdl));
3363 m_xAssignBT->connect_clicked(LINK(this, SwTOXStylesTabPage, AssignHdl));
3364 m_xStdBT->connect_clicked(LINK(this, SwTOXStylesTabPage, StdHdl));
3365 m_xParaLayLB->connect_changed(LINK(this, SwTOXStylesTabPage, EnableSelectHdl));
3366 m_xLevelLB->connect_changed(LINK(this, SwTOXStylesTabPage, EnableSelectHdl));
3367 m_xParaLayLB->connect_row_activated(LINK(this, SwTOXStylesTabPage, DoubleClickHdl));
3368 }
3369
~SwTOXStylesTabPage()3370 SwTOXStylesTabPage::~SwTOXStylesTabPage()
3371 {
3372 }
3373
FillItemSet(SfxItemSet *)3374 bool SwTOXStylesTabPage::FillItemSet( SfxItemSet* )
3375 {
3376 return true;
3377 }
3378
Reset(const SfxItemSet * rSet)3379 void SwTOXStylesTabPage::Reset( const SfxItemSet* rSet )
3380 {
3381 ActivatePage(*rSet);
3382 }
3383
ActivatePage(const SfxItemSet &)3384 void SwTOXStylesTabPage::ActivatePage( const SfxItemSet& )
3385 {
3386 m_pCurrentForm.reset(new SwForm(GetForm()));
3387
3388 // not hyperlink for user directories
3389 const sal_uInt16 nSize = m_pCurrentForm->GetFormMax();
3390
3391 // display form pattern without title
3392
3393 m_xLevelLB->freeze();
3394 m_xLevelLB->clear();
3395 // display 1st TemplateEntry
3396 OUString aStr( SwResId( STR_TITLE ));
3397 if( !m_pCurrentForm->GetTemplate( 0 ).isEmpty() )
3398 {
3399 aStr += " " + OUStringChar(aDeliStart)
3400 + m_pCurrentForm->GetTemplate( 0 )
3401 + OUStringChar(aDeliEnd);
3402 }
3403 m_xLevelLB->append_text(aStr);
3404
3405 for( sal_uInt16 i=1; i < nSize; ++i )
3406 {
3407 if( TOX_INDEX == m_pCurrentForm->GetTOXType() &&
3408 FORM_ALPHA_DELIMITER == i )
3409 {
3410 aStr = SwResId(STR_ALPHA);
3411 }
3412 else
3413 {
3414 aStr = SwResId(STR_LEVEL) + OUString::number(
3415 TOX_INDEX == m_pCurrentForm->GetTOXType() ? i - 1 : i );
3416 }
3417 if( !m_pCurrentForm->GetTemplate( i ).isEmpty() )
3418 {
3419 aStr += " " + OUStringChar(aDeliStart)
3420 + m_pCurrentForm->GetTemplate( i )
3421 + OUStringChar(aDeliEnd);
3422 }
3423 m_xLevelLB->append_text(aStr);
3424 }
3425 m_xLevelLB->thaw();
3426
3427 // initialise templates
3428 SwWrtShell& rSh = static_cast<SwMultiTOXTabDialog*>(GetDialogController())->GetWrtShell();
3429 const sal_uInt16 nSz = rSh.GetTextFormatCollCount();
3430
3431 m_xParaLayLB->freeze();
3432 m_xParaLayLB->clear();
3433 for( sal_uInt16 i = 0; i < nSz; ++i )
3434 {
3435 const SwTextFormatColl *pColl = &rSh.GetTextFormatColl( i );
3436 if( !pColl->IsDefault() )
3437 m_xParaLayLB->append_text( pColl->GetName() );
3438 }
3439
3440 // query pool collections and set them for the directory
3441 for( sal_uInt16 i = 0; i < m_pCurrentForm->GetFormMax(); ++i )
3442 {
3443 aStr = m_pCurrentForm->GetTemplate( i );
3444 if (!aStr.isEmpty() && m_xParaLayLB->find_text(aStr) == -1)
3445 m_xParaLayLB->append_text(aStr);
3446 }
3447 m_xParaLayLB->thaw();
3448
3449 EnableSelectHdl(*m_xParaLayLB);
3450 }
3451
DeactivatePage(SfxItemSet *)3452 DeactivateRC SwTOXStylesTabPage::DeactivatePage( SfxItemSet* /*pSet*/ )
3453 {
3454 GetForm() = *m_pCurrentForm;
3455 return DeactivateRC::LeavePage;
3456 }
3457
Create(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * rAttrSet)3458 std::unique_ptr<SfxTabPage> SwTOXStylesTabPage::Create(weld::Container* pPage, weld::DialogController* pController,
3459 const SfxItemSet* rAttrSet)
3460 {
3461 return std::make_unique<SwTOXStylesTabPage>(pPage, pController, *rAttrSet);
3462 }
3463
IMPL_LINK_NOARG(SwTOXStylesTabPage,EditStyleHdl,weld::Button &,void)3464 IMPL_LINK_NOARG(SwTOXStylesTabPage, EditStyleHdl, weld::Button&, void)
3465 {
3466 if (m_xParaLayLB->get_selected_index() != -1)
3467 {
3468 SfxStringItem aStyle(SID_STYLE_EDIT, m_xParaLayLB->get_selected_text());
3469 SfxUInt16Item aFamily(SID_STYLE_FAMILY, sal_uInt16(SfxStyleFamily::Para));
3470 SwWrtShell& rSh = static_cast<SwMultiTOXTabDialog*>(GetDialogController())->GetWrtShell();
3471 rSh.GetView().GetViewFrame()->GetDispatcher()->ExecuteList(SID_STYLE_EDIT,
3472 SfxCallMode::SYNCHRON,
3473 { &aStyle, &aFamily });
3474 }
3475 }
3476
3477 // allocate templates
IMPL_LINK_NOARG(SwTOXStylesTabPage,AssignHdl,weld::Button &,void)3478 IMPL_LINK_NOARG(SwTOXStylesTabPage, AssignHdl, weld::Button&, void)
3479 {
3480 auto nLevPos = m_xLevelLB->get_selected_index();
3481 auto nTemplPos = m_xParaLayLB->get_selected_index();
3482 if (nLevPos != -1 && nTemplPos != -1)
3483 {
3484 const OUString aStr(m_xLevelLB->get_text(nLevPos).getToken(0, aDeliStart)
3485 + OUStringChar(aDeliStart)
3486 + m_xParaLayLB->get_selected_text()
3487 + OUStringChar(aDeliEnd));
3488
3489 m_pCurrentForm->SetTemplate(nLevPos, m_xParaLayLB->get_selected_text());
3490
3491 m_xLevelLB->remove(nLevPos);
3492 m_xLevelLB->insert_text(nLevPos, aStr);
3493 m_xLevelLB->select_text(aStr);
3494 Modify();
3495 }
3496 }
3497
IMPL_LINK_NOARG(SwTOXStylesTabPage,StdHdl,weld::Button &,void)3498 IMPL_LINK_NOARG(SwTOXStylesTabPage, StdHdl, weld::Button&, void)
3499 {
3500 const auto nPos = m_xLevelLB->get_selected_index();
3501 if (nPos != -1)
3502 {
3503 const OUString aStr(m_xLevelLB->get_text(nPos).getToken(0, aDeliStart));
3504 m_xLevelLB->remove(nPos);
3505 m_xLevelLB->insert_text(nPos, aStr);
3506 m_xLevelLB->select_text(aStr);
3507 m_pCurrentForm->SetTemplate(nPos, OUString());
3508 Modify();
3509 }
3510 }
3511
IMPL_LINK_NOARG(SwTOXStylesTabPage,DoubleClickHdl,weld::TreeView &,bool)3512 IMPL_LINK_NOARG(SwTOXStylesTabPage, DoubleClickHdl, weld::TreeView&, bool)
3513 {
3514 const OUString aTmpName(m_xParaLayLB->get_selected_text());
3515 SwWrtShell& rSh = static_cast<SwMultiTOXTabDialog*>(GetDialogController())->GetWrtShell();
3516
3517 if(m_xParaLayLB->get_selected_index() != -1 &&
3518 (m_xLevelLB->get_selected_index() == 0 || SwMultiTOXTabDialog::IsNoNum(rSh, aTmpName)))
3519 AssignHdl(*m_xAssignBT);
3520
3521 return true;
3522 }
3523
3524 // enable only when selected
IMPL_LINK_NOARG(SwTOXStylesTabPage,EnableSelectHdl,weld::TreeView &,void)3525 IMPL_LINK_NOARG(SwTOXStylesTabPage, EnableSelectHdl, weld::TreeView&, void)
3526 {
3527 m_xStdBT->set_sensitive(m_xLevelLB->get_selected_index() != -1);
3528
3529 SwWrtShell& rSh = static_cast<SwMultiTOXTabDialog*>(GetDialogController())->GetWrtShell();
3530 const OUString aTmpName(m_xParaLayLB->get_selected_text());
3531 m_xAssignBT->set_sensitive(m_xParaLayLB->get_selected_index() != -1 &&
3532 m_xLevelLB->get_selected_index() != -1 &&
3533 (m_xLevelLB->get_selected_index() == 0 || SwMultiTOXTabDialog::IsNoNum(rSh, aTmpName)));
3534 m_xEditStyleBT->set_sensitive(m_xParaLayLB->get_selected_index() != -1);
3535 }
3536
Modify()3537 void SwTOXStylesTabPage::Modify()
3538 {
3539 SwMultiTOXTabDialog* pTOXDlg = static_cast<SwMultiTOXTabDialog*>(GetDialogController());
3540 if (pTOXDlg)
3541 {
3542 GetForm() = *m_pCurrentForm;
3543 pTOXDlg->CreateOrUpdateExample(pTOXDlg->GetCurrentTOXType().eType, TOX_PAGE_STYLES);
3544 }
3545 }
3546
3547 #define ITEM_SEARCH 1
3548 #define ITEM_ALTERNATIVE 2
3549 #define ITEM_PRIM_KEY 3
3550 #define ITEM_SEC_KEY 4
3551 #define ITEM_COMMENT 5
3552 #define ITEM_CASE 6
3553 #define ITEM_WORDONLY 7
3554
SwEntryBrowseBox(const css::uno::Reference<css::awt::XWindow> & rParent)3555 SwEntryBrowseBox::SwEntryBrowseBox(const css::uno::Reference<css::awt::XWindow> &rParent)
3556 : SwEntryBrowseBox_Base(VCLUnoHelper::GetWindow(rParent), EditBrowseBoxFlags::NONE, WB_TABSTOP | WB_BORDER,
3557 BrowserMode::KEEPHIGHLIGHT |
3558 BrowserMode::COLUMNSELECTION |
3559 BrowserMode::MULTISELECTION |
3560 BrowserMode::TRACKING_TIPS |
3561 BrowserMode::HLINES |
3562 BrowserMode::VLINES |
3563 BrowserMode::AUTO_VSCROLL|
3564 BrowserMode::HIDECURSOR )
3565 , m_aCellEdit(VclPtr<Edit>::Create(&GetDataWindow(), 0))
3566 , m_aCellCheckBox(VclPtr< ::svt::CheckBoxControl>::Create(&GetDataWindow()))
3567 , m_nCurrentRow(0)
3568 , m_bModified(false)
3569 {
3570 m_sSearch = SwResId(STR_AUTOMARK_SEARCHTERM);
3571 m_sAlternative = SwResId(STR_AUTOMARK_ALTERNATIVE);
3572 m_sPrimKey = SwResId(STR_AUTOMARK_KEY1);
3573 m_sSecKey = SwResId(STR_AUTOMARK_KEY2);
3574 m_sComment = SwResId(STR_AUTOMARK_COMMENT);
3575 m_sCaseSensitive = SwResId(STR_AUTOMARK_CASESENSITIVE);
3576 m_sWordOnly = SwResId(STR_AUTOMARK_WORDONLY);
3577 m_sYes = SwResId(STR_AUTOMARK_YES);
3578 m_sNo = SwResId(STR_AUTOMARK_NO);
3579
3580 m_aCellCheckBox->GetBox().EnableTriState(false);
3581 m_xController = new ::svt::EditCellController(m_aCellEdit.get());
3582 m_xCheckController = new ::svt::CheckBoxCellController(m_aCellCheckBox.get());
3583
3584 // HACK: BrowseBox doesn't invalidate its children, how it should be.
3585 // That's why WB_CLIPCHILDREN is reset in order to enforce the
3586 // children' invalidation
3587 WinBits aStyle = GetStyle();
3588 if( aStyle & WB_CLIPCHILDREN )
3589 {
3590 aStyle &= ~WB_CLIPCHILDREN;
3591 SetStyle( aStyle );
3592 }
3593
3594 const OUString* aTitles[7] =
3595 {
3596 &m_sSearch,
3597 &m_sAlternative,
3598 &m_sPrimKey,
3599 &m_sSecKey,
3600 &m_sComment,
3601 &m_sCaseSensitive,
3602 &m_sWordOnly
3603 };
3604
3605 long nWidth = GetSizePixel().Width();
3606 nWidth /=7;
3607 --nWidth;
3608 for(sal_uInt16 i = 1; i < 8; i++)
3609 InsertDataColumn( i, *aTitles[i - 1], nWidth );
3610 }
3611
~SwEntryBrowseBox()3612 SwEntryBrowseBox::~SwEntryBrowseBox()
3613 {
3614 disposeOnce();
3615 }
3616
dispose()3617 void SwEntryBrowseBox::dispose()
3618 {
3619 m_aCellEdit.disposeAndClear();
3620 m_aCellCheckBox.disposeAndClear();
3621 SwEntryBrowseBox_Base::dispose();
3622 }
3623
Resize()3624 void SwEntryBrowseBox::Resize()
3625 {
3626 SwEntryBrowseBox_Base::Resize();
3627
3628 long nWidth = GetSizePixel().Width();
3629 std::vector<long> aWidths = GetOptimalColWidths();
3630 long nNaturalWidth(std::accumulate(aWidths.begin(), aWidths.end(), 0));
3631 long nExcess = ((nWidth - nNaturalWidth) / aWidths.size()) - 1;
3632
3633 for (size_t i = 0; i < aWidths.size(); ++i)
3634 SetColumnWidth(i+1, aWidths[i] + nExcess);
3635 }
3636
GetOptimalColWidths() const3637 std::vector<long> SwEntryBrowseBox::GetOptimalColWidths() const
3638 {
3639 std::vector<long> aWidths;
3640
3641 long nStandardColMinWidth = approximate_char_width() * 16;
3642 long nYesNoWidth = approximate_char_width() * 5;
3643 nYesNoWidth = std::max(nYesNoWidth, GetTextWidth(m_sYes));
3644 nYesNoWidth = std::max(nYesNoWidth, GetTextWidth(m_sNo));
3645 for (sal_uInt16 i = 1; i < 6; i++)
3646 {
3647 long nColWidth = std::max(nStandardColMinWidth,
3648 GetTextWidth(GetColumnTitle(i)));
3649 nColWidth += 12;
3650 aWidths.push_back(nColWidth);
3651 }
3652
3653 for (sal_uInt16 i = 6; i < 8; i++)
3654 {
3655 long nColWidth = std::max(nYesNoWidth,
3656 GetTextWidth(GetColumnTitle(i)));
3657 nColWidth += 12;
3658 aWidths.push_back(nColWidth);
3659 }
3660
3661 return aWidths;
3662 }
3663
GetOptimalSize() const3664 Size SwEntryBrowseBox::GetOptimalSize() const
3665 {
3666 Size aSize = LogicToPixel(Size(276 , 175), MapMode(MapUnit::MapAppFont));
3667
3668 std::vector<long> aWidths = GetOptimalColWidths();
3669
3670 long nWidth(std::accumulate(aWidths.begin(), aWidths.end(), 0));
3671
3672 aSize.setWidth( std::max(aSize.Width(), nWidth) );
3673
3674 return aSize;
3675 }
3676
SeekRow(long nRow)3677 bool SwEntryBrowseBox::SeekRow( long nRow )
3678 {
3679 m_nCurrentRow = nRow;
3680 return true;
3681 }
3682
GetCellText(long nRow,sal_uInt16 nColumn) const3683 OUString SwEntryBrowseBox::GetCellText(long nRow, sal_uInt16 nColumn) const
3684 {
3685 OUString pRet;
3686 if (static_cast<size_t>(nRow) < m_Entries.size())
3687 {
3688 const AutoMarkEntry* pEntry = m_Entries[ nRow ].get();
3689 switch(nColumn)
3690 {
3691 case ITEM_SEARCH : pRet = pEntry->sSearch; break;
3692 case ITEM_ALTERNATIVE : pRet = pEntry->sAlternative; break;
3693 case ITEM_PRIM_KEY : pRet = pEntry->sPrimKey; break;
3694 case ITEM_SEC_KEY : pRet = pEntry->sSecKey; break;
3695 case ITEM_COMMENT : pRet = pEntry->sComment; break;
3696 case ITEM_CASE : pRet = pEntry->bCase ? m_sYes : m_sNo; break;
3697 case ITEM_WORDONLY : pRet = pEntry->bWord ? m_sYes : m_sNo; break;
3698 }
3699 }
3700 return pRet;
3701 }
3702
PaintCell(OutputDevice & rDev,const tools::Rectangle & rRect,sal_uInt16 nColumnId) const3703 void SwEntryBrowseBox::PaintCell(OutputDevice& rDev,
3704 const tools::Rectangle& rRect, sal_uInt16 nColumnId) const
3705 {
3706 const DrawTextFlags nStyle = DrawTextFlags::Clip | DrawTextFlags::Center;
3707 rDev.DrawText( rRect, GetCellText( m_nCurrentRow, nColumnId ), nStyle );
3708 }
3709
GetController(long,sal_uInt16 nCol)3710 ::svt::CellController* SwEntryBrowseBox::GetController(long /*nRow*/, sal_uInt16 nCol)
3711 {
3712 return nCol < ITEM_CASE ? m_xController.get() : m_xCheckController.get();
3713 }
3714
SaveModified()3715 bool SwEntryBrowseBox::SaveModified()
3716 {
3717 m_bModified = true;
3718 const size_t nRow = GetCurRow();
3719 const sal_uInt16 nCol = GetCurColumnId();
3720
3721 OUString sNew;
3722 bool bVal = false;
3723 ::svt::CellController* pController = nullptr;
3724 if(nCol < ITEM_CASE)
3725 {
3726 pController = m_xController.get();
3727 sNew = static_cast< ::svt::EditCellController*>(pController)->GetEditImplementation()->GetText( LINEEND_LF );
3728 }
3729 else
3730 {
3731 pController = m_xCheckController.get();
3732 bVal = static_cast< ::svt::CheckBoxCellController*>(pController)->GetCheckBox().IsChecked();
3733 }
3734 const bool bAddEntry = nRow >= m_Entries.size();
3735 std::unique_ptr<AutoMarkEntry> xNewEntry(bAddEntry ? new AutoMarkEntry : nullptr);
3736 AutoMarkEntry* pEntry = bAddEntry ? xNewEntry.get() : m_Entries[nRow].get();
3737 switch(nCol)
3738 {
3739 case ITEM_SEARCH : pEntry->sSearch = sNew; break;
3740 case ITEM_ALTERNATIVE : pEntry->sAlternative = sNew; break;
3741 case ITEM_PRIM_KEY : pEntry->sPrimKey = sNew; break;
3742 case ITEM_SEC_KEY : pEntry->sSecKey = sNew; break;
3743 case ITEM_COMMENT : pEntry->sComment = sNew; break;
3744 case ITEM_CASE : pEntry->bCase = bVal; break;
3745 case ITEM_WORDONLY : pEntry->bWord = bVal; break;
3746 }
3747 if (bAddEntry)
3748 {
3749 m_Entries.push_back(std::move(xNewEntry));
3750 RowInserted(nRow, 1, true, true);
3751 if(nCol < ITEM_WORDONLY)
3752 {
3753 pController->ClearModified();
3754 GoToRow( nRow );
3755 }
3756 }
3757 return true;
3758 }
3759
InitController(::svt::CellControllerRef & rController,long nRow,sal_uInt16 nCol)3760 void SwEntryBrowseBox::InitController(
3761 ::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol)
3762 {
3763 const OUString rText = GetCellText( nRow, nCol );
3764 if(nCol < ITEM_CASE)
3765 {
3766 rController = m_xController;
3767 ::svt::CellController* pController = m_xController.get();
3768 static_cast< ::svt::EditCellController*>(pController)->GetEditImplementation()->SetText( rText );
3769 }
3770 else
3771 {
3772 rController = m_xCheckController;
3773 ::svt::CellController* pController = m_xCheckController.get();
3774 static_cast< ::svt::CheckBoxCellController*>(pController)->GetCheckBox().Check(
3775 rText == m_sYes );
3776 }
3777 }
3778
ReadEntries(SvStream & rInStr)3779 void SwEntryBrowseBox::ReadEntries(SvStream& rInStr)
3780 {
3781 AutoMarkEntry* pToInsert = nullptr;
3782 rtl_TextEncoding eTEnc = osl_getThreadTextEncoding();
3783 while (rInStr.good())
3784 {
3785 OUString sLine;
3786 rInStr.ReadByteStringLine( sLine, eTEnc );
3787
3788 // # -> comment
3789 // ; -> delimiter between entries ->
3790 // Format: TextToSearchFor;AlternativeString;PrimaryKey;SecondaryKey
3791 // Leading and trailing blanks are ignored
3792 if( !sLine.isEmpty() )
3793 {
3794 //comments are contained in separate lines but are put into the struct of the following data
3795 //line (if available)
3796 if( '#' != sLine[0] )
3797 {
3798 if( !pToInsert )
3799 pToInsert = new AutoMarkEntry;
3800
3801 sal_Int32 nSttPos = 0;
3802 pToInsert->sSearch = sLine.getToken(0, ';', nSttPos );
3803 pToInsert->sAlternative = sLine.getToken(0, ';', nSttPos );
3804 pToInsert->sPrimKey = sLine.getToken(0, ';', nSttPos );
3805 pToInsert->sSecKey = sLine.getToken(0, ';', nSttPos );
3806
3807 OUString sStr = sLine.getToken(0, ';', nSttPos );
3808 pToInsert->bCase = !sStr.isEmpty() && sStr != "0";
3809
3810 sStr = sLine.getToken(0, ';', nSttPos );
3811 pToInsert->bWord = !sStr.isEmpty() && sStr != "0";
3812
3813 m_Entries.push_back(std::unique_ptr<AutoMarkEntry>(pToInsert));
3814 pToInsert = nullptr;
3815 }
3816 else
3817 {
3818 if(pToInsert)
3819 m_Entries.push_back(std::unique_ptr<AutoMarkEntry>(pToInsert));
3820 pToInsert = new AutoMarkEntry;
3821 pToInsert->sComment = sLine.copy(1);
3822 }
3823 }
3824 }
3825 if( pToInsert )
3826 m_Entries.push_back(std::unique_ptr<AutoMarkEntry>(pToInsert));
3827 RowInserted(0, m_Entries.size() + 1);
3828 }
3829
WriteEntries(SvStream & rOutStr)3830 void SwEntryBrowseBox::WriteEntries(SvStream& rOutStr)
3831 {
3832 //check if the current controller is modified
3833 const sal_uInt16 nCol = GetCurColumnId();
3834 ::svt::CellController* pController;
3835 if(nCol < ITEM_CASE)
3836 pController = m_xController.get();
3837 else
3838 pController = m_xCheckController.get();
3839 if(pController ->IsModified())
3840 GoToColumnId(nCol + (nCol < ITEM_CASE ? 1 : -1 ));
3841
3842 rtl_TextEncoding eTEnc = osl_getThreadTextEncoding();
3843 for(const std::unique_ptr<AutoMarkEntry> & rpEntry : m_Entries)
3844 {
3845 AutoMarkEntry* pEntry = rpEntry.get();
3846 if(!pEntry->sComment.isEmpty())
3847 {
3848 rOutStr.WriteByteStringLine( "#" + pEntry->sComment, eTEnc );
3849 }
3850
3851 OUString sWrite( pEntry->sSearch + ";" +
3852 pEntry->sAlternative + ";" +
3853 pEntry->sPrimKey + ";" +
3854 pEntry->sSecKey + ";" +
3855 (pEntry->bCase ? OUStringLiteral("1") : OUStringLiteral("0")) + ";" +
3856 (pEntry->bWord ? OUStringLiteral("1") : OUStringLiteral("0")) );
3857
3858 if( sWrite.getLength() > 5 )
3859 rOutStr.WriteByteStringLine( sWrite, eTEnc );
3860 }
3861 }
3862
IsModified() const3863 bool SwEntryBrowseBox::IsModified()const
3864 {
3865 if(m_bModified)
3866 return true;
3867
3868 //check if the current controller is modified
3869 const sal_uInt16 nCol = GetCurColumnId();
3870 ::svt::CellController* pController;
3871 if(nCol < ITEM_CASE)
3872 pController = m_xController.get();
3873 else
3874 pController = m_xCheckController.get();
3875 return pController->IsModified();
3876 }
3877
SwAutoMarkDlg_Impl(weld::Window * pParent,const OUString & rAutoMarkURL,bool bCreate)3878 SwAutoMarkDlg_Impl::SwAutoMarkDlg_Impl(weld::Window* pParent, const OUString& rAutoMarkURL,
3879 bool bCreate)
3880 : GenericDialogController(pParent, "modules/swriter/ui/createautomarkdialog.ui", "CreateAutomarkDialog")
3881 , sAutoMarkURL(rAutoMarkURL)
3882 , bCreateMode(bCreate)
3883 , m_xOKPB(m_xBuilder->weld_button("ok"))
3884 , m_xTable(m_xBuilder->weld_container("area"))
3885 , m_xTableCtrlParent(m_xTable->CreateChildFrame())
3886 , m_xEntriesBB(VclPtr<SwEntryBrowseBox>::Create(m_xTableCtrlParent))
3887 {
3888 m_xEntriesBB->Show();
3889 m_xOKPB->connect_clicked(LINK(this, SwAutoMarkDlg_Impl, OkHdl));
3890
3891 m_xDialog->set_title(m_xDialog->get_title() + ": " + sAutoMarkURL);
3892 bool bError = false;
3893 if( bCreateMode )
3894 m_xEntriesBB->RowInserted(0);
3895 else
3896 {
3897 SfxMedium aMed( sAutoMarkURL, StreamMode::STD_READ );
3898 if( aMed.GetInStream() && !aMed.GetInStream()->GetError() )
3899 m_xEntriesBB->ReadEntries( *aMed.GetInStream() );
3900 else
3901 bError = true;
3902 }
3903
3904 Size aPrefSize = m_xEntriesBB->GetOptimalSize();
3905 m_xTable->set_size_request(aPrefSize.Width(), aPrefSize.Height());
3906
3907 if (bError)
3908 m_xDialog->response(RET_CANCEL);
3909 }
3910
~SwAutoMarkDlg_Impl()3911 SwAutoMarkDlg_Impl::~SwAutoMarkDlg_Impl()
3912 {
3913 m_xEntriesBB.disposeAndClear();
3914 m_xTableCtrlParent->dispose();
3915 m_xTableCtrlParent.clear();
3916 }
3917
IMPL_LINK_NOARG(SwAutoMarkDlg_Impl,OkHdl,weld::Button &,void)3918 IMPL_LINK_NOARG(SwAutoMarkDlg_Impl, OkHdl, weld::Button&, void)
3919 {
3920 bool bError = false;
3921 if (m_xEntriesBB->IsModified() || bCreateMode)
3922 {
3923 SfxMedium aMed( sAutoMarkURL,
3924 bCreateMode ? StreamMode::WRITE
3925 : StreamMode::WRITE| StreamMode::TRUNC );
3926 SvStream* pStrm = aMed.GetOutStream();
3927 pStrm->SetStreamCharSet( RTL_TEXTENCODING_MS_1253 );
3928 if( !pStrm->GetError() )
3929 {
3930 m_xEntriesBB->WriteEntries( *pStrm );
3931 aMed.Commit();
3932 }
3933 else
3934 bError = true;
3935 }
3936 if (!bError)
3937 m_xDialog->response(RET_OK);
3938 }
3939
3940 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
3941