1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "marktree.hxx"
21 #include "dbu_control.hrc"
22 #include <vcl/svapp.hxx>
23 #include <vcl/settings.hxx>
27 using namespace ::com::sun::star::uno
;
28 using namespace ::com::sun::star::lang
;
31 OMarkableTreeListBox::OMarkableTreeListBox( vcl::Window
* pParent
, WinBits nWinStyle
)
32 : DBTreeListBox(pParent
, nWinStyle
)
38 OMarkableTreeListBox::~OMarkableTreeListBox()
43 void OMarkableTreeListBox::dispose()
45 delete m_pCheckButton
;
46 DBTreeListBox::dispose();
49 void OMarkableTreeListBox::Paint(vcl::RenderContext
& rRenderContext
, const Rectangle
& _rRect
)
53 vcl::Font aOldFont
= rRenderContext
.GetFont();
54 vcl::Font
aNewFont(aOldFont
);
56 StyleSettings aSystemStyle
= Application::GetSettings().GetStyleSettings();
57 aNewFont
.SetColor(aSystemStyle
.GetDisableColor());
59 rRenderContext
.SetFont(aNewFont
);
60 DBTreeListBox::Paint(rRenderContext
, _rRect
);
61 rRenderContext
.SetFont(aOldFont
);
64 DBTreeListBox::Paint(rRenderContext
, _rRect
);
67 void OMarkableTreeListBox::InitButtonData()
69 m_pCheckButton
= new SvLBoxButtonData( this );
70 EnableCheckButton( m_pCheckButton
);
73 void OMarkableTreeListBox::KeyInput( const KeyEvent
& rKEvt
)
75 // only if there are spaces
76 if (rKEvt
.GetKeyCode().GetCode() == KEY_SPACE
&& !rKEvt
.GetKeyCode().IsShift() && !rKEvt
.GetKeyCode().IsMod1())
78 SvTreeListEntry
* pCurrentHandlerEntry
= GetHdlEntry();
79 if(pCurrentHandlerEntry
)
81 SvButtonState eState
= GetCheckButtonState( pCurrentHandlerEntry
);
82 if(eState
== SV_BUTTON_CHECKED
)
83 SetCheckButtonState( pCurrentHandlerEntry
, SV_BUTTON_UNCHECKED
);
85 SetCheckButtonState( pCurrentHandlerEntry
, SV_BUTTON_CHECKED
);
90 DBTreeListBox::KeyInput(rKEvt
);
93 DBTreeListBox::KeyInput(rKEvt
);
96 SvButtonState
OMarkableTreeListBox::implDetermineState(SvTreeListEntry
* _pEntry
)
98 SvButtonState eState
= GetCheckButtonState(_pEntry
);
99 if (!GetModel()->HasChildren(_pEntry
))
100 // nothing to do in this bottom-up routine if there are no children ...
103 // loop through the children and check their states
104 sal_uInt16 nCheckedChildren
= 0;
105 sal_uInt16 nChildrenOverall
= 0;
107 SvTreeListEntry
* pChildLoop
= GetModel()->FirstChild(_pEntry
);
110 SvButtonState eChildState
= implDetermineState(pChildLoop
);
111 if (SV_BUTTON_TRISTATE
== eChildState
)
114 if (SV_BUTTON_CHECKED
== eChildState
)
118 pChildLoop
= SvTreeList::NextSibling(pChildLoop
);
123 // we did not finish the loop because at least one of the children is in tristate
124 eState
= SV_BUTTON_TRISTATE
;
126 // but this means that we did not finish all the siblings of pChildLoop,
127 // so their checking may be incorrect at the moment
131 implDetermineState(pChildLoop
);
132 pChildLoop
= SvTreeList::NextSibling(pChildLoop
);
136 // none if the children are in tristate
137 if (nCheckedChildren
)
138 // we have at least one child checked
139 if (nCheckedChildren
!= nChildrenOverall
)
140 // not all children are checked
141 eState
= SV_BUTTON_TRISTATE
;
143 // all children are checked
144 eState
= SV_BUTTON_CHECKED
;
146 // no children are checked
147 eState
= SV_BUTTON_UNCHECKED
;
149 // finally set the entry to the state we just determined
150 SetCheckButtonState(_pEntry
, eState
);
155 void OMarkableTreeListBox::CheckButtons()
157 SvTreeListEntry
* pEntry
= GetModel()->First();
160 implDetermineState(pEntry
);
161 pEntry
= SvTreeList::NextSibling(pEntry
);
165 void OMarkableTreeListBox::CheckButtonHdl()
167 checkedButton_noBroadcast(GetHdlEntry());
168 if (m_aCheckButtonHandler
.IsSet())
169 m_aCheckButtonHandler
.Call(this);
172 void OMarkableTreeListBox::checkedButton_noBroadcast(SvTreeListEntry
* _pEntry
)
174 SvButtonState eState
= GetCheckButtonState( _pEntry
);
175 if (GetModel()->HasChildren(_pEntry
)) // if it has children, check those too
177 SvTreeListEntry
* pChildEntry
= GetModel()->Next(_pEntry
);
178 SvTreeListEntry
* pSiblingEntry
= SvTreeList::NextSibling(_pEntry
);
179 while(pChildEntry
&& pChildEntry
!= pSiblingEntry
)
181 SetCheckButtonState(pChildEntry
, eState
);
182 pChildEntry
= GetModel()->Next(pChildEntry
);
186 SvTreeListEntry
* pEntry
= IsSelected(_pEntry
) ? FirstSelected() : NULL
;
189 SetCheckButtonState(pEntry
,eState
);
190 if(GetModel()->HasChildren(pEntry
)) // if it has children, check those too
192 SvTreeListEntry
* pChildEntry
= GetModel()->Next(pEntry
);
193 SvTreeListEntry
* pSiblingEntry
= SvTreeList::NextSibling(pEntry
);
194 while(pChildEntry
&& pChildEntry
!= pSiblingEntry
)
196 SetCheckButtonState(pChildEntry
,eState
);
197 pChildEntry
= GetModel()->Next(pChildEntry
);
200 pEntry
= NextSelected(pEntry
);
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */