1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
31 #include "defaulthelpprovider.hxx"
32 #include "pcrcommon.hxx"
33 #include "modulepcr.hxx"
35 /** === begin UNO includes === **/
36 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
37 #include <com/sun/star/lang/IllegalArgumentException.hpp>
38 #include <com/sun/star/awt/XVclWindowPeer.hpp>
39 /** === end UNO includes === **/
41 #include <toolkit/helper/vclunohelper.hxx>
42 #include <vcl/window.hxx>
43 #include <tools/diagnose_ex.h>
45 //------------------------------------------------------------------------
46 extern "C" void SAL_CALL
createRegistryInfo_DefaultHelpProvider()
48 ::pcr::OAutoRegistration
< ::pcr::DefaultHelpProvider
> aAutoRegistration
;
51 //........................................................................
54 //........................................................................
56 /** === begin UNO using === **/
57 using ::com::sun::star::uno::Reference
;
58 using ::com::sun::star::uno::XComponentContext
;
59 using ::com::sun::star::inspection::XPropertyControl
;
60 using ::com::sun::star::uno::RuntimeException
;
61 using ::com::sun::star::uno::Sequence
;
62 using ::com::sun::star::uno::Any
;
63 using ::com::sun::star::uno::Exception
;
64 using ::com::sun::star::inspection::XObjectInspectorUI
;
65 using ::com::sun::star::uno::XInterface
;
66 using ::com::sun::star::ucb::AlreadyInitializedException
;
67 using ::com::sun::star::lang::IllegalArgumentException
;
68 using ::com::sun::star::uno::UNO_QUERY
;
69 using ::com::sun::star::uno::UNO_QUERY_THROW
;
70 using ::com::sun::star::awt::XWindow
;
71 using ::com::sun::star::awt::XVclWindowPeer
;
72 /** === end UNO using === **/
74 //====================================================================
75 //= DefaultHelpProvider
76 //====================================================================
77 //--------------------------------------------------------------------
78 DefaultHelpProvider::DefaultHelpProvider( const Reference
< XComponentContext
>& _rxContext
)
79 :m_aContext( _rxContext
)
80 ,m_bConstructed( false )
84 //--------------------------------------------------------------------
85 DefaultHelpProvider::~DefaultHelpProvider()
89 //------------------------------------------------------------------------
90 ::rtl::OUString
DefaultHelpProvider::getImplementationName_static( ) throw(RuntimeException
)
92 return ::rtl::OUString::createFromAscii( "org.openoffice.comp.extensions.DefaultHelpProvider");
95 //------------------------------------------------------------------------
96 Sequence
< ::rtl::OUString
> DefaultHelpProvider::getSupportedServiceNames_static( ) throw(RuntimeException
)
98 Sequence
< ::rtl::OUString
> aSupported(1);
99 aSupported
[0] = ::rtl::OUString::createFromAscii( "com.sun.star.inspection.DefaultHelpProvider" );
103 //------------------------------------------------------------------------
104 Reference
< XInterface
> SAL_CALL
DefaultHelpProvider::Create( const Reference
< XComponentContext
>& _rxContext
)
106 return *new DefaultHelpProvider( _rxContext
);
109 //--------------------------------------------------------------------
110 void SAL_CALL
DefaultHelpProvider::focusGained( const Reference
< XPropertyControl
>& _Control
) throw (RuntimeException
)
112 if ( !m_xInspectorUI
.is() )
113 throw RuntimeException( ::rtl::OUString(), *this );
117 m_xInspectorUI
->setHelpSectionText( impl_getHelpText_nothrow( _Control
) );
119 catch( const Exception
& )
121 DBG_UNHANDLED_EXCEPTION();
125 //--------------------------------------------------------------------
126 void SAL_CALL
DefaultHelpProvider::valueChanged( const Reference
< XPropertyControl
>& /*_Control*/ ) throw (RuntimeException
)
131 //--------------------------------------------------------------------
132 void SAL_CALL
DefaultHelpProvider::initialize( const Sequence
< Any
>& _arguments
) throw (Exception
, RuntimeException
)
134 if ( m_bConstructed
)
135 throw AlreadyInitializedException();
137 StlSyntaxSequence
< Any
> arguments( _arguments
);
138 if ( arguments
.size() == 1 )
139 { // constructor: "create( XObjectInspectorUI )"
140 Reference
< XObjectInspectorUI
> xUI( arguments
[0], UNO_QUERY
);
145 throw IllegalArgumentException( ::rtl::OUString(), *this, 0 );
148 //--------------------------------------------------------------------
149 void DefaultHelpProvider::create( const Reference
< XObjectInspectorUI
>& _rxUI
)
152 throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
156 m_xInspectorUI
= _rxUI
;
157 m_xInspectorUI
->registerControlObserver( this );
159 catch( const Exception
& )
161 DBG_UNHANDLED_EXCEPTION();
164 m_bConstructed
= true;
167 //--------------------------------------------------------------------
168 Window
* DefaultHelpProvider::impl_getVclControlWindow_nothrow( const Reference
< XPropertyControl
>& _rxControl
)
170 Window
* pControlWindow
= NULL
;
171 OSL_PRECOND( _rxControl
.is(), "DefaultHelpProvider::impl_getVclControlWindow_nothrow: illegal control!" );
172 if ( !_rxControl
.is() )
173 return pControlWindow
;
177 Reference
< XWindow
> xControlWindow( _rxControl
->getControlWindow(), UNO_QUERY_THROW
);
178 pControlWindow
= VCLUnoHelper::GetWindow( xControlWindow
);
180 catch( const Exception
& )
182 DBG_UNHANDLED_EXCEPTION();
185 return pControlWindow
;
188 //--------------------------------------------------------------------
189 ::rtl::OUString
DefaultHelpProvider::impl_getHelpText_nothrow( const Reference
< XPropertyControl
>& _rxControl
)
191 ::rtl::OUString sHelpText
;
192 OSL_PRECOND( _rxControl
.is(), "DefaultHelpProvider::impl_getHelpText_nothrow: illegal control!" );
193 if ( !_rxControl
.is() )
196 Window
* pControlWindow( impl_getVclControlWindow_nothrow( _rxControl
) );
197 OSL_ENSURE( pControlWindow
, "DefaultHelpProvider::impl_getHelpText_nothrow: could not determine the VCL window!" );
198 if ( !pControlWindow
)
201 sHelpText
= pControlWindow
->GetHelpText();
204 //........................................................................
206 //........................................................................