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 : :
20 : :
21 : : #include "imestatuswindow.hxx"
22 : :
23 : : #include <sfx2/app.hxx>
24 : : #include <sfx2/sfxsids.hrc>
25 : :
26 : : #include "com/sun/star/beans/PropertyState.hpp"
27 : : #include "com/sun/star/beans/PropertyValue.hpp"
28 : : #include "com/sun/star/beans/XPropertySet.hpp"
29 : : #include "com/sun/star/lang/DisposedException.hpp"
30 : : #include "com/sun/star/lang/XMultiServiceFactory.hpp"
31 : : #include "com/sun/star/uno/Any.hxx"
32 : : #include "com/sun/star/uno/Exception.hpp"
33 : : #include "com/sun/star/uno/Reference.hxx"
34 : : #include "com/sun/star/uno/RuntimeException.hpp"
35 : : #include "com/sun/star/uno/Sequence.hxx"
36 : : #include "com/sun/star/util/XChangesBatch.hpp"
37 : : #include "osl/diagnose.h"
38 : : #include "osl/mutex.hxx"
39 : : #include "rtl/ustring.h"
40 : : #include "rtl/ustring.hxx"
41 : : #include "sal/types.h"
42 : : #include "vcl/svapp.hxx"
43 : :
44 : : //TO-Do, merge into framework/inc/helpers/mischelpers.hxx and deliver
45 : : class WeakPropertyChangeListener : public ::cppu::WeakImplHelper1<com::sun::star::beans::XPropertyChangeListener>
46 : : {
47 : : private:
48 : : com::sun::star::uno::WeakReference<com::sun::star::beans::XPropertyChangeListener> mxOwner;
49 : :
50 : : public:
51 : 0 : WeakPropertyChangeListener(com::sun::star::uno::Reference<com::sun::star::beans::XPropertyChangeListener> xOwner)
52 [ # # ]: 0 : : mxOwner(xOwner)
53 : : {
54 : 0 : }
55 : :
56 : 0 : virtual ~WeakPropertyChangeListener()
57 [ # # ]: 0 : {
58 [ # # ]: 0 : }
59 : :
60 : 0 : virtual void SAL_CALL propertyChange(const com::sun::star::beans::PropertyChangeEvent &rEvent )
61 : : throw(com::sun::star::uno::RuntimeException)
62 : : {
63 : : com::sun::star::uno::Reference<com::sun::star::beans::XPropertyChangeListener> xOwner(mxOwner.get(),
64 [ # # ][ # # ]: 0 : com::sun::star::uno::UNO_QUERY);
65 [ # # ]: 0 : if (xOwner.is())
66 [ # # ][ # # ]: 0 : xOwner->propertyChange(rEvent);
67 : :
68 : 0 : }
69 : :
70 : : // lang.XEventListener
71 : 0 : virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent)
72 : : throw(com::sun::star::uno::RuntimeException)
73 : : {
74 : : com::sun::star::uno::Reference<com::sun::star::beans::XPropertyChangeListener> xOwner(mxOwner.get(),
75 [ # # ][ # # ]: 0 : com::sun::star::uno::UNO_QUERY);
76 [ # # ]: 0 : if (xOwner.is())
77 [ # # ][ # # ]: 0 : xOwner->disposing(rEvent);
78 : :
79 : 0 : }
80 : : };
81 : :
82 : : namespace css = com::sun::star;
83 : :
84 : : using sfx2::appl::ImeStatusWindow;
85 : :
86 : 233 : ImeStatusWindow::ImeStatusWindow(
87 : : css::uno::Reference< css::lang::XMultiServiceFactory > const &
88 : : rServiceFactory):
89 : : m_xServiceFactory(rServiceFactory),
90 [ + - ]: 233 : m_bDisposed(false)
91 : 233 : {}
92 : :
93 : 233 : void ImeStatusWindow::init()
94 : : {
95 [ - + ]: 233 : if (Application::CanToggleImeStatusWindow())
96 : : try
97 : : {
98 : 0 : sal_Bool bShow = sal_Bool();
99 [ # # ][ # # : 0 : if (getConfig()->getPropertyValue(
# # # # ]
100 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
101 : 0 : "ShowStatusWindow")))
102 [ # # ][ # # ]: 0 : >>= bShow)
103 [ # # ]: 0 : Application::ShowImeStatusWindow(bShow);
104 : : }
105 : 0 : catch (css::uno::Exception &)
106 : : {
107 : : OSL_FAIL("com.sun.star.uno.Exception");
108 : : // Degrade gracefully and use the VCL-supplied default if no
109 : : // configuration is available.
110 : : }
111 : 233 : }
112 : :
113 : 0 : bool ImeStatusWindow::isShowing()
114 : : {
115 : : try
116 : : {
117 : 0 : sal_Bool bShow = sal_Bool();
118 [ # # ][ # # : 0 : if (getConfig()->getPropertyValue(
# # # # ]
119 : 0 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowStatusWindow")))
120 [ # # ][ # # ]: 0 : >>= bShow)
121 : 0 : return bShow;
122 : : }
123 : 0 : catch (css::uno::Exception &)
124 : : {
125 : : OSL_FAIL("com.sun.star.uno.Exception");
126 : : // Degrade gracefully and use the VCL-supplied default if no
127 : : // configuration is available.
128 : : }
129 : 0 : return Application::GetShowImeStatusWindowDefault();
130 : : }
131 : :
132 : 0 : void ImeStatusWindow::show(bool bShow)
133 : : {
134 : : try
135 : : {
136 [ # # ]: 0 : css::uno::Reference< css::beans::XPropertySet > xConfig(getConfig());
137 [ # # ]: 0 : xConfig->setPropertyValue(
138 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowStatusWindow")),
139 [ # # ][ # # ]: 0 : css::uno::makeAny(static_cast< sal_Bool >(bShow)));
[ # # ]
140 : : css::uno::Reference< css::util::XChangesBatch > xCommit(
141 [ # # ]: 0 : xConfig, css::uno::UNO_QUERY);
142 : : // Degrade gracefully by not saving the settings permanently:
143 [ # # ]: 0 : if (xCommit.is())
144 [ # # ][ # # ]: 0 : xCommit->commitChanges();
145 : : // Alternatively, setting the VCL status could be done even if updating
146 : : // the configuration failed:
147 [ # # ][ # # ]: 0 : Application::ShowImeStatusWindow(bShow);
148 : : }
149 : 0 : catch (css::uno::Exception &)
150 : : {
151 : : OSL_FAIL("com.sun.star.uno.Exception");
152 : : }
153 : 0 : }
154 : :
155 : 8 : bool ImeStatusWindow::canToggle() const
156 : : {
157 : 8 : return Application::CanToggleImeStatusWindow();
158 : : }
159 : :
160 [ + - ]: 158 : ImeStatusWindow::~ImeStatusWindow()
161 : : {
162 [ - + ][ # # ]: 158 : if (m_xConfig.is() && m_xConfigListener.is())
[ - + ]
163 : : // We should never get here, but just in case...
164 : : try
165 : : {
166 [ # # ]: 0 : m_xConfig->removePropertyChangeListener(
167 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowStatusWindow")),
168 [ # # ][ # # ]: 0 : m_xConfigListener);
[ # # ]
169 : : }
170 [ # # ]: 0 : catch (css::uno::Exception &)
171 : : {
172 : : OSL_FAIL("com.sun.star.uno.RuntimeException");
173 : : }
174 [ - + ]: 316 : }
175 : :
176 : 0 : void SAL_CALL ImeStatusWindow::disposing(css::lang::EventObject const & )
177 : : throw (css::uno::RuntimeException)
178 : : {
179 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
180 [ # # ]: 0 : m_xConfig = 0;
181 [ # # ]: 0 : m_bDisposed = true;
182 : 0 : }
183 : :
184 : : void SAL_CALL
185 : 0 : ImeStatusWindow::propertyChange(css::beans::PropertyChangeEvent const & )
186 : : throw (css::uno::RuntimeException)
187 : : {
188 [ # # ]: 0 : SolarMutexGuard aGuard;
189 : 0 : SfxApplication* pApp = SfxApplication::Get();
190 [ # # ]: 0 : if (pApp)
191 [ # # ][ # # ]: 0 : pApp->Invalidate(SID_SHOW_IME_STATUS_WINDOW);
192 : 0 : }
193 : :
194 : 0 : css::uno::Reference< css::beans::XPropertySet > ImeStatusWindow::getConfig()
195 : : {
196 : 0 : css::uno::Reference< css::beans::XPropertySet > xConfig;
197 : 0 : bool bAdd = false;
198 : : {
199 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
200 [ # # ]: 0 : if (!m_xConfig.is())
201 : : {
202 [ # # ]: 0 : if (m_bDisposed)
203 [ # # ]: 0 : throw css::lang::DisposedException();
204 [ # # ]: 0 : if (!m_xServiceFactory.is())
205 : : throw css::uno::RuntimeException(
206 : : rtl::OUString(
207 : : RTL_CONSTASCII_USTRINGPARAM(
208 : : "null comphelper::getProcessServiceFactory")),
209 [ # # ][ # # ]: 0 : 0);
[ # # ]
210 : : css::uno::Reference< css::lang::XMultiServiceFactory > xProvider(
211 [ # # ]: 0 : m_xServiceFactory->createInstance(
212 : : rtl::OUString(
213 : : RTL_CONSTASCII_USTRINGPARAM(
214 : 0 : "com.sun.star.configuration.ConfigurationProvider"))),
215 [ # # ][ # # ]: 0 : css::uno::UNO_QUERY);
[ # # ]
216 [ # # ]: 0 : if (!xProvider.is())
217 : : throw css::uno::RuntimeException(
218 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
219 : : "null com.sun.star.configuration."
220 : : "ConfigurationProvider")),
221 [ # # ][ # # ]: 0 : 0);
[ # # ]
222 : : css::beans::PropertyValue aArg(
223 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath")), -1,
224 : : css::uno::makeAny(
225 : : rtl::OUString(
226 : : RTL_CONSTASCII_USTRINGPARAM(
227 : : "/org.openoffice.Office.Common/I18N/InputMethod"))),
228 [ # # ][ # # ]: 0 : css::beans::PropertyState_DIRECT_VALUE);
[ # # ]
229 [ # # ]: 0 : css::uno::Sequence< css::uno::Any > aArgs(1);
230 [ # # ][ # # ]: 0 : aArgs[0] <<= aArg;
231 : : m_xConfig
232 : : = css::uno::Reference< css::beans::XPropertySet >(
233 [ # # ]: 0 : xProvider->createInstanceWithArguments(
234 : : rtl::OUString(
235 : : RTL_CONSTASCII_USTRINGPARAM(
236 : : "com.sun.star.configuration.ConfigurationUpdateAccess")),
237 : 0 : aArgs),
238 [ # # ][ # # ]: 0 : css::uno::UNO_QUERY);
[ # # ][ # # ]
239 [ # # ]: 0 : if (!m_xConfig.is())
240 : : throw css::uno::RuntimeException(
241 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
242 : : "null com.sun.star.configuration."
243 : : "ConfigurationUpdateAccess")),
244 [ # # ][ # # ]: 0 : 0);
[ # # ]
245 [ # # ]: 0 : bAdd = true;
246 : : }
247 [ # # ][ # # ]: 0 : xConfig = m_xConfig;
248 : : }
249 [ # # ]: 0 : if (bAdd)
250 : : {
251 : : // Exceptions here could be handled individually, to support graceful
252 : : // degradation (no update notification mechanism in this case---but also
253 : : // no dispose notifications):
254 [ # # ][ # # ]: 0 : m_xConfigListener = new WeakPropertyChangeListener(this);
[ # # ][ # # ]
255 [ # # ]: 0 : xConfig->addPropertyChangeListener(
256 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowStatusWindow")),
257 [ # # ][ # # ]: 0 : m_xConfigListener);
258 : : }
259 : 0 : return xConfig;
260 : : }
261 : :
262 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|