LibreOffice Module extensions (master) 1
defaulthelpprovider.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
22#include "pcrcommon.hxx"
23
24#include <com/sun/star/ucb/AlreadyInitializedException.hpp>
25#include <com/sun/star/lang/IllegalArgumentException.hpp>
26#include <com/sun/star/uno/XComponentContext.hpp>
27
29#include <vcl/window.hxx>
32
33
34namespace pcr
35{
36
37
38 using ::com::sun::star::uno::Reference;
39 using ::com::sun::star::uno::XComponentContext;
40 using ::com::sun::star::inspection::XPropertyControl;
41 using ::com::sun::star::uno::RuntimeException;
42 using ::com::sun::star::uno::Sequence;
43 using ::com::sun::star::uno::Any;
44 using ::com::sun::star::uno::Exception;
45 using ::com::sun::star::inspection::XObjectInspectorUI;
46 using ::com::sun::star::uno::XInterface;
47 using ::com::sun::star::ucb::AlreadyInitializedException;
48 using ::com::sun::star::lang::IllegalArgumentException;
49 using ::com::sun::star::uno::UNO_QUERY;
50 using ::com::sun::star::awt::XWindow;
51
53 :m_bConstructed( false )
54 {
55 }
56
57
59 {
60 }
61
62
63 Sequence< OUString > SAL_CALL DefaultHelpProvider::getSupportedServiceNames()
64 {
65 return { "com.sun.star.inspection.DefaultHelpProvider" };
66 }
67
69 {
70 return "org.openoffice.comp.extensions.DefaultHelpProvider";
71 }
72
73 sal_Bool SAL_CALL DefaultHelpProvider::supportsService(const OUString& aServiceName)
74 {
75 return cppu::supportsService(this, aServiceName);
76 }
77
78
79 void SAL_CALL DefaultHelpProvider::focusGained( const Reference< XPropertyControl >& Control )
80 {
81 if ( !m_xInspectorUI.is() )
82 throw RuntimeException( OUString(), *this );
83
84 try
85 {
86 m_xInspectorUI->setHelpSectionText( impl_getHelpText_nothrow( Control ) );
87 }
88 catch( const Exception& )
89 {
90 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr");
91 }
92 }
93
94
95 void SAL_CALL DefaultHelpProvider::valueChanged( const Reference< XPropertyControl >& )
96 {
97 // not interested in
98 }
99
100
101 void SAL_CALL DefaultHelpProvider::initialize( const Sequence< Any >& _arguments )
102 {
103 if ( m_bConstructed )
104 throw AlreadyInitializedException();
105
106 StlSyntaxSequence< Any > arguments( _arguments );
107 if ( arguments.size() == 1 )
108 { // constructor: "create( XObjectInspectorUI )"
109 Reference< XObjectInspectorUI > xUI( arguments[0], UNO_QUERY );
110 create( xUI );
111 return;
112 }
113
114 throw IllegalArgumentException( OUString(), *this, 0 );
115 }
116
117
118 void DefaultHelpProvider::create( const Reference< XObjectInspectorUI >& _rxUI )
119 {
120 if ( !_rxUI.is() )
121 throw IllegalArgumentException( OUString(), *this, 1 );
122
123 try
124 {
125 m_xInspectorUI = _rxUI;
126 m_xInspectorUI->registerControlObserver( this );
127 }
128 catch( const Exception& )
129 {
130 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr");
131 }
132
133 m_bConstructed = true;
134 }
135
136
137 vcl::Window* DefaultHelpProvider::impl_getVclControlWindow_nothrow( const Reference< XPropertyControl >& _rxControl )
138 {
139 vcl::Window* pControlWindow = nullptr;
140 OSL_PRECOND( _rxControl.is(), "DefaultHelpProvider::impl_getVclControlWindow_nothrow: illegal control!" );
141 if ( !_rxControl.is() )
142 return pControlWindow;
143
144 try
145 {
146 Reference< XWindow > xControlWindow( _rxControl->getControlWindow(), css::uno::UNO_SET_THROW );
147 pControlWindow = VCLUnoHelper::GetWindow( xControlWindow );
148 }
149 catch( const Exception& )
150 {
151 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr");
152 }
153
154 return pControlWindow;
155 }
156
157
158 OUString DefaultHelpProvider::impl_getHelpText_nothrow( const Reference< XPropertyControl >& _rxControl )
159 {
160 OUString sHelpText;
161 OSL_PRECOND( _rxControl.is(), "DefaultHelpProvider::impl_getHelpText_nothrow: illegal control!" );
162 if ( !_rxControl.is() )
163 return sHelpText;
164
165 vcl::Window* pControlWindow( impl_getVclControlWindow_nothrow( _rxControl ) );
166 OSL_ENSURE( pControlWindow, "DefaultHelpProvider::impl_getHelpText_nothrow: could not determine the VCL window!" );
167 if ( !pControlWindow )
168 return sHelpText;
169
170 sHelpText = pControlWindow->GetHelpText();
171 return sHelpText;
172 }
173
174} // namespace pcr
175
176extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
178 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
179{
180 return cppu::acquire(new pcr::DefaultHelpProvider());
181}
182
183/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
static vcl::Window * impl_getVclControlWindow_nothrow(const css::uno::Reference< css::inspection::XPropertyControl > &_rxControl)
virtual void SAL_CALL focusGained(const css::uno::Reference< css::inspection::XPropertyControl > &Control) override
virtual OUString SAL_CALL getImplementationName() override
void create(const css::uno::Reference< css::inspection::XObjectInspectorUI > &_rxUI)
virtual ~DefaultHelpProvider() override
virtual void SAL_CALL valueChanged(const css::uno::Reference< css::inspection::XPropertyControl > &Control) override
css::uno::Reference< css::inspection::XObjectInspectorUI > m_xInspectorUI
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
static OUString impl_getHelpText_nothrow(const css::uno::Reference< css::inspection::XPropertyControl > &_rxControl)
sal_Int32 size() const
Definition: pcrcommon.hxx:93
const OUString & GetHelpText() const
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * extensions_propctrlr_DefaultHelpProvider_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
#define DBG_UNHANDLED_EXCEPTION(...)
@ Exception
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
a property handler for any virtual string properties
Definition: browserline.cxx:39
unsigned char sal_Bool