Bump for 3.6-28
[LibreOffice.git] / extensions / source / propctrlr / defaulthelpprovider.cxx
blobbcced921218e88de955a6632da997beeeb56a60b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "defaulthelpprovider.hxx"
31 #include "pcrcommon.hxx"
32 #include "modulepcr.hxx"
34 /** === begin UNO includes === **/
35 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
36 #include <com/sun/star/lang/IllegalArgumentException.hpp>
37 #include <com/sun/star/awt/XVclWindowPeer.hpp>
38 /** === end UNO includes === **/
40 #include <toolkit/helper/vclunohelper.hxx>
41 #include <vcl/window.hxx>
42 #include <tools/diagnose_ex.h>
44 //------------------------------------------------------------------------
45 extern "C" void SAL_CALL createRegistryInfo_DefaultHelpProvider()
47 ::pcr::OAutoRegistration< ::pcr::DefaultHelpProvider > aAutoRegistration;
50 //........................................................................
51 namespace pcr
53 //........................................................................
55 /** === begin UNO using === **/
56 using ::com::sun::star::uno::Reference;
57 using ::com::sun::star::uno::XComponentContext;
58 using ::com::sun::star::inspection::XPropertyControl;
59 using ::com::sun::star::uno::RuntimeException;
60 using ::com::sun::star::uno::Sequence;
61 using ::com::sun::star::uno::Any;
62 using ::com::sun::star::uno::Exception;
63 using ::com::sun::star::inspection::XObjectInspectorUI;
64 using ::com::sun::star::uno::XInterface;
65 using ::com::sun::star::ucb::AlreadyInitializedException;
66 using ::com::sun::star::lang::IllegalArgumentException;
67 using ::com::sun::star::uno::UNO_QUERY;
68 using ::com::sun::star::uno::UNO_QUERY_THROW;
69 using ::com::sun::star::awt::XWindow;
70 using ::com::sun::star::awt::XVclWindowPeer;
71 /** === end UNO using === **/
73 //====================================================================
74 //= DefaultHelpProvider
75 //====================================================================
76 //--------------------------------------------------------------------
77 DefaultHelpProvider::DefaultHelpProvider( const Reference< XComponentContext >& _rxContext )
78 :m_aContext( _rxContext )
79 ,m_bConstructed( false )
83 //--------------------------------------------------------------------
84 DefaultHelpProvider::~DefaultHelpProvider()
88 //------------------------------------------------------------------------
89 ::rtl::OUString DefaultHelpProvider::getImplementationName_static( ) throw(RuntimeException)
91 return ::rtl::OUString("org.openoffice.comp.extensions.DefaultHelpProvider");
94 //------------------------------------------------------------------------
95 Sequence< ::rtl::OUString > DefaultHelpProvider::getSupportedServiceNames_static( ) throw(RuntimeException)
97 Sequence< ::rtl::OUString > aSupported(1);
98 aSupported[0] = ::rtl::OUString("com.sun.star.inspection.DefaultHelpProvider");
99 return aSupported;
102 //------------------------------------------------------------------------
103 Reference< XInterface > SAL_CALL DefaultHelpProvider::Create( const Reference< XComponentContext >& _rxContext )
105 return *new DefaultHelpProvider( _rxContext );
108 //--------------------------------------------------------------------
109 void SAL_CALL DefaultHelpProvider::focusGained( const Reference< XPropertyControl >& _Control ) throw (RuntimeException)
111 if ( !m_xInspectorUI.is() )
112 throw RuntimeException( ::rtl::OUString(), *this );
116 m_xInspectorUI->setHelpSectionText( impl_getHelpText_nothrow( _Control ) );
118 catch( const Exception& )
120 DBG_UNHANDLED_EXCEPTION();
124 //--------------------------------------------------------------------
125 void SAL_CALL DefaultHelpProvider::valueChanged( const Reference< XPropertyControl >& /*_Control*/ ) throw (RuntimeException)
127 // not interested in
130 //--------------------------------------------------------------------
131 void SAL_CALL DefaultHelpProvider::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException)
133 if ( m_bConstructed )
134 throw AlreadyInitializedException();
136 StlSyntaxSequence< Any > arguments( _arguments );
137 if ( arguments.size() == 1 )
138 { // constructor: "create( XObjectInspectorUI )"
139 Reference< XObjectInspectorUI > xUI( arguments[0], UNO_QUERY );
140 create( xUI );
141 return;
144 throw IllegalArgumentException( ::rtl::OUString(), *this, 0 );
147 //--------------------------------------------------------------------
148 void DefaultHelpProvider::create( const Reference< XObjectInspectorUI >& _rxUI )
150 if ( !_rxUI.is() )
151 throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
155 m_xInspectorUI = _rxUI;
156 m_xInspectorUI->registerControlObserver( this );
158 catch( const Exception& )
160 DBG_UNHANDLED_EXCEPTION();
163 m_bConstructed = true;
166 //--------------------------------------------------------------------
167 Window* DefaultHelpProvider::impl_getVclControlWindow_nothrow( const Reference< XPropertyControl >& _rxControl )
169 Window* pControlWindow = NULL;
170 OSL_PRECOND( _rxControl.is(), "DefaultHelpProvider::impl_getVclControlWindow_nothrow: illegal control!" );
171 if ( !_rxControl.is() )
172 return pControlWindow;
176 Reference< XWindow > xControlWindow( _rxControl->getControlWindow(), UNO_QUERY_THROW );
177 pControlWindow = VCLUnoHelper::GetWindow( xControlWindow );
179 catch( const Exception& )
181 DBG_UNHANDLED_EXCEPTION();
184 return pControlWindow;
187 //--------------------------------------------------------------------
188 ::rtl::OUString DefaultHelpProvider::impl_getHelpText_nothrow( const Reference< XPropertyControl >& _rxControl )
190 ::rtl::OUString sHelpText;
191 OSL_PRECOND( _rxControl.is(), "DefaultHelpProvider::impl_getHelpText_nothrow: illegal control!" );
192 if ( !_rxControl.is() )
193 return sHelpText;
195 Window* pControlWindow( impl_getVclControlWindow_nothrow( _rxControl ) );
196 OSL_ENSURE( pControlWindow, "DefaultHelpProvider::impl_getHelpText_nothrow: could not determine the VCL window!" );
197 if ( !pControlWindow )
198 return sHelpText;
200 sHelpText = pControlWindow->GetHelpText();
201 return sHelpText;
203 //........................................................................
204 } // namespace pcr
205 //........................................................................
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */