26#include <com/sun/star/uno/Sequence.hxx>
27#include <com/sun/star/i18n/BreakIterator.hpp>
28#include <com/sun/star/i18n/ScriptType.hpp>
29#include <com/sun/star/i18n/UnicodeScript.hpp>
30#include <com/sun/star/i18n/TextConversion.hpp>
31#include <com/sun/star/i18n/XExtendedTextConversion.hpp>
32#include <com/sun/star/i18n/TextConversionType.hpp>
33#include <com/sun/star/i18n/TextConversionOption.hpp>
37#include <osl/diagnose.h>
43#define HHC HangulHanjaConversion
53 using namespace ::com::sun::star::i18n::TextConversionOption;
54 using namespace ::com::sun::star::i18n::TextConversionType;
71 Reference< XComponentContext >
73 Reference< XExtendedTextConversion >
121 const Reference< XComponentContext >& rxContext,
122 const lang::Locale& _rSourceLocale,
123 const lang::Locale& _rTargetLocale,
125 sal_Int32 _nConvOptions,
126 bool _bIsInteractive,
172 void implChange(
const OUString& _rChangeInto );
207 bool implUpdateSuggestions(
const bool _bAllowSearchNextConvertibleText=
false,
const sal_Int32 _nStartAt=-1 );
230 const Reference< XComponentContext >& rxContext,
231 const lang::Locale& _rSourceLocale,
232 const lang::Locale& _rTargetLocale,
235 bool _bIsInteractive,
237 : m_pUIParent( pUIParent )
239 , m_aSourceLocale( _rSourceLocale )
240 , m_nSourceLang(
LanguageTag::convertToLanguageType( _rSourceLocale ) )
241 , m_nTargetLang(
LanguageTag::convertToLanguageType( _rTargetLocale ) )
242 , m_pTargetFont( _pTargetFont )
243 , m_nConvOptions(_nOptions)
244 , m_bIsInteractive( _bIsInteractive )
245 , m_pAntiImpl( _pAntiImpl )
246 , m_bByCharacter((_nOptions & CHARACTER_BY_CHARACTER) != 0)
247 , m_eConversionFormat(
HHC::eSimpleConversion)
248 , m_ePrimaryConversionDirection(
HHC::eHangulToHanja)
249 , m_eCurrentConversionDirection(
HHC::eHangulToHanja)
251 , m_nCurrentStartIndex( 0 )
252 , m_nCurrentEndIndex( 0 )
253 , m_nReplacementBaseIndex( 0 )
254 , m_nCurrentConversionOption( TextConversionOption::
NONE )
255 , m_nCurrentConversionType( -1 )
256 , m_bTryBothDirections( true )
260 DBG_ASSERT(
m_xContext.is(),
"HangulHanjaConversion_Impl::HangulHanjaConversion_Impl: no ORB!" );
271 OSL_FAIL(
"failed to determine conversion type from languages" );
305 sal_Int16 nConversionType = -1;
308 else if (
m_eConvType == HHC::eConvSimplifiedTraditional)
310 DBG_ASSERT( nConversionType != -1,
"unexpected conversion type" );
311 return nConversionType;
318 if( _bAllowSearchNextConvertibleText )
319 nStartSearch = _nStartAt;
328 if (
m_eConvType == HHC::eConvSimplifiedTraditional)
331 bool bFoundAny =
true;
334 TextConversionResult aResult =
m_xConverter->getConversions(
342 const bool bFoundPrimary = aResult.Boundary.startPos < aResult.Boundary.endPos;
343 bFoundAny = bFoundPrimary;
347 TextConversionResult aSecondResult =
m_xConverter->getConversions(
355 if ( aSecondResult.Boundary.startPos < aSecondResult.Boundary.endPos )
362 || ( aSecondResult.Boundary.startPos < aResult.Boundary.startPos )
366 aResult = aSecondResult;
370 ? HHC::eHanjaToHangul : HHC::eHangulToHanja;
376 if( _bAllowSearchNextConvertibleText )
387 && aResult.Boundary.endPos != aResult.Boundary.startPos )
409 Sequence< OUString > aTmp(
nCount);
410 auto pTmp = aTmp.getArray();
411 pTmp[0]=aRecentlyUsed->second;
444 HHC::ConversionDirection eDialogDirection =
m_pConversionDialog->GetDirection( HHC::eHangulToHanja );
464 const bool bAllowImplicitChanges =
m_eConvType == HHC::eConvSimplifiedTraditional;
513 "HangulHanjaConversion_Impl::GetCurrentUnit: invalid index into current portion!" );
515 "HangulHanjaConversion_Impl::GetCurrentUnit: invalid index into current portion!" );
517 "HangulHanjaConversion_Impl::GetCurrentUnit: invalid interval!" );
533 StringMap::const_iterator aChangeListPos =
m_aChangeList.find( sCurrentUnit );
534 const bool bAlwaysChangeThis =
m_aChangeList.end() != aChangeListPos;
545 else if (bAutoChange)
549 else if ( bAlwaysChangeThis )
553 else if ( !bAlwaysIgnoreThis )
579 bool bSuccess =
true;
587 Reference< XBreakIterator > xBreakIter = i18n::BreakIterator::create(
m_xContext );
589 if ( -1 == nNextAsianScript )
596 css::i18n::UnicodeScript nScript = aCharClassificaton.
getScript(
m_sCurrentPortion, sal::static_int_cast< sal_uInt16 >(nNextAsianScript) );
597 if ( ( UnicodeScript_kHangulJamo == nScript )
598 || ( UnicodeScript_kHangulCompatibilityJamo == nScript )
599 || ( UnicodeScript_kHangulSyllable == nScript )
602 rDirection = HHC::eHangulToHanja;
606 rDirection = HHC::eHanjaToHangul;
614 TOOLS_WARN_EXCEPTION(
"editeng",
"HangulHanjaConversion_Impl::implGetConversionDirectionForCurrentPortion" );
630 SAL_INFO(
"editeng",
"HangulHanjaConversion_Impl::DoDocumentConversion: why did you call me if you do have nothing to convert?" );
637 HHC::ConversionDirection eDirection = HHC::eHangulToHanja;
672 DBG_ASSERT( bCompletelyDone,
"HangulHanjaConversion_Impl::DoDocumentConversion: ContinueConversion should have returned true here!" );
688 if( _rChangeInto.isEmpty() )
694 HHC::ReplacementAction eAction( HHC::eExchange );
703 case HHC::eSimpleConversion: eAction = HHC::eExchange;
break;
704 case HHC::eHangulBracketed: eAction = bOriginalIsHangul ? HHC::eOriginalBracketed : HHC::eReplacementBracketed;
break;
705 case HHC::eHanjaBracketed: eAction = bOriginalIsHangul ? HHC::eReplacementBracketed : HHC::eOriginalBracketed;
break;
706 case HHC::eRubyHanjaAbove: eAction = bOriginalIsHangul ? HHC::eReplacementAbove : HHC::eOriginalAbove;
break;
707 case HHC::eRubyHanjaBelow: eAction = bOriginalIsHangul ? HHC::eReplacementBelow : HHC::eOriginalBelow;
break;
708 case HHC::eRubyHangulAbove: eAction = bOriginalIsHangul ? HHC::eOriginalAbove : HHC::eReplacementAbove;
break;
709 case HHC::eRubyHangulBelow: eAction = bOriginalIsHangul ? HHC::eOriginalBelow : HHC::eReplacementBelow;
break;
711 OSL_FAIL(
"HangulHanjaConversion_Impl::implChange: invalid/unexpected conversion format!" );
718 "HangulHanjaConversion_Impl::implChange: invalid replacement base!" );
728 if (
m_eConvType == HHC::eConvSimplifiedTraditional)
738 pNewUnitLang = &nNewUnitLang;
746 Sequence< sal_Int32 > aOffsets;
763 TOOLS_WARN_EXCEPTION(
"editeng",
"HangulHanjaConversion_Impl::implChange: caught unexpected exception!" );
770 _rChangeInto, aOffsets, eAction, pNewUnitLang );
811 implProceed(
false );
816 DBG_ASSERT( m_pConversionDialog,
"HangulHanjaConversion_Impl::OnIgnoreAll: no dialog! How this?" );
818 if ( m_pConversionDialog )
820 OUString sCurrentUnit = m_pConversionDialog->GetCurrentString();
821 DBG_ASSERT( m_sIgnoreList.end() == m_sIgnoreList.find( sCurrentUnit ),
822 "HangulHanjaConversion_Impl, OnIgnoreAll: shouldn't this have been ignored before" );
825 m_sIgnoreList.insert( sCurrentUnit );
828 implProceed(
false );
835 DBG_ASSERT( m_pConversionDialog,
"we should always have a dialog here!" );
836 if( m_pConversionDialog )
837 implChange( m_pConversionDialog->GetCurrentSuggestion( ) );
839 implProceed(
false );
844 DBG_ASSERT( m_pConversionDialog,
"HangulHanjaConversion_Impl::OnChangeAll: no dialog! How this?" );
845 if ( !m_pConversionDialog )
848 OUString sCurrentUnit( m_pConversionDialog->GetCurrentString() );
849 OUString sChangeInto( m_pConversionDialog->GetCurrentSuggestion( ) );
851 if( !sChangeInto.isEmpty() )
854 implChange( sChangeInto );
857 m_aChangeList.emplace( sCurrentUnit, sChangeInto );
861 implProceed(
false );
866 m_bByCharacter = rBox.get_active();
874 DBG_ASSERT( m_pConversionDialog,
"we should always have a dialog here!" );
875 if( m_pConversionDialog )
876 m_eConversionFormat = m_pConversionDialog->GetConversionFormat( );
881 DBG_ASSERT( m_pConversionDialog,
"HangulHanjaConversion_Impl::OnFind: where did this come from?" );
882 if ( !m_pConversionDialog )
887 OUString sNewOriginal( m_pConversionDialog->GetCurrentSuggestion( ) );
888 Sequence< OUString > aSuggestions;
891 TextConversionResult aToHanja =
m_xConverter->getConversions(
893 0, sNewOriginal.getLength(),
895 TextConversionType::TO_HANJA,
896 TextConversionOption::NONE
898 TextConversionResult aToHangul =
m_xConverter->getConversions(
900 0, sNewOriginal.getLength(),
902 TextConversionType::TO_HANGUL,
903 TextConversionOption::NONE
906 bool bHaveToHanja = ( aToHanja.Boundary.startPos < aToHanja.Boundary.endPos );
907 bool bHaveToHangul = ( aToHangul.Boundary.startPos < aToHangul.Boundary.endPos );
909 TextConversionResult* pResult =
nullptr;
910 if ( bHaveToHanja && bHaveToHangul )
912 if ( aToHangul.Boundary.startPos < aToHanja.Boundary.startPos )
913 pResult = &aToHangul;
917 else if ( bHaveToHanja )
923 pResult = &aToHangul;
926 aSuggestions = pResult->Candidates;
928 m_pConversionDialog->SetCurrentString( sNewOriginal, aSuggestions,
false );
929 m_pConversionDialog->FocusSuggestion();
942 const Reference< XComponentContext >& rxContext,
943 const lang::Locale& _rSourceLocale,
const lang::Locale& _rTargetLocale,
945 sal_Int32 _nOptions,
bool _bIsInteractive)
946 :
m_pImpl( new HangulHanjaConversion_Impl( pUIParent, rxContext, _rSourceLocale, _rTargetLocale, _pTargetFont, _nOptions, _bIsInteractive, this ) )
950 HangulHanjaConversion::~HangulHanjaConversion() COVERITY_NOEXCEPT_FALSE
954 void HangulHanjaConversion::SetUseSavedConversionDirectionState(
bool bVal )
956 m_bUseSavedValues = bVal;
959 bool HangulHanjaConversion::IsUseSavedConversionDirectionState()
961 return m_bUseSavedValues;
971 return m_pImpl->GetSourceLang();
976 return m_pImpl->GetTargetLang();
979 const vcl::Font * HangulHanjaConversion::GetTargetFont( )
const
981 return m_pImpl->GetTargetFont();
984 sal_Int32 HangulHanjaConversion::GetConversionOptions( )
const
986 return m_pImpl->GetConvOptions();
989 bool HangulHanjaConversion::IsInteractive( )
const
991 return m_pImpl->IsInteractive();
994 void HangulHanjaConversion::ConvertDocument()
997 m_pImpl->DoDocumentConversion( );
Reference< XComponentContext > m_xContext
css::i18n::UnicodeScript getScript(const OUString &rStr, sal_Int32 nPos) const
virtual VclPtr< AbstractHangulHanjaConversionDialog > CreateHangulHanjaConversionDialog(weld::Widget *pParent)=0
static EditAbstractDialogFactory * Create()
css::uno::Any GetProperty(std::u16string_view rPropertyName) const
DECL_LINK(OnChange, weld::Button &, void)
void implChange(const OUString &_rChangeInto)
LanguageType GetTargetLang() const
sal_Int32 m_nCurrentStartIndex
HHC::ConversionFormat m_eConversionFormat
LanguageType m_nTargetLang
DECL_LINK(OnConversionTypeChanged, weld::Toggleable &, void)
VclPtr< AbstractHangulHanjaConversionDialog > m_pConversionDialog
OUString m_sCurrentPortion
bool implRetrieveNextPortion()
retrieves the next portion, with setting the index members properly
HHC::ConversionDirection m_eCurrentConversionDirection
bool implNextConvertibleUnit(const sal_Int32 _nStartAt)
find the next convertible unit within the current portion
OUString GetCurrentUnit() const
get the string currently considered to be replaced or ignored
void implUpdateData()
read options from configuration, update suggestion list and dialog content
LanguageType m_nCurrentPortionLang
bool implNextConvertible(bool _bRepeatUnit)
find the next convertible piece of text, with possibly advancing to the next portion
HangulHanjaConversion_Impl(weld::Widget *pUIParent, const Reference< XComponentContext > &rxContext, const lang::Locale &_rSourceLocale, const lang::Locale &_rTargetLocale, const vcl::Font *_pTargetFont, sal_Int32 _nConvOptions, bool _bIsInteractive, HangulHanjaConversion *_pAntiImpl)
lang::Locale m_aSourceLocale
weld::Widget * m_pUIParent
Sequence< OUString > m_aCurrentSuggestions
sal_Int32 m_nReplacementBaseIndex
Reference< XComponentContext > m_xContext
std::map< OUString, OUString > StringMap
sal_Int16 implGetConversionType(bool bSwitchDirection=false) const
get the conversion direction dependent from m_eConvType and m_eCurrentConversionDirection in case of ...
DECL_LINK(OnFind, weld::Button &, void)
bool ContinueConversion(bool _bRepeatCurrentUnit)
continue with the conversion, return <TRUE> if and only if the complete conversion is done
sal_Int32 GetConvOptions() const
void implProceed(bool _bRepeatCurrentUnit)
proceed, after the current convertible has been handled
bool m_bShowRecentlyUsedFirst
void DoDocumentConversion()
std::set< OUString > StringBag
bool m_bAutoReplaceUnique
HangulHanjaConversion * m_pAntiImpl
bool m_bIgnorePostPositionalWord
sal_Int16 m_nCurrentConversionType
const vcl::Font * GetTargetFont() const
static StringMap m_aRecentlyUsedList
bool IsInteractive() const
HHC::ConversionType m_eConvType
bool m_bTryBothDirections
weld::Widget * GetUIParent() const
DECL_LINK(OnOptionsChanged, LinkParamNone *, void)
DECL_LINK(OnChangeAll, weld::Button &, void)
sal_Int32 m_nCurrentConversionOption
bool implGetConversionDirectionForCurrentPortion(HHC::ConversionDirection &rDirection)
determine the ConversionDirection for m_sCurrentPortion
DECL_LINK(OnByCharClicked, weld::Toggleable &, void)
DECL_LINK(OnIgnore, weld::Button &, void)
sal_Int32 m_nCurrentEndIndex
const vcl::Font * m_pTargetFont
Reference< XExtendedTextConversion > m_xConverter
DECL_LINK(OnIgnoreAll, weld::Button &, void)
LanguageType GetSourceLang() const
HHC::ConversionDirection m_ePrimaryConversionDirection
bool implUpdateSuggestions(const bool _bAllowSearchNextConvertibleText=false, const sal_Int32 _nStartAt=-1)
member m_aCurrentSuggestions and m_nCurrentEndIndex are updated according to the other settings and c...
LanguageType m_nSourceLang
void implReadOptionsFromConfiguration()
reads the options from Hangul/Hanja Options dialog that are saved to configuration
encapsulates Hangul-Hanja conversion functionality
static ConversionDirection m_ePrimaryConversionDirectionSave
static bool m_bUseSavedValues
HangulHanjaConversion(const HangulHanjaConversion &)=delete
virtual void GetNextPortion(OUString &_rNextPortion, LanguageType &_rLangOfPortion, bool _bAllowImplicitChangesForNotConvertibleText)=0
retrieves the next text portion which is to be analyzed
static bool IsSimplified(LanguageType nLang)
static bool m_bTryBothDirectionsSave
virtual void ReplaceUnit(const sal_Int32 _nUnitStart, const sal_Int32 _nUnitEnd, const OUString &_rOrigText, const OUString &_rReplaceWith, const css::uno::Sequence< sal_Int32 > &_rOffsets, ReplacementAction _eAction, LanguageType *pNewUnitLanguage)=0
replaces a text unit within a text portion with a new text
static bool IsTraditional(LanguageType nLang)
virtual void HandleNewUnit(const sal_Int32 _nUnitStart, const sal_Int32 _nUnitEnd)=0
announces a new "current unit"
virtual bool HasRubySupport() const =0
specifies if rubies are supported by the document implementing this class.
static bool IsUseSavedConversionDirectionState()
LanguageType GetTargetLanguage() const
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XTypeConverter > m_xConverter
#define LANGUAGE_CHINESE_TRADITIONAL
#define LANGUAGE_CHINESE_SIMPLIFIED
#define UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
#define UPH_IS_IGNORE_POST_POSITIONAL_WORD
#define UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES
#define LINK(Instance, Class, Member)
#define SAL_INFO(area, stream)
IMPL_LINK_NOARG(HangulHanjaConversion_Impl, OnOptionsChanged, LinkParamNone *, void)
IMPL_LINK(HangulHanjaConversion_Impl, OnByCharClicked, weld::Toggleable &, rBox, void)