Branch data 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 : :
23 : : #include "testlistener.hxx"
24 : :
25 : : #define U2S(s) OUStringToOString(s, RTL_TEXTENCODING_UTF8).getStr()
26 : :
27 : :
28 : : using ::com::sun::star::lang::XMultiServiceFactory;
29 : : using ::com::sun::star::lang::IllegalArgumentException;
30 : :
31 : :
32 : : namespace DOM { namespace events
33 : : {
34 : :
35 : 0 : Reference< XInterface > CTestListener::_getInstance(const Reference< XMultiServiceFactory >& rSMgr)
36 : : {
37 : : // XXX
38 : : // return static_cast< XXPathAPI* >(new CTestListener());
39 [ # # ][ # # ]: 0 : return Reference< XInterface >(static_cast<XEventListener*>(new CTestListener(rSMgr)));
40 : : }
41 : :
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",
45 : : NULL
46 : : };
47 : :
48 : 0 : OUString CTestListener::_getImplementationName()
49 : : {
50 : 0 : return OUString::createFromAscii(aImplementationName);
51 : : }
52 : 0 : Sequence<OUString> CTestListener::_getSupportedServiceNames()
53 : : {
54 : 0 : Sequence<OUString> aSequence;
55 [ # # ]: 0 : for (int i=0; aSupportedServiceNames[i]!=NULL; i++) {
56 [ # # ]: 0 : aSequence.realloc(i+1);
57 [ # # ]: 0 : aSequence[i]=(OUString::createFromAscii(aSupportedServiceNames[i]));
58 : : }
59 : 0 : return aSequence;
60 : : }
61 : :
62 : 0 : Sequence< OUString > SAL_CALL CTestListener::getSupportedServiceNames()
63 : : throw (RuntimeException)
64 : : {
65 : 0 : return CTestListener::_getSupportedServiceNames();
66 : : }
67 : :
68 : 0 : OUString SAL_CALL CTestListener::getImplementationName()
69 : : throw (RuntimeException)
70 : : {
71 : 0 : return CTestListener::_getImplementationName();
72 : : }
73 : :
74 : 0 : sal_Bool SAL_CALL CTestListener::supportsService(const OUString& aServiceName)
75 : : throw (RuntimeException)
76 : : {
77 [ # # ]: 0 : Sequence< OUString > supported = CTestListener::_getSupportedServiceNames();
78 [ # # ]: 0 : for (sal_Int32 i=0; i<supported.getLength(); i++)
79 : : {
80 [ # # ][ # # ]: 0 : if (supported[i] == aServiceName) return sal_True;
81 : : }
82 [ # # ]: 0 : return sal_False;
83 : : }
84 : :
85 : : // --- XInitialize
86 : :
87 : 0 : void SAL_CALL CTestListener::initialize(const Sequence< Any >& args) throw(RuntimeException)
88 : : {
89 [ # # ]: 0 : if (args.getLength() < 3) throw IllegalArgumentException(
90 [ # # ]: 0 : "Wrong number of arguments", Reference< XInterface >(), 0);
91 : :
92 : 0 : Reference <XEventTarget> aTarget;
93 [ # # ][ # # ]: 0 : if(! (args[0] >>= aTarget)) throw IllegalArgumentException(
94 [ # # ]: 0 : "Illegal argument 1", Reference< XInterface >(), 1);
95 : :
96 : 0 : OUString aType;
97 [ # # ]: 0 : if (! (args[1] >>= aType))
98 [ # # ]: 0 : throw IllegalArgumentException("Illegal argument 2", Reference< XInterface >(), 2);
99 : :
100 : 0 : sal_Bool bCapture = sal_False;
101 [ # # ]: 0 : if(! (args[2] >>= bCapture)) throw IllegalArgumentException(
102 [ # # ]: 0 : "Illegal argument 3", Reference< XInterface >(), 3);
103 : :
104 [ # # ]: 0 : if(! (args[3] >>= m_name)) m_name = "<unnamed listener>";
105 : :
106 [ # # ]: 0 : m_target = aTarget;
107 : 0 : m_type = aType;
108 : 0 : m_capture = bCapture;
109 : :
110 [ # # ][ # # ]: 0 : m_target->addEventListener(m_type, Reference< XEventListener >(this), m_capture);
[ # # ]
111 : :
112 : :
113 : 0 : }
114 : :
115 : 0 : CTestListener::~CTestListener()
116 : : {
117 [ # # ]: 0 : fprintf(stderr, "CTestListener::~CTestListener()\n");
118 [ # # ]: 0 : if( m_target.is())
119 [ # # ][ # # ]: 0 : m_target->removeEventListener(m_type, Reference< XEventListener >(this), m_capture);
[ # # ]
120 [ # # ]: 0 : }
121 : :
122 : : // --- XEventListener
123 : :
124 : 0 : void SAL_CALL CTestListener::handleEvent(const Reference< XEvent >& evt) throw (RuntimeException)
125 : : {
126 : 0 : FILE* f = fopen("C:\\listener.out", "a");
127 [ # # ]: 0 : fprintf(f, "CTestListener::handleEvent in %s\n", U2S(m_name));
128 [ # # ][ # # ]: 0 : fprintf(f, " type: %s\n\n", OUStringToOString(evt->getType(), RTL_TEXTENCODING_ASCII_US).getStr());
129 : 0 : fclose(f);
130 : :
131 : 0 : }
132 : :
133 : : }}
134 : :
135 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|