Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / shells / textsh.cxx
blobd9bedfdf2a5bf1673e129fd4f1dbb7b6fd331a14
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_features.h>
22 #include <hintids.hxx>
23 #include <comphelper/string.hxx>
24 #include <svl/globalnameitem.hxx>
25 #include <sfx2/bindings.hxx>
26 #include <sfx2/frmdescr.hxx>
27 #include <sfx2/objface.hxx>
28 #include <sfx2/viewfrm.hxx>
30 #include <i18nutil/transliteration.hxx>
31 #include <svl/eitem.hxx>
32 #include <svl/ptitem.hxx>
33 #include <svl/stritem.hxx>
34 #include <unotools/moduleoptions.hxx>
35 #include <svx/hlnkitem.hxx>
36 #include <svl/whiter.hxx>
37 #include <sfx2/request.hxx>
38 #include <editeng/fontitem.hxx>
39 #include <editeng/boxitem.hxx>
40 #include <editeng/sizeitem.hxx>
41 #include <editeng/svxacorr.hxx>
42 #include <editeng/scripttypeitem.hxx>
43 #include <sfx2/htmlmode.hxx>
44 #include <svtools/htmlcfg.hxx>
45 #include <com/sun/star/embed/Aspects.hpp>
46 #include <com/sun/star/embed/XEmbeddedObject.hpp>
47 #include <osl/diagnose.h>
49 #include <comphelper/classids.hxx>
50 #include <editeng/acorrcfg.hxx>
51 #include <wdocsh.hxx>
52 #include <fmtinfmt.hxx>
53 #include <fmtclds.hxx>
54 #include <fmtfsize.hxx>
55 #include <swmodule.hxx>
56 #include <wrtsh.hxx>
57 #include <view.hxx>
58 #include <docsh.hxx>
59 #include <doc.hxx>
60 #include <IDocumentChartDataProviderAccess.hxx>
61 #include <uitool.hxx>
62 #include <cmdid.h>
63 #include <globals.hrc>
64 #include <frmmgr.hxx>
65 #include <textsh.hxx>
66 #include <frmfmt.hxx>
67 #include <tablemgr.hxx>
68 #include <swundo.hxx>
69 #include <breakit.hxx>
70 #include <edtwin.hxx>
71 #include <strings.hrc>
72 #include <unochart.hxx>
73 #include <chartins.hxx>
74 #include <viewopt.hxx>
76 #define ShellClass_SwTextShell
77 #include <sfx2/msg.hxx>
78 #include <vcl/EnumContext.hxx>
79 #include <swslots.hxx>
80 #include <SwRewriter.hxx>
81 #include <SwCapObjType.hxx>
83 using namespace ::com::sun::star;
85 #include <svx/svxdlg.hxx>
86 #include <swabstdlg.hxx>
87 #include <IDocumentDrawModelAccess.hxx>
88 #include <drawdoc.hxx>
89 #include <svtools/embedhlp.hxx>
90 #include <sfx2/event.hxx>
91 #include <com/sun/star/ui/dialogs/DialogClosedEvent.hpp>
92 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
93 #include <IDocumentUndoRedo.hxx>
94 #include <formatcontentcontrol.hxx>
96 SFX_IMPL_INTERFACE(SwTextShell, SwBaseShell)
98 IMPL_STATIC_LINK( SwTextShell, DialogClosedHdl, css::ui::dialogs::DialogClosedEvent*, pEvent, void )
100 if (SwView* pView = GetActiveView())
102 SwWrtShell& rWrtShell = pView->GetWrtShell();
104 sal_Int16 nDialogRet = pEvent->DialogResult;
105 if( nDialogRet == ui::dialogs::ExecutableDialogResults::CANCEL )
107 rWrtShell.Undo();
108 rWrtShell.GetIDocumentUndoRedo().ClearRedo();
110 else
112 OSL_ENSURE( nDialogRet == ui::dialogs::ExecutableDialogResults::OK,
113 "dialog execution failed" );
118 void SwTextShell::InitInterface_Impl()
120 GetStaticInterface()->RegisterPopupMenu("text");
122 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Text_Toolbox_Sw);
124 GetStaticInterface()->RegisterChildWindow(FN_EDIT_FORMULA);
125 GetStaticInterface()->RegisterChildWindow(FN_INSERT_FIELD);
126 GetStaticInterface()->RegisterChildWindow(FN_INSERT_IDX_ENTRY_DLG);
127 GetStaticInterface()->RegisterChildWindow(FN_INSERT_AUTH_ENTRY_DLG);
128 GetStaticInterface()->RegisterChildWindow(SID_RUBY_DIALOG);
129 GetStaticInterface()->RegisterChildWindow(FN_WORDCOUNT_DIALOG);
133 void SwTextShell::ExecInsert(SfxRequest &rReq)
135 SwWrtShell &rSh = GetShell();
137 OSL_ENSURE( !rSh.IsObjSelected() && !rSh.IsFrameSelected(),
138 "wrong shell on dispatcher" );
140 const SfxItemSet *pArgs = rReq.GetArgs();
141 const SfxPoolItem* pItem = nullptr;
142 const sal_uInt16 nSlot = rReq.GetSlot();
143 if(pArgs)
144 pArgs->GetItemState(nSlot, false, &pItem );
146 switch( nSlot )
148 case FN_INSERT_STRING:
149 if( pItem )
150 rSh.InsertByWord(static_cast<const SfxStringItem *>(pItem)->GetValue());
151 break;
153 case FN_INSERT_SOFT_HYPHEN:
154 if( CHAR_SOFTHYPHEN != rSh.SwCursorShell::GetChar() &&
155 CHAR_SOFTHYPHEN != rSh.SwCursorShell::GetChar( true, -1 ))
156 rSh.Insert( OUString( CHAR_SOFTHYPHEN ) );
157 break;
159 case FN_INSERT_HARDHYPHEN:
160 case FN_INSERT_HARD_SPACE:
162 const sal_Unicode cIns = FN_INSERT_HARD_SPACE == nSlot ? CHAR_HARDBLANK : CHAR_HARDHYPHEN;
164 SvxAutoCorrCfg& rACfg = SvxAutoCorrCfg::Get();
165 SvxAutoCorrect* pACorr = rACfg.GetAutoCorrect();
166 if( pACorr && rACfg.IsAutoFormatByInput()
167 && pACorr->IsAutoCorrFlag(
168 ACFlags::CapitalStartSentence | ACFlags::CapitalStartWord |
169 ACFlags::AddNonBrkSpace | ACFlags::ChgOrdinalNumber | ACFlags::TransliterateRTL |
170 ACFlags::ChgToEnEmDash | ACFlags::SetINetAttr | ACFlags::Autocorrect |
171 ACFlags::SetDOIAttr ) )
173 rSh.AutoCorrect( *pACorr, cIns );
175 else
177 rSh.Insert( OUString( cIns ) );
180 break;
182 case FN_INSERT_NNBSP: // shift+mod2/alt+space inserts some other character w/o going through SwEditWin::KeyInput(), at least on macOS
183 case SID_INSERT_RLM :
184 case SID_INSERT_LRM :
185 case SID_INSERT_WJ :
186 case SID_INSERT_ZWSP:
188 sal_Unicode cIns = 0;
189 switch(nSlot)
191 case SID_INSERT_RLM : cIns = CHAR_RLM ; break;
192 case SID_INSERT_LRM : cIns = CHAR_LRM ; break;
193 case SID_INSERT_ZWSP : cIns = CHAR_ZWSP ; break;
194 case SID_INSERT_WJ: cIns = CHAR_WJ; break;
195 case FN_INSERT_NNBSP: cIns = CHAR_NNBSP; break;
197 rSh.Insert( OUString( cIns ) );
199 break;
201 case FN_INSERT_BREAK:
203 if (!rSh.CursorInsideInputField() && !rSh.CursorInsideContentControl())
205 rSh.SplitNode();
207 else
209 rSh.InsertLineBreak();
212 rReq.Done();
213 break;
215 case FN_INSERT_PAGEBREAK:
216 rSh.InsertPageBreak();
217 rReq.Done();
218 break;
220 case FN_INSERT_LINEBREAK:
221 rSh.InsertLineBreak();
222 rReq.Done();
223 break;
225 case FN_INSERT_CONTENT_CONTROL:
226 rSh.InsertContentControl(SwContentControlType::RICH_TEXT);
227 rReq.Done();
228 break;
230 case FN_INSERT_CHECKBOX_CONTENT_CONTROL:
231 rSh.InsertContentControl(SwContentControlType::CHECKBOX);
232 rReq.Done();
233 break;
235 case FN_INSERT_DROPDOWN_CONTENT_CONTROL:
236 rSh.InsertContentControl(SwContentControlType::DROP_DOWN_LIST);
237 rReq.Done();
238 break;
240 case FN_INSERT_PICTURE_CONTENT_CONTROL:
241 rSh.InsertContentControl(SwContentControlType::PICTURE);
242 rReq.Done();
243 break;
245 case FN_INSERT_DATE_CONTENT_CONTROL:
246 rSh.InsertContentControl(SwContentControlType::DATE);
247 rReq.Done();
248 break;
250 case FN_INSERT_PLAIN_TEXT_CONTENT_CONTROL:
251 rSh.InsertContentControl(SwContentControlType::PLAIN_TEXT);
252 rReq.Done();
253 break;
255 case FN_INSERT_COMBO_BOX_CONTENT_CONTROL:
256 rSh.InsertContentControl(SwContentControlType::COMBO_BOX);
257 rReq.Done();
258 break;
260 case FN_CONTENT_CONTROL_PROPERTIES:
262 SwWrtShell& rWrtSh = GetShell();
263 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
264 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSwContentControlDlg(GetView().GetFrameWeld(), rWrtSh));
265 VclAbstractDialog::AsyncContext aContext;
266 aContext.maEndDialogFn = [](sal_Int32){};
267 pDlg->StartExecuteAsync(aContext);
268 rReq.Done();
269 break;
272 case FN_INSERT_COLUMN_BREAK:
273 rSh.InsertColumnBreak();
274 rReq.Done();
275 break;
277 case SID_HYPERLINK_SETLINK:
278 if (pItem)
279 InsertHyperlink(*static_cast<const SvxHyperlinkItem *>(pItem));
280 rReq.Done();
281 break;
283 #if HAVE_FEATURE_AVMEDIA
284 case SID_INSERT_AVMEDIA:
285 rReq.SetReturnValue(SfxBoolItem(nSlot, InsertMediaDlg( rReq )));
286 break;
287 #endif
289 case SID_INSERT_OBJECT:
291 const SfxGlobalNameItem* pNameItem = rReq.GetArg<SfxGlobalNameItem>(SID_INSERT_OBJECT);
292 SvGlobalName *pName = nullptr;
293 SvGlobalName aName;
294 if ( pNameItem )
296 aName = pNameItem->GetValue();
297 pName = &aName;
300 svt::EmbeddedObjectRef xObj;
301 rSh.InsertObject( xObj, pName, nSlot);
302 rReq.Done();
303 break;
305 case SID_INSERT_FLOATINGFRAME:
307 svt::EmbeddedObjectRef xObj;
308 const SfxStringItem* pNameItem = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
309 const SfxStringItem* pURLItem = rReq.GetArg<SfxStringItem>(FN_PARAM_2);
310 const SvxSizeItem* pMarginItem = rReq.GetArg<SvxSizeItem>(FN_PARAM_3);
311 const SfxByteItem* pScrollingItem = rReq.GetArg<SfxByteItem>(FN_PARAM_4);
312 const SfxBoolItem* pBorderItem = rReq.GetArg<SfxBoolItem>(FN_PARAM_5);
314 if(pURLItem) // URL is a _must_
316 comphelper::EmbeddedObjectContainer aCnt;
317 OUString aName;
318 xObj.Assign( aCnt.CreateEmbeddedObject( SvGlobalName( SO3_IFRAME_CLASSID ).GetByteSequence(), aName ),
319 embed::Aspects::MSOLE_CONTENT );
320 svt::EmbeddedObjectRef::TryRunningState( xObj.GetObject() );
321 uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY );
322 if ( xSet.is() )
326 ScrollingMode eScroll = ScrollingMode::Auto;
327 if( pScrollingItem && pScrollingItem->GetValue() <= int(ScrollingMode::Auto) )
328 eScroll = static_cast<ScrollingMode>(pScrollingItem->GetValue());
330 Size aMargin;
331 if ( pMarginItem )
332 aMargin = pMarginItem->GetSize();
334 xSet->setPropertyValue("FrameURL", uno::Any( pURLItem->GetValue() ) );
335 if ( pNameItem )
336 xSet->setPropertyValue("FrameName", uno::Any( pNameItem->GetValue() ) );
338 if ( eScroll == ScrollingMode::Auto )
339 xSet->setPropertyValue("FrameIsAutoScroll",
340 uno::Any( true ) );
341 else
342 xSet->setPropertyValue("FrameIsScrollingMode",
343 uno::Any( eScroll == ScrollingMode::Yes ) );
345 if ( pBorderItem )
346 xSet->setPropertyValue("FrameIsBorder",
347 uno::Any( pBorderItem->GetValue() ) );
349 if ( pMarginItem )
351 xSet->setPropertyValue("FrameMarginWidth",
352 uno::Any( sal_Int32( aMargin.Width() ) ) );
354 xSet->setPropertyValue("FrameMarginHeight",
355 uno::Any( sal_Int32( aMargin.Height() ) ) );
358 catch (const uno::Exception&)
363 rSh.InsertOleObject( xObj );
365 else
367 rSh.InsertObject( xObj, nullptr, nSlot);
368 rReq.Done();
371 break;
372 case SID_INSERT_DIAGRAM:
374 SvtModuleOptions aMOpt;
375 if ( !aMOpt.IsChart() )
376 break;
377 if(!rReq.IsAPI())
379 SwInsertChart( LINK( this, SwTextShell, DialogClosedHdl ) );
381 else
383 uno::Reference< chart2::data::XDataProvider > xDataProvider;
384 bool bFillWithData = true;
385 OUString aRangeString;
386 if (!GetShell().IsTableComplexForChart())
388 SwFrameFormat* pTableFormat = GetShell().GetTableFormat();
389 aRangeString = pTableFormat->GetName() + "."
390 + GetShell().GetBoxNms();
392 // get table data provider
393 xDataProvider.set( GetView().GetDocShell()->getIDocumentChartDataProviderAccess().GetChartDataProvider() );
395 else
396 bFillWithData = false; // will create chart with only it's default image
398 SwTableFUNC( &rSh ).InsertChart( xDataProvider, bFillWithData, aRangeString );
399 rSh.LaunchOLEObj();
401 svt::EmbeddedObjectRef& xObj = rSh.GetOLEObject();
402 if(pItem && xObj.is())
404 Size aSize(static_cast<const SvxSizeItem*>(pItem)->GetSize());
405 aSize = o3tl::convert(aSize, o3tl::Length::twip, o3tl::Length::mm100);
407 if(aSize.Width() > MINLAY&& aSize.Height()> MINLAY)
409 awt::Size aSz;
410 aSz.Width = aSize.Width();
411 aSz.Height = aSize.Height();
412 xObj->setVisualAreaSize( xObj.GetViewAspect(), aSz );
417 break;
419 case FN_INSERT_SMA:
421 // #i34343# Inserting a math object into an autocompletion crashes
422 // the suggestion has to be removed before
423 GetView().GetEditWin().StopQuickHelp();
424 SvGlobalName aGlobalName( SO3_SM_CLASSID );
425 rSh.InsertObject( svt::EmbeddedObjectRef(), &aGlobalName );
427 break;
429 case FN_INSERT_TABLE:
430 InsertTable( rReq );
431 break;
433 case FN_INSERT_FRAME_INTERACT_NOCOL:
434 case FN_INSERT_FRAME_INTERACT:
436 sal_uInt16 nCols = 1;
437 bool bModifier1 = rReq.GetModifier() == KEY_MOD1;
438 if(pArgs)
440 const SfxUInt16Item* pColsItem = nullptr;
441 if(FN_INSERT_FRAME_INTERACT_NOCOL != nSlot &&
442 (pColsItem = pArgs->GetItemIfSet(SID_ATTR_COLUMNS, false)))
443 nCols = pColsItem->GetValue();
444 if(const SfxUInt16Item* pModifierItem = pArgs->GetItemIfSet(SID_MODIFIER, false))
445 bModifier1 |= KEY_MOD1 == pModifierItem->GetValue();
447 if(bModifier1 )
449 SwEditWin& rEdtWin = GetView().GetEditWin();
450 Size aWinSize = rEdtWin.GetSizePixel();
451 Point aStartPos(aWinSize.Width()/2, aWinSize.Height() / 2);
452 aStartPos = rEdtWin.PixelToLogic(aStartPos);
453 constexpr tools::Long constTwips_2cm = o3tl::toTwips(2, o3tl::Length::cm);
454 constexpr tools::Long constTwips_4cm = o3tl::toTwips(4, o3tl::Length::cm);
455 aStartPos.AdjustX(-constTwips_4cm);
456 aStartPos.AdjustY(-constTwips_2cm);
457 Size aSize(2 * constTwips_4cm, 2 * constTwips_2cm);
458 GetShell().LockPaint(LockPaintReason::InsertFrame);
459 GetShell().StartAllAction();
460 SwFlyFrameAttrMgr aMgr( true, GetShellPtr(), Frmmgr_Type::TEXT, nullptr );
461 if(nCols > 1)
463 SwFormatCol aCol;
464 aCol.Init( nCols, aCol.GetGutterWidth(), aCol.GetWishWidth() );
465 aMgr.SetCol( aCol );
467 aMgr.InsertFlyFrame(RndStdIds::FLY_AT_PARA, aStartPos, aSize);
468 GetShell().EndAllAction();
469 GetShell().UnlockPaint();
471 else
473 GetView().InsFrameMode(nCols);
475 rReq.Ignore();
477 break;
478 case FN_INSERT_FRAME:
480 bool bSingleCol = false;
481 if( nullptr!= dynamic_cast< SwWebDocShell*>( GetView().GetDocShell()) )
483 if( HTML_CFG_MSIE == SvxHtmlOptions::GetExportMode() )
485 bSingleCol = true;
489 // Create new border
490 SwFlyFrameAttrMgr aMgr( true, GetShellPtr(), Frmmgr_Type::TEXT, nullptr );
491 if(pArgs)
493 Size aSize(aMgr.GetSize());
494 aSize.setWidth( GetShell().GetAnyCurRect(CurRectType::PagePrt).Width() );
495 Point aPos = aMgr.GetPos();
496 RndStdIds eAnchor = RndStdIds::FLY_AT_PARA;
497 if(pArgs->GetItemState(nSlot, false, &pItem) == SfxItemState::SET)
498 eAnchor = static_cast<RndStdIds>(static_cast<const SfxUInt16Item *>(pItem)->GetValue());
499 if(pArgs->GetItemState(FN_PARAM_1, false, &pItem) == SfxItemState::SET)
500 aPos = static_cast<const SfxPointItem *>(pItem)->GetValue();
501 if(pArgs->GetItemState(FN_PARAM_2, false, &pItem) == SfxItemState::SET)
502 aSize = static_cast<const SvxSizeItem *>(pItem)->GetSize();
503 if(const SfxUInt16Item* pColsItem = pArgs->GetItemIfSet(SID_ATTR_COLUMNS, false))
505 const sal_uInt16 nCols = pColsItem->GetValue();
506 if( !bSingleCol && 1 < nCols )
508 SwFormatCol aFormatCol;
509 aFormatCol.Init( nCols , (rReq.IsAPI() ? 0
510 : DEF_GUTTER_WIDTH), USHRT_MAX );
511 aMgr.SetCol(aFormatCol);
515 GetShell().LockPaint(LockPaintReason::InsertFrame);
516 GetShell().StartAllAction();
518 aMgr.InsertFlyFrame(eAnchor, aPos, aSize);
520 GetShell().EndAllAction();
521 GetShell().UnlockPaint();
523 else
525 SfxItemSet aSet = CreateInsertFrameItemSet(aMgr);
527 FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebDocShell*>( GetView().GetDocShell()) != nullptr );
528 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)));
529 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
530 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateFrameTabDialog("FrameDialog",
531 GetView().GetViewFrame(),
532 GetView().GetFrameWeld(),
533 aSet));
534 if(pDlg->Execute() == RET_OK && pDlg->GetOutputItemSet())
536 //local variable necessary at least after call of .AutoCaption() because this could be deleted at this point
537 SwWrtShell& rShell = GetShell();
538 rShell.LockPaint(LockPaintReason::InsertFrame);
539 rShell.StartAllAction();
540 rShell.StartUndo(SwUndoId::INSERT);
542 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
543 aMgr.SetAttrSet(*pOutSet);
545 // At first delete the selection at the ClickToEditField.
546 if( rShell.IsInClickToEdit() )
547 rShell.DelRight();
549 aMgr.InsertFlyFrame();
551 uno::Reference< frame::XDispatchRecorder > xRecorder =
552 GetView().GetViewFrame().GetBindings().GetRecorder();
553 if ( xRecorder.is() )
555 //FN_INSERT_FRAME
556 sal_uInt16 nAnchor = static_cast<sal_uInt16>(aMgr.GetAnchor());
557 rReq.AppendItem(SfxUInt16Item(nSlot, nAnchor));
558 rReq.AppendItem(SfxPointItem(FN_PARAM_1, rShell.GetObjAbsPos()));
559 rReq.AppendItem(SvxSizeItem(FN_PARAM_2, rShell.GetObjSize()));
560 rReq.Done();
563 GetView().AutoCaption(FRAME_CAP);
566 SwRewriter aRewriter;
568 aRewriter.AddRule(UndoArg1, SwResId(STR_FRAME));
570 rShell.EndUndo(SwUndoId::INSERT, &aRewriter);
572 rShell.EndAllAction();
573 rShell.UnlockPaint();
576 break;
578 case FN_FORMAT_COLUMN :
580 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
581 VclPtr<VclAbstractDialog> pColDlg(pFact->CreateSwColumnDialog(GetView().GetFrameWeld(), rSh));
582 pColDlg->StartExecuteAsync([=](sal_Int32 /*nResult*/){
583 pColDlg->disposeOnce();
586 break;
588 default:
589 OSL_ENSURE(false, "wrong dispatcher");
590 return;
594 static bool lcl_IsMarkInSameSection( SwWrtShell& rWrtSh, const SwSection* pSect )
596 rWrtSh.SwapPam();
597 bool bRet = pSect == rWrtSh.GetCurrSection();
598 rWrtSh.SwapPam();
599 return bRet;
602 void SwTextShell::StateInsert( SfxItemSet &rSet )
604 const bool bHtmlModeOn = ::GetHtmlMode(GetView().GetDocShell()) & HTMLMODE_ON;
605 SfxWhichIter aIter( rSet );
606 SwWrtShell &rSh = GetShell();
607 sal_uInt16 nWhich = aIter.FirstWhich();
608 SvtModuleOptions aMOpt;
609 SfxObjectCreateMode eCreateMode =
610 GetView().GetDocShell()->GetCreateMode();
611 const bool bCursorInHidden = rSh.IsInHiddenRange(/*bSelect=*/false);
613 while ( nWhich )
615 switch ( nWhich )
617 case SID_INSERT_AVMEDIA:
618 if ( GetShell().IsSelFrameMode()
619 || GetShell().CursorInsideInputField()
620 || SfxObjectCreateMode::EMBEDDED == eCreateMode
621 || bCursorInHidden )
623 rSet.DisableItem( nWhich );
625 break;
627 case SID_INSERT_DIAGRAM:
628 if( !aMOpt.IsChart()
629 || GetShell().CursorInsideInputField()
630 || eCreateMode == SfxObjectCreateMode::EMBEDDED
631 || bCursorInHidden )
633 rSet.DisableItem( nWhich );
635 break;
637 case FN_INSERT_SMA:
638 if( !aMOpt.IsMath()
639 || eCreateMode == SfxObjectCreateMode::EMBEDDED
640 || bCursorInHidden
641 || rSh.CursorInsideInputField() )
643 rSet.DisableItem( nWhich );
645 break;
647 case SID_INSERT_FLOATINGFRAME:
648 case SID_INSERT_OBJECT:
650 if( eCreateMode == SfxObjectCreateMode::EMBEDDED || bCursorInHidden )
652 rSet.DisableItem( nWhich );
654 else if( GetShell().IsSelFrameMode()
655 || GetShell().CursorInsideInputField() )
657 rSet.DisableItem( nWhich );
659 else if(SID_INSERT_FLOATINGFRAME == nWhich && bHtmlModeOn)
661 const sal_uInt16 nExport = SvxHtmlOptions::GetExportMode();
662 if(HTML_CFG_MSIE != nExport && HTML_CFG_WRITER != nExport )
663 rSet.DisableItem(nWhich);
666 break;
668 case FN_INSERT_FRAME_INTERACT_NOCOL :
669 case FN_INSERT_FRAME_INTERACT:
671 if( GetShell().IsSelFrameMode()
672 || rSh.IsTableMode()
673 || GetShell().CursorInsideInputField()
674 || bCursorInHidden )
675 rSet.DisableItem(nWhich);
677 break;
679 case SID_HYPERLINK_GETLINK:
681 SfxItemSetFixed<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT> aSet(GetPool());
682 rSh.GetCurAttr( aSet );
684 SvxHyperlinkItem aHLinkItem;
685 if(const SwFormatINetFormat* pINetFormat = aSet.GetItemIfSet(RES_TXTATR_INETFMT, false))
687 aHLinkItem.SetURL(pINetFormat->GetValue());
688 aHLinkItem.SetTargetFrame(pINetFormat->GetTargetFrame());
689 aHLinkItem.SetIntName(pINetFormat->GetName());
690 const SvxMacro *pMacro = pINetFormat->GetMacro( SvMacroItemId::OnMouseOver );
691 if( pMacro )
692 aHLinkItem.SetMacro(HyperDialogEvent::MouseOverObject, *pMacro);
694 pMacro = pINetFormat->GetMacro( SvMacroItemId::OnClick );
695 if( pMacro )
696 aHLinkItem.SetMacro(HyperDialogEvent::MouseClickObject, *pMacro);
698 pMacro = pINetFormat->GetMacro( SvMacroItemId::OnMouseOut );
699 if( pMacro )
700 aHLinkItem.SetMacro(HyperDialogEvent::MouseOutObject, *pMacro);
702 // Get the text of the Link.
703 rSh.StartAction();
704 const bool bAtEnd(rSh.IsCursorPtAtEnd());
705 if(!bAtEnd) // tdf#91832: ensure forward selection
706 rSh.SwapPam();
707 rSh.CreateCursor();
708 if(!bAtEnd)
709 rSh.SwapPam();
710 rSh.SwCursorShell::SelectTextAttr(RES_TXTATR_INETFMT,true);
711 OUString sLinkName = rSh.GetSelText();
712 aHLinkItem.SetName(sLinkName);
713 aHLinkItem.SetInsertMode(HLINK_FIELD);
714 rSh.DestroyCursor();
715 rSh.EndAction();
717 else
719 OUString sReturn = rSh.GetSelText();
720 sReturn = sReturn.copy(0, std::min<sal_Int32>(255, sReturn.getLength()));
721 aHLinkItem.SetName(comphelper::string::stripEnd(sReturn, ' '));
724 aHLinkItem.SetInsertMode(static_cast<SvxLinkInsertMode>(aHLinkItem.GetInsertMode() |
725 (bHtmlModeOn ? HLINK_HTMLMODE : 0)));
726 aHLinkItem.SetMacroEvents ( HyperDialogEvent::MouseOverObject|
727 HyperDialogEvent::MouseClickObject | HyperDialogEvent::MouseOutObject );
729 rSet.Put(aHLinkItem);
731 break;
733 case FN_INSERT_FRAME:
734 if (rSh.IsSelFrameMode() )
736 const SelectionType nSel = rSh.GetSelectionType();
737 if( ((SelectionType::Graphic | SelectionType::Ole ) & nSel ) || bCursorInHidden )
738 rSet.DisableItem(nWhich);
740 else if ( rSh.CursorInsideInputField() )
742 rSet.DisableItem(nWhich);
744 break;
746 case FN_FORMAT_COLUMN :
748 //#i80458# column dialog cannot work if the selection contains different page styles and different sections
749 bool bDisable = true;
750 if( rSh.GetFlyFrameFormat() || rSh.GetSelectedPageDescs() )
751 bDisable = false;
752 if( bDisable )
754 const SwSection* pCurrSection = rSh.GetCurrSection();
755 const sal_uInt16 nFullSectCnt = rSh.GetFullSelectedSectionCount();
756 if( pCurrSection && ( !rSh.HasSelection() || 0 != nFullSectCnt ))
757 bDisable = false;
758 else if(
759 rSh.HasSelection() && rSh.IsInsRegionAvailable() &&
760 ( !pCurrSection || ( 1 != nFullSectCnt &&
761 lcl_IsMarkInSameSection( rSh, pCurrSection ) )))
762 bDisable = false;
764 if(bDisable)
765 rSet.DisableItem(nWhich);
767 break;
769 nWhich = aIter.NextWhich();
773 void SwTextShell::ExecDelete(SfxRequest &rReq)
775 SwWrtShell &rSh = GetShell();
776 switch( rReq.GetSlot() )
778 case FN_DELETE_SENT:
779 if( rSh.IsTableMode() )
781 rSh.DeleteRow();
782 rSh.EnterStdMode();
784 else
785 rSh.DelToEndOfSentence();
786 break;
787 case FN_DELETE_BACK_SENT:
788 rSh.DelToStartOfSentence();
789 break;
790 case FN_DELETE_WORD:
791 rSh.DelNxtWord();
792 break;
793 case FN_DELETE_BACK_WORD:
794 rSh.DelPrvWord();
795 break;
796 case FN_DELETE_LINE:
797 rSh.DelToEndOfLine();
798 break;
799 case FN_DELETE_BACK_LINE:
800 rSh.DelToStartOfLine();
801 break;
802 case FN_DELETE_PARA:
803 rSh.DelToEndOfPara();
804 break;
805 case FN_DELETE_BACK_PARA:
806 rSh.DelToStartOfPara();
807 break;
808 case FN_DELETE_WHOLE_LINE:
809 rSh.DelLine();
810 break;
811 default:
812 OSL_ENSURE(false, "wrong dispatcher");
813 return;
815 rReq.Done();
818 void SwTextShell::ExecTransliteration( SfxRequest const & rReq )
820 using namespace ::com::sun::star::i18n;
821 TransliterationFlags nMode = TransliterationFlags::NONE;
823 switch( rReq.GetSlot() )
825 case SID_TRANSLITERATE_SENTENCE_CASE:
826 nMode = TransliterationFlags::SENTENCE_CASE;
827 break;
828 case SID_TRANSLITERATE_TITLE_CASE:
829 nMode = TransliterationFlags::TITLE_CASE;
830 break;
831 case SID_TRANSLITERATE_TOGGLE_CASE:
832 nMode = TransliterationFlags::TOGGLE_CASE;
833 break;
834 case SID_TRANSLITERATE_UPPER:
835 nMode = TransliterationFlags::LOWERCASE_UPPERCASE;
836 break;
837 case SID_TRANSLITERATE_LOWER:
838 nMode = TransliterationFlags::UPPERCASE_LOWERCASE;
839 break;
841 case SID_TRANSLITERATE_HALFWIDTH:
842 nMode = TransliterationFlags::FULLWIDTH_HALFWIDTH;
843 break;
844 case SID_TRANSLITERATE_FULLWIDTH:
845 nMode = TransliterationFlags::HALFWIDTH_FULLWIDTH;
846 break;
848 case SID_TRANSLITERATE_HIRAGANA:
849 nMode = TransliterationFlags::KATAKANA_HIRAGANA;
850 break;
851 case SID_TRANSLITERATE_KATAKANA:
852 nMode = TransliterationFlags::HIRAGANA_KATAKANA;
853 break;
855 default:
856 OSL_ENSURE(false, "wrong dispatcher");
859 if( nMode != TransliterationFlags::NONE )
860 GetShell().TransliterateText( nMode );
863 void SwTextShell::ExecRotateTransliteration( SfxRequest const & rReq )
865 if( rReq.GetSlot() == SID_TRANSLITERATE_ROTATE_CASE )
866 GetShell().TransliterateText( m_aRotateCase.getNextMode() );
869 SwTextShell::SwTextShell(SwView &_rView) :
870 SwBaseShell(_rView)
872 SetName("Text");
873 SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Text));
876 SwTextShell::~SwTextShell()
880 SfxItemSet SwTextShell::CreateInsertFrameItemSet(SwFlyFrameAttrMgr& rMgr)
882 SfxItemSet aSet(GetPool(), svl::Items<
883 RES_FRMATR_BEGIN, RES_FRMATR_END-1,
884 XATTR_FILL_FIRST, XATTR_FILL_LAST, // tdf#95003
885 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
886 SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
887 SID_COLOR_TABLE, SID_PATTERN_LIST,
888 SID_HTML_MODE, SID_HTML_MODE,
889 FN_GET_PRINT_AREA, FN_GET_PRINT_AREA,
890 FN_SET_FRM_NAME, FN_SET_FRM_NAME>);
891 aSet.Put(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(GetView().GetDocShell())));
893 // For the Area tab page.
894 GetShell().GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->PutAreaListItems(aSet);
896 const SwRect &rPg = GetShell().GetAnyCurRect(CurRectType::Page);
897 SwFormatFrameSize aFrameSize(SwFrameSize::Variable, rPg.Width(), rPg.Height());
898 aFrameSize.SetWhich(GetPool().GetWhich(SID_ATTR_PAGE_SIZE));
899 aSet.Put(aFrameSize);
901 const SwRect &rPr = GetShell().GetAnyCurRect(CurRectType::PagePrt);
902 SwFormatFrameSize aPrtSize(SwFrameSize::Variable, rPr.Width(), rPr.Height());
903 aPrtSize.SetWhich(GetPool().GetWhich(FN_GET_PRINT_AREA));
904 aSet.Put(aPrtSize);
906 aSet.Put(rMgr.GetAttrSet());
907 aSet.SetParent( rMgr.GetAttrSet().GetParent() );
909 // Delete minimum size in columns.
910 SvxBoxInfoItem aBoxInfo(aSet.Get(SID_ATTR_BORDER_INNER));
911 const SvxBoxItem& rBox = aSet.Get(RES_BOX);
912 aBoxInfo.SetMinDist(false);
913 aBoxInfo.SetDefDist(rBox.GetDistance(SvxBoxItemLine::LEFT));
914 aSet.Put(aBoxInfo);
916 return aSet;
919 void SwTextShell::InsertSymbol( SfxRequest& rReq )
921 const SfxItemSet *pArgs = rReq.GetArgs();
922 const SfxStringItem* pItem = nullptr;
923 if( pArgs )
924 pItem = pArgs->GetItemIfSet(SID_CHARMAP, false);
926 OUString aChars, aFontName;
927 if ( pItem )
929 aChars = pItem->GetValue();
930 const SfxStringItem* pFontItem = pArgs->GetItemIfSet( SID_ATTR_SPECIALCHAR, false );
931 if ( pFontItem )
932 aFontName = pFontItem->GetValue();
935 SwWrtShell &rSh = GetShell();
936 SfxItemSetFixed<RES_CHRATR_FONT, RES_CHRATR_FONT,
937 RES_CHRATR_CJK_FONT, RES_CHRATR_CJK_FONT,
938 RES_CHRATR_CTL_FONT, RES_CHRATR_CTL_FONT> aSet( GetPool() );
939 rSh.GetCurAttr( aSet );
940 SvtScriptType nScript = rSh.GetScriptType();
942 std::shared_ptr<SvxFontItem> aFont(std::make_shared<SvxFontItem>(RES_CHRATR_FONT));
944 SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, *aSet.GetPool() );
945 aSetItem.GetItemSet().Put( aSet, false );
946 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
947 if( pI )
949 aFont.reset(static_cast<SvxFontItem*>(pI->Clone()));
951 else
953 TypedWhichId<SvxFontItem> nFontWhich =
954 GetWhichOfScript(
955 RES_CHRATR_FONT,
956 SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() ) );
957 aFont.reset(aSet.Get(nFontWhich).Clone());
960 if (aFontName.isEmpty())
961 aFontName = aFont->GetFamilyName();
964 vcl::Font aNewFont(aFontName, Size(1,1)); // Size only because CTOR.
965 if( aChars.isEmpty() )
967 // Set selected font as default.
968 SfxAllItemSet aAllSet( rSh.GetAttrPool() );
969 aAllSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
971 SwViewOption aOpt(*GetShell().GetViewOptions());
972 const OUString& sSymbolFont = aOpt.GetSymbolFont();
973 if( aFontName.isEmpty() && !sSymbolFont.isEmpty() )
974 aAllSet.Put( SfxStringItem( SID_FONT_NAME, sSymbolFont ) );
975 else
976 aAllSet.Put( SfxStringItem( SID_FONT_NAME, aFont->GetFamilyName() ) );
978 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
979 auto xFrame = GetView().GetViewFrame().GetFrame().GetFrameInterface();
980 ScopedVclPtr<SfxAbstractDialog> pDlg(pFact->CreateCharMapDialog(GetView().GetFrameWeld(), aAllSet, xFrame));
981 pDlg->Execute();
982 return;
985 if( aChars.isEmpty() )
986 return;
988 rSh.StartAllAction();
990 // Delete selected content.
991 SwRewriter aRewriter;
992 aRewriter.AddRule(UndoArg1, SwResId(STR_SPECIALCHAR));
994 rSh.StartUndo( SwUndoId::INSERT, &aRewriter );
995 if ( rSh.HasSelection() )
997 rSh.DelRight();
998 aSet.ClearItem();
999 rSh.GetCurAttr( aSet );
1001 SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, *aSet.GetPool() );
1002 aSetItem.GetItemSet().Put( aSet, false );
1003 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
1004 if( pI )
1006 aFont.reset(static_cast<SvxFontItem*>(pI->Clone()));
1008 else
1010 TypedWhichId<SvxFontItem> nFontWhich =
1011 GetWhichOfScript(
1012 RES_CHRATR_FONT,
1013 SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() ) );
1014 aFont.reset(aSet.Get( nFontWhich ).Clone());
1018 // Insert character.
1019 rSh.Insert( aChars );
1021 // #108876# a font attribute has to be set always due to a guessed script type
1022 if( !aNewFont.GetFamilyName().isEmpty() )
1024 std::unique_ptr<SvxFontItem> aNewFontItem(aFont->Clone());
1025 aNewFontItem->SetFamilyName( aNewFont.GetFamilyName() );
1026 aNewFontItem->SetFamily( aNewFont.GetFamilyType());
1027 aNewFontItem->SetPitch( aNewFont.GetPitch());
1028 aNewFontItem->SetCharSet( aNewFont.GetCharSet() );
1030 SfxItemSetFixed<RES_CHRATR_FONT, RES_CHRATR_FONT,
1031 RES_CHRATR_CJK_FONT, RES_CHRATR_CJK_FONT,
1032 RES_CHRATR_CTL_FONT, RES_CHRATR_CTL_FONT> aRestoreSet( GetPool() );
1034 nScript = g_pBreakIt->GetAllScriptsOfText( aChars );
1035 if( SvtScriptType::LATIN & nScript )
1037 aRestoreSet.Put( aSet.Get( RES_CHRATR_FONT ) );
1038 aNewFontItem->SetWhich(RES_CHRATR_FONT);
1039 aSet.Put( *aNewFontItem );
1041 if( SvtScriptType::ASIAN & nScript )
1043 aRestoreSet.Put( aSet.Get( RES_CHRATR_CJK_FONT ) );
1044 aNewFontItem->SetWhich(RES_CHRATR_CJK_FONT);
1045 aSet.Put( *aNewFontItem );
1047 if( SvtScriptType::COMPLEX & nScript )
1049 aRestoreSet.Put( aSet.Get( RES_CHRATR_CTL_FONT ) );
1050 aNewFontItem->SetWhich(RES_CHRATR_CTL_FONT);
1051 aSet.Put( *aNewFontItem );
1054 rSh.SetMark();
1055 rSh.ExtendSelection( false, aChars.getLength() );
1056 rSh.SetAttrSet( aSet, SetAttrMode::DONTEXPAND | SetAttrMode::NOFORMATATTR );
1057 if( !rSh.IsCursorPtAtEnd() )
1058 rSh.SwapPam();
1060 rSh.ClearMark();
1062 // #i75891#
1063 // SETATTR_DONTEXPAND does not work if there are already hard attributes.
1064 // Therefore we have to restore the font attributes.
1065 rSh.SetMark();
1066 rSh.SetAttrSet( aRestoreSet );
1067 rSh.ClearMark();
1069 rSh.UpdateAttr();
1071 // Why was this done? aFont is not used anymore below, we are not
1072 // in a loop and it's a local variable...?
1073 // aFont = aNewFontItem;
1076 rSh.EndAllAction();
1077 rSh.EndUndo();
1079 if ( !aChars.isEmpty() )
1081 rReq.AppendItem( SfxStringItem( SID_CHARMAP, aChars ) );
1082 rReq.AppendItem( SfxStringItem( SID_ATTR_SPECIALCHAR, aNewFont.GetFamilyName() ) );
1083 rReq.Done();
1087 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */