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>
54 #include <strings.hrc>
57 #include <boost/property_tree/json_parser.hpp>
59 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
60 #include <com/sun/star/ui/ContextMenuExecuteEvent.hpp>
61 #include <com/sun/star/lang/XInitialization.hpp>
62 #include <com/sun/star/frame/XDispatch.hpp>
63 #include <com/sun/star/frame/XDispatchProvider.hpp>
64 #include <com/sun/star/frame/XFrame.hpp>
65 #include <com/sun/star/frame/XPopupMenuController.hpp>
66 #include <com/sun/star/awt/PopupMenuDirection.hpp>
67 #include <com/sun/star/util/URL.hpp>
68 #include <com/sun/star/beans/PropertyValue.hpp>
69 #include <com/sun/star/beans/XPropertySet.hpp>
70 #include <com/sun/star/util/URLTransformer.hpp>
71 #include <com/sun/star/util/XURLTransformer.hpp>
74 #include <rtl/ustring.hxx>
80 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
100 case SID_HANGUL_HANJA_CONVERSION:
102 i18n::TextConversionOption::CHARACTER_BY_CHARACTER,
true );
104 case SID_CHINESE_CONVERSION:
111 Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
114 Reference< ui::dialogs::XExecutableDialog > xDialog(
115 xMCF->createInstanceWithContext(
116 "com.sun.star.linguistic2.ChineseTranslationDialog", xContext),
118 Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
121 Reference<awt::XWindow> xParentWindow;
123 xParentWindow = pParentWindow->GetXWindow();
127 {
"ParentWindow",
uno::Any(xParentWindow)}
129 xInit->initialize( aSeq );
132 sal_Int16 nDialogRet = xDialog->execute();
133 if(
RET_OK == nDialogRet )
136 bool bToSimplified =
true;
137 bool bUseVariants =
true;
138 bool bCommonTerms =
true;
144 xProp->getPropertyValue(
"IsDirectionToSimplified" ) >>= bToSimplified;
145 xProp->getPropertyValue(
"IsUseCharacterVariants" ) >>= bUseVariants;
146 xProp->getPropertyValue(
"IsTranslateCommonTerms" ) >>= bCommonTerms;
156 sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
158 nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
161 nTargetLang, GetDefaultFontFlags::OnlyOne );
166 m_pWrtShell->StartAction();
169 const SwPosition *pPoint = m_pWrtShell->GetCursor()->GetPoint();
178 StartTextConversion( nSourceLang, nTargetLang, &aTargetFont, nOptions,
false );
186 OSL_ENSURE(pTextNode && pTextNode->
GetText().getLength() >= nPointIndex,
187 "text missing: corrupted node?" );
188 if (!pTextNode || pTextNode->
GetText().getLength() < nPointIndex)
191 m_pWrtShell->GetCursor()->GetPoint()->nContent.Assign( pTextNode, nPointIndex );
195 m_pWrtShell->EndAction();
199 if( xComponent.is() )
200 xComponent->dispose();
209 OSL_ENSURE(
false,
"wrong Dispatcher");
221 bool bIsInteractive )
231 const SwViewOption* pVOpt = m_pWrtShell->GetViewOptions();
232 const bool bOldIdle = pVOpt->
IsIdle();
235 bool bOldIns = m_pWrtShell->IsInsMode();
236 m_pWrtShell->SetInsMode();
238 const bool bSelection =
static_cast<SwCursorShell*
>(m_pWrtShell.get())->HasSelection() ||
241 const bool bStart = bSelection || m_pWrtShell->IsStartOfDoc();
242 const bool bOther = !bSelection && !(m_pWrtShell->GetFrameType(
nullptr,
true) &
FrameTypeFlags::BODY);
245 const uno::Reference< uno::XComponentContext > xContext(
247 SwHHCWrapper aWrap(
this, xContext, nSourceLang, nTargetLang, pTargetFont,
248 nOptions, bIsInteractive,
249 bStart, bOther, bSelection );
253 m_pWrtShell->SetInsMode( bOldIns );
261 bool bStartDone,
bool bEndDone,
265 bool bIsWrapReverse = !pConvArgs && xProp.is() && xProp->getIsWrapReverse();
272 case SvxSpellArea::Body:
278 case SvxSpellArea::BodyEnd:
285 else if( bStartDone )
288 case SvxSpellArea::BodyStart:
289 if( !bIsWrapReverse )
298 case SvxSpellArea::Other:
313 OSL_ENSURE(
false,
"SpellStart with unknown Area" );
315 m_pWrtShell->SpellStart( eStart, eEnd, eCurr, pConvArgs );
325 if ( m_pWrtShell->ActionPend() )
328 m_pWrtShell->ClearMark();
331 m_pWrtShell->EndAction();
334 while( m_pWrtShell->ActionPend() );
340 while( rEditWin.
IsWait() )
359 m_pWrtShell->StartAction();
360 m_pWrtShell->Combine();
368 m_pWrtShell->SpellEnd( pConvArgs );
369 if( m_pWrtShell->IsExtMode() )
370 m_pWrtShell->SetMark();
377 case SvxSpellArea::Body:
380 case SvxSpellArea::BodyEnd:
383 case SvxSpellArea::BodyStart:
386 case SvxSpellArea::Other:
390 OSL_ENSURE(
false,
"HyphStart with unknown Area" );
402 VclMessageType::Warning, VclButtonsType::Ok,
SwResId(STR_MULT_INTERACT_HYPH_WARN)));
403 xBox->set_title(
SwResId(STR_HYPH_TITLE));
426 bool bOldIdle = pVOpt->
IsIdle();
433 bool bHyphSpecial = xProp.is() && xProp->getIsHyphSpecial();
434 bool bSelection =
static_cast<SwCursorShell*
>(m_pWrtShell.get())->HasSelection() ||
436 bool bOther = m_pWrtShell->HasOtherCnt() && bHyphSpecial && !bSelection;
437 bool bStart = bSelection || ( !bOther && m_pWrtShell->IsStartOfDoc() );
439 if( !bOther && !(m_pWrtShell->GetFrameType(
nullptr,
true) &
FrameTypeFlags::BODY) && !bSelection )
444 VclMessageType::Question, VclButtonsType::YesNo,
445 SwResId(STR_QUERY_SPECIAL_FORCED)));
451 xProp->setIsHyphSpecial(
true );
460 SwHyphWrapper aWrap(
this, xHyph, bStart, bOther, bSelection );
473 const bool bMultiSel = m_pWrtShell->GetCursor()->IsMultiSelection();
474 const bool bSelection =
static_cast<SwCursorShell*
>(m_pWrtShell.get())->HasSelection();
475 return !bMultiSel && (!bSelection || m_pWrtShell->IsSelOnePara() );
480 return bSelection ? m_pWrtShell->GetSelText() : m_pWrtShell->GetCurWord();
485 bool bOldIns = m_pWrtShell->IsInsMode();
486 m_pWrtShell->SetInsMode();
488 m_pWrtShell->StartAllAction();
493 if(m_pWrtShell->IsEndWrd())
496 m_pWrtShell->SelWrd();
506 pChar = rLookUpText.getLength() ? rLookUpText.getStr() + rLookUpText.getLength() - 1 :
nullptr;
507 sal_Int32 nRight = 0;
512 SwPaM *pCursor = m_pWrtShell->GetCursor();
517 m_pWrtShell->Insert( rSynonmText );
520 m_pWrtShell->EndAllAction();
522 m_pWrtShell->SetInsMode( bOldIns );
529 if (!IsValidSelectionForThesaurus())
547 const bool bOldIdle = pVOpt->
IsIdle();
552 const bool bSelection =
static_cast<SwCursorShell*
>(m_pWrtShell.get())->HasSelection();
553 OUString aTmp = GetThesaurusLookUpText( bSelection );
564 SwWait aWait( *GetDocShell(),
true );
567 pDlg.
reset(pFact->CreateThesaurusDialog(GetEditWin().
GetFrameWeld(), xThes, aTmp, eLang));
574 pDlg->StartExecuteAsync([aTmp, bSelection, bOldIdle, pDlg, pVOpt,
this](sal_Int32 nResult){
576 InsertThesaurusSynonym(pDlg->
GetWord(), aTmp, bSelection);
592 uno::Reference< frame::XDispatch >
xDispatch;
594 uno::Sequence< PropertyValue > aArgs;
607 ExecuteInfo* pExecuteInfo =
static_cast<ExecuteInfo*
>(
p);
614 pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
627 const SwViewOption* pVOpt = m_pWrtShell->GetViewOptions();
629 !m_pWrtShell->IsSelection())
632 bRet = ExecDrwTextSpellPopup(rPt);
633 else if (!m_pWrtShell->IsSelFrameMode())
635 const bool bOldViewLock = m_pWrtShell->IsViewLocked();
636 m_pWrtShell->LockView(
true );
648 if (pNode && pNode->IsWrongDirty() &&
652 std::pair<Point, bool>
const tmp(rPt,
false);
658 SwRect aRepaint(static_cast<SwTextFrame*>(pContentFrame)->AutoSpell_(
661 m_pWrtShell->InvalidateWindows(aRepaint);
668 bool bUseGrammarContext =
false;
669 Reference< XSpellAlternatives > xAlt( m_pWrtShell->GetCorrection(&rPt, aToFill) );
670 ProofreadingResult aGrammarCheckRes;
671 sal_Int32 nErrorInResult = -1;
672 uno::Sequence< OUString > aSuggestions;
673 bool bCorrectionRes =
false;
674 if (!xAlt.is() || !xAlt->getAlternatives().hasElements())
676 sal_Int32 nErrorPosInText = -1;
677 bCorrectionRes = m_pWrtShell->GetGrammarCorrection( aGrammarCheckRes, nErrorPosInText, nErrorInResult, aSuggestions, &rPt, aToFill );
678 OUString aMessageText;
679 if (nErrorInResult >= 0)
680 aMessageText = aGrammarCheckRes.aErrors[ nErrorInResult ].aShortComment;
683 bUseGrammarContext = bCorrectionRes &&
684 (aSuggestions.hasElements() || !aMessageText.isEmpty());
688 if ((!bUseGrammarContext && xAlt.is()) ||
689 (bUseGrammarContext && bCorrectionRes && aGrammarCheckRes.aErrors.hasElements()))
694 aParaText = pNode->GetText();
697 OSL_FAIL(
"text node expected but not found" );
701 m_pWrtShell->SttSelect();
702 std::unique_ptr<SwSpellPopup> xPopup(bUseGrammarContext ?
703 new SwSpellPopup(m_pWrtShell.get(), aGrammarCheckRes, nErrorInResult, aSuggestions, aParaText) :
705 ui::ContextMenuExecuteEvent
aEvent;
706 const Point aPixPos = GetEditWin().LogicToPixel( rPt );
709 aEvent.ExecutePosition.X = aPixPos.X();
710 aEvent.ExecutePosition.Y = aPixPos.Y();
713 OUString sMenuName = bUseGrammarContext ?
714 OUString(
"private:resource/GrammarContextMenu") : OUString(
"private:resource/SpellContextMenu");
715 if (TryContextMenuInterception(xPopup->GetMenu(), sMenuName, pMenu, aEvent))
723 if (aCommand.isEmpty() )
731 uno::Reference< frame::XFrame >
xFrame;
735 uno::Reference< frame::XDispatchProvider > xDispatchProvider( xFrame, UNO_QUERY );
739 uno::Reference< frame::XDispatch >
xDispatch;
742 aURL.Complete = aCommand;
743 xURLTransformer->parseStrict(aURL);
744 uno::Sequence< beans::PropertyValue > aArgs;
745 xDispatch = xDispatchProvider->queryDispatch( aURL, OUString(), 0 );
750 ExecuteInfo* pExecuteInfo =
new ExecuteInfo;
751 pExecuteInfo->xDispatch = xDispatch;
752 pExecuteInfo->aTargetURL = aURL;
753 pExecuteInfo->aArgs = aArgs;
769 boost::property_tree::ptree aRoot;
770 aRoot.add_child(
"menu", aMenu);
772 std::stringstream aStream;
773 boost::property_tree::write_json(aStream, aRoot,
true);
774 pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CONTEXT_MENU, aStream.str().c_str());
779 xPopup->Execute(aToFill.
SVRect(), m_pEditWin);
787 m_pWrtShell->LockView( bOldViewLock );
800 const bool bOldViewLock = m_pWrtShell->IsViewLocked();
801 m_pWrtShell->LockView(
true );
804 css::uno::Sequence< css::uno::Any > aArgs( 2 );
809 css::uno::Reference< css::frame::XPopupMenuController > xPopupController(
810 xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
811 "com.sun.star.comp.svx.SmartTagMenuController", aArgs, xContext ), css::uno::UNO_QUERY );
813 css::uno::Reference< css::awt::XPopupMenu > xPopupMenu( xContext->getServiceManager()->createInstanceWithContext(
814 "com.sun.star.awt.PopupMenu", xContext ), css::uno::UNO_QUERY );
816 if ( xPopupController.is() && xPopupMenu.is() )
818 xPopupController->setPopupMenu( xPopupMenu );
821 m_pWrtShell->GetSmartTagRect( rPt, aToFill );
822 m_pWrtShell->SttSelect();
825 xPopupMenu->execute( m_pEditWin->GetComponentInterface(),
828 css::uno::Reference< css::lang::XComponent > xComponent( xPopupController, css::uno::UNO_QUERY );
829 if ( xComponent.is() )
830 xComponent->dispose();
834 m_pWrtShell->LockView( bOldViewLock );
#define LINK(Instance, Class, Member)
static vcl::Font GetDefaultFont(DefaultFontType nType, LanguageType eLang, GetDefaultFontFlags nFlags, const OutputDevice *pOutDev=nullptr)
SAL_DLLPRIVATE void HyphenateDocument()
void ExecLingu(SfxRequest &)
Marks a position in the document model.
bool IsMultiSelection() const
SwPaM * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
const OUString & GetText() const
static bool HasConvIter()
Is text conversion active somewhere else?
#define FN_HYPHENATE_OPT_DLG
SAL_DLLPRIVATE void SpellStart(SvxSpellArea eSpell, bool bStartDone, bool bEndDone, SwConversionArgs *pConvArgs)
static SvxAbstractDialogFactory * Create()
Reference< XFrame > xFrame
const SwPosition * GetMark() const
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
Of course Writer needs its own rectangles.
static bool HasHyphIter()
Is hyphenation active somewhere else?
virtual OUString GetWord()=0
SwContentNode * GetContentNode(bool bPoint=true) const
static boost::property_tree::ptree fillPopupMenu(Menu *pMenu)
SfxFrame & GetFrame() const
static SfxViewShell * Current()
bool ExecSpellPopup(const Point &rPt)
! End of extra code for context menu modifying extensions
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
PaM is Point and Mark: a selection of the document model.
const SwPosition * GetPoint() const
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
SVX_DLLPUBLIC const ErrMsgCode RID_SVXERRCTX[]
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
void ExecSmartTagPopup(const Point &rPt)
Function: ExecSmartTagPopup.
void SpellError(LanguageType eLang)
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
#define ERRCTX_SVX_LINGU_THESAURUS
#define LANGUAGE_DONTKNOW
#define LANGUAGE_CHINESE_SIMPLIFIED
void InsertThesaurusSynonym(const OUString &rSynonmText, const OUString &rLookUpText, bool bValidSelection)
CPPUHELPER_DLLPUBLIC css::uno::Reference< css::uno::XComponentContext > SAL_CALL defaultBootstrap_InitialComponentContext()
Marks a node in the document model.
IMPL_STATIC_LINK(AsyncExecute, ExecuteHdl_Impl, void *, p, void)
OUString SwResId(const char *pId)
bool IsOnlineSpell() const
OUString GetThesaurusLookUpText(bool bSelection) const
#define ERRCODE_SVX_LINGU_LANGUAGENOTEXISTS
static css::awt::Rectangle ConvertToAWTRect(::tools::Rectangle const &_rRect)
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
#define ERRCODE_SVX_LINGU_LINGUNOTEXISTS
void reset(reference_type *pBody)
uno::Reference< linguistic2::XThesaurus > GetThesaurus()
weld::Window * GetFrameWeld() const
SAL_DLLPRIVATE void StartTextConversion(LanguageType nSourceLang, LanguageType nTargetLang, const vcl::Font *pTargetFont, sal_Int32 nOptions, bool bIsInteractive)
const sal_uInt16 CRSR_SKIP_CELLS
SwTextNode is a paragraph in the document model.
sal_uInt16 GetSlot() const
Reference< XDispatch > xDispatch
SfxDispatcher * GetDispatcher()
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
tools::Rectangle SVRect() const
SAL_DLLPRIVATE void HyphStart(SvxSpellArea eSpell)
bool IsValidSelectionForThesaurus() const
void SetIdle(bool b) const
SAL_DLLPRIVATE void StartThesaurus()
sal_Int32 GetIndex() const
LanguageType GetAppLanguage()
Reference< XComponentContext > getProcessComponentContext()
Sequence< sal_Int8 > aSeq
#define ERRCTX_SVX_LINGU_HYPHENATION
static OUString GetLanguageString(const LanguageType eType)
uno::Reference< linguistic2::XHyphenator > GetHyphenator()
#define LANGUAGE_CHINESE_TRADITIONAL
SAL_DLLPRIVATE void SpellEnd(SwConversionArgs const *pConvArgs)
#define DECL_STATIC_LINK(Class, Member, ArgType, RetType)
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
#define ERRCODE_SVX_LINGU_NOLANGUAGE
SwRootFrame * GetLayout() const
std::locale SvxResLocale()
uno::Reference< linguistic2::XLinguProperties > GetLinguPropertySet()
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)