1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_extensions.hxx" 30 31 #include "defaulthelpprovider.hxx" 32 #include "pcrcommon.hxx" 33 #include "modulepcr.hxx" 34 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 === **/ 40 41 #include <toolkit/helper/vclunohelper.hxx> 42 #include <vcl/window.hxx> 43 #include <tools/diagnose_ex.h> 44 45 //------------------------------------------------------------------------ 46 extern "C" void SAL_CALL createRegistryInfo_DefaultHelpProvider() 47 { 48 ::pcr::OAutoRegistration< ::pcr::DefaultHelpProvider > aAutoRegistration; 49 } 50 51 //........................................................................ 52 namespace pcr 53 { 54 //........................................................................ 55 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 === **/ 73 74 //==================================================================== 75 //= DefaultHelpProvider 76 //==================================================================== 77 //-------------------------------------------------------------------- 78 DefaultHelpProvider::DefaultHelpProvider( const Reference< XComponentContext >& _rxContext ) 79 :m_aContext( _rxContext ) 80 ,m_bConstructed( false ) 81 { 82 } 83 84 //-------------------------------------------------------------------- 85 DefaultHelpProvider::~DefaultHelpProvider() 86 { 87 } 88 89 //------------------------------------------------------------------------ 90 ::rtl::OUString DefaultHelpProvider::getImplementationName_static( ) throw(RuntimeException) 91 { 92 return ::rtl::OUString::createFromAscii( "org.openoffice.comp.extensions.DefaultHelpProvider"); 93 } 94 95 //------------------------------------------------------------------------ 96 Sequence< ::rtl::OUString > DefaultHelpProvider::getSupportedServiceNames_static( ) throw(RuntimeException) 97 { 98 Sequence< ::rtl::OUString > aSupported(1); 99 aSupported[0] = ::rtl::OUString::createFromAscii( "com.sun.star.inspection.DefaultHelpProvider" ); 100 return aSupported; 101 } 102 103 //------------------------------------------------------------------------ 104 Reference< XInterface > SAL_CALL DefaultHelpProvider::Create( const Reference< XComponentContext >& _rxContext ) 105 { 106 return *new DefaultHelpProvider( _rxContext ); 107 } 108 109 //-------------------------------------------------------------------- 110 void SAL_CALL DefaultHelpProvider::focusGained( const Reference< XPropertyControl >& _Control ) throw (RuntimeException) 111 { 112 if ( !m_xInspectorUI.is() ) 113 throw RuntimeException( ::rtl::OUString(), *this ); 114 115 try 116 { 117 m_xInspectorUI->setHelpSectionText( impl_getHelpText_nothrow( _Control ) ); 118 } 119 catch( const Exception& ) 120 { 121 DBG_UNHANDLED_EXCEPTION(); 122 } 123 } 124 125 //-------------------------------------------------------------------- 126 void SAL_CALL DefaultHelpProvider::valueChanged( const Reference< XPropertyControl >& /*_Control*/ ) throw (RuntimeException) 127 { 128 // not interested in 129 } 130 131 //-------------------------------------------------------------------- 132 void SAL_CALL DefaultHelpProvider::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException) 133 { 134 if ( m_bConstructed ) 135 throw AlreadyInitializedException(); 136 137 StlSyntaxSequence< Any > arguments( _arguments ); 138 if ( arguments.size() == 1 ) 139 { // constructor: "create( XObjectInspectorUI )" 140 Reference< XObjectInspectorUI > xUI( arguments[0], UNO_QUERY ); 141 create( xUI ); 142 return; 143 } 144 145 throw IllegalArgumentException( ::rtl::OUString(), *this, 0 ); 146 } 147 148 //-------------------------------------------------------------------- 149 void DefaultHelpProvider::create( const Reference< XObjectInspectorUI >& _rxUI ) 150 { 151 if ( !_rxUI.is() ) 152 throw IllegalArgumentException( ::rtl::OUString(), *this, 1 ); 153 154 try 155 { 156 m_xInspectorUI = _rxUI; 157 m_xInspectorUI->registerControlObserver( this ); 158 } 159 catch( const Exception& ) 160 { 161 DBG_UNHANDLED_EXCEPTION(); 162 } 163 164 m_bConstructed = true; 165 } 166 167 //-------------------------------------------------------------------- 168 Window* DefaultHelpProvider::impl_getVclControlWindow_nothrow( const Reference< XPropertyControl >& _rxControl ) 169 { 170 Window* pControlWindow = NULL; 171 OSL_PRECOND( _rxControl.is(), "DefaultHelpProvider::impl_getVclControlWindow_nothrow: illegal control!" ); 172 if ( !_rxControl.is() ) 173 return pControlWindow; 174 175 try 176 { 177 Reference< XWindow > xControlWindow( _rxControl->getControlWindow(), UNO_QUERY_THROW ); 178 pControlWindow = VCLUnoHelper::GetWindow( xControlWindow ); 179 } 180 catch( const Exception& ) 181 { 182 DBG_UNHANDLED_EXCEPTION(); 183 } 184 185 return pControlWindow; 186 } 187 188 //-------------------------------------------------------------------- 189 ::rtl::OUString DefaultHelpProvider::impl_getHelpText_nothrow( const Reference< XPropertyControl >& _rxControl ) 190 { 191 ::rtl::OUString sHelpText; 192 OSL_PRECOND( _rxControl.is(), "DefaultHelpProvider::impl_getHelpText_nothrow: illegal control!" ); 193 if ( !_rxControl.is() ) 194 return sHelpText; 195 196 Window* pControlWindow( impl_getVclControlWindow_nothrow( _rxControl ) ); 197 OSL_ENSURE( pControlWindow, "DefaultHelpProvider::impl_getHelpText_nothrow: could not determine the VCL window!" ); 198 if ( !pControlWindow ) 199 return sHelpText; 200 201 sHelpText = pControlWindow->GetHelpText(); 202 return sHelpText; 203 } 204 //........................................................................ 205 } // namespace pcr 206 //........................................................................ 207