LCOV - code coverage report
Current view: top level - sd/source/ui/docshell - docshel3.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 27 124 21.8 %
Date: 2015-06-13 12:38:46 Functions: 4 6 66.7 %
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 "Window.hxx"
      21             : #include "DrawDocShell.hxx"
      22             : 
      23             : #include "app.hrc"
      24             : 
      25             : #include <svx/svxids.hrc>
      26             : #include <svx/dialogs.hrc>
      27             : 
      28             : #include <svx/ofaitem.hxx>
      29             : #include <svx/svxerr.hxx>
      30             : #include <svx/dialmgr.hxx>
      31             : #include <svl/srchitem.hxx>
      32             : #include <svl/languageoptions.hxx>
      33             : #include <svtools/langtab.hxx>
      34             : #include <svx/srchdlg.hxx>
      35             : #include <sfx2/request.hxx>
      36             : #include <sfx2/sfxdlg.hxx>
      37             : #include <vcl/abstdlg.hxx>
      38             : #include <vcl/window.hxx>
      39             : #include <svl/style.hxx>
      40             : #include <svx/drawitem.hxx>
      41             : #include <editeng/unolingu.hxx>
      42             : #include <editeng/langitem.hxx>
      43             : #include <editeng/eeitem.hxx>
      44             : #include <com/sun/star/i18n/TextConversionOption.hpp>
      45             : 
      46             : #include "strings.hrc"
      47             : #include "glob.hrc"
      48             : #include "res_bmp.hrc"
      49             : 
      50             : #include "sdmod.hxx"
      51             : #include "drawdoc.hxx"
      52             : #include "sdpage.hxx"
      53             : #include "sdattr.hxx"
      54             : #include "fusearch.hxx"
      55             : #include "ViewShell.hxx"
      56             : #include "View.hxx"
      57             : #include "slideshow.hxx"
      58             : #include "fuhhconv.hxx"
      59             : #include <boost/scoped_ptr.hpp>
      60             : 
      61             : using namespace ::com::sun::star;
      62             : using namespace ::com::sun::star::beans;
      63             : using namespace ::com::sun::star::uno;
      64             : 
      65             : namespace sd {
      66             : 
      67           0 : static void lcl_setLanguageForObj( SdrObject *pObj, LanguageType nLang, bool bLanguageNone = false )
      68             : {
      69             :     const sal_uInt16 aLangWhichId_EE[3] =
      70             :     {
      71             :         EE_CHAR_LANGUAGE,
      72             :         EE_CHAR_LANGUAGE_CJK,
      73             :         EE_CHAR_LANGUAGE_CTL
      74           0 :     };
      75             : 
      76           0 :     if( bLanguageNone )
      77           0 :         nLang = LANGUAGE_NONE;
      78             : 
      79           0 :     if( nLang != LANGUAGE_DONTKNOW )
      80             :     {
      81           0 :         if( nLang == LANGUAGE_NONE )
      82             :         {
      83           0 :             for(sal_Int32 n = 0; n < 3; n++ )
      84           0 :                 pObj->SetMergedItem( SvxLanguageItem( nLang, aLangWhichId_EE[n] ) );
      85             :         }
      86             :         else
      87             :         {
      88           0 :             sal_uInt16 nLangWhichId = 0;
      89           0 :             SvtScriptType nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nLang );
      90           0 :             switch (nScriptType)
      91             :             {
      92           0 :                 case SvtScriptType::LATIN :    nLangWhichId = EE_CHAR_LANGUAGE; break;
      93           0 :                 case SvtScriptType::ASIAN :    nLangWhichId = EE_CHAR_LANGUAGE_CJK; break;
      94           0 :                 case SvtScriptType::COMPLEX :  nLangWhichId = EE_CHAR_LANGUAGE_CTL; break;
      95             :                 default:
      96             :                     OSL_FAIL("unexpected case" );
      97           0 :                     return;
      98             :             }
      99           0 :             pObj->SetMergedItem( SvxLanguageItem( nLang, nLangWhichId ) );
     100             :         }
     101             :     }
     102             :     else    // Reset to default
     103             :     {
     104           0 :         for( sal_Int32 n = 0; n < 3; n++ )
     105           0 :             pObj->ClearMergedItem( aLangWhichId_EE[n] );
     106             :     }
     107             : }
     108             : 
     109           0 : static void lcl_setLanguage( const SdDrawDocument *pDoc, const OUString &rLanguage, bool bLanguageNone = false )
     110             : {
     111           0 :     LanguageType nLang = SvtLanguageTable::GetLanguageType( rLanguage );
     112             : 
     113             :     // Do it for SdDrawDocument->SetLanguage as well?
     114             : 
     115           0 :     sal_uInt16 nPageCount = pDoc->GetPageCount();   // Pick All Pages
     116           0 :     for( sal_uInt16 nPage = 0; nPage < nPageCount; nPage++ )
     117             :     {
     118           0 :         const SdrPage *pPage = pDoc->GetPage( nPage );
     119           0 :         const size_t nObjCount = pPage->GetObjCount();
     120           0 :         for( size_t nObj = 0; nObj < nObjCount; ++nObj )
     121             :         {
     122           0 :             SdrObject *pObj = pPage->GetObj( nObj );
     123           0 :             lcl_setLanguageForObj( pObj, nLang, bLanguageNone );
     124             :         }
     125             :     }
     126           0 : }
     127             : 
     128             : /**
     129             :  * Handles SFX-Requests
     130             :  */
     131           3 : void DrawDocShell::Execute( SfxRequest& rReq )
     132             : {
     133           3 :     if(mpViewShell && SlideShow::IsRunning( mpViewShell->GetViewShellBase() ))
     134             :     {
     135             :         // during a running presentation no slot will be executed
     136           3 :         return;
     137             :     }
     138             : 
     139           3 :     switch ( rReq.GetSlot() )
     140             :     {
     141             :         case SID_SEARCH_ITEM:
     142             :         {
     143           0 :             const SfxItemSet* pReqArgs = rReq.GetArgs();
     144             : 
     145           0 :             if (pReqArgs)
     146             :             {
     147           0 :                 const SvxSearchItem* pSearchItem = static_cast<const SvxSearchItem*>( &pReqArgs->Get(SID_SEARCH_ITEM) );
     148             : 
     149             :                 // would be nice to have an assign operation at SearchItem
     150           0 :                 SvxSearchItem* pAppSearchItem = SD_MOD()->GetSearchItem();
     151           0 :                 delete pAppSearchItem;
     152           0 :                 pAppSearchItem = static_cast<SvxSearchItem*>( pSearchItem->Clone() );
     153           0 :                 SD_MOD()->SetSearchItem(pAppSearchItem);
     154             :             }
     155             : 
     156           0 :             rReq.Done();
     157             :         }
     158           0 :         break;
     159             : 
     160             :         case FID_SEARCH_ON:
     161             :         {
     162             :             // no action needed
     163           0 :             rReq.Done();
     164             :         }
     165           0 :         break;
     166             : 
     167             :         case FID_SEARCH_OFF:
     168             :         {
     169           0 :             if( dynamic_cast< FuSearch* >(mxDocShellFunction.get()) )
     170             :             {
     171             :                 // End Search&Replace in all docshells
     172           0 :                 SfxObjectShell* pFirstShell = SfxObjectShell::GetFirst();
     173           0 :                 SfxObjectShell* pShell = pFirstShell;
     174             : 
     175           0 :                 while (pShell)
     176             :                 {
     177           0 :                     if (pShell->ISA(DrawDocShell))
     178             :                     {
     179           0 :                         static_cast<DrawDocShell*>(pShell)->CancelSearching();
     180             :                     }
     181             : 
     182           0 :                     pShell = SfxObjectShell::GetNext(*pShell);
     183             : 
     184           0 :                     if (pShell == pFirstShell)
     185             :                     {
     186           0 :                         pShell = NULL;
     187             :                     }
     188             :                 }
     189             : 
     190           0 :                 SetDocShellFunction(0);
     191           0 :                 Invalidate();
     192           0 :                 rReq.Done();
     193             :             }
     194             :         }
     195           0 :         break;
     196             : 
     197             :         case FID_SEARCH_NOW:
     198             :         {
     199           3 :             const SfxItemSet* pReqArgs = rReq.GetArgs();
     200             : 
     201           3 :             if ( pReqArgs )
     202             :             {
     203           3 :                 rtl::Reference< FuSearch > xFuSearch( dynamic_cast< FuSearch* >( GetDocShellFunction().get() ) );
     204             : 
     205           3 :                 if( !xFuSearch.is() && mpViewShell )
     206             :                 {
     207           1 :                     ::sd::View* pView = mpViewShell->GetView();
     208           1 :                     SetDocShellFunction( FuSearch::Create( mpViewShell, mpViewShell->GetActiveWindow(), pView, mpDoc, rReq ) );
     209           1 :                     xFuSearch.set( dynamic_cast< FuSearch* >( GetDocShellFunction().get() ) );
     210             :                 }
     211             : 
     212           3 :                 if( xFuSearch.is() )
     213             :                 {
     214             :                     const SvxSearchItem* pSearchItem =
     215           3 :                         static_cast<const SvxSearchItem*>( &pReqArgs->Get(SID_SEARCH_ITEM) );
     216             : 
     217             :                     // would be nice to have an assign operation at SearchItem
     218           3 :                     SvxSearchItem* pAppSearchItem = SD_MOD()->GetSearchItem();
     219           3 :                     delete pAppSearchItem;
     220           3 :                     pAppSearchItem = static_cast<SvxSearchItem*>( pSearchItem->Clone() );
     221           3 :                     SD_MOD()->SetSearchItem(pAppSearchItem);
     222           3 :                     xFuSearch->SearchAndReplace(pSearchItem);
     223           3 :                 }
     224             :             }
     225             : 
     226           3 :             rReq.Done();
     227             :         }
     228           3 :         break;
     229             : 
     230             :         case SID_CLOSEDOC:
     231             :         {
     232           0 :             ExecuteSlot(rReq, SfxObjectShell::GetStaticInterface());
     233             :         }
     234           0 :         break;
     235             : 
     236             :         case SID_GET_COLORLIST:
     237             :         {
     238           0 :             const SvxColorListItem* pColItem = static_cast<const SvxColorListItem*>( GetItem( SID_COLOR_TABLE ) );
     239           0 :             XColorListRef pList = pColItem->GetColorList();
     240           0 :             rReq.SetReturnValue( OfaRefItem<XColorList>( SID_GET_COLORLIST, pList ) );
     241             :         }
     242           0 :         break;
     243             : 
     244             :         case SID_VERSION:
     245             :         {
     246           0 :             const SdrSwapGraphicsMode nOldSwapMode = mpDoc->GetSwapGraphicsMode();
     247             : 
     248           0 :             mpDoc->SetSwapGraphicsMode( SdrSwapGraphicsMode::TEMP );
     249           0 :             ExecuteSlot( rReq, SfxObjectShell::GetStaticInterface() );
     250           0 :             mpDoc->SetSwapGraphicsMode( nOldSwapMode );
     251             :         }
     252           0 :         break;
     253             : 
     254             :         case SID_HANGUL_HANJA_CONVERSION:
     255             :         {
     256           0 :             if( mpViewShell )
     257             :             {
     258           0 :                 rtl::Reference<FuPoor> aFunc( FuHangulHanjaConversion::Create( mpViewShell, mpViewShell->GetActiveWindow(), mpViewShell->GetView(), mpDoc, rReq ) );
     259           0 :                 static_cast< FuHangulHanjaConversion* >( aFunc.get() )->StartConversion( LANGUAGE_KOREAN, LANGUAGE_KOREAN, NULL, i18n::TextConversionOption::CHARACTER_BY_CHARACTER, true );
     260             :             }
     261             :         }
     262           0 :         break;
     263             : 
     264             :         case SID_CHINESE_CONVERSION:
     265             :         {
     266           0 :             if( mpViewShell )
     267             :             {
     268           0 :                 rtl::Reference<FuPoor> aFunc( FuHangulHanjaConversion::Create( mpViewShell, mpViewShell->GetActiveWindow(), mpViewShell->GetView(), mpDoc, rReq ) );
     269           0 :                 static_cast< FuHangulHanjaConversion* >( aFunc.get() )->StartChineseConversion();
     270             :             }
     271             :         }
     272           0 :         break;
     273             :         case SID_LANGUAGE_STATUS:
     274             :         {
     275           0 :             OUString aNewLangTxt;
     276           0 :             SFX_REQUEST_ARG( rReq, pItem, SfxStringItem, SID_LANGUAGE_STATUS , false );
     277           0 :             if (pItem)
     278           0 :                 aNewLangTxt = pItem->GetValue();
     279           0 :             if (aNewLangTxt == "*" )
     280             :             {
     281             :                 // open the dialog "Tools/Options/Language Settings - Language"
     282           0 :                 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
     283           0 :                 if (pFact && mpViewShell)
     284             :                 {
     285           0 :                     boost::scoped_ptr<VclAbstractDialog> pDlg(pFact->CreateVclDialog( mpViewShell->GetActiveWindow(), SID_LANGUAGE_OPTIONS ));
     286           0 :                     pDlg->Execute();
     287             :                 }
     288             :             }
     289             :             else
     290             :             {
     291           0 :                 if( mpViewShell )
     292             :                 {
     293             :                     // setting the new language...
     294           0 :                     if (!aNewLangTxt.isEmpty())
     295             :                     {
     296           0 :                         const OUString aDocumentLangPrefix("Default_");
     297           0 :                         const OUString aStrNone("LANGUAGE_NONE");
     298           0 :                         const OUString aStrResetLangs("RESET_LANGUAGES");
     299           0 :                         sal_Int32 nPos = -1;
     300           0 :                         if (-1 != (nPos = aNewLangTxt.indexOf( aDocumentLangPrefix , 0 )))
     301             :                         {
     302           0 :                             aNewLangTxt = aNewLangTxt.replaceAt( nPos, aDocumentLangPrefix.getLength(), "" );
     303             :                         }
     304             :                         else
     305             :                         {
     306           0 :                             break;
     307             :                         }
     308           0 :                         if (aNewLangTxt == aStrNone)
     309           0 :                             lcl_setLanguage( mpViewShell->GetDoc(), OUString() );
     310           0 :                         else if (aNewLangTxt == aStrResetLangs)
     311           0 :                             lcl_setLanguage( mpViewShell->GetDoc(), OUString(), true );
     312             :                         else
     313           0 :                             lcl_setLanguage( mpViewShell->GetDoc(), aNewLangTxt );
     314             :                     }
     315             :                 }
     316           0 :             }
     317             :         }
     318           0 :         break;
     319             : 
     320             :         default:
     321           0 :         break;
     322             :     }
     323             : }
     324             : 
     325         441 : void DrawDocShell::SetDocShellFunction( const rtl::Reference<FuPoor>& xFunction )
     326             : {
     327         441 :     if( mxDocShellFunction.is() )
     328           1 :         mxDocShellFunction->Dispose();
     329             : 
     330         441 :     mxDocShellFunction = xFunction;
     331         441 : }
     332             : 
     333          66 : } // end of namespace sd
     334             : 
     335             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11