cid#1636693 COPY_INSTEAD_OF_MOVE
[LibreOffice.git] / extensions / source / propctrlr / defaulthelpprovider.cxx
blobd087c474cae2092b7e8e8912a4bcd32d13dad60b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "defaulthelpprovider.hxx"
22 #include "pcrcommon.hxx"
24 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
25 #include <com/sun/star/lang/IllegalArgumentException.hpp>
26 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <toolkit/helper/vclunohelper.hxx>
29 #include <vcl/window.hxx>
30 #include <comphelper/diagnose_ex.hxx>
31 #include <cppuhelper/supportsservice.hxx>
34 namespace pcr
38 using ::com::sun::star::uno::Reference;
39 using ::com::sun::star::uno::XComponentContext;
40 using ::com::sun::star::inspection::XPropertyControl;
41 using ::com::sun::star::uno::RuntimeException;
42 using ::com::sun::star::uno::Sequence;
43 using ::com::sun::star::uno::Any;
44 using ::com::sun::star::uno::Exception;
45 using ::com::sun::star::inspection::XObjectInspectorUI;
46 using ::com::sun::star::uno::XInterface;
47 using ::com::sun::star::ucb::AlreadyInitializedException;
48 using ::com::sun::star::lang::IllegalArgumentException;
49 using ::com::sun::star::uno::UNO_QUERY;
50 using ::com::sun::star::awt::XWindow;
52 DefaultHelpProvider::DefaultHelpProvider()
53 :m_bConstructed( false )
58 DefaultHelpProvider::~DefaultHelpProvider()
63 Sequence< OUString > SAL_CALL DefaultHelpProvider::getSupportedServiceNames()
65 return { u"com.sun.star.inspection.DefaultHelpProvider"_ustr };
68 OUString SAL_CALL DefaultHelpProvider::getImplementationName()
70 return u"org.openoffice.comp.extensions.DefaultHelpProvider"_ustr;
73 sal_Bool SAL_CALL DefaultHelpProvider::supportsService(const OUString& aServiceName)
75 return cppu::supportsService(this, aServiceName);
79 void SAL_CALL DefaultHelpProvider::focusGained( const Reference< XPropertyControl >& Control )
81 if ( !m_xInspectorUI.is() )
82 throw RuntimeException( OUString(), *this );
84 try
86 m_xInspectorUI->setHelpSectionText( impl_getHelpText_nothrow( Control ) );
88 catch( const Exception& )
90 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr");
95 void SAL_CALL DefaultHelpProvider::valueChanged( const Reference< XPropertyControl >& )
97 // not interested in
101 void SAL_CALL DefaultHelpProvider::initialize( const Sequence< Any >& _arguments )
103 if ( m_bConstructed )
104 throw AlreadyInitializedException();
106 StlSyntaxSequence< Any > arguments( _arguments );
107 if ( arguments.size() == 1 )
108 { // constructor: "create( XObjectInspectorUI )"
109 Reference< XObjectInspectorUI > xUI( arguments[0], UNO_QUERY );
110 create( xUI );
111 return;
114 throw IllegalArgumentException( OUString(), *this, 0 );
118 void DefaultHelpProvider::create( const Reference< XObjectInspectorUI >& _rxUI )
120 if ( !_rxUI.is() )
121 throw IllegalArgumentException( OUString(), *this, 1 );
125 m_xInspectorUI = _rxUI;
126 m_xInspectorUI->registerControlObserver( this );
128 catch( const Exception& )
130 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr");
133 m_bConstructed = true;
137 vcl::Window* DefaultHelpProvider::impl_getVclControlWindow_nothrow( const Reference< XPropertyControl >& _rxControl )
139 vcl::Window* pControlWindow = nullptr;
140 OSL_PRECOND( _rxControl.is(), "DefaultHelpProvider::impl_getVclControlWindow_nothrow: illegal control!" );
141 if ( !_rxControl.is() )
142 return pControlWindow;
146 Reference< XWindow > xControlWindow( _rxControl->getControlWindow(), css::uno::UNO_SET_THROW );
147 pControlWindow = VCLUnoHelper::GetWindow( xControlWindow );
149 catch( const Exception& )
151 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr");
154 return pControlWindow;
158 OUString DefaultHelpProvider::impl_getHelpText_nothrow( const Reference< XPropertyControl >& _rxControl )
160 OUString sHelpText;
161 OSL_PRECOND( _rxControl.is(), "DefaultHelpProvider::impl_getHelpText_nothrow: illegal control!" );
162 if ( !_rxControl.is() )
163 return sHelpText;
165 vcl::Window* pControlWindow( impl_getVclControlWindow_nothrow( _rxControl ) );
166 OSL_ENSURE( pControlWindow, "DefaultHelpProvider::impl_getHelpText_nothrow: could not determine the VCL window!" );
167 if ( !pControlWindow )
168 return sHelpText;
170 sHelpText = pControlWindow->GetHelpText();
171 return sHelpText;
174 } // namespace pcr
176 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
177 extensions_propctrlr_DefaultHelpProvider_get_implementation(
178 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
180 return cppu::acquire(new pcr::DefaultHelpProvider());
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */