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