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

Generated by: LCOV version 1.10