"Update all" should do a full reformatting
[LibreOffice.git] / sw / source / uibase / shells / basesh.cxx
blob3732a1de05c118729cd972edac1256b521c8a353
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>
22 #include <sal/config.h>
24 #include <hintids.hxx>
25 #include <svl/languageoptions.hxx>
26 #include <sfx2/linkmgr.hxx>
27 #include <sfx2/htmlmode.hxx>
28 #include <svx/imapdlg.hxx>
29 #include <sfx2/dispatch.hxx>
30 #include <sfx2/viewfrm.hxx>
31 #include <sfx2/request.hxx>
32 #include <svl/whiter.hxx>
33 #include <svl/visitem.hxx>
34 #include <editeng/langitem.hxx>
35 #include <svx/clipfmtitem.hxx>
36 #include <svx/contdlg.hxx>
37 #include <vcl/graph.hxx>
38 #include <vcl/inputctx.hxx>
39 #include <svl/slstitm.hxx>
40 #include <svl/ptitem.hxx>
41 #include <svl/stritem.hxx>
42 #include <editeng/colritem.hxx>
43 #include <editeng/fhgtitem.hxx>
44 #include <editeng/fontitem.hxx>
45 #include <editeng/shaditem.hxx>
46 #include <editeng/boxitem.hxx>
47 #include <editeng/brushitem.hxx>
48 #include <editeng/opaqitem.hxx>
49 #include <editeng/sizeitem.hxx>
50 #include <svx/flagsdef.hxx>
51 #include <editeng/scripttypeitem.hxx>
52 #include <sfx2/objface.hxx>
53 #include <fmturl.hxx>
54 #include <fmthdft.hxx>
55 #include <fmtclds.hxx>
56 #include <docsh.hxx>
57 #include <wrtsh.hxx>
58 #include <view.hxx>
59 #include <swmodule.hxx>
60 #include <swundo.hxx>
61 #include <fldbas.hxx>
62 #include <uitool.hxx>
63 #include <basesh.hxx>
64 #include <viewopt.hxx>
65 #include <fontcfg.hxx>
66 #include <fmtsrnd.hxx>
67 #include <fldmgr.hxx>
68 #include <frmmgr.hxx>
69 #include <tablemgr.hxx>
70 #include <mdiexp.hxx>
71 #include <swdtflvr.hxx>
72 #include <pagedesc.hxx>
73 #include <fmtcol.hxx>
74 #include <edtwin.hxx>
75 #include <tblafmt.hxx>
76 #include <swwait.hxx>
77 #include <cmdid.h>
78 #include <strings.hrc>
79 #include <unotxdoc.hxx>
80 #include <doc.hxx>
81 #include <IDocumentSettingAccess.hxx>
82 #include <IDocumentUndoRedo.hxx>
83 #include <swabstdlg.hxx>
84 #include <modcfg.hxx>
85 #include <svx/fmshell.hxx>
86 #include <SwRewriter.hxx>
87 #include <svx/galleryitem.hxx>
88 #include <svx/devtools/DevelopmentToolChildWindow.hxx>
89 #include <com/sun/star/gallery/GalleryItemType.hpp>
90 #include <memory>
92 #include <svx/unobrushitemhelper.hxx>
93 #include <comphelper/scopeguard.hxx>
94 #include <comphelper/lok.hxx>
96 #include <svx/svxdlg.hxx>
98 #include <shellres.hxx>
99 #include <UndoTable.hxx>
101 FlyMode SwBaseShell::eFrameMode = FLY_DRAG_END;
103 // These variables keep the state of Gallery (slot SID_GALLERY_BG_BRUSH)
104 // detected by GetGalleryState() for the subsequent ExecuteGallery() call.
106 static sal_uInt8 nParagraphPos;
107 static sal_uInt8 nGraphicPos;
108 static sal_uInt8 nOlePos;
109 static sal_uInt8 nFramePos;
110 static sal_uInt8 nTablePos;
111 static sal_uInt8 nTableRowPos;
112 static sal_uInt8 nTableCellPos;
113 static sal_uInt8 nPagePos;
114 static sal_uInt8 nHeaderPos;
115 static sal_uInt8 nFooterPos;
117 #define ShellClass_SwBaseShell
118 #include <sfx2/msg.hxx>
119 #include <swslots.hxx>
121 #include <AccessibilityCheck.hxx>
122 #include <svx/AccessibilityCheckDialog.hxx>
124 namespace
126 SvxContourDlg* GetContourDlg(SwView const &rView)
128 SfxChildWindow *pWnd = rView.GetViewFrame()->GetChildWindow(SvxContourDlgChildWindow::GetChildWindowId());
129 return pWnd ? static_cast<SvxContourDlg*>(pWnd->GetController().get()) : nullptr;
132 SvxIMapDlg* GetIMapDlg(SwView const &rView)
134 SfxChildWindow* pWnd = rView.GetViewFrame()->GetChildWindow(SvxIMapDlgChildWindow::GetChildWindowId());
135 return pWnd ? static_cast<SvxIMapDlg*>(pWnd->GetController().get()) : nullptr;
139 using namespace ::com::sun::star;
140 using namespace ::com::sun::star::uno;
141 using namespace ::com::sun::star::frame;
142 using namespace ::com::sun::star::lang;
144 SFX_IMPL_SUPERCLASS_INTERFACE(SwBaseShell, SfxShell)
146 void SwBaseShell::InitInterface_Impl()
148 GetStaticInterface()->RegisterChildWindow(SvxIMapDlgChildWindow::GetChildWindowId());
149 GetStaticInterface()->RegisterChildWindow(SvxContourDlgChildWindow::GetChildWindowId());
150 GetStaticInterface()->RegisterChildWindow(DevelopmentToolChildWindow::GetChildWindowId());
153 static void lcl_UpdateIMapDlg( SwWrtShell& rSh )
155 Graphic aGrf( rSh.GetIMapGraphic() );
156 GraphicType nGrfType = aGrf.GetType();
157 void* pEditObj = GraphicType::NONE != nGrfType && GraphicType::Default != nGrfType
158 ? rSh.GetIMapInventor() : nullptr;
159 std::unique_ptr<TargetList> pList(new TargetList);
160 SfxFrame::GetDefaultTargetList(*pList);
162 SfxItemSet aSet( rSh.GetAttrPool(), svl::Items<RES_URL, RES_URL>{} );
163 rSh.GetFlyFrameAttr( aSet );
164 const SwFormatURL &rURL = aSet.Get( RES_URL );
165 SvxIMapDlgChildWindow::UpdateIMapDlg(
166 aGrf, rURL.GetMap(), pList.get(), pEditObj );
169 static bool lcl_UpdateContourDlg( SwWrtShell &rSh, SelectionType nSel )
171 Graphic aGraf( rSh.GetIMapGraphic() );
172 GraphicType nGrfType = aGraf.GetType();
173 bool bRet = GraphicType::NONE != nGrfType && GraphicType::Default != nGrfType;
174 if( bRet )
176 OUString aGrfName;
177 if ( nSel & SelectionType::Graphic )
178 rSh.GetGrfNms( &aGrfName, nullptr );
180 SvxContourDlg *pDlg = GetContourDlg(rSh.GetView());
181 if (pDlg)
183 pDlg->Update(aGraf, !aGrfName.isEmpty(),
184 rSh.GetGraphicPolygon(), rSh.GetIMapInventor());
187 return bRet;
190 void SwBaseShell::ExecDelete(SfxRequest &rReq)
192 SwWrtShell &rSh = GetShell();
193 SwEditWin& rTmpEditWin = GetView().GetEditWin();
194 switch(rReq.GetSlot())
196 case SID_DELETE:
197 rSh.DelRight();
198 break;
200 case FN_BACKSPACE:
202 if( rSh.IsNoNum() )
204 rSh.SttCursorMove();
205 bool bLeft = rSh.Left( CRSR_SKIP_CHARS, true, 1, false );
206 if( bLeft )
208 rSh.DelLeft();
210 else
211 // JP 15.07.96: If it no longer goes forward, cancel
212 // the numbering. For example at the beginning
213 // of a doc, frame, table or an area.
214 rSh.DelNumRules();
216 rSh.EndCursorMove();
217 break;
220 [[fallthrough]]; // otherwise call DelLeft
221 case FN_SHIFT_BACKSPACE:
222 rSh.DelLeft();
223 break;
224 default:
225 OSL_FAIL("wrong Dispatcher");
226 return;
228 rReq.Done();
230 //#i42732# - notify the edit window that from now on we do not use the input language
231 rTmpEditWin.SetUseInputLanguage( false );
234 void SwBaseShell::ExecClpbrd(SfxRequest &rReq)
236 // Attention: At risk of suicide!
237 // After paste, paste special the shell can be destroy.
239 SwWrtShell &rSh = GetShell();
240 sal_uInt16 nId = rReq.GetSlot();
241 bool bIgnore = false;
242 PasteTableType ePasteTable = PasteTableType::PASTE_DEFAULT;
244 switch( nId )
246 case SID_CUT:
247 case SID_COPY:
248 rView.GetEditWin().FlushInBuffer();
249 if ( rSh.HasSelection() )
251 rtl::Reference<SwTransferable> pTransfer = new SwTransferable( rSh );
253 if ( nId == SID_CUT && FlyProtectFlags::NONE == rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent) )
254 pTransfer->Cut();
255 else
257 const bool bLockedView = rSh.IsViewLocked();
258 rSh.LockView( true ); //lock visible section
259 pTransfer->Copy();
260 rSh.LockView( bLockedView );
262 break;
264 return;
266 case FN_PASTE_NESTED_TABLE:
267 case FN_TABLE_PASTE_ROW_BEFORE:
268 case FN_TABLE_PASTE_COL_BEFORE:
269 switch ( nId )
271 case FN_PASTE_NESTED_TABLE:
272 ePasteTable = PasteTableType::PASTE_TABLE;
273 break;
274 case FN_TABLE_PASTE_ROW_BEFORE:
275 ePasteTable = PasteTableType::PASTE_ROW;
276 break;
277 case FN_TABLE_PASTE_COL_BEFORE:
278 ePasteTable = PasteTableType::PASTE_COLUMN;
279 break;
280 default:
283 [[fallthrough]];
284 case SID_PASTE:
286 TransferableDataHelper aDataHelper(
287 TransferableDataHelper::CreateFromSystemClipboard( &rSh.GetView().GetEditWin() ) );
288 if( aDataHelper.GetXTransferable().is()
289 && SwTransferable::IsPaste( rSh, aDataHelper ) )
291 // Temporary variables, because the shell could already be
292 // destroyed after the paste.
293 SwView* pView = &rView;
295 RndStdIds nAnchorType = RndStdIds::FLY_AT_PARA;
296 const SfxUInt16Item* pAnchorType = rReq.GetArg<SfxUInt16Item>(FN_PARAM_1);
297 if (pAnchorType)
298 nAnchorType = static_cast<RndStdIds>(pAnchorType->GetValue());
299 bool bIgnoreComments = false;
300 const SfxBoolItem* pIgnoreComments = rReq.GetArg<SfxBoolItem>(FN_PARAM_2);
301 if (pIgnoreComments)
302 bIgnoreComments = pIgnoreComments->GetValue();
303 SwTransferable::Paste(rSh, aDataHelper, nAnchorType, bIgnoreComments, ePasteTable);
305 if( rSh.IsFrameSelected() || rSh.IsObjSelected() )
306 rSh.EnterSelFrameMode();
307 pView->AttrChangedNotify(nullptr);
309 else
310 return;
312 break;
314 case SID_CLIPBOARD_FORMAT_ITEMS:
316 const SfxItemSet* pArgs = rReq.GetArgs();
317 const SfxPoolItem* pFormat;
318 if( pArgs && SfxItemState::SET == pArgs->GetItemState( nId, false, &pFormat ) )
320 TransferableDataHelper aDataHelper(
321 TransferableDataHelper::CreateFromSystemClipboard(
322 &rSh.GetView().GetEditWin()) );
323 if( aDataHelper.GetXTransferable().is()
324 /*&& SwTransferable::IsPaste( rSh, aDataHelper )*/ )
326 // Temporary variables, because the shell could already be
327 // destroyed after the paste.
328 SwView* pView = &rView;
330 SwTransferable::PasteFormat( rSh, aDataHelper,
331 static_cast<SotClipboardFormatId>(static_cast<const SfxUInt32Item*>(pFormat)->GetValue()) );
333 //Done() has to be called before the shell has been removed
334 rReq.Done();
335 bIgnore = true;
336 if( rSh.IsFrameSelected() || rSh.IsObjSelected())
337 rSh.EnterSelFrameMode();
338 pView->AttrChangedNotify(nullptr);
342 break;
344 case SID_PASTE_UNFORMATTED:
346 TransferableDataHelper aDataHelper(
347 TransferableDataHelper::CreateFromSystemClipboard( &rSh.GetView().GetEditWin()) );
348 if( aDataHelper.GetXTransferable().is()
349 && SwTransferable::IsPaste( rSh, aDataHelper ) )
351 // Temporary variables, because the shell could already be
352 // destroyed after the paste.
353 SwView* pView = &rView;
354 rReq.Ignore();
355 bIgnore = true;
356 if(SwTransferable::PasteUnformatted( rSh, aDataHelper ))
358 SfxViewFrame* pViewFrame = pView->GetViewFrame();
359 uno::Reference< frame::XDispatchRecorder > xRecorder =
360 pViewFrame->GetBindings().GetRecorder();
361 if(xRecorder.is()) {
362 SfxRequest aReq( pViewFrame, SID_CLIPBOARD_FORMAT_ITEMS );
363 aReq.AppendItem( SfxUInt32Item( SID_CLIPBOARD_FORMAT_ITEMS, static_cast<sal_uInt32>(SotClipboardFormatId::STRING) ) );
364 aReq.Done();
368 if (rSh.IsFrameSelected() || rSh.IsObjSelected())
369 rSh.EnterSelFrameMode();
370 pView->AttrChangedNotify(nullptr);
372 else
373 return;
375 break;
377 case SID_PASTE_SPECIAL:
379 std::shared_ptr<TransferableDataHelper> aDataHelper =
380 std::make_shared<TransferableDataHelper>(TransferableDataHelper::CreateFromSystemClipboard( &rSh.GetView().GetEditWin()));
382 if( aDataHelper->GetXTransferable().is()
383 && SwTransferable::IsPaste( rSh, *aDataHelper )
384 && !rSh.CursorInsideInputField() )
386 rReq.Ignore();
387 bIgnore = true;
389 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
390 VclPtr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog( rReq.GetFrameWeld() ));
392 // Prepare the dialog
393 SwTransferable::PrePasteSpecial(rSh, *aDataHelper, pDlg);
394 pDlg->PreGetFormat(*aDataHelper);
397 pDlg->StartExecuteAsync([aDataHelper, pDlg, &rSh, this](sal_Int32 nResult){
398 if (nResult == RET_OK)
400 // Temporary variables, because the shell could already be
401 // destroyed after the paste.
402 SwView* pView = &rView;
403 bool bRet = false;
404 SotClipboardFormatId nFormatId = pDlg->GetFormatOnly();
406 if( nFormatId != SotClipboardFormatId::NONE )
407 bRet = SwTransferable::PasteFormat( rSh, *aDataHelper, nFormatId );
409 if (bRet)
411 SfxViewFrame* pViewFrame = pView->GetViewFrame();
412 uno::Reference< frame::XDispatchRecorder > xRecorder =
413 pViewFrame->GetBindings().GetRecorder();
414 if(xRecorder.is()) {
415 SfxRequest aReq( pViewFrame, SID_CLIPBOARD_FORMAT_ITEMS );
416 aReq.AppendItem( SfxUInt32Item( SID_CLIPBOARD_FORMAT_ITEMS, static_cast<sal_uInt32>(nFormatId) ) );
417 aReq.Done();
421 if (rSh.IsFrameSelected() || rSh.IsObjSelected())
422 rSh.EnterSelFrameMode();
423 pView->AttrChangedNotify(nullptr);
426 pDlg->disposeOnce();
430 else
431 return;
433 break;
435 default:
436 OSL_FAIL("wrong Dispatcher");
437 return;
439 if(!bIgnore)
440 rReq.Done();
443 // ClipBoard state
445 void SwBaseShell::StateClpbrd(SfxItemSet &rSet)
447 SwWrtShell &rSh = GetShell();
448 SfxWhichIter aIter(rSet);
450 const bool bCopy = rSh.HasSelection();
452 sal_uInt16 nWhich = aIter.FirstWhich();
454 while(nWhich)
456 switch(nWhich)
458 case SID_CUT:
459 if( FlyProtectFlags::NONE != rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent ) )
461 rSet.DisableItem( nWhich );
462 break;
464 [[fallthrough]];
465 case SID_COPY:
466 if( !bCopy || GetObjectShell()->isContentExtractionLocked())
467 rSet.DisableItem( nWhich );
468 break;
470 case FN_PASTE_NESTED_TABLE:
471 case FN_TABLE_PASTE_ROW_BEFORE:
472 case FN_TABLE_PASTE_COL_BEFORE:
473 if( !rSh.IsCursorInTable()
474 || !GetView().IsPasteSpecialAllowed()
475 || rSh.CursorInsideInputField()
476 // disable if not a native Writer table and not a spreadsheet format
477 || !GetView().IsPasteSpreadsheet(rSh.GetTableCopied()) )
479 rSet.DisableItem( nWhich );
481 break;
483 case SID_PASTE:
484 if( !GetView().IsPasteAllowed() )
486 rSet.DisableItem( nWhich );
488 break;
490 case SID_PASTE_SPECIAL:
491 if( !GetView().IsPasteSpecialAllowed()
492 || rSh.CursorInsideInputField() )
494 rSet.DisableItem( nWhich );
496 break;
498 case SID_PASTE_UNFORMATTED:
499 if( !GetView().IsPasteSpecialAllowed() )
501 rSet.DisableItem( nWhich );
503 break;
505 case SID_CLIPBOARD_FORMAT_ITEMS:
507 TransferableDataHelper aDataHelper(
508 TransferableDataHelper::CreateFromSystemClipboard(
509 &rSh.GetView().GetEditWin()) );
511 SvxClipboardFormatItem aFormatItem( nWhich );
512 SwTransferable::FillClipFormatItem( rSh, aDataHelper, aFormatItem );
513 rSet.Put( aFormatItem );
515 break;
517 nWhich = aIter.NextWhich();
521 // Perform undo
523 void SwBaseShell::ExecUndo(SfxRequest &rReq)
525 SwWrtShell &rWrtShell = GetShell();
527 SwUndoId nUndoId(SwUndoId::EMPTY);
528 sal_uInt16 nId = rReq.GetSlot(), nCnt = 1;
529 const SfxItemSet* pArgs = rReq.GetArgs();
530 const SfxPoolItem* pItem;
531 if( pArgs && SfxItemState::SET == pArgs->GetItemState( nId, false, &pItem ))
532 nCnt = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
534 // Repair mode: allow undo/redo of all undo actions, even if access would
535 // be limited based on the view shell ID.
536 bool bRepair = false;
537 if (pArgs && pArgs->GetItemState(SID_REPAIRPACKAGE, false, &pItem) == SfxItemState::SET)
538 bRepair = static_cast<const SfxBoolItem*>(pItem)->GetValue();
540 // #i106349#: save pointer: undo/redo may delete the shell, i.e., this!
541 SfxViewFrame *const pViewFrame( GetView().GetViewFrame() );
543 IDocumentUndoRedo& rUndoRedo = rWrtShell.GetIDocumentUndoRedo();
544 bool bWasRepair = rUndoRedo.DoesRepair();
545 rUndoRedo.DoRepair(bRepair);
546 comphelper::ScopeGuard aGuard([&rUndoRedo, bWasRepair]()
548 rUndoRedo.DoRepair(bWasRepair);
551 switch( nId )
553 case SID_UNDO:
554 if (rUndoRedo.GetLastUndoInfo(nullptr, &nUndoId, &rWrtShell.GetView()))
556 for (SwViewShell& rShell : rWrtShell.GetRingContainer())
557 rShell.LockPaint();
558 rWrtShell.Do( SwWrtShell::UNDO, nCnt );
559 for (SwViewShell& rShell : rWrtShell.GetRingContainer())
560 rShell.UnlockPaint();
562 break;
564 case SID_REDO:
565 if (rUndoRedo.GetFirstRedoInfo(nullptr, &nUndoId, &rWrtShell.GetView()))
567 for (SwViewShell& rShell : rWrtShell.GetRingContainer())
568 rShell.LockPaint();
569 rWrtShell.Do( SwWrtShell::REDO, nCnt );
570 for (SwViewShell& rShell : rWrtShell.GetRingContainer())
571 rShell.UnlockPaint();
573 break;
575 case SID_REPEAT:
576 rWrtShell.Do( SwWrtShell::REPEAT );
577 break;
578 default:
579 OSL_FAIL("wrong Dispatcher");
582 if (nUndoId == SwUndoId::CONFLICT)
584 rReq.SetReturnValue( SfxUInt32Item(nId, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
586 else if (nUndoId == SwUndoId::INSFMTATTR)
588 rWrtShell.GetDoc()->GetDocShell()->GetStyleSheetPool()->Broadcast(SfxHint(SfxHintId::StyleSheetModified));
591 if (pViewFrame) { pViewFrame->GetBindings().InvalidateAll(false); }
594 // State of undo
596 void SwBaseShell::StateUndo(SfxItemSet &rSet)
598 SwUndoId nUndoId(SwUndoId::EMPTY);
599 SwWrtShell &rSh = GetShell();
600 SfxWhichIter aIter(rSet);
601 sal_uInt16 nWhich = aIter.FirstWhich();
602 while(nWhich)
604 switch(nWhich)
606 case SID_UNDO:
608 if (rSh.GetLastUndoInfo(nullptr, &nUndoId, &rSh.GetView()))
610 rSet.Put( SfxStringItem(nWhich,
611 rSh.GetDoString(SwWrtShell::UNDO)));
613 else if (nUndoId == SwUndoId::CONFLICT)
615 rSet.Put( SfxUInt32Item(nWhich, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
617 else
618 rSet.DisableItem(nWhich);
620 break;
622 case SID_REDO:
624 if (rSh.GetFirstRedoInfo(nullptr, &nUndoId, &rSh.GetView()))
626 rSet.Put(SfxStringItem(nWhich,
627 rSh.GetDoString(SwWrtShell::REDO)));
629 else if (nUndoId == SwUndoId::CONFLICT)
631 rSet.Put( SfxInt32Item(nWhich, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
633 else
634 rSet.DisableItem(nWhich);
635 break;
637 case SID_REPEAT:
638 { // Repeat is only possible if no REDO is possible - UI-Restriction
639 if ((!rSh.GetFirstRedoInfo(nullptr, nullptr)) &&
640 !rSh.IsSelFrameMode() &&
641 (SwUndoId::EMPTY != rSh.GetRepeatInfo(nullptr)))
643 rSet.Put(SfxStringItem(nWhich, rSh.GetRepeatString()));
645 else
646 rSet.DisableItem(nWhich);
647 break;
650 case SID_GETUNDOSTRINGS:
651 if (rSh.GetLastUndoInfo(nullptr, nullptr))
653 SfxStringListItem aStrLst( nWhich );
654 rSh.GetDoStrings( SwWrtShell::UNDO, aStrLst );
655 rSet.Put( aStrLst );
657 else
658 rSet.DisableItem( nWhich );
659 break;
661 case SID_GETREDOSTRINGS:
662 if (rSh.GetFirstRedoInfo(nullptr, nullptr))
664 SfxStringListItem aStrLst( nWhich );
665 rSh.GetDoStrings( SwWrtShell::REDO, aStrLst );
666 rSet.Put( aStrLst );
668 else
669 rSet.DisableItem( nWhich );
670 break;
672 nWhich = aIter.NextWhich();
676 // Evaluate respectively dispatching the slot Id
678 void SwBaseShell::Execute(SfxRequest &rReq)
680 const SfxPoolItem *pItem;
681 SwWrtShell &rSh = GetShell();
682 const SfxItemSet* pArgs = rReq.GetArgs();
683 bool bMore = false;
685 sal_uInt16 nSlot = rReq.GetSlot();
686 switch(nSlot)
688 case FN_REPAGINATE:
690 Reference < XModel > xModel = GetView().GetDocShell()->GetModel();
691 auto pDoc = comphelper::getUnoTunnelImplementation<SwXTextDocument>(xModel);
692 pDoc->NotifyRefreshListeners();
693 rSh.CalcLayout();
695 break;
696 case FN_UPDATE_FIELDS:
698 rSh.UpdateDocStat();
699 rSh.EndAllTableBoxEdit();
700 rSh.SwViewShell::UpdateFields(true);
702 if( rSh.IsCursorInTable() )
704 if( !rSh.IsTableComplexForChart() )
705 SwTableFUNC( &rSh ).UpdateChart();
706 rSh.ClearTableBoxContent();
707 rSh.SaveTableBoxContent();
710 break;
711 case FN_UPDATE_CHARTS:
713 SwWait aWait( *rView.GetDocShell(), true );
714 rSh.UpdateAllCharts();
716 break;
718 case FN_UPDATE_ALL:
720 comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer
721 = GetObjectShell()->getEmbeddedObjectContainer();
722 rEmbeddedObjectContainer.setUserAllowsLinkUpdate(true);
724 SwView& rTempView = GetView();
725 rSh.EnterStdMode();
726 if( !rSh.GetLinkManager().GetLinks().empty() )
728 rSh.StartAllAction();
729 rSh.GetLinkManager().UpdateAllLinks( false, true, nullptr );
730 rSh.EndAllAction();
732 SfxDispatcher &rDis = *rTempView.GetViewFrame()->GetDispatcher();
733 rDis.Execute( FN_UPDATE_FIELDS );
734 rDis.Execute( FN_UPDATE_TOX );
735 rDis.Execute( FN_UPDATE_CHARTS );
736 rSh.Reformat();
738 break;
740 case FN_UPDATE_INPUTFIELDS:
741 rSh.UpdateInputFields();
742 break;
744 case FN_PREV_BOOKMARK:
745 rReq.SetReturnValue(SfxBoolItem( nSlot, rSh.GoPrevBookmark()));
746 break;
747 case FN_NEXT_BOOKMARK:
748 rReq.SetReturnValue(SfxBoolItem( nSlot, rSh.GoNextBookmark()));
749 break;
751 case FN_GOTO_NEXT_MARK:
752 case FN_GOTO_PREV_MARK:
754 SwFieldMgr aFieldMgr;
755 SwFieldType* pFieldType = aFieldMgr.GetFieldType(SwFieldIds::JumpEdit);
757 if (pFieldType)
759 if (rSh.IsSelFrameMode())
761 rSh.UnSelectFrame();
762 rSh.LeaveSelFrameMode();
765 if (rSh.HasMark())
767 SwMvContext aMvContext(&rSh);
768 if (rSh.IsCursorPtAtEnd())
769 rSh.SwapPam();
770 rSh.ClearMark();
771 rSh.EndSelect();
773 bool bRet = rSh.MoveFieldType( pFieldType, nSlot == FN_GOTO_NEXT_MARK );
774 SwField* pCurField = bRet ? rSh.GetCurField() : nullptr;
775 if (pCurField)
776 rSh.ClickToField(*pCurField);
777 rReq.SetReturnValue(SfxBoolItem( nSlot, bRet));
780 break;
782 case FN_START_DOC_DIRECT:
783 case FN_END_DOC_DIRECT:
785 if (rSh.IsSelFrameMode())
787 rSh.UnSelectFrame();
788 rSh.LeaveSelFrameMode();
790 rSh.EnterStdMode();
791 nSlot == FN_START_DOC_DIRECT ?
792 rSh.SttEndDoc(true) :
793 rSh.SttEndDoc(false);
795 break;
796 case FN_GOTO_PREV_OBJ:
797 case FN_GOTO_NEXT_OBJ:
799 bool bSuccess = rSh.GotoObj( nSlot == FN_GOTO_NEXT_OBJ );
800 rReq.SetReturnValue(SfxBoolItem(nSlot, bSuccess));
801 if (bSuccess && !rSh.IsSelFrameMode())
803 rSh.HideCursor();
804 rSh.EnterSelFrameMode();
805 GetView().AttrChangedNotify(nullptr);
808 break;
809 case SID_GALLERY_FORMATS:
811 const SvxGalleryItem* pGalleryItem = SfxItemSet::GetItem<SvxGalleryItem>(pArgs, SID_GALLERY_FORMATS, false);
812 if ( !pGalleryItem )
813 break;
815 const SelectionType nSelType = rSh.GetSelectionType();
816 sal_Int8 nGalleryItemType( pGalleryItem->GetType() );
818 if ( (!rSh.IsSelFrameMode() || nSelType & SelectionType::Graphic) &&
819 nGalleryItemType == css::gallery::GalleryItemType::GRAPHIC )
821 SwWait aWait( *rView.GetDocShell(), true );
823 OUString aGrfName, aFltName;
824 const Graphic aGrf( pGalleryItem->GetGraphic() );
826 if ( nSelType & SelectionType::Graphic )
827 rSh.ReRead( aGrfName, aFltName, &aGrf );
828 else
829 rSh.Insert( aGrfName, aFltName, aGrf );
831 GetView().GetEditWin().GrabFocus();
833 else if(!rSh.IsSelFrameMode() &&
834 nGalleryItemType == css::gallery::GalleryItemType::MEDIA )
836 const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, pGalleryItem->GetURL() );
837 GetView().GetViewFrame()->GetDispatcher()->ExecuteList(
838 SID_INSERT_AVMEDIA, SfxCallMode::SYNCHRON,
839 { &aMediaURLItem });
842 break;
843 case FN_PAGE_STYLE_SET_COLS:
845 if (pArgs)
847 // Determine the current PageDescriptor and fill the set with that.
848 const size_t nCurIdx = rSh.GetCurPageDesc();
849 SwPageDesc aPageDesc(rSh.GetPageDesc(nCurIdx));
851 SwFrameFormat &rFormat = aPageDesc.GetMaster();
853 SwFormatCol aFormatCol = rFormat.GetCol();
855 sal_uInt16 nCount;
856 if(SfxItemState::SET == pArgs->GetItemState(nSlot))
857 nCount = static_cast<const SfxUInt16Item &>(pArgs->Get(nSlot)).GetValue();
858 else
859 nCount = pArgs->Get(SID_ATTR_COLUMNS).GetValue();
860 sal_uInt16 nGutterWidth = DEF_GUTTER_WIDTH;
862 aFormatCol.Init(nCount ? nCount : 1, nGutterWidth, USHRT_MAX);
863 aFormatCol.SetWishWidth(USHRT_MAX);
864 aFormatCol.SetGutterWidth(nGutterWidth, USHRT_MAX);
866 rFormat.SetFormatAttr(aFormatCol);
868 rSh.ChgPageDesc(nCurIdx, aPageDesc);
870 else
871 GetView().GetViewFrame()->GetDispatcher()->Execute(FN_FORMAT_PAGE_COLUMN_DLG);
873 break;
874 case FN_CONVERT_TABLE_TO_TEXT:
875 case FN_CONVERT_TEXT_TO_TABLE:
876 case FN_CONVERT_TEXT_TABLE:
878 sal_Unicode cDelim = 0;
879 bool bToTable = false;
880 if( nSlot == FN_CONVERT_TEXT_TO_TABLE ||
881 ( nSlot == FN_CONVERT_TEXT_TABLE && nullptr == rSh.GetTableFormat() ))
882 bToTable = true;
883 SwInsertTableOptions aInsTableOpts( SwInsertTableFlags::All, 1 );
884 SwTableAutoFormat const* pTAFormat = nullptr;
885 std::unique_ptr<SwTableAutoFormatTable> pAutoFormatTable;
886 bool bDeleteFormat = true;
887 if(pArgs && SfxItemState::SET == pArgs->GetItemState( FN_PARAM_1, true, &pItem))
889 aInsTableOpts.mnInsMode = SwInsertTableFlags::NONE;
890 // Delimiter
891 OUString sDelim = static_cast< const SfxStringItem* >(pItem)->GetValue();
892 if(!sDelim.isEmpty())
893 cDelim = sDelim[0];
894 // AutoFormat
895 if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_2, true, &pItem))
897 OUString sAutoFormat = static_cast< const SfxStringItem* >(pItem)->GetValue();
899 pAutoFormatTable.reset(new SwTableAutoFormatTable);
900 pAutoFormatTable->Load();
902 for( sal_uInt16 i = 0, nCount = pAutoFormatTable->size(); i < nCount; i++ )
904 SwTableAutoFormat const*const pFormat = &(*pAutoFormatTable)[ i ];
905 if( pFormat->GetName() == sAutoFormat )
907 pTAFormat = pFormat;
908 bDeleteFormat = false;
909 break;
913 //WithHeader
914 if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_3, true, &pItem) &&
915 static_cast< const SfxBoolItem* >(pItem)->GetValue())
916 aInsTableOpts.mnInsMode |= SwInsertTableFlags::Headline;
917 // RepeatHeaderLines
918 if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_4, true, &pItem))
919 aInsTableOpts.mnRowsToRepeat =
920 static_cast<sal_uInt16>(static_cast< const SfxInt16Item* >(pItem)->GetValue());
921 //WithBorder
922 if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_5, true, &pItem) &&
923 static_cast< const SfxBoolItem* >(pItem)->GetValue())
924 aInsTableOpts.mnInsMode |= SwInsertTableFlags::DefaultBorder;
925 //DontSplitTable
926 if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_6, true, &pItem) &&
927 !static_cast< const SfxBoolItem* >(pItem)->GetValue() )
928 aInsTableOpts.mnInsMode |= SwInsertTableFlags::SplitLayout;
930 else
932 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
933 ScopedVclPtr<AbstractSwConvertTableDlg> pDlg(pFact->CreateSwConvertTableDlg(GetView(), bToTable));
934 if( RET_OK == pDlg->Execute() )
936 pDlg->GetValues( cDelim, aInsTableOpts, pTAFormat );
941 if( cDelim )
943 //Shell change!
944 SwView& rSaveView = rView;
945 bool bInserted = false;
946 //recording:
947 SfxViewFrame* pViewFrame = GetView().GetViewFrame();
948 if( SfxRequest::HasMacroRecorder(pViewFrame) )
950 SfxRequest aReq( pViewFrame, nSlot);
951 aReq.AppendItem( SfxStringItem( FN_PARAM_1, OUString(cDelim) ));
952 if(bToTable)
954 if(pTAFormat)
955 aReq.AppendItem( SfxStringItem( FN_PARAM_2, pTAFormat->GetName()));
956 aReq.AppendItem( SfxBoolItem ( FN_PARAM_3, bool(aInsTableOpts.mnInsMode & SwInsertTableFlags::Headline)));
957 aReq.AppendItem( SfxInt16Item( FN_PARAM_4, static_cast<short>(aInsTableOpts.mnRowsToRepeat) ));
958 aReq.AppendItem( SfxBoolItem ( FN_PARAM_5, bool(aInsTableOpts.mnInsMode & SwInsertTableFlags::DefaultBorder) ));
959 aReq.AppendItem( SfxBoolItem ( FN_PARAM_6, !(aInsTableOpts.mnInsMode & SwInsertTableFlags::SplitLayout)));
961 aReq.Done();
964 if( !bToTable )
965 rSh.TableToText( cDelim );
966 else
968 bInserted = rSh.TextToTable( aInsTableOpts, cDelim, pTAFormat );
970 rSh.EnterStdMode();
972 if( bInserted )
973 rSaveView.AutoCaption( TABLE_CAP );
975 if(bDeleteFormat)
976 delete pTAFormat;
978 break;
979 case SID_STYLE_WATERCAN:
980 case SID_STYLE_UPDATE_BY_EXAMPLE:
981 case SID_STYLE_NEW_BY_EXAMPLE:
982 case SID_STYLE_APPLY:
984 ShellMode eMode = GetView().GetShellMode();
985 if ( ShellMode::Draw != eMode &&
986 ShellMode::DrawForm != eMode &&
987 ShellMode::DrawText != eMode &&
988 ShellMode::Bezier != eMode )
990 // oj #107754#
991 if ( SID_STYLE_WATERCAN == nSlot )
993 const bool bLockedView = rSh.IsViewLocked();
994 rSh.LockView( true ); //lock visible section
996 GetView().GetDocShell()->ExecStyleSheet(rReq);
998 rSh.LockView( bLockedView );
1000 else
1001 // Will be recorded from the DocShell
1002 GetView().GetDocShell()->ExecStyleSheet(rReq);
1005 break;
1006 case SID_CLASSIFICATION_APPLY:
1008 GetView().GetDocShell()->Execute(rReq);
1010 break;
1011 case SID_CLASSIFICATION_DIALOG:
1013 GetView().GetDocShell()->Execute(rReq);
1015 break;
1016 case SID_PARAGRAPH_SIGN_CLASSIFY_DLG:
1018 GetView().GetDocShell()->Execute(rReq);
1020 break;
1021 case SID_WATERMARK:
1023 GetView().GetDocShell()->Execute(rReq);
1025 break;
1026 case FN_ESCAPE:
1027 GetView().ExecuteSlot(rReq);
1028 break;
1029 case SID_IMAP:
1031 sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
1033 SfxViewFrame* pVFrame = GetView().GetViewFrame();
1034 pVFrame->ToggleChildWindow( nId );
1035 pVFrame->GetBindings().Invalidate( SID_IMAP );
1037 if ( pVFrame->HasChildWindow( nId ) && rSh.IsFrameSelected() )
1038 lcl_UpdateIMapDlg( rSh );
1040 break;
1041 case SID_IMAP_EXEC:
1043 SvxIMapDlg* pDlg = GetIMapDlg(GetView());
1045 // Check, if the allocation is useful or allowed at all.
1046 if ( rSh.IsFrameSelected() &&
1047 pDlg->GetEditingObject() == rSh.GetIMapInventor() )
1049 SfxItemSet aSet( rSh.GetAttrPool(), svl::Items<RES_URL, RES_URL>{} );
1050 rSh.GetFlyFrameAttr( aSet );
1051 SwFormatURL aURL( aSet.Get( RES_URL ) );
1052 aURL.SetMap( &pDlg->GetImageMap() );
1053 aSet.Put( aURL );
1054 rSh.SetFlyFrameAttr( aSet );
1057 break;
1058 case SID_CONTOUR_DLG:
1060 sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
1062 SfxViewFrame* pVFrame = GetView().GetViewFrame();
1063 pVFrame->ToggleChildWindow( nId );
1064 pVFrame->GetBindings().Invalidate( SID_CONTOUR_DLG );
1066 SelectionType nSel = rSh.GetSelectionType();
1067 if ( pVFrame->HasChildWindow( nId ) &&
1068 (nSel & (SelectionType::Graphic|SelectionType::Ole)) )
1070 lcl_UpdateContourDlg( rSh, nSel );
1073 break;
1074 case SID_CONTOUR_EXEC:
1076 SvxContourDlg *pDlg = GetContourDlg(GetView());
1077 // Check, if the allocation is useful or allowed at all.
1078 SelectionType nSel = rSh.GetSelectionType();
1079 if ( nSel & (SelectionType::Graphic|SelectionType::Ole) )
1081 if (pDlg && pDlg->GetEditingObject() == rSh.GetIMapInventor())
1083 rSh.StartAction();
1084 SfxItemSet aSet( rSh.GetAttrPool(), svl::Items<RES_SURROUND, RES_SURROUND>{});
1085 rSh.GetFlyFrameAttr( aSet );
1086 SwFormatSurround aSur( aSet.Get( RES_SURROUND ) );
1087 if ( !aSur.IsContour() )
1089 aSur.SetContour( true );
1090 if ( aSur.GetSurround() == css::text::WrapTextMode_NONE )
1091 aSur.SetSurround( css::text::WrapTextMode_PARALLEL );
1092 aSet.Put( aSur );
1093 rSh.SetFlyFrameAttr( aSet );
1095 const tools::PolyPolygon aPoly( pDlg->GetPolyPolygon() );
1096 rSh.SetGraphicPolygon( &aPoly );
1097 if ( pDlg->IsGraphicChanged() )
1098 rSh.ReRead( OUString(), OUString(), &pDlg->GetGraphic());
1099 rSh.EndAction();
1103 break;
1104 case FN_FRAME_TO_ANCHOR:
1106 rSh.GotoFlyAnchor();
1107 rSh.EnterStdMode();
1108 rSh.CallChgLnk();
1110 break;
1111 case FN_TOOL_ANCHOR_PAGE:
1112 case FN_TOOL_ANCHOR_PARAGRAPH:
1113 case FN_TOOL_ANCHOR_CHAR:
1114 case FN_TOOL_ANCHOR_AT_CHAR:
1115 case FN_TOOL_ANCHOR_FRAME:
1117 RndStdIds eSet = nSlot == FN_TOOL_ANCHOR_PAGE
1118 ? RndStdIds::FLY_AT_PAGE
1119 : nSlot == FN_TOOL_ANCHOR_PARAGRAPH
1120 ? RndStdIds::FLY_AT_PARA
1121 : nSlot == FN_TOOL_ANCHOR_FRAME
1122 ? RndStdIds::FLY_AT_FLY
1123 : nSlot == FN_TOOL_ANCHOR_CHAR
1124 ? RndStdIds::FLY_AS_CHAR
1125 : RndStdIds::FLY_AT_CHAR;
1126 rSh.StartUndo();
1127 if (rSh.IsObjSelected())
1128 rSh.ChgAnchor(eSet);
1129 else if (rSh.IsFrameSelected())
1131 SwFormatAnchor aAnc(eSet, rSh.GetPhyPageNum());
1132 SfxItemSet aSet(SwFEShell::makeItemSetFromFormatAnchor(GetPool(), aAnc));
1133 rSh.SetFlyFrameAttr(aSet);
1135 // if new anchor is 'as char' and it is a Math object and the usual
1136 // pre-conditions are met then align the formula to the baseline of the text
1137 const uno::Reference < embed::XEmbeddedObject > xObj( rSh.GetOleRef() );
1138 const bool bDoMathBaselineAlignment = xObj.is() && SotExchange::IsMath( xObj->getClassID() )
1139 && RndStdIds::FLY_AS_CHAR == eSet && rSh.GetDoc()->getIDocumentSettingAccess().get( DocumentSettingId::MATH_BASELINE_ALIGNMENT );
1140 if (bDoMathBaselineAlignment)
1141 rSh.AlignFormulaToBaseline( xObj );
1143 sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
1144 if( nHtmlMode )
1146 SfxItemSet aSet(GetPool(), svl::Items<RES_SURROUND, RES_HORI_ORIENT>{});
1147 rSh.GetFlyFrameAttr(aSet);
1149 const SwFormatSurround& rSurround = aSet.Get(RES_SURROUND);
1150 const SwFormatVertOrient& rVert = aSet.Get(RES_VERT_ORIENT);
1151 const SwFormatHoriOrient& rHori = aSet.Get(RES_HORI_ORIENT);
1152 sal_Int16 eVOrient = rVert.GetVertOrient();
1153 sal_Int16 eHOrient = rHori.GetHoriOrient();
1154 css::text::WrapTextMode eSurround = rSurround.GetSurround();
1156 switch( eSet )
1158 case RndStdIds::FLY_AT_FLY:
1159 case RndStdIds::FLY_AT_PAGE:
1160 //Wrap through, left or from left, top, from top
1161 if(eSurround != css::text::WrapTextMode_THROUGH)
1162 aSet.Put(SwFormatSurround(css::text::WrapTextMode_THROUGH));
1164 if( eVOrient != text::VertOrientation::TOP && eVOrient != text::VertOrientation::NONE)
1165 aSet.Put(SwFormatVertOrient(0, text::VertOrientation::TOP));
1167 if (eHOrient != text::HoriOrientation::NONE && eHOrient != text::HoriOrientation::LEFT)
1168 aSet.Put(SwFormatHoriOrient(0, text::HoriOrientation::LEFT));
1169 break;
1171 case RndStdIds::FLY_AT_PARA:
1172 // left, from left, right, top, no wrap, wrap left and right
1173 if (eSurround != css::text::WrapTextMode_LEFT && eSurround != css::text::WrapTextMode_RIGHT)
1174 aSet.Put(SwFormatSurround(css::text::WrapTextMode_LEFT));
1176 if( eVOrient != text::VertOrientation::TOP)
1177 aSet.Put(SwFormatVertOrient(0, text::VertOrientation::TOP));
1179 if (eHOrient != text::HoriOrientation::NONE && eHOrient != text::HoriOrientation::LEFT && eHOrient != text::HoriOrientation::RIGHT)
1180 aSet.Put(SwFormatHoriOrient(0, text::HoriOrientation::LEFT));
1181 break;
1183 case RndStdIds::FLY_AT_CHAR:
1184 // left, from left, right, top, wrap through
1185 if(eSurround != css::text::WrapTextMode_THROUGH)
1186 aSet.Put(SwFormatSurround(css::text::WrapTextMode_THROUGH));
1188 if( eVOrient != text::VertOrientation::TOP)
1189 aSet.Put(SwFormatVertOrient(0, text::VertOrientation::TOP));
1191 if (eHOrient != text::HoriOrientation::NONE && eHOrient != text::HoriOrientation::LEFT && eHOrient != text::HoriOrientation::RIGHT)
1192 aSet.Put(SwFormatHoriOrient(0, text::HoriOrientation::LEFT));
1193 break;
1195 default:
1199 if( aSet.Count() )
1200 rSh.SetFlyFrameAttr( aSet );
1202 rSh.EndUndo();
1204 GetView().GetViewFrame()->GetBindings().Invalidate( SID_ANCHOR_MENU );
1206 break;
1208 case FN_FRAME_NOWRAP:
1209 case FN_FRAME_WRAP:
1210 case FN_FRAME_WRAP_IDEAL:
1211 case FN_FRAME_WRAPTHRU:
1212 case FN_FRAME_WRAPTHRU_TRANSP:
1213 case FN_FRAME_WRAPTHRU_TOGGLE:
1214 case FN_FRAME_WRAP_CONTOUR:
1215 case FN_WRAP_ANCHOR_ONLY:
1216 case FN_FRAME_WRAP_LEFT:
1217 case FN_FRAME_WRAP_RIGHT:
1218 SetWrapMode( nSlot );
1219 break;
1221 case FN_UPDATE_ALL_LINKS:
1223 if( !rSh.GetLinkManager().GetLinks().empty() )
1225 rSh.EnterStdMode();
1226 rSh.StartAllAction();
1227 rSh.GetLinkManager().UpdateAllLinks( false, false, nullptr );
1228 rSh.EndAllAction();
1231 break;
1233 case FN_XFORMS_DESIGN_MODE:
1234 if (pArgs && pArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET)
1236 if (const SfxBoolItem* pBoolItem = dynamic_cast<const SfxBoolItem*>(pItem))
1238 bool bDesignMode = pBoolItem->GetValue();
1240 // set from design mode
1241 OSL_ENSURE( GetView().GetFormShell() != nullptr, "form shell?" );
1242 SfxRequest aReq( GetView().GetViewFrame(), SID_FM_DESIGN_MODE );
1243 aReq.AppendItem( SfxBoolItem( SID_FM_DESIGN_MODE, bDesignMode ) );
1244 GetView().GetFormShell()->Execute( aReq );
1245 aReq.Done();
1247 // also set suitable view options
1248 SwViewOption aViewOption = *rSh.GetViewOptions();
1249 aViewOption.SetFormView( ! bDesignMode );
1250 rSh.ApplyViewOptions( aViewOption );
1253 break;
1255 default:
1256 bMore = true;
1260 if(!bMore || !pArgs)
1261 return;
1263 pItem = nullptr;
1264 pArgs->GetItemState(GetPool().GetWhich(nSlot), false, &pItem);
1265 if(!pItem)
1266 return;
1268 switch(nSlot)
1270 case SID_ATTR_BRUSH:
1271 case SID_ATTR_BORDER_SHADOW:
1272 case RES_SHADOW:
1274 rSh.StartAllAction();
1275 // Tabele cell(s) selected?
1276 if ( rSh.IsTableMode() )
1278 SwFrameFormat *pFormat = rSh.GetTableFormat();
1279 pFormat->SetFormatAttr( *pItem );
1281 else if ( rSh.IsFrameSelected() )
1283 // Set border attributes via Frame-Manager.
1284 SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr );
1285 aMgr.SetAttrSet( *pArgs );
1286 aMgr.UpdateFlyFrame();
1288 else
1290 rSh.SetAttrSet( *pArgs );
1292 rSh.EndAllAction();
1294 break;
1295 case FN_PAGE_STYLE_SET_LR_MARGIN:
1296 case FN_PAGE_STYLE_SET_UL_MARGIN:
1297 case FN_PAGE_STYLE_SET_NUMBER_FORMAT:
1298 case FN_PAGE_STYLE_SET_PAPER_SIZE:
1299 case FN_PAGE_STYLE_SET_PAPER_BIN:
1301 OSL_FAIL("not implemented");
1303 break;
1305 case SID_ATTR_BORDER_OUTER:
1307 // Tabele cell(s) selected?
1308 if ( rSh.IsTableMode() )
1310 // Set border attributes Get/SetTabBorders()
1311 rSh.SetTabBorders(*pArgs);
1313 else if ( rSh.IsFrameSelected() )
1315 // Set border attributes via Frame-Manager.
1316 SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr );
1317 aMgr.SetAttrSet(*pArgs);
1318 aMgr.UpdateFlyFrame();
1320 else
1322 // Set border attributes via shell quite normally.
1323 rSh.SetAttrItem( *pItem );
1326 break;
1327 default:
1328 OSL_FAIL("wrong Dispatcher");
1332 // Here the state for SID_IMAP / SID_CONTOUR will be handled
1333 // until the swapping of the graphic is finished.
1335 IMPL_LINK_NOARG(SwBaseShell, GraphicArrivedHdl, SwCursorShell&, void)
1337 SwWrtShell &rSh = GetShell();
1338 if (CNT_GRF != rSh.SwEditShell::GetCntType())
1339 return;
1340 GraphicType const nGrfType(rSh.GetGraphicType());
1341 if (GraphicType::NONE == nGrfType || aGrfUpdateSlots.empty())
1342 return;
1344 bool bProtect = FlyProtectFlags::NONE != rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent);
1345 SfxViewFrame* pVFrame = GetView().GetViewFrame();
1346 for( const auto nSlot : aGrfUpdateSlots )
1348 bool bSetState = false;
1349 bool bState = false;
1350 switch( nSlot )
1352 case SID_IMAP:
1353 case SID_IMAP_EXEC:
1355 sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
1356 SfxChildWindow *pChildWindow = pVFrame->HasChildWindow(nId) ?
1357 pVFrame->GetChildWindow(nId) : nullptr;
1358 SvxIMapDlg *pDlg = pChildWindow ?
1359 static_cast<SvxIMapDlg*>(pChildWindow->GetController().get()) : nullptr;
1361 if( pDlg && ( SID_IMAP_EXEC == nSlot ||
1362 ( SID_IMAP == nSlot && !bProtect)) &&
1363 pDlg->GetEditingObject() != rSh.GetIMapInventor())
1364 lcl_UpdateIMapDlg( rSh );
1366 if( !bProtect && SID_IMAP == nSlot )
1368 bSetState = true;
1369 bState = nullptr != pDlg;
1372 break;
1374 case SID_CONTOUR_DLG:
1375 if( !bProtect )
1377 sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
1378 SfxChildWindow *pChildWindow = pVFrame->HasChildWindow(nId) ?
1379 pVFrame->GetChildWindow(nId) : nullptr;
1380 SvxIMapDlg *pDlg = pChildWindow ?
1381 static_cast<SvxIMapDlg*>(pChildWindow->GetController().get()) : nullptr;
1382 if( pDlg && pDlg->GetEditingObject() !=
1383 rSh.GetIMapInventor() )
1384 lcl_UpdateContourDlg( rSh, SelectionType::Graphic );
1386 bSetState = true;
1387 bState = nullptr != pDlg;
1389 break;
1391 case FN_FRAME_WRAP_CONTOUR:
1392 if( !bProtect )
1394 SfxItemSet aSet(GetPool(), svl::Items<RES_SURROUND, RES_SURROUND>{});
1395 rSh.GetFlyFrameAttr(aSet);
1396 const SwFormatSurround& rWrap = aSet.Get(RES_SURROUND);
1397 bSetState = true;
1398 bState = rWrap.IsContour();
1400 break;
1402 case SID_GRFFILTER:
1403 case SID_GRFFILTER_INVERT:
1404 case SID_GRFFILTER_SMOOTH:
1405 case SID_GRFFILTER_SHARPEN:
1406 case SID_GRFFILTER_REMOVENOISE:
1407 case SID_GRFFILTER_SOBEL:
1408 case SID_GRFFILTER_MOSAIC:
1409 case SID_GRFFILTER_EMBOSS:
1410 case SID_GRFFILTER_POSTER:
1411 case SID_GRFFILTER_POPART:
1412 case SID_GRFFILTER_SEPIA:
1413 case SID_GRFFILTER_SOLARIZE:
1414 bSetState = bState = GraphicType::Bitmap == nGrfType;
1415 break;
1418 if( bSetState )
1420 SfxBoolItem aBool( nSlot, bState );
1421 if( pGetStateSet )
1422 pGetStateSet->Put( aBool );
1423 else
1424 pVFrame->GetBindings().SetState( aBool );
1427 aGrfUpdateSlots.clear();
1430 void SwBaseShell::GetState( SfxItemSet &rSet )
1432 SwWrtShell &rSh = GetShell();
1433 SfxViewFrame* pVFrame = GetView().GetViewFrame();
1434 SfxWhichIter aIter( rSet );
1435 sal_uInt16 nWhich = aIter.FirstWhich();
1436 pGetStateSet = &rSet;
1437 while ( nWhich )
1439 switch ( nWhich )
1441 case SID_GALLERY_FORMATS:
1442 if ( rSh.IsObjSelected() ||
1443 (rSh.IsSelFrameMode() &&
1444 !(rSh.GetSelectionType() & SelectionType::Graphic)) )
1445 rSet.DisableItem( nWhich );
1446 break;
1447 case SID_GALLERY_ENABLE_ADDCOPY:
1448 // #108230# allow copy from gallery in Writer AND Writer/Web!
1449 rSet.Put( SfxBoolItem( SID_GALLERY_ENABLE_ADDCOPY, true ) );
1450 break;
1451 case FN_EDIT_REGION:
1452 if( !rSh.IsAnySectionInDoc() )
1453 rSet.DisableItem(nWhich);
1454 break;
1456 case FN_EDIT_CURRENT_REGION:
1457 //tdf#112808 if cursor is in an index, don't show the edit section.
1458 if( !rSh.GetCurrSection() ||
1459 (rSh.GetCurrSection()->GetType() != SectionType::Content &&
1460 rSh.GetCurrSection()->GetType() != SectionType::FileLink ))
1462 rSet.DisableItem(nWhich);
1464 break;
1466 case FN_INSERT_REGION:
1467 if( rSh.CursorInsideInputField()
1468 || rSh.IsSelFrameMode()
1469 || !rSh.IsInsRegionAvailable() )
1471 rSet.DisableItem( nWhich );
1473 break;
1475 case FN_CONVERT_TABLE_TO_TEXT:
1477 FrameTypeFlags eFrameType = rSh.GetFrameType(nullptr,true);
1478 if( (eFrameType & FrameTypeFlags::FOOTNOTE) ||
1479 !rSh.GetTableFormat() )
1480 rSet.DisableItem( nWhich );
1482 break;
1483 case FN_CONVERT_TEXT_TO_TABLE:
1485 FrameTypeFlags eFrameType = rSh.GetFrameType(nullptr,true);
1486 if( (eFrameType & FrameTypeFlags::FOOTNOTE) ||
1487 !rSh.IsTextToTableAvailable() )
1488 rSet.DisableItem( nWhich );
1490 break;
1491 case FN_CONVERT_TEXT_TABLE:
1493 FrameTypeFlags eFrameType = rSh.GetFrameType(nullptr,true);
1494 if( (eFrameType & FrameTypeFlags::FOOTNOTE) ||
1495 (!rSh.GetTableFormat() && !rSh.IsTextToTableAvailable() ) )
1496 rSet.DisableItem( nWhich );
1498 break;
1499 case RES_SHADOW:
1501 SfxItemSet aSet( rSh.GetAttrPool(),
1502 svl::Items<RES_SHADOW, RES_SHADOW>{} );
1504 // Table cell(s) selected?
1505 if ( rSh.IsTableMode() )
1507 SwFrameFormat *pFormat = rSh.GetTableFormat();
1508 aSet.Put(pFormat->GetFormatAttr( nWhich ));
1510 else if( rSh.IsFrameSelected() )
1512 SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr );
1513 aSet.Put( aMgr.GetAttrSet() );
1515 else
1516 rSh.GetCurAttr( aSet );
1518 const SvxShadowItem& rShItem = static_cast<const SvxShadowItem&>(aSet.Get(nWhich));
1519 rSet.Put(rShItem);
1521 break;
1522 case SID_IMAP:
1524 // #i59688#
1525 // Improve efficiency:
1526 // If selected object is protected, item has to disabled.
1527 const bool bProtect = FlyProtectFlags::NONE != rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent);
1528 if ( bProtect )
1530 rSet.DisableItem( nWhich );
1532 else
1534 const sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
1535 const bool bHas = pVFrame->HasChildWindow( nId );
1536 const bool bFrameSel = rSh.IsFrameSelected();
1537 const bool bIsGraphicSelection =
1538 rSh.GetSelectionType() == SelectionType::Graphic;
1540 // #i59688#
1541 // Avoid unnecessary loading of selected graphic.
1542 // The graphic is only needed, if the dialog is open.
1543 // If the swapping of the graphic is finished, the status
1544 // must be determined asynchronously, until this the slot
1545 // will be disabled.
1546 if ( bHas && bIsGraphicSelection && rSh.IsLinkedGrfSwapOut() )
1548 if( AddGrfUpdateSlot( nWhich ))
1549 rSh.GetGraphic(false); // start the loading
1551 else
1553 if ( !bHas &&
1554 ( !bFrameSel ||
1555 ( bIsGraphicSelection &&
1556 rSh.GetGraphicType() == GraphicType::NONE ) ) )
1558 rSet.DisableItem( nWhich );
1560 else
1562 SfxBoolItem aBool(nWhich, bHas);
1563 if ( bHas && bFrameSel )
1564 lcl_UpdateIMapDlg( rSh );
1565 rSet.Put(aBool);
1570 break;
1571 case SID_IMAP_EXEC:
1573 bool bDisable = false;
1574 if( !rSh.IsFrameSelected())
1575 bDisable = true;
1576 sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
1577 if(!bDisable && pVFrame->HasChildWindow( nId ))
1579 if(rSh.GetSelectionType() == SelectionType::Graphic
1580 && rSh.IsLinkedGrfSwapOut())
1582 if( AddGrfUpdateSlot( nWhich ))
1583 rSh.GetGraphic(false); // start the loading
1585 else
1587 SvxIMapDlg *pDlg = GetIMapDlg(GetView());
1588 if (pDlg && pDlg->GetEditingObject() != rSh.GetIMapInventor())
1589 lcl_UpdateIMapDlg( rSh );
1592 rSet.Put(SfxBoolItem(nWhich, bDisable));
1594 break;
1596 case FN_BACKSPACE:
1597 case SID_DELETE:
1598 if ( ( rSh.HasReadonlySel() && !rSh.CursorInsideInputField() )
1599 || rSh.IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE )
1601 rSet.DisableItem( nWhich );
1603 break;
1605 case SID_CONTOUR_DLG:
1607 bool bParentCntProt = FlyProtectFlags::NONE != rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent );
1609 if( bParentCntProt || 0 != (HTMLMODE_ON & ::GetHtmlMode(
1610 GetView().GetDocShell() )) )
1611 rSet.DisableItem( nWhich );
1612 else
1614 sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
1615 bool bHas = GetView().GetViewFrame()->HasChildWindow( nId );
1616 SelectionType nSel = rSh.GetSelectionType();
1617 bool bOk(nSel & (SelectionType::Graphic|SelectionType::Ole));
1619 bool bDisable = false;
1620 if( !bHas && !bOk )
1621 bDisable = true;
1622 // #i59688#
1623 // Avoid unnecessary loading of selected graphic.
1624 // The graphic is only needed, if the dialog is open.
1625 // If the swapping of the graphic is finished, the status
1626 // must be determined asynchronously, until this the slot
1627 // will be disabled.
1628 else if ( bHas && (nSel & SelectionType::Graphic) &&
1629 rSh.IsLinkedGrfSwapOut() )
1631 if( AddGrfUpdateSlot( nWhich ))
1632 rSh.GetGraphic(false); // start the loading
1633 // #i75481#
1634 bDisable = true;
1636 else if( bHas && bOk )
1637 bDisable = !lcl_UpdateContourDlg( rSh, nSel );
1638 else if( bOk )
1640 // #i75481#
1641 // apply fix #i59688# only for selected graphics
1642 if ( nSel & SelectionType::Graphic )
1643 bDisable = GraphicType::NONE == rSh.GetGraphicType();
1644 else
1645 bDisable = GraphicType::NONE == rSh.GetIMapGraphic().GetType();
1648 if( bDisable )
1649 rSet.DisableItem( nWhich );
1650 else
1651 rSet.Put( SfxBoolItem(nWhich, bHas) );
1654 break;
1655 case SID_CONTOUR_EXEC:
1657 bool bDisable = false;
1658 SelectionType nSel = rSh.GetSelectionType();
1659 if( !(nSel & (SelectionType::Graphic|SelectionType::Ole)) )
1660 bDisable = true;
1661 sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
1662 if( !bDisable && GetView().GetViewFrame()->HasChildWindow( nId ))
1664 SvxContourDlg *pDlg = GetContourDlg(GetView());
1665 if (pDlg && pDlg->GetEditingObject() != rSh.GetIMapInventor())
1666 bDisable = true;
1668 rSet.Put(SfxBoolItem(nWhich, bDisable));
1670 break;
1672 case SID_ANCHOR_MENU:
1673 case FN_TOOL_ANCHOR_PAGE:
1674 case FN_TOOL_ANCHOR_PARAGRAPH:
1675 case FN_TOOL_ANCHOR_CHAR:
1676 case FN_TOOL_ANCHOR_AT_CHAR:
1677 case FN_TOOL_ANCHOR_FRAME:
1679 bool bObj = 0 != rSh.IsObjSelected();
1680 bool bParentCntProt = rSh.IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE;
1682 if( !bParentCntProt && (bObj || rSh.IsFrameSelected()))
1684 SfxItemSet aSet(GetPool(), svl::Items<RES_ANCHOR, RES_ANCHOR>{});
1685 if(bObj)
1686 rSh.GetObjAttr(aSet);
1687 else
1688 rSh.GetFlyFrameAttr(aSet);
1689 RndStdIds eSet = aSet.Get(RES_ANCHOR).GetAnchorId();
1690 const bool bSet =
1691 ((nWhich == FN_TOOL_ANCHOR_PAGE) &&
1692 (eSet == RndStdIds::FLY_AT_PAGE))
1693 || ((nWhich == FN_TOOL_ANCHOR_PARAGRAPH) &&
1694 (eSet == RndStdIds::FLY_AT_PARA))
1695 || ((nWhich == FN_TOOL_ANCHOR_FRAME) &&
1696 (eSet == RndStdIds::FLY_AT_FLY))
1697 || ((nWhich == FN_TOOL_ANCHOR_AT_CHAR) &&
1698 (eSet == RndStdIds::FLY_AT_CHAR))
1699 || ((nWhich == FN_TOOL_ANCHOR_CHAR) &&
1700 (eSet == RndStdIds::FLY_AS_CHAR));
1702 if( nWhich == FN_TOOL_ANCHOR_FRAME && !rSh.IsFlyInFly() )
1703 rSet.DisableItem(nWhich);
1704 else if(nWhich != SID_ANCHOR_MENU)
1705 rSet.Put(SfxBoolItem(nWhich, bSet));
1707 if (comphelper::LibreOfficeKit::isActive())
1709 if (nWhich == FN_TOOL_ANCHOR_PAGE || nWhich == FN_TOOL_ANCHOR_PARAGRAPH
1710 || nWhich == FN_TOOL_ANCHOR_FRAME)
1712 rSet.DisableItem(nWhich);
1716 else
1717 rSet.DisableItem( nWhich );
1719 break;
1720 case FN_FRAME_NOWRAP:
1721 case FN_FRAME_WRAP:
1722 case FN_FRAME_WRAP_IDEAL:
1723 case FN_FRAME_WRAPTHRU:
1724 case FN_FRAME_WRAPTHRU_TRANSP:
1725 case FN_FRAME_WRAPTHRU_TOGGLE:
1726 case FN_FRAME_WRAP_CONTOUR:
1727 case FN_WRAP_ANCHOR_ONLY:
1728 case FN_FRAME_WRAP_LEFT:
1729 case FN_FRAME_WRAP_RIGHT:
1731 bool bObj = 0 != rSh.IsObjSelected();
1732 bool bParentCntProt = rSh.IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE;
1734 if( !bParentCntProt && (bObj || rSh.IsFrameSelected()))
1736 SfxItemSet aSet(GetPool(), svl::Items<RES_OPAQUE, RES_ANCHOR>{});
1737 RndStdIds nAnchorType;
1738 if(bObj)
1740 rSh.GetObjAttr(aSet);
1741 nAnchorType = rSh.GetAnchorId();
1743 else
1745 rSh.GetFlyFrameAttr(aSet);
1746 nAnchorType = aSet.Get(RES_ANCHOR).GetAnchorId();
1748 const SwFormatSurround& rWrap = aSet.Get(RES_SURROUND);
1750 const SvxOpaqueItem& rOpaque = aSet.Get(RES_OPAQUE);
1751 bool bOpaque = rOpaque.GetValue();
1752 css::text::WrapTextMode nSurround = rWrap.GetSurround();
1753 bool bSet = false;
1755 bool bDisable =
1756 (nAnchorType == RndStdIds::UNKNOWN) || (nAnchorType == RndStdIds::FLY_AS_CHAR);
1757 const bool bHtmlMode =
1758 0 != ::GetHtmlMode(GetView().GetDocShell());
1760 switch( nWhich )
1762 case FN_FRAME_NOWRAP:
1763 bDisable |=
1764 ( (nAnchorType != RndStdIds::FLY_AT_PARA)
1765 && (nAnchorType != RndStdIds::FLY_AT_CHAR)
1766 && (nAnchorType != RndStdIds::FLY_AT_PAGE));
1767 bSet = nSurround == css::text::WrapTextMode_NONE;
1768 break;
1769 case FN_FRAME_WRAP:
1770 bDisable |= bHtmlMode;
1771 bSet = nSurround == css::text::WrapTextMode_PARALLEL;
1772 break;
1773 case FN_FRAME_WRAP_IDEAL:
1774 bDisable |= bHtmlMode;
1775 bSet = nSurround == css::text::WrapTextMode_DYNAMIC;
1776 break;
1777 case FN_FRAME_WRAPTHRU:
1778 bDisable |= (bHtmlMode ||
1779 ( (nAnchorType != RndStdIds::FLY_AT_PARA)
1780 && (nAnchorType != RndStdIds::FLY_AT_CHAR)
1781 && (nAnchorType != RndStdIds::FLY_AT_PAGE)));
1782 if(bObj)
1783 bSet = nSurround == css::text::WrapTextMode_THROUGH && rSh.GetLayerId();
1784 else
1785 bSet = nSurround == css::text::WrapTextMode_THROUGH && bOpaque;
1786 break;
1787 case FN_FRAME_WRAPTHRU_TRANSP:
1788 case FN_FRAME_WRAPTHRU_TOGGLE:
1789 bDisable |= bHtmlMode;
1790 if(bObj)
1791 bSet = nSurround == css::text::WrapTextMode_THROUGH && !rSh.GetLayerId();
1792 else
1793 bSet = nSurround == css::text::WrapTextMode_THROUGH && !bOpaque;
1794 break;
1795 case FN_FRAME_WRAP_CONTOUR:
1796 bDisable |= bHtmlMode;
1797 //no contour available whenn no wrap or wrap through is set
1798 bDisable |= (nSurround == css::text::WrapTextMode_NONE || nSurround == css::text::WrapTextMode_THROUGH);
1799 if( !bDisable )
1801 SelectionType nSel = rSh.GetSelectionType();
1802 if( (nSel & SelectionType::Graphic) &&
1803 rSh.IsLinkedGrfSwapOut())
1805 if( AddGrfUpdateSlot( nWhich ))
1806 rSh.GetGraphic(false); // start the loading
1808 else if( rSh.IsFrameSelected() )
1810 // #i102253# applied patch from OD (see task)
1811 bDisable =
1812 nSel & SelectionType::Frame ||
1813 GraphicType::NONE == rSh.GetIMapGraphic().GetType();
1816 bSet = !bDisable && rWrap.IsContour();
1818 break;
1819 case FN_WRAP_ANCHOR_ONLY:
1820 bDisable |= (bHtmlMode ||
1821 (nAnchorType != RndStdIds::FLY_AT_PARA));
1822 bSet = rWrap.IsAnchorOnly();
1823 break;
1824 case FN_FRAME_WRAP_LEFT:
1825 bSet = nSurround == css::text::WrapTextMode_LEFT;
1826 break;
1827 case FN_FRAME_WRAP_RIGHT:
1828 bSet = nSurround == css::text::WrapTextMode_RIGHT;
1829 break;
1832 if(bDisable)
1833 rSet.DisableItem(nWhich);
1834 else
1835 rSet.Put(SfxBoolItem(nWhich, bSet));
1837 else
1838 rSet.DisableItem(nWhich);
1840 break;
1841 case FN_UPDATE_CHARTS:
1842 if( !rSh.HasCharts() )
1843 rSet.DisableItem( nWhich );
1844 break;
1845 case FN_UPDATE_ALL_LINKS:
1846 if ( rSh.GetLinkManager().GetLinks().empty() )
1847 rSet.DisableItem(nWhich);
1848 break;
1849 case FN_XFORMS_DESIGN_MODE:
1850 // enable if in XForms document
1851 if( rSh.GetDoc()->isXForms() )
1853 // determine current state from view options
1854 bool bValue = ! rSh.GetViewOptions()->IsFormView();
1855 rSet.Put( SfxBoolItem( nWhich, bValue ) );
1857 else
1858 rSet.Put( SfxVisibilityItem( nWhich, false ) );
1859 break;
1861 nWhich = aIter.NextWhich();
1863 pGetStateSet = nullptr;
1866 // Disable the slots with this status method
1868 void SwBaseShell::StateDisableItems( SfxItemSet &rSet )
1870 SfxWhichIter aIter(rSet);
1871 sal_uInt16 nWhich = aIter.FirstWhich();
1873 while (nWhich)
1875 rSet.DisableItem( nWhich );
1876 nWhich = aIter.NextWhich();
1880 // Disable the slots with this status method
1882 void SwBaseShell::StateStyle( SfxItemSet &rSet )
1884 bool bParentCntProt = GetShell().IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE;
1885 ShellMode eMode = GetView().GetShellMode();
1887 if ( bParentCntProt ||
1888 ShellMode::Draw == eMode ||
1889 ShellMode::DrawForm == eMode ||
1890 ShellMode::DrawText == eMode ||
1891 ShellMode::Bezier == eMode )
1893 SfxWhichIter aIter( rSet );
1894 sal_uInt16 nWhich = aIter.FirstWhich();
1895 while ( nWhich )
1897 rSet.DisableItem( nWhich );
1898 nWhich = aIter.NextWhich();
1901 else
1902 GetView().GetDocShell()->StateStyleSheet(rSet, &GetShell());
1905 void SwBaseShell::SetWrapMode( sal_uInt16 nSlot )
1907 SwWrtShell &rSh = GetShell();
1908 bool bObj = 0 != rSh.IsObjSelected();
1909 if( !bObj && !rSh.IsFrameSelected())
1910 return;
1912 SfxItemSet aSet(GetPool(), svl::Items<RES_OPAQUE, RES_SURROUND>{});
1913 if(bObj)
1914 rSh.GetObjAttr(aSet);
1915 else
1916 rSh.GetFlyFrameAttr(aSet);
1917 SwFormatSurround aWrap( aSet.Get(RES_SURROUND) );
1918 css::text::WrapTextMode nOldSurround(aWrap.GetSurround());
1919 css::text::WrapTextMode nSurround = css::text::WrapTextMode_PARALLEL;
1921 switch (nSlot)
1923 case FN_FRAME_NOWRAP:
1924 nSurround = css::text::WrapTextMode_NONE;
1925 if (aWrap.IsContour())
1926 aWrap.SetContour(false);
1927 break;
1928 case FN_FRAME_WRAP_IDEAL:
1929 nSurround = css::text::WrapTextMode_DYNAMIC;
1930 break;
1931 case FN_WRAP_ANCHOR_ONLY:
1932 aWrap.SetAnchorOnly(!aWrap.IsAnchorOnly());
1934 // keep previous wrapping
1936 // switch to wrap css::text::WrapTextMode_PARALLEL, if previous wrap is css::text::WrapTextMode_NONE
1937 if ( nOldSurround != css::text::WrapTextMode_NONE )
1939 nSurround = nOldSurround;
1941 break;
1942 case FN_FRAME_WRAP_CONTOUR:
1943 aWrap.SetContour(!aWrap.IsContour());
1944 // Contour is meaningless in no-wrap or wrap-through context. Otherwise keep existing wrap.
1945 if ( !aWrap.IsContour() ||
1946 ( nOldSurround != css::text::WrapTextMode_NONE &&
1947 nOldSurround != css::text::WrapTextMode_THROUGH ) )
1949 nSurround = nOldSurround;
1951 break;
1952 case FN_FRAME_WRAPTHRU_TRANSP:
1953 case FN_FRAME_WRAPTHRU_TOGGLE:
1954 if (aWrap.IsContour())
1955 aWrap.SetContour(false);
1956 [[fallthrough]];
1957 case FN_FRAME_WRAPTHRU:
1958 nSurround = css::text::WrapTextMode_THROUGH;
1959 break;
1961 case FN_FRAME_WRAP_LEFT:
1962 nSurround = css::text::WrapTextMode_LEFT;
1963 break;
1965 case FN_FRAME_WRAP_RIGHT:
1966 nSurround = css::text::WrapTextMode_RIGHT;
1967 break;
1969 default:
1970 break;
1972 aWrap.SetSurround(nSurround);
1974 if (nSlot != FN_FRAME_WRAP_CONTOUR)
1976 // Defaulting the contour wrap on draw objects.
1977 if (bObj && nOldSurround != nSurround &&
1978 (nOldSurround == css::text::WrapTextMode_NONE || nOldSurround == css::text::WrapTextMode_THROUGH))
1980 aWrap.SetContour(true);
1984 aSet.Put( aWrap );
1986 bool bOpaque = nSlot != FN_FRAME_WRAPTHRU_TRANSP && nSlot != FN_FRAME_WRAPTHRU_TOGGLE;
1987 if( nSlot == FN_FRAME_WRAPTHRU_TOGGLE )
1989 if( bObj )
1990 bOpaque = !rSh.GetLayerId();
1991 else
1993 const SvxOpaqueItem& aOpaque( aSet.Get(RES_OPAQUE) );
1994 bOpaque = !aOpaque.GetValue();
1997 aSet.Put(SvxOpaqueItem(RES_OPAQUE, bOpaque ));
1999 if(bObj)
2001 rSh.SetObjAttr(aSet);
2002 if ( bOpaque )
2003 rSh.SelectionToHeaven();
2004 else
2005 rSh.SelectionToHell();
2007 else
2008 rSh.SetFlyFrameAttr(aSet);
2012 //Force update of the status line
2014 void SwBaseShell::SetFrameMode(FlyMode eMode, SwWrtShell *pSh )
2016 eFrameMode = eMode;
2017 SfxBindings &rBnd = pSh->GetView().GetViewFrame()->GetBindings();
2019 if( eMode == FLY_DRAG || pSh->IsFrameSelected() || pSh->IsObjSelected() )
2021 const SfxPointItem aTmp1( SID_ATTR_POSITION, pSh->GetAnchorObjDiff());
2022 const SvxSizeItem aTmp2( SID_ATTR_SIZE, pSh->GetObjSize());
2023 rBnd.SetState( aTmp1 );
2024 rBnd.SetState( aTmp2 );
2026 else if( eMode == FLY_DRAG_END )
2028 static sal_uInt16 aInval[] =
2030 SID_ATTR_POSITION, SID_ATTR_SIZE, 0
2032 rBnd.Invalidate(aInval);
2036 SwBaseShell::SwBaseShell(SwView& rVw) :
2037 SfxShell( &rVw ),
2038 rView(rVw),
2039 pGetStateSet(nullptr)
2041 SwWrtShell& rWrtSh = rView.GetWrtShell();
2043 SetPool(&rWrtSh.GetAttrPool());
2044 SetName("Base");
2045 rWrtSh.SetGrfArrivedLnk( LINK( this, SwBaseShell, GraphicArrivedHdl));
2048 SwBaseShell::~SwBaseShell()
2050 if( rView.GetCurShell() == this )
2051 rView.ResetSubShell();
2053 Link<SwCursorShell&,void> aTmp( LINK( this, SwBaseShell, GraphicArrivedHdl));
2054 if( aTmp == rView.GetWrtShell().GetGrfArrivedLnk() )
2055 rView.GetWrtShell().SetGrfArrivedLnk( Link<SwCursorShell&,void>() );
2058 void SwBaseShell::ExecTextCtrl( SfxRequest& rReq )
2060 const SfxItemSet *pArgs = rReq.GetArgs();
2062 if( pArgs)
2064 SwWrtShell &rSh = GetShell();
2065 std::unique_ptr<SvxScriptSetItem> pSSetItem;
2066 sal_uInt16 nSlot = rReq.GetSlot();
2067 SfxItemPool& rPool = rSh.GetAttrPool();
2068 sal_uInt16 nWhich = rPool.GetWhich( nSlot );
2069 SvtScriptType nScripts = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
2070 SfxItemSet aHeightSet( GetPool(), svl::Items<RES_CHRATR_FONTSIZE, RES_CHRATR_FONTSIZE,
2071 RES_CHRATR_CJK_FONTSIZE, RES_CHRATR_CJK_FONTSIZE,
2072 RES_CHRATR_CTL_FONTSIZE, RES_CHRATR_CTL_FONTSIZE>{});
2074 switch( nSlot )
2076 case SID_ATTR_CHAR_FONT:
2078 nScripts = rSh.GetScriptType();
2079 // #i42732# input language should be preferred over
2080 // current cursor position to detect script type
2081 if(!rSh.HasSelection())
2083 LanguageType nInputLang = GetView().GetEditWin().GetInputLanguage();
2084 if(nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
2085 nScripts = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
2087 [[fallthrough]];
2089 case SID_ATTR_CHAR_POSTURE:
2090 case SID_ATTR_CHAR_WEIGHT:
2092 pSSetItem.reset(new SvxScriptSetItem( nSlot, rPool ));
2093 pSSetItem->PutItemForScriptType( nScripts, pArgs->Get( nWhich ));
2094 pArgs = &pSSetItem->GetItemSet();
2096 break;
2097 case SID_ATTR_CHAR_FONTHEIGHT:
2099 if(rSh.HasSelection())
2101 pSSetItem.reset(new SvxScriptSetItem( nSlot, rPool ));
2102 pSSetItem->PutItemForScriptType( nScripts, pArgs->Get( nWhich ));
2103 pArgs = &pSSetItem->GetItemSet();
2105 else
2107 nScripts = rSh.GetScriptType();
2108 LanguageType nInputLang = GetView().GetEditWin().GetInputLanguage();
2109 if(nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
2110 nScripts = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
2111 sal_uInt32 nHeight = static_cast< const SvxFontHeightItem& >(pArgs->Get( nWhich )).GetHeight();
2112 SwStdFontConfig* pStdFont = SW_MOD()->GetStdFontConfig();
2114 SfxItemSet aLangSet( GetPool(), svl::Items<RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
2115 RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
2116 RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE>{});
2117 rSh.GetCurAttr( aLangSet );
2119 sal_Int32 nWesternSize =
2120 pStdFont->GetFontHeight(FONT_STANDARD, FONT_GROUP_DEFAULT,
2121 aLangSet.Get( RES_CHRATR_LANGUAGE).GetLanguage());
2122 sal_Int32 nCJKSize =
2123 pStdFont->GetFontHeight(FONT_STANDARD, FONT_GROUP_CJK,
2124 aLangSet.Get( RES_CHRATR_CJK_LANGUAGE).GetLanguage());
2125 sal_Int32 nCTLSize =
2126 pStdFont->GetFontHeight(FONT_STANDARD, FONT_GROUP_CTL,
2127 aLangSet.Get( RES_CHRATR_CTL_LANGUAGE).GetLanguage());
2129 switch(nScripts)
2131 case SvtScriptType::LATIN:
2132 nCJKSize = nHeight * nCJKSize / nWesternSize;
2133 nCTLSize = nHeight * nCTLSize / nWesternSize;
2134 nWesternSize = static_cast<sal_Int32>(nHeight);
2135 break;
2136 case SvtScriptType::ASIAN:
2137 nCTLSize = nHeight* nCTLSize / nCJKSize;
2138 nWesternSize = nHeight * nWesternSize / nCJKSize;
2139 nCJKSize = static_cast<sal_Int32>(nHeight);
2140 break;
2141 case SvtScriptType::COMPLEX:
2142 nCJKSize = nHeight * nCJKSize / nCTLSize;
2143 nWesternSize = nHeight * nWesternSize / nCTLSize;
2144 nCTLSize = static_cast<sal_Int32>(nHeight);
2145 break;
2146 default: break;
2148 aHeightSet.Put( SvxFontHeightItem( static_cast<sal_uInt32>(nWesternSize), 100, RES_CHRATR_FONTSIZE ));
2149 aHeightSet.Put( SvxFontHeightItem( static_cast<sal_uInt32>(nCJKSize), 100, RES_CHRATR_CJK_FONTSIZE ));
2150 aHeightSet.Put( SvxFontHeightItem( static_cast<sal_uInt32>(nCTLSize), 100, RES_CHRATR_CTL_FONTSIZE ));
2151 pArgs = &aHeightSet;
2154 break;
2157 if( pArgs )
2159 bool bAuto = false;
2160 if ( !isCHRATR(nWhich) ||
2161 ( rSh.HasSelection() && rSh.IsSelFullPara() ) )
2163 SwTextFormatColl * pColl = rSh.GetCurTextFormatColl();
2164 if ( pColl && pColl->IsAutoUpdateFormat() )
2166 rSh.AutoUpdatePara( pColl, *pArgs );
2167 bAuto = true;
2171 if (!bAuto)
2173 rSh.SetAttrSet( *pArgs );
2177 else
2178 GetView().GetViewFrame()->GetDispatcher()->Execute( SID_CHAR_DLG );
2179 rReq.Done();
2182 void SwBaseShell::GetTextCtrlState( SfxItemSet& rSet )
2184 SwWrtShell &rSh = GetShell();
2185 rSh.GetCurAttr( rSet );
2188 void SwBaseShell::GetTextFontCtrlState( SfxItemSet& rSet )
2190 SwWrtShell &rSh = GetShell();
2191 bool bFirst = true;
2192 std::unique_ptr<SfxItemSet> pFntCoreSet;
2193 SvtScriptType nScriptType = SvtScriptType::LATIN;
2194 SfxWhichIter aIter( rSet );
2195 sal_uInt16 nWhich = aIter.FirstWhich();
2196 while( nWhich )
2198 switch( nWhich )
2200 case RES_CHRATR_FONT:
2201 case RES_CHRATR_FONTSIZE:
2202 case RES_CHRATR_WEIGHT:
2203 case RES_CHRATR_POSTURE:
2205 if( !pFntCoreSet )
2207 pFntCoreSet.reset(new SfxItemSet( *rSet.GetPool(),
2208 svl::Items<RES_CHRATR_BEGIN, RES_CHRATR_END-1>{} ));
2209 rSh.GetCurAttr( *pFntCoreSet );
2210 nScriptType = rSh.GetScriptType();
2211 // #i42732# input language should be preferred over
2212 // current cursor position to detect script type
2213 SwEditWin& rEditWin = GetView().GetEditWin();
2214 if( rEditWin.IsUseInputLanguage() )
2216 if(!rSh.HasSelection() && (
2217 nWhich == RES_CHRATR_FONT ||
2218 nWhich == RES_CHRATR_FONTSIZE ))
2220 LanguageType nInputLang = rEditWin.GetInputLanguage();
2221 if(nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
2222 nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
2226 SfxItemPool& rPool = *rSet.GetPool();
2227 SvxScriptSetItem aSetItem( rPool.GetSlotId( nWhich ), rPool );
2228 aSetItem.GetItemSet().Put( *pFntCoreSet, false );
2229 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScriptType );
2230 if( pI )
2232 rSet.Put( pI->CloneSetWhich(nWhich) );
2234 else
2235 rSet.InvalidateItem( nWhich );
2236 // Set input context of the SwEditWin according to the selected font and script type
2237 if(RES_CHRATR_FONT == nWhich)
2239 vcl::Font aFont;
2240 if (const SvxFontItem* pFontItem = dynamic_cast<const SvxFontItem*>(pI))
2242 aFont.SetFamilyName(pFontItem->GetFamilyName());
2243 aFont.SetStyleName(pFontItem->GetStyleName());
2244 aFont.SetFamily(pFontItem->GetFamily());
2245 aFont.SetPitch(pFontItem->GetPitch());
2246 aFont.SetCharSet(pFontItem->GetCharSet());
2249 bool bVertical = rSh.IsInVerticalText();
2250 aFont.SetOrientation(Degree10(bVertical ? 2700 : 0));
2251 aFont.SetVertical(bVertical);
2252 GetView().GetEditWin().SetInputContext( InputContext( aFont, InputContextFlags::Text |
2253 InputContextFlags::ExtText ) );
2256 break;
2258 default:
2259 if( bFirst )
2261 rSh.GetCurAttr( rSet );
2262 bFirst = false;
2265 nWhich = aIter.NextWhich();
2269 void SwBaseShell::GetBckColState(SfxItemSet &rSet)
2271 SwWrtShell &rSh = GetShell();
2272 SfxWhichIter aIter(rSet);
2273 sal_uInt16 nWhich(aIter.FirstWhich());
2274 SelectionType nSelType(rSh.GetSelectionType());
2275 std::unique_ptr<SvxBrushItem> aBrushItem(std::make_unique<SvxBrushItem>(RES_BACKGROUND));
2277 if( nWhich == SID_TABLE_CELL_BACKGROUND_COLOR )
2279 rSh.GetBoxBackground( aBrushItem );
2281 else
2283 // Adapt to new DrawingLayer FillStyle; use a parent which has XFILL_NONE set
2284 SfxItemSet aCoreSet(GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{});
2286 aCoreSet.SetParent(&GetView().GetDocShell()->GetDoc()->GetDfltFrameFormat()->GetAttrSet());
2288 if(nSelType & SelectionType::Graphic || SelectionType::Frame & nSelType)
2290 rSh.GetFlyFrameAttr(aCoreSet);
2292 else
2294 rSh.GetCurAttr(aCoreSet);
2297 aBrushItem = getSvxBrushItemFromSourceSet(aCoreSet, RES_BACKGROUND);
2300 while(nWhich)
2302 switch(nWhich)
2304 case SID_BACKGROUND_COLOR:
2305 case SID_TABLE_CELL_BACKGROUND_COLOR:
2307 SvxColorItem aColorItem(aBrushItem->GetColor(), nWhich);
2308 rSet.Put(aColorItem);
2309 break;
2311 case SID_ATTR_BRUSH:
2312 case RES_BACKGROUND:
2314 // if this was intended to have a independent copy of the Item to be set
2315 // this is not needed due to the ItemSet/Pool cloning Items which get set anyways.
2316 // Keeping code as reference - it may have had other reasons I do notz see (?!?)
2317 // std::unique_ptr<SfxPoolItem> pNewItem(aBrushItem.CloneSetWhich(GetPool().GetWhich(nWhich)));
2318 rSet.Put(*aBrushItem);
2319 break;
2323 nWhich = aIter.NextWhich();
2327 void SwBaseShell::ExecBckCol(SfxRequest& rReq)
2329 SwWrtShell &rSh = GetShell();
2330 SelectionType nSelType(rSh.GetSelectionType());
2331 const SfxItemSet* pArgs = rReq.GetArgs();
2332 sal_uInt16 nSlot(rReq.GetSlot());
2334 if (!pArgs && nSlot != SID_BACKGROUND_COLOR && nSlot != SID_TABLE_CELL_BACKGROUND_COLOR)
2336 return;
2339 std::unique_ptr<SvxBrushItem> aBrushItem(std::make_unique<SvxBrushItem>(RES_BACKGROUND));
2341 if ( nSlot == SID_TABLE_CELL_BACKGROUND_COLOR )
2343 rSh.GetBoxBackground( aBrushItem );
2345 else
2347 // Adapt to new DrawingLayer FillStyle; use a parent which has XFILL_NONE set
2348 SfxItemSet aCoreSet(GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{});
2350 aCoreSet.SetParent(&GetView().GetDocShell()->GetDoc()->GetDfltFrameFormat()->GetAttrSet());
2352 if((SelectionType::Frame & nSelType) || (SelectionType::Graphic & nSelType))
2354 rSh.GetFlyFrameAttr(aCoreSet);
2356 else
2358 rSh.GetCurAttr(aCoreSet);
2361 aBrushItem = getSvxBrushItemFromSourceSet(aCoreSet, RES_BACKGROUND);
2364 switch(nSlot)
2366 case SID_BACKGROUND_COLOR:
2367 case SID_TABLE_CELL_BACKGROUND_COLOR:
2369 const SfxPoolItem* pColorStringItem = nullptr;
2370 bool bIsTransparent = false;
2372 aBrushItem->SetGraphicPos(GPOS_NONE);
2374 sal_uInt16 nSlotId = (nSlot == SID_BACKGROUND_COLOR) ? SID_BACKGROUND_COLOR : SID_TABLE_CELL_BACKGROUND_COLOR;
2375 if (pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_COLOR_STR, false, &pColorStringItem))
2377 OUString sColor = static_cast<const SfxStringItem*>(pColorStringItem)->GetValue();
2378 if (sColor == "transparent")
2380 bIsTransparent = true;
2382 else
2384 Color aColor(ColorTransparency, sColor.toInt32(16));
2386 aBrushItem->SetColor(aColor);
2388 SvxColorItem aNewColorItem(nSlotId);
2389 aNewColorItem.SetValue(aColor);
2391 GetView().GetViewFrame()->GetBindings().SetState(aNewColorItem);
2394 else if (pArgs)
2396 const SvxColorItem& rNewColorItem = static_cast<const SvxColorItem&>(pArgs->Get(nSlotId));
2397 const Color& rNewColor = rNewColorItem.GetValue();
2398 aBrushItem->SetColor(rNewColor);
2399 GetView().GetViewFrame()->GetBindings().SetState(rNewColorItem);
2401 else
2403 bIsTransparent = true;
2406 if (bIsTransparent)
2408 aBrushItem->SetColor(COL_TRANSPARENT);
2409 rReq.AppendItem(SvxColorItem(COL_TRANSPARENT,nSlot));
2411 break;
2414 case SID_ATTR_BRUSH:
2415 case RES_BACKGROUND:
2417 assert(pArgs && "only SID_BACKGROUND_COLOR can have !pArgs, checked at entry");
2418 aBrushItem.reset(static_cast<SvxBrushItem*>(pArgs->Get(GetPool().GetWhich(nSlot)).Clone()));
2419 break;
2421 default:
2423 rReq.Ignore();
2424 OSL_FAIL("unknown message in ExecuteAttr!" );
2425 return;
2429 if ( nSlot == SID_TABLE_CELL_BACKGROUND_COLOR )
2431 rSh.SetBoxBackground( *aBrushItem );
2433 else
2435 // Adapt to new DrawingLayer FillStyle; use a parent which has XFILL_NONE set
2436 SfxItemSet aCoreSet(GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{});
2438 aCoreSet.SetParent(&GetView().GetDocShell()->GetDoc()->GetDfltFrameFormat()->GetAttrSet());
2439 setSvxBrushItemAsFillAttributesToTargetSet(*aBrushItem, aCoreSet);
2441 if((SelectionType::Frame & nSelType) || (SelectionType::Graphic & nSelType))
2443 // Template autoupdate
2444 SwFrameFormat* pFormat = rSh.GetSelectedFrameFormat();
2446 if(pFormat && pFormat->IsAutoUpdateFormat())
2448 rSh.AutoUpdateFrame(pFormat, aCoreSet);
2450 else
2452 rSh.SetFlyFrameAttr(aCoreSet);
2455 else
2457 SwTextFormatColl* pColl = rSh.GetCurTextFormatColl();
2459 if(pColl && pColl->IsAutoUpdateFormat())
2461 rSh.AutoUpdatePara(pColl, aCoreSet);
2463 else
2465 rSh.SetAttrSet(aCoreSet);
2470 rReq.Done();
2473 void SwBaseShell::GetBorderState(SfxItemSet &rSet)
2475 SwWrtShell &rSh = GetShell();
2476 // Tabele cell(s) selected?
2477 bool bPrepare = true;
2478 bool bTableMode = rSh.IsTableMode();
2479 if ( bTableMode )
2481 SfxItemSet aCoreSet( GetPool(),
2482 svl::Items<RES_BOX, RES_BOX,
2483 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER>{} );
2484 SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
2485 aCoreSet.Put( aBoxInfo );
2486 rSh.GetTabBorders( aCoreSet );
2487 rSet.Put( aCoreSet );
2489 else if ( rSh.IsFrameSelected() )
2491 SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr );
2492 rSet.Put( aMgr.GetAttrSet() );
2493 bPrepare = false;
2495 else
2496 // Get border attributes via shell quite normal
2497 rSh.GetCurAttr( rSet );
2498 if ( bPrepare )
2499 ::PrepareBoxInfo( rSet, rSh );
2500 // Switch the border toolbox controller mode
2501 rSet.Put( SfxBoolItem( SID_BORDER_REDUCED_MODE, !bTableMode ));
2504 void SwBaseShell::ExecDlg(SfxRequest &rReq)
2506 SwWrtShell &rSh = GetShell();
2507 weld::Window* pMDI = GetView().GetFrameWeld();
2508 // So that from the basic no dialogues for the background views are called:
2509 bool bBackground = (&GetView() != GetActiveView());
2510 const SfxPoolItem* pItem = nullptr;
2511 const SfxItemSet* pArgs = rReq.GetArgs();
2513 sal_uInt16 nSlot = rReq.GetSlot();
2514 const SfxItemSet* pOutSet = nullptr;
2515 bool bDone = false;
2516 if(pArgs)
2517 pArgs->GetItemState( GetPool().GetWhich(nSlot), false, &pItem );
2519 switch ( nSlot )
2521 case FN_FORMAT_TITLEPAGE_DLG:
2523 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2524 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateTitlePageDlg(pMDI));
2525 VclAbstractDialog::AsyncContext aContext;
2526 aContext.maEndDialogFn = [](sal_Int32){};
2527 pDlg->StartExecuteAsync(aContext);
2529 break;
2530 case FN_FORMAT_PAGE_DLG:
2531 case FN_FORMAT_PAGE_COLUMN_DLG:
2532 case FN_FORMAT_PAGE_SETTING_DLG:
2534 if( !bBackground )
2536 const size_t nCurIdx = rSh.GetCurPageDesc();
2537 const SwPageDesc& rPageDesc = rSh.GetPageDesc( nCurIdx );
2538 // Temporary view, because the shell does not need to be valid after the dialog
2539 // for example disable header
2540 SwView& rTempView = GetView();
2542 OString sPageId;
2543 switch (nSlot)
2545 case FN_FORMAT_PAGE_COLUMN_DLG:
2546 sPageId = "columns";
2547 break;
2548 case FN_FORMAT_PAGE_SETTING_DLG:
2549 sPageId = "page";
2550 break;
2551 case FN_FORMAT_PAGE_DLG:
2552 if (pItem)
2553 sPageId = OUStringToOString(static_cast<const SfxStringItem*>(pItem)->GetValue(), RTL_TEXTENCODING_UTF8);
2554 break;
2556 rTempView.GetDocShell()->FormatPage(rPageDesc.GetName(), sPageId, rSh, &rReq);
2557 rTempView.InvalidateRulerPos();
2559 bDone = true; // FormatPage() takes care of calling Done()
2562 break;
2563 case FN_FORMAT_BORDER_DLG:
2565 SfxItemSet aSet( rSh.GetAttrPool(),
2566 svl::Items<RES_BOX , RES_SHADOW,
2567 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER>{} );
2568 ScopedVclPtr<SfxAbstractDialog> pDlg;
2569 // Table cell(s) selected?
2570 if ( rSh.IsTableMode() )
2572 // Set border attributes Get/SetTabBorders()
2573 ::PrepareBoxInfo( aSet, rSh );
2574 rSh.GetTabBorders( aSet );
2575 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2576 pDlg.disposeAndReset(pFact->CreateSwBorderDlg(pMDI, aSet, SwBorderModes::TABLE));
2577 if ( pDlg->Execute() == RET_OK )
2579 rSh.SetTabBorders( *pDlg->GetOutputItemSet() );
2580 pOutSet = pDlg->GetOutputItemSet();
2583 else if ( rSh.IsFrameSelected() )
2585 // Set border attributes via Frame-Manager
2586 SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr );
2587 aSet.Put( aMgr.GetAttrSet() );
2589 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2590 pDlg.disposeAndReset(pFact->CreateSwBorderDlg(pMDI, aSet, SwBorderModes::FRAME));
2591 if ( pDlg->Execute() == RET_OK )
2593 aMgr.SetAttrSet( *pDlg->GetOutputItemSet() );
2594 aMgr.UpdateFlyFrame();
2595 pOutSet = pDlg->GetOutputItemSet();
2598 else
2600 // Set border attributes via Shell quite normal
2601 rSh.GetCurAttr( aSet );
2602 ::PrepareBoxInfo( aSet, rSh );
2604 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2605 pDlg.disposeAndReset(pFact->CreateSwBorderDlg(pMDI, aSet, SwBorderModes::PARA));
2606 if ( pDlg->Execute() == RET_OK )
2608 rSh.SetAttrSet( *pDlg->GetOutputItemSet() );
2609 pOutSet = pDlg->GetOutputItemSet();
2612 if(pOutSet)
2614 rReq.Done(*pOutSet);
2615 bDone = true;
2618 break;
2619 case FN_FORMAT_BACKGROUND_DLG:
2621 SfxItemSet aSet( rSh.GetAttrPool(),
2622 svl::Items<RES_BACKGROUND, RES_BACKGROUND,
2623 XATTR_FILL_FIRST, XATTR_FILL_LAST>{} );
2625 ScopedVclPtr<SfxAbstractDialog> pDlg;
2626 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2628 // Table cell(s) selected?
2629 if ( rSh.IsTableMode() )
2631 // Get background attributes of the table and put it in the set
2632 std::unique_ptr<SvxBrushItem> aBrush;
2633 rSh.GetBoxBackground( aBrush );
2634 pDlg.disposeAndReset(pFact->CreateSwBackgroundDialog(pMDI, aSet));
2635 aSet.Put( *aBrush );
2636 if ( pDlg->Execute() == RET_OK )
2639 rSh.SetBoxBackground( pDlg->GetOutputItemSet()->Get( RES_BACKGROUND ) );
2640 pOutSet = pDlg->GetOutputItemSet();
2643 else if ( rSh.IsFrameSelected() )
2646 rSh.GetFlyFrameAttr( aSet );
2648 pDlg.disposeAndReset(pFact->CreateSwBackgroundDialog(pMDI, aSet));
2649 if ( pDlg->Execute() == RET_OK )
2651 rSh.SetFlyFrameAttr(const_cast<SfxItemSet &>(*pDlg->GetOutputItemSet()) );
2652 pOutSet = pDlg->GetOutputItemSet();
2655 else
2657 // Set border attributes Umrandungsattribute with the shell quite normal.
2658 rSh.GetCurAttr( aSet );
2660 pDlg.disposeAndReset(pFact->CreateSwBackgroundDialog(pMDI, aSet));
2661 if ( pDlg->Execute() == RET_OK )
2663 rSh.SetAttrSet( *pDlg->GetOutputItemSet() );
2664 pOutSet = pDlg->GetOutputItemSet();
2667 if(pOutSet)
2669 rReq.Done(*pOutSet);
2670 bDone = true;
2673 break;
2674 case SID_ACCESSIBILITY_CHECK:
2676 sw::AccessibilityCheck aCheck(rSh.GetDoc());
2677 aCheck.check();
2678 svx::AccessibilityCheckDialog aDialog(pMDI, aCheck.getIssueCollection());
2679 aDialog.run();
2681 break;
2682 default:OSL_FAIL("wrong Dispatcher (basesh.cxx)");
2684 if(!bDone)
2685 rReq.Done();
2688 SwWrtShell& SwBaseShell::GetShell()
2690 return rView.GetWrtShell();
2693 SwWrtShell* SwBaseShell::GetShellPtr()
2695 return rView.GetWrtShellPtr();
2698 static void EndUndo(SwWrtShell& rSh)
2700 SwRewriter aRewriter;
2702 if (rSh.GetTableFormat())
2704 aRewriter.AddRule(UndoArg1, SwResId(STR_START_QUOTE));
2705 aRewriter.AddRule(UndoArg2, rSh.GetTableFormat()->GetName());
2706 aRewriter.AddRule(UndoArg3, SwResId(STR_END_QUOTE));
2709 rSh.EndUndo(SwUndoId::INSTABLE, &aRewriter); // If possible change the Shell
2712 static void InsertTableImpl(SwWrtShell& rSh,
2713 SwView &rTempView,
2714 const OUString& aTableName,
2715 sal_uInt16 nRows,
2716 sal_uInt16 nCols,
2717 SwInsertTableOptions aInsTableOpts,
2718 const OUString& aAutoName,
2719 const std::unique_ptr<SwTableAutoFormat>& pTAFormat)
2721 rSh.StartUndo(SwUndoId::INSTABLE);
2723 rSh.StartAllAction();
2724 if( rSh.HasSelection() )
2725 rSh.DelRight();
2727 rSh.InsertTable( aInsTableOpts, nRows, nCols, pTAFormat.get() );
2728 rSh.MoveTable( GotoPrevTable, fnTableStart );
2730 if( !aTableName.isEmpty() && !rSh.GetTableStyle( aTableName ) )
2731 rSh.GetTableFormat()->SetName( aTableName );
2733 if( pTAFormat != nullptr && !aAutoName.isEmpty()
2734 && aAutoName != SwViewShell::GetShellRes()->aStrNone )
2736 SwTableNode* pTableNode = const_cast<SwTableNode*>( rSh.IsCursorInTable() );
2737 if ( pTableNode )
2739 pTableNode->GetTable().SetTableStyleName( aAutoName );
2740 SwUndoTableAutoFormat* pUndo = new SwUndoTableAutoFormat( *pTableNode, *pTAFormat );
2741 if ( pUndo )
2742 rSh.GetIDocumentUndoRedo().AppendUndo( std::unique_ptr<SwUndo>(pUndo) );
2746 rSh.EndAllAction();
2747 rTempView.AutoCaption(TABLE_CAP);
2750 void SwBaseShell::InsertTable( SfxRequest& _rRequest )
2752 const SfxItemSet* pArgs = _rRequest.GetArgs();
2753 SwWrtShell& rSh = GetShell();
2755 if ( rSh.GetFrameType( nullptr, true ) & FrameTypeFlags::FOOTNOTE )
2756 return;
2758 SwView &rTempView = GetView(); // Because GetView() does not work after the shell exchange
2759 bool bHTMLMode = 0 != (::GetHtmlMode(rTempView.GetDocShell())&HTMLMODE_ON);
2760 bool bCallEndUndo = false;
2762 if( !pArgs && rSh.IsSelection() && !rSh.IsInClickToEdit() &&
2763 !rSh.IsTableMode() )
2765 const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
2766 SwInsertTableOptions aInsTableOpts = pModOpt->GetInsTableFlags(bHTMLMode);
2768 rSh.StartUndo(SwUndoId::INSTABLE);
2769 bCallEndUndo = true;
2771 bool bInserted = rSh.TextToTable( aInsTableOpts, '\t' );
2772 rSh.EnterStdMode();
2773 if (bInserted)
2774 rTempView.AutoCaption(TABLE_CAP);
2775 _rRequest.Done();
2777 else
2779 sal_uInt16 nColsIn = 0;
2780 sal_uInt16 nRowsIn = 0;
2781 SwInsertTableOptions aInsTableOptsIn( SwInsertTableFlags::All, 1 );
2782 OUString aTableNameIn;
2783 OUString aAutoNameIn;
2784 std::unique_ptr<SwTableAutoFormat> pTAFormatIn;
2786 if( pArgs && pArgs->Count() >= 2 )
2788 const SfxStringItem* pName = _rRequest.GetArg<SfxStringItem>(FN_INSERT_TABLE);
2789 const SfxUInt16Item* pCols = _rRequest.GetArg<SfxUInt16Item>(SID_ATTR_TABLE_COLUMN);
2790 const SfxUInt16Item* pRows = _rRequest.GetArg<SfxUInt16Item>(SID_ATTR_TABLE_ROW);
2791 const SfxInt32Item* pFlags = _rRequest.GetArg<SfxInt32Item>(FN_PARAM_1);
2792 const SfxStringItem* pAuto = _rRequest.GetArg<SfxStringItem>(FN_PARAM_2);
2794 if ( pName )
2795 aTableNameIn = pName->GetValue();
2796 if ( pCols )
2797 nColsIn = pCols->GetValue();
2798 if ( pRows )
2799 nRowsIn = pRows->GetValue();
2800 if ( pAuto )
2802 aAutoNameIn = pAuto->GetValue();
2803 if ( !aAutoNameIn.isEmpty() )
2805 SwTableAutoFormatTable aTableTable;
2806 aTableTable.Load();
2807 for ( size_t n=0; n<aTableTable.size(); n++ )
2809 if ( aTableTable[n].GetName() == aAutoNameIn )
2811 pTAFormatIn.reset(new SwTableAutoFormat( aTableTable[n] ));
2812 break;
2818 if ( pFlags )
2819 aInsTableOptsIn.mnInsMode = static_cast<SwInsertTableFlags>(pFlags->GetValue());
2820 else
2822 const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
2823 aInsTableOptsIn = pModOpt->GetInsTableFlags(bHTMLMode);
2827 if( !nColsIn || !nRowsIn )
2829 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2830 std::shared_ptr<AbstractInsTableDlg> pAbstractDialog(pFact->CreateInsTableDlg(rTempView));
2831 std::shared_ptr<weld::DialogController> pDialogController(pAbstractDialog->getDialogController());
2833 weld::DialogController::runAsync(pDialogController,
2834 [pAbstractDialog, &rSh, &rTempView, aTableNameIn, nRowsIn, nColsIn, aInsTableOptsIn, aAutoNameIn] (sal_Int32 nResult) {
2835 if( RET_OK == nResult )
2837 sal_uInt16 nCols = nColsIn;
2838 sal_uInt16 nRows = nRowsIn;
2839 SwInsertTableOptions aInsTableOpts = aInsTableOptsIn;
2840 OUString aTableName = aTableNameIn;
2841 OUString aAutoName = aAutoNameIn;
2842 std::unique_ptr<SwTableAutoFormat> pTAFormat;
2844 pAbstractDialog->GetValues( aTableName, nRows, nCols, aInsTableOpts, aAutoName, pTAFormat );
2846 if( nCols && nRows )
2848 InsertTableImpl( rSh, rTempView, aTableName, nRows, nCols, aInsTableOpts, aAutoName, pTAFormat );
2849 EndUndo(rSh);
2855 else
2857 // record before shell change
2858 _rRequest.AppendItem( SfxStringItem( FN_INSERT_TABLE, aTableNameIn ) );
2859 if ( !aAutoNameIn.isEmpty() )
2860 _rRequest.AppendItem( SfxStringItem( FN_PARAM_2, aAutoNameIn ) );
2861 _rRequest.AppendItem( SfxUInt16Item( SID_ATTR_TABLE_COLUMN, nColsIn ) );
2862 _rRequest.AppendItem( SfxUInt16Item( SID_ATTR_TABLE_ROW, nRowsIn ) );
2863 _rRequest.AppendItem( SfxInt32Item( FN_PARAM_1, static_cast<sal_Int32>(aInsTableOptsIn.mnInsMode) ) );
2864 _rRequest.Done();
2866 InsertTableImpl( rSh, rTempView, aTableNameIn, nRowsIn, nColsIn, aInsTableOptsIn, aAutoNameIn, pTAFormatIn );
2868 bCallEndUndo = true;
2872 if( bCallEndUndo )
2873 EndUndo(rSh);
2876 void SwBaseShell::GetGalleryState( SfxItemSet &rSet )
2878 SwWrtShell &rSh = GetShell();
2879 SfxWhichIter aIter( rSet );
2880 sal_uInt16 nWhich = aIter.FirstWhich();
2881 switch ( nWhich )
2883 case SID_GALLERY_BG_BRUSH:
2885 SelectionType nSel = rSh.GetSelectionType();
2886 SfxStringListItem aLst( nWhich );
2887 std::vector<OUString> &rLst = aLst.GetList();
2888 nParagraphPos = nGraphicPos = nOlePos = nFramePos = nTablePos =
2889 nTableRowPos = nTableCellPos = nPagePos =
2890 nHeaderPos = nFooterPos = 0;
2891 sal_uInt8 nPos = 1;
2892 rLst.push_back( SwResId( STR_SWBG_PAGE ) );
2893 nPagePos = nPos++;
2894 sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
2895 bool bHtmlMode = 0 != (nHtmlMode & HTMLMODE_ON);
2897 if ( (!bHtmlMode || (nHtmlMode & HTMLMODE_FULL_STYLES)) &&
2898 (nSel & SelectionType::Text) )
2900 rLst.push_back( SwResId( STR_SWBG_PARAGRAPH ) );
2901 nParagraphPos = nPos++;
2903 if ( (!bHtmlMode || (nHtmlMode & HTMLMODE_SOME_STYLES)) &&
2904 nSel & (SelectionType::Table|SelectionType::TableCell) )
2906 rLst.push_back( SwResId( STR_SWBG_TABLE ) );
2907 nTablePos = nPos++;
2909 if(!bHtmlMode)
2911 rLst.push_back( SwResId( STR_SWBG_TABLE_ROW ) );
2912 nTableRowPos = nPos++;
2915 rLst.push_back( SwResId( STR_SWBG_TABLE_CELL) );
2916 nTableCellPos = nPos++;
2918 if(!bHtmlMode)
2920 if ( nSel & SelectionType::Frame )
2922 rLst.push_back( SwResId( STR_SWBG_FRAME ) );
2923 nFramePos = nPos++;
2925 if ( nSel & SelectionType::Graphic )
2927 rLst.push_back( SwResId( STR_SWBG_GRAPHIC ) );
2928 nGraphicPos = nPos++;
2930 if ( nSel & SelectionType::Ole )
2932 rLst.push_back( SwResId( STR_SWBG_OLE ) );
2933 nOlePos = nPos++;
2935 const FrameTypeFlags nType = rSh.GetFrameType(nullptr,true);
2936 if ( nType & FrameTypeFlags::HEADER )
2938 rLst.push_back( SwResId( STR_SWBG_HEADER ) );
2939 nHeaderPos = nPos++;
2941 if ( nType & FrameTypeFlags::FOOTER )
2943 rLst.push_back( SwResId( STR_SWBG_FOOTER ) );
2944 nFooterPos = nPos;
2947 if ( rLst.empty() )
2948 rSet.DisableItem( nWhich );
2949 else
2950 rSet.Put( aLst );
2951 break;
2956 void SwBaseShell::ExecuteGallery(SfxRequest &rReq)
2958 SwWrtShell &rSh = GetShell();
2959 rSh.StartAction();
2960 const SfxItemSet* pArgs = rReq.GetArgs();
2961 sal_uInt16 nSlot = rReq.GetSlot();
2962 switch(nSlot)
2964 case SID_GALLERY_BG_BRUSH:
2966 if ( !pArgs )
2967 break;
2969 SelectionType nSel = rSh.GetSelectionType();
2970 if ( nSel & SelectionType::DrawObjectEditMode )
2971 break;
2973 const SfxUInt16Item* pPos = rReq.GetArg<SfxUInt16Item>(SID_GALLERY_BG_POS);
2974 const SvxBrushItem* pBrush = rReq.GetArg<SvxBrushItem>(SID_GALLERY_BG_BRUSH);
2975 if ( !pPos || !pBrush )
2976 break;
2978 sal_uInt8 nPos = pPos->GetValue();
2979 ++nPos;
2981 SvxBrushItem aBrush( *pBrush );
2982 aBrush.SetWhich( RES_BACKGROUND );
2983 if ( nPos == nParagraphPos )
2984 rSh.SetAttrItem( aBrush );
2985 else if ( nPos == nTablePos )
2986 rSh.SetTabBackground( aBrush );
2987 else if ( nPos == nTableRowPos )
2988 rSh.SetRowBackground( aBrush );
2989 else if ( nPos == nTableCellPos )
2990 rSh.SetBoxBackground( aBrush );
2991 else if ( nPos == nFramePos || nPos == nGraphicPos || nPos == nOlePos )
2993 SfxItemSet aCoreSet(GetPool(), svl::Items<RES_BACKGROUND, RES_BACKGROUND>{});
2994 aCoreSet.Put( aBrush );
2995 rSh.SetFlyFrameAttr( aCoreSet );
2997 else if ( nPos == nPagePos || nPos == nHeaderPos || nPos == nFooterPos )
2999 sal_uInt16 nDesc = rSh.GetCurPageDesc();
3000 SwPageDesc aDesc( rSh.GetPageDesc( nDesc ) );
3001 if ( nPos == nPagePos )
3002 aDesc.GetMaster().SetFormatAttr( aBrush );
3003 else if ( nPos == nHeaderPos )
3005 SwFormatHeader aHead( aDesc.GetMaster().GetHeader() );
3006 aHead.GetHeaderFormat()->SetFormatAttr( aBrush );
3007 aDesc.GetMaster().SetFormatAttr( aHead );
3009 else if ( nPos == nFooterPos )
3011 SwFormatFooter aFoot( aDesc.GetMaster().GetFooter() );
3012 aFoot.GetFooterFormat()->SetFormatAttr( aBrush );
3013 aDesc.GetMaster().SetFormatAttr( aFoot );
3015 rSh.ChgPageDesc( nDesc, aDesc );
3017 break;
3020 rSh.EndAction();
3021 rReq.Done();
3024 void SwBaseShell::ExecField( SfxRequest const & rReq )
3026 sal_uInt16 nSlot = rReq.GetSlot();
3027 switch( nSlot )
3029 #if HAVE_FEATURE_DBCONNECTIVITY
3030 case FN_CHANGE_DBFIELD:
3032 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
3033 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSwChangeDBDlg(GetView()));
3034 pDlg->Execute();
3036 break;
3037 #endif
3038 default:
3039 OSL_FAIL("wrong dispatcher");
3043 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */