diff options
author | jp <jp@openoffice.org> | 2000-12-21 08:32:45 +0000 |
---|---|---|
committer | jp <jp@openoffice.org> | 2000-12-21 08:32:45 +0000 |
commit | 52c520fd72373eb4d5ccd5edbb73e896c8731038 (patch) | |
tree | 260a71e2e261a4fdbe0ed05e76730e5d1f022a67 /sw/source | |
parent | 2d241beb981bbcd81f8f06fe1ab8a5a04def0481 (diff) |
new: transliteration
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/core/doc/docedt.cxx | 79 | ||||
-rw-r--r-- | sw/source/core/edit/editsh.cxx | 23 | ||||
-rw-r--r-- | sw/source/core/txtnode/makefile.mk | 6 | ||||
-rw-r--r-- | sw/source/core/txtnode/txtedt.cxx | 93 | ||||
-rw-r--r-- | sw/source/core/undo/unovwr.cxx | 156 | ||||
-rw-r--r-- | sw/source/ui/wrtsh/wrtsh.hrc | 6 | ||||
-rw-r--r-- | sw/source/ui/wrtsh/wrtsh.src | 10 |
7 files changed, 350 insertions, 23 deletions
diff --git a/sw/source/core/doc/docedt.cxx b/sw/source/core/doc/docedt.cxx index 54ef78c5c223..1085866cb163 100644 --- a/sw/source/core/doc/docedt.cxx +++ b/sw/source/core/doc/docedt.cxx @@ -2,9 +2,9 @@ * * $RCSfile: docedt.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: tl $ $Date: 2000-11-19 11:31:55 $ + * last change: $Author: jp $ $Date: 2000-12-21 09:31:55 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -86,6 +86,9 @@ #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ #include <com/sun/star/beans/XPropertySet.hpp> #endif +#ifndef _COM_SUN_STAR_I18N_WORDTYPE_HDL +#include <com/sun/star/i18n/WordType.hdl> +#endif #ifndef _UNOTOOLS_CHARCLASS_HXX #include <unotools/charclass.hxx> #endif @@ -174,11 +177,15 @@ #ifndef _UNDOBJ_HXX #include <undobj.hxx> #endif +#ifndef _BREAKIT_HXX +#include <breakit.hxx> +#endif using namespace ::com::sun::star; using namespace ::com::sun::star::linguistic2; using namespace ::rtl; +using namespace ::com::sun::star::i18n; //using namespace ::utl; #define S2U(rString) OUString::createFromAscii(rString) @@ -2260,4 +2267,72 @@ sal_Bool SwDoc::DelFullPara( SwPaM& rPam ) } +void SwDoc::TransliterateText( const SwPaM& rPaM, + utl::TransliterationWrapper& rTrans ) +{ + SwUndoTransliterate* pUndo; + if( DoesUndo() ) + pUndo = new SwUndoTransliterate( rPaM, rTrans ); + else + pUndo = 0; + + const SwPosition* pStt = rPaM.Start(), + * pEnd = pStt == rPaM.GetPoint() ? rPaM.GetMark() + : rPaM.GetPoint(); + ULONG nSttNd = pStt->nNode.GetIndex(), nEndNd = pEnd->nNode.GetIndex(); + xub_StrLen nSttCnt = pStt->nContent.GetIndex(), + nEndCnt = pEnd->nContent.GetIndex(); + + SwTxtNode* pTNd = pStt->nNode.GetNode().GetTxtNode(); + if( pStt == pEnd && pTNd ) // no region ? + { + Boundary aBndry; + if( pBreakIt->xBreak.is() ) + aBndry = pBreakIt->xBreak->getWordBoundary( + pTNd->GetTxt(), nSttCnt, + pBreakIt->GetLocale( pTNd->GetLang( nSttCnt ) ), + WordType::ANY_WORD /*ANYWORD_IGNOREWHITESPACES*/, + TRUE ); + + if( aBndry.startPos < nSttCnt && nSttCnt < aBndry.endPos ) + { + nSttCnt = (xub_StrLen)aBndry.startPos; + nEndCnt = (xub_StrLen)aBndry.endPos; + } + } + + if( nSttNd != nEndNd ) + { + SwNodeIndex aIdx( pStt->nNode ); + if( nSttCnt ) + { + aIdx++; + if( pTNd ) + pTNd->TransliterateText( rTrans, nSttCnt, + pTNd->GetTxt().Len(), pUndo ); + } + + for( ; aIdx.GetIndex() < nEndNd; aIdx++ ) + if( 0 != ( pTNd = aIdx.GetNode().GetTxtNode() )) + pTNd->TransliterateText( rTrans, 0, pTNd->GetTxt().Len(), + pUndo ); + + if( nEndCnt && 0 != ( pTNd = pEnd->nNode.GetNode().GetTxtNode() )) + pTNd->TransliterateText( rTrans, 0, nEndCnt, pUndo ); + } + else if( pTNd && nSttCnt < nEndCnt ) + pTNd->TransliterateText( rTrans, nSttCnt, nEndCnt, pUndo ); + + if( pUndo ) + { + if( pUndo->HasData() ) + { + ClearRedo(); + AppendUndo( pUndo ); + } + else + delete pUndo; + } +} + diff --git a/sw/source/core/edit/editsh.cxx b/sw/source/core/edit/editsh.cxx index 4e64d61b37b3..1e45b6b5cb55 100644 --- a/sw/source/core/edit/editsh.cxx +++ b/sw/source/core/edit/editsh.cxx @@ -2,9 +2,9 @@ * * $RCSfile: editsh.cxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: jp $ $Date: 2000-11-28 20:34:53 $ + * last change: $Author: jp $ $Date: 2000-12-21 09:32:08 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -87,6 +87,12 @@ #ifndef _UNOTOOLS_CHARCLASS_HXX #include <unotools/charclass.hxx> #endif +#ifndef _COMPHELPER_PROCESSFACTORY_HXX_ +#include <comphelper/processfactory.hxx> +#endif +#ifndef _UNOTOOLS_TRANSLITERATIONWRAPPER_HXX +#include <unotools/transliterationwrapper.hxx> +#endif #ifndef _SWWAIT_HXX #include <swwait.hxx> @@ -1090,4 +1096,17 @@ void SwEditShell::SetExtTextInputData( const CommandExtTextInputData& rData ) } +void SwEditShell::TransliterateText( sal_uInt32 nType ) +{ + utl::TransliterationWrapper aTrans( + ::comphelper::getProcessServiceFactory(), nType ); + StartAllAction(); + SET_CURR_SHELL( this ); + FOREACHPAM_START( this ) + + GetDoc()->TransliterateText( *PCURCRSR, aTrans ); + + FOREACHPAM_END() + EndAllAction(); +} diff --git a/sw/source/core/txtnode/makefile.mk b/sw/source/core/txtnode/makefile.mk index abc0391e6798..ea53e8471c32 100644 --- a/sw/source/core/txtnode/makefile.mk +++ b/sw/source/core/txtnode/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.1.1.1 $ +# $Revision: 1.2 $ # -# last change: $Author: hr $ $Date: 2000-09-19 00:08:27 $ +# last change: $Author: jp $ $Date: 2000-12-21 09:32:45 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -106,6 +106,7 @@ CXXFILES = \ swfont.cxx \ thints.cxx \ txatbase.cxx \ + txatritr.cxx \ txtatr0.cxx \ txtatr1.cxx \ txtatr2.cxx \ @@ -130,6 +131,7 @@ SLOFILES = \ $(SLO)$/swfont.obj \ $(SLO)$/thints.obj \ $(SLO)$/txatbase.obj \ + $(SLO)$/txatritr.obj \ $(SLO)$/txtatr0.obj \ $(SLO)$/txtatr1.obj \ $(SLO)$/txtatr2.obj \ diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx index 142b1fb974b2..756e8e4731c1 100644 --- a/sw/source/core/txtnode/txtedt.cxx +++ b/sw/source/core/txtnode/txtedt.cxx @@ -2,9 +2,9 @@ * * $RCSfile: txtedt.cxx,v $ * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * - * last change: $Author: jp $ $Date: 2000-12-13 14:32:08 $ + * last change: $Author: jp $ $Date: 2000-12-21 09:32:30 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -94,8 +94,14 @@ #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ #include <com/sun/star/beans/XPropertySet.hpp> #endif -#ifndef _COM_SUN_STAR_I18N_WORDTYPE_HPP_ -#include <com/sun/star/i18n/WordType.hpp> +#ifndef _COM_SUN_STAR_I18N_WORDTYPE_HDL +#include <com/sun/star/i18n/WordType.hdl> +#endif +#ifndef _COM_SUN_STAR_I18N_SCRIPTTYPE_HDL_ +#include <com/sun/star/i18n/ScriptType.hdl> +#endif +#ifndef _UNOTOOLS_TRANSLITERATIONWRAPPER_HXX +#include <unotools/transliterationwrapper.hxx> #endif #ifndef _SPLARGS_HXX @@ -155,6 +161,12 @@ #ifndef _CRSTATE_HXX #include <crstate.hxx> #endif +#ifndef _UNDOBJ_HXX +#include <undobj.hxx> +#endif +#ifndef _TXATRITR_HXX +#include <txatritr.hxx> +#endif using namespace ::com::sun::star; using namespace ::com::sun::star::i18n; @@ -428,9 +440,11 @@ XubString SwTxtNode::GetCurWord( xub_StrLen nPos ) aText, nPos, pBreakIt->GetLocale( GetLang( nPos ) ), WordType::ANY_WORD /*ANYWORD_IGNOREWHITESPACES*/, TRUE ); - if( aBndry.endPos != aBndry.startPos && IsSymbol( aBndry.startPos ) ) + if( aBndry.endPos != aBndry.startPos && + IsSymbol( (xub_StrLen)aBndry.startPos ) ) aBndry.endPos = aBndry.startPos; - return aText.Copy( aBndry.startPos, aBndry.endPos - aBndry.startPos ); + return aText.Copy( (xub_StrLen)aBndry.startPos, + (xub_StrLen)(aBndry.endPos - aBndry.startPos) ); } @@ -536,10 +550,10 @@ BOOL SwScanner::NextWord( LanguageType aLang ) if( bReverse ) { if( nEndPos > aBound.startPos ) - nEndPos = aBound.startPos; + nEndPos = (xub_StrLen)aBound.startPos; } else if( nEndPos < aBound.endPos && nEndPos > aBound.startPos ) - nEndPos = aBound.endPos; + nEndPos = (xub_StrLen)aBound.endPos; } } if( !bStart ) @@ -554,7 +568,7 @@ BOOL SwScanner::NextWord( LanguageType aLang ) else bStart = FALSE; - nBegin = aBound.startPos; + nBegin = (xub_StrLen)aBound.startPos; nLen = aBound.endPos - nBegin; if( !nLen ) return FALSE; @@ -1020,4 +1034,65 @@ void SwLinguStatistik::Flush() #endif +// change text to Upper/Lower/Hiragana/Katagana/... +void SwTxtNode::TransliterateText( utl::TransliterationWrapper& rTrans, + xub_StrLen nStart, xub_StrLen nEnd, SwUndoTransliterate* pUndo ) +{ + if( nStart < nEnd ) + { + SwLanguageIterator* pIter; + if( rTrans.needLanguageForTheMode() ) + pIter = new SwLanguageIterator( *this, nStart ); + else + pIter = 0; + + xub_StrLen nEndPos; + sal_uInt16 nLang; + do { + if( pIter ) + { + nLang = pIter->GetLanguage(); + nEndPos = pIter->GetChgPos(); + if( nEndPos > nEnd ) + nEndPos = nEnd; + } + else + { + nLang = LANGUAGE_SYSTEM; + nEndPos = nEnd; + } + xub_StrLen nLen = nEndPos - nStart; + + Sequence <long> aOffsets; + Sequence <long>* pOffsets = pUndo ? &aOffsets : 0; + + String sChgd( rTrans.transliterate( aText, nLang, nStart, nLen, + pOffsets )); + + ASSERT( nLen == sChgd.Len(), "transliterate add/remove characters" ); + if( nLen == sChgd.Len() && !aText.Equals( sChgd, nStart, nLen )) + { + if( pUndo ) + pUndo->AddChanges( *this, nStart, nLen, aOffsets ); + ReplaceTextOnly( nStart, sChgd ); + } + nStart = nEndPos; + } while( nEndPos < nEnd && pIter && pIter->Next() ); + delete pIter; + } +} + +void SwTxtNode::ReplaceTextOnly( xub_StrLen nPos, const XubString& rText ) +{ + aText.Replace( nPos, rText.Len(), rText ); + + // notify the layout! + SwDelTxt aDelHint( nPos, rText.Len() ); + SwModify::Modify( 0, &aDelHint ); + + SwInsTxt aHint( nPos, rText.Len() ); + SwModify::Modify( 0, &aHint ); +} + + diff --git a/sw/source/core/undo/unovwr.cxx b/sw/source/core/undo/unovwr.cxx index 65699358148f..10f0f8abaff1 100644 --- a/sw/source/core/undo/unovwr.cxx +++ b/sw/source/core/undo/unovwr.cxx @@ -2,9 +2,9 @@ * * $RCSfile: unovwr.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: jp $ $Date: 2000-11-06 10:47:36 $ + * last change: $Author: jp $ $Date: 2000-12-21 09:29:24 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -68,6 +68,12 @@ #ifndef _UNOTOOLS_CHARCLASS_HXX #include <unotools/charclass.hxx> #endif +#ifndef _UNOTOOLS_TRANSLITERATIONWRAPPER_HXX +#include <unotools/transliterationwrapper.hxx> +#endif +#ifndef _COMPHELPER_PROCESSFACTORY_HXX_ +#include <comphelper/processfactory.hxx> +#endif #ifndef _DOC_HXX #include <doc.hxx> @@ -95,6 +101,9 @@ #endif +using namespace ::com::sun::star::i18n; +using namespace ::com::sun::star::uno; + //------------------------------------------------------------------ // zwei Zugriffs-Funktionen @@ -377,15 +386,156 @@ void SwUndoOverwrite::Redo( SwUndoIter& rUndoIter ) } } +//------------------------------------------------------------ + +struct _UndoTransliterate_Data +{ + struct _SeqOfPosAndChar + { + xub_StrLen nPos; + sal_Unicode cChar; + }; + + _UndoTransliterate_Data* pNext; + ULONG nNdIdx; + xub_StrLen nDataLen; + union { + sal_Unicode* pStr; + _SeqOfPosAndChar* pSeq; + } aData; + + xub_StrLen nStart; + sal_Bool bStr; + + _UndoTransliterate_Data() : pNext( 0 ) {} + ~_UndoTransliterate_Data() { delete aData.pStr; } + + void SetChangeAtNode( SwDoc& rDoc ); +}; + +SwUndoTransliterate::SwUndoTransliterate( const SwPaM& rPam, + const utl::TransliterationWrapper& rTrans ) + : SwUndo( UNDO_TRANSLITERATE ), SwUndRng( rPam ), + nType( rTrans.getType() ), pData( 0 ), pLastData( 0 ) +{ +} + +SwUndoTransliterate::~SwUndoTransliterate() +{ + _UndoTransliterate_Data* pD = pData; + while( pD ) + { + pData = pD; + pD = pD->pNext; + delete pData; + } +} + +void SwUndoTransliterate::Undo( SwUndoIter& rUndoIter ) +{ + SwDoc& rDoc = rUndoIter.GetDoc(); + BOOL bUndo = rDoc.DoesUndo(); + rDoc.DoUndo( FALSE ); + + for( _UndoTransliterate_Data* pD = pData; pD; pD = pD->pNext ) + pD->SetChangeAtNode( rDoc ); + + rDoc.DoUndo( bUndo ); + SetPaM( rUndoIter, TRUE ); +} + +void SwUndoTransliterate::Redo( SwUndoIter& rUndoIter ) +{ +/* ??? */ rUndoIter.SetUpdateAttr( TRUE ); + + SetPaM( *rUndoIter.pAktPam ); + Repeat( rUndoIter ); +} + +void SwUndoTransliterate::Repeat( SwUndoIter& rUndoIter ) +{ + SwPaM& rPam = *rUndoIter.pAktPam; + SwDoc& rDoc = rUndoIter.GetDoc(); + + utl::TransliterationWrapper aTrans( + ::comphelper::getProcessServiceFactory(), nType ); + rDoc.TransliterateText( rPam, aTrans ); + + rUndoIter.pLastUndoObj = this; +} + +void SwUndoTransliterate::AddChanges( const SwTxtNode& rTNd, + xub_StrLen nStart, xub_StrLen nLen, + ::com::sun::star::uno::Sequence <long>& rOffsets ) +{ + _UndoTransliterate_Data* pNew = new _UndoTransliterate_Data; + if( pData ) + pLastData->pNext = pNew; + else + pData = pNew; + pLastData = pNew; + + pNew->nNdIdx = rTNd.GetIndex(); + pNew->nStart = nStart; + const String& rOrig = rTNd.GetTxt(); + + // where did we need less memory ? + if( ( nLen * sizeof( sal_Unicode )) > + ( rOffsets.getLength() * + sizeof( _UndoTransliterate_Data::_SeqOfPosAndChar ) ) ) + { + pNew->bStr = sal_False; + pNew->nDataLen = (xub_StrLen)rOffsets.getLength(); + pNew->aData.pSeq = new _UndoTransliterate_Data::_SeqOfPosAndChar[ pNew->nDataLen ]; + _UndoTransliterate_Data::_SeqOfPosAndChar* p = pNew->aData.pSeq; + for( xub_StrLen n = 0, nEnd = pNew->nDataLen; n < nEnd; ++n, ++p ) + { + p->nPos = (xub_StrLen)rOffsets[ n ]; + p->cChar = rOrig.GetChar( p->nPos ); + } + } + else + { + pNew->bStr = sal_True; + pNew->nDataLen = nLen; + pNew->aData.pStr = new sal_Unicode[ pNew->nDataLen ]; + memcpy( pNew->aData.pStr, rOrig.GetBuffer() + nStart, + pNew->nDataLen * sizeof( sal_Unicode ) ); + } +} + +void _UndoTransliterate_Data::SetChangeAtNode( SwDoc& rDoc ) +{ + SwTxtNode* pTNd = rDoc.GetNodes()[ nNdIdx ]->GetTxtNode(); + if( pTNd ) + { + String sChgd; + if( bStr ) + sChgd.Append( aData.pStr, nDataLen ); + else + { + sChgd = pTNd->GetTxt().Copy( nStart, nDataLen ); + _SeqOfPosAndChar* p = aData.pSeq; + for( xub_StrLen n = 0; n < nDataLen; ++n, ++p ) + sChgd.SetChar( p->nPos - nStart, p->cChar ); + } + pTNd->ReplaceTextOnly( nStart, sChgd ); + } +} + + /************************************************************************* Source Code Control System - Header - $Header: /zpool/svn/migration/cvs_rep_09_09_08/code/sw/source/core/undo/unovwr.cxx,v 1.4 2000-11-06 10:47:36 jp Exp $ + $Header: /zpool/svn/migration/cvs_rep_09_09_08/code/sw/source/core/undo/unovwr.cxx,v 1.5 2000-12-21 09:29:24 jp Exp $ Source Code Control System - Update $Log: not supported by cvs2svn $ + Revision 1.4 2000/11/06 10:47:36 jp + use new flag from the txtnode for textattribut expansion + Revision 1.3 2000/10/26 11:24:24 jp for bug #78848#: don't call DeleteRedline diff --git a/sw/source/ui/wrtsh/wrtsh.hrc b/sw/source/ui/wrtsh/wrtsh.hrc index 7c841b48ed8c..a5ebf9583300 100644 --- a/sw/source/ui/wrtsh/wrtsh.hrc +++ b/sw/source/ui/wrtsh/wrtsh.hrc @@ -2,9 +2,9 @@ * * $RCSfile: wrtsh.hrc,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: hr $ $Date: 2000-09-18 17:14:53 $ + * last change: $Author: jp $ $Date: 2000-12-21 09:28:55 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -117,8 +117,8 @@ #define STR_DONTEXPAND (UNDO_BASE +36) #define STR_AUTOCORRECT (UNDO_BASE +37) #define STR_MERGE_TABLE (UNDO_BASE +38) +#define STR_TRANSLITERATE (UNDO_BASE +39) -#define STR_REPEAT_DUMMY_3 (UNDO_BASE +39) #define STR_REPEAT_DUMMY_4 (UNDO_BASE +40) #define STR_REPEAT_DUMMY_5 (UNDO_BASE +41) #define STR_REPEAT_DUMMY_6 (UNDO_BASE +42) diff --git a/sw/source/ui/wrtsh/wrtsh.src b/sw/source/ui/wrtsh/wrtsh.src index a7958319798e..aa33635f985e 100644 --- a/sw/source/ui/wrtsh/wrtsh.src +++ b/sw/source/ui/wrtsh/wrtsh.src @@ -2,9 +2,9 @@ * * $RCSfile: wrtsh.src,v $ * - * $Revision: 1.13 $ + * $Revision: 1.14 $ * - * last change: $Author: kz $ $Date: 2000-12-11 23:24:30 $ + * last change: $Author: jp $ $Date: 2000-12-21 09:28:55 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -1625,6 +1625,12 @@ String STR_MERGE_TABLE Text[ language_user1 ] = " "; }; +String STR_TRANSLITERATE +{ + TEXT = "Gro-/Kleinschreibung" ; + TEXT [ English ] = "Change case" ; +}; + String STR_DELNUM { TEXT = "Nummerierung lschen" ; |