1cdf0e10cSrcweir /************************************************************************* 2cdf0e10cSrcweir * 3cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4cdf0e10cSrcweir * 5cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6cdf0e10cSrcweir * 7cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8cdf0e10cSrcweir * 9cdf0e10cSrcweir * This file is part of OpenOffice.org. 10cdf0e10cSrcweir * 11cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14cdf0e10cSrcweir * 15cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20cdf0e10cSrcweir * 21cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25cdf0e10cSrcweir * 26cdf0e10cSrcweir ************************************************************************/ 27cdf0e10cSrcweir 28cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29cdf0e10cSrcweir #include "precompiled_framework.hxx" 30cdf0e10cSrcweir 31cdf0e10cSrcweir #ifndef __FRAMEWORK_UIELEMENT_DROPDOWNBOXTOOLBARCONTROLLER_HXX 32cdf0e10cSrcweir #include "uielement/dropdownboxtoolbarcontroller.hxx" 33cdf0e10cSrcweir #endif 34cdf0e10cSrcweir 35cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 36cdf0e10cSrcweir // my own includes 37cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 38cdf0e10cSrcweir 39cdf0e10cSrcweir #ifndef __FRAMEWORK_TOOLBAR_HXX_ 40cdf0e10cSrcweir #include "uielement/toolbar.hxx" 41cdf0e10cSrcweir #endif 42cdf0e10cSrcweir 43cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 44cdf0e10cSrcweir // interface includes 45cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 46cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp> 47cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 48cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 49cdf0e10cSrcweir #include <com/sun/star/frame/status/ItemStatus.hpp> 50cdf0e10cSrcweir #include <com/sun/star/frame/status/ItemState.hpp> 51cdf0e10cSrcweir #include <com/sun/star/frame/status/Visibility.hpp> 52cdf0e10cSrcweir #include <com/sun/star/frame/XControlNotificationListener.hpp> 53cdf0e10cSrcweir 54cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 55cdf0e10cSrcweir // other includes 56cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 57cdf0e10cSrcweir #include <svtools/toolboxcontroller.hxx> 58cdf0e10cSrcweir #include <vos/mutex.hxx> 59cdf0e10cSrcweir #include <vcl/svapp.hxx> 60cdf0e10cSrcweir #ifndef _VCL_MNEMONIC_HXX_ 61cdf0e10cSrcweir #include <vcl/mnemonic.hxx> 62cdf0e10cSrcweir #endif 63cdf0e10cSrcweir #include <tools/urlobj.hxx> 64cdf0e10cSrcweir 65cdf0e10cSrcweir using namespace ::com::sun::star; 66cdf0e10cSrcweir using namespace ::com::sun::star::awt; 67cdf0e10cSrcweir using namespace ::com::sun::star::uno; 68cdf0e10cSrcweir using namespace ::com::sun::star::beans; 69cdf0e10cSrcweir using namespace ::com::sun::star::lang; 70cdf0e10cSrcweir using namespace ::com::sun::star::frame; 71cdf0e10cSrcweir using namespace ::com::sun::star::frame::status; 72cdf0e10cSrcweir using namespace ::com::sun::star::util; 73cdf0e10cSrcweir 74cdf0e10cSrcweir namespace framework 75cdf0e10cSrcweir { 76cdf0e10cSrcweir 77cdf0e10cSrcweir // ------------------------------------------------------------------ 78cdf0e10cSrcweir 79cdf0e10cSrcweir // Wrapper class to notify controller about events from ListBox. 80cdf0e10cSrcweir // Unfortunaltly the events are notifed through virtual methods instead 81cdf0e10cSrcweir // of Listeners. 82cdf0e10cSrcweir 83cdf0e10cSrcweir class ListBoxControl : public ListBox 84cdf0e10cSrcweir { 85cdf0e10cSrcweir public: 86cdf0e10cSrcweir ListBoxControl( Window* pParent, WinBits nStyle, IListBoxListener* pListBoxListener ); 87cdf0e10cSrcweir virtual ~ListBoxControl(); 88cdf0e10cSrcweir 89cdf0e10cSrcweir virtual void Select(); 90cdf0e10cSrcweir virtual void DoubleClick(); 91cdf0e10cSrcweir virtual void GetFocus(); 92cdf0e10cSrcweir virtual void LoseFocus(); 93cdf0e10cSrcweir virtual long PreNotify( NotifyEvent& rNEvt ); 94cdf0e10cSrcweir 95cdf0e10cSrcweir private: 96cdf0e10cSrcweir IListBoxListener* m_pListBoxListener; 97cdf0e10cSrcweir }; 98cdf0e10cSrcweir 99cdf0e10cSrcweir ListBoxControl::ListBoxControl( Window* pParent, WinBits nStyle, IListBoxListener* pListBoxListener ) : 100cdf0e10cSrcweir ListBox( pParent, nStyle ) 101cdf0e10cSrcweir , m_pListBoxListener( pListBoxListener ) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir ListBoxControl::~ListBoxControl() 106cdf0e10cSrcweir { 107cdf0e10cSrcweir m_pListBoxListener = 0; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir 110cdf0e10cSrcweir void ListBoxControl::Select() 111cdf0e10cSrcweir { 112cdf0e10cSrcweir ListBox::Select(); 113cdf0e10cSrcweir if ( m_pListBoxListener ) 114cdf0e10cSrcweir m_pListBoxListener->Select(); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir void ListBoxControl::DoubleClick() 118cdf0e10cSrcweir { 119cdf0e10cSrcweir ListBox::DoubleClick(); 120cdf0e10cSrcweir if ( m_pListBoxListener ) 121cdf0e10cSrcweir m_pListBoxListener->DoubleClick(); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir void ListBoxControl::GetFocus() 125cdf0e10cSrcweir { 126cdf0e10cSrcweir ListBox::GetFocus(); 127cdf0e10cSrcweir if ( m_pListBoxListener ) 128cdf0e10cSrcweir m_pListBoxListener->GetFocus(); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir void ListBoxControl::LoseFocus() 132cdf0e10cSrcweir { 133cdf0e10cSrcweir ListBox::LoseFocus(); 134cdf0e10cSrcweir if ( m_pListBoxListener ) 135cdf0e10cSrcweir m_pListBoxListener->LoseFocus(); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir long ListBoxControl::PreNotify( NotifyEvent& rNEvt ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir long nRet( 0 ); 141cdf0e10cSrcweir if ( m_pListBoxListener ) 142cdf0e10cSrcweir nRet = m_pListBoxListener->PreNotify( rNEvt ); 143cdf0e10cSrcweir if ( nRet == 0 ) 144cdf0e10cSrcweir nRet = ListBox::PreNotify( rNEvt ); 145cdf0e10cSrcweir 146cdf0e10cSrcweir return nRet; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir // ------------------------------------------------------------------ 150cdf0e10cSrcweir 151cdf0e10cSrcweir DropdownToolbarController::DropdownToolbarController( 152cdf0e10cSrcweir const Reference< XMultiServiceFactory >& rServiceManager, 153cdf0e10cSrcweir const Reference< XFrame >& rFrame, 154cdf0e10cSrcweir ToolBox* pToolbar, 155cdf0e10cSrcweir sal_uInt16 nID, 156cdf0e10cSrcweir sal_Int32 nWidth, 157cdf0e10cSrcweir const ::rtl::OUString& aCommand ) : 158cdf0e10cSrcweir ComplexToolbarController( rServiceManager, rFrame, pToolbar, nID, aCommand ) 159cdf0e10cSrcweir , m_pListBoxControl( 0 ) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir m_pListBoxControl = new ListBoxControl( m_pToolbar, WB_DROPDOWN|WB_AUTOHSCROLL|WB_BORDER, this ); 162cdf0e10cSrcweir if ( nWidth == 0 ) 163cdf0e10cSrcweir nWidth = 100; 164cdf0e10cSrcweir 165cdf0e10cSrcweir // default dropdown size 166cdf0e10cSrcweir ::Size aLogicalSize( 0, 160 ); 167cdf0e10cSrcweir ::Size aPixelSize = m_pListBoxControl->LogicToPixel( aLogicalSize, MAP_APPFONT ); 168cdf0e10cSrcweir 169cdf0e10cSrcweir m_pListBoxControl->SetSizePixel( ::Size( nWidth, aPixelSize.Height() )); 170cdf0e10cSrcweir m_pToolbar->SetItemWindow( m_nID, m_pListBoxControl ); 171cdf0e10cSrcweir m_pListBoxControl->SetDropDownLineCount( 5 ); 172cdf0e10cSrcweir } 173cdf0e10cSrcweir 174cdf0e10cSrcweir // ------------------------------------------------------------------ 175cdf0e10cSrcweir 176cdf0e10cSrcweir DropdownToolbarController::~DropdownToolbarController() 177cdf0e10cSrcweir { 178cdf0e10cSrcweir } 179cdf0e10cSrcweir 180cdf0e10cSrcweir // ------------------------------------------------------------------ 181cdf0e10cSrcweir 182cdf0e10cSrcweir void SAL_CALL DropdownToolbarController::dispose() 183cdf0e10cSrcweir throw ( RuntimeException ) 184cdf0e10cSrcweir { 185cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 186cdf0e10cSrcweir 187cdf0e10cSrcweir m_pToolbar->SetItemWindow( m_nID, 0 ); 188cdf0e10cSrcweir delete m_pListBoxControl; 189cdf0e10cSrcweir 190cdf0e10cSrcweir ComplexToolbarController::dispose(); 191cdf0e10cSrcweir 192cdf0e10cSrcweir m_pListBoxControl = 0; 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir // ------------------------------------------------------------------ 196cdf0e10cSrcweir Sequence<PropertyValue> DropdownToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const 197cdf0e10cSrcweir { 198cdf0e10cSrcweir Sequence<PropertyValue> aArgs( 2 ); 199*fcc33d43SPedro Giffuni ::rtl::OUString aSelectedText = m_pListBoxControl->GetSelectEntry(); 200cdf0e10cSrcweir 201cdf0e10cSrcweir // Add key modifier to argument list 202cdf0e10cSrcweir aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "KeyModifier" )); 203cdf0e10cSrcweir aArgs[0].Value <<= KeyModifier; 204cdf0e10cSrcweir aArgs[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" )); 205cdf0e10cSrcweir aArgs[1].Value <<= aSelectedText; 206cdf0e10cSrcweir return aArgs; 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir // ------------------------------------------------------------------ 210cdf0e10cSrcweir 211cdf0e10cSrcweir void DropdownToolbarController::Select() 212cdf0e10cSrcweir { 213cdf0e10cSrcweir if ( m_pListBoxControl->GetEntryCount() > 0 ) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir Window::PointerState aState = m_pListBoxControl->GetPointerState(); 216cdf0e10cSrcweir 217cdf0e10cSrcweir sal_uInt16 nKeyModifier = sal_uInt16( aState.mnState & KEY_MODTYPE ); 218cdf0e10cSrcweir execute( nKeyModifier ); 219cdf0e10cSrcweir } 220cdf0e10cSrcweir } 221cdf0e10cSrcweir 222cdf0e10cSrcweir void DropdownToolbarController::DoubleClick() 223cdf0e10cSrcweir { 224cdf0e10cSrcweir } 225cdf0e10cSrcweir 226cdf0e10cSrcweir void DropdownToolbarController::GetFocus() 227cdf0e10cSrcweir { 228cdf0e10cSrcweir notifyFocusGet(); 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir void DropdownToolbarController::LoseFocus() 232cdf0e10cSrcweir { 233cdf0e10cSrcweir notifyFocusLost(); 234cdf0e10cSrcweir } 235cdf0e10cSrcweir 236cdf0e10cSrcweir long DropdownToolbarController::PreNotify( NotifyEvent& /*rNEvt*/ ) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir return 0; 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir // -------------------------------------------------------- 242cdf0e10cSrcweir 243cdf0e10cSrcweir void DropdownToolbarController::executeControlCommand( const ::com::sun::star::frame::ControlCommand& rControlCommand ) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir if ( rControlCommand.Command.equalsAsciiL( "SetList", 7 )) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ ) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "List", 4 )) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir Sequence< ::rtl::OUString > aList; 252cdf0e10cSrcweir m_pListBoxControl->Clear(); 253cdf0e10cSrcweir 254cdf0e10cSrcweir rControlCommand.Arguments[i].Value >>= aList; 255cdf0e10cSrcweir for ( sal_Int32 j = 0; j < aList.getLength(); j++ ) 256cdf0e10cSrcweir m_pListBoxControl->InsertEntry( aList[j] ); 257cdf0e10cSrcweir 258cdf0e10cSrcweir m_pListBoxControl->SelectEntryPos( 0 ); 259cdf0e10cSrcweir 260cdf0e10cSrcweir // send notification 261cdf0e10cSrcweir uno::Sequence< beans::NamedValue > aInfo( 1 ); 262cdf0e10cSrcweir aInfo[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "List" )); 263cdf0e10cSrcweir aInfo[0].Value <<= aList; 264cdf0e10cSrcweir addNotifyInfo( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ListChanged" )), 265cdf0e10cSrcweir getDispatchFromCommand( m_aCommandURL ), 266cdf0e10cSrcweir aInfo ); 267cdf0e10cSrcweir 268cdf0e10cSrcweir break; 269cdf0e10cSrcweir } 270cdf0e10cSrcweir } 271cdf0e10cSrcweir } 272cdf0e10cSrcweir else if ( rControlCommand.Command.equalsAsciiL( "AddEntry", 8 )) 273cdf0e10cSrcweir { 274cdf0e10cSrcweir sal_uInt16 nPos( LISTBOX_APPEND ); 275cdf0e10cSrcweir rtl::OUString aText; 276cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ ) 277cdf0e10cSrcweir { 278cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 )) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Value >>= aText ) 281cdf0e10cSrcweir m_pListBoxControl->InsertEntry( aText, nPos ); 282cdf0e10cSrcweir break; 283cdf0e10cSrcweir } 284cdf0e10cSrcweir } 285cdf0e10cSrcweir } 286cdf0e10cSrcweir else if ( rControlCommand.Command.equalsAsciiL( "InsertEntry", 11 )) 287cdf0e10cSrcweir { 288cdf0e10cSrcweir sal_uInt16 nPos( LISTBOX_APPEND ); 289cdf0e10cSrcweir rtl::OUString aText; 290cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ ) 291cdf0e10cSrcweir { 292cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Pos", 3 )) 293cdf0e10cSrcweir { 294cdf0e10cSrcweir sal_Int32 nTmpPos = 0; 295cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Value >>= nTmpPos ) 296cdf0e10cSrcweir { 297cdf0e10cSrcweir if (( nTmpPos >= 0 ) && 298cdf0e10cSrcweir ( nTmpPos < sal_Int32( m_pListBoxControl->GetEntryCount() ))) 299cdf0e10cSrcweir nPos = sal_uInt16( nTmpPos ); 300cdf0e10cSrcweir } 301cdf0e10cSrcweir } 302cdf0e10cSrcweir else if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 )) 303cdf0e10cSrcweir rControlCommand.Arguments[i].Value >>= aText; 304cdf0e10cSrcweir } 305cdf0e10cSrcweir 306cdf0e10cSrcweir m_pListBoxControl->InsertEntry( aText, nPos ); 307cdf0e10cSrcweir } 308cdf0e10cSrcweir else if ( rControlCommand.Command.equalsAsciiL( "RemoveEntryPos", 14 )) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ ) 311cdf0e10cSrcweir { 312cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Pos", 3 )) 313cdf0e10cSrcweir { 314cdf0e10cSrcweir sal_Int32 nPos( -1 ); 315cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Value >>= nPos ) 316cdf0e10cSrcweir { 317cdf0e10cSrcweir if ( nPos < sal_Int32( m_pListBoxControl->GetEntryCount() )) 318cdf0e10cSrcweir m_pListBoxControl->RemoveEntry( sal_uInt16( nPos )); 319cdf0e10cSrcweir } 320cdf0e10cSrcweir break; 321cdf0e10cSrcweir } 322cdf0e10cSrcweir } 323cdf0e10cSrcweir } 324cdf0e10cSrcweir else if ( rControlCommand.Command.equalsAsciiL( "RemoveEntryText", 15 )) 325cdf0e10cSrcweir { 326cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ ) 327cdf0e10cSrcweir { 328cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 )) 329cdf0e10cSrcweir { 330cdf0e10cSrcweir rtl::OUString aText; 331cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Value >>= aText ) 332cdf0e10cSrcweir m_pListBoxControl->RemoveEntry( aText ); 333cdf0e10cSrcweir break; 334cdf0e10cSrcweir } 335cdf0e10cSrcweir } 336cdf0e10cSrcweir } 337cdf0e10cSrcweir else if ( rControlCommand.Command.equalsAsciiL( "SetDropDownLines", 16 )) 338cdf0e10cSrcweir { 339cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ ) 340cdf0e10cSrcweir { 341cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Lines", 5 )) 342cdf0e10cSrcweir { 343cdf0e10cSrcweir sal_Int32 nValue( 5 ); 344cdf0e10cSrcweir rControlCommand.Arguments[i].Value >>= nValue; 345cdf0e10cSrcweir m_pListBoxControl->SetDropDownLineCount( sal_uInt16( nValue )); 346cdf0e10cSrcweir break; 347cdf0e10cSrcweir } 348cdf0e10cSrcweir } 349cdf0e10cSrcweir } 350cdf0e10cSrcweir } 351cdf0e10cSrcweir 352cdf0e10cSrcweir } // namespace 353cdf0e10cSrcweir 354