Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #include <stdio.h>
20 :
21 : #include <com/sun/star/lang/IllegalArgumentException.hpp>
22 : #include <cppuhelper/supportsservice.hxx>
23 :
24 : #include "testlistener.hxx"
25 :
26 : #define U2S(s) OUStringToOString(s, RTL_TEXTENCODING_UTF8).getStr()
27 :
28 : using namespace css::uno;
29 : using namespace css::xml::dom::events;
30 : using css::lang::XMultiServiceFactory;
31 : using css::lang::IllegalArgumentException;
32 :
33 :
34 : namespace DOM { namespace events
35 : {
36 :
37 0 : Reference< XInterface > CTestListener::_getInstance(const Reference< XMultiServiceFactory >& rSMgr)
38 : {
39 : // XXX
40 : // return static_cast< XXPathAPI* >(new CTestListener());
41 0 : return Reference< XInterface >(static_cast<XEventListener*>(new CTestListener(rSMgr)));
42 : }
43 :
44 : const char* CTestListener::aImplementationName = "com.sun.star.comp.xml.dom.events.TestListener";
45 : const char* CTestListener::aSupportedServiceNames[] = {
46 : "com.sun.star.comp.xml.dom.events.TestListener",
47 : NULL
48 : };
49 :
50 0 : OUString CTestListener::_getImplementationName()
51 : {
52 0 : return OUString::createFromAscii(aImplementationName);
53 : }
54 0 : Sequence<OUString> CTestListener::_getSupportedServiceNames()
55 : {
56 0 : Sequence<OUString> aSequence;
57 0 : for (int i=0; aSupportedServiceNames[i]!=NULL; i++) {
58 0 : aSequence.realloc(i+1);
59 0 : aSequence[i]=(OUString::createFromAscii(aSupportedServiceNames[i]));
60 : }
61 0 : return aSequence;
62 : }
63 :
64 0 : Sequence< OUString > SAL_CALL CTestListener::getSupportedServiceNames()
65 : throw (RuntimeException, std::exception)
66 : {
67 0 : return CTestListener::_getSupportedServiceNames();
68 : }
69 :
70 0 : OUString SAL_CALL CTestListener::getImplementationName()
71 : throw (RuntimeException, std::exception)
72 : {
73 0 : return CTestListener::_getImplementationName();
74 : }
75 :
76 0 : sal_Bool SAL_CALL CTestListener::supportsService(const OUString& aServiceName)
77 : throw (RuntimeException, std::exception)
78 : {
79 0 : return cppu::supportsService(this, aServiceName);
80 : }
81 :
82 : // --- XInitialize
83 :
84 0 : void SAL_CALL CTestListener::initialize(const Sequence< Any >& args) throw(RuntimeException, std::exception)
85 : {
86 0 : if (args.getLength() < 3) throw IllegalArgumentException(
87 0 : "Wrong number of arguments", Reference< XInterface >(), 0);
88 :
89 0 : Reference <XEventTarget> aTarget;
90 0 : if(! (args[0] >>= aTarget)) throw IllegalArgumentException(
91 0 : "Illegal argument 1", Reference< XInterface >(), 1);
92 :
93 0 : OUString aType;
94 0 : if (! (args[1] >>= aType))
95 0 : throw IllegalArgumentException("Illegal argument 2", Reference< XInterface >(), 2);
96 :
97 0 : bool bCapture = false;
98 0 : if(! (args[2] >>= bCapture)) throw IllegalArgumentException(
99 0 : "Illegal argument 3", Reference< XInterface >(), 3);
100 :
101 0 : if(! (args[3] >>= m_name)) m_name = "<unnamed listener>";
102 :
103 0 : m_target = aTarget;
104 0 : m_type = aType;
105 0 : m_capture = bCapture;
106 :
107 0 : m_target->addEventListener(m_type, Reference< XEventListener >(this), m_capture);
108 :
109 :
110 0 : }
111 :
112 0 : CTestListener::~CTestListener()
113 : {
114 0 : fprintf(stderr, "CTestListener::~CTestListener()\n");
115 0 : if( m_target.is())
116 0 : m_target->removeEventListener(m_type, Reference< XEventListener >(this), m_capture);
117 0 : }
118 :
119 : // --- XEventListener
120 :
121 0 : void SAL_CALL CTestListener::handleEvent(const Reference< XEvent >& evt) throw (RuntimeException, std::exception)
122 : {
123 0 : FILE* f = fopen("C:\\listener.out", "a");
124 0 : fprintf(f, "CTestListener::handleEvent in %s\n", U2S(m_name));
125 0 : fprintf(f, " type: %s\n\n", OUStringToOString(evt->getType(), RTL_TEXTENCODING_ASCII_US).getStr());
126 0 : fclose(f);
127 :
128 0 : }
129 :
130 : }}
131 :
132 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|