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/.
11 #include <PlacesListBox.hxx>
12 #include <svtools/PlaceEditDialog.hxx>
14 #include <vcl/msgbox.hxx>
15 #include <svtools/headbar.hxx>
16 #include <svtools/svtresid.hxx>
21 PlacesListBox_Impl::PlacesListBox_Impl( PlacesListBox
* pParent
, const OUString
& rTitle
) :
22 SvHeaderTabListBox( pParent
, WB_TABSTOP
| WB_NOINITIALSELECTION
),
26 Size aBoxSize
= pParent
->GetSizePixel( );
27 mpHeaderBar
= new HeaderBar( pParent
, WB_BUTTONSTYLE
| WB_BOTTOMBORDER
);
28 mpHeaderBar
->SetPosSizePixel( Point( 0, 0 ), Size( 600, 16 ) );
30 long pTabs
[] = { 2, 20, 600 };
31 SetTabs( &pTabs
[0], MAP_PIXEL
);
32 mpHeaderBar
->InsertItem( COLUMN_NAME
, rTitle
, 600, HIB_LEFT
| HIB_VCENTER
);
34 Size aHeadSize
= mpHeaderBar
->GetSizePixel();
35 SetPosSizePixel( Point( 0, aHeadSize
.getHeight() ),
36 Size( aBoxSize
.getWidth(), aBoxSize
.getHeight() - aHeadSize
.getHeight() ) );
38 InitHeaderBar( mpHeaderBar
);
44 PlacesListBox_Impl::~PlacesListBox_Impl( )
50 void PlacesListBox_Impl::MouseButtonUp( const MouseEvent
& rMEvt
)
52 SvHeaderTabListBox::MouseButtonUp( rMEvt
);
53 mpParent
->updateView( );
56 PlacesListBox::PlacesListBox( SvtFileDialog
* pFileDlg
, const OUString
& rTitle
, const ResId
& rResId
) :
57 Control( pFileDlg
, rResId
),
65 mbSelectionChanged( false )
67 mpImpl
= new PlacesListBox_Impl( this, rTitle
);
69 mpImpl
->SetSelectHdl( LINK( this, PlacesListBox
, Selection
) );
70 mpImpl
->SetDoubleClickHdl( LINK( this, PlacesListBox
, DoubleClick
) ) ;
72 mpAddBtn
= new ImageButton( this, 0 );
73 mpAddBtn
->SetText( OUString( "+" ) );
74 mpAddBtn
->SetPosSizePixel( Point( 0, 0 ), Size( 22, 22 ) );
77 mpDelBtn
= new ImageButton( this, 0 );
78 mpDelBtn
->SetText( OUString( "-" ) );
79 mpDelBtn
->SetPosSizePixel( Point( 0, 0 ), Size( 22, 22 ) );
83 PlacesListBox::~PlacesListBox( )
90 void PlacesListBox::AppendPlace( PlacePtr pPlace
)
92 maPlaces
.push_back( pPlace
);
93 mpImpl
->InsertEntry( pPlace
->GetName( ),
94 getEntryIcon( pPlace
), getEntryIcon( pPlace
) );
96 if(pPlace
->IsEditable()) {
102 sal_Int32
PlacesListBox::GetNbEditablePlaces() {
103 return mnNbEditables
;
106 bool PlacesListBox::IsUpdated() {
114 const std::vector
<PlacePtr
>& PlacesListBox::GetPlaces() {
118 void PlacesListBox::RemovePlace( sal_uInt16 nPos
)
120 if ( nPos
< maPlaces
.size() )
122 if(maPlaces
[nPos
]->IsEditable()) {
126 maPlaces
.erase( maPlaces
.begin() + nPos
);
127 SvTreeListEntry
* pEntry
= mpImpl
->GetEntry( nPos
);
128 mpImpl
->RemoveEntry( pEntry
);
132 void PlacesListBox::RemoveSelectedPlace() {
133 RemovePlace(mpImpl
->GetCurrRow());
136 void PlacesListBox::SetAddHdl( const Link
& rHdl
)
138 mpAddBtn
->SetClickHdl( rHdl
);
141 void PlacesListBox::SetDelHdl( const Link
& rHdl
)
143 mpDelBtn
->SetClickHdl( rHdl
);
146 void PlacesListBox::SetDelEnabled( bool enabled
)
148 mpDelBtn
->Enable( enabled
);
151 void PlacesListBox::SetSizePixel( const Size
& rNewSize
)
153 Control::SetSizePixel( rNewSize
);
154 Size
aListSize( rNewSize
);
155 aListSize
.Height() -= 26 + 18;
156 mpImpl
->SetSizePixel( aListSize
);
158 sal_Int32 nBtnY
= rNewSize
.Height() - 26;
159 mpAddBtn
->SetPosPixel( Point( 3, nBtnY
) );
160 mpDelBtn
->SetPosPixel( Point( 6 + 24, nBtnY
) );
163 Image
PlacesListBox::getEntryIcon( PlacePtr pPlace
)
165 Image theImage
= mpDlg
->GetButtonImage( IMG_FILEDLG_PLACE_LOCAL
);
166 if ( !pPlace
->IsLocal( ) )
167 theImage
= mpDlg
->GetButtonImage( IMG_FILEDLG_PLACE_REMOTE
);
171 IMPL_LINK( PlacesListBox
, Selection
, void* , EMPTYARG
)
173 sal_uInt32 nSelected
= mpImpl
->GetCurrRow();
174 PlacePtr pPlace
= maPlaces
[nSelected
];
176 mbSelectionChanged
= true;
177 if(pPlace
->IsEditable())
178 mpDlg
->RemovablePlaceSelected();
180 mpDlg
->RemovablePlaceSelected(false);
184 IMPL_LINK ( PlacesListBox
, DoubleClick
, void*, EMPTYARG
)
186 sal_uInt16 nSelected
= mpImpl
->GetCurrRow();
187 PlacePtr pPlace
= maPlaces
[nSelected
];
188 if ( pPlace
->IsEditable() == true && !pPlace
->IsLocal( ) )
190 PlaceEditDialog
aDlg( mpDlg
, pPlace
);
191 short aRetCode
= aDlg
.Execute();
195 pPlace
->SetName ( aDlg
.GetServerName() );
196 pPlace
->SetUrl( aDlg
.GetServerUrl() );
202 RemovePlace(nSelected
);
212 void PlacesListBox::updateView( )
214 if ( mbSelectionChanged
)
216 mbSelectionChanged
= false;
217 sal_uInt32 nSelected
= mpImpl
->GetCurrRow();
218 PlacePtr pPlace
= maPlaces
[nSelected
];
219 mpDlg
->OpenURL_Impl( pPlace
->GetUrl( ) );
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */