Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : */
12 :
13 : #include <iodlg.hrc>
14 : #include <PlacesListBox.hxx>
15 : #include <svtools/PlaceEditDialog.hxx>
16 :
17 : #include <vcl/msgbox.hxx>
18 : #include <svtools/headbar.hxx>
19 : #include <svtools/svtresid.hxx>
20 :
21 : #define COLUMN_NAME 1
22 :
23 :
24 0 : PlacesListBox_Impl::PlacesListBox_Impl( PlacesListBox* pParent, const OUString& rTitle ) :
25 : SvHeaderTabListBox( pParent, WB_TABSTOP | WB_NOINITIALSELECTION ),
26 : mpHeaderBar( NULL ),
27 0 : mpParent( pParent )
28 : {
29 0 : Size aBoxSize = pParent->GetSizePixel( );
30 0 : mpHeaderBar = new HeaderBar( pParent, WB_BUTTONSTYLE | WB_BOTTOMBORDER );
31 0 : mpHeaderBar->SetPosSizePixel( Point( 0, 0 ), Size( 600, 16 ) );
32 :
33 0 : long pTabs[] = { 2, 20, 600 };
34 0 : SetTabs( &pTabs[0], MAP_PIXEL );
35 0 : mpHeaderBar->InsertItem( COLUMN_NAME, rTitle, 600, HIB_LEFT | HIB_VCENTER );
36 :
37 0 : Size aHeadSize = mpHeaderBar->GetSizePixel();
38 : SetPosSizePixel( Point( 0, aHeadSize.getHeight() ),
39 0 : Size( aBoxSize.getWidth(), aBoxSize.getHeight() - aHeadSize.getHeight() ) );
40 :
41 0 : InitHeaderBar( mpHeaderBar );
42 :
43 0 : Show( );
44 0 : mpHeaderBar->Show();
45 0 : }
46 :
47 0 : PlacesListBox_Impl::~PlacesListBox_Impl( )
48 : {
49 0 : delete mpHeaderBar;
50 0 : mpParent = NULL;
51 0 : }
52 :
53 0 : void PlacesListBox_Impl::MouseButtonUp( const MouseEvent& rMEvt )
54 : {
55 0 : SvHeaderTabListBox::MouseButtonUp( rMEvt );
56 0 : mpParent->updateView( );
57 0 : }
58 :
59 0 : PlacesListBox::PlacesListBox( SvtFileDialog* pFileDlg, const OUString& rTitle, const ResId& rResId ) :
60 : Control( pFileDlg, rResId ),
61 : maPlaces( ),
62 : mpDlg( pFileDlg ),
63 : mpImpl( NULL ),
64 : mpAddBtn( ),
65 : mpDelBtn( ),
66 : mnNbEditables( 0 ),
67 : mbUpdated( false ),
68 0 : mbSelectionChanged( false )
69 : {
70 0 : mpImpl = new PlacesListBox_Impl( this, rTitle );
71 :
72 0 : mpImpl->SetSelectHdl( LINK( this, PlacesListBox, Selection ) );
73 0 : mpImpl->SetDoubleClickHdl( LINK( this, PlacesListBox, DoubleClick ) ) ;
74 :
75 0 : mpAddBtn = new ImageButton( this, 0 );
76 0 : mpAddBtn->SetText( OUString( "+" ) );
77 0 : mpAddBtn->SetPosSizePixel( Point( 0, 0 ), Size( 24, 24 ) );
78 0 : mpAddBtn->Show();
79 :
80 0 : mpDelBtn = new ImageButton( this, 0 );
81 0 : mpDelBtn->SetText( OUString( "-" ) );
82 0 : mpDelBtn->SetPosSizePixel( Point( 0, 0 ), Size( 24, 24 ) );
83 0 : mpDelBtn->Show();
84 0 : }
85 :
86 0 : PlacesListBox::~PlacesListBox( )
87 : {
88 0 : delete mpImpl;
89 0 : delete mpAddBtn;
90 0 : delete mpDelBtn;
91 0 : }
92 :
93 0 : void PlacesListBox::AppendPlace( PlacePtr pPlace )
94 : {
95 0 : maPlaces.push_back( pPlace );
96 0 : mpImpl->InsertEntry( pPlace->GetName( ),
97 0 : getEntryIcon( pPlace ), getEntryIcon( pPlace ) );
98 :
99 0 : if(pPlace->IsEditable()) {
100 0 : ++mnNbEditables;
101 0 : mbUpdated = true;
102 : }
103 0 : }
104 :
105 0 : sal_Int32 PlacesListBox::GetNbEditablePlaces() {
106 0 : return mnNbEditables;
107 : }
108 :
109 0 : bool PlacesListBox::IsUpdated() {
110 0 : if(mbUpdated) {
111 0 : mbUpdated = false;
112 0 : return true;
113 : }
114 0 : return false;
115 : }
116 :
117 0 : const std::vector<PlacePtr>& PlacesListBox::GetPlaces() {
118 0 : return maPlaces;
119 : }
120 :
121 0 : void PlacesListBox::RemovePlace( sal_uInt16 nPos )
122 : {
123 0 : if ( nPos < maPlaces.size() )
124 : {
125 0 : if(maPlaces[nPos]->IsEditable()) {
126 0 : --mnNbEditables;
127 0 : mbUpdated = true;
128 : }
129 0 : maPlaces.erase( maPlaces.begin() + nPos );
130 0 : SvTreeListEntry* pEntry = mpImpl->GetEntry( nPos );
131 0 : mpImpl->RemoveEntry( pEntry );
132 : }
133 0 : }
134 :
135 0 : void PlacesListBox::RemoveSelectedPlace() {
136 0 : RemovePlace(mpImpl->GetCurrRow());
137 0 : }
138 :
139 0 : void PlacesListBox::SetAddHdl( const Link& rHdl )
140 : {
141 0 : mpAddBtn->SetClickHdl( rHdl );
142 0 : }
143 :
144 0 : void PlacesListBox::SetDelHdl( const Link& rHdl )
145 : {
146 0 : mpDelBtn->SetClickHdl( rHdl );
147 0 : }
148 :
149 0 : void PlacesListBox::SetDelEnabled( bool enabled )
150 : {
151 0 : mpDelBtn->Enable( enabled );
152 0 : }
153 :
154 0 : void PlacesListBox::SetSizePixel( const Size& rNewSize )
155 : {
156 0 : Control::SetSizePixel( rNewSize );
157 0 : Size aListSize( rNewSize );
158 0 : aListSize.Height() -= 26 + 18;
159 0 : mpImpl->SetSizePixel( aListSize );
160 :
161 0 : sal_Int32 nBtnY = rNewSize.Height() - 26;
162 0 : mpAddBtn->SetPosPixel( Point( 3, nBtnY ) );
163 0 : mpDelBtn->SetPosPixel( Point( 6 + 24, nBtnY ) );
164 0 : }
165 :
166 0 : Image PlacesListBox::getEntryIcon( PlacePtr pPlace )
167 : {
168 0 : Image theImage = mpDlg->GetButtonImage( IMG_FILEDLG_PLACE_LOCAL );
169 0 : if ( !pPlace->IsLocal( ) )
170 0 : theImage = mpDlg->GetButtonImage( IMG_FILEDLG_PLACE_REMOTE );
171 0 : return theImage;
172 : }
173 :
174 0 : IMPL_LINK( PlacesListBox, Selection, void* , EMPTYARG )
175 : {
176 0 : sal_uInt32 nSelected = mpImpl->GetCurrRow();
177 0 : PlacePtr pPlace = maPlaces[nSelected];
178 :
179 0 : mbSelectionChanged = true;
180 0 : if(pPlace->IsEditable())
181 0 : mpDlg->RemovablePlaceSelected();
182 : else
183 0 : mpDlg->RemovablePlaceSelected(false);
184 0 : return 0;
185 : }
186 :
187 0 : IMPL_LINK ( PlacesListBox, DoubleClick, void*, EMPTYARG )
188 : {
189 0 : sal_uInt16 nSelected = mpImpl->GetCurrRow();
190 0 : PlacePtr pPlace = maPlaces[nSelected];
191 0 : if ( pPlace->IsEditable() == true && !pPlace->IsLocal( ) )
192 : {
193 0 : PlaceEditDialog aDlg( mpDlg, pPlace );
194 0 : short aRetCode = aDlg.Execute();
195 0 : switch(aRetCode) {
196 : case RET_OK :
197 : {
198 0 : pPlace->SetName ( aDlg.GetServerName() );
199 0 : pPlace->SetUrl( aDlg.GetServerUrl() );
200 0 : mbUpdated = true;
201 0 : break;
202 : }
203 : case RET_NO :
204 : {
205 0 : RemovePlace(nSelected);
206 0 : break;
207 : }
208 : default:
209 0 : break;
210 0 : };
211 : }
212 0 : return 0;
213 : }
214 :
215 0 : void PlacesListBox::updateView( )
216 : {
217 0 : if ( mbSelectionChanged )
218 : {
219 0 : mbSelectionChanged = false;
220 0 : sal_uInt32 nSelected = mpImpl->GetCurrRow();
221 0 : PlacePtr pPlace = maPlaces[nSelected];
222 0 : mpDlg->OpenURL_Impl( pPlace->GetUrl( ) );
223 : }
224 0 : }
225 :
226 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|