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
),
23 mpHeaderBar( nullptr ),
26 Size aBoxSize
= pParent
->GetSizePixel( );
27 mpHeaderBar
= VclPtr
<HeaderBar
>::Create( pParent
, WB_BUTTONSTYLE
| WB_BOTTOMBORDER
);
28 mpHeaderBar
->SetPosSizePixel( Point( 0, 0 ), Size( 600, 16 ) );
30 long pTabs
[] = { 2, 20, 600 };
31 SetTabs( &pTabs
[0], MapUnit::MapPixel
);
32 mpHeaderBar
->InsertItem( COLUMN_NAME
, rTitle
, 600, HeaderBarItemBits::LEFT
| HeaderBarItemBits::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( )
49 void PlacesListBox_Impl::dispose()
51 mpHeaderBar
.disposeAndClear();
53 SvHeaderTabListBox::dispose();
56 void PlacesListBox_Impl::MouseButtonUp( const MouseEvent
& rMEvt
)
58 SvHeaderTabListBox::MouseButtonUp( rMEvt
);
59 mpParent
->updateView( );
62 PlacesListBox::PlacesListBox( vcl::Window
* pParent
, SvtFileDialog
* pFileDlg
, const OUString
& rTitle
, WinBits nBits
) :
63 Control( pParent
, nBits
),
71 mbSelectionChanged( false )
73 mpImpl
= VclPtr
<PlacesListBox_Impl
>::Create( this, rTitle
);
75 mpImpl
->SetSelectHdl( LINK( this, PlacesListBox
, Selection
) );
76 mpImpl
->SetDoubleClickHdl( LINK( this, PlacesListBox
, DoubleClick
) ) ;
78 mpAddBtn
.reset( VclPtr
<ImageButton
>::Create( this, 0 ) );
79 mpAddBtn
->SetText( "+" );
80 mpAddBtn
->SetPosSizePixel( Point( 0, 0 ), Size( 22, 22 ) );
83 mpDelBtn
.reset( VclPtr
<ImageButton
>::Create( this, 0 ) );
84 mpDelBtn
->SetText( "-" );
85 mpDelBtn
->SetPosSizePixel( Point( 0, 0 ), Size( 22, 22 ) );
89 PlacesListBox::~PlacesListBox( )
94 void PlacesListBox::dispose()
96 mpImpl
.disposeAndClear();
97 mpAddBtn
.disposeAndClear();
98 mpDelBtn
.disposeAndClear();
103 void PlacesListBox::AppendPlace( const PlacePtr
& pPlace
)
105 maPlaces
.push_back( pPlace
);
106 mpImpl
->InsertEntry( pPlace
->GetName( ),
107 getEntryIcon( pPlace
), getEntryIcon( pPlace
) );
109 if(pPlace
->IsEditable()) {
116 bool PlacesListBox::IsUpdated() {
125 void PlacesListBox::RemovePlace( sal_uInt16 nPos
)
127 if ( nPos
< maPlaces
.size() )
129 if(maPlaces
[nPos
]->IsEditable()) {
133 maPlaces
.erase( maPlaces
.begin() + nPos
);
134 SvTreeListEntry
* pEntry
= mpImpl
->GetEntry( nPos
);
135 mpImpl
->RemoveEntry( pEntry
);
139 void PlacesListBox::RemoveSelectedPlace() {
140 RemovePlace(mpImpl
->GetCurrRow());
143 void PlacesListBox::SetAddHdl( const Link
<Button
*,void>& rHdl
)
145 mpAddBtn
->SetClickHdl( rHdl
);
148 void PlacesListBox::SetDelHdl( const Link
<Button
*,void>& rHdl
)
150 mpDelBtn
->SetClickHdl( rHdl
);
153 void PlacesListBox::SetDelEnabled( bool enabled
)
155 mpDelBtn
->Enable( enabled
);
158 void PlacesListBox::SetSizePixel( const Size
& rNewSize
)
160 Control::SetSizePixel( rNewSize
);
161 Size
aListSize( rNewSize
);
162 aListSize
.Height() -= 26 + 18;
163 mpImpl
->SetSizePixel( aListSize
);
165 sal_Int32 nBtnY
= rNewSize
.Height() - 26;
166 mpAddBtn
->SetPosPixel( Point( 3, nBtnY
) );
167 mpDelBtn
->SetPosPixel( Point( 6 + 24, nBtnY
) );
170 bool PlacesListBox::EventNotify( NotifyEvent
& rNEvt
)
172 if( rNEvt
.GetType() == MouseNotifyEvent::KEYINPUT
)
174 const KeyEvent
* pKeyEvent
= rNEvt
.GetKeyEvent();
175 const vcl::KeyCode
& rCode
= pKeyEvent
->GetKeyCode();
177 if( rCode
.GetCode() == KEY_RETURN
)
179 mbSelectionChanged
= true;
184 return Control::EventNotify(rNEvt
);
187 Image
PlacesListBox::getEntryIcon( const PlacePtr
& pPlace
)
189 Image theImage
= mpDlg
->GetButtonImage( IMG_FILEDLG_PLACE_LOCAL
);
190 if ( !pPlace
->IsLocal( ) )
191 theImage
= mpDlg
->GetButtonImage( IMG_FILEDLG_PLACE_REMOTE
);
195 IMPL_LINK_NOARG( PlacesListBox
, Selection
, SvTreeListBox
*, void )
197 sal_uInt32 nSelected
= mpImpl
->GetCurrRow();
198 PlacePtr pPlace
= maPlaces
[nSelected
];
200 mbSelectionChanged
= true;
201 if(pPlace
->IsEditable())
202 mpDlg
->RemovablePlaceSelected();
204 mpDlg
->RemovablePlaceSelected(false);
207 IMPL_LINK_NOARG( PlacesListBox
, DoubleClick
, SvTreeListBox
*, bool )
209 sal_uInt16 nSelected
= mpImpl
->GetCurrRow();
210 PlacePtr pPlace
= maPlaces
[nSelected
];
211 if ( pPlace
->IsEditable() && !pPlace
->IsLocal( ) )
213 ScopedVclPtrInstance
< PlaceEditDialog
> aDlg(mpDlg
, pPlace
);
214 short aRetCode
= aDlg
->Execute();
218 pPlace
->SetName ( aDlg
->GetServerName() );
219 pPlace
->SetUrl( aDlg
->GetServerUrl() );
225 RemovePlace(nSelected
);
235 void PlacesListBox::updateView( )
237 if ( mbSelectionChanged
)
239 mbSelectionChanged
= false;
240 sal_uInt32 nSelected
= mpImpl
->GetCurrRow();
241 PlacePtr pPlace
= maPlaces
[nSelected
];
242 mpDlg
->OpenURL_Impl( pPlace
->GetUrl( ) );
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */