1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_extensions.hxx" 26 27 #include "defaulthelpprovider.hxx" 28 #include "pcrcommon.hxx" 29 #include "modulepcr.hxx" 30 31 /** === begin UNO includes === **/ 32 #include <com/sun/star/ucb/AlreadyInitializedException.hpp> 33 #include <com/sun/star/lang/IllegalArgumentException.hpp> 34 #include <com/sun/star/awt/XVclWindowPeer.hpp> 35 /** === end UNO includes === **/ 36 37 #include <toolkit/helper/vclunohelper.hxx> 38 #include <vcl/window.hxx> 39 #include <tools/diagnose_ex.h> 40 41 //------------------------------------------------------------------------ 42 extern "C" void SAL_CALL createRegistryInfo_DefaultHelpProvider() 43 { 44 ::pcr::OAutoRegistration< ::pcr::DefaultHelpProvider > aAutoRegistration; 45 } 46 47 //........................................................................ 48 namespace pcr 49 { 50 //........................................................................ 51 52 /** === begin UNO using === **/ 53 using ::com::sun::star::uno::Reference; 54 using ::com::sun::star::uno::XComponentContext; 55 using ::com::sun::star::inspection::XPropertyControl; 56 using ::com::sun::star::uno::RuntimeException; 57 using ::com::sun::star::uno::Sequence; 58 using ::com::sun::star::uno::Any; 59 using ::com::sun::star::uno::Exception; 60 using ::com::sun::star::inspection::XObjectInspectorUI; 61 using ::com::sun::star::uno::XInterface; 62 using ::com::sun::star::ucb::AlreadyInitializedException; 63 using ::com::sun::star::lang::IllegalArgumentException; 64 using ::com::sun::star::uno::UNO_QUERY; 65 using ::com::sun::star::uno::UNO_QUERY_THROW; 66 using ::com::sun::star::awt::XWindow; 67 using ::com::sun::star::awt::XVclWindowPeer; 68 /** === end UNO using === **/ 69 70 //==================================================================== 71 //= DefaultHelpProvider 72 //==================================================================== 73 //-------------------------------------------------------------------- 74 DefaultHelpProvider::DefaultHelpProvider( const Reference< XComponentContext >& _rxContext ) 75 :m_aContext( _rxContext ) 76 ,m_bConstructed( false ) 77 { 78 } 79 80 //-------------------------------------------------------------------- 81 DefaultHelpProvider::~DefaultHelpProvider() 82 { 83 } 84 85 //------------------------------------------------------------------------ 86 ::rtl::OUString DefaultHelpProvider::getImplementationName_static( ) throw(RuntimeException) 87 { 88 return ::rtl::OUString::createFromAscii( "org.openoffice.comp.extensions.DefaultHelpProvider"); 89 } 90 91 //------------------------------------------------------------------------ 92 Sequence< ::rtl::OUString > DefaultHelpProvider::getSupportedServiceNames_static( ) throw(RuntimeException) 93 { 94 Sequence< ::rtl::OUString > aSupported(1); 95 aSupported[0] = ::rtl::OUString::createFromAscii( "com.sun.star.inspection.DefaultHelpProvider" ); 96 return aSupported; 97 } 98 99 //------------------------------------------------------------------------ 100 Reference< XInterface > SAL_CALL DefaultHelpProvider::Create( const Reference< XComponentContext >& _rxContext ) 101 { 102 return *new DefaultHelpProvider( _rxContext ); 103 } 104 105 //-------------------------------------------------------------------- 106 void SAL_CALL DefaultHelpProvider::focusGained( const Reference< XPropertyControl >& _Control ) throw (RuntimeException) 107 { 108 if ( !m_xInspectorUI.is() ) 109 throw RuntimeException( ::rtl::OUString(), *this ); 110 111 try 112 { 113 m_xInspectorUI->setHelpSectionText( impl_getHelpText_nothrow( _Control ) ); 114 } 115 catch( const Exception& ) 116 { 117 DBG_UNHANDLED_EXCEPTION(); 118 } 119 } 120 121 //-------------------------------------------------------------------- 122 void SAL_CALL DefaultHelpProvider::valueChanged( const Reference< XPropertyControl >& /*_Control*/ ) throw (RuntimeException) 123 { 124 // not interested in 125 } 126 127 //-------------------------------------------------------------------- 128 void SAL_CALL DefaultHelpProvider::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException) 129 { 130 if ( m_bConstructed ) 131 throw AlreadyInitializedException(); 132 133 StlSyntaxSequence< Any > arguments( _arguments ); 134 if ( arguments.size() == 1 ) 135 { // constructor: "create( XObjectInspectorUI )" 136 Reference< XObjectInspectorUI > xUI( arguments[0], UNO_QUERY ); 137 create( xUI ); 138 return; 139 } 140 141 throw IllegalArgumentException( ::rtl::OUString(), *this, 0 ); 142 } 143 144 //-------------------------------------------------------------------- 145 void DefaultHelpProvider::create( const Reference< XObjectInspectorUI >& _rxUI ) 146 { 147 if ( !_rxUI.is() ) 148 throw IllegalArgumentException( ::rtl::OUString(), *this, 1 ); 149 150 try 151 { 152 m_xInspectorUI = _rxUI; 153 m_xInspectorUI->registerControlObserver( this ); 154 } 155 catch( const Exception& ) 156 { 157 DBG_UNHANDLED_EXCEPTION(); 158 } 159 160 m_bConstructed = true; 161 } 162 163 //-------------------------------------------------------------------- 164 Window* DefaultHelpProvider::impl_getVclControlWindow_nothrow( const Reference< XPropertyControl >& _rxControl ) 165 { 166 Window* pControlWindow = NULL; 167 OSL_PRECOND( _rxControl.is(), "DefaultHelpProvider::impl_getVclControlWindow_nothrow: illegal control!" ); 168 if ( !_rxControl.is() ) 169 return pControlWindow; 170 171 try 172 { 173 Reference< XWindow > xControlWindow( _rxControl->getControlWindow(), UNO_QUERY_THROW ); 174 pControlWindow = VCLUnoHelper::GetWindow( xControlWindow ); 175 } 176 catch( const Exception& ) 177 { 178 DBG_UNHANDLED_EXCEPTION(); 179 } 180 181 return pControlWindow; 182 } 183 184 //-------------------------------------------------------------------- 185 ::rtl::OUString DefaultHelpProvider::impl_getHelpText_nothrow( const Reference< XPropertyControl >& _rxControl ) 186 { 187 ::rtl::OUString sHelpText; 188 OSL_PRECOND( _rxControl.is(), "DefaultHelpProvider::impl_getHelpText_nothrow: illegal control!" ); 189 if ( !_rxControl.is() ) 190 return sHelpText; 191 192 Window* pControlWindow( impl_getVclControlWindow_nothrow( _rxControl ) ); 193 OSL_ENSURE( pControlWindow, "DefaultHelpProvider::impl_getHelpText_nothrow: could not determine the VCL window!" ); 194 if ( !pControlWindow ) 195 return sHelpText; 196 197 sHelpText = pControlWindow->GetHelpText(); 198 return sHelpText; 199 } 200 //........................................................................ 201 } // namespace pcr 202 //........................................................................ 203