1*2a97ec55SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2a97ec55SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2a97ec55SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2a97ec55SAndrew Rist * distributed with this work for additional information 6*2a97ec55SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2a97ec55SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2a97ec55SAndrew Rist * "License"); you may not use this file except in compliance 9*2a97ec55SAndrew Rist * with the License. You may obtain a copy of the License at 10*2a97ec55SAndrew Rist * 11*2a97ec55SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*2a97ec55SAndrew Rist * 13*2a97ec55SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2a97ec55SAndrew Rist * software distributed under the License is distributed on an 15*2a97ec55SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2a97ec55SAndrew Rist * KIND, either express or implied. See the License for the 17*2a97ec55SAndrew Rist * specific language governing permissions and limitations 18*2a97ec55SAndrew Rist * under the License. 19*2a97ec55SAndrew Rist * 20*2a97ec55SAndrew Rist *************************************************************/ 21*2a97ec55SAndrew Rist 22*2a97ec55SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_extensions.hxx" 26cdf0e10cSrcweir #include "listselectiondlg.hxx" 27cdf0e10cSrcweir #ifndef EXTENSIONS_SOURCE_PROPCTRLR_LISTSELECTIONDLG_HRC 28cdf0e10cSrcweir #include "listselectiondlg.hrc" 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir 31cdf0e10cSrcweir #ifndef _EXTENSIONS_PROPCTRLR_MODULEPRC_HXX_ 32cdf0e10cSrcweir #include "modulepcr.hxx" 33cdf0e10cSrcweir #endif 34cdf0e10cSrcweir #ifndef _EXTENSIONS_FORMCTRLR_PROPRESID_HRC_ 35cdf0e10cSrcweir #include "formresid.hrc" 36cdf0e10cSrcweir #endif 37cdf0e10cSrcweir #include "formstrings.hxx" 38cdf0e10cSrcweir #include <vcl/msgbox.hxx> 39cdf0e10cSrcweir 40cdf0e10cSrcweir /** === begin UNO includes === **/ 41cdf0e10cSrcweir /** === end UNO includes === **/ 42cdf0e10cSrcweir 43cdf0e10cSrcweir //........................................................................ 44cdf0e10cSrcweir namespace pcr 45cdf0e10cSrcweir { 46cdf0e10cSrcweir //........................................................................ 47cdf0e10cSrcweir 48cdf0e10cSrcweir using namespace ::com::sun::star::uno; 49cdf0e10cSrcweir using namespace ::com::sun::star::beans; 50cdf0e10cSrcweir 51cdf0e10cSrcweir //==================================================================== 52cdf0e10cSrcweir //= ListSelectionDialog 53cdf0e10cSrcweir //==================================================================== 54cdf0e10cSrcweir //-------------------------------------------------------------------- ListSelectionDialog(Window * _pParent,const Reference<XPropertySet> & _rxListBox,const::rtl::OUString & _rPropertyName,const String & _rPropertyUIName)55cdf0e10cSrcweir ListSelectionDialog::ListSelectionDialog( Window* _pParent, const Reference< XPropertySet >& _rxListBox, 56cdf0e10cSrcweir const ::rtl::OUString& _rPropertyName, const String& _rPropertyUIName ) 57cdf0e10cSrcweir :ModalDialog( _pParent, PcrRes( RID_DLG_SELECTION ) ) 58cdf0e10cSrcweir ,m_aLabel ( this, PcrRes( FT_ENTRIES ) ) 59cdf0e10cSrcweir ,m_aEntries ( this, PcrRes( LB_ENTRIES ) ) 60cdf0e10cSrcweir ,m_aOK ( this, PcrRes( PB_OK ) ) 61cdf0e10cSrcweir ,m_aCancel ( this, PcrRes( PB_CANCEL ) ) 62cdf0e10cSrcweir ,m_aHelp ( this, PcrRes( PB_HELP ) ) 63cdf0e10cSrcweir ,m_xListBox ( _rxListBox ) 64cdf0e10cSrcweir ,m_sPropertyName( _rPropertyName ) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir FreeResource(); 67cdf0e10cSrcweir 68cdf0e10cSrcweir OSL_PRECOND( m_xListBox.is(), "ListSelectionDialog::ListSelectionDialog: invalid list box!" ); 69cdf0e10cSrcweir 70cdf0e10cSrcweir SetText( _rPropertyUIName ); 71cdf0e10cSrcweir m_aLabel.SetText( _rPropertyUIName ); 72cdf0e10cSrcweir 73cdf0e10cSrcweir initialize( ); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir //------------------------------------------------------------------------ Execute()77cdf0e10cSrcweir short ListSelectionDialog::Execute() 78cdf0e10cSrcweir { 79cdf0e10cSrcweir short nResult = ModalDialog::Execute(); 80cdf0e10cSrcweir 81cdf0e10cSrcweir if ( RET_OK == nResult ) 82cdf0e10cSrcweir commitSelection(); 83cdf0e10cSrcweir 84cdf0e10cSrcweir return nResult; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir //-------------------------------------------------------------------- initialize()88cdf0e10cSrcweir void ListSelectionDialog::initialize( ) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir if ( !m_xListBox.is() ) 91cdf0e10cSrcweir return; 92cdf0e10cSrcweir 93cdf0e10cSrcweir m_aEntries.SetStyle( GetStyle() | WB_SIMPLEMODE ); 94cdf0e10cSrcweir 95cdf0e10cSrcweir try 96cdf0e10cSrcweir { 97cdf0e10cSrcweir // initialize the multi-selection flag 98cdf0e10cSrcweir sal_Bool bMultiSelection = sal_False; 99cdf0e10cSrcweir OSL_VERIFY( m_xListBox->getPropertyValue( PROPERTY_MULTISELECTION ) >>= bMultiSelection ); 100cdf0e10cSrcweir m_aEntries.EnableMultiSelection( bMultiSelection ); 101cdf0e10cSrcweir 102cdf0e10cSrcweir // fill the list box with all entries 103cdf0e10cSrcweir Sequence< ::rtl::OUString > aListEntries; 104cdf0e10cSrcweir OSL_VERIFY( m_xListBox->getPropertyValue( PROPERTY_STRINGITEMLIST ) >>= aListEntries ); 105cdf0e10cSrcweir fillEntryList( aListEntries ); 106cdf0e10cSrcweir 107cdf0e10cSrcweir // select entries according to the property 108cdf0e10cSrcweir Sequence< sal_Int16 > aSelection; 109cdf0e10cSrcweir OSL_VERIFY( m_xListBox->getPropertyValue( m_sPropertyName ) >>= aSelection ); 110cdf0e10cSrcweir selectEntries( aSelection ); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir catch( const Exception& ) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir OSL_ENSURE( sal_False, "ListSelectionDialog::initialize: caught an exception!" ); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir //-------------------------------------------------------------------- commitSelection()119cdf0e10cSrcweir void ListSelectionDialog::commitSelection() 120cdf0e10cSrcweir { 121cdf0e10cSrcweir if ( !m_xListBox.is() ) 122cdf0e10cSrcweir return; 123cdf0e10cSrcweir 124cdf0e10cSrcweir Sequence< sal_Int16 > aSelection; 125cdf0e10cSrcweir collectSelection( aSelection ); 126cdf0e10cSrcweir 127cdf0e10cSrcweir try 128cdf0e10cSrcweir { 129cdf0e10cSrcweir m_xListBox->setPropertyValue( m_sPropertyName, makeAny( aSelection ) ); 130cdf0e10cSrcweir } 131cdf0e10cSrcweir catch( const Exception& ) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir OSL_ENSURE( sal_False, "ListSelectionDialog::commitSelection: caught an exception!" ); 134cdf0e10cSrcweir } 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir //-------------------------------------------------------------------- fillEntryList(const Sequence<::rtl::OUString> & _rListEntries)138cdf0e10cSrcweir void ListSelectionDialog::fillEntryList( const Sequence< ::rtl::OUString >& _rListEntries ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir m_aEntries.Clear(); 141cdf0e10cSrcweir const ::rtl::OUString* _pListEntries = _rListEntries.getConstArray(); 142cdf0e10cSrcweir const ::rtl::OUString* _pListEntriesEnd = _rListEntries.getConstArray() + _rListEntries.getLength(); 143cdf0e10cSrcweir for ( ; _pListEntries < _pListEntriesEnd; ++_pListEntries ) 144cdf0e10cSrcweir m_aEntries.InsertEntry( *_pListEntries ); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir //-------------------------------------------------------------------- collectSelection(Sequence<sal_Int16> & _rSelection)148cdf0e10cSrcweir void ListSelectionDialog::collectSelection( Sequence< sal_Int16 >& /* [out] */ _rSelection ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir sal_uInt16 nSelectedCount = m_aEntries.GetSelectEntryCount( ); 151cdf0e10cSrcweir _rSelection.realloc( nSelectedCount ); 152cdf0e10cSrcweir sal_Int16* pSelection = _rSelection.getArray(); 153cdf0e10cSrcweir for ( sal_uInt16 selected = 0; selected < nSelectedCount; ++selected, ++pSelection ) 154cdf0e10cSrcweir *pSelection = static_cast< sal_Int16 >( m_aEntries.GetSelectEntryPos( selected ) ); 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir //-------------------------------------------------------------------- selectEntries(const Sequence<sal_Int16> & _rSelection)158cdf0e10cSrcweir void ListSelectionDialog::selectEntries( const Sequence< sal_Int16 >& /* [in ] */ _rSelection ) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir m_aEntries.SetNoSelection(); 161cdf0e10cSrcweir const sal_Int16* pSelection = _rSelection.getConstArray(); 162cdf0e10cSrcweir const sal_Int16* pSelectionEnd = _rSelection.getConstArray() + _rSelection.getLength(); 163cdf0e10cSrcweir for ( ; pSelection != pSelectionEnd; ++pSelection ) 164cdf0e10cSrcweir m_aEntries.SelectEntryPos( *pSelection ); 165cdf0e10cSrcweir } 166cdf0e10cSrcweir 167cdf0e10cSrcweir //........................................................................ 168cdf0e10cSrcweir } // namespace pcr 169cdf0e10cSrcweir //........................................................................ 170