Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / shells / basesh.cxx
blobea695cf8beb4ef978ebd3b40e8007284eecf9724
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 <config_features.h>
21 #include <config_fuzzers.h>
23 #include <sal/config.h>
25 #include <hintids.hxx>
26 #include <comphelper/servicehelper.hxx>
27 #include <svl/languageoptions.hxx>
28 #include <sfx2/linkmgr.hxx>
29 #include <sfx2/htmlmode.hxx>
30 #include <svx/imapdlg.hxx>
31 #include <sfx2/dispatch.hxx>
32 #include <sfx2/viewfrm.hxx>
33 #include <sfx2/request.hxx>
34 #include <svl/whiter.hxx>
35 #include <svl/visitem.hxx>
36 #include <editeng/langitem.hxx>
37 #include <svx/clipfmtitem.hxx>
38 #include <svx/contdlg.hxx>
39 #include <vcl/graph.hxx>
40 #include <vcl/inputctx.hxx>
41 #include <svl/slstitm.hxx>
42 #include <svl/ptitem.hxx>
43 #include <svl/stritem.hxx>
44 #include <editeng/colritem.hxx>
45 #include <editeng/fhgtitem.hxx>
46 #include <editeng/fontitem.hxx>
47 #include <editeng/shaditem.hxx>
48 #include <editeng/boxitem.hxx>
49 #include <editeng/brushitem.hxx>
50 #include <editeng/opaqitem.hxx>
51 #include <editeng/sizeitem.hxx>
52 #include <svx/flagsdef.hxx>
53 #include <editeng/scripttypeitem.hxx>
54 #include <sfx2/objface.hxx>
55 #include <fmturl.hxx>
56 #include <fmthdft.hxx>
57 #include <fmtclds.hxx>
58 #include <docsh.hxx>
59 #include <wrtsh.hxx>
60 #include <view.hxx>
61 #include <swmodule.hxx>
62 #include <swundo.hxx>
63 #include <fldbas.hxx>
64 #include <uitool.hxx>
65 #include <basesh.hxx>
66 #include <viewopt.hxx>
67 #include <fontcfg.hxx>
68 #include <fmtsrnd.hxx>
69 #include <fldmgr.hxx>
70 #include <frmmgr.hxx>
71 #include <tablemgr.hxx>
72 #include <mdiexp.hxx>
73 #include <swdtflvr.hxx>
74 #include <pagedesc.hxx>
75 #include <fmtcol.hxx>
76 #include <edtwin.hxx>
77 #include <tblafmt.hxx>
78 #include <swwait.hxx>
79 #include <cmdid.h>
80 #include <strings.hrc>
81 #include <unotxdoc.hxx>
82 #include <doc.hxx>
83 #include <drawdoc.hxx>
84 #include <IDocumentSettingAccess.hxx>
85 #include <IDocumentDrawModelAccess.hxx>
86 #include <IDocumentUndoRedo.hxx>
87 #include <ThemeColorChanger.hxx>
88 #include <swabstdlg.hxx>
89 #include <modcfg.hxx>
90 #include <svx/fmshell.hxx>
91 #include <SwRewriter.hxx>
92 #include <GraphicSizeCheck.hxx>
93 #include <svx/galleryitem.hxx>
94 #include <svx/theme/ThemeColorPaletteManager.hxx>
95 #include <sfx2/devtools/DevelopmentToolChildWindow.hxx>
96 #include <com/sun/star/gallery/GalleryItemType.hpp>
97 #include <com/sun/star/beans/PropertyValues.hpp>
98 #include <memory>
101 #include <svx/unobrushitemhelper.hxx>
102 #include <svx/dialog/ThemeDialog.hxx>
103 #include <comphelper/scopeguard.hxx>
104 #include <comphelper/lok.hxx>
105 #include <sfx2/lokhelper.hxx>
106 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
107 #include <osl/diagnose.h>
109 #include <svx/svxdlg.hxx>
110 #include <comphelper/sequenceashashmap.hxx>
112 #include <shellres.hxx>
113 #include <UndoTable.hxx>
115 #include <ndtxt.hxx>
116 #include <UndoManager.hxx>
117 #include <fmtrfmrk.hxx>
118 #include <txtrfmrk.hxx>
119 #include <translatehelper.hxx>
121 FlyMode SwBaseShell::s_eFrameMode = FLY_DRAG_END;
123 // These variables keep the state of Gallery (slot SID_GALLERY_BG_BRUSH)
124 // detected by GetGalleryState() for the subsequent ExecuteGallery() call.
126 static sal_uInt8 nParagraphPos;
127 static sal_uInt8 nGraphicPos;
128 static sal_uInt8 nOlePos;
129 static sal_uInt8 nFramePos;
130 static sal_uInt8 nTablePos;
131 static sal_uInt8 nTableRowPos;
132 static sal_uInt8 nTableCellPos;
133 static sal_uInt8 nPagePos;
134 static sal_uInt8 nHeaderPos;
135 static sal_uInt8 nFooterPos;
137 #define ShellClass_SwBaseShell
138 #include <sfx2/msg.hxx>
139 #include <swslots.hxx>
141 #include <AccessibilityCheck.hxx>
143 namespace
145 SvxContourDlg* GetContourDlg(SwView const &rView)
147 SfxChildWindow *pWnd = rView.GetViewFrame().GetChildWindow(SvxContourDlgChildWindow::GetChildWindowId());
148 return pWnd ? static_cast<SvxContourDlg*>(pWnd->GetController().get()) : nullptr;
151 SvxIMapDlg* GetIMapDlg(SwView const &rView)
153 SfxChildWindow* pWnd = rView.GetViewFrame().GetChildWindow(SvxIMapDlgChildWindow::GetChildWindowId());
154 return pWnd ? static_cast<SvxIMapDlg*>(pWnd->GetController().get()) : nullptr;
158 using namespace ::com::sun::star;
159 using namespace ::com::sun::star::uno;
160 using namespace ::com::sun::star::frame;
161 using namespace ::com::sun::star::lang;
163 SFX_IMPL_SUPERCLASS_INTERFACE(SwBaseShell, SfxShell)
165 void SwBaseShell::InitInterface_Impl()
167 GetStaticInterface()->RegisterChildWindow(SvxIMapDlgChildWindow::GetChildWindowId());
168 GetStaticInterface()->RegisterChildWindow(SvxContourDlgChildWindow::GetChildWindowId());
169 GetStaticInterface()->RegisterChildWindow(DevelopmentToolChildWindow::GetChildWindowId());
172 static void lcl_UpdateIMapDlg( SwWrtShell& rSh )
174 Graphic aGrf( rSh.GetIMapGraphic() );
175 GraphicType nGrfType = aGrf.GetType();
176 void* pEditObj = GraphicType::NONE != nGrfType && GraphicType::Default != nGrfType
177 ? rSh.GetIMapInventor() : nullptr;
178 TargetList aList;
179 SfxFrame::GetDefaultTargetList(aList);
181 SfxItemSetFixed<RES_URL, RES_URL> aSet( rSh.GetAttrPool() );
182 rSh.GetFlyFrameAttr( aSet );
183 const SwFormatURL &rURL = aSet.Get( RES_URL );
184 SvxIMapDlgChildWindow::UpdateIMapDlg(
185 aGrf, rURL.GetMap(), &aList, pEditObj );
188 static bool lcl_UpdateContourDlg( SwWrtShell &rSh, SelectionType nSel )
190 Graphic aGraf( rSh.GetIMapGraphic() );
191 GraphicType nGrfType = aGraf.GetType();
192 bool bRet = GraphicType::NONE != nGrfType && GraphicType::Default != nGrfType;
193 if( bRet )
195 OUString aGrfName;
196 if ( nSel & SelectionType::Graphic )
197 rSh.GetGrfNms( &aGrfName, nullptr );
199 SvxContourDlg *pDlg = GetContourDlg(rSh.GetView());
200 if (pDlg)
202 pDlg->Update(aGraf, !aGrfName.isEmpty(),
203 rSh.GetGraphicPolygon(), rSh.GetIMapInventor());
206 return bRet;
209 void SwBaseShell::ExecDelete(SfxRequest &rReq)
211 SwWrtShell &rSh = GetShell();
212 SwEditWin& rTmpEditWin = GetView().GetEditWin();
213 switch(rReq.GetSlot())
215 case SID_DELETE:
216 if (rSh.GetViewOptions()->IsShowOutlineContentVisibilityButton())
218 // Disallow if the cursor is at the end of a paragraph and the document model
219 // node at this position is an outline node with folded content or the next node
220 // is an outline node with folded content.
221 if (rSh.IsEndPara())
223 SwNodeIndex aIdx(rSh.GetCursor()->GetPointNode());
224 if (aIdx.GetNode().IsTextNode())
226 bool bVisible = true;
227 aIdx.GetNode().GetTextNode()->GetAttrOutlineContentVisible(bVisible);
228 if (!bVisible)
229 break;
230 ++aIdx;
231 if (aIdx.GetNode().IsTextNode())
233 bVisible = true;
234 aIdx.GetNode().GetTextNode()->GetAttrOutlineContentVisible(bVisible);
235 if (!bVisible)
236 break;
241 rSh.DelRight();
242 break;
244 case FN_BACKSPACE:
245 if (rSh.GetViewOptions()->IsShowOutlineContentVisibilityButton())
247 // Disallow if the cursor is at the start of a paragraph and the document model
248 // node at this position is an outline node with folded content or the previous
249 // node is a content node without a layout frame.
250 if (rSh.IsSttPara())
252 SwNodeIndex aIdx(rSh.GetCursor()->GetPointNode());
253 if (aIdx.GetNode().IsTextNode())
255 bool bVisible = true;
256 aIdx.GetNode().GetTextNode()->GetAttrOutlineContentVisible(bVisible);
257 if (!bVisible)
258 break;
259 --aIdx;
260 if (aIdx.GetNode().IsContentNode() &&
261 !aIdx.GetNode().GetContentNode()->getLayoutFrame(rSh.GetLayout()))
262 break;
266 if( rSh.IsNoNum() )
268 rSh.SttCursorMove();
269 bool bLeft = rSh.Left( SwCursorSkipMode::Chars, true, 1, false );
270 if( bLeft )
272 rSh.DelLeft();
274 else
275 // JP 15.07.96: If it no longer goes forward, cancel
276 // the numbering. For example at the beginning
277 // of a doc, frame, table or an area.
278 rSh.DelNumRules();
280 rSh.EndCursorMove();
281 break;
284 [[fallthrough]]; // otherwise call DelLeft
285 case FN_SHIFT_BACKSPACE:
286 rSh.DelLeft();
287 break;
288 default:
289 OSL_FAIL("wrong Dispatcher");
290 return;
292 rReq.Done();
294 //#i42732# - notify the edit window that from now on we do not use the input language
295 rTmpEditWin.SetUseInputLanguage( false );
298 void SwBaseShell::ExecClpbrd(SfxRequest &rReq)
300 // Attention: At risk of suicide!
301 // After paste, paste special the shell can be destroy.
303 SwWrtShell &rSh = GetShell();
304 sal_uInt16 nId = rReq.GetSlot();
305 bool bIgnore = false;
306 PasteTableType ePasteTable = PasteTableType::PASTE_DEFAULT;
308 switch( nId )
310 case SID_CUT:
311 case SID_COPY:
312 m_rView.GetEditWin().FlushInBuffer();
313 if ( rSh.HasSelection() )
315 rtl::Reference<SwTransferable> pTransfer = new SwTransferable( rSh );
317 if ( nId == SID_CUT && FlyProtectFlags::NONE == rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent) )
318 pTransfer->Cut();
319 else
321 const bool bLockedView = rSh.IsViewLocked();
322 rSh.LockView( true ); //lock visible section
323 pTransfer->Copy();
324 rSh.LockView( bLockedView );
326 break;
328 return;
330 case FN_PASTE_NESTED_TABLE:
331 case FN_TABLE_PASTE_ROW_BEFORE:
332 case FN_TABLE_PASTE_COL_BEFORE:
333 switch ( nId )
335 case FN_PASTE_NESTED_TABLE:
336 ePasteTable = PasteTableType::PASTE_TABLE;
337 break;
338 case FN_TABLE_PASTE_ROW_BEFORE:
339 ePasteTable = PasteTableType::PASTE_ROW;
340 break;
341 case FN_TABLE_PASTE_COL_BEFORE:
342 ePasteTable = PasteTableType::PASTE_COLUMN;
343 break;
344 default:
347 [[fallthrough]];
348 case SID_PASTE:
350 TransferableDataHelper aDataHelper(
351 TransferableDataHelper::CreateFromSystemClipboard( &rSh.GetView().GetEditWin() ) );
352 if( aDataHelper.GetXTransferable().is()
353 && SwTransferable::IsPaste( rSh, aDataHelper ) )
355 // Temporary variables, because the shell could already be
356 // destroyed after the paste.
357 SwView* pView = &m_rView;
359 RndStdIds nAnchorType = RndStdIds::FLY_AT_PARA;
360 const SfxUInt16Item* pAnchorType = rReq.GetArg<SfxUInt16Item>(FN_PARAM_1);
361 if (pAnchorType)
362 nAnchorType = static_cast<RndStdIds>(pAnchorType->GetValue());
363 bool bIgnoreComments = false;
364 const SfxBoolItem* pIgnoreComments = rReq.GetArg<SfxBoolItem>(FN_PARAM_2);
365 if (pIgnoreComments)
366 bIgnoreComments = pIgnoreComments->GetValue();
367 SwTransferable::Paste(rSh, aDataHelper, nAnchorType, bIgnoreComments, ePasteTable);
369 if( rSh.IsFrameSelected() || rSh.IsObjSelected() )
370 rSh.EnterSelFrameMode();
371 pView->AttrChangedNotify(nullptr);
373 // Fold pasted outlines that have outline content visible attribute false
374 MakeAllOutlineContentTemporarilyVisible a(rSh.GetDoc());
376 else
377 return;
379 break;
381 case SID_CLIPBOARD_FORMAT_ITEMS:
383 const SfxItemSet* pArgs = rReq.GetArgs();
384 const SfxPoolItem* pFormat;
385 if( pArgs && SfxItemState::SET == pArgs->GetItemState( nId, false, &pFormat ) )
387 TransferableDataHelper aDataHelper(
388 TransferableDataHelper::CreateFromSystemClipboard(
389 &rSh.GetView().GetEditWin()) );
390 if( aDataHelper.GetXTransferable().is()
391 /*&& SwTransferable::IsPaste( rSh, aDataHelper )*/ )
393 // Temporary variables, because the shell could already be
394 // destroyed after the paste.
395 SwView* pView = &m_rView;
397 SwTransferable::PasteFormat( rSh, aDataHelper,
398 static_cast<SotClipboardFormatId>(static_cast<const SfxUInt32Item*>(pFormat)->GetValue()) );
400 //Done() has to be called before the shell has been removed
401 rReq.Done();
402 bIgnore = true;
403 if( rSh.IsFrameSelected() || rSh.IsObjSelected())
404 rSh.EnterSelFrameMode();
405 pView->AttrChangedNotify(nullptr);
407 // Fold pasted outlines that have outline content visible attribute false
408 MakeAllOutlineContentTemporarilyVisible a(rSh.GetDoc());
412 break;
414 case SID_PASTE_UNFORMATTED:
416 TransferableDataHelper aDataHelper(
417 TransferableDataHelper::CreateFromSystemClipboard( &rSh.GetView().GetEditWin()) );
418 if( aDataHelper.GetXTransferable().is()
419 && SwTransferable::IsPaste( rSh, aDataHelper ) )
421 // Temporary variables, because the shell could already be
422 // destroyed after the paste.
423 SwView* pView = &m_rView;
424 rReq.Ignore();
425 bIgnore = true;
426 if(SwTransferable::PasteUnformatted( rSh, aDataHelper ))
428 SfxViewFrame& rViewFrame = pView->GetViewFrame();
429 uno::Reference< frame::XDispatchRecorder > xRecorder =
430 rViewFrame.GetBindings().GetRecorder();
431 if(xRecorder.is()) {
432 SfxRequest aReq(rViewFrame, SID_CLIPBOARD_FORMAT_ITEMS);
433 aReq.AppendItem( SfxUInt32Item( SID_CLIPBOARD_FORMAT_ITEMS, static_cast<sal_uInt32>(SotClipboardFormatId::STRING) ) );
434 aReq.Done();
438 if (rSh.IsFrameSelected() || rSh.IsObjSelected())
439 rSh.EnterSelFrameMode();
440 pView->AttrChangedNotify(nullptr);
442 // Fold pasted outlines that have outline content visible attribute false
443 MakeAllOutlineContentTemporarilyVisible a(rSh.GetDoc());
445 else
446 return;
448 break;
450 case SID_PASTE_SPECIAL:
452 std::shared_ptr<TransferableDataHelper> aDataHelper =
453 std::make_shared<TransferableDataHelper>(TransferableDataHelper::CreateFromSystemClipboard( &rSh.GetView().GetEditWin()));
455 if( aDataHelper->GetXTransferable().is()
456 && SwTransferable::IsPaste( rSh, *aDataHelper )
457 && !rSh.CursorInsideInputField() )
459 rReq.Ignore();
460 bIgnore = true;
462 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
463 VclPtr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog( rReq.GetFrameWeld() ));
465 // Prepare the dialog
466 SwTransferable::PrePasteSpecial(rSh, *aDataHelper, pDlg);
467 pDlg->PreGetFormat(*aDataHelper);
470 pDlg->StartExecuteAsync([aDataHelper, pDlg, &rSh, this](sal_Int32 nResult){
471 if (nResult == RET_OK)
473 // Temporary variables, because the shell could already be
474 // destroyed after the paste.
475 SwView* pView = &m_rView;
476 bool bRet = false;
477 SotClipboardFormatId nFormatId = pDlg->GetFormatOnly();
479 if( nFormatId != SotClipboardFormatId::NONE )
480 bRet = SwTransferable::PasteFormat( rSh, *aDataHelper, nFormatId );
482 if (bRet)
484 SfxViewFrame& rViewFrame = pView->GetViewFrame();
485 uno::Reference< frame::XDispatchRecorder > xRecorder =
486 rViewFrame.GetBindings().GetRecorder();
487 if(xRecorder.is()) {
488 SfxRequest aReq(rViewFrame, SID_CLIPBOARD_FORMAT_ITEMS);
489 aReq.AppendItem( SfxUInt32Item( SID_CLIPBOARD_FORMAT_ITEMS, static_cast<sal_uInt32>(nFormatId) ) );
490 aReq.Done();
494 if (rSh.IsFrameSelected() || rSh.IsObjSelected())
495 rSh.EnterSelFrameMode();
496 pView->AttrChangedNotify(nullptr);
498 // Fold pasted outlines that have outline content visible attribute false
499 MakeAllOutlineContentTemporarilyVisible a(rSh.GetDoc());
502 pDlg->disposeOnce();
506 else
507 return;
509 break;
511 default:
512 OSL_FAIL("wrong Dispatcher");
513 return;
515 if(!bIgnore)
516 rReq.Done();
519 // ClipBoard state
521 void SwBaseShell::StateClpbrd(SfxItemSet &rSet)
523 SwWrtShell &rSh = GetShell();
524 SfxWhichIter aIter(rSet);
526 const bool bCopy = rSh.HasSelection();
528 sal_uInt16 nWhich = aIter.FirstWhich();
530 while(nWhich)
532 switch(nWhich)
534 case SID_CUT:
535 if( FlyProtectFlags::NONE != rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent ) )
537 rSet.DisableItem( nWhich );
538 break;
540 [[fallthrough]];
541 case SID_COPY:
542 if( !bCopy || GetObjectShell()->isContentExtractionLocked())
543 rSet.DisableItem( nWhich );
544 break;
546 case FN_PASTE_NESTED_TABLE:
547 case FN_TABLE_PASTE_ROW_BEFORE:
548 case FN_TABLE_PASTE_COL_BEFORE:
549 if( !rSh.IsCursorInTable()
550 || !GetView().IsPasteSpecialAllowed()
551 || rSh.CursorInsideInputField()
552 // disable if not a native Writer table and not a spreadsheet format
553 || !GetView().IsPasteSpreadsheet(rSh.GetTableCopied()) )
555 rSet.DisableItem( nWhich );
557 break;
559 case SID_PASTE:
560 if( !GetView().IsPasteAllowed() )
562 rSet.DisableItem( nWhich );
564 break;
566 case SID_PASTE_SPECIAL:
567 if( !GetView().IsPasteSpecialAllowed()
568 || rSh.CursorInsideInputField() )
570 rSet.DisableItem( nWhich );
572 break;
574 case SID_PASTE_UNFORMATTED:
575 if( !GetView().IsPasteSpecialAllowed() )
577 rSet.DisableItem( nWhich );
579 break;
581 case SID_CLIPBOARD_FORMAT_ITEMS:
583 TransferableDataHelper aDataHelper(
584 TransferableDataHelper::CreateFromSystemClipboard(
585 &rSh.GetView().GetEditWin()) );
587 SvxClipboardFormatItem aFormatItem( SID_CLIPBOARD_FORMAT_ITEMS );
588 SwTransferable::FillClipFormatItem( rSh, aDataHelper, aFormatItem );
589 rSet.Put( aFormatItem );
591 break;
593 nWhich = aIter.NextWhich();
597 // Perform undo
599 void SwBaseShell::ExecUndo(SfxRequest &rReq)
601 MakeAllOutlineContentTemporarilyVisible a(GetShell().GetDoc(), true);
603 SwWrtShell &rWrtShell = GetShell();
605 SwUndoId nUndoId(SwUndoId::EMPTY);
606 sal_uInt16 nId = rReq.GetSlot(), nCnt = 1;
607 const SfxItemSet* pArgs = rReq.GetArgs();
608 const SfxPoolItem* pItem;
609 if( pArgs && SfxItemState::SET == pArgs->GetItemState( nId, false, &pItem ))
610 nCnt = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
612 // Repair mode: allow undo/redo of all undo actions, even if access would
613 // be limited based on the view shell ID.
614 bool bRepair = false;
615 const SfxBoolItem* pRepairItem;
616 if (pArgs && (pRepairItem = pArgs->GetItemIfSet(SID_REPAIRPACKAGE, false)))
617 bRepair = pRepairItem->GetValue();
619 // #i106349#: save pointer: undo/redo may delete the shell, i.e., this!
620 SfxViewFrame& rViewFrame( GetView().GetViewFrame() );
622 IDocumentUndoRedo& rUndoRedo = rWrtShell.GetIDocumentUndoRedo();
623 bool bWasRepair = rUndoRedo.DoesRepair();
624 rUndoRedo.DoRepair(bRepair);
625 comphelper::ScopeGuard aGuard([&rUndoRedo, bWasRepair]()
627 rUndoRedo.DoRepair(bWasRepair);
630 switch( nId )
632 case SID_UNDO:
633 if (rUndoRedo.GetLastUndoInfo(nullptr, &nUndoId, &rWrtShell.GetView()))
635 for (SwViewShell& rShell : rWrtShell.GetRingContainer())
636 rShell.LockPaint(LockPaintReason::Undo);
638 sal_uInt16 nUndoOffset = 0;
639 if (comphelper::LibreOfficeKit::isActive() && !bRepair && nCnt == 1)
641 sw::UndoManager& rManager = rWrtShell.GetDoc()->GetUndoManager();
642 const SfxUndoAction* pAction = rManager.GetUndoAction();
643 SwView& rView = rWrtShell.GetView();
644 ViewShellId nViewShellId = rView.GetViewShellId();
645 sal_uInt16 nOffset = 0;
646 if (pAction->GetViewShellId() != nViewShellId
647 && rManager.IsViewUndoActionIndependent(&rView, nOffset))
649 // Execute the undo with an offset: don't undo the top action, but an
650 // earlier one, since it's independent and that belongs to our view.
651 nUndoOffset += nOffset;
655 rWrtShell.Do(SwWrtShell::UNDO, nCnt, nUndoOffset);
657 for (SwViewShell& rShell : rWrtShell.GetRingContainer())
658 rShell.UnlockPaint();
660 // tdf#141613 FIXME: Disable redoing header/footer changes for now.
661 // The proper solution would be to write a SwUndoHeaderFooter class
662 // to represent the addition of a header or footer to the current page.
663 if (nUndoId == SwUndoId::HEADER_FOOTER)
664 rUndoRedo.ClearRedo();
666 break;
668 case SID_REDO:
669 if (rUndoRedo.GetFirstRedoInfo(nullptr, &nUndoId, &rWrtShell.GetView()))
671 for (SwViewShell& rShell : rWrtShell.GetRingContainer())
672 rShell.LockPaint(LockPaintReason::Redo);
673 rWrtShell.Do( SwWrtShell::REDO, nCnt );
674 for (SwViewShell& rShell : rWrtShell.GetRingContainer())
675 rShell.UnlockPaint();
677 break;
679 case SID_REPEAT:
680 rWrtShell.Do( SwWrtShell::REPEAT );
681 break;
682 default:
683 OSL_FAIL("wrong Dispatcher");
686 if (nUndoId == SwUndoId::CONFLICT)
688 rReq.SetReturnValue( SfxUInt32Item(nId, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
690 else if (nUndoId == SwUndoId::INSFMTATTR)
692 rWrtShell.GetDoc()->GetDocShell()->GetStyleSheetPool()->Broadcast(SfxHint(SfxHintId::StyleSheetModified));
695 rViewFrame.GetBindings().InvalidateAll(false);
698 // State of undo
700 void SwBaseShell::StateUndo(SfxItemSet &rSet)
702 SwUndoId nUndoId(SwUndoId::EMPTY);
703 SwWrtShell &rSh = GetShell();
704 SfxWhichIter aIter(rSet);
705 sal_uInt16 nWhich = aIter.FirstWhich();
706 while(nWhich)
708 switch(nWhich)
710 case SID_UNDO:
712 if (rSh.GetLastUndoInfo(nullptr, &nUndoId, &rSh.GetView()))
714 rSet.Put( SfxStringItem(nWhich,
715 rSh.GetDoString(SwWrtShell::UNDO)));
717 else if (nUndoId == SwUndoId::CONFLICT)
719 rSet.Put( SfxUInt32Item(nWhich, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
721 else
722 rSet.DisableItem(nWhich);
724 break;
726 case SID_REDO:
728 if (rSh.GetFirstRedoInfo(nullptr, &nUndoId, &rSh.GetView()))
730 rSet.Put(SfxStringItem(nWhich,
731 rSh.GetDoString(SwWrtShell::REDO)));
733 else if (nUndoId == SwUndoId::CONFLICT)
735 rSet.Put( SfxInt32Item(nWhich, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
737 else
738 rSet.DisableItem(nWhich);
739 break;
741 case SID_REPEAT:
742 { // Repeat is only possible if no REDO is possible - UI-Restriction
743 if ((!rSh.GetFirstRedoInfo(nullptr, nullptr)) &&
744 !rSh.IsSelFrameMode() &&
745 (SwUndoId::EMPTY != rSh.GetRepeatInfo(nullptr)))
747 rSet.Put(SfxStringItem(nWhich, rSh.GetRepeatString()));
749 else
750 rSet.DisableItem(nWhich);
751 break;
754 case SID_GETUNDOSTRINGS:
755 if (rSh.GetLastUndoInfo(nullptr, nullptr))
757 SfxStringListItem aStrLst( nWhich );
758 rSh.GetDoStrings( SwWrtShell::UNDO, aStrLst );
759 rSet.Put( aStrLst );
761 else
762 rSet.DisableItem( nWhich );
763 break;
765 case SID_GETREDOSTRINGS:
766 if (rSh.GetFirstRedoInfo(nullptr, nullptr))
768 SfxStringListItem aStrLst( nWhich );
769 rSh.GetDoStrings( SwWrtShell::REDO, aStrLst );
770 rSet.Put( aStrLst );
772 else
773 rSet.DisableItem( nWhich );
774 break;
776 nWhich = aIter.NextWhich();
780 namespace
782 /// Searches for the specified field type and field name prefix and update the matching fields to
783 /// have the provided new name and content.
784 bool UpdateFieldContents(SfxRequest& rReq, SwWrtShell& rWrtSh)
786 const SfxStringItem* pTypeName = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
787 if (!pTypeName || pTypeName->GetValue() != "SetRef")
789 // This is implemented so far only for reference marks.
790 return false;
793 const SfxStringItem* pNamePrefix = rReq.GetArg<SfxStringItem>(FN_PARAM_2);
794 if (!pNamePrefix)
796 return false;
798 const OUString& rNamePrefix = pNamePrefix->GetValue();
800 const SfxUnoAnyItem* pFields = rReq.GetArg<SfxUnoAnyItem>(FN_PARAM_3);
801 if (!pFields)
803 return false;
805 uno::Sequence<beans::PropertyValues> aFields;
806 pFields->GetValue() >>= aFields;
808 SwDoc* pDoc = rWrtSh.GetDoc();
809 pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::UPDATE_FIELDS, nullptr);
810 rWrtSh.StartAction();
812 std::vector<const SwFormatRefMark*> aRefMarks;
814 for (sal_uInt16 i = 0; i < pDoc->GetRefMarks(); ++i)
816 aRefMarks.push_back(pDoc->GetRefMark(i));
819 std::sort(aRefMarks.begin(), aRefMarks.end(),
820 [](const SwFormatRefMark* pMark1, const SwFormatRefMark* pMark2) -> bool {
821 const SwTextRefMark* pTextRefMark1 = pMark1->GetTextRefMark();
822 const SwTextRefMark* pTextRefMark2 = pMark2->GetTextRefMark();
823 SwPosition aPos1(pTextRefMark1->GetTextNode(), pTextRefMark1->GetStart());
824 SwPosition aPos2(pTextRefMark2->GetTextNode(), pTextRefMark2->GetStart());
825 return aPos1 < aPos2;
828 sal_uInt16 nFieldIndex = 0;
829 for (auto& pIntermediateRefMark : aRefMarks)
831 auto pRefMark = const_cast<SwFormatRefMark*>(pIntermediateRefMark);
832 if (!pRefMark->GetRefName().startsWith(rNamePrefix))
834 continue;
837 if (nFieldIndex >= aFields.getLength())
839 break;
841 comphelper::SequenceAsHashMap aMap(aFields[nFieldIndex++]);
842 auto aName = aMap["Name"].get<OUString>();
843 pRefMark->GetRefName() = aName;
845 OUString aContent = aMap["Content"].get<OUString>();
846 auto pTextRefMark = const_cast<SwTextRefMark*>(pRefMark->GetTextRefMark());
847 pTextRefMark->UpdateFieldContent(pDoc, rWrtSh, aContent);
850 rWrtSh.EndAction();
851 pDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::UPDATE_FIELDS, nullptr);
852 return true;
855 /// Searches for the specified field type and field name prefix under cursor and update the matching
856 /// field to have the provided new name and content.
857 void UpdateFieldContent(SfxRequest& rReq, SwWrtShell& rWrtSh)
859 const SfxStringItem* pTypeName = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
860 if (!pTypeName || pTypeName->GetValue() != "SetRef")
862 // This is implemented so far only for reference marks.
863 return;
866 const SfxStringItem* pNamePrefix = rReq.GetArg<SfxStringItem>(FN_PARAM_2);
867 if (!pNamePrefix)
869 return;
871 const OUString& rNamePrefix = pNamePrefix->GetValue();
873 const SfxUnoAnyItem* pField = rReq.GetArg<SfxUnoAnyItem>(FN_PARAM_3);
874 if (!pField)
876 return;
878 uno::Sequence<beans::PropertyValue> aField;
879 pField->GetValue() >>= aField;
881 SwPosition& rCursor = *rWrtSh.GetCursor()->GetPoint();
882 SwTextNode* pTextNode = rCursor.GetNode().GetTextNode();
883 std::vector<SwTextAttr*> aAttrs
884 = pTextNode->GetTextAttrsAt(rCursor.GetContentIndex(), RES_TXTATR_REFMARK);
885 if (aAttrs.empty())
887 return;
890 auto& rRefmark = const_cast<SwFormatRefMark&>(aAttrs[0]->GetRefMark());
891 if (!rRefmark.GetRefName().startsWith(rNamePrefix))
893 return;
896 SwDoc* pDoc = rWrtSh.GetDoc();
897 SwRewriter aRewriter;
898 aRewriter.AddRule(UndoArg1, rRefmark.GetRefName());
899 pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::UPDATE_FIELD, &aRewriter);
900 rWrtSh.StartAction();
901 comphelper::ScopeGuard g(
902 [&rWrtSh, &aRewriter]
904 rWrtSh.EndAction();
905 rWrtSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::UPDATE_FIELD, &aRewriter);
908 comphelper::SequenceAsHashMap aMap(aField);
909 auto aName = aMap["Name"].get<OUString>();
910 rRefmark.GetRefName() = aName;
912 OUString aContent = aMap["Content"].get<OUString>();
913 auto pTextRefMark = const_cast<SwTextRefMark*>(rRefmark.GetTextRefMark());
914 pTextRefMark->UpdateFieldContent(pDoc, rWrtSh, aContent);
918 // Evaluate respectively dispatching the slot Id
920 void SwBaseShell::Execute(SfxRequest &rReq)
922 const SfxPoolItem *pItem;
923 SwWrtShell &rSh = GetShell();
924 const SfxItemSet* pArgs = rReq.GetArgs();
925 bool bMore = false;
927 sal_uInt16 nSlot = rReq.GetSlot();
928 switch(nSlot)
930 case FN_REPAGINATE:
932 Reference < XModel > xModel = GetView().GetDocShell()->GetModel();
933 auto pDoc = comphelper::getFromUnoTunnel<SwXTextDocument>(xModel);
934 pDoc->NotifyRefreshListeners();
935 rSh.CalcLayout();
937 break;
938 case FN_UPDATE_FIELDS:
940 if (UpdateFieldContents(rReq, rSh))
942 // Parameters indicated that the name / content of fields has to be updated to
943 // the provided values, don't do an actual fields update.
944 break;
947 rSh.UpdateDocStat();
948 rSh.EndAllTableBoxEdit();
949 rSh.SwViewShell::UpdateFields(true);
951 if( rSh.IsCursorInTable() )
953 if( !rSh.IsTableComplexForChart() )
954 SwTableFUNC( &rSh ).UpdateChart();
955 rSh.ClearTableBoxContent();
956 rSh.SaveTableBoxContent();
959 break;
960 case FN_UPDATE_FIELD:
962 UpdateFieldContent(rReq, rSh);
964 break;
965 case FN_UPDATE_CHARTS:
967 SwWait aWait( *m_rView.GetDocShell(), true );
968 rSh.UpdateAllCharts();
970 break;
972 case FN_UPDATE_ALL:
974 comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer
975 = GetObjectShell()->getEmbeddedObjectContainer();
976 rEmbeddedObjectContainer.setUserAllowsLinkUpdate(true);
978 SwView& rTempView = GetView();
979 rSh.EnterStdMode();
980 if( !rSh.GetLinkManager().GetLinks().empty() )
982 rSh.StartAllAction();
983 rSh.GetLinkManager().UpdateAllLinks( false, true, nullptr );
984 rSh.EndAllAction();
986 SfxDispatcher &rDis = *rTempView.GetViewFrame().GetDispatcher();
987 rDis.Execute( FN_UPDATE_FIELDS );
988 rDis.Execute( FN_UPDATE_TOX );
989 rDis.Execute( FN_UPDATE_CHARTS );
990 rSh.Reformat();
991 rSh.UpdateOleObjectPreviews();
993 break;
995 case FN_UPDATE_INPUTFIELDS:
996 rSh.UpdateInputFields();
997 break;
999 case FN_PREV_BOOKMARK:
1000 rReq.SetReturnValue(SfxBoolItem( nSlot, rSh.GoPrevBookmark()));
1001 break;
1002 case FN_NEXT_BOOKMARK:
1003 rReq.SetReturnValue(SfxBoolItem( nSlot, rSh.GoNextBookmark()));
1004 break;
1006 case FN_GOTO_NEXT_MARK:
1007 case FN_GOTO_PREV_MARK:
1009 SwFieldMgr aFieldMgr;
1010 SwFieldType* pFieldType = aFieldMgr.GetFieldType(SwFieldIds::JumpEdit);
1012 if (pFieldType)
1014 if (rSh.IsSelFrameMode())
1016 rSh.UnSelectFrame();
1017 rSh.LeaveSelFrameMode();
1020 if (rSh.HasMark())
1022 SwMvContext aMvContext(&rSh);
1023 if (rSh.IsCursorPtAtEnd())
1024 rSh.SwapPam();
1025 rSh.ClearMark();
1026 rSh.EndSelect();
1028 bool bRet = rSh.MoveFieldType( pFieldType, nSlot == FN_GOTO_NEXT_MARK );
1029 SwField* pCurField = bRet ? rSh.GetCurField() : nullptr;
1030 if (pCurField)
1031 rSh.ClickToField(*pCurField, /*bExecHyperlinks=*/false);
1032 rReq.SetReturnValue(SfxBoolItem( nSlot, bRet));
1035 break;
1037 case FN_START_DOC_DIRECT:
1038 case FN_END_DOC_DIRECT:
1040 if (rSh.IsSelFrameMode())
1042 rSh.UnSelectFrame();
1043 rSh.LeaveSelFrameMode();
1045 rSh.EnterStdMode();
1046 nSlot == FN_START_DOC_DIRECT ?
1047 rSh.SttEndDoc(true) :
1048 rSh.SttEndDoc(false);
1050 break;
1051 case FN_GOTO_PREV_OBJ:
1052 case FN_GOTO_NEXT_OBJ:
1054 bool bSuccess = rSh.GotoObj( nSlot == FN_GOTO_NEXT_OBJ );
1055 rReq.SetReturnValue(SfxBoolItem(nSlot, bSuccess));
1056 if (bSuccess && !rSh.IsSelFrameMode())
1058 rSh.HideCursor();
1059 rSh.EnterSelFrameMode();
1060 GetView().AttrChangedNotify(nullptr);
1063 break;
1064 case SID_GALLERY_FORMATS:
1066 const SvxGalleryItem* pGalleryItem = SfxItemSet::GetItem<SvxGalleryItem>(pArgs, SID_GALLERY_FORMATS, false);
1067 if ( !pGalleryItem )
1068 break;
1070 const SelectionType nSelType = rSh.GetSelectionType();
1071 sal_Int8 nGalleryItemType( pGalleryItem->GetType() );
1073 if ( (!rSh.IsSelFrameMode() || nSelType & SelectionType::Graphic) &&
1074 nGalleryItemType == css::gallery::GalleryItemType::GRAPHIC )
1076 SwWait aWait( *m_rView.GetDocShell(), true );
1078 OUString aGrfName, aFltName;
1079 const Graphic aGrf( pGalleryItem->GetGraphic() );
1081 if ( nSelType & SelectionType::Graphic )
1082 rSh.ReRead( aGrfName, aFltName, &aGrf );
1083 else
1084 rSh.InsertGraphic( aGrfName, aFltName, aGrf );
1086 GetView().GetEditWin().GrabFocus();
1088 else if(!rSh.IsSelFrameMode() &&
1089 nGalleryItemType == css::gallery::GalleryItemType::MEDIA )
1091 const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, pGalleryItem->GetURL() );
1092 GetView().GetViewFrame().GetDispatcher()->ExecuteList(
1093 SID_INSERT_AVMEDIA, SfxCallMode::SYNCHRON,
1094 { &aMediaURLItem });
1097 break;
1098 case FN_PAGE_STYLE_SET_COLS:
1100 if (pArgs)
1102 // Determine the current PageDescriptor and fill the set with that.
1103 const size_t nCurIdx = rSh.GetCurPageDesc();
1104 SwPageDesc aPageDesc(rSh.GetPageDesc(nCurIdx));
1106 SwFrameFormat &rFormat = aPageDesc.GetMaster();
1108 SwFormatCol aFormatCol = rFormat.GetCol();
1110 sal_uInt16 nCount;
1111 if(SfxItemState::SET == pArgs->GetItemState(nSlot))
1112 nCount = static_cast<const SfxUInt16Item &>(pArgs->Get(nSlot)).GetValue();
1113 else
1114 nCount = pArgs->Get(SID_ATTR_COLUMNS).GetValue();
1115 sal_uInt16 nGutterWidth = DEF_GUTTER_WIDTH;
1117 aFormatCol.Init(nCount ? nCount : 1, nGutterWidth, USHRT_MAX);
1118 aFormatCol.SetWishWidth(USHRT_MAX);
1119 aFormatCol.SetGutterWidth(nGutterWidth, USHRT_MAX);
1121 rFormat.SetFormatAttr(aFormatCol);
1123 rSh.ChgPageDesc(nCurIdx, aPageDesc);
1125 else
1126 GetView().GetViewFrame().GetDispatcher()->Execute(FN_FORMAT_PAGE_COLUMN_DLG);
1128 break;
1129 case FN_CONVERT_TABLE_TO_TEXT:
1130 case FN_CONVERT_TEXT_TO_TABLE:
1131 case FN_CONVERT_TEXT_TABLE:
1133 sal_Unicode cDelim = 0;
1134 bool bToTable = false;
1135 if( nSlot == FN_CONVERT_TEXT_TO_TABLE ||
1136 ( nSlot == FN_CONVERT_TEXT_TABLE && nullptr == rSh.GetTableFormat() ))
1137 bToTable = true;
1138 SwInsertTableOptions aInsTableOpts( SwInsertTableFlags::All, 1 );
1139 SwTableAutoFormat const* pTAFormat = nullptr;
1140 std::unique_ptr<SwTableAutoFormatTable> pAutoFormatTable;
1141 bool bDeleteFormat = true;
1142 if(pArgs && SfxItemState::SET == pArgs->GetItemState( FN_PARAM_1, true, &pItem))
1144 aInsTableOpts.mnInsMode = SwInsertTableFlags::NONE;
1145 // Delimiter
1146 OUString sDelim = static_cast< const SfxStringItem* >(pItem)->GetValue();
1147 if(!sDelim.isEmpty())
1148 cDelim = sDelim[0];
1149 // AutoFormat
1150 if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_2, true, &pItem))
1152 OUString sAutoFormat = static_cast< const SfxStringItem* >(pItem)->GetValue();
1154 pAutoFormatTable.reset(new SwTableAutoFormatTable);
1155 pAutoFormatTable->Load();
1157 for( sal_uInt16 i = 0, nCount = pAutoFormatTable->size(); i < nCount; i++ )
1159 SwTableAutoFormat const*const pFormat = &(*pAutoFormatTable)[ i ];
1160 if( pFormat->GetName() == sAutoFormat )
1162 pTAFormat = pFormat;
1163 bDeleteFormat = false;
1164 break;
1168 //WithHeader
1169 if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_3, true, &pItem) &&
1170 static_cast< const SfxBoolItem* >(pItem)->GetValue())
1171 aInsTableOpts.mnInsMode |= SwInsertTableFlags::Headline;
1172 // RepeatHeaderLines
1173 if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_4, true, &pItem))
1174 aInsTableOpts.mnRowsToRepeat =
1175 o3tl::narrowing<sal_uInt16>(static_cast< const SfxInt16Item* >(pItem)->GetValue());
1176 //WithBorder
1177 if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_5, true, &pItem) &&
1178 static_cast< const SfxBoolItem* >(pItem)->GetValue())
1179 aInsTableOpts.mnInsMode |= SwInsertTableFlags::DefaultBorder;
1180 //DontSplitTable
1181 if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_6, true, &pItem) &&
1182 !static_cast< const SfxBoolItem* >(pItem)->GetValue() )
1183 aInsTableOpts.mnInsMode |= SwInsertTableFlags::SplitLayout;
1185 else
1187 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
1188 ScopedVclPtr<AbstractSwConvertTableDlg> pDlg(pFact->CreateSwConvertTableDlg(GetView(), bToTable));
1189 if( RET_OK == pDlg->Execute() )
1191 pDlg->GetValues( cDelim, aInsTableOpts, pTAFormat );
1196 if( cDelim )
1198 //Shell change!
1199 SwView& rSaveView = m_rView;
1200 bool bInserted = false;
1201 //recording:
1202 SfxViewFrame& rViewFrame = GetView().GetViewFrame();
1203 if (SfxRequest::HasMacroRecorder(rViewFrame))
1205 SfxRequest aReq(rViewFrame, nSlot);
1206 aReq.AppendItem( SfxStringItem( FN_PARAM_1, OUString(cDelim) ));
1207 if(bToTable)
1209 if(pTAFormat)
1210 aReq.AppendItem( SfxStringItem( FN_PARAM_2, pTAFormat->GetName()));
1211 aReq.AppendItem( SfxBoolItem ( FN_PARAM_3, bool(aInsTableOpts.mnInsMode & SwInsertTableFlags::Headline)));
1212 aReq.AppendItem( SfxInt16Item( FN_PARAM_4, static_cast<short>(aInsTableOpts.mnRowsToRepeat) ));
1213 aReq.AppendItem( SfxBoolItem ( FN_PARAM_5, bool(aInsTableOpts.mnInsMode & SwInsertTableFlags::DefaultBorder) ));
1214 aReq.AppendItem( SfxBoolItem ( FN_PARAM_6, !(aInsTableOpts.mnInsMode & SwInsertTableFlags::SplitLayout)));
1216 aReq.Done();
1219 if( !bToTable )
1220 rSh.TableToText( cDelim );
1221 else
1223 bInserted = rSh.TextToTable( aInsTableOpts, cDelim, pTAFormat );
1225 rSh.EnterStdMode();
1227 if( bInserted )
1228 rSaveView.AutoCaption( TABLE_CAP );
1230 if(bDeleteFormat)
1231 delete pTAFormat;
1233 break;
1234 case SID_STYLE_WATERCAN:
1235 case SID_STYLE_UPDATE_BY_EXAMPLE:
1236 case SID_STYLE_NEW_BY_EXAMPLE:
1237 case SID_STYLE_APPLY:
1239 ShellMode eMode = GetView().GetShellMode();
1240 if ( ShellMode::Draw != eMode &&
1241 ShellMode::DrawForm != eMode &&
1242 ShellMode::DrawText != eMode &&
1243 ShellMode::Bezier != eMode )
1245 // oj #107754#
1246 if ( SID_STYLE_WATERCAN == nSlot )
1248 const bool bLockedView = rSh.IsViewLocked();
1249 rSh.LockView( true ); //lock visible section
1251 GetView().GetDocShell()->ExecStyleSheet(rReq);
1253 rSh.LockView( bLockedView );
1255 else
1256 // Will be recorded from the DocShell
1257 GetView().GetDocShell()->ExecStyleSheet(rReq);
1260 break;
1261 case SID_CLASSIFICATION_APPLY:
1263 GetView().GetDocShell()->Execute(rReq);
1265 break;
1266 case SID_CLASSIFICATION_DIALOG:
1268 GetView().GetDocShell()->Execute(rReq);
1270 break;
1271 case SID_PARAGRAPH_SIGN_CLASSIFY_DLG:
1273 GetView().GetDocShell()->Execute(rReq);
1275 break;
1276 case SID_WATERMARK:
1278 GetView().GetDocShell()->Execute(rReq);
1280 break;
1281 case FN_ESCAPE:
1282 GetView().ExecuteSlot(rReq);
1283 break;
1284 case SID_IMAP:
1286 sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
1288 SfxViewFrame& rVFrame = GetView().GetViewFrame();
1289 rVFrame.ToggleChildWindow( nId );
1290 rVFrame.GetBindings().Invalidate( SID_IMAP );
1292 if ( rVFrame.HasChildWindow( nId ) && rSh.IsFrameSelected() )
1293 lcl_UpdateIMapDlg( rSh );
1295 break;
1296 case SID_IMAP_EXEC:
1298 SvxIMapDlg* pDlg = GetIMapDlg(GetView());
1300 // Check, if the allocation is useful or allowed at all.
1301 if ( rSh.IsFrameSelected() &&
1302 pDlg->GetEditingObject() == rSh.GetIMapInventor() )
1304 SfxItemSetFixed<RES_URL, RES_URL> aSet( rSh.GetAttrPool() );
1305 rSh.GetFlyFrameAttr( aSet );
1306 SwFormatURL aURL( aSet.Get( RES_URL ) );
1307 aURL.SetMap( &pDlg->GetImageMap() );
1308 aSet.Put( aURL );
1309 rSh.SetFlyFrameAttr( aSet );
1312 break;
1313 case FN_SET_TRACKED_CHANGES_IN_TEXT:
1314 case FN_SET_TRACKED_DELETIONS_IN_MARGIN:
1315 case FN_SET_TRACKED_INSERTIONS_IN_MARGIN:
1317 SwViewOption aViewOption = *rSh.GetViewOptions();
1318 bool bAllInText = FN_SET_TRACKED_CHANGES_IN_TEXT == nSlot;
1319 aViewOption.SetShowChangesInMargin( !bAllInText );
1320 if ( !bAllInText )
1321 aViewOption.SetShowChangesInMargin2( FN_SET_TRACKED_INSERTIONS_IN_MARGIN == nSlot );
1322 rSh.ApplyViewOptions( aViewOption );
1324 // tdf#140982 restore annotation ranges stored in temporary bookmarks
1325 // (only remove temporary bookmarks during file saving to avoid possible
1326 // conflict with lazy deletion of the bookmarks of the moved tracked deletions)
1327 if ( bAllInText || FN_SET_TRACKED_INSERTIONS_IN_MARGIN == nSlot )
1328 rSh.GetDoc()->getIDocumentMarkAccess()->restoreAnnotationMarks(false);
1330 break;
1331 case SID_CONTOUR_DLG:
1333 sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
1335 SfxViewFrame& rVFrame = GetView().GetViewFrame();
1336 rVFrame.ToggleChildWindow( nId );
1337 rVFrame.GetBindings().Invalidate( SID_CONTOUR_DLG );
1339 SelectionType nSel = rSh.GetSelectionType();
1340 if ( rVFrame.HasChildWindow( nId ) &&
1341 (nSel & (SelectionType::Graphic|SelectionType::Ole)) )
1343 lcl_UpdateContourDlg( rSh, nSel );
1346 break;
1347 case SID_CONTOUR_EXEC:
1349 SvxContourDlg *pDlg = GetContourDlg(GetView());
1350 // Check, if the allocation is useful or allowed at all.
1351 SelectionType nSel = rSh.GetSelectionType();
1352 if ( nSel & (SelectionType::Graphic|SelectionType::Ole) )
1354 if (pDlg && pDlg->GetEditingObject() == rSh.GetIMapInventor())
1356 rSh.StartAction();
1357 SfxItemSetFixed<RES_SURROUND, RES_SURROUND> aSet( rSh.GetAttrPool() );
1358 rSh.GetFlyFrameAttr( aSet );
1359 SwFormatSurround aSur( aSet.Get( RES_SURROUND ) );
1360 if ( !aSur.IsContour() )
1362 aSur.SetContour( true );
1363 if ( aSur.GetSurround() == css::text::WrapTextMode_NONE )
1364 aSur.SetSurround( css::text::WrapTextMode_PARALLEL );
1365 aSet.Put( aSur );
1366 rSh.SetFlyFrameAttr( aSet );
1368 const tools::PolyPolygon aPoly( pDlg->GetPolyPolygon() );
1369 rSh.SetGraphicPolygon( &aPoly );
1370 if ( pDlg->IsGraphicChanged() )
1371 rSh.ReRead( OUString(), OUString(), &pDlg->GetGraphic());
1372 rSh.EndAction();
1376 break;
1377 case FN_FRAME_TO_ANCHOR:
1379 rSh.GotoFlyAnchor();
1380 rSh.EnterStdMode();
1381 rSh.CallChgLnk();
1383 break;
1384 case FN_TOOL_ANCHOR_PAGE:
1385 case FN_TOOL_ANCHOR_PARAGRAPH:
1386 case FN_TOOL_ANCHOR_CHAR:
1387 case FN_TOOL_ANCHOR_AT_CHAR:
1388 case FN_TOOL_ANCHOR_FRAME:
1390 RndStdIds eSet = nSlot == FN_TOOL_ANCHOR_PAGE
1391 ? RndStdIds::FLY_AT_PAGE
1392 : nSlot == FN_TOOL_ANCHOR_PARAGRAPH
1393 ? RndStdIds::FLY_AT_PARA
1394 : nSlot == FN_TOOL_ANCHOR_FRAME
1395 ? RndStdIds::FLY_AT_FLY
1396 : nSlot == FN_TOOL_ANCHOR_CHAR
1397 ? RndStdIds::FLY_AS_CHAR
1398 : RndStdIds::FLY_AT_CHAR;
1399 rSh.StartUndo();
1400 if (rSh.IsObjSelected())
1401 rSh.ChgAnchor(eSet);
1402 else if (rSh.IsFrameSelected())
1404 SwFormatAnchor aAnc(eSet, eSet == RndStdIds::FLY_AT_PAGE ? rSh.GetPhyPageNum() : 0);
1405 SfxItemSet aSet(SwFEShell::makeItemSetFromFormatAnchor(GetPool(), aAnc));
1406 rSh.SetFlyFrameAttr(aSet);
1408 // if new anchor is 'as char' and it is a Math object and the usual
1409 // pre-conditions are met then align the formula to the baseline of the text
1410 const uno::Reference < embed::XEmbeddedObject > xObj( rSh.GetOleRef() );
1411 const bool bDoMathBaselineAlignment = xObj.is() && SotExchange::IsMath( xObj->getClassID() )
1412 && RndStdIds::FLY_AS_CHAR == eSet && rSh.GetDoc()->getIDocumentSettingAccess().get( DocumentSettingId::MATH_BASELINE_ALIGNMENT );
1413 if (bDoMathBaselineAlignment)
1414 rSh.AlignFormulaToBaseline( xObj );
1416 sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
1417 if( nHtmlMode )
1419 SfxItemSetFixed<RES_SURROUND, RES_HORI_ORIENT> aSet(GetPool());
1420 rSh.GetFlyFrameAttr(aSet);
1422 const SwFormatSurround& rSurround = aSet.Get(RES_SURROUND);
1423 const SwFormatVertOrient& rVert = aSet.Get(RES_VERT_ORIENT);
1424 const SwFormatHoriOrient& rHori = aSet.Get(RES_HORI_ORIENT);
1425 sal_Int16 eVOrient = rVert.GetVertOrient();
1426 sal_Int16 eHOrient = rHori.GetHoriOrient();
1427 css::text::WrapTextMode eSurround = rSurround.GetSurround();
1429 switch( eSet )
1431 case RndStdIds::FLY_AT_FLY:
1432 case RndStdIds::FLY_AT_PAGE:
1433 //Wrap through, left or from left, top, from top
1434 if(eSurround != css::text::WrapTextMode_THROUGH)
1435 aSet.Put(SwFormatSurround(css::text::WrapTextMode_THROUGH));
1437 if( eVOrient != text::VertOrientation::TOP && eVOrient != text::VertOrientation::NONE)
1438 aSet.Put(SwFormatVertOrient(0, text::VertOrientation::TOP));
1440 if (eHOrient != text::HoriOrientation::NONE && eHOrient != text::HoriOrientation::LEFT)
1441 aSet.Put(SwFormatHoriOrient(0, text::HoriOrientation::LEFT));
1442 break;
1444 case RndStdIds::FLY_AT_PARA:
1445 // left, from left, right, top, no wrap, wrap left and right
1446 if (eSurround != css::text::WrapTextMode_LEFT && eSurround != css::text::WrapTextMode_RIGHT)
1447 aSet.Put(SwFormatSurround(css::text::WrapTextMode_LEFT));
1449 if( eVOrient != text::VertOrientation::TOP)
1450 aSet.Put(SwFormatVertOrient(0, text::VertOrientation::TOP));
1452 if (eHOrient != text::HoriOrientation::NONE && eHOrient != text::HoriOrientation::LEFT && eHOrient != text::HoriOrientation::RIGHT)
1453 aSet.Put(SwFormatHoriOrient(0, text::HoriOrientation::LEFT));
1454 break;
1456 case RndStdIds::FLY_AT_CHAR:
1457 // left, from left, right, top, wrap through
1458 if(eSurround != css::text::WrapTextMode_THROUGH)
1459 aSet.Put(SwFormatSurround(css::text::WrapTextMode_THROUGH));
1461 if( eVOrient != text::VertOrientation::TOP)
1462 aSet.Put(SwFormatVertOrient(0, text::VertOrientation::TOP));
1464 if (eHOrient != text::HoriOrientation::NONE && eHOrient != text::HoriOrientation::LEFT && eHOrient != text::HoriOrientation::RIGHT)
1465 aSet.Put(SwFormatHoriOrient(0, text::HoriOrientation::LEFT));
1466 break;
1468 default:
1472 if( aSet.Count() )
1473 rSh.SetFlyFrameAttr( aSet );
1475 rSh.EndUndo();
1477 GetView().GetViewFrame().GetBindings().Invalidate( SID_ANCHOR_MENU );
1479 break;
1481 case FN_FRAME_NOWRAP:
1482 case FN_FRAME_WRAP:
1483 case FN_FRAME_WRAP_IDEAL:
1484 case FN_FRAME_WRAPTHRU:
1485 case FN_FRAME_WRAPTHRU_TRANSP:
1486 case FN_FRAME_WRAPTHRU_TOGGLE:
1487 case FN_FRAME_WRAP_CONTOUR:
1488 case FN_WRAP_ANCHOR_ONLY:
1489 case FN_FRAME_WRAP_LEFT:
1490 case FN_FRAME_WRAP_RIGHT:
1491 SetWrapMode( nSlot );
1492 break;
1494 case FN_UPDATE_ALL_LINKS:
1496 if( !rSh.GetLinkManager().GetLinks().empty() )
1498 rSh.EnterStdMode();
1499 rSh.StartAllAction();
1500 rSh.GetLinkManager().UpdateAllLinks( false, false, nullptr );
1501 rSh.EndAllAction();
1504 break;
1506 case FN_XFORMS_DESIGN_MODE:
1507 if (pArgs && pArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET)
1509 if (const SfxBoolItem* pBoolItem = dynamic_cast<const SfxBoolItem*>(pItem))
1511 bool bDesignMode = pBoolItem->GetValue();
1513 // set from design mode
1514 OSL_ENSURE( GetView().GetFormShell() != nullptr, "form shell?" );
1515 SfxRequest aReq(GetView().GetViewFrame(), SID_FM_DESIGN_MODE);
1516 aReq.AppendItem( SfxBoolItem( SID_FM_DESIGN_MODE, bDesignMode ) );
1517 GetView().GetFormShell()->Execute( aReq );
1518 aReq.Done();
1520 // also set suitable view options
1521 SwViewOption aViewOption = *rSh.GetViewOptions();
1522 aViewOption.SetFormView( ! bDesignMode );
1523 rSh.ApplyViewOptions( aViewOption );
1526 break;
1528 default:
1529 bMore = true;
1533 if(!bMore || !pArgs)
1534 return;
1536 pItem = nullptr;
1537 pArgs->GetItemState(GetPool().GetWhich(nSlot), false, &pItem);
1538 if(!pItem)
1539 return;
1541 switch(nSlot)
1543 case SID_ATTR_BRUSH:
1544 case SID_ATTR_BORDER_SHADOW:
1545 case RES_SHADOW:
1547 rSh.StartAllAction();
1548 // Table cell(s) selected?
1549 if ( rSh.IsTableMode() )
1551 SwFrameFormat *pFormat = rSh.GetTableFormat();
1552 pFormat->SetFormatAttr( *pItem );
1554 else if ( rSh.IsFrameSelected() )
1556 // Set border attributes via Frame-Manager.
1557 SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr );
1558 aMgr.SetAttrSet( *pArgs );
1559 aMgr.UpdateFlyFrame();
1561 else
1563 rSh.SetAttrSet( *pArgs );
1565 rSh.EndAllAction();
1567 break;
1568 case FN_PAGE_STYLE_SET_LR_MARGIN:
1569 case FN_PAGE_STYLE_SET_UL_MARGIN:
1570 case FN_PAGE_STYLE_SET_NUMBER_FORMAT:
1571 case FN_PAGE_STYLE_SET_PAPER_SIZE:
1572 case FN_PAGE_STYLE_SET_PAPER_BIN:
1574 OSL_FAIL("not implemented");
1576 break;
1578 case SID_ATTR_BORDER_OUTER:
1580 // Table cell(s) selected?
1581 if ( rSh.IsTableMode() )
1583 // Set border attributes Get/SetTabBorders()
1584 rSh.SetTabBorders(*pArgs);
1586 else if ( rSh.IsFrameSelected() )
1588 // Set border attributes via Frame-Manager.
1589 SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr );
1590 aMgr.SetAttrSet(*pArgs);
1591 aMgr.UpdateFlyFrame();
1593 else
1595 // Set border attributes via shell quite normally.
1596 rSh.SetAttrItem( *pItem );
1599 break;
1600 default:
1601 OSL_FAIL("wrong Dispatcher");
1605 // Here the state for SID_IMAP / SID_CONTOUR will be handled
1606 // until the swapping of the graphic is finished.
1608 IMPL_LINK_NOARG(SwBaseShell, GraphicArrivedHdl, SwCursorShell&, void)
1610 SwWrtShell &rSh = GetShell();
1611 if (CNT_GRF != rSh.SwEditShell::GetCntType())
1612 return;
1613 GraphicType const nGrfType(rSh.GetGraphicType());
1614 if (GraphicType::NONE == nGrfType || m_aGrfUpdateSlots.empty())
1615 return;
1617 bool bProtect = FlyProtectFlags::NONE != rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent);
1618 SfxViewFrame& rVFrame = GetView().GetViewFrame();
1619 for( const auto nSlot : m_aGrfUpdateSlots )
1621 bool bSetState = false;
1622 bool bState = false;
1623 switch( nSlot )
1625 case SID_IMAP:
1626 case SID_IMAP_EXEC:
1628 sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
1629 SfxChildWindow *pChildWindow = rVFrame.HasChildWindow(nId) ?
1630 rVFrame.GetChildWindow(nId) : nullptr;
1631 SvxIMapDlg *pDlg = pChildWindow ?
1632 static_cast<SvxIMapDlg*>(pChildWindow->GetController().get()) : nullptr;
1634 if( pDlg && ( SID_IMAP_EXEC == nSlot ||
1635 ( SID_IMAP == nSlot && !bProtect)) &&
1636 pDlg->GetEditingObject() != rSh.GetIMapInventor())
1637 lcl_UpdateIMapDlg( rSh );
1639 if( !bProtect && SID_IMAP == nSlot )
1641 bSetState = true;
1642 bState = nullptr != pDlg;
1645 break;
1647 case SID_CONTOUR_DLG:
1648 if( !bProtect )
1650 sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
1651 SfxChildWindow *pChildWindow = rVFrame.HasChildWindow(nId) ?
1652 rVFrame.GetChildWindow(nId) : nullptr;
1653 SvxIMapDlg *pDlg = pChildWindow ?
1654 static_cast<SvxIMapDlg*>(pChildWindow->GetController().get()) : nullptr;
1655 if( pDlg && pDlg->GetEditingObject() !=
1656 rSh.GetIMapInventor() )
1657 lcl_UpdateContourDlg( rSh, SelectionType::Graphic );
1659 bSetState = true;
1660 bState = nullptr != pDlg;
1662 break;
1664 case FN_FRAME_WRAP_CONTOUR:
1665 if( !bProtect )
1667 SfxItemSetFixed<RES_SURROUND, RES_SURROUND> aSet(GetPool());
1668 rSh.GetFlyFrameAttr(aSet);
1669 const SwFormatSurround& rWrap = aSet.Get(RES_SURROUND);
1670 bSetState = true;
1671 bState = rWrap.IsContour();
1673 break;
1675 case SID_GRFFILTER:
1676 case SID_GRFFILTER_INVERT:
1677 case SID_GRFFILTER_SMOOTH:
1678 case SID_GRFFILTER_SHARPEN:
1679 case SID_GRFFILTER_REMOVENOISE:
1680 case SID_GRFFILTER_SOBEL:
1681 case SID_GRFFILTER_MOSAIC:
1682 case SID_GRFFILTER_EMBOSS:
1683 case SID_GRFFILTER_POSTER:
1684 case SID_GRFFILTER_POPART:
1685 case SID_GRFFILTER_SEPIA:
1686 case SID_GRFFILTER_SOLARIZE:
1687 bSetState = bState = GraphicType::Bitmap == nGrfType;
1688 break;
1691 if( bSetState )
1693 SfxBoolItem aBool( nSlot, bState );
1694 if( m_pGetStateSet )
1695 m_pGetStateSet->Put( aBool );
1696 else
1697 rVFrame.GetBindings().SetState( aBool );
1700 m_aGrfUpdateSlots.clear();
1703 void SwBaseShell::GetState( SfxItemSet &rSet )
1705 SwWrtShell &rSh = GetShell();
1706 SfxViewFrame& rVFrame = GetView().GetViewFrame();
1707 SfxWhichIter aIter( rSet );
1708 sal_uInt16 nWhich = aIter.FirstWhich();
1709 m_pGetStateSet = &rSet;
1710 while ( nWhich )
1712 switch ( nWhich )
1714 case SID_GALLERY_FORMATS:
1715 if ( rSh.IsObjSelected() ||
1716 (rSh.IsSelFrameMode() &&
1717 !(rSh.GetSelectionType() & SelectionType::Graphic)) )
1718 rSet.DisableItem( nWhich );
1719 break;
1720 case SID_GALLERY_ENABLE_ADDCOPY:
1721 // #108230# allow copy from gallery in Writer AND Writer/Web!
1722 rSet.Put( SfxBoolItem( SID_GALLERY_ENABLE_ADDCOPY, true ) );
1723 break;
1724 case FN_EDIT_REGION:
1725 if( !rSh.IsAnySectionInDoc() )
1726 rSet.DisableItem(nWhich);
1727 break;
1729 case FN_EDIT_CURRENT_REGION:
1730 //tdf#112808 if cursor is in an index, don't show the edit section.
1731 if( !rSh.GetCurrSection() ||
1732 (rSh.GetCurrSection()->GetType() != SectionType::Content &&
1733 rSh.GetCurrSection()->GetType() != SectionType::FileLink ))
1735 rSet.DisableItem(nWhich);
1737 break;
1739 case FN_INSERT_REGION:
1740 if( rSh.CursorInsideInputField()
1741 || rSh.IsSelFrameMode()
1742 || !rSh.IsInsRegionAvailable() )
1744 rSet.DisableItem( nWhich );
1746 break;
1748 case FN_CONVERT_TABLE_TO_TEXT:
1750 FrameTypeFlags eFrameType = rSh.GetFrameType(nullptr,true);
1751 if( (eFrameType & FrameTypeFlags::FOOTNOTE) ||
1752 !rSh.GetTableFormat() )
1753 rSet.DisableItem( nWhich );
1755 break;
1756 case FN_CONVERT_TEXT_TO_TABLE:
1758 FrameTypeFlags eFrameType = rSh.GetFrameType(nullptr,true);
1759 if( (eFrameType & FrameTypeFlags::FOOTNOTE) ||
1760 !rSh.IsTextToTableAvailable() )
1761 rSet.DisableItem( nWhich );
1763 break;
1764 case FN_CONVERT_TEXT_TABLE:
1766 FrameTypeFlags eFrameType = rSh.GetFrameType(nullptr,true);
1767 if( (eFrameType & FrameTypeFlags::FOOTNOTE) ||
1768 (!rSh.GetTableFormat() && !rSh.IsTextToTableAvailable() ) )
1769 rSet.DisableItem( nWhich );
1771 break;
1772 case RES_SHADOW:
1774 SfxItemSetFixed<RES_SHADOW, RES_SHADOW> aSet( rSh.GetAttrPool());
1776 // Table cell(s) selected?
1777 if ( rSh.IsTableMode() )
1779 SwFrameFormat *pFormat = rSh.GetTableFormat();
1780 aSet.Put(pFormat->GetFormatAttr( nWhich ));
1782 else if( rSh.IsFrameSelected() )
1784 SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr );
1785 aSet.Put( aMgr.GetAttrSet() );
1787 else
1788 rSh.GetCurAttr( aSet );
1790 const SvxShadowItem& rShItem = static_cast<const SvxShadowItem&>(aSet.Get(nWhich));
1791 rSet.Put(rShItem);
1793 break;
1794 case SID_IMAP:
1796 // #i59688#
1797 // Improve efficiency:
1798 // If selected object is protected, item has to disabled.
1799 const bool bProtect = FlyProtectFlags::NONE != rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent);
1800 if ( bProtect )
1802 rSet.DisableItem( nWhich );
1804 else
1806 const sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
1807 const bool bHas = rVFrame.HasChildWindow( nId );
1808 const bool bFrameSel = rSh.IsFrameSelected();
1809 const bool bIsGraphicSelection =
1810 rSh.GetSelectionType() == SelectionType::Graphic;
1812 // #i59688#
1813 // Avoid unnecessary loading of selected graphic.
1814 // The graphic is only needed, if the dialog is open.
1815 // If the swapping of the graphic is finished, the status
1816 // must be determined asynchronously, until this the slot
1817 // will be disabled.
1818 if ( bHas && bIsGraphicSelection && rSh.IsLinkedGrfSwapOut() )
1820 if( AddGrfUpdateSlot( nWhich ))
1821 rSh.GetGraphic(false); // start the loading
1823 else
1825 if ( !bHas &&
1826 ( !bFrameSel ||
1827 ( bIsGraphicSelection &&
1828 rSh.GetGraphicType() == GraphicType::NONE ) ) )
1830 rSet.DisableItem( nWhich );
1832 else
1834 SfxBoolItem aBool(nWhich, bHas);
1835 if ( bHas && bFrameSel )
1836 lcl_UpdateIMapDlg( rSh );
1837 rSet.Put(aBool);
1842 break;
1843 case SID_IMAP_EXEC:
1845 bool bDisable = false;
1846 if( !rSh.IsFrameSelected())
1847 bDisable = true;
1848 sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
1849 if(!bDisable && rVFrame.HasChildWindow( nId ))
1851 if(rSh.GetSelectionType() == SelectionType::Graphic
1852 && rSh.IsLinkedGrfSwapOut())
1854 if( AddGrfUpdateSlot( nWhich ))
1855 rSh.GetGraphic(false); // start the loading
1857 else
1859 SvxIMapDlg *pDlg = GetIMapDlg(GetView());
1860 if (pDlg && pDlg->GetEditingObject() != rSh.GetIMapInventor())
1861 lcl_UpdateIMapDlg( rSh );
1864 rSet.Put(SfxBoolItem(nWhich, bDisable));
1866 break;
1868 case FN_BACKSPACE:
1869 case SID_DELETE:
1870 if ( ( rSh.HasReadonlySel() && !rSh.CursorInsideInputField() )
1871 || rSh.IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE )
1873 rSet.DisableItem( nWhich );
1875 break;
1877 case SID_CONTOUR_DLG:
1879 bool bParentCntProt = FlyProtectFlags::NONE != rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent );
1881 if( bParentCntProt || 0 != (HTMLMODE_ON & ::GetHtmlMode(
1882 GetView().GetDocShell() )) )
1883 rSet.DisableItem( nWhich );
1884 else
1886 sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
1887 bool bHas = GetView().GetViewFrame().HasChildWindow( nId );
1888 SelectionType nSel = rSh.GetSelectionType();
1889 bool bOk(nSel & (SelectionType::Graphic|SelectionType::Ole));
1891 bool bDisable = false;
1892 if( !bHas && !bOk )
1893 bDisable = true;
1894 // #i59688#
1895 // Avoid unnecessary loading of selected graphic.
1896 // The graphic is only needed, if the dialog is open.
1897 // If the swapping of the graphic is finished, the status
1898 // must be determined asynchronously, until this the slot
1899 // will be disabled.
1900 else if ( bHas && (nSel & SelectionType::Graphic) &&
1901 rSh.IsLinkedGrfSwapOut() )
1903 if( AddGrfUpdateSlot( nWhich ))
1904 rSh.GetGraphic(false); // start the loading
1905 // #i75481#
1906 bDisable = true;
1908 else if( bHas && bOk )
1909 bDisable = !lcl_UpdateContourDlg( rSh, nSel );
1910 else if( bOk )
1912 // #i75481#
1913 // apply fix #i59688# only for selected graphics
1914 if ( nSel & SelectionType::Graphic )
1915 bDisable = GraphicType::NONE == rSh.GetGraphicType();
1916 else
1917 bDisable = GraphicType::NONE == rSh.GetIMapGraphic().GetType();
1920 if( bDisable )
1921 rSet.DisableItem( nWhich );
1922 else
1923 rSet.Put( SfxBoolItem(nWhich, bHas) );
1926 break;
1927 case SID_CONTOUR_EXEC:
1929 bool bDisable = false;
1930 SelectionType nSel = rSh.GetSelectionType();
1931 if( !(nSel & (SelectionType::Graphic|SelectionType::Ole)) )
1932 bDisable = true;
1933 sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
1934 if( !bDisable && GetView().GetViewFrame().HasChildWindow( nId ))
1936 SvxContourDlg *pDlg = GetContourDlg(GetView());
1937 if (pDlg && pDlg->GetEditingObject() != rSh.GetIMapInventor())
1938 bDisable = true;
1940 rSet.Put(SfxBoolItem(nWhich, bDisable));
1942 break;
1944 case SID_ANCHOR_MENU:
1945 case FN_TOOL_ANCHOR_PAGE:
1946 case FN_TOOL_ANCHOR_PARAGRAPH:
1947 case FN_TOOL_ANCHOR_CHAR:
1948 case FN_TOOL_ANCHOR_AT_CHAR:
1949 case FN_TOOL_ANCHOR_FRAME:
1951 bool bObj = 0 != rSh.IsObjSelected();
1952 bool bParentCntProt = rSh.IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE;
1954 if( !bParentCntProt && (bObj || rSh.IsFrameSelected()))
1956 SfxItemSetFixed<RES_ANCHOR, RES_ANCHOR> aSet(GetPool());
1957 if(bObj)
1958 rSh.GetObjAttr(aSet);
1959 else
1960 rSh.GetFlyFrameAttr(aSet);
1961 RndStdIds eSet = aSet.Get(RES_ANCHOR).GetAnchorId();
1962 const bool bSet =
1963 ((nWhich == FN_TOOL_ANCHOR_PAGE) &&
1964 (eSet == RndStdIds::FLY_AT_PAGE))
1965 || ((nWhich == FN_TOOL_ANCHOR_PARAGRAPH) &&
1966 (eSet == RndStdIds::FLY_AT_PARA))
1967 || ((nWhich == FN_TOOL_ANCHOR_FRAME) &&
1968 (eSet == RndStdIds::FLY_AT_FLY))
1969 || ((nWhich == FN_TOOL_ANCHOR_AT_CHAR) &&
1970 (eSet == RndStdIds::FLY_AT_CHAR))
1971 || ((nWhich == FN_TOOL_ANCHOR_CHAR) &&
1972 (eSet == RndStdIds::FLY_AS_CHAR));
1974 if( nWhich == FN_TOOL_ANCHOR_FRAME && !rSh.IsFlyInFly() )
1975 rSet.DisableItem(nWhich);
1976 else if(nWhich != SID_ANCHOR_MENU)
1977 rSet.Put(SfxBoolItem(nWhich, bSet));
1979 if (comphelper::LibreOfficeKit::isActive())
1981 if (nWhich == FN_TOOL_ANCHOR_PAGE || nWhich == FN_TOOL_ANCHOR_FRAME)
1983 rSet.DisableItem(nWhich);
1987 else
1988 rSet.DisableItem( nWhich );
1990 break;
1991 case FN_FRAME_NOWRAP:
1992 case FN_FRAME_WRAP:
1993 case FN_FRAME_WRAP_IDEAL:
1994 case FN_FRAME_WRAPTHRU:
1995 case FN_FRAME_WRAPTHRU_TRANSP:
1996 case FN_FRAME_WRAPTHRU_TOGGLE:
1997 case FN_FRAME_WRAP_CONTOUR:
1998 case FN_WRAP_ANCHOR_ONLY:
1999 case FN_FRAME_WRAP_LEFT:
2000 case FN_FRAME_WRAP_RIGHT:
2002 bool bObj = 0 != rSh.IsObjSelected();
2003 bool bParentCntProt = rSh.IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE;
2005 if( !bParentCntProt && (bObj || rSh.IsFrameSelected()))
2007 SfxItemSetFixed<RES_OPAQUE, RES_ANCHOR> aSet(GetPool());
2008 RndStdIds nAnchorType;
2009 if(bObj)
2011 rSh.GetObjAttr(aSet);
2012 nAnchorType = rSh.GetAnchorId();
2014 else
2016 rSh.GetFlyFrameAttr(aSet);
2017 nAnchorType = aSet.Get(RES_ANCHOR).GetAnchorId();
2019 const SwFormatSurround& rWrap = aSet.Get(RES_SURROUND);
2021 const SvxOpaqueItem& rOpaque = aSet.Get(RES_OPAQUE);
2022 bool bOpaque = rOpaque.GetValue();
2023 css::text::WrapTextMode nSurround = rWrap.GetSurround();
2024 bool bSet = false;
2026 bool bDisable =
2027 (nAnchorType == RndStdIds::UNKNOWN) || (nAnchorType == RndStdIds::FLY_AS_CHAR);
2028 const bool bHtmlMode =
2029 0 != ::GetHtmlMode(GetView().GetDocShell());
2031 switch( nWhich )
2033 case FN_FRAME_NOWRAP:
2034 bDisable |=
2035 ( (nAnchorType != RndStdIds::FLY_AT_PARA)
2036 && (nAnchorType != RndStdIds::FLY_AT_CHAR)
2037 && (nAnchorType != RndStdIds::FLY_AT_PAGE));
2038 bSet = nSurround == css::text::WrapTextMode_NONE;
2039 break;
2040 case FN_FRAME_WRAP:
2041 bDisable |= bHtmlMode;
2042 bSet = nSurround == css::text::WrapTextMode_PARALLEL;
2043 break;
2044 case FN_FRAME_WRAP_IDEAL:
2045 bDisable |= bHtmlMode;
2046 bSet = nSurround == css::text::WrapTextMode_DYNAMIC;
2047 break;
2048 case FN_FRAME_WRAPTHRU:
2049 bDisable |= (bHtmlMode ||
2050 ( (nAnchorType != RndStdIds::FLY_AT_PARA)
2051 && (nAnchorType != RndStdIds::FLY_AT_CHAR)
2052 && (nAnchorType != RndStdIds::FLY_AT_PAGE)));
2053 if(bObj)
2054 bSet = nSurround == css::text::WrapTextMode_THROUGH && rSh.GetLayerId();
2055 else
2056 bSet = nSurround == css::text::WrapTextMode_THROUGH && bOpaque;
2057 break;
2058 case FN_FRAME_WRAPTHRU_TRANSP:
2059 case FN_FRAME_WRAPTHRU_TOGGLE:
2060 bDisable |= bHtmlMode;
2061 if(bObj)
2062 bSet = nSurround == css::text::WrapTextMode_THROUGH && !rSh.GetLayerId();
2063 else
2064 bSet = nSurround == css::text::WrapTextMode_THROUGH && !bOpaque;
2065 break;
2066 case FN_FRAME_WRAP_CONTOUR:
2067 bDisable |= bHtmlMode;
2068 //no contour available when no wrap or wrap through is set
2069 bDisable |= (nSurround == css::text::WrapTextMode_NONE || nSurround == css::text::WrapTextMode_THROUGH);
2070 if( !bDisable )
2072 SelectionType nSel = rSh.GetSelectionType();
2073 if( (nSel & SelectionType::Graphic) &&
2074 rSh.IsLinkedGrfSwapOut())
2076 if( AddGrfUpdateSlot( nWhich ))
2077 rSh.GetGraphic(false); // start the loading
2079 else if( rSh.IsFrameSelected() )
2081 // #i102253# applied patch from OD (see task)
2082 bDisable =
2083 nSel & SelectionType::Frame ||
2084 GraphicType::NONE == rSh.GetIMapGraphic().GetType();
2087 bSet = !bDisable && rWrap.IsContour();
2089 break;
2090 case FN_WRAP_ANCHOR_ONLY:
2091 bDisable |= (bHtmlMode ||
2092 (nAnchorType != RndStdIds::FLY_AT_PARA));
2093 bSet = rWrap.IsAnchorOnly();
2094 break;
2095 case FN_FRAME_WRAP_LEFT:
2096 bSet = nSurround == css::text::WrapTextMode_LEFT;
2097 break;
2098 case FN_FRAME_WRAP_RIGHT:
2099 bSet = nSurround == css::text::WrapTextMode_RIGHT;
2100 break;
2103 if(bDisable)
2104 rSet.DisableItem(nWhich);
2105 else
2106 rSet.Put(SfxBoolItem(nWhich, bSet));
2108 else
2109 rSet.DisableItem(nWhich);
2111 break;
2112 case FN_UPDATE_CHARTS:
2113 if( !rSh.HasCharts() )
2114 rSet.DisableItem( nWhich );
2115 break;
2116 case FN_UPDATE_ALL_LINKS:
2117 if ( rSh.GetLinkManager().GetLinks().empty() )
2118 rSet.DisableItem(nWhich);
2119 break;
2120 case FN_XFORMS_DESIGN_MODE:
2121 // enable if in XForms document
2122 if( rSh.GetDoc()->isXForms() )
2124 // determine current state from view options
2125 bool bValue = ! rSh.GetViewOptions()->IsFormView();
2126 rSet.Put( SfxBoolItem( nWhich, bValue ) );
2128 else
2129 rSet.Put( SfxVisibilityItem( nWhich, false ) );
2130 break;
2131 case SID_GRAPHIC_SIZE_CHECK:
2133 sal_Int32 nDPI = rSh.GetDoc()->getIDocumentSettingAccess().getImagePreferredDPI();
2134 if (nDPI <= 0)
2135 rSet.DisableItem(nWhich);
2137 break;
2138 case SID_THEME_DIALOG:
2140 bool bDisable = true;
2141 auto* pDocument = rSh.GetDoc();
2142 auto* pDocumentShell = pDocument->GetDocShell();
2143 if (pDocumentShell)
2145 SdrPage* pPage = pDocument->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
2146 if (pPage)
2148 auto const& pTheme = pPage->getSdrPageProperties().GetTheme();
2149 if (pTheme)
2150 bDisable = false;
2153 if (bDisable)
2154 rSet.DisableItem(nWhich);
2156 break;
2158 nWhich = aIter.NextWhich();
2160 m_pGetStateSet = nullptr;
2163 // Disable the slots with this status method
2165 void SwBaseShell::StateDisableItems( SfxItemSet &rSet )
2167 SfxWhichIter aIter(rSet);
2168 sal_uInt16 nWhich = aIter.FirstWhich();
2170 while (nWhich)
2172 rSet.DisableItem( nWhich );
2173 nWhich = aIter.NextWhich();
2177 // Disable the slots with this status method
2179 void SwBaseShell::StateStyle( SfxItemSet &rSet )
2181 bool bParentCntProt = GetShell().IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE;
2182 ShellMode eMode = GetView().GetShellMode();
2184 if ( bParentCntProt ||
2185 ShellMode::Draw == eMode ||
2186 ShellMode::DrawForm == eMode ||
2187 ShellMode::DrawText == eMode ||
2188 ShellMode::Bezier == eMode )
2190 SfxWhichIter aIter( rSet );
2191 sal_uInt16 nWhich = aIter.FirstWhich();
2192 while ( nWhich )
2194 rSet.DisableItem( nWhich );
2195 nWhich = aIter.NextWhich();
2198 else
2199 GetView().GetDocShell()->StateStyleSheet(rSet, &GetShell());
2202 void SwBaseShell::SetWrapMode( sal_uInt16 nSlot )
2204 SwWrtShell &rSh = GetShell();
2205 bool bObj = 0 != rSh.IsObjSelected();
2206 if( !bObj && !rSh.IsFrameSelected())
2207 return;
2209 SfxItemSetFixed<RES_OPAQUE, RES_SURROUND> aSet(GetPool());
2210 if(bObj)
2211 rSh.GetObjAttr(aSet);
2212 else
2213 rSh.GetFlyFrameAttr(aSet);
2214 SwFormatSurround aWrap( aSet.Get(RES_SURROUND) );
2215 css::text::WrapTextMode nOldSurround(aWrap.GetSurround());
2216 css::text::WrapTextMode nSurround = css::text::WrapTextMode_PARALLEL;
2218 switch (nSlot)
2220 case FN_FRAME_NOWRAP:
2221 nSurround = css::text::WrapTextMode_NONE;
2222 if (aWrap.IsContour())
2223 aWrap.SetContour(false);
2224 break;
2225 case FN_FRAME_WRAP_IDEAL:
2226 nSurround = css::text::WrapTextMode_DYNAMIC;
2227 break;
2228 case FN_WRAP_ANCHOR_ONLY:
2229 aWrap.SetAnchorOnly(!aWrap.IsAnchorOnly());
2231 // keep previous wrapping
2233 // switch to wrap css::text::WrapTextMode_PARALLEL, if previous wrap is css::text::WrapTextMode_NONE
2234 if ( nOldSurround != css::text::WrapTextMode_NONE )
2236 nSurround = nOldSurround;
2238 break;
2239 case FN_FRAME_WRAP_CONTOUR:
2240 aWrap.SetContour(!aWrap.IsContour());
2241 // Contour is meaningless in no-wrap or wrap-through context. Otherwise keep existing wrap.
2242 if ( !aWrap.IsContour() ||
2243 ( nOldSurround != css::text::WrapTextMode_NONE &&
2244 nOldSurround != css::text::WrapTextMode_THROUGH ) )
2246 nSurround = nOldSurround;
2248 break;
2249 case FN_FRAME_WRAPTHRU_TRANSP:
2250 case FN_FRAME_WRAPTHRU_TOGGLE:
2251 if (aWrap.IsContour())
2252 aWrap.SetContour(false);
2253 [[fallthrough]];
2254 case FN_FRAME_WRAPTHRU:
2255 nSurround = css::text::WrapTextMode_THROUGH;
2256 break;
2258 case FN_FRAME_WRAP_LEFT:
2259 nSurround = css::text::WrapTextMode_LEFT;
2260 break;
2262 case FN_FRAME_WRAP_RIGHT:
2263 nSurround = css::text::WrapTextMode_RIGHT;
2264 break;
2266 default:
2267 break;
2269 aWrap.SetSurround(nSurround);
2271 if (nSlot != FN_FRAME_WRAP_CONTOUR)
2273 // Defaulting the contour wrap on draw objects.
2274 if (bObj && nOldSurround != nSurround &&
2275 (nOldSurround == css::text::WrapTextMode_NONE || nOldSurround == css::text::WrapTextMode_THROUGH))
2277 aWrap.SetContour(true);
2281 aSet.Put( aWrap );
2283 bool bOpaque = nSlot != FN_FRAME_WRAPTHRU_TRANSP && nSlot != FN_FRAME_WRAPTHRU_TOGGLE;
2284 if( nSlot == FN_FRAME_WRAPTHRU_TOGGLE )
2286 if( bObj )
2287 bOpaque = !rSh.GetLayerId();
2288 else
2290 const SvxOpaqueItem& aOpaque( aSet.Get(RES_OPAQUE) );
2291 bOpaque = !aOpaque.GetValue();
2294 aSet.Put(SvxOpaqueItem(RES_OPAQUE, bOpaque ));
2296 if(bObj)
2298 rSh.SetObjAttr(aSet);
2299 if ( bOpaque )
2300 rSh.SelectionToHeaven();
2301 else
2302 rSh.SelectionToHell();
2304 else
2305 rSh.SetFlyFrameAttr(aSet);
2309 //Force update of the status line
2311 void SwBaseShell::SetFrameMode(FlyMode eMode, SwWrtShell *pSh )
2313 s_eFrameMode = eMode;
2314 SfxBindings &rBnd = pSh->GetView().GetViewFrame().GetBindings();
2316 if( eMode == FLY_DRAG || pSh->IsFrameSelected() || pSh->IsObjSelected() )
2318 const SfxPointItem aTmp1( SID_ATTR_POSITION, pSh->GetAnchorObjDiff());
2319 const SvxSizeItem aTmp2( SID_ATTR_SIZE, pSh->GetObjSize());
2320 rBnd.SetState( aTmp1 );
2321 rBnd.SetState( aTmp2 );
2323 else if( eMode == FLY_DRAG_END )
2325 static sal_uInt16 aInval[] =
2327 SID_ATTR_POSITION, SID_ATTR_SIZE, 0
2329 rBnd.Invalidate(aInval);
2333 SwBaseShell::SwBaseShell(SwView& rVw) :
2334 SfxShell( &rVw ),
2335 m_rView(rVw),
2336 m_pGetStateSet(nullptr)
2338 SwWrtShell& rWrtSh = m_rView.GetWrtShell();
2340 SetPool(&rWrtSh.GetAttrPool());
2341 SetName("Base");
2342 rWrtSh.SetGrfArrivedLnk( LINK( this, SwBaseShell, GraphicArrivedHdl));
2345 SwBaseShell::~SwBaseShell()
2347 if( m_rView.GetCurShell() == this )
2348 m_rView.ResetSubShell();
2350 Link<SwCursorShell&,void> aTmp( LINK( this, SwBaseShell, GraphicArrivedHdl));
2351 if( aTmp == m_rView.GetWrtShell().GetGrfArrivedLnk() )
2352 m_rView.GetWrtShell().SetGrfArrivedLnk( Link<SwCursorShell&,void>() );
2355 void SwBaseShell::ExecTextCtrl( SfxRequest& rReq )
2357 const SfxItemSet *pArgs = rReq.GetArgs();
2358 const sal_uInt16 nSlot = rReq.GetSlot();
2360 if( pArgs)
2362 SwWrtShell &rSh = GetShell();
2363 std::unique_ptr<SvxScriptSetItem> pSSetItem;
2364 SfxItemPool& rPool = rSh.GetAttrPool();
2365 sal_uInt16 nWhich = rPool.GetWhich( nSlot );
2366 SvtScriptType nScripts = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
2367 SfxItemSetFixed<RES_CHRATR_FONTSIZE, RES_CHRATR_FONTSIZE,
2368 RES_CHRATR_CJK_FONTSIZE, RES_CHRATR_CJK_FONTSIZE,
2369 RES_CHRATR_CTL_FONTSIZE, RES_CHRATR_CTL_FONTSIZE>
2370 aHeightSet( GetPool() );
2372 switch( nSlot )
2374 case SID_ATTR_CHAR_FONT:
2376 nScripts = rSh.GetScriptType();
2377 // #i42732# input language should be preferred over
2378 // current cursor position to detect script type
2379 if(!rSh.HasSelection())
2381 LanguageType nInputLang = GetView().GetEditWin().GetInputLanguage();
2382 if(nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
2383 nScripts = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
2385 [[fallthrough]];
2387 case SID_ATTR_CHAR_POSTURE:
2388 case SID_ATTR_CHAR_WEIGHT:
2390 pSSetItem.reset(new SvxScriptSetItem( nSlot, rPool ));
2391 pSSetItem->PutItemForScriptType( nScripts, pArgs->Get( nWhich ));
2392 pArgs = &pSSetItem->GetItemSet();
2394 break;
2395 case SID_ATTR_CHAR_FONTHEIGHT:
2397 if(rSh.HasSelection())
2399 pSSetItem.reset(new SvxScriptSetItem( nSlot, rPool ));
2400 pSSetItem->PutItemForScriptType( nScripts, pArgs->Get( nWhich ));
2401 pArgs = &pSSetItem->GetItemSet();
2403 else
2405 nScripts = rSh.GetScriptType();
2406 LanguageType nInputLang = GetView().GetEditWin().GetInputLanguage();
2407 if(nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
2408 nScripts = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
2409 sal_uInt32 nHeight = static_cast< const SvxFontHeightItem& >(pArgs->Get( nWhich )).GetHeight();
2410 SwStdFontConfig* pStdFont = SW_MOD()->GetStdFontConfig();
2412 SfxItemSetFixed<RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
2413 RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
2414 RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE>
2415 aLangSet( GetPool() );
2416 rSh.GetCurAttr( aLangSet );
2418 sal_Int32 nWesternSize =
2419 pStdFont->GetFontHeight(FONT_STANDARD, FONT_GROUP_DEFAULT,
2420 aLangSet.Get( RES_CHRATR_LANGUAGE).GetLanguage());
2421 sal_Int32 nCJKSize =
2422 pStdFont->GetFontHeight(FONT_STANDARD, FONT_GROUP_CJK,
2423 aLangSet.Get( RES_CHRATR_CJK_LANGUAGE).GetLanguage());
2424 sal_Int32 nCTLSize =
2425 pStdFont->GetFontHeight(FONT_STANDARD, FONT_GROUP_CTL,
2426 aLangSet.Get( RES_CHRATR_CTL_LANGUAGE).GetLanguage());
2428 switch(nScripts)
2430 case SvtScriptType::LATIN:
2431 nCJKSize = nHeight * nCJKSize / nWesternSize;
2432 nCTLSize = nHeight * nCTLSize / nWesternSize;
2433 nWesternSize = static_cast<sal_Int32>(nHeight);
2434 break;
2435 case SvtScriptType::ASIAN:
2436 nCTLSize = nHeight* nCTLSize / nCJKSize;
2437 nWesternSize = nHeight * nWesternSize / nCJKSize;
2438 nCJKSize = static_cast<sal_Int32>(nHeight);
2439 break;
2440 case SvtScriptType::COMPLEX:
2441 nCJKSize = nHeight * nCJKSize / nCTLSize;
2442 nWesternSize = nHeight * nWesternSize / nCTLSize;
2443 nCTLSize = static_cast<sal_Int32>(nHeight);
2444 break;
2445 default: break;
2447 aHeightSet.Put( SvxFontHeightItem( static_cast<sal_uInt32>(nWesternSize), 100, RES_CHRATR_FONTSIZE ));
2448 aHeightSet.Put( SvxFontHeightItem( static_cast<sal_uInt32>(nCJKSize), 100, RES_CHRATR_CJK_FONTSIZE ));
2449 aHeightSet.Put( SvxFontHeightItem( static_cast<sal_uInt32>(nCTLSize), 100, RES_CHRATR_CTL_FONTSIZE ));
2450 pArgs = &aHeightSet;
2453 break;
2456 if( pArgs )
2458 bool bAuto = false;
2459 if ( !isCHRATR(nWhich) ||
2460 ( rSh.HasSelection() && rSh.IsSelFullPara() ) )
2462 SwTextFormatColl * pColl = rSh.GetCurTextFormatColl();
2463 if ( pColl && pColl->IsAutoUpdateOnDirectFormat() )
2465 rSh.AutoUpdatePara( pColl, *pArgs );
2466 bAuto = true;
2470 if (!bAuto)
2472 rSh.SetAttrSet( *pArgs );
2476 else
2478 if (nSlot == SID_ATTR_CHAR_KERNING)
2479 GetView().GetViewFrame().GetDispatcher()->Execute(SID_CHAR_DLG_POSITION);
2480 else if (nSlot == SID_ATTR_CHAR_COLOR)
2481 GetView().GetViewFrame().GetDispatcher()->Execute(SID_CHAR_DLG_EFFECT);
2482 else
2483 GetView().GetViewFrame().GetDispatcher()->Execute(SID_CHAR_DLG);
2485 rReq.Done();
2488 void SwBaseShell::GetTextCtrlState( SfxItemSet& rSet )
2490 SwWrtShell &rSh = GetShell();
2491 rSh.GetCurAttr( rSet );
2494 void SwBaseShell::GetTextFontCtrlState( SfxItemSet& rSet )
2496 SwWrtShell &rSh = GetShell();
2497 bool bFirst = true;
2498 std::optional<SfxItemSet> pFntCoreSet;
2499 SvtScriptType nScriptType = SvtScriptType::LATIN;
2500 SfxWhichIter aIter( rSet );
2501 sal_uInt16 nWhich = aIter.FirstWhich();
2502 while( nWhich )
2504 switch( nWhich )
2506 case RES_CHRATR_FONT:
2507 case RES_CHRATR_FONTSIZE:
2508 case RES_CHRATR_WEIGHT:
2509 case RES_CHRATR_POSTURE:
2511 if( !pFntCoreSet )
2513 pFntCoreSet.emplace( *rSet.GetPool(),
2514 svl::Items<RES_CHRATR_BEGIN, RES_CHRATR_END-1> );
2515 rSh.GetCurAttr( *pFntCoreSet );
2516 nScriptType = rSh.GetScriptType();
2517 // #i42732# input language should be preferred over
2518 // current cursor position to detect script type
2519 SwEditWin& rEditWin = GetView().GetEditWin();
2520 if( rEditWin.IsUseInputLanguage() )
2522 if(!rSh.HasSelection() && (
2523 nWhich == RES_CHRATR_FONT ||
2524 nWhich == RES_CHRATR_FONTSIZE ))
2526 LanguageType nInputLang = rEditWin.GetInputLanguage();
2527 if(nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
2528 nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
2532 SfxItemPool& rPool = *rSet.GetPool();
2533 SvxScriptSetItem aSetItem( rPool.GetSlotId( nWhich ), rPool );
2534 aSetItem.GetItemSet().Put( *pFntCoreSet, false );
2535 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScriptType );
2536 if( pI )
2538 rSet.Put( pI->CloneSetWhich(nWhich) );
2540 else
2541 rSet.InvalidateItem( nWhich );
2542 // Set input context of the SwEditWin according to the selected font and script type
2543 if(RES_CHRATR_FONT == nWhich)
2545 vcl::Font aFont;
2546 if (const SvxFontItem* pFontItem = dynamic_cast<const SvxFontItem*>(pI))
2548 aFont.SetFamilyName(pFontItem->GetFamilyName());
2549 aFont.SetStyleName(pFontItem->GetStyleName());
2550 aFont.SetFamily(pFontItem->GetFamily());
2551 aFont.SetPitch(pFontItem->GetPitch());
2552 aFont.SetCharSet(pFontItem->GetCharSet());
2555 bool bVertical = rSh.IsInVerticalText();
2556 aFont.SetOrientation(Degree10(bVertical ? 2700 : 0));
2557 aFont.SetVertical(bVertical);
2558 GetView().GetEditWin().SetInputContext( InputContext( aFont, InputContextFlags::Text |
2559 InputContextFlags::ExtText ) );
2562 break;
2564 default:
2565 if( bFirst )
2567 rSh.GetCurAttr( rSet );
2568 bFirst = false;
2571 nWhich = aIter.NextWhich();
2575 void SwBaseShell::GetBckColState(SfxItemSet &rSet)
2577 SwWrtShell &rSh = GetShell();
2578 SfxWhichIter aIter(rSet);
2579 sal_uInt16 nWhich(aIter.FirstWhich());
2580 SelectionType nSelType(rSh.GetSelectionType());
2581 std::unique_ptr<SvxBrushItem> aBrushItem(std::make_unique<SvxBrushItem>(RES_BACKGROUND));
2583 if( nWhich == SID_TABLE_CELL_BACKGROUND_COLOR )
2585 rSh.GetBoxBackground( aBrushItem );
2587 else
2589 // Adapt to new DrawingLayer FillStyle; use a parent which has XFILL_NONE set
2590 SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST> aCoreSet(GetPool());
2592 aCoreSet.SetParent(&GetView().GetDocShell()->GetDoc()->GetDfltFrameFormat()->GetAttrSet());
2594 if(nSelType & SelectionType::Graphic || SelectionType::Frame & nSelType)
2596 rSh.GetFlyFrameAttr(aCoreSet);
2598 else
2600 rSh.GetCurAttr(aCoreSet);
2603 aBrushItem = getSvxBrushItemFromSourceSet(aCoreSet, RES_BACKGROUND);
2606 while(nWhich)
2608 switch(nWhich)
2610 case SID_BACKGROUND_COLOR:
2611 case SID_TABLE_CELL_BACKGROUND_COLOR:
2613 SvxColorItem aColorItem(aBrushItem->GetColor(), aBrushItem->getComplexColor(), nWhich);
2614 rSet.Put(aColorItem);
2615 break;
2617 case SID_ATTR_BRUSH:
2618 case RES_BACKGROUND:
2620 // if this was intended to have a independent copy of the Item to be set
2621 // this is not needed due to the ItemSet/Pool cloning Items which get set anyways.
2622 // Keeping code as reference - it may have had other reasons I do notz see (?!?)
2623 // std::unique_ptr<SfxPoolItem> pNewItem(aBrushItem.CloneSetWhich(GetPool().GetWhich(nWhich)));
2624 rSet.Put(*aBrushItem);
2625 break;
2629 nWhich = aIter.NextWhich();
2633 void SwBaseShell::ExecBckCol(SfxRequest& rReq)
2635 SwWrtShell &rSh = GetShell();
2636 SelectionType nSelType(rSh.GetSelectionType());
2637 const SfxItemSet* pArgs = rReq.GetArgs();
2638 sal_uInt16 nSlot(rReq.GetSlot());
2640 if (!pArgs && nSlot != SID_BACKGROUND_COLOR && nSlot != SID_TABLE_CELL_BACKGROUND_COLOR)
2642 return;
2645 std::unique_ptr<SvxBrushItem> aBrushItem(std::make_unique<SvxBrushItem>(RES_BACKGROUND));
2647 if ( nSlot == SID_TABLE_CELL_BACKGROUND_COLOR )
2649 rSh.GetBoxBackground( aBrushItem );
2651 else
2653 // Adapt to new DrawingLayer FillStyle; use a parent which has XFILL_NONE set
2654 SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST> aCoreSet(GetPool());
2656 aCoreSet.SetParent(&GetView().GetDocShell()->GetDoc()->GetDfltFrameFormat()->GetAttrSet());
2658 if((SelectionType::Frame & nSelType) || (SelectionType::Graphic & nSelType))
2660 rSh.GetFlyFrameAttr(aCoreSet);
2662 else
2664 rSh.GetCurAttr(aCoreSet);
2667 aBrushItem = getSvxBrushItemFromSourceSet(aCoreSet, RES_BACKGROUND);
2670 switch(nSlot)
2672 case SID_BACKGROUND_COLOR:
2673 case SID_TABLE_CELL_BACKGROUND_COLOR:
2675 bool bIsTransparent = false;
2677 aBrushItem->SetGraphicPos(GPOS_NONE);
2679 sal_uInt16 nSlotId = (nSlot == SID_BACKGROUND_COLOR) ? SID_BACKGROUND_COLOR : SID_TABLE_CELL_BACKGROUND_COLOR;
2680 if (pArgs)
2682 const SvxColorItem& rNewColorItem = static_cast<const SvxColorItem&>(pArgs->Get(nSlotId));
2683 aBrushItem->SetColor(rNewColorItem.GetValue());
2684 aBrushItem->setComplexColor(rNewColorItem.getComplexColor());
2685 GetView().GetViewFrame().GetBindings().SetState(rNewColorItem);
2687 else
2689 bIsTransparent = true;
2692 if (bIsTransparent)
2694 aBrushItem->SetColor(COL_TRANSPARENT);
2695 rReq.AppendItem(SvxColorItem(COL_TRANSPARENT,nSlot));
2697 break;
2700 case SID_ATTR_BRUSH:
2701 case RES_BACKGROUND:
2703 assert(pArgs && "only SID_BACKGROUND_COLOR can have !pArgs, checked at entry");
2704 aBrushItem.reset(static_cast<SvxBrushItem*>(pArgs->Get(GetPool().GetWhich(nSlot)).Clone()));
2705 break;
2707 default:
2709 rReq.Ignore();
2710 OSL_FAIL("unknown message in ExecuteAttr!" );
2711 return;
2715 if ( nSlot == SID_TABLE_CELL_BACKGROUND_COLOR )
2717 rSh.SetBoxBackground( *aBrushItem );
2719 else
2721 // Adapt to new DrawingLayer FillStyle; use a parent which has XFILL_NONE set
2722 SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST> aCoreSet(GetPool());
2724 aCoreSet.SetParent(&GetView().GetDocShell()->GetDoc()->GetDfltFrameFormat()->GetAttrSet());
2725 setSvxBrushItemAsFillAttributesToTargetSet(*aBrushItem, aCoreSet);
2727 if((SelectionType::Frame & nSelType) || (SelectionType::Graphic & nSelType))
2729 // Template autoupdate
2730 SwFrameFormat* pFormat = rSh.GetSelectedFrameFormat();
2732 if(pFormat && pFormat->IsAutoUpdateOnDirectFormat())
2734 rSh.AutoUpdateFrame(pFormat, aCoreSet);
2736 else
2738 rSh.SetFlyFrameAttr(aCoreSet);
2741 else
2743 SwTextFormatColl* pColl = rSh.GetCurTextFormatColl();
2745 if(pColl && pColl->IsAutoUpdateOnDirectFormat())
2747 rSh.AutoUpdatePara(pColl, aCoreSet);
2749 else
2751 rSh.SetAttrSet(aCoreSet);
2756 rReq.Done();
2759 void SwBaseShell::GetBorderState(SfxItemSet &rSet)
2761 SwWrtShell &rSh = GetShell();
2762 // Table cell(s) selected?
2763 bool bPrepare = true;
2764 bool bTableMode = rSh.IsTableMode();
2765 if ( bTableMode )
2767 SfxItemSetFixed<RES_BOX, RES_BOX,
2768 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER> aCoreSet( GetPool() );
2769 SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
2770 aCoreSet.Put( aBoxInfo );
2771 rSh.GetTabBorders( aCoreSet );
2772 rSet.Put( aCoreSet );
2774 else if ( rSh.IsFrameSelected() )
2776 SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr );
2777 rSet.Put( aMgr.GetAttrSet() );
2778 bPrepare = false;
2780 else
2781 // Get border attributes via shell quite normal
2782 rSh.GetCurAttr( rSet );
2783 if ( bPrepare )
2784 ::PrepareBoxInfo( rSet, rSh );
2785 // Switch the border toolbox controller mode
2786 rSet.Put( SfxBoolItem( SID_BORDER_REDUCED_MODE, !bTableMode ));
2789 void SwBaseShell::ExecDlg(SfxRequest &rReq)
2791 SwWrtShell &rSh = GetShell();
2792 weld::Window* pMDI = GetView().GetFrameWeld();
2793 // So that from the basic no dialogues for the background views are called:
2794 bool bBackground = (&GetView() != GetActiveView());
2795 const SfxPoolItem* pItem = nullptr;
2796 const SfxItemSet* pArgs = rReq.GetArgs();
2798 sal_uInt16 nSlot = rReq.GetSlot();
2799 const SfxItemSet* pOutSet = nullptr;
2800 bool bDone = false;
2801 if(pArgs)
2802 pArgs->GetItemState( GetPool().GetWhich(nSlot), false, &pItem );
2804 switch ( nSlot )
2806 case FN_FORMAT_TITLEPAGE_DLG:
2808 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2809 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateTitlePageDlg(pMDI));
2810 VclAbstractDialog::AsyncContext aContext;
2811 aContext.maEndDialogFn = [](sal_Int32){};
2812 pDlg->StartExecuteAsync(aContext);
2814 break;
2815 case FN_FORMAT_PAGE_DLG:
2816 case FN_FORMAT_PAGE_COLUMN_DLG:
2817 case FN_FORMAT_PAGE_SETTING_DLG:
2818 case FN_FORMAT_PAGE_AREA_DLG:
2820 if( !bBackground )
2822 const size_t nCurIdx = rSh.GetCurPageDesc();
2823 const SwPageDesc& rPageDesc = rSh.GetPageDesc( nCurIdx );
2824 // Temporary view, because the shell does not need to be valid after the dialog
2825 // for example disable header
2826 SwView& rTempView = GetView();
2828 OUString sPageId;
2829 switch (nSlot)
2831 case FN_FORMAT_PAGE_COLUMN_DLG:
2832 sPageId = "columns";
2833 break;
2834 case FN_FORMAT_PAGE_SETTING_DLG:
2835 sPageId = "page";
2836 break;
2837 case FN_FORMAT_PAGE_AREA_DLG:
2838 sPageId = "area";
2839 break;
2840 case FN_FORMAT_PAGE_DLG:
2841 if (pItem)
2842 sPageId = static_cast<const SfxStringItem*>(pItem)->GetValue();
2843 break;
2845 rTempView.GetDocShell()->FormatPage(rReq.GetFrameWeld(), rPageDesc.GetName(), sPageId, rSh, &rReq);
2846 rTempView.InvalidateRulerPos();
2848 bDone = true; // FormatPage() takes care of calling Done()
2851 break;
2852 case FN_FORMAT_BORDER_DLG:
2854 SfxItemSetFixed<RES_BOX , RES_SHADOW,
2855 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER> aSet( rSh.GetAttrPool() );
2856 ScopedVclPtr<SfxAbstractDialog> pDlg;
2857 // Table cell(s) selected?
2858 if ( rSh.IsTableMode() )
2860 // Set border attributes Get/SetTabBorders()
2861 ::PrepareBoxInfo( aSet, rSh );
2862 rSh.GetTabBorders( aSet );
2863 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2864 pDlg.disposeAndReset(pFact->CreateSwBorderDlg(pMDI, aSet, SwBorderModes::TABLE));
2865 if ( pDlg->Execute() == RET_OK )
2867 rSh.SetTabBorders( *pDlg->GetOutputItemSet() );
2868 pOutSet = pDlg->GetOutputItemSet();
2871 else if ( rSh.IsFrameSelected() )
2873 // Set border attributes via Frame-Manager
2874 SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr );
2875 aSet.Put( aMgr.GetAttrSet() );
2877 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2878 pDlg.disposeAndReset(pFact->CreateSwBorderDlg(pMDI, aSet, SwBorderModes::FRAME));
2879 if ( pDlg->Execute() == RET_OK )
2881 aMgr.SetAttrSet( *pDlg->GetOutputItemSet() );
2882 aMgr.UpdateFlyFrame();
2883 pOutSet = pDlg->GetOutputItemSet();
2886 else
2888 // Set border attributes via Shell quite normal
2889 rSh.GetCurAttr( aSet );
2890 ::PrepareBoxInfo( aSet, rSh );
2892 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2893 pDlg.disposeAndReset(pFact->CreateSwBorderDlg(pMDI, aSet, SwBorderModes::PARA));
2894 if ( pDlg->Execute() == RET_OK )
2896 rSh.SetAttrSet( *pDlg->GetOutputItemSet() );
2897 pOutSet = pDlg->GetOutputItemSet();
2900 if(pOutSet)
2902 rReq.Done(*pOutSet);
2903 bDone = true;
2906 break;
2907 case FN_FORMAT_BACKGROUND_DLG:
2909 SfxItemSetFixed<RES_BACKGROUND, RES_BACKGROUND,
2910 XATTR_FILL_FIRST, XATTR_FILL_LAST> aSet( rSh.GetAttrPool() );
2912 ScopedVclPtr<SfxAbstractDialog> pDlg;
2913 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2915 // Table cell(s) selected?
2916 if ( rSh.IsTableMode() )
2918 // Get background attributes of the table and put it in the set
2919 // tdf#144843 calling GetBoxBackground *requires* an incarnation to be handed over
2920 std::unique_ptr<SvxBrushItem> aBrush(std::make_unique<SvxBrushItem>(RES_BACKGROUND));
2921 rSh.GetBoxBackground( aBrush );
2922 pDlg.disposeAndReset(pFact->CreateSwBackgroundDialog(pMDI, aSet));
2923 aSet.Put( std::move(aBrush) );
2924 if ( pDlg->Execute() == RET_OK )
2927 rSh.SetBoxBackground( pDlg->GetOutputItemSet()->Get( RES_BACKGROUND ) );
2928 pOutSet = pDlg->GetOutputItemSet();
2931 else if ( rSh.IsFrameSelected() )
2934 rSh.GetFlyFrameAttr( aSet );
2936 pDlg.disposeAndReset(pFact->CreateSwBackgroundDialog(pMDI, aSet));
2937 if ( pDlg->Execute() == RET_OK )
2939 rSh.SetFlyFrameAttr(const_cast<SfxItemSet &>(*pDlg->GetOutputItemSet()) );
2940 pOutSet = pDlg->GetOutputItemSet();
2943 else
2945 // Set border attributes Umrandungsattribute with the shell quite normal.
2946 rSh.GetCurAttr( aSet );
2948 pDlg.disposeAndReset(pFact->CreateSwBackgroundDialog(pMDI, aSet));
2949 if ( pDlg->Execute() == RET_OK )
2951 rSh.SetAttrSet( *pDlg->GetOutputItemSet() );
2952 pOutSet = pDlg->GetOutputItemSet();
2955 if(pOutSet)
2957 rReq.Done(*pOutSet);
2958 bDone = true;
2961 break;
2963 case SID_GRAPHIC_SIZE_CHECK:
2965 sw::GraphicSizeCheckGUIResult aResult(rSh.GetDoc());
2966 svx::GenericCheckDialog aDialog(pMDI, aResult);
2967 aDialog.run();
2969 break;
2971 case SID_THEME_DIALOG:
2973 auto* pDocument = rSh.GetDoc();
2974 auto* pDocumentShell = pDocument->GetDocShell();
2975 if (pDocumentShell)
2977 SdrPage* pPage = pDocument->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
2978 auto const& pTheme = pPage->getSdrPageProperties().GetTheme();
2979 if (pTheme)
2981 std::shared_ptr<svx::IThemeColorChanger> pChanger(new sw::ThemeColorChanger(pDocumentShell));
2982 auto pDialog = std::make_shared<svx::ThemeDialog>(pMDI, pTheme.get());
2983 weld::DialogController::runAsync(pDialog, [pDialog, pChanger](sal_uInt32 nResult) {
2984 if (RET_OK != nResult)
2985 return;
2987 auto pColorSet = pDialog->getCurrentColorSet();
2988 if (pColorSet)
2990 pChanger->apply(pColorSet);
2991 if (comphelper::LibreOfficeKit::isActive())
2993 svx::ThemeColorPaletteManager aManager(pColorSet);
2994 SfxLokHelper::notifyAllViews(LOK_CALLBACK_COLOR_PALETTES, aManager.generateJSON());
3001 break;
3003 default:OSL_FAIL("wrong Dispatcher (basesh.cxx)");
3005 if(!bDone)
3006 rReq.Done();
3009 SwWrtShell& SwBaseShell::GetShell()
3011 return m_rView.GetWrtShell();
3014 SwWrtShell* SwBaseShell::GetShellPtr()
3016 return m_rView.GetWrtShellPtr();
3019 static void EndUndo(SwWrtShell& rSh)
3021 SwRewriter aRewriter;
3023 if (rSh.GetTableFormat())
3025 aRewriter.AddRule(UndoArg1, SwResId(STR_START_QUOTE));
3026 aRewriter.AddRule(UndoArg2, rSh.GetTableFormat()->GetName());
3027 aRewriter.AddRule(UndoArg3, SwResId(STR_END_QUOTE));
3030 rSh.EndUndo(SwUndoId::INSTABLE, &aRewriter); // If possible change the Shell
3033 static void InsertTableImpl(SwWrtShell& rSh,
3034 SwView &rTempView,
3035 const OUString& aTableName,
3036 sal_uInt16 nRows,
3037 sal_uInt16 nCols,
3038 SwInsertTableOptions aInsTableOpts,
3039 const OUString& aAutoName,
3040 const std::unique_ptr<SwTableAutoFormat>& pTAFormat)
3042 rSh.StartUndo(SwUndoId::INSTABLE);
3044 rSh.StartAllAction();
3045 if( rSh.HasSelection() )
3046 rSh.DelRight();
3048 rSh.InsertTable( aInsTableOpts, nRows, nCols, pTAFormat.get() );
3049 rSh.MoveTable( GotoPrevTable, fnTableStart );
3051 if( !aTableName.isEmpty() && !rSh.GetTableStyle( aTableName ) )
3052 rSh.GetTableFormat()->SetFormatName( aTableName );
3054 if( pTAFormat != nullptr && !aAutoName.isEmpty()
3055 && aAutoName != SwViewShell::GetShellRes()->aStrNone )
3057 SwTableNode* pTableNode = const_cast<SwTableNode*>( rSh.IsCursorInTable() );
3058 if ( pTableNode )
3060 pTableNode->GetTable().SetTableStyleName( aAutoName );
3061 SwUndoTableAutoFormat* pUndo = new SwUndoTableAutoFormat( *pTableNode, *pTAFormat );
3062 if ( pUndo )
3063 rSh.GetIDocumentUndoRedo().AppendUndo( std::unique_ptr<SwUndo>(pUndo) );
3067 rSh.EndAllAction();
3068 rTempView.AutoCaption(TABLE_CAP);
3071 void SwBaseShell::InsertTable( SfxRequest& _rRequest )
3073 const SfxItemSet* pArgs = _rRequest.GetArgs();
3074 SwWrtShell& rSh = GetShell();
3076 if ( rSh.GetFrameType( nullptr, true ) & FrameTypeFlags::FOOTNOTE )
3077 return;
3079 SwView &rTempView = GetView(); // Because GetView() does not work after the shell exchange
3080 bool bHTMLMode = 0 != (::GetHtmlMode(rTempView.GetDocShell())&HTMLMODE_ON);
3081 bool bCallEndUndo = false;
3083 if( !pArgs && rSh.IsSelection() && !rSh.IsInClickToEdit() &&
3084 !rSh.IsTableMode() )
3086 const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
3087 SwInsertTableOptions aInsTableOpts = pModOpt->GetInsTableFlags(bHTMLMode);
3089 rSh.StartUndo(SwUndoId::INSTABLE);
3090 bCallEndUndo = true;
3092 bool bInserted = rSh.TextToTable( aInsTableOpts, '\t' );
3093 rSh.EnterStdMode();
3094 if (bInserted)
3095 rTempView.AutoCaption(TABLE_CAP);
3096 _rRequest.Done();
3098 else
3100 sal_uInt16 nColsIn = 0;
3101 sal_uInt16 nRowsIn = 0;
3102 SwInsertTableOptions aInsTableOptsIn( SwInsertTableFlags::All, 1 );
3103 OUString aTableNameIn;
3104 OUString aAutoNameIn;
3105 std::unique_ptr<SwTableAutoFormat> pTAFormatIn;
3107 if( pArgs && pArgs->Count() >= 2 )
3109 const SfxStringItem* pName = _rRequest.GetArg<SfxStringItem>(FN_INSERT_TABLE);
3110 const SfxUInt16Item* pCols = _rRequest.GetArg<SfxUInt16Item>(SID_ATTR_TABLE_COLUMN);
3111 const SfxUInt16Item* pRows = _rRequest.GetArg<SfxUInt16Item>(SID_ATTR_TABLE_ROW);
3112 const SfxInt32Item* pFlags = _rRequest.GetArg<SfxInt32Item>(FN_PARAM_1);
3113 const SfxStringItem* pAuto = _rRequest.GetArg<SfxStringItem>(FN_PARAM_2);
3115 if ( pName )
3116 aTableNameIn = pName->GetValue();
3117 if ( pCols )
3118 nColsIn = pCols->GetValue();
3119 if ( pRows )
3120 nRowsIn = pRows->GetValue();
3121 if ( pAuto )
3123 aAutoNameIn = pAuto->GetValue();
3124 if ( !aAutoNameIn.isEmpty() )
3126 SwTableAutoFormatTable aTableTable;
3127 aTableTable.Load();
3128 for ( size_t n=0; n<aTableTable.size(); n++ )
3130 if ( aTableTable[n].GetName() == aAutoNameIn )
3132 pTAFormatIn.reset(new SwTableAutoFormat( aTableTable[n] ));
3133 break;
3139 if ( pFlags )
3140 aInsTableOptsIn.mnInsMode = static_cast<SwInsertTableFlags>(pFlags->GetValue());
3141 else
3143 const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
3144 aInsTableOptsIn = pModOpt->GetInsTableFlags(bHTMLMode);
3148 if( !nColsIn || !nRowsIn )
3150 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
3151 std::shared_ptr<AbstractInsTableDlg> pAbstractDialog(pFact->CreateInsTableDlg(rTempView));
3152 std::shared_ptr<weld::DialogController> pDialogController(pAbstractDialog->getDialogController());
3154 weld::DialogController::runAsync(pDialogController,
3155 [pAbstractDialog, &rSh, &rTempView, aTableNameIn, nRowsIn, nColsIn, aInsTableOptsIn, aAutoNameIn] (sal_Int32 nResult) {
3156 if( RET_OK == nResult )
3158 sal_uInt16 nCols = nColsIn;
3159 sal_uInt16 nRows = nRowsIn;
3160 SwInsertTableOptions aInsTableOpts = aInsTableOptsIn;
3161 OUString aTableName = aTableNameIn;
3162 OUString aAutoName = aAutoNameIn;
3163 std::unique_ptr<SwTableAutoFormat> pTAFormat;
3165 pAbstractDialog->GetValues( aTableName, nRows, nCols, aInsTableOpts, aAutoName, pTAFormat );
3167 if( nCols && nRows )
3169 InsertTableImpl( rSh, rTempView, aTableName, nRows, nCols, aInsTableOpts, aAutoName, pTAFormat );
3170 EndUndo(rSh);
3176 else
3178 // record before shell change
3179 _rRequest.AppendItem( SfxStringItem( FN_INSERT_TABLE, aTableNameIn ) );
3180 if ( !aAutoNameIn.isEmpty() )
3181 _rRequest.AppendItem( SfxStringItem( FN_PARAM_2, aAutoNameIn ) );
3182 _rRequest.AppendItem( SfxUInt16Item( SID_ATTR_TABLE_COLUMN, nColsIn ) );
3183 _rRequest.AppendItem( SfxUInt16Item( SID_ATTR_TABLE_ROW, nRowsIn ) );
3184 _rRequest.AppendItem( SfxInt32Item( FN_PARAM_1, static_cast<sal_Int32>(aInsTableOptsIn.mnInsMode) ) );
3185 _rRequest.Done();
3187 InsertTableImpl( rSh, rTempView, aTableNameIn, nRowsIn, nColsIn, aInsTableOptsIn, aAutoNameIn, pTAFormatIn );
3189 bCallEndUndo = true;
3193 if( bCallEndUndo )
3194 EndUndo(rSh);
3197 void SwBaseShell::GetGalleryState( SfxItemSet &rSet )
3199 SwWrtShell &rSh = GetShell();
3200 SfxWhichIter aIter( rSet );
3201 sal_uInt16 nWhich = aIter.FirstWhich();
3202 switch ( nWhich )
3204 case SID_GALLERY_BG_BRUSH:
3206 SelectionType nSel = rSh.GetSelectionType();
3207 SfxStringListItem aLst( nWhich );
3208 std::vector<OUString> &rLst = aLst.GetList();
3209 nParagraphPos = nGraphicPos = nOlePos = nFramePos = nTablePos =
3210 nTableRowPos = nTableCellPos = nPagePos =
3211 nHeaderPos = nFooterPos = 0;
3212 sal_uInt8 nPos = 1;
3213 rLst.push_back( SwResId( STR_SWBG_PAGE ) );
3214 nPagePos = nPos++;
3215 sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
3216 bool bHtmlMode = 0 != (nHtmlMode & HTMLMODE_ON);
3218 if ( (!bHtmlMode || (nHtmlMode & HTMLMODE_FULL_STYLES)) &&
3219 (nSel & SelectionType::Text) )
3221 rLst.push_back( SwResId( STR_SWBG_PARAGRAPH ) );
3222 nParagraphPos = nPos++;
3224 if ( (!bHtmlMode || (nHtmlMode & HTMLMODE_SOME_STYLES)) &&
3225 nSel & (SelectionType::Table|SelectionType::TableCell) )
3227 rLst.push_back( SwResId( STR_SWBG_TABLE ) );
3228 nTablePos = nPos++;
3230 if(!bHtmlMode)
3232 rLst.push_back( SwResId( STR_SWBG_TABLE_ROW ) );
3233 nTableRowPos = nPos++;
3236 rLst.push_back( SwResId( STR_SWBG_TABLE_CELL) );
3237 nTableCellPos = nPos++;
3239 if(!bHtmlMode)
3241 if ( nSel & SelectionType::Frame )
3243 rLst.push_back( SwResId( STR_SWBG_FRAME ) );
3244 nFramePos = nPos++;
3246 if ( nSel & SelectionType::Graphic )
3248 rLst.push_back( SwResId( STR_SWBG_GRAPHIC ) );
3249 nGraphicPos = nPos++;
3251 if ( nSel & SelectionType::Ole )
3253 rLst.push_back( SwResId( STR_SWBG_OLE ) );
3254 nOlePos = nPos++;
3256 const FrameTypeFlags nType = rSh.GetFrameType(nullptr,true);
3257 if ( nType & FrameTypeFlags::HEADER )
3259 rLst.push_back( SwResId( STR_SWBG_HEADER ) );
3260 nHeaderPos = nPos++;
3262 if ( nType & FrameTypeFlags::FOOTER )
3264 rLst.push_back( SwResId( STR_SWBG_FOOTER ) );
3265 nFooterPos = nPos;
3268 if ( rLst.empty() )
3269 rSet.DisableItem( nWhich );
3270 else
3271 rSet.Put( aLst );
3272 break;
3277 void SwBaseShell::ExecuteGallery(SfxRequest &rReq)
3279 SwWrtShell &rSh = GetShell();
3280 rSh.StartAction();
3281 const SfxItemSet* pArgs = rReq.GetArgs();
3282 sal_uInt16 nSlot = rReq.GetSlot();
3283 switch(nSlot)
3285 case SID_GALLERY_BG_BRUSH:
3287 if ( !pArgs )
3288 break;
3290 SelectionType nSel = rSh.GetSelectionType();
3291 if ( nSel & SelectionType::DrawObjectEditMode )
3292 break;
3294 const SfxUInt16Item* pPos = rReq.GetArg<SfxUInt16Item>(SID_GALLERY_BG_POS);
3295 const SvxBrushItem* pBrush = rReq.GetArg<SvxBrushItem>(SID_GALLERY_BG_BRUSH);
3296 if ( !pPos || !pBrush )
3297 break;
3299 sal_uInt8 nPos = pPos->GetValue();
3300 ++nPos;
3302 SvxBrushItem aBrush( *pBrush );
3303 aBrush.SetWhich( RES_BACKGROUND );
3304 if ( nPos == nParagraphPos )
3305 rSh.SetAttrItem( aBrush );
3306 else if ( nPos == nTablePos )
3307 rSh.SetTabBackground( aBrush );
3308 else if ( nPos == nTableRowPos )
3309 rSh.SetRowBackground( aBrush );
3310 else if ( nPos == nTableCellPos )
3311 rSh.SetBoxBackground( aBrush );
3312 else if ( nPos == nFramePos || nPos == nGraphicPos || nPos == nOlePos )
3314 SfxItemSetFixed<RES_BACKGROUND, RES_BACKGROUND> aCoreSet(GetPool());
3315 aCoreSet.Put( aBrush );
3316 rSh.SetFlyFrameAttr( aCoreSet );
3318 else if ( nPos == nPagePos || nPos == nHeaderPos || nPos == nFooterPos )
3320 sal_uInt16 nDesc = rSh.GetCurPageDesc();
3321 SwPageDesc aDesc( rSh.GetPageDesc( nDesc ) );
3322 if ( nPos == nPagePos )
3323 aDesc.GetMaster().SetFormatAttr( aBrush );
3324 else if ( nPos == nHeaderPos )
3326 SwFormatHeader aHead( aDesc.GetMaster().GetHeader() );
3327 aHead.GetHeaderFormat()->SetFormatAttr( aBrush );
3328 aDesc.GetMaster().SetFormatAttr( aHead );
3330 else if ( nPos == nFooterPos )
3332 SwFormatFooter aFoot( aDesc.GetMaster().GetFooter() );
3333 aFoot.GetFooterFormat()->SetFormatAttr( aBrush );
3334 aDesc.GetMaster().SetFormatAttr( aFoot );
3336 rSh.ChgPageDesc( nDesc, aDesc );
3338 break;
3341 rSh.EndAction();
3342 rReq.Done();
3345 void SwBaseShell::ExecField( SfxRequest const & rReq )
3347 sal_uInt16 nSlot = rReq.GetSlot();
3348 switch( nSlot )
3350 #if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
3351 case FN_CHANGE_DBFIELD:
3353 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
3354 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSwChangeDBDlg(GetView()));
3355 pDlg->Execute();
3357 break;
3358 #endif
3359 default:
3360 OSL_FAIL("wrong dispatcher");
3364 std::shared_ptr<std::vector<std::unique_ptr<SwPaM>>> SwBaseShell::CopyPaMRing(SwPaM& rOrig)
3366 auto vCursors = std::make_shared<std::vector<std::unique_ptr<SwPaM>>>();
3367 vCursors->emplace_back(std::make_unique<SwPaM>(rOrig, nullptr));
3368 for (auto& rCursor : rOrig.GetRingContainer())
3370 if (&rCursor != &rOrig)
3371 vCursors->emplace_back(std::make_unique<SwPaM>(rCursor, vCursors->front().get()));
3373 return vCursors;
3376 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */