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