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