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/comboboxtoolbarcontroller.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 : : #include <com/sun/star/util/Color.hpp>
42 : :
43 : : #include <svtools/toolboxcontroller.hxx>
44 : : #include <osl/mutex.hxx>
45 : : #include <vcl/svapp.hxx>
46 : : #include <vcl/mnemonic.hxx>
47 : : #include <vcl/toolbox.hxx>
48 : : #include <vcl/combobox.hxx>
49 : :
50 : : using namespace ::com::sun::star;
51 : : using namespace ::com::sun::star::uno;
52 : : using namespace ::com::sun::star::beans;
53 : : using namespace ::com::sun::star::lang;
54 : : using namespace ::com::sun::star::frame;
55 : : using namespace ::com::sun::star::frame::status;
56 : : using namespace ::com::sun::star::util;
57 : :
58 : : namespace framework
59 : : {
60 : :
61 : : // ------------------------------------------------------------------
62 : :
63 : : // Wrapper class to notify controller about events from combobox.
64 : : // Unfortunaltly the events are notifed through virtual methods instead
65 : : // of Listeners.
66 : :
67 : : class ComboBoxControl : public ComboBox
68 : : {
69 : : public:
70 : : ComboBoxControl( Window* pParent, WinBits nStyle, IComboBoxListener* pComboBoxListener );
71 : : virtual ~ComboBoxControl();
72 : :
73 : : virtual void Select();
74 : : virtual void DoubleClick();
75 : : virtual void Modify();
76 : : virtual void KeyInput( const ::KeyEvent& rKEvt );
77 : : virtual void GetFocus();
78 : : virtual void LoseFocus();
79 : : virtual long PreNotify( NotifyEvent& rNEvt );
80 : :
81 : : private:
82 : : IComboBoxListener* m_pComboBoxListener;
83 : : };
84 : :
85 : 0 : ComboBoxControl::ComboBoxControl( Window* pParent, WinBits nStyle, IComboBoxListener* pComboBoxListener ) :
86 : : ComboBox( pParent, nStyle )
87 : 0 : , m_pComboBoxListener( pComboBoxListener )
88 : : {
89 : 0 : }
90 : :
91 : 0 : ComboBoxControl::~ComboBoxControl()
92 : : {
93 : 0 : m_pComboBoxListener = 0;
94 [ # # ]: 0 : }
95 : :
96 : 0 : void ComboBoxControl::Select()
97 : : {
98 : 0 : ComboBox::Select();
99 [ # # ]: 0 : if ( m_pComboBoxListener )
100 : 0 : m_pComboBoxListener->Select();
101 : 0 : }
102 : :
103 : 0 : void ComboBoxControl::DoubleClick()
104 : : {
105 : 0 : ComboBox::DoubleClick();
106 [ # # ]: 0 : if ( m_pComboBoxListener )
107 : 0 : m_pComboBoxListener->DoubleClick();
108 : 0 : }
109 : :
110 : 0 : void ComboBoxControl::Modify()
111 : : {
112 : 0 : ComboBox::Modify();
113 [ # # ]: 0 : if ( m_pComboBoxListener )
114 : 0 : m_pComboBoxListener->Modify();
115 : 0 : }
116 : :
117 : 0 : void ComboBoxControl::KeyInput( const ::KeyEvent& rKEvt )
118 : : {
119 : 0 : ComboBox::KeyInput( rKEvt );
120 [ # # ]: 0 : if ( m_pComboBoxListener )
121 : 0 : m_pComboBoxListener->KeyInput( rKEvt );
122 : 0 : }
123 : :
124 : 0 : void ComboBoxControl::GetFocus()
125 : : {
126 : 0 : ComboBox::GetFocus();
127 [ # # ]: 0 : if ( m_pComboBoxListener )
128 : 0 : m_pComboBoxListener->GetFocus();
129 : 0 : }
130 : :
131 : 0 : void ComboBoxControl::LoseFocus()
132 : : {
133 : 0 : ComboBox::LoseFocus();
134 [ # # ]: 0 : if ( m_pComboBoxListener )
135 : 0 : m_pComboBoxListener->LoseFocus();
136 : 0 : }
137 : :
138 : 0 : long ComboBoxControl::PreNotify( NotifyEvent& rNEvt )
139 : : {
140 : 0 : long nRet( 0 );
141 [ # # ]: 0 : if ( m_pComboBoxListener )
142 : 0 : nRet = m_pComboBoxListener->PreNotify( rNEvt );
143 [ # # ]: 0 : if ( nRet == 0 )
144 : 0 : nRet = ComboBox::PreNotify( rNEvt );
145 : :
146 : 0 : return nRet;
147 : : }
148 : :
149 : : // ------------------------------------------------------------------
150 : :
151 : 0 : ComboboxToolbarController::ComboboxToolbarController(
152 : : const Reference< XMultiServiceFactory >& rServiceManager,
153 : : const Reference< XFrame >& rFrame,
154 : : ToolBox* pToolbar,
155 : : sal_uInt16 nID,
156 : : sal_Int32 nWidth,
157 : : const ::rtl::OUString& aCommand ) :
158 : : ComplexToolbarController( rServiceManager, rFrame, pToolbar, nID, aCommand )
159 [ # # ]: 0 : , m_pComboBox( 0 )
160 : : {
161 [ # # ][ # # ]: 0 : m_pComboBox = new ComboBoxControl( m_pToolbar, WB_DROPDOWN, this );
162 [ # # ]: 0 : if ( nWidth == 0 )
163 : 0 : nWidth = 100;
164 : :
165 : : // default dropdown size
166 : 0 : ::Size aLogicalSize( 8, 160 );
167 [ # # ][ # # ]: 0 : ::Size aPixelSize = m_pComboBox->LogicToPixel( aLogicalSize, MAP_APPFONT );
[ # # ]
168 : :
169 [ # # ]: 0 : m_pComboBox->SetSizePixel( ::Size( nWidth, aPixelSize.Height() ));
170 [ # # ]: 0 : m_pToolbar->SetItemWindow( m_nID, m_pComboBox );
171 : 0 : }
172 : :
173 : : // ------------------------------------------------------------------
174 : :
175 [ # # ]: 0 : ComboboxToolbarController::~ComboboxToolbarController()
176 : : {
177 [ # # ]: 0 : }
178 : :
179 : : // ------------------------------------------------------------------
180 : :
181 : 0 : void SAL_CALL ComboboxToolbarController::dispose()
182 : : throw ( RuntimeException )
183 : : {
184 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
185 : :
186 [ # # ]: 0 : m_pToolbar->SetItemWindow( m_nID, 0 );
187 [ # # ][ # # ]: 0 : delete m_pComboBox;
188 : :
189 [ # # ]: 0 : ComplexToolbarController::dispose();
190 : :
191 [ # # ]: 0 : m_pComboBox = 0;
192 : 0 : }
193 : :
194 : : // ------------------------------------------------------------------
195 : 0 : Sequence<PropertyValue> ComboboxToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
196 : : {
197 [ # # ]: 0 : Sequence<PropertyValue> aArgs( 2 );
198 [ # # ][ # # ]: 0 : ::rtl::OUString aSelectedText = m_pComboBox->GetText();
[ # # ]
199 : :
200 : : // Add key modifier to argument list
201 [ # # ][ # # ]: 0 : aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "KeyModifier" ));
202 [ # # ][ # # ]: 0 : aArgs[0].Value <<= KeyModifier;
203 [ # # ][ # # ]: 0 : aArgs[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ));
204 [ # # ][ # # ]: 0 : aArgs[1].Value <<= aSelectedText;
205 : 0 : return aArgs;
206 : : }
207 : :
208 : : // ------------------------------------------------------------------
209 : :
210 : 0 : void ComboboxToolbarController::Select()
211 : : {
212 [ # # ]: 0 : if ( m_pComboBox->GetEntryCount() > 0 )
213 : : {
214 [ # # ]: 0 : Window::PointerState aState = m_pComboBox->GetPointerState();
215 : :
216 : 0 : sal_uInt16 nKeyModifier = sal_uInt16( aState.mnState & KEY_MODTYPE );
217 [ # # ]: 0 : execute( nKeyModifier );
218 : : }
219 : 0 : }
220 : :
221 : 0 : void ComboboxToolbarController::DoubleClick()
222 : : {
223 : 0 : }
224 : :
225 : 0 : void ComboboxToolbarController::Modify()
226 : : {
227 [ # # ][ # # ]: 0 : notifyTextChanged( m_pComboBox->GetText() );
228 : 0 : }
229 : :
230 : 0 : void ComboboxToolbarController::KeyInput( const ::KeyEvent& )
231 : : {
232 : 0 : }
233 : :
234 : 0 : void ComboboxToolbarController::GetFocus()
235 : : {
236 : 0 : notifyFocusGet();
237 : 0 : }
238 : :
239 : 0 : void ComboboxToolbarController::LoseFocus()
240 : : {
241 : 0 : notifyFocusLost();
242 : 0 : }
243 : :
244 : 0 : long ComboboxToolbarController::PreNotify( NotifyEvent& rNEvt )
245 : : {
246 [ # # # # ]: 0 : switch ( rNEvt.GetType() )
247 : : {
248 : : case EVENT_KEYINPUT :
249 : : {
250 : 0 : const ::KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
251 : 0 : const KeyCode& rKeyCode = pKeyEvent->GetKeyCode();
252 [ # # ]: 0 : if(( rKeyCode.GetModifier() | rKeyCode.GetCode()) == KEY_RETURN )
253 : : {
254 : : // Call execute only with non-empty text
255 [ # # ]: 0 : if ( m_pComboBox->GetText().Len() > 0 )
256 : 0 : execute( rKeyCode.GetModifier() );
257 : 0 : return 1;
258 : : }
259 : : }
260 : 0 : break;
261 : : case EVENT_GETFOCUS :
262 : 0 : notifyFocusGet();
263 : 0 : break;
264 : : case EVENT_LOSEFOCUS :
265 : 0 : notifyFocusLost();
266 : 0 : break;
267 : : default :
268 : 0 : break;
269 : : }
270 : 0 : return 0;
271 : : }
272 : :
273 : : // --------------------------------------------------------
274 : :
275 : 0 : void ComboboxToolbarController::executeControlCommand( const ::com::sun::star::frame::ControlCommand& rControlCommand )
276 : : {
277 [ # # ]: 0 : if ( rControlCommand.Command.equalsAsciiL( "SetText", 7 ))
278 : : {
279 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
280 : : {
281 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
282 : : {
283 : 0 : rtl::OUString aText;
284 : 0 : rControlCommand.Arguments[i].Value >>= aText;
285 [ # # ][ # # ]: 0 : m_pComboBox->SetText( aText );
[ # # ]
286 : :
287 : : // send notification
288 [ # # ]: 0 : notifyTextChanged( aText );
289 : 0 : break;
290 : : }
291 : : }
292 : : }
293 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "SetList", 7 ))
294 : : {
295 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
296 : : {
297 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "List", 4 ))
298 : : {
299 [ # # ]: 0 : Sequence< ::rtl::OUString > aList;
300 [ # # ]: 0 : m_pComboBox->Clear();
301 : :
302 [ # # ]: 0 : rControlCommand.Arguments[i].Value >>= aList;
303 [ # # ]: 0 : for ( sal_Int32 j = 0; j < aList.getLength(); j++ )
304 [ # # ][ # # ]: 0 : m_pComboBox->InsertEntry( aList[j] );
[ # # ][ # # ]
305 : :
306 : : // send notification
307 [ # # ]: 0 : uno::Sequence< beans::NamedValue > aInfo( 1 );
308 [ # # ][ # # ]: 0 : aInfo[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "List" ));
309 [ # # ][ # # ]: 0 : aInfo[0].Value <<= aList;
310 : : addNotifyInfo( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ListChanged" )),
311 : : getDispatchFromCommand( m_aCommandURL ),
312 [ # # ][ # # ]: 0 : aInfo );
[ # # ]
313 : :
314 [ # # ][ # # ]: 0 : break;
315 : : }
316 : : }
317 : : }
318 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "AddEntry", 8 ))
319 : : {
320 : 0 : sal_uInt16 nPos( COMBOBOX_APPEND );
321 : 0 : rtl::OUString aText;
322 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
323 : : {
324 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
325 : : {
326 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Value >>= aText )
327 [ # # ][ # # ]: 0 : m_pComboBox->InsertEntry( aText, nPos );
[ # # ]
328 : 0 : break;
329 : : }
330 : 0 : }
331 : : }
332 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "InsertEntry", 11 ))
333 : : {
334 : 0 : sal_uInt16 nPos( COMBOBOX_APPEND );
335 : 0 : rtl::OUString aText;
336 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
337 : : {
338 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Pos", 3 ))
339 : : {
340 : 0 : sal_Int32 nTmpPos = 0;
341 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Value >>= nTmpPos )
342 : : {
343 [ # # ][ # # ]: 0 : if (( nTmpPos >= 0 ) &&
[ # # ]
344 [ # # ]: 0 : ( nTmpPos < sal_Int32( m_pComboBox->GetEntryCount() )))
345 : 0 : nPos = sal_uInt16( nTmpPos );
346 : : }
347 : : }
348 [ # # ]: 0 : else if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
349 : 0 : rControlCommand.Arguments[i].Value >>= aText;
350 : : }
351 : :
352 [ # # ][ # # ]: 0 : m_pComboBox->InsertEntry( aText, nPos );
[ # # ]
353 : : }
354 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "RemoveEntryPos", 14 ))
355 : : {
356 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
357 : : {
358 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Pos", 3 ))
359 : : {
360 : 0 : sal_Int32 nPos( -1 );
361 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Value >>= nPos )
362 : : {
363 [ # # ][ # # ]: 0 : if ( nPos < sal_Int32( m_pComboBox->GetEntryCount() ))
364 [ # # ]: 0 : m_pComboBox->RemoveEntry( sal_uInt16( nPos ));
365 : : }
366 : : break;
367 : : }
368 : : }
369 : : }
370 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "RemoveEntryText", 15 ))
371 : : {
372 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
373 : : {
374 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
375 : : {
376 : 0 : rtl::OUString aText;
377 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Value >>= aText )
378 [ # # ][ # # ]: 0 : m_pComboBox->RemoveEntry( aText );
[ # # ]
379 : 0 : break;
380 : : }
381 : : }
382 : : }
383 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "SetDropDownLines", 16 ))
384 : : {
385 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
386 : : {
387 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Lines", 5 ))
388 : : {
389 : 0 : sal_Int32 nValue( 5 );
390 : 0 : rControlCommand.Arguments[i].Value >>= nValue;
391 [ # # ]: 0 : m_pComboBox->SetDropDownLineCount( sal_uInt16( nValue ));
392 : : break;
393 : : }
394 : : }
395 : : }
396 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "SetBackgroundColor", 18 ))
397 : : {
398 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
399 : : {
400 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Color", 5 ))
401 : : {
402 : 0 : com::sun::star::util::Color aColor(0);
403 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Value >>= aColor )
404 : : {
405 : 0 : ::Color aBackColor( static_cast< sal_uInt32 >( aColor ));
406 [ # # ]: 0 : m_pComboBox->SetControlBackground( aBackColor );
407 : : }
408 : : break;
409 : : }
410 : : }
411 : : }
412 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "SetTextColor", 12 ))
413 : : {
414 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
415 : : {
416 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Color", 5 ))
417 : : {
418 : 0 : com::sun::star::util::Color aColor(0);
419 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Value >>= aColor )
420 : : {
421 : 0 : ::Color aForeColor( static_cast< sal_uInt32 >( aColor ));
422 [ # # ]: 0 : m_pComboBox->SetControlForeground( aForeColor );
423 : : }
424 : : break;
425 : : }
426 : : }
427 : : }
428 : 0 : }
429 : :
430 : : } // namespace
431 : :
432 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|