1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #ifndef _DBAUI_MARKTREE_HXX_ 32*cdf0e10cSrcweir #include "marktree.hxx" 33*cdf0e10cSrcweir #endif 34*cdf0e10cSrcweir #ifndef _DBU_CONTROL_HRC_ 35*cdf0e10cSrcweir #include "dbu_control.hrc" 36*cdf0e10cSrcweir #endif 37*cdf0e10cSrcweir #ifndef _SV_SVAPP_HXX 38*cdf0e10cSrcweir #include <vcl/svapp.hxx> 39*cdf0e10cSrcweir #endif 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir //......................................................................... 42*cdf0e10cSrcweir namespace dbaui 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 45*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 46*cdf0e10cSrcweir //......................................................................... 47*cdf0e10cSrcweir #define SPACEBETWEENENTRIES 4 48*cdf0e10cSrcweir //======================================================================== 49*cdf0e10cSrcweir //= OMarkableTreeListBox 50*cdf0e10cSrcweir //======================================================================== 51*cdf0e10cSrcweir DBG_NAME(OMarkableTreeListBox) 52*cdf0e10cSrcweir //------------------------------------------------------------------------ 53*cdf0e10cSrcweir OMarkableTreeListBox::OMarkableTreeListBox( Window* pParent, const Reference< XMultiServiceFactory >& _rxORB, WinBits nWinStyle ) 54*cdf0e10cSrcweir : DBTreeListBox(pParent,_rxORB,nWinStyle) 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir DBG_CTOR(OMarkableTreeListBox,NULL); 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir InitButtonData(); 59*cdf0e10cSrcweir } 60*cdf0e10cSrcweir //------------------------------------------------------------------------ 61*cdf0e10cSrcweir OMarkableTreeListBox::OMarkableTreeListBox( Window* pParent, const Reference< XMultiServiceFactory >& _rxORB, const ResId& rResId) 62*cdf0e10cSrcweir : DBTreeListBox(pParent,_rxORB,rResId) 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir DBG_CTOR(OMarkableTreeListBox,NULL); 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir InitButtonData(); 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir //------------------------------------------------------------------------ 69*cdf0e10cSrcweir OMarkableTreeListBox::~OMarkableTreeListBox() 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir delete m_pCheckButton; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir DBG_DTOR(OMarkableTreeListBox,NULL); 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir //------------------------------------------------------------------------ 76*cdf0e10cSrcweir void OMarkableTreeListBox::Paint(const Rectangle& _rRect) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir if (!IsEnabled()) 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir Font aOldFont = GetFont(); 81*cdf0e10cSrcweir Font aNewFont(aOldFont); 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings(); 84*cdf0e10cSrcweir aNewFont.SetColor(aSystemStyle.GetDisableColor()); 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir SetFont(aNewFont); 87*cdf0e10cSrcweir DBTreeListBox::Paint(_rRect); 88*cdf0e10cSrcweir SetFont(aOldFont); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir else 91*cdf0e10cSrcweir DBTreeListBox::Paint(_rRect); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir //------------------------------------------------------------------------ 94*cdf0e10cSrcweir void OMarkableTreeListBox::InitButtonData() 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir m_pCheckButton = new SvLBoxButtonData( this ); 97*cdf0e10cSrcweir EnableCheckButton( m_pCheckButton ); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir //------------------------------------------------------------------------ 100*cdf0e10cSrcweir void OMarkableTreeListBox::KeyInput( const KeyEvent& rKEvt ) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir // nur wenn space 103*cdf0e10cSrcweir if (rKEvt.GetKeyCode().GetCode() == KEY_SPACE && !rKEvt.GetKeyCode().IsShift() && !rKEvt.GetKeyCode().IsMod1()) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir SvLBoxEntry* pCurrentHandlerEntry = GetHdlEntry(); 106*cdf0e10cSrcweir if(pCurrentHandlerEntry) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir SvButtonState eState = GetCheckButtonState( pCurrentHandlerEntry); 109*cdf0e10cSrcweir if(eState == SV_BUTTON_CHECKED) 110*cdf0e10cSrcweir SetCheckButtonState( pCurrentHandlerEntry, SV_BUTTON_UNCHECKED); 111*cdf0e10cSrcweir else 112*cdf0e10cSrcweir SetCheckButtonState( pCurrentHandlerEntry, SV_BUTTON_CHECKED); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir CheckButtonHdl(); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir else 117*cdf0e10cSrcweir DBTreeListBox::KeyInput(rKEvt); 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir else 120*cdf0e10cSrcweir DBTreeListBox::KeyInput(rKEvt); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir //------------------------------------------------------------------------ 124*cdf0e10cSrcweir SvButtonState OMarkableTreeListBox::implDetermineState(SvLBoxEntry* _pEntry) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir SvButtonState eState = GetCheckButtonState(_pEntry); 127*cdf0e10cSrcweir if (!GetModel()->HasChilds(_pEntry)) 128*cdf0e10cSrcweir // nothing to do in this bottom-up routine if there are no children ... 129*cdf0e10cSrcweir return eState; 130*cdf0e10cSrcweir #ifdef DBG_UTIL 131*cdf0e10cSrcweir String sEntryText =GetEntryText(_pEntry); 132*cdf0e10cSrcweir #endif 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir // loop through the children and check their states 135*cdf0e10cSrcweir sal_uInt16 nCheckedChildren = 0; 136*cdf0e10cSrcweir sal_uInt16 nChildrenOverall = 0; 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir SvLBoxEntry* pChildLoop = GetModel()->FirstChild(_pEntry); 139*cdf0e10cSrcweir while (pChildLoop) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir #ifdef DBG_UTIL 142*cdf0e10cSrcweir String sChildText =GetEntryText(pChildLoop); 143*cdf0e10cSrcweir #endif 144*cdf0e10cSrcweir SvButtonState eChildState = implDetermineState(pChildLoop); 145*cdf0e10cSrcweir if (SV_BUTTON_TRISTATE == eChildState) 146*cdf0e10cSrcweir break; 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir if (SV_BUTTON_CHECKED == eChildState) 149*cdf0e10cSrcweir ++nCheckedChildren; 150*cdf0e10cSrcweir ++nChildrenOverall; 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir pChildLoop = GetModel()->NextSibling(pChildLoop); 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir if (pChildLoop) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir // we did not finish the loop because at least one of the children is in tristate 158*cdf0e10cSrcweir eState = SV_BUTTON_TRISTATE; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir // but this means that we did not finish all the siblings of pChildLoop, so their checking may be 161*cdf0e10cSrcweir // incorrect at the moment 162*cdf0e10cSrcweir // -> correct this 163*cdf0e10cSrcweir // 88485 - 20.06.2001 - frank.schoenheit@sun.com 164*cdf0e10cSrcweir while (pChildLoop) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir implDetermineState(pChildLoop); 167*cdf0e10cSrcweir pChildLoop = GetModel()->NextSibling(pChildLoop); 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir else 171*cdf0e10cSrcweir // none if the children is in tristate 172*cdf0e10cSrcweir if (nCheckedChildren) 173*cdf0e10cSrcweir // we have at least one chil checked 174*cdf0e10cSrcweir if (nCheckedChildren != nChildrenOverall) 175*cdf0e10cSrcweir // not all children are checked 176*cdf0e10cSrcweir eState = SV_BUTTON_TRISTATE; 177*cdf0e10cSrcweir else 178*cdf0e10cSrcweir // all children are checked 179*cdf0e10cSrcweir eState = SV_BUTTON_CHECKED; 180*cdf0e10cSrcweir else 181*cdf0e10cSrcweir // no children are checked 182*cdf0e10cSrcweir eState = SV_BUTTON_UNCHECKED; 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir // finally set the entry to the state we just determined 185*cdf0e10cSrcweir SetCheckButtonState(_pEntry, eState); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir // outta here 188*cdf0e10cSrcweir return eState; 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir //------------------------------------------------------------------------ 192*cdf0e10cSrcweir void OMarkableTreeListBox::CheckButtons() 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir SvLBoxEntry* pEntry = GetModel()->First(); 195*cdf0e10cSrcweir while (pEntry) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir implDetermineState(pEntry); 198*cdf0e10cSrcweir pEntry = GetModel()->NextSibling(pEntry); 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir //------------------------------------------------------------------------ 202*cdf0e10cSrcweir void OMarkableTreeListBox::CheckButtonHdl() 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir checkedButton_noBroadcast(GetHdlEntry()); 205*cdf0e10cSrcweir if (m_aCheckButtonHandler.IsSet()) 206*cdf0e10cSrcweir m_aCheckButtonHandler.Call(this); 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir //------------------------------------------------------------------------ 210*cdf0e10cSrcweir void OMarkableTreeListBox::checkedButton_noBroadcast(SvLBoxEntry* _pEntry) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir SvButtonState eState = GetCheckButtonState( _pEntry); 213*cdf0e10cSrcweir if (GetModel()->HasChilds(_pEntry)) // Falls Kinder, dann diese auch checken 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir SvLBoxEntry* pChildEntry = GetModel()->Next(_pEntry); 216*cdf0e10cSrcweir SvLBoxEntry* pSiblingEntry = GetModel()->NextSibling(_pEntry); 217*cdf0e10cSrcweir while(pChildEntry && pChildEntry != pSiblingEntry) 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir SetCheckButtonState(pChildEntry, eState); 220*cdf0e10cSrcweir pChildEntry = GetModel()->Next(pChildEntry); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir SvLBoxEntry* pEntry = IsSelected(_pEntry) ? FirstSelected() : NULL; 225*cdf0e10cSrcweir while(pEntry) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir SetCheckButtonState(pEntry,eState); 228*cdf0e10cSrcweir if(GetModel()->HasChilds(pEntry)) // Falls Kinder, dann diese auch checken 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir SvLBoxEntry* pChildEntry = GetModel()->Next(pEntry); 231*cdf0e10cSrcweir SvLBoxEntry* pSiblingEntry = GetModel()->NextSibling(pEntry); 232*cdf0e10cSrcweir while(pChildEntry && pChildEntry != pSiblingEntry) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir SetCheckButtonState(pChildEntry,eState); 235*cdf0e10cSrcweir pChildEntry = GetModel()->Next(pChildEntry); 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir pEntry = NextSelected(pEntry); 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir CheckButtons(); 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir //------------------------------------------------------------------------ 244*cdf0e10cSrcweir //......................................................................... 245*cdf0e10cSrcweir } // namespace dbaui 246*cdf0e10cSrcweir //......................................................................... 247*cdf0e10cSrcweir 248