bump product version to 4.1.6.2
[LibreOffice.git] / fpicker / source / office / PlacesListBox.cxx
blobc3b381888929bd9cda68cc2e6c9f4c626442ea66
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( NULL ),
24 mpParent( pParent )
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 );
40 Show( );
41 mpHeaderBar->Show();
44 PlacesListBox_Impl::~PlacesListBox_Impl( )
46 delete mpHeaderBar;
47 mpParent = NULL;
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 ),
58 maPlaces( ),
59 mpDlg( pFileDlg ),
60 mpImpl( NULL ),
61 mpAddBtn( ),
62 mpDelBtn( ),
63 mnNbEditables( 0 ),
64 mbUpdated( false ),
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 ) );
75 mpAddBtn->Show();
77 mpDelBtn = new ImageButton( this, 0 );
78 mpDelBtn->SetText( OUString( "-" ) );
79 mpDelBtn->SetPosSizePixel( Point( 0, 0 ), Size( 22, 22 ) );
80 mpDelBtn->Show();
83 PlacesListBox::~PlacesListBox( )
85 delete mpImpl;
86 delete mpAddBtn;
87 delete mpDelBtn;
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()) {
97 ++mnNbEditables;
98 mbUpdated = true;
102 sal_Int32 PlacesListBox::GetNbEditablePlaces() {
103 return mnNbEditables;
106 bool PlacesListBox::IsUpdated() {
107 if(mbUpdated) {
108 mbUpdated = false;
109 return true;
111 return false;
114 const std::vector<PlacePtr>& PlacesListBox::GetPlaces() {
115 return maPlaces;
118 void PlacesListBox::RemovePlace( sal_uInt16 nPos )
120 if ( nPos < maPlaces.size() )
122 if(maPlaces[nPos]->IsEditable()) {
123 --mnNbEditables;
124 mbUpdated = true;
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 );
168 return theImage;
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();
179 else
180 mpDlg->RemovablePlaceSelected(false);
181 return 0;
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();
192 switch(aRetCode) {
193 case RET_OK :
195 pPlace->SetName ( aDlg.GetServerName() );
196 pPlace->SetUrl( aDlg.GetServerUrl() );
197 mbUpdated = true;
198 break;
200 case RET_NO :
202 RemovePlace(nSelected);
203 break;
205 default:
206 break;
209 return 0;
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: */