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>
28 #include <com/sun/star/awt/XVclWindowPeer.hpp>
30 #include <toolkit/helper/vclunohelper.hxx>
31 #include <vcl/window.hxx>
32 #include <tools/diagnose_ex.h>
35 extern "C" void SAL_CALL
createRegistryInfo_DefaultHelpProvider()
37 ::pcr::OAutoRegistration
< ::pcr::DefaultHelpProvider
> aAutoRegistration
;
45 using ::com::sun::star::uno::Reference
;
46 using ::com::sun::star::uno::XComponentContext
;
47 using ::com::sun::star::inspection::XPropertyControl
;
48 using ::com::sun::star::uno::RuntimeException
;
49 using ::com::sun::star::uno::Sequence
;
50 using ::com::sun::star::uno::Any
;
51 using ::com::sun::star::uno::Exception
;
52 using ::com::sun::star::inspection::XObjectInspectorUI
;
53 using ::com::sun::star::uno::XInterface
;
54 using ::com::sun::star::ucb::AlreadyInitializedException
;
55 using ::com::sun::star::lang::IllegalArgumentException
;
56 using ::com::sun::star::uno::UNO_QUERY
;
57 using ::com::sun::star::uno::UNO_QUERY_THROW
;
58 using ::com::sun::star::awt::XWindow
;
59 using ::com::sun::star::awt::XVclWindowPeer
;
61 DefaultHelpProvider::DefaultHelpProvider()
62 :m_bConstructed( false )
67 DefaultHelpProvider::~DefaultHelpProvider()
72 OUString
DefaultHelpProvider::getImplementationName_static( ) throw(RuntimeException
)
74 return OUString("org.openoffice.comp.extensions.DefaultHelpProvider");
78 Sequence
< OUString
> DefaultHelpProvider::getSupportedServiceNames_static( ) throw(RuntimeException
)
80 Sequence
< OUString
> aSupported(1);
81 aSupported
[0] = "com.sun.star.inspection.DefaultHelpProvider";
86 Reference
< XInterface
> SAL_CALL
DefaultHelpProvider::Create( const Reference
< XComponentContext
>& )
88 return *new DefaultHelpProvider
;
92 void SAL_CALL
DefaultHelpProvider::focusGained( const Reference
< XPropertyControl
>& _Control
) throw (RuntimeException
, std::exception
)
94 if ( !m_xInspectorUI
.is() )
95 throw RuntimeException( OUString(), *this );
99 m_xInspectorUI
->setHelpSectionText( impl_getHelpText_nothrow( _Control
) );
101 catch( const Exception
& )
103 DBG_UNHANDLED_EXCEPTION();
108 void SAL_CALL
DefaultHelpProvider::valueChanged( const Reference
< XPropertyControl
>& /*_Control*/ ) throw (RuntimeException
, std::exception
)
114 void SAL_CALL
DefaultHelpProvider::initialize( const Sequence
< Any
>& _arguments
) throw (Exception
, RuntimeException
, std::exception
)
116 if ( m_bConstructed
)
117 throw AlreadyInitializedException();
119 StlSyntaxSequence
< Any
> arguments( _arguments
);
120 if ( arguments
.size() == 1 )
121 { // constructor: "create( XObjectInspectorUI )"
122 Reference
< XObjectInspectorUI
> xUI( arguments
[0], UNO_QUERY
);
127 throw IllegalArgumentException( OUString(), *this, 0 );
131 void DefaultHelpProvider::create( const Reference
< XObjectInspectorUI
>& _rxUI
)
134 throw IllegalArgumentException( OUString(), *this, 1 );
138 m_xInspectorUI
= _rxUI
;
139 m_xInspectorUI
->registerControlObserver( this );
141 catch( const Exception
& )
143 DBG_UNHANDLED_EXCEPTION();
146 m_bConstructed
= true;
150 vcl::Window
* DefaultHelpProvider::impl_getVclControlWindow_nothrow( const Reference
< XPropertyControl
>& _rxControl
)
152 vcl::Window
* pControlWindow
= NULL
;
153 OSL_PRECOND( _rxControl
.is(), "DefaultHelpProvider::impl_getVclControlWindow_nothrow: illegal control!" );
154 if ( !_rxControl
.is() )
155 return pControlWindow
;
159 Reference
< XWindow
> xControlWindow( _rxControl
->getControlWindow(), UNO_QUERY_THROW
);
160 pControlWindow
= VCLUnoHelper::GetWindow( xControlWindow
);
162 catch( const Exception
& )
164 DBG_UNHANDLED_EXCEPTION();
167 return pControlWindow
;
171 OUString
DefaultHelpProvider::impl_getHelpText_nothrow( const Reference
< XPropertyControl
>& _rxControl
)
174 OSL_PRECOND( _rxControl
.is(), "DefaultHelpProvider::impl_getHelpText_nothrow: illegal control!" );
175 if ( !_rxControl
.is() )
178 vcl::Window
* pControlWindow( impl_getVclControlWindow_nothrow( _rxControl
) );
179 OSL_ENSURE( pControlWindow
, "DefaultHelpProvider::impl_getHelpText_nothrow: could not determine the VCL window!" );
180 if ( !pControlWindow
)
183 sHelpText
= pControlWindow
->GetHelpText();
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */