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