1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 #include "propertycontrolextender.hxx"
31 /** === begin UNO includes === **/
32 #include <com/sun/star/awt/KeyFunction.hpp>
33 /** === end UNO includes === **/
35 #include <tools/diagnose_ex.h>
37 //........................................................................
40 //........................................................................
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
;
62 //====================================================================
63 //= PropertyControlExtender_Data
64 //====================================================================
65 struct PropertyControlExtender_Data
67 Reference
< XPropertyControl
> xControl
;
68 Reference
< XWindow
> xControlWindow
;
71 //====================================================================
72 //= PropertyControlExtender
73 //====================================================================
74 //--------------------------------------------------------------------
75 PropertyControlExtender::PropertyControlExtender( const Reference
< XPropertyControl
>& _rxObservedControl
)
76 :m_pData( new PropertyControlExtender_Data
)
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 );
84 catch( const Exception
& )
86 DBG_UNHANDLED_EXCEPTION();
90 //--------------------------------------------------------------------
91 PropertyControlExtender::~PropertyControlExtender()
95 //--------------------------------------------------------------------
96 void SAL_CALL
PropertyControlExtender::keyPressed( const KeyEvent
& _event
) throw (RuntimeException
)
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 )
105 Reference
< XPropertyControl
> xControl( m_pData
->xControl
, UNO_SET_THROW
);
108 xControl
->setValue( Any() );
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
);
117 catch( const Exception
& )
119 DBG_UNHANDLED_EXCEPTION();
124 //--------------------------------------------------------------------
125 void SAL_CALL
PropertyControlExtender::keyReleased( const KeyEvent
& /*_event*/ ) throw (RuntimeException
)
130 //--------------------------------------------------------------------
131 void SAL_CALL
PropertyControlExtender::disposing( const EventObject
& Source
) throw (RuntimeException
)
133 OSL_ENSURE( Source
.Source
== m_pData
->xControlWindow
, "PropertyControlExtender::disposing: where does this come from?" );
135 m_pData
->xControlWindow
.clear();
136 m_pData
->xControl
.clear();
140 //........................................................................
142 //........................................................................
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */