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 : : #include "vbacomment.hxx"
29 : :
30 : : #include <ooo/vba/excel/XlCreator.hpp>
31 : : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
32 : : #include <com/sun/star/sheet/XSpreadsheet.hpp>
33 : : #include <com/sun/star/sheet/XSheetAnnotationAnchor.hpp>
34 : : #include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp>
35 : : #include <com/sun/star/sheet/XSheetAnnotationShapeSupplier.hpp>
36 : : #include <com/sun/star/sheet/XSheetCellRange.hpp>
37 : : #include <com/sun/star/sheet/XCellAddressable.hpp>
38 : : #include <com/sun/star/table/CellAddress.hpp>
39 : : #include <com/sun/star/table/XCell.hpp>
40 : : #include <com/sun/star/text/XText.hpp>
41 : :
42 : : #include <cellsuno.hxx>
43 : : #include <postit.hxx>
44 : : #include <svx/svdobj.hxx>
45 : : #include <svx/svdocapt.hxx>
46 : : #include <ooo/vba/msforms/XShape.hpp>
47 : : #include <com/sun/star/drawing/XShape.hpp>
48 : : #include <com/sun/star/frame/XModel.hpp>
49 : :
50 : : #include <vbahelper/vbashape.hxx>
51 : : #include "vbaglobals.hxx"
52 : : #include "vbacomments.hxx"
53 : :
54 : : using namespace ::ooo::vba;
55 : : using namespace ::com::sun::star;
56 : :
57 : 0 : ScVbaComment::ScVbaComment(
58 : : const uno::Reference< XHelperInterface >& xParent,
59 : : const uno::Reference< uno::XComponentContext >& xContext,
60 : : const uno::Reference< frame::XModel >& xModel,
61 : : const uno::Reference< table::XCellRange >& xRange ) throw( lang::IllegalArgumentException ) :
62 : : ScVbaComment_BASE( xParent, xContext ),
63 : : mxModel( xModel, uno::UNO_SET_THROW ),
64 [ # # ]: 0 : mxRange( xRange )
65 : : {
66 [ # # ]: 0 : if ( !xRange.is() )
67 [ # # ][ # # ]: 0 : throw lang::IllegalArgumentException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "range is not set " ) ), uno::Reference< uno::XInterface >() , 1 );
68 [ # # ][ # # ]: 0 : uno::Reference< text::XSimpleText > xAnnoText( getAnnotation(), uno::UNO_QUERY );
69 : 0 : }
70 : :
71 : : // private helper functions
72 : :
73 : : uno::Reference< sheet::XSheetAnnotation > SAL_CALL
74 : 0 : ScVbaComment::getAnnotation() throw (uno::RuntimeException)
75 : : {
76 [ # # ][ # # ]: 0 : uno::Reference< table::XCell > xCell( mxRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW );
[ # # ]
77 [ # # ]: 0 : uno::Reference< sheet::XSheetAnnotationAnchor > xAnnoAnchor( xCell, uno::UNO_QUERY_THROW );
78 [ # # ][ # # ]: 0 : return uno::Reference< sheet::XSheetAnnotation > ( xAnnoAnchor->getAnnotation(), uno::UNO_QUERY_THROW );
[ # # ]
79 : : }
80 : :
81 : : uno::Reference< sheet::XSheetAnnotations > SAL_CALL
82 : 0 : ScVbaComment::getAnnotations() throw (uno::RuntimeException)
83 : : {
84 [ # # ]: 0 : uno::Reference< sheet::XSheetCellRange > xSheetCellRange(mxRange, ::uno::UNO_QUERY_THROW );
85 [ # # ][ # # ]: 0 : uno::Reference< sheet::XSpreadsheet > xSheet = xSheetCellRange->getSpreadsheet();
86 [ # # ]: 0 : uno::Reference< sheet::XSheetAnnotationsSupplier > xAnnosSupp( xSheet, uno::UNO_QUERY_THROW );
87 : :
88 [ # # ][ # # ]: 0 : return uno::Reference< sheet::XSheetAnnotations > ( xAnnosSupp->getAnnotations(), uno::UNO_QUERY_THROW );
[ # # ]
89 : : }
90 : :
91 : : sal_Int32 SAL_CALL
92 : 0 : ScVbaComment::getAnnotationIndex() throw (uno::RuntimeException)
93 : : {
94 [ # # ]: 0 : uno::Reference< sheet::XSheetAnnotations > xAnnos = getAnnotations();
95 [ # # ][ # # ]: 0 : table::CellAddress aAddress = getAnnotation()->getPosition();
[ # # ]
96 : :
97 : 0 : sal_Int32 aIndex = 0;
98 [ # # ][ # # ]: 0 : sal_Int32 aCount = xAnnos->getCount();
99 : :
100 [ # # ]: 0 : for ( ; aIndex < aCount ; aIndex++ )
101 : : {
102 [ # # ][ # # ]: 0 : uno::Reference< sheet::XSheetAnnotation > xAnno( xAnnos->getByIndex( aIndex ), uno::UNO_QUERY_THROW );
[ # # ]
103 [ # # ][ # # ]: 0 : table::CellAddress xAddress = xAnno->getPosition();
104 : :
105 [ # # ][ # # ]: 0 : if ( xAddress.Column == aAddress.Column && xAddress.Row == aAddress.Row && xAddress.Sheet == aAddress.Sheet )
[ # # ]
106 : : {
107 : : OSL_TRACE("** terminating search, index is %d", aIndex );
108 : : break;
109 : : }
110 [ # # ]: 0 : }
111 : : OSL_TRACE("** returning index is %d", aIndex );
112 : :
113 : 0 : return aIndex;
114 : : }
115 : :
116 : : uno::Reference< excel::XComment > SAL_CALL
117 : 0 : ScVbaComment::getCommentByIndex( sal_Int32 Index ) throw (uno::RuntimeException)
118 : : {
119 [ # # ][ # # ]: 0 : uno::Reference< container::XIndexAccess > xIndexAccess( getAnnotations(), uno::UNO_QUERY_THROW );
120 : : // parent is sheet ( parent of the range which is the parent of the comment )
121 [ # # ][ # # ]: 0 : uno::Reference< XCollection > xColl( new ScVbaComments( getParent()->getParent(), mxContext, mxModel, xIndexAccess ) );
[ # # ][ # # ]
[ # # ][ # # ]
122 : :
123 [ # # ][ # # ]: 0 : return uno::Reference< excel::XComment > ( xColl->Item( uno::makeAny( Index ), uno::Any() ), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
124 : : }
125 : :
126 : : // public vba functions
127 : :
128 : : rtl::OUString SAL_CALL
129 : 0 : ScVbaComment::getAuthor() throw (uno::RuntimeException)
130 : : {
131 [ # # ][ # # ]: 0 : return getAnnotation()->getAuthor();
132 : : }
133 : :
134 : : void SAL_CALL
135 : 0 : ScVbaComment::setAuthor( const rtl::OUString& /*_author*/ ) throw (uno::RuntimeException)
136 : : {
137 : : // #TODO #FIXME implementation needed
138 : 0 : }
139 : :
140 : : uno::Reference< msforms::XShape > SAL_CALL
141 : 0 : ScVbaComment::getShape() throw (uno::RuntimeException)
142 : : {
143 [ # # ][ # # ]: 0 : uno::Reference< sheet::XSheetAnnotationShapeSupplier > xAnnoShapeSupp( getAnnotation(), uno::UNO_QUERY_THROW );
144 [ # # ][ # # ]: 0 : uno::Reference< drawing::XShape > xAnnoShape( xAnnoShapeSupp->getAnnotationShape(), uno::UNO_SET_THROW );
[ # # ]
145 [ # # ]: 0 : uno::Reference< sheet::XSheetCellRange > xCellRange( mxRange, uno::UNO_QUERY_THROW );
146 [ # # ][ # # ]: 0 : uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupp( xCellRange->getSpreadsheet(), uno::UNO_QUERY_THROW );
[ # # ]
147 [ # # ][ # # ]: 0 : uno::Reference< drawing::XShapes > xShapes( xDrawPageSupp->getDrawPage(), uno::UNO_QUERY_THROW );
[ # # ]
148 [ # # ][ # # ]: 0 : return new ScVbaShape( this, mxContext, xAnnoShape, xShapes, mxModel, office::MsoShapeType::msoComment );
[ # # ][ # # ]
149 : : }
150 : :
151 : : sal_Bool SAL_CALL
152 : 0 : ScVbaComment::getVisible() throw (uno::RuntimeException)
153 : : {
154 [ # # ][ # # ]: 0 : return getAnnotation()->getIsVisible();
155 : : }
156 : :
157 : : void SAL_CALL
158 : 0 : ScVbaComment::setVisible( sal_Bool _visible ) throw (uno::RuntimeException)
159 : : {
160 [ # # ][ # # ]: 0 : getAnnotation()->setIsVisible( _visible );
161 : 0 : }
162 : :
163 : : void SAL_CALL
164 : 0 : ScVbaComment::Delete() throw (uno::RuntimeException)
165 : : {
166 [ # # ][ # # ]: 0 : getAnnotations()->removeByIndex( getAnnotationIndex() );
[ # # ]
167 : 0 : }
168 : :
169 : : uno::Reference< excel::XComment > SAL_CALL
170 : 0 : ScVbaComment::Next() throw (uno::RuntimeException)
171 : : {
172 : : // index: uno = 0, vba = 1
173 : 0 : return getCommentByIndex( getAnnotationIndex() + 2 );
174 : : }
175 : :
176 : : uno::Reference< excel::XComment > SAL_CALL
177 : 0 : ScVbaComment::Previous() throw (uno::RuntimeException)
178 : : {
179 : : // index: uno = 0, vba = 1
180 : 0 : return getCommentByIndex( getAnnotationIndex() );
181 : : }
182 : :
183 : : rtl::OUString SAL_CALL
184 : 0 : ScVbaComment::Text( const uno::Any& aText, const uno::Any& aStart, const uno::Any& Overwrite ) throw (uno::RuntimeException)
185 : : {
186 : 0 : rtl::OUString sText;
187 : 0 : aText >>= sText;
188 : :
189 [ # # ][ # # ]: 0 : uno::Reference< text::XSimpleText > xAnnoText( getAnnotation(), uno::UNO_QUERY_THROW );
190 : :
191 [ # # ]: 0 : if ( aStart.hasValue() )
192 : : {
193 : 0 : sal_Int16 nStart = 0;
194 : 0 : sal_Bool bOverwrite = sal_True;
195 : 0 : Overwrite >>= bOverwrite;
196 : :
197 [ # # ]: 0 : if ( aStart >>= nStart )
198 : : {
199 [ # # ][ # # ]: 0 : uno::Reference< text::XTextCursor > xTextCursor( xAnnoText->createTextCursor(), uno::UNO_QUERY_THROW );
[ # # ]
200 : :
201 [ # # ]: 0 : if ( bOverwrite )
202 : : {
203 [ # # ][ # # ]: 0 : xTextCursor->collapseToStart();
204 [ # # ][ # # ]: 0 : xTextCursor->gotoStart( false );
205 [ # # ][ # # ]: 0 : xTextCursor->goRight( nStart - 1, false );
206 [ # # ][ # # ]: 0 : xTextCursor->gotoEnd( sal_True );
207 : : }
208 : : else
209 : : {
210 [ # # ][ # # ]: 0 : xTextCursor->collapseToStart();
211 [ # # ][ # # ]: 0 : xTextCursor->gotoStart( false );
212 [ # # ][ # # ]: 0 : xTextCursor->goRight( nStart - 1 , sal_True );
213 : : }
214 : :
215 [ # # ]: 0 : uno::Reference< text::XTextRange > xRange( xTextCursor, uno::UNO_QUERY_THROW );
216 [ # # ][ # # ]: 0 : xAnnoText->insertString( xRange, sText, bOverwrite );
217 [ # # ][ # # ]: 0 : return xAnnoText->getString();
218 : : }
219 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScVbaComment::Text - bad Start value " ) ), uno::Reference< uno::XInterface >() );
220 : : }
221 [ # # ]: 0 : else if ( aText.hasValue() )
222 : : {
223 [ # # ][ # # ]: 0 : uno::Reference< sheet::XCellAddressable > xCellAddr(mxRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW );
[ # # ]
224 [ # # ][ # # ]: 0 : table::CellAddress aAddress = xCellAddr->getCellAddress();
225 [ # # ][ # # ]: 0 : getAnnotations()->insertNew( aAddress, sText );
[ # # ]
226 : : }
227 : :
228 [ # # ][ # # ]: 0 : rtl::OUString sAnnoText = xAnnoText->getString();
229 : 0 : return sAnnoText;
230 : : }
231 : :
232 : : rtl::OUString
233 : 0 : ScVbaComment::getServiceImplName()
234 : : {
235 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScVbaComment"));
236 : : }
237 : :
238 : : uno::Sequence< rtl::OUString >
239 : 0 : ScVbaComment::getServiceNames()
240 : : {
241 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
242 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
243 : : {
244 : 0 : aServiceNames.realloc( 1 );
245 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.ScVbaComment" ) );
246 : : }
247 : 0 : return aServiceNames;
248 : : }
249 : :
250 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|