22#include <com/sun/star/lang/Locale.hpp>
23#include <com/sun/star/linguistic2/XThesaurus.hpp>
24#include <com/sun/star/linguistic2/ProofreadingResult.hpp>
25#include <com/sun/star/linguistic2/XLinguProperties.hpp>
26#include <com/sun/star/i18n/TextConversionOption.hpp>
41#include <osl/diagnose.h>
58#include <boost/property_tree/json_parser.hpp>
60#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
61#include <com/sun/star/ui/ContextMenuExecuteEvent.hpp>
62#include <com/sun/star/lang/XInitialization.hpp>
63#include <com/sun/star/frame/XDispatch.hpp>
64#include <com/sun/star/frame/XDispatchProvider.hpp>
65#include <com/sun/star/frame/XFrame.hpp>
66#include <com/sun/star/frame/XPopupMenuController.hpp>
67#include <com/sun/star/awt/PopupMenuDirection.hpp>
68#include <com/sun/star/util/URL.hpp>
69#include <com/sun/star/beans/PropertyValue.hpp>
70#include <com/sun/star/beans/XPropertySet.hpp>
71#include <com/sun/star/util/URLTransformer.hpp>
72#include <com/sun/star/util/XURLTransformer.hpp>
75#include <rtl/ustring.hxx>
81#include <LibreOfficeKit/LibreOfficeKitEnums.h>
101 case SID_HANGUL_HANJA_CONVERSION:
103 i18n::TextConversionOption::CHARACTER_BY_CHARACTER,
true );
105 case SID_CHINESE_CONVERSION:
108 Reference< XComponentContext > xContext(
109 ::cppu::defaultBootstrap_InitialComponentContext() );
112 Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
115 Reference< ui::dialogs::XExecutableDialog > xDialog(
116 xMCF->createInstanceWithContext(
117 "com.sun.star.linguistic2.ChineseTranslationDialog", xContext),
119 Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
122 Reference<awt::XWindow> xParentWindow;
124 xParentWindow = pParentWindow->GetXWindow();
128 {
"ParentWindow",
uno::Any(xParentWindow)}
130 xInit->initialize(
aSeq );
133 sal_Int16 nDialogRet = xDialog->execute();
134 if(
RET_OK == nDialogRet )
137 bool bToSimplified =
true;
138 bool bUseVariants =
true;
139 bool bCommonTerms =
true;
140 Reference< beans::XPropertySet > xProp( xDialog, UNO_QUERY );
145 xProp->getPropertyValue(
"IsDirectionToSimplified" ) >>= bToSimplified;
146 xProp->getPropertyValue(
"IsUseCharacterVariants" ) >>= bUseVariants;
147 xProp->getPropertyValue(
"IsTranslateCommonTerms" ) >>= bCommonTerms;
157 sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
159 nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
162 nTargetLang, GetDefaultFontFlags::OnlyOne );
187 OSL_ENSURE(pTextNode && pTextNode->
GetText().getLength() >= nPointIndex,
188 "text missing: corrupted node?" );
190 if (!pTextNode || pTextNode->
GetText().getLength() < nPointIndex)
191 m_pWrtShell->GetCursor()->GetPoint()->Assign( aPointNodeIndex );
193 m_pWrtShell->GetCursor()->GetPoint()->Assign( *pTextNode, nPointIndex );
200 Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
201 if( xComponent.is() )
202 xComponent->dispose();
211 OSL_ENSURE(
false,
"wrong Dispatcher");
223 bool bIsInteractive )
234 const bool bOldIdle = pVOpt->
IsIdle();
243 const bool bStart = bSelection ||
m_pWrtShell->IsStartOfDoc();
247 const uno::Reference< uno::XComponentContext > xContext(
249 SwHHCWrapper aWrap(
this, xContext, nSourceLang, nTargetLang, pTargetFont,
250 nOptions, bIsInteractive,
251 bStart, bOther, bSelection );
263 bool bStartDone,
bool bEndDone,
267 bool bIsWrapReverse = !pConvArgs && xProp.is() && xProp->getIsWrapReverse();
274 case SvxSpellArea::Body:
280 case SvxSpellArea::BodyEnd:
287 else if( bStartDone )
290 case SvxSpellArea::BodyStart:
291 if( !bIsWrapReverse )
300 case SvxSpellArea::Other:
315 OSL_ENSURE(
false,
"SpellStart with unknown Area" );
317 m_pWrtShell->SpellStart( eStart, eEnd, eCurr, pConvArgs );
342 while( rEditWin.
IsWait() )
379 case SvxSpellArea::Body:
382 case SvxSpellArea::BodyEnd:
385 case SvxSpellArea::BodyStart:
388 case SvxSpellArea::Other:
392 OSL_ENSURE(
false,
"HyphStart with unknown Area" );
404 VclMessageType::Warning, VclButtonsType::Ok,
SwResId(STR_MULT_INTERACT_HYPH_WARN)));
405 xBox->set_title(
SwResId(STR_HYPH_TITLE));
428 bool bOldIdle = pVOpt->
IsIdle();
435 bool bHyphSpecial = xProp.is() && xProp->getIsHyphSpecial();
438 bool bOther =
m_pWrtShell->HasOtherCnt() && bHyphSpecial && !bSelection;
439 bool bStart = bSelection || ( !bOther &&
m_pWrtShell->IsStartOfDoc() );
446 VclMessageType::Question, VclButtonsType::YesNo,
447 SwResId(STR_QUERY_SPECIAL_FORCED)));
453 xProp->setIsHyphSpecial(
true );
462 SwHyphWrapper aWrap(
this, xHyph, bStart, bOther, bSelection );
475 const bool bMultiSel =
m_pWrtShell->GetCursor()->IsMultiSelection();
477 return !bMultiSel && (!bSelection ||
m_pWrtShell->IsSelOnePara() );
508 pChar = rLookUpText.getLength() ? rLookUpText.getStr() + rLookUpText.getLength() - 1 :
nullptr;
509 sal_Int32 nRight = 0;
549 const bool bOldIdle = pVOpt->
IsIdle();
576 pDlg->StartExecuteAsync([aTmp, bSelection, bOldIdle, pDlg, pVOpt,
this](sal_Int32 nResult){
594 uno::Reference< frame::XDispatch >
xDispatch;
596 uno::Sequence< PropertyValue > aArgs;
609 ExecuteInfo* pExecuteInfo =
static_cast<ExecuteInfo*
>(
p);
616 pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
637 const bool bOldViewLock =
m_pWrtShell->IsViewLocked();
654 std::pair<Point, bool>
const tmp(rPt,
false);
670 bool bUseGrammarContext =
false;
671 Reference< XSpellAlternatives > xAlt(
m_pWrtShell->GetCorrection(&rPt, aToFill) );
672 ProofreadingResult aGrammarCheckRes;
673 sal_Int32 nErrorInResult = -1;
674 uno::Sequence< OUString > aSuggestions;
675 bool bCorrectionRes =
false;
676 if (!xAlt.is() || !xAlt->getAlternatives().hasElements())
678 sal_Int32 nErrorPosInText = -1;
679 bCorrectionRes =
m_pWrtShell->GetGrammarCorrection( aGrammarCheckRes, nErrorPosInText, nErrorInResult, aSuggestions, &rPt, aToFill );
680 OUString aMessageText;
681 if (nErrorInResult >= 0)
682 aMessageText = aGrammarCheckRes.aErrors[ nErrorInResult ].aShortComment;
685 bUseGrammarContext = bCorrectionRes &&
686 (aSuggestions.hasElements() || !aMessageText.isEmpty());
690 if ((!bUseGrammarContext && xAlt.is()) ||
691 (bUseGrammarContext && bCorrectionRes && aGrammarCheckRes.aErrors.hasElements()))
697 pCursorShell->
Push();
712 OSL_FAIL(
"text node expected but not found" );
717 std::unique_ptr<SwSpellPopup> xPopup(bUseGrammarContext ?
720 ui::ContextMenuExecuteEvent
aEvent;
724 aEvent.ExecutePosition.X = aPixPos.X();
725 aEvent.ExecutePosition.Y = aPixPos.Y();
728 OUString sMenuName = bUseGrammarContext ?
729 OUString(
"private:resource/GrammarContextMenu") : OUString(
"private:resource/SpellContextMenu");
737 css::uno::Reference<css::awt::XWindowPeer> xParent(
aEvent.SourceWindow, css::uno::UNO_QUERY);
738 const sal_uInt16
nId = xMenu->execute(xParent, css::awt::Rectangle(aPixPos.X(), aPixPos.Y(), 1, 1),
739 css::awt::PopupMenuDirection::EXECUTE_DOWN);
744 xPopup->Execute(
nId);
749 uno::Reference< frame::XFrame >
xFrame;
753 uno::Reference< frame::XDispatchProvider > xDispatchProvider(
xFrame, UNO_QUERY );
757 uno::Reference< frame::XDispatch >
xDispatch;
761 xURLTransformer->parseStrict(
aURL);
762 uno::Sequence< beans::PropertyValue > aArgs;
763 xDispatch = xDispatchProvider->queryDispatch(
aURL, OUString(), 0 );
768 ExecuteInfo* pExecuteInfo =
new ExecuteInfo;
770 pExecuteInfo->aTargetURL =
aURL;
771 pExecuteInfo->aArgs = aArgs;
787 boost::property_tree::ptree aRoot;
788 aRoot.add_child(
"menu", aMenu);
790 std::stringstream aStream;
791 boost::property_tree::write_json(aStream, aRoot,
true);
792 pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CONTEXT_MENU, aStream.str().c_str());
818 const bool bOldViewLock =
m_pWrtShell->IsViewLocked();
822 css::uno::Sequence< css::uno::Any > aArgs{
828 css::uno::Reference< css::frame::XPopupMenuController > xPopupController(
829 xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
830 "com.sun.star.comp.svx.SmartTagMenuController", aArgs, xContext ), css::uno::UNO_QUERY );
832 css::uno::Reference< css::awt::XPopupMenu > xPopupMenu( xContext->getServiceManager()->createInstanceWithContext(
833 "com.sun.star.awt.PopupMenu", xContext ), css::uno::UNO_QUERY );
835 if ( xPopupController.is() && xPopupMenu.is() )
837 xPopupController->setPopupMenu( xPopupMenu );
844 xPopupMenu->execute(
m_pEditWin->GetComponentInterface(),
847 css::uno::Reference< css::lang::XComponent > xComponent( xPopupController, css::uno::UNO_QUERY );
848 if ( xComponent.is() )
849 xComponent->dispose();
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage)
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)
static vcl::Font GetDefaultFont(DefaultFontType nType, LanguageType eLang, GetDefaultFontFlags nFlags, const OutputDevice *pOutDev=nullptr)
static boost::property_tree::ptree fillPopupMenu(const rtl::Reference< VCLXPopupMenu > &rMenu)
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
sal_uInt16 GetSlot() const
weld::Window * GetFrameWeld() const
SfxViewFrame * GetFrame() const
SfxFrame & GetFrame() const
weld::Window * GetFrameWeld() const
bool TryContextMenuInterception(const rtl::Reference< VCLXPopupMenu > &rIn, const OUString &rMenuIdentifier, rtl::Reference< VCLXPopupMenu > &rOut, css::ui::ContextMenuExecuteEvent aEvent)
SfxViewFrame * GetViewFrame() const
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
static OUString GetLanguageString(const LanguageType eType)
static SvxAbstractDialogFactory * Create()
SwContentFrame is the layout for content nodes: a common base class for text (paragraph) and non-text...
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
bool Pop(PopMode, ::std::optional< SwCallLink > &roLink)
void Push()
store a copy of the current cursor on the cursor stack
bool MovePara(SwWhichPara, SwMoveFnCollection const &)
SwCursor * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
OUString GetSelText() const
get selected text of a node at current cursor
static bool HasConvIter()
Is text conversion active somewhere else?
static bool HasHyphIter()
Is hyphenation active somewhere else?
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Marks a node in the document model.
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
PaM is Point and Mark: a selection of the document model.
const SwPosition * GetMark() const
bool IsMultiSelection() const
SwContentNode * GetPointContentNode() const
const SwPosition * GetPoint() const
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
Of course Writer needs its own rectangles.
tools::Rectangle SVRect() const
Represents the visualization of a paragraph.
SwTextNode is a paragraph in the document model.
bool IsWrongDirty() const
const OUString & GetText() const
void SetIdle(bool b) const
bool IsOnlineSpell() const
SwRootFrame * GetLayout() const
bool ExecDrwTextSpellPopup(const Point &rPt)
virtual bool HasSelection(bool bText=true) const override
SfxDispatcher & GetDispatcher()
std::unique_ptr< SwWrtShell > m_pWrtShell
void ExecLingu(SfxRequest &)
SAL_DLLPRIVATE void HyphenateDrawText()
bool ExecSpellPopup(const Point &rPt)
! End of extra code for context menu modifying extensions
VclPtr< SwEditWin > m_pEditWin
SAL_DLLPRIVATE void StartThesaurus()
SAL_DLLPRIVATE void SpellContext(bool bOn=true)
SAL_DLLPRIVATE void HyphenateDocument()
OUString GetThesaurusLookUpText(bool bSelection) const
SAL_DLLPRIVATE void SpellStart(SvxSpellArea eSpell, bool bStartDone, bool bEndDone, SwConversionArgs *pConvArgs)
void ExecSmartTagPopup(const Point &rPt)
Function: ExecSmartTagPopup.
SwDocShell * GetDocShell()
SAL_DLLPRIVATE void HyphStart(SvxSpellArea eSpell)
void SpellError(LanguageType eLang)
SAL_DLLPRIVATE void StartTextConversion(LanguageType nSourceLang, LanguageType nTargetLang, const vcl::Font *pTargetFont, sal_Int32 nOptions, bool bIsInteractive)
SAL_DLLPRIVATE void SpellEnd(SwConversionArgs const *pConvArgs)
void InsertThesaurusSynonym(const OUString &rSynonmText, const OUString &rLookUpText, bool bValidSelection)
bool IsValidSelectionForThesaurus() const
static css::awt::Rectangle ConvertToAWTRect(::tools::Rectangle const &_rRect)
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
void reset(reference_type *pBody)
Point LogicToPixel(const Point &rLogicPt) const
#define FN_HYPHENATE_OPT_DLG
SVXCORE_DLLPUBLIC std::locale SvxResLocale()
Reference< XDispatch > xDispatch
#define ERRCODE_SVX_LINGU_LANGUAGENOTEXISTS
LanguageType GetAppLanguage()
#define LANGUAGE_CHINESE_TRADITIONAL
#define LANGUAGE_CHINESE_SIMPLIFIED
#define LANGUAGE_DONTKNOW
#define LINK(Instance, Class, Member)
#define DECL_STATIC_LINK(Class, Member, ArgType, RetType)
Sequence< sal_Int8 > aSeq
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
Reference< XComponentContext > getProcessComponentContext()
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
bool GoCurrPara(SwPaM &rPam, SwMoveFnCollection const &aPosPara)
SwMoveFnCollection const & fnParaStart
SwMoveFnCollection const & fnParaEnd
Marks a position in the document model.
sal_Int32 GetContentIndex() const
void AdjustContent(sal_Int32 nDelta)
Adjust content index, only valid to call this if the position points to a SwContentNode subclass.
Reference< XFrame > xFrame
SVX_DLLPUBLIC const ErrMsgCode RID_SVXERRCTX[]
#define ERRCODE_SVX_LINGU_NOLANGUAGE
#define ERRCTX_SVX_LINGU_HYPHENATION
#define ERRCODE_SVX_LINGU_LINGUNOTEXISTS
#define ERRCTX_SVX_LINGU_THESAURUS
OUString SwResId(TranslateId aId)
uno::Reference< linguistic2::XLinguProperties > GetLinguPropertySet()
uno::Reference< linguistic2::XThesaurus > GetThesaurus()
uno::Reference< linguistic2::XHyphenator > GetHyphenator()
IMPL_STATIC_LINK(AsyncExecute, ExecuteHdl_Impl, void *, p, void)