fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / uielement / edittoolbarcontroller.cxx
blob41403fd9f7e72ca1e05429c5aca26b3fa5512502
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "uielement/edittoolbarcontroller.hxx"
22 #include <com/sun/star/util/XURLTransformer.hpp>
23 #include <com/sun/star/frame/XDispatchProvider.hpp>
24 #include <com/sun/star/beans/PropertyValue.hpp>
25 #include <com/sun/star/frame/status/ItemStatus.hpp>
26 #include <com/sun/star/frame/status/ItemState.hpp>
27 #include <com/sun/star/frame/status/Visibility.hpp>
28 #include <com/sun/star/frame/XControlNotificationListener.hpp>
30 #include <svtools/toolboxcontroller.hxx>
31 #include <osl/mutex.hxx>
32 #include <vcl/svapp.hxx>
33 #include <vcl/mnemonic.hxx>
34 #include <vcl/toolbox.hxx>
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::beans;
39 using namespace ::com::sun::star::lang;
40 using namespace ::com::sun::star::frame;
41 using namespace ::com::sun::star::frame::status;
42 using namespace ::com::sun::star::util;
44 namespace framework
47 // Wrapper class to notify controller about events from edit.
48 // Unfortunaltly the events are notifed through virtual methods instead
49 // of Listeners.
51 class EditControl : public Edit
53 public:
54 EditControl( vcl::Window* pParent, WinBits nStyle, IEditListener* pEditListener );
55 virtual ~EditControl();
56 virtual void dispose() SAL_OVERRIDE;
58 virtual void Modify() SAL_OVERRIDE;
59 virtual void KeyInput( const ::KeyEvent& rKEvt ) SAL_OVERRIDE;
60 virtual void GetFocus() SAL_OVERRIDE;
61 virtual void LoseFocus() SAL_OVERRIDE;
62 virtual bool PreNotify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
64 private:
65 IEditListener* m_pEditListener;
68 EditControl::EditControl( vcl::Window* pParent, WinBits nStyle, IEditListener* pEditListener ) :
69 Edit( pParent, nStyle )
70 , m_pEditListener( pEditListener )
74 EditControl::~EditControl()
76 disposeOnce();
79 void EditControl::dispose()
81 m_pEditListener = 0;
82 Edit::dispose();
85 void EditControl::Modify()
87 Edit::Modify();
88 if ( m_pEditListener )
89 m_pEditListener->Modify();
92 void EditControl::KeyInput( const ::KeyEvent& rKEvt )
94 Edit::KeyInput( rKEvt );
95 if ( m_pEditListener )
96 m_pEditListener->KeyInput( rKEvt );
99 void EditControl::GetFocus()
101 Edit::GetFocus();
102 if ( m_pEditListener )
103 m_pEditListener->GetFocus();
106 void EditControl::LoseFocus()
108 Edit::LoseFocus();
109 if ( m_pEditListener )
110 m_pEditListener->LoseFocus();
113 bool EditControl::PreNotify( NotifyEvent& rNEvt )
115 bool nRet = false;
116 if ( m_pEditListener )
117 nRet = m_pEditListener->PreNotify( rNEvt );
118 if ( !nRet )
119 nRet = Edit::PreNotify( rNEvt );
121 return nRet;
124 EditToolbarController::EditToolbarController(
125 const Reference< XComponentContext >& rxContext,
126 const Reference< XFrame >& rFrame,
127 ToolBox* pToolbar,
128 sal_uInt16 nID,
129 sal_Int32 nWidth,
130 const OUString& aCommand ) :
131 ComplexToolbarController( rxContext, rFrame, pToolbar, nID, aCommand )
132 , m_pEditControl( 0 )
134 m_pEditControl = VclPtr<EditControl>::Create( m_pToolbar, WB_BORDER, this );
135 if ( nWidth == 0 )
136 nWidth = 100;
138 // Calculate height of the edit field according to the application font height
139 sal_Int32 nHeight = getFontSizePixel( m_pEditControl ) + 6 + 1;
141 m_pEditControl->SetSizePixel( ::Size( nWidth, nHeight ));
142 m_pToolbar->SetItemWindow( m_nID, m_pEditControl );
145 EditToolbarController::~EditToolbarController()
149 void SAL_CALL EditToolbarController::dispose()
150 throw ( RuntimeException, std::exception )
152 SolarMutexGuard aSolarMutexGuard;
154 m_pToolbar->SetItemWindow( m_nID, 0 );
155 m_pEditControl.disposeAndClear();
157 ComplexToolbarController::dispose();
160 Sequence<PropertyValue> EditToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
162 Sequence<PropertyValue> aArgs( 2 );
163 OUString aSelectedText = m_pEditControl->GetText();
165 // Add key modifier to argument list
166 aArgs[0].Name = "KeyModifier";
167 aArgs[0].Value <<= KeyModifier;
168 aArgs[1].Name = "Text";
169 aArgs[1].Value <<= aSelectedText;
170 return aArgs;
173 void EditToolbarController::Modify()
175 notifyTextChanged( m_pEditControl->GetText() );
178 void EditToolbarController::KeyInput( const ::KeyEvent& /*rKEvt*/ )
182 void EditToolbarController::GetFocus()
184 notifyFocusGet();
187 void EditToolbarController::LoseFocus()
189 notifyFocusLost();
192 bool EditToolbarController::PreNotify( NotifyEvent& rNEvt )
194 if( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
196 const ::KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
197 const vcl::KeyCode& rKeyCode = pKeyEvent->GetKeyCode();
198 if(( rKeyCode.GetModifier() | rKeyCode.GetCode()) == KEY_RETURN )
200 // Call execute only with non-empty text
201 if ( !m_pEditControl->GetText().isEmpty() )
202 execute( rKeyCode.GetModifier() );
203 return true;
207 return false;
210 void EditToolbarController::executeControlCommand( const ::com::sun::star::frame::ControlCommand& rControlCommand )
212 if ( rControlCommand.Command.startsWith( "SetText" ))
214 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
216 if ( rControlCommand.Arguments[i].Name.startsWith( "Text" ))
218 OUString aText;
219 rControlCommand.Arguments[i].Value >>= aText;
220 m_pEditControl->SetText( aText );
222 // send notification
223 notifyTextChanged( aText );
224 break;
230 } // namespace
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */