LCOV - code coverage report
Current view: top level - svx/source/dialog - checklbx.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 108 0.0 %
Date: 2014-04-11 Functions: 0 20 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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <tools/shl.hxx>
      21             : 
      22             : #include <svtools/treelistentry.hxx>
      23             : 
      24             : #include <svx/checklbx.hxx>
      25             : #include <svx/dialmgr.hxx>
      26             : 
      27             : #include <svx/dialogs.hrc>
      28             : 
      29             : #include <vcl/builder.hxx>
      30             : 
      31             : // class SvxCheckListBox -------------------------------------------------
      32             : 
      33           0 : SvxCheckListBox::SvxCheckListBox( Window* pParent, WinBits nWinStyle ) :
      34             : 
      35           0 :     SvTreeListBox( pParent, nWinStyle )
      36             : 
      37             : {
      38           0 :     Init_Impl();
      39           0 : }
      40             : 
      41           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSvxCheckListBox(Window *pParent, VclBuilder::stringmap &rMap)
      42             : {
      43           0 :     WinBits nWinStyle = WB_TABSTOP;
      44           0 :     OString sBorder = VclBuilder::extractCustomProperty(rMap);
      45           0 :     if (!sBorder.isEmpty())
      46           0 :         nWinStyle |= WB_BORDER;
      47           0 :     return new SvxCheckListBox(pParent, nWinStyle);
      48             : }
      49             : 
      50           0 : SvxCheckListBox::SvxCheckListBox( Window* pParent, const ResId& rResId,
      51             :                                   const Image& rNormalStaticImage )
      52           0 :     : SvTreeListBox( pParent, rResId )
      53             : 
      54             : {
      55           0 :     Init_Impl();
      56           0 :     pCheckButton->aBmps[SV_BMP_STATICIMAGE] = rNormalStaticImage;
      57           0 : }
      58             : 
      59           0 : SvxCheckListBox::~SvxCheckListBox()
      60             : {
      61           0 :     delete pCheckButton;
      62           0 : }
      63             : 
      64             : 
      65             : 
      66           0 : void SvxCheckListBox::Init_Impl()
      67             : {
      68           0 :     pCheckButton = new SvLBoxButtonData( this );
      69           0 :     EnableCheckButton( pCheckButton );
      70           0 : }
      71             : 
      72             : 
      73             : 
      74           0 : void SvxCheckListBox::InsertEntry( const OUString& rStr, sal_uLong nPos,
      75             :                                    void* pUserData,
      76             :                                    SvLBoxButtonKind eButtonKind )
      77             : {
      78             :     SvTreeListBox::InsertEntry( rStr, NULL, false, nPos, pUserData,
      79           0 :                                 eButtonKind );
      80           0 : }
      81             : 
      82             : 
      83             : 
      84           0 : void SvxCheckListBox::RemoveEntry( sal_uLong nPos )
      85             : {
      86           0 :     if ( nPos < GetEntryCount() )
      87           0 :         SvTreeListBox::GetModel()->Remove( GetEntry( nPos ) );
      88           0 : }
      89             : 
      90             : 
      91             : 
      92           0 : void SvxCheckListBox::SelectEntryPos( sal_uLong nPos, bool bSelect )
      93             : {
      94           0 :     if ( nPos < GetEntryCount() )
      95           0 :         Select( GetEntry( nPos ), bSelect );
      96           0 : }
      97             : 
      98             : 
      99             : 
     100           0 : sal_uLong SvxCheckListBox::GetSelectEntryPos() const
     101             : {
     102           0 :     SvTreeListEntry* pEntry = GetCurEntry();
     103             : 
     104           0 :     if ( pEntry )
     105           0 :         return GetModel()->GetAbsPos( pEntry );
     106           0 :     return TREELIST_ENTRY_NOTFOUND;
     107             : }
     108             : 
     109             : 
     110             : 
     111           0 : OUString SvxCheckListBox::GetText( sal_uLong nPos ) const
     112             : {
     113           0 :     SvTreeListEntry* pEntry = GetEntry( nPos );
     114             : 
     115           0 :     if ( pEntry )
     116           0 :         return GetEntryText( pEntry );
     117           0 :     return OUString();
     118             : }
     119             : 
     120             : 
     121             : 
     122           0 : sal_uLong SvxCheckListBox::GetCheckedEntryCount() const
     123             : {
     124           0 :     sal_uLong nCheckCount = 0;
     125           0 :     sal_uLong nCount = GetEntryCount();
     126             : 
     127           0 :     for ( sal_uLong i = 0; i < nCount; ++i )
     128             :     {
     129           0 :         if ( IsChecked( i ) )
     130           0 :             nCheckCount++;
     131             :     }
     132           0 :     return nCheckCount;
     133             : }
     134             : 
     135             : 
     136             : 
     137           0 : void SvxCheckListBox::CheckEntryPos( sal_uLong nPos, bool bCheck )
     138             : {
     139           0 :     if ( nPos < GetEntryCount() )
     140             :         SetCheckButtonState(
     141             :             GetEntry( nPos ), bCheck ? SvButtonState( SV_BUTTON_CHECKED ) :
     142           0 :                                        SvButtonState( SV_BUTTON_UNCHECKED ) );
     143           0 : }
     144             : 
     145             : 
     146             : 
     147           0 : bool SvxCheckListBox::IsChecked( sal_uLong nPos ) const
     148             : {
     149           0 :     if ( nPos < GetEntryCount() )
     150           0 :         return (GetCheckButtonState( GetEntry( nPos ) ) == SV_BUTTON_CHECKED);
     151             :     else
     152           0 :         return false;
     153             : }
     154             : 
     155             : 
     156             : 
     157           0 : void* SvxCheckListBox::SetEntryData ( sal_uLong nPos, void* pNewData )
     158             : {
     159           0 :     void* pOld = NULL;
     160             : 
     161           0 :     if ( nPos < GetEntryCount() )
     162             :     {
     163           0 :         pOld = GetEntry( nPos )->GetUserData();
     164           0 :         GetEntry( nPos )->SetUserData( pNewData );
     165             :     }
     166           0 :     return pOld;
     167             : }
     168             : 
     169             : 
     170             : 
     171           0 : void* SvxCheckListBox::GetEntryData( sal_uLong nPos ) const
     172             : {
     173           0 :     if ( nPos < GetEntryCount() )
     174           0 :         return GetEntry( nPos )->GetUserData();
     175             :     else
     176           0 :         return NULL;
     177             : }
     178             : 
     179             : 
     180             : 
     181           0 : void SvxCheckListBox::ToggleCheckButton( SvTreeListEntry* pEntry )
     182             : {
     183           0 :     if ( pEntry )
     184             :     {
     185           0 :         if ( !IsSelected( pEntry ) )
     186           0 :             Select( pEntry );
     187             :         else
     188           0 :             CheckEntryPos( GetSelectEntryPos(), !IsChecked( GetSelectEntryPos() ) );
     189             :     }
     190           0 : }
     191             : 
     192             : 
     193             : 
     194           0 : void SvxCheckListBox::MouseButtonDown( const MouseEvent& rMEvt )
     195             : {
     196           0 :     if ( rMEvt.IsLeft() )
     197             :     {
     198           0 :         const Point aPnt = rMEvt.GetPosPixel();
     199           0 :         SvTreeListEntry* pEntry = GetEntry( aPnt );
     200             : 
     201           0 :         if ( pEntry )
     202             :         {
     203           0 :             bool bCheck = ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED );
     204           0 :             SvLBoxItem* pItem = GetItem( pEntry, aPnt.X() );
     205             : 
     206           0 :             if (pItem && pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
     207             :             {
     208           0 :                 SvTreeListBox::MouseButtonDown( rMEvt );
     209           0 :                 Select( pEntry, true );
     210           0 :                 return;
     211             :             }
     212             :             else
     213             :             {
     214           0 :                 ToggleCheckButton( pEntry );
     215           0 :                 SvTreeListBox::MouseButtonDown( rMEvt );
     216             : 
     217             :                 // check if the entry below the mouse changed during the base method call. This is possible if,
     218             :                 // for instance, a handler invoked by the base class tampers with the list entries.
     219           0 :                 const SvTreeListEntry* pNewEntry = GetEntry( aPnt );
     220           0 :                 if ( pNewEntry != pEntry )
     221           0 :                     return;
     222             : 
     223           0 :                 if ( bCheck != ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED ) )
     224           0 :                     CheckButtonHdl();
     225           0 :                 return;
     226             :             }
     227             :         }
     228             :     }
     229           0 :     SvTreeListBox::MouseButtonDown( rMEvt );
     230             : }
     231             : 
     232             : 
     233             : 
     234           0 : void SvxCheckListBox::KeyInput( const KeyEvent& rKEvt )
     235             : {
     236           0 :     const KeyCode& rKey = rKEvt.GetKeyCode();
     237             : 
     238           0 :     if ( rKey.GetCode() == KEY_RETURN || rKey.GetCode() == KEY_SPACE )
     239             :     {
     240           0 :         SvTreeListEntry* pEntry = GetCurEntry();
     241             : 
     242           0 :         if ( pEntry )
     243             :         {
     244           0 :             bool bCheck = ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED );
     245           0 :             ToggleCheckButton( pEntry );
     246           0 :             if ( bCheck != ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED ) )
     247           0 :                 CheckButtonHdl();
     248             :         }
     249             :     }
     250           0 :     else if ( GetEntryCount() )
     251           0 :         SvTreeListBox::KeyInput( rKEvt );
     252           0 : }
     253             : 
     254             : 
     255             : 
     256           0 : SvTreeListEntry* SvxCheckListBox::InsertEntry( const OUString& rText, SvTreeListEntry* pParent, bool bChildrenOnDemand, sal_uIntPtr nPos, void* pUserData, SvLBoxButtonKind eButtonKind )
     257             : {
     258           0 :     return SvTreeListBox::InsertEntry( rText, pParent, bChildrenOnDemand, nPos, pUserData, eButtonKind );
     259             : }
     260             : 
     261             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10