1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <config_features.h>
21 
22 #include <sal/config.h>
23 
24 #include <hintids.hxx>
25 #include <svl/urihelper.hxx>
26 #include <svl/languageoptions.hxx>
27 #include <svx/svxids.hrc>
28 #include <sfx2/linkmgr.hxx>
29 #include <sfx2/htmlmode.hxx>
30 #include <svx/imapdlg.hxx>
31 #include <sfx2/dispatch.hxx>
32 #include <sfx2/docfile.hxx>
33 #include <sfx2/viewfrm.hxx>
34 #include <sfx2/request.hxx>
35 #include <svl/whiter.hxx>
36 #include <svl/visitem.hxx>
37 #include <sfx2/objitem.hxx>
38 #include <vcl/graphicfilter.hxx>
39 #include <svx/gallery.hxx>
40 #include <editeng/langitem.hxx>
41 #include <svx/clipfmtitem.hxx>
42 #include <svx/contdlg.hxx>
43 #include <vcl/graph.hxx>
44 #include <vcl/inputctx.hxx>
45 #include <svl/slstitm.hxx>
46 #include <svl/ptitem.hxx>
47 #include <svl/itemiter.hxx>
48 #include <svl/stritem.hxx>
49 #include <editeng/colritem.hxx>
50 #include <editeng/fhgtitem.hxx>
51 #include <editeng/fontitem.hxx>
52 #include <editeng/shaditem.hxx>
53 #include <editeng/boxitem.hxx>
54 #include <svl/srchitem.hxx>
55 #include <editeng/ulspitem.hxx>
56 #include <editeng/lrspitem.hxx>
57 #include <editeng/brushitem.hxx>
58 #include <editeng/opaqitem.hxx>
59 #include <editeng/sizeitem.hxx>
60 #include <svx/flagsdef.hxx>
61 #include <svx/xflclit.hxx>
62 #include <editeng/scripttypeitem.hxx>
63 #include <sfx2/objface.hxx>
64 #include <fmturl.hxx>
65 #include <fmthdft.hxx>
66 #include <fmtclds.hxx>
67 #include <docsh.hxx>
68 #include <wrtsh.hxx>
69 #include <view.hxx>
70 #include <swmodule.hxx>
71 #include <swundo.hxx>
72 #include <fldbas.hxx>
73 #include <uitool.hxx>
74 #include <basesh.hxx>
75 #include <viewopt.hxx>
76 #include <fontcfg.hxx>
77 #include <docstat.hxx>
78 #include <usrfld.hxx>
79 #include <expfld.hxx>
80 #include <fmtsrnd.hxx>
81 #include <fldmgr.hxx>
82 #include <frmmgr.hxx>
83 #include <tablemgr.hxx>
84 #include <mdiexp.hxx>
85 #include <swdtflvr.hxx>
86 #include <pagedesc.hxx>
87 #include <convert.hxx>
88 #include <fmtcol.hxx>
89 #include <edtwin.hxx>
90 #include <tblafmt.hxx>
91 #include <caption.hxx>
92 #include <swwait.hxx>
93 #include <cmdid.h>
94 #include <globals.hrc>
95 #include <strings.hrc>
96 #include <globals.h>
97 #include <unotxdoc.hxx>
98 #include <fmtinfmt.hxx>
99 #include <doc.hxx>
100 #include <IDocumentSettingAccess.hxx>
101 #include <IDocumentUndoRedo.hxx>
102 #include <swabstdlg.hxx>
103 #include <modcfg.hxx>
104 #include <instable.hxx>
105 #include <svx/fmshell.hxx>
106 #include <SwRewriter.hxx>
107 #include <unomid.h>
108 #include <svx/galleryitem.hxx>
109 #include <com/sun/star/gallery/GalleryItemType.hpp>
110 #include <memory>
111 
112 #include <svx/unobrushitemhelper.hxx>
113 #include <comphelper/scopeguard.hxx>
114 #include <comphelper/lok.hxx>
115 
116 #include <svx/svxdlg.hxx>
117 
118 #include <SwStyleNameMapper.hxx>
119 #include <poolfmt.hxx>
120 #include <shellres.hxx>
121 #include <UndoTable.hxx>
122 
123 FlyMode SwBaseShell::eFrameMode = FLY_DRAG_END;
124 
125 // These variables keep the state of Gallery (slot SID_GALLERY_BG_BRUSH)
126 // detected by GetGalleryState() for the subsequent ExecuteGallery() call.
127 
128 static sal_uInt8 nParagraphPos;
129 static sal_uInt8 nGraphicPos;
130 static sal_uInt8 nOlePos;
131 static sal_uInt8 nFramePos;
132 static sal_uInt8 nTablePos;
133 static sal_uInt8 nTableRowPos;
134 static sal_uInt8 nTableCellPos;
135 static sal_uInt8 nPagePos;
136 static sal_uInt8 nHeaderPos;
137 static sal_uInt8 nFooterPos;
138 
139 #define ShellClass_SwBaseShell
140 #include <sfx2/msg.hxx>
141 #include <swslots.hxx>
142 
143 namespace
144 {
GetContourDlg(SwView const & rView)145     SvxContourDlg* GetContourDlg(SwView const &rView)
146     {
147         SfxChildWindow *pWnd = rView.GetViewFrame()->GetChildWindow(SvxContourDlgChildWindow::GetChildWindowId());
148         return pWnd ? static_cast<SvxContourDlg*>(pWnd->GetController().get()) : nullptr;
149     }
150 
GetIMapDlg(SwView const & rView)151     SvxIMapDlg* GetIMapDlg(SwView const &rView)
152     {
153         SfxChildWindow* pWnd = rView.GetViewFrame()->GetChildWindow(SvxIMapDlgChildWindow::GetChildWindowId());
154         return pWnd ? static_cast<SvxIMapDlg*>(pWnd->GetController().get()) : nullptr;
155     }
156 }
157 
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;
162 
SFX_IMPL_SUPERCLASS_INTERFACE(SwBaseShell,SfxShell)163 SFX_IMPL_SUPERCLASS_INTERFACE(SwBaseShell, SfxShell)
164 
165 void SwBaseShell::InitInterface_Impl()
166 {
167     GetStaticInterface()->RegisterChildWindow(SvxIMapDlgChildWindow::GetChildWindowId());
168     GetStaticInterface()->RegisterChildWindow(SvxContourDlgChildWindow::GetChildWindowId());
169 }
170 
171 
lcl_UpdateIMapDlg(SwWrtShell & rSh)172 static void lcl_UpdateIMapDlg( SwWrtShell& rSh )
173 {
174     Graphic aGrf( rSh.GetIMapGraphic() );
175     GraphicType nGrfType = aGrf.GetType();
176     void* pEditObj = GraphicType::NONE != nGrfType && GraphicType::Default != nGrfType
177                         ? rSh.GetIMapInventor() : nullptr;
178     std::unique_ptr<TargetList> pList(new TargetList);
179     SfxFrame::GetDefaultTargetList(*pList);
180 
181     SfxItemSet aSet( rSh.GetAttrPool(), svl::Items<RES_URL, RES_URL>{} );
182     rSh.GetFlyFrameAttr( aSet );
183     const SwFormatURL &rURL = aSet.Get( RES_URL );
184     SvxIMapDlgChildWindow::UpdateIMapDlg(
185             aGrf, rURL.GetMap(), pList.get(), pEditObj );
186 }
187 
lcl_UpdateContourDlg(SwWrtShell & rSh,SelectionType nSel)188 static bool lcl_UpdateContourDlg( SwWrtShell &rSh, SelectionType nSel )
189 {
190     Graphic aGraf( rSh.GetIMapGraphic() );
191     GraphicType nGrfType = aGraf.GetType();
192     bool bRet = GraphicType::NONE != nGrfType && GraphicType::Default != nGrfType;
193     if( bRet )
194     {
195         OUString aGrfName;
196         if ( nSel & SelectionType::Graphic )
197             rSh.GetGrfNms( &aGrfName, nullptr );
198 
199         SvxContourDlg *pDlg = GetContourDlg(rSh.GetView());
200         if (pDlg)
201         {
202             pDlg->Update(aGraf, !aGrfName.isEmpty(),
203                          rSh.GetGraphicPolygon(), rSh.GetIMapInventor());
204         }
205     }
206     return bRet;
207 }
208 
ExecDelete(SfxRequest & rReq)209 void SwBaseShell::ExecDelete(SfxRequest &rReq)
210 {
211     SwWrtShell &rSh = GetShell();
212     SwEditWin& rTmpEditWin = GetView().GetEditWin();
213     switch(rReq.GetSlot())
214     {
215         case SID_DELETE:
216             rSh.DelRight();
217             break;
218 
219         case FN_BACKSPACE:
220 
221             if( rSh.IsNoNum() )
222             {
223                 rSh.SttCursorMove();
224                 bool bLeft = rSh.Left( CRSR_SKIP_CHARS, true, 1, false  );
225                 if( bLeft )
226                 {
227                     rSh.DelLeft();
228                 }
229                 else
230                     // JP 15.07.96: If it no longer goes forward, cancel
231                     //              the numbering. For example at the beginning
232                     //              of a doc, frame, table or an area.
233                     rSh.DelNumRules();
234 
235                 rSh.EndCursorMove();
236                 break;
237             }
238 
239             [[fallthrough]]; // otherwise call DelLeft
240         case FN_SHIFT_BACKSPACE:
241             rSh.DelLeft();
242             break;
243         default:
244             OSL_FAIL("wrong Dispatcher");
245             return;
246     }
247     rReq.Done();
248 
249     //#i42732# - notify the edit window that from now on we do not use the input language
250     rTmpEditWin.SetUseInputLanguage( false );
251 }
252 
ExecClpbrd(SfxRequest & rReq)253 void SwBaseShell::ExecClpbrd(SfxRequest &rReq)
254 {
255     // Attention: At risk of suicide!
256     // After paste, paste special the shell can be destroy.
257 
258     SwWrtShell &rSh = GetShell();
259     sal_uInt16 nId = rReq.GetSlot();
260     bool bIgnore = false;
261     PasteTableType ePasteTable = PasteTableType::PASTE_DEFAULT;
262 
263     switch( nId )
264     {
265         case SID_CUT:
266         case SID_COPY:
267             rView.GetEditWin().FlushInBuffer();
268             if ( rSh.HasSelection() )
269             {
270                 rtl::Reference<SwTransferable> pTransfer = new SwTransferable( rSh );
271 
272                 if ( nId == SID_CUT && FlyProtectFlags::NONE == rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent) )
273                     pTransfer->Cut();
274                 else
275                 {
276                     const bool bLockedView = rSh.IsViewLocked();
277                     rSh.LockView( true );    //lock visible section
278                     pTransfer->Copy();
279                     rSh.LockView( bLockedView );
280                 }
281                 break;
282             }
283             return;
284 
285         case FN_PASTE_NESTED_TABLE:
286         case FN_TABLE_PASTE_ROW_BEFORE:
287         case FN_TABLE_PASTE_COL_BEFORE:
288             switch ( nId )
289             {
290                 case FN_PASTE_NESTED_TABLE:
291                      ePasteTable = PasteTableType::PASTE_TABLE;
292                      break;
293                 case FN_TABLE_PASTE_ROW_BEFORE:
294                      ePasteTable = PasteTableType::PASTE_ROW;
295                      break;
296                 case FN_TABLE_PASTE_COL_BEFORE:
297                      ePasteTable = PasteTableType::PASTE_COLUMN;
298                      break;
299                 default:
300                     ;
301             }
302             [[fallthrough]];
303         case SID_PASTE:
304             {
305                 TransferableDataHelper aDataHelper(
306                     TransferableDataHelper::CreateFromSystemClipboard( &rSh.GetView().GetEditWin() ) );
307                 if( aDataHelper.GetXTransferable().is()
308                     && SwTransferable::IsPaste( rSh, aDataHelper ) )
309                 {
310                     // Temporary variables, because the shell could already be
311                     // destroyed after the paste.
312                     SwView* pView = &rView;
313 
314                     RndStdIds nAnchorType = RndStdIds::FLY_AT_PARA;
315                     const SfxUInt16Item* pAnchorType = rReq.GetArg<SfxUInt16Item>(FN_PARAM_1);
316                     if (pAnchorType)
317                         nAnchorType = static_cast<RndStdIds>(pAnchorType->GetValue());
318                     bool bIgnoreComments = false;
319                     const SfxBoolItem* pIgnoreComments = rReq.GetArg<SfxBoolItem>(FN_PARAM_2);
320                     if (pIgnoreComments)
321                         bIgnoreComments = pIgnoreComments->GetValue();
322                     SwTransferable::Paste(rSh, aDataHelper, nAnchorType, bIgnoreComments, ePasteTable);
323 
324                     if( rSh.IsFrameSelected() || rSh.IsObjSelected() )
325                         rSh.EnterSelFrameMode();
326                     pView->AttrChangedNotify(nullptr);
327                 }
328                 else
329                     return;
330             }
331             break;
332 
333         case SID_CLIPBOARD_FORMAT_ITEMS:
334             {
335                 const SfxItemSet* pArgs = rReq.GetArgs();
336                 const SfxPoolItem* pFormat;
337                 if( pArgs && SfxItemState::SET == pArgs->GetItemState( nId, false, &pFormat ) )
338                 {
339                     TransferableDataHelper aDataHelper(
340                         TransferableDataHelper::CreateFromSystemClipboard(
341                                             &rSh.GetView().GetEditWin()) );
342                     if( aDataHelper.GetXTransferable().is()
343                         /*&& SwTransferable::IsPaste( rSh, aDataHelper )*/ )
344                     {
345                         // Temporary variables, because the shell could already be
346                         // destroyed after the paste.
347                         SwView* pView = &rView;
348 
349                         SwTransferable::PasteFormat( rSh, aDataHelper,
350                                         static_cast<SotClipboardFormatId>(static_cast<const SfxUInt32Item*>(pFormat)->GetValue()) );
351 
352                         //Done() has to be called before the shell has been removed
353                         rReq.Done();
354                         bIgnore = true;
355                         if( rSh.IsFrameSelected() || rSh.IsObjSelected())
356                             rSh.EnterSelFrameMode();
357                         pView->AttrChangedNotify(nullptr);
358                     }
359                 }
360             }
361             break;
362 
363         case SID_PASTE_UNFORMATTED:
364             {
365                 TransferableDataHelper aDataHelper(
366                     TransferableDataHelper::CreateFromSystemClipboard( &rSh.GetView().GetEditWin()) );
367                 if( aDataHelper.GetXTransferable().is()
368                     && SwTransferable::IsPaste( rSh, aDataHelper ) )
369                 {
370                     // Temporary variables, because the shell could already be
371                     // destroyed after the paste.
372                     SwView* pView = &rView;
373                     rReq.Ignore();
374                     bIgnore = true;
375                     if(SwTransferable::PasteUnformatted( rSh, aDataHelper ))
376                     {
377                         SfxViewFrame* pViewFrame = pView->GetViewFrame();
378                         uno::Reference< frame::XDispatchRecorder > xRecorder =
379                             pViewFrame->GetBindings().GetRecorder();
380                         if(xRecorder.is()) {
381                             SfxRequest aReq( pViewFrame, SID_CLIPBOARD_FORMAT_ITEMS );
382                             aReq.AppendItem( SfxUInt32Item( SID_CLIPBOARD_FORMAT_ITEMS, static_cast<sal_uInt32>(SotClipboardFormatId::STRING) ) );
383                             aReq.Done();
384                         }
385                     }
386 
387                     if (rSh.IsFrameSelected() || rSh.IsObjSelected())
388                         rSh.EnterSelFrameMode();
389                     pView->AttrChangedNotify(nullptr);
390                 }
391                 else
392                     return;
393             }
394             break;
395 
396         case SID_PASTE_SPECIAL:
397             {
398                 std::shared_ptr<TransferableDataHelper> aDataHelper;
399                 aDataHelper.reset(new TransferableDataHelper(TransferableDataHelper::CreateFromSystemClipboard( &rSh.GetView().GetEditWin())));
400 
401                 if( aDataHelper->GetXTransferable().is()
402                     && SwTransferable::IsPaste( rSh, *aDataHelper )
403                     && !rSh.CursorInsideInputField() )
404                 {
405                     rReq.Ignore();
406                     bIgnore = true;
407 
408                     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
409                     VclPtr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog( rReq.GetFrameWeld() ));
410 
411                     // Prepare the dialog
412                     SwTransferable::PrePasteSpecial(rSh, *aDataHelper, pDlg);
413                     pDlg->PreGetFormat(*aDataHelper);
414 
415 
416                     pDlg->StartExecuteAsync([aDataHelper, pDlg, &rSh, this](sal_Int32 nResult){
417                     if (nResult == RET_OK)
418                     {
419                         // Temporary variables, because the shell could already be
420                         // destroyed after the paste.
421                         SwView* pView = &rView;
422                         bool bRet = false;
423                         SotClipboardFormatId nFormatId = pDlg->GetFormatOnly();
424 
425                         if( nFormatId != SotClipboardFormatId::NONE )
426                             bRet = SwTransferable::PasteFormat( rSh, *aDataHelper, nFormatId );
427 
428                         if (bRet)
429                         {
430                             SfxViewFrame* pViewFrame = pView->GetViewFrame();
431                             uno::Reference< frame::XDispatchRecorder > xRecorder =
432                                     pViewFrame->GetBindings().GetRecorder();
433                             if(xRecorder.is()) {
434                                 SfxRequest aReq( pViewFrame, SID_CLIPBOARD_FORMAT_ITEMS );
435                                 aReq.AppendItem( SfxUInt32Item( SID_CLIPBOARD_FORMAT_ITEMS, static_cast<sal_uInt32>(nFormatId) ) );
436                                 aReq.Done();
437                             }
438                         }
439 
440                         if (rSh.IsFrameSelected() || rSh.IsObjSelected())
441                             rSh.EnterSelFrameMode();
442                         pView->AttrChangedNotify(nullptr);
443                     }
444 
445                     pDlg->disposeOnce();
446 
447                     });
448                 }
449                 else
450                     return;
451             }
452             break;
453 
454         default:
455             OSL_FAIL("wrong Dispatcher");
456             return;
457     }
458     if(!bIgnore)
459         rReq.Done();
460 }
461 
462 // ClipBoard state
463 
StateClpbrd(SfxItemSet & rSet)464 void SwBaseShell::StateClpbrd(SfxItemSet &rSet)
465 {
466     SwWrtShell &rSh = GetShell();
467     SfxWhichIter aIter(rSet);
468 
469     const bool bCopy = rSh.HasSelection();
470 
471     sal_uInt16 nWhich = aIter.FirstWhich();
472 
473     while(nWhich)
474     {
475         switch(nWhich)
476         {
477         case SID_CUT:
478             if( FlyProtectFlags::NONE != rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent ) )
479             {
480                 rSet.DisableItem( nWhich );
481                 break;
482             }
483             [[fallthrough]];
484         case SID_COPY:
485             if( !bCopy || GetView().isContentExtractionLocked())
486                 rSet.DisableItem( nWhich );
487             break;
488 
489         case FN_PASTE_NESTED_TABLE:
490         case FN_TABLE_PASTE_ROW_BEFORE:
491         case FN_TABLE_PASTE_COL_BEFORE:
492             if( !rSh.IsCursorInTable()
493                 || !GetView().IsPasteSpecialAllowed()
494                 || rSh.CursorInsideInputField()
495                 // disable if not a native Writer table and not a spreadsheet format
496                 || !GetView().IsPasteSpreadsheet(rSh.GetTableCopied()) )
497             {
498                 rSet.DisableItem( nWhich );
499             }
500             break;
501 
502         case SID_PASTE:
503             if( !GetView().IsPasteAllowed() )
504             {
505                 rSet.DisableItem( nWhich );
506             }
507             break;
508 
509         case SID_PASTE_SPECIAL:
510             if( !GetView().IsPasteSpecialAllowed()
511                 || rSh.CursorInsideInputField() )
512             {
513                 rSet.DisableItem( nWhich );
514             }
515             break;
516 
517         case SID_PASTE_UNFORMATTED:
518             if( !GetView().IsPasteSpecialAllowed() )
519             {
520                 rSet.DisableItem( nWhich );
521             }
522             break;
523 
524         case SID_CLIPBOARD_FORMAT_ITEMS:
525             {
526                 TransferableDataHelper aDataHelper(
527                     TransferableDataHelper::CreateFromSystemClipboard(
528                                             &rSh.GetView().GetEditWin()) );
529 
530                 SvxClipboardFormatItem aFormatItem( nWhich );
531                 SwTransferable::FillClipFormatItem( rSh, aDataHelper, aFormatItem );
532                 rSet.Put( aFormatItem );
533             }
534             break;
535         }
536         nWhich = aIter.NextWhich();
537     }
538 }
539 
540 // Perform undo
541 
ExecUndo(SfxRequest & rReq)542 void SwBaseShell::ExecUndo(SfxRequest &rReq)
543 {
544     SwWrtShell &rWrtShell = GetShell();
545 
546     SwUndoId nUndoId(SwUndoId::EMPTY);
547     sal_uInt16 nId = rReq.GetSlot(), nCnt = 1;
548     const SfxItemSet* pArgs = rReq.GetArgs();
549     const SfxPoolItem* pItem;
550     if( pArgs && SfxItemState::SET == pArgs->GetItemState( nId, false, &pItem ))
551         nCnt = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
552 
553     // Repair mode: allow undo/redo of all undo actions, even if access would
554     // be limited based on the view shell ID.
555     bool bRepair = false;
556     if (pArgs && pArgs->GetItemState(SID_REPAIRPACKAGE, false, &pItem) == SfxItemState::SET)
557         bRepair = static_cast<const SfxBoolItem*>(pItem)->GetValue();
558 
559     // #i106349#: save pointer: undo/redo may delete the shell, i.e., this!
560     SfxViewFrame *const pViewFrame( GetView().GetViewFrame() );
561 
562     IDocumentUndoRedo& rUndoRedo = rWrtShell.GetIDocumentUndoRedo();
563     bool bWasRepair = rUndoRedo.DoesRepair();
564     rUndoRedo.DoRepair(bRepair);
565     comphelper::ScopeGuard aGuard([&rUndoRedo, bWasRepair]()
566     {
567         rUndoRedo.DoRepair(bWasRepair);
568     });
569 
570     switch( nId )
571     {
572         case SID_UNDO:
573             if (rUndoRedo.GetLastUndoInfo(nullptr, &nUndoId, &rWrtShell.GetView()))
574             {
575                 for (SwViewShell& rShell : rWrtShell.GetRingContainer())
576                     rShell.LockPaint();
577                 rWrtShell.Do( SwWrtShell::UNDO, nCnt );
578                 for (SwViewShell& rShell : rWrtShell.GetRingContainer())
579                     rShell.UnlockPaint();
580             }
581             break;
582 
583         case SID_REDO:
584             if (rUndoRedo.GetFirstRedoInfo(nullptr, &nUndoId, &rWrtShell.GetView()))
585             {
586                 for (SwViewShell& rShell : rWrtShell.GetRingContainer())
587                     rShell.LockPaint();
588                 rWrtShell.Do( SwWrtShell::REDO, nCnt );
589                 for (SwViewShell& rShell : rWrtShell.GetRingContainer())
590                     rShell.UnlockPaint();
591             }
592             break;
593 
594         case SID_REPEAT:
595             rWrtShell.Do( SwWrtShell::REPEAT );
596             break;
597         default:
598             OSL_FAIL("wrong Dispatcher");
599     }
600 
601     if (nUndoId == SwUndoId::CONFLICT)
602     {
603         rReq.SetReturnValue( SfxUInt32Item(nId, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
604     }
605     else if (nUndoId == SwUndoId::INSFMTATTR)
606     {
607         rWrtShell.GetDoc()->GetDocShell()->GetStyleSheetPool()->Broadcast(SfxHint(SfxHintId::StyleSheetModified));
608     }
609 
610     if (pViewFrame) { pViewFrame->GetBindings().InvalidateAll(false); }
611 }
612 
613 // State of undo
614 
StateUndo(SfxItemSet & rSet)615 void SwBaseShell::StateUndo(SfxItemSet &rSet)
616 {
617     SwUndoId nUndoId(SwUndoId::EMPTY);
618     SwWrtShell &rSh = GetShell();
619     SfxWhichIter aIter(rSet);
620     sal_uInt16 nWhich = aIter.FirstWhich();
621     while(nWhich)
622     {
623         switch(nWhich)
624         {
625             case SID_UNDO:
626             {
627                 if (rSh.GetLastUndoInfo(nullptr, &nUndoId, &rSh.GetView()))
628                 {
629                     rSet.Put( SfxStringItem(nWhich,
630                         rSh.GetDoString(SwWrtShell::UNDO)));
631                 }
632                 else if (nUndoId == SwUndoId::CONFLICT)
633                 {
634                     rSet.Put( SfxUInt32Item(nWhich, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
635                 }
636                 else
637                     rSet.DisableItem(nWhich);
638 
639                 break;
640             }
641             case SID_REDO:
642             {
643                 if (rSh.GetFirstRedoInfo(nullptr, &nUndoId, &rSh.GetView()))
644                 {
645                     rSet.Put(SfxStringItem(nWhich,
646                         rSh.GetDoString(SwWrtShell::REDO)));
647                 }
648                 else if (nUndoId == SwUndoId::CONFLICT)
649                 {
650                      rSet.Put( SfxInt32Item(nWhich, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
651                 }
652                 else
653                     rSet.DisableItem(nWhich);
654                 break;
655             }
656             case SID_REPEAT:
657             {   // Repeat is only possible if no REDO is possible - UI-Restriction
658                 if ((!rSh.GetFirstRedoInfo(nullptr, nullptr)) &&
659                     !rSh.IsSelFrameMode() &&
660                     (SwUndoId::EMPTY != rSh.GetRepeatInfo(nullptr)))
661                 {
662                     rSet.Put(SfxStringItem(nWhich, rSh.GetRepeatString()));
663                 }
664                 else
665                     rSet.DisableItem(nWhich);
666                 break;
667             }
668 
669             case SID_GETUNDOSTRINGS:
670                 if (rSh.GetLastUndoInfo(nullptr, nullptr))
671                 {
672                     SfxStringListItem aStrLst( nWhich );
673                     rSh.GetDoStrings( SwWrtShell::UNDO, aStrLst );
674                     rSet.Put( aStrLst );
675                 }
676                 else
677                     rSet.DisableItem( nWhich );
678                 break;
679 
680             case SID_GETREDOSTRINGS:
681                 if (rSh.GetFirstRedoInfo(nullptr, nullptr))
682                 {
683                     SfxStringListItem aStrLst( nWhich );
684                     rSh.GetDoStrings( SwWrtShell::REDO, aStrLst );
685                     rSet.Put( aStrLst );
686                 }
687                 else
688                     rSet.DisableItem( nWhich );
689                 break;
690         }
691         nWhich = aIter.NextWhich();
692     }
693 }
694 
695 // Evaluate respectively dispatching the slot Id
696 
Execute(SfxRequest & rReq)697 void SwBaseShell::Execute(SfxRequest &rReq)
698 {
699     const SfxPoolItem *pItem;
700     SwWrtShell &rSh = GetShell();
701     const SfxItemSet* pArgs = rReq.GetArgs();
702     bool bMore = false;
703 
704     sal_uInt16 nSlot = rReq.GetSlot();
705     switch(nSlot)
706     {
707         case FN_REPAGINATE:
708             {
709                 Reference < XModel > xModel = GetView().GetDocShell()->GetModel();
710                 auto pDoc = comphelper::getUnoTunnelImplementation<SwXTextDocument>(xModel);
711                 pDoc->NotifyRefreshListeners();
712                 rSh.CalcLayout();
713             }
714             break;
715         case FN_UPDATE_FIELDS:
716             {
717                 rSh.UpdateDocStat();
718                 rSh.EndAllTableBoxEdit();
719                 rSh.SwViewShell::UpdateFields(true);
720 
721                 if( rSh.IsCursorInTable() )
722                 {
723                     if( !rSh.IsTableComplexForChart() )
724                         SwTableFUNC( &rSh ).UpdateChart();
725                     rSh.ClearTableBoxContent();
726                     rSh.SaveTableBoxContent();
727                 }
728             }
729             break;
730         case FN_UPDATE_CHARTS:
731             {
732                 SwWait aWait( *rView.GetDocShell(), true );
733                 rSh.UpdateAllCharts();
734             }
735             break;
736 
737         case FN_UPDATE_ALL:
738             {
739                 SwView&  rTempView = GetView();
740                 rSh.EnterStdMode();
741                 if( !rSh.GetLinkManager().GetLinks().empty() )
742                 {
743                     rSh.StartAllAction();
744                     rSh.GetLinkManager().UpdateAllLinks( false, true, nullptr );
745                     rSh.EndAllAction();
746                 }
747                 SfxDispatcher &rDis = *rTempView.GetViewFrame()->GetDispatcher();
748                 rDis.Execute( FN_UPDATE_FIELDS );
749                 rDis.Execute( FN_UPDATE_TOX );
750                 rDis.Execute( FN_UPDATE_CHARTS );
751                 rSh.CalcLayout();
752             }
753             break;
754 
755         case FN_UPDATE_INPUTFIELDS:
756             rSh.UpdateInputFields();
757             break;
758 
759         case FN_PREV_BOOKMARK:
760             rReq.SetReturnValue(SfxBoolItem( nSlot, rSh.GoPrevBookmark()));
761             break;
762         case FN_NEXT_BOOKMARK:
763             rReq.SetReturnValue(SfxBoolItem( nSlot, rSh.GoNextBookmark()));
764             break;
765 
766         case FN_GOTO_NEXT_MARK:
767         case FN_GOTO_PREV_MARK:
768         {
769             SwFieldMgr aFieldMgr;
770             SwFieldType* pFieldType = aFieldMgr.GetFieldType(SwFieldIds::JumpEdit);
771 
772             if (pFieldType)
773             {
774                 if (rSh.IsSelFrameMode())
775                 {
776                     rSh.UnSelectFrame();
777                     rSh.LeaveSelFrameMode();
778                 }
779 
780                 if (rSh.HasMark())
781                 {
782                     SwMvContext aMvContext(&rSh);
783                     if (rSh.IsCursorPtAtEnd())
784                         rSh.SwapPam();
785                     rSh.ClearMark();
786                     rSh.EndSelect();
787                 }
788                 bool bRet = rSh.MoveFieldType( pFieldType, nSlot == FN_GOTO_NEXT_MARK );
789                 SwField* pCurField = bRet ? rSh.GetCurField() : nullptr;
790                 if (pCurField)
791                     rSh.ClickToField(*pCurField);
792                 rReq.SetReturnValue(SfxBoolItem( nSlot, bRet));
793             }
794         }
795         break;
796 
797         case FN_START_DOC_DIRECT:
798         case FN_END_DOC_DIRECT:
799         {
800             if (rSh.IsSelFrameMode())
801             {
802                 rSh.UnSelectFrame();
803                 rSh.LeaveSelFrameMode();
804             }
805             rSh.EnterStdMode();
806             nSlot == FN_START_DOC_DIRECT ?
807                 rSh.SttEndDoc(true) :
808                     rSh.SttEndDoc(false);
809         }
810         break;
811         case FN_GOTO_PREV_OBJ:
812         case FN_GOTO_NEXT_OBJ:
813         {
814                 bool bSuccess = rSh.GotoObj( nSlot == FN_GOTO_NEXT_OBJ );
815                 rReq.SetReturnValue(SfxBoolItem(nSlot, bSuccess));
816                 if (bSuccess && !rSh.IsSelFrameMode())
817                 {
818                     rSh.HideCursor();
819                     rSh.EnterSelFrameMode();
820                     GetView().AttrChangedNotify(nullptr);
821                 }
822         }
823         break;
824         case SID_GALLERY_FORMATS:
825         {
826             const SvxGalleryItem* pGalleryItem = SfxItemSet::GetItem<SvxGalleryItem>(pArgs, SID_GALLERY_FORMATS, false);
827             if ( !pGalleryItem )
828                 break;
829 
830             const SelectionType nSelType = rSh.GetSelectionType();
831             sal_Int8 nGalleryItemType( pGalleryItem->GetType() );
832 
833             if ( (!rSh.IsSelFrameMode() || nSelType & SelectionType::Graphic) &&
834                 nGalleryItemType == css::gallery::GalleryItemType::GRAPHIC )
835             {
836                 SwWait aWait( *rView.GetDocShell(), true );
837 
838                 OUString aGrfName, aFltName;
839                 const Graphic aGrf( pGalleryItem->GetGraphic() );
840 
841                 if ( nSelType & SelectionType::Graphic )
842                     rSh.ReRead( aGrfName, aFltName, &aGrf );
843                 else
844                     rSh.Insert( aGrfName, aFltName, aGrf );
845 
846                 GetView().GetEditWin().GrabFocus();
847             }
848             else if(!rSh.IsSelFrameMode() &&
849                 nGalleryItemType == css::gallery::GalleryItemType::MEDIA  )
850             {
851                 const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, pGalleryItem->GetURL() );
852                 GetView().GetViewFrame()->GetDispatcher()->ExecuteList(
853                         SID_INSERT_AVMEDIA, SfxCallMode::SYNCHRON,
854                         { &aMediaURLItem });
855             }
856         }
857         break;
858         case FN_PAGE_STYLE_SET_COLS:
859         {
860             if (pArgs)
861             {
862                 // Determine the current PageDescriptor and fill the set with that.
863                 const size_t nCurIdx = rSh.GetCurPageDesc();
864                 SwPageDesc aPageDesc(rSh.GetPageDesc(nCurIdx));
865 
866                 SwFrameFormat &rFormat = aPageDesc.GetMaster();
867 
868                 SwFormatCol aFormatCol = rFormat.GetCol();
869 
870                 sal_uInt16 nCount;
871                 if(SfxItemState::SET == pArgs->GetItemState(nSlot))
872                     nCount = static_cast<const SfxUInt16Item &>(pArgs->Get(nSlot)).GetValue();
873                 else
874                     nCount = pArgs->Get(SID_ATTR_COLUMNS).GetValue();
875                 sal_uInt16 nGutterWidth = DEF_GUTTER_WIDTH;
876 
877                 aFormatCol.Init(nCount ? nCount : 1, nGutterWidth, USHRT_MAX);
878                 aFormatCol.SetWishWidth(USHRT_MAX);
879                 aFormatCol.SetGutterWidth(nGutterWidth, USHRT_MAX);
880 
881                 rFormat.SetFormatAttr(aFormatCol);
882 
883                 rSh.ChgPageDesc(nCurIdx, aPageDesc);
884             }
885             else
886                 GetView().GetViewFrame()->GetDispatcher()->Execute(FN_FORMAT_PAGE_COLUMN_DLG);
887         }
888         break;
889         case FN_CONVERT_TABLE_TO_TEXT:
890         case FN_CONVERT_TEXT_TO_TABLE:
891         case FN_CONVERT_TEXT_TABLE:
892         {
893             sal_Unicode cDelim = 0;
894             bool bToTable = false;
895             if( nSlot == FN_CONVERT_TEXT_TO_TABLE ||
896                 ( nSlot == FN_CONVERT_TEXT_TABLE && nullptr == rSh.GetTableFormat() ))
897                 bToTable = true;
898             SwInsertTableOptions aInsTableOpts( SwInsertTableFlags::All, 1 );
899             SwTableAutoFormat const* pTAFormat = nullptr;
900             std::unique_ptr<SwTableAutoFormatTable> pAutoFormatTable;
901             bool bDeleteFormat = true;
902             if(pArgs && SfxItemState::SET == pArgs->GetItemState( FN_PARAM_1, true, &pItem))
903             {
904                 aInsTableOpts.mnInsMode = SwInsertTableFlags::NONE;
905                 // Delimiter
906                 OUString sDelim = static_cast< const SfxStringItem* >(pItem)->GetValue();
907                 if(!sDelim.isEmpty())
908                     cDelim = sDelim[0];
909                 // AutoFormat
910                 if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_2, true, &pItem))
911                 {
912                     OUString sAutoFormat = static_cast< const SfxStringItem* >(pItem)->GetValue();
913 
914                     pAutoFormatTable.reset(new SwTableAutoFormatTable);
915                     pAutoFormatTable->Load();
916 
917                     for( sal_uInt16 i = 0, nCount = pAutoFormatTable->size(); i < nCount; i++ )
918                     {
919                         SwTableAutoFormat const*const pFormat = &(*pAutoFormatTable)[ i ];
920                         if( pFormat->GetName() == sAutoFormat )
921                         {
922                             pTAFormat = pFormat;
923                             bDeleteFormat = false;
924                             break;
925                         }
926                     }
927                 }
928                 //WithHeader
929                 if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_3, true, &pItem) &&
930                             static_cast< const SfxBoolItem* >(pItem)->GetValue())
931                     aInsTableOpts.mnInsMode |= SwInsertTableFlags::Headline;
932                 // RepeatHeaderLines
933                 if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_4, true, &pItem))
934                    aInsTableOpts.mnRowsToRepeat =
935                             static_cast<sal_uInt16>(static_cast< const SfxInt16Item* >(pItem)->GetValue());
936                 //WithBorder
937                 if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_5, true, &pItem) &&
938                     static_cast< const SfxBoolItem* >(pItem)->GetValue())
939                     aInsTableOpts.mnInsMode |= SwInsertTableFlags::DefaultBorder;
940                 //DontSplitTable
941                 if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_6, true, &pItem) &&
942                     !static_cast< const SfxBoolItem* >(pItem)->GetValue() )
943                     aInsTableOpts.mnInsMode |= SwInsertTableFlags::SplitLayout;
944             }
945             else
946             {
947                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
948                 ScopedVclPtr<AbstractSwConvertTableDlg> pDlg(pFact->CreateSwConvertTableDlg(GetView(), bToTable));
949                 if( RET_OK == pDlg->Execute() )
950                 {
951                     pDlg->GetValues( cDelim, aInsTableOpts, pTAFormat );
952 
953                 }
954             }
955 
956             if( cDelim )
957             {
958                 //Shell change!
959                 SwView& rSaveView = rView;
960                 bool bInserted = false;
961                 //recording:
962                 SfxViewFrame* pViewFrame = GetView().GetViewFrame();
963                 if( SfxRequest::HasMacroRecorder(pViewFrame) )
964                 {
965                     SfxRequest aReq( pViewFrame, nSlot);
966                     aReq.AppendItem( SfxStringItem( FN_PARAM_1, OUString(cDelim) ));
967                     if(bToTable)
968                     {
969                         if(pTAFormat)
970                             aReq.AppendItem( SfxStringItem( FN_PARAM_2, pTAFormat->GetName()));
971                         aReq.AppendItem( SfxBoolItem ( FN_PARAM_3, bool(aInsTableOpts.mnInsMode & SwInsertTableFlags::Headline)));
972                         aReq.AppendItem( SfxInt16Item( FN_PARAM_4, static_cast<short>(aInsTableOpts.mnRowsToRepeat) ));
973                         aReq.AppendItem( SfxBoolItem ( FN_PARAM_5, bool(aInsTableOpts.mnInsMode & SwInsertTableFlags::DefaultBorder) ));
974                         aReq.AppendItem( SfxBoolItem ( FN_PARAM_6, !(aInsTableOpts.mnInsMode & SwInsertTableFlags::SplitLayout)));
975                     }
976                     aReq.Done();
977                 }
978 
979                 if( !bToTable )
980                     rSh.TableToText( cDelim );
981                 else
982                 {
983                     bInserted = rSh.TextToTable( aInsTableOpts, cDelim, pTAFormat );
984                 }
985                 rSh.EnterStdMode();
986 
987                 if( bInserted )
988                     rSaveView.AutoCaption( TABLE_CAP );
989             }
990             if(bDeleteFormat)
991                 delete pTAFormat;
992         }
993         break;
994         case SID_STYLE_WATERCAN:
995         case SID_STYLE_UPDATE_BY_EXAMPLE:
996         case SID_STYLE_NEW_BY_EXAMPLE:
997         case SID_STYLE_APPLY:
998         {
999             ShellMode eMode = GetView().GetShellMode();
1000             if ( ShellMode::Draw != eMode &&
1001                  ShellMode::DrawForm != eMode &&
1002                  ShellMode::DrawText != eMode &&
1003                  ShellMode::Bezier != eMode )
1004             {
1005                 // oj #107754#
1006                 if ( SID_STYLE_WATERCAN == nSlot )
1007                 {
1008                     const bool bLockedView = rSh.IsViewLocked();
1009                     rSh.LockView( true );    //lock visible section
1010 
1011                     GetView().GetDocShell()->ExecStyleSheet(rReq);
1012 
1013                     rSh.LockView( bLockedView );
1014                 }
1015                 else
1016                 // Will be recorded from the DocShell
1017                     GetView().GetDocShell()->ExecStyleSheet(rReq);
1018             }
1019         }
1020         break;
1021         case SID_CLASSIFICATION_APPLY:
1022         {
1023             GetView().GetDocShell()->Execute(rReq);
1024         }
1025         break;
1026         case SID_CLASSIFICATION_DIALOG:
1027         {
1028             GetView().GetDocShell()->Execute(rReq);
1029         }
1030         break;
1031         case SID_PARAGRAPH_SIGN_CLASSIFY_DLG:
1032         {
1033             GetView().GetDocShell()->Execute(rReq);
1034         }
1035         break;
1036         case SID_WATERMARK:
1037         {
1038             GetView().GetDocShell()->Execute(rReq);
1039         }
1040         break;
1041         case FN_ESCAPE:
1042             GetView().ExecuteSlot(rReq);
1043         break;
1044         case SID_IMAP:
1045         {
1046             sal_uInt16      nId = SvxIMapDlgChildWindow::GetChildWindowId();
1047 
1048             SfxViewFrame* pVFrame = GetView().GetViewFrame();
1049             pVFrame->ToggleChildWindow( nId );
1050             pVFrame->GetBindings().Invalidate( SID_IMAP );
1051 
1052             if ( pVFrame->HasChildWindow( nId ) && rSh.IsFrameSelected() )
1053                 lcl_UpdateIMapDlg( rSh );
1054         }
1055         break;
1056         case SID_IMAP_EXEC:
1057         {
1058             SvxIMapDlg* pDlg = GetIMapDlg(GetView());
1059 
1060             // Check, if the allocation is useful or allowed at all.
1061             if ( rSh.IsFrameSelected() &&
1062                  pDlg->GetEditingObject() == rSh.GetIMapInventor() )
1063             {
1064                     SfxItemSet aSet( rSh.GetAttrPool(), svl::Items<RES_URL, RES_URL>{} );
1065                     rSh.GetFlyFrameAttr( aSet );
1066                     SwFormatURL aURL( aSet.Get( RES_URL ) );
1067                     aURL.SetMap( &pDlg->GetImageMap() );
1068                     aSet.Put( aURL );
1069                     rSh.SetFlyFrameAttr( aSet );
1070             }
1071         }
1072         break;
1073         case SID_CONTOUR_DLG:
1074         {
1075             sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
1076 
1077             SfxViewFrame* pVFrame = GetView().GetViewFrame();
1078             pVFrame->ToggleChildWindow( nId );
1079             pVFrame->GetBindings().Invalidate( SID_CONTOUR_DLG );
1080 
1081             SelectionType nSel = rSh.GetSelectionType();
1082             if ( pVFrame->HasChildWindow( nId ) &&
1083                  (nSel & (SelectionType::Graphic|SelectionType::Ole)) )
1084             {
1085                 lcl_UpdateContourDlg( rSh, nSel );
1086             }
1087         }
1088         break;
1089         case SID_CONTOUR_EXEC:
1090         {
1091             SvxContourDlg *pDlg = GetContourDlg(GetView());
1092             // Check, if the allocation is useful or allowed at all.
1093             SelectionType nSel = rSh.GetSelectionType();
1094             if ( nSel & (SelectionType::Graphic|SelectionType::Ole) )
1095             {
1096                 if (pDlg && pDlg->GetEditingObject() == rSh.GetIMapInventor())
1097                 {
1098                     rSh.StartAction();
1099                     SfxItemSet aSet( rSh.GetAttrPool(), svl::Items<RES_SURROUND, RES_SURROUND>{});
1100                     rSh.GetFlyFrameAttr( aSet );
1101                     SwFormatSurround aSur( aSet.Get( RES_SURROUND ) );
1102                     if ( !aSur.IsContour() )
1103                     {
1104                         aSur.SetContour( true );
1105                         if ( aSur.GetSurround() == css::text::WrapTextMode_NONE )
1106                             aSur.SetSurround( css::text::WrapTextMode_PARALLEL );
1107                         aSet.Put( aSur );
1108                         rSh.SetFlyFrameAttr( aSet );
1109                     }
1110                     const tools::PolyPolygon aPoly( pDlg->GetPolyPolygon() );
1111                     rSh.SetGraphicPolygon( &aPoly );
1112                     if ( pDlg->IsGraphicChanged() )
1113                         rSh.ReRead( OUString(), OUString(), &pDlg->GetGraphic());
1114                     rSh.EndAction();
1115                 }
1116             }
1117         }
1118         break;
1119         case FN_FRAME_TO_ANCHOR:
1120         {
1121             rSh.GotoFlyAnchor();
1122             rSh.EnterStdMode();
1123             rSh.CallChgLnk();
1124         }
1125         break;
1126         case FN_TOOL_ANCHOR_PAGE:
1127         case FN_TOOL_ANCHOR_PARAGRAPH:
1128         case FN_TOOL_ANCHOR_CHAR:
1129         case FN_TOOL_ANCHOR_AT_CHAR:
1130         case FN_TOOL_ANCHOR_FRAME:
1131         {
1132             RndStdIds eSet = nSlot == FN_TOOL_ANCHOR_PAGE
1133                                 ? RndStdIds::FLY_AT_PAGE
1134                                 : nSlot == FN_TOOL_ANCHOR_PARAGRAPH
1135                                     ? RndStdIds::FLY_AT_PARA
1136                                     : nSlot == FN_TOOL_ANCHOR_FRAME
1137                                         ? RndStdIds::FLY_AT_FLY
1138                                         : nSlot == FN_TOOL_ANCHOR_CHAR
1139                                             ? RndStdIds::FLY_AS_CHAR
1140                                             : RndStdIds::FLY_AT_CHAR;
1141             rSh.StartUndo();
1142             if (rSh.IsObjSelected())
1143                 rSh.ChgAnchor(eSet);
1144             else if (rSh.IsFrameSelected())
1145             {
1146                 SwFormatAnchor aAnc(eSet, rSh.GetPhyPageNum());
1147                 SfxItemSet aSet(SwFEShell::makeItemSetFromFormatAnchor(GetPool(), aAnc));
1148                 rSh.SetFlyFrameAttr(aSet);
1149             }
1150             // if new anchor is 'as char' and it is a Math object and the usual
1151             // pre-conditions are met then align the formula to the baseline of the text
1152             const uno::Reference < embed::XEmbeddedObject > xObj( rSh.GetOleRef() );
1153             const bool bDoMathBaselineAlignment = xObj.is() && SotExchange::IsMath( xObj->getClassID() )
1154                     && RndStdIds::FLY_AS_CHAR == eSet && rSh.GetDoc()->getIDocumentSettingAccess().get( DocumentSettingId::MATH_BASELINE_ALIGNMENT );
1155             if (bDoMathBaselineAlignment)
1156                 rSh.AlignFormulaToBaseline( xObj );
1157 
1158             sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
1159             if( nHtmlMode )
1160             {
1161                 SfxItemSet aSet(GetPool(), svl::Items<RES_SURROUND, RES_HORI_ORIENT>{});
1162                 rSh.GetFlyFrameAttr(aSet);
1163 
1164                 const SwFormatSurround& rSurround = aSet.Get(RES_SURROUND);
1165                 const SwFormatVertOrient& rVert = aSet.Get(RES_VERT_ORIENT);
1166                 const SwFormatHoriOrient& rHori = aSet.Get(RES_HORI_ORIENT);
1167                 sal_Int16 eVOrient = rVert.GetVertOrient();
1168                 sal_Int16 eHOrient = rHori.GetHoriOrient();
1169                 css::text::WrapTextMode eSurround = rSurround.GetSurround();
1170 
1171                 switch( eSet )
1172                 {
1173                 case RndStdIds::FLY_AT_FLY:
1174                 case RndStdIds::FLY_AT_PAGE:
1175                     //Wrap through, left or from left, top, from top
1176                     if(eSurround != css::text::WrapTextMode_THROUGH)
1177                         aSet.Put(SwFormatSurround(css::text::WrapTextMode_THROUGH));
1178 
1179                     if( eVOrient != text::VertOrientation::TOP && eVOrient != text::VertOrientation::NONE)
1180                         aSet.Put(SwFormatVertOrient(0, text::VertOrientation::TOP));
1181 
1182                     if (eHOrient != text::HoriOrientation::NONE && eHOrient != text::HoriOrientation::LEFT)
1183                         aSet.Put(SwFormatHoriOrient(0, text::HoriOrientation::LEFT));
1184                     break;
1185 
1186                 case RndStdIds::FLY_AT_PARA:
1187                     // left, from left, right, top, no wrap, wrap left and right
1188                     if (eSurround != css::text::WrapTextMode_LEFT && eSurround != css::text::WrapTextMode_RIGHT)
1189                         aSet.Put(SwFormatSurround(css::text::WrapTextMode_LEFT));
1190 
1191                     if( eVOrient != text::VertOrientation::TOP)
1192                         aSet.Put(SwFormatVertOrient(0, text::VertOrientation::TOP));
1193 
1194                     if (eHOrient != text::HoriOrientation::NONE && eHOrient != text::HoriOrientation::LEFT && eHOrient != text::HoriOrientation::RIGHT)
1195                         aSet.Put(SwFormatHoriOrient(0, text::HoriOrientation::LEFT));
1196                     break;
1197 
1198                 case RndStdIds::FLY_AT_CHAR:
1199                     // left, from left, right, top, wrap through
1200                     if(eSurround != css::text::WrapTextMode_THROUGH)
1201                         aSet.Put(SwFormatSurround(css::text::WrapTextMode_THROUGH));
1202 
1203                     if( eVOrient != text::VertOrientation::TOP)
1204                         aSet.Put(SwFormatVertOrient(0, text::VertOrientation::TOP));
1205 
1206                     if (eHOrient != text::HoriOrientation::NONE && eHOrient != text::HoriOrientation::LEFT && eHOrient != text::HoriOrientation::RIGHT)
1207                         aSet.Put(SwFormatHoriOrient(0, text::HoriOrientation::LEFT));
1208                     break;
1209 
1210                 default:
1211                     ;
1212                 }
1213 
1214                 if( aSet.Count() )
1215                     rSh.SetFlyFrameAttr( aSet );
1216             }
1217             rSh.EndUndo();
1218 
1219             GetView().GetViewFrame()->GetBindings().Invalidate( SID_ANCHOR_MENU );
1220         }
1221         break;
1222 
1223         case FN_FRAME_NOWRAP:
1224         case FN_FRAME_WRAP:
1225         case FN_FRAME_WRAP_IDEAL:
1226         case FN_FRAME_WRAPTHRU:
1227         case FN_FRAME_WRAPTHRU_TRANSP:
1228         case FN_FRAME_WRAPTHRU_TOGGLE:
1229         case FN_FRAME_WRAP_CONTOUR:
1230         case FN_WRAP_ANCHOR_ONLY:
1231         case FN_FRAME_WRAP_LEFT:
1232         case FN_FRAME_WRAP_RIGHT:
1233             SetWrapMode( nSlot );
1234             break;
1235 
1236         case FN_UPDATE_ALL_LINKS:
1237             {
1238                 if( !rSh.GetLinkManager().GetLinks().empty() )
1239                 {
1240                     rSh.EnterStdMode();
1241                     rSh.StartAllAction();
1242                     rSh.GetLinkManager().UpdateAllLinks( false, false, nullptr );
1243                     rSh.EndAllAction();
1244                 }
1245             }
1246             break;
1247 
1248         case FN_XFORMS_DESIGN_MODE:
1249             if (pArgs && pArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET)
1250             {
1251                 if (const SfxBoolItem* pBoolItem = dynamic_cast<const SfxBoolItem*>(pItem))
1252                 {
1253                     bool bDesignMode = pBoolItem->GetValue();
1254 
1255                     // set from design mode
1256                     OSL_ENSURE( GetView().GetFormShell() != nullptr, "form shell?" );
1257                     SfxRequest aReq( GetView().GetViewFrame(), SID_FM_DESIGN_MODE );
1258                     aReq.AppendItem( SfxBoolItem( SID_FM_DESIGN_MODE, bDesignMode ) );
1259                     GetView().GetFormShell()->Execute( aReq );
1260                     aReq.Done();
1261 
1262                     // also set suitable view options
1263                     SwViewOption aViewOption = *rSh.GetViewOptions();
1264                     aViewOption.SetFormView( ! bDesignMode );
1265                     rSh.ApplyViewOptions( aViewOption );
1266                 }
1267             }
1268             break;
1269 
1270         default:
1271             bMore = true;
1272     }
1273 
1274 
1275     if(!bMore || !pArgs)
1276         return;
1277 
1278     pItem = nullptr;
1279     pArgs->GetItemState(GetPool().GetWhich(nSlot), false, &pItem);
1280     if(pItem)
1281         switch(nSlot)
1282         {
1283         case SID_ATTR_BRUSH:
1284         case SID_ATTR_BORDER_SHADOW:
1285         case RES_SHADOW:
1286         {
1287             rSh.StartAllAction();
1288             // Tabele cell(s) selected?
1289             if ( rSh.IsTableMode() )
1290             {
1291                 SwFrameFormat *pFormat = rSh.GetTableFormat();
1292                 pFormat->SetFormatAttr( *pItem );
1293             }
1294             else if ( rSh.IsFrameSelected() )
1295             {
1296                 // Set border attributes via Frame-Manager.
1297                 SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE );
1298                 aMgr.SetAttrSet( *pArgs );
1299                 aMgr.UpdateFlyFrame();
1300             }
1301             else
1302             {
1303                 rSh.SetAttrSet( *pArgs );
1304             }
1305             rSh.EndAllAction();
1306         }
1307         break;
1308         case FN_PAGE_STYLE_SET_LR_MARGIN:
1309         case FN_PAGE_STYLE_SET_UL_MARGIN:
1310         case FN_PAGE_STYLE_SET_NUMBER_FORMAT:
1311         case FN_PAGE_STYLE_SET_PAPER_SIZE:
1312         case FN_PAGE_STYLE_SET_PAPER_BIN:
1313         {
1314             OSL_FAIL("not implemented");
1315         }
1316         break;
1317 
1318         case SID_ATTR_BORDER_OUTER:
1319         {
1320             // Tabele cell(s) selected?
1321             if ( rSh.IsTableMode() )
1322             {
1323                 // Set border attributes Get/SetTabBorders()
1324                 rSh.SetTabBorders(*pArgs);
1325             }
1326             else if ( rSh.IsFrameSelected() )
1327             {
1328                 // Set border attributes via Frame-Manager.
1329                 SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE );
1330                 aMgr.SetAttrSet(*pArgs);
1331                 aMgr.UpdateFlyFrame();
1332             }
1333             else
1334             {
1335                 // Set border attributes via shell quite normally.
1336                 rSh.SetAttrItem( *pItem );
1337             }
1338         }
1339         break;
1340         default:
1341                 OSL_FAIL("wrong Dispatcher");
1342         }
1343 }
1344 
1345 // Here the state for SID_IMAP / SID_CONTOUR will be handled
1346 // until the swapping of the graphic is finished.
1347 
IMPL_LINK_NOARG(SwBaseShell,GraphicArrivedHdl,SwCursorShell &,void)1348 IMPL_LINK_NOARG(SwBaseShell, GraphicArrivedHdl, SwCursorShell&, void)
1349 {
1350     SwWrtShell &rSh = GetShell();
1351     if (CNT_GRF != rSh.SwEditShell::GetCntType())
1352         return;
1353     GraphicType const nGrfType(rSh.GetGraphicType());
1354     if (GraphicType::NONE != nGrfType &&
1355         !aGrfUpdateSlots.empty() )
1356     {
1357         bool bProtect = FlyProtectFlags::NONE != rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent);
1358         SfxViewFrame* pVFrame = GetView().GetViewFrame();
1359         for( const auto nSlot : aGrfUpdateSlots )
1360         {
1361             bool bSetState = false;
1362             bool bState = false;
1363             switch( nSlot )
1364             {
1365             case SID_IMAP:
1366             case SID_IMAP_EXEC:
1367                 {
1368                     sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
1369                     SfxChildWindow *pChildWindow = pVFrame->HasChildWindow(nId) ?
1370                         pVFrame->GetChildWindow(nId) : nullptr;
1371                     SvxIMapDlg *pDlg = pChildWindow ?
1372                         static_cast<SvxIMapDlg*>(pChildWindow->GetController().get()) : nullptr;
1373 
1374                     if( pDlg && ( SID_IMAP_EXEC == nSlot ||
1375                                 ( SID_IMAP == nSlot && !bProtect)) &&
1376                         pDlg->GetEditingObject() != rSh.GetIMapInventor())
1377                             lcl_UpdateIMapDlg( rSh );
1378 
1379                     if( !bProtect && SID_IMAP == nSlot )
1380                     {
1381                         bSetState = true;
1382                         bState = nullptr != pDlg;
1383                     }
1384                 }
1385                 break;
1386 
1387             case SID_CONTOUR_DLG:
1388                 if( !bProtect )
1389                 {
1390                     sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
1391                     SfxChildWindow *pChildWindow = pVFrame->HasChildWindow(nId) ?
1392                         pVFrame->GetChildWindow(nId) : nullptr;
1393                     SvxIMapDlg *pDlg = pChildWindow ?
1394                         static_cast<SvxIMapDlg*>(pChildWindow->GetController().get()) : nullptr;
1395                     if( pDlg && pDlg->GetEditingObject() !=
1396                                 rSh.GetIMapInventor() )
1397                         lcl_UpdateContourDlg( rSh, SelectionType::Graphic );
1398 
1399                     bSetState = true;
1400                     bState = nullptr != pDlg;
1401                 }
1402                 break;
1403 
1404             case FN_FRAME_WRAP_CONTOUR:
1405                 if( !bProtect )
1406                 {
1407                     SfxItemSet aSet(GetPool(), svl::Items<RES_SURROUND, RES_SURROUND>{});
1408                     rSh.GetFlyFrameAttr(aSet);
1409                     const SwFormatSurround& rWrap = aSet.Get(RES_SURROUND);
1410                     bSetState = true;
1411                     bState = rWrap.IsContour();
1412                 }
1413                 break;
1414 
1415             case SID_GRFFILTER:
1416             case SID_GRFFILTER_INVERT:
1417             case SID_GRFFILTER_SMOOTH:
1418             case SID_GRFFILTER_SHARPEN:
1419             case SID_GRFFILTER_REMOVENOISE:
1420             case SID_GRFFILTER_SOBEL:
1421             case SID_GRFFILTER_MOSAIC:
1422             case SID_GRFFILTER_EMBOSS:
1423             case SID_GRFFILTER_POSTER:
1424             case SID_GRFFILTER_POPART:
1425             case SID_GRFFILTER_SEPIA:
1426             case SID_GRFFILTER_SOLARIZE:
1427                 bSetState = bState = GraphicType::Bitmap == nGrfType;
1428                 break;
1429             }
1430 
1431             if( bSetState )
1432             {
1433                 SfxBoolItem aBool( nSlot, bState );
1434                 if( pGetStateSet )
1435                     pGetStateSet->Put( aBool );
1436                 else
1437                     pVFrame->GetBindings().SetState( aBool );
1438             }
1439         }
1440         aGrfUpdateSlots.clear();
1441     }
1442 }
1443 
GetState(SfxItemSet & rSet)1444 void SwBaseShell::GetState( SfxItemSet &rSet )
1445 {
1446     SwWrtShell &rSh = GetShell();
1447     SfxViewFrame* pVFrame = GetView().GetViewFrame();
1448     SfxWhichIter aIter( rSet );
1449     sal_uInt16 nWhich = aIter.FirstWhich();
1450     pGetStateSet = &rSet;
1451     while ( nWhich )
1452     {
1453         switch ( nWhich )
1454         {
1455             case SID_GALLERY_FORMATS:
1456                 if ( rSh.IsObjSelected() ||
1457                      (rSh.IsSelFrameMode() &&
1458                       !(rSh.GetSelectionType() & SelectionType::Graphic)) )
1459                     rSet.DisableItem( nWhich );
1460                 break;
1461             case SID_GALLERY_ENABLE_ADDCOPY:
1462                 // #108230# allow copy from gallery in Writer AND Writer/Web!
1463                 rSet.Put( SfxBoolItem( SID_GALLERY_ENABLE_ADDCOPY, true ) );
1464                 break;
1465             case FN_EDIT_REGION:
1466                 if( !rSh.IsAnySectionInDoc() )
1467                     rSet.DisableItem(nWhich);
1468                 break;
1469 
1470             case FN_EDIT_CURRENT_REGION:
1471                 //tdf#112808 if cursor is in an index, don't show the edit section.
1472                 if( !rSh.GetCurrSection() ||
1473                     (rSh.GetCurrSection()->GetType() != CONTENT_SECTION &&
1474                     rSh.GetCurrSection()->GetType() != FILE_LINK_SECTION ))
1475                 {
1476                     rSet.DisableItem(nWhich);
1477                 }
1478                 break;
1479 
1480             case FN_INSERT_REGION:
1481                 if( rSh.CursorInsideInputField()
1482                     || rSh.IsSelFrameMode()
1483                     || !rSh.IsInsRegionAvailable() )
1484                 {
1485                     rSet.DisableItem( nWhich );
1486                 }
1487                 break;
1488 
1489             case FN_CONVERT_TABLE_TO_TEXT:
1490             {
1491                 FrameTypeFlags eFrameType = rSh.GetFrameType(nullptr,true);
1492                 if( (eFrameType & FrameTypeFlags::FOOTNOTE) ||
1493                     !rSh.GetTableFormat() )
1494                     rSet.DisableItem( nWhich );
1495             }
1496             break;
1497             case FN_CONVERT_TEXT_TO_TABLE:
1498             {
1499                 FrameTypeFlags eFrameType = rSh.GetFrameType(nullptr,true);
1500                 if( (eFrameType & FrameTypeFlags::FOOTNOTE) ||
1501                     !rSh.IsTextToTableAvailable()  )
1502                     rSet.DisableItem( nWhich );
1503             }
1504             break;
1505             case FN_CONVERT_TEXT_TABLE:
1506             {
1507                 FrameTypeFlags eFrameType = rSh.GetFrameType(nullptr,true);
1508                 if( (eFrameType & FrameTypeFlags::FOOTNOTE) ||
1509                     (!rSh.GetTableFormat() && !rSh.IsTextToTableAvailable() ) )
1510                     rSet.DisableItem( nWhich );
1511             }
1512             break;
1513             case RES_SHADOW:
1514             {
1515                 SfxItemSet   aSet( rSh.GetAttrPool(),
1516                                     svl::Items<RES_SHADOW, RES_SHADOW>{} );
1517 
1518                 // Table cell(s) selected?
1519                 if ( rSh.IsTableMode() )
1520                 {
1521                     SwFrameFormat *pFormat = rSh.GetTableFormat();
1522                     aSet.Put(pFormat->GetFormatAttr( nWhich ));
1523                 }
1524                 else if( rSh.IsFrameSelected() )
1525                 {
1526                     SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE );
1527                     aSet.Put( aMgr.GetAttrSet() );
1528                 }
1529                 else
1530                     rSh.GetCurAttr( aSet );
1531 
1532                 const SvxShadowItem& rShItem = static_cast<const SvxShadowItem&>(aSet.Get(nWhich));
1533                 rSet.Put(rShItem);
1534             }
1535             break;
1536             case SID_IMAP:
1537             {
1538                 // #i59688#
1539                 // Improve efficiency:
1540                 // If selected object is protected, item has to disabled.
1541                 const bool bProtect = FlyProtectFlags::NONE != rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent);
1542                 if ( bProtect )
1543                 {
1544                     rSet.DisableItem( nWhich );
1545                 }
1546                 else
1547                 {
1548                     const sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
1549                     const bool bHas = pVFrame->HasChildWindow( nId );
1550                     const bool bFrameSel = rSh.IsFrameSelected();
1551                     const bool bIsGraphicSelection =
1552                                 rSh.GetSelectionType() == SelectionType::Graphic;
1553 
1554                     // #i59688#
1555                     // Avoid unnecessary loading of selected graphic.
1556                     // The graphic is only needed, if the dialog is open.
1557                     // If the swapping of the graphic is finished, the status
1558                     // must be determined asynchronously, until this the slot
1559                     // will be disabled.
1560                     if ( bHas && bIsGraphicSelection && rSh.IsLinkedGrfSwapOut() )
1561                     {
1562                         if( AddGrfUpdateSlot( nWhich ))
1563                             rSh.GetGraphic(false);  // start the loading
1564                     }
1565                     else
1566                     {
1567                         if ( !bHas &&
1568                              ( !bFrameSel ||
1569                                ( bIsGraphicSelection &&
1570                                  rSh.GetGraphicType() == GraphicType::NONE ) ) )
1571                         {
1572                             rSet.DisableItem( nWhich );
1573                         }
1574                         else
1575                         {
1576                             SfxBoolItem aBool(nWhich, bHas);
1577                             if ( bHas && bFrameSel )
1578                                 lcl_UpdateIMapDlg( rSh );
1579                             rSet.Put(aBool);
1580                         }
1581                     }
1582                 }
1583             }
1584             break;
1585             case SID_IMAP_EXEC:
1586             {
1587                 bool bDisable = false;
1588                 if( !rSh.IsFrameSelected())
1589                     bDisable = true;
1590                 sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
1591                 if(!bDisable && pVFrame->HasChildWindow( nId ))
1592                 {
1593                     if(rSh.GetSelectionType() == SelectionType::Graphic
1594                                     && rSh.IsLinkedGrfSwapOut())
1595                     {
1596                         if( AddGrfUpdateSlot( nWhich ))
1597                             rSh.GetGraphic(false);  // start the loading
1598                     }
1599                     else
1600                     {
1601                         SvxIMapDlg *pDlg = GetIMapDlg(GetView());
1602                         if (pDlg && pDlg->GetEditingObject() != rSh.GetIMapInventor())
1603                             lcl_UpdateIMapDlg( rSh );
1604                     }
1605                 }
1606                 rSet.Put(SfxBoolItem(nWhich, bDisable));
1607             }
1608             break;
1609 
1610             case FN_BACKSPACE:
1611             case SID_DELETE:
1612                 if ( ( rSh.HasReadonlySel() && !rSh.CursorInsideInputField() )
1613                      || rSh.IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE )
1614                 {
1615                     rSet.DisableItem( nWhich );
1616                 }
1617                 break;
1618 
1619             case SID_CONTOUR_DLG:
1620             {
1621                 bool bParentCntProt = FlyProtectFlags::NONE != rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent );
1622 
1623                 if( bParentCntProt || 0 != (HTMLMODE_ON & ::GetHtmlMode(
1624                                             GetView().GetDocShell() )) )
1625                     rSet.DisableItem( nWhich );
1626                 else
1627                 {
1628                     sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
1629                     bool bHas = GetView().GetViewFrame()->HasChildWindow( nId );
1630                     SelectionType nSel = rSh.GetSelectionType();
1631                     bool bOk(nSel & (SelectionType::Graphic|SelectionType::Ole));
1632 
1633                     bool bDisable = false;
1634                     if( !bHas && !bOk )
1635                         bDisable = true;
1636                     // #i59688#
1637                     // Avoid unnecessary loading of selected graphic.
1638                     // The graphic is only needed, if the dialog is open.
1639                     // If the swapping of the graphic is finished, the status
1640                     // must be determined asynchronously, until this the slot
1641                     // will be disabled.
1642                     else if ( bHas && (nSel & SelectionType::Graphic) &&
1643                               rSh.IsLinkedGrfSwapOut() )
1644                     {
1645                         if( AddGrfUpdateSlot( nWhich ))
1646                             rSh.GetGraphic(false);  // start the loading
1647                         // #i75481#
1648                         bDisable = true;
1649                     }
1650                     else if( bHas && bOk )
1651                         bDisable = !lcl_UpdateContourDlg( rSh, nSel );
1652                     else if( bOk )
1653                     {
1654                         // #i75481#
1655                         // apply fix #i59688# only for selected graphics
1656                         if ( nSel & SelectionType::Graphic )
1657                             bDisable = GraphicType::NONE == rSh.GetGraphicType();
1658                         else
1659                             bDisable = GraphicType::NONE == rSh.GetIMapGraphic().GetType();
1660                     }
1661 
1662                     if( bDisable )
1663                         rSet.DisableItem( nWhich );
1664                     else
1665                         rSet.Put( SfxBoolItem(nWhich, bHas) );
1666                 }
1667             }
1668             break;
1669             case SID_CONTOUR_EXEC:
1670             {
1671                 bool bDisable = false;
1672                 SelectionType nSel = rSh.GetSelectionType();
1673                 if( !(nSel & (SelectionType::Graphic|SelectionType::Ole)) )
1674                     bDisable = true;
1675                 sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
1676                 if( !bDisable && GetView().GetViewFrame()->HasChildWindow( nId ))
1677                 {
1678                     SvxContourDlg *pDlg = GetContourDlg(GetView());
1679                     if (pDlg && pDlg->GetEditingObject() != rSh.GetIMapInventor())
1680                         bDisable = true;
1681                 }
1682                 rSet.Put(SfxBoolItem(nWhich, bDisable));
1683             }
1684             break;
1685 
1686             case SID_ANCHOR_MENU:
1687             case FN_TOOL_ANCHOR_PAGE:
1688             case FN_TOOL_ANCHOR_PARAGRAPH:
1689             case FN_TOOL_ANCHOR_CHAR:
1690             case FN_TOOL_ANCHOR_AT_CHAR:
1691             case FN_TOOL_ANCHOR_FRAME:
1692             {
1693                 bool bObj = 0 != rSh.IsObjSelected();
1694                 bool bParentCntProt = rSh.IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE;
1695 
1696                 if( !bParentCntProt && (bObj || rSh.IsFrameSelected()))
1697                 {
1698                     SfxItemSet aSet(GetPool(), svl::Items<RES_ANCHOR, RES_ANCHOR>{});
1699                     if(bObj)
1700                         rSh.GetObjAttr(aSet);
1701                     else
1702                         rSh.GetFlyFrameAttr(aSet);
1703                     RndStdIds eSet = aSet.Get(RES_ANCHOR).GetAnchorId();
1704                     const bool bSet =
1705                            ((nWhich == FN_TOOL_ANCHOR_PAGE) &&
1706                             (eSet == RndStdIds::FLY_AT_PAGE))
1707                         || ((nWhich == FN_TOOL_ANCHOR_PARAGRAPH) &&
1708                             (eSet == RndStdIds::FLY_AT_PARA))
1709                         || ((nWhich == FN_TOOL_ANCHOR_FRAME) &&
1710                             (eSet == RndStdIds::FLY_AT_FLY))
1711                         || ((nWhich == FN_TOOL_ANCHOR_AT_CHAR) &&
1712                             (eSet == RndStdIds::FLY_AT_CHAR))
1713                         || ((nWhich == FN_TOOL_ANCHOR_CHAR) &&
1714                             (eSet == RndStdIds::FLY_AS_CHAR));
1715 
1716                     if( nWhich == FN_TOOL_ANCHOR_FRAME && !rSh.IsFlyInFly() )
1717                         rSet.DisableItem(nWhich);
1718                     else if(nWhich != SID_ANCHOR_MENU)
1719                         rSet.Put(SfxBoolItem(nWhich, bSet));
1720 
1721                     if (comphelper::LibreOfficeKit::isActive())
1722                     {
1723                         if (nWhich == FN_TOOL_ANCHOR_PAGE || nWhich == FN_TOOL_ANCHOR_PARAGRAPH
1724                             || nWhich == FN_TOOL_ANCHOR_FRAME)
1725                         {
1726                             rSet.DisableItem(nWhich);
1727                         }
1728                     }
1729                 }
1730                 else
1731                     rSet.DisableItem( nWhich );
1732             }
1733             break;
1734             case FN_FRAME_NOWRAP:
1735             case FN_FRAME_WRAP:
1736             case FN_FRAME_WRAP_IDEAL:
1737             case FN_FRAME_WRAPTHRU:
1738             case FN_FRAME_WRAPTHRU_TRANSP:
1739             case FN_FRAME_WRAPTHRU_TOGGLE:
1740             case FN_FRAME_WRAP_CONTOUR:
1741             case FN_WRAP_ANCHOR_ONLY:
1742             case FN_FRAME_WRAP_LEFT:
1743             case FN_FRAME_WRAP_RIGHT:
1744             {
1745                 bool bObj = 0 != rSh.IsObjSelected();
1746                 bool bParentCntProt = rSh.IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE;
1747 
1748                 if( !bParentCntProt && (bObj || rSh.IsFrameSelected()))
1749                 {
1750                     SfxItemSet aSet(GetPool(), svl::Items<RES_OPAQUE, RES_ANCHOR>{});
1751                     RndStdIds nAnchorType;
1752                     if(bObj)
1753                     {
1754                         rSh.GetObjAttr(aSet);
1755                         nAnchorType = rSh.GetAnchorId();
1756                     }
1757                     else
1758                     {
1759                         rSh.GetFlyFrameAttr(aSet);
1760                         nAnchorType = aSet.Get(RES_ANCHOR).GetAnchorId();
1761                     }
1762                     const SwFormatSurround& rWrap = aSet.Get(RES_SURROUND);
1763 
1764                     const SvxOpaqueItem& rOpaque = aSet.Get(RES_OPAQUE);
1765                     bool bOpaque = rOpaque.GetValue();
1766                     css::text::WrapTextMode nSurround = rWrap.GetSurround();
1767                     bool bSet = false;
1768 
1769                     bool bDisable =
1770                         (nAnchorType == RndStdIds::UNKNOWN) || (nAnchorType == RndStdIds::FLY_AS_CHAR);
1771                     const bool bHtmlMode =
1772                         0 != ::GetHtmlMode(GetView().GetDocShell());
1773 
1774                     switch( nWhich )
1775                     {
1776                         case FN_FRAME_NOWRAP:
1777                             bDisable |=
1778                                 (   (nAnchorType != RndStdIds::FLY_AT_PARA)
1779                                  && (nAnchorType != RndStdIds::FLY_AT_CHAR)
1780                                  && (nAnchorType != RndStdIds::FLY_AT_PAGE));
1781                             bSet = nSurround == css::text::WrapTextMode_NONE;
1782                         break;
1783                         case FN_FRAME_WRAP:
1784                             bDisable |= bHtmlMode;
1785                             bSet = nSurround == css::text::WrapTextMode_PARALLEL;
1786                         break;
1787                         case FN_FRAME_WRAP_IDEAL:
1788                             bDisable |= bHtmlMode;
1789                             bSet = nSurround == css::text::WrapTextMode_DYNAMIC;
1790                         break;
1791                         case FN_FRAME_WRAPTHRU:
1792                             bDisable |= (bHtmlMode ||
1793                                 (   (nAnchorType != RndStdIds::FLY_AT_PARA)
1794                                  && (nAnchorType != RndStdIds::FLY_AT_CHAR)
1795                                  && (nAnchorType != RndStdIds::FLY_AT_PAGE)));
1796                             if(bObj)
1797                                 bSet = nSurround == css::text::WrapTextMode_THROUGH && rSh.GetLayerId();
1798                             else
1799                                 bSet = nSurround == css::text::WrapTextMode_THROUGH && bOpaque;
1800                         break;
1801                         case FN_FRAME_WRAPTHRU_TRANSP:
1802                         case FN_FRAME_WRAPTHRU_TOGGLE:
1803                             bDisable |= bHtmlMode;
1804                             if(bObj)
1805                                 bSet = nSurround == css::text::WrapTextMode_THROUGH && !rSh.GetLayerId();
1806                             else
1807                                 bSet = nSurround == css::text::WrapTextMode_THROUGH && !bOpaque;
1808                         break;
1809                         case FN_FRAME_WRAP_CONTOUR:
1810                             bDisable |= bHtmlMode;
1811                             //no contour available whenn no wrap or wrap through is set
1812                             bDisable |= (nSurround == css::text::WrapTextMode_NONE || nSurround == css::text::WrapTextMode_THROUGH);
1813                             if( !bDisable )
1814                             {
1815                                 SelectionType nSel = rSh.GetSelectionType();
1816                                 if( (nSel & SelectionType::Graphic) &&
1817                                             rSh.IsLinkedGrfSwapOut())
1818                                 {
1819                                     if( AddGrfUpdateSlot( nWhich ))
1820                                         rSh.GetGraphic(false);  // start the loading
1821                                 }
1822                                 else if( rSh.IsFrameSelected() )
1823                                 {
1824                                     // #i102253# applied patch from OD (see task)
1825                                     bDisable =
1826                                         nSel & SelectionType::Frame ||
1827                                         GraphicType::NONE == rSh.GetIMapGraphic().GetType();
1828                                 }
1829                             }
1830                             bSet = !bDisable && rWrap.IsContour();
1831 
1832                         break;
1833                         case FN_WRAP_ANCHOR_ONLY:
1834                             bDisable |= (bHtmlMode ||
1835                                 (nAnchorType != RndStdIds::FLY_AT_PARA));
1836                             bSet = rWrap.IsAnchorOnly();
1837                         break;
1838                         case FN_FRAME_WRAP_LEFT:
1839                             bSet = nSurround == css::text::WrapTextMode_LEFT;
1840                         break;
1841                         case FN_FRAME_WRAP_RIGHT:
1842                             bSet = nSurround == css::text::WrapTextMode_RIGHT;
1843                         break;
1844                     }
1845 
1846                     if(bDisable)
1847                         rSet.DisableItem(nWhich);
1848                     else
1849                         rSet.Put(SfxBoolItem(nWhich, bSet));
1850                 }
1851                 else
1852                     rSet.DisableItem(nWhich);
1853             }
1854             break;
1855             case FN_UPDATE_CHARTS:
1856                 if( !rSh.HasCharts() )
1857                     rSet.DisableItem( nWhich );
1858                 break;
1859             case FN_UPDATE_ALL_LINKS:
1860                 if ( rSh.GetLinkManager().GetLinks().empty() )
1861                     rSet.DisableItem(nWhich);
1862                 break;
1863             case FN_XFORMS_DESIGN_MODE:
1864                 // enable if in XForms document
1865                 if( rSh.GetDoc()->isXForms() )
1866                 {
1867                     // determine current state from view options
1868                     bool bValue = ! rSh.GetViewOptions()->IsFormView();
1869                     rSet.Put( SfxBoolItem( nWhich, bValue ) );
1870                 }
1871                 else
1872                     rSet.Put( SfxVisibilityItem( nWhich, false ) );
1873                 break;
1874         }
1875         nWhich = aIter.NextWhich();
1876     }
1877     pGetStateSet = nullptr;
1878 }
1879 
1880 // Disable the slots with this status method
1881 
StateDisableItems(SfxItemSet & rSet)1882 void SwBaseShell::StateDisableItems( SfxItemSet &rSet )
1883 {
1884     SfxWhichIter aIter(rSet);
1885     sal_uInt16 nWhich = aIter.FirstWhich();
1886 
1887     while (nWhich)
1888     {
1889         rSet.DisableItem( nWhich );
1890         nWhich = aIter.NextWhich();
1891     }
1892 }
1893 
1894 // Disable the slots with this status method
1895 
StateStyle(SfxItemSet & rSet)1896 void SwBaseShell::StateStyle( SfxItemSet &rSet )
1897 {
1898     bool bParentCntProt = GetShell().IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE;
1899     ShellMode eMode = GetView().GetShellMode();
1900 
1901     if ( bParentCntProt ||
1902          ShellMode::Draw == eMode ||
1903          ShellMode::DrawForm == eMode ||
1904          ShellMode::DrawText == eMode ||
1905          ShellMode::Bezier == eMode )
1906     {
1907         SfxWhichIter aIter( rSet );
1908         sal_uInt16 nWhich = aIter.FirstWhich();
1909         while ( nWhich )
1910         {
1911             rSet.DisableItem( nWhich );
1912             nWhich = aIter.NextWhich();
1913         }
1914     }
1915     else
1916         GetView().GetDocShell()->StateStyleSheet(rSet, &GetShell());
1917 }
1918 
SetWrapMode(sal_uInt16 nSlot)1919 void SwBaseShell::SetWrapMode( sal_uInt16 nSlot )
1920 {
1921     SwWrtShell &rSh = GetShell();
1922     bool bObj = 0 != rSh.IsObjSelected();
1923     if( !bObj && !rSh.IsFrameSelected())
1924         return;
1925 
1926     SfxItemSet aSet(GetPool(), svl::Items<RES_OPAQUE, RES_SURROUND>{});
1927     if(bObj)
1928         rSh.GetObjAttr(aSet);
1929     else
1930         rSh.GetFlyFrameAttr(aSet);
1931     SwFormatSurround aWrap( aSet.Get(RES_SURROUND) );
1932     css::text::WrapTextMode nOldSurround(aWrap.GetSurround());
1933     css::text::WrapTextMode nSurround = css::text::WrapTextMode_PARALLEL;
1934 
1935     switch (nSlot)
1936     {
1937         case FN_FRAME_NOWRAP:
1938             nSurround = css::text::WrapTextMode_NONE;
1939             if (aWrap.IsContour())
1940                 aWrap.SetContour(false);
1941             break;
1942         case FN_FRAME_WRAP_IDEAL:
1943             nSurround = css::text::WrapTextMode_DYNAMIC;
1944             break;
1945         case FN_WRAP_ANCHOR_ONLY:
1946             aWrap.SetAnchorOnly(!aWrap.IsAnchorOnly());
1947 
1948             // keep previous wrapping
1949 
1950             // switch to wrap css::text::WrapTextMode_PARALLEL, if previous wrap is css::text::WrapTextMode_NONE
1951             if ( nOldSurround != css::text::WrapTextMode_NONE )
1952             {
1953                 nSurround = nOldSurround;
1954             }
1955             break;
1956         case FN_FRAME_WRAP_CONTOUR:
1957             aWrap.SetContour(!aWrap.IsContour());
1958             break;
1959         case FN_FRAME_WRAPTHRU_TRANSP:
1960         case FN_FRAME_WRAPTHRU_TOGGLE:
1961             if (aWrap.IsContour())
1962                 aWrap.SetContour(false);
1963             [[fallthrough]];
1964         case FN_FRAME_WRAPTHRU:
1965             nSurround = css::text::WrapTextMode_THROUGH;
1966             break;
1967 
1968         case FN_FRAME_WRAP_LEFT:
1969             nSurround = css::text::WrapTextMode_LEFT;
1970             break;
1971 
1972         case FN_FRAME_WRAP_RIGHT:
1973             nSurround = css::text::WrapTextMode_RIGHT;
1974             break;
1975 
1976         default:
1977             break;
1978     }
1979     aWrap.SetSurround(nSurround);
1980 
1981     if (nSlot != FN_FRAME_WRAP_CONTOUR)
1982     {
1983         // Defaulting the contour wrap on draw objects.
1984         if (bObj && nOldSurround != nSurround &&
1985             (nOldSurround == css::text::WrapTextMode_NONE || nOldSurround == css::text::WrapTextMode_THROUGH))
1986         {
1987             aWrap.SetContour(true);
1988         }
1989     }
1990 
1991     aSet.Put( aWrap );
1992 
1993     bool bOpaque = nSlot != FN_FRAME_WRAPTHRU_TRANSP && nSlot != FN_FRAME_WRAPTHRU_TOGGLE;
1994     if( nSlot == FN_FRAME_WRAPTHRU_TOGGLE )
1995     {
1996         if( bObj )
1997             bOpaque = !rSh.GetLayerId();
1998         else
1999         {
2000             const SvxOpaqueItem& aOpaque( aSet.Get(RES_OPAQUE) );
2001             bOpaque = !aOpaque.GetValue();
2002         }
2003     }
2004     aSet.Put(SvxOpaqueItem(RES_OPAQUE, bOpaque ));
2005 
2006     if(bObj)
2007     {
2008         rSh.SetObjAttr(aSet);
2009         if ( bOpaque )
2010             rSh.SelectionToHeaven();
2011         else
2012             rSh.SelectionToHell();
2013     }
2014     else
2015         rSh.SetFlyFrameAttr(aSet);
2016 
2017 }
2018 
2019 //Force update of the status line
2020 
SetFrameMode(FlyMode eMode,SwWrtShell * pSh)2021 void SwBaseShell::SetFrameMode(FlyMode eMode, SwWrtShell *pSh )
2022 {
2023     eFrameMode = eMode;
2024     SfxBindings &rBnd = pSh->GetView().GetViewFrame()->GetBindings();
2025 
2026     if( eMode == FLY_DRAG || pSh->IsFrameSelected() || pSh->IsObjSelected() )
2027     {
2028         const SfxPointItem aTmp1( SID_ATTR_POSITION, pSh->GetAnchorObjDiff());
2029         const SvxSizeItem  aTmp2( SID_ATTR_SIZE,     pSh->GetObjSize());
2030         rBnd.SetState( aTmp1 );
2031         rBnd.SetState( aTmp2 );
2032     }
2033     else if( eMode == FLY_DRAG_END )
2034     {
2035         static sal_uInt16 aInval[] =
2036         {
2037             SID_ATTR_POSITION, SID_ATTR_SIZE, 0
2038         };
2039         rBnd.Invalidate(aInval);
2040     }
2041 }
2042 
SwBaseShell(SwView & rVw)2043 SwBaseShell::SwBaseShell(SwView& rVw) :
2044     SfxShell( &rVw ),
2045     rView(rVw),
2046     pGetStateSet(nullptr)
2047 {
2048     SwWrtShell& rWrtSh = rView.GetWrtShell();
2049 
2050     SetPool(&rWrtSh.GetAttrPool());
2051     SetName("Base");
2052     rWrtSh.SetGrfArrivedLnk( LINK( this, SwBaseShell, GraphicArrivedHdl));
2053 }
2054 
~SwBaseShell()2055 SwBaseShell::~SwBaseShell()
2056 {
2057     if( rView.GetCurShell() == this )
2058         rView.ResetSubShell();
2059 
2060     Link<SwCursorShell&,void> aTmp( LINK( this, SwBaseShell, GraphicArrivedHdl));
2061     if( aTmp == rView.GetWrtShell().GetGrfArrivedLnk() )
2062         rView.GetWrtShell().SetGrfArrivedLnk( Link<SwCursorShell&,void>() );
2063 }
2064 
ExecTextCtrl(SfxRequest & rReq)2065 void SwBaseShell::ExecTextCtrl( SfxRequest& rReq )
2066 {
2067     const SfxItemSet *pArgs = rReq.GetArgs();
2068 
2069     if( pArgs)
2070     {
2071         SwWrtShell &rSh = GetShell();
2072         std::unique_ptr<SvxScriptSetItem> pSSetItem;
2073         sal_uInt16 nSlot = rReq.GetSlot();
2074         SfxItemPool& rPool = rSh.GetAttrPool();
2075         sal_uInt16 nWhich = rPool.GetWhich( nSlot );
2076         SvtScriptType nScripts = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
2077         SfxItemSet aHeightSet( GetPool(),  svl::Items<RES_CHRATR_FONTSIZE, RES_CHRATR_FONTSIZE,
2078                                             RES_CHRATR_CJK_FONTSIZE, RES_CHRATR_CJK_FONTSIZE,
2079                                             RES_CHRATR_CTL_FONTSIZE, RES_CHRATR_CTL_FONTSIZE>{});
2080 
2081         switch( nSlot )
2082         {
2083             case SID_ATTR_CHAR_FONT:
2084             {
2085                 nScripts = rSh.GetScriptType();
2086                 // #i42732# input language should be preferred over
2087                 // current cursor position to detect script type
2088                 if(!rSh.HasSelection())
2089                 {
2090                     LanguageType nInputLang = GetView().GetEditWin().GetInputLanguage();
2091                     if(nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
2092                         nScripts = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
2093                 }
2094                 [[fallthrough]];
2095             }
2096             case SID_ATTR_CHAR_POSTURE:
2097             case SID_ATTR_CHAR_WEIGHT:
2098             {
2099                 pSSetItem.reset(new SvxScriptSetItem( nSlot, rPool ));
2100                 pSSetItem->PutItemForScriptType( nScripts, pArgs->Get( nWhich ));
2101                 pArgs = &pSSetItem->GetItemSet();
2102             }
2103             break;
2104             case SID_ATTR_CHAR_FONTHEIGHT:
2105             {
2106                 if(rSh.HasSelection())
2107                 {
2108                     pSSetItem.reset(new SvxScriptSetItem( nSlot, rPool ));
2109                     pSSetItem->PutItemForScriptType( nScripts, pArgs->Get( nWhich ));
2110                     pArgs = &pSSetItem->GetItemSet();
2111                 }
2112                 else
2113                 {
2114                     nScripts = rSh.GetScriptType();
2115                     LanguageType nInputLang = GetView().GetEditWin().GetInputLanguage();
2116                     if(nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
2117                         nScripts = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
2118                     sal_uInt32 nHeight = static_cast< const SvxFontHeightItem& >(pArgs->Get( nWhich )).GetHeight();
2119                     SwStdFontConfig* pStdFont = SW_MOD()->GetStdFontConfig();
2120 
2121                     SfxItemSet aLangSet( GetPool(), svl::Items<RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
2122                                                     RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
2123                                                     RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE>{});
2124                     rSh.GetCurAttr( aLangSet );
2125 
2126                     sal_Int32 nWesternSize =
2127                             pStdFont->GetFontHeight(FONT_STANDARD, FONT_GROUP_DEFAULT,
2128                             aLangSet.Get( RES_CHRATR_LANGUAGE).GetLanguage());
2129                     sal_Int32 nCJKSize =
2130                             pStdFont->GetFontHeight(FONT_STANDARD, FONT_GROUP_CJK,
2131                             aLangSet.Get( RES_CHRATR_CJK_LANGUAGE).GetLanguage());
2132                     sal_Int32 nCTLSize =
2133                             pStdFont->GetFontHeight(FONT_STANDARD, FONT_GROUP_CTL,
2134                             aLangSet.Get( RES_CHRATR_CTL_LANGUAGE).GetLanguage());
2135 
2136                     switch(nScripts)
2137                     {
2138                         case SvtScriptType::LATIN:
2139                             nCJKSize = nHeight * nCJKSize / nWesternSize;
2140                             nCTLSize = nHeight * nCTLSize / nWesternSize;
2141                             nWesternSize = static_cast<sal_Int32>(nHeight);
2142                         break;
2143                         case SvtScriptType::ASIAN:
2144                             nCTLSize = nHeight* nCTLSize / nCJKSize;
2145                             nWesternSize = nHeight * nWesternSize / nCJKSize;
2146                             nCJKSize = static_cast<sal_Int32>(nHeight);
2147                         break;
2148                         case SvtScriptType::COMPLEX:
2149                             nCJKSize = nHeight * nCJKSize / nCTLSize;
2150                             nWesternSize = nHeight * nWesternSize / nCTLSize;
2151                             nCTLSize = static_cast<sal_Int32>(nHeight);
2152                         break;
2153                         default: break;
2154                     }
2155                     aHeightSet.Put( SvxFontHeightItem( static_cast<sal_uInt32>(nWesternSize), 100, RES_CHRATR_FONTSIZE ));
2156                     aHeightSet.Put( SvxFontHeightItem( static_cast<sal_uInt32>(nCJKSize), 100, RES_CHRATR_CJK_FONTSIZE ));
2157                     aHeightSet.Put( SvxFontHeightItem( static_cast<sal_uInt32>(nCTLSize), 100, RES_CHRATR_CTL_FONTSIZE ));
2158                     pArgs = &aHeightSet;
2159                 }
2160             }
2161             break;
2162         }
2163 
2164         if( pArgs )
2165         {
2166             bool bAuto = false;
2167             if ( !isCHRATR(nWhich) ||
2168                  ( rSh.HasSelection() && rSh.IsSelFullPara() ) )
2169             {
2170                 SwTextFormatColl * pColl = rSh.GetCurTextFormatColl();
2171                 if ( pColl && pColl->IsAutoUpdateFormat() )
2172                 {
2173                     rSh.AutoUpdatePara( pColl, *pArgs );
2174                     bAuto = true;
2175                 }
2176             }
2177 
2178             if (!bAuto)
2179             {
2180                 rSh.SetAttrSet( *pArgs );
2181             }
2182         }
2183     }
2184     else
2185         GetView().GetViewFrame()->GetDispatcher()->Execute( SID_CHAR_DLG );
2186     rReq.Done();
2187 }
2188 
GetTextCtrlState(SfxItemSet & rSet)2189 void SwBaseShell::GetTextCtrlState( SfxItemSet& rSet )
2190 {
2191     SwWrtShell &rSh = GetShell();
2192     rSh.GetCurAttr( rSet );
2193 }
2194 
GetTextFontCtrlState(SfxItemSet & rSet)2195 void SwBaseShell::GetTextFontCtrlState( SfxItemSet& rSet )
2196 {
2197     SwWrtShell &rSh = GetShell();
2198     bool bFirst = true;
2199     std::unique_ptr<SfxItemSet> pFntCoreSet;
2200     SvtScriptType nScriptType = SvtScriptType::LATIN;
2201     SfxWhichIter aIter( rSet );
2202     sal_uInt16 nWhich = aIter.FirstWhich();
2203     while( nWhich )
2204     {
2205         switch( nWhich )
2206         {
2207         case RES_CHRATR_FONT:
2208         case RES_CHRATR_FONTSIZE:
2209         case RES_CHRATR_WEIGHT:
2210         case RES_CHRATR_POSTURE:
2211             {
2212                 if( !pFntCoreSet )
2213                 {
2214                     pFntCoreSet.reset(new SfxItemSet( *rSet.GetPool(),
2215                                     svl::Items<RES_CHRATR_BEGIN, RES_CHRATR_END-1>{} ));
2216                     rSh.GetCurAttr( *pFntCoreSet );
2217                     nScriptType = rSh.GetScriptType();
2218                     // #i42732# input language should be preferred over
2219                     // current cursor position to detect script type
2220                     SwEditWin& rEditWin = GetView().GetEditWin();
2221                     if( rEditWin.IsUseInputLanguage() )
2222                     {
2223                         if(!rSh.HasSelection() && (
2224                             nWhich == RES_CHRATR_FONT ||
2225                             nWhich == RES_CHRATR_FONTSIZE ))
2226                         {
2227                             LanguageType nInputLang = rEditWin.GetInputLanguage();
2228                             if(nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
2229                                 nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
2230                         }
2231                     }
2232                 }
2233                 SfxItemPool& rPool = *rSet.GetPool();
2234                 SvxScriptSetItem aSetItem( rPool.GetSlotId( nWhich ), rPool );
2235                 aSetItem.GetItemSet().Put( *pFntCoreSet, false );
2236                 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScriptType );
2237                 if( pI )
2238                 {
2239                     rSet.Put( pI->CloneSetWhich(nWhich) );
2240                 }
2241                 else
2242                     rSet.InvalidateItem( nWhich );
2243                 // Set input context of the SwEditWin according to the selected font and script type
2244                 if(RES_CHRATR_FONT == nWhich)
2245                 {
2246                     vcl::Font aFont;
2247                     if (const SvxFontItem* pFontItem = dynamic_cast<const SvxFontItem*>(pI))
2248                     {
2249                         aFont.SetFamilyName(pFontItem->GetFamilyName());
2250                         aFont.SetStyleName(pFontItem->GetStyleName());
2251                         aFont.SetFamily(pFontItem->GetFamily());
2252                         aFont.SetPitch(pFontItem->GetPitch());
2253                         aFont.SetCharSet(pFontItem->GetCharSet());
2254                     }
2255 
2256                     bool bVertical = rSh.IsInVerticalText();
2257                     aFont.SetOrientation(bVertical ? 2700 : 0);
2258                     aFont.SetVertical(bVertical);
2259                     GetView().GetEditWin().SetInputContext( InputContext( aFont, InputContextFlags::Text |
2260                                                         InputContextFlags::ExtText ) );
2261                 }
2262             }
2263             break;
2264 
2265         default:
2266             if( bFirst )
2267             {
2268                 rSh.GetCurAttr( rSet );
2269                 bFirst = false;
2270             }
2271         }
2272         nWhich = aIter.NextWhich();
2273     }
2274 }
2275 
GetBckColState(SfxItemSet & rSet)2276 void SwBaseShell::GetBckColState(SfxItemSet &rSet)
2277 {
2278     SwWrtShell &rSh = GetShell();
2279     SfxWhichIter aIter(rSet);
2280     sal_uInt16 nWhich(aIter.FirstWhich());
2281     SelectionType nSelType(rSh.GetSelectionType());
2282     std::shared_ptr<SvxBrushItem> aBrushItem(std::make_shared<SvxBrushItem>(RES_BACKGROUND));
2283 
2284     if( nWhich == SID_TABLE_CELL_BACKGROUND_COLOR )
2285     {
2286         rSh.GetBoxBackground( aBrushItem );
2287     }
2288     else
2289     {
2290         // Adapt to new DrawingLayer FillStyle; use a parent which has XFILL_NONE set
2291         SfxItemSet aCoreSet(GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{});
2292 
2293         aCoreSet.SetParent(&GetView().GetDocShell()->GetDoc()->GetDfltFrameFormat()->GetAttrSet());
2294 
2295         if(nSelType & SelectionType::Graphic || SelectionType::Frame & nSelType)
2296         {
2297             rSh.GetFlyFrameAttr(aCoreSet);
2298         }
2299         else
2300         {
2301             rSh.GetCurAttr(aCoreSet);
2302         }
2303 
2304         aBrushItem = getSvxBrushItemFromSourceSet(aCoreSet, RES_BACKGROUND);
2305     }
2306 
2307     while(nWhich)
2308     {
2309         switch(nWhich)
2310         {
2311             case SID_BACKGROUND_COLOR:
2312             case SID_TABLE_CELL_BACKGROUND_COLOR:
2313             {
2314                 SvxColorItem aColorItem(aBrushItem->GetColor(),SID_BACKGROUND_COLOR);
2315                 rSet.Put(aColorItem);
2316                 break;
2317             }
2318             case SID_ATTR_BRUSH:
2319             case RES_BACKGROUND:
2320             {
2321                 // if this was intended to have a independent copy of the Item to be set
2322                 // this is not needed due to the ItemSet/Pool cloning Items which get set anyways.
2323                 // Keeping code as reference - it may have had other reasons I do notz see (?!?)
2324                 // std::unique_ptr<SfxPoolItem> pNewItem(aBrushItem.CloneSetWhich(GetPool().GetWhich(nWhich)));
2325                 rSet.Put(*aBrushItem);
2326                 break;
2327             }
2328         }
2329 
2330         nWhich = aIter.NextWhich();
2331     }
2332 }
2333 
ExecBckCol(SfxRequest & rReq)2334 void SwBaseShell::ExecBckCol(SfxRequest& rReq)
2335 {
2336     SwWrtShell &rSh = GetShell();
2337     SelectionType nSelType(rSh.GetSelectionType());
2338     const SfxItemSet* pArgs = rReq.GetArgs();
2339     sal_uInt16 nSlot(rReq.GetSlot());
2340 
2341     if (!pArgs && nSlot != SID_BACKGROUND_COLOR && nSlot != SID_TABLE_CELL_BACKGROUND_COLOR)
2342     {
2343         return;
2344     }
2345 
2346     std::shared_ptr<SvxBrushItem> aBrushItem(std::make_shared<SvxBrushItem>(RES_BACKGROUND));
2347 
2348     if ( nSlot == SID_TABLE_CELL_BACKGROUND_COLOR )
2349     {
2350         rSh.GetBoxBackground( aBrushItem );
2351     }
2352     else
2353     {
2354         // Adapt to new DrawingLayer FillStyle; use a parent which has XFILL_NONE set
2355         SfxItemSet aCoreSet(GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{});
2356 
2357         aCoreSet.SetParent(&GetView().GetDocShell()->GetDoc()->GetDfltFrameFormat()->GetAttrSet());
2358 
2359         if((SelectionType::Frame & nSelType) || (SelectionType::Graphic & nSelType))
2360         {
2361             rSh.GetFlyFrameAttr(aCoreSet);
2362         }
2363         else
2364         {
2365             rSh.GetCurAttr(aCoreSet);
2366         }
2367 
2368         aBrushItem = getSvxBrushItemFromSourceSet(aCoreSet, RES_BACKGROUND);
2369     }
2370 
2371     switch(nSlot)
2372     {
2373         case SID_BACKGROUND_COLOR:
2374         case SID_TABLE_CELL_BACKGROUND_COLOR:
2375         {
2376             const SfxPoolItem* pColorStringItem = nullptr;
2377             bool bIsTransparent = false;
2378 
2379             aBrushItem->SetGraphicPos(GPOS_NONE);
2380 
2381             sal_uInt16 nSlotId = (nSlot == SID_BACKGROUND_COLOR) ? SID_BACKGROUND_COLOR : SID_TABLE_CELL_BACKGROUND_COLOR;
2382             if (pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_COLOR_STR, false, &pColorStringItem))
2383             {
2384                 OUString sColor = static_cast<const SfxStringItem*>(pColorStringItem)->GetValue();
2385                 if (sColor == "transparent")
2386                 {
2387                     bIsTransparent = true;
2388                 }
2389                 else
2390                 {
2391                     Color aColor(sColor.toInt32(16));
2392 
2393                     aBrushItem->SetColor(aColor);
2394 
2395                     SvxColorItem aNewColorItem(nSlotId);
2396                     aNewColorItem.SetValue(aColor);
2397 
2398                     GetView().GetViewFrame()->GetBindings().SetState(aNewColorItem);
2399                 }
2400             }
2401             else if (pArgs)
2402             {
2403                 const SvxColorItem& rNewColorItem = static_cast<const SvxColorItem&>(pArgs->Get(nSlotId));
2404                 const Color& rNewColor = rNewColorItem.GetValue();
2405                 aBrushItem->SetColor(rNewColor);
2406                 GetView().GetViewFrame()->GetBindings().SetState(rNewColorItem);
2407             }
2408             else
2409             {
2410                 bIsTransparent = true;
2411             }
2412 
2413             if (bIsTransparent)
2414             {
2415                 aBrushItem->SetColor(COL_TRANSPARENT);
2416                 rReq.AppendItem(SvxColorItem(COL_TRANSPARENT,nSlot));
2417             }
2418             break;
2419         }
2420 
2421         case SID_ATTR_BRUSH:
2422         case RES_BACKGROUND:
2423         {
2424             assert(pArgs && "only SID_BACKGROUND_COLOR can have !pArgs, checked at entry");
2425             aBrushItem.reset(static_cast<SvxBrushItem*>(pArgs->Get(GetPool().GetWhich(nSlot)).Clone()));
2426             break;
2427         }
2428         default:
2429         {
2430             rReq.Ignore();
2431             OSL_FAIL("unknown message in ExecuteAttr!" );
2432             return;
2433         }
2434     }
2435 
2436     if ( nSlot == SID_TABLE_CELL_BACKGROUND_COLOR )
2437     {
2438         rSh.SetBoxBackground( *aBrushItem );
2439     }
2440     else
2441     {
2442         // Adapt to new DrawingLayer FillStyle; use a parent which has XFILL_NONE set
2443         SfxItemSet aCoreSet(GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{});
2444 
2445         aCoreSet.SetParent(&GetView().GetDocShell()->GetDoc()->GetDfltFrameFormat()->GetAttrSet());
2446         setSvxBrushItemAsFillAttributesToTargetSet(*aBrushItem, aCoreSet);
2447 
2448         if((SelectionType::Frame & nSelType) || (SelectionType::Graphic & nSelType))
2449         {
2450             // Template autoupdate
2451             SwFrameFormat* pFormat = rSh.GetSelectedFrameFormat();
2452 
2453             if(pFormat && pFormat->IsAutoUpdateFormat())
2454             {
2455                 rSh.AutoUpdateFrame(pFormat, aCoreSet);
2456             }
2457             else
2458             {
2459                 rSh.SetFlyFrameAttr(aCoreSet);
2460             }
2461         }
2462         else
2463         {
2464             SwTextFormatColl* pColl = rSh.GetCurTextFormatColl();
2465 
2466             if(pColl && pColl->IsAutoUpdateFormat())
2467             {
2468                 rSh.AutoUpdatePara(pColl, aCoreSet);
2469             }
2470             else
2471             {
2472                 rSh.SetAttrSet(aCoreSet);
2473             }
2474         }
2475     }
2476 
2477     rReq.Done();
2478 }
2479 
GetBorderState(SfxItemSet & rSet)2480 void SwBaseShell::GetBorderState(SfxItemSet &rSet)
2481 {
2482     SwWrtShell &rSh = GetShell();
2483     // Tabele cell(s) selected?
2484     bool bPrepare = true;
2485     bool bTableMode = rSh.IsTableMode();
2486     if ( bTableMode )
2487     {
2488         SfxItemSet aCoreSet( GetPool(),
2489                              svl::Items<RES_BOX, RES_BOX,
2490                              SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER>{} );
2491         SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
2492         aCoreSet.Put( aBoxInfo );
2493         rSh.GetTabBorders( aCoreSet );
2494         rSet.Put( aCoreSet );
2495     }
2496     else if ( rSh.IsFrameSelected() )
2497     {
2498         SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE );
2499         rSet.Put( aMgr.GetAttrSet() );
2500         bPrepare = false;
2501     }
2502     else
2503         // Get border attributes via shell quite normal
2504         rSh.GetCurAttr( rSet );
2505     if ( bPrepare )
2506         ::PrepareBoxInfo( rSet, rSh );
2507     // Switch the border toolbox controller mode
2508     rSet.Put( SfxBoolItem( SID_BORDER_REDUCED_MODE, !bTableMode ));
2509 }
2510 
ExecDlg(SfxRequest & rReq)2511 void SwBaseShell::ExecDlg(SfxRequest &rReq)
2512 {
2513     SwWrtShell &rSh = GetShell();
2514     weld::Window* pMDI = GetView().GetFrameWeld();
2515     // So that from the basic no dialogues for the background views are called:
2516     bool bBackground = (&GetView() != GetActiveView());
2517     const SfxPoolItem* pItem = nullptr;
2518     const SfxItemSet* pArgs = rReq.GetArgs();
2519 
2520     sal_uInt16 nSlot = rReq.GetSlot();
2521     const SfxItemSet* pOutSet = nullptr;
2522     bool bDone = false;
2523     if(pArgs)
2524         pArgs->GetItemState( GetPool().GetWhich(nSlot), false, &pItem );
2525 
2526     switch ( nSlot )
2527     {
2528         case FN_FORMAT_TITLEPAGE_DLG:
2529         {
2530             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2531             ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateTitlePageDlg(pMDI));
2532             pDlg->Execute();
2533         }
2534         break;
2535         case FN_FORMAT_PAGE_DLG:
2536         case FN_FORMAT_PAGE_COLUMN_DLG:
2537         case FN_FORMAT_PAGE_SETTING_DLG:
2538         {
2539             if( !bBackground )
2540             {
2541                 const size_t nCurIdx = rSh.GetCurPageDesc();
2542                 const SwPageDesc& rPageDesc = rSh.GetPageDesc( nCurIdx );
2543                 // Temporary view, because the shell does not need to be valid after the dialogue
2544                 // for example disable header
2545                 SwView& rTempView = GetView();
2546 
2547                 OString sPageId;
2548                 switch (nSlot)
2549                 {
2550                     case FN_FORMAT_PAGE_COLUMN_DLG:
2551                         sPageId = "columns";
2552                         break;
2553                     case FN_FORMAT_PAGE_SETTING_DLG:
2554                         sPageId = "page";
2555                         break;
2556                     case FN_FORMAT_PAGE_DLG:
2557                         if (pItem)
2558                           sPageId = OUStringToOString(static_cast<const SfxStringItem*>(pItem)->GetValue(), RTL_TEXTENCODING_UTF8);
2559                         break;
2560                 }
2561                 rTempView.GetDocShell()->FormatPage(rPageDesc.GetName(), sPageId, rSh, &rReq);
2562                 rTempView.InvalidateRulerPos();
2563 
2564                 bDone = true; // FormatPage() takes care of calling Done()
2565             }
2566         }
2567         break;
2568         case FN_FORMAT_BORDER_DLG:
2569         {
2570             SfxItemSet   aSet( rSh.GetAttrPool(),
2571                                svl::Items<RES_BOX              , RES_SHADOW,
2572                                SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER>{} );
2573             ScopedVclPtr<SfxAbstractDialog> pDlg;
2574             // Table cell(s) selected?
2575             if ( rSh.IsTableMode() )
2576             {
2577                 // Set border attributes Get/SetTabBorders()
2578                 ::PrepareBoxInfo( aSet, rSh );
2579                 rSh.GetTabBorders( aSet );
2580                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2581                 pDlg.disposeAndReset(pFact->CreateSwBorderDlg(pMDI, aSet, SwBorderModes::TABLE));
2582                 if ( pDlg->Execute() == RET_OK )
2583                 {
2584                     rSh.SetTabBorders( *pDlg->GetOutputItemSet() );
2585                     pOutSet = pDlg->GetOutputItemSet();
2586                 }
2587             }
2588             else if ( rSh.IsFrameSelected() )
2589             {
2590                 // Set border attributes via Frame-Manager
2591                 SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE );
2592                 aSet.Put( aMgr.GetAttrSet() );
2593 
2594                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2595                 pDlg.disposeAndReset(pFact->CreateSwBorderDlg(pMDI, aSet, SwBorderModes::FRAME));
2596                 if ( pDlg->Execute() == RET_OK )
2597                 {
2598                     aMgr.SetAttrSet( *pDlg->GetOutputItemSet() );
2599                     aMgr.UpdateFlyFrame();
2600                     pOutSet = pDlg->GetOutputItemSet();
2601                 }
2602             }
2603             else
2604             {
2605                 // Set border attributes via Shell quite normal
2606                 rSh.GetCurAttr( aSet );
2607                 ::PrepareBoxInfo( aSet, rSh );
2608 
2609                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2610                 pDlg.disposeAndReset(pFact->CreateSwBorderDlg(pMDI, aSet, SwBorderModes::PARA));
2611                 if ( pDlg->Execute() == RET_OK )
2612                 {
2613                     rSh.SetAttrSet( *pDlg->GetOutputItemSet() );
2614                     pOutSet = pDlg->GetOutputItemSet();
2615                 }
2616             }
2617             if(pOutSet)
2618             {
2619                 rReq.Done(*pOutSet);
2620                 bDone = true;
2621             }
2622         }
2623         break;
2624         case FN_FORMAT_BACKGROUND_DLG:
2625         {
2626             SfxItemSet aSet( rSh.GetAttrPool(),
2627                              svl::Items<RES_BACKGROUND, RES_BACKGROUND>{} );
2628 
2629             ScopedVclPtr<SfxAbstractDialog> pDlg;
2630             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2631 
2632             // Table cell(s) selected?
2633             if ( rSh.IsTableMode() )
2634             {
2635                 // Get background attributes of the table and put it in the set
2636                 std::shared_ptr<SvxBrushItem> aBrush;
2637                 rSh.GetBoxBackground( aBrush );
2638                 pDlg.disposeAndReset(pFact->CreateSwBackgroundDialog(pMDI, aSet));
2639                 aSet.Put( *aBrush );
2640                 if ( pDlg->Execute() == RET_OK )
2641                 {
2642 
2643                     rSh.SetBoxBackground( pDlg->GetOutputItemSet()->Get( RES_BACKGROUND ) );
2644                     pOutSet = pDlg->GetOutputItemSet();
2645                 }
2646             }
2647             else if ( rSh.IsFrameSelected() )
2648             {
2649 
2650                 rSh.GetFlyFrameAttr( aSet );
2651 
2652                 pDlg.disposeAndReset(pFact->CreateSwBackgroundDialog(pMDI, aSet));
2653                 if ( pDlg->Execute() == RET_OK )
2654                 {
2655                     rSh.SetFlyFrameAttr(const_cast<SfxItemSet &>(*pDlg->GetOutputItemSet()) );
2656                     pOutSet = pDlg->GetOutputItemSet();
2657                 }
2658             }
2659             else
2660             {
2661                 // Set border attributes Umrandungsattribute with the shell quite normal.
2662                 rSh.GetCurAttr( aSet );
2663 
2664                 pDlg.disposeAndReset(pFact->CreateSwBackgroundDialog(pMDI, aSet));
2665                 if ( pDlg->Execute() == RET_OK )
2666                 {
2667                     rSh.SetAttrSet( *pDlg->GetOutputItemSet() );
2668                     pOutSet = pDlg->GetOutputItemSet();
2669                 }
2670             }
2671             if(pOutSet)
2672             {
2673                 rReq.Done(*pOutSet);
2674                 bDone = true;
2675             }
2676         }
2677         break;
2678         default:OSL_FAIL("wrong Dispatcher (basesh.cxx)");
2679     }
2680     if(!bDone)
2681         rReq.Done();
2682 }
2683 
GetShell()2684 SwWrtShell& SwBaseShell::GetShell()
2685 {
2686     return rView.GetWrtShell();
2687 }
2688 
GetShellPtr()2689 SwWrtShell* SwBaseShell::GetShellPtr()
2690 {
2691     return rView.GetWrtShellPtr();
2692 }
2693 
InsertTable(SfxRequest & _rRequest)2694 void SwBaseShell::InsertTable( SfxRequest& _rRequest )
2695 {
2696     const SfxItemSet* pArgs = _rRequest.GetArgs();
2697     SwWrtShell& rSh = GetShell();
2698 
2699     if ( !( rSh.GetFrameType( nullptr, true ) & FrameTypeFlags::FOOTNOTE ) )
2700     {
2701         SwView &rTempView = GetView(); // Because GetView() does not work after the shell exchange
2702         bool bHTMLMode = 0 != (::GetHtmlMode(rTempView.GetDocShell())&HTMLMODE_ON);
2703         bool bCallEndUndo = false;
2704 
2705         if( !pArgs && rSh.IsSelection() && !rSh.IsInClickToEdit() &&
2706             !rSh.IsTableMode() )
2707         {
2708             const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
2709             SwInsertTableOptions aInsTableOpts = pModOpt->GetInsTableFlags(bHTMLMode);
2710 
2711             rSh.StartUndo(SwUndoId::INSTABLE);
2712             bCallEndUndo = true;
2713 
2714             bool bInserted = rSh.TextToTable( aInsTableOpts, '\t' );
2715             rSh.EnterStdMode();
2716             if (bInserted)
2717                 rTempView.AutoCaption(TABLE_CAP);
2718             _rRequest.Done();
2719         }
2720         else
2721         {
2722             sal_uInt16 nCols = 0;
2723             sal_uInt16 nRows = 0;
2724             SwInsertTableOptions aInsTableOpts( SwInsertTableFlags::All, 1 );
2725             OUString aTableName;
2726             OUString aAutoName;
2727             std::unique_ptr<SwTableAutoFormat> pTAFormat;
2728 
2729             if( pArgs && pArgs->Count() >= 2 )
2730             {
2731                 const SfxStringItem* pName = _rRequest.GetArg<SfxStringItem>(FN_INSERT_TABLE);
2732                 const SfxUInt16Item* pCols = _rRequest.GetArg<SfxUInt16Item>(SID_ATTR_TABLE_COLUMN);
2733                 const SfxUInt16Item* pRows = _rRequest.GetArg<SfxUInt16Item>(SID_ATTR_TABLE_ROW);
2734                 const SfxInt32Item* pFlags = _rRequest.GetArg<SfxInt32Item>(FN_PARAM_1);
2735                 const SfxStringItem* pAuto = _rRequest.GetArg<SfxStringItem>(FN_PARAM_2);
2736 
2737                 if ( pName )
2738                     aTableName = pName->GetValue();
2739                 if ( pCols )
2740                     nCols = pCols->GetValue();
2741                 if ( pRows )
2742                     nRows = pRows->GetValue();
2743                 if ( pAuto )
2744                 {
2745                     aAutoName = pAuto->GetValue();
2746                     if ( !aAutoName.isEmpty() )
2747                     {
2748                         SwTableAutoFormatTable aTableTable;
2749                         aTableTable.Load();
2750                         for ( size_t n=0; n<aTableTable.size(); n++ )
2751                         {
2752                             if ( aTableTable[n].GetName() == aAutoName )
2753                             {
2754                                 pTAFormat.reset(new SwTableAutoFormat( aTableTable[n] ));
2755                                 break;
2756                             }
2757                         }
2758                     }
2759                 }
2760 
2761                 if ( pFlags )
2762                     aInsTableOpts.mnInsMode = static_cast<SwInsertTableFlags>(pFlags->GetValue());
2763                 else
2764                 {
2765                     const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
2766                     aInsTableOpts = pModOpt->GetInsTableFlags(bHTMLMode);
2767                 }
2768             }
2769 
2770             if( !nCols || !nRows )
2771             {
2772                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2773                 ScopedVclPtr<AbstractInsTableDlg> pDlg(pFact->CreateInsTableDlg(rTempView));
2774                 if( RET_OK == pDlg->Execute() )
2775                 {
2776                     pDlg->GetValues( aTableName, nRows, nCols, aInsTableOpts, aAutoName, pTAFormat );
2777                 }
2778                 else
2779                     _rRequest.Ignore();
2780             }
2781 
2782             if( nCols && nRows )
2783             {
2784                 // record before shell change
2785                 _rRequest.AppendItem( SfxStringItem( FN_INSERT_TABLE, aTableName ) );
2786                 if ( !aAutoName.isEmpty() )
2787                     _rRequest.AppendItem( SfxStringItem( FN_PARAM_2, aAutoName ) );
2788                 _rRequest.AppendItem( SfxUInt16Item( SID_ATTR_TABLE_COLUMN, nCols ) );
2789                 _rRequest.AppendItem( SfxUInt16Item( SID_ATTR_TABLE_ROW, nRows ) );
2790                 _rRequest.AppendItem( SfxInt32Item( FN_PARAM_1, static_cast<sal_Int32>(aInsTableOpts.mnInsMode) ) );
2791                 _rRequest.Done();
2792 
2793                 rSh.StartUndo(SwUndoId::INSTABLE);
2794                 bCallEndUndo = true;
2795 
2796                 rSh.StartAllAction();
2797                 if( rSh.HasSelection() )
2798                     rSh.DelRight();
2799 
2800                 rSh.InsertTable( aInsTableOpts, nRows, nCols, pTAFormat.get() );
2801                 rSh.MoveTable( GotoPrevTable, fnTableStart );
2802 
2803                 if( !aTableName.isEmpty() && !rSh.GetTableStyle( aTableName ) )
2804                     rSh.GetTableFormat()->SetName( aTableName );
2805 
2806                 if( pTAFormat != nullptr && !aAutoName.isEmpty()
2807                         && aAutoName != SwViewShell::GetShellRes()->aStrNone )
2808                 {
2809                     SwTableNode* pTableNode = const_cast<SwTableNode*>( rSh.IsCursorInTable() );
2810                     if ( pTableNode )
2811                     {
2812                         pTableNode->GetTable().SetTableStyleName( aAutoName );
2813                         SwUndoTableAutoFormat* pUndo = new SwUndoTableAutoFormat( *pTableNode, *pTAFormat );
2814                         if ( pUndo )
2815                             rSh.GetIDocumentUndoRedo().AppendUndo( std::unique_ptr<SwUndo>(pUndo) );
2816                     }
2817                 }
2818 
2819                 rSh.EndAllAction();
2820                 rTempView.AutoCaption(TABLE_CAP);
2821             }
2822         }
2823 
2824         if( bCallEndUndo )
2825         {
2826             SwRewriter aRewriter;
2827 
2828             if (rSh.GetTableFormat())
2829             {
2830                 aRewriter.AddRule(UndoArg1, SwResId(STR_START_QUOTE));
2831                 aRewriter.AddRule(UndoArg2, rSh.GetTableFormat()->GetName());
2832                 aRewriter.AddRule(UndoArg3, SwResId(STR_END_QUOTE));
2833 
2834             }
2835             rSh.EndUndo(SwUndoId::INSTABLE, &aRewriter); // If possible change the Shell
2836         }
2837     }
2838 }
2839 
GetGalleryState(SfxItemSet & rSet)2840 void SwBaseShell::GetGalleryState( SfxItemSet &rSet )
2841 {
2842     SwWrtShell &rSh = GetShell();
2843     SfxWhichIter aIter( rSet );
2844     sal_uInt16 nWhich = aIter.FirstWhich();
2845     switch ( nWhich )
2846     {
2847         case SID_GALLERY_BG_BRUSH:
2848         {
2849             SelectionType nSel = rSh.GetSelectionType();
2850             SfxStringListItem aLst( nWhich );
2851             std::vector<OUString> &rLst = aLst.GetList();
2852             nParagraphPos = nGraphicPos = nOlePos = nFramePos = nTablePos =
2853             nTableRowPos  = nTableCellPos = nPagePos =
2854             nHeaderPos    = nFooterPos = 0;
2855             sal_uInt8 nPos = 1;
2856             rLst.push_back( SwResId( STR_SWBG_PAGE ) );
2857             nPagePos = nPos++;
2858             sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
2859             bool bHtmlMode = 0 != (nHtmlMode & HTMLMODE_ON);
2860 
2861             if ( (!bHtmlMode || (nHtmlMode & HTMLMODE_FULL_STYLES)) &&
2862                  (nSel & SelectionType::Text) )
2863             {
2864                 rLst.push_back( SwResId( STR_SWBG_PARAGRAPH ) );
2865                 nParagraphPos = nPos++;
2866             }
2867             if ( (!bHtmlMode || (nHtmlMode & HTMLMODE_SOME_STYLES)) &&
2868                     nSel & (SelectionType::Table|SelectionType::TableCell) )
2869             {
2870                 rLst.push_back( SwResId( STR_SWBG_TABLE ) );
2871                 nTablePos = nPos++;
2872 
2873                 if(!bHtmlMode)
2874                 {
2875                     rLst.push_back( SwResId( STR_SWBG_TABLE_ROW ) );
2876                     nTableRowPos = nPos++;
2877                 }
2878 
2879                 rLst.push_back( SwResId( STR_SWBG_TABLE_CELL) );
2880                 nTableCellPos = nPos++;
2881             }
2882             if(!bHtmlMode)
2883             {
2884                 if ( nSel & SelectionType::Frame )
2885                 {
2886                     rLst.push_back( SwResId( STR_SWBG_FRAME ) );
2887                     nFramePos = nPos++;
2888                 }
2889                 if ( nSel & SelectionType::Graphic )
2890                 {
2891                     rLst.push_back( SwResId( STR_SWBG_GRAPHIC ) );
2892                     nGraphicPos = nPos++;
2893                 }
2894                 if ( nSel & SelectionType::Ole )
2895                 {
2896                     rLst.push_back( SwResId( STR_SWBG_OLE ) );
2897                     nOlePos = nPos++;
2898                 }
2899                 const FrameTypeFlags nType = rSh.GetFrameType(nullptr,true);
2900                 if ( nType & FrameTypeFlags::HEADER )
2901                 {
2902                     rLst.push_back( SwResId( STR_SWBG_HEADER ) );
2903                     nHeaderPos = nPos++;
2904                 }
2905                 if ( nType & FrameTypeFlags::FOOTER )
2906                 {
2907                     rLst.push_back( SwResId( STR_SWBG_FOOTER ) );
2908                     nFooterPos = nPos;
2909                 }
2910             }
2911             if ( rLst.empty() )
2912                 rSet.DisableItem( nWhich );
2913             else
2914                 rSet.Put( aLst );
2915             break;
2916         }
2917     }
2918 }
2919 
ExecuteGallery(SfxRequest & rReq)2920 void SwBaseShell::ExecuteGallery(SfxRequest &rReq)
2921 {
2922     SwWrtShell &rSh = GetShell();
2923     rSh.StartAction();
2924     const SfxItemSet* pArgs = rReq.GetArgs();
2925     sal_uInt16 nSlot = rReq.GetSlot();
2926     switch(nSlot)
2927     {
2928         case SID_GALLERY_BG_BRUSH:
2929         {
2930             if ( !pArgs )
2931                 break;
2932 
2933             SelectionType nSel = rSh.GetSelectionType();
2934             if ( nSel & SelectionType::DrawObjectEditMode )
2935                 break;
2936 
2937             const SfxUInt16Item* pPos = rReq.GetArg<SfxUInt16Item>(SID_GALLERY_BG_POS);
2938             const SvxBrushItem* pBrush = rReq.GetArg<SvxBrushItem>(SID_GALLERY_BG_BRUSH);
2939             if ( !pPos || !pBrush )
2940                 break;
2941 
2942             sal_uInt8 nPos = pPos->GetValue();
2943             ++nPos;
2944 
2945             SvxBrushItem aBrush( *pBrush );
2946             aBrush.SetWhich( RES_BACKGROUND );
2947             if ( nPos == nParagraphPos )
2948                 rSh.SetAttrItem( aBrush );
2949             else if ( nPos == nTablePos )
2950                 rSh.SetTabBackground( aBrush );
2951             else if ( nPos == nTableRowPos )
2952                 rSh.SetRowBackground( aBrush );
2953             else if ( nPos == nTableCellPos )
2954                 rSh.SetBoxBackground( aBrush );
2955             else if ( nPos == nFramePos || nPos == nGraphicPos || nPos == nOlePos )
2956             {
2957                 SfxItemSet aCoreSet(GetPool(), svl::Items<RES_BACKGROUND, RES_BACKGROUND>{});
2958                 aCoreSet.Put( aBrush );
2959                 rSh.SetFlyFrameAttr( aCoreSet );
2960             }
2961             else if ( nPos == nPagePos || nPos == nHeaderPos || nPos == nFooterPos )
2962             {
2963                 sal_uInt16 nDesc = rSh.GetCurPageDesc();
2964                 SwPageDesc aDesc( rSh.GetPageDesc( nDesc ) );
2965                 if ( nPos == nPagePos )
2966                     aDesc.GetMaster().SetFormatAttr( aBrush );
2967                 else if ( nPos == nHeaderPos )
2968                 {
2969                     SwFormatHeader aHead( aDesc.GetMaster().GetHeader() );
2970                     aHead.GetHeaderFormat()->SetFormatAttr( aBrush );
2971                     aDesc.GetMaster().SetFormatAttr( aHead );
2972                 }
2973                 else if ( nPos == nFooterPos )
2974                 {
2975                     SwFormatFooter aFoot( aDesc.GetMaster().GetFooter() );
2976                     aFoot.GetFooterFormat()->SetFormatAttr( aBrush );
2977                     aDesc.GetMaster().SetFormatAttr( aFoot );
2978                 }
2979                 rSh.ChgPageDesc( nDesc, aDesc );
2980             }
2981             break;
2982         }
2983     }
2984     rSh.EndAction();
2985     rReq.Done();
2986 }
2987 
ExecField(SfxRequest const & rReq)2988 void SwBaseShell::ExecField( SfxRequest const & rReq )
2989 {
2990     sal_uInt16 nSlot = rReq.GetSlot();
2991     switch( nSlot )
2992     {
2993 #if HAVE_FEATURE_DBCONNECTIVITY
2994         case FN_CHANGE_DBFIELD:
2995         {
2996             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2997             ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSwChangeDBDlg(GetView()));
2998             pDlg->Execute();
2999         }
3000         break;
3001 #endif
3002         default:
3003             OSL_FAIL("wrong dispatcher");
3004     }
3005 }
3006 
3007 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
3008