summaryrefslogtreecommitdiff
path: root/sw/source/uibase/shells/textsh1.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sw/source/uibase/shells/textsh1.cxx')
-rw-r--r--sw/source/uibase/shells/textsh1.cxx1386
1 files changed, 1079 insertions, 307 deletions
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index 1aae087262d0..39f655d115bd 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -17,6 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <config_features.h>
+
#include <com/sun/star/i18n/WordType.hpp>
#include <com/sun/star/linguistic2/XThesaurus.hpp>
@@ -27,6 +31,7 @@
#include <i18nutil/unicode.hxx>
#include <i18nlangtag/languagetag.hxx>
#include <svtools/langtab.hxx>
+#include <svl/numformat.hxx>
#include <svl/slstitm.hxx>
#include <svl/stritem.hxx>
#include <sfx2/htmlmode.hxx>
@@ -48,6 +53,9 @@
#include <IDocumentSettingAccess.hxx>
#include <charfmt.hxx>
#include <svx/SmartTagItem.hxx>
+#include <svx/xflgrit.hxx>
+#include <svx/xflhtit.hxx>
+#include <svx/xfillit0.hxx>
#include <fmtinfmt.hxx>
#include <wrtsh.hxx>
#include <wview.hxx>
@@ -66,7 +74,9 @@
#include <cellatr.hxx>
#include <edtwin.hxx>
#include <fldmgr.hxx>
+#include <ndtxt.hxx>
#include <strings.hrc>
+#include <txatbase.hxx>
#include <paratr.hxx>
#include <vcl/svapp.hxx>
#include <sfx2/app.hxx>
@@ -97,8 +107,25 @@
#include <numrule.hxx>
#include <memory>
#include <xmloff/odffields.hxx>
-#include <bookmrk.hxx>
+#include <bookmark.hxx>
#include <linguistic/misc.hxx>
+#include <comphelper/sequenceashashmap.hxx>
+#include <comphelper/scopeguard.hxx>
+#include <authfld.hxx>
+#include <config_wasm_strip.h>
+#if HAVE_FEATURE_CURL && !ENABLE_WASM_STRIP_EXTRA
+#include <officecfg/Office/Common.hxx>
+#include <officecfg/Office/Linguistic.hxx>
+#include <svl/visitem.hxx>
+#include <translatelangselect.hxx>
+#endif // HAVE_FEATURE_CURL && ENABLE_WASM_STRIP_EXTRA
+#include <translatehelper.hxx>
+#include <IDocumentContentOperations.hxx>
+#include <IDocumentUndoRedo.hxx>
+#include <fmtcntnt.hxx>
+#include <fmtrfmrk.hxx>
+#include <cntfrm.hxx>
+#include <flyfrm.hxx>
using namespace ::com::sun::star;
using namespace com::sun::star::beans;
@@ -106,23 +133,22 @@ using namespace ::com::sun::star::container;
using namespace com::sun::star::style;
using namespace svx::sidebar;
-static void sw_CharDialogResult(const SfxItemSet* pSet, SwWrtShell &rWrtSh, std::shared_ptr<SfxItemSet> const & pCoreSet, bool bSel, bool bSelectionPut, SfxRequest *pReq);
+static void sw_CharDialogResult(const SfxItemSet* pSet, SwWrtShell &rWrtSh, std::shared_ptr<SfxItemSet> const & pCoreSet, bool bSel,
+ bool bSelectionPut, bool bApplyToParagraph, SfxRequest *pReq);
-static void sw_CharDialog(SwWrtShell &rWrtSh, bool bUseDialog, sal_uInt16 nSlot, const SfxItemSet *pArgs, SfxRequest *pReq )
+static void sw_CharDialog(SwWrtShell& rWrtSh, bool bUseDialog, bool bApplyToParagraph,
+ sal_uInt16 nSlot, const SfxItemSet* pArgs, SfxRequest* pReq)
{
FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebView*>( &rWrtSh.GetView()) != nullptr );
SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)));
- auto pCoreSet = std::make_shared<SfxItemSet>(
- rWrtSh.GetView().GetPool(),
- svl::Items<
+ auto pCoreSet = std::make_shared<SfxItemSetFixed<
RES_CHRATR_BEGIN, RES_CHRATR_END - 1,
RES_TXTATR_INETFMT, RES_TXTATR_INETFMT,
RES_BACKGROUND, RES_SHADOW,
- XATTR_FILLSTYLE, XATTR_FILLCOLOR,
SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
SID_HTML_MODE, SID_HTML_MODE,
SID_ATTR_CHAR_WIDTH_FIT_TO_LINE, SID_ATTR_CHAR_WIDTH_FIT_TO_LINE,
- FN_PARAM_SELECTION, FN_PARAM_SELECTION>{});
+ FN_PARAM_SELECTION, FN_PARAM_SELECTION>> ( rWrtSh.GetView().GetPool() );
rWrtSh.GetCurAttr(*pCoreSet);
bool bSel = rWrtSh.HasSelection();
@@ -162,13 +188,15 @@ static void sw_CharDialog(SwWrtShell &rWrtSh, bool bUseDialog, sal_uInt16 nSlot,
pDlg->SetCurPageId("hyperlink");
else if (nSlot == SID_CHAR_DLG_EFFECT)
pDlg->SetCurPageId("fonteffects");
+ else if (nSlot == SID_CHAR_DLG_POSITION)
+ pDlg->SetCurPageId("position");
else if (nSlot == SID_CHAR_DLG_FOR_PARAGRAPH)
pDlg->SetCurPageId("font");
else if (pReq)
{
const SfxStringItem* pItem = (*pReq).GetArg<SfxStringItem>(FN_PARAM_1);
if (pItem)
- pDlg->SetCurPageId(OUStringToOString(pItem->GetValue(), RTL_TEXTENCODING_UTF8));
+ pDlg->SetCurPageId(pItem->GetValue());
}
}
@@ -180,33 +208,44 @@ static void sw_CharDialog(SwWrtShell &rWrtSh, bool bUseDialog, sal_uInt16 nSlot,
pRequest = std::make_shared<SfxRequest>(*pReq);
pReq->Ignore(); // the 'old' request is not relevant any more
}
- pDlg->StartExecuteAsync([pDlg, &rWrtSh, pCoreSet, bSel, bSelectionPut, pRequest](sal_Int32 nResult){
+ pDlg->StartExecuteAsync([pDlg, &rWrtSh, pCoreSet, bSel, bSelectionPut, bApplyToParagraph, pRequest](sal_Int32 nResult){
if (nResult == RET_OK)
{
- sw_CharDialogResult(pDlg->GetOutputItemSet(), rWrtSh, pCoreSet, bSel, bSelectionPut, pRequest.get());
+ sw_CharDialogResult(pDlg->GetOutputItemSet(), rWrtSh, pCoreSet, bSel, bSelectionPut,
+ bApplyToParagraph, pRequest.get());
}
pDlg->disposeOnce();
});
}
else if (pArgs)
{
- sw_CharDialogResult(pArgs, rWrtSh, pCoreSet, bSel, bSelectionPut, pReq);
+ sw_CharDialogResult(pArgs, rWrtSh, pCoreSet, bSel, bSelectionPut, bApplyToParagraph, pReq);
}
}
-static void sw_CharDialogResult(const SfxItemSet* pSet, SwWrtShell &rWrtSh, std::shared_ptr<SfxItemSet> const & pCoreSet, bool bSel, bool bSelectionPut, SfxRequest *pReq)
+static void sw_CharDialogResult(const SfxItemSet* pSet, SwWrtShell& rWrtSh, std::shared_ptr<SfxItemSet> const & pCoreSet, bool bSel,
+ bool bSelectionPut, bool bApplyToParagraph, SfxRequest* pReq)
{
SfxItemSet aTmpSet( *pSet );
::ConvertAttrGenToChar(aTmpSet, *pCoreSet);
- const SfxPoolItem* pSelectionItem;
+ const bool bWasLocked = rWrtSh.IsViewLocked();
+ if (bApplyToParagraph)
+ {
+ rWrtSh.StartAction();
+ rWrtSh.LockView(true);
+ rWrtSh.Push();
+ SwLangHelper::SelectCurrentPara(rWrtSh);
+ }
+
+ const SfxStringItem* pSelectionItem;
bool bInsert = false;
sal_Int32 nInsert = 0;
// The old item is for unknown reasons back in the set again.
- if( !bSelectionPut && SfxItemState::SET == aTmpSet.GetItemState(FN_PARAM_SELECTION, false, &pSelectionItem) )
+ if( !bSelectionPut && (pSelectionItem = aTmpSet.GetItemIfSet(FN_PARAM_SELECTION, false)) )
{
- OUString sInsert = static_cast<const SfxStringItem*>(pSelectionItem)->GetValue();
+ OUString sInsert = pSelectionItem->GetValue();
bInsert = !sInsert.isEmpty();
if(bInsert)
{
@@ -215,10 +254,10 @@ static void sw_CharDialogResult(const SfxItemSet* pSet, SwWrtShell &rWrtSh, std:
rWrtSh.Insert( sInsert );
rWrtSh.SetMark();
rWrtSh.ExtendSelection(false, sInsert.getLength());
- SfxRequest aReq( rWrtSh.GetView().GetViewFrame(), FN_INSERT_STRING );
+ SfxRequest aReq(rWrtSh.GetView().GetViewFrame(), FN_INSERT_STRING);
aReq.AppendItem( SfxStringItem( FN_INSERT_STRING, sInsert ) );
aReq.Done();
- SfxRequest aReq1( rWrtSh.GetView().GetViewFrame(), FN_CHAR_LEFT );
+ SfxRequest aReq1(rWrtSh.GetView().GetViewFrame(), FN_CHAR_LEFT);
aReq1.AppendItem( SfxInt32Item(FN_PARAM_MOVE_COUNT, nInsert) );
aReq1.AppendItem( SfxBoolItem(FN_PARAM_MOVE_SELECTION, true) );
aReq1.Done();
@@ -227,7 +266,7 @@ static void sw_CharDialogResult(const SfxItemSet* pSet, SwWrtShell &rWrtSh, std:
aTmpSet.ClearItem(FN_PARAM_SELECTION);
SwTextFormatColl* pColl = rWrtSh.GetCurTextFormatColl();
- if(bSel && rWrtSh.IsSelFullPara() && pColl && pColl->IsAutoUpdateFormat())
+ if(bSel && rWrtSh.IsSelFullPara() && pColl && pColl->IsAutoUpdateOnDirectFormat())
{
rWrtSh.AutoUpdatePara(pColl, aTmpSet);
}
@@ -237,7 +276,7 @@ static void sw_CharDialogResult(const SfxItemSet* pSet, SwWrtShell &rWrtSh, std:
pReq->Done(aTmpSet);
if(bInsert)
{
- SfxRequest aReq1( rWrtSh.GetView().GetViewFrame(), FN_CHAR_RIGHT );
+ SfxRequest aReq1(rWrtSh.GetView().GetViewFrame(), FN_CHAR_RIGHT);
aReq1.AppendItem( SfxInt32Item(FN_PARAM_MOVE_COUNT, nInsert) );
aReq1.AppendItem( SfxBoolItem(FN_PARAM_MOVE_SELECTION, false) );
aReq1.Done();
@@ -247,14 +286,14 @@ static void sw_CharDialogResult(const SfxItemSet* pSet, SwWrtShell &rWrtSh, std:
rWrtSh.EndAction();
}
+ if (bApplyToParagraph)
+ {
+ rWrtSh.Pop(SwCursorShell::PopMode::DeleteCurrent);
+ rWrtSh.LockView(bWasLocked);
+ rWrtSh.EndAction();
+ }
}
-static short lcl_AskRedlineFlags(weld::Window *pWin)
-{
- std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pWin, "modules/swriter/ui/queryredlinedialog.ui"));
- std::unique_ptr<weld::MessageDialog> xQBox(xBuilder->weld_message_dialog("QueryRedlineDialog"));
- return xQBox->run();
-}
static void sw_ParagraphDialogResult(SfxItemSet* pSet, SwWrtShell &rWrtSh, SfxRequest& rReq, SwPaM* pPaM)
{
@@ -276,16 +315,15 @@ static void sw_ParagraphDialogResult(SfxItemSet* pSet, SwWrtShell &rWrtSh, SfxRe
if( pSet->Count() )
{
rWrtSh.StartAction();
- const SfxPoolItem* pItem = nullptr;
- if ( SfxItemState::SET == pSet->GetItemState(FN_DROP_TEXT, false, &pItem) )
+ if ( const SfxStringItem* pDropTextItem = pSet->GetItemIfSet(FN_DROP_TEXT, false) )
{
- if ( !static_cast<const SfxStringItem*>(pItem)->GetValue().isEmpty() )
- rWrtSh.ReplaceDropText(static_cast<const SfxStringItem*>(pItem)->GetValue(), pPaM);
+ if ( !pDropTextItem->GetValue().isEmpty() )
+ rWrtSh.ReplaceDropText(pDropTextItem->GetValue(), pPaM);
}
rWrtSh.SetAttrSet(*pSet, SetAttrMode::DEFAULT, pPaM);
rWrtSh.EndAction();
SwTextFormatColl* pColl = rWrtSh.GetPaMTextFormatColl(pPaM);
- if(pColl && pColl->IsAutoUpdateFormat())
+ if(pColl && pColl->IsAutoUpdateOnDirectFormat())
{
rWrtSh.AutoUpdatePara(pColl, *pSet, pPaM);
}
@@ -306,14 +344,14 @@ static void sw_ParagraphDialogResult(SfxItemSet* pSet, SwWrtShell &rWrtSh, SfxRe
sal_uInt16 nNumStart = USHRT_MAX;
if( SfxItemState::SET == pSet->GetItemState(FN_NUMBER_NEWSTART_AT) )
{
- nNumStart = static_cast<const SfxUInt16Item&>(pSet->Get(FN_NUMBER_NEWSTART_AT)).GetValue();
+ nNumStart = pSet->Get(FN_NUMBER_NEWSTART_AT).GetValue();
}
rWrtSh.SetNumRuleStart(bStart, pPaM);
rWrtSh.SetNodeNumStart(nNumStart);
}
else if( SfxItemState::SET == pSet->GetItemState(FN_NUMBER_NEWSTART_AT) )
{
- rWrtSh.SetNodeNumStart(static_cast<const SfxUInt16Item&>(pSet->Get(FN_NUMBER_NEWSTART_AT)).GetValue());
+ rWrtSh.SetNodeNumStart(pSet->Get(FN_NUMBER_NEWSTART_AT).GetValue());
rWrtSh.SetNumRuleStart(false, pPaM);
}
// #i56253#
@@ -328,12 +366,13 @@ namespace {
void InsertBreak(SwWrtShell& rWrtSh,
sal_uInt16 nKind,
::std::optional<sal_uInt16> oPageNumber,
- const OUString& rTemplateName)
+ const OUString& rTemplateName, std::optional<SwLineBreakClear> oClear)
{
switch ( nKind )
{
case 1 :
- rWrtSh.InsertLineBreak(); break;
+ rWrtSh.InsertLineBreak(oClear);
+ break;
case 2 :
rWrtSh.InsertColumnBreak(); break;
case 3 :
@@ -348,6 +387,400 @@ void InsertBreak(SwWrtShell& rWrtSh,
}
}
+OUString GetLocalURL(const SwWrtShell& rSh)
+{
+ SwField* pField = rSh.GetCurField();
+ if (!pField)
+ {
+ return OUString();
+ }
+
+ if (pField->GetTyp()->Which() != SwFieldIds::TableOfAuthorities)
+ {
+ return OUString();
+ }
+
+ const auto& rAuthorityField = *static_cast<const SwAuthorityField*>(pField);
+ SwAuthEntry* pAuthEntry = rAuthorityField.GetAuthEntry();
+ if (!pAuthEntry)
+ {
+ return OUString();
+ }
+
+ const OUString& rLocalURL = pAuthEntry->GetAuthorField(AUTH_FIELD_LOCAL_URL);
+ return rLocalURL;
+}
+
+void UpdateSections(SfxRequest& rReq, SwWrtShell& rWrtSh)
+{
+ OUString aSectionNamePrefix;
+ const SfxStringItem* pSectionNamePrefix = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
+ if (pSectionNamePrefix)
+ {
+ aSectionNamePrefix = pSectionNamePrefix->GetValue();
+ }
+
+ uno::Sequence<beans::PropertyValues> aSections;
+ const SfxUnoAnyItem* pSections = rReq.GetArg<SfxUnoAnyItem>(FN_PARAM_2);
+ if (pSections)
+ {
+ pSections->GetValue() >>= aSections;
+ }
+
+ rWrtSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::UPDATE_SECTIONS, nullptr);
+ rWrtSh.StartAction();
+
+ SwDoc* pDoc = rWrtSh.GetDoc();
+ sal_Int32 nSectionIndex = 0;
+ const SwSectionFormats& rFormats = pDoc->GetSections();
+ IDocumentContentOperations& rIDCO = pDoc->getIDocumentContentOperations();
+ for (size_t i = 0; i < rFormats.size(); ++i)
+ {
+ const SwSectionFormat* pFormat = rFormats[i];
+ if (!pFormat->GetName().startsWith(aSectionNamePrefix))
+ {
+ continue;
+ }
+
+ if (nSectionIndex >= aSections.getLength())
+ {
+ break;
+ }
+
+ comphelper::SequenceAsHashMap aMap(aSections[nSectionIndex++]);
+ OUString aSectionName = aMap["RegionName"].get<OUString>();
+ if (aSectionName != pFormat->GetName())
+ {
+ const_cast<SwSectionFormat*>(pFormat)->SetFormatName(aSectionName, /*bBroadcast=*/true);
+ SwSectionData aSectionData(*pFormat->GetSection());
+ aSectionData.SetSectionName(aSectionName);
+ pDoc->UpdateSection(i, aSectionData);
+ }
+
+ const SwFormatContent& rContent = pFormat->GetContent();
+ const SwNodeIndex* pContentNodeIndex = rContent.GetContentIdx();
+ if (pContentNodeIndex)
+ {
+ SwPaM aSectionStart(SwPosition{*pContentNodeIndex});
+ aSectionStart.Move(fnMoveForward, GoInContent);
+ SwPaM* pCursorPos = rWrtSh.GetCursor();
+ *pCursorPos = aSectionStart;
+ rWrtSh.EndOfSection(/*bSelect=*/true);
+ rIDCO.DeleteAndJoin(*pCursorPos);
+ rWrtSh.EndSelect();
+
+ OUString aSectionText = aMap["Content"].get<OUString>();
+ SwTranslateHelper::PasteHTMLToPaM(rWrtSh, pCursorPos, aSectionText.toUtf8());
+ }
+ }
+
+ rWrtSh.EndAction();
+ rWrtSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::UPDATE_SECTIONS, nullptr);
+}
+
+void DeleteSections(SfxRequest& rReq, SwWrtShell& rWrtSh)
+{
+ OUString aSectionNamePrefix;
+ const SfxStringItem* pSectionNamePrefix = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
+ if (pSectionNamePrefix)
+ {
+ aSectionNamePrefix = pSectionNamePrefix->GetValue();
+ }
+
+ rWrtSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::DELETE_SECTIONS, nullptr);
+ rWrtSh.StartAction();
+ comphelper::ScopeGuard g(
+ [&rWrtSh]
+ {
+ rWrtSh.EndAction();
+ rWrtSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::DELETE_SECTIONS, nullptr);
+ });
+
+ SwDoc* pDoc = rWrtSh.GetDoc();
+ SwSectionFormats& rFormats = pDoc->GetSections();
+ std::vector<SwSectionFormat*> aRemovals;
+ for (size_t i = 0; i < rFormats.size(); ++i)
+ {
+ SwSectionFormat* pFormat = rFormats[i];
+
+ if (!aSectionNamePrefix.isEmpty())
+ {
+ if (!pFormat->GetName().startsWith(aSectionNamePrefix))
+ {
+ continue;
+ }
+ }
+
+ aRemovals.push_back(pFormat);
+ }
+
+ for (const auto& pFormat : aRemovals)
+ {
+ // Just delete the format, not the content of the section.
+ pDoc->DelSectionFormat(pFormat);
+ }
+}
+
+void UpdateBookmarks(SfxRequest& rReq, SwWrtShell& rWrtSh)
+{
+ if (rWrtSh.getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS))
+ {
+ return;
+ }
+
+ OUString aBookmarkNamePrefix;
+ const SfxStringItem* pBookmarkNamePrefix = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
+ if (pBookmarkNamePrefix)
+ {
+ aBookmarkNamePrefix = pBookmarkNamePrefix->GetValue();
+ }
+
+ uno::Sequence<beans::PropertyValues> aBookmarks;
+ const SfxUnoAnyItem* pBookmarks = rReq.GetArg<SfxUnoAnyItem>(FN_PARAM_2);
+ if (pBookmarks)
+ {
+ pBookmarks->GetValue() >>= aBookmarks;
+ }
+
+ rWrtSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::UPDATE_BOOKMARKS, nullptr);
+ rWrtSh.StartAction();
+
+ IDocumentMarkAccess& rIDMA = *rWrtSh.GetDoc()->getIDocumentMarkAccess();
+ sal_Int32 nBookmarkIndex = 0;
+ bool bSortMarks = false;
+ for (auto it = rIDMA.getBookmarksBegin(); it != rIDMA.getBookmarksEnd(); ++it)
+ {
+ auto pMark = dynamic_cast<sw::mark::Bookmark*>(*it);
+ assert(pMark);
+ if (!pMark->GetName().startsWith(aBookmarkNamePrefix))
+ {
+ continue;
+ }
+
+ if (aBookmarks.getLength() <= nBookmarkIndex)
+ {
+ continue;
+ }
+
+ comphelper::SequenceAsHashMap aMap(aBookmarks[nBookmarkIndex++]);
+ if (aMap["Bookmark"].get<OUString>() != pMark->GetName())
+ {
+ rIDMA.renameMark(pMark, aMap["Bookmark"].get<OUString>());
+ }
+
+ OUString aBookmarkText = aMap["BookmarkText"].get<OUString>();
+
+ // Insert markers to remember where the paste positions are.
+ SwPaM aMarkers(pMark->GetMarkEnd());
+ IDocumentContentOperations& rIDCO = rWrtSh.GetDoc()->getIDocumentContentOperations();
+ bool bSuccess = rIDCO.InsertString(aMarkers, "XY");
+ if (bSuccess)
+ {
+ SwPaM aPasteEnd(pMark->GetMarkEnd());
+ aPasteEnd.Move(fnMoveForward, GoInContent);
+
+ // Paste HTML content.
+ SwPaM* pCursorPos = rWrtSh.GetCursor();
+ *pCursorPos = aPasteEnd;
+ SwTranslateHelper::PasteHTMLToPaM(rWrtSh, pCursorPos, aBookmarkText.toUtf8());
+
+ // Update the bookmark to point to the new content.
+ SwPaM aPasteStart(pMark->GetMarkEnd());
+ aPasteStart.Move(fnMoveForward, GoInContent);
+ SwPaM aStartMarker(pMark->GetMarkStart(), *aPasteStart.GetPoint());
+ SwPaM aEndMarker(*aPasteEnd.GetPoint(), *aPasteEnd.GetPoint());
+ aEndMarker.GetMark()->AdjustContent(1);
+ pMark->SetMarkPos(*aPasteStart.GetPoint());
+ pMark->SetOtherMarkPos(*aPasteEnd.GetPoint());
+ bSortMarks = true;
+
+ // Remove markers. the start marker includes the old content as well.
+ rIDCO.DeleteAndJoin(aStartMarker);
+ rIDCO.DeleteAndJoin(aEndMarker);
+ }
+ }
+ if (bSortMarks)
+ {
+ rIDMA.assureSortedMarkContainers();
+ }
+
+ rWrtSh.EndAction();
+ rWrtSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::UPDATE_BOOKMARKS, nullptr);
+}
+
+void UpdateBookmark(SfxRequest& rReq, SwWrtShell& rWrtSh)
+{
+ if (rWrtSh.getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS))
+ {
+ return;
+ }
+
+ OUString aBookmarkNamePrefix;
+ const SfxStringItem* pBookmarkNamePrefix = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
+ if (pBookmarkNamePrefix)
+ {
+ aBookmarkNamePrefix = pBookmarkNamePrefix->GetValue();
+ }
+
+ uno::Sequence<beans::PropertyValue> aBookmark;
+ const SfxUnoAnyItem* pBookmarks = rReq.GetArg<SfxUnoAnyItem>(FN_PARAM_2);
+ if (pBookmarks)
+ {
+ pBookmarks->GetValue() >>= aBookmark;
+ }
+
+ IDocumentMarkAccess& rIDMA = *rWrtSh.GetDoc()->getIDocumentMarkAccess();
+ SwPosition& rCursor = *rWrtSh.GetCursor()->GetPoint();
+ auto pBookmark = dynamic_cast<sw::mark::Bookmark*>(rIDMA.getOneInnermostBookmarkFor(rCursor));
+ if (!pBookmark || !pBookmark->GetName().startsWith(aBookmarkNamePrefix))
+ {
+ return;
+ }
+
+ SwRewriter aRewriter;
+ aRewriter.AddRule(UndoArg1, pBookmark->GetName());
+ rWrtSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::UPDATE_BOOKMARK, &aRewriter);
+ rWrtSh.StartAction();
+ comphelper::ScopeGuard g(
+ [&rWrtSh, &aRewriter]
+ {
+ rWrtSh.EndAction();
+ rWrtSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::UPDATE_BOOKMARK, &aRewriter);
+ });
+
+
+ comphelper::SequenceAsHashMap aMap(aBookmark);
+ if (aMap["Bookmark"].get<OUString>() != pBookmark->GetName())
+ {
+ rIDMA.renameMark(pBookmark, aMap["Bookmark"].get<OUString>());
+ }
+
+ // Insert markers to remember where the paste positions are.
+ SwPaM aMarkers(pBookmark->GetMarkEnd());
+ IDocumentContentOperations& rIDCO = rWrtSh.GetDoc()->getIDocumentContentOperations();
+ if (!rIDCO.InsertString(aMarkers, "XY"))
+ {
+ return;
+ }
+
+ SwPaM aPasteEnd(pBookmark->GetMarkEnd());
+ aPasteEnd.Move(fnMoveForward, GoInContent);
+
+ OUString aBookmarkText = aMap["BookmarkText"].get<OUString>();
+
+ // Paste HTML content.
+ SwPaM* pCursorPos = rWrtSh.GetCursor();
+ *pCursorPos = aPasteEnd;
+ SwTranslateHelper::PasteHTMLToPaM(rWrtSh, pCursorPos, aBookmarkText.toUtf8());
+
+ // Update the bookmark to point to the new content.
+ SwPaM aPasteStart(pBookmark->GetMarkEnd());
+ aPasteStart.Move(fnMoveForward, GoInContent);
+ SwPaM aStartMarker(pBookmark->GetMarkStart(), *aPasteStart.GetPoint());
+ SwPaM aEndMarker(*aPasteEnd.GetPoint(), *aPasteEnd.GetPoint());
+ aEndMarker.GetMark()->AdjustContent(1);
+ pBookmark->SetMarkPos(*aPasteStart.GetPoint());
+ pBookmark->SetOtherMarkPos(*aPasteEnd.GetPoint());
+
+ // Remove markers. the start marker includes the old content as well.
+ rIDCO.DeleteAndJoin(aStartMarker);
+ rIDCO.DeleteAndJoin(aEndMarker);
+ rIDMA.assureSortedMarkContainers();
+}
+
+void DeleteBookmarks(SfxRequest& rReq, SwWrtShell& rWrtSh)
+{
+ if (rWrtSh.getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS))
+ {
+ return;
+ }
+
+ OUString aBookmarkNamePrefix;
+ const SfxStringItem* pBookmarkNamePrefix = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
+ if (pBookmarkNamePrefix)
+ {
+ aBookmarkNamePrefix = pBookmarkNamePrefix->GetValue();
+ }
+
+ rWrtSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::DELETE_BOOKMARKS, nullptr);
+ rWrtSh.StartAction();
+ comphelper::ScopeGuard g(
+ [&rWrtSh]
+ {
+ rWrtSh.EndAction();
+ rWrtSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::DELETE_BOOKMARKS, nullptr);
+ });
+
+ IDocumentMarkAccess* pMarkAccess = rWrtSh.GetDoc()->getIDocumentMarkAccess();
+ std::vector<sw::mark::IMark*> aRemovals;
+ for (auto it = pMarkAccess->getBookmarksBegin(); it != pMarkAccess->getBookmarksEnd(); ++it)
+ {
+ auto pBookmark = dynamic_cast<sw::mark::Bookmark*>(*it);
+ assert(pBookmark);
+
+ if (!aBookmarkNamePrefix.isEmpty())
+ {
+ if (!pBookmark->GetName().startsWith(aBookmarkNamePrefix))
+ {
+ continue;
+ }
+ }
+
+ aRemovals.push_back(pBookmark);
+ }
+
+ for (const auto& pMark : aRemovals)
+ {
+ pMarkAccess->deleteMark(pMark);
+ }
+}
+
+void DeleteFields(SfxRequest& rReq, SwWrtShell& rWrtSh)
+{
+ const SfxStringItem* pTypeName = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
+ if (!pTypeName || pTypeName->GetValue() != "SetRef")
+ {
+ // This is implemented so far only for reference marks.
+ return;
+ }
+
+ OUString aNamePrefix;
+ const SfxStringItem* pNamePrefix = rReq.GetArg<SfxStringItem>(FN_PARAM_2);
+ if (pNamePrefix)
+ {
+ aNamePrefix = pNamePrefix->GetValue();
+ }
+
+ SwDoc* pDoc = rWrtSh.GetDoc();
+ pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::DELETE_FIELDS, nullptr);
+ rWrtSh.StartAction();
+ comphelper::ScopeGuard g(
+ [&rWrtSh]
+ {
+ rWrtSh.EndAction();
+ rWrtSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::DELETE_FIELDS, nullptr);
+ });
+
+ std::vector<const SwFormatRefMark*> aRemovals;
+ for (sal_uInt16 i = 0; i < pDoc->GetRefMarks(); ++i)
+ {
+ const SwFormatRefMark* pRefMark = pDoc->GetRefMark(i);
+ if (!aNamePrefix.isEmpty())
+ {
+ if (!pRefMark->GetRefName().startsWith(aNamePrefix))
+ {
+ continue;
+ }
+ }
+
+ aRemovals.push_back(pRefMark);
+ }
+
+ for (const auto& pMark : aRemovals)
+ {
+ pDoc->DeleteFormatRefMark(pMark);
+ }
+}
}
void SwTextShell::Execute(SfxRequest &rReq)
@@ -358,7 +791,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
const SfxPoolItem* pItem = nullptr;
const sal_uInt16 nSlot = rReq.GetSlot();
if(pArgs)
- pArgs->GetItemState(GetPool().GetWhich(nSlot), false, &pItem);
+ pArgs->GetItemState(GetPool().GetWhichIDFromSlotID(nSlot), false, &pItem);
switch( nSlot )
{
case SID_UNICODE_NOTATION_TOGGLE:
@@ -379,10 +812,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
if (rWrtSh.HasReadonlySel() && !rWrtSh.CursorInsideInputField())
{
// Only break if there's something to do; don't nag with the dialog otherwise
- auto xInfo(std::make_unique<weld::GenericDialogController>(
- rWrtSh.GetView().GetFrameWeld(), "modules/swriter/ui/inforeadonlydialog.ui",
- "InfoReadonlyDialog"));
- xInfo->run();
+ rWrtSh.InfoReadOnlyDialog(false);
break;
}
SwRewriter aRewriter;
@@ -415,11 +845,11 @@ void SwTextShell::Execute(SfxRequest &rReq)
//!! Remember the view frame right now...
//!! (call to GetView().GetViewFrame() will break if the
//!! SwTextShell got destroyed meanwhile.)
- SfxViewFrame *pViewFrame = GetView().GetViewFrame();
+ SfxViewFrame& rViewFrame = GetView().GetViewFrame();
if (aNewLangText == "*")
{
- // open the dialog "Tools/Options/Language Settings - Language"
+ // open the dialog "Tools/Options/Languages and Locales - General"
// to set the documents default language
SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateVclDialog(GetView().GetFrameWeld(), SID_LANGUAGE_OPTIONS));
@@ -437,14 +867,14 @@ void SwTextShell::Execute(SfxRequest &rReq)
// setting the new language...
if (!aNewLangText.isEmpty())
{
- const OUString aSelectionLangPrefix("Current_");
- const OUString aParagraphLangPrefix("Paragraph_");
- const OUString aDocumentLangPrefix("Default_");
+ static constexpr OUString aSelectionLangPrefix(u"Current_"_ustr);
+ static constexpr OUString aParagraphLangPrefix(u"Paragraph_"_ustr);
+ static constexpr OUString aDocumentLangPrefix(u"Default_"_ustr);
- SfxItemSet aCoreSet( GetPool(),
- svl::Items<RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
+ SfxItemSetFixed
+ <RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
- RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE>{} );
+ RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE> aCoreSet( GetPool() );
sal_Int32 nPos = 0;
bool bForSelection = true;
@@ -452,20 +882,20 @@ void SwTextShell::Execute(SfxRequest &rReq)
if (-1 != (nPos = aNewLangText.indexOf( aSelectionLangPrefix )))
{
// ... for the current selection
- aNewLangText = aNewLangText.replaceAt(nPos, aSelectionLangPrefix.getLength(), "");
+ aNewLangText = aNewLangText.replaceAt(nPos, aSelectionLangPrefix.getLength(), u"");
bForSelection = true;
}
else if (-1 != (nPos = aNewLangText.indexOf(aParagraphLangPrefix)))
{
// ... for the current paragraph language
- aNewLangText = aNewLangText.replaceAt(nPos, aParagraphLangPrefix.getLength(), "");
+ aNewLangText = aNewLangText.replaceAt(nPos, aParagraphLangPrefix.getLength(), u"");
bForSelection = true;
bForParagraph = true;
}
else if (-1 != (nPos = aNewLangText.indexOf(aDocumentLangPrefix)))
{
// ... as default document language
- aNewLangText = aNewLangText.replaceAt(nPos, aDocumentLangPrefix.getLength(), "");
+ aNewLangText = aNewLangText.replaceAt(nPos, aDocumentLangPrefix.getLength(), u"");
bForSelection = false;
}
@@ -504,7 +934,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
}
// invalidate slot to get the new language displayed
- pViewFrame->GetBindings().Invalidate( nSlot );
+ rViewFrame.GetBindings().Invalidate( nSlot );
rReq.Done();
break;
@@ -514,7 +944,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
{
// replace word/selection with text from selected sub menu entry
OUString aReplaceText;
- const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(SID_THES);
+ const SfxStringItem* pItem2 = rReq.GetArg(FN_PARAM_THES_WORD_REPLACE);
if (pItem2)
aReplaceText = pItem2->GetValue();
if (!aReplaceText.isEmpty())
@@ -545,8 +975,8 @@ void SwTextShell::Execute(SfxRequest &rReq)
rWrtSh.InsertFootnote( aStr, nSlot == FN_INSERT_ENDNOTE, !bFont );
if ( bFont )
{
- rWrtSh.Left( CRSR_SKIP_CHARS, true, 1, false );
- SfxItemSet aSet( rWrtSh.GetAttrPool(), svl::Items<RES_CHRATR_FONT, RES_CHRATR_FONT>{} );
+ rWrtSh.Left( SwCursorSkipMode::Chars, true, 1, false );
+ SfxItemSetFixed<RES_CHRATR_FONT, RES_CHRATR_FONT> aSet( rWrtSh.GetAttrPool() );
rWrtSh.GetCurAttr( aSet );
rWrtSh.SetAttrSet( aSet, SetAttrMode::DONTEXPAND );
rWrtSh.ResetSelect(nullptr, false);
@@ -560,20 +990,26 @@ void SwTextShell::Execute(SfxRequest &rReq)
case FN_INSERT_FOOTNOTE_DLG:
{
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
- ScopedVclPtr<AbstractInsFootNoteDlg> pDlg(pFact->CreateInsFootNoteDlg(
+ VclPtr<AbstractInsFootNoteDlg> pDlg(pFact->CreateInsFootNoteDlg(
GetView().GetFrameWeld(), rWrtSh));
pDlg->SetHelpId(GetStaticInterface()->GetSlot(nSlot)->GetCommand());
- if ( pDlg->Execute() == RET_OK )
- {
- const sal_uInt16 nId = pDlg->IsEndNote() ? FN_INSERT_ENDNOTE : FN_INSERT_FOOTNOTE;
- SfxRequest aReq( GetView().GetViewFrame(), nId );
- if ( !pDlg->GetStr().isEmpty() )
- aReq.AppendItem( SfxStringItem( nId, pDlg->GetStr() ) );
- if ( !pDlg->GetFontName().isEmpty() )
- aReq.AppendItem( SfxStringItem( FN_PARAM_1, pDlg->GetFontName() ) );
- ExecuteSlot( aReq );
- }
-
+ pDlg->StartExecuteAsync(
+ [this, pDlg] (sal_Int32 nResult)->void
+ {
+ if ( nResult == RET_OK )
+ {
+ pDlg->Apply();
+ const sal_uInt16 nId = pDlg->IsEndNote() ? FN_INSERT_ENDNOTE : FN_INSERT_FOOTNOTE;
+ SfxRequest aReq(GetView().GetViewFrame(), nId);
+ if ( !pDlg->GetStr().isEmpty() )
+ aReq.AppendItem( SfxStringItem( nId, pDlg->GetStr() ) );
+ if ( !pDlg->GetFontName().isEmpty() )
+ aReq.AppendItem( SfxStringItem( FN_PARAM_1, pDlg->GetFontName() ) );
+ ExecuteSlot( aReq );
+ }
+ pDlg->disposeOnce();
+ }
+ );
rReq.Ignore();
}
break;
@@ -604,6 +1040,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
{ RES_CHRATR_CJK_LANGUAGE + 1, RES_CHRATR_CTL_LANGUAGE - 1 },
{ RES_CHRATR_CTL_LANGUAGE + 1, RES_CHRATR_END - 1 },
{ RES_PARATR_BEGIN, RES_PARATR_END - 1 },
+ { RES_PARATR_LIST_AUTOFMT, RES_PARATR_LIST_AUTOFMT },
{ RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER },
{ RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END - 1 },
};
@@ -615,7 +1052,8 @@ void SwTextShell::Execute(SfxRequest &rReq)
rWrtSh.ResetAttr( aAttribs );
// also clear the direct formatting flag inside SwTableBox(es)
- GetView().GetDocShell()->GetFEShell()->UpdateTableStyleFormatting(nullptr, true);
+ if (SwFEShell* pFEShell = GetView().GetDocShell()->GetFEShell())
+ pFEShell->UpdateTableStyleFormatting(nullptr, true);
rReq.Done();
break;
@@ -625,6 +1063,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
if ( pItem )
{
::std::optional<sal_uInt16> oPageNumber;
+ std::optional<SwLineBreakClear> oClear;
OUString aTemplateName;
sal_uInt16 nKind = static_cast<const SfxInt16Item*>(pItem)->GetValue();
const SfxStringItem* pTemplate = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
@@ -635,7 +1074,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
if ( pNumber && pIsNumberFilled && pIsNumberFilled->GetValue() )
oPageNumber = pNumber->GetValue();
- InsertBreak(rWrtSh, nKind, oPageNumber, aTemplateName);
+ InsertBreak(rWrtSh, nKind, oPageNumber, aTemplateName, oClear);
}
else
{
@@ -651,8 +1090,9 @@ void SwTextShell::Execute(SfxRequest &rReq)
sal_uInt16 nKind = pAbstractDialog->GetKind();
OUString aTemplateName = pAbstractDialog->GetTemplateName();
::std::optional<sal_uInt16> oPageNumber = pAbstractDialog->GetPageNumber();
+ std::optional<SwLineBreakClear> oClear = pAbstractDialog->GetClear();
- InsertBreak(rWrtSh, nKind, oPageNumber, aTemplateName);
+ InsertBreak(rWrtSh, nKind, oPageNumber, aTemplateName, oClear);
}
});
}
@@ -661,15 +1101,66 @@ void SwTextShell::Execute(SfxRequest &rReq)
}
case FN_INSERT_BOOKMARK:
{
+ const SfxStringItem* pBookmarkText = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
+ SwPaM* pCursorPos = rWrtSh.GetCursor();
if ( pItem )
{
+ rWrtSh.StartAction();
OUString sName = static_cast<const SfxStringItem*>(pItem)->GetValue();
+
+ if (pBookmarkText)
+ {
+ OUString aBookmarkText = pBookmarkText->GetValue();
+ // Split node to remember where the start position is.
+ bool bSuccess = rWrtSh.GetDoc()->getIDocumentContentOperations().SplitNode(
+ *pCursorPos->GetPoint(), /*bChkTableStart=*/false);
+ if (bSuccess)
+ {
+ SwPaM aBookmarkPam(*pCursorPos->GetPoint());
+ aBookmarkPam.Move(fnMoveBackward, GoInContent);
+
+ // Paste HTML content.
+ SwTranslateHelper::PasteHTMLToPaM(
+ rWrtSh, pCursorPos, aBookmarkText.toUtf8());
+ if (pCursorPos->GetPoint()->GetContentIndex() == 0)
+ {
+ // The paste created a last empty text node, remove it.
+ SwPaM aPam(*pCursorPos->GetPoint());
+ aPam.SetMark();
+ aPam.Move(fnMoveBackward, GoInContent);
+ rWrtSh.GetDoc()->getIDocumentContentOperations().DeleteAndJoin(aPam);
+ }
+
+ // Undo the above SplitNode().
+ aBookmarkPam.SetMark();
+ aBookmarkPam.Move(fnMoveForward, GoInContent);
+ rWrtSh.GetDoc()->getIDocumentContentOperations().DeleteAndJoin(
+ aBookmarkPam);
+ *aBookmarkPam.GetMark() = *pCursorPos->GetPoint();
+ *pCursorPos = aBookmarkPam;
+ }
+ }
+
rWrtSh.SetBookmark( vcl::KeyCode(), sName );
+ if (pBookmarkText)
+ {
+ pCursorPos->DeleteMark();
+ }
+ rWrtSh.EndAction();
+ break;
+ }
+ [[fallthrough]];
+ }
+ case FN_EDIT_BOOKMARK:
+ {
+ ::std::optional<OUString> oName;
+ if (pItem)
+ {
+ oName.emplace(static_cast<const SfxStringItem*>(pItem)->GetValue());
}
- else
{
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
- ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSwInsertBookmarkDlg(GetView().GetFrameWeld(), rWrtSh));
+ ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSwInsertBookmarkDlg(GetView().GetFrameWeld(), rWrtSh, oName ? &*oName : nullptr));
VclAbstractDialog::AsyncContext aContext;
aContext.maEndDialogFn = [](sal_Int32){};
pDlg->StartExecuteAsync(aContext);
@@ -677,15 +1168,53 @@ void SwTextShell::Execute(SfxRequest &rReq)
break;
}
+ case FN_UPDATE_BOOKMARKS:
+ {
+ // This updates all bookmarks in the document that match the conditions specified in
+ // rReq.
+ UpdateBookmarks(rReq, rWrtSh);
+ break;
+ }
+ case FN_UPDATE_BOOKMARK:
+ {
+ // This updates the bookmark under the cursor.
+ UpdateBookmark(rReq, rWrtSh);
+ break;
+ }
case FN_DELETE_BOOKMARK:
{
+ // This deletes a bookmark with the specified name.
if (pItem && !rWrtSh.getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS))
{
IDocumentMarkAccess* const pMarkAccess = rWrtSh.getIDocumentMarkAccess();
- pMarkAccess->deleteMark( pMarkAccess->findMark(static_cast<const SfxStringItem*>(pItem)->GetValue()) );
+ pMarkAccess->deleteMark(pMarkAccess->findMark(static_cast<const SfxStringItem*>(pItem)->GetValue()), false);
}
break;
}
+ case FN_DELETE_BOOKMARKS:
+ {
+ // This deletes all bookmarks in the document matching a specified prefix.
+ DeleteBookmarks(rReq, rWrtSh);
+ break;
+ }
+ case FN_DELETE_FIELDS:
+ {
+ // This deletes all fields in the document matching a specified type & prefix.
+ DeleteFields(rReq, rWrtSh);
+ break;
+ }
+ case FN_UPDATE_SECTIONS:
+ {
+ UpdateSections(rReq, rWrtSh);
+ break;
+ }
+ case FN_DELETE_SECTIONS:
+ {
+ // This deletes all sections in the document matching a specified prefix. Note that the
+ // section is deleted, but not its contents.
+ DeleteSections(rReq, rWrtSh);
+ break;
+ }
case FN_SET_REMINDER:
{
// collect and sort navigator reminder names
@@ -703,7 +1232,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
// we are maxed out so delete the first one
// this assumes that IDocumentMarkAccess generates Names in ascending order
if(vNavMarkNames.size() == MAX_MARKS)
- pMarkAccess->deleteMark(pMarkAccess->findMark(vNavMarkNames[0]));
+ pMarkAccess->deleteMark(pMarkAccess->findMark(vNavMarkNames[0]), false);
rWrtSh.SetBookmark(vcl::KeyCode(), OUString(), IDocumentMarkAccess::MarkType::NAVIGATOR_REMINDER);
SwView::SetActMark(vNavMarkNames.size() < MAX_MARKS ? vNavMarkNames.size() : MAX_MARKS-1);
@@ -716,37 +1245,24 @@ void SwTextShell::Execute(SfxRequest &rReq)
// This must always be false for the postprocessing.
aFlags.bAFormatByInput = false;
aFlags.bWithRedlining = true;
- rWrtSh.AutoFormat( &aFlags );
+ rWrtSh.AutoFormat( &aFlags, false );
aFlags.bWithRedlining = false;
- SfxViewFrame* pVFrame = GetView().GetViewFrame();
- if (pVFrame->HasChildWindow(FN_REDLINE_ACCEPT))
- pVFrame->ToggleChildWindow(FN_REDLINE_ACCEPT);
+ SfxViewFrame& rVFrame = GetView().GetViewFrame();
+ if (rVFrame.HasChildWindow(FN_REDLINE_ACCEPT))
+ rVFrame.ToggleChildWindow(FN_REDLINE_ACCEPT);
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
- ScopedVclPtr<AbstractSwModalRedlineAcceptDlg> xDlg(pFact->CreateSwModalRedlineAcceptDlg(GetView().GetEditWin().GetFrameWeld()));
-
- switch (lcl_AskRedlineFlags(GetView().GetFrameWeld()))
- {
- case RET_OK:
+ auto xRequest = std::make_shared<SfxRequest>(rReq);
+ rReq.Ignore(); // the 'old' request is not relevant any more
+ VclPtr<AbstractSwModalRedlineAcceptDlg> pDlg(pFact->CreateSwModalRedlineAcceptDlg(GetView().GetEditWin().GetFrameWeld()));
+ pDlg->StartExecuteAsync(
+ [pDlg, xRequest] (sal_Int32 /*nResult*/)->void
{
- xDlg->AcceptAll(true);
- SfxRequest aReq( pVFrame, FN_AUTOFORMAT_APPLY );
- aReq.Done();
- rReq.Ignore();
- break;
+ pDlg->disposeOnce();
+ xRequest->Done();
}
-
- case RET_CANCEL:
- xDlg->AcceptAll(false);
- rReq.Ignore();
- break;
-
- case 102:
- xDlg->Execute();
- rReq.Done();
- break;
- }
+ );
}
break;
@@ -755,7 +1271,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
SvxSwAutoFormatFlags aFlags(SvxAutoCorrCfg::Get().GetAutoCorrect()->GetSwFlags());
// This must always be false for the postprocessing.
aFlags.bAFormatByInput = false;
- rWrtSh.AutoFormat( &aFlags );
+ rWrtSh.AutoFormat( &aFlags, false );
rReq.Done();
}
break;
@@ -767,9 +1283,9 @@ void SwTextShell::Execute(SfxRequest &rReq)
{
rACfg.SetAutoFormatByInput( bSet );
rACfg.Commit();
- GetView().GetViewFrame()->GetBindings().Invalidate( nSlot );
+ GetView().GetViewFrame().GetBindings().Invalidate( nSlot );
if ( !pItem )
- rReq.AppendItem( SfxBoolItem( GetPool().GetWhich(nSlot), bSet ) );
+ rReq.AppendItem( SfxBoolItem( GetPool().GetWhichIDFromSlotID(nSlot), bSet ) );
rReq.Done();
}
}
@@ -785,9 +1301,18 @@ void SwTextShell::Execute(SfxRequest &rReq)
case FN_SORTING_DLG:
{
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
- ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSwSortingDialog(GetView().GetFrameWeld(), rWrtSh));
- pDlg->Execute();
- rReq.Done();
+ VclPtr<AbstractSwSortDlg> pDlg(pFact->CreateSwSortingDialog(GetView().GetFrameWeld(), rWrtSh));
+ auto xRequest = std::make_shared<SfxRequest>(rReq);
+ rReq.Ignore(); // the 'old' request is not relevant any more
+ pDlg->StartExecuteAsync(
+ [pDlg, xRequest] (sal_Int32 nResult)->void
+ {
+ if (nResult == RET_OK)
+ pDlg->Apply();
+ pDlg->disposeOnce();
+ xRequest->Done();
+ }
+ );
}
break;
case FN_NUMBERING_OUTLINE_DLG:
@@ -811,7 +1336,8 @@ void SwTextShell::Execute(SfxRequest &rReq)
rWrtSh.StartAllAction();
rWrtSh.SwCursorShell::GotoRefMark( static_cast<SwGetRefField*>(pField)->GetSetRefName(),
static_cast<SwGetRefField*>(pField)->GetSubType(),
- static_cast<SwGetRefField*>(pField)->GetSeqNo() );
+ static_cast<SwGetRefField*>(pField)->GetSeqNo(),
+ static_cast<SwGetRefField*>(pField)->GetFlags() );
rWrtSh.EndAllAction();
rReq.Done();
}
@@ -820,14 +1346,14 @@ void SwTextShell::Execute(SfxRequest &rReq)
case FN_EDIT_FORMULA:
{
const sal_uInt16 nId = SwInputChild::GetChildWindowId();
- SfxViewFrame* pVFrame = GetView().GetViewFrame();
+ SfxViewFrame& rVFrame = GetView().GetViewFrame();
if(pItem)
{
//if the ChildWindow is active it has to be removed
- if( pVFrame->HasChildWindow( nId ) )
+ if( rVFrame.HasChildWindow( nId ) )
{
- pVFrame->ToggleChildWindow( nId );
- pVFrame->GetBindings().InvalidateAll( true );
+ rVFrame.ToggleChildWindow( nId );
+ rVFrame.GetBindings().InvalidateAll( true );
}
OUString sFormula(static_cast<const SfxStringItem*>(pItem)->GetValue());
@@ -850,7 +1376,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
{
if( rWrtSh.IsCursorInTable() )
{
- SfxItemSet aSet( rWrtSh.GetAttrPool(), svl::Items<RES_BOXATR_FORMULA, RES_BOXATR_FORMULA>{} );
+ SfxItemSetFixed<RES_BOXATR_FORMULA, RES_BOXATR_FORMULA> aSet( rWrtSh.GetAttrPool() );
aSet.Put( SwTableBoxFormula( sFormula ));
rWrtSh.SetTableBoxFormulaAttrs( aSet );
rWrtSh.UpdateTable();
@@ -872,9 +1398,9 @@ void SwTextShell::Execute(SfxRequest &rReq)
else
{
rWrtSh.EndAllTableBoxEdit();
- pVFrame->ToggleChildWindow( nId );
- if( !pVFrame->HasChildWindow( nId ) )
- pVFrame->GetBindings().InvalidateAll( true );
+ rVFrame.ToggleChildWindow( nId );
+ if( !rVFrame.HasChildWindow( nId ) )
+ rVFrame.GetBindings().InvalidateAll( true );
rReq.Ignore();
}
}
@@ -886,7 +1412,27 @@ void SwTextShell::Execute(SfxRequest &rReq)
}
break;
case SID_EDIT_HYPERLINK:
- GetView().GetViewFrame()->SetChildWindow(SID_HYPERLINK_DIALOG, true);
+ {
+ if (!rWrtSh.HasSelection())
+ {
+ SfxItemSetFixed<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT> aSet(GetPool());
+ rWrtSh.GetCurAttr(aSet);
+ if (SfxItemState::SET > aSet.GetItemState(RES_TXTATR_INETFMT))
+ {
+ // Didn't find a hyperlink to edit yet.
+
+ // If the cursor is just before an unselected hyperlink,
+ // the dialog will not know that it should edit that hyperlink,
+ // so in this case, first select it so the dialog will find the hyperlink.
+ // The dialog would leave the hyperlink selected anyway after a successful edit
+ // (although it isn't normally selected after a cancel, but oh well).
+ if (!rWrtSh.SelectTextAttr(RES_TXTATR_INETFMT))
+ break;
+ }
+ }
+
+ GetView().GetViewFrame().SetChildWindow(SID_HYPERLINK_DIALOG, true);
+ }
break;
case SID_REMOVE_HYPERLINK:
{
@@ -913,23 +1459,21 @@ void SwTextShell::Execute(SfxRequest &rReq)
case FN_TXTATR_INET :
case FN_INSERT_HYPERLINK:
{
- const sal_uInt16 nWhich = GetPool().GetWhich( nSlot );
+ const sal_uInt16 nWhich = GetPool().GetWhichIDFromSlotID( nSlot );
if ( pArgs && pArgs->GetItemState( nWhich ) == SfxItemState::SET )
bUseDialog = false;
[[fallthrough]];
}
case SID_CHAR_DLG:
case SID_CHAR_DLG_EFFECT:
+ case SID_CHAR_DLG_POSITION:
{
- sw_CharDialog( rWrtSh, bUseDialog, nSlot, pArgs, &rReq );
+ sw_CharDialog(rWrtSh, bUseDialog, /*ApplyToParagraph*/false, nSlot, pArgs, &rReq);
}
break;
case SID_CHAR_DLG_FOR_PARAGRAPH:
{
- rWrtSh.Push(); //save current cursor
- SwLangHelper::SelectCurrentPara( rWrtSh );
- sw_CharDialog( rWrtSh, bUseDialog, nSlot, pArgs, &rReq );
- rWrtSh.Pop(SwCursorShell::PopMode::DeleteCurrent); // restore old cursor
+ sw_CharDialog(rWrtSh, /*UseDialog*/true, /*ApplyToParagraph*/true, nSlot, pArgs, &rReq);
}
break;
case SID_ATTR_LRSPACE :
@@ -946,7 +1490,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
case FN_DROP_TEXT:
case SID_ATTR_PARA_LRSPACE:
{
- const sal_uInt16 nWhich = GetPool().GetWhich( nSlot );
+ const sal_uInt16 nWhich = GetPool().GetWhichIDFromSlotID( nSlot );
if ( pArgs && pArgs->GetItemState( nWhich ) == SfxItemState::SET )
bUseDialog = false;
[[fallthrough]];
@@ -957,10 +1501,9 @@ void SwTextShell::Execute(SfxRequest &rReq)
if ( pArgs )
{
- const SfxPoolItem* pPaMItem = nullptr;
- pArgs->GetItemState( GetPool().GetWhich( FN_PARAM_PAM ), false, &pPaMItem );
+ const SwPaMItem* pPaMItem = pArgs->GetItemIfSet( GetPool().GetWhichIDFromSlotID( FN_PARAM_PAM ), false );
if ( pPaMItem )
- pPaM = static_cast< const SwPaMItem* >( pPaMItem )->GetValue( );
+ pPaM = pPaMItem->GetValue( );
}
if ( !pPaM )
@@ -972,9 +1515,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
bool bApplyCharUnit = ::HasCharUnit( dynamic_cast<SwWebView*>( &GetView()) != nullptr );
SW_MOD()->PutItem(SfxBoolItem(SID_ATTR_APPLYCHARUNIT, bApplyCharUnit));
- SfxItemSet aCoreSet(
- GetPool(),
- svl::Items<
+ SfxItemSetFixed<
RES_PARATR_BEGIN, RES_FRMATR_END - 1,
// FillAttribute support:
XATTR_FILL_FIRST, XATTR_FILL_LAST,
@@ -990,7 +1531,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
SID_ATTR_PARA_PAGENUM, SID_ATTR_PARA_PAGENUM,
FN_PARAM_1, FN_PARAM_1,
FN_NUMBER_NEWSTART, FN_NUMBER_NEWSTART_AT,
- FN_DROP_TEXT, FN_DROP_CHAR_STYLE_NAME>{});
+ FN_DROP_TEXT, FN_DROP_CHAR_STYLE_NAME> aCoreSet( GetPool() );
// get also the list level indent values merged as LR-SPACE item, if needed.
rWrtSh.GetPaMAttr( pPaM, aCoreSet, true );
@@ -998,7 +1539,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
// create needed items for XPropertyList entries from the DrawModel so that
// the Area TabPage can access them
// Do this after GetCurAttr, this resets the ItemSet content again
- const SwDrawModel* pDrawModel = GetView().GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
+ SwDrawModel* pDrawModel = GetView().GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
aCoreSet.Put(SvxColorListItem(pDrawModel->GetColorList(), SID_COLOR_TABLE));
aCoreSet.Put(SvxGradientListItem(pDrawModel->GetGradientList(), SID_GRADIENT_LIST));
@@ -1010,9 +1551,9 @@ void SwTextShell::Execute(SfxRequest &rReq)
// Tabulators: Put DefaultTabs into ItemSet
const SvxTabStopItem& rDefTabs =
- GetPool().GetDefaultItem(RES_PARATR_TABSTOP);
+ GetPool().GetUserOrPoolDefaultItem(RES_PARATR_TABSTOP);
- const sal_uInt16 nDefDist = static_cast<sal_uInt16>(::GetTabDist( rDefTabs ));
+ const sal_uInt16 nDefDist = o3tl::narrowing<sal_uInt16>(::GetTabDist( rDefTabs ));
SfxUInt16Item aDefDistItem( SID_ATTR_TABSTOP_DEFAULTS, nDefDist );
aCoreSet.Put( aDefDistItem );
@@ -1022,8 +1563,8 @@ void SwTextShell::Execute(SfxRequest &rReq)
// Left border as offset
//#i24363# tab stops relative to indent
- const tools::Long nOff = rWrtSh.getIDocumentSettingAccess().get(DocumentSettingId::TABS_RELATIVE_TO_INDENT) ?
- aCoreSet.Get( RES_LR_SPACE ).GetTextLeft() : 0;
+ const tools::Long nOff = rWrtSh.getIDocumentSettingAccess().get(DocumentSettingId::TABS_RELATIVE_TO_INDENT)
+ ? aCoreSet.Get(RES_MARGIN_TEXTLEFT).GetTextLeft() : 0;
SfxInt32Item aOff( SID_ATTR_TABSTOP_OFFSET, nOff );
aCoreSet.Put( aOff );
@@ -1046,9 +1587,9 @@ void SwTextShell::Execute(SfxRequest &rReq)
if ( bUseDialog && GetActiveView() )
{
- OString sDefPage;
+ OUString sDefPage;
if (pItem)
- sDefPage = OUStringToOString(static_cast<const SfxStringItem*>(pItem)->GetValue(), RTL_TEXTENCODING_UTF8);
+ sDefPage = static_cast<const SfxStringItem*>(pItem)->GetValue();
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
pDlg.reset(pFact->CreateSwParaDlg(GetView().GetFrameWeld(), GetView(), aCoreSet, false, sDefPage));
@@ -1059,8 +1600,16 @@ void SwTextShell::Execute(SfxRequest &rReq)
if ( nSlot == SID_ATTR_PARA_LRSPACE)
{
SvxLRSpaceItem aParaMargin(static_cast<const SvxLRSpaceItem&>(pArgs->Get(nSlot)));
- aParaMargin.SetWhich( RES_LR_SPACE);
- aCoreSet.Put(aParaMargin);
+ SvxFirstLineIndentItem firstLine(RES_MARGIN_FIRSTLINE);
+ SvxTextLeftMarginItem leftMargin(RES_MARGIN_TEXTLEFT);
+ SvxRightMarginItem rightMargin(RES_MARGIN_RIGHT);
+ firstLine.SetTextFirstLineOffset(aParaMargin.GetTextFirstLineOffset(), aParaMargin.GetPropTextFirstLineOffset());
+ firstLine.SetAutoFirst(aParaMargin.IsAutoFirst());
+ leftMargin.SetTextLeft(aParaMargin.GetTextLeft(), aParaMargin.GetPropLeft());
+ rightMargin.SetRight(aParaMargin.GetRight(), aParaMargin.GetPropRight());
+ aCoreSet.Put(firstLine);
+ aCoreSet.Put(leftMargin);
+ aCoreSet.Put(rightMargin);
sw_ParagraphDialogResult(&aCoreSet, rWrtSh, rReq, pPaM);
}
@@ -1072,16 +1621,15 @@ void SwTextShell::Execute(SfxRequest &rReq)
auto pRequest = std::make_shared<SfxRequest>(rReq);
rReq.Ignore(); // the 'old' request is not relevant any more
- auto xPaM(std::make_shared<SwPaM>(*pPaM, nullptr)); // tdf#134439 make a copy to use at later apply
- pDlg->StartExecuteAsync([pDlg, &rWrtSh, pRequest, nDefDist, xPaM](sal_Int32 nResult){
+ auto vCursors = CopyPaMRing(*pPaM); // tdf#134439 make a copy to use at later apply
+ pDlg->StartExecuteAsync([pDlg, &rWrtSh, pDrawModel, pRequest, nDefDist, vCursors](sal_Int32 nResult){
if (nResult == RET_OK)
{
// Apply defaults if necessary.
SfxItemSet* pSet = const_cast<SfxItemSet*>(pDlg->GetOutputItemSet());
sal_uInt16 nNewDist;
- const SfxPoolItem* pItem2 = nullptr;
- if (SfxItemState::SET == pSet->GetItemState(SID_ATTR_TABSTOP_DEFAULTS, false, &pItem2) &&
- nDefDist != (nNewDist = static_cast<const SfxUInt16Item*>(pItem2)->GetValue()) )
+ const SfxUInt16Item* pDefaultsItem = pSet->GetItemIfSet(SID_ATTR_TABSTOP_DEFAULTS, false);
+ if (pDefaultsItem && nDefDist != (nNewDist = pDefaultsItem->GetValue()) )
{
SvxTabStopItem aDefTabs( 0, 0, SvxTabAdjust::Default, RES_PARATR_TABSTOP );
MakeDefTabs( nNewDist, aDefTabs );
@@ -1089,21 +1637,44 @@ void SwTextShell::Execute(SfxRequest &rReq)
pSet->ClearItem( SID_ATTR_TABSTOP_DEFAULTS );
}
+ const SfxPoolItem* pItem2 = nullptr;
if (SfxItemState::SET == pSet->GetItemState(FN_PARAM_1, false, &pItem2))
{
pSet->Put(SfxStringItem(FN_DROP_TEXT, static_cast<const SfxStringItem*>(pItem2)->GetValue()));
pSet->ClearItem(FN_PARAM_1);
}
- if (SfxItemState::SET == pSet->GetItemState(RES_PARATR_DROP, false, &pItem2))
+ if (const SwFormatDrop* pDropItem = pSet->GetItemIfSet(RES_PARATR_DROP, false))
{
OUString sCharStyleName;
- if (static_cast<const SwFormatDrop*>(pItem2)->GetCharFormat())
- sCharStyleName = static_cast<const SwFormatDrop*>(pItem2)->GetCharFormat()->GetName();
+ if (pDropItem->GetCharFormat())
+ sCharStyleName = pDropItem->GetCharFormat()->GetName();
pSet->Put(SfxStringItem(FN_DROP_CHAR_STYLE_NAME, sCharStyleName));
}
- sw_ParagraphDialogResult(pSet, rWrtSh, *pRequest, xPaM.get());
+ const XFillStyleItem* pFS = pSet->GetItem<XFillStyleItem>(XATTR_FILLSTYLE);
+ bool bSet = pFS && pFS->GetValue() == drawing::FillStyle_GRADIENT;
+ const XFillGradientItem* pTempGradItem
+ = bSet ? pSet->GetItem<XFillGradientItem>(XATTR_FILLGRADIENT) : nullptr;
+ if (pTempGradItem && pTempGradItem->GetName().isEmpty())
+ {
+ // MigrateItemSet guarantees unique gradient names
+ SfxItemSetFixed<XATTR_FILLGRADIENT, XATTR_FILLGRADIENT> aMigrateSet(rWrtSh.GetView().GetPool());
+ aMigrateSet.Put(XFillGradientItem("gradient", pTempGradItem->GetGradientValue()));
+ SdrModel::MigrateItemSet(&aMigrateSet, pSet, pDrawModel);
+ }
+
+ bSet = pFS && pFS->GetValue() == drawing::FillStyle_HATCH;
+ const XFillHatchItem* pTempHatchItem
+ = bSet ? pSet->GetItem<XFillHatchItem>(XATTR_FILLHATCH) : nullptr;
+ if (pTempHatchItem && pTempHatchItem->GetName().isEmpty())
+ {
+ SfxItemSetFixed<XATTR_FILLHATCH, XATTR_FILLHATCH> aMigrateSet(rWrtSh.GetView().GetPool());
+ aMigrateSet.Put(XFillHatchItem("hatch", pTempHatchItem->GetHatchValue()));
+ SdrModel::MigrateItemSet(&aMigrateSet, pSet, pDrawModel);
+ }
+
+ sw_ParagraphDialogResult(pSet, rWrtSh, *pRequest, vCursors->front().get());
}
pDlg->disposeOnce();
});
@@ -1175,64 +1746,45 @@ void SwTextShell::Execute(SfxRequest &rReq)
case SID_ATTR_CHAR_COLOR2:
{
- Color aSet;
- const SfxPoolItem* pColorStringItem = nullptr;
- bool bHasItem = false;
-
- if(pItem)
- {
- aSet = static_cast<const SvxColorItem*>(pItem)->GetValue();
- bHasItem = true;
- }
- else if (pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_COLOR_STR, false, &pColorStringItem))
- {
- OUString sColor = static_cast<const SfxStringItem*>(pColorStringItem)->GetValue();
- aSet = Color(ColorTransparency, sColor.toInt32(16));
- bHasItem = true;
- }
-
- if (bHasItem)
+ if (pItem)
{
+ auto* pColorItem = static_cast<const SvxColorItem*>(pItem);
SwEditWin& rEditWin = GetView().GetEditWin();
- rEditWin.SetWaterCanTextColor(aSet);
+ rEditWin.SetWaterCanTextColor(pColorItem->GetValue());
SwApplyTemplate* pApply = rEditWin.GetApplyTemplate();
// If there is a selection, then set the color on it
// otherwise, it'll be the color for the next text to be typed
- if(!pApply || pApply->nColor != SID_ATTR_CHAR_COLOR_EXT)
+ if (!pApply || pApply->nColor != SID_ATTR_CHAR_COLOR_EXT)
{
- rWrtSh.SetAttrItem(SvxColorItem (aSet, RES_CHRATR_COLOR));
+ rWrtSh.SetAttrItem(SvxColorItem(pColorItem->GetValue(), pColorItem->getComplexColor(), RES_CHRATR_COLOR));
}
rReq.Done();
}
}
break;
- case SID_ATTR_CHAR_COLOR_BACKGROUND:
- case SID_ATTR_CHAR_COLOR_BACKGROUND_EXT:
+ case SID_ATTR_CHAR_BACK_COLOR:
+ case SID_ATTR_CHAR_COLOR_BACKGROUND: // deprecated
case SID_ATTR_CHAR_COLOR_EXT:
{
- Color aSet;
- const SfxPoolItem* pColorStringItem = nullptr;
+ Color aColor;
+ model::ComplexColor aComplexColor;
- if (pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_COLOR_STR, false, &pColorStringItem))
+ if (pItem)
{
- OUString sColor = static_cast<const SfxStringItem*>(pColorStringItem)->GetValue();
- if (sColor == "transparent")
- aSet = COL_TRANSPARENT;
- else
- aSet = Color(ColorTransparency, sColor.toInt32(16));
+ auto* pColorItem = static_cast<const SvxColorItem*>(pItem);
+ aColor = pColorItem->GetValue();
+ aComplexColor = pColorItem->getComplexColor();
}
- else if (pItem)
- aSet = static_cast<const SvxColorItem*>(pItem)->GetValue();
else
- aSet = COL_TRANSPARENT;
+ aColor = COL_TRANSPARENT;
SwEditWin& rEdtWin = GetView().GetEditWin();
if (nSlot != SID_ATTR_CHAR_COLOR_EXT)
- rEdtWin.SetWaterCanTextBackColor(aSet);
+ rEdtWin.SetWaterCanTextBackColor(aColor);
else if (pItem)
- rEdtWin.SetWaterCanTextColor(aSet);
+ rEdtWin.SetWaterCanTextColor(aColor);
SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate();
SwApplyTemplate aTempl;
@@ -1240,29 +1792,21 @@ void SwTextShell::Execute(SfxRequest &rReq)
{
if (nSlot != SID_ATTR_CHAR_COLOR_EXT)
{
- SfxItemSet aCoreSet( rWrtSh.GetView().GetPool(), svl::Items<
- RES_CHRATR_BACKGROUND, RES_CHRATR_BACKGROUND>{} );
+ SfxItemSetFixed<RES_CHRATR_BACKGROUND, RES_CHRATR_BACKGROUND> aCoreSet( rWrtSh.GetView().GetPool() );
- rWrtSh.GetCurAttr( aCoreSet );
+ rWrtSh.GetCurAttr(aCoreSet);
// Remove highlight if already set of the same color
const SvxBrushItem& rBrushItem = aCoreSet.Get(RES_CHRATR_BACKGROUND);
- if ( aSet == rBrushItem.GetColor() )
- aSet = COL_TRANSPARENT;
-
- ApplyCharBackground(aSet, rWrtSh);
+ if (aColor == rBrushItem.GetColor())
+ {
+ aComplexColor = model::ComplexColor();
+ aColor = COL_TRANSPARENT;
+ }
+ ApplyCharBackground(aColor, aComplexColor, rWrtSh);
}
else
- rWrtSh.SetAttrItem(
- SvxColorItem(aSet, RES_CHRATR_COLOR) );
- }
- else if (nSlot == SID_ATTR_CHAR_COLOR_BACKGROUND)
- {
- if (!pApply || pApply->nColor != SID_ATTR_CHAR_COLOR_BACKGROUND_EXT)
- {
- aTempl.nColor = SID_ATTR_CHAR_COLOR_BACKGROUND_EXT;
- rEdtWin.SetApplyTemplate(aTempl);
- }
+ rWrtSh.SetAttrItem(SvxColorItem(aColor, aComplexColor, RES_CHRATR_COLOR));
}
else
{
@@ -1283,14 +1827,14 @@ void SwTextShell::Execute(SfxRequest &rReq)
case FN_NUM_BULLET_MOVEUP:
if (!rWrtSh.IsAddMode())
- rWrtSh.MoveParagraph(-1);
+ rWrtSh.MoveParagraph(SwNodeOffset(-1));
rReq.Done();
break;
case SID_RUBY_DIALOG:
case SID_HYPERLINK_DIALOG:
{
SfxRequest aReq(nSlot, SfxCallMode::SLOT, SfxGetpApp()->GetPool());
- GetView().GetViewFrame()->ExecuteSlot( aReq);
+ GetView().GetViewFrame().ExecuteSlot( aReq);
rReq.Ignore();
}
break;
@@ -1326,7 +1870,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
rWrtSh.EnterBlockMode();
else
rWrtSh.EnterStdMode();
- SfxBindings &rBnd = GetView().GetViewFrame()->GetBindings();
+ SfxBindings &rBnd = GetView().GetViewFrame().GetBindings();
rBnd.Invalidate(FN_STAT_SELMODE);
rBnd.Update(FN_STAT_SELMODE);
}
@@ -1334,22 +1878,76 @@ void SwTextShell::Execute(SfxRequest &rReq)
case SID_OPEN_HYPERLINK:
case SID_COPY_HYPERLINK_LOCATION:
{
- SfxItemSet aSet(GetPool(),
- svl::Items<RES_TXTATR_INETFMT,
- RES_TXTATR_INETFMT>{});
+ SfxItemSetFixed<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT> aSet(GetPool());
rWrtSh.GetCurAttr(aSet);
+
+ const SwFormatINetFormat* pINetFormat = nullptr;
if(SfxItemState::SET <= aSet.GetItemState( RES_TXTATR_INETFMT ))
+ pINetFormat = &aSet.Get(RES_TXTATR_INETFMT);
+ else if (!rWrtSh.HasSelection())
{
- const SwFormatINetFormat& rINetFormat = dynamic_cast<const SwFormatINetFormat&>( aSet.Get(RES_TXTATR_INETFMT) );
- if( nSlot == SID_COPY_HYPERLINK_LOCATION )
+ // is the cursor at the beginning of a hyperlink?
+ const SwTextNode* pTextNd = rWrtSh.GetCursor()->GetPointNode().GetTextNode();
+ if (pTextNd)
{
- OUString hyperlinkLocation = rINetFormat.GetValue();
- ::uno::Reference< datatransfer::clipboard::XClipboard > xClipboard = GetView().GetEditWin().GetClipboard();
+ const sal_Int32 nIndex = rWrtSh.GetCursor()->Start()->GetContentIndex();
+ const SwTextAttr* pINetFmt = pTextNd->GetTextAttrAt(nIndex, RES_TXTATR_INETFMT);
+ if (pINetFmt && !pINetFmt->GetINetFormat().GetValue().isEmpty())
+ pINetFormat = &pINetFmt->GetINetFormat();
+ }
+ }
+ if (pINetFormat)
+ {
+ if (nSlot == SID_OPEN_HYPERLINK)
+ {
+ rWrtSh.ClickToINetAttr(*pINetFormat);
+ }
+ else if (nSlot == SID_COPY_HYPERLINK_LOCATION)
+ {
+ OUString hyperlinkLocation = pINetFormat->GetValue();
+ ::uno::Reference< datatransfer::clipboard::XClipboard > xClipboard = GetView().GetEditWin().GetClipboard();
vcl::unohelper::TextDataObject::CopyStringTo(hyperlinkLocation, xClipboard, SfxViewShell::Current());
}
- else
- rWrtSh.ClickToINetAttr(rINetFormat);
+ }
+ else
+ {
+ SwField* pField = rWrtSh.GetCurField();
+ if (pField && pField->GetTyp()->Which() == SwFieldIds::TableOfAuthorities)
+ {
+ const auto& rAuthorityField = *static_cast<const SwAuthorityField*>(pField);
+ OUString targetURL = "";
+
+ if (auto targetType = rAuthorityField.GetTargetType();
+ targetType == SwAuthorityField::TargetType::UseDisplayURL
+ || targetType == SwAuthorityField::TargetType::UseTargetURL)
+ {
+ // Bibliography entry with URL also provides a hyperlink.
+ targetURL = rAuthorityField.GetAbsoluteURL();
+ }
+
+ if (targetURL.getLength() > 0)
+ {
+ if (nSlot == SID_OPEN_HYPERLINK)
+ {
+ ::LoadURL(rWrtSh, targetURL, LoadUrlFlags::NewView, /*rTargetFrameName=*/OUString());
+ }
+ else if (nSlot == SID_COPY_HYPERLINK_LOCATION)
+ {
+ ::uno::Reference< datatransfer::clipboard::XClipboard > xClipboard = GetView().GetEditWin().GetClipboard();
+ vcl::unohelper::TextDataObject::CopyStringTo(targetURL, xClipboard, SfxViewShell::Current());
+ }
+ }
+ }
+ }
+ }
+ break;
+ case FN_OPEN_LOCAL_URL:
+ {
+ OUString aLocalURL = GetLocalURL(rWrtSh);
+ if (!aLocalURL.isEmpty())
+ {
+ ::LoadURL(rWrtSh, aLocalURL, LoadUrlFlags::NewView, /*rTargetFrameName=*/OUString());
}
}
break;
@@ -1392,56 +1990,104 @@ void SwTextShell::Execute(SfxRequest &rReq)
: DocumentSettingId::PROTECT_BOOKMARKS;
rIDSA.set(aSettingId, !rIDSA.get(aSettingId));
// Invalidate so that toggle state gets updated
- SfxViewFrame* pViewFrame = GetView().GetViewFrame();
- pViewFrame->GetBindings().Invalidate(nSlot);
- pViewFrame->GetBindings().Update(nSlot);
+ SfxViewFrame& rViewFrame = GetView().GetViewFrame();
+ rViewFrame.GetBindings().Invalidate(nSlot);
+ rViewFrame.GetBindings().Update(nSlot);
}
break;
case SID_FM_CTL_PROPERTIES:
{
SwPosition aPos(*GetShell().GetCursor()->GetPoint());
- sw::mark::IFieldmark* pFieldBM = GetShell().getIDocumentMarkAccess()->getFieldmarkFor(aPos);
+ sw::mark::IFieldmark* pFieldBM = GetShell().getIDocumentMarkAccess()->getInnerFieldmarkFor(aPos);
if ( !pFieldBM )
{
- --aPos.nContent;
- pFieldBM = GetShell().getIDocumentMarkAccess()->getFieldmarkFor(aPos);
+ aPos.AdjustContent(-1);
+ pFieldBM = GetShell().getIDocumentMarkAccess()->getInnerFieldmarkFor(aPos);
}
- if ( pFieldBM && pFieldBM->GetFieldname() == ODF_FORMDROPDOWN )
+ if ( pFieldBM && pFieldBM->GetFieldname() == ODF_FORMDROPDOWN
+ && !(rWrtSh.GetCurrSection() && rWrtSh.GetCurrSection()->IsProtect()) )
{
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
- ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateDropDownFormFieldDialog(rWrtSh.GetView().GetFrameWeld(), pFieldBM));
- if (pDlg->Execute() == RET_OK)
- {
- pFieldBM->Invalidate();
- rWrtSh.InvalidateWindows( rWrtSh.GetView().GetVisArea() );
- rWrtSh.UpdateCursor(); // cursor position might be invalid
- // Hide the button here and make it visible later, to make transparent background work with SAL_USE_VCLPLUGIN=gen
- dynamic_cast<::sw::mark::DropDownFieldmark&>(*pFieldBM).HideButton();
- }
+ VclPtr<AbstractDropDownFormFieldDialog> pDlg(pFact->CreateDropDownFormFieldDialog(rWrtSh.GetView().GetFrameWeld(), pFieldBM));
+ auto xRequest = std::make_shared<SfxRequest>(rReq);
+ rReq.Ignore(); // the 'old' request is not relevant any more
+ auto pWrtSh = &rWrtSh;
+ pDlg->StartExecuteAsync(
+ [pDlg, pFieldBM, pWrtSh, xRequest] (sal_Int32 nResult)->void
+ {
+ if (nResult == RET_OK)
+ {
+ pDlg->Apply();
+ pFieldBM->Invalidate();
+ pWrtSh->InvalidateWindows( SwRect(pWrtSh->GetView().GetVisArea()) );
+ pWrtSh->UpdateCursor(); // cursor position might be invalid
+ }
+ pDlg->disposeOnce();
+ xRequest->Done();
+ }
+ );
}
else if ( pFieldBM && pFieldBM->GetFieldname() == ODF_FORMDATE )
{
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
- sw::mark::DateFieldmark& rDateField = dynamic_cast<sw::mark::DateFieldmark&>(*pFieldBM);
- ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateDateFormFieldDialog(rWrtSh.GetView().GetFrameWeld(), &rDateField, *GetView().GetDocShell()->GetDoc()));
- if (pDlg->Execute() == RET_OK)
- {
- rDateField.Invalidate();
- rWrtSh.InvalidateWindows( rWrtSh.GetView().GetVisArea() );
- rWrtSh.UpdateCursor(); // cursor position might be invalid
- // Hide the button here and make it visible later, to make transparent background work with SAL_USE_VCLPLUGIN=gen
- rDateField.HideButton();
- }
+ sw::mark::DateFieldmark* pDateField = &dynamic_cast<sw::mark::DateFieldmark&>(*pFieldBM);
+ VclPtr<AbstractDateFormFieldDialog> pDlg(pFact->CreateDateFormFieldDialog(rWrtSh.GetView().GetFrameWeld(), pDateField, *GetView().GetDocShell()->GetDoc()));
+ auto pWrtSh = &rWrtSh;
+ auto xRequest = std::make_shared<SfxRequest>(rReq);
+ rReq.Ignore(); // the 'old' request is not relevant any more
+ pDlg->StartExecuteAsync(
+ [pDlg, pWrtSh, pDateField, xRequest] (sal_Int32 nResult)->void
+ {
+ if (nResult == RET_OK)
+ {
+ pDlg->Apply();
+ pDateField->Invalidate();
+ pWrtSh->InvalidateWindows( SwRect(pWrtSh->GetView().GetVisArea()) );
+ pWrtSh->UpdateCursor(); // cursor position might be invalid
+ }
+ pDlg->disposeOnce();
+ xRequest->Done();
+ }
+ );
}
else
{
- SfxRequest aReq( GetView().GetViewFrame(), SID_FM_CTL_PROPERTIES );
+ SfxRequest aReq(GetView().GetViewFrame(), SID_FM_CTL_PROPERTIES);
aReq.AppendItem( SfxBoolItem( SID_FM_CTL_PROPERTIES, true ) );
rWrtSh.GetView().GetFormShell()->Execute( aReq );
}
}
break;
+ case SID_FM_TRANSLATE:
+ {
+#if HAVE_FEATURE_CURL && !ENABLE_WASM_STRIP_EXTRA
+ const SfxPoolItem* pTargetLangStringItem = nullptr;
+ if (pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_TARGETLANG_STR, false, &pTargetLangStringItem))
+ {
+ std::optional<OUString> oDeeplAPIUrl = officecfg::Office::Linguistic::Translation::Deepl::ApiURL::get();
+ std::optional<OUString> oDeeplKey = officecfg::Office::Linguistic::Translation::Deepl::AuthKey::get();
+ if (!oDeeplAPIUrl || oDeeplAPIUrl->isEmpty() || !oDeeplKey || oDeeplKey->isEmpty())
+ {
+ SAL_WARN("sw.ui", "SID_FM_TRANSLATE: API options are not set");
+ break;
+ }
+ const OString aAPIUrl = OUStringToOString(rtl::Concat2View(*oDeeplAPIUrl + "?tag_handling=html"), RTL_TEXTENCODING_UTF8).trim();
+ const OString aAuthKey = OUStringToOString(*oDeeplKey, RTL_TEXTENCODING_UTF8).trim();
+ OString aTargetLang = OUStringToOString(static_cast<const SfxStringItem*>(pTargetLangStringItem)->GetValue(), RTL_TEXTENCODING_UTF8);
+ SwTranslateHelper::TranslateAPIConfig aConfig({aAPIUrl, aAuthKey, aTargetLang});
+ SwTranslateHelper::TranslateDocument(rWrtSh, aConfig);
+ }
+ else
+ {
+ SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
+ std::shared_ptr<AbstractSwTranslateLangSelectDlg> pAbstractDialog(pFact->CreateSwTranslateLangSelectDlg(GetView().GetFrameWeld(), rWrtSh));
+ std::shared_ptr<weld::DialogController> pDialogController(pAbstractDialog->getDialogController());
+ weld::DialogController::runAsync(pDialogController, [] (sal_Int32 /*nResult*/) { });
+ }
+#endif // HAVE_FEATURE_CURL && ENABLE_WASM_STRIP_EXTRA
+ }
+ break;
case SID_SPELLCHECK_IGNORE:
{
SwPaM *pPaM = rWrtSh.GetCursor();
@@ -1475,9 +2121,13 @@ void SwTextShell::Execute(SfxRequest &rReq)
SwPaM *pPaM = rWrtSh.GetCursor();
if (pPaM)
SwEditShell::IgnoreGrammarErrorAt( *pPaM );
- // refresh the layout of all paragraphs (workaround to launch a dictionary event)
- xDictionary->setActive(false);
- xDictionary->setActive(true);
+ if (xDictionary.is() && pPaM)
+ {
+ linguistic::AddEntryToDic( xDictionary, pPaM->GetText(), false, OUString() );
+ // refresh the layout of all paragraphs (workaround to launch a dictionary event)
+ xDictionary->setActive(false);
+ xDictionary->setActive(true);
+ }
}
catch( const uno::Exception& )
{
@@ -1487,12 +2137,14 @@ void SwTextShell::Execute(SfxRequest &rReq)
else if (sApplyText == "Spelling")
{
SwRect aToFill;
- uno::Reference< linguistic2::XSpellAlternatives > xSpellAlt( rWrtSh.GetCorrection(nullptr, aToFill) );
+ uno::Reference<linguistic2::XSpellAlternatives> xSpellAlt(rWrtSh.GetCorrection(nullptr, aToFill));
+ if (!xSpellAlt.is())
+ return;
uno::Reference< linguistic2::XDictionary > xDictionary = LinguMgr::GetIgnoreAllList();
OUString sWord(xSpellAlt->getWord());
linguistic::DictionaryError nAddRes = linguistic::AddEntryToDic( xDictionary,
sWord, false, OUString() );
- if (linguistic::DictionaryError::NONE != nAddRes && !xDictionary->getEntry(sWord).is())
+ if (linguistic::DictionaryError::NONE != nAddRes && xDictionary.is() && !xDictionary->getEntry(sWord).is())
{
SvxDicError(rWrtSh.GetView().GetFrameWeld(), nAddRes);
}
@@ -1506,20 +2158,20 @@ void SwTextShell::Execute(SfxRequest &rReq)
if (pItem2)
sApplyText = pItem2->GetValue();
- const OUString sSpellingRule("Spelling_");
- const OUString sGrammarRule("Grammar_");
+ static constexpr OUString sSpellingRule(u"Spelling_"_ustr);
+ static constexpr OUString sGrammarRule(u"Grammar_"_ustr);
bool bGrammar = false;
sal_Int32 nPos = 0;
uno::Reference< linguistic2::XSpellAlternatives > xSpellAlt;
if(-1 != (nPos = sApplyText.indexOf( sGrammarRule )))
{
- sApplyText = sApplyText.replaceAt(nPos, sGrammarRule.getLength(), "");
+ sApplyText = sApplyText.replaceAt(nPos, sGrammarRule.getLength(), u"");
bGrammar = true;
}
else if (-1 != (nPos = sApplyText.indexOf( sSpellingRule )))
{
- sApplyText = sApplyText.replaceAt(nPos, sSpellingRule.getLength(), "");
+ sApplyText = sApplyText.replaceAt(nPos, sSpellingRule.getLength(), u"");
SwRect aToFill;
xSpellAlt.set(rWrtSh.GetCorrection(nullptr, aToFill));
bGrammar = false;
@@ -1545,7 +2197,9 @@ void SwTextShell::Execute(SfxRequest &rReq)
SwRewriter aRewriter;
- aRewriter.AddRule(UndoArg1, rWrtSh.GetCursorDescr());
+ aRewriter.AddRule(UndoArg1, rWrtSh.GetCursorDescr()
+ // don't show the hidden control character of the comment
+ .replaceAll(OUStringChar(CH_TXTATR_INWORD), "") );
aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS));
OUString aTmpStr = SwResId(STR_START_QUOTE) +
@@ -1555,7 +2209,9 @@ void SwTextShell::Execute(SfxRequest &rReq)
rWrtSh.StartUndo(SwUndoId::UI_REPLACE, &aRewriter);
rWrtSh.StartAction();
- rWrtSh.Replace(aTmp, false);
+ // keep comments at the end of the replacement in case spelling correction is
+ // invoked via the context menu. The spell check dialog does the correction in edlingu.cxx.
+ rWrtSh.ReplaceKeepComments(aTmp);
rWrtSh.EndAction();
rWrtSh.EndUndo();
@@ -1576,7 +2232,8 @@ void SwTextShell::GetState( SfxItemSet &rSet )
sal_uInt16 nWhich = aIter.FirstWhich();
while ( nWhich )
{
- switch ( nWhich )
+ const sal_uInt16 nSlotId = GetPool().GetSlotId(nWhich);
+ switch (nSlotId)
{
case FN_FORMAT_CURRENT_FOOTNOTE_DLG:
if( !rSh.IsCursorInFootnote() )
@@ -1615,11 +2272,10 @@ void SwTextShell::GetState( SfxItemSet &rSet )
}
// build sequence for status value
- uno::Sequence< OUString > aSeq( 4 );
- aSeq[0] = aCurrentLang;
- aSeq[1] = aScriptTypesInUse;
- aSeq[2] = aKeyboardLang;
- aSeq[3] = SwLangHelper::GetTextForLanguageGuessing( rSh );
+ uno::Sequence< OUString > aSeq{ aCurrentLang,
+ aScriptTypesInUse,
+ aKeyboardLang,
+ SwLangHelper::GetTextForLanguageGuessing( rSh ) };
// set sequence as status value
SfxStringListItem aItem( SID_LANGUAGE_STATUS );
@@ -1669,7 +2325,6 @@ void SwTextShell::GetState( SfxItemSet &rSet )
case FN_EDIT_FORMULA:
case SID_CHARMAP:
- case SID_EMOJI_CONTROL:
case SID_CHARMAP_CONTROL:
{
const SelectionType nType = rSh.GetSelectionType();
@@ -1693,7 +2348,18 @@ void SwTextShell::GetState( SfxItemSet &rSet )
{
const FrameTypeFlags nNoType =
FrameTypeFlags::FLY_ANY | FrameTypeFlags::HEADER | FrameTypeFlags::FOOTER | FrameTypeFlags::FOOTNOTE;
- if ( rSh.GetFrameType(nullptr,true) & nNoType )
+ FrameTypeFlags eType = rSh.GetFrameType(nullptr, true);
+ bool bSplitFly = false;
+ if (eType & FrameTypeFlags::FLY_ATCNT)
+ {
+ SwContentFrame* pContentFrame = rSh.GetCurrFrame(/*bCalcFrame=*/false);
+ if (pContentFrame)
+ {
+ SwFlyFrame* pFlyFrame = pContentFrame->FindFlyFrame();
+ bSplitFly = pFlyFrame && pFlyFrame->IsFlySplitAllowed();
+ }
+ }
+ if (eType & nNoType && !bSplitFly)
rSet.DisableItem(nWhich);
if ( rSh.CursorInsideInputField() )
@@ -1787,6 +2453,7 @@ void SwTextShell::GetState( SfxItemSet &rSet )
rSet.Put( aColorItem.CloneSetWhich(SID_ATTR_CHAR_COLOR2) );
}
break;
+ case SID_ATTR_CHAR_BACK_COLOR:
case SID_ATTR_CHAR_COLOR_BACKGROUND:
{
// Always use the visible background
@@ -1795,16 +2462,25 @@ void SwTextShell::GetState( SfxItemSet &rSet )
const SvxBrushItem& aBrushItem = aSet.Get(RES_CHRATR_HIGHLIGHT);
if( aBrushItem.GetColor() != COL_TRANSPARENT )
{
- rSet.Put( SvxColorItem(aBrushItem.GetColor(), nWhich) );
+ rSet.Put(SvxColorItem(aBrushItem.GetColor(), aBrushItem.getComplexColor(), nWhich));
}
else
{
const SvxBrushItem& aBrushItem2 = aSet.Get(RES_CHRATR_BACKGROUND);
- rSet.Put( SvxColorItem(aBrushItem2.GetColor(), nWhich) );
+ rSet.Put(SvxColorItem(aBrushItem2.GetColor(), aBrushItem2.getComplexColor(), nWhich));
}
}
break;
case SID_ATTR_CHAR_COLOR_BACKGROUND_EXT:
+ {
+ SwEditWin& rEdtWin = GetView().GetEditWin();
+ SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate();
+ const sal_uInt32 nColWhich = pApply ? pApply->nColor : 0;
+ const bool bUseTemplate = nColWhich == SID_ATTR_CHAR_BACK_COLOR
+ || nColWhich == SID_ATTR_CHAR_COLOR_BACKGROUND;
+ rSet.Put(SfxBoolItem(nWhich, bUseTemplate));
+ }
+ break;
case SID_ATTR_CHAR_COLOR_EXT:
{
SwEditWin& rEdtWin = GetView().GetEditWin();
@@ -1832,7 +2508,7 @@ void SwTextShell::GetState( SfxItemSet &rSet )
case FN_INSERT_BREAK_DLG:
case FN_INSERT_COLUMN_BREAK:
case FN_INSERT_PAGEBREAK:
- if( rSh.CursorInsideInputField() )
+ if( rSh.CursorInsideInputField() || rSh.CursorInsideContentControl() )
{
rSet.DisableItem( nWhich );
}
@@ -1848,8 +2524,8 @@ void SwTextShell::GetState( SfxItemSet &rSet )
OUString aStyleName;
std::vector<OUString> aList;
- const OUString sPhysical("IsPhysical");
- const OUString sDisplay("DisplayName");
+ static constexpr OUStringLiteral sPhysical(u"IsPhysical");
+ static constexpr OUStringLiteral sDisplay(u"DisplayName");
const OUString sHeaderOn(nWhich == FN_INSERT_PAGEHEADER ? OUString("HeaderIsOn") : OUString("FooterIsOn"));
uno::Reference< XStyleFamiliesSupplier > xSupplier(GetView().GetDocShell()->GetBaseModel(), uno::UNO_QUERY);
@@ -1877,7 +2553,7 @@ void SwTextShell::GetState( SfxItemSet &rSet )
}
else
bIsPhysical = false;
- }
+ }
}
}
@@ -1900,21 +2576,39 @@ void SwTextShell::GetState( SfxItemSet &rSet )
case SID_RUBY_DIALOG:
{
- SvtCJKOptions aCJKOptions;
- if( !aCJKOptions.IsRubyEnabled()
+ if( !SvtCJKOptions::IsRubyEnabled()
|| rSh.CursorInsideInputField() )
{
- GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, false );
+ GetView().GetViewFrame().GetBindings().SetVisibleState( nWhich, false );
rSet.DisableItem(nWhich);
}
else
- GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, true );
+ GetView().GetViewFrame().GetBindings().SetVisibleState( nWhich, true );
+ }
+ break;
+
+ case SID_FM_TRANSLATE:
+ {
+#if HAVE_FEATURE_CURL && !ENABLE_WASM_STRIP_EXTRA
+ if (!officecfg::Office::Common::Misc::ExperimentalMode::get()
+ && !comphelper::LibreOfficeKit::isActive())
+ {
+ rSet.Put(SfxVisibilityItem(nWhich, false));
+ break;
+ }
+ std::optional<OUString> oDeeplAPIUrl = officecfg::Office::Linguistic::Translation::Deepl::ApiURL::get();
+ std::optional<OUString> oDeeplKey = officecfg::Office::Linguistic::Translation::Deepl::AuthKey::get();
+ if (!oDeeplAPIUrl || oDeeplAPIUrl->isEmpty() || !oDeeplKey || oDeeplKey->isEmpty())
+ {
+ rSet.DisableItem(nWhich);
+ }
+#endif
}
break;
case SID_HYPERLINK_DIALOG:
if( GetView().GetDocShell()->IsReadOnly()
- || ( !GetView().GetViewFrame()->HasChildWindow(nWhich)
+ || ( !GetView().GetViewFrame().HasChildWindow(nWhich)
&& rSh.HasReadonlySel() )
|| rSh.CursorInsideInputField() )
{
@@ -1922,37 +2616,59 @@ void SwTextShell::GetState( SfxItemSet &rSet )
}
else
{
- rSet.Put(SfxBoolItem( nWhich, nullptr != GetView().GetViewFrame()->GetChildWindow( nWhich ) ));
+ rSet.Put(SfxBoolItem( nWhich, nullptr != GetView().GetViewFrame().GetChildWindow( nWhich ) ));
}
break;
case SID_EDIT_HYPERLINK:
- case SID_COPY_HYPERLINK_LOCATION:
{
- SfxItemSet aSet(GetPool(),
- svl::Items<RES_TXTATR_INETFMT,
- RES_TXTATR_INETFMT>{});
- rSh.GetCurAttr(aSet);
- if(SfxItemState::SET > aSet.GetItemState( RES_TXTATR_INETFMT ) || rSh.HasReadonlySel())
+ if (!rSh.HasReadonlySel())
{
- rSet.DisableItem(nWhich);
+ SfxItemSetFixed<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT> aSet(GetPool());
+ rSh.GetCurAttr(aSet);
+ if (SfxItemState::SET <= aSet.GetItemState(RES_TXTATR_INETFMT))
+ break;
+
+ // is the cursor at the beginning of a hyperlink?
+ const SwTextNode* pTextNd = rSh.GetCursor()->GetPointNode().GetTextNode();
+ if (pTextNd && !rSh.HasSelection())
+ {
+ const sal_Int32 nIndex = rSh.GetCursor()->Start()->GetContentIndex();
+ const SwTextAttr* pINetFmt
+ = pTextNd->GetTextAttrAt(nIndex, RES_TXTATR_INETFMT);
+ if (pINetFmt && !pINetFmt->GetINetFormat().GetValue().isEmpty())
+ break;
+ }
}
+ rSet.DisableItem(nWhich);
}
break;
case SID_REMOVE_HYPERLINK:
{
- SfxItemSet aSet(GetPool(),
- svl::Items<RES_TXTATR_INETFMT,
- RES_TXTATR_INETFMT>{});
- rSh.GetCurAttr(aSet);
-
- // If a hyperlink is selected, either alone or along with other text...
- if ((aSet.GetItemState(RES_TXTATR_INETFMT) < SfxItemState::SET &&
- aSet.GetItemState(RES_TXTATR_INETFMT) != SfxItemState::DONTCARE) ||
- rSh.HasReadonlySel())
+ if (!rSh.HasReadonlySel())
{
- rSet.DisableItem(nWhich);
+ SfxItemSetFixed<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT> aSet(GetPool());
+ rSh.GetCurAttr(aSet);
+
+ // If a hyperlink is selected, either alone or along with other text...
+ if (SfxItemState::SET <= aSet.GetItemState(RES_TXTATR_INETFMT)
+ || aSet.GetItemState(RES_TXTATR_INETFMT) == SfxItemState::INVALID)
+ {
+ break;
+ }
+
+ // is the cursor at the beginning of a hyperlink?
+ const SwTextNode* pTextNd = rSh.GetCursor()->GetPointNode().GetTextNode();
+ if (pTextNd && !rSh.HasSelection())
+ {
+ const sal_Int32 nIndex = rSh.GetCursor()->Start()->GetContentIndex();
+ const SwTextAttr* pINetFmt
+ = pTextNd->GetTextAttrAt(nIndex, RES_TXTATR_INETFMT);
+ if (pINetFmt && !pINetFmt->GetINetFormat().GetValue().isEmpty())
+ break;
+ }
}
+ rSet.DisableItem(nWhich);
}
break;
case SID_TRANSLITERATE_HALFWIDTH:
@@ -1960,14 +2676,13 @@ void SwTextShell::GetState( SfxItemSet &rSet )
case SID_TRANSLITERATE_HIRAGANA:
case SID_TRANSLITERATE_KATAKANA:
{
- SvtCJKOptions aCJKOptions;
- if(!aCJKOptions.IsChangeCaseMapEnabled())
+ if(!SvtCJKOptions::IsChangeCaseMapEnabled())
{
- GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, false );
+ GetView().GetViewFrame().GetBindings().SetVisibleState( nWhich, false );
rSet.DisableItem(nWhich);
}
else
- GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, true );
+ GetView().GetViewFrame().GetBindings().SetVisibleState( nWhich, true );
}
break;
case FN_READONLY_SELECTION_MODE :
@@ -1982,14 +2697,47 @@ void SwTextShell::GetState( SfxItemSet &rSet )
case FN_SELECTION_MODE_BLOCK :
rSet.Put(SfxBoolItem(nWhich, (nWhich == FN_SELECTION_MODE_DEFAULT) != rSh.IsBlockMode()));
break;
- case SID_OPEN_HYPERLINK:
+ case SID_COPY_HYPERLINK_LOCATION:
+ case SID_OPEN_HYPERLINK:
{
- SfxItemSet aSet(GetPool(),
- svl::Items<RES_TXTATR_INETFMT,
- RES_TXTATR_INETFMT>{});
+ SfxItemSetFixed<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT> aSet(GetPool());
rSh.GetCurAttr(aSet);
- if(SfxItemState::SET > aSet.GetItemState( RES_TXTATR_INETFMT, false ))
+ if (SfxItemState::SET <= aSet.GetItemState(RES_TXTATR_INETFMT, false))
+ break;
+
+ // is the cursor at the beginning of a hyperlink?
+ const SwTextNode* pTextNd = rSh.GetCursor()->GetPointNode().GetTextNode();
+ if (pTextNd && !rSh.HasSelection())
+ {
+ const sal_Int32 nIndex = rSh.GetCursor()->Start()->GetContentIndex();
+ const SwTextAttr* pINetFmt = pTextNd->GetTextAttrAt(nIndex, RES_TXTATR_INETFMT);
+ if (pINetFmt && !pINetFmt->GetINetFormat().GetValue().isEmpty())
+ break;
+ }
+
+ SwField* pField = rSh.GetCurField();
+ if (pField && pField->GetTyp()->Which() == SwFieldIds::TableOfAuthorities)
+ {
+ const auto& rAuthorityField = *static_cast<const SwAuthorityField*>(pField);
+ if (auto targetType = rAuthorityField.GetTargetType();
+ targetType == SwAuthorityField::TargetType::UseDisplayURL
+ || targetType == SwAuthorityField::TargetType::UseTargetURL)
+ {
+ // Check if the Bibliography entry has a target URL
+ if (rAuthorityField.GetAbsoluteURL().getLength() > 0)
+ break;
+ }
+ }
+
+ rSet.DisableItem(nWhich);
+ }
+ break;
+ case FN_OPEN_LOCAL_URL:
+ {
+ if (GetLocalURL(rSh).isEmpty())
+ {
rSet.DisableItem(nWhich);
+ }
}
break;
case SID_OPEN_SMARTTAGMENU:
@@ -2011,17 +2759,17 @@ void SwTextShell::GetState( SfxItemSet &rSet )
aActionIndicesSequence );
uno::Reference <frame::XController> xController = GetView().GetController();
- const lang::Locale aLocale( SW_BREAKITER()->GetLocale( GetAppLanguageTag() ) );
+ lang::Locale aLocale( SW_BREAKITER()->GetLocale( GetAppLanguageTag() ) );
const OUString& aApplicationName( rSmartTagMgr.GetApplicationName() );
const OUString aRangeText = xRange->getString();
- const SvxSmartTagItem aItem( nWhich,
+ const SvxSmartTagItem aItem( SID_OPEN_SMARTTAGMENU,
aActionComponentsSequence,
aActionIndicesSequence,
aStringKeyMaps,
xRange,
- xController,
- aLocale,
+ std::move(xController),
+ std::move(aLocale),
aApplicationName,
aRangeText );
@@ -2040,6 +2788,23 @@ void SwTextShell::GetState( SfxItemSet &rSet )
rSet.Put(SfxBoolItem(FN_NUM_BULLET_ON,rSh.SelectionHasBullet()));
break;
+ case FN_NUM_BULLET_OFF:
+ rSet.Put(SfxBoolItem(FN_NUM_BULLET_OFF, !rSh.GetNumRuleAtCurrCursorPos() &&
+ !rSh.GetNumRuleAtCurrentSelection()));
+ break;
+
+ case FN_SVX_SET_OUTLINE:
+ {
+ NBOTypeMgrBase* pOutline = NBOutlineTypeMgrFact::CreateInstance(NBOType::Outline);
+ auto pCurRule = const_cast<SwNumRule*>(rSh.GetNumRuleAtCurrCursorPos());
+ if (pOutline && pCurRule)
+ {
+ SvxNumRule aSvxRule = pCurRule->MakeSvxNumRule();
+ const sal_uInt16 nIndex = pOutline->GetNBOIndexForNumRule(aSvxRule, 0);
+ rSet.Put(SfxBoolItem(FN_SVX_SET_OUTLINE, nIndex < USHRT_MAX));
+ }
+ break;
+ }
case FN_BUL_NUM_RULE_INDEX:
case FN_NUM_NUM_RULE_INDEX:
case FN_OUTLINE_RULE_INDEX:
@@ -2106,9 +2871,8 @@ void SwTextShell::GetState( SfxItemSet &rSet )
case SID_INSERT_RLM :
case SID_INSERT_LRM :
{
- SvtCTLOptions aCTLOptions;
- bool bEnabled = aCTLOptions.IsCTLFontEnabled();
- GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, bEnabled );
+ bool bEnabled = SvtCTLOptions::IsCTLFontEnabled();
+ GetView().GetViewFrame().GetBindings().SetVisibleState( nWhich, bEnabled );
if(!bEnabled)
rSet.DisableItem(nWhich);
}
@@ -2118,7 +2882,7 @@ void SwTextShell::GetState( SfxItemSet &rSet )
bool bDisable = false;
// First get the state from the form shell
- SfxItemSet aSet(GetShell().GetAttrPool(), svl::Items<SID_FM_CTL_PROPERTIES, SID_FM_CTL_PROPERTIES>{});
+ SfxItemSetFixed<SID_FM_CTL_PROPERTIES, SID_FM_CTL_PROPERTIES> aSet(GetShell().GetAttrPool());
aSet.Put(SfxBoolItem( SID_FM_CTL_PROPERTIES, true ));
GetShell().GetView().GetFormShell()->GetState( aSet );
@@ -2129,11 +2893,11 @@ void SwTextShell::GetState( SfxItemSet &rSet )
// Enable it if we have a valid object other than what form shell knows
SwPosition aPos(*GetShell().GetCursor()->GetPoint());
- sw::mark::IFieldmark* pFieldBM = GetShell().getIDocumentMarkAccess()->getFieldmarkFor(aPos);
- if ( !pFieldBM && aPos.nContent.GetIndex() > 0)
+ sw::mark::IFieldmark* pFieldBM = GetShell().getIDocumentMarkAccess()->getInnerFieldmarkFor(aPos);
+ if ( !pFieldBM && aPos.GetContentIndex() > 0)
{
- --aPos.nContent;
- pFieldBM = GetShell().getIDocumentMarkAccess()->getFieldmarkFor(aPos);
+ aPos.AdjustContent(-1);
+ pFieldBM = GetShell().getIDocumentMarkAccess()->getInnerFieldmarkFor(aPos);
}
if ( pFieldBM && (pFieldBM->GetFieldname() == ODF_FORMDROPDOWN || pFieldBM->GetFieldname() == ODF_FORMDATE) )
{
@@ -2161,6 +2925,14 @@ void SwTextShell::GetState( SfxItemSet &rSet )
rSet.Put(SfxBoolItem(nWhich, bProtected));
}
break;
+ case FN_CONTENT_CONTROL_PROPERTIES:
+ {
+ if (!GetShell().CursorInsideContentControl())
+ {
+ rSet.DisableItem(nWhich);
+ }
+ }
+ break;
}
nWhich = aIter.NextWhich();
}