build fix
[LibreOffice.git] / fpicker / source / office / PlacesListBox.cxx
blobeb77e55d548a9ab268660cf6fdefc71b1fc666e3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <iodlg.hrc>
11 #include <PlacesListBox.hxx>
12 #include <svtools/PlaceEditDialog.hxx>
14 #include <vcl/msgbox.hxx>
15 #include <svtools/headbar.hxx>
16 #include <svtools/svtresid.hxx>
18 #define COLUMN_NAME 1
21 PlacesListBox_Impl::PlacesListBox_Impl( PlacesListBox* pParent, const OUString& rTitle ) :
22 SvHeaderTabListBox( pParent, WB_TABSTOP | WB_NOINITIALSELECTION ),
23 mpHeaderBar( nullptr ),
24 mpParent( pParent )
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 );
40 Show( );
41 mpHeaderBar->Show();
44 PlacesListBox_Impl::~PlacesListBox_Impl( )
46 disposeOnce();
49 void PlacesListBox_Impl::dispose()
51 mpHeaderBar.disposeAndClear();
52 mpParent.clear();
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 ),
64 maPlaces( ),
65 mpDlg( pFileDlg ),
66 mpImpl( nullptr ),
67 mpAddBtn( ),
68 mpDelBtn( ),
69 mnNbEditables( 0 ),
70 mbUpdated( false ),
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 ) );
81 mpAddBtn->Show();
83 mpDelBtn.reset( VclPtr<ImageButton>::Create( this, 0 ) );
84 mpDelBtn->SetText( "-" );
85 mpDelBtn->SetPosSizePixel( Point( 0, 0 ), Size( 22, 22 ) );
86 mpDelBtn->Show();
89 PlacesListBox::~PlacesListBox( )
91 disposeOnce();
94 void PlacesListBox::dispose()
96 mpImpl.disposeAndClear();
97 mpAddBtn.disposeAndClear();
98 mpDelBtn.disposeAndClear();
99 mpDlg.clear();
100 Control::dispose();
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()) {
110 ++mnNbEditables;
111 mbUpdated = true;
116 bool PlacesListBox::IsUpdated() {
117 if(mbUpdated) {
118 mbUpdated = false;
119 return true;
121 return false;
125 void PlacesListBox::RemovePlace( sal_uInt16 nPos )
127 if ( nPos < maPlaces.size() )
129 if(maPlaces[nPos]->IsEditable()) {
130 --mnNbEditables;
131 mbUpdated = true;
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;
180 updateView();
181 return 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 );
192 return theImage;
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();
203 else
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();
215 switch(aRetCode) {
216 case RET_OK :
218 pPlace->SetName ( aDlg->GetServerName() );
219 pPlace->SetUrl( aDlg->GetServerUrl() );
220 mbUpdated = true;
221 break;
223 case RET_NO :
225 RemovePlace(nSelected);
226 break;
228 default:
229 break;
232 return false;
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: */