LCOV - code coverage report
Current view: top level - libreoffice/fpicker/source/office - PlacesListBox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 124 0.0 %
Date: 2012-12-27 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             :  * 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             : 
      40           0 : PlacesListBox_Impl::PlacesListBox_Impl( PlacesListBox* pParent, const OUString& rTitle ) :
      41             :     SvHeaderTabListBox( pParent, WB_TABSTOP | WB_NOINITIALSELECTION ),
      42             :     mpHeaderBar( NULL ),
      43           0 :     mpParent( pParent )
      44             : {
      45           0 :     Size aBoxSize = pParent->GetSizePixel( );
      46           0 :     mpHeaderBar = new HeaderBar( pParent, WB_BUTTONSTYLE | WB_BOTTOMBORDER );
      47           0 :     mpHeaderBar->SetPosSizePixel( Point( 0, 0 ), Size( 600, 16 ) );
      48             : 
      49           0 :     long pTabs[] = { 2, 20, 600 };
      50           0 :     SetTabs( &pTabs[0], MAP_PIXEL );
      51           0 :     mpHeaderBar->InsertItem( COLUMN_NAME, rTitle, 600, HIB_LEFT | HIB_VCENTER );
      52             : 
      53           0 :     Size aHeadSize = mpHeaderBar->GetSizePixel();
      54             :     SetPosSizePixel( Point( 0, aHeadSize.getHeight() ),
      55           0 :                   Size( aBoxSize.getWidth(), aBoxSize.getHeight() - aHeadSize.getHeight() ) );
      56             : 
      57           0 :     InitHeaderBar( mpHeaderBar );
      58             : 
      59           0 :     Show( );
      60           0 :     mpHeaderBar->Show();
      61           0 : }
      62             : 
      63           0 : PlacesListBox_Impl::~PlacesListBox_Impl( )
      64             : {
      65           0 :     delete mpHeaderBar;
      66           0 :     mpParent = NULL;
      67           0 : }
      68             : 
      69           0 : void PlacesListBox_Impl::MouseButtonUp( const MouseEvent& rMEvt )
      70             : {
      71           0 :     SvHeaderTabListBox::MouseButtonUp( rMEvt );
      72           0 :     mpParent->updateView( );
      73           0 : }
      74             : 
      75           0 : PlacesListBox::PlacesListBox( SvtFileDialog* pFileDlg, const OUString& rTitle, const ResId& rResId ) :
      76             :     Control( pFileDlg, rResId ),
      77             :     maPlaces( ),
      78             :     mpDlg( pFileDlg ),
      79             :     mpImpl( NULL ),
      80             :     mpAddBtn( ),
      81             :     mpDelBtn( ),
      82             :     mnNbEditables( 0 ),
      83             :     mbUpdated( false ),
      84           0 :     mbSelectionChanged( false )
      85             : {
      86           0 :     mpImpl = new PlacesListBox_Impl( this, rTitle );
      87             : 
      88           0 :     mpImpl->SetSelectHdl( LINK( this, PlacesListBox, Selection ) );
      89           0 :     mpImpl->SetDoubleClickHdl( LINK( this, PlacesListBox, DoubleClick ) ) ;
      90             : 
      91           0 :     mpAddBtn = new ImageButton( this, 0 );
      92           0 :     mpAddBtn->SetText( OUString( "+" ) );
      93           0 :     mpAddBtn->SetPosSizePixel( Point( 0, 0 ), Size( 24, 24 ) );
      94           0 :     mpAddBtn->Show();
      95             : 
      96           0 :     mpDelBtn = new ImageButton( this, 0 );
      97           0 :     mpDelBtn->SetText( OUString( "-" ) );
      98           0 :     mpDelBtn->SetPosSizePixel( Point( 0, 0 ), Size( 24, 24 ) );
      99           0 :     mpDelBtn->Show();
     100           0 : }
     101             : 
     102           0 : PlacesListBox::~PlacesListBox( )
     103             : {
     104           0 :     delete mpImpl;
     105           0 :     delete mpAddBtn;
     106           0 :     delete mpDelBtn;
     107           0 : }
     108             : 
     109           0 : void PlacesListBox::AppendPlace( PlacePtr pPlace )
     110             : {
     111           0 :     maPlaces.push_back( pPlace );
     112           0 :     mpImpl->InsertEntry( pPlace->GetName( ),
     113           0 :             getEntryIcon( pPlace ), getEntryIcon( pPlace ) );
     114             : 
     115           0 :     if(pPlace->IsEditable()) {
     116           0 :         ++mnNbEditables;
     117           0 :         mbUpdated = true;
     118             :     }
     119           0 : }
     120             : 
     121           0 : sal_Int32 PlacesListBox::GetNbEditablePlaces() {
     122           0 :     return mnNbEditables;
     123             : }
     124             : 
     125           0 : bool PlacesListBox::IsUpdated() {
     126           0 :     if(mbUpdated) {
     127           0 :         mbUpdated = false;
     128           0 :         return true;
     129             :     }
     130           0 :     return false;
     131             : }
     132             : 
     133           0 : const std::vector<PlacePtr>& PlacesListBox::GetPlaces() {
     134           0 :     return maPlaces;
     135             : }
     136             : 
     137           0 : void PlacesListBox::RemovePlace( sal_uInt16 nPos )
     138             : {
     139           0 :     if ( nPos < maPlaces.size() )
     140             :     {
     141           0 :         if(maPlaces[nPos]->IsEditable()) {
     142           0 :             --mnNbEditables;
     143           0 :             mbUpdated = true;
     144             :         }
     145           0 :         maPlaces.erase( maPlaces.begin() + nPos );
     146           0 :         SvTreeListEntry* pEntry = mpImpl->GetEntry( nPos );
     147           0 :         mpImpl->RemoveEntry( pEntry );
     148             :     }
     149           0 : }
     150             : 
     151           0 : void PlacesListBox::RemoveSelectedPlace() {
     152           0 :     RemovePlace(mpImpl->GetCurrRow());
     153           0 : }
     154             : 
     155           0 : void PlacesListBox::SetAddHdl( const Link& rHdl )
     156             : {
     157           0 :     mpAddBtn->SetClickHdl( rHdl );
     158           0 : }
     159             : 
     160           0 : void PlacesListBox::SetDelHdl( const Link& rHdl )
     161             : {
     162           0 :     mpDelBtn->SetClickHdl( rHdl );
     163           0 : }
     164             : 
     165           0 : void PlacesListBox::SetDelEnabled( bool enabled )
     166             : {
     167           0 :     mpDelBtn->Enable( enabled );
     168           0 : }
     169             : 
     170           0 : void PlacesListBox::SetSizePixel( const Size& rNewSize )
     171             : {
     172           0 :     Control::SetSizePixel( rNewSize );
     173           0 :     Size aListSize( rNewSize );
     174           0 :     aListSize.Height() -= 26 + 18;
     175           0 :     mpImpl->SetSizePixel( aListSize );
     176             : 
     177           0 :     sal_Int32 nBtnY = rNewSize.Height() - 26;
     178           0 :     mpAddBtn->SetPosPixel( Point( 3, nBtnY ) );
     179           0 :     mpDelBtn->SetPosPixel( Point( 6 + 24, nBtnY ) );
     180           0 : }
     181             : 
     182           0 : Image PlacesListBox::getEntryIcon( PlacePtr pPlace )
     183             : {
     184           0 :     Image theImage = mpDlg->GetButtonImage( IMG_FILEDLG_PLACE_LOCAL );
     185           0 :     if ( !pPlace->IsLocal( ) )
     186           0 :         theImage = mpDlg->GetButtonImage( IMG_FILEDLG_PLACE_REMOTE );
     187           0 :     return theImage;
     188             : }
     189             : 
     190           0 : IMPL_LINK( PlacesListBox, Selection, void* , EMPTYARG )
     191             : {
     192           0 :     sal_uInt32 nSelected = mpImpl->GetCurrRow();
     193           0 :     PlacePtr pPlace = maPlaces[nSelected];
     194             : 
     195           0 :     mbSelectionChanged = true;
     196           0 :     if(pPlace->IsEditable())
     197           0 :         mpDlg->RemovablePlaceSelected();
     198             :     else
     199           0 :         mpDlg->RemovablePlaceSelected(false);
     200           0 :     return 0;
     201             : }
     202             : 
     203           0 : IMPL_LINK ( PlacesListBox, DoubleClick, void*, EMPTYARG )
     204             : {
     205           0 :     sal_uInt16 nSelected = mpImpl->GetCurrRow();
     206           0 :     PlacePtr pPlace = maPlaces[nSelected];
     207           0 :     if ( pPlace->IsEditable() == true && !pPlace->IsLocal( ) )
     208             :     {
     209           0 :         PlaceEditDialog aDlg( mpDlg, pPlace );
     210           0 :         short aRetCode = aDlg.Execute();
     211           0 :         switch(aRetCode) {
     212             :             case RET_OK :
     213             :             {
     214           0 :                 pPlace->SetName ( aDlg.GetServerName() );
     215           0 :                 pPlace->SetUrl( aDlg.GetServerUrl() );
     216           0 :                 mbUpdated = true;
     217           0 :                 break;
     218             :             }
     219             :             case RET_NO :
     220             :             {
     221           0 :                 RemovePlace(nSelected);
     222           0 :                 break;
     223             :             }
     224             :             default:
     225           0 :                 break;
     226           0 :         };
     227             :     }
     228           0 :     return 0;
     229             : }
     230             : 
     231           0 : void PlacesListBox::updateView( )
     232             : {
     233           0 :     if ( mbSelectionChanged )
     234             :     {
     235           0 :         mbSelectionChanged = false;
     236           0 :         sal_uInt32 nSelected = mpImpl->GetCurrRow();
     237           0 :         PlacePtr pPlace = maPlaces[nSelected];
     238           0 :         mpDlg->OpenURL_Impl( pPlace->GetUrl( ) );
     239             :     }
     240           0 : }
     241             : 
     242             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10