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/awt/XVclWindowPeer.hpp>
69#include <com/sun/star/util/URL.hpp>
70#include <com/sun/star/beans/PropertyValue.hpp>
71#include <com/sun/star/beans/XPropertySet.hpp>
72#include <com/sun/star/util/URLTransformer.hpp>
73#include <com/sun/star/util/XURLTransformer.hpp>
76#include <rtl/ustring.hxx>
82#include <LibreOfficeKit/LibreOfficeKitEnums.h>
102 case SID_HANGUL_HANJA_CONVERSION:
104 i18n::TextConversionOption::CHARACTER_BY_CHARACTER,
true );
106 case SID_CHINESE_CONVERSION:
109 Reference< XComponentContext > xContext(
110 ::cppu::defaultBootstrap_InitialComponentContext() );
113 Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
116 Reference< ui::dialogs::XExecutableDialog > xDialog(
117 xMCF->createInstanceWithContext(
118 "com.sun.star.linguistic2.ChineseTranslationDialog", xContext),
120 Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
123 Reference<awt::XWindow> xParentWindow;
125 xParentWindow = pParentWindow->GetXWindow();
129 {
"ParentWindow",
uno::Any(xParentWindow)}
131 xInit->initialize(
aSeq );
134 sal_Int16 nDialogRet = xDialog->execute();
135 if(
RET_OK == nDialogRet )
138 bool bToSimplified =
true;
139 bool bUseVariants =
true;
140 bool bCommonTerms =
true;
141 Reference< beans::XPropertySet > xProp( xDialog, UNO_QUERY );
146 xProp->getPropertyValue(
"IsDirectionToSimplified" ) >>= bToSimplified;
147 xProp->getPropertyValue(
"IsUseCharacterVariants" ) >>= bUseVariants;
148 xProp->getPropertyValue(
"IsTranslateCommonTerms" ) >>= bCommonTerms;
158 sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
160 nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
163 nTargetLang, GetDefaultFontFlags::OnlyOne );
188 OSL_ENSURE(pTextNode && pTextNode->
GetText().getLength() >= nPointIndex,
189 "text missing: corrupted node?" );
191 if (!pTextNode || pTextNode->
GetText().getLength() < nPointIndex)
192 m_pWrtShell->GetCursor()->GetPoint()->Assign( aPointNodeIndex );
194 m_pWrtShell->GetCursor()->GetPoint()->Assign( *pTextNode, nPointIndex );
201 Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
202 if( xComponent.is() )
203 xComponent->dispose();
212 OSL_ENSURE(
false,
"wrong Dispatcher");
224 bool bIsInteractive )
235 const bool bOldIdle = pVOpt->
IsIdle();
244 const bool bStart = bSelection ||
m_pWrtShell->IsStartOfDoc();
248 const uno::Reference< uno::XComponentContext > xContext(
250 SwHHCWrapper aWrap(
this, xContext, nSourceLang, nTargetLang, pTargetFont,
251 nOptions, bIsInteractive,
252 bStart, bOther, bSelection );
264 bool bStartDone,
bool bEndDone,
268 bool bIsWrapReverse = !pConvArgs && xProp.is() && xProp->getIsWrapReverse();
275 case SvxSpellArea::Body:
281 case SvxSpellArea::BodyEnd:
288 else if( bStartDone )
291 case SvxSpellArea::BodyStart:
292 if( !bIsWrapReverse )
301 case SvxSpellArea::Other:
316 OSL_ENSURE(
false,
"SpellStart with unknown Area" );
318 m_pWrtShell->SpellStart( eStart, eEnd, eCurr, pConvArgs );
343 while( rEditWin.
IsWait() )
380 case SvxSpellArea::Body:
383 case SvxSpellArea::BodyEnd:
386 case SvxSpellArea::BodyStart:
389 case SvxSpellArea::Other:
393 OSL_ENSURE(
false,
"HyphStart with unknown Area" );
405 VclMessageType::Warning, VclButtonsType::Ok,
SwResId(STR_MULT_INTERACT_HYPH_WARN)));
406 xBox->set_title(
SwResId(STR_HYPH_TITLE));
429 bool bOldIdle = pVOpt->
IsIdle();
436 bool bHyphSpecial = xProp.is() && xProp->getIsHyphSpecial();
439 bool bOther =
m_pWrtShell->HasOtherCnt() && bHyphSpecial && !bSelection;
440 bool bStart = bSelection || ( !bOther &&
m_pWrtShell->IsStartOfDoc() );
447 VclMessageType::Question, VclButtonsType::YesNo,
448 SwResId(STR_QUERY_SPECIAL_FORCED)));
454 xProp->setIsHyphSpecial(
true );
463 SwHyphWrapper aWrap(
this, xHyph, bStart, bOther, bSelection );
476 const bool bMultiSel =
m_pWrtShell->GetCursor()->IsMultiSelection();
478 return !bMultiSel && (!bSelection ||
m_pWrtShell->IsSelOnePara() );
509 pChar = rLookUpText.getLength() ? rLookUpText.getStr() + rLookUpText.getLength() - 1 :
nullptr;
510 sal_Int32 nRight = 0;
550 const bool bOldIdle = pVOpt->
IsIdle();
577 pDlg->StartExecuteAsync([aTmp, bSelection, bOldIdle, pDlg, pVOpt,
this](sal_Int32 nResult){
595 uno::Reference< frame::XDispatch >
xDispatch;
597 uno::Sequence< PropertyValue > aArgs;
610 ExecuteInfo* pExecuteInfo =
static_cast<ExecuteInfo*
>(
p);
617 pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
638 const bool bOldViewLock =
m_pWrtShell->IsViewLocked();
656 std::pair<Point, bool>
const tmp(rPt,
false);
672 bool bUseGrammarContext =
false;
673 Reference< XSpellAlternatives > xAlt(
m_pWrtShell->GetCorrection(&rPt, aToFill) );
674 ProofreadingResult aGrammarCheckRes;
675 sal_Int32 nErrorInResult = -1;
676 uno::Sequence< OUString > aSuggestions;
677 bool bCorrectionRes =
false;
678 if (!xAlt.is() || !xAlt->getAlternatives().hasElements())
680 sal_Int32 nErrorPosInText = -1;
681 bCorrectionRes =
m_pWrtShell->GetGrammarCorrection( aGrammarCheckRes, nErrorPosInText, nErrorInResult, aSuggestions, &rPt, aToFill );
682 OUString aMessageText;
683 if (nErrorInResult >= 0)
684 aMessageText = aGrammarCheckRes.aErrors[ nErrorInResult ].aShortComment;
687 bUseGrammarContext = bCorrectionRes &&
688 (aSuggestions.hasElements() || !aMessageText.isEmpty());
692 if ((!bUseGrammarContext && xAlt.is()) ||
693 (bUseGrammarContext && bCorrectionRes && aGrammarCheckRes.aErrors.hasElements()))
699 pCursorShell->
Push();
714 OSL_FAIL(
"text node expected but not found" );
719 std::unique_ptr<SwSpellPopup> xPopup(bUseGrammarContext ?
722 ui::ContextMenuExecuteEvent
aEvent;
726 aEvent.ExecutePosition.X = aPixPos.
X();
727 aEvent.ExecutePosition.Y = aPixPos.
Y();
730 OUString sMenuName = bUseGrammarContext ?
731 OUString(
"private:resource/GrammarContextMenu") : OUString(
"private:resource/SpellContextMenu");
739 css::uno::Reference<css::awt::XWindowPeer> xParent(
aEvent.SourceWindow, css::uno::UNO_QUERY);
740 const sal_uInt16
nId = xMenu->execute(xParent, css::awt::Rectangle(aPixPos.
X(), aPixPos.
Y(), 1, 1),
741 css::awt::PopupMenuDirection::EXECUTE_DOWN);
746 xPopup->Execute(
nId);
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, OString(aStream.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, const ILibreOfficeKitNotifier *pNotifier=nullptr)
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)
constexpr tools::Long Y() const
constexpr tools::Long X() const
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
SfxViewFrame & GetViewFrame() const
bool TryContextMenuInterception(const rtl::Reference< VCLXPopupMenu > &rIn, const OUString &rMenuIdentifier, rtl::Reference< VCLXPopupMenu > &rOut, css::ui::ContextMenuExecuteEvent aEvent)
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)