1 /*************************************************************************
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * Copyright 2000, 2010 Oracle and/or its affiliates.
6 * OpenOffice.org - a multi-platform office productivity suite
8 * This file is part of OpenOffice.org.
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.
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).
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.
25 ************************************************************************/
27 // MARKER(update_precomp.py): autogen include statement, do not remove
28 #include "precompiled_extensions.hxx"
30 #ifndef EXTENSIONS_PROPERTYCONTROLEXTENDER_HXX
31 #include "propertycontrolextender.hxx"
34 /** === begin UNO includes === **/
35 #include <com/sun/star/awt/KeyFunction.hpp>
36 /** === end UNO includes === **/
38 #include <tools/diagnose_ex.h>
40 //........................................................................
43 //........................................................................
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
;
65 //====================================================================
66 //= PropertyControlExtender_Data
67 //====================================================================
68 struct PropertyControlExtender_Data
70 Reference
< XPropertyControl
> xControl
;
71 Reference
< XWindow
> xControlWindow
;
74 //====================================================================
75 //= PropertyControlExtender
76 //====================================================================
77 //--------------------------------------------------------------------
78 PropertyControlExtender::PropertyControlExtender( const Reference
< XPropertyControl
>& _rxObservedControl
)
79 :m_pData( new PropertyControlExtender_Data
)
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 );
87 catch( const Exception
& )
89 DBG_UNHANDLED_EXCEPTION();
93 //--------------------------------------------------------------------
94 PropertyControlExtender::~PropertyControlExtender()
98 //--------------------------------------------------------------------
99 void SAL_CALL
PropertyControlExtender::keyPressed( const KeyEvent
& _event
) throw (RuntimeException
)
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 )
108 Reference
< XPropertyControl
> xControl( m_pData
->xControl
, UNO_SET_THROW
);
111 xControl
->setValue( Any() );
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
);
120 catch( const Exception
& )
122 DBG_UNHANDLED_EXCEPTION();
127 //--------------------------------------------------------------------
128 void SAL_CALL
PropertyControlExtender::keyReleased( const KeyEvent
& /*_event*/ ) throw (RuntimeException
)
133 //--------------------------------------------------------------------
134 void SAL_CALL
PropertyControlExtender::disposing( const EventObject
& Source
) throw (RuntimeException
)
136 OSL_ENSURE( Source
.Source
== m_pData
->xControlWindow
, "PropertyControlExtender::disposing: where does this come from?" );
138 m_pData
->xControlWindow
.clear();
139 m_pData
->xControl
.clear();
143 //........................................................................
145 //........................................................................