1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
52 #include <fmtinfmt.hxx>
53 #include <fmtclds.hxx>
54 #include <fmtfsize.hxx>
55 #include <swmodule.hxx>
60 #include <IDocumentChartDataProviderAccess.hxx>
63 #include <globals.hrc>
67 #include <tablemgr.hxx>
69 #include <breakit.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
)
107 rWrtShell
.GetIDocumentUndoRedo().ClearRedo();
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();
142 pArgs
->GetItemState(nSlot
, false, &pItem
);
146 case FN_INSERT_STRING
:
148 rSh
.InsertByWord(static_cast<const SfxStringItem
*>(pItem
)->GetValue());
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
) );
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
);
174 rSh
.Insert( OUString( cIns
) );
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
:
183 case SID_INSERT_ZWSP
:
185 sal_Unicode cIns
= 0;
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
) );
198 case FN_INSERT_BREAK
:
200 if (!rSh
.CursorInsideInputField() && !rSh
.CursorInsideContentControl())
206 rSh
.InsertLineBreak();
212 case FN_INSERT_PAGEBREAK
:
213 rSh
.InsertPageBreak();
217 case FN_INSERT_LINEBREAK
:
218 rSh
.InsertLineBreak();
222 case FN_INSERT_CONTENT_CONTROL
:
223 rSh
.InsertContentControl(SwContentControlType::RICH_TEXT
);
227 case FN_INSERT_CHECKBOX_CONTENT_CONTROL
:
228 rSh
.InsertContentControl(SwContentControlType::CHECKBOX
);
232 case FN_INSERT_DROPDOWN_CONTENT_CONTROL
:
233 rSh
.InsertContentControl(SwContentControlType::DROP_DOWN_LIST
);
237 case FN_INSERT_PICTURE_CONTENT_CONTROL
:
238 rSh
.InsertContentControl(SwContentControlType::PICTURE
);
242 case FN_INSERT_DATE_CONTENT_CONTROL
:
243 rSh
.InsertContentControl(SwContentControlType::DATE
);
247 case FN_INSERT_PLAIN_TEXT_CONTENT_CONTROL
:
248 rSh
.InsertContentControl(SwContentControlType::PLAIN_TEXT
);
252 case FN_INSERT_COMBO_BOX_CONTENT_CONTROL
:
253 rSh
.InsertContentControl(SwContentControlType::COMBO_BOX
);
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
);
269 case FN_INSERT_COLUMN_BREAK
:
270 rSh
.InsertColumnBreak();
274 case SID_HYPERLINK_SETLINK
:
276 InsertHyperlink(*static_cast<const SvxHyperlinkItem
*>(pItem
));
280 #if HAVE_FEATURE_AVMEDIA
281 case SID_INSERT_AVMEDIA
:
282 rReq
.SetReturnValue(SfxBoolItem(nSlot
, InsertMediaDlg( rReq
)));
286 case SID_INSERT_OBJECT
:
288 const SfxGlobalNameItem
* pNameItem
= rReq
.GetArg
<SfxGlobalNameItem
>(SID_INSERT_OBJECT
);
289 SvGlobalName
*pName
= nullptr;
293 aName
= pNameItem
->GetValue();
297 svt::EmbeddedObjectRef xObj
;
298 rSh
.InsertObject( xObj
, pName
, nSlot
);
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
;
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
);
323 ScrollingMode eScroll
= ScrollingMode::Auto
;
324 if( pScrollingItem
&& pScrollingItem
->GetValue() <= int(ScrollingMode::Auto
) )
325 eScroll
= static_cast<ScrollingMode
>(pScrollingItem
->GetValue());
329 aMargin
= pMarginItem
->GetSize();
331 xSet
->setPropertyValue("FrameURL", uno::Any( pURLItem
->GetValue() ) );
333 xSet
->setPropertyValue("FrameName", uno::Any( pNameItem
->GetValue() ) );
335 if ( eScroll
== ScrollingMode::Auto
)
336 xSet
->setPropertyValue("FrameIsAutoScroll",
339 xSet
->setPropertyValue("FrameIsScrollingMode",
340 uno::Any( eScroll
== ScrollingMode::Yes
) );
343 xSet
->setPropertyValue("FrameIsBorder",
344 uno::Any( pBorderItem
->GetValue() ) );
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
);
364 rSh
.InsertObject( xObj
, nullptr, nSlot
);
369 case SID_INSERT_DIAGRAM
:
371 SvtModuleOptions aMOpt
;
372 if ( !aMOpt
.IsChart() )
376 SwInsertChart( LINK( this, SwTextShell
, DialogClosedHdl
) );
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() );
393 bFillWithData
= false; // will create chart with only it's default image
395 SwTableFUNC( &rSh
).InsertChart( xDataProvider
, bFillWithData
, aRangeString
);
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
)
407 aSz
.Width
= aSize
.Width();
408 aSz
.Height
= aSize
.Height();
409 xObj
->setVisualAreaSize( xObj
.GetViewAspect(), aSz
);
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
);
426 case FN_INSERT_TABLE
:
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
;
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();
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 );
461 aCol
.Init( nCols
, aCol
.GetGutterWidth(), aCol
.GetWishWidth() );
464 aMgr
.InsertFlyFrame(RndStdIds::FLY_AT_PARA
, aStartPos
, aSize
);
465 GetShell().EndAllAction();
466 GetShell().UnlockPaint();
470 GetView().InsFrameMode(nCols
);
475 case FN_INSERT_FRAME
:
477 bool bSingleCol
= false;
478 if( nullptr!= dynamic_cast< SwWebDocShell
*>( GetView().GetDocShell()) )
480 if( HTML_CFG_MSIE
== SvxHtmlOptions::GetExportMode() )
487 SwFlyFrameAttrMgr
aMgr( true, GetShellPtr(), Frmmgr_Type::TEXT
, nullptr );
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();
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(),
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();
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() )
546 aMgr
.InsertFlyFrame();
548 uno::Reference
< frame::XDispatchRecorder
> xRecorder
=
549 GetView().GetViewFrame()->GetBindings().GetRecorder();
550 if ( xRecorder
.is() )
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()));
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();
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();
586 OSL_ENSURE(false, "wrong dispatcher");
591 static bool lcl_IsMarkInSameSection( SwWrtShell
& rWrtSh
, const SwSection
* pSect
)
594 bool bRet
= pSect
== rWrtSh
.GetCurrSection();
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;
613 bCursorInHidden
= rSh
.SelectHiddenRange();
621 case SID_INSERT_AVMEDIA
:
622 if ( GetShell().IsSelFrameMode()
623 || GetShell().CursorInsideInputField()
624 || SfxObjectCreateMode::EMBEDDED
== eCreateMode
627 rSet
.DisableItem( nWhich
);
631 case SID_INSERT_DIAGRAM
:
633 || GetShell().CursorInsideInputField()
634 || eCreateMode
== SfxObjectCreateMode::EMBEDDED
637 rSet
.DisableItem( nWhich
);
643 || eCreateMode
== SfxObjectCreateMode::EMBEDDED
645 || rSh
.CursorInsideInputField() )
647 rSet
.DisableItem( nWhich
);
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
);
672 case FN_INSERT_FRAME_INTERACT_NOCOL
:
673 case FN_INSERT_FRAME_INTERACT
:
675 if( GetShell().IsSelFrameMode()
677 || GetShell().CursorInsideInputField()
679 rSet
.DisableItem(nWhich
);
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
);
696 aHLinkItem
.SetMacro(HyperDialogEvent::MouseOverObject
, *pMacro
);
698 pMacro
= pINetFormat
->GetMacro( SvMacroItemId::OnClick
);
700 aHLinkItem
.SetMacro(HyperDialogEvent::MouseClickObject
, *pMacro
);
702 pMacro
= pINetFormat
->GetMacro( SvMacroItemId::OnMouseOut
);
704 aHLinkItem
.SetMacro(HyperDialogEvent::MouseOutObject
, *pMacro
);
706 // Get the text of the Link.
708 const bool bAtEnd(rSh
.IsCursorPtAtEnd());
709 if(!bAtEnd
) // tdf#91832: ensure forward selection
714 rSh
.SwCursorShell::SelectTextAttr(RES_TXTATR_INETFMT
,true);
715 OUString sLinkName
= rSh
.GetSelText();
716 aHLinkItem
.SetName(sLinkName
);
717 aHLinkItem
.SetInsertMode(HLINK_FIELD
);
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
);
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
);
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() )
758 const SwSection
* pCurrSection
= rSh
.GetCurrSection();
759 const sal_uInt16 nFullSectCnt
= rSh
.GetFullSelectedSectionCount();
760 if( pCurrSection
&& ( !rSh
.HasSelection() || 0 != nFullSectCnt
))
763 rSh
.HasSelection() && rSh
.IsInsRegionAvailable() &&
764 ( !pCurrSection
|| ( 1 != nFullSectCnt
&&
765 lcl_IsMarkInSameSection( rSh
, pCurrSection
) )))
769 rSet
.DisableItem(nWhich
);
773 nWhich
= aIter
.NextWhich();
777 void SwTextShell::ExecDelete(SfxRequest
&rReq
)
779 SwWrtShell
&rSh
= GetShell();
780 switch( rReq
.GetSlot() )
783 if( rSh
.IsTableMode() )
789 rSh
.DelToEndOfSentence();
791 case FN_DELETE_BACK_SENT
:
792 rSh
.DelToStartOfSentence();
797 case FN_DELETE_BACK_WORD
:
801 rSh
.DelToEndOfLine();
803 case FN_DELETE_BACK_LINE
:
804 rSh
.DelToStartOfLine();
807 rSh
.DelToEndOfPara();
809 case FN_DELETE_BACK_PARA
:
810 rSh
.DelToStartOfPara();
812 case FN_DELETE_WHOLE_LINE
:
816 OSL_ENSURE(false, "wrong dispatcher");
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
;
832 case SID_TRANSLITERATE_TITLE_CASE
:
833 nMode
= TransliterationFlags::TITLE_CASE
;
835 case SID_TRANSLITERATE_TOGGLE_CASE
:
836 nMode
= TransliterationFlags::TOGGLE_CASE
;
838 case SID_TRANSLITERATE_UPPER
:
839 nMode
= TransliterationFlags::LOWERCASE_UPPERCASE
;
841 case SID_TRANSLITERATE_LOWER
:
842 nMode
= TransliterationFlags::UPPERCASE_LOWERCASE
;
845 case SID_TRANSLITERATE_HALFWIDTH
:
846 nMode
= TransliterationFlags::FULLWIDTH_HALFWIDTH
;
848 case SID_TRANSLITERATE_FULLWIDTH
:
849 nMode
= TransliterationFlags::HALFWIDTH_FULLWIDTH
;
852 case SID_TRANSLITERATE_HIRAGANA
:
853 nMode
= TransliterationFlags::KATAKANA_HIRAGANA
;
855 case SID_TRANSLITERATE_KATAKANA
:
856 nMode
= TransliterationFlags::HIRAGANA_KATAKANA
;
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
) :
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
));
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
));
923 void SwTextShell::InsertSymbol( SfxRequest
& rReq
)
925 const SfxItemSet
*pArgs
= rReq
.GetArgs();
926 const SfxStringItem
* pItem
= nullptr;
928 pItem
= pArgs
->GetItemIfSet(SID_CHARMAP
, false);
930 OUString aChars
, aFontName
;
933 aChars
= pItem
->GetValue();
934 const SfxStringItem
* pFontItem
= pArgs
->GetItemIfSet( SID_ATTR_SPECIALCHAR
, false );
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
);
953 aFont
.reset(static_cast<SvxFontItem
*>(pI
->Clone()));
957 TypedWhichId
<SvxFontItem
> nFontWhich
=
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
) );
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
));
989 if( aChars
.isEmpty() )
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() )
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
);
1010 aFont
.reset(static_cast<SvxFontItem
*>(pI
->Clone()));
1014 TypedWhichId
<SvxFontItem
> nFontWhich
=
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
);
1059 rSh
.ExtendSelection( false, aChars
.getLength() );
1060 rSh
.SetAttrSet( aSet
, SetAttrMode::DONTEXPAND
| SetAttrMode::NOFORMATATTR
);
1061 if( !rSh
.IsCursorPtAtEnd() )
1067 // SETATTR_DONTEXPAND does not work if there are already hard attributes.
1068 // Therefore we have to restore the font attributes.
1070 rSh
.SetAttrSet( aRestoreSet
);
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;
1083 if ( !aChars
.isEmpty() )
1085 rReq
.AppendItem( SfxStringItem( SID_CHARMAP
, aChars
) );
1086 rReq
.AppendItem( SfxStringItem( SID_ATTR_SPECIALCHAR
, aNewFont
.GetFamilyName() ) );
1091 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */