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 "modulepcr.hxx"
25 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
26 #include <com/sun/star/lang/IllegalArgumentException.hpp>
27 #include <com/sun/star/awt/XVclWindowPeer.hpp>
29 #include <toolkit/helper/vclunohelper.hxx>
30 #include <vcl/window.hxx>
31 #include <tools/diagnose_ex.h>
33 //------------------------------------------------------------------------
34 extern "C" void SAL_CALL
createRegistryInfo_DefaultHelpProvider()
36 ::pcr::OAutoRegistration
< ::pcr::DefaultHelpProvider
> aAutoRegistration
;
39 //........................................................................
42 //........................................................................
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
;
58 using ::com::sun::star::awt::XVclWindowPeer
;
60 //====================================================================
61 //= DefaultHelpProvider
62 //====================================================================
63 //--------------------------------------------------------------------
64 DefaultHelpProvider::DefaultHelpProvider( const Reference
< XComponentContext
>& _rxContext
)
65 :m_aContext( _rxContext
)
66 ,m_bConstructed( false )
70 //--------------------------------------------------------------------
71 DefaultHelpProvider::~DefaultHelpProvider()
75 //------------------------------------------------------------------------
76 OUString
DefaultHelpProvider::getImplementationName_static( ) throw(RuntimeException
)
78 return OUString("org.openoffice.comp.extensions.DefaultHelpProvider");
81 //------------------------------------------------------------------------
82 Sequence
< OUString
> DefaultHelpProvider::getSupportedServiceNames_static( ) throw(RuntimeException
)
84 Sequence
< OUString
> aSupported(1);
85 aSupported
[0] = OUString("com.sun.star.inspection.DefaultHelpProvider");
89 //------------------------------------------------------------------------
90 Reference
< XInterface
> SAL_CALL
DefaultHelpProvider::Create( const Reference
< XComponentContext
>& _rxContext
)
92 return *new DefaultHelpProvider( _rxContext
);
95 //--------------------------------------------------------------------
96 void SAL_CALL
DefaultHelpProvider::focusGained( const Reference
< XPropertyControl
>& _Control
) throw (RuntimeException
)
98 if ( !m_xInspectorUI
.is() )
99 throw RuntimeException( OUString(), *this );
103 m_xInspectorUI
->setHelpSectionText( impl_getHelpText_nothrow( _Control
) );
105 catch( const Exception
& )
107 DBG_UNHANDLED_EXCEPTION();
111 //--------------------------------------------------------------------
112 void SAL_CALL
DefaultHelpProvider::valueChanged( const Reference
< XPropertyControl
>& /*_Control*/ ) throw (RuntimeException
)
117 //--------------------------------------------------------------------
118 void SAL_CALL
DefaultHelpProvider::initialize( const Sequence
< Any
>& _arguments
) throw (Exception
, RuntimeException
)
120 if ( m_bConstructed
)
121 throw AlreadyInitializedException();
123 StlSyntaxSequence
< Any
> arguments( _arguments
);
124 if ( arguments
.size() == 1 )
125 { // constructor: "create( XObjectInspectorUI )"
126 Reference
< XObjectInspectorUI
> xUI( arguments
[0], UNO_QUERY
);
131 throw IllegalArgumentException( OUString(), *this, 0 );
134 //--------------------------------------------------------------------
135 void DefaultHelpProvider::create( const Reference
< XObjectInspectorUI
>& _rxUI
)
138 throw IllegalArgumentException( OUString(), *this, 1 );
142 m_xInspectorUI
= _rxUI
;
143 m_xInspectorUI
->registerControlObserver( this );
145 catch( const Exception
& )
147 DBG_UNHANDLED_EXCEPTION();
150 m_bConstructed
= true;
153 //--------------------------------------------------------------------
154 Window
* DefaultHelpProvider::impl_getVclControlWindow_nothrow( const Reference
< XPropertyControl
>& _rxControl
)
156 Window
* pControlWindow
= NULL
;
157 OSL_PRECOND( _rxControl
.is(), "DefaultHelpProvider::impl_getVclControlWindow_nothrow: illegal control!" );
158 if ( !_rxControl
.is() )
159 return pControlWindow
;
163 Reference
< XWindow
> xControlWindow( _rxControl
->getControlWindow(), UNO_QUERY_THROW
);
164 pControlWindow
= VCLUnoHelper::GetWindow( xControlWindow
);
166 catch( const Exception
& )
168 DBG_UNHANDLED_EXCEPTION();
171 return pControlWindow
;
174 //--------------------------------------------------------------------
175 OUString
DefaultHelpProvider::impl_getHelpText_nothrow( const Reference
< XPropertyControl
>& _rxControl
)
178 OSL_PRECOND( _rxControl
.is(), "DefaultHelpProvider::impl_getHelpText_nothrow: illegal control!" );
179 if ( !_rxControl
.is() )
182 Window
* pControlWindow( impl_getVclControlWindow_nothrow( _rxControl
) );
183 OSL_ENSURE( pControlWindow
, "DefaultHelpProvider::impl_getHelpText_nothrow: could not determine the VCL window!" );
184 if ( !pControlWindow
)
187 sHelpText
= pControlWindow
->GetHelpText();
190 //........................................................................
192 //........................................................................
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */