1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MyListener.cxx,v $
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 ************************************************************************/
32 #include "MyListener.h"
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/frame/XModel.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/document/XEventBroadcaster.hpp>
38 namespace css
= ::com::sun::star
;
40 /*-----------------------------------------------------
42 -----------------------------------------------------*/
43 MyListener::MyListener(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
)
47 /*-----------------------------------------------------
49 -----------------------------------------------------*/
50 MyListener::~MyListener()
53 /*-----------------------------------------------------
55 -----------------------------------------------------*/
56 css::uno::Any SAL_CALL
MyListener::execute(const css::uno::Sequence
< css::beans::NamedValue
>& lArguments
)
57 throw (css::lang::IllegalArgumentException
,
59 css::uno::RuntimeException
)
61 css::uno::Sequence
< css::beans::NamedValue
> lEnv
;
64 sal_Int32 c
= lArguments
.getLength();
65 const css::beans::NamedValue
* p
= lArguments
.getConstArray();
68 if (p
[i
].Name
.equalsAscii("Environment"))
75 css::uno::Reference
< css::frame::XModel
> xModel
;
78 p
= lEnv
.getConstArray();
81 if (p
[i
].Name
.equalsAscii("Model"))
83 p
[i
].Value
>>= xModel
;
86 if (p
[i
].Name
.equalsAscii("Frame"))
88 css::uno::Reference
< css::frame::XController
> xController
;
89 css::uno::Reference
< css::frame::XFrame
> xFrame
;
90 p
[i
].Value
>>= xFrame
;
92 xController
= xFrame
->getController();
94 xModel
= xController
->getModel();
100 return css::uno::Any();
102 css::uno::Reference
< css::lang::XServiceInfo
> xInfo(xModel
, css::uno::UNO_QUERY
);
103 sal_Bool bCalc
= xInfo
->supportsService(::rtl::OUString::createFromAscii("com.sun.star.sheet.SpreadsheetDocument"));
105 xInfo
->supportsService(::rtl::OUString::createFromAscii("com.sun.star.text.TextDocument" )) &&
106 !xInfo
->supportsService(::rtl::OUString::createFromAscii("com.sun.star.text.WebDocument" )) &&
107 !xInfo
->supportsService(::rtl::OUString::createFromAscii("com.sun.star.text.GlobalDocument"))
110 // Wir interessieren uns nur für Writer und Calc. Werden hier aber für
111 // alle neu geöffneten Dokumente benachrichtigt ...
112 if (!bCalc
&& !bWriter
)
113 return css::uno::Any();
117 pListener
= (void*)(new CalcListener(m_xSMGR
));
120 pListener
= (void*)(new WriterListener(m_xSMGR
));
122 css::uno::Reference
< css::document::XEventListener
> xDocListener (static_cast< css::document::XEventListener
* >(pListener
), css::uno::UNO_QUERY
);
123 css::uno::Reference
< css::document::XEventBroadcaster
> xDocBroadcaster (xModel
, css::uno::UNO_QUERY
);
125 xDocBroadcaster
->addEventListener(xDocListener
);
127 return css::uno::Any();
130 /*-----------------------------------------------------
132 -----------------------------------------------------*/
133 ::rtl::OUString SAL_CALL
MyListener::getImplementationName()
134 throw (css::uno::RuntimeException
)
136 return ::rtl::OUString::createFromAscii(MYLISTENER_IMPLEMENTATIONNAME
);
139 /*-----------------------------------------------------
141 -----------------------------------------------------*/
142 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
MyListener::getSupportedServiceNames()
143 throw (css::uno::RuntimeException
)
145 css::uno::Sequence
< ::rtl::OUString
> lNames(1);
146 lNames
[0] = ::rtl::OUString::createFromAscii(MYLISTENER_SERVICENAME
);
150 /*-----------------------------------------------------
152 -----------------------------------------------------*/
153 sal_Bool SAL_CALL
MyListener::supportsService(const ::rtl::OUString
& sServiceName
)
154 throw (css::uno::RuntimeException
)
157 sServiceName
.equalsAscii(MYLISTENER_SERVICENAME
) ||
158 sServiceName
.equalsAscii("com.sun.star.task.Job" )
162 /*-----------------------------------------------------
164 -----------------------------------------------------*/
165 css::uno::Reference
< css::uno::XInterface
> MyListener::st_createInstance(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
)
167 MyListener
* pListener
= new MyListener(xSMGR
);
168 css::uno::Reference
< css::uno::XInterface
> xListener(static_cast< css::task::XJob
* >(pListener
), css::uno::UNO_QUERY
);