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