LibreOffice Module extensions (master) 1
propertycontrolextender.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
23#include <com/sun/star/awt/KeyFunction.hpp>
24
26
27
28namespace pcr
29{
30
31
32 using ::com::sun::star::uno::Reference;
33 using ::com::sun::star::uno::UNO_SET_THROW;
34 using ::com::sun::star::uno::Exception;
35 using ::com::sun::star::uno::Any;
36 using ::com::sun::star::awt::KeyEvent;
37 using ::com::sun::star::inspection::XPropertyControl;
38 using ::com::sun::star::lang::EventObject;
39 using ::com::sun::star::inspection::XPropertyControlContext;
40
41 namespace KeyFunction = ::com::sun::star::awt::KeyFunction;
42
43
44 //= PropertyControlExtender
45
46
47 PropertyControlExtender::PropertyControlExtender( const Reference< XPropertyControl >& _rxObservedControl )
48 {
49 try
50 {
51 mxControl.set( _rxObservedControl, UNO_SET_THROW );
52 mxControlWindow.set( mxControl->getControlWindow(), UNO_SET_THROW );
53 mxControlWindow->addKeyListener( this );
54 }
55 catch( const Exception& )
56 {
57 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr");
58 }
59 }
60
61
63 {
64 }
65
66
67 void SAL_CALL PropertyControlExtender::keyPressed( const KeyEvent& _event )
68 {
69 OSL_ENSURE( _event.Source == mxControlWindow, "PropertyControlExtender::keyPressed: where does this come from?" );
70 if ( ( _event.KeyFunc != KeyFunction::DELETE )
71 || ( _event.Modifiers != 0 )
72 )
73 return;
74
75 try
76 {
77 Reference< XPropertyControl > xControl( mxControl, UNO_SET_THROW );
78
79 // reset the value
80 xControl->setValue( Any() );
81
82 // and notify the change
83 // don't use XPropertyControl::notifyModifiedValue. It only notifies when the control content
84 // is recognized as being modified by the user, which is not the case, since we just modified
85 // it programmatically.
86 Reference< XPropertyControlContext > xControlContext( xControl->getControlContext(), UNO_SET_THROW );
87 xControlContext->valueChanged( xControl );
88 }
89 catch( const Exception& )
90 {
91 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr");
92 }
93 }
94
95
96 void SAL_CALL PropertyControlExtender::keyReleased( const KeyEvent& /*_event*/ )
97 {
98 // not interested in
99 }
100
101
102 void SAL_CALL PropertyControlExtender::disposing( const EventObject& Source )
103 {
104 OSL_ENSURE( Source.Source == mxControlWindow, "PropertyControlExtender::disposing: where does this come from?" );
105 (void)Source.Source;
106 mxControlWindow.clear();
107 mxControl.clear();
108 }
109
110
111} // namespace pcr
112
113
114/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::awt::XWindow > mxControlWindow
css::uno::Reference< css::inspection::XPropertyControl > mxControl
virtual void SAL_CALL keyPressed(const css::awt::KeyEvent &e) override
PropertyControlExtender(const css::uno::Reference< css::inspection::XPropertyControl > &_rxObservedControl)
virtual void SAL_CALL keyReleased(const css::awt::KeyEvent &e) override
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
#define DBG_UNHANDLED_EXCEPTION(...)
@ Exception
a property handler for any virtual string properties
Definition: browserline.cxx:39