no need to use UNO to get to ChineseTranslation_UnoDialog

Change-Id: Ibcae13ba0b96b283d595e2e9f3dc8e99548c892d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186498
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2025-06-14 19:34:28 +02:00
committed by Noel Grandin
parent 39f2c62847
commit f9a01110b5
18 changed files with 242 additions and 606 deletions
@@ -0,0 +1,83 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#pragma once
#include <sal/config.h>
#include <svx/svxdllapi.h>
#include <memory>
#include <com/sun/star/awt/XWindow.hpp>
#include <cppuhelper/implbase.hxx>
#include <comphelper/interfacecontainer4.hxx>
#include <mutex>
namespace textconversiondlgs
{
/** This class provides the chinese translation dialog as a uno component.
It can be created via lang::XMultiComponentFactory::createInstanceWithContext
with servicename "com.sun.star.linguistic2.ChineseTranslationDialog"
or implementation name "com.sun.star.comp.linguistic2.ChineseTranslationDialog"
It can be initialized via the XInitialization interface with the following single parameter:
PropertyValue-Parameter: Name="ParentWindow" Type="awt::XWindow".
It can be executed via the ui::dialogs::XExecutableDialog interface.
Made settings can be retrieved via beans::XPropertySet interface.
Following properties are available (read only and not bound):
1) Name="IsDirectionToSimplified" Type="sal_Bool"
2) Name="IsUseCharacterVariants" Type="sal_Bool"
3) Name="IsTranslateCommonTerms" Type="sal_Bool"
The dialog gets this information from the registry on execute and writes it back to the registry if ended with OK.
*/
class ChineseTranslationDialog;
class TEXTCONVERSIONDLGS_DLLPUBLIC ChineseTranslation_UnoDialog : public ::cppu::WeakImplHelper <>
{
public:
ChineseTranslation_UnoDialog(const css::uno::Reference< css::awt::XWindow >& xParentWindow);
virtual ~ChineseTranslation_UnoDialog() override;
sal_Int16 execute();
bool getIsDirectionToSimplified();
bool getIsTranslateCommonTerms();
private:
void impl_DeleteDialog();
private:
css::uno::Reference< css::awt::XWindow > m_xParentWindow;
std::unique_ptr<ChineseTranslationDialog> m_xDialog;
};
} //end namespace textconversiondlgs
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+7
View File
@@ -36,6 +36,13 @@
#endif
#define SVXCORE_DLLPRIVATE SAL_DLLPRIVATE
#if defined(TEXTCONVERSIONDLGS_DLLIMPLEMENTATION)
#define TEXTCONVERSIONDLGS_DLLPUBLIC SAL_DLLPUBLIC_EXPORT
#else
#define TEXTCONVERSIONDLGS_DLLPUBLIC SAL_DLLPUBLIC_IMPORT
#endif
#define TEXTCONVERSIONDLGS_DLLPRIVATE SAL_DLLPRIVATE
#endif // INCLUDED_SVX_SVXDLLAPI_H
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+1
View File
@@ -90,6 +90,7 @@ $(eval $(call gb_Library_use_libraries,sc,\
svt \
svx \
svxcore \
textconversiondlgs \
tk \
tl \
ucbhelper \
+22 -59
View File
@@ -40,6 +40,7 @@
#include <vcl/svapp.hxx>
#include <vcl/weld.hxx>
#include <svx/svxdlg.hxx>
#include <svx/chinese_translation_unodialog.hxx>
#include <sot/formats.hxx>
#include <svx/postattr.hxx>
#include <editeng/fontitem.hxx>
@@ -2010,68 +2011,30 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
case SID_CHINESE_CONVERSION:
{
//open ChineseTranslationDialog
uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext());
if(xContext.is())
rtl::Reference< textconversiondlgs::ChineseTranslation_UnoDialog > xDialog(new textconversiondlgs::ChineseTranslation_UnoDialog({}));
//execute dialog
sal_Int16 nDialogRet = xDialog->execute();
if( RET_OK == nDialogRet )
{
Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
if(xMCF.is())
{
Reference< ui::dialogs::XExecutableDialog > xDialog(
xMCF->createInstanceWithContext(
u"com.sun.star.linguistic2.ChineseTranslationDialog"_ustr
, xContext),
UNO_QUERY);
Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
if( xInit.is() )
{
// initialize dialog
uno::Sequence<uno::Any> aSeq(comphelper::InitAnyPropertySequence(
{
{"ParentWindow", uno::Any(Reference< awt::XWindow >())}
}));
xInit->initialize( aSeq );
//get some parameters from the dialog
bool bToSimplified = xDialog->getIsDirectionToSimplified();
bool bUseVariants = false;
bool bCommonTerms = xDialog->getIsTranslateCommonTerms();
//execute dialog
sal_Int16 nDialogRet = xDialog->execute();
if( RET_OK == nDialogRet )
{
//get some parameters from the dialog
bool bToSimplified = true;
bool bUseVariants = true;
bool bCommonTerms = true;
Reference< beans::XPropertySet > xProp( xDialog, UNO_QUERY );
if( xProp.is() )
{
try
{
xProp->getPropertyValue(u"IsDirectionToSimplified"_ustr) >>= bToSimplified;
xProp->getPropertyValue(u"IsUseCharacterVariants"_ustr) >>= bUseVariants;
xProp->getPropertyValue(u"IsTranslateCommonTerms"_ustr) >>= bCommonTerms;
}
catch( Exception& )
{
}
}
//execute translation
LanguageType eSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
LanguageType eTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
if( !bCommonTerms )
nOptions |= i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
//execute translation
LanguageType eSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
LanguageType eTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
if( !bCommonTerms )
nOptions |= i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
vcl::Font aTargetFont = OutputDevice::GetDefaultFont(
DefaultFontType::CJK_SPREADSHEET,
eTargetLang, GetDefaultFontFlags::OnlyOne );
ScConversionParam aConvParam( SC_CONVERSION_CHINESE_TRANSL,
eSourceLang, eTargetLang, std::move(aTargetFont), nOptions, false );
pTabViewShell->DoSheetConversion( aConvParam );
}
}
Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
if( xComponent.is() )
xComponent->dispose();
}
vcl::Font aTargetFont = OutputDevice::GetDefaultFont(
DefaultFontType::CJK_SPREADSHEET,
eTargetLang, GetDefaultFontFlags::OnlyOne );
ScConversionParam aConvParam( SC_CONVERSION_CHINESE_TRANSL,
eSourceLang, eTargetLang, std::move(aTargetFont), nOptions, false );
pTabViewShell->DoSheetConversion( aConvParam );
}
}
break;
+1
View File
@@ -67,6 +67,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_ucalc$(1), \
svx \
svxcore \
test \
textconversiondlgs \
tk \
tl \
ucbhelper \
+1
View File
@@ -46,6 +46,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sd_uimpress,\
svxcore \
svx \
test \
textconversiondlgs \
tk \
tl \
ucbhelper \
+1
View File
@@ -94,6 +94,7 @@ $(eval $(call gb_Library_use_libraries,sd,\
svt \
svxcore \
svx \
textconversiondlgs \
tk \
tl \
ucbhelper \
+20 -56
View File
@@ -27,6 +27,7 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/propertysequence.hxx>
#include <svl/style.hxx>
#include <svx/chinese_translation_unodialog.hxx>
#include <editeng/eeitem.hxx>
#include <editeng/langitem.hxx>
#include <editeng/fontitem.hxx>
@@ -183,68 +184,31 @@ void FuHangulHanjaConversion::ConvertStyles( LanguageType nTargetLanguage, const
void FuHangulHanjaConversion::StartChineseConversion()
{
//open ChineseTranslationDialog
uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext());
if(!xContext.is())
return;
rtl::Reference< textconversiondlgs::ChineseTranslation_UnoDialog > xDialog(new textconversiondlgs::ChineseTranslation_UnoDialog({}));
Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
if(!xMCF.is())
return;
Reference< ui::dialogs::XExecutableDialog > xDialog(
xMCF->createInstanceWithContext(u"com.sun.star.linguistic2.ChineseTranslationDialog"_ustr
, xContext), UNO_QUERY);
Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
if( xInit.is() )
//execute dialog
sal_Int16 nDialogRet = xDialog->execute();
if( RET_OK == nDialogRet )
{
// initialize dialog
Reference< awt::XWindow > xDialogParentWindow;
Sequence<Any> aSeq(comphelper::InitAnyPropertySequence(
{
{"ParentWindow", uno::Any(xDialogParentWindow)}
}));
xInit->initialize( aSeq );
//get some parameters from the dialog
bool bToSimplified = xDialog->getIsDirectionToSimplified();
bool bUseVariants = false;
bool bCommonTerms = xDialog->getIsTranslateCommonTerms();
//execute dialog
sal_Int16 nDialogRet = xDialog->execute();
if( RET_OK == nDialogRet )
{
//get some parameters from the dialog
bool bToSimplified = true;
bool bUseVariants = true;
bool bCommonTerms = true;
Reference< beans::XPropertySet > xProp( xDialog, UNO_QUERY );
if( xProp.is() )
{
try
{
xProp->getPropertyValue( u"IsDirectionToSimplified"_ustr ) >>= bToSimplified;
xProp->getPropertyValue( u"IsUseCharacterVariants"_ustr ) >>= bUseVariants;
xProp->getPropertyValue( u"IsTranslateCommonTerms"_ustr ) >>= bCommonTerms;
}
catch( Exception& )
{
}
}
//execute translation
LanguageType nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
LanguageType nTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
if( !bCommonTerms )
nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
//execute translation
LanguageType nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
LanguageType nTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
if( !bCommonTerms )
nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
vcl::Font aTargetFont = OutputDevice::GetDefaultFont(
DefaultFontType::CJK_PRESENTATION,
nTargetLang, GetDefaultFontFlags::OnlyOne );
vcl::Font aTargetFont = OutputDevice::GetDefaultFont(
DefaultFontType::CJK_PRESENTATION,
nTargetLang, GetDefaultFontFlags::OnlyOne );
StartConversion( nSourceLang, nTargetLang, &aTargetFont, nOptions, false );
ConvertStyles( nTargetLang, &aTargetFont );
}
StartConversion( nSourceLang, nTargetLang, &aTargetFont, nOptions, false );
ConvertStyles( nTargetLang, &aTargetFont );
}
Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
if( xComponent.is() )
xComponent->dispose();
}
} // end of namespace
+1 -1
View File
@@ -5630,6 +5630,7 @@ include/svx/autoformathelper.hxx
include/svx/bmpmask.hxx
include/svx/charmap.hxx
include/svx/charthelper.hxx
include/svx/chinese_translation_unodialog.hxx
include/svx/chrtitem.hxx
include/svx/clipboardctl.hxx
include/svx/colorwindow.hxx
@@ -11687,7 +11688,6 @@ svx/source/uitest/uiobject.cxx
svx/source/unodialogs/textconversiondlgs/chinese_dictionarydialog.cxx
svx/source/unodialogs/textconversiondlgs/chinese_dictionarydialog.hxx
svx/source/unodialogs/textconversiondlgs/chinese_translation_unodialog.cxx
svx/source/unodialogs/textconversiondlgs/chinese_translation_unodialog.hxx
svx/source/unodialogs/textconversiondlgs/chinese_translationdialog.cxx
svx/source/unodraw/UnoGraphicExporter.cxx
svx/source/unodraw/UnoNameItemTable.cxx
+4 -2
View File
@@ -19,8 +19,6 @@
$(eval $(call gb_Library_Library,textconversiondlgs))
$(eval $(call gb_Library_set_componentfile,textconversiondlgs,svx/util/textconversiondlgs,services))
$(eval $(call gb_Library_set_include,textconversiondlgs,\
-I$(SRCDIR)/svx/inc \
$$(INCLUDE) \
@@ -30,6 +28,10 @@ $(eval $(call gb_Library_use_external,textconversiondlgs,boost_headers))
$(eval $(call gb_Library_use_sdk_api,textconversiondlgs))
$(eval $(call gb_Library_add_defs,textconversiondlgs,\
-DTEXTCONVERSIONDLGS_DLLIMPLEMENTATION \
))
$(eval $(call gb_Library_use_libraries,textconversiondlgs,\
comphelper \
cppuhelper \
@@ -18,7 +18,7 @@
*/
#include "chinese_translation_unodialog.hxx"
#include <svx/chinese_translation_unodialog.hxx>
#include "chinese_translationdialog.hxx"
#include <vcl/svapp.hxx>
#include <cppuhelper/supportsservice.hxx>
@@ -29,10 +29,9 @@ namespace textconversiondlgs
{
using namespace ::com::sun::star;
ChineseTranslation_UnoDialog::ChineseTranslation_UnoDialog()
: m_bDisposed(false)
, m_bInDispose(false)
ChineseTranslation_UnoDialog::ChineseTranslation_UnoDialog(const css::uno::Reference< css::awt::XWindow >& xParentWindow)
{
m_xParentWindow = xParentWindow;
}
ChineseTranslation_UnoDialog::~ChineseTranslation_UnoDialog()
@@ -50,55 +49,11 @@ void ChineseTranslation_UnoDialog::impl_DeleteDialog()
}
}
// lang::XServiceInfo
OUString SAL_CALL ChineseTranslation_UnoDialog::getImplementationName()
{
return u"com.sun.star.comp.linguistic2.ChineseTranslationDialog"_ustr;
}
sal_Bool SAL_CALL ChineseTranslation_UnoDialog::supportsService( const OUString& ServiceName )
{
return cppu::supportsService(this, ServiceName);
}
uno::Sequence< OUString > SAL_CALL ChineseTranslation_UnoDialog::getSupportedServiceNames()
{
return { u"com.sun.star.linguistic2.ChineseTranslationDialog"_ustr };
}
// ui::dialogs::XExecutableDialog
void SAL_CALL ChineseTranslation_UnoDialog::setTitle( const OUString& )
{
//not implemented - fell free to do so, if you do need this
}
void SAL_CALL ChineseTranslation_UnoDialog::initialize( const uno::Sequence< uno::Any >& aArguments )
{
SolarMutexGuard aSolarGuard;
if( m_bDisposed || m_bInDispose )
return;
for(const uno::Any& rArgument : aArguments)
{
beans::PropertyValue aProperty;
if(rArgument >>= aProperty)
{
if( aProperty.Name == "ParentWindow" )
{
aProperty.Value >>= m_xParentWindow;
}
}
}
}
sal_Int16 SAL_CALL ChineseTranslation_UnoDialog::execute()
sal_Int16 ChineseTranslation_UnoDialog::execute()
{
sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL;
{
SolarMutexGuard aSolarGuard;
if (m_bDisposed || m_bInDispose)
return nRet;
if (!m_xDialog)
m_xDialog.reset(new ChineseTranslationDialog(Application::GetFrameWeld(m_xParentWindow)));
nRet = m_xDialog->run();
@@ -108,120 +63,30 @@ sal_Int16 SAL_CALL ChineseTranslation_UnoDialog::execute()
return nRet;
}
// lang::XComponent
void SAL_CALL ChineseTranslation_UnoDialog::dispose()
bool ChineseTranslation_UnoDialog::getIsDirectionToSimplified()
{
lang::EventObject aEvt;
{
SolarMutexGuard aSolarGuard;
if( m_bDisposed || m_bInDispose )
return;
m_bInDispose = true;
impl_DeleteDialog();
m_xParentWindow = nullptr;
m_bDisposed = true;
aEvt.Source = static_cast< XComponent * >( this );
}
std::unique_lock aGuard(m_aContainerMutex);
m_aDisposeEventListeners.disposeAndClear( aGuard, aEvt );
}
void SAL_CALL ChineseTranslation_UnoDialog::addEventListener( const uno::Reference< lang::XEventListener > & xListener )
{
SolarMutexGuard aSolarGuard;
if( m_bDisposed || m_bInDispose )
return;
std::unique_lock aGuard(m_aContainerMutex);
m_aDisposeEventListeners.addInterface( aGuard, xListener );
}
void SAL_CALL ChineseTranslation_UnoDialog::removeEventListener( const uno::Reference< lang::XEventListener > & xListener )
{
SolarMutexGuard aSolarGuard;
if( m_bDisposed || m_bInDispose )
return;
std::unique_lock aGuard(m_aContainerMutex);
m_aDisposeEventListeners.removeInterface( aGuard, xListener );
}
// XPropertySet
uno::Reference< beans::XPropertySetInfo > SAL_CALL ChineseTranslation_UnoDialog::getPropertySetInfo( )
{
return nullptr;
}
void SAL_CALL ChineseTranslation_UnoDialog::setPropertyValue( const OUString&, const uno::Any& )
{
//only read only properties
throw beans::PropertyVetoException();
}
uno::Any SAL_CALL ChineseTranslation_UnoDialog::getPropertyValue( const OUString& rPropertyName )
{
uno::Any aRet;
bool bDirectionToSimplified = true;
bool bTranslateCommonTerms = false;
{
SolarMutexGuard aSolarGuard;
if (m_bDisposed || m_bInDispose || !m_xDialog)
return aRet;
m_xDialog->getSettings(bDirectionToSimplified, bTranslateCommonTerms);
}
return bDirectionToSimplified;
}
bool ChineseTranslation_UnoDialog::getIsTranslateCommonTerms()
{
bool bDirectionToSimplified = true;
bool bTranslateCommonTerms = false;
if( rPropertyName == "IsDirectionToSimplified" )
{
aRet <<= bDirectionToSimplified;
SolarMutexGuard aSolarGuard;
m_xDialog->getSettings(bDirectionToSimplified, bTranslateCommonTerms);
}
else if( rPropertyName == "IsUseCharacterVariants" )
{
aRet <<= false;
}
else if( rPropertyName == "IsTranslateCommonTerms" )
{
aRet <<= bTranslateCommonTerms;
}
else
{
throw beans::UnknownPropertyException( rPropertyName, getXWeak());
}
return aRet;
return bTranslateCommonTerms;
}
void SAL_CALL ChineseTranslation_UnoDialog::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& )
{
//only not bound properties -> ignore listener
}
void SAL_CALL ChineseTranslation_UnoDialog::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& )
{
//only not bound properties -> ignore listener
}
void SAL_CALL ChineseTranslation_UnoDialog::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& )
{
//only not bound properties -> ignore listener
}
void SAL_CALL ChineseTranslation_UnoDialog::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& )
{
//only not bound properties -> ignore listener
}
} //end namespace
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
svx_ChineseTranslation_UnoDialog_get_implementation(
css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
{
return cppu::acquire(new textconversiondlgs::ChineseTranslation_UnoDialog());
}
} //namespace textconversiondlgs
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@@ -1,119 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#pragma once
#include <sal/config.h>
#include <memory>
#include <com/sun/star/awt/XWindow.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
#include <cppuhelper/implbase.hxx>
#include <comphelper/interfacecontainer4.hxx>
#include <mutex>
namespace textconversiondlgs
{
/** This class provides the chinese translation dialog as a uno component.
It can be created via lang::XMultiComponentFactory::createInstanceWithContext
with servicename "com.sun.star.linguistic2.ChineseTranslationDialog"
or implementation name "com.sun.star.comp.linguistic2.ChineseTranslationDialog"
It can be initialized via the XInitialization interface with the following single parameter:
PropertyValue-Parameter: Name="ParentWindow" Type="awt::XWindow".
It can be executed via the ui::dialogs::XExecutableDialog interface.
Made settings can be retrieved via beans::XPropertySet interface.
Following properties are available (read only and not bound):
1) Name="IsDirectionToSimplified" Type="sal_Bool"
2) Name="IsUseCharacterVariants" Type="sal_Bool"
3) Name="IsTranslateCommonTerms" Type="sal_Bool"
The dialog gets this information from the registry on execute and writes it back to the registry if ended with OK.
*/
class ChineseTranslationDialog;
class ChineseTranslation_UnoDialog : public ::cppu::WeakImplHelper <
css::ui::dialogs::XExecutableDialog
, css::lang::XInitialization
, css::beans::XPropertySet
, css::lang::XComponent
, css::lang::XServiceInfo
>
{
public:
ChineseTranslation_UnoDialog();
virtual ~ChineseTranslation_UnoDialog() override;
// lang::XServiceInfo
virtual OUString SAL_CALL getImplementationName() override;
virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
// lang::XInitialization
virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
// ui::dialogs::XExecutableDialog
virtual void SAL_CALL setTitle( const OUString& aTitle ) override;
virtual sal_Int16 SAL_CALL execute( ) override;
// beans::XPropertySet
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
// lang::XComponent
virtual void SAL_CALL dispose() override;
virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener > & xListener ) override;
virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener > & xListener ) override;
private:
void impl_DeleteDialog();
private:
css::uno::Reference<
css::awt::XWindow > m_xParentWindow;
std::unique_ptr<ChineseTranslationDialog> m_xDialog;
bool m_bDisposed; ///Dispose call ready.
bool m_bInDispose;///In dispose call
std::mutex m_aContainerMutex;
comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> m_aDisposeEventListeners;
};
} //end namespace
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
-26
View File
@@ -1,26 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
xmlns="http://openoffice.org/2010/uno-components">
<implementation name="com.sun.star.comp.linguistic2.ChineseTranslationDialog"
constructor="svx_ChineseTranslation_UnoDialog_get_implementation">
<service name="com.sun.star.linguistic2.ChineseTranslationDialog"/>
</implementation>
</component>
+1
View File
@@ -56,6 +56,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_uwriter, \
svxcore \
swd \
test \
textconversiondlgs \
tk \
tl \
ucbhelper \
+1
View File
@@ -76,6 +76,7 @@ $(eval $(call gb_Library_use_libraries,sw,\
svt \
svx \
svxcore \
textconversiondlgs \
tk \
tl \
ucbhelper \
+22 -58
View File
@@ -52,6 +52,7 @@
#include <editeng/udlnitem.hxx>
#include <editeng/fontitem.hxx>
#include <svx/clipfmtitem.hxx>
#include <svx/chinese_translation_unodialog.hxx>
#include <svl/stritem.hxx>
#include <svl/slstitm.hxx>
#include <editeng/frmdiritem.hxx>
@@ -1357,69 +1358,32 @@ void SwAnnotationShell::ExecLingu(SfxRequest &rReq)
case SID_CHINESE_CONVERSION:
{
//open ChineseTranslationDialog
uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext());
if(xContext.is())
{
Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
if(xMCF.is())
{
Reference< ui::dialogs::XExecutableDialog > xDialog(
xMCF->createInstanceWithContext(
u"com.sun.star.linguistic2.ChineseTranslationDialog"_ustr, xContext),
UNO_QUERY);
Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
if( xInit.is() )
{
// initialize dialog
uno::Sequence<uno::Any> aSeq(comphelper::InitAnyPropertySequence(
{
{"ParentWindow", uno::Any(Reference<awt::XWindow>())}
}));
xInit->initialize( aSeq );
//open ChineseTranslationDialog
rtl::Reference< textconversiondlgs::ChineseTranslation_UnoDialog > xDialog(new textconversiondlgs::ChineseTranslation_UnoDialog({}));
//execute dialog
sal_Int16 nDialogRet = xDialog->execute();
if( RET_OK == nDialogRet )
{
//get some parameters from the dialog
bool bToSimplified = true;
bool bUseVariants = true;
bool bCommonTerms = true;
Reference< beans::XPropertySet > xProp( xDialog, UNO_QUERY );
if( xProp.is() )
{
try
{
xProp->getPropertyValue( u"IsDirectionToSimplified"_ustr ) >>= bToSimplified;
xProp->getPropertyValue( u"IsUseCharacterVariants"_ustr ) >>= bUseVariants;
xProp->getPropertyValue( u"IsTranslateCommonTerms"_ustr ) >>= bCommonTerms;
}
catch (const Exception&)
{
}
}
//execute dialog
sal_Int16 nDialogRet = xDialog->execute();
if( RET_OK == nDialogRet )
{
//get some parameters from the dialog
bool bToSimplified = xDialog->getIsDirectionToSimplified();
bool bUseVariants = false;
bool bCommonTerms = xDialog->getIsTranslateCommonTerms();
//execute translation
LanguageType nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
LanguageType nTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
if( !bCommonTerms )
nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
//execute translation
LanguageType nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
LanguageType nTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
if( !bCommonTerms )
nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
vcl::Font aTargetFont = OutputDevice::GetDefaultFont( DefaultFontType::CJK_TEXT,
nTargetLang, GetDefaultFontFlags::OnlyOne );
vcl::Font aTargetFont = OutputDevice::GetDefaultFont( DefaultFontType::CJK_TEXT,
nTargetLang, GetDefaultFontFlags::OnlyOne );
pOLV->StartTextConversion(rReq.GetFrameWeld(), nSourceLang, nTargetLang, &aTargetFont, nOptions, false, false);
}
}
Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
if( xComponent.is() )
xComponent->dispose();
}
}
pOLV->StartTextConversion(rReq.GetFrameWeld(), nSourceLang, nTargetLang, &aTargetFont, nOptions, false, false);
}
break;
}
break;
}
if (bRestoreSelection)
+5 -42
View File
@@ -30,6 +30,7 @@
#include <sfx2/objface.hxx>
#include <svx/svdotext.hxx>
#include <svx/sdooitm.hxx>
#include <svx/chinese_translation_unodialog.hxx>
#include <editeng/editeng.hxx>
#include <editeng/editview.hxx>
#include <editeng/eeitem.hxx>
@@ -284,50 +285,16 @@ void SwDrawTextShell::ExecDrawLingu(SfxRequest const &rReq)
case SID_CHINESE_CONVERSION:
{
//open ChineseTranslationDialog
const Reference<XComponentContext>& xContext = comphelper::getProcessComponentContext();
if (!xContext.is())
return;
Reference<lang::XMultiComponentFactory> xMCF(xContext->getServiceManager());
if (!xMCF.is())
return;
Reference<ui::dialogs::XExecutableDialog> xDialog(
xMCF->createInstanceWithContext(u"com.sun.star.linguistic2.ChineseTranslationDialog"_ustr, xContext), UNO_QUERY);
Reference<lang::XInitialization> xInit(xDialog, UNO_QUERY);
if (!xInit.is())
return;
// initialize dialog
uno::Sequence<uno::Any> aSequence(comphelper::InitAnyPropertySequence(
{
{"ParentWindow", uno::Any(Reference<awt::XWindow>())}
}));
xInit->initialize( aSequence );
rtl::Reference<textconversiondlgs::ChineseTranslation_UnoDialog> xDialog(new textconversiondlgs::ChineseTranslation_UnoDialog({}));
//execute dialog
sal_Int16 nDialogRet = xDialog->execute();
if(RET_OK == nDialogRet)
{
//get some parameters from the dialog
bool bToSimplified = true;
bool bUseVariants = true;
bool bCommonTerms = true;
Reference<beans::XPropertySet> xPropertySet(xDialog, UNO_QUERY);
if (xPropertySet.is())
{
try
{
xPropertySet->getPropertyValue(u"IsDirectionToSimplified"_ustr) >>= bToSimplified;
xPropertySet->getPropertyValue(u"IsUseCharacterVariants"_ustr) >>= bUseVariants;
xPropertySet->getPropertyValue(u"IsTranslateCommonTerms"_ustr) >>= bCommonTerms;
}
catch (const Exception&)
{
}
}
bool bToSimplified = xDialog->getIsDirectionToSimplified();
bool bUseVariants = false;
bool bCommonTerms = xDialog->getIsTranslateCommonTerms();
//execute translation
LanguageType nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
@@ -340,10 +307,6 @@ void SwDrawTextShell::ExecDrawLingu(SfxRequest const &rReq)
pOutlinerView->StartTextConversion(rReq.GetFrameWeld(), nSourceLang, nTargetLang, &aTargetFont, nOptions, false, false);
}
Reference<lang::XComponent> xComponent(xDialog, UNO_QUERY);
if (xComponent.is())
xComponent->dispose();
}
break;
+56 -92
View File
@@ -38,6 +38,7 @@
#include <svx/ehdl.hxx>
#include <svx/svxerr.hxx>
#include <svx/svxdlg.hxx>
#include <svx/chinese_translation_unodialog.hxx>
#include <osl/diagnose.h>
#include <swwait.hxx>
#include <uitool.hxx>
@@ -106,101 +107,64 @@ void SwView::ExecLingu(SfxRequest &rReq)
case SID_CHINESE_CONVERSION:
{
//open ChineseTranslationDialog
uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext());
if(xContext.is())
Reference<awt::XWindow> xParentWindow;
if (weld::Window* pParentWindow = rReq.GetFrameWeld())
xParentWindow = pParentWindow->GetXWindow();
rtl::Reference< textconversiondlgs::ChineseTranslation_UnoDialog > xDialog(new textconversiondlgs::ChineseTranslation_UnoDialog(xParentWindow));
//execute dialog
sal_Int16 nDialogRet = xDialog->execute();
if( RET_OK == nDialogRet )
{
Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
if(xMCF.is())
//get some parameters from the dialog
bool bToSimplified = xDialog->getIsDirectionToSimplified();
bool bUseVariants = false;
bool bCommonTerms = xDialog->getIsTranslateCommonTerms();
//execute translation
LanguageType nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
LanguageType nTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
if( !bCommonTerms )
nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
vcl::Font aTargetFont = OutputDevice::GetDefaultFont( DefaultFontType::CJK_TEXT,
nTargetLang, GetDefaultFontFlags::OnlyOne );
// disallow formatting, updating the view, ... while
// converting the document. (saves time)
// Also remember the current view and cursor position for later
m_pWrtShell->StartAction();
// remember cursor position data for later restoration of the cursor
const SwPosition *pPoint = m_pWrtShell->GetCursor()->GetPoint();
bool bRestoreCursor = pPoint->GetNode().IsTextNode();
const SwNodeIndex aPointNodeIndex( pPoint->GetNode() );
sal_Int32 nPointIndex = pPoint->GetContentIndex();
// since this conversion is not interactive the whole converted
// document should be undone in a single undo step.
m_pWrtShell->StartUndo( SwUndoId::OVERWRITE );
StartTextConversion( nSourceLang, nTargetLang, &aTargetFont, nOptions, false );
m_pWrtShell->EndUndo( SwUndoId::OVERWRITE );
if (bRestoreCursor)
{
Reference< ui::dialogs::XExecutableDialog > xDialog(
xMCF->createInstanceWithContext(
u"com.sun.star.linguistic2.ChineseTranslationDialog"_ustr, xContext),
UNO_QUERY);
Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
if( xInit.is() )
{
Reference<awt::XWindow> xParentWindow;
if (weld::Window* pParentWindow = rReq.GetFrameWeld())
xParentWindow = pParentWindow->GetXWindow();
// initialize dialog
uno::Sequence<uno::Any> aSeq(comphelper::InitAnyPropertySequence(
{
{"ParentWindow", uno::Any(xParentWindow)}
}));
xInit->initialize( aSeq );
//execute dialog
sal_Int16 nDialogRet = xDialog->execute();
if( RET_OK == nDialogRet )
{
//get some parameters from the dialog
bool bToSimplified = true;
bool bUseVariants = true;
bool bCommonTerms = true;
Reference< beans::XPropertySet > xProp( xDialog, UNO_QUERY );
if( xProp.is() )
{
try
{
xProp->getPropertyValue( u"IsDirectionToSimplified"_ustr ) >>= bToSimplified;
xProp->getPropertyValue( u"IsUseCharacterVariants"_ustr ) >>= bUseVariants;
xProp->getPropertyValue( u"IsTranslateCommonTerms"_ustr ) >>= bCommonTerms;
}
catch (const Exception&)
{
}
}
//execute translation
LanguageType nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
LanguageType nTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
if( !bCommonTerms )
nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
vcl::Font aTargetFont = OutputDevice::GetDefaultFont( DefaultFontType::CJK_TEXT,
nTargetLang, GetDefaultFontFlags::OnlyOne );
// disallow formatting, updating the view, ... while
// converting the document. (saves time)
// Also remember the current view and cursor position for later
m_pWrtShell->StartAction();
// remember cursor position data for later restoration of the cursor
const SwPosition *pPoint = m_pWrtShell->GetCursor()->GetPoint();
bool bRestoreCursor = pPoint->GetNode().IsTextNode();
const SwNodeIndex aPointNodeIndex( pPoint->GetNode() );
sal_Int32 nPointIndex = pPoint->GetContentIndex();
// since this conversion is not interactive the whole converted
// document should be undone in a single undo step.
m_pWrtShell->StartUndo( SwUndoId::OVERWRITE );
StartTextConversion( nSourceLang, nTargetLang, &aTargetFont, nOptions, false );
m_pWrtShell->EndUndo( SwUndoId::OVERWRITE );
if (bRestoreCursor)
{
SwTextNode *pTextNode = aPointNodeIndex.GetNode().GetTextNode();
// check for unexpected error case
OSL_ENSURE(pTextNode && pTextNode->GetText().getLength() >= nPointIndex,
"text missing: corrupted node?" );
// restore cursor to its original position
if (!pTextNode || pTextNode->GetText().getLength() < nPointIndex)
m_pWrtShell->GetCursor()->GetPoint()->Assign( aPointNodeIndex );
else
m_pWrtShell->GetCursor()->GetPoint()->Assign( *pTextNode, nPointIndex );
}
// enable all, restore view and cursor position
m_pWrtShell->EndAction();
}
}
Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
if( xComponent.is() )
xComponent->dispose();
SwTextNode *pTextNode = aPointNodeIndex.GetNode().GetTextNode();
// check for unexpected error case
OSL_ENSURE(pTextNode && pTextNode->GetText().getLength() >= nPointIndex,
"text missing: corrupted node?" );
// restore cursor to its original position
if (!pTextNode || pTextNode->GetText().getLength() < nPointIndex)
m_pWrtShell->GetCursor()->GetPoint()->Assign( aPointNodeIndex );
else
m_pWrtShell->GetCursor()->GetPoint()->Assign( *pTextNode, nPointIndex );
}
// enable all, restore view and cursor position
m_pWrtShell->EndAction();
}
break;
}