LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sd/source/ui/func - fuhhconv.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 117 0.9 %
Date: 2013-07-09 Functions: 2 14 14.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10