Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "uielement/edittoolbarcontroller.hxx"
31 : :
32 : : #include "uielement/toolbar.hxx"
33 : :
34 : : #include <com/sun/star/util/XURLTransformer.hpp>
35 : : #include <com/sun/star/frame/XDispatchProvider.hpp>
36 : : #include <com/sun/star/beans/PropertyValue.hpp>
37 : : #include <com/sun/star/frame/status/ItemStatus.hpp>
38 : : #include <com/sun/star/frame/status/ItemState.hpp>
39 : : #include <com/sun/star/frame/status/Visibility.hpp>
40 : : #include <com/sun/star/frame/XControlNotificationListener.hpp>
41 : :
42 : : #include <svtools/toolboxcontroller.hxx>
43 : : #include <osl/mutex.hxx>
44 : : #include <vcl/svapp.hxx>
45 : : #include <vcl/mnemonic.hxx>
46 : :
47 : : using namespace ::com::sun::star;
48 : : using namespace ::com::sun::star::uno;
49 : : using namespace ::com::sun::star::beans;
50 : : using namespace ::com::sun::star::lang;
51 : : using namespace ::com::sun::star::frame;
52 : : using namespace ::com::sun::star::frame::status;
53 : : using namespace ::com::sun::star::util;
54 : :
55 : : namespace framework
56 : : {
57 : :
58 : : // ------------------------------------------------------------------
59 : :
60 : : // Wrapper class to notify controller about events from edit.
61 : : // Unfortunaltly the events are notifed through virtual methods instead
62 : : // of Listeners.
63 : :
64 : : class EditControl : public Edit
65 : : {
66 : : public:
67 : : EditControl( Window* pParent, WinBits nStyle, IEditListener* pEditListener );
68 : : virtual ~EditControl();
69 : :
70 : : virtual void Modify();
71 : : virtual void KeyInput( const ::KeyEvent& rKEvt );
72 : : virtual void GetFocus();
73 : : virtual void LoseFocus();
74 : : virtual long PreNotify( NotifyEvent& rNEvt );
75 : :
76 : : private:
77 : : IEditListener* m_pEditListener;
78 : : };
79 : :
80 : 0 : EditControl::EditControl( Window* pParent, WinBits nStyle, IEditListener* pEditListener ) :
81 : : Edit( pParent, nStyle )
82 : 0 : , m_pEditListener( pEditListener )
83 : : {
84 : 0 : }
85 : :
86 : 0 : EditControl::~EditControl()
87 : : {
88 : 0 : m_pEditListener = 0;
89 [ # # ]: 0 : }
90 : :
91 : 0 : void EditControl::Modify()
92 : : {
93 : 0 : Edit::Modify();
94 [ # # ]: 0 : if ( m_pEditListener )
95 : 0 : m_pEditListener->Modify();
96 : 0 : }
97 : :
98 : 0 : void EditControl::KeyInput( const ::KeyEvent& rKEvt )
99 : : {
100 : 0 : Edit::KeyInput( rKEvt );
101 [ # # ]: 0 : if ( m_pEditListener )
102 : 0 : m_pEditListener->KeyInput( rKEvt );
103 : 0 : }
104 : :
105 : 0 : void EditControl::GetFocus()
106 : : {
107 : 0 : Edit::GetFocus();
108 [ # # ]: 0 : if ( m_pEditListener )
109 : 0 : m_pEditListener->GetFocus();
110 : 0 : }
111 : :
112 : 0 : void EditControl::LoseFocus()
113 : : {
114 : 0 : Edit::LoseFocus();
115 [ # # ]: 0 : if ( m_pEditListener )
116 : 0 : m_pEditListener->LoseFocus();
117 : 0 : }
118 : :
119 : 0 : long EditControl::PreNotify( NotifyEvent& rNEvt )
120 : : {
121 : 0 : long nRet( 0 );
122 [ # # ]: 0 : if ( m_pEditListener )
123 : 0 : nRet = m_pEditListener->PreNotify( rNEvt );
124 [ # # ]: 0 : if ( nRet == 0 )
125 : 0 : nRet = Edit::PreNotify( rNEvt );
126 : :
127 : 0 : return nRet;
128 : : }
129 : :
130 : : // ------------------------------------------------------------------
131 : :
132 : 0 : EditToolbarController::EditToolbarController(
133 : : const Reference< XMultiServiceFactory >& rServiceManager,
134 : : const Reference< XFrame >& rFrame,
135 : : ToolBox* pToolbar,
136 : : sal_uInt16 nID,
137 : : sal_Int32 nWidth,
138 : : const ::rtl::OUString& aCommand ) :
139 : : ComplexToolbarController( rServiceManager, rFrame, pToolbar, nID, aCommand )
140 [ # # ]: 0 : , m_pEditControl( 0 )
141 : : {
142 [ # # ][ # # ]: 0 : m_pEditControl = new EditControl( m_pToolbar, WB_BORDER, this );
143 [ # # ]: 0 : if ( nWidth == 0 )
144 : 0 : nWidth = 100;
145 : :
146 : : // Calculate height of the edit field according to the application font height
147 [ # # ]: 0 : sal_Int32 nHeight = getFontSizePixel( m_pEditControl ) + 6 + 1;
148 : :
149 [ # # ]: 0 : m_pEditControl->SetSizePixel( ::Size( nWidth, nHeight ));
150 [ # # ]: 0 : m_pToolbar->SetItemWindow( m_nID, m_pEditControl );
151 : 0 : }
152 : :
153 : : // ------------------------------------------------------------------
154 : :
155 [ # # ]: 0 : EditToolbarController::~EditToolbarController()
156 : : {
157 [ # # ]: 0 : }
158 : :
159 : : // ------------------------------------------------------------------
160 : :
161 : 0 : void SAL_CALL EditToolbarController::dispose()
162 : : throw ( RuntimeException )
163 : : {
164 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
165 : :
166 [ # # ]: 0 : m_pToolbar->SetItemWindow( m_nID, 0 );
167 [ # # ][ # # ]: 0 : delete m_pEditControl;
168 : :
169 [ # # ]: 0 : ComplexToolbarController::dispose();
170 : :
171 [ # # ]: 0 : m_pEditControl = 0;
172 : 0 : }
173 : :
174 : : // ------------------------------------------------------------------
175 : 0 : Sequence<PropertyValue> EditToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
176 : : {
177 [ # # ]: 0 : Sequence<PropertyValue> aArgs( 2 );
178 [ # # ][ # # ]: 0 : ::rtl::OUString aSelectedText = m_pEditControl->GetText();
[ # # ]
179 : :
180 : : // Add key modifier to argument list
181 [ # # ][ # # ]: 0 : aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "KeyModifier" ));
182 [ # # ][ # # ]: 0 : aArgs[0].Value <<= KeyModifier;
183 [ # # ][ # # ]: 0 : aArgs[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ));
184 [ # # ][ # # ]: 0 : aArgs[1].Value <<= aSelectedText;
185 : 0 : return aArgs;
186 : : }
187 : :
188 : : // ------------------------------------------------------------------
189 : :
190 : 0 : void EditToolbarController::Modify()
191 : : {
192 [ # # ][ # # ]: 0 : notifyTextChanged( m_pEditControl->GetText() );
193 : 0 : }
194 : :
195 : 0 : void EditToolbarController::KeyInput( const ::KeyEvent& /*rKEvt*/ )
196 : : {
197 : 0 : }
198 : :
199 : 0 : void EditToolbarController::GetFocus()
200 : : {
201 : 0 : notifyFocusGet();
202 : 0 : }
203 : :
204 : 0 : void EditToolbarController::LoseFocus()
205 : : {
206 : 0 : notifyFocusLost();
207 : 0 : }
208 : :
209 : 0 : long EditToolbarController::PreNotify( NotifyEvent& rNEvt )
210 : : {
211 [ # # ]: 0 : if( rNEvt.GetType() == EVENT_KEYINPUT )
212 : : {
213 : 0 : const ::KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
214 : 0 : const KeyCode& rKeyCode = pKeyEvent->GetKeyCode();
215 [ # # ]: 0 : if(( rKeyCode.GetModifier() | rKeyCode.GetCode()) == KEY_RETURN )
216 : : {
217 : : // Call execute only with non-empty text
218 [ # # ]: 0 : if ( m_pEditControl->GetText().Len() > 0 )
219 : 0 : execute( rKeyCode.GetModifier() );
220 : 0 : return 1;
221 : : }
222 : : }
223 : :
224 : 0 : return 0;
225 : : }
226 : :
227 : : // --------------------------------------------------------
228 : :
229 : 0 : void EditToolbarController::executeControlCommand( const ::com::sun::star::frame::ControlCommand& rControlCommand )
230 : : {
231 [ # # ]: 0 : if ( rControlCommand.Command.equalsAsciiL( "SetText", 7 ))
232 : : {
233 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
234 : : {
235 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
236 : : {
237 : 0 : rtl::OUString aText;
238 : 0 : rControlCommand.Arguments[i].Value >>= aText;
239 [ # # ][ # # ]: 0 : m_pEditControl->SetText( aText );
[ # # ]
240 : :
241 : : // send notification
242 [ # # ]: 0 : notifyTextChanged( aText );
243 : 0 : break;
244 : : }
245 : : }
246 : : }
247 : 0 : }
248 : :
249 : : } // namespace
250 : :
251 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|