2010-10-12 15:57:08 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2004-03-19 11:03:43 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 10:06:42 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2004-03-19 11:03:43 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2004-03-19 11:03:43 +00:00
|
|
|
*
|
2008-04-11 10:06:42 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2004-03-19 11:03:43 +00:00
|
|
|
*
|
2008-04-11 10:06:42 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2004-03-19 11:03:43 +00:00
|
|
|
*
|
2008-04-11 10:06:42 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2004-03-19 11:03:43 +00:00
|
|
|
*
|
2008-04-11 10:06:42 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2004-03-19 11:03:43 +00:00
|
|
|
*
|
2008-04-11 10:06:42 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2004-03-19 11:03:43 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 12:20:17 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_extensions.hxx"
|
2004-03-19 11:03:43 +00:00
|
|
|
#include "listselectiondlg.hxx"
|
|
|
|
#include "listselectiondlg.hrc"
|
|
|
|
|
|
|
|
#include "modulepcr.hxx"
|
|
|
|
#include "formresid.hrc"
|
|
|
|
#include "formstrings.hxx"
|
|
|
|
#include <vcl/msgbox.hxx>
|
|
|
|
|
|
|
|
/** === begin UNO includes === **/
|
|
|
|
/** === end UNO includes === **/
|
|
|
|
|
|
|
|
//........................................................................
|
|
|
|
namespace pcr
|
|
|
|
{
|
|
|
|
//........................................................................
|
|
|
|
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
|
|
|
|
//====================================================================
|
|
|
|
//= ListSelectionDialog
|
|
|
|
//====================================================================
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
ListSelectionDialog::ListSelectionDialog( Window* _pParent, const Reference< XPropertySet >& _rxListBox,
|
|
|
|
const ::rtl::OUString& _rPropertyName, const String& _rPropertyUIName )
|
2006-03-14 10:26:08 +00:00
|
|
|
:ModalDialog( _pParent, PcrRes( RID_DLG_SELECTION ) )
|
2007-04-26 07:08:07 +00:00
|
|
|
,m_aLabel ( this, PcrRes( FT_ENTRIES ) )
|
|
|
|
,m_aEntries ( this, PcrRes( LB_ENTRIES ) )
|
|
|
|
,m_aOK ( this, PcrRes( PB_OK ) )
|
|
|
|
,m_aCancel ( this, PcrRes( PB_CANCEL ) )
|
|
|
|
,m_aHelp ( this, PcrRes( PB_HELP ) )
|
2004-03-19 11:03:43 +00:00
|
|
|
,m_xListBox ( _rxListBox )
|
|
|
|
,m_sPropertyName( _rPropertyName )
|
|
|
|
{
|
|
|
|
FreeResource();
|
|
|
|
|
|
|
|
OSL_PRECOND( m_xListBox.is(), "ListSelectionDialog::ListSelectionDialog: invalid list box!" );
|
|
|
|
|
|
|
|
SetText( _rPropertyUIName );
|
|
|
|
m_aLabel.SetText( _rPropertyUIName );
|
|
|
|
|
|
|
|
initialize( );
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
short ListSelectionDialog::Execute()
|
|
|
|
{
|
|
|
|
short nResult = ModalDialog::Execute();
|
|
|
|
|
|
|
|
if ( RET_OK == nResult )
|
|
|
|
commitSelection();
|
|
|
|
|
|
|
|
return nResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void ListSelectionDialog::initialize( )
|
|
|
|
{
|
|
|
|
if ( !m_xListBox.is() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_aEntries.SetStyle( GetStyle() | WB_SIMPLEMODE );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// initialize the multi-selection flag
|
|
|
|
sal_Bool bMultiSelection = sal_False;
|
|
|
|
OSL_VERIFY( m_xListBox->getPropertyValue( PROPERTY_MULTISELECTION ) >>= bMultiSelection );
|
|
|
|
m_aEntries.EnableMultiSelection( bMultiSelection );
|
|
|
|
|
|
|
|
// fill the list box with all entries
|
|
|
|
Sequence< ::rtl::OUString > aListEntries;
|
|
|
|
OSL_VERIFY( m_xListBox->getPropertyValue( PROPERTY_STRINGITEMLIST ) >>= aListEntries );
|
|
|
|
fillEntryList( aListEntries );
|
|
|
|
|
|
|
|
// select entries according to the property
|
|
|
|
Sequence< sal_Int16 > aSelection;
|
|
|
|
OSL_VERIFY( m_xListBox->getPropertyValue( m_sPropertyName ) >>= aSelection );
|
|
|
|
selectEntries( aSelection );
|
|
|
|
}
|
|
|
|
catch( const Exception& )
|
|
|
|
{
|
|
|
|
OSL_ENSURE( sal_False, "ListSelectionDialog::initialize: caught an exception!" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void ListSelectionDialog::commitSelection()
|
|
|
|
{
|
|
|
|
if ( !m_xListBox.is() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
Sequence< sal_Int16 > aSelection;
|
|
|
|
collectSelection( aSelection );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
m_xListBox->setPropertyValue( m_sPropertyName, makeAny( aSelection ) );
|
|
|
|
}
|
|
|
|
catch( const Exception& )
|
|
|
|
{
|
|
|
|
OSL_ENSURE( sal_False, "ListSelectionDialog::commitSelection: caught an exception!" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void ListSelectionDialog::fillEntryList( const Sequence< ::rtl::OUString >& _rListEntries )
|
|
|
|
{
|
|
|
|
m_aEntries.Clear();
|
|
|
|
const ::rtl::OUString* _pListEntries = _rListEntries.getConstArray();
|
|
|
|
const ::rtl::OUString* _pListEntriesEnd = _rListEntries.getConstArray() + _rListEntries.getLength();
|
|
|
|
for ( ; _pListEntries < _pListEntriesEnd; ++_pListEntries )
|
|
|
|
m_aEntries.InsertEntry( *_pListEntries );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void ListSelectionDialog::collectSelection( Sequence< sal_Int16 >& /* [out] */ _rSelection )
|
|
|
|
{
|
|
|
|
sal_uInt16 nSelectedCount = m_aEntries.GetSelectEntryCount( );
|
|
|
|
_rSelection.realloc( nSelectedCount );
|
|
|
|
sal_Int16* pSelection = _rSelection.getArray();
|
|
|
|
for ( sal_uInt16 selected = 0; selected < nSelectedCount; ++selected, ++pSelection )
|
|
|
|
*pSelection = static_cast< sal_Int16 >( m_aEntries.GetSelectEntryPos( selected ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void ListSelectionDialog::selectEntries( const Sequence< sal_Int16 >& /* [in ] */ _rSelection )
|
|
|
|
{
|
|
|
|
m_aEntries.SetNoSelection();
|
|
|
|
const sal_Int16* pSelection = _rSelection.getConstArray();
|
|
|
|
const sal_Int16* pSelectionEnd = _rSelection.getConstArray() + _rSelection.getLength();
|
|
|
|
for ( ; pSelection != pSelectionEnd; ++pSelection )
|
|
|
|
m_aEntries.SelectEntryPos( *pSelection );
|
|
|
|
}
|
|
|
|
|
|
|
|
//........................................................................
|
|
|
|
} // namespace pcr
|
|
|
|
//........................................................................
|
2010-10-12 15:57:08 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|