sw content controls, combo box: add insert UI
[LibreOffice.git] / sw / source / uibase / shells / textsh.cxx
blobaf047adc2d198fdfa0fbe39b311d593a9b6c61e5
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 SwView* pView = ::GetActiveView();
101 SwWrtShell& rWrtShell = pView->GetWrtShell();
103 sal_Int16 nDialogRet = pEvent->DialogResult;
104 if( nDialogRet == ui::dialogs::ExecutableDialogResults::CANCEL )
106 rWrtShell.Undo();
107 rWrtShell.GetIDocumentUndoRedo().ClearRedo();
109 else
111 OSL_ENSURE( nDialogRet == ui::dialogs::ExecutableDialogResults::OK,
112 "dialog execution failed" );
116 void SwTextShell::InitInterface_Impl()
118 GetStaticInterface()->RegisterPopupMenu("text");
120 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Text_Toolbox_Sw);
122 GetStaticInterface()->RegisterChildWindow(FN_EDIT_FORMULA);
123 GetStaticInterface()->RegisterChildWindow(FN_INSERT_FIELD);
124 GetStaticInterface()->RegisterChildWindow(FN_INSERT_IDX_ENTRY_DLG);
125 GetStaticInterface()->RegisterChildWindow(FN_INSERT_AUTH_ENTRY_DLG);
126 GetStaticInterface()->RegisterChildWindow(SID_RUBY_DIALOG);
127 GetStaticInterface()->RegisterChildWindow(FN_WORDCOUNT_DIALOG);
131 void SwTextShell::ExecInsert(SfxRequest &rReq)
133 SwWrtShell &rSh = GetShell();
135 OSL_ENSURE( !rSh.IsObjSelected() && !rSh.IsFrameSelected(),
136 "wrong shell on dispatcher" );
138 const SfxItemSet *pArgs = rReq.GetArgs();
139 const SfxPoolItem* pItem = nullptr;
140 const sal_uInt16 nSlot = rReq.GetSlot();
141 if(pArgs)
142 pArgs->GetItemState(nSlot, false, &pItem );
144 switch( nSlot )
146 case FN_INSERT_STRING:
147 if( pItem )
148 rSh.InsertByWord(static_cast<const SfxStringItem *>(pItem)->GetValue());
149 break;
151 case FN_INSERT_SOFT_HYPHEN:
152 if( CHAR_SOFTHYPHEN != rSh.SwCursorShell::GetChar() &&
153 CHAR_SOFTHYPHEN != rSh.SwCursorShell::GetChar( true, -1 ))
154 rSh.Insert( OUString( CHAR_SOFTHYPHEN ) );
155 break;
157 case FN_INSERT_HARDHYPHEN:
158 case FN_INSERT_HARD_SPACE:
160 const sal_Unicode cIns = FN_INSERT_HARD_SPACE == nSlot ? CHAR_HARDBLANK : CHAR_HARDHYPHEN;
162 SvxAutoCorrCfg& rACfg = SvxAutoCorrCfg::Get();
163 SvxAutoCorrect* pACorr = rACfg.GetAutoCorrect();
164 if( pACorr && rACfg.IsAutoFormatByInput()
165 && pACorr->IsAutoCorrFlag(
166 ACFlags::CapitalStartSentence | ACFlags::CapitalStartWord |
167 ACFlags::AddNonBrkSpace | ACFlags::ChgOrdinalNumber | ACFlags::TransliterateRTL |
168 ACFlags::ChgToEnEmDash | ACFlags::SetINetAttr | ACFlags::Autocorrect ) )
170 rSh.AutoCorrect( *pACorr, cIns );
172 else
174 rSh.Insert( OUString( cIns ) );
177 break;
179 case FN_INSERT_NNBSP: // shift+mod2/alt+space inserts some other character w/o going through SwEditWin::KeyInput(), at least on macOS
180 case SID_INSERT_RLM :
181 case SID_INSERT_LRM :
182 case SID_INSERT_WJ :
183 case SID_INSERT_ZWSP:
185 sal_Unicode cIns = 0;
186 switch(nSlot)
188 case SID_INSERT_RLM : cIns = CHAR_RLM ; break;
189 case SID_INSERT_LRM : cIns = CHAR_LRM ; break;
190 case SID_INSERT_ZWSP : cIns = CHAR_ZWSP ; break;
191 case SID_INSERT_WJ: cIns = CHAR_WJ; break;
192 case FN_INSERT_NNBSP: cIns = CHAR_NNBSP; break;
194 rSh.Insert( OUString( cIns ) );
196 break;
198 case FN_INSERT_BREAK:
200 if (!rSh.CursorInsideInputField() && !rSh.CursorInsideContentControl())
202 rSh.SplitNode();
204 else
206 rSh.InsertLineBreak();
209 rReq.Done();
210 break;
212 case FN_INSERT_PAGEBREAK:
213 rSh.InsertPageBreak();
214 rReq.Done();
215 break;
217 case FN_INSERT_LINEBREAK:
218 rSh.InsertLineBreak();
219 rReq.Done();
220 break;
222 case FN_INSERT_CONTENT_CONTROL:
223 rSh.InsertContentControl(SwContentControlType::RICH_TEXT);
224 rReq.Done();
225 break;
227 case FN_INSERT_CHECKBOX_CONTENT_CONTROL:
228 rSh.InsertContentControl(SwContentControlType::CHECKBOX);
229 rReq.Done();
230 break;
232 case FN_INSERT_DROPDOWN_CONTENT_CONTROL:
233 rSh.InsertContentControl(SwContentControlType::DROP_DOWN_LIST);
234 rReq.Done();
235 break;
237 case FN_INSERT_PICTURE_CONTENT_CONTROL:
238 rSh.InsertContentControl(SwContentControlType::PICTURE);
239 rReq.Done();
240 break;
242 case FN_INSERT_DATE_CONTENT_CONTROL:
243 rSh.InsertContentControl(SwContentControlType::DATE);
244 rReq.Done();
245 break;
247 case FN_INSERT_PLAIN_TEXT_CONTENT_CONTROL:
248 rSh.InsertContentControl(SwContentControlType::PLAIN_TEXT);
249 rReq.Done();
250 break;
252 case FN_INSERT_COMBO_BOX_CONTENT_CONTROL:
253 rSh.InsertContentControl(SwContentControlType::COMBO_BOX);
254 rReq.Done();
255 break;
257 case FN_CONTENT_CONTROL_PROPERTIES:
259 SwWrtShell& rWrtSh = GetShell();
260 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
261 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSwContentControlDlg(GetView().GetFrameWeld(), rWrtSh));
262 VclAbstractDialog::AsyncContext aContext;
263 aContext.maEndDialogFn = [](sal_Int32){};
264 pDlg->StartExecuteAsync(aContext);
265 rReq.Done();
266 break;
269 case FN_INSERT_COLUMN_BREAK:
270 rSh.InsertColumnBreak();
271 rReq.Done();
272 break;
274 case SID_HYPERLINK_SETLINK:
275 if (pItem)
276 InsertHyperlink(*static_cast<const SvxHyperlinkItem *>(pItem));
277 rReq.Done();
278 break;
280 #if HAVE_FEATURE_AVMEDIA
281 case SID_INSERT_AVMEDIA:
282 rReq.SetReturnValue(SfxBoolItem(nSlot, InsertMediaDlg( rReq )));
283 break;
284 #endif
286 case SID_INSERT_OBJECT:
288 const SfxGlobalNameItem* pNameItem = rReq.GetArg<SfxGlobalNameItem>(SID_INSERT_OBJECT);
289 SvGlobalName *pName = nullptr;
290 SvGlobalName aName;
291 if ( pNameItem )
293 aName = pNameItem->GetValue();
294 pName = &aName;
297 svt::EmbeddedObjectRef xObj;
298 rSh.InsertObject( xObj, pName, nSlot);
299 rReq.Done();
300 break;
302 case SID_INSERT_FLOATINGFRAME:
304 svt::EmbeddedObjectRef xObj;
305 const SfxStringItem* pNameItem = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
306 const SfxStringItem* pURLItem = rReq.GetArg<SfxStringItem>(FN_PARAM_2);
307 const SvxSizeItem* pMarginItem = rReq.GetArg<SvxSizeItem>(FN_PARAM_3);
308 const SfxByteItem* pScrollingItem = rReq.GetArg<SfxByteItem>(FN_PARAM_4);
309 const SfxBoolItem* pBorderItem = rReq.GetArg<SfxBoolItem>(FN_PARAM_5);
311 if(pURLItem) // URL is a _must_
313 comphelper::EmbeddedObjectContainer aCnt;
314 OUString aName;
315 xObj.Assign( aCnt.CreateEmbeddedObject( SvGlobalName( SO3_IFRAME_CLASSID ).GetByteSequence(), aName ),
316 embed::Aspects::MSOLE_CONTENT );
317 svt::EmbeddedObjectRef::TryRunningState( xObj.GetObject() );
318 uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY );
319 if ( xSet.is() )
323 ScrollingMode eScroll = ScrollingMode::Auto;
324 if( pScrollingItem && pScrollingItem->GetValue() <= int(ScrollingMode::Auto) )
325 eScroll = static_cast<ScrollingMode>(pScrollingItem->GetValue());
327 Size aMargin;
328 if ( pMarginItem )
329 aMargin = pMarginItem->GetSize();
331 xSet->setPropertyValue("FrameURL", uno::Any( pURLItem->GetValue() ) );
332 if ( pNameItem )
333 xSet->setPropertyValue("FrameName", uno::Any( pNameItem->GetValue() ) );
335 if ( eScroll == ScrollingMode::Auto )
336 xSet->setPropertyValue("FrameIsAutoScroll",
337 uno::Any( true ) );
338 else
339 xSet->setPropertyValue("FrameIsScrollingMode",
340 uno::Any( eScroll == ScrollingMode::Yes ) );
342 if ( pBorderItem )
343 xSet->setPropertyValue("FrameIsBorder",
344 uno::Any( pBorderItem->GetValue() ) );
346 if ( pMarginItem )
348 xSet->setPropertyValue("FrameMarginWidth",
349 uno::Any( sal_Int32( aMargin.Width() ) ) );
351 xSet->setPropertyValue("FrameMarginHeight",
352 uno::Any( sal_Int32( aMargin.Height() ) ) );
355 catch (const uno::Exception&)
360 rSh.InsertOleObject( xObj );
362 else
364 rSh.InsertObject( xObj, nullptr, nSlot);
365 rReq.Done();
368 break;
369 case SID_INSERT_DIAGRAM:
371 SvtModuleOptions aMOpt;
372 if ( !aMOpt.IsChart() )
373 break;
374 if(!rReq.IsAPI())
376 SwInsertChart( LINK( this, SwTextShell, DialogClosedHdl ) );
378 else
380 uno::Reference< chart2::data::XDataProvider > xDataProvider;
381 bool bFillWithData = true;
382 OUString aRangeString;
383 if (!GetShell().IsTableComplexForChart())
385 SwFrameFormat* pTableFormat = GetShell().GetTableFormat();
386 aRangeString = pTableFormat->GetName() + "."
387 + GetShell().GetBoxNms();
389 // get table data provider
390 xDataProvider.set( GetView().GetDocShell()->getIDocumentChartDataProviderAccess().GetChartDataProvider() );
392 else
393 bFillWithData = false; // will create chart with only it's default image
395 SwTableFUNC( &rSh ).InsertChart( xDataProvider, bFillWithData, aRangeString );
396 rSh.LaunchOLEObj();
398 svt::EmbeddedObjectRef& xObj = rSh.GetOLEObject();
399 if(pItem && xObj.is())
401 Size aSize(static_cast<const SvxSizeItem*>(pItem)->GetSize());
402 aSize = o3tl::convert(aSize, o3tl::Length::twip, o3tl::Length::mm100);
404 if(aSize.Width() > MINLAY&& aSize.Height()> MINLAY)
406 awt::Size aSz;
407 aSz.Width = aSize.Width();
408 aSz.Height = aSize.Height();
409 xObj->setVisualAreaSize( xObj.GetViewAspect(), aSz );
414 break;
416 case FN_INSERT_SMA:
418 // #i34343# Inserting a math object into an autocompletion crashes
419 // the suggestion has to be removed before
420 GetView().GetEditWin().StopQuickHelp();
421 SvGlobalName aGlobalName( SO3_SM_CLASSID );
422 rSh.InsertObject( svt::EmbeddedObjectRef(), &aGlobalName );
424 break;
426 case FN_INSERT_TABLE:
427 InsertTable( rReq );
428 break;
430 case FN_INSERT_FRAME_INTERACT_NOCOL:
431 case FN_INSERT_FRAME_INTERACT:
433 sal_uInt16 nCols = 1;
434 bool bModifier1 = rReq.GetModifier() == KEY_MOD1;
435 if(pArgs)
437 const SfxUInt16Item* pColsItem = nullptr;
438 if(FN_INSERT_FRAME_INTERACT_NOCOL != nSlot &&
439 (pColsItem = pArgs->GetItemIfSet(SID_ATTR_COLUMNS, false)))
440 nCols = pColsItem->GetValue();
441 if(const SfxUInt16Item* pModifierItem = pArgs->GetItemIfSet(SID_MODIFIER, false))
442 bModifier1 |= KEY_MOD1 == pModifierItem->GetValue();
444 if(bModifier1 )
446 SwEditWin& rEdtWin = GetView().GetEditWin();
447 Size aWinSize = rEdtWin.GetSizePixel();
448 Point aStartPos(aWinSize.Width()/2, aWinSize.Height() / 2);
449 aStartPos = rEdtWin.PixelToLogic(aStartPos);
450 constexpr tools::Long constTwips_2cm = o3tl::toTwips(2, o3tl::Length::cm);
451 constexpr tools::Long constTwips_4cm = o3tl::toTwips(4, o3tl::Length::cm);
452 aStartPos.AdjustX(-constTwips_4cm);
453 aStartPos.AdjustY(-constTwips_2cm);
454 Size aSize(2 * constTwips_4cm, 2 * constTwips_2cm);
455 GetShell().LockPaint();
456 GetShell().StartAllAction();
457 SwFlyFrameAttrMgr aMgr( true, GetShellPtr(), Frmmgr_Type::TEXT, nullptr );
458 if(nCols > 1)
460 SwFormatCol aCol;
461 aCol.Init( nCols, aCol.GetGutterWidth(), aCol.GetWishWidth() );
462 aMgr.SetCol( aCol );
464 aMgr.InsertFlyFrame(RndStdIds::FLY_AT_PARA, aStartPos, aSize);
465 GetShell().EndAllAction();
466 GetShell().UnlockPaint();
468 else
470 GetView().InsFrameMode(nCols);
472 rReq.Ignore();
474 break;
475 case FN_INSERT_FRAME:
477 bool bSingleCol = false;
478 if( nullptr!= dynamic_cast< SwWebDocShell*>( GetView().GetDocShell()) )
480 if( HTML_CFG_MSIE == SvxHtmlOptions::GetExportMode() )
482 bSingleCol = true;
486 // Create new border
487 SwFlyFrameAttrMgr aMgr( true, GetShellPtr(), Frmmgr_Type::TEXT, nullptr );
488 if(pArgs)
490 Size aSize(aMgr.GetSize());
491 aSize.setWidth( GetShell().GetAnyCurRect(CurRectType::PagePrt).Width() );
492 Point aPos = aMgr.GetPos();
493 RndStdIds eAnchor = RndStdIds::FLY_AT_PARA;
494 if(pArgs->GetItemState(nSlot, false, &pItem) == SfxItemState::SET)
495 eAnchor = static_cast<RndStdIds>(static_cast<const SfxUInt16Item *>(pItem)->GetValue());
496 if(pArgs->GetItemState(FN_PARAM_1, false, &pItem) == SfxItemState::SET)
497 aPos = static_cast<const SfxPointItem *>(pItem)->GetValue();
498 if(pArgs->GetItemState(FN_PARAM_2, false, &pItem) == SfxItemState::SET)
499 aSize = static_cast<const SvxSizeItem *>(pItem)->GetSize();
500 if(const SfxUInt16Item* pColsItem = pArgs->GetItemIfSet(SID_ATTR_COLUMNS, false))
502 const sal_uInt16 nCols = pColsItem->GetValue();
503 if( !bSingleCol && 1 < nCols )
505 SwFormatCol aFormatCol;
506 aFormatCol.Init( nCols , (rReq.IsAPI() ? 0
507 : DEF_GUTTER_WIDTH), USHRT_MAX );
508 aMgr.SetCol(aFormatCol);
512 GetShell().LockPaint();
513 GetShell().StartAllAction();
515 aMgr.InsertFlyFrame(eAnchor, aPos, aSize);
517 GetShell().EndAllAction();
518 GetShell().UnlockPaint();
520 else
522 SfxItemSet aSet = CreateInsertFrameItemSet(aMgr);
524 FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebDocShell*>( GetView().GetDocShell()) != nullptr );
525 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)));
526 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
527 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateFrameTabDialog("FrameDialog",
528 GetView().GetViewFrame(),
529 GetView().GetFrameWeld(),
530 aSet));
531 if(pDlg->Execute() == RET_OK && pDlg->GetOutputItemSet())
533 //local variable necessary at least after call of .AutoCaption() because this could be deleted at this point
534 SwWrtShell& rShell = GetShell();
535 rShell.LockPaint();
536 rShell.StartAllAction();
537 rShell.StartUndo(SwUndoId::INSERT);
539 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
540 aMgr.SetAttrSet(*pOutSet);
542 // At first delete the selection at the ClickToEditField.
543 if( rShell.IsInClickToEdit() )
544 rShell.DelRight();
546 aMgr.InsertFlyFrame();
548 uno::Reference< frame::XDispatchRecorder > xRecorder =
549 GetView().GetViewFrame()->GetBindings().GetRecorder();
550 if ( xRecorder.is() )
552 //FN_INSERT_FRAME
553 sal_uInt16 nAnchor = static_cast<sal_uInt16>(aMgr.GetAnchor());
554 rReq.AppendItem(SfxUInt16Item(nSlot, nAnchor));
555 rReq.AppendItem(SfxPointItem(FN_PARAM_1, rShell.GetObjAbsPos()));
556 rReq.AppendItem(SvxSizeItem(FN_PARAM_2, rShell.GetObjSize()));
557 rReq.Done();
560 GetView().AutoCaption(FRAME_CAP);
563 SwRewriter aRewriter;
565 aRewriter.AddRule(UndoArg1, SwResId(STR_FRAME));
567 rShell.EndUndo(SwUndoId::INSERT, &aRewriter);
569 rShell.EndAllAction();
570 rShell.UnlockPaint();
573 break;
575 case FN_FORMAT_COLUMN :
577 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
578 VclPtr<VclAbstractDialog> pColDlg(pFact->CreateSwColumnDialog(GetView().GetFrameWeld(), rSh));
579 pColDlg->StartExecuteAsync([=](sal_Int32 /*nResult*/){
580 pColDlg->disposeOnce();
583 break;
585 default:
586 OSL_ENSURE(false, "wrong dispatcher");
587 return;
591 static bool lcl_IsMarkInSameSection( SwWrtShell& rWrtSh, const SwSection* pSect )
593 rWrtSh.SwapPam();
594 bool bRet = pSect == rWrtSh.GetCurrSection();
595 rWrtSh.SwapPam();
596 return bRet;
599 void SwTextShell::StateInsert( SfxItemSet &rSet )
601 const bool bHtmlModeOn = ::GetHtmlMode(GetView().GetDocShell()) & HTMLMODE_ON;
602 SfxWhichIter aIter( rSet );
603 SwWrtShell &rSh = GetShell();
604 sal_uInt16 nWhich = aIter.FirstWhich();
605 SvtModuleOptions aMOpt;
606 SfxObjectCreateMode eCreateMode =
607 GetView().GetDocShell()->GetCreateMode();
609 bool bCursorInHidden = false;
610 if( !rSh.HasMark() )
612 rSh.Push();
613 bCursorInHidden = rSh.SelectHiddenRange();
614 rSh.Pop();
617 while ( nWhich )
619 switch ( nWhich )
621 case SID_INSERT_AVMEDIA:
622 if ( GetShell().IsSelFrameMode()
623 || GetShell().CursorInsideInputField()
624 || SfxObjectCreateMode::EMBEDDED == eCreateMode
625 || bCursorInHidden )
627 rSet.DisableItem( nWhich );
629 break;
631 case SID_INSERT_DIAGRAM:
632 if( !aMOpt.IsChart()
633 || GetShell().CursorInsideInputField()
634 || eCreateMode == SfxObjectCreateMode::EMBEDDED
635 || bCursorInHidden )
637 rSet.DisableItem( nWhich );
639 break;
641 case FN_INSERT_SMA:
642 if( !aMOpt.IsMath()
643 || eCreateMode == SfxObjectCreateMode::EMBEDDED
644 || bCursorInHidden
645 || rSh.CursorInsideInputField() )
647 rSet.DisableItem( nWhich );
649 break;
651 case SID_INSERT_FLOATINGFRAME:
652 case SID_INSERT_OBJECT:
654 if( eCreateMode == SfxObjectCreateMode::EMBEDDED || bCursorInHidden )
656 rSet.DisableItem( nWhich );
658 else if( GetShell().IsSelFrameMode()
659 || GetShell().CursorInsideInputField() )
661 rSet.DisableItem( nWhich );
663 else if(SID_INSERT_FLOATINGFRAME == nWhich && bHtmlModeOn)
665 const sal_uInt16 nExport = SvxHtmlOptions::GetExportMode();
666 if(HTML_CFG_MSIE != nExport && HTML_CFG_WRITER != nExport )
667 rSet.DisableItem(nWhich);
670 break;
672 case FN_INSERT_FRAME_INTERACT_NOCOL :
673 case FN_INSERT_FRAME_INTERACT:
675 if( GetShell().IsSelFrameMode()
676 || rSh.IsTableMode()
677 || GetShell().CursorInsideInputField()
678 || bCursorInHidden )
679 rSet.DisableItem(nWhich);
681 break;
683 case SID_HYPERLINK_GETLINK:
685 SfxItemSetFixed<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT> aSet(GetPool());
686 rSh.GetCurAttr( aSet );
688 SvxHyperlinkItem aHLinkItem;
689 if(const SwFormatINetFormat* pINetFormat = aSet.GetItemIfSet(RES_TXTATR_INETFMT, false))
691 aHLinkItem.SetURL(pINetFormat->GetValue());
692 aHLinkItem.SetTargetFrame(pINetFormat->GetTargetFrame());
693 aHLinkItem.SetIntName(pINetFormat->GetName());
694 const SvxMacro *pMacro = pINetFormat->GetMacro( SvMacroItemId::OnMouseOver );
695 if( pMacro )
696 aHLinkItem.SetMacro(HyperDialogEvent::MouseOverObject, *pMacro);
698 pMacro = pINetFormat->GetMacro( SvMacroItemId::OnClick );
699 if( pMacro )
700 aHLinkItem.SetMacro(HyperDialogEvent::MouseClickObject, *pMacro);
702 pMacro = pINetFormat->GetMacro( SvMacroItemId::OnMouseOut );
703 if( pMacro )
704 aHLinkItem.SetMacro(HyperDialogEvent::MouseOutObject, *pMacro);
706 // Get the text of the Link.
707 rSh.StartAction();
708 const bool bAtEnd(rSh.IsCursorPtAtEnd());
709 if(!bAtEnd) // tdf#91832: ensure forward selection
710 rSh.SwapPam();
711 rSh.CreateCursor();
712 if(!bAtEnd)
713 rSh.SwapPam();
714 rSh.SwCursorShell::SelectTextAttr(RES_TXTATR_INETFMT,true);
715 OUString sLinkName = rSh.GetSelText();
716 aHLinkItem.SetName(sLinkName);
717 aHLinkItem.SetInsertMode(HLINK_FIELD);
718 rSh.DestroyCursor();
719 rSh.EndAction();
721 else
723 OUString sReturn = rSh.GetSelText();
724 sReturn = sReturn.copy(0, std::min<sal_Int32>(255, sReturn.getLength()));
725 aHLinkItem.SetName(comphelper::string::stripEnd(sReturn, ' '));
728 aHLinkItem.SetInsertMode(static_cast<SvxLinkInsertMode>(aHLinkItem.GetInsertMode() |
729 (bHtmlModeOn ? HLINK_HTMLMODE : 0)));
730 aHLinkItem.SetMacroEvents ( HyperDialogEvent::MouseOverObject|
731 HyperDialogEvent::MouseClickObject | HyperDialogEvent::MouseOutObject );
733 rSet.Put(aHLinkItem);
735 break;
737 case FN_INSERT_FRAME:
738 if (rSh.IsSelFrameMode() )
740 const SelectionType nSel = rSh.GetSelectionType();
741 if( ((SelectionType::Graphic | SelectionType::Ole ) & nSel ) || bCursorInHidden )
742 rSet.DisableItem(nWhich);
744 else if ( rSh.CursorInsideInputField() )
746 rSet.DisableItem(nWhich);
748 break;
750 case FN_FORMAT_COLUMN :
752 //#i80458# column dialog cannot work if the selection contains different page styles and different sections
753 bool bDisable = true;
754 if( rSh.GetFlyFrameFormat() || rSh.GetSelectedPageDescs() )
755 bDisable = false;
756 if( bDisable )
758 const SwSection* pCurrSection = rSh.GetCurrSection();
759 const sal_uInt16 nFullSectCnt = rSh.GetFullSelectedSectionCount();
760 if( pCurrSection && ( !rSh.HasSelection() || 0 != nFullSectCnt ))
761 bDisable = false;
762 else if(
763 rSh.HasSelection() && rSh.IsInsRegionAvailable() &&
764 ( !pCurrSection || ( 1 != nFullSectCnt &&
765 lcl_IsMarkInSameSection( rSh, pCurrSection ) )))
766 bDisable = false;
768 if(bDisable)
769 rSet.DisableItem(nWhich);
771 break;
773 nWhich = aIter.NextWhich();
777 void SwTextShell::ExecDelete(SfxRequest &rReq)
779 SwWrtShell &rSh = GetShell();
780 switch( rReq.GetSlot() )
782 case FN_DELETE_SENT:
783 if( rSh.IsTableMode() )
785 rSh.DeleteRow();
786 rSh.EnterStdMode();
788 else
789 rSh.DelToEndOfSentence();
790 break;
791 case FN_DELETE_BACK_SENT:
792 rSh.DelToStartOfSentence();
793 break;
794 case FN_DELETE_WORD:
795 rSh.DelNxtWord();
796 break;
797 case FN_DELETE_BACK_WORD:
798 rSh.DelPrvWord();
799 break;
800 case FN_DELETE_LINE:
801 rSh.DelToEndOfLine();
802 break;
803 case FN_DELETE_BACK_LINE:
804 rSh.DelToStartOfLine();
805 break;
806 case FN_DELETE_PARA:
807 rSh.DelToEndOfPara();
808 break;
809 case FN_DELETE_BACK_PARA:
810 rSh.DelToStartOfPara();
811 break;
812 case FN_DELETE_WHOLE_LINE:
813 rSh.DelLine();
814 break;
815 default:
816 OSL_ENSURE(false, "wrong dispatcher");
817 return;
819 rReq.Done();
822 void SwTextShell::ExecTransliteration( SfxRequest const & rReq )
824 using namespace ::com::sun::star::i18n;
825 TransliterationFlags nMode = TransliterationFlags::NONE;
827 switch( rReq.GetSlot() )
829 case SID_TRANSLITERATE_SENTENCE_CASE:
830 nMode = TransliterationFlags::SENTENCE_CASE;
831 break;
832 case SID_TRANSLITERATE_TITLE_CASE:
833 nMode = TransliterationFlags::TITLE_CASE;
834 break;
835 case SID_TRANSLITERATE_TOGGLE_CASE:
836 nMode = TransliterationFlags::TOGGLE_CASE;
837 break;
838 case SID_TRANSLITERATE_UPPER:
839 nMode = TransliterationFlags::LOWERCASE_UPPERCASE;
840 break;
841 case SID_TRANSLITERATE_LOWER:
842 nMode = TransliterationFlags::UPPERCASE_LOWERCASE;
843 break;
845 case SID_TRANSLITERATE_HALFWIDTH:
846 nMode = TransliterationFlags::FULLWIDTH_HALFWIDTH;
847 break;
848 case SID_TRANSLITERATE_FULLWIDTH:
849 nMode = TransliterationFlags::HALFWIDTH_FULLWIDTH;
850 break;
852 case SID_TRANSLITERATE_HIRAGANA:
853 nMode = TransliterationFlags::KATAKANA_HIRAGANA;
854 break;
855 case SID_TRANSLITERATE_KATAKANA:
856 nMode = TransliterationFlags::HIRAGANA_KATAKANA;
857 break;
859 default:
860 OSL_ENSURE(false, "wrong dispatcher");
863 if( nMode != TransliterationFlags::NONE )
864 GetShell().TransliterateText( nMode );
867 void SwTextShell::ExecRotateTransliteration( SfxRequest const & rReq )
869 if( rReq.GetSlot() == SID_TRANSLITERATE_ROTATE_CASE )
870 GetShell().TransliterateText( m_aRotateCase.getNextMode() );
873 SwTextShell::SwTextShell(SwView &_rView) :
874 SwBaseShell(_rView)
876 SetName("Text");
877 SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Text));
880 SwTextShell::~SwTextShell()
884 SfxItemSet SwTextShell::CreateInsertFrameItemSet(SwFlyFrameAttrMgr& rMgr)
886 SfxItemSet aSet(GetPool(), svl::Items<
887 RES_FRMATR_BEGIN, RES_FRMATR_END-1,
888 XATTR_FILL_FIRST, XATTR_FILL_LAST, // tdf#95003
889 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
890 SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
891 SID_COLOR_TABLE, SID_PATTERN_LIST,
892 SID_HTML_MODE, SID_HTML_MODE,
893 FN_GET_PRINT_AREA, FN_GET_PRINT_AREA,
894 FN_SET_FRM_NAME, FN_SET_FRM_NAME>);
895 aSet.Put(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(GetView().GetDocShell())));
897 // For the Area tab page.
898 GetShell().GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->PutAreaListItems(aSet);
900 const SwRect &rPg = GetShell().GetAnyCurRect(CurRectType::Page);
901 SwFormatFrameSize aFrameSize(SwFrameSize::Variable, rPg.Width(), rPg.Height());
902 aFrameSize.SetWhich(GetPool().GetWhich(SID_ATTR_PAGE_SIZE));
903 aSet.Put(aFrameSize);
905 const SwRect &rPr = GetShell().GetAnyCurRect(CurRectType::PagePrt);
906 SwFormatFrameSize aPrtSize(SwFrameSize::Variable, rPr.Width(), rPr.Height());
907 aPrtSize.SetWhich(GetPool().GetWhich(FN_GET_PRINT_AREA));
908 aSet.Put(aPrtSize);
910 aSet.Put(rMgr.GetAttrSet());
911 aSet.SetParent( rMgr.GetAttrSet().GetParent() );
913 // Delete minimum size in columns.
914 SvxBoxInfoItem aBoxInfo(aSet.Get(SID_ATTR_BORDER_INNER));
915 const SvxBoxItem& rBox = aSet.Get(RES_BOX);
916 aBoxInfo.SetMinDist(false);
917 aBoxInfo.SetDefDist(rBox.GetDistance(SvxBoxItemLine::LEFT));
918 aSet.Put(aBoxInfo);
920 return aSet;
923 void SwTextShell::InsertSymbol( SfxRequest& rReq )
925 const SfxItemSet *pArgs = rReq.GetArgs();
926 const SfxStringItem* pItem = nullptr;
927 if( pArgs )
928 pItem = pArgs->GetItemIfSet(SID_CHARMAP, false);
930 OUString aChars, aFontName;
931 if ( pItem )
933 aChars = pItem->GetValue();
934 const SfxStringItem* pFontItem = pArgs->GetItemIfSet( SID_ATTR_SPECIALCHAR, false );
935 if ( pFontItem )
936 aFontName = pFontItem->GetValue();
939 SwWrtShell &rSh = GetShell();
940 SfxItemSetFixed<RES_CHRATR_FONT, RES_CHRATR_FONT,
941 RES_CHRATR_CJK_FONT, RES_CHRATR_CJK_FONT,
942 RES_CHRATR_CTL_FONT, RES_CHRATR_CTL_FONT> aSet( GetPool() );
943 rSh.GetCurAttr( aSet );
944 SvtScriptType nScript = rSh.GetScriptType();
946 std::shared_ptr<SvxFontItem> aFont(std::make_shared<SvxFontItem>(RES_CHRATR_FONT));
948 SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, *aSet.GetPool() );
949 aSetItem.GetItemSet().Put( aSet, false );
950 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
951 if( pI )
953 aFont.reset(static_cast<SvxFontItem*>(pI->Clone()));
955 else
957 TypedWhichId<SvxFontItem> nFontWhich =
958 GetWhichOfScript(
959 RES_CHRATR_FONT,
960 SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() ) );
961 aFont.reset(aSet.Get(nFontWhich).Clone());
964 if (aFontName.isEmpty())
965 aFontName = aFont->GetFamilyName();
968 vcl::Font aNewFont(aFontName, Size(1,1)); // Size only because CTOR.
969 if( aChars.isEmpty() )
971 // Set selected font as default.
972 SfxAllItemSet aAllSet( rSh.GetAttrPool() );
973 aAllSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
975 SwViewOption aOpt(*GetShell().GetViewOptions());
976 const OUString& sSymbolFont = aOpt.GetSymbolFont();
977 if( aFontName.isEmpty() && !sSymbolFont.isEmpty() )
978 aAllSet.Put( SfxStringItem( SID_FONT_NAME, sSymbolFont ) );
979 else
980 aAllSet.Put( SfxStringItem( SID_FONT_NAME, aFont->GetFamilyName() ) );
982 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
983 auto xFrame = GetView().GetViewFrame()->GetFrame().GetFrameInterface();
984 ScopedVclPtr<SfxAbstractDialog> pDlg(pFact->CreateCharMapDialog(GetView().GetFrameWeld(), aAllSet, xFrame));
985 pDlg->Execute();
986 return;
989 if( aChars.isEmpty() )
990 return;
992 rSh.StartAllAction();
994 // Delete selected content.
995 SwRewriter aRewriter;
996 aRewriter.AddRule(UndoArg1, SwResId(STR_SPECIALCHAR));
998 rSh.StartUndo( SwUndoId::INSERT, &aRewriter );
999 if ( rSh.HasSelection() )
1001 rSh.DelRight();
1002 aSet.ClearItem();
1003 rSh.GetCurAttr( aSet );
1005 SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, *aSet.GetPool() );
1006 aSetItem.GetItemSet().Put( aSet, false );
1007 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
1008 if( pI )
1010 aFont.reset(static_cast<SvxFontItem*>(pI->Clone()));
1012 else
1014 TypedWhichId<SvxFontItem> nFontWhich =
1015 GetWhichOfScript(
1016 RES_CHRATR_FONT,
1017 SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() ) );
1018 aFont.reset(aSet.Get( nFontWhich ).Clone());
1022 // Insert character.
1023 rSh.Insert( aChars );
1025 // #108876# a font attribute has to be set always due to a guessed script type
1026 if( !aNewFont.GetFamilyName().isEmpty() )
1028 std::unique_ptr<SvxFontItem> aNewFontItem(aFont->Clone());
1029 aNewFontItem->SetFamilyName( aNewFont.GetFamilyName() );
1030 aNewFontItem->SetFamily( aNewFont.GetFamilyType());
1031 aNewFontItem->SetPitch( aNewFont.GetPitch());
1032 aNewFontItem->SetCharSet( aNewFont.GetCharSet() );
1034 SfxItemSetFixed<RES_CHRATR_FONT, RES_CHRATR_FONT,
1035 RES_CHRATR_CJK_FONT, RES_CHRATR_CJK_FONT,
1036 RES_CHRATR_CTL_FONT, RES_CHRATR_CTL_FONT> aRestoreSet( GetPool() );
1038 nScript = g_pBreakIt->GetAllScriptsOfText( aChars );
1039 if( SvtScriptType::LATIN & nScript )
1041 aRestoreSet.Put( aSet.Get( RES_CHRATR_FONT ) );
1042 aNewFontItem->SetWhich(RES_CHRATR_FONT);
1043 aSet.Put( *aNewFontItem );
1045 if( SvtScriptType::ASIAN & nScript )
1047 aRestoreSet.Put( aSet.Get( RES_CHRATR_CJK_FONT ) );
1048 aNewFontItem->SetWhich(RES_CHRATR_CJK_FONT);
1049 aSet.Put( *aNewFontItem );
1051 if( SvtScriptType::COMPLEX & nScript )
1053 aRestoreSet.Put( aSet.Get( RES_CHRATR_CTL_FONT ) );
1054 aNewFontItem->SetWhich(RES_CHRATR_CTL_FONT);
1055 aSet.Put( *aNewFontItem );
1058 rSh.SetMark();
1059 rSh.ExtendSelection( false, aChars.getLength() );
1060 rSh.SetAttrSet( aSet, SetAttrMode::DONTEXPAND | SetAttrMode::NOFORMATATTR );
1061 if( !rSh.IsCursorPtAtEnd() )
1062 rSh.SwapPam();
1064 rSh.ClearMark();
1066 // #i75891#
1067 // SETATTR_DONTEXPAND does not work if there are already hard attributes.
1068 // Therefore we have to restore the font attributes.
1069 rSh.SetMark();
1070 rSh.SetAttrSet( aRestoreSet );
1071 rSh.ClearMark();
1073 rSh.UpdateAttr();
1075 // Why was this done? aFont is not used anymore below, we are not
1076 // in a loop and it's a local variable...?
1077 // aFont = aNewFontItem;
1080 rSh.EndAllAction();
1081 rSh.EndUndo();
1083 if ( !aChars.isEmpty() )
1085 rReq.AppendItem( SfxStringItem( SID_CHARMAP, aChars ) );
1086 rReq.AppendItem( SfxStringItem( SID_ATTR_SPECIALCHAR, aNewFont.GetFamilyName() ) );
1087 rReq.Done();
1091 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */