1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "listselectiondlg.hxx"
22 #include "modulepcr.hxx"
23 #include "formresid.hrc"
24 #include "formstrings.hxx"
25 #include <vcl/msgbox.hxx>
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::beans
;
32 ListSelectionDialog::ListSelectionDialog(vcl::Window
* _pParent
, const Reference
< XPropertySet
>& _rxListBox
,
33 const OUString
& _rPropertyName
, const OUString
& _rPropertyUIName
)
34 : ModalDialog( _pParent
, "ListSelectDialog", "modules/spropctrlr/ui/listselectdialog.ui" )
35 ,m_xListBox ( _rxListBox
)
36 ,m_sPropertyName( _rPropertyName
)
38 OSL_PRECOND( m_xListBox
.is(), "ListSelectionDialog::ListSelectionDialog: invalid list box!" );
40 get(m_pEntries
, "treeview");
41 Size
aSize(LogicToPixel(Size(85, 97), MAP_APPFONT
));
42 m_pEntries
->set_width_request(aSize
.Width());
43 m_pEntries
->set_height_request(aSize
.Height());
45 SetText(_rPropertyUIName
);
46 get
<VclFrame
>("frame")->set_label(_rPropertyUIName
);
51 ListSelectionDialog::~ListSelectionDialog()
56 void ListSelectionDialog::dispose()
59 ModalDialog::dispose();
62 short ListSelectionDialog::Execute()
64 short nResult
= ModalDialog::Execute();
66 if ( RET_OK
== nResult
)
73 void ListSelectionDialog::initialize( )
75 if ( !m_xListBox
.is() )
78 m_pEntries
->SetStyle( GetStyle() | WB_SIMPLEMODE
);
82 // initialize the multi-selection flag
83 bool bMultiSelection
= false;
84 OSL_VERIFY( m_xListBox
->getPropertyValue( PROPERTY_MULTISELECTION
) >>= bMultiSelection
);
85 m_pEntries
->EnableMultiSelection( bMultiSelection
);
87 // fill the list box with all entries
88 Sequence
< OUString
> aListEntries
;
89 OSL_VERIFY( m_xListBox
->getPropertyValue( PROPERTY_STRINGITEMLIST
) >>= aListEntries
);
90 fillEntryList( aListEntries
);
92 // select entries according to the property
93 Sequence
< sal_Int16
> aSelection
;
94 OSL_VERIFY( m_xListBox
->getPropertyValue( m_sPropertyName
) >>= aSelection
);
95 selectEntries( aSelection
);
97 catch( const Exception
& )
99 OSL_FAIL( "ListSelectionDialog::initialize: caught an exception!" );
104 void ListSelectionDialog::commitSelection()
106 if ( !m_xListBox
.is() )
109 Sequence
< sal_Int16
> aSelection
;
110 collectSelection( aSelection
);
114 m_xListBox
->setPropertyValue( m_sPropertyName
, makeAny( aSelection
) );
116 catch( const Exception
& )
118 OSL_FAIL( "ListSelectionDialog::commitSelection: caught an exception!" );
123 void ListSelectionDialog::fillEntryList( const Sequence
< OUString
>& _rListEntries
)
126 const OUString
* _pListEntries
= _rListEntries
.getConstArray();
127 const OUString
* _pListEntriesEnd
= _rListEntries
.getConstArray() + _rListEntries
.getLength();
128 for ( ; _pListEntries
< _pListEntriesEnd
; ++_pListEntries
)
129 m_pEntries
->InsertEntry( *_pListEntries
);
133 void ListSelectionDialog::collectSelection( Sequence
< sal_Int16
>& /* [out] */ _rSelection
)
135 sal_uInt16 nSelectedCount
= m_pEntries
->GetSelectEntryCount( );
136 _rSelection
.realloc( nSelectedCount
);
137 sal_Int16
* pSelection
= _rSelection
.getArray();
138 for ( sal_uInt16 selected
= 0; selected
< nSelectedCount
; ++selected
, ++pSelection
)
139 *pSelection
= static_cast< sal_Int16
>( m_pEntries
->GetSelectEntryPos( selected
) );
143 void ListSelectionDialog::selectEntries( const Sequence
< sal_Int16
>& /* [in ] */ _rSelection
)
145 m_pEntries
->SetNoSelection();
146 const sal_Int16
* pSelection
= _rSelection
.getConstArray();
147 const sal_Int16
* pSelectionEnd
= _rSelection
.getConstArray() + _rSelection
.getLength();
148 for ( ; pSelection
!= pSelectionEnd
; ++pSelection
)
149 m_pEntries
->SelectEntryPos( *pSelection
);
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */