merge the formfield patch from ooo-build
[ooovba.git] / sfx2 / source / appl / imestatuswindow.cxx
blob4c0ef295c0ed0c167f2de4bb7e3bedea1cb15f3a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: imestatuswindow.cxx,v $
10 * $Revision: 1.8 $
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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 #include "imestatuswindow.hxx"
36 #include <sfx2/app.hxx>
37 #include <sfx2/sfxsids.hrc>
39 #include "com/sun/star/beans/PropertyState.hpp"
40 #include "com/sun/star/beans/PropertyValue.hpp"
41 #include "com/sun/star/beans/XPropertySet.hpp"
42 #include "com/sun/star/lang/DisposedException.hpp"
43 #include "com/sun/star/lang/XMultiServiceFactory.hpp"
44 #include "com/sun/star/uno/Any.hxx"
45 #include "com/sun/star/uno/Exception.hpp"
46 #include "com/sun/star/uno/Reference.hxx"
47 #include "com/sun/star/uno/RuntimeException.hpp"
48 #include "com/sun/star/uno/Sequence.hxx"
49 #include "com/sun/star/util/XChangesBatch.hpp"
50 #include "osl/diagnose.h"
51 #include "osl/mutex.hxx"
52 #include "rtl/ustring.h"
53 #include "rtl/ustring.hxx"
54 #include "sal/types.h"
55 #include "vcl/svapp.hxx"
56 #include "vos/mutex.hxx"
58 namespace css = com::sun::star;
60 using sfx2::appl::ImeStatusWindow;
62 ImeStatusWindow::ImeStatusWindow(
63 SfxApplication & rApplication,
64 css::uno::Reference< css::lang::XMultiServiceFactory > const &
65 rServiceFactory):
66 m_rApplication(rApplication),
67 m_xServiceFactory(rServiceFactory),
68 m_bDisposed(false)
71 void ImeStatusWindow::init()
73 if (Application::CanToggleImeStatusWindow())
74 try
76 sal_Bool bShow = sal_Bool();
77 if (getConfig()->getPropertyValue(
78 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
79 "ShowStatusWindow")))
80 >>= bShow)
81 Application::ShowImeStatusWindow(bShow);
83 catch (css::uno::Exception &)
85 OSL_ENSURE(false, "com.sun.star.uno.Exception");
86 // Degrade gracefully and use the VCL-supplied default if no
87 // configuration is available.
91 bool ImeStatusWindow::isShowing()
93 try
95 sal_Bool bShow = sal_Bool();
96 if (getConfig()->getPropertyValue(
97 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowStatusWindow")))
98 >>= bShow)
99 return bShow;
101 catch (css::uno::Exception &)
103 OSL_ENSURE(false, "com.sun.star.uno.Exception");
104 // Degrade gracefully and use the VCL-supplied default if no
105 // configuration is available.
107 return Application::GetShowImeStatusWindowDefault();
110 void ImeStatusWindow::show(bool bShow)
114 css::uno::Reference< css::beans::XPropertySet > xConfig(getConfig());
115 xConfig->setPropertyValue(
116 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowStatusWindow")),
117 css::uno::makeAny(static_cast< sal_Bool >(bShow)));
118 css::uno::Reference< css::util::XChangesBatch > xCommit(
119 xConfig, css::uno::UNO_QUERY);
120 // Degrade gracefully by not saving the settings permanently:
121 if (xCommit.is())
122 xCommit->commitChanges();
123 // Alternatively, setting the VCL status could be done even if updating
124 // the configuration failed:
125 Application::ShowImeStatusWindow(bShow);
127 catch (css::uno::Exception &)
129 OSL_ENSURE(false, "com.sun.star.uno.Exception");
133 bool ImeStatusWindow::canToggle() const
135 return Application::CanToggleImeStatusWindow();
138 ImeStatusWindow::~ImeStatusWindow()
140 if (m_xConfig.is())
141 // We should never get here, but just in case...
144 m_xConfig->removePropertyChangeListener(
145 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowStatusWindow")),
146 this);
148 catch (css::uno::Exception &)
150 OSL_ENSURE(false, "com.sun.star.uno.RuntimeException");
154 void SAL_CALL ImeStatusWindow::disposing(css::lang::EventObject const & )
155 throw (css::uno::RuntimeException)
157 osl::MutexGuard aGuard(m_aMutex);
158 m_xConfig = 0;
159 m_bDisposed = true;
162 void SAL_CALL
163 ImeStatusWindow::propertyChange(css::beans::PropertyChangeEvent const & )
164 throw (css::uno::RuntimeException)
166 vos::OGuard aGuard(Application::GetSolarMutex());
167 m_rApplication.Invalidate(SID_SHOW_IME_STATUS_WINDOW);
170 css::uno::Reference< css::beans::XPropertySet > ImeStatusWindow::getConfig()
172 css::uno::Reference< css::beans::XPropertySet > xConfig;
173 bool bAdd = false;
175 osl::MutexGuard aGuard(m_aMutex);
176 if (!m_xConfig.is())
178 if (m_bDisposed)
179 throw css::lang::DisposedException();
180 if (!m_xServiceFactory.is())
181 throw css::uno::RuntimeException(
182 rtl::OUString(
183 RTL_CONSTASCII_USTRINGPARAM(
184 "null comphelper::getProcessServiceFactory")),
186 css::uno::Reference< css::lang::XMultiServiceFactory > xProvider(
187 m_xServiceFactory->createInstance(
188 rtl::OUString(
189 RTL_CONSTASCII_USTRINGPARAM(
190 "com.sun.star.configuration.ConfigurationProvider"))),
191 css::uno::UNO_QUERY);
192 if (!xProvider.is())
193 throw css::uno::RuntimeException(
194 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
195 "null com.sun.star.configuration."
196 "ConfigurationProvider")),
198 css::beans::PropertyValue aArg(
199 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath")), -1,
200 css::uno::makeAny(
201 rtl::OUString(
202 RTL_CONSTASCII_USTRINGPARAM(
203 "/org.openoffice.Office.Common/I18N/InputMethod"))),
204 css::beans::PropertyState_DIRECT_VALUE);
205 css::uno::Sequence< css::uno::Any > aArgs(1);
206 aArgs[0] <<= aArg;
207 m_xConfig
208 = css::uno::Reference< css::beans::XPropertySet >(
209 xProvider->createInstanceWithArguments(
210 rtl::OUString(
211 RTL_CONSTASCII_USTRINGPARAM(
212 "com.sun.star.configuration.ConfigurationUpdateAccess")),
213 aArgs),
214 css::uno::UNO_QUERY);
215 if (!m_xConfig.is())
216 throw css::uno::RuntimeException(
217 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
218 "null com.sun.star.configuration."
219 "ConfigurationUpdateAccess")),
221 bAdd = true;
223 xConfig = m_xConfig;
225 if (bAdd)
226 // Exceptions here could be handled individually, to support graceful
227 // degradation (no update notification mechanism in this case---but also
228 // no dispose notifications):
229 xConfig->addPropertyChangeListener(
230 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowStatusWindow")),
231 this);
232 return xConfig;