LCOV - code coverage report
Current view: top level - fpicker/source/office - PlacesListBox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 124 0.0 %
Date: 2012-08-25 Functions: 0 23 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4                 :            :  *
       5                 :            :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :            :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :            :  * the License or as specified alternatively below. You may obtain a copy of
       8                 :            :  * the License at http://www.mozilla.org/MPL/
       9                 :            :  *
      10                 :            :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :            :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :            :  * for the specific language governing rights and limitations under the
      13                 :            :  * License.
      14                 :            :  *
      15                 :            :  * Major Contributor(s):
      16                 :            :  * [ Copyright (C) 2011 Cedric Bosdonnat <cbosdonnat@suse.com> (initial developer) ]
      17                 :            :  *
      18                 :            :  * All Rights Reserved.
      19                 :            :  *
      20                 :            :  * For minor contributions see the git repository.
      21                 :            :  *
      22                 :            :  * Alternatively, the contents of this file may be used under the terms of
      23                 :            :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24                 :            :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25                 :            :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26                 :            :  * instead of those above.
      27                 :            :  */
      28                 :            : 
      29                 :            : #include <iodlg.hrc>
      30                 :            : #include <PlacesListBox.hxx>
      31                 :            : #include <svtools/PlaceEditDialog.hxx>
      32                 :            : 
      33                 :            : #include <vcl/msgbox.hxx>
      34                 :            : #include <svtools/headbar.hxx>
      35                 :            : #include <svtools/svtresid.hxx>
      36                 :            : 
      37                 :            : #define COLUMN_NAME     1
      38                 :            : 
      39                 :            : using rtl::OUString;
      40                 :            : 
      41                 :          0 : PlacesListBox_Impl::PlacesListBox_Impl( PlacesListBox* pParent, const rtl::OUString& rTitle ) :
      42                 :            :     SvHeaderTabListBox( pParent, WB_TABSTOP | WB_NOINITIALSELECTION ),
      43                 :            :     mpHeaderBar( NULL ),
      44                 :          0 :     mpParent( pParent )
      45                 :            : {
      46                 :          0 :     Size aBoxSize = pParent->GetSizePixel( );
      47                 :          0 :     mpHeaderBar = new HeaderBar( pParent, WB_BUTTONSTYLE | WB_BOTTOMBORDER );
      48                 :          0 :     mpHeaderBar->SetPosSizePixel( Point( 0, 0 ), Size( 600, 16 ) );
      49                 :            : 
      50                 :          0 :     long pTabs[] = { 2, 20, 600 };
      51                 :          0 :     SetTabs( &pTabs[0], MAP_PIXEL );
      52                 :          0 :     mpHeaderBar->InsertItem( COLUMN_NAME, rTitle, 600, HIB_LEFT | HIB_VCENTER );
      53                 :            : 
      54                 :          0 :     Size aHeadSize = mpHeaderBar->GetSizePixel();
      55                 :            :     SetPosSizePixel( Point( 0, aHeadSize.getHeight() ),
      56                 :          0 :                   Size( aBoxSize.getWidth(), aBoxSize.getHeight() - aHeadSize.getHeight() ) );
      57                 :            : 
      58                 :          0 :     InitHeaderBar( mpHeaderBar );
      59                 :            : 
      60                 :          0 :     Show( );
      61                 :          0 :     mpHeaderBar->Show();
      62                 :          0 : }
      63                 :            : 
      64                 :          0 : PlacesListBox_Impl::~PlacesListBox_Impl( )
      65                 :            : {
      66                 :          0 :     delete mpHeaderBar;
      67                 :          0 :     mpParent = NULL;
      68                 :          0 : }
      69                 :            : 
      70                 :          0 : void PlacesListBox_Impl::MouseButtonUp( const MouseEvent& rMEvt )
      71                 :            : {
      72                 :          0 :     SvHeaderTabListBox::MouseButtonUp( rMEvt );
      73                 :          0 :     mpParent->updateView( );
      74                 :          0 : }
      75                 :            : 
      76                 :          0 : PlacesListBox::PlacesListBox( SvtFileDialog* pFileDlg, const rtl::OUString& rTitle, const ResId& rResId ) :
      77                 :            :     Control( pFileDlg, rResId ),
      78                 :            :     maPlaces( ),
      79                 :            :     mpDlg( pFileDlg ),
      80                 :            :     mpImpl( NULL ),
      81                 :            :     mpAddBtn( ),
      82                 :            :     mpDelBtn( ),
      83                 :            :     mnNbEditables( 0 ),
      84                 :            :     mbUpdated( false ),
      85                 :          0 :     mbSelectionChanged( false )
      86                 :            : {
      87                 :          0 :     mpImpl = new PlacesListBox_Impl( this, rTitle );
      88                 :            : 
      89                 :          0 :     mpImpl->SetSelectHdl( LINK( this, PlacesListBox, Selection ) );
      90                 :          0 :     mpImpl->SetDoubleClickHdl( LINK( this, PlacesListBox, DoubleClick ) ) ;
      91                 :            : 
      92                 :          0 :     mpAddBtn = new ImageButton( this, 0 );
      93                 :          0 :     mpAddBtn->SetText( rtl::OUString( "+" ) );
      94                 :          0 :     mpAddBtn->SetPosSizePixel( Point( 0, 0 ), Size( 24, 24 ) );
      95                 :          0 :     mpAddBtn->Show();
      96                 :            : 
      97                 :          0 :     mpDelBtn = new ImageButton( this, 0 );
      98                 :          0 :     mpDelBtn->SetText( rtl::OUString( "-" ) );
      99                 :          0 :     mpDelBtn->SetPosSizePixel( Point( 0, 0 ), Size( 24, 24 ) );
     100                 :          0 :     mpDelBtn->Show();
     101                 :          0 : }
     102                 :            : 
     103                 :          0 : PlacesListBox::~PlacesListBox( )
     104                 :            : {
     105                 :          0 :     delete mpImpl;
     106                 :          0 :     delete mpAddBtn;
     107                 :          0 :     delete mpDelBtn;
     108                 :          0 : }
     109                 :            : 
     110                 :          0 : void PlacesListBox::AppendPlace( PlacePtr pPlace )
     111                 :            : {
     112                 :          0 :     maPlaces.push_back( pPlace );
     113                 :          0 :     mpImpl->InsertEntry( pPlace->GetName( ),
     114                 :          0 :             getEntryIcon( pPlace ), getEntryIcon( pPlace ) );
     115                 :            : 
     116                 :          0 :     if(pPlace->IsEditable()) {
     117                 :          0 :         ++mnNbEditables;
     118                 :          0 :         mbUpdated = true;
     119                 :            :     }
     120                 :          0 : }
     121                 :            : 
     122                 :          0 : sal_Int32 PlacesListBox::GetNbEditablePlaces() {
     123                 :          0 :     return mnNbEditables;
     124                 :            : }
     125                 :            : 
     126                 :          0 : bool PlacesListBox::IsUpdated() {
     127                 :          0 :     if(mbUpdated) {
     128                 :          0 :         mbUpdated = false;
     129                 :          0 :         return true;
     130                 :            :     }
     131                 :          0 :     return false;
     132                 :            : }
     133                 :            : 
     134                 :          0 : const std::vector<PlacePtr>& PlacesListBox::GetPlaces() {
     135                 :          0 :     return maPlaces;
     136                 :            : }
     137                 :            : 
     138                 :          0 : void PlacesListBox::RemovePlace( sal_uInt16 nPos )
     139                 :            : {
     140                 :          0 :     if ( nPos < maPlaces.size() )
     141                 :            :     {
     142                 :          0 :         if(maPlaces[nPos]->IsEditable()) {
     143                 :          0 :             --mnNbEditables;
     144                 :          0 :             mbUpdated = true;
     145                 :            :         }
     146                 :          0 :         maPlaces.erase( maPlaces.begin() + nPos );
     147                 :          0 :         SvLBoxEntry* pEntry = mpImpl->GetEntry( nPos );
     148                 :          0 :         mpImpl->RemoveEntry( pEntry );
     149                 :            :     }
     150                 :          0 : }
     151                 :            : 
     152                 :          0 : void PlacesListBox::RemoveSelectedPlace() {
     153                 :          0 :     RemovePlace(mpImpl->GetCurrRow());
     154                 :          0 : }
     155                 :            : 
     156                 :          0 : void PlacesListBox::SetAddHdl( const Link& rHdl )
     157                 :            : {
     158                 :          0 :     mpAddBtn->SetClickHdl( rHdl );
     159                 :          0 : }
     160                 :            : 
     161                 :          0 : void PlacesListBox::SetDelHdl( const Link& rHdl )
     162                 :            : {
     163                 :          0 :     mpDelBtn->SetClickHdl( rHdl );
     164                 :          0 : }
     165                 :            : 
     166                 :          0 : void PlacesListBox::SetDelEnabled( bool enabled )
     167                 :            : {
     168                 :          0 :     mpDelBtn->Enable( enabled );
     169                 :          0 : }
     170                 :            : 
     171                 :          0 : void PlacesListBox::SetSizePixel( const Size& rNewSize )
     172                 :            : {
     173                 :          0 :     Control::SetSizePixel( rNewSize );
     174                 :          0 :     Size aListSize( rNewSize );
     175                 :          0 :     aListSize.Height() -= 26 + 18;
     176                 :          0 :     mpImpl->SetSizePixel( aListSize );
     177                 :            : 
     178                 :          0 :     sal_Int32 nBtnY = rNewSize.Height() - 26;
     179                 :          0 :     mpAddBtn->SetPosPixel( Point( 3, nBtnY ) );
     180                 :          0 :     mpDelBtn->SetPosPixel( Point( 6 + 24, nBtnY ) );
     181                 :          0 : }
     182                 :            : 
     183                 :          0 : Image PlacesListBox::getEntryIcon( PlacePtr pPlace )
     184                 :            : {
     185                 :          0 :     Image theImage = mpDlg->GetButtonImage( IMG_FILEDLG_PLACE_LOCAL );
     186                 :          0 :     if ( !pPlace->IsLocal( ) )
     187                 :          0 :         theImage = mpDlg->GetButtonImage( IMG_FILEDLG_PLACE_REMOTE );
     188                 :          0 :     return theImage;
     189                 :            : }
     190                 :            : 
     191                 :          0 : IMPL_LINK( PlacesListBox, Selection, void* , EMPTYARG )
     192                 :            : {
     193                 :          0 :     sal_uInt32 nSelected = mpImpl->GetCurrRow();
     194                 :          0 :     PlacePtr pPlace = maPlaces[nSelected];
     195                 :            : 
     196                 :          0 :     mbSelectionChanged = true;
     197                 :          0 :     if(pPlace->IsEditable())
     198                 :          0 :         mpDlg->RemovablePlaceSelected();
     199                 :            :     else
     200                 :          0 :         mpDlg->RemovablePlaceSelected(false);
     201                 :          0 :     return 0;
     202                 :            : }
     203                 :            : 
     204                 :          0 : IMPL_LINK ( PlacesListBox, DoubleClick, void*, EMPTYARG )
     205                 :            : {
     206                 :          0 :     sal_uInt16 nSelected = mpImpl->GetCurrRow();
     207                 :          0 :     PlacePtr pPlace = maPlaces[nSelected];
     208                 :          0 :     if ( pPlace->IsEditable() == true && !pPlace->IsLocal( ) )
     209                 :            :     {
     210                 :          0 :         PlaceEditDialog aDlg( mpDlg, pPlace );
     211                 :          0 :         short aRetCode = aDlg.Execute();
     212                 :          0 :         switch(aRetCode) {
     213                 :            :             case RET_OK :
     214                 :            :             {
     215                 :          0 :                 pPlace->SetName ( aDlg.GetServerName() );
     216                 :          0 :                 pPlace->SetUrl( aDlg.GetServerUrl() );
     217                 :          0 :                 mbUpdated = true;
     218                 :          0 :                 break;
     219                 :            :             }
     220                 :            :             case RET_NO :
     221                 :            :             {
     222                 :          0 :                 RemovePlace(nSelected);
     223                 :          0 :                 break;
     224                 :            :             }
     225                 :            :             default:
     226                 :          0 :                 break;
     227                 :          0 :         };
     228                 :            :     }
     229                 :          0 :     return 0;
     230                 :            : }
     231                 :            : 
     232                 :          0 : void PlacesListBox::updateView( )
     233                 :            : {
     234                 :          0 :     if ( mbSelectionChanged )
     235                 :            :     {
     236                 :          0 :         mbSelectionChanged = false;
     237                 :          0 :         sal_uInt32 nSelected = mpImpl->GetCurrRow();
     238                 :          0 :         PlacePtr pPlace = maPlaces[nSelected];
     239                 :          0 :         mpDlg->OpenURL_Impl( pPlace->GetUrl( ) );
     240                 :            :     }
     241                 :          0 : }
     242                 :            : 
     243                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10