1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: marktree.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef _DBAUI_MARKTREE_HXX_
35 #include "marktree.hxx"
37 #ifndef _DBU_CONTROL_HRC_
38 #include "dbu_control.hrc"
41 #include <vcl/svapp.hxx>
44 //.........................................................................
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::lang
;
49 //.........................................................................
50 #define SPACEBETWEENENTRIES 4
51 //========================================================================
52 //= OMarkableTreeListBox
53 //========================================================================
54 DBG_NAME(OMarkableTreeListBox
)
55 //------------------------------------------------------------------------
56 OMarkableTreeListBox::OMarkableTreeListBox( Window
* pParent
, const Reference
< XMultiServiceFactory
>& _rxORB
, WinBits nWinStyle
)
57 : DBTreeListBox(pParent
,_rxORB
,nWinStyle
)
59 DBG_CTOR(OMarkableTreeListBox
,NULL
);
63 //------------------------------------------------------------------------
64 OMarkableTreeListBox::OMarkableTreeListBox( Window
* pParent
, const Reference
< XMultiServiceFactory
>& _rxORB
, const ResId
& rResId
)
65 : DBTreeListBox(pParent
,_rxORB
,rResId
)
67 DBG_CTOR(OMarkableTreeListBox
,NULL
);
71 //------------------------------------------------------------------------
72 OMarkableTreeListBox::~OMarkableTreeListBox()
74 delete m_pCheckButton
;
76 DBG_DTOR(OMarkableTreeListBox
,NULL
);
78 //------------------------------------------------------------------------
79 void OMarkableTreeListBox::Paint(const Rectangle
& _rRect
)
83 Font aOldFont
= GetFont();
84 Font
aNewFont(aOldFont
);
86 StyleSettings aSystemStyle
= Application::GetSettings().GetStyleSettings();
87 aNewFont
.SetColor(aSystemStyle
.GetDisableColor());
90 DBTreeListBox::Paint(_rRect
);
94 DBTreeListBox::Paint(_rRect
);
96 //------------------------------------------------------------------------
97 void OMarkableTreeListBox::InitButtonData()
99 m_pCheckButton
= new SvLBoxButtonData( this );
100 EnableCheckButton( m_pCheckButton
);
102 //------------------------------------------------------------------------
103 void OMarkableTreeListBox::KeyInput( const KeyEvent
& rKEvt
)
106 if (rKEvt
.GetKeyCode().GetCode() == KEY_SPACE
&& !rKEvt
.GetKeyCode().IsShift() && !rKEvt
.GetKeyCode().IsMod1())
108 SvLBoxEntry
* pCurrentHandlerEntry
= GetHdlEntry();
109 if(pCurrentHandlerEntry
)
111 SvButtonState eState
= GetCheckButtonState( pCurrentHandlerEntry
);
112 if(eState
== SV_BUTTON_CHECKED
)
113 SetCheckButtonState( pCurrentHandlerEntry
, SV_BUTTON_UNCHECKED
);
115 SetCheckButtonState( pCurrentHandlerEntry
, SV_BUTTON_CHECKED
);
120 DBTreeListBox::KeyInput(rKEvt
);
123 DBTreeListBox::KeyInput(rKEvt
);
126 //------------------------------------------------------------------------
127 SvButtonState
OMarkableTreeListBox::implDetermineState(SvLBoxEntry
* _pEntry
)
129 SvButtonState eState
= GetCheckButtonState(_pEntry
);
130 if (!GetModel()->HasChilds(_pEntry
))
131 // nothing to do in this bottom-up routine if there are no children ...
134 String sEntryText
=GetEntryText(_pEntry
);
137 // loop through the children and check their states
138 sal_uInt16 nCheckedChildren
= 0;
139 sal_uInt16 nChildrenOverall
= 0;
141 SvLBoxEntry
* pChildLoop
= GetModel()->FirstChild(_pEntry
);
145 String sChildText
=GetEntryText(pChildLoop
);
147 SvButtonState eChildState
= implDetermineState(pChildLoop
);
148 if (SV_BUTTON_TRISTATE
== eChildState
)
151 if (SV_BUTTON_CHECKED
== eChildState
)
155 pChildLoop
= GetModel()->NextSibling(pChildLoop
);
160 // we did not finish the loop because at least one of the children is in tristate
161 eState
= SV_BUTTON_TRISTATE
;
163 // but this means that we did not finish all the siblings of pChildLoop, so their checking may be
164 // incorrect at the moment
166 // 88485 - 20.06.2001 - frank.schoenheit@sun.com
169 implDetermineState(pChildLoop
);
170 pChildLoop
= GetModel()->NextSibling(pChildLoop
);
174 // none if the children is in tristate
175 if (nCheckedChildren
)
176 // we have at least one chil checked
177 if (nCheckedChildren
!= nChildrenOverall
)
178 // not all children are checked
179 eState
= SV_BUTTON_TRISTATE
;
181 // all children are checked
182 eState
= SV_BUTTON_CHECKED
;
184 // no children are checked
185 eState
= SV_BUTTON_UNCHECKED
;
187 // finally set the entry to the state we just determined
188 SetCheckButtonState(_pEntry
, eState
);
194 //------------------------------------------------------------------------
195 void OMarkableTreeListBox::CheckButtons()
197 SvLBoxEntry
* pEntry
= GetModel()->First();
200 implDetermineState(pEntry
);
201 pEntry
= GetModel()->NextSibling(pEntry
);
204 //------------------------------------------------------------------------
205 void OMarkableTreeListBox::CheckButtonHdl()
207 checkedButton_noBroadcast(GetHdlEntry());
208 if (m_aCheckButtonHandler
.IsSet())
209 m_aCheckButtonHandler
.Call(this);
212 //------------------------------------------------------------------------
213 void OMarkableTreeListBox::checkedButton_noBroadcast(SvLBoxEntry
* _pEntry
)
215 SvButtonState eState
= GetCheckButtonState( _pEntry
);
216 if (GetModel()->HasChilds(_pEntry
)) // Falls Kinder, dann diese auch checken
218 SvLBoxEntry
* pChildEntry
= GetModel()->Next(_pEntry
);
219 SvLBoxEntry
* pSiblingEntry
= GetModel()->NextSibling(_pEntry
);
220 while(pChildEntry
&& pChildEntry
!= pSiblingEntry
)
222 SetCheckButtonState(pChildEntry
, eState
);
223 pChildEntry
= GetModel()->Next(pChildEntry
);
227 SvLBoxEntry
* pEntry
= IsSelected(_pEntry
) ? FirstSelected() : NULL
;
230 SetCheckButtonState(pEntry
,eState
);
231 if(GetModel()->HasChilds(pEntry
)) // Falls Kinder, dann diese auch checken
233 SvLBoxEntry
* pChildEntry
= GetModel()->Next(pEntry
);
234 SvLBoxEntry
* pSiblingEntry
= GetModel()->NextSibling(pEntry
);
235 while(pChildEntry
&& pChildEntry
!= pSiblingEntry
)
237 SetCheckButtonState(pChildEntry
,eState
);
238 pChildEntry
= GetModel()->Next(pChildEntry
);
241 pEntry
= NextSelected(pEntry
);
246 //------------------------------------------------------------------------
247 //.........................................................................
249 //.........................................................................