Update ooo320-m1
[ooovba.git] / extensions / source / propctrlr / defaulthelpprovider.cxx
blob1c26dbb6d3b56500d83805a8d835f284f64e13e0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: defaulthelpprovider.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
34 #include "defaulthelpprovider.hxx"
35 #include "pcrcommon.hxx"
36 #include "modulepcr.hxx"
38 /** === begin UNO includes === **/
39 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
40 #include <com/sun/star/lang/IllegalArgumentException.hpp>
41 #include <com/sun/star/awt/XVclWindowPeer.hpp>
42 /** === end UNO includes === **/
44 #include <toolkit/helper/vclunohelper.hxx>
45 #include <vcl/window.hxx>
46 #include <tools/diagnose_ex.h>
48 //------------------------------------------------------------------------
49 extern "C" void SAL_CALL createRegistryInfo_DefaultHelpProvider()
51 ::pcr::OAutoRegistration< ::pcr::DefaultHelpProvider > aAutoRegistration;
54 //........................................................................
55 namespace pcr
57 //........................................................................
59 /** === begin UNO using === **/
60 using ::com::sun::star::uno::Reference;
61 using ::com::sun::star::uno::XComponentContext;
62 using ::com::sun::star::inspection::XPropertyControl;
63 using ::com::sun::star::uno::RuntimeException;
64 using ::com::sun::star::uno::Sequence;
65 using ::com::sun::star::uno::Any;
66 using ::com::sun::star::uno::Exception;
67 using ::com::sun::star::inspection::XObjectInspectorUI;
68 using ::com::sun::star::uno::XInterface;
69 using ::com::sun::star::ucb::AlreadyInitializedException;
70 using ::com::sun::star::lang::IllegalArgumentException;
71 using ::com::sun::star::uno::UNO_QUERY;
72 using ::com::sun::star::uno::UNO_QUERY_THROW;
73 using ::com::sun::star::awt::XWindow;
74 using ::com::sun::star::awt::XVclWindowPeer;
75 /** === end UNO using === **/
77 //====================================================================
78 //= DefaultHelpProvider
79 //====================================================================
80 //--------------------------------------------------------------------
81 DefaultHelpProvider::DefaultHelpProvider( const Reference< XComponentContext >& _rxContext )
82 :m_aContext( _rxContext )
83 ,m_bConstructed( false )
87 //--------------------------------------------------------------------
88 DefaultHelpProvider::~DefaultHelpProvider()
92 //------------------------------------------------------------------------
93 ::rtl::OUString DefaultHelpProvider::getImplementationName_static( ) throw(RuntimeException)
95 return ::rtl::OUString::createFromAscii( "org.openoffice.comp.extensions.DefaultHelpProvider");
98 //------------------------------------------------------------------------
99 Sequence< ::rtl::OUString > DefaultHelpProvider::getSupportedServiceNames_static( ) throw(RuntimeException)
101 Sequence< ::rtl::OUString > aSupported(1);
102 aSupported[0] = ::rtl::OUString::createFromAscii( "com.sun.star.inspection.DefaultHelpProvider" );
103 return aSupported;
106 //------------------------------------------------------------------------
107 Reference< XInterface > SAL_CALL DefaultHelpProvider::Create( const Reference< XComponentContext >& _rxContext )
109 return *new DefaultHelpProvider( _rxContext );
112 //--------------------------------------------------------------------
113 void SAL_CALL DefaultHelpProvider::focusGained( const Reference< XPropertyControl >& _Control ) throw (RuntimeException)
115 if ( !m_xInspectorUI.is() )
116 throw RuntimeException( ::rtl::OUString(), *this );
120 m_xInspectorUI->setHelpSectionText( impl_getHelpText_nothrow( _Control ) );
122 catch( const Exception& )
124 DBG_UNHANDLED_EXCEPTION();
128 //--------------------------------------------------------------------
129 void SAL_CALL DefaultHelpProvider::valueChanged( const Reference< XPropertyControl >& /*_Control*/ ) throw (RuntimeException)
131 // not interested in
134 //--------------------------------------------------------------------
135 void SAL_CALL DefaultHelpProvider::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException)
137 if ( m_bConstructed )
138 throw AlreadyInitializedException();
140 StlSyntaxSequence< Any > arguments( _arguments );
141 if ( arguments.size() == 1 )
142 { // constructor: "create( XObjectInspectorUI )"
143 Reference< XObjectInspectorUI > xUI( arguments[0], UNO_QUERY );
144 create( xUI );
145 return;
148 throw IllegalArgumentException( ::rtl::OUString(), *this, 0 );
151 //--------------------------------------------------------------------
152 void DefaultHelpProvider::create( const Reference< XObjectInspectorUI >& _rxUI )
154 if ( !_rxUI.is() )
155 throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
159 m_xInspectorUI = _rxUI;
160 m_xInspectorUI->registerControlObserver( this );
162 catch( const Exception& )
164 DBG_UNHANDLED_EXCEPTION();
167 m_bConstructed = true;
170 //--------------------------------------------------------------------
171 Window* DefaultHelpProvider::impl_getVclControlWindow_nothrow( const Reference< XPropertyControl >& _rxControl )
173 Window* pControlWindow = NULL;
174 OSL_PRECOND( _rxControl.is(), "DefaultHelpProvider::impl_getVclControlWindow_nothrow: illegal control!" );
175 if ( !_rxControl.is() )
176 return pControlWindow;
180 Reference< XWindow > xControlWindow( _rxControl->getControlWindow(), UNO_QUERY_THROW );
181 pControlWindow = VCLUnoHelper::GetWindow( xControlWindow );
183 catch( const Exception& )
185 DBG_UNHANDLED_EXCEPTION();
188 return pControlWindow;
191 //--------------------------------------------------------------------
192 ::rtl::OUString DefaultHelpProvider::impl_getHelpText_nothrow( const Reference< XPropertyControl >& _rxControl )
194 ::rtl::OUString sHelpText;
195 OSL_PRECOND( _rxControl.is(), "DefaultHelpProvider::impl_getHelpText_nothrow: illegal control!" );
196 if ( !_rxControl.is() )
197 return sHelpText;
199 Window* pControlWindow( impl_getVclControlWindow_nothrow( _rxControl ) );
200 OSL_ENSURE( pControlWindow, "DefaultHelpProvider::impl_getHelpText_nothrow: could not determine the VCL window!" );
201 if ( !pControlWindow )
202 return sHelpText;
204 sHelpText = pControlWindow->GetHelpText();
205 return sHelpText;
207 //........................................................................
208 } // namespace pcr
209 //........................................................................