1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: edittoolbarcontroller.cxx,v $
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.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 #ifndef __FRAMEWORK_UIELEMENT_EDITTOOLBARCONTROLLER_HXX
35 #include "uielement/edittoolbarcontroller.hxx"
38 //_________________________________________________________________________________________________________________
40 //_________________________________________________________________________________________________________________
42 #ifndef __FRAMEWORK_TOOLBAR_HXX_
43 #include "uielement/toolbar.hxx"
46 //_________________________________________________________________________________________________________________
48 //_________________________________________________________________________________________________________________
49 #include <com/sun/star/util/XURLTransformer.hpp>
50 #include <com/sun/star/frame/XDispatchProvider.hpp>
51 #include <com/sun/star/beans/PropertyValue.hpp>
52 #include <com/sun/star/lang/DisposedException.hpp>
53 #include <com/sun/star/frame/status/ItemStatus.hpp>
54 #include <com/sun/star/frame/status/ItemState.hpp>
55 #include <com/sun/star/frame/status/Visibility.hpp>
56 #include <com/sun/star/frame/XControlNotificationListener.hpp>
58 //_________________________________________________________________________________________________________________
60 //_________________________________________________________________________________________________________________
61 #include <svtools/toolboxcontroller.hxx>
62 #include <vos/mutex.hxx>
63 #include <vcl/svapp.hxx>
64 #ifndef _VCL_MNEMONIC_HXX_
65 #include <vcl/mnemonic.hxx>
67 #include <tools/urlobj.hxx>
69 using namespace ::com::sun::star
;
70 using namespace ::com::sun::star::uno
;
71 using namespace ::com::sun::star::beans
;
72 using namespace ::com::sun::star::lang
;
73 using namespace ::com::sun::star::frame
;
74 using namespace ::com::sun::star::frame::status
;
75 using namespace ::com::sun::star::util
;
80 // ------------------------------------------------------------------
82 // Wrapper class to notify controller about events from edit.
83 // Unfortunaltly the events are notifed through virtual methods instead
86 class EditControl
: public Edit
89 EditControl( Window
* pParent
, WinBits nStyle
, IEditListener
* pEditListener
);
90 virtual ~EditControl();
92 virtual void Modify();
93 virtual void KeyInput( const ::KeyEvent
& rKEvt
);
94 virtual void GetFocus();
95 virtual void LoseFocus();
96 virtual long PreNotify( NotifyEvent
& rNEvt
);
99 IEditListener
* m_pEditListener
;
102 EditControl::EditControl( Window
* pParent
, WinBits nStyle
, IEditListener
* pEditListener
) :
103 Edit( pParent
, nStyle
)
104 , m_pEditListener( pEditListener
)
108 EditControl::~EditControl()
113 void EditControl::Modify()
116 if ( m_pEditListener
)
117 m_pEditListener
->Modify();
120 void EditControl::KeyInput( const ::KeyEvent
& rKEvt
)
122 Edit::KeyInput( rKEvt
);
123 if ( m_pEditListener
)
124 m_pEditListener
->KeyInput( rKEvt
);
127 void EditControl::GetFocus()
130 if ( m_pEditListener
)
131 m_pEditListener
->GetFocus();
134 void EditControl::LoseFocus()
137 if ( m_pEditListener
)
138 m_pEditListener
->LoseFocus();
141 long EditControl::PreNotify( NotifyEvent
& rNEvt
)
144 if ( m_pEditListener
)
145 nRet
= m_pEditListener
->PreNotify( rNEvt
);
147 nRet
= Edit::PreNotify( rNEvt
);
152 // ------------------------------------------------------------------
154 EditToolbarController::EditToolbarController(
155 const Reference
< XMultiServiceFactory
>& rServiceManager
,
156 const Reference
< XFrame
>& rFrame
,
160 const ::rtl::OUString
& aCommand
) :
161 ComplexToolbarController( rServiceManager
, rFrame
, pToolbar
, nID
, aCommand
)
162 , m_pEditControl( 0 )
164 m_pEditControl
= new EditControl( m_pToolbar
, WB_BORDER
, this );
168 // Calculate height of the edit field according to the application font height
169 sal_Int32 nHeight
= getFontSizePixel( m_pEditControl
) + 6 + 1;
171 m_pEditControl
->SetSizePixel( ::Size( nWidth
, nHeight
));
172 m_pToolbar
->SetItemWindow( m_nID
, m_pEditControl
);
175 // ------------------------------------------------------------------
177 EditToolbarController::~EditToolbarController()
181 // ------------------------------------------------------------------
183 void SAL_CALL
EditToolbarController::dispose()
184 throw ( RuntimeException
)
186 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
188 m_pToolbar
->SetItemWindow( m_nID
, 0 );
189 delete m_pEditControl
;
191 ComplexToolbarController::dispose();
196 // ------------------------------------------------------------------
197 Sequence
<PropertyValue
> EditToolbarController::getExecuteArgs(sal_Int16 KeyModifier
) const
199 Sequence
<PropertyValue
> aArgs( 2 );
200 ::rtl::OUString aSelectedText
= m_pEditControl
->GetText();
202 // Add key modifier to argument list
203 aArgs
[0].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "KeyModifier" ));
204 aArgs
[0].Value
<<= KeyModifier
;
205 aArgs
[1].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ));
206 aArgs
[1].Value
<<= aSelectedText
;
210 // ------------------------------------------------------------------
212 void EditToolbarController::Modify()
214 notifyTextChanged( m_pEditControl
->GetText() );
217 void EditToolbarController::KeyInput( const ::KeyEvent
& /*rKEvt*/ )
221 void EditToolbarController::GetFocus()
226 void EditToolbarController::LoseFocus()
231 long EditToolbarController::PreNotify( NotifyEvent
& rNEvt
)
233 if( rNEvt
.GetType() == EVENT_KEYINPUT
)
235 const ::KeyEvent
* pKeyEvent
= rNEvt
.GetKeyEvent();
236 const KeyCode
& rKeyCode
= pKeyEvent
->GetKeyCode();
237 if(( rKeyCode
.GetModifier() | rKeyCode
.GetCode()) == KEY_RETURN
)
239 // Call execute only with non-empty text
240 if ( m_pEditControl
->GetText().Len() > 0 )
241 execute( rKeyCode
.GetModifier() );
249 // --------------------------------------------------------
251 void EditToolbarController::executeControlCommand( const ::com::sun::star::frame::ControlCommand
& rControlCommand
)
253 if ( rControlCommand
.Command
.equalsAsciiL( "SetText", 7 ))
255 for ( sal_Int32 i
= 0; i
< rControlCommand
.Arguments
.getLength(); i
++ )
257 if ( rControlCommand
.Arguments
[i
].Name
.equalsAsciiL( "Text", 4 ))
260 rControlCommand
.Arguments
[i
].Value
>>= aText
;
261 m_pEditControl
->SetText( aText
);
264 notifyTextChanged( aText
);