Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / extensions / source / propctrlr / propertycontrolextender.cxx
blobc48c7675164fd32138d46df6b4deb5bfa55d8f97
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "propertycontrolextender.hxx"
23 #include <com/sun/star/awt/KeyFunction.hpp>
25 #include <tools/diagnose_ex.h>
28 namespace pcr
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::RuntimeException;
36 using ::com::sun::star::uno::Any;
37 using ::com::sun::star::awt::XWindow;
38 using ::com::sun::star::awt::KeyEvent;
39 using ::com::sun::star::inspection::XPropertyControl;
40 using ::com::sun::star::lang::EventObject;
41 using ::com::sun::star::inspection::XPropertyControlContext;
43 namespace KeyFunction = ::com::sun::star::awt::KeyFunction;
46 //= PropertyControlExtender_Data
48 struct PropertyControlExtender_Data
50 Reference< XPropertyControl > xControl;
51 Reference< XWindow > xControlWindow;
55 //= PropertyControlExtender
58 PropertyControlExtender::PropertyControlExtender( const Reference< XPropertyControl >& _rxObservedControl )
59 :m_pData( new PropertyControlExtender_Data )
61 try
63 m_pData->xControl.set( _rxObservedControl, UNO_SET_THROW );
64 m_pData->xControlWindow.set( m_pData->xControl->getControlWindow(), UNO_SET_THROW );
65 m_pData->xControlWindow->addKeyListener( this );
67 catch( const Exception& )
69 DBG_UNHANDLED_EXCEPTION();
74 PropertyControlExtender::~PropertyControlExtender()
79 void SAL_CALL PropertyControlExtender::keyPressed( const KeyEvent& _event )
81 OSL_ENSURE( _event.Source == m_pData->xControlWindow, "PropertyControlExtender::keyPressed: where does this come from?" );
82 if ( ( _event.KeyFunc == KeyFunction::DELETE )
83 && ( _event.Modifiers == 0 )
86 try
88 Reference< XPropertyControl > xControl( m_pData->xControl, UNO_SET_THROW );
90 // reset the value
91 xControl->setValue( Any() );
93 // and notify the change
94 // don't use XPropertyControl::notifyModifiedValue. It only notifies when the control content
95 // is recognized as being modified by the user, which is not the case, since we just modified
96 // it programmatically.
97 Reference< XPropertyControlContext > xControlContext( xControl->getControlContext(), UNO_SET_THROW );
98 xControlContext->valueChanged( xControl );
100 catch( const Exception& )
102 DBG_UNHANDLED_EXCEPTION();
108 void SAL_CALL PropertyControlExtender::keyReleased( const KeyEvent& /*_event*/ )
110 // not interested in
114 void SAL_CALL PropertyControlExtender::disposing( const EventObject& Source )
116 OSL_ENSURE( Source.Source == m_pData->xControlWindow, "PropertyControlExtender::disposing: where does this come from?" );
117 (void)Source.Source;
118 m_pData->xControlWindow.clear();
119 m_pData->xControl.clear();
123 } // namespace pcr
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */