merge the formfield patch from ooo-build
[ooovba.git] / unoxml / source / events / testlistener.cxx
blob91ac1ecc0293995f9ac5e0ef3cd6057fb8a3bec0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testlistener.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include <stdio.h>
32 #include <com/sun/star/lang/IllegalArgumentException.hpp>
34 #include "testlistener.hxx"
36 #define U2S(s) OUStringToOString(s, RTL_TEXTENCODING_UTF8).getStr()
39 namespace DOM { namespace events
42 Reference< XInterface > CTestListener::_getInstance(const Reference< XMultiServiceFactory >& rSMgr)
44 // XXX
45 // return static_cast< XXPathAPI* >(new CTestListener());
46 return Reference< XInterface >(static_cast<XEventListener*>(new CTestListener(rSMgr)));
49 const char* CTestListener::aImplementationName = "com.sun.star.comp.xml.dom.events.TestListener";
50 const char* CTestListener::aSupportedServiceNames[] = {
51 "com.sun.star.comp.xml.dom.events.TestListener",
52 NULL
55 OUString CTestListener::_getImplementationName()
57 return OUString::createFromAscii(aImplementationName);
59 Sequence<OUString> CTestListener::_getSupportedServiceNames()
61 Sequence<OUString> aSequence;
62 for (int i=0; aSupportedServiceNames[i]!=NULL; i++) {
63 aSequence.realloc(i+1);
64 aSequence[i]=(OUString::createFromAscii(aSupportedServiceNames[i]));
66 return aSequence;
69 Sequence< OUString > SAL_CALL CTestListener::getSupportedServiceNames()
70 throw (RuntimeException)
72 return CTestListener::_getSupportedServiceNames();
75 OUString SAL_CALL CTestListener::getImplementationName()
76 throw (RuntimeException)
78 return CTestListener::_getImplementationName();
81 sal_Bool SAL_CALL CTestListener::supportsService(const OUString& aServiceName)
82 throw (RuntimeException)
84 Sequence< OUString > supported = CTestListener::_getSupportedServiceNames();
85 for (sal_Int32 i=0; i<supported.getLength(); i++)
87 if (supported[i] == aServiceName) return sal_True;
89 return sal_False;
92 // --- XInitialize
94 void SAL_CALL CTestListener::initialize(const Sequence< Any >& args) throw(RuntimeException)
96 if (args.getLength() < 3) throw IllegalArgumentException(
97 OUString::createFromAscii("Wrong number of arguments"), Reference< XInterface >(), 0);
99 Reference <XEventTarget> aTarget;
100 if(! (args[0] >>= aTarget)) throw IllegalArgumentException(
101 OUString::createFromAscii("Illegal argument 1"), Reference< XInterface >(), 1);
103 OUString aType;
104 if (! (args[1] >>= aType))
105 throw IllegalArgumentException(OUString::createFromAscii("Illegal argument 2"), Reference< XInterface >(), 2);
107 sal_Bool bCapture = sal_False;
108 if(! (args[2] >>= bCapture)) throw IllegalArgumentException(
109 OUString::createFromAscii("Illegal argument 3"), Reference< XInterface >(), 3);
111 if(! (args[3] >>= m_name)) m_name = OUString::createFromAscii("<unnamed listener>");
113 m_target = aTarget;
114 m_type = aType;
115 m_capture = bCapture;
117 m_target->addEventListener(m_type, Reference< XEventListener >(this), m_capture);
122 CTestListener::~CTestListener()
124 fprintf(stderr, "CTestListener::~CTestListener()\n");
125 if( m_target.is())
126 m_target->removeEventListener(m_type, Reference< XEventListener >(this), m_capture);
129 // --- XEventListener
131 void SAL_CALL CTestListener::handleEvent(const Reference< XEvent >& evt) throw (RuntimeException)
133 FILE* f = fopen("C:\\listener.out", "a");
134 fprintf(f, "CTestListener::handleEvent in %s\n", U2S(m_name));
135 fprintf(f, " type: %s\n\n", OUStringToOString(evt->getType(), RTL_TEXTENCODING_ASCII_US).getStr());
136 fclose(f);