1*6d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*6d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*6d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*6d739b60SAndrew Rist * distributed with this work for additional information
6*6d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*6d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*6d739b60SAndrew Rist * "License"); you may not use this file except in compliance
9*6d739b60SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*6d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*6d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*6d739b60SAndrew Rist * software distributed under the License is distributed on an
15*6d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6d739b60SAndrew Rist * KIND, either express or implied. See the License for the
17*6d739b60SAndrew Rist * specific language governing permissions and limitations
18*6d739b60SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*6d739b60SAndrew Rist *************************************************************/
21*6d739b60SAndrew Rist
22*6d739b60SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #ifndef __FRAMEWORK_UIELEMENT_EDITTOOLBARCONTROLLER_HXX
28cdf0e10cSrcweir #include "uielement/edittoolbarcontroller.hxx"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir
31cdf0e10cSrcweir //_________________________________________________________________________________________________________________
32cdf0e10cSrcweir // my own includes
33cdf0e10cSrcweir //_________________________________________________________________________________________________________________
34cdf0e10cSrcweir
35cdf0e10cSrcweir #ifndef __FRAMEWORK_TOOLBAR_HXX_
36cdf0e10cSrcweir #include "uielement/toolbar.hxx"
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir
39cdf0e10cSrcweir //_________________________________________________________________________________________________________________
40cdf0e10cSrcweir // interface includes
41cdf0e10cSrcweir //_________________________________________________________________________________________________________________
42cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
43cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
44cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
45cdf0e10cSrcweir #include <com/sun/star/frame/status/ItemStatus.hpp>
46cdf0e10cSrcweir #include <com/sun/star/frame/status/ItemState.hpp>
47cdf0e10cSrcweir #include <com/sun/star/frame/status/Visibility.hpp>
48cdf0e10cSrcweir #include <com/sun/star/frame/XControlNotificationListener.hpp>
49cdf0e10cSrcweir
50cdf0e10cSrcweir //_________________________________________________________________________________________________________________
51cdf0e10cSrcweir // other includes
52cdf0e10cSrcweir //_________________________________________________________________________________________________________________
53cdf0e10cSrcweir #include <svtools/toolboxcontroller.hxx>
54cdf0e10cSrcweir #include <vos/mutex.hxx>
55cdf0e10cSrcweir #include <vcl/svapp.hxx>
56cdf0e10cSrcweir #ifndef _VCL_MNEMONIC_HXX_
57cdf0e10cSrcweir #include <vcl/mnemonic.hxx>
58cdf0e10cSrcweir #endif
59cdf0e10cSrcweir #include <tools/urlobj.hxx>
60cdf0e10cSrcweir
61cdf0e10cSrcweir using namespace ::com::sun::star;
62cdf0e10cSrcweir using namespace ::com::sun::star::uno;
63cdf0e10cSrcweir using namespace ::com::sun::star::beans;
64cdf0e10cSrcweir using namespace ::com::sun::star::lang;
65cdf0e10cSrcweir using namespace ::com::sun::star::frame;
66cdf0e10cSrcweir using namespace ::com::sun::star::frame::status;
67cdf0e10cSrcweir using namespace ::com::sun::star::util;
68cdf0e10cSrcweir
69cdf0e10cSrcweir namespace framework
70cdf0e10cSrcweir {
71cdf0e10cSrcweir
72cdf0e10cSrcweir // ------------------------------------------------------------------
73cdf0e10cSrcweir
74cdf0e10cSrcweir // Wrapper class to notify controller about events from edit.
75cdf0e10cSrcweir // Unfortunaltly the events are notifed through virtual methods instead
76cdf0e10cSrcweir // of Listeners.
77cdf0e10cSrcweir
78cdf0e10cSrcweir class EditControl : public Edit
79cdf0e10cSrcweir {
80cdf0e10cSrcweir public:
81cdf0e10cSrcweir EditControl( Window* pParent, WinBits nStyle, IEditListener* pEditListener );
82cdf0e10cSrcweir virtual ~EditControl();
83cdf0e10cSrcweir
84cdf0e10cSrcweir virtual void Modify();
85cdf0e10cSrcweir virtual void KeyInput( const ::KeyEvent& rKEvt );
86cdf0e10cSrcweir virtual void GetFocus();
87cdf0e10cSrcweir virtual void LoseFocus();
88cdf0e10cSrcweir virtual long PreNotify( NotifyEvent& rNEvt );
89cdf0e10cSrcweir
90cdf0e10cSrcweir private:
91cdf0e10cSrcweir IEditListener* m_pEditListener;
92cdf0e10cSrcweir };
93cdf0e10cSrcweir
EditControl(Window * pParent,WinBits nStyle,IEditListener * pEditListener)94cdf0e10cSrcweir EditControl::EditControl( Window* pParent, WinBits nStyle, IEditListener* pEditListener ) :
95cdf0e10cSrcweir Edit( pParent, nStyle )
96cdf0e10cSrcweir , m_pEditListener( pEditListener )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir }
99cdf0e10cSrcweir
~EditControl()100cdf0e10cSrcweir EditControl::~EditControl()
101cdf0e10cSrcweir {
102cdf0e10cSrcweir m_pEditListener = 0;
103cdf0e10cSrcweir }
104cdf0e10cSrcweir
Modify()105cdf0e10cSrcweir void EditControl::Modify()
106cdf0e10cSrcweir {
107cdf0e10cSrcweir Edit::Modify();
108cdf0e10cSrcweir if ( m_pEditListener )
109cdf0e10cSrcweir m_pEditListener->Modify();
110cdf0e10cSrcweir }
111cdf0e10cSrcweir
KeyInput(const::KeyEvent & rKEvt)112cdf0e10cSrcweir void EditControl::KeyInput( const ::KeyEvent& rKEvt )
113cdf0e10cSrcweir {
114cdf0e10cSrcweir Edit::KeyInput( rKEvt );
115cdf0e10cSrcweir if ( m_pEditListener )
116cdf0e10cSrcweir m_pEditListener->KeyInput( rKEvt );
117cdf0e10cSrcweir }
118cdf0e10cSrcweir
GetFocus()119cdf0e10cSrcweir void EditControl::GetFocus()
120cdf0e10cSrcweir {
121cdf0e10cSrcweir Edit::GetFocus();
122cdf0e10cSrcweir if ( m_pEditListener )
123cdf0e10cSrcweir m_pEditListener->GetFocus();
124cdf0e10cSrcweir }
125cdf0e10cSrcweir
LoseFocus()126cdf0e10cSrcweir void EditControl::LoseFocus()
127cdf0e10cSrcweir {
128cdf0e10cSrcweir Edit::LoseFocus();
129cdf0e10cSrcweir if ( m_pEditListener )
130cdf0e10cSrcweir m_pEditListener->LoseFocus();
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
PreNotify(NotifyEvent & rNEvt)133cdf0e10cSrcweir long EditControl::PreNotify( NotifyEvent& rNEvt )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir long nRet( 0 );
136cdf0e10cSrcweir if ( m_pEditListener )
137cdf0e10cSrcweir nRet = m_pEditListener->PreNotify( rNEvt );
138cdf0e10cSrcweir if ( nRet == 0 )
139cdf0e10cSrcweir nRet = Edit::PreNotify( rNEvt );
140cdf0e10cSrcweir
141cdf0e10cSrcweir return nRet;
142cdf0e10cSrcweir }
143cdf0e10cSrcweir
144cdf0e10cSrcweir // ------------------------------------------------------------------
145cdf0e10cSrcweir
EditToolbarController(const Reference<XMultiServiceFactory> & rServiceManager,const Reference<XFrame> & rFrame,ToolBox * pToolbar,sal_uInt16 nID,sal_Int32 nWidth,const::rtl::OUString & aCommand)146cdf0e10cSrcweir EditToolbarController::EditToolbarController(
147cdf0e10cSrcweir const Reference< XMultiServiceFactory >& rServiceManager,
148cdf0e10cSrcweir const Reference< XFrame >& rFrame,
149cdf0e10cSrcweir ToolBox* pToolbar,
150cdf0e10cSrcweir sal_uInt16 nID,
151cdf0e10cSrcweir sal_Int32 nWidth,
152cdf0e10cSrcweir const ::rtl::OUString& aCommand ) :
153cdf0e10cSrcweir ComplexToolbarController( rServiceManager, rFrame, pToolbar, nID, aCommand )
154cdf0e10cSrcweir , m_pEditControl( 0 )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir m_pEditControl = new EditControl( m_pToolbar, WB_BORDER, this );
157cdf0e10cSrcweir if ( nWidth == 0 )
158cdf0e10cSrcweir nWidth = 100;
159cdf0e10cSrcweir
160cdf0e10cSrcweir // Calculate height of the edit field according to the application font height
161cdf0e10cSrcweir sal_Int32 nHeight = getFontSizePixel( m_pEditControl ) + 6 + 1;
162cdf0e10cSrcweir
163cdf0e10cSrcweir m_pEditControl->SetSizePixel( ::Size( nWidth, nHeight ));
164cdf0e10cSrcweir m_pToolbar->SetItemWindow( m_nID, m_pEditControl );
165cdf0e10cSrcweir }
166cdf0e10cSrcweir
167cdf0e10cSrcweir // ------------------------------------------------------------------
168cdf0e10cSrcweir
~EditToolbarController()169cdf0e10cSrcweir EditToolbarController::~EditToolbarController()
170cdf0e10cSrcweir {
171cdf0e10cSrcweir }
172cdf0e10cSrcweir
173cdf0e10cSrcweir // ------------------------------------------------------------------
174cdf0e10cSrcweir
dispose()175cdf0e10cSrcweir void SAL_CALL EditToolbarController::dispose()
176cdf0e10cSrcweir throw ( RuntimeException )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
179cdf0e10cSrcweir
180cdf0e10cSrcweir m_pToolbar->SetItemWindow( m_nID, 0 );
181cdf0e10cSrcweir delete m_pEditControl;
182cdf0e10cSrcweir
183cdf0e10cSrcweir ComplexToolbarController::dispose();
184cdf0e10cSrcweir
185cdf0e10cSrcweir m_pEditControl = 0;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir
188cdf0e10cSrcweir // ------------------------------------------------------------------
getExecuteArgs(sal_Int16 KeyModifier) const189cdf0e10cSrcweir Sequence<PropertyValue> EditToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
190cdf0e10cSrcweir {
191cdf0e10cSrcweir Sequence<PropertyValue> aArgs( 2 );
192cdf0e10cSrcweir ::rtl::OUString aSelectedText = m_pEditControl->GetText();
193cdf0e10cSrcweir
194cdf0e10cSrcweir // Add key modifier to argument list
195cdf0e10cSrcweir aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "KeyModifier" ));
196cdf0e10cSrcweir aArgs[0].Value <<= KeyModifier;
197cdf0e10cSrcweir aArgs[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ));
198cdf0e10cSrcweir aArgs[1].Value <<= aSelectedText;
199cdf0e10cSrcweir return aArgs;
200cdf0e10cSrcweir }
201cdf0e10cSrcweir
202cdf0e10cSrcweir // ------------------------------------------------------------------
203cdf0e10cSrcweir
Modify()204cdf0e10cSrcweir void EditToolbarController::Modify()
205cdf0e10cSrcweir {
206cdf0e10cSrcweir notifyTextChanged( m_pEditControl->GetText() );
207cdf0e10cSrcweir }
208cdf0e10cSrcweir
KeyInput(const::KeyEvent &)209cdf0e10cSrcweir void EditToolbarController::KeyInput( const ::KeyEvent& /*rKEvt*/ )
210cdf0e10cSrcweir {
211cdf0e10cSrcweir }
212cdf0e10cSrcweir
GetFocus()213cdf0e10cSrcweir void EditToolbarController::GetFocus()
214cdf0e10cSrcweir {
215cdf0e10cSrcweir notifyFocusGet();
216cdf0e10cSrcweir }
217cdf0e10cSrcweir
LoseFocus()218cdf0e10cSrcweir void EditToolbarController::LoseFocus()
219cdf0e10cSrcweir {
220cdf0e10cSrcweir notifyFocusLost();
221cdf0e10cSrcweir }
222cdf0e10cSrcweir
PreNotify(NotifyEvent & rNEvt)223cdf0e10cSrcweir long EditToolbarController::PreNotify( NotifyEvent& rNEvt )
224cdf0e10cSrcweir {
225cdf0e10cSrcweir if( rNEvt.GetType() == EVENT_KEYINPUT )
226cdf0e10cSrcweir {
227cdf0e10cSrcweir const ::KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
228cdf0e10cSrcweir const KeyCode& rKeyCode = pKeyEvent->GetKeyCode();
229cdf0e10cSrcweir if(( rKeyCode.GetModifier() | rKeyCode.GetCode()) == KEY_RETURN )
230cdf0e10cSrcweir {
231cdf0e10cSrcweir // Call execute only with non-empty text
232cdf0e10cSrcweir if ( m_pEditControl->GetText().Len() > 0 )
233cdf0e10cSrcweir execute( rKeyCode.GetModifier() );
234cdf0e10cSrcweir return 1;
235cdf0e10cSrcweir }
236cdf0e10cSrcweir }
237cdf0e10cSrcweir
238cdf0e10cSrcweir return 0;
239cdf0e10cSrcweir }
240cdf0e10cSrcweir
241cdf0e10cSrcweir // --------------------------------------------------------
242cdf0e10cSrcweir
executeControlCommand(const::com::sun::star::frame::ControlCommand & rControlCommand)243cdf0e10cSrcweir void EditToolbarController::executeControlCommand( const ::com::sun::star::frame::ControlCommand& rControlCommand )
244cdf0e10cSrcweir {
245cdf0e10cSrcweir if ( rControlCommand.Command.equalsAsciiL( "SetText", 7 ))
246cdf0e10cSrcweir {
247cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
248cdf0e10cSrcweir {
249cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
250cdf0e10cSrcweir {
251cdf0e10cSrcweir rtl::OUString aText;
252cdf0e10cSrcweir rControlCommand.Arguments[i].Value >>= aText;
253cdf0e10cSrcweir m_pEditControl->SetText( aText );
254cdf0e10cSrcweir
255cdf0e10cSrcweir // send notification
256cdf0e10cSrcweir notifyTextChanged( aText );
257cdf0e10cSrcweir break;
258cdf0e10cSrcweir }
259cdf0e10cSrcweir }
260cdf0e10cSrcweir }
261cdf0e10cSrcweir }
262cdf0e10cSrcweir
263cdf0e10cSrcweir } // namespace
264cdf0e10cSrcweir
265