1 /*************************************************************************
2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3  *
4  * Copyright 2000, 2010 Oracle and/or its affiliates.
5  *
6  * OpenOffice.org - a multi-platform office productivity suite
7  *
8  * This file is part of OpenOffice.org.
9  *
10  * OpenOffice.org is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License version 3
12  * only, as published by the Free Software Foundation.
13  *
14  * OpenOffice.org is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License version 3 for more details
18  * (a copy is included in the LICENSE file that accompanied this code).
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with OpenOffice.org.  If not, see
22  * <http://www.openoffice.org/license.html>
23  * for a copy of the LGPLv3 License.
24  *
25 ************************************************************************/
26 
27 // MARKER(update_precomp.py): autogen include statement, do not remove
28 #include "precompiled_extensions.hxx"
29 
30 #ifndef EXTENSIONS_PROPERTYCONTROLEXTENDER_HXX
31 #include "propertycontrolextender.hxx"
32 #endif
33 
34 /** === begin UNO includes === **/
35 #include <com/sun/star/awt/KeyFunction.hpp>
36 /** === end UNO includes === **/
37 
38 #include <tools/diagnose_ex.h>
39 
40 //........................................................................
41 namespace pcr
42 {
43 //........................................................................
44 
45 	/** === begin UNO using === **/
46 	using ::com::sun::star::uno::Reference;
47 	using ::com::sun::star::uno::XInterface;
48 	using ::com::sun::star::uno::UNO_QUERY;
49 	using ::com::sun::star::uno::UNO_QUERY_THROW;
50 	using ::com::sun::star::uno::UNO_SET_THROW;
51 	using ::com::sun::star::uno::Exception;
52 	using ::com::sun::star::uno::RuntimeException;
53 	using ::com::sun::star::uno::Any;
54 	using ::com::sun::star::uno::makeAny;
55 	using ::com::sun::star::uno::Sequence;
56 	using ::com::sun::star::uno::Type;
57     using ::com::sun::star::awt::XWindow;
58     using ::com::sun::star::awt::KeyEvent;
59     using ::com::sun::star::inspection::XPropertyControl;
60     using ::com::sun::star::lang::EventObject;
61     using ::com::sun::star::inspection::XPropertyControlContext;
62 	/** === end UNO using === **/
63     namespace KeyFunction = ::com::sun::star::awt::KeyFunction;
64 
65 	//====================================================================
66 	//= PropertyControlExtender_Data
67 	//====================================================================
68     struct PropertyControlExtender_Data
69     {
70         Reference< XPropertyControl >   xControl;
71         Reference< XWindow >            xControlWindow;
72     };
73 
74 	//====================================================================
75 	//= PropertyControlExtender
76 	//====================================================================
77 	//--------------------------------------------------------------------
78     PropertyControlExtender::PropertyControlExtender( const Reference< XPropertyControl >& _rxObservedControl )
79         :m_pData( new PropertyControlExtender_Data )
80     {
81         try
82         {
83             m_pData->xControl.set( _rxObservedControl, UNO_SET_THROW );
84             m_pData->xControlWindow.set( m_pData->xControl->getControlWindow(), UNO_SET_THROW );
85             m_pData->xControlWindow->addKeyListener( this );
86         }
87         catch( const Exception& )
88         {
89         	DBG_UNHANDLED_EXCEPTION();
90         }
91     }
92 
93     //--------------------------------------------------------------------
94     PropertyControlExtender::~PropertyControlExtender()
95     {
96     }
97 
98     //--------------------------------------------------------------------
99     void SAL_CALL PropertyControlExtender::keyPressed( const KeyEvent& _event ) throw (RuntimeException)
100     {
101         OSL_ENSURE( _event.Source == m_pData->xControlWindow, "PropertyControlExtender::keyPressed: where does this come from?" );
102         if  (   ( _event.KeyFunc == KeyFunction::DELETE )
103             &&  ( _event.Modifiers == 0 )
104             )
105         {
106             try
107             {
108                 Reference< XPropertyControl > xControl( m_pData->xControl, UNO_SET_THROW );
109 
110                 // reset the value
111                 xControl->setValue( Any() );
112 
113                 // and notify the change
114                 // don't use XPropertyControl::notifyModifiedValue. It only notifies when the control content
115                 // is recognized as being modified by the user, which is not the case, since we just modified
116                 // it programmatically.
117                 Reference< XPropertyControlContext > xControlContext( xControl->getControlContext(), UNO_SET_THROW );
118                 xControlContext->valueChanged( xControl );
119             }
120             catch( const Exception& )
121             {
122             	DBG_UNHANDLED_EXCEPTION();
123             }
124         }
125     }
126 
127     //--------------------------------------------------------------------
128     void SAL_CALL PropertyControlExtender::keyReleased( const KeyEvent& /*_event*/ ) throw (RuntimeException)
129     {
130         // not interested in
131     }
132 
133     //--------------------------------------------------------------------
134     void SAL_CALL PropertyControlExtender::disposing( const EventObject& Source ) throw (RuntimeException)
135     {
136         OSL_ENSURE( Source.Source == m_pData->xControlWindow, "PropertyControlExtender::disposing: where does this come from?" );
137         (void)Source.Source;
138         m_pData->xControlWindow.clear();
139         m_pData->xControl.clear();
140     }
141 
142 
143 //........................................................................
144 } // namespace pcr
145 //........................................................................
146