LCOV - code coverage report
Current view: top level - fpicker/source/office - PlacesListBox.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 124 0.0 %
Date: 2014-04-14 Functions: 0 25 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10