xref: /aoo42x/main/sc/source/ui/vba/vbasheetobject.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "vbasheetobject.hxx"
29*cdf0e10cSrcweir #include <com/sun/star/awt/TextAlign.hpp>
30*cdf0e10cSrcweir #include <com/sun/star/container/XIndexContainer.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/drawing/XControlShape.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/script/ScriptEventDescriptor.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/script/XEventAttacherManager.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/style/VerticalAlignment.hpp>
35*cdf0e10cSrcweir #include <ooo/vba/excel/Constants.hpp>
36*cdf0e10cSrcweir #include <ooo/vba/excel/XlOrientation.hpp>
37*cdf0e10cSrcweir #include <ooo/vba/excel/XlPlacement.hpp>
38*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
39*cdf0e10cSrcweir #include <filter/msfilter/msvbahelper.hxx>
40*cdf0e10cSrcweir #include <oox/helper/helper.hxx>
41*cdf0e10cSrcweir #include <svx/unoshape.hxx>
42*cdf0e10cSrcweir #include "vbafont.hxx"
43*cdf0e10cSrcweir #include "drwlayer.hxx"
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir using ::rtl::OUString;
46*cdf0e10cSrcweir using namespace ::com::sun::star;
47*cdf0e10cSrcweir using namespace ::ooo::vba;
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir // ============================================================================
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir ScVbaButtonCharacters::ScVbaButtonCharacters(
52*cdf0e10cSrcweir         const uno::Reference< XHelperInterface >& rxParent,
53*cdf0e10cSrcweir         const uno::Reference< uno::XComponentContext >& rxContext,
54*cdf0e10cSrcweir         const uno::Reference< beans::XPropertySet >& rxPropSet,
55*cdf0e10cSrcweir         const ScVbaPalette& rPalette,
56*cdf0e10cSrcweir         const uno::Any& rStart,
57*cdf0e10cSrcweir         const uno::Any& rLength ) throw (uno::RuntimeException) :
58*cdf0e10cSrcweir     ScVbaButtonCharacters_BASE( rxParent, rxContext ),
59*cdf0e10cSrcweir     maPalette( rPalette ),
60*cdf0e10cSrcweir     mxPropSet( rxPropSet, uno::UNO_SET_THROW )
61*cdf0e10cSrcweir {
62*cdf0e10cSrcweir     // extract optional start parameter (missing or invalid -> from beginning)
63*cdf0e10cSrcweir     if( !(rStart >>= mnStart) || (mnStart < 1) )
64*cdf0e10cSrcweir         mnStart = 1;
65*cdf0e10cSrcweir     --mnStart;  // VBA is 1-based, rtl string is 0-based
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir     // extract optional length parameter (missing or invalid -> to end)
68*cdf0e10cSrcweir     if( !(rLength >>= mnLength) || (mnLength < 1) )
69*cdf0e10cSrcweir         mnLength = SAL_MAX_INT32;
70*cdf0e10cSrcweir }
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir ScVbaButtonCharacters::~ScVbaButtonCharacters()
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir }
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir // XCharacters attributes
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir OUString SAL_CALL ScVbaButtonCharacters::getCaption() throw (uno::RuntimeException)
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir     // ignore invalid mnStart and/or mnLength members
81*cdf0e10cSrcweir     OUString aString = getFullString();
82*cdf0e10cSrcweir     sal_Int32 nStart = ::std::min( mnStart, aString.getLength() );
83*cdf0e10cSrcweir     sal_Int32 nLength = ::std::min( mnLength, aString.getLength() - nStart );
84*cdf0e10cSrcweir     return aString.copy( nStart, nLength );
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir void SAL_CALL ScVbaButtonCharacters::setCaption( const OUString& rCaption ) throw (uno::RuntimeException)
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir     /*  Replace the covered text with the passed text, ignore invalid mnStart
90*cdf0e10cSrcweir         and/or mnLength members. This operation does not affect the mnLength
91*cdf0e10cSrcweir         parameter. If the inserted text is longer than mnLength, the additional
92*cdf0e10cSrcweir         characters are not covered by this object. If the inserted text is
93*cdf0e10cSrcweir         shorter than mnLength, other uncovered characters from the original
94*cdf0e10cSrcweir         string will be covered now, thus may be changed with subsequent
95*cdf0e10cSrcweir         operations. */
96*cdf0e10cSrcweir     OUString aString = getFullString();
97*cdf0e10cSrcweir     sal_Int32 nStart = ::std::min( mnStart, aString.getLength() );
98*cdf0e10cSrcweir     sal_Int32 nLength = ::std::min( mnLength, aString.getLength() - nStart );
99*cdf0e10cSrcweir     setFullString( aString.replaceAt( nStart, nLength, rCaption ) );
100*cdf0e10cSrcweir }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir sal_Int32 SAL_CALL ScVbaButtonCharacters::getCount() throw (uno::RuntimeException)
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir     // always return the total length of the caption
105*cdf0e10cSrcweir     return getFullString().getLength();
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir OUString SAL_CALL ScVbaButtonCharacters::getText() throw (uno::RuntimeException)
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir     // Text attribute same as Caption attribute?
111*cdf0e10cSrcweir     return getCaption();
112*cdf0e10cSrcweir }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir void SAL_CALL ScVbaButtonCharacters::setText( const OUString& rText ) throw (uno::RuntimeException)
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir     // Text attribute same as Caption attribute?
117*cdf0e10cSrcweir     setCaption( rText );
118*cdf0e10cSrcweir }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir uno::Reference< excel::XFont > SAL_CALL ScVbaButtonCharacters::getFont() throw (uno::RuntimeException)
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir     return new ScVbaFont( this, mxContext, maPalette, mxPropSet, 0, true );
123*cdf0e10cSrcweir }
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir void SAL_CALL ScVbaButtonCharacters::setFont( const uno::Reference< excel::XFont >& /*rxFont*/ ) throw (uno::RuntimeException)
126*cdf0e10cSrcweir {
127*cdf0e10cSrcweir     // TODO
128*cdf0e10cSrcweir }
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir // XCharacters methods
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir void SAL_CALL ScVbaButtonCharacters::Insert( const OUString& rString ) throw (uno::RuntimeException)
133*cdf0e10cSrcweir {
134*cdf0e10cSrcweir     /*  The Insert() operation is in fact "replace covered characters", at
135*cdf0e10cSrcweir         least for buttons... It seems there is no easy way to really insert a
136*cdf0e10cSrcweir         substring. This operation does not affect the mnLength parameter. */
137*cdf0e10cSrcweir     setCaption( rString );
138*cdf0e10cSrcweir }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir void SAL_CALL ScVbaButtonCharacters::Delete() throw (uno::RuntimeException)
141*cdf0e10cSrcweir {
142*cdf0e10cSrcweir     /*  The Delete() operation is nothing else than "replace with empty string".
143*cdf0e10cSrcweir         This does not affect the mnLength parameter, multiple calls of Delete()
144*cdf0e10cSrcweir         will remove characters as long as there are some more covered by this
145*cdf0e10cSrcweir         object. */
146*cdf0e10cSrcweir     setCaption( OUString() );
147*cdf0e10cSrcweir }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir // XHelperInterface
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir VBAHELPER_IMPL_XHELPERINTERFACE( ScVbaButtonCharacters, "ooo.vba.excel.Characters" )
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir // private
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir OUString ScVbaButtonCharacters::getFullString() const throw (uno::RuntimeException)
156*cdf0e10cSrcweir {
157*cdf0e10cSrcweir     return mxPropSet->getPropertyValue( CREATE_OUSTRING( "Label" ) ).get< OUString >();
158*cdf0e10cSrcweir }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir void ScVbaButtonCharacters::setFullString( const OUString& rString ) throw (uno::RuntimeException)
161*cdf0e10cSrcweir {
162*cdf0e10cSrcweir     mxPropSet->setPropertyValue( CREATE_OUSTRING( "Label" ), uno::Any( rString ) );
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir // ============================================================================
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir ScVbaSheetObjectBase::ScVbaSheetObjectBase(
168*cdf0e10cSrcweir         const uno::Reference< XHelperInterface >& rxParent,
169*cdf0e10cSrcweir         const uno::Reference< uno::XComponentContext >& rxContext,
170*cdf0e10cSrcweir         const uno::Reference< frame::XModel >& rxModel,
171*cdf0e10cSrcweir         const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException) :
172*cdf0e10cSrcweir     ScVbaSheetObject_BASE( rxParent, rxContext ),
173*cdf0e10cSrcweir     maPalette( rxModel ),
174*cdf0e10cSrcweir     mxModel( rxModel, uno::UNO_SET_THROW ),
175*cdf0e10cSrcweir     mxShape( rxShape, uno::UNO_SET_THROW ),
176*cdf0e10cSrcweir     mxShapeProps( rxShape, uno::UNO_QUERY_THROW )
177*cdf0e10cSrcweir {
178*cdf0e10cSrcweir }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir // XSheetObject attributes
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir double SAL_CALL ScVbaSheetObjectBase::getLeft() throw (uno::RuntimeException)
183*cdf0e10cSrcweir {
184*cdf0e10cSrcweir     return HmmToPoints( mxShape->getPosition().X );
185*cdf0e10cSrcweir }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir void SAL_CALL ScVbaSheetObjectBase::setLeft( double fLeft ) throw (uno::RuntimeException)
188*cdf0e10cSrcweir {
189*cdf0e10cSrcweir     if( fLeft < 0.0 )
190*cdf0e10cSrcweir         throw uno::RuntimeException();
191*cdf0e10cSrcweir     mxShape->setPosition( awt::Point( PointsToHmm( fLeft ), mxShape->getPosition().Y ) );
192*cdf0e10cSrcweir }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir double SAL_CALL ScVbaSheetObjectBase::getTop() throw (uno::RuntimeException)
195*cdf0e10cSrcweir {
196*cdf0e10cSrcweir     return HmmToPoints( mxShape->getPosition().Y );
197*cdf0e10cSrcweir }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir void SAL_CALL ScVbaSheetObjectBase::setTop( double fTop ) throw (uno::RuntimeException)
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir     if( fTop < 0.0 )
202*cdf0e10cSrcweir         throw uno::RuntimeException();
203*cdf0e10cSrcweir     mxShape->setPosition( awt::Point( mxShape->getPosition().X, PointsToHmm( fTop ) ) );
204*cdf0e10cSrcweir }
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir double SAL_CALL ScVbaSheetObjectBase::getWidth() throw (uno::RuntimeException)
207*cdf0e10cSrcweir {
208*cdf0e10cSrcweir     return HmmToPoints( mxShape->getSize().Width );
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir void SAL_CALL ScVbaSheetObjectBase::setWidth( double fWidth ) throw (uno::RuntimeException)
212*cdf0e10cSrcweir {
213*cdf0e10cSrcweir     if( fWidth <= 0.0 )
214*cdf0e10cSrcweir         throw uno::RuntimeException();
215*cdf0e10cSrcweir     mxShape->setSize( awt::Size( PointsToHmm( fWidth ), mxShape->getSize().Height ) );
216*cdf0e10cSrcweir }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir double SAL_CALL ScVbaSheetObjectBase::getHeight() throw (uno::RuntimeException)
219*cdf0e10cSrcweir {
220*cdf0e10cSrcweir     return HmmToPoints( mxShape->getSize().Height );
221*cdf0e10cSrcweir }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir void SAL_CALL ScVbaSheetObjectBase::setHeight( double fHeight ) throw (uno::RuntimeException)
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir     if( fHeight <= 0.0 )
226*cdf0e10cSrcweir         throw uno::RuntimeException();
227*cdf0e10cSrcweir     mxShape->setSize( awt::Size( mxShape->getSize().Width, PointsToHmm( fHeight ) ) );
228*cdf0e10cSrcweir }
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir OUString SAL_CALL ScVbaSheetObjectBase::getName() throw (uno::RuntimeException)
231*cdf0e10cSrcweir {
232*cdf0e10cSrcweir     return mxShapeProps->getPropertyValue( CREATE_OUSTRING( "Name" ) ).get< OUString >();
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir void SAL_CALL ScVbaSheetObjectBase::setName( const OUString& rName ) throw (uno::RuntimeException)
236*cdf0e10cSrcweir {
237*cdf0e10cSrcweir     mxShapeProps->setPropertyValue( CREATE_OUSTRING( "Name" ), uno::Any( rName ) );
238*cdf0e10cSrcweir }
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir sal_Int32 SAL_CALL ScVbaSheetObjectBase::getPlacement() throw (uno::RuntimeException)
241*cdf0e10cSrcweir {
242*cdf0e10cSrcweir     sal_Int32 nRet = excel::XlPlacement::xlMoveAndSize;
243*cdf0e10cSrcweir     SvxShape* pShape = SvxShape::getImplementation( mxShape );
244*cdf0e10cSrcweir     if(pShape)
245*cdf0e10cSrcweir     {
246*cdf0e10cSrcweir         SdrObject* pObj = pShape->GetSdrObject();
247*cdf0e10cSrcweir         if (pObj)
248*cdf0e10cSrcweir         {
249*cdf0e10cSrcweir             ScAnchorType eType = ScDrawLayer::GetAnchor(pObj);
250*cdf0e10cSrcweir             if (eType == SCA_PAGE)
251*cdf0e10cSrcweir                 nRet = excel::XlPlacement::xlFreeFloating;
252*cdf0e10cSrcweir         }
253*cdf0e10cSrcweir     }
254*cdf0e10cSrcweir     return nRet;
255*cdf0e10cSrcweir }
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir void SAL_CALL ScVbaSheetObjectBase::setPlacement( sal_Int32 nPlacement ) throw (uno::RuntimeException)
258*cdf0e10cSrcweir {
259*cdf0e10cSrcweir     SvxShape* pShape = SvxShape::getImplementation( mxShape );
260*cdf0e10cSrcweir     if(pShape)
261*cdf0e10cSrcweir     {
262*cdf0e10cSrcweir         SdrObject* pObj = pShape->GetSdrObject();
263*cdf0e10cSrcweir         if (pObj)
264*cdf0e10cSrcweir         {
265*cdf0e10cSrcweir             ScAnchorType eType = SCA_CELL;
266*cdf0e10cSrcweir             if ( nPlacement == excel::XlPlacement::xlFreeFloating )
267*cdf0e10cSrcweir                 eType = SCA_PAGE;
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir             // xlMove is not supported, treated as SCA_CELL (xlMoveAndSize)
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir             ScDrawLayer::SetAnchor(pObj, eType);
272*cdf0e10cSrcweir         }
273*cdf0e10cSrcweir     }
274*cdf0e10cSrcweir }
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir sal_Bool SAL_CALL ScVbaSheetObjectBase::getPrintObject() throw (uno::RuntimeException)
277*cdf0e10cSrcweir {
278*cdf0e10cSrcweir     // not supported
279*cdf0e10cSrcweir     return sal_True;
280*cdf0e10cSrcweir }
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir void SAL_CALL ScVbaSheetObjectBase::setPrintObject( sal_Bool /*bPrintObject*/ ) throw (uno::RuntimeException)
283*cdf0e10cSrcweir {
284*cdf0e10cSrcweir     // not supported
285*cdf0e10cSrcweir }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir // private
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir void ScVbaSheetObjectBase::setDefaultProperties( sal_Int32 nIndex ) throw (uno::RuntimeException)
290*cdf0e10cSrcweir {
291*cdf0e10cSrcweir     OUString aName = ::rtl::OUStringBuffer( implGetBaseName() ).append( sal_Unicode( ' ' ) ).append( nIndex + 1 ).makeStringAndClear();
292*cdf0e10cSrcweir     setName( aName );
293*cdf0e10cSrcweir     implSetDefaultProperties();
294*cdf0e10cSrcweir }
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir void ScVbaSheetObjectBase::implSetDefaultProperties() throw (uno::RuntimeException)
297*cdf0e10cSrcweir {
298*cdf0e10cSrcweir }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir // ============================================================================
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir ScVbaControlObjectBase::ScVbaControlObjectBase(
303*cdf0e10cSrcweir         const uno::Reference< XHelperInterface >& rxParent,
304*cdf0e10cSrcweir         const uno::Reference< uno::XComponentContext >& rxContext,
305*cdf0e10cSrcweir         const uno::Reference< frame::XModel >& rxModel,
306*cdf0e10cSrcweir         const uno::Reference< container::XIndexContainer >& rxFormIC,
307*cdf0e10cSrcweir         const uno::Reference< drawing::XControlShape >& rxControlShape,
308*cdf0e10cSrcweir         ListenerType eListenerType ) throw (uno::RuntimeException) :
309*cdf0e10cSrcweir     ScVbaControlObject_BASE( rxParent, rxContext, rxModel, uno::Reference< drawing::XShape >( rxControlShape, uno::UNO_QUERY_THROW ) ),
310*cdf0e10cSrcweir     mxFormIC( rxFormIC, uno::UNO_SET_THROW ),
311*cdf0e10cSrcweir     mxControlProps( rxControlShape->getControl(), uno::UNO_QUERY_THROW )
312*cdf0e10cSrcweir {
313*cdf0e10cSrcweir     // set listener and event name to be used for OnAction attribute
314*cdf0e10cSrcweir     switch( eListenerType )
315*cdf0e10cSrcweir     {
316*cdf0e10cSrcweir         case LISTENER_ACTION:
317*cdf0e10cSrcweir             maListenerType = CREATE_OUSTRING( "XActionListener" );
318*cdf0e10cSrcweir             maEventMethod = CREATE_OUSTRING( "actionPerformed" );
319*cdf0e10cSrcweir         break;
320*cdf0e10cSrcweir         case LISTENER_MOUSE:
321*cdf0e10cSrcweir             maListenerType = CREATE_OUSTRING( "XMouseListener" );
322*cdf0e10cSrcweir             maEventMethod = CREATE_OUSTRING( "mouseReleased" );
323*cdf0e10cSrcweir         break;
324*cdf0e10cSrcweir         case LISTENER_TEXT:
325*cdf0e10cSrcweir             maListenerType = CREATE_OUSTRING( "XTextListener" );
326*cdf0e10cSrcweir             maEventMethod = CREATE_OUSTRING( "textChanged" );
327*cdf0e10cSrcweir         break;
328*cdf0e10cSrcweir         case LISTENER_VALUE:
329*cdf0e10cSrcweir             maListenerType = CREATE_OUSTRING( "XAdjustmentListener" );
330*cdf0e10cSrcweir             maEventMethod = CREATE_OUSTRING( "adjustmentValueChanged" );
331*cdf0e10cSrcweir         break;
332*cdf0e10cSrcweir         case LISTENER_CHANGE:
333*cdf0e10cSrcweir             maListenerType = CREATE_OUSTRING( "XChangeListener" );
334*cdf0e10cSrcweir             maEventMethod = CREATE_OUSTRING( "changed" );
335*cdf0e10cSrcweir         break;
336*cdf0e10cSrcweir         // no default, to let the compiler complain about missing case
337*cdf0e10cSrcweir     }
338*cdf0e10cSrcweir }
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir // XSheetObject attributes
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir OUString SAL_CALL ScVbaControlObjectBase::getName() throw (uno::RuntimeException)
343*cdf0e10cSrcweir {
344*cdf0e10cSrcweir     return mxControlProps->getPropertyValue( CREATE_OUSTRING( "Name" ) ).get< OUString >();
345*cdf0e10cSrcweir }
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir void SAL_CALL ScVbaControlObjectBase::setName( const OUString& rName ) throw (uno::RuntimeException)
348*cdf0e10cSrcweir {
349*cdf0e10cSrcweir     mxControlProps->setPropertyValue( CREATE_OUSTRING( "Name" ), uno::Any( rName ) );
350*cdf0e10cSrcweir }
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir OUString SAL_CALL ScVbaControlObjectBase::getOnAction() throw (uno::RuntimeException)
353*cdf0e10cSrcweir {
354*cdf0e10cSrcweir     uno::Reference< script::XEventAttacherManager > xEventMgr( mxFormIC, uno::UNO_QUERY_THROW );
355*cdf0e10cSrcweir     sal_Int32 nIndex = getModelIndexInForm();
356*cdf0e10cSrcweir     uno::Sequence< script::ScriptEventDescriptor > aEvents = xEventMgr->getScriptEvents( nIndex );
357*cdf0e10cSrcweir     if( aEvents.hasElements() )
358*cdf0e10cSrcweir     {
359*cdf0e10cSrcweir         const script::ScriptEventDescriptor* pEvent = aEvents.getConstArray();
360*cdf0e10cSrcweir         const script::ScriptEventDescriptor* pEventEnd = pEvent + aEvents.getLength();
361*cdf0e10cSrcweir         const OUString aScriptType = CREATE_OUSTRING( "Script" );
362*cdf0e10cSrcweir         for( ; pEvent < pEventEnd; ++pEvent )
363*cdf0e10cSrcweir             if( (pEvent->ListenerType == maListenerType) && (pEvent->EventMethod == maEventMethod) && (pEvent->ScriptType == aScriptType) )
364*cdf0e10cSrcweir                 return extractMacroName( pEvent->ScriptCode );
365*cdf0e10cSrcweir     }
366*cdf0e10cSrcweir     return OUString();
367*cdf0e10cSrcweir }
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir void SAL_CALL ScVbaControlObjectBase::setOnAction( const OUString& rMacroName ) throw (uno::RuntimeException)
370*cdf0e10cSrcweir {
371*cdf0e10cSrcweir     uno::Reference< script::XEventAttacherManager > xEventMgr( mxFormIC, uno::UNO_QUERY_THROW );
372*cdf0e10cSrcweir     sal_Int32 nIndex = getModelIndexInForm();
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir     // first, remove a registered event (try/catch just in case implementation throws)
375*cdf0e10cSrcweir     try { xEventMgr->revokeScriptEvent( nIndex, maListenerType, maEventMethod, OUString() ); } catch( uno::Exception& ) {}
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir     // if a macro name has been passed, try to attach it to the event
378*cdf0e10cSrcweir     if( rMacroName.getLength() > 0 )
379*cdf0e10cSrcweir     {
380*cdf0e10cSrcweir         MacroResolvedInfo aResolvedMacro = resolveVBAMacro( getSfxObjShell( mxModel ), rMacroName );
381*cdf0e10cSrcweir         if( !aResolvedMacro.mbFound )
382*cdf0e10cSrcweir             throw uno::RuntimeException();
383*cdf0e10cSrcweir         script::ScriptEventDescriptor aDescriptor;
384*cdf0e10cSrcweir         aDescriptor.ListenerType = maListenerType;
385*cdf0e10cSrcweir         aDescriptor.EventMethod = maEventMethod;
386*cdf0e10cSrcweir         aDescriptor.ScriptType = CREATE_OUSTRING( "Script" );
387*cdf0e10cSrcweir         aDescriptor.ScriptCode = makeMacroURL( aResolvedMacro.msResolvedMacro );
388*cdf0e10cSrcweir         xEventMgr->registerScriptEvent( nIndex, aDescriptor );
389*cdf0e10cSrcweir     }
390*cdf0e10cSrcweir }
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir sal_Bool SAL_CALL ScVbaControlObjectBase::getPrintObject() throw (uno::RuntimeException)
393*cdf0e10cSrcweir {
394*cdf0e10cSrcweir     return mxControlProps->getPropertyValue( CREATE_OUSTRING( "Printable" ) ).get< sal_Bool >();
395*cdf0e10cSrcweir }
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir void SAL_CALL ScVbaControlObjectBase::setPrintObject( sal_Bool bPrintObject ) throw (uno::RuntimeException)
398*cdf0e10cSrcweir {
399*cdf0e10cSrcweir     mxControlProps->setPropertyValue( CREATE_OUSTRING( "Printable" ), uno::Any( bPrintObject ) );
400*cdf0e10cSrcweir }
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir // XControlObject attributes
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir sal_Bool SAL_CALL ScVbaControlObjectBase::getAutoSize() throw (uno::RuntimeException)
405*cdf0e10cSrcweir {
406*cdf0e10cSrcweir     // not supported
407*cdf0e10cSrcweir     return sal_False;
408*cdf0e10cSrcweir }
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir void SAL_CALL ScVbaControlObjectBase::setAutoSize( sal_Bool /*bAutoSize*/ ) throw (uno::RuntimeException)
411*cdf0e10cSrcweir {
412*cdf0e10cSrcweir     // not supported
413*cdf0e10cSrcweir }
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir // private
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir sal_Int32 ScVbaControlObjectBase::getModelIndexInForm() const throw (uno::RuntimeException)
418*cdf0e10cSrcweir {
419*cdf0e10cSrcweir     for( sal_Int32 nIndex = 0, nCount = mxFormIC->getCount(); nIndex < nCount; ++nIndex )
420*cdf0e10cSrcweir     {
421*cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > xProps( mxFormIC->getByIndex( nIndex ), uno::UNO_QUERY_THROW );
422*cdf0e10cSrcweir         if( mxControlProps.get() == xProps.get() )
423*cdf0e10cSrcweir             return nIndex;
424*cdf0e10cSrcweir     }
425*cdf0e10cSrcweir     throw uno::RuntimeException();
426*cdf0e10cSrcweir }
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir // ============================================================================
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir ScVbaButton::ScVbaButton(
431*cdf0e10cSrcweir         const uno::Reference< XHelperInterface >& rxParent,
432*cdf0e10cSrcweir         const uno::Reference< uno::XComponentContext >& rxContext,
433*cdf0e10cSrcweir         const uno::Reference< frame::XModel >& rxModel,
434*cdf0e10cSrcweir         const uno::Reference< container::XIndexContainer >& rxFormIC,
435*cdf0e10cSrcweir         const uno::Reference< drawing::XControlShape >& rxControlShape ) throw (uno::RuntimeException) :
436*cdf0e10cSrcweir     ScVbaButton_BASE( rxParent, rxContext, rxModel, rxFormIC, rxControlShape, LISTENER_ACTION )
437*cdf0e10cSrcweir {
438*cdf0e10cSrcweir }
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir // XButton attributes
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir OUString SAL_CALL ScVbaButton::getCaption() throw (uno::RuntimeException)
443*cdf0e10cSrcweir {
444*cdf0e10cSrcweir     return mxControlProps->getPropertyValue( CREATE_OUSTRING( "Label" ) ).get< OUString >();
445*cdf0e10cSrcweir }
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir void SAL_CALL ScVbaButton::setCaption( const OUString& rCaption ) throw (uno::RuntimeException)
448*cdf0e10cSrcweir {
449*cdf0e10cSrcweir     mxControlProps->setPropertyValue( CREATE_OUSTRING( "Label" ), uno::Any( rCaption ) );
450*cdf0e10cSrcweir }
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir uno::Reference< excel::XFont > SAL_CALL ScVbaButton::getFont() throw (uno::RuntimeException)
453*cdf0e10cSrcweir {
454*cdf0e10cSrcweir     return new ScVbaFont( this, mxContext, maPalette, mxControlProps, 0, true );
455*cdf0e10cSrcweir }
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir void SAL_CALL ScVbaButton::setFont( const uno::Reference< excel::XFont >& /*rxFont*/ ) throw (uno::RuntimeException)
458*cdf0e10cSrcweir {
459*cdf0e10cSrcweir     // TODO
460*cdf0e10cSrcweir }
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir sal_Int32 SAL_CALL ScVbaButton::getHorizontalAlignment() throw (uno::RuntimeException)
463*cdf0e10cSrcweir {
464*cdf0e10cSrcweir     switch( mxControlProps->getPropertyValue( CREATE_OUSTRING( "Align" ) ).get< sal_Int16 >() )
465*cdf0e10cSrcweir     {
466*cdf0e10cSrcweir         case awt::TextAlign::LEFT:      return excel::Constants::xlLeft;
467*cdf0e10cSrcweir         case awt::TextAlign::RIGHT:     return excel::Constants::xlRight;
468*cdf0e10cSrcweir         case awt::TextAlign::CENTER:    return excel::Constants::xlCenter;
469*cdf0e10cSrcweir     }
470*cdf0e10cSrcweir     return excel::Constants::xlCenter;
471*cdf0e10cSrcweir }
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir void SAL_CALL ScVbaButton::setHorizontalAlignment( sal_Int32 nAlign ) throw (uno::RuntimeException)
474*cdf0e10cSrcweir {
475*cdf0e10cSrcweir     sal_Int32 nAwtAlign = awt::TextAlign::CENTER;
476*cdf0e10cSrcweir     switch( nAlign )
477*cdf0e10cSrcweir     {
478*cdf0e10cSrcweir         case excel::Constants::xlLeft:      nAwtAlign = awt::TextAlign::LEFT;   break;
479*cdf0e10cSrcweir         case excel::Constants::xlRight:     nAwtAlign = awt::TextAlign::RIGHT;  break;
480*cdf0e10cSrcweir         case excel::Constants::xlCenter:    nAwtAlign = awt::TextAlign::CENTER; break;
481*cdf0e10cSrcweir     }
482*cdf0e10cSrcweir     // form controls expect short value
483*cdf0e10cSrcweir     mxControlProps->setPropertyValue( CREATE_OUSTRING( "Align" ), uno::Any( static_cast< sal_Int16 >( nAwtAlign ) ) );
484*cdf0e10cSrcweir }
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir sal_Int32 SAL_CALL ScVbaButton::getVerticalAlignment() throw (uno::RuntimeException)
487*cdf0e10cSrcweir {
488*cdf0e10cSrcweir     switch( mxControlProps->getPropertyValue( CREATE_OUSTRING( "VerticalAlign" ) ).get< style::VerticalAlignment >() )
489*cdf0e10cSrcweir     {
490*cdf0e10cSrcweir         case style::VerticalAlignment_TOP:      return excel::Constants::xlTop;
491*cdf0e10cSrcweir         case style::VerticalAlignment_BOTTOM:   return excel::Constants::xlBottom;
492*cdf0e10cSrcweir         case style::VerticalAlignment_MIDDLE:   return excel::Constants::xlCenter;
493*cdf0e10cSrcweir         default:;
494*cdf0e10cSrcweir     }
495*cdf0e10cSrcweir     return excel::Constants::xlCenter;
496*cdf0e10cSrcweir }
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir void SAL_CALL ScVbaButton::setVerticalAlignment( sal_Int32 nAlign ) throw (uno::RuntimeException)
499*cdf0e10cSrcweir {
500*cdf0e10cSrcweir     style::VerticalAlignment eAwtAlign = style::VerticalAlignment_MIDDLE;
501*cdf0e10cSrcweir     switch( nAlign )
502*cdf0e10cSrcweir     {
503*cdf0e10cSrcweir         case excel::Constants::xlTop:       eAwtAlign = style::VerticalAlignment_TOP;       break;
504*cdf0e10cSrcweir         case excel::Constants::xlBottom:    eAwtAlign = style::VerticalAlignment_BOTTOM;    break;
505*cdf0e10cSrcweir         case excel::Constants::xlCenter:    eAwtAlign = style::VerticalAlignment_MIDDLE;    break;
506*cdf0e10cSrcweir     }
507*cdf0e10cSrcweir     mxControlProps->setPropertyValue( CREATE_OUSTRING( "VerticalAlign" ), uno::Any( eAwtAlign ) );
508*cdf0e10cSrcweir }
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir sal_Int32 SAL_CALL ScVbaButton::getOrientation() throw (uno::RuntimeException)
511*cdf0e10cSrcweir {
512*cdf0e10cSrcweir     // not supported
513*cdf0e10cSrcweir     return excel::XlOrientation::xlHorizontal;
514*cdf0e10cSrcweir }
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir void SAL_CALL ScVbaButton::setOrientation( sal_Int32 /*nOrientation*/ ) throw (uno::RuntimeException)
517*cdf0e10cSrcweir {
518*cdf0e10cSrcweir     // not supported
519*cdf0e10cSrcweir }
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir // XButton methods
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir uno::Reference< excel::XCharacters > SAL_CALL ScVbaButton::Characters( const uno::Any& rStart, const uno::Any& rLength ) throw (uno::RuntimeException)
524*cdf0e10cSrcweir {
525*cdf0e10cSrcweir     return new ScVbaButtonCharacters( this, mxContext, mxControlProps, maPalette, rStart, rLength );
526*cdf0e10cSrcweir }
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir // XHelperInterface
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir VBAHELPER_IMPL_XHELPERINTERFACE( ScVbaButton, "ooo.vba.excel.Button" )
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir // private
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir OUString ScVbaButton::implGetBaseName() const
535*cdf0e10cSrcweir {
536*cdf0e10cSrcweir     return CREATE_OUSTRING( "Button" );
537*cdf0e10cSrcweir }
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir void ScVbaButton::implSetDefaultProperties() throw (uno::RuntimeException)
540*cdf0e10cSrcweir {
541*cdf0e10cSrcweir     setCaption( getName() );
542*cdf0e10cSrcweir }
543*cdf0e10cSrcweir 
544*cdf0e10cSrcweir // ============================================================================
545