LCOV - code coverage report
Current view: top level - sd/source/ui/func - fuhhconv.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 116 0.0 %
Date: 2012-08-25 Functions: 0 12 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 264 0.0 %

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

Generated by: LCOV version 1.10