LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/ui/control - marktree.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 96 0.0 %
Date: 2012-12-17 Functions: 0 11 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 "marktree.hxx"
      21             : #include "dbu_control.hrc"
      22             : #include <vcl/svapp.hxx>
      23             : 
      24             : namespace dbaui
      25             : {
      26             :     using namespace ::com::sun::star::uno;
      27             :     using namespace ::com::sun::star::lang;
      28             : 
      29             : #define SPACEBETWEENENTRIES     4
      30             : 
      31             : DBG_NAME(OMarkableTreeListBox)
      32             : 
      33           0 : OMarkableTreeListBox::OMarkableTreeListBox( Window* pParent, const Reference< XMultiServiceFactory >& _rxORB, WinBits nWinStyle )
      34           0 :     : DBTreeListBox(pParent,_rxORB,nWinStyle)
      35             : {
      36             :     DBG_CTOR(OMarkableTreeListBox,NULL);
      37             : 
      38           0 :     InitButtonData();
      39           0 : }
      40             : 
      41           0 : OMarkableTreeListBox::OMarkableTreeListBox( Window* pParent, const Reference< XMultiServiceFactory >& _rxORB, const ResId& rResId)
      42           0 :     : DBTreeListBox(pParent,_rxORB,rResId)
      43             : {
      44             :     DBG_CTOR(OMarkableTreeListBox,NULL);
      45             : 
      46           0 :     InitButtonData();
      47           0 : }
      48             : 
      49           0 : OMarkableTreeListBox::~OMarkableTreeListBox()
      50             : {
      51           0 :     delete m_pCheckButton;
      52             : 
      53             :     DBG_DTOR(OMarkableTreeListBox,NULL);
      54           0 : }
      55             : 
      56           0 : void OMarkableTreeListBox::Paint(const Rectangle& _rRect)
      57             : {
      58           0 :     if (!IsEnabled())
      59             :     {
      60           0 :         Font aOldFont = GetFont();
      61           0 :         Font aNewFont(aOldFont);
      62             : 
      63           0 :         StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings();
      64           0 :         aNewFont.SetColor(aSystemStyle.GetDisableColor());
      65             : 
      66           0 :         SetFont(aNewFont);
      67           0 :         DBTreeListBox::Paint(_rRect);
      68           0 :         SetFont(aOldFont);
      69             :     }
      70             :     else
      71           0 :         DBTreeListBox::Paint(_rRect);
      72           0 : }
      73             : 
      74           0 : void OMarkableTreeListBox::InitButtonData()
      75             : {
      76           0 :     m_pCheckButton = new SvLBoxButtonData( this );
      77           0 :     EnableCheckButton( m_pCheckButton );
      78           0 : }
      79             : 
      80           0 : void OMarkableTreeListBox::KeyInput( const KeyEvent& rKEvt )
      81             : {
      82             :     // only if there are spaces
      83           0 :     if (rKEvt.GetKeyCode().GetCode() == KEY_SPACE && !rKEvt.GetKeyCode().IsShift() && !rKEvt.GetKeyCode().IsMod1())
      84             :     {
      85           0 :         SvTreeListEntry* pCurrentHandlerEntry = GetHdlEntry();
      86           0 :         if(pCurrentHandlerEntry)
      87             :         {
      88           0 :             SvButtonState eState = GetCheckButtonState( pCurrentHandlerEntry);
      89           0 :             if(eState == SV_BUTTON_CHECKED)
      90           0 :                 SetCheckButtonState( pCurrentHandlerEntry, SV_BUTTON_UNCHECKED);
      91             :             else
      92           0 :                 SetCheckButtonState( pCurrentHandlerEntry, SV_BUTTON_CHECKED);
      93             : 
      94           0 :             CheckButtonHdl();
      95             :         }
      96             :         else
      97           0 :             DBTreeListBox::KeyInput(rKEvt);
      98             :     }
      99             :     else
     100           0 :         DBTreeListBox::KeyInput(rKEvt);
     101           0 : }
     102             : 
     103           0 : SvButtonState OMarkableTreeListBox::implDetermineState(SvTreeListEntry* _pEntry)
     104             : {
     105           0 :     SvButtonState eState = GetCheckButtonState(_pEntry);
     106           0 :     if (!GetModel()->HasChildren(_pEntry))
     107             :         // nothing to do in this bottom-up routine if there are no children ...
     108           0 :         return eState;
     109             : #ifdef DBG_UTIL
     110             :     String sEntryText  =GetEntryText(_pEntry);
     111             : #endif
     112             : 
     113             :     // loop through the children and check their states
     114           0 :     sal_uInt16 nCheckedChildren = 0;
     115           0 :     sal_uInt16 nChildrenOverall = 0;
     116             : 
     117           0 :     SvTreeListEntry* pChildLoop = GetModel()->FirstChild(_pEntry);
     118           0 :     while (pChildLoop)
     119             :     {
     120             : #ifdef DBG_UTIL
     121             :         String sChildText  =GetEntryText(pChildLoop);
     122             : #endif
     123           0 :         SvButtonState eChildState = implDetermineState(pChildLoop);
     124           0 :         if (SV_BUTTON_TRISTATE == eChildState)
     125           0 :             break;
     126             : 
     127           0 :         if (SV_BUTTON_CHECKED == eChildState)
     128           0 :             ++nCheckedChildren;
     129           0 :         ++nChildrenOverall;
     130             : 
     131           0 :         pChildLoop = GetModel()->NextSibling(pChildLoop);
     132             :     }
     133             : 
     134           0 :     if (pChildLoop)
     135             :     {
     136             :         // we did not finish the loop because at least one of the children is in tristate
     137           0 :         eState = SV_BUTTON_TRISTATE;
     138             : 
     139             :         // but this means that we did not finish all the siblings of pChildLoop,
     140             :         // so their checking may be incorrect at the moment
     141             :         // -> correct this
     142           0 :         while (pChildLoop)
     143             :         {
     144           0 :             implDetermineState(pChildLoop);
     145           0 :             pChildLoop = GetModel()->NextSibling(pChildLoop);
     146             :         }
     147             :     }
     148             :     else
     149             :         // none if the children are in tristate
     150           0 :         if (nCheckedChildren)
     151             :             // we have at least one child checked
     152           0 :             if (nCheckedChildren != nChildrenOverall)
     153             :                 // not all children are checked
     154           0 :                 eState = SV_BUTTON_TRISTATE;
     155             :             else
     156             :                 // all children are checked
     157           0 :                 eState = SV_BUTTON_CHECKED;
     158             :         else
     159             :             // no children are checked
     160           0 :             eState = SV_BUTTON_UNCHECKED;
     161             : 
     162             :     // finally set the entry to the state we just determined
     163           0 :     SetCheckButtonState(_pEntry, eState);
     164             : 
     165           0 :     return eState;
     166             : }
     167             : 
     168           0 : void OMarkableTreeListBox::CheckButtons()
     169             : {
     170           0 :     SvTreeListEntry* pEntry = GetModel()->First();
     171           0 :     while (pEntry)
     172             :     {
     173           0 :         implDetermineState(pEntry);
     174           0 :         pEntry = GetModel()->NextSibling(pEntry);
     175             :     }
     176           0 : }
     177             : 
     178           0 : void OMarkableTreeListBox::CheckButtonHdl()
     179             : {
     180           0 :     checkedButton_noBroadcast(GetHdlEntry());
     181           0 :     if (m_aCheckButtonHandler.IsSet())
     182           0 :         m_aCheckButtonHandler.Call(this);
     183           0 : }
     184             : 
     185           0 : void OMarkableTreeListBox::checkedButton_noBroadcast(SvTreeListEntry* _pEntry)
     186             : {
     187           0 :     SvButtonState eState = GetCheckButtonState( _pEntry);
     188           0 :     if (GetModel()->HasChildren(_pEntry)) // if it has children, check those too
     189             :     {
     190           0 :         SvTreeListEntry* pChildEntry = GetModel()->Next(_pEntry);
     191           0 :         SvTreeListEntry* pSiblingEntry = GetModel()->NextSibling(_pEntry);
     192           0 :         while(pChildEntry && pChildEntry != pSiblingEntry)
     193             :         {
     194           0 :             SetCheckButtonState(pChildEntry, eState);
     195           0 :             pChildEntry = GetModel()->Next(pChildEntry);
     196             :         }
     197             :     }
     198             : 
     199           0 :     SvTreeListEntry* pEntry = IsSelected(_pEntry) ? FirstSelected() : NULL;
     200           0 :     while(pEntry)
     201             :     {
     202           0 :         SetCheckButtonState(pEntry,eState);
     203           0 :         if(GetModel()->HasChildren(pEntry))   // if it has children, check those too
     204             :         {
     205           0 :             SvTreeListEntry* pChildEntry = GetModel()->Next(pEntry);
     206           0 :             SvTreeListEntry* pSiblingEntry = GetModel()->NextSibling(pEntry);
     207           0 :             while(pChildEntry && pChildEntry != pSiblingEntry)
     208             :             {
     209           0 :                 SetCheckButtonState(pChildEntry,eState);
     210           0 :                 pChildEntry = GetModel()->Next(pChildEntry);
     211             :             }
     212             :         }
     213           0 :         pEntry = NextSelected(pEntry);
     214             :     }
     215           0 :     CheckButtons();
     216           0 : }
     217             : 
     218             : } // namespace
     219             : 
     220             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10