update dev300-m58
[ooovba.git] / framework / source / uielement / dropdownboxtoolbarcontroller.cxx
blobe9910d6b454ec6bda0a837568e0246ae5135dbf2
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: dropdownboxtoolbarcontroller.cxx,v $
10 * $Revision: 1.7 $
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_DROPDOWNBOXTOOLBARCONTROLLER_HXX
35 #include "uielement/dropdownboxtoolbarcontroller.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::awt;
71 using namespace ::com::sun::star::uno;
72 using namespace ::com::sun::star::beans;
73 using namespace ::com::sun::star::lang;
74 using namespace ::com::sun::star::frame;
75 using namespace ::com::sun::star::frame::status;
76 using namespace ::com::sun::star::util;
78 namespace framework
81 // ------------------------------------------------------------------
83 // Wrapper class to notify controller about events from ListBox.
84 // Unfortunaltly the events are notifed through virtual methods instead
85 // of Listeners.
87 class ListBoxControl : public ListBox
89 public:
90 ListBoxControl( Window* pParent, WinBits nStyle, IListBoxListener* pListBoxListener );
91 virtual ~ListBoxControl();
93 virtual void Select();
94 virtual void DoubleClick();
95 virtual void GetFocus();
96 virtual void LoseFocus();
97 virtual long PreNotify( NotifyEvent& rNEvt );
99 private:
100 IListBoxListener* m_pListBoxListener;
103 ListBoxControl::ListBoxControl( Window* pParent, WinBits nStyle, IListBoxListener* pListBoxListener ) :
104 ListBox( pParent, nStyle )
105 , m_pListBoxListener( pListBoxListener )
109 ListBoxControl::~ListBoxControl()
111 m_pListBoxListener = 0;
114 void ListBoxControl::Select()
116 ListBox::Select();
117 if ( m_pListBoxListener )
118 m_pListBoxListener->Select();
121 void ListBoxControl::DoubleClick()
123 ListBox::DoubleClick();
124 if ( m_pListBoxListener )
125 m_pListBoxListener->DoubleClick();
128 void ListBoxControl::GetFocus()
130 ListBox::GetFocus();
131 if ( m_pListBoxListener )
132 m_pListBoxListener->GetFocus();
135 void ListBoxControl::LoseFocus()
137 ListBox::LoseFocus();
138 if ( m_pListBoxListener )
139 m_pListBoxListener->LoseFocus();
142 long ListBoxControl::PreNotify( NotifyEvent& rNEvt )
144 long nRet( 0 );
145 if ( m_pListBoxListener )
146 nRet = m_pListBoxListener->PreNotify( rNEvt );
147 if ( nRet == 0 )
148 nRet = ListBox::PreNotify( rNEvt );
150 return nRet;
153 // ------------------------------------------------------------------
155 DropdownToolbarController::DropdownToolbarController(
156 const Reference< XMultiServiceFactory >& rServiceManager,
157 const Reference< XFrame >& rFrame,
158 ToolBox* pToolbar,
159 USHORT nID,
160 sal_Int32 nWidth,
161 const ::rtl::OUString& aCommand ) :
162 ComplexToolbarController( rServiceManager, rFrame, pToolbar, nID, aCommand )
163 , m_pListBoxControl( 0 )
165 m_pListBoxControl = new ListBoxControl( m_pToolbar, WB_DROPDOWN|WB_AUTOHSCROLL|WB_BORDER, this );
166 if ( nWidth == 0 )
167 nWidth = 100;
169 // default dropdown size
170 ::Size aLogicalSize( 0, 160 );
171 ::Size aPixelSize = m_pListBoxControl->LogicToPixel( aLogicalSize, MAP_APPFONT );
173 m_pListBoxControl->SetSizePixel( ::Size( nWidth, aPixelSize.Height() ));
174 m_pToolbar->SetItemWindow( m_nID, m_pListBoxControl );
175 m_pListBoxControl->SetDropDownLineCount( 5 );
178 // ------------------------------------------------------------------
180 DropdownToolbarController::~DropdownToolbarController()
184 // ------------------------------------------------------------------
186 void SAL_CALL DropdownToolbarController::dispose()
187 throw ( RuntimeException )
189 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
191 m_pToolbar->SetItemWindow( m_nID, 0 );
192 delete m_pListBoxControl;
194 ComplexToolbarController::dispose();
196 m_pListBoxControl = 0;
199 // ------------------------------------------------------------------
200 Sequence<PropertyValue> DropdownToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
202 Sequence<PropertyValue> aArgs( 2 );
203 ::rtl::OUString aSelectedText = m_pListBoxControl->GetText();
205 // Add key modifier to argument list
206 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "KeyModifier" ));
207 aArgs[0].Value <<= KeyModifier;
208 aArgs[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ));
209 aArgs[1].Value <<= aSelectedText;
210 return aArgs;
213 // ------------------------------------------------------------------
215 void DropdownToolbarController::Select()
217 if ( m_pListBoxControl->GetEntryCount() > 0 )
219 Window::PointerState aState = m_pListBoxControl->GetPointerState();
221 sal_uInt16 nKeyModifier = sal_uInt16( aState.mnState & KEY_MODTYPE );
222 execute( nKeyModifier );
226 void DropdownToolbarController::DoubleClick()
230 void DropdownToolbarController::GetFocus()
232 notifyFocusGet();
235 void DropdownToolbarController::LoseFocus()
237 notifyFocusLost();
240 long DropdownToolbarController::PreNotify( NotifyEvent& /*rNEvt*/ )
242 return 0;
245 // --------------------------------------------------------
247 void DropdownToolbarController::executeControlCommand( const ::com::sun::star::frame::ControlCommand& rControlCommand )
249 if ( rControlCommand.Command.equalsAsciiL( "SetList", 7 ))
251 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
253 if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "List", 4 ))
255 Sequence< ::rtl::OUString > aList;
256 m_pListBoxControl->Clear();
258 rControlCommand.Arguments[i].Value >>= aList;
259 for ( sal_Int32 j = 0; j < aList.getLength(); j++ )
260 m_pListBoxControl->InsertEntry( aList[j] );
262 m_pListBoxControl->SelectEntryPos( 0 );
264 // send notification
265 uno::Sequence< beans::NamedValue > aInfo( 1 );
266 aInfo[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "List" ));
267 aInfo[0].Value <<= aList;
268 addNotifyInfo( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ListChanged" )),
269 getDispatchFromCommand( m_aCommandURL ),
270 aInfo );
272 break;
276 else if ( rControlCommand.Command.equalsAsciiL( "AddEntry", 8 ))
278 sal_uInt16 nPos( LISTBOX_APPEND );
279 rtl::OUString aText;
280 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
282 if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
284 if ( rControlCommand.Arguments[i].Value >>= aText )
285 m_pListBoxControl->InsertEntry( aText, nPos );
286 break;
290 else if ( rControlCommand.Command.equalsAsciiL( "InsertEntry", 11 ))
292 sal_uInt16 nPos( LISTBOX_APPEND );
293 rtl::OUString aText;
294 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
296 if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Pos", 3 ))
298 sal_Int32 nTmpPos = 0;
299 if ( rControlCommand.Arguments[i].Value >>= nTmpPos )
301 if (( nTmpPos >= 0 ) &&
302 ( nTmpPos < sal_Int32( m_pListBoxControl->GetEntryCount() )))
303 nPos = sal_uInt16( nTmpPos );
306 else if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
307 rControlCommand.Arguments[i].Value >>= aText;
310 m_pListBoxControl->InsertEntry( aText, nPos );
312 else if ( rControlCommand.Command.equalsAsciiL( "RemoveEntryPos", 14 ))
314 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
316 if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Pos", 3 ))
318 sal_Int32 nPos( -1 );
319 if ( rControlCommand.Arguments[i].Value >>= nPos )
321 if ( nPos < sal_Int32( m_pListBoxControl->GetEntryCount() ))
322 m_pListBoxControl->RemoveEntry( sal_uInt16( nPos ));
324 break;
328 else if ( rControlCommand.Command.equalsAsciiL( "RemoveEntryText", 15 ))
330 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
332 if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
334 rtl::OUString aText;
335 if ( rControlCommand.Arguments[i].Value >>= aText )
336 m_pListBoxControl->RemoveEntry( aText );
337 break;
341 else if ( rControlCommand.Command.equalsAsciiL( "SetDropDownLines", 16 ))
343 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
345 if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Lines", 5 ))
347 sal_Int32 nValue( 5 );
348 rControlCommand.Arguments[i].Value >>= nValue;
349 m_pListBoxControl->SetDropDownLineCount( sal_uInt16( nValue ));
350 break;
356 } // namespace