1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
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" };
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 );
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
>& )
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
);
124 throw IllegalArgumentException( OUString(), *this, 0 );
128 void DefaultHelpProvider::create( const Reference
< XObjectInspectorUI
>& _rxUI
)
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
)
171 OSL_PRECOND( _rxControl
.is(), "DefaultHelpProvider::impl_getHelpText_nothrow: illegal control!" );
172 if ( !_rxControl
.is() )
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
)
180 sHelpText
= pControlWindow
->GetHelpText();
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */