2012-01-31 00:44:34 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
2013-04-19 21:10:42 +01:00
|
|
|
* This file is part of the LibreOffice project.
|
2012-01-31 00:44:34 +01:00
|
|
|
*
|
2013-04-19 21:10:42 +01:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2012-01-31 00:44:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iodlg.hrc>
|
|
|
|
#include <PlacesListBox.hxx>
|
2012-08-03 18:12:51 -04:30
|
|
|
#include <svtools/PlaceEditDialog.hxx>
|
2012-01-31 00:44:34 +01:00
|
|
|
|
|
|
|
#include <vcl/msgbox.hxx>
|
2012-03-27 18:01:07 +02:00
|
|
|
#include <svtools/headbar.hxx>
|
2012-04-25 15:33:16 +01:00
|
|
|
#include <svtools/svtresid.hxx>
|
2012-01-31 00:44:34 +01:00
|
|
|
|
2012-03-27 18:01:07 +02:00
|
|
|
#define COLUMN_NAME 1
|
|
|
|
|
2012-01-31 00:44:34 +01:00
|
|
|
|
2012-12-08 13:42:54 +02:00
|
|
|
PlacesListBox_Impl::PlacesListBox_Impl( PlacesListBox* pParent, const OUString& rTitle ) :
|
2012-04-27 14:38:50 +02:00
|
|
|
SvHeaderTabListBox( pParent, WB_TABSTOP | WB_NOINITIALSELECTION ),
|
2015-11-10 10:16:02 +01:00
|
|
|
mpHeaderBar( nullptr ),
|
2012-06-27 17:04:34 +02:00
|
|
|
mpParent( pParent )
|
2012-03-27 18:01:07 +02:00
|
|
|
{
|
|
|
|
Size aBoxSize = pParent->GetSizePixel( );
|
2015-04-16 22:09:41 +01:00
|
|
|
mpHeaderBar = VclPtr<HeaderBar>::Create( pParent, WB_BUTTONSTYLE | WB_BOTTOMBORDER );
|
2012-07-13 13:12:13 +02:00
|
|
|
mpHeaderBar->SetPosSizePixel( Point( 0, 0 ), Size( 600, 16 ) );
|
2012-03-27 18:01:07 +02:00
|
|
|
|
2012-07-13 13:12:13 +02:00
|
|
|
long pTabs[] = { 2, 20, 600 };
|
2016-09-20 16:41:39 +02:00
|
|
|
SetTabs( &pTabs[0], MapUnit::MapPixel );
|
2015-04-20 10:24:32 +02:00
|
|
|
mpHeaderBar->InsertItem( COLUMN_NAME, rTitle, 600, HeaderBarItemBits::LEFT | HeaderBarItemBits::VCENTER );
|
2012-03-27 18:01:07 +02:00
|
|
|
|
|
|
|
Size aHeadSize = mpHeaderBar->GetSizePixel();
|
|
|
|
SetPosSizePixel( Point( 0, aHeadSize.getHeight() ),
|
|
|
|
Size( aBoxSize.getWidth(), aBoxSize.getHeight() - aHeadSize.getHeight() ) );
|
|
|
|
|
|
|
|
InitHeaderBar( mpHeaderBar );
|
|
|
|
|
|
|
|
Show( );
|
|
|
|
mpHeaderBar->Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
PlacesListBox_Impl::~PlacesListBox_Impl( )
|
|
|
|
{
|
2015-03-10 09:07:06 +02:00
|
|
|
disposeOnce();
|
2015-01-26 13:11:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlacesListBox_Impl::dispose()
|
2012-03-27 18:01:07 +02:00
|
|
|
{
|
2015-04-10 10:44:13 +01:00
|
|
|
mpHeaderBar.disposeAndClear();
|
2015-03-09 14:29:30 +02:00
|
|
|
mpParent.clear();
|
2015-01-26 13:11:58 +02:00
|
|
|
SvHeaderTabListBox::dispose();
|
2012-06-27 17:04:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlacesListBox_Impl::MouseButtonUp( const MouseEvent& rMEvt )
|
|
|
|
{
|
|
|
|
SvHeaderTabListBox::MouseButtonUp( rMEvt );
|
|
|
|
mpParent->updateView( );
|
2012-03-27 18:01:07 +02:00
|
|
|
}
|
|
|
|
|
2014-09-23 11:20:40 +02:00
|
|
|
PlacesListBox::PlacesListBox( vcl::Window* pParent, SvtFileDialog* pFileDlg, const OUString& rTitle, WinBits nBits ) :
|
2014-06-28 16:10:39 +02:00
|
|
|
Control( pParent, nBits ),
|
2012-01-31 00:44:34 +01:00
|
|
|
maPlaces( ),
|
|
|
|
mpDlg( pFileDlg ),
|
2015-11-10 10:16:02 +01:00
|
|
|
mpImpl( nullptr ),
|
2012-07-13 17:16:40 +02:00
|
|
|
mpAddBtn( ),
|
|
|
|
mpDelBtn( ),
|
2012-01-31 00:44:34 +01:00
|
|
|
mnNbEditables( 0 ),
|
2012-06-27 17:04:34 +02:00
|
|
|
mbUpdated( false ),
|
|
|
|
mbSelectionChanged( false )
|
2012-01-31 00:44:34 +01:00
|
|
|
{
|
2015-04-16 22:09:41 +01:00
|
|
|
mpImpl = VclPtr<PlacesListBox_Impl>::Create( this, rTitle );
|
2012-03-27 18:01:07 +02:00
|
|
|
|
|
|
|
mpImpl->SetSelectHdl( LINK( this, PlacesListBox, Selection ) );
|
|
|
|
mpImpl->SetDoubleClickHdl( LINK( this, PlacesListBox, DoubleClick ) ) ;
|
2012-07-13 17:16:40 +02:00
|
|
|
|
2015-04-16 22:09:41 +01:00
|
|
|
mpAddBtn.reset( VclPtr<ImageButton>::Create( this, 0 ) );
|
2015-11-06 09:36:04 +01:00
|
|
|
mpAddBtn->SetText( "+" );
|
2013-11-13 12:58:09 +01:00
|
|
|
mpAddBtn->SetPosSizePixel( Point( 0, 0 ), Size( 22, 22 ) );
|
2012-07-13 17:16:40 +02:00
|
|
|
mpAddBtn->Show();
|
|
|
|
|
2015-04-16 22:09:41 +01:00
|
|
|
mpDelBtn.reset( VclPtr<ImageButton>::Create( this, 0 ) );
|
2015-11-06 09:36:04 +01:00
|
|
|
mpDelBtn->SetText( "-" );
|
2013-11-13 12:58:09 +01:00
|
|
|
mpDelBtn->SetPosSizePixel( Point( 0, 0 ), Size( 22, 22 ) );
|
2012-07-13 17:16:40 +02:00
|
|
|
mpDelBtn->Show();
|
2012-01-31 00:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
PlacesListBox::~PlacesListBox( )
|
|
|
|
{
|
2015-03-10 09:07:06 +02:00
|
|
|
disposeOnce();
|
2015-01-26 13:11:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlacesListBox::dispose()
|
2012-01-31 00:44:34 +01:00
|
|
|
{
|
2015-04-10 10:44:13 +01:00
|
|
|
mpImpl.disposeAndClear();
|
|
|
|
mpAddBtn.disposeAndClear();
|
|
|
|
mpDelBtn.disposeAndClear();
|
2015-03-09 14:29:30 +02:00
|
|
|
mpDlg.clear();
|
2015-01-26 13:11:58 +02:00
|
|
|
Control::dispose();
|
2012-01-31 00:44:34 +01:00
|
|
|
}
|
|
|
|
|
2016-04-12 12:08:00 +02:00
|
|
|
void PlacesListBox::AppendPlace( const PlacePtr& pPlace )
|
2012-01-31 00:44:34 +01:00
|
|
|
{
|
|
|
|
maPlaces.push_back( pPlace );
|
2012-03-27 18:01:07 +02:00
|
|
|
mpImpl->InsertEntry( pPlace->GetName( ),
|
|
|
|
getEntryIcon( pPlace ), getEntryIcon( pPlace ) );
|
2012-01-31 00:44:34 +01:00
|
|
|
|
|
|
|
if(pPlace->IsEditable()) {
|
|
|
|
++mnNbEditables;
|
|
|
|
mbUpdated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PlacesListBox::IsUpdated() {
|
|
|
|
if(mbUpdated) {
|
|
|
|
mbUpdated = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PlacesListBox::RemovePlace( sal_uInt16 nPos )
|
|
|
|
{
|
|
|
|
if ( nPos < maPlaces.size() )
|
|
|
|
{
|
|
|
|
if(maPlaces[nPos]->IsEditable()) {
|
|
|
|
--mnNbEditables;
|
|
|
|
mbUpdated = true;
|
|
|
|
}
|
|
|
|
maPlaces.erase( maPlaces.begin() + nPos );
|
2012-10-18 16:28:20 +02:00
|
|
|
SvTreeListEntry* pEntry = mpImpl->GetEntry( nPos );
|
2012-03-27 18:01:07 +02:00
|
|
|
mpImpl->RemoveEntry( pEntry );
|
2012-01-31 00:44:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlacesListBox::RemoveSelectedPlace() {
|
2012-03-27 18:01:07 +02:00
|
|
|
RemovePlace(mpImpl->GetCurrRow());
|
|
|
|
}
|
|
|
|
|
2015-08-19 09:11:34 +02:00
|
|
|
void PlacesListBox::SetAddHdl( const Link<Button*,void>& rHdl )
|
2012-07-13 17:16:40 +02:00
|
|
|
{
|
|
|
|
mpAddBtn->SetClickHdl( rHdl );
|
|
|
|
}
|
|
|
|
|
2015-08-19 09:11:34 +02:00
|
|
|
void PlacesListBox::SetDelHdl( const Link<Button*,void>& rHdl )
|
2012-07-13 17:16:40 +02:00
|
|
|
{
|
|
|
|
mpDelBtn->SetClickHdl( rHdl );
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlacesListBox::SetDelEnabled( bool enabled )
|
|
|
|
{
|
|
|
|
mpDelBtn->Enable( enabled );
|
|
|
|
}
|
|
|
|
|
2012-03-27 18:01:07 +02:00
|
|
|
void PlacesListBox::SetSizePixel( const Size& rNewSize )
|
|
|
|
{
|
|
|
|
Control::SetSizePixel( rNewSize );
|
2012-07-13 17:16:40 +02:00
|
|
|
Size aListSize( rNewSize );
|
|
|
|
aListSize.Height() -= 26 + 18;
|
|
|
|
mpImpl->SetSizePixel( aListSize );
|
|
|
|
|
|
|
|
sal_Int32 nBtnY = rNewSize.Height() - 26;
|
|
|
|
mpAddBtn->SetPosPixel( Point( 3, nBtnY ) );
|
|
|
|
mpDelBtn->SetPosPixel( Point( 6 + 24, nBtnY ) );
|
2012-01-31 00:44:34 +01:00
|
|
|
}
|
|
|
|
|
2016-11-24 22:40:33 +01:00
|
|
|
bool PlacesListBox::EventNotify( NotifyEvent& rNEvt )
|
2015-10-01 19:31:17 +02:00
|
|
|
{
|
|
|
|
if( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
|
|
|
|
{
|
|
|
|
const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
|
|
|
|
const vcl::KeyCode& rCode = pKeyEvent->GetKeyCode();
|
|
|
|
|
|
|
|
if( rCode.GetCode() == KEY_RETURN )
|
|
|
|
{
|
|
|
|
mbSelectionChanged = true;
|
|
|
|
updateView();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-11-24 22:40:33 +01:00
|
|
|
return Control::EventNotify(rNEvt);
|
2015-10-01 19:31:17 +02:00
|
|
|
}
|
|
|
|
|
2016-04-12 12:08:00 +02:00
|
|
|
Image PlacesListBox::getEntryIcon( const PlacePtr& pPlace )
|
2012-01-31 00:44:34 +01:00
|
|
|
{
|
2016-12-06 13:47:28 +02:00
|
|
|
Image theImage = SvtFileDialog::GetButtonImage( BMP_FILEDLG_PLACE_LOCAL );
|
2012-03-27 18:01:07 +02:00
|
|
|
if ( !pPlace->IsLocal( ) )
|
2016-12-06 13:47:28 +02:00
|
|
|
theImage = SvtFileDialog::GetButtonImage( BMP_FILEDLG_PLACE_REMOTE );
|
2012-08-03 18:12:51 -04:30
|
|
|
return theImage;
|
2012-01-31 00:44:34 +01:00
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK_NOARG( PlacesListBox, Selection, SvTreeListBox*, void )
|
2012-01-31 00:44:34 +01:00
|
|
|
{
|
2012-03-27 18:01:07 +02:00
|
|
|
sal_uInt32 nSelected = mpImpl->GetCurrRow();
|
2012-01-31 00:44:34 +01:00
|
|
|
PlacePtr pPlace = maPlaces[nSelected];
|
2012-03-27 18:01:07 +02:00
|
|
|
|
2012-06-27 17:04:34 +02:00
|
|
|
mbSelectionChanged = true;
|
2012-01-31 00:44:34 +01:00
|
|
|
if(pPlace->IsEditable())
|
|
|
|
mpDlg->RemovablePlaceSelected();
|
|
|
|
else
|
|
|
|
mpDlg->RemovablePlaceSelected(false);
|
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK_NOARG( PlacesListBox, DoubleClick, SvTreeListBox*, bool )
|
2012-01-31 00:44:34 +01:00
|
|
|
{
|
2012-07-11 16:58:10 +02:00
|
|
|
sal_uInt16 nSelected = mpImpl->GetCurrRow();
|
|
|
|
PlacePtr pPlace = maPlaces[nSelected];
|
2015-04-27 15:27:42 +02:00
|
|
|
if ( pPlace->IsEditable() && !pPlace->IsLocal( ) )
|
2012-07-11 16:58:10 +02:00
|
|
|
{
|
2015-03-31 23:04:14 +01:00
|
|
|
ScopedVclPtrInstance< PlaceEditDialog > aDlg(mpDlg, pPlace);
|
2015-02-11 14:42:23 +02:00
|
|
|
short aRetCode = aDlg->Execute();
|
2012-07-11 16:58:10 +02:00
|
|
|
switch(aRetCode) {
|
|
|
|
case RET_OK :
|
|
|
|
{
|
2015-02-11 14:42:23 +02:00
|
|
|
pPlace->SetName ( aDlg->GetServerName() );
|
|
|
|
pPlace->SetUrl( aDlg->GetServerUrl() );
|
2012-05-03 16:55:22 +02:00
|
|
|
mbUpdated = true;
|
2012-07-11 16:58:10 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case RET_NO :
|
|
|
|
{
|
|
|
|
RemovePlace(nSelected);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
}
|
2015-09-10 14:39:17 +02:00
|
|
|
return false;
|
2012-01-31 00:44:34 +01:00
|
|
|
}
|
|
|
|
|
2012-06-27 17:04:34 +02:00
|
|
|
void PlacesListBox::updateView( )
|
|
|
|
{
|
|
|
|
if ( mbSelectionChanged )
|
|
|
|
{
|
|
|
|
mbSelectionChanged = false;
|
|
|
|
sal_uInt32 nSelected = mpImpl->GetCurrRow();
|
|
|
|
PlacePtr pPlace = maPlaces[nSelected];
|
|
|
|
mpDlg->OpenURL_Impl( pPlace->GetUrl( ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-31 00:44:34 +01:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|