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