1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_extensions.hxx"
26 
27 #ifndef EXTENSIONS_PROPERTYCONTROLEXTENDER_HXX
28 #include "propertycontrolextender.hxx"
29 #endif
30 
31 /** === begin UNO includes === **/
32 #include <com/sun/star/awt/KeyFunction.hpp>
33 /** === end UNO includes === **/
34 
35 #include <tools/diagnose_ex.h>
36 
37 //........................................................................
38 namespace pcr
39 {
40 //........................................................................
41 
42 	/** === begin UNO using === **/
43 	using ::com::sun::star::uno::Reference;
44 	using ::com::sun::star::uno::XInterface;
45 	using ::com::sun::star::uno::UNO_QUERY;
46 	using ::com::sun::star::uno::UNO_QUERY_THROW;
47 	using ::com::sun::star::uno::UNO_SET_THROW;
48 	using ::com::sun::star::uno::Exception;
49 	using ::com::sun::star::uno::RuntimeException;
50 	using ::com::sun::star::uno::Any;
51 	using ::com::sun::star::uno::makeAny;
52 	using ::com::sun::star::uno::Sequence;
53 	using ::com::sun::star::uno::Type;
54     using ::com::sun::star::awt::XWindow;
55     using ::com::sun::star::awt::KeyEvent;
56     using ::com::sun::star::inspection::XPropertyControl;
57     using ::com::sun::star::lang::EventObject;
58     using ::com::sun::star::inspection::XPropertyControlContext;
59 	/** === end UNO using === **/
60     namespace KeyFunction = ::com::sun::star::awt::KeyFunction;
61 
62 	//====================================================================
63 	//= PropertyControlExtender_Data
64 	//====================================================================
65     struct PropertyControlExtender_Data
66     {
67         Reference< XPropertyControl >   xControl;
68         Reference< XWindow >            xControlWindow;
69     };
70 
71 	//====================================================================
72 	//= PropertyControlExtender
73 	//====================================================================
74 	//--------------------------------------------------------------------
PropertyControlExtender(const Reference<XPropertyControl> & _rxObservedControl)75     PropertyControlExtender::PropertyControlExtender( const Reference< XPropertyControl >& _rxObservedControl )
76         :m_pData( new PropertyControlExtender_Data )
77     {
78         try
79         {
80             m_pData->xControl.set( _rxObservedControl, UNO_SET_THROW );
81             m_pData->xControlWindow.set( m_pData->xControl->getControlWindow(), UNO_SET_THROW );
82             m_pData->xControlWindow->addKeyListener( this );
83         }
84         catch( const Exception& )
85         {
86         	DBG_UNHANDLED_EXCEPTION();
87         }
88     }
89 
90     //--------------------------------------------------------------------
~PropertyControlExtender()91     PropertyControlExtender::~PropertyControlExtender()
92     {
93     }
94 
95     //--------------------------------------------------------------------
keyPressed(const KeyEvent & _event)96     void SAL_CALL PropertyControlExtender::keyPressed( const KeyEvent& _event ) throw (RuntimeException)
97     {
98         OSL_ENSURE( _event.Source == m_pData->xControlWindow, "PropertyControlExtender::keyPressed: where does this come from?" );
99         if  (   ( _event.KeyFunc == KeyFunction::DELETE )
100             &&  ( _event.Modifiers == 0 )
101             )
102         {
103             try
104             {
105                 Reference< XPropertyControl > xControl( m_pData->xControl, UNO_SET_THROW );
106 
107                 // reset the value
108                 xControl->setValue( Any() );
109 
110                 // and notify the change
111                 // don't use XPropertyControl::notifyModifiedValue. It only notifies when the control content
112                 // is recognized as being modified by the user, which is not the case, since we just modified
113                 // it programmatically.
114                 Reference< XPropertyControlContext > xControlContext( xControl->getControlContext(), UNO_SET_THROW );
115                 xControlContext->valueChanged( xControl );
116             }
117             catch( const Exception& )
118             {
119             	DBG_UNHANDLED_EXCEPTION();
120             }
121         }
122     }
123 
124     //--------------------------------------------------------------------
keyReleased(const KeyEvent &)125     void SAL_CALL PropertyControlExtender::keyReleased( const KeyEvent& /*_event*/ ) throw (RuntimeException)
126     {
127         // not interested in
128     }
129 
130     //--------------------------------------------------------------------
disposing(const EventObject & Source)131     void SAL_CALL PropertyControlExtender::disposing( const EventObject& Source ) throw (RuntimeException)
132     {
133         OSL_ENSURE( Source.Source == m_pData->xControlWindow, "PropertyControlExtender::disposing: where does this come from?" );
134         (void)Source.Source;
135         m_pData->xControlWindow.clear();
136         m_pData->xControl.clear();
137     }
138 
139 
140 //........................................................................
141 } // namespace pcr
142 //........................................................................
143