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