android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / ui / dialog / uiregionsw.cxx
blob96c5b7f8f708410d7bbd5dc19e4b2ca14d8db7f2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <hintids.hxx>
21 #include <regionsw.hxx>
22 #include <svl/urihelper.hxx>
23 #include <svl/PasswordHelper.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/weld.hxx>
26 #include <svl/stritem.hxx>
27 #include <svl/eitem.hxx>
28 #include <sfx2/passwd.hxx>
29 #include <sfx2/docfilt.hxx>
30 #include <sfx2/request.hxx>
31 #include <sfx2/docfile.hxx>
32 #include <sfx2/linkmgr.hxx>
33 #include <sfx2/docinsert.hxx>
34 #include <sfx2/filedlghelper.hxx>
35 #include <editeng/sizeitem.hxx>
36 #include <svtools/htmlcfg.hxx>
37 #include <osl/diagnose.h>
38 #include <o3tl/string_view.hxx>
39 #include <comphelper/lok.hxx>
41 #include <uitool.hxx>
42 #include <IMark.hxx>
43 #include <section.hxx>
44 #include <docary.hxx>
45 #include <doc.hxx>
46 #include <wdocsh.hxx>
47 #include <view.hxx>
48 #include <wrtsh.hxx>
49 #include <column.hxx>
50 #include <fmtclbl.hxx>
51 #include <fmtfsize.hxx>
52 #include <frmatr.hxx>
53 #include <shellio.hxx>
55 #include <cmdid.h>
56 #include <strings.hrc>
57 #include <bitmaps.hlst>
58 #include <sfx2/bindings.hxx>
59 #include <sfx2/sfxdlg.hxx>
60 #include <sfx2/viewfrm.hxx>
61 #include <svx/dialogs.hrc>
62 #include <svx/flagsdef.hxx>
63 #include <memory>
64 #include <string_view>
66 using namespace ::com::sun::star;
68 namespace {
70 OUString BuildBitmap(bool bProtect, bool bHidden)
72 if (bProtect)
73 return bHidden ? OUString(RID_BMP_PROT_HIDE) : OUString(RID_BMP_PROT_NO_HIDE);
74 return bHidden ? OUString(RID_BMP_HIDE) : OUString(RID_BMP_NO_HIDE);
77 OUString CollapseWhiteSpaces(std::u16string_view sName)
79 const sal_Int32 nLen = sName.size();
80 const sal_Unicode cRef = ' ';
81 OUStringBuffer aBuf(nLen);
82 for (sal_Int32 i = 0; i<nLen; )
84 const sal_Unicode cCur = sName[i++];
85 aBuf.append(cCur);
86 if (cCur!=cRef)
87 continue;
88 while (i<nLen && sName[i]==cRef)
89 ++i;
91 return aBuf.makeStringAndClear();
96 static void lcl_ReadSections( SfxMedium& rMedium, weld::ComboBox& rBox );
98 static void lcl_FillList( SwWrtShell& rSh, weld::ComboBox& rSubRegions, weld::ComboBox* pAvailNames, const SwSectionFormat* pNewFormat )
100 if( !pNewFormat )
102 const size_t nCount = rSh.GetSectionFormatCount();
103 for (size_t i = 0; i<nCount; i++)
105 SectionType eTmpType;
106 const SwSectionFormat* pFormat = &rSh.GetSectionFormat(i);
107 if( !pFormat->GetParent() &&
108 pFormat->IsInNodesArr() &&
109 (eTmpType = pFormat->GetSection()->GetType()) != SectionType::ToxContent
110 && SectionType::ToxHeader != eTmpType )
112 const OUString sString(pFormat->GetSection()->GetSectionName());
113 if (pAvailNames)
114 pAvailNames->append_text(sString);
115 rSubRegions.append_text(sString);
116 lcl_FillList( rSh, rSubRegions, pAvailNames, pFormat );
120 else
122 SwSections aTmpArr;
123 pNewFormat->GetChildSections(aTmpArr, SectionSort::Pos);
124 if( !aTmpArr.empty() )
126 SectionType eTmpType;
127 for( const auto pSect : aTmpArr )
129 const SwSectionFormat* pFormat = pSect->GetFormat();
130 if( pFormat->IsInNodesArr()&&
131 (eTmpType = pFormat->GetSection()->GetType()) != SectionType::ToxContent
132 && SectionType::ToxHeader != eTmpType )
134 const OUString sString(pFormat->GetSection()->GetSectionName());
135 if (pAvailNames)
136 pAvailNames->append_text(sString);
137 rSubRegions.append_text(sString);
138 lcl_FillList( rSh, rSubRegions, pAvailNames, pFormat );
145 static void lcl_FillSubRegionList( SwWrtShell& rSh, weld::ComboBox& rSubRegions, weld::ComboBox* pAvailNames )
147 rSubRegions.clear();
148 lcl_FillList( rSh, rSubRegions, pAvailNames, nullptr );
149 IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess();
150 for( IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getBookmarksBegin();
151 ppMark != pMarkAccess->getBookmarksEnd();
152 ++ppMark)
154 const ::sw::mark::IMark* pBkmk = *ppMark;
155 if( pBkmk->IsExpanded() )
156 rSubRegions.append_text( pBkmk->GetName() );
160 // user data class for region information
161 class SectRepr
163 private:
164 SwSectionData m_SectionData;
165 SwFormatCol m_Col;
166 std::unique_ptr<SvxBrushItem> m_Brush;
167 SwFormatFootnoteAtTextEnd m_FootnoteNtAtEnd;
168 SwFormatEndAtTextEnd m_EndNtAtEnd;
169 SwFormatNoBalancedColumns m_Balance;
170 std::shared_ptr<SvxFrameDirectionItem> m_FrameDirItem;
171 std::shared_ptr<SvxLRSpaceItem> m_LRSpaceItem;
172 const size_t m_nArrPos;
173 // shows, if maybe textcontent is in the region
174 bool m_bContent : 1;
175 // for multiselection, mark at first, then work with TreeListBox!
176 bool m_bSelected : 1;
177 uno::Sequence<sal_Int8> m_TempPasswd;
179 public:
180 SectRepr(size_t nPos, SwSection& rSect);
182 SwSectionData & GetSectionData() { return m_SectionData; }
183 SwFormatCol& GetCol() { return m_Col; }
184 std::unique_ptr<SvxBrushItem>& GetBackground() { return m_Brush; }
185 SwFormatFootnoteAtTextEnd& GetFootnoteNtAtEnd() { return m_FootnoteNtAtEnd; }
186 SwFormatEndAtTextEnd& GetEndNtAtEnd() { return m_EndNtAtEnd; }
187 SwFormatNoBalancedColumns& GetBalance() { return m_Balance; }
188 std::shared_ptr<SvxFrameDirectionItem>& GetFrameDir() { return m_FrameDirItem; }
189 std::shared_ptr<SvxLRSpaceItem>& GetLRSpace() { return m_LRSpaceItem; }
191 size_t GetArrPos() const { return m_nArrPos; }
192 OUString GetFile() const;
193 OUString GetSubRegion() const;
194 void SetFile(std::u16string_view rFile);
195 void SetFilter(std::u16string_view rFilter);
196 void SetSubRegion(std::u16string_view rSubRegion);
198 bool IsContent() const { return m_bContent; }
199 void SetContent(bool const bValue) { m_bContent = bValue; }
201 void SetSelected() { m_bSelected = true; }
202 bool IsSelected() const { return m_bSelected; }
204 uno::Sequence<sal_Int8> & GetTempPasswd() { return m_TempPasswd; }
205 void SetTempPasswd(const uno::Sequence<sal_Int8> & rPasswd)
206 { m_TempPasswd = rPasswd; }
209 SectRepr::SectRepr( size_t nPos, SwSection& rSect )
210 : m_SectionData( rSect )
211 , m_Brush(std::make_unique<SvxBrushItem>(RES_BACKGROUND))
212 , m_FrameDirItem(std::make_shared<SvxFrameDirectionItem>(SvxFrameDirection::Environment, RES_FRAMEDIR))
213 , m_LRSpaceItem(std::make_shared<SvxLRSpaceItem>(RES_LR_SPACE))
214 , m_nArrPos(nPos)
215 , m_bContent(m_SectionData.GetLinkFileName().isEmpty())
216 , m_bSelected(false)
218 SwSectionFormat *pFormat = rSect.GetFormat();
219 if( pFormat )
221 m_Col = pFormat->GetCol();
222 m_Brush = pFormat->makeBackgroundBrushItem();
223 m_FootnoteNtAtEnd = pFormat->GetFootnoteAtTextEnd();
224 m_EndNtAtEnd = pFormat->GetEndAtTextEnd();
225 m_Balance.SetValue(pFormat->GetBalancedColumns().GetValue());
226 m_FrameDirItem.reset(pFormat->GetFrameDir().Clone());
227 m_LRSpaceItem.reset(pFormat->GetLRSpace().Clone());
231 void SectRepr::SetFile( std::u16string_view rFile )
233 OUString sNewFile( INetURLObject::decode( rFile,
234 INetURLObject::DecodeMechanism::Unambiguous ));
235 const OUString sOldFileName( m_SectionData.GetLinkFileName() );
236 const std::u16string_view sSub( o3tl::getToken(sOldFileName, 2, sfx2::cTokenSeparator ) );
238 if( !rFile.empty() || !sSub.empty() )
240 sNewFile += OUStringChar(sfx2::cTokenSeparator);
241 if( !rFile.empty() ) // Filter only with FileName
242 sNewFile += o3tl::getToken(sOldFileName, 1, sfx2::cTokenSeparator );
244 sNewFile += OUStringChar(sfx2::cTokenSeparator) + sSub;
247 m_SectionData.SetLinkFileName( sNewFile );
249 if( !rFile.empty() || !sSub.empty() )
251 m_SectionData.SetType( SectionType::FileLink );
253 else
255 m_SectionData.SetType( SectionType::Content );
259 void SectRepr::SetFilter( std::u16string_view rFilter )
261 OUString sNewFile;
262 const OUString sOldFileName( m_SectionData.GetLinkFileName() );
263 sal_Int32 nIdx{ 0 };
264 const std::u16string_view sFile( o3tl::getToken(sOldFileName, 0, sfx2::cTokenSeparator, nIdx ) ); // token 0
265 const std::u16string_view sSub( o3tl::getToken(sOldFileName, 1, sfx2::cTokenSeparator, nIdx ) ); // token 2
267 if( !sFile.empty() )
268 sNewFile = sFile + OUStringChar(sfx2::cTokenSeparator) +
269 rFilter + OUStringChar(sfx2::cTokenSeparator) + sSub;
270 else if( !sSub.empty() )
271 sNewFile = OUStringChar(sfx2::cTokenSeparator) + OUStringChar(sfx2::cTokenSeparator) + sSub;
273 m_SectionData.SetLinkFileName( sNewFile );
275 if( !sNewFile.isEmpty() )
277 m_SectionData.SetType( SectionType::FileLink );
281 void SectRepr::SetSubRegion(std::u16string_view rSubRegion)
283 OUString sNewFile;
284 sal_Int32 n(0);
285 const OUString sLinkFileName(m_SectionData.GetLinkFileName());
286 const std::u16string_view sOldFileName( o3tl::getToken(sLinkFileName, 0, sfx2::cTokenSeparator, n ) );
287 const std::u16string_view sFilter( o3tl::getToken(sLinkFileName, 0, sfx2::cTokenSeparator, n ) );
289 if( !rSubRegion.empty() || !sOldFileName.empty() )
290 sNewFile = sOldFileName + OUStringChar(sfx2::cTokenSeparator) +
291 sFilter + OUStringChar(sfx2::cTokenSeparator) + rSubRegion;
293 m_SectionData.SetLinkFileName( sNewFile );
295 if( !rSubRegion.empty() || !sOldFileName.empty() )
297 m_SectionData.SetType( SectionType::FileLink );
299 else
301 m_SectionData.SetType( SectionType::Content );
305 OUString SectRepr::GetFile() const
307 const OUString sLinkFile( m_SectionData.GetLinkFileName() );
309 if( sLinkFile.isEmpty() )
311 return sLinkFile;
313 if (SectionType::DdeLink == m_SectionData.GetType())
315 sal_Int32 n = 0;
316 return sLinkFile.replaceFirst( OUStringChar(sfx2::cTokenSeparator), " ", &n )
317 .replaceFirst( OUStringChar(sfx2::cTokenSeparator), " ", &n );
319 return INetURLObject::decode( o3tl::getToken(sLinkFile, 0, sfx2::cTokenSeparator ),
320 INetURLObject::DecodeMechanism::Unambiguous );
323 OUString SectRepr::GetSubRegion() const
325 const OUString sLinkFile( m_SectionData.GetLinkFileName() );
326 if( !sLinkFile.isEmpty() )
327 return sLinkFile.getToken( 2, sfx2::cTokenSeparator );
328 return sLinkFile;
331 // dialog edit regions
332 SwEditRegionDlg::SwEditRegionDlg(weld::Window* pParent, SwWrtShell& rWrtSh)
333 : SfxDialogController(pParent, "modules/swriter/ui/editsectiondialog.ui",
334 "EditSectionDialog")
335 , m_bSubRegionsFilled(false)
336 , m_rSh(rWrtSh)
337 , m_bDontCheckPasswd(true)
338 , m_xCurName(m_xBuilder->weld_entry("curname"))
339 , m_xTree(m_xBuilder->weld_tree_view("tree"))
340 , m_xFileCB(m_xBuilder->weld_check_button("link"))
341 , m_xDDECB(m_xBuilder->weld_check_button("dde"))
342 , m_xDDEFrame(m_xBuilder->weld_widget("ddedepend"))
343 , m_xFileNameFT(m_xBuilder->weld_label("filenameft"))
344 , m_xDDECommandFT(m_xBuilder->weld_label("ddeft"))
345 , m_xFileNameED(m_xBuilder->weld_entry("filename"))
346 , m_xFilePB(m_xBuilder->weld_button("file"))
347 , m_xSubRegionFT(m_xBuilder->weld_label("sectionft"))
348 , m_xSubRegionED(m_xBuilder->weld_combo_box("section"))
349 , m_xProtectCB(m_xBuilder->weld_check_button("protect"))
350 , m_xPasswdCB(m_xBuilder->weld_check_button("withpassword"))
351 , m_xPasswdPB(m_xBuilder->weld_button("password"))
352 , m_xHideCB(m_xBuilder->weld_check_button("hide"))
353 , m_xConditionFT(m_xBuilder->weld_label("conditionft"))
354 , m_xConditionED(new ConditionEdit(m_xBuilder->weld_entry("condition")))
355 , m_xEditInReadonlyCB(m_xBuilder->weld_check_button("editinro"))
356 , m_xOK(m_xBuilder->weld_button("ok"))
357 , m_xOptionsPB(m_xBuilder->weld_button("options"))
358 , m_xDismiss(m_xBuilder->weld_button("remove"))
359 , m_xHideFrame(m_xBuilder->weld_widget("hideframe"))
361 m_xTree->set_size_request(-1, m_xTree->get_height_rows(16));
362 m_xFileCB->set_state(TRISTATE_FALSE);
363 m_xSubRegionED->make_sorted();
364 m_xProtectCB->set_state(TRISTATE_FALSE);
365 m_xHideCB->set_state(TRISTATE_FALSE);
366 // edit in readonly sections
367 m_xEditInReadonlyCB->set_state(TRISTATE_FALSE);
369 bool bWeb = dynamic_cast<SwWebDocShell*>( m_rSh.GetView().GetDocShell() ) != nullptr;
371 m_xTree->connect_changed(LINK(this, SwEditRegionDlg, GetFirstEntryHdl));
372 m_xCurName->connect_changed(LINK(this, SwEditRegionDlg, NameEditHdl));
373 m_xConditionED->connect_changed( LINK( this, SwEditRegionDlg, ConditionEditHdl));
374 m_xOK->connect_clicked( LINK( this, SwEditRegionDlg, OkHdl));
375 m_xPasswdCB->connect_toggled(LINK(this, SwEditRegionDlg, TogglePasswdHdl));
376 m_xPasswdPB->connect_clicked(LINK(this, SwEditRegionDlg, ChangePasswdHdl));
377 m_xHideCB->connect_toggled(LINK(this, SwEditRegionDlg, ChangeHideHdl));
378 // edit in readonly sections
379 m_xEditInReadonlyCB->connect_toggled(LINK(this, SwEditRegionDlg, ChangeEditInReadonlyHdl));
381 m_xOptionsPB->connect_clicked(LINK(this, SwEditRegionDlg, OptionsHdl));
382 m_xProtectCB->connect_toggled(LINK(this, SwEditRegionDlg, ChangeProtectHdl));
383 m_xDismiss->connect_clicked( LINK( this, SwEditRegionDlg, ChangeDismissHdl));
384 m_xFileCB->connect_toggled(LINK(this, SwEditRegionDlg, UseFileHdl));
385 m_xFilePB->connect_clicked(LINK(this, SwEditRegionDlg, FileSearchHdl));
386 m_xFileNameED->connect_changed(LINK(this, SwEditRegionDlg, FileNameEntryHdl));
387 m_xSubRegionED->connect_changed(LINK(this, SwEditRegionDlg, FileNameComboBoxHdl));
388 m_xSubRegionED->connect_popup_toggled(LINK(this, SwEditRegionDlg, SubRegionEventHdl));
389 m_xSubRegionED->set_entry_completion(true, true);
391 m_xTree->set_selection_mode(SelectionMode::Multiple);
393 if (bWeb)
395 m_xDDECB->hide();
396 m_xHideFrame->hide();
397 m_xPasswdCB->hide();
400 m_xDDECB->connect_toggled(LINK(this, SwEditRegionDlg, DDEHdl));
402 m_pCurrSect = m_rSh.GetCurrSection();
403 RecurseList( nullptr, nullptr );
405 // if the cursor is not in a region the first one will always be selected
406 if (!m_xTree->get_selected(nullptr))
408 std::unique_ptr<weld::TreeIter> xIter(m_xTree->make_iterator());
409 if (m_xTree->get_iter_first(*xIter))
411 m_xTree->select(*xIter);
412 GetFirstEntryHdl(*m_xTree);
416 m_xTree->show();
417 m_bDontCheckPasswd = false;
419 if(comphelper::LibreOfficeKit::isActive())
421 m_xDDECB->hide();
422 m_xDDECommandFT->hide();
423 m_xFileNameFT->hide();
424 m_xFileNameED->hide();
425 m_xFilePB->hide();
429 bool SwEditRegionDlg::CheckPasswd(weld::Toggleable* pBox)
431 if (m_bDontCheckPasswd)
432 return true;
433 bool bRet = true;
435 m_xTree->selected_foreach([this, &bRet](weld::TreeIter& rEntry){
436 SectRepr* pRepr = weld::fromId<SectRepr*>(m_xTree->get_id(rEntry));
437 if (!pRepr->GetTempPasswd().hasElements()
438 && pRepr->GetSectionData().GetPassword().hasElements())
440 SfxPasswordDialog aPasswdDlg(m_xDialog.get());
441 bRet = false;
442 if (aPasswdDlg.run())
444 const OUString sNewPasswd(aPasswdDlg.GetPassword());
445 css::uno::Sequence <sal_Int8 > aNewPasswd;
446 SvPasswordHelper::GetHashPassword( aNewPasswd, sNewPasswd );
447 if (SvPasswordHelper::CompareHashPassword(
448 pRepr->GetSectionData().GetPassword(), sNewPasswd))
450 pRepr->SetTempPasswd(aNewPasswd);
451 bRet = true;
453 else
455 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(m_xDialog.get(),
456 VclMessageType::Info, VclButtonsType::Ok,
457 SwResId(STR_WRONG_PASSWORD)));
458 xInfoBox->run();
462 return false;
464 if (!bRet && pBox)
466 //reset old button state
467 if (pBox->get_state() != TRISTATE_INDET)
468 pBox->set_active(!pBox->get_active());
471 return bRet;
474 // recursively look for child-sections
475 void SwEditRegionDlg::RecurseList(const SwSectionFormat* pFormat, const weld::TreeIter* pEntry)
477 std::unique_ptr<weld::TreeIter> xIter(m_xTree->make_iterator());
478 if (!pFormat)
480 const size_t nCount=m_rSh.GetSectionFormatCount();
481 for ( size_t n = 0; n < nCount; n++ )
483 SectionType eTmpType;
484 if( !( pFormat = &m_rSh.GetSectionFormat(n))->GetParent() &&
485 pFormat->IsInNodesArr() &&
486 (eTmpType = pFormat->GetSection()->GetType()) != SectionType::ToxContent
487 && SectionType::ToxHeader != eTmpType )
489 SwSection *pSect = pFormat->GetSection();
490 SectRepr* pSectRepr = new SectRepr( n, *pSect );
492 OUString sText(pSect->GetSectionName());
493 OUString sImage(BuildBitmap(pSect->IsProtect(),pSect->IsHidden()));
494 OUString sId(weld::toId(pSectRepr));
495 m_xTree->insert(nullptr, -1, &sText, &sId, nullptr, nullptr, false, xIter.get());
496 m_xTree->set_image(*xIter, sImage);
498 RecurseList(pFormat, xIter.get());
499 if (m_xTree->iter_has_child(*xIter))
500 m_xTree->expand_row(*xIter);
501 if (m_pCurrSect==pSect)
503 m_xTree->select(*xIter);
504 m_xTree->scroll_to_row(*xIter);
505 GetFirstEntryHdl(*m_xTree);
510 else
512 SwSections aTmpArr;
513 pFormat->GetChildSections(aTmpArr, SectionSort::Pos);
514 for( const auto pSect : aTmpArr )
516 SectionType eTmpType;
517 pFormat = pSect->GetFormat();
518 if( pFormat->IsInNodesArr() &&
519 (eTmpType = pFormat->GetSection()->GetType()) != SectionType::ToxContent
520 && SectionType::ToxHeader != eTmpType )
522 SectRepr* pSectRepr=new SectRepr(
523 FindArrPos( pSect->GetFormat() ), *pSect );
525 OUString sText(pSect->GetSectionName());
526 OUString sImage = BuildBitmap(pSect->IsProtect(), pSect->IsHidden());
527 OUString sId(weld::toId(pSectRepr));
528 m_xTree->insert(pEntry, -1, &sText, &sId, nullptr, nullptr, false, xIter.get());
529 m_xTree->set_image(*xIter, sImage);
531 RecurseList(pSect->GetFormat(), xIter.get());
532 if (m_xTree->iter_has_child(*xIter))
533 m_xTree->expand_row(*xIter);
534 if (m_pCurrSect==pSect)
536 m_xTree->select(*xIter);
537 m_xTree->scroll_to_row(*xIter);
538 GetFirstEntryHdl(*m_xTree);
545 size_t SwEditRegionDlg::FindArrPos(const SwSectionFormat* pFormat )
547 const size_t nCount=m_rSh.GetSectionFormatCount();
548 for ( size_t i = 0; i < nCount; i++ )
549 if ( pFormat == &m_rSh.GetSectionFormat(i) )
550 return i;
552 OSL_FAIL("SectionFormat not on the list" );
553 return SIZE_MAX;
556 SwEditRegionDlg::~SwEditRegionDlg( )
558 std::unique_ptr<weld::TreeIter> xIter(m_xTree->make_iterator());
559 if (m_xTree->get_iter_first(*xIter))
563 delete weld::fromId<SectRepr*>(m_xTree->get_id(*xIter));
564 } while (m_xTree->iter_next(*xIter));
568 void SwEditRegionDlg::SelectSection(std::u16string_view rSectionName)
570 std::unique_ptr<weld::TreeIter> xIter(m_xTree->make_iterator());
571 if (!m_xTree->get_iter_first(*xIter))
572 return;
576 SectRepr* pRepr = weld::fromId<SectRepr*>(m_xTree->get_id(*xIter));
577 if (pRepr->GetSectionData().GetSectionName() == rSectionName)
579 m_xTree->unselect_all();
580 m_xTree->select(*xIter);
581 m_xTree->scroll_to_row(*xIter);
582 GetFirstEntryHdl(*m_xTree);
583 break;
585 } while (m_xTree->iter_next(*xIter));
588 // selected entry in TreeListBox is showed in Edit window in case of
589 // multiselection some controls are disabled
590 IMPL_LINK(SwEditRegionDlg, GetFirstEntryHdl, weld::TreeView&, rBox, void)
592 m_bDontCheckPasswd = true;
593 std::unique_ptr<weld::TreeIter> xIter(rBox.make_iterator());
594 bool bEntry = rBox.get_selected(xIter.get());
595 m_xHideCB->set_sensitive(true);
596 // edit in readonly sections
597 m_xEditInReadonlyCB->set_sensitive(true);
599 m_xProtectCB->set_sensitive(true);
600 m_xFileCB->set_sensitive(true);
601 css::uno::Sequence <sal_Int8> aCurPasswd;
602 if (1 < rBox.count_selected_rows())
604 m_xHideCB->set_state(TRISTATE_INDET);
605 m_xProtectCB->set_state(TRISTATE_INDET);
606 // edit in readonly sections
607 m_xEditInReadonlyCB->set_state(TRISTATE_INDET);
608 m_xFileCB->set_state(TRISTATE_INDET);
610 bool bHiddenValid = true;
611 bool bProtectValid = true;
612 bool bConditionValid = true;
613 // edit in readonly sections
614 bool bEditInReadonlyValid = true;
615 bool bEditInReadonly = true;
617 bool bHidden = true;
618 bool bProtect = true;
619 OUString sCondition;
620 bool bFirst = true;
621 bool bFileValid = true;
622 bool bFile = true;
623 bool bPasswdValid = true;
625 m_xTree->selected_foreach([&](weld::TreeIter& rEntry){
626 SectRepr* pRepr = weld::fromId<SectRepr*>(m_xTree->get_id(rEntry));
627 SwSectionData const& rData( pRepr->GetSectionData() );
628 if(bFirst)
630 sCondition = rData.GetCondition();
631 bHidden = rData.IsHidden();
632 bProtect = rData.IsProtectFlag();
633 // edit in readonly sections
634 bEditInReadonly = rData.IsEditInReadonlyFlag();
636 bFile = (rData.GetType() != SectionType::Content);
637 aCurPasswd = rData.GetPassword();
639 else
641 if(sCondition != rData.GetCondition())
642 bConditionValid = false;
643 bHiddenValid = (bHidden == rData.IsHidden());
644 bProtectValid = (bProtect == rData.IsProtectFlag());
645 // edit in readonly sections
646 bEditInReadonlyValid =
647 (bEditInReadonly == rData.IsEditInReadonlyFlag());
649 bFileValid = (bFile ==
650 (rData.GetType() != SectionType::Content));
651 bPasswdValid = (aCurPasswd == rData.GetPassword());
653 bFirst = false;
654 return false;
657 m_xHideCB->set_state(!bHiddenValid ? TRISTATE_INDET :
658 bHidden ? TRISTATE_TRUE : TRISTATE_FALSE);
659 m_xProtectCB->set_state(!bProtectValid ? TRISTATE_INDET :
660 bProtect ? TRISTATE_TRUE : TRISTATE_FALSE);
661 // edit in readonly sections
662 m_xEditInReadonlyCB->set_state(!bEditInReadonlyValid ? TRISTATE_INDET :
663 bEditInReadonly ? TRISTATE_TRUE : TRISTATE_FALSE);
665 m_xFileCB->set_state(!bFileValid ? TRISTATE_INDET :
666 bFile ? TRISTATE_TRUE : TRISTATE_FALSE);
668 if (bConditionValid)
669 m_xConditionED->set_text(sCondition);
670 else
672 m_xConditionFT->set_sensitive(false);
673 m_xConditionED->set_sensitive(false);
676 m_xCurName->set_sensitive(false);
677 m_xDDECB->set_sensitive(false);
678 m_xDDEFrame->set_sensitive(false);
679 m_xOptionsPB->set_sensitive(false);
680 bool bPasswdEnabled = m_xProtectCB->get_state() == TRISTATE_TRUE;
681 m_xPasswdCB->set_sensitive(bPasswdEnabled);
682 m_xPasswdPB->set_sensitive(bPasswdEnabled);
683 if(!bPasswdValid)
685 rBox.get_selected(xIter.get());
686 rBox.unselect_all();
687 rBox.select(*xIter);
688 GetFirstEntryHdl(rBox);
689 return;
691 else
692 m_xPasswdCB->set_active(aCurPasswd.hasElements());
694 else if (bEntry )
696 m_xCurName->set_sensitive(true);
697 m_xOptionsPB->set_sensitive(true);
698 SectRepr* pRepr = weld::fromId<SectRepr*>(m_xTree->get_id(*xIter));
699 SwSectionData const& rData( pRepr->GetSectionData() );
700 m_xConditionED->set_text(rData.GetCondition());
701 m_xHideCB->set_sensitive(true);
702 m_xHideCB->set_state((rData.IsHidden()) ? TRISTATE_TRUE : TRISTATE_FALSE);
703 bool bHide = TRISTATE_TRUE == m_xHideCB->get_state();
704 m_xConditionED->set_sensitive(bHide);
705 m_xConditionFT->set_sensitive(bHide);
706 m_xPasswdCB->set_active(rData.GetPassword().hasElements());
708 m_xOK->set_sensitive(true);
709 m_xPasswdCB->set_sensitive(true);
710 m_xCurName->set_text(rBox.get_text(*xIter));
711 m_xCurName->set_sensitive(true);
712 m_xDismiss->set_sensitive(true);
713 const OUString aFile = pRepr->GetFile();
714 const OUString sSub = pRepr->GetSubRegion();
715 m_xSubRegionED->clear();
716 m_xSubRegionED->append_text(""); // put in a dummy entry, which is replaced when m_bSubRegionsFilled is set
717 m_bSubRegionsFilled = false;
718 if( !aFile.isEmpty() || !sSub.isEmpty() )
720 m_xFileCB->set_active(true);
721 m_xFileNameED->set_text(aFile);
722 m_xSubRegionED->set_entry_text(sSub);
723 m_xDDECB->set_active(rData.GetType() == SectionType::DdeLink);
725 else
727 m_xFileCB->set_active(false);
728 m_xFileNameED->set_text(aFile);
729 m_xDDECB->set_sensitive(false);
730 m_xDDECB->set_active(false);
732 UseFileHdl(*m_xFileCB);
733 DDEHdl(*m_xDDECB);
734 m_xProtectCB->set_state((rData.IsProtectFlag())
735 ? TRISTATE_TRUE : TRISTATE_FALSE);
736 m_xProtectCB->set_sensitive(true);
738 // edit in readonly sections
739 m_xEditInReadonlyCB->set_state((rData.IsEditInReadonlyFlag())
740 ? TRISTATE_TRUE : TRISTATE_FALSE);
741 m_xEditInReadonlyCB->set_sensitive(true);
743 bool bPasswdEnabled = m_xProtectCB->get_active();
744 m_xPasswdCB->set_sensitive(bPasswdEnabled);
745 m_xPasswdPB->set_sensitive(bPasswdEnabled);
747 m_bDontCheckPasswd = false;
750 // in OkHdl the modified settings are being applied and reversed regions are deleted
751 IMPL_LINK_NOARG(SwEditRegionDlg, OkHdl, weld::Button&, void)
753 // temp. Array because during changing of a region the position
754 // inside of the "Core-Arrays" can be shifted:
755 // - at linked regions, when they have more SubRegions or get
756 // new ones.
757 // StartUndo must certainly also happen not before the formats
758 // are copied (ClearRedo!)
760 const SwSectionFormats& rDocFormats = m_rSh.GetDoc()->GetSections();
761 SwSectionFormats aOrigArray(rDocFormats);
763 m_rSh.StartAllAction();
764 m_rSh.StartUndo();
765 m_rSh.ResetSelect( nullptr,false );
767 std::unique_ptr<weld::TreeIter> xIter(m_xTree->make_iterator());
768 if (m_xTree->get_iter_first(*xIter))
772 SectRepr* pRepr = weld::fromId<SectRepr*>(m_xTree->get_id(*xIter));
773 SwSectionFormat* pFormat = aOrigArray[ pRepr->GetArrPos() ];
774 if (!pRepr->GetSectionData().IsProtectFlag())
776 pRepr->GetSectionData().SetPassword(uno::Sequence<sal_Int8 >());
778 size_t nNewPos = rDocFormats.GetPos(pFormat);
779 if ( SIZE_MAX != nNewPos )
781 std::unique_ptr<SfxItemSet> pSet(pFormat->GetAttrSet().Clone( false ));
782 if( pFormat->GetCol() != pRepr->GetCol() )
783 pSet->Put( pRepr->GetCol() );
785 std::unique_ptr<SvxBrushItem> aBrush(pFormat->makeBackgroundBrushItem(false));
786 if( pRepr->GetBackground() && *aBrush != *pRepr->GetBackground() )
787 pSet->Put( *pRepr->GetBackground() );
789 if( pFormat->GetFootnoteAtTextEnd(false) != pRepr->GetFootnoteNtAtEnd() )
790 pSet->Put( pRepr->GetFootnoteNtAtEnd() );
792 if( pFormat->GetEndAtTextEnd(false) != pRepr->GetEndNtAtEnd() )
793 pSet->Put( pRepr->GetEndNtAtEnd() );
795 if( pFormat->GetBalancedColumns() != pRepr->GetBalance() )
796 pSet->Put( pRepr->GetBalance() );
798 if( pFormat->GetFrameDir() != *pRepr->GetFrameDir() )
799 pSet->Put( *pRepr->GetFrameDir() );
801 if( pFormat->GetLRSpace() != *pRepr->GetLRSpace())
802 pSet->Put( *pRepr->GetLRSpace());
804 m_rSh.UpdateSection( nNewPos, pRepr->GetSectionData(),
805 pSet->Count() ? pSet.get() : nullptr );
807 } while (m_xTree->iter_next(*xIter));
810 for (SectReprs_t::reverse_iterator it = m_SectReprs.rbegin(), aEnd = m_SectReprs.rend(); it != aEnd; ++it)
812 assert(it->first == it->second->GetArrPos());
813 SwSectionFormat* pFormat = aOrigArray[ it->second->GetArrPos() ];
814 const size_t nNewPos = rDocFormats.GetPos( pFormat );
815 if( SIZE_MAX != nNewPos )
816 m_rSh.DelSectionFormat( nNewPos );
819 aOrigArray.clear();
821 // response must be called ahead of EndAction's end,
822 // otherwise ScrollError can occur.
823 m_xDialog->response(RET_OK);
825 m_rSh.EndUndo();
826 m_rSh.EndAllAction();
829 // Toggle protect
830 IMPL_LINK(SwEditRegionDlg, ChangeProtectHdl, weld::Toggleable&, rButton, void)
832 if (!CheckPasswd(&rButton))
833 return;
834 bool bCheck = TRISTATE_TRUE == rButton.get_state();
835 m_xTree->selected_foreach([this, bCheck](weld::TreeIter& rEntry){
836 SectRepr* pRepr = weld::fromId<SectRepr*>(m_xTree->get_id(rEntry));
837 pRepr->GetSectionData().SetProtectFlag(bCheck);
838 OUString aImage = BuildBitmap(bCheck, TRISTATE_TRUE == m_xHideCB->get_state());
839 m_xTree->set_image(rEntry, aImage);
840 return false;
842 m_xPasswdCB->set_sensitive(bCheck);
843 m_xPasswdPB->set_sensitive(bCheck);
846 // Toggle hide
847 IMPL_LINK( SwEditRegionDlg, ChangeHideHdl, weld::Toggleable&, rButton, void)
849 if (!CheckPasswd(&rButton))
850 return;
851 m_xTree->selected_foreach([this, &rButton](weld::TreeIter& rEntry){
852 SectRepr* pRepr = weld::fromId<SectRepr*>(m_xTree->get_id(rEntry));
853 pRepr->GetSectionData().SetHidden(TRISTATE_TRUE == rButton.get_state());
854 OUString aImage = BuildBitmap(TRISTATE_TRUE == m_xProtectCB->get_state(),
855 TRISTATE_TRUE == rButton.get_state());
856 m_xTree->set_image(rEntry, aImage);
857 return false;
859 bool bHide = TRISTATE_TRUE == rButton.get_state();
860 m_xConditionED->set_sensitive(bHide);
861 m_xConditionFT->set_sensitive(bHide);
864 // Toggle edit in readonly
865 IMPL_LINK(SwEditRegionDlg, ChangeEditInReadonlyHdl, weld::Toggleable&, rButton, void)
867 if (!CheckPasswd(&rButton))
868 return;
869 m_xTree->selected_foreach([this, &rButton](weld::TreeIter& rEntry){
870 SectRepr* pRepr = weld::fromId<SectRepr*>(m_xTree->get_id(rEntry));
871 pRepr->GetSectionData().SetEditInReadonlyFlag(
872 TRISTATE_TRUE == rButton.get_state());
873 return false;
877 // clear selected region
878 IMPL_LINK_NOARG(SwEditRegionDlg, ChangeDismissHdl, weld::Button&, void)
880 if(!CheckPasswd())
881 return;
882 // at first mark all selected
883 m_xTree->selected_foreach([this](weld::TreeIter& rEntry){
884 SectRepr* const pSectRepr = weld::fromId<SectRepr*>(m_xTree->get_id(rEntry));
885 pSectRepr->SetSelected();
886 return false;
889 std::unique_ptr<weld::TreeIter> xEntry(m_xTree->make_iterator());
890 bool bEntry(m_xTree->get_selected(xEntry.get()));
891 // then delete
892 while (bEntry)
894 SectRepr* const pSectRepr = weld::fromId<SectRepr*>(m_xTree->get_id(*xEntry));
895 std::unique_ptr<weld::TreeIter> xRemove;
896 bool bRestart = false;
897 if (pSectRepr->IsSelected())
899 m_SectReprs.insert(std::make_pair(pSectRepr->GetArrPos(),
900 std::unique_ptr<SectRepr>(pSectRepr)));
901 if (m_xTree->iter_has_child(*xEntry))
903 std::unique_ptr<weld::TreeIter> xChild(m_xTree->make_iterator(xEntry.get()));
904 (void)m_xTree->iter_children(*xChild);
905 std::unique_ptr<weld::TreeIter> xParent(m_xTree->make_iterator(xEntry.get()));
906 if (!m_xTree->iter_parent(*xParent))
907 xParent.reset();
908 bool bChild = true;
911 // because of the repositioning we have to start at the beginning again
912 bRestart = true;
913 std::unique_ptr<weld::TreeIter> xMove(m_xTree->make_iterator(xChild.get()));
914 bChild = m_xTree->iter_next_sibling(*xChild);
915 m_xTree->move_subtree(*xMove, xParent.get(), m_xTree->get_iter_index_in_parent(*xEntry));
916 } while (bChild);
918 xRemove = m_xTree->make_iterator(xEntry.get());
920 if (bRestart)
921 bEntry = m_xTree->get_iter_first(*xEntry);
922 else
923 bEntry = m_xTree->iter_next(*xEntry);
924 if (xRemove)
925 m_xTree->remove(*xRemove);
928 if (m_xTree->get_selected(nullptr))
929 return;
931 m_xConditionFT->set_sensitive(false);
932 m_xConditionED->set_sensitive(false);
933 m_xDismiss->set_sensitive(false);
934 m_xCurName->set_sensitive(false);
935 m_xProtectCB->set_sensitive(false);
936 m_xPasswdCB->set_sensitive(false);
937 m_xHideCB->set_sensitive(false);
938 // edit in readonly sections
939 m_xEditInReadonlyCB->set_sensitive(false);
940 m_xEditInReadonlyCB->set_state(TRISTATE_FALSE);
941 m_xProtectCB->set_state(TRISTATE_FALSE);
942 m_xPasswdCB->set_active(false);
943 m_xHideCB->set_state(TRISTATE_FALSE);
944 m_xFileCB->set_active(false);
945 // otherwise the focus would be on HelpButton
946 m_xOK->grab_focus();
947 UseFileHdl(*m_xFileCB);
950 // link CheckBox to file?
951 IMPL_LINK(SwEditRegionDlg, UseFileHdl, weld::Toggleable&, rButton, void)
953 if (!CheckPasswd(&rButton))
954 return;
955 bool bMulti = 1 < m_xTree->count_selected_rows();
956 bool bFile = rButton.get_active();
957 if (m_xTree->get_selected(nullptr))
959 m_xTree->selected_foreach([&](weld::TreeIter& rEntry){
960 SectRepr* const pSectRepr = weld::fromId<SectRepr*>(m_xTree->get_id(rEntry));
961 bool bContent = pSectRepr->IsContent();
962 if( rButton.get_active() && bContent && m_rSh.HasSelection() )
964 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(m_xDialog.get(),
965 VclMessageType::Question, VclButtonsType::YesNo,
966 SwResId(STR_QUERY_CONNECT)));
967 if (RET_NO == xQueryBox->run())
968 rButton.set_active( false );
970 if( bFile )
971 pSectRepr->SetContent(false);
972 else
974 pSectRepr->SetFile(u"");
975 pSectRepr->SetSubRegion(std::u16string_view());
976 pSectRepr->GetSectionData().SetLinkFilePassword(OUString());
978 return false;
980 m_xDDECB->set_sensitive(bFile && !bMulti);
981 m_xDDEFrame->set_sensitive(bFile && !bMulti);
982 if( bFile )
984 m_xProtectCB->set_state(TRISTATE_TRUE);
985 m_xFileNameED->grab_focus();
988 else
990 m_xDDECB->set_active(false);
991 m_xSubRegionED->set_entry_text(OUString());
993 DDEHdl(*m_xDDECB);
995 else
997 rButton.set_active(false);
998 rButton.set_sensitive(false);
999 m_xDDECB->set_active(false);
1000 m_xDDECB->set_sensitive(false);
1001 m_xDDEFrame->set_sensitive(false);
1005 // call dialog paste file
1006 IMPL_LINK_NOARG(SwEditRegionDlg, FileSearchHdl, weld::Button&, void)
1008 if(!CheckPasswd())
1009 return;
1010 m_pDocInserter.reset(new ::sfx2::DocumentInserter(m_xDialog.get(), "swriter"));
1011 m_pDocInserter->StartExecuteModal( LINK( this, SwEditRegionDlg, DlgClosedHdl ) );
1014 IMPL_LINK_NOARG(SwEditRegionDlg, OptionsHdl, weld::Button&, void)
1016 if(!CheckPasswd())
1017 return;
1018 SectRepr* pSectRepr = weld::fromId<SectRepr*>(m_xTree->get_selected_id());
1019 if (!pSectRepr)
1020 return;
1022 SfxItemSetFixed<
1023 RES_FRM_SIZE, RES_FRM_SIZE,
1024 RES_LR_SPACE, RES_LR_SPACE,
1025 RES_BACKGROUND, RES_BACKGROUND,
1026 RES_COL, RES_COL,
1027 RES_FTN_AT_TXTEND, RES_FRAMEDIR,
1028 XATTR_FILL_FIRST, XATTR_FILL_LAST,
1029 SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE> aSet( m_rSh.GetView().GetPool() );
1031 aSet.Put( pSectRepr->GetCol() );
1032 aSet.Put( *pSectRepr->GetBackground() );
1033 aSet.Put( pSectRepr->GetFootnoteNtAtEnd() );
1034 aSet.Put( pSectRepr->GetEndNtAtEnd() );
1035 aSet.Put( pSectRepr->GetBalance() );
1036 aSet.Put( *pSectRepr->GetFrameDir() );
1037 aSet.Put( *pSectRepr->GetLRSpace() );
1039 const SwSectionFormats& rDocFormats = m_rSh.GetDoc()->GetSections();
1040 SwSectionFormats aOrigArray(rDocFormats);
1042 SwSectionFormat* pFormat = aOrigArray[pSectRepr->GetArrPos()];
1043 tools::Long nWidth = m_rSh.GetSectionWidth(*pFormat);
1044 aOrigArray.clear();
1045 if (!nWidth)
1046 nWidth = USHRT_MAX;
1048 aSet.Put(SwFormatFrameSize(SwFrameSize::Variable, nWidth));
1049 aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
1051 SwSectionPropertyTabDialog aTabDlg(m_xDialog.get(), aSet, m_rSh);
1052 if (RET_OK != aTabDlg.run())
1053 return;
1055 const SfxItemSet* pOutSet = aTabDlg.GetOutputItemSet();
1056 if( !(pOutSet && pOutSet->Count()) )
1057 return;
1059 const SwFormatCol* pColItem = pOutSet->GetItemIfSet(
1060 RES_COL, false );
1061 const SvxBrushItem* pBrushItem = pOutSet->GetItemIfSet(
1062 RES_BACKGROUND, false );
1063 const SwFormatFootnoteAtTextEnd* pFootnoteItem = pOutSet->GetItemIfSet(
1064 RES_FTN_AT_TXTEND, false );
1065 const SwFormatEndAtTextEnd* pEndItem = pOutSet->GetItemIfSet(
1066 RES_END_AT_TXTEND, false );
1067 const SwFormatNoBalancedColumns* pBalanceItem = pOutSet->GetItemIfSet(
1068 RES_COLUMNBALANCE, false );
1069 const SvxFrameDirectionItem* pFrameDirItem = pOutSet->GetItemIfSet(
1070 RES_FRAMEDIR, false );
1071 const SvxLRSpaceItem* pLRSpaceItem = pOutSet->GetItemIfSet(
1072 RES_LR_SPACE, false );
1074 if( !(pColItem ||
1075 pBrushItem ||
1076 pFootnoteItem ||
1077 pEndItem ||
1078 pBalanceItem ||
1079 pFrameDirItem ||
1080 pLRSpaceItem) )
1081 return;
1083 m_xTree->selected_foreach([&](weld::TreeIter& rEntry)
1085 SectRepr* pRepr = weld::fromId<SectRepr*>(m_xTree->get_id(rEntry));
1086 if (pColItem)
1087 pRepr->GetCol() = *pColItem;
1088 if (pBrushItem)
1089 pRepr->GetBackground().reset(pBrushItem->Clone());
1090 if (pFootnoteItem)
1091 pRepr->GetFootnoteNtAtEnd() = *pFootnoteItem;
1092 if (pEndItem)
1093 pRepr->GetEndNtAtEnd() = *pEndItem;
1094 if (pBalanceItem)
1095 pRepr->GetBalance().SetValue(pBalanceItem->GetValue());
1096 if (pFrameDirItem)
1097 pRepr->GetFrameDir()->SetValue(pFrameDirItem->GetValue());
1098 if (pLRSpaceItem)
1099 pRepr->GetLRSpace().reset(pLRSpaceItem->Clone());
1100 return false;
1104 IMPL_LINK(SwEditRegionDlg, FileNameComboBoxHdl, weld::ComboBox&, rEdit, void)
1106 int nStartPos, nEndPos;
1107 rEdit.get_entry_selection_bounds(nStartPos, nEndPos);
1108 if (!CheckPasswd())
1109 return;
1110 rEdit.select_entry_region(nStartPos, nEndPos);
1111 SectRepr* pSectRepr = weld::fromId<SectRepr*>(m_xTree->get_selected_id());
1112 pSectRepr->SetSubRegion( rEdit.get_active_text() );
1115 // Applying of the filename or the linked region
1116 IMPL_LINK(SwEditRegionDlg, FileNameEntryHdl, weld::Entry&, rEdit, void)
1118 int nStartPos, nEndPos;
1119 rEdit.get_selection_bounds(nStartPos, nEndPos);
1120 if (!CheckPasswd())
1121 return;
1122 rEdit.select_region(nStartPos, nEndPos);
1123 SectRepr* pSectRepr = weld::fromId<SectRepr*>(m_xTree->get_selected_id());
1124 m_xSubRegionED->clear();
1125 m_xSubRegionED->append_text(""); // put in a dummy entry, which is replaced when m_bSubRegionsFilled is set
1126 m_bSubRegionsFilled = false;
1127 if (m_xDDECB->get_active())
1129 OUString sLink( CollapseWhiteSpaces(rEdit.get_text()) );
1130 sal_Int32 nPos = 0;
1131 sLink = sLink.replaceFirst( " ", OUStringChar(sfx2::cTokenSeparator), &nPos );
1132 if (nPos>=0)
1134 sLink = sLink.replaceFirst( " ", OUStringChar(sfx2::cTokenSeparator), &nPos );
1137 pSectRepr->GetSectionData().SetLinkFileName( sLink );
1138 pSectRepr->GetSectionData().SetType( SectionType::DdeLink );
1140 else
1142 OUString sTmp(rEdit.get_text());
1143 if(!sTmp.isEmpty())
1145 SfxMedium* pMedium = m_rSh.GetView().GetDocShell()->GetMedium();
1146 INetURLObject aAbs;
1147 if( pMedium )
1148 aAbs = pMedium->GetURLObject();
1149 sTmp = URIHelper::SmartRel2Abs(
1150 aAbs, sTmp, URIHelper::GetMaybeFileHdl() );
1152 pSectRepr->SetFile( sTmp );
1153 pSectRepr->GetSectionData().SetLinkFilePassword(OUString());
1157 IMPL_LINK(SwEditRegionDlg, DDEHdl, weld::Toggleable&, rButton, void)
1159 if (!CheckPasswd(&rButton))
1160 return;
1161 SectRepr* pSectRepr = weld::fromId<SectRepr*>(m_xTree->get_selected_id());
1162 if (!pSectRepr)
1163 return;
1165 bool bFile = m_xFileCB->get_active();
1166 SwSectionData & rData( pSectRepr->GetSectionData() );
1167 bool bDDE = rButton.get_active();
1168 if(bDDE)
1170 m_xFileNameFT->hide();
1171 m_xDDECommandFT->set_sensitive(true);
1172 m_xDDECommandFT->show();
1173 m_xSubRegionFT->hide();
1174 m_xSubRegionED->hide();
1175 if (SectionType::FileLink == rData.GetType())
1177 pSectRepr->SetFile(u"");
1178 m_xFileNameED->set_text(OUString());
1179 rData.SetLinkFilePassword(OUString());
1181 rData.SetType(SectionType::DdeLink);
1183 else
1185 m_xDDECommandFT->hide();
1186 m_xFileNameFT->set_sensitive(bFile);
1187 if(!comphelper::LibreOfficeKit::isActive())
1188 m_xFileNameFT->show();
1189 m_xSubRegionED->show();
1190 m_xSubRegionFT->show();
1191 m_xSubRegionED->set_sensitive(bFile);
1192 m_xSubRegionFT->set_sensitive(bFile);
1193 m_xSubRegionED->set_sensitive(bFile);
1194 if (SectionType::DdeLink == rData.GetType())
1196 rData.SetType(SectionType::FileLink);
1197 pSectRepr->SetFile(u"");
1198 rData.SetLinkFilePassword(OUString());
1199 m_xFileNameED->set_text(OUString());
1202 m_xFilePB->set_sensitive(bFile && !bDDE);
1205 void SwEditRegionDlg::ChangePasswd(bool bChange)
1207 if (!CheckPasswd())
1209 if (!bChange)
1210 m_xPasswdCB->set_active(!m_xPasswdCB->get_active());
1211 return;
1214 bool bSet = bChange ? bChange : m_xPasswdCB->get_active();
1216 m_xTree->selected_foreach([this, bChange, bSet](weld::TreeIter& rEntry){
1217 SectRepr* pRepr = weld::fromId<SectRepr*>(m_xTree->get_id(rEntry));
1218 if(bSet)
1220 if(!pRepr->GetTempPasswd().hasElements() || bChange)
1222 SfxPasswordDialog aPasswdDlg(m_xDialog.get());
1223 aPasswdDlg.ShowExtras(SfxShowExtras::CONFIRM);
1224 if (RET_OK == aPasswdDlg.run())
1226 const OUString sNewPasswd(aPasswdDlg.GetPassword());
1227 if (aPasswdDlg.GetConfirm() == sNewPasswd)
1229 SvPasswordHelper::GetHashPassword( pRepr->GetTempPasswd(), sNewPasswd );
1231 else
1233 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(m_xDialog.get(),
1234 VclMessageType::Info, VclButtonsType::Ok,
1235 SwResId(STR_WRONG_PASSWD_REPEAT)));
1236 xInfoBox->run();
1237 ChangePasswd(bChange);
1238 return true;
1241 else
1243 if(!bChange)
1244 m_xPasswdCB->set_active(false);
1245 return true;
1248 pRepr->GetSectionData().SetPassword(pRepr->GetTempPasswd());
1250 else
1252 pRepr->GetSectionData().SetPassword(uno::Sequence<sal_Int8 >());
1254 return false;
1258 IMPL_LINK_NOARG(SwEditRegionDlg, TogglePasswdHdl, weld::Toggleable&, void)
1260 ChangePasswd(false);
1263 IMPL_LINK_NOARG(SwEditRegionDlg, ChangePasswdHdl, weld::Button&, void)
1265 ChangePasswd(true);
1268 // the current region name is being added to the TreeListBox immediately during
1269 // editing, with empty string no Ok()
1270 IMPL_LINK_NOARG(SwEditRegionDlg, NameEditHdl, weld::Entry&, void)
1272 if(!CheckPasswd())
1273 return;
1274 std::unique_ptr<weld::TreeIter> xIter(m_xTree->make_iterator());
1275 if (m_xTree->get_selected(xIter.get()))
1277 const OUString aName = m_xCurName->get_text();
1278 m_xTree->set_text(*xIter, aName);
1279 SectRepr* pRepr = weld::fromId<SectRepr*>(m_xTree->get_id(*xIter));
1280 pRepr->GetSectionData().SetSectionName(aName);
1282 m_xOK->set_sensitive(!aName.isEmpty());
1286 IMPL_LINK( SwEditRegionDlg, ConditionEditHdl, weld::Entry&, rEdit, void )
1288 int nStartPos, nEndPos;
1289 rEdit.get_selection_bounds(nStartPos, nEndPos);
1290 if(!CheckPasswd())
1291 return;
1292 rEdit.select_region(nStartPos, nEndPos);
1294 m_xTree->selected_foreach([this, &rEdit](weld::TreeIter& rEntry){
1295 SectRepr* pRepr = weld::fromId<SectRepr*>(m_xTree->get_id(rEntry));
1296 pRepr->GetSectionData().SetCondition(rEdit.get_text());
1297 return false;
1301 IMPL_LINK( SwEditRegionDlg, DlgClosedHdl, sfx2::FileDialogHelper *, _pFileDlg, void )
1303 OUString sFileName, sFilterName, sPassword;
1304 if ( _pFileDlg->GetError() == ERRCODE_NONE )
1306 std::unique_ptr<SfxMedium> pMedium(m_pDocInserter->CreateMedium("sglobal"));
1307 if ( pMedium )
1309 sFileName = pMedium->GetURLObject().GetMainURL( INetURLObject::DecodeMechanism::NONE );
1310 sFilterName = pMedium->GetFilter()->GetFilterName();
1311 if ( const SfxStringItem* pItem = pMedium->GetItemSet()->GetItemIfSet( SID_PASSWORD, false ) )
1312 sPassword = pItem->GetValue();
1313 ::lcl_ReadSections(*pMedium, *m_xSubRegionED);
1317 SectRepr* pSectRepr = weld::fromId<SectRepr*>(m_xTree->get_selected_id());
1318 if (pSectRepr)
1320 pSectRepr->SetFile( sFileName );
1321 pSectRepr->SetFilter( sFilterName );
1322 pSectRepr->GetSectionData().SetLinkFilePassword(sPassword);
1323 m_xFileNameED->set_text(pSectRepr->GetFile());
1327 IMPL_LINK_NOARG(SwEditRegionDlg, SubRegionEventHdl, weld::ComboBox&, void)
1329 if (m_bSubRegionsFilled)
1330 return;
1332 //if necessary fill the names bookmarks/sections/tables now
1334 OUString sFileName = m_xFileNameED->get_text();
1335 if(!sFileName.isEmpty())
1337 SfxMedium* pMedium = m_rSh.GetView().GetDocShell()->GetMedium();
1338 INetURLObject aAbs;
1339 if( pMedium )
1340 aAbs = pMedium->GetURLObject();
1341 sFileName = URIHelper::SmartRel2Abs(
1342 aAbs, sFileName, URIHelper::GetMaybeFileHdl() );
1344 //load file and set the shell
1345 SfxMedium aMedium( sFileName, StreamMode::STD_READ );
1346 sFileName = aMedium.GetURLObject().GetMainURL( INetURLObject::DecodeMechanism::NONE );
1347 ::lcl_ReadSections(aMedium, *m_xSubRegionED);
1349 else
1350 lcl_FillSubRegionList(m_rSh, *m_xSubRegionED, nullptr);
1351 m_bSubRegionsFilled = true;
1354 // helper function - read section names from medium
1355 static void lcl_ReadSections( SfxMedium& rMedium, weld::ComboBox& rBox )
1357 rBox.clear();
1358 uno::Reference < embed::XStorage > xStg;
1359 if( !(rMedium.IsStorage() && (xStg = rMedium.GetStorage()).is()) )
1360 return;
1362 std::vector<OUString> aArr;
1363 SotClipboardFormatId nFormat = SotStorage::GetFormatID( xStg );
1364 if ( nFormat == SotClipboardFormatId::STARWRITER_60 || nFormat == SotClipboardFormatId::STARWRITERGLOB_60 ||
1365 nFormat == SotClipboardFormatId::STARWRITER_8 || nFormat == SotClipboardFormatId::STARWRITERGLOB_8)
1366 SwGetReaderXML()->GetSectionList( rMedium, aArr );
1368 for (auto const& it : aArr)
1370 rBox.append_text(it);
1374 SwInsertSectionTabDialog::SwInsertSectionTabDialog(
1375 weld::Window* pParent, const SfxItemSet& rSet, SwWrtShell& rSh)
1376 : SfxTabDialogController(pParent, "modules/swriter/ui/insertsectiondialog.ui",
1377 "InsertSectionDialog",&rSet)
1378 , m_rWrtSh(rSh)
1380 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1381 AddTabPage("section", SwInsertSectionTabPage::Create, nullptr);
1382 AddTabPage("columns", SwColumnPage::Create, nullptr);
1383 AddTabPage("background", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_BKG), nullptr);
1384 AddTabPage("notes", SwSectionFootnoteEndTabPage::Create, nullptr);
1385 AddTabPage("indents", SwSectionIndentTabPage::Create, nullptr);
1387 tools::Long nHtmlMode = SvxHtmlOptions::GetExportMode();
1389 bool bWeb = dynamic_cast<SwWebDocShell*>( rSh.GetView().GetDocShell() ) != nullptr ;
1390 if(bWeb)
1392 RemoveTabPage("notes");
1393 RemoveTabPage("indents");
1394 if( HTML_CFG_NS40 != nHtmlMode && HTML_CFG_WRITER != nHtmlMode)
1395 RemoveTabPage("columns");
1397 SetCurPageId("section");
1400 SwInsertSectionTabDialog::~SwInsertSectionTabDialog()
1404 void SwInsertSectionTabDialog::PageCreated(const OUString& rId, SfxTabPage &rPage)
1406 if (rId == "section")
1407 static_cast<SwInsertSectionTabPage&>(rPage).SetWrtShell(m_rWrtSh);
1408 else if (rId == "background")
1410 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
1411 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, static_cast<sal_uInt32>(SvxBackgroundTabFlags::SHOW_SELECTOR)));
1412 rPage.PageCreated(aSet);
1414 else if (rId == "columns")
1416 const SwFormatFrameSize& rSize = GetInputSetImpl()->Get(RES_FRM_SIZE);
1417 static_cast<SwColumnPage&>(rPage).SetPageWidth(rSize.GetWidth());
1418 static_cast<SwColumnPage&>(rPage).ShowBalance(true);
1419 static_cast<SwColumnPage&>(rPage).SetInSection(true);
1421 else if (rId == "indents")
1422 static_cast<SwSectionIndentTabPage&>(rPage).SetWrtShell(m_rWrtSh);
1425 void SwInsertSectionTabDialog::SetSectionData(SwSectionData const& rSect)
1427 m_pSectionData.reset( new SwSectionData(rSect) );
1430 short SwInsertSectionTabDialog::Ok()
1432 short nRet = SfxTabDialogController::Ok();
1433 OSL_ENSURE(m_pSectionData, "SwInsertSectionTabDialog: no SectionData?");
1434 const SfxItemSet* pOutputItemSet = GetOutputItemSet();
1435 m_rWrtSh.InsertSection(*m_pSectionData, pOutputItemSet);
1436 SfxViewFrame& rViewFrame = m_rWrtSh.GetView().GetViewFrame();
1437 uno::Reference< frame::XDispatchRecorder > xRecorder =
1438 rViewFrame.GetBindings().GetRecorder();
1439 if ( xRecorder.is() )
1441 SfxRequest aRequest(rViewFrame, FN_INSERT_REGION);
1442 if(const SwFormatCol* pCol = pOutputItemSet->GetItemIfSet(RES_COL, false))
1444 aRequest.AppendItem(SfxUInt16Item(SID_ATTR_COLUMNS,
1445 pCol->GetColumns().size()));
1447 aRequest.AppendItem(SfxStringItem( FN_PARAM_REGION_NAME,
1448 m_pSectionData->GetSectionName()));
1449 aRequest.AppendItem(SfxStringItem( FN_PARAM_REGION_CONDITION,
1450 m_pSectionData->GetCondition()));
1451 aRequest.AppendItem(SfxBoolItem( FN_PARAM_REGION_HIDDEN,
1452 m_pSectionData->IsHidden()));
1453 aRequest.AppendItem(SfxBoolItem( FN_PARAM_REGION_PROTECT,
1454 m_pSectionData->IsProtectFlag()));
1455 // edit in readonly sections
1456 aRequest.AppendItem(SfxBoolItem( FN_PARAM_REGION_EDIT_IN_READONLY,
1457 m_pSectionData->IsEditInReadonlyFlag()));
1459 const OUString sLinkFileName( m_pSectionData->GetLinkFileName() );
1460 sal_Int32 n = 0;
1461 aRequest.AppendItem(SfxStringItem( FN_PARAM_1, sLinkFileName.getToken( 0, sfx2::cTokenSeparator, n )));
1462 aRequest.AppendItem(SfxStringItem( FN_PARAM_2, sLinkFileName.getToken( 0, sfx2::cTokenSeparator, n )));
1463 aRequest.AppendItem(SfxStringItem( FN_PARAM_3, sLinkFileName.getToken( 0, sfx2::cTokenSeparator, n )));
1464 aRequest.Done();
1466 return nRet;
1469 SwInsertSectionTabPage::SwInsertSectionTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet &rAttrSet)
1470 : SfxTabPage(pPage, pController, "modules/swriter/ui/sectionpage.ui", "SectionPage", &rAttrSet)
1471 , m_pWrtSh(nullptr)
1472 , m_xCurName(m_xBuilder->weld_entry_tree_view("sectionnames", "sectionnames-entry",
1473 "sectionnames-list"))
1474 , m_xFileCB(m_xBuilder->weld_check_button("link"))
1475 , m_xDDECB(m_xBuilder->weld_check_button("dde"))
1476 , m_xDDECommandFT(m_xBuilder->weld_label("ddelabel"))
1477 , m_xFileNameFT(m_xBuilder->weld_label("filelabel"))
1478 , m_xFileNameED(m_xBuilder->weld_entry("filename"))
1479 , m_xFilePB(m_xBuilder->weld_button("selectfile"))
1480 , m_xSubRegionFT(m_xBuilder->weld_label("sectionlabel"))
1481 , m_xSubRegionED(m_xBuilder->weld_combo_box("sectionname"))
1482 , m_xProtectCB(m_xBuilder->weld_check_button("protect"))
1483 , m_xPasswdCB(m_xBuilder->weld_check_button("withpassword"))
1484 , m_xPasswdPB(m_xBuilder->weld_button("selectpassword"))
1485 , m_xHideCB(m_xBuilder->weld_check_button("hide"))
1486 , m_xConditionFT(m_xBuilder->weld_label("condlabel"))
1487 , m_xConditionED(new ConditionEdit(m_xBuilder->weld_entry("withcond")))
1488 // edit in readonly sections
1489 , m_xEditInReadonlyCB(m_xBuilder->weld_check_button("editable"))
1491 m_xCurName->make_sorted();
1492 m_xCurName->set_height_request_by_rows(12);
1493 m_xSubRegionED->make_sorted();
1495 m_xProtectCB->connect_toggled( LINK( this, SwInsertSectionTabPage, ChangeProtectHdl));
1496 m_xPasswdCB->connect_toggled( LINK( this, SwInsertSectionTabPage, TogglePasswdHdl));
1497 m_xPasswdPB->connect_clicked( LINK( this, SwInsertSectionTabPage, ChangePasswdHdl));
1498 m_xHideCB->connect_toggled( LINK( this, SwInsertSectionTabPage, ChangeHideHdl));
1499 m_xFileCB->connect_toggled( LINK( this, SwInsertSectionTabPage, UseFileHdl ));
1500 m_xFilePB->connect_clicked( LINK( this, SwInsertSectionTabPage, FileSearchHdl ));
1501 m_xCurName->connect_changed( LINK( this, SwInsertSectionTabPage, NameEditHdl));
1502 m_xDDECB->connect_toggled( LINK( this, SwInsertSectionTabPage, DDEHdl ));
1503 ChangeProtectHdl(*m_xProtectCB);
1504 m_xSubRegionED->set_entry_completion(true, true);
1506 // Hide Link section. In general it makes no sense to insert a file from the jail,
1507 // because it does not contain any usable files (documents).
1508 if(comphelper::LibreOfficeKit::isActive())
1510 m_xBuilder->weld_label("label1")->hide(); // Link
1511 m_xFileCB->hide();
1512 m_xDDECB->hide();
1513 m_xDDECommandFT->hide();
1514 m_xFileNameFT->hide();
1515 m_xFileNameED->hide();
1516 m_xFilePB->hide();
1517 m_xSubRegionFT->hide();
1518 m_xSubRegionED->hide();
1522 SwInsertSectionTabPage::~SwInsertSectionTabPage()
1526 void SwInsertSectionTabPage::SetWrtShell(SwWrtShell& rSh)
1528 m_pWrtSh = &rSh;
1530 bool bWeb = dynamic_cast<SwWebDocShell*>( m_pWrtSh->GetView().GetDocShell() )!= nullptr;
1531 if(bWeb)
1533 m_xHideCB->hide();
1534 m_xConditionED->hide();
1535 m_xConditionFT->hide();
1536 m_xDDECB->hide();
1537 m_xDDECommandFT->hide();
1540 lcl_FillSubRegionList(*m_pWrtSh, *m_xSubRegionED, m_xCurName.get());
1542 SwSectionData *const pSectionData =
1543 static_cast<SwInsertSectionTabDialog*>(GetDialogController())
1544 ->GetSectionData();
1545 if (pSectionData) // something set?
1547 const OUString sSectionName(pSectionData->GetSectionName());
1548 m_xCurName->set_entry_text(rSh.GetUniqueSectionName(&sSectionName));
1549 m_xProtectCB->set_active( pSectionData->IsProtectFlag() );
1550 ChangeProtectHdl(*m_xProtectCB);
1551 m_sFileName = pSectionData->GetLinkFileName();
1552 m_sFilePasswd = pSectionData->GetLinkFilePassword();
1553 m_xFileCB->set_active( !m_sFileName.isEmpty() );
1554 m_xFileNameED->set_text( m_sFileName );
1555 UseFileHdl(*m_xFileCB);
1557 else
1559 m_xCurName->set_entry_text(rSh.GetUniqueSectionName());
1563 bool SwInsertSectionTabPage::FillItemSet( SfxItemSet* )
1565 SwSectionData aSection(SectionType::Content, m_xCurName->get_active_text());
1566 aSection.SetCondition(m_xConditionED->get_text());
1567 bool bProtected = m_xProtectCB->get_active();
1568 aSection.SetProtectFlag(bProtected);
1569 aSection.SetHidden(m_xHideCB->get_active());
1570 // edit in readonly sections
1571 aSection.SetEditInReadonlyFlag(m_xEditInReadonlyCB->get_active());
1573 if(bProtected)
1575 aSection.SetPassword(m_aNewPasswd);
1577 const OUString sFileName = m_xFileNameED->get_text();
1578 const OUString sSubRegion = m_xSubRegionED->get_active_text();
1579 bool bDDe = m_xDDECB->get_active();
1580 if (m_xFileCB->get_active() && (!sFileName.isEmpty() || !sSubRegion.isEmpty() || bDDe))
1582 OUString aLinkFile;
1583 if( bDDe )
1585 aLinkFile = CollapseWhiteSpaces(sFileName);
1586 sal_Int32 nPos = 0;
1587 aLinkFile = aLinkFile.replaceFirst( " ", OUStringChar(sfx2::cTokenSeparator), &nPos );
1588 if (nPos>=0)
1590 aLinkFile = aLinkFile.replaceFirst( " ", OUStringChar(sfx2::cTokenSeparator), &nPos );
1593 else
1595 if(!sFileName.isEmpty())
1597 SfxMedium* pMedium = m_pWrtSh->GetView().GetDocShell()->GetMedium();
1598 INetURLObject aAbs;
1599 if( pMedium )
1600 aAbs = pMedium->GetURLObject();
1601 aLinkFile = URIHelper::SmartRel2Abs(
1602 aAbs, sFileName, URIHelper::GetMaybeFileHdl() );
1603 aSection.SetLinkFilePassword( m_sFilePasswd );
1606 aLinkFile += OUStringChar(sfx2::cTokenSeparator) + m_sFilterName
1607 + OUStringChar(sfx2::cTokenSeparator) + sSubRegion;
1610 aSection.SetLinkFileName(aLinkFile);
1611 if (!aLinkFile.isEmpty())
1613 aSection.SetType( m_xDDECB->get_active() ?
1614 SectionType::DdeLink :
1615 SectionType::FileLink);
1618 static_cast<SwInsertSectionTabDialog*>(GetDialogController())->SetSectionData(aSection);
1619 return true;
1622 void SwInsertSectionTabPage::Reset( const SfxItemSet* )
1626 std::unique_ptr<SfxTabPage> SwInsertSectionTabPage::Create(weld::Container* pPage, weld::DialogController* pController,
1627 const SfxItemSet* rAttrSet)
1629 return std::make_unique<SwInsertSectionTabPage>(pPage, pController, *rAttrSet);
1632 IMPL_LINK(SwInsertSectionTabPage, ChangeHideHdl, weld::Toggleable&, rBox, void)
1634 bool bHide = rBox.get_active();
1635 m_xConditionED->set_sensitive(bHide);
1636 m_xConditionFT->set_sensitive(bHide);
1639 IMPL_LINK(SwInsertSectionTabPage, ChangeProtectHdl, weld::Toggleable&, rBox, void)
1641 bool bCheck = rBox.get_active();
1642 m_xPasswdCB->set_sensitive(bCheck);
1643 m_xPasswdPB->set_sensitive(bCheck);
1646 void SwInsertSectionTabPage::ChangePasswd(bool bChange)
1648 bool bSet = bChange ? bChange : m_xPasswdCB->get_active();
1649 if (bSet)
1651 if(!m_aNewPasswd.hasElements() || bChange)
1653 SfxPasswordDialog aPasswdDlg(GetFrameWeld());
1654 aPasswdDlg.ShowExtras(SfxShowExtras::CONFIRM);
1655 if (RET_OK == aPasswdDlg.run())
1657 const OUString sNewPasswd(aPasswdDlg.GetPassword());
1658 if (aPasswdDlg.GetConfirm() == sNewPasswd)
1660 SvPasswordHelper::GetHashPassword( m_aNewPasswd, sNewPasswd );
1662 else
1664 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(GetFrameWeld(),
1665 VclMessageType::Info, VclButtonsType::Ok,
1666 SwResId(STR_WRONG_PASSWD_REPEAT)));
1667 xInfoBox->run();
1670 else if(!bChange)
1671 m_xPasswdCB->set_active(false);
1674 else
1675 m_aNewPasswd.realloc(0);
1678 IMPL_LINK_NOARG(SwInsertSectionTabPage, TogglePasswdHdl, weld::Toggleable&, void)
1680 ChangePasswd(false);
1683 IMPL_LINK_NOARG(SwInsertSectionTabPage, ChangePasswdHdl, weld::Button&, void)
1685 ChangePasswd(true);
1689 IMPL_LINK_NOARG(SwInsertSectionTabPage, NameEditHdl, weld::ComboBox&, void)
1691 const OUString aName = m_xCurName->get_active_text();
1692 GetDialogController()->GetOKButton().set_sensitive(!aName.isEmpty() &&
1693 m_xCurName->find_text(aName) == -1);
1696 IMPL_LINK(SwInsertSectionTabPage, UseFileHdl, weld::Toggleable&, rButton, void)
1698 if (rButton.get_active())
1700 if (m_pWrtSh->HasSelection())
1702 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
1703 VclMessageType::Question, VclButtonsType::YesNo,
1704 SwResId(STR_QUERY_CONNECT)));
1705 if (RET_NO == xQueryBox->run())
1706 rButton.set_active(false);
1710 bool bFile = rButton.get_active();
1711 m_xFileNameFT->set_sensitive(bFile);
1712 m_xFileNameED->set_sensitive(bFile);
1713 m_xFilePB->set_sensitive(bFile);
1714 m_xSubRegionFT->set_sensitive(bFile);
1715 m_xSubRegionED->set_sensitive(bFile);
1716 m_xDDECommandFT->set_sensitive(bFile);
1717 m_xDDECB->set_sensitive(bFile);
1718 if (bFile)
1720 m_xFileNameED->grab_focus();
1721 m_xProtectCB->set_active(true);
1722 ChangeProtectHdl(*m_xProtectCB);
1724 else
1726 m_xDDECB->set_active(false);
1727 DDEHdl(*m_xDDECB);
1731 IMPL_LINK_NOARG(SwInsertSectionTabPage, FileSearchHdl, weld::Button&, void)
1733 m_pDocInserter.reset(new ::sfx2::DocumentInserter(GetFrameWeld(), "swriter"));
1734 m_pDocInserter->StartExecuteModal( LINK( this, SwInsertSectionTabPage, DlgClosedHdl ) );
1737 IMPL_LINK( SwInsertSectionTabPage, DDEHdl, weld::Toggleable&, rButton, void )
1739 bool bDDE = rButton.get_active();
1740 bool bFile = m_xFileCB->get_active();
1741 m_xFilePB->set_sensitive(!bDDE && bFile);
1742 if (bDDE)
1744 m_xFileNameFT->hide();
1745 m_xDDECommandFT->set_sensitive(bDDE);
1746 m_xDDECommandFT->show();
1747 m_xSubRegionFT->hide();
1748 m_xSubRegionED->hide();
1749 m_xFileNameED->set_accessible_name(m_xDDECommandFT->get_label());
1751 else
1753 m_xDDECommandFT->hide();
1754 m_xFileNameFT->set_sensitive(bFile);
1755 if(!comphelper::LibreOfficeKit::isActive())
1756 m_xFileNameFT->show();
1757 m_xSubRegionFT->show();
1758 m_xSubRegionED->show();
1759 m_xSubRegionED->set_sensitive(bFile);
1760 m_xFileNameED->set_accessible_name(m_xFileNameFT->get_label());
1764 IMPL_LINK( SwInsertSectionTabPage, DlgClosedHdl, sfx2::FileDialogHelper *, _pFileDlg, void )
1766 if ( _pFileDlg->GetError() == ERRCODE_NONE )
1768 std::unique_ptr<SfxMedium> pMedium(m_pDocInserter->CreateMedium("sglobal"));
1769 if ( pMedium )
1771 m_sFileName = pMedium->GetURLObject().GetMainURL( INetURLObject::DecodeMechanism::NONE );
1772 m_sFilterName = pMedium->GetFilter()->GetFilterName();
1773 if ( const SfxStringItem* pItem = pMedium->GetItemSet()->GetItemIfSet( SID_PASSWORD, false ) )
1774 m_sFilePasswd = pItem->GetValue();
1775 m_xFileNameED->set_text( INetURLObject::decode(
1776 m_sFileName, INetURLObject::DecodeMechanism::Unambiguous ) );
1777 ::lcl_ReadSections(*pMedium, *m_xSubRegionED);
1780 else
1782 m_sFilterName.clear();
1783 m_sFilePasswd.clear();
1787 SwSectionFootnoteEndTabPage::SwSectionFootnoteEndTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet &rAttrSet)
1788 : SfxTabPage(pPage, pController, "modules/swriter/ui/footnotesendnotestabpage.ui", "FootnotesEndnotesTabPage", &rAttrSet)
1789 , m_xFootnoteNtAtTextEndCB(m_xBuilder->weld_check_button("ftnntattextend"))
1790 , m_xFootnoteNtNumCB(m_xBuilder->weld_check_button("ftnntnum"))
1791 , m_xFootnoteOffsetLbl(m_xBuilder->weld_label("ftnoffset_label"))
1792 , m_xFootnoteOffsetField(m_xBuilder->weld_spin_button("ftnoffset"))
1793 , m_xFootnoteNtNumFormatCB(m_xBuilder->weld_check_button("ftnntnumfmt"))
1794 , m_xFootnotePrefixFT(m_xBuilder->weld_label("ftnprefix_label"))
1795 , m_xFootnotePrefixED(m_xBuilder->weld_entry("ftnprefix"))
1796 , m_xFootnoteNumViewBox(new SwNumberingTypeListBox(m_xBuilder->weld_combo_box("ftnnumviewbox")))
1797 , m_xFootnoteSuffixFT(m_xBuilder->weld_label("ftnsuffix_label"))
1798 , m_xFootnoteSuffixED(m_xBuilder->weld_entry("ftnsuffix"))
1799 , m_xEndNtAtTextEndCB(m_xBuilder->weld_check_button("endntattextend"))
1800 , m_xEndNtNumCB(m_xBuilder->weld_check_button("endntnum"))
1801 , m_xEndOffsetLbl(m_xBuilder->weld_label("endoffset_label"))
1802 , m_xEndOffsetField(m_xBuilder->weld_spin_button("endoffset"))
1803 , m_xEndNtNumFormatCB(m_xBuilder->weld_check_button("endntnumfmt"))
1804 , m_xEndPrefixFT(m_xBuilder->weld_label("endprefix_label"))
1805 , m_xEndPrefixED(m_xBuilder->weld_entry("endprefix"))
1806 , m_xEndNumViewBox(new SwNumberingTypeListBox(m_xBuilder->weld_combo_box("endnumviewbox")))
1807 , m_xEndSuffixFT(m_xBuilder->weld_label("endsuffix_label"))
1808 , m_xEndSuffixED(m_xBuilder->weld_entry("endsuffix"))
1810 m_xFootnoteNumViewBox->Reload(SwInsertNumTypes::Extended);
1811 m_xEndNumViewBox->Reload(SwInsertNumTypes::Extended);
1813 Link<weld::Toggleable&,void> aLk( LINK( this, SwSectionFootnoteEndTabPage, FootEndHdl));
1814 m_xFootnoteNtAtTextEndCB->connect_toggled( aLk );
1815 m_xFootnoteNtNumCB->connect_toggled( aLk );
1816 m_xEndNtAtTextEndCB->connect_toggled( aLk );
1817 m_xEndNtNumCB->connect_toggled( aLk );
1818 m_xFootnoteNtNumFormatCB->connect_toggled( aLk );
1819 m_xEndNtNumFormatCB->connect_toggled( aLk );
1822 SwSectionFootnoteEndTabPage::~SwSectionFootnoteEndTabPage()
1826 bool SwSectionFootnoteEndTabPage::FillItemSet( SfxItemSet* rSet )
1828 SwFormatFootnoteAtTextEnd aFootnote( m_xFootnoteNtAtTextEndCB->get_active()
1829 ? ( m_xFootnoteNtNumCB->get_active()
1830 ? ( m_xFootnoteNtNumFormatCB->get_active()
1831 ? FTNEND_ATTXTEND_OWNNUMANDFMT
1832 : FTNEND_ATTXTEND_OWNNUMSEQ )
1833 : FTNEND_ATTXTEND )
1834 : FTNEND_ATPGORDOCEND );
1836 switch( aFootnote.GetValue() )
1838 case FTNEND_ATTXTEND_OWNNUMANDFMT:
1839 aFootnote.SetNumType( m_xFootnoteNumViewBox->GetSelectedNumberingType() );
1840 aFootnote.SetPrefix( m_xFootnotePrefixED->get_text().replaceAll("\\t", "\t") ); // fdo#65666
1841 aFootnote.SetSuffix( m_xFootnoteSuffixED->get_text().replaceAll("\\t", "\t") );
1842 [[fallthrough]];
1844 case FTNEND_ATTXTEND_OWNNUMSEQ:
1845 aFootnote.SetOffset( static_cast< sal_uInt16 >( m_xFootnoteOffsetField->get_value()-1 ) );
1846 break;
1847 default: break;
1850 SwFormatEndAtTextEnd aEnd( m_xEndNtAtTextEndCB->get_active()
1851 ? ( m_xEndNtNumCB->get_active()
1852 ? ( m_xEndNtNumFormatCB->get_active()
1853 ? FTNEND_ATTXTEND_OWNNUMANDFMT
1854 : FTNEND_ATTXTEND_OWNNUMSEQ )
1855 : FTNEND_ATTXTEND )
1856 : FTNEND_ATPGORDOCEND );
1858 switch( aEnd.GetValue() )
1860 case FTNEND_ATTXTEND_OWNNUMANDFMT:
1861 aEnd.SetNumType( m_xEndNumViewBox->GetSelectedNumberingType() );
1862 aEnd.SetPrefix( m_xEndPrefixED->get_text().replaceAll("\\t", "\t") );
1863 aEnd.SetSuffix( m_xEndSuffixED->get_text().replaceAll("\\t", "\t") );
1864 [[fallthrough]];
1866 case FTNEND_ATTXTEND_OWNNUMSEQ:
1867 aEnd.SetOffset( static_cast< sal_uInt16 >( m_xEndOffsetField->get_value()-1 ) );
1868 break;
1869 default: break;
1872 rSet->Put( aFootnote );
1873 rSet->Put( aEnd );
1875 return true;
1878 void SwSectionFootnoteEndTabPage::ResetState( bool bFootnote,
1879 const SwFormatFootnoteEndAtTextEnd& rAttr )
1881 weld::CheckButton *pNtAtTextEndCB, *pNtNumCB, *pNtNumFormatCB;
1882 weld::Label *pPrefixFT, *pSuffixFT;
1883 weld::Entry *pPrefixED, *pSuffixED;
1884 SwNumberingTypeListBox *pNumViewBox;
1885 weld::Label *pOffsetText;
1886 weld::SpinButton *pOffsetField;
1888 if( bFootnote )
1890 pNtAtTextEndCB = m_xFootnoteNtAtTextEndCB.get();
1891 pNtNumCB = m_xFootnoteNtNumCB.get();
1892 pNtNumFormatCB = m_xFootnoteNtNumFormatCB.get();
1893 pPrefixFT = m_xFootnotePrefixFT.get();
1894 pPrefixED = m_xFootnotePrefixED.get();
1895 pSuffixFT = m_xFootnoteSuffixFT.get();
1896 pSuffixED = m_xFootnoteSuffixED.get();
1897 pNumViewBox = m_xFootnoteNumViewBox.get();
1898 pOffsetText = m_xFootnoteOffsetLbl.get();
1899 pOffsetField = m_xFootnoteOffsetField.get();
1901 else
1903 pNtAtTextEndCB = m_xEndNtAtTextEndCB.get();
1904 pNtNumCB = m_xEndNtNumCB.get();
1905 pNtNumFormatCB = m_xEndNtNumFormatCB.get();
1906 pPrefixFT = m_xEndPrefixFT.get();
1907 pPrefixED = m_xEndPrefixED.get();
1908 pSuffixFT = m_xEndSuffixFT.get();
1909 pSuffixED = m_xEndSuffixED.get();
1910 pNumViewBox = m_xEndNumViewBox.get();
1911 pOffsetText = m_xEndOffsetLbl.get();
1912 pOffsetField = m_xEndOffsetField.get();
1915 const sal_uInt16 eState = rAttr.GetValue();
1916 switch( eState )
1918 case FTNEND_ATTXTEND_OWNNUMANDFMT:
1919 pNtNumFormatCB->set_state( TRISTATE_TRUE );
1920 [[fallthrough]];
1922 case FTNEND_ATTXTEND_OWNNUMSEQ:
1923 pNtNumCB->set_state( TRISTATE_TRUE );
1924 [[fallthrough]];
1926 case FTNEND_ATTXTEND:
1927 pNtAtTextEndCB->set_state( TRISTATE_TRUE );
1928 // no break;
1931 pNumViewBox->SelectNumberingType( rAttr.GetNumType() );
1932 pOffsetField->set_value( rAttr.GetOffset() + 1 );
1933 pPrefixED->set_text( rAttr.GetPrefix().replaceAll("\t", "\\t") );
1934 pSuffixED->set_text( rAttr.GetSuffix().replaceAll("\t", "\\t") );
1936 switch( eState )
1938 case FTNEND_ATPGORDOCEND:
1939 pNtNumCB->set_sensitive( false );
1940 [[fallthrough]];
1942 case FTNEND_ATTXTEND:
1943 pNtNumFormatCB->set_sensitive( false );
1944 pOffsetField->set_sensitive( false );
1945 pOffsetText->set_sensitive( false );
1946 [[fallthrough]];
1948 case FTNEND_ATTXTEND_OWNNUMSEQ:
1949 pNumViewBox->set_sensitive( false );
1950 pPrefixFT->set_sensitive( false );
1951 pPrefixED->set_sensitive( false );
1952 pSuffixFT->set_sensitive( false );
1953 pSuffixED->set_sensitive( false );
1954 // no break;
1958 void SwSectionFootnoteEndTabPage::Reset( const SfxItemSet* rSet )
1960 ResetState( true, rSet->Get( RES_FTN_AT_TXTEND, false ));
1961 ResetState( false, rSet->Get( RES_END_AT_TXTEND, false ));
1964 std::unique_ptr<SfxTabPage> SwSectionFootnoteEndTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
1965 const SfxItemSet* rAttrSet)
1967 return std::make_unique<SwSectionFootnoteEndTabPage>(pPage, pController, *rAttrSet);
1970 IMPL_LINK( SwSectionFootnoteEndTabPage, FootEndHdl, weld::Toggleable&, rBox, void )
1972 bool bFoot = m_xFootnoteNtAtTextEndCB.get() == &rBox || m_xFootnoteNtNumCB.get() == &rBox ||
1973 m_xFootnoteNtNumFormatCB.get() == &rBox ;
1975 weld::CheckButton *pNumBox, *pNumFormatBox, *pEndBox;
1976 SwNumberingTypeListBox* pNumViewBox;
1977 weld::Label *pOffsetText;
1978 weld::SpinButton *pOffsetField;
1979 weld::Label *pPrefixFT, *pSuffixFT;
1980 weld::Entry *pPrefixED, *pSuffixED;
1982 if( bFoot )
1984 pEndBox = m_xFootnoteNtAtTextEndCB.get();
1985 pNumBox = m_xFootnoteNtNumCB.get();
1986 pNumFormatBox = m_xFootnoteNtNumFormatCB.get();
1987 pNumViewBox = m_xFootnoteNumViewBox.get();
1988 pOffsetText = m_xFootnoteOffsetLbl.get();
1989 pOffsetField = m_xFootnoteOffsetField.get();
1990 pPrefixFT = m_xFootnotePrefixFT.get();
1991 pSuffixFT = m_xFootnoteSuffixFT.get();
1992 pPrefixED = m_xFootnotePrefixED.get();
1993 pSuffixED = m_xFootnoteSuffixED.get();
1995 else
1997 pEndBox = m_xEndNtAtTextEndCB.get();
1998 pNumBox = m_xEndNtNumCB.get();
1999 pNumFormatBox = m_xEndNtNumFormatCB.get();
2000 pNumViewBox = m_xEndNumViewBox.get();
2001 pOffsetText = m_xEndOffsetLbl.get();
2002 pOffsetField = m_xEndOffsetField.get();
2003 pPrefixFT = m_xEndPrefixFT.get();
2004 pSuffixFT = m_xEndSuffixFT.get();
2005 pPrefixED = m_xEndPrefixED.get();
2006 pSuffixED = m_xEndSuffixED.get();
2009 bool bEnableAtEnd = TRISTATE_TRUE == pEndBox->get_state();
2010 bool bEnableNum = bEnableAtEnd && TRISTATE_TRUE == pNumBox->get_state();
2011 bool bEnableNumFormat = bEnableNum && TRISTATE_TRUE == pNumFormatBox->get_state();
2013 pNumBox->set_sensitive( bEnableAtEnd );
2014 pOffsetText->set_sensitive( bEnableNum );
2015 pOffsetField->set_sensitive( bEnableNum );
2016 pNumFormatBox->set_sensitive( bEnableNum );
2017 pNumViewBox->set_sensitive( bEnableNumFormat );
2018 pPrefixED->set_sensitive( bEnableNumFormat );
2019 pSuffixED->set_sensitive( bEnableNumFormat );
2020 pPrefixFT->set_sensitive( bEnableNumFormat );
2021 pSuffixFT->set_sensitive( bEnableNumFormat );
2024 SwSectionPropertyTabDialog::SwSectionPropertyTabDialog(
2025 weld::Window* pParent, const SfxItemSet& rSet, SwWrtShell& rSh)
2026 : SfxTabDialogController(pParent, "modules/swriter/ui/formatsectiondialog.ui",
2027 "FormatSectionDialog", &rSet)
2028 , m_rWrtSh(rSh)
2030 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
2031 AddTabPage("columns", SwColumnPage::Create, nullptr);
2032 AddTabPage("background", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_BKG), nullptr);
2033 AddTabPage("notes", SwSectionFootnoteEndTabPage::Create, nullptr);
2034 AddTabPage("indents", SwSectionIndentTabPage::Create, nullptr);
2036 tools::Long nHtmlMode = SvxHtmlOptions::GetExportMode();
2037 bool bWeb = dynamic_cast<SwWebDocShell*>( rSh.GetView().GetDocShell() ) != nullptr ;
2038 if(bWeb)
2040 RemoveTabPage("notes");
2041 RemoveTabPage("indents");
2042 if( HTML_CFG_NS40 != nHtmlMode && HTML_CFG_WRITER != nHtmlMode)
2043 RemoveTabPage("columns");
2047 SwSectionPropertyTabDialog::~SwSectionPropertyTabDialog()
2051 void SwSectionPropertyTabDialog::PageCreated(const OUString& rId, SfxTabPage &rPage)
2053 if (rId == "background")
2055 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
2056 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, static_cast<sal_uInt32>(SvxBackgroundTabFlags::SHOW_SELECTOR)));
2057 rPage.PageCreated(aSet);
2059 else if (rId == "columns")
2061 static_cast<SwColumnPage&>(rPage).ShowBalance(true);
2062 static_cast<SwColumnPage&>(rPage).SetInSection(true);
2064 else if (rId == "indents")
2065 static_cast<SwSectionIndentTabPage&>(rPage).SetWrtShell(m_rWrtSh);
2068 SwSectionIndentTabPage::SwSectionIndentTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet &rAttrSet)
2069 : SfxTabPage(pPage, pController, "modules/swriter/ui/indentpage.ui", "IndentPage", &rAttrSet)
2070 , m_xBeforeMF(m_xBuilder->weld_metric_spin_button("before", FieldUnit::CM))
2071 , m_xAfterMF(m_xBuilder->weld_metric_spin_button("after", FieldUnit::CM))
2072 , m_xPreviewWin(new weld::CustomWeld(*m_xBuilder, "preview", m_aPreviewWin))
2074 Link<weld::MetricSpinButton&,void> aLk = LINK(this, SwSectionIndentTabPage, IndentModifyHdl);
2075 m_xBeforeMF->connect_value_changed(aLk);
2076 m_xAfterMF->connect_value_changed(aLk);
2079 SwSectionIndentTabPage::~SwSectionIndentTabPage()
2083 bool SwSectionIndentTabPage::FillItemSet(SfxItemSet* rSet)
2085 if (m_xBeforeMF->get_value_changed_from_saved() || m_xAfterMF->get_value_changed_from_saved())
2087 SvxLRSpaceItem aLRSpace(
2088 m_xBeforeMF->denormalize(m_xBeforeMF->get_value(FieldUnit::TWIP)) ,
2089 m_xAfterMF->denormalize(m_xAfterMF->get_value(FieldUnit::TWIP)), 0, RES_LR_SPACE);
2090 rSet->Put(aLRSpace);
2092 return true;
2095 void SwSectionIndentTabPage::Reset( const SfxItemSet* rSet)
2097 //this page doesn't show up in HTML mode
2098 FieldUnit aMetric = ::GetDfltMetric(false);
2099 SetFieldUnit(*m_xBeforeMF, aMetric);
2100 SetFieldUnit(*m_xAfterMF , aMetric);
2102 SfxItemState eItemState = rSet->GetItemState( RES_LR_SPACE );
2103 if ( eItemState >= SfxItemState::DEFAULT )
2105 const SvxLRSpaceItem& rSpace =
2106 rSet->Get( RES_LR_SPACE );
2108 m_xBeforeMF->set_value(m_xBeforeMF->normalize(rSpace.GetLeft()), FieldUnit::TWIP);
2109 m_xAfterMF->set_value(m_xAfterMF->normalize(rSpace.GetRight()), FieldUnit::TWIP);
2111 else
2113 m_xBeforeMF->set_text("");
2114 m_xAfterMF->set_text("");
2116 m_xBeforeMF->save_value();
2117 m_xAfterMF->save_value();
2118 IndentModifyHdl(*m_xBeforeMF);
2121 std::unique_ptr<SfxTabPage> SwSectionIndentTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
2123 return std::make_unique<SwSectionIndentTabPage>(pPage, pController, *rAttrSet);
2126 void SwSectionIndentTabPage::SetWrtShell(SwWrtShell const & rSh)
2128 //set sensible values at the preview
2129 m_aPreviewWin.SetAdjust(SvxAdjust::Block);
2130 m_aPreviewWin.SetLastLine(SvxAdjust::Block);
2131 const SwRect& rPageRect = rSh.GetAnyCurRect( CurRectType::Page );
2132 Size aPageSize(rPageRect.Width(), rPageRect.Height());
2133 m_aPreviewWin.SetSize(aPageSize);
2136 IMPL_LINK_NOARG(SwSectionIndentTabPage, IndentModifyHdl, weld::MetricSpinButton&, void)
2138 m_aPreviewWin.SetLeftMargin(m_xBeforeMF->denormalize(m_xBeforeMF->get_value(FieldUnit::TWIP)));
2139 m_aPreviewWin.SetRightMargin(m_xAfterMF->denormalize(m_xAfterMF->get_value(FieldUnit::TWIP)));
2140 m_aPreviewWin.Invalidate();
2143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */