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