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