Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / extensions / source / propctrlr / defaulthelpprovider.cxx
blob322a04f8926ca2a8d4394fefbd6b3f39f1399e81
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"
23 #include "pcrservices.hxx"
24 #include "modulepcr.hxx"
26 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
27 #include <com/sun/star/lang/IllegalArgumentException.hpp>
29 #include <toolkit/helper/vclunohelper.hxx>
30 #include <vcl/window.hxx>
31 #include <tools/diagnose_ex.h>
34 extern "C" void createRegistryInfo_DefaultHelpProvider()
36 ::pcr::OAutoRegistration< ::pcr::DefaultHelpProvider > aAutoRegistration;
40 namespace pcr
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::uno::XComponentContext;
46 using ::com::sun::star::inspection::XPropertyControl;
47 using ::com::sun::star::uno::RuntimeException;
48 using ::com::sun::star::uno::Sequence;
49 using ::com::sun::star::uno::Any;
50 using ::com::sun::star::uno::Exception;
51 using ::com::sun::star::inspection::XObjectInspectorUI;
52 using ::com::sun::star::uno::XInterface;
53 using ::com::sun::star::ucb::AlreadyInitializedException;
54 using ::com::sun::star::lang::IllegalArgumentException;
55 using ::com::sun::star::uno::UNO_QUERY;
56 using ::com::sun::star::uno::UNO_QUERY_THROW;
57 using ::com::sun::star::awt::XWindow;
59 DefaultHelpProvider::DefaultHelpProvider()
60 :m_bConstructed( false )
65 DefaultHelpProvider::~DefaultHelpProvider()
70 OUString DefaultHelpProvider::getImplementationName_static( )
72 return "org.openoffice.comp.extensions.DefaultHelpProvider";
76 Sequence< OUString > DefaultHelpProvider::getSupportedServiceNames_static( )
78 Sequence< OUString > aSupported { "com.sun.star.inspection.DefaultHelpProvider" };
79 return aSupported;
83 Reference< XInterface > DefaultHelpProvider::Create( const Reference< XComponentContext >& )
85 return *new DefaultHelpProvider;
89 void SAL_CALL DefaultHelpProvider::focusGained( const Reference< XPropertyControl >& Control )
91 if ( !m_xInspectorUI.is() )
92 throw RuntimeException( OUString(), *this );
94 try
96 m_xInspectorUI->setHelpSectionText( impl_getHelpText_nothrow( Control ) );
98 catch( const Exception& )
100 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr");
105 void SAL_CALL DefaultHelpProvider::valueChanged( const Reference< XPropertyControl >& )
107 // not interested in
111 void SAL_CALL DefaultHelpProvider::initialize( const Sequence< Any >& _arguments )
113 if ( m_bConstructed )
114 throw AlreadyInitializedException();
116 StlSyntaxSequence< Any > arguments( _arguments );
117 if ( arguments.size() == 1 )
118 { // constructor: "create( XObjectInspectorUI )"
119 Reference< XObjectInspectorUI > xUI( arguments[0], UNO_QUERY );
120 create( xUI );
121 return;
124 throw IllegalArgumentException( OUString(), *this, 0 );
128 void DefaultHelpProvider::create( const Reference< XObjectInspectorUI >& _rxUI )
130 if ( !_rxUI.is() )
131 throw IllegalArgumentException( OUString(), *this, 1 );
135 m_xInspectorUI = _rxUI;
136 m_xInspectorUI->registerControlObserver( this );
138 catch( const Exception& )
140 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr");
143 m_bConstructed = true;
147 vcl::Window* DefaultHelpProvider::impl_getVclControlWindow_nothrow( const Reference< XPropertyControl >& _rxControl )
149 vcl::Window* pControlWindow = nullptr;
150 OSL_PRECOND( _rxControl.is(), "DefaultHelpProvider::impl_getVclControlWindow_nothrow: illegal control!" );
151 if ( !_rxControl.is() )
152 return pControlWindow;
156 Reference< XWindow > xControlWindow( _rxControl->getControlWindow(), css::uno::UNO_SET_THROW );
157 pControlWindow = VCLUnoHelper::GetWindow( xControlWindow ).get();
159 catch( const Exception& )
161 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr");
164 return pControlWindow;
168 OUString DefaultHelpProvider::impl_getHelpText_nothrow( const Reference< XPropertyControl >& _rxControl )
170 OUString sHelpText;
171 OSL_PRECOND( _rxControl.is(), "DefaultHelpProvider::impl_getHelpText_nothrow: illegal control!" );
172 if ( !_rxControl.is() )
173 return sHelpText;
175 vcl::Window* pControlWindow( impl_getVclControlWindow_nothrow( _rxControl ) );
176 OSL_ENSURE( pControlWindow, "DefaultHelpProvider::impl_getHelpText_nothrow: could not determine the VCL window!" );
177 if ( !pControlWindow )
178 return sHelpText;
180 sHelpText = pControlWindow->GetHelpText();
181 return sHelpText;
184 } // namespace pcr
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */