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 "vbaautotextentry.hxx"
20 : #include <vbahelper/vbahelper.hxx>
21 : #include <com/sun/star/text/XParagraphCursor.hpp>
22 : #include <tools/diagnose_ex.h>
23 : #include "wordvbahelper.hxx"
24 : #include "vbarange.hxx"
25 :
26 : using namespace ::ooo::vba;
27 : using namespace ::com::sun::star;
28 :
29 0 : SwVbaAutoTextEntry::SwVbaAutoTextEntry( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XAutoTextEntry >& xEntry ) throw ( uno::RuntimeException ) :
30 0 : SwVbaAutoTextEntry_BASE( rParent, rContext ), mxEntry( xEntry )
31 : {
32 0 : }
33 :
34 0 : SwVbaAutoTextEntry::~SwVbaAutoTextEntry()
35 : {
36 0 : }
37 :
38 0 : uno::Reference< word::XRange > SAL_CALL SwVbaAutoTextEntry::Insert( const uno::Reference< word::XRange >& _where, const uno::Any& _richtext ) throw ( uno::RuntimeException, std::exception )
39 : {
40 0 : SwVbaRange* pWhere = dynamic_cast<SwVbaRange*>( _where.get() );
41 0 : if( pWhere )
42 : {
43 0 : uno::Reference< text::XTextRange > xTextRange = pWhere->getXTextRange();
44 0 : xTextRange->setString( OUString("x") ); // set marker
45 0 : uno::Reference< text::XTextRange > xEndMarker = xTextRange->getEnd();
46 0 : xEndMarker->setString( OUString("x") ); // set marker
47 0 : uno::Reference< text::XText > xText = pWhere->getXText();
48 0 : mxEntry->applyTo( xEndMarker->getStart() );
49 0 : uno::Reference< text::XTextCursor > xTC = xText->createTextCursorByRange( xTextRange->getStart() );
50 0 : xTC->goRight( 1, sal_True );
51 0 : xTC->setString( OUString("") ); // remove marker
52 : // remove the blank paragraph if it is a rich text
53 0 : bool bRich = false;
54 0 : _richtext >>= bRich;
55 0 : if( bRich )
56 : {
57 : // check if it is a blank paragraph
58 0 : uno::Reference< text::XParagraphCursor > xParaCursor( xTC, uno::UNO_QUERY_THROW );
59 0 : if( xParaCursor->isStartOfParagraph() && xParaCursor->isEndOfParagraph() )
60 : {
61 : //remove the blank paragraph
62 0 : uno::Reference< frame::XModel > xModel( getCurrentWordDoc( mxContext ), uno::UNO_QUERY_THROW );
63 0 : uno::Reference< text::XTextViewCursor > xTVCursor = word::getXTextViewCursor( xModel );
64 0 : uno::Reference< text::XTextRange > xCurrentRange( xTC->getEnd(), uno::UNO_QUERY_THROW );
65 0 : xTVCursor->gotoRange( xCurrentRange, sal_False );
66 0 : OUString url = ".uno:Delete";
67 0 : dispatchRequests( xModel,url );
68 0 : xTVCursor->gotoRange( xEndMarker->getEnd(), sal_False );
69 0 : }
70 : }
71 0 : xEndMarker->setString( OUString("") ); // remove marker
72 0 : xTC = xText->createTextCursorByRange( xEndMarker->getEnd() );
73 0 : pWhere->setXTextCursor( xTC );
74 : }
75 0 : return uno::Reference< word::XRange >( pWhere );
76 : }
77 :
78 : OUString
79 0 : SwVbaAutoTextEntry::getServiceImplName()
80 : {
81 0 : return OUString("SwVbaAutoTextEntry");
82 : }
83 :
84 : uno::Sequence< OUString >
85 0 : SwVbaAutoTextEntry::getServiceNames()
86 : {
87 0 : static uno::Sequence< OUString > aServiceNames;
88 0 : if ( aServiceNames.getLength() == 0 )
89 : {
90 0 : aServiceNames.realloc( 1 );
91 0 : aServiceNames[ 0 ] = "ooo.vba.word.AutoTextEntry";
92 : }
93 0 : return aServiceNames;
94 : }
95 :
96 0 : SwVbaAutoTextEntries::SwVbaAutoTextEntries( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< ::com::sun::star::uno::XComponentContext > & xContext, const uno::Reference< container::XIndexAccess >& xIndexAccess ) throw (uno::RuntimeException) : SwVbaAutoTextEntries_BASE( xParent, xContext, xIndexAccess ), mxAutoTextEntryAccess( xIndexAccess )
97 : {
98 0 : }
99 :
100 : // XEnumerationAccess
101 : uno::Type
102 0 : SwVbaAutoTextEntries::getElementType() throw (uno::RuntimeException)
103 : {
104 0 : return cppu::UnoType<word::XAutoTextEntry>::get();
105 : }
106 : uno::Reference< container::XEnumeration >
107 0 : SwVbaAutoTextEntries::createEnumeration() throw (uno::RuntimeException)
108 : {
109 0 : throw uno::RuntimeException("Not implemented" );
110 : }
111 :
112 : uno::Any
113 0 : SwVbaAutoTextEntries::createCollectionObject( const css::uno::Any& aSource )
114 : {
115 0 : uno::Reference< text::XAutoTextEntry > xEntry( aSource, uno::UNO_QUERY_THROW );
116 0 : return uno::makeAny( uno::Reference< word::XAutoTextEntry >( new SwVbaAutoTextEntry( this, mxContext, xEntry ) ) );
117 : }
118 :
119 : OUString
120 0 : SwVbaAutoTextEntries::getServiceImplName()
121 : {
122 0 : return OUString("SwVbaAutoTextEntries");
123 : }
124 :
125 : css::uno::Sequence<OUString>
126 0 : SwVbaAutoTextEntries::getServiceNames()
127 : {
128 0 : static uno::Sequence< OUString > sNames;
129 0 : if ( sNames.getLength() == 0 )
130 : {
131 0 : sNames.realloc( 1 );
132 0 : sNames[0] = "ooo.vba.word.AutoTextEntries";
133 : }
134 0 : return sNames;
135 : }
136 :
137 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|