LCOV - code coverage report
Current view: top level - svx/source/dialog - checklbx.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 103 0.0 %
Date: 2012-08-25 Functions: 0 20 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 90 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <tools/shl.hxx>
      30                 :            : 
      31                 :            : #define _SVX_CHECKLBX_CXX
      32                 :            : 
      33                 :            : #include <svx/checklbx.hxx>
      34                 :            : #include <svx/dialmgr.hxx>
      35                 :            : 
      36                 :            : #include <svx/dialogs.hrc>
      37                 :            : 
      38                 :            : // class SvxCheckListBox -------------------------------------------------
      39                 :            : 
      40                 :          0 : SvxCheckListBox::SvxCheckListBox( Window* pParent, WinBits nWinStyle ) :
      41                 :            : 
      42                 :          0 :     SvTreeListBox( pParent, nWinStyle )
      43                 :            : 
      44                 :            : {
      45         [ #  # ]:          0 :     Init_Impl();
      46                 :          0 : }
      47                 :            : 
      48                 :            : // -----------------------------------------------------------------------
      49                 :            : 
      50                 :          0 : SvxCheckListBox::SvxCheckListBox( Window* pParent, const ResId& rResId ) :
      51                 :            : 
      52                 :          0 :     SvTreeListBox( pParent, rResId )
      53                 :            : 
      54                 :            : {
      55         [ #  # ]:          0 :     Init_Impl();
      56                 :          0 : }
      57                 :            : 
      58                 :            : // -----------------------------------------------------------------------
      59                 :            : 
      60                 :          0 : SvxCheckListBox::SvxCheckListBox( Window* pParent, const ResId& rResId,
      61                 :            :                                   const Image& rNormalStaticImage )
      62                 :          0 :     : SvTreeListBox( pParent, rResId )
      63                 :            : 
      64                 :            : {
      65         [ #  # ]:          0 :     Init_Impl();
      66         [ #  # ]:          0 :     pCheckButton->aBmps[SV_BMP_STATICIMAGE] = rNormalStaticImage;
      67                 :          0 : }
      68                 :            : 
      69                 :            : // -----------------------------------------------------------------------
      70                 :            : 
      71                 :          0 : SvxCheckListBox::~SvxCheckListBox()
      72                 :            : {
      73 [ #  # ][ #  # ]:          0 :     delete pCheckButton;
      74         [ #  # ]:          0 : }
      75                 :            : 
      76                 :            : // -----------------------------------------------------------------------
      77                 :            : 
      78                 :          0 : void SvxCheckListBox::Init_Impl()
      79                 :            : {
      80         [ #  # ]:          0 :     pCheckButton = new SvLBoxButtonData( this );
      81                 :          0 :     EnableCheckButton( pCheckButton );
      82                 :          0 : }
      83                 :            : 
      84                 :            : // -----------------------------------------------------------------------
      85                 :            : 
      86                 :          0 : void SvxCheckListBox::InsertEntry( const String& rStr, sal_uInt16 nPos,
      87                 :            :                                    void* pUserData,
      88                 :            :                                    SvLBoxButtonKind eButtonKind )
      89                 :            : {
      90                 :            :     SvTreeListBox::InsertEntry( rStr, NULL, sal_False, nPos, pUserData,
      91                 :          0 :                                 eButtonKind );
      92                 :          0 : }
      93                 :            : 
      94                 :            : // -----------------------------------------------------------------------
      95                 :            : 
      96                 :          0 : void SvxCheckListBox::RemoveEntry( sal_uInt16 nPos )
      97                 :            : {
      98         [ #  # ]:          0 :     if ( nPos < GetEntryCount() )
      99                 :          0 :         SvTreeListBox::GetModel()->Remove( GetEntry( nPos ) );
     100                 :          0 : }
     101                 :            : 
     102                 :            : // -----------------------------------------------------------------------
     103                 :            : 
     104                 :          0 : void SvxCheckListBox::SelectEntryPos( sal_uInt16 nPos, sal_Bool bSelect )
     105                 :            : {
     106         [ #  # ]:          0 :     if ( nPos < GetEntryCount() )
     107                 :          0 :         Select( GetEntry( nPos ), bSelect );
     108                 :          0 : }
     109                 :            : 
     110                 :            : // -----------------------------------------------------------------------
     111                 :            : 
     112                 :          0 : sal_uInt16 SvxCheckListBox::GetSelectEntryPos() const
     113                 :            : {
     114                 :          0 :     SvLBoxEntry* pEntry = GetCurEntry();
     115                 :            : 
     116         [ #  # ]:          0 :     if ( pEntry )
     117                 :          0 :         return (sal_uInt16)GetModel()->GetAbsPos( pEntry );
     118                 :          0 :     return LISTBOX_ENTRY_NOTFOUND;
     119                 :            : }
     120                 :            : 
     121                 :            : // -----------------------------------------------------------------------
     122                 :            : 
     123                 :          0 : String SvxCheckListBox::GetText( sal_uInt16 nPos ) const
     124                 :            : {
     125                 :          0 :     SvLBoxEntry* pEntry = GetEntry( nPos );
     126                 :            : 
     127         [ #  # ]:          0 :     if ( pEntry )
     128                 :          0 :         return GetEntryText( pEntry );
     129                 :          0 :     return String();
     130                 :            : }
     131                 :            : 
     132                 :            : // -----------------------------------------------------------------------
     133                 :            : 
     134                 :          0 : sal_uInt16 SvxCheckListBox::GetCheckedEntryCount() const
     135                 :            : {
     136                 :          0 :     sal_uInt16 nCheckCount = 0;
     137                 :          0 :     sal_uInt16 nCount = (sal_uInt16)GetEntryCount();
     138                 :            : 
     139         [ #  # ]:          0 :     for ( sal_uInt16 i = 0; i < nCount; ++i )
     140                 :            :     {
     141         [ #  # ]:          0 :         if ( IsChecked( i ) )
     142                 :          0 :             nCheckCount++;
     143                 :            :     }
     144                 :          0 :     return nCheckCount;
     145                 :            : }
     146                 :            : 
     147                 :            : // -----------------------------------------------------------------------
     148                 :            : 
     149                 :          0 : void SvxCheckListBox::CheckEntryPos( sal_uInt16 nPos, sal_Bool bCheck )
     150                 :            : {
     151         [ #  # ]:          0 :     if ( nPos < GetEntryCount() )
     152                 :            :         SetCheckButtonState(
     153                 :            :             GetEntry( nPos ), bCheck ? SvButtonState( SV_BUTTON_CHECKED ) :
     154         [ #  # ]:          0 :                                        SvButtonState( SV_BUTTON_UNCHECKED ) );
     155                 :          0 : }
     156                 :            : 
     157                 :            : // -----------------------------------------------------------------------
     158                 :            : 
     159                 :          0 : sal_Bool SvxCheckListBox::IsChecked( sal_uInt16 nPos ) const
     160                 :            : {
     161         [ #  # ]:          0 :     if ( nPos < GetEntryCount() )
     162                 :          0 :         return (GetCheckButtonState( GetEntry( nPos ) ) == SV_BUTTON_CHECKED);
     163                 :            :     else
     164                 :          0 :         return sal_False;
     165                 :            : }
     166                 :            : 
     167                 :            : // -----------------------------------------------------------------------
     168                 :            : 
     169                 :          0 : void* SvxCheckListBox::SetEntryData ( sal_uInt16 nPos, void* pNewData )
     170                 :            : {
     171                 :          0 :     void* pOld = NULL;
     172                 :            : 
     173         [ #  # ]:          0 :     if ( nPos < GetEntryCount() )
     174                 :            :     {
     175                 :          0 :         pOld = GetEntry( nPos )->GetUserData();
     176                 :          0 :         GetEntry( nPos )->SetUserData( pNewData );
     177                 :            :     }
     178                 :          0 :     return pOld;
     179                 :            : }
     180                 :            : 
     181                 :            : // -----------------------------------------------------------------------
     182                 :            : 
     183                 :          0 : void* SvxCheckListBox::GetEntryData( sal_uInt16 nPos ) const
     184                 :            : {
     185         [ #  # ]:          0 :     if ( nPos < GetEntryCount() )
     186                 :          0 :         return GetEntry( nPos )->GetUserData();
     187                 :            :     else
     188                 :          0 :         return NULL;
     189                 :            : }
     190                 :            : 
     191                 :            : // -----------------------------------------------------------------------
     192                 :            : 
     193                 :          0 : void SvxCheckListBox::ToggleCheckButton( SvLBoxEntry* pEntry )
     194                 :            : {
     195         [ #  # ]:          0 :     if ( pEntry )
     196                 :            :     {
     197         [ #  # ]:          0 :         if ( !IsSelected( pEntry ) )
     198                 :          0 :             Select( pEntry );
     199                 :            :         else
     200                 :          0 :             CheckEntryPos( GetSelectEntryPos(), !IsChecked( GetSelectEntryPos() ) );
     201                 :            :     }
     202                 :          0 : }
     203                 :            : 
     204                 :            : // -----------------------------------------------------------------------
     205                 :            : 
     206                 :          0 : void SvxCheckListBox::MouseButtonDown( const MouseEvent& rMEvt )
     207                 :            : {
     208         [ #  # ]:          0 :     if ( rMEvt.IsLeft() )
     209                 :            :     {
     210                 :          0 :         const Point aPnt = rMEvt.GetPosPixel();
     211         [ #  # ]:          0 :         SvLBoxEntry* pEntry = GetEntry( aPnt );
     212                 :            : 
     213         [ #  # ]:          0 :         if ( pEntry )
     214                 :            :         {
     215         [ #  # ]:          0 :             sal_Bool bCheck = ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED );
     216         [ #  # ]:          0 :             SvLBoxItem* pItem = GetItem( pEntry, aPnt.X() );
     217                 :            : 
     218 [ #  # ][ #  # ]:          0 :             if ( pItem && pItem->IsA() == SV_ITEM_ID_LBOXBUTTON )
         [ #  # ][ #  # ]
     219                 :            :             {
     220         [ #  # ]:          0 :                 SvTreeListBox::MouseButtonDown( rMEvt );
     221         [ #  # ]:          0 :                 Select( pEntry, sal_True );
     222                 :            :                 return;
     223                 :            :             }
     224                 :            :             else
     225                 :            :             {
     226         [ #  # ]:          0 :                 ToggleCheckButton( pEntry );
     227         [ #  # ]:          0 :                 SvTreeListBox::MouseButtonDown( rMEvt );
     228                 :            : 
     229                 :            :                 // check if the entry below the mouse changed during the base method call. This is possible if,
     230                 :            :                 // for instance, a handler invoked by the base class tampers with the list entries.
     231         [ #  # ]:          0 :                 const SvLBoxEntry* pNewEntry = GetEntry( aPnt );
     232         [ #  # ]:          0 :                 if ( pNewEntry != pEntry )
     233                 :            :                     return;
     234                 :            : 
     235 [ #  # ][ #  # ]:          0 :                 if ( bCheck != ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED ) )
     236         [ #  # ]:          0 :                     CheckButtonHdl();
     237                 :            :                 return;
     238                 :            :             }
     239                 :            :         }
     240                 :            :     }
     241                 :          0 :     SvTreeListBox::MouseButtonDown( rMEvt );
     242                 :            : }
     243                 :            : 
     244                 :            : // -----------------------------------------------------------------------
     245                 :            : 
     246                 :          0 : void SvxCheckListBox::KeyInput( const KeyEvent& rKEvt )
     247                 :            : {
     248                 :          0 :     const KeyCode& rKey = rKEvt.GetKeyCode();
     249                 :            : 
     250 [ #  # ][ #  # ]:          0 :     if ( rKey.GetCode() == KEY_RETURN || rKey.GetCode() == KEY_SPACE )
                 [ #  # ]
     251                 :            :     {
     252                 :          0 :         SvLBoxEntry* pEntry = GetCurEntry();
     253                 :            : 
     254         [ #  # ]:          0 :         if ( pEntry )
     255                 :            :         {
     256                 :          0 :             sal_Bool bCheck = ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED );
     257                 :          0 :             ToggleCheckButton( pEntry );
     258         [ #  # ]:          0 :             if ( bCheck != ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED ) )
     259                 :          0 :                 CheckButtonHdl();
     260                 :            :         }
     261                 :            :     }
     262         [ #  # ]:          0 :     else if ( GetEntryCount() )
     263                 :          0 :         SvTreeListBox::KeyInput( rKEvt );
     264                 :          0 : }
     265                 :            : 
     266                 :            : // -----------------------------------------------------------------------
     267                 :            : 
     268                 :          0 : SvLBoxEntry* SvxCheckListBox::InsertEntry( const XubString& rText, SvLBoxEntry* pParent, sal_Bool bChildrenOnDemand, sal_uIntPtr nPos, void* pUserData, SvLBoxButtonKind eButtonKind )
     269                 :            : {
     270                 :          0 :     return SvTreeListBox::InsertEntry( rText, pParent, bChildrenOnDemand, nPos, pUserData, eButtonKind );
     271                 :            : }
     272                 :            : 
     273                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10