merge the formfield patch from ooo-build
[ooovba.git] / framework / source / uielement / edittoolbarcontroller.cxx
blob5faefa9282707c13f0f240f4ae3d79e25f1eb171
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 $
10 * $Revision: 1.6 $
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"
36 #endif
38 //_________________________________________________________________________________________________________________
39 // my own includes
40 //_________________________________________________________________________________________________________________
42 #ifndef __FRAMEWORK_TOOLBAR_HXX_
43 #include "uielement/toolbar.hxx"
44 #endif
46 //_________________________________________________________________________________________________________________
47 // interface includes
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 //_________________________________________________________________________________________________________________
59 // other includes
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>
66 #endif
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;
77 namespace framework
80 // ------------------------------------------------------------------
82 // Wrapper class to notify controller about events from edit.
83 // Unfortunaltly the events are notifed through virtual methods instead
84 // of Listeners.
86 class EditControl : public Edit
88 public:
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 );
98 private:
99 IEditListener* m_pEditListener;
102 EditControl::EditControl( Window* pParent, WinBits nStyle, IEditListener* pEditListener ) :
103 Edit( pParent, nStyle )
104 , m_pEditListener( pEditListener )
108 EditControl::~EditControl()
110 m_pEditListener = 0;
113 void EditControl::Modify()
115 Edit::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()
129 Edit::GetFocus();
130 if ( m_pEditListener )
131 m_pEditListener->GetFocus();
134 void EditControl::LoseFocus()
136 Edit::LoseFocus();
137 if ( m_pEditListener )
138 m_pEditListener->LoseFocus();
141 long EditControl::PreNotify( NotifyEvent& rNEvt )
143 long nRet( 0 );
144 if ( m_pEditListener )
145 nRet = m_pEditListener->PreNotify( rNEvt );
146 if ( nRet == 0 )
147 nRet = Edit::PreNotify( rNEvt );
149 return nRet;
152 // ------------------------------------------------------------------
154 EditToolbarController::EditToolbarController(
155 const Reference< XMultiServiceFactory >& rServiceManager,
156 const Reference< XFrame >& rFrame,
157 ToolBox* pToolbar,
158 USHORT nID,
159 sal_Int32 nWidth,
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 );
165 if ( nWidth == 0 )
166 nWidth = 100;
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();
193 m_pEditControl = 0;
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;
207 return aArgs;
210 // ------------------------------------------------------------------
212 void EditToolbarController::Modify()
214 notifyTextChanged( m_pEditControl->GetText() );
217 void EditToolbarController::KeyInput( const ::KeyEvent& /*rKEvt*/ )
221 void EditToolbarController::GetFocus()
223 notifyFocusGet();
226 void EditToolbarController::LoseFocus()
228 notifyFocusLost();
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() );
242 return 1;
246 return 0;
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 ))
259 rtl::OUString aText;
260 rControlCommand.Arguments[i].Value >>= aText;
261 m_pEditControl->SetText( aText );
263 // send notification
264 notifyTextChanged( aText );
265 break;
271 } // namespace