LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/dialog - checklbx.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 113 0.9 %
Date: 2013-07-09 Functions: 2 23 8.7 %
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             : // -----------------------------------------------------------------------
      51             : 
      52           0 : SvxCheckListBox::SvxCheckListBox( Window* pParent, const ResId& rResId ) :
      53             : 
      54           0 :     SvTreeListBox( pParent, rResId )
      55             : 
      56             : {
      57           0 :     Init_Impl();
      58           0 : }
      59             : 
      60             : // -----------------------------------------------------------------------
      61             : 
      62           0 : SvxCheckListBox::SvxCheckListBox( Window* pParent, const ResId& rResId,
      63             :                                   const Image& rNormalStaticImage )
      64           0 :     : SvTreeListBox( pParent, rResId )
      65             : 
      66             : {
      67           0 :     Init_Impl();
      68           0 :     pCheckButton->aBmps[SV_BMP_STATICIMAGE] = rNormalStaticImage;
      69           0 : }
      70             : 
      71             : // -----------------------------------------------------------------------
      72             : 
      73           0 : SvxCheckListBox::~SvxCheckListBox()
      74             : {
      75           0 :     delete pCheckButton;
      76           0 : }
      77             : 
      78             : // -----------------------------------------------------------------------
      79             : 
      80           0 : void SvxCheckListBox::Init_Impl()
      81             : {
      82           0 :     pCheckButton = new SvLBoxButtonData( this );
      83           0 :     EnableCheckButton( pCheckButton );
      84           0 : }
      85             : 
      86             : // -----------------------------------------------------------------------
      87             : 
      88           0 : void SvxCheckListBox::InsertEntry( const String& rStr, sal_uInt16 nPos,
      89             :                                    void* pUserData,
      90             :                                    SvLBoxButtonKind eButtonKind )
      91             : {
      92             :     SvTreeListBox::InsertEntry( rStr, NULL, sal_False, nPos, pUserData,
      93           0 :                                 eButtonKind );
      94           0 : }
      95             : 
      96             : // -----------------------------------------------------------------------
      97             : 
      98           0 : void SvxCheckListBox::RemoveEntry( sal_uInt16 nPos )
      99             : {
     100           0 :     if ( nPos < GetEntryCount() )
     101           0 :         SvTreeListBox::GetModel()->Remove( GetEntry( nPos ) );
     102           0 : }
     103             : 
     104             : // -----------------------------------------------------------------------
     105             : 
     106           0 : void SvxCheckListBox::SelectEntryPos( sal_uInt16 nPos, sal_Bool bSelect )
     107             : {
     108           0 :     if ( nPos < GetEntryCount() )
     109           0 :         Select( GetEntry( nPos ), bSelect );
     110           0 : }
     111             : 
     112             : // -----------------------------------------------------------------------
     113             : 
     114           0 : sal_uInt16 SvxCheckListBox::GetSelectEntryPos() const
     115             : {
     116           0 :     SvTreeListEntry* pEntry = GetCurEntry();
     117             : 
     118           0 :     if ( pEntry )
     119           0 :         return (sal_uInt16)GetModel()->GetAbsPos( pEntry );
     120           0 :     return LISTBOX_ENTRY_NOTFOUND;
     121             : }
     122             : 
     123             : // -----------------------------------------------------------------------
     124             : 
     125           0 : String SvxCheckListBox::GetText( sal_uInt16 nPos ) const
     126             : {
     127           0 :     SvTreeListEntry* pEntry = GetEntry( nPos );
     128             : 
     129           0 :     if ( pEntry )
     130           0 :         return GetEntryText( pEntry );
     131           0 :     return String();
     132             : }
     133             : 
     134             : // -----------------------------------------------------------------------
     135             : 
     136           0 : sal_uInt16 SvxCheckListBox::GetCheckedEntryCount() const
     137             : {
     138           0 :     sal_uInt16 nCheckCount = 0;
     139           0 :     sal_uInt16 nCount = (sal_uInt16)GetEntryCount();
     140             : 
     141           0 :     for ( sal_uInt16 i = 0; i < nCount; ++i )
     142             :     {
     143           0 :         if ( IsChecked( i ) )
     144           0 :             nCheckCount++;
     145             :     }
     146           0 :     return nCheckCount;
     147             : }
     148             : 
     149             : // -----------------------------------------------------------------------
     150             : 
     151           0 : void SvxCheckListBox::CheckEntryPos( sal_uInt16 nPos, sal_Bool bCheck )
     152             : {
     153           0 :     if ( nPos < GetEntryCount() )
     154             :         SetCheckButtonState(
     155             :             GetEntry( nPos ), bCheck ? SvButtonState( SV_BUTTON_CHECKED ) :
     156           0 :                                        SvButtonState( SV_BUTTON_UNCHECKED ) );
     157           0 : }
     158             : 
     159             : // -----------------------------------------------------------------------
     160             : 
     161           0 : sal_Bool SvxCheckListBox::IsChecked( sal_uInt16 nPos ) const
     162             : {
     163           0 :     if ( nPos < GetEntryCount() )
     164           0 :         return (GetCheckButtonState( GetEntry( nPos ) ) == SV_BUTTON_CHECKED);
     165             :     else
     166           0 :         return sal_False;
     167             : }
     168             : 
     169             : // -----------------------------------------------------------------------
     170             : 
     171           0 : void* SvxCheckListBox::SetEntryData ( sal_uInt16 nPos, void* pNewData )
     172             : {
     173           0 :     void* pOld = NULL;
     174             : 
     175           0 :     if ( nPos < GetEntryCount() )
     176             :     {
     177           0 :         pOld = GetEntry( nPos )->GetUserData();
     178           0 :         GetEntry( nPos )->SetUserData( pNewData );
     179             :     }
     180           0 :     return pOld;
     181             : }
     182             : 
     183             : // -----------------------------------------------------------------------
     184             : 
     185           0 : void* SvxCheckListBox::GetEntryData( sal_uInt16 nPos ) const
     186             : {
     187           0 :     if ( nPos < GetEntryCount() )
     188           0 :         return GetEntry( nPos )->GetUserData();
     189             :     else
     190           0 :         return NULL;
     191             : }
     192             : 
     193             : // -----------------------------------------------------------------------
     194             : 
     195           0 : void SvxCheckListBox::ToggleCheckButton( SvTreeListEntry* pEntry )
     196             : {
     197           0 :     if ( pEntry )
     198             :     {
     199           0 :         if ( !IsSelected( pEntry ) )
     200           0 :             Select( pEntry );
     201             :         else
     202           0 :             CheckEntryPos( GetSelectEntryPos(), !IsChecked( GetSelectEntryPos() ) );
     203             :     }
     204           0 : }
     205             : 
     206             : // -----------------------------------------------------------------------
     207             : 
     208           0 : void SvxCheckListBox::MouseButtonDown( const MouseEvent& rMEvt )
     209             : {
     210           0 :     if ( rMEvt.IsLeft() )
     211             :     {
     212           0 :         const Point aPnt = rMEvt.GetPosPixel();
     213           0 :         SvTreeListEntry* pEntry = GetEntry( aPnt );
     214             : 
     215           0 :         if ( pEntry )
     216             :         {
     217           0 :             sal_Bool bCheck = ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED );
     218           0 :             SvLBoxItem* pItem = GetItem( pEntry, aPnt.X() );
     219             : 
     220           0 :             if (pItem && pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
     221             :             {
     222           0 :                 SvTreeListBox::MouseButtonDown( rMEvt );
     223           0 :                 Select( pEntry, sal_True );
     224           0 :                 return;
     225             :             }
     226             :             else
     227             :             {
     228           0 :                 ToggleCheckButton( pEntry );
     229           0 :                 SvTreeListBox::MouseButtonDown( rMEvt );
     230             : 
     231             :                 // check if the entry below the mouse changed during the base method call. This is possible if,
     232             :                 // for instance, a handler invoked by the base class tampers with the list entries.
     233           0 :                 const SvTreeListEntry* pNewEntry = GetEntry( aPnt );
     234           0 :                 if ( pNewEntry != pEntry )
     235           0 :                     return;
     236             : 
     237           0 :                 if ( bCheck != ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED ) )
     238           0 :                     CheckButtonHdl();
     239           0 :                 return;
     240             :             }
     241             :         }
     242             :     }
     243           0 :     SvTreeListBox::MouseButtonDown( rMEvt );
     244             : }
     245             : 
     246             : // -----------------------------------------------------------------------
     247             : 
     248           0 : void SvxCheckListBox::KeyInput( const KeyEvent& rKEvt )
     249             : {
     250           0 :     const KeyCode& rKey = rKEvt.GetKeyCode();
     251             : 
     252           0 :     if ( rKey.GetCode() == KEY_RETURN || rKey.GetCode() == KEY_SPACE )
     253             :     {
     254           0 :         SvTreeListEntry* pEntry = GetCurEntry();
     255             : 
     256           0 :         if ( pEntry )
     257             :         {
     258           0 :             sal_Bool bCheck = ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED );
     259           0 :             ToggleCheckButton( pEntry );
     260           0 :             if ( bCheck != ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED ) )
     261           0 :                 CheckButtonHdl();
     262             :         }
     263             :     }
     264           0 :     else if ( GetEntryCount() )
     265           0 :         SvTreeListBox::KeyInput( rKEvt );
     266           0 : }
     267             : 
     268             : // -----------------------------------------------------------------------
     269             : 
     270           0 : SvTreeListEntry* SvxCheckListBox::InsertEntry( const XubString& rText, SvTreeListEntry* pParent, sal_Bool bChildrenOnDemand, sal_uIntPtr nPos, void* pUserData, SvLBoxButtonKind eButtonKind )
     271             : {
     272           0 :     return SvTreeListBox::InsertEntry( rText, pParent, bChildrenOnDemand, nPos, pUserData, eButtonKind );
     273         258 : }
     274             : 
     275             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10