1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
30 #include <com/sun/star/lang/IllegalArgumentException.hpp>
32 #include "testlistener.hxx"
34 #define U2S(s) OUStringToOString(s, RTL_TEXTENCODING_UTF8).getStr()
37 using ::com::sun::star::lang::XMultiServiceFactory
;
38 using ::com::sun::star::lang::IllegalArgumentException
;
41 namespace DOM
{ namespace events
44 Reference
< XInterface
> CTestListener::_getInstance(const Reference
< XMultiServiceFactory
>& rSMgr
)
47 // return static_cast< XXPathAPI* >(new CTestListener());
48 return Reference
< XInterface
>(static_cast<XEventListener
*>(new CTestListener(rSMgr
)));
51 const char* CTestListener::aImplementationName
= "com.sun.star.comp.xml.dom.events.TestListener";
52 const char* CTestListener::aSupportedServiceNames
[] = {
53 "com.sun.star.comp.xml.dom.events.TestListener",
57 OUString
CTestListener::_getImplementationName()
59 return OUString::createFromAscii(aImplementationName
);
61 Sequence
<OUString
> CTestListener::_getSupportedServiceNames()
63 Sequence
<OUString
> aSequence
;
64 for (int i
=0; aSupportedServiceNames
[i
]!=NULL
; i
++) {
65 aSequence
.realloc(i
+1);
66 aSequence
[i
]=(OUString::createFromAscii(aSupportedServiceNames
[i
]));
71 Sequence
< OUString
> SAL_CALL
CTestListener::getSupportedServiceNames()
72 throw (RuntimeException
)
74 return CTestListener::_getSupportedServiceNames();
77 OUString SAL_CALL
CTestListener::getImplementationName()
78 throw (RuntimeException
)
80 return CTestListener::_getImplementationName();
83 sal_Bool SAL_CALL
CTestListener::supportsService(const OUString
& aServiceName
)
84 throw (RuntimeException
)
86 Sequence
< OUString
> supported
= CTestListener::_getSupportedServiceNames();
87 for (sal_Int32 i
=0; i
<supported
.getLength(); i
++)
89 if (supported
[i
] == aServiceName
) return sal_True
;
96 void SAL_CALL
CTestListener::initialize(const Sequence
< Any
>& args
) throw(RuntimeException
)
98 if (args
.getLength() < 3) throw IllegalArgumentException(
99 "Wrong number of arguments", Reference
< XInterface
>(), 0);
101 Reference
<XEventTarget
> aTarget
;
102 if(! (args
[0] >>= aTarget
)) throw IllegalArgumentException(
103 "Illegal argument 1", Reference
< XInterface
>(), 1);
106 if (! (args
[1] >>= aType
))
107 throw IllegalArgumentException("Illegal argument 2", Reference
< XInterface
>(), 2);
109 sal_Bool bCapture
= sal_False
;
110 if(! (args
[2] >>= bCapture
)) throw IllegalArgumentException(
111 "Illegal argument 3", Reference
< XInterface
>(), 3);
113 if(! (args
[3] >>= m_name
)) m_name
= "<unnamed listener>";
117 m_capture
= bCapture
;
119 m_target
->addEventListener(m_type
, Reference
< XEventListener
>(this), m_capture
);
124 CTestListener::~CTestListener()
126 fprintf(stderr
, "CTestListener::~CTestListener()\n");
128 m_target
->removeEventListener(m_type
, Reference
< XEventListener
>(this), m_capture
);
131 // --- XEventListener
133 void SAL_CALL
CTestListener::handleEvent(const Reference
< XEvent
>& evt
) throw (RuntimeException
)
135 FILE* f
= fopen("C:\\listener.out", "a");
136 fprintf(f
, "CTestListener::handleEvent in %s\n", U2S(m_name
));
137 fprintf(f
, " type: %s\n\n", OUStringToOString(evt
->getType(), RTL_TEXTENCODING_ASCII_US
).getStr());
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */