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

Generated by: LCOV version 1.11