1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <com/sun/star/lang/IllegalArgumentException.hpp>
23 #include "testlistener.hxx"
25 #define U2S(s) OUStringToOString(s, RTL_TEXTENCODING_UTF8).getStr()
28 using ::com::sun::star::lang::XMultiServiceFactory
;
29 using ::com::sun::star::lang::IllegalArgumentException
;
32 namespace DOM
{ namespace events
35 Reference
< XInterface
> CTestListener::_getInstance(const Reference
< XMultiServiceFactory
>& rSMgr
)
38 // return static_cast< XXPathAPI* >(new CTestListener());
39 return Reference
< XInterface
>(static_cast<XEventListener
*>(new CTestListener(rSMgr
)));
42 const char* CTestListener::aImplementationName
= "com.sun.star.comp.xml.dom.events.TestListener";
43 const char* CTestListener::aSupportedServiceNames
[] = {
44 "com.sun.star.comp.xml.dom.events.TestListener",
48 OUString
CTestListener::_getImplementationName()
50 return OUString::createFromAscii(aImplementationName
);
52 Sequence
<OUString
> CTestListener::_getSupportedServiceNames()
54 Sequence
<OUString
> aSequence
;
55 for (int i
=0; aSupportedServiceNames
[i
]!=NULL
; i
++) {
56 aSequence
.realloc(i
+1);
57 aSequence
[i
]=(OUString::createFromAscii(aSupportedServiceNames
[i
]));
62 Sequence
< OUString
> SAL_CALL
CTestListener::getSupportedServiceNames()
63 throw (RuntimeException
)
65 return CTestListener::_getSupportedServiceNames();
68 OUString SAL_CALL
CTestListener::getImplementationName()
69 throw (RuntimeException
)
71 return CTestListener::_getImplementationName();
74 sal_Bool SAL_CALL
CTestListener::supportsService(const OUString
& aServiceName
)
75 throw (RuntimeException
)
77 Sequence
< OUString
> supported
= CTestListener::_getSupportedServiceNames();
78 for (sal_Int32 i
=0; i
<supported
.getLength(); i
++)
80 if (supported
[i
] == aServiceName
) return sal_True
;
87 void SAL_CALL
CTestListener::initialize(const Sequence
< Any
>& args
) throw(RuntimeException
)
89 if (args
.getLength() < 3) throw IllegalArgumentException(
90 "Wrong number of arguments", Reference
< XInterface
>(), 0);
92 Reference
<XEventTarget
> aTarget
;
93 if(! (args
[0] >>= aTarget
)) throw IllegalArgumentException(
94 "Illegal argument 1", Reference
< XInterface
>(), 1);
97 if (! (args
[1] >>= aType
))
98 throw IllegalArgumentException("Illegal argument 2", Reference
< XInterface
>(), 2);
100 sal_Bool bCapture
= sal_False
;
101 if(! (args
[2] >>= bCapture
)) throw IllegalArgumentException(
102 "Illegal argument 3", Reference
< XInterface
>(), 3);
104 if(! (args
[3] >>= m_name
)) m_name
= "<unnamed listener>";
108 m_capture
= bCapture
;
110 m_target
->addEventListener(m_type
, Reference
< XEventListener
>(this), m_capture
);
115 CTestListener::~CTestListener()
117 fprintf(stderr
, "CTestListener::~CTestListener()\n");
119 m_target
->removeEventListener(m_type
, Reference
< XEventListener
>(this), m_capture
);
122 // --- XEventListener
124 void SAL_CALL
CTestListener::handleEvent(const Reference
< XEvent
>& evt
) throw (RuntimeException
)
126 FILE* f
= fopen("C:\\listener.out", "a");
127 fprintf(f
, "CTestListener::handleEvent in %s\n", U2S(m_name
));
128 fprintf(f
, " type: %s\n\n", OUStringToOString(evt
->getType(), RTL_TEXTENCODING_ASCII_US
).getStr());
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */