LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/vba - vbaview.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 154 0.0 %
Date: 2012-12-17 Functions: 0 14 0.0 %
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             : #include "vbaview.hxx"
      20             : #include <vbahelper/vbahelper.hxx>
      21             : #include <tools/diagnose_ex.h>
      22             : #include <com/sun/star/beans/XPropertySet.hpp>
      23             : #include <com/sun/star/view/XViewSettingsSupplier.hpp>
      24             : #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
      25             : #include <com/sun/star/text/XText.hpp>
      26             : #include <com/sun/star/text/XTextTable.hpp>
      27             : #include <com/sun/star/table/XCellRange.hpp>
      28             : #include <com/sun/star/text/XTextDocument.hpp>
      29             : #include <com/sun/star/text/XFootnotesSupplier.hpp>
      30             : #include <com/sun/star/text/XEndnotesSupplier.hpp>
      31             : #include <com/sun/star/container/XIndexAccess.hpp>
      32             : #include <com/sun/star/container/XEnumerationAccess.hpp>
      33             : #include <com/sun/star/container/XEnumeration.hpp>
      34             : #include <com/sun/star/frame/XController.hpp>
      35             : #include <com/sun/star/lang/XServiceInfo.hpp>
      36             : #include <ooo/vba/word/WdSpecialPane.hpp>
      37             : #include <ooo/vba/word/WdViewType.hpp>
      38             : #include <ooo/vba/word/WdSeekView.hpp>
      39             : 
      40             : #include "wordvbahelper.hxx"
      41             : #include "vbaheaderfooterhelper.hxx"
      42             : #include <view.hxx>
      43             : 
      44             : using namespace ::ooo::vba;
      45             : using namespace ::com::sun::star;
      46             : 
      47             : static const sal_Int32 DEFAULT_BODY_DISTANCE = 500;
      48             : 
      49           0 : SwVbaView::SwVbaView( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext,
      50             :     const uno::Reference< frame::XModel >& rModel ) throw ( uno::RuntimeException ) :
      51           0 :     SwVbaView_BASE( rParent, rContext ), mxModel( rModel )
      52             : {
      53           0 :     uno::Reference< frame::XController > xController = mxModel->getCurrentController();
      54             : 
      55           0 :     uno::Reference< text::XTextViewCursorSupplier > xTextViewCursorSupp( xController, uno::UNO_QUERY_THROW );
      56           0 :     mxViewCursor = xTextViewCursorSupp->getViewCursor();
      57             : 
      58           0 :     uno::Reference< view::XViewSettingsSupplier > xViewSettingSupp( xController, uno::UNO_QUERY_THROW );
      59           0 :     mxViewSettings.set( xViewSettingSupp->getViewSettings(), uno::UNO_QUERY_THROW );
      60           0 : }
      61             : 
      62           0 : SwVbaView::~SwVbaView()
      63             : {
      64           0 : }
      65             : 
      66             : ::sal_Int32 SAL_CALL
      67           0 : SwVbaView::getSeekView() throw (css::uno::RuntimeException)
      68             : {
      69             :     // FIXME: if the view cursor is in table, field, section and frame
      70             :     // handle if the cursor is in table
      71           0 :     uno::Reference< text::XText > xCurrentText = mxViewCursor->getText();
      72           0 :     uno::Reference< beans::XPropertySet > xCursorProps( mxViewCursor, uno::UNO_QUERY_THROW );
      73           0 :     uno::Reference< text::XTextContent > xTextContent;
      74           0 :     while( xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ) >>= xTextContent )
      75             :     {
      76           0 :         xCurrentText = xTextContent->getAnchor()->getText();
      77           0 :         xCursorProps.set( xCurrentText->createTextCursor(), uno::UNO_QUERY_THROW );
      78             :     }
      79           0 :     uno::Reference< lang::XServiceInfo > xServiceInfo( xCurrentText, uno::UNO_QUERY_THROW );
      80           0 :     rtl::OUString aImplName = xServiceInfo->getImplementationName();
      81           0 :     if ( aImplName == "SwXBodyText" )
      82             :     {
      83           0 :         return word::WdSeekView::wdSeekMainDocument;
      84             :     }
      85           0 :     else if ( aImplName == "SwXHeadFootText" )
      86             :     {
      87           0 :         if( HeaderFooterHelper::isHeader( mxModel ) )
      88             :         {
      89           0 :             if( HeaderFooterHelper::isFirstPageHeader( mxModel ) )
      90           0 :                 return word::WdSeekView::wdSeekFirstPageHeader;
      91           0 :             else if( HeaderFooterHelper::isEvenPagesHeader( mxModel ) )
      92           0 :                 return word::WdSeekView::wdSeekEvenPagesHeader;
      93             :             else
      94           0 :                 return word::WdSeekView::wdSeekPrimaryHeader;
      95             :         }
      96             :         else
      97             :         {
      98           0 :             if( HeaderFooterHelper::isFirstPageFooter( mxModel ) )
      99           0 :                 return word::WdSeekView::wdSeekFirstPageFooter;
     100           0 :             else if( HeaderFooterHelper::isEvenPagesFooter( mxModel ) )
     101           0 :                 return word::WdSeekView::wdSeekEvenPagesFooter;
     102             :             else
     103           0 :                 return word::WdSeekView::wdSeekPrimaryFooter;
     104             :         }
     105             :     }
     106           0 :     else if ( aImplName == "SwXFootnote" )
     107             :     {
     108           0 :         if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Endnote") ) ) )
     109           0 :             return word::WdSeekView::wdSeekEndnotes;
     110             :         else
     111           0 :             return word::WdSeekView::wdSeekFootnotes;
     112             :     }
     113             : 
     114           0 :     return word::WdSeekView::wdSeekMainDocument;
     115             : }
     116             : 
     117             : void SAL_CALL
     118           0 : SwVbaView::setSeekView( ::sal_Int32 _seekview ) throw (css::uno::RuntimeException)
     119             : {
     120             :     // FIXME: save the current cursor position, if the cursor is in the main
     121             :     // document, so we can jump back to this position, if the macro sets
     122             :     // the ViewMode back to wdSeekMainDocument
     123             : 
     124           0 :     word::gotoSelectedObjectAnchor( mxModel );
     125           0 :     switch( _seekview )
     126             :     {
     127             :         case word::WdSeekView::wdSeekFirstPageFooter:
     128             :         case word::WdSeekView::wdSeekFirstPageHeader:
     129             :         case word::WdSeekView::wdSeekCurrentPageFooter:
     130             :         case word::WdSeekView::wdSeekCurrentPageHeader:
     131             :         case word::WdSeekView::wdSeekPrimaryFooter:
     132             :         case word::WdSeekView::wdSeekPrimaryHeader:
     133             :         case word::WdSeekView::wdSeekEvenPagesFooter:
     134             :         case word::WdSeekView::wdSeekEvenPagesHeader:
     135             :         {
     136             :             // need to test
     137           0 :             mxViewCursor->gotoRange( getHFTextRange( _seekview ), sal_False );
     138           0 :             break;
     139             :         }
     140             :         case word::WdSeekView::wdSeekFootnotes:
     141             :         {
     142           0 :             uno::Reference< text::XFootnotesSupplier > xFootnotesSupp( mxModel, uno::UNO_QUERY_THROW );
     143           0 :             uno::Reference< container::XIndexAccess > xFootnotes( xFootnotesSupp->getFootnotes(), uno::UNO_QUERY_THROW );
     144           0 :             if( xFootnotes->getCount() > 0 )
     145             :             {
     146           0 :                 uno::Reference< text::XText > xText( xFootnotes->getByIndex(0), uno::UNO_QUERY_THROW );
     147           0 :                 mxViewCursor->gotoRange( xText->getStart(), sal_False );
     148             :             }
     149             :             else
     150             :             {
     151           0 :                 DebugHelper::exception( SbERR_NO_ACTIVE_OBJECT, rtl::OUString() );
     152             :             }
     153           0 :             break;
     154             :         }
     155             :         case word::WdSeekView::wdSeekEndnotes:
     156             :         {
     157           0 :             uno::Reference< text::XEndnotesSupplier > xEndnotesSupp( mxModel, uno::UNO_QUERY_THROW );
     158           0 :             uno::Reference< container::XIndexAccess > xEndnotes( xEndnotesSupp->getEndnotes(), uno::UNO_QUERY_THROW );
     159           0 :             if( xEndnotes->getCount() > 0 )
     160             :             {
     161           0 :                 uno::Reference< text::XText > xText( xEndnotes->getByIndex(0), uno::UNO_QUERY_THROW );
     162           0 :                 mxViewCursor->gotoRange( xText->getStart(), sal_False );
     163             :             }
     164             :             else
     165             :             {
     166           0 :                 DebugHelper::exception( SbERR_NO_ACTIVE_OBJECT, rtl::OUString() );
     167             :             }
     168           0 :             break;
     169             :         }
     170             :         case word::WdSeekView::wdSeekMainDocument:
     171             :         {
     172           0 :             uno::Reference< text::XTextDocument > xTextDocument( mxModel, uno::UNO_QUERY_THROW );
     173           0 :             uno::Reference< text::XText > xText = xTextDocument->getText();
     174           0 :             mxViewCursor->gotoRange( word::getFirstObjectPosition( xText ), sal_False );
     175           0 :             break;
     176             :         }
     177             :     }
     178           0 : }
     179             : 
     180             : ::sal_Int32 SAL_CALL
     181           0 : SwVbaView::getSplitSpecial() throw (css::uno::RuntimeException)
     182             : {
     183           0 :     return word::WdSpecialPane::wdPaneNone;
     184             : }
     185             : 
     186             : void SAL_CALL
     187           0 : SwVbaView::setSplitSpecial( ::sal_Int32/* _splitspecial */) throw (css::uno::RuntimeException)
     188             : {
     189             :     // not support in Writer
     190           0 : }
     191             : 
     192             : ::sal_Bool SAL_CALL
     193           0 : SwVbaView::getTableGridLines() throw (css::uno::RuntimeException)
     194             : {
     195           0 :     sal_Bool bShowTableGridLine = sal_False;
     196           0 :     mxViewSettings->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ShowTableBoundaries"))) >>= bShowTableGridLine;
     197           0 :     return bShowTableGridLine;
     198             : }
     199             : 
     200             : void SAL_CALL
     201           0 : SwVbaView::setTableGridLines( ::sal_Bool _tablegridlines ) throw (css::uno::RuntimeException)
     202             : {
     203           0 :     mxViewSettings->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ShowTableBoundaries")), uno::makeAny( _tablegridlines ) );
     204           0 : }
     205             : 
     206             : ::sal_Int32 SAL_CALL
     207           0 : SwVbaView::getType() throw (css::uno::RuntimeException)
     208             : {
     209             :     // FIXME: handle wdPrintPreview type
     210           0 :     sal_Bool bOnlineLayout = sal_False;
     211           0 :     mxViewSettings->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ShowOnlineLayout"))) >>= bOnlineLayout;
     212           0 :     return bOnlineLayout ? word::WdViewType::wdWebView : word::WdViewType::wdPrintView;
     213             : }
     214             : 
     215             : void SAL_CALL
     216           0 : SwVbaView::setType( ::sal_Int32 _type ) throw (css::uno::RuntimeException)
     217             : {
     218             :     // FIXME: handle wdPrintPreview type
     219           0 :     switch( _type )
     220             :     {
     221             :         case word::WdViewType::wdPrintView:
     222             :         case word::WdViewType::wdNormalView:
     223             :         {
     224           0 :             mxViewSettings->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ShowOnlineLayout")), uno::makeAny( sal_False ) );
     225           0 :             break;
     226             :         }
     227             :         case word::WdViewType::wdWebView:
     228             :         {
     229           0 :             mxViewSettings->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ShowOnlineLayout")), uno::makeAny( sal_True ) );
     230           0 :             break;
     231             :         }
     232             :         case word::WdViewType::wdPrintPreview:
     233             :         {
     234           0 :             PrintPreviewHelper( uno::Any(),word::getView( mxModel ) );
     235           0 :             break;
     236             :         }
     237             :         default:
     238           0 :             DebugHelper::exception( SbERR_NOT_IMPLEMENTED, rtl::OUString() );
     239             : 
     240             :     }
     241           0 : }
     242             : 
     243           0 : uno::Reference< text::XTextRange > SwVbaView::getHFTextRange( sal_Int32 nType ) throw (uno::RuntimeException)
     244             : {
     245           0 :     mxModel->lockControllers();
     246             : 
     247           0 :     rtl::OUString aPropIsOn;
     248           0 :     rtl::OUString aPropIsShared;
     249           0 :     rtl::OUString aPropBodyDistance;
     250           0 :     rtl::OUString aPropText;
     251             : 
     252           0 :     switch( nType )
     253             :     {
     254             :         case word::WdSeekView::wdSeekCurrentPageFooter:
     255             :         case word::WdSeekView::wdSeekFirstPageFooter:
     256             :         case word::WdSeekView::wdSeekPrimaryFooter:
     257             :         case word::WdSeekView::wdSeekEvenPagesFooter:
     258             :         {
     259           0 :             aPropIsOn = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsOn") );
     260           0 :             aPropIsShared = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsShared") );
     261           0 :             aPropBodyDistance = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterBodyDistance") );
     262           0 :             aPropText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterText") );
     263           0 :             break;
     264             :         }
     265             :         case word::WdSeekView::wdSeekCurrentPageHeader:
     266             :         case word::WdSeekView::wdSeekFirstPageHeader:
     267             :         case word::WdSeekView::wdSeekPrimaryHeader:
     268             :         case word::WdSeekView::wdSeekEvenPagesHeader:
     269             :         {
     270           0 :             aPropIsOn = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn") );
     271           0 :             aPropIsShared = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsShared") );
     272           0 :             aPropBodyDistance = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderBodyDistance") );
     273           0 :             aPropText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderText") );
     274           0 :             break;
     275             :         }
     276             :     }
     277             : 
     278           0 :     uno::Reference< text::XPageCursor > xPageCursor( mxViewCursor, uno::UNO_QUERY_THROW );
     279             : 
     280           0 :     if( nType == word::WdSeekView::wdSeekFirstPageFooter
     281             :         || nType == word::WdSeekView::wdSeekFirstPageHeader )
     282             :     {
     283           0 :         xPageCursor->jumpToFirstPage();
     284             :     }
     285             : 
     286           0 :     uno::Reference< style::XStyle > xStyle;
     287           0 :     uno::Reference< text::XText > xText;
     288           0 :     switch( nType )
     289             :     {
     290             :         case word::WdSeekView::wdSeekPrimaryFooter:
     291             :         case word::WdSeekView::wdSeekPrimaryHeader:
     292             :         case word::WdSeekView::wdSeekEvenPagesFooter:
     293             :         case word::WdSeekView::wdSeekEvenPagesHeader:
     294             :         {
     295             :             // The primary header is the first header of the section.
     296             :             // If the header is not shared between odd and even pages
     297             :             // the odd page's header is the primary header. If the
     298             :             // first page's header is different from the rest of the
     299             :             // document, it is NOT the primary header ( the next primary
     300             :             // header would be on page 3 )
     301             :             // The even pages' header is only available if the header is
     302             :             // not shared and the current style is applied to a page with
     303             :             // an even page number
     304           0 :             uno::Reference< beans::XPropertySet > xCursorProps( mxViewCursor, uno::UNO_QUERY_THROW );
     305           0 :             rtl::OUString aPageStyleName;
     306           0 :             xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyleName"))) >>= aPageStyleName;
     307           0 :             if ( aPageStyleName == "First Page" )
     308             :             {
     309             :                 // go to the beginning of where the next style is used
     310           0 :                 sal_Bool hasNextPage = sal_False;
     311           0 :                 xStyle = word::getCurrentPageStyle( mxModel );
     312           0 :                 do
     313             :                 {
     314           0 :                     hasNextPage = xPageCursor->jumpToNextPage();
     315             :                 }
     316           0 :                 while( hasNextPage && ( xStyle == word::getCurrentPageStyle( mxModel ) ) );
     317             : 
     318           0 :                 if( !hasNextPage )
     319           0 :                     DebugHelper::exception( SbERR_BAD_ACTION, rtl::OUString() );
     320             :             }
     321           0 :             break;
     322             :         }
     323             :         default:
     324             :         {
     325           0 :             break;
     326             :         }
     327             :     }
     328             : 
     329           0 :     xStyle = word::getCurrentPageStyle( mxModel );
     330           0 :     uno::Reference< beans::XPropertySet > xPageProps( xStyle, uno::UNO_QUERY_THROW );
     331           0 :     sal_Bool isOn = sal_False;
     332           0 :     xPageProps->getPropertyValue( aPropIsOn ) >>= isOn;
     333           0 :     sal_Bool isShared =  sal_False;
     334           0 :     xPageProps->getPropertyValue( aPropIsShared ) >>= isShared;
     335           0 :     if( !isOn )
     336             :     {
     337           0 :         xPageProps->setPropertyValue( aPropIsOn, uno::makeAny( sal_True ) );
     338           0 :         xPageProps->setPropertyValue( aPropBodyDistance, uno::makeAny( DEFAULT_BODY_DISTANCE ) );
     339             :     }
     340           0 :     if( !isShared )
     341             :     {
     342           0 :         rtl::OUString aTempPropText = aPropText;
     343           0 :         if( nType == word::WdSeekView::wdSeekEvenPagesFooter
     344             :             || nType == word::WdSeekView::wdSeekEvenPagesHeader )
     345             :         {
     346           0 :             aTempPropText += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Left") );
     347             :         }
     348             :         else
     349             :         {
     350           0 :             aTempPropText += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Right") );
     351             :         }
     352           0 :         xText.set( xPageProps->getPropertyValue( aTempPropText), uno::UNO_QUERY_THROW );
     353             :     }
     354             :     else
     355             :     {
     356           0 :         if( nType == word::WdSeekView::wdSeekEvenPagesFooter
     357             :             || nType == word::WdSeekView::wdSeekEvenPagesHeader )
     358             :         {
     359           0 :             DebugHelper::exception( SbERR_BAD_ACTION, rtl::OUString() );
     360             :         }
     361           0 :         xText.set( xPageProps->getPropertyValue( aPropText ), uno::UNO_QUERY_THROW );
     362             :     }
     363             : 
     364           0 :     mxModel->unlockControllers();
     365           0 :     if( !xText.is() )
     366             :     {
     367           0 :         DebugHelper::exception( SbERR_INTERNAL_ERROR, rtl::OUString() );
     368             :     }
     369           0 :     uno::Reference< text::XTextRange > xTextRange = word::getFirstObjectPosition( xText );
     370           0 :     return xTextRange;
     371             : }
     372             : 
     373             : rtl::OUString
     374           0 : SwVbaView::getServiceImplName()
     375             : {
     376           0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaView"));
     377             : }
     378             : 
     379             : uno::Sequence< rtl::OUString >
     380           0 : SwVbaView::getServiceNames()
     381             : {
     382           0 :     static uno::Sequence< rtl::OUString > aServiceNames;
     383           0 :     if ( aServiceNames.getLength() == 0 )
     384             :     {
     385           0 :         aServiceNames.realloc( 1 );
     386           0 :         aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.View" ) );
     387             :     }
     388           0 :     return aServiceNames;
     389             : }
     390             : 
     391             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10