fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / ui / control / marktree.cxx
blob0291f06e9c25be654685b2c7452d56173abb8269
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
25 namespace dbaui
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)
35 InitButtonData();
38 OMarkableTreeListBox::~OMarkableTreeListBox()
40 disposeOnce();
43 void OMarkableTreeListBox::dispose()
45 delete m_pCheckButton;
46 DBTreeListBox::dispose();
49 void OMarkableTreeListBox::Paint(vcl::RenderContext& rRenderContext, const Rectangle& _rRect)
51 if (!IsEnabled())
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);
63 else
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);
84 else
85 SetCheckButtonState( pCurrentHandlerEntry, SV_BUTTON_CHECKED);
87 CheckButtonHdl();
89 else
90 DBTreeListBox::KeyInput(rKEvt);
92 else
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 ...
101 return eState;
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);
108 while (pChildLoop)
110 SvButtonState eChildState = implDetermineState(pChildLoop);
111 if (SV_BUTTON_TRISTATE == eChildState)
112 break;
114 if (SV_BUTTON_CHECKED == eChildState)
115 ++nCheckedChildren;
116 ++nChildrenOverall;
118 pChildLoop = SvTreeList::NextSibling(pChildLoop);
121 if (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
128 // -> correct this
129 while (pChildLoop)
131 implDetermineState(pChildLoop);
132 pChildLoop = SvTreeList::NextSibling(pChildLoop);
135 else
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;
142 else
143 // all children are checked
144 eState = SV_BUTTON_CHECKED;
145 else
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);
152 return eState;
155 void OMarkableTreeListBox::CheckButtons()
157 SvTreeListEntry* pEntry = GetModel()->First();
158 while (pEntry)
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;
187 while(pEntry)
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);
202 CheckButtons();
205 } // namespace
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */