1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sd.hxx" 30*cdf0e10cSrcweir #include <com/sun/star/i18n/TextConversionOption.hpp> 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 36*cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx> 37*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 38*cdf0e10cSrcweir #include <svl/style.hxx> 39*cdf0e10cSrcweir #include <editeng/eeitem.hxx> 40*cdf0e10cSrcweir #include <editeng/langitem.hxx> 41*cdf0e10cSrcweir #include <editeng/fontitem.hxx> 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #include <fuhhconv.hxx> 44*cdf0e10cSrcweir #include "drawdoc.hxx" 45*cdf0e10cSrcweir #include "Outliner.hxx" 46*cdf0e10cSrcweir #include "DrawViewShell.hxx" 47*cdf0e10cSrcweir #include "OutlineViewShell.hxx" 48*cdf0e10cSrcweir #include "Window.hxx" 49*cdf0e10cSrcweir #include "ViewShellBase.hxx" 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir #include "sdresid.hxx" 52*cdf0e10cSrcweir #include "strings.hrc" 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir class SfxRequest; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir #define C2U(cChar) rtl::OUString::createFromAscii(cChar) 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir using namespace ::com::sun::star; 59*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 60*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir namespace sd { 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir class ViewShell; 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir TYPEINIT1( FuHangulHanjaConversion, FuPoor ); 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir /************************************************************************* 69*cdf0e10cSrcweir |* 70*cdf0e10cSrcweir |* Konstruktor 71*cdf0e10cSrcweir |* 72*cdf0e10cSrcweir \************************************************************************/ 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir FuHangulHanjaConversion::FuHangulHanjaConversion ( 75*cdf0e10cSrcweir ViewShell* pViewSh, 76*cdf0e10cSrcweir ::sd::Window* pWin, 77*cdf0e10cSrcweir ::sd::View* pView, 78*cdf0e10cSrcweir SdDrawDocument* pDocument, 79*cdf0e10cSrcweir SfxRequest& rReq ) 80*cdf0e10cSrcweir : FuPoor(pViewSh, pWin, pView, pDocument, rReq), 81*cdf0e10cSrcweir pSdOutliner(NULL), 82*cdf0e10cSrcweir bOwnOutliner(sal_False) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir if ( mpViewShell->ISA(DrawViewShell) ) 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir bOwnOutliner = sal_True; 87*cdf0e10cSrcweir pSdOutliner = new Outliner( mpDoc, OUTLINERMODE_TEXTOBJECT ); 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir else if ( mpViewShell->ISA(OutlineViewShell) ) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir bOwnOutliner = sal_False; 92*cdf0e10cSrcweir pSdOutliner = mpDoc->GetOutliner(); 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir if (pSdOutliner) 96*cdf0e10cSrcweir pSdOutliner->PrepareSpelling(); 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir /************************************************************************* 102*cdf0e10cSrcweir |* 103*cdf0e10cSrcweir |* Destruktor 104*cdf0e10cSrcweir |* 105*cdf0e10cSrcweir \************************************************************************/ 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir FuHangulHanjaConversion::~FuHangulHanjaConversion() 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir if (pSdOutliner) 110*cdf0e10cSrcweir pSdOutliner->EndConversion(); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir if (bOwnOutliner) 113*cdf0e10cSrcweir delete pSdOutliner; 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir FunctionReference FuHangulHanjaConversion::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq ) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir FunctionReference xFunc( new FuHangulHanjaConversion( pViewSh, pWin, pView, pDoc, rReq ) ); 119*cdf0e10cSrcweir return xFunc; 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir /************************************************************************* 123*cdf0e10cSrcweir |* 124*cdf0e10cSrcweir |* Suchen&Ersetzen 125*cdf0e10cSrcweir |* 126*cdf0e10cSrcweir \************************************************************************/ 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir void FuHangulHanjaConversion::StartConversion( sal_Int16 nSourceLanguage, sal_Int16 nTargetLanguage, 129*cdf0e10cSrcweir const Font *pTargetFont, sal_Int32 nOptions, sal_Bool bIsInteractive ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir String aString( SdResId(STR_UNDO_HANGULHANJACONVERSION) ); 133*cdf0e10cSrcweir mpView->BegUndo( aString ); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir ViewShellBase* pBase = PTR_CAST(ViewShellBase, SfxViewShell::Current()); 136*cdf0e10cSrcweir if (pBase != NULL) 137*cdf0e10cSrcweir mpViewShell = pBase->GetMainViewShell().get(); 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir if( mpViewShell ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir if ( pSdOutliner && mpViewShell->ISA(DrawViewShell) && !bOwnOutliner ) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir pSdOutliner->EndConversion(); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir bOwnOutliner = sal_True; 146*cdf0e10cSrcweir pSdOutliner = new Outliner( mpDoc, OUTLINERMODE_TEXTOBJECT ); 147*cdf0e10cSrcweir pSdOutliner->BeginConversion(); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir else if ( pSdOutliner && mpViewShell->ISA(OutlineViewShell) && bOwnOutliner ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir pSdOutliner->EndConversion(); 152*cdf0e10cSrcweir delete pSdOutliner; 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir bOwnOutliner = sal_False; 155*cdf0e10cSrcweir pSdOutliner = mpDoc->GetOutliner(); 156*cdf0e10cSrcweir pSdOutliner->BeginConversion(); 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir if (pSdOutliner) 160*cdf0e10cSrcweir pSdOutliner->StartConversion(nSourceLanguage, nTargetLanguage, pTargetFont, nOptions, bIsInteractive ); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir // Due to changing between edit mode, notes mode, and handout mode the 164*cdf0e10cSrcweir // view has most likely changed. Get the new one. 165*cdf0e10cSrcweir mpViewShell = pBase->GetMainViewShell().get(); 166*cdf0e10cSrcweir if (mpViewShell != NULL) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir mpView = mpViewShell->GetView(); 169*cdf0e10cSrcweir mpWindow = mpViewShell->GetActiveWindow(); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir else 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir mpView = 0; 174*cdf0e10cSrcweir mpWindow = NULL; 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir if (mpView != NULL) 178*cdf0e10cSrcweir mpView->EndUndo(); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir void FuHangulHanjaConversion::ConvertStyles( sal_Int16 nTargetLanguage, const Font *pTargetFont ) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir if( !mpDoc ) 185*cdf0e10cSrcweir return; 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir SfxStyleSheetBasePool* pStyleSheetPool = mpDoc->GetStyleSheetPool(); 188*cdf0e10cSrcweir if( !pStyleSheetPool ) 189*cdf0e10cSrcweir return; 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir SfxStyleSheetBase* pStyle = pStyleSheetPool->First(); 192*cdf0e10cSrcweir while( pStyle ) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir SfxItemSet& rSet = pStyle->GetItemSet(); 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir const bool bHasParent = pStyle->GetParent().Len() != 0; 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir if( !bHasParent || rSet.GetItemState( EE_CHAR_LANGUAGE_CJK, sal_False ) == SFX_ITEM_SET ) 199*cdf0e10cSrcweir rSet.Put( SvxLanguageItem( nTargetLanguage, EE_CHAR_LANGUAGE_CJK ) ); 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir if( pTargetFont && 202*cdf0e10cSrcweir ( !bHasParent || rSet.GetItemState( EE_CHAR_FONTINFO_CJK, sal_False ) == SFX_ITEM_SET ) ) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir // set new font attribute 205*cdf0e10cSrcweir SvxFontItem aFontItem( (SvxFontItem&) rSet.Get( EE_CHAR_FONTINFO_CJK ) ); 206*cdf0e10cSrcweir aFontItem.SetFamilyName( pTargetFont->GetName()); 207*cdf0e10cSrcweir aFontItem.SetFamily( pTargetFont->GetFamily()); 208*cdf0e10cSrcweir aFontItem.SetStyleName( pTargetFont->GetStyleName()); 209*cdf0e10cSrcweir aFontItem.SetPitch( pTargetFont->GetPitch()); 210*cdf0e10cSrcweir aFontItem.SetCharSet( pTargetFont->GetCharSet()); 211*cdf0e10cSrcweir rSet.Put( aFontItem ); 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir pStyle = pStyleSheetPool->Next(); 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir mpDoc->SetLanguage( EE_CHAR_LANGUAGE_CJK, nTargetLanguage ); 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir void FuHangulHanjaConversion::StartChineseConversion() 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir //open ChineseTranslationDialog 223*cdf0e10cSrcweir Reference< XComponentContext > xContext( 224*cdf0e10cSrcweir ::cppu::defaultBootstrap_InitialComponentContext() ); //@todo get context from calc if that has one 225*cdf0e10cSrcweir if(xContext.is()) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() ); 228*cdf0e10cSrcweir if(xMCF.is()) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir Reference< ui::dialogs::XExecutableDialog > xDialog( 231*cdf0e10cSrcweir xMCF->createInstanceWithContext( 232*cdf0e10cSrcweir rtl::OUString::createFromAscii("com.sun.star.linguistic2.ChineseTranslationDialog") 233*cdf0e10cSrcweir , xContext), UNO_QUERY); 234*cdf0e10cSrcweir Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY ); 235*cdf0e10cSrcweir if( xInit.is() ) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir // initialize dialog 238*cdf0e10cSrcweir Reference< awt::XWindow > xDialogParentWindow(0); 239*cdf0e10cSrcweir Sequence<Any> aSeq(1); 240*cdf0e10cSrcweir Any* pArray = aSeq.getArray(); 241*cdf0e10cSrcweir PropertyValue aParam; 242*cdf0e10cSrcweir aParam.Name = rtl::OUString::createFromAscii("ParentWindow"); 243*cdf0e10cSrcweir aParam.Value <<= makeAny(xDialogParentWindow); 244*cdf0e10cSrcweir pArray[0] <<= makeAny(aParam); 245*cdf0e10cSrcweir xInit->initialize( aSeq ); 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir //execute dialog 248*cdf0e10cSrcweir sal_Int16 nDialogRet = xDialog->execute(); 249*cdf0e10cSrcweir if( RET_OK == nDialogRet ) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir //get some parameters from the dialog 252*cdf0e10cSrcweir sal_Bool bToSimplified = sal_True; 253*cdf0e10cSrcweir sal_Bool bUseVariants = sal_True; 254*cdf0e10cSrcweir sal_Bool bCommonTerms = sal_True; 255*cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( xDialog, UNO_QUERY ); 256*cdf0e10cSrcweir if( xProp.is() ) 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir try 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir xProp->getPropertyValue( C2U("IsDirectionToSimplified") ) >>= bToSimplified; 261*cdf0e10cSrcweir xProp->getPropertyValue( C2U("IsUseCharacterVariants") ) >>= bUseVariants; 262*cdf0e10cSrcweir xProp->getPropertyValue( C2U("IsTranslateCommonTerms") ) >>= bCommonTerms; 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir catch( Exception& ) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir //execute translation 270*cdf0e10cSrcweir sal_Int16 nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED; 271*cdf0e10cSrcweir sal_Int16 nTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL; 272*cdf0e10cSrcweir sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0; 273*cdf0e10cSrcweir if( !bCommonTerms ) 274*cdf0e10cSrcweir nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER; 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir Font aTargetFont = mpWindow->GetDefaultFont( 277*cdf0e10cSrcweir DEFAULTFONT_CJK_PRESENTATION, 278*cdf0e10cSrcweir nTargetLang, DEFAULTFONT_FLAGS_ONLYONE ); 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir StartConversion( nSourceLang, nTargetLang, &aTargetFont, nOptions, sal_False ); 281*cdf0e10cSrcweir ConvertStyles( nTargetLang, &aTargetFont ); 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY ); 285*cdf0e10cSrcweir if( xComponent.is() ) 286*cdf0e10cSrcweir xComponent->dispose(); 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir } // end of namespace 291