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