/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
if ( bSupportsCatalogs || bSupportsSchemas )
{ // we display empty catalogs if the DB supports catalogs, and they're noted at the beginning of a // composed name. Otherwise, we display empty schematas. (also see the tree structure explained in // implAddEntry) bool bCatalogs = bSupportsCatalogs && xMeta->isCatalogAtStart();
std::unique_ptr<weld::TreeIter> OTableTreeListBox::getAllObjectsEntry() const
{ if (!haveVirtualRoot()) return nullptr; auto xRet = m_xTreeView->make_iterator(); if (!m_xTreeView->get_iter_first(*xRet)) return nullptr; return xRet;
}
void OTableTreeListBox::checkedButton_noBroadcast(const weld::TreeIter& rEntry)
{ if (!m_bShowToggles) return;
TriState eState = m_xTreeView->get_toggle(rEntry);
OSL_ENSURE(TRISTATE_INDET != eState, "OTableTreeListBox::CheckButtonHdl: user action which lead to TRISTATE?");
if (m_xTreeView->iter_has_child(rEntry)) // if it has children, check those too
{
std::unique_ptr<weld::TreeIter> xChildEntry(m_xTreeView->make_iterator(&rEntry));
std::unique_ptr<weld::TreeIter> xSiblingEntry(m_xTreeView->make_iterator(&rEntry)); bool bChildEntry = m_xTreeView->iter_next(*xChildEntry); bool bSiblingEntry = m_xTreeView->iter_next_sibling(*xSiblingEntry); while (bChildEntry && (!bSiblingEntry || !xChildEntry->equal(*xSiblingEntry)))
{
m_xTreeView->set_toggle(*xChildEntry, eState);
bChildEntry = m_xTreeView->iter_next(*xChildEntry);
}
}
if (m_xTreeView->is_selected(rEntry))
{
m_xTreeView->selected_foreach([this, eState](weld::TreeIter& rSelected){
m_xTreeView->set_toggle(rSelected, eState); if (m_xTreeView->iter_has_child(rSelected)) // if it has children, check those too
{
std::unique_ptr<weld::TreeIter> xChildEntry(m_xTreeView->make_iterator(&rSelected));
std::unique_ptr<weld::TreeIter> xSiblingEntry(m_xTreeView->make_iterator(&rSelected)); bool bChildEntry = m_xTreeView->iter_next(*xChildEntry); bool bSiblingEntry = m_xTreeView->iter_next_sibling(*xSiblingEntry); while (bChildEntry && (!bSiblingEntry || !xChildEntry->equal(*xSiblingEntry)))
{
m_xTreeView->set_toggle(*xChildEntry, eState);
bChildEntry = m_xTreeView->iter_next(*xChildEntry);
}
} returnfalse;
});
}
CheckButtons();
// if an entry has children, it makes a difference if the entry is checked // because all children are checked or if the user checked it explicitly. // So we track explicit (un)checking
implEmphasize(rEntry, eState == TRISTATE_TRUE);
}
void OTableTreeListBox::implEmphasize(const weld::TreeIter& rEntry, bool _bChecked, bool _bUpdateDescendants, bool _bUpdateAncestors)
{ // special emphasizing handling for the "all objects" entry bool bAllObjectsEntryAffected = haveVirtualRoot() && (getAllObjectsEntry()->equal(rEntry)); if ( m_xTreeView->iter_has_child(rEntry) // the entry has children
|| bAllObjectsEntryAffected // or it is the "all objects" entry
)
{
m_xTreeView->set_text_emphasis(rEntry, _bChecked, 0);
}
if (_bUpdateDescendants)
{
std::unique_ptr<weld::TreeIter> xChild(m_xTreeView->make_iterator(&rEntry)); // remove the mark for all children of the checked entry bool bChildLoop = m_xTreeView->iter_children(*xChild); while (bChildLoop)
{ if (m_xTreeView->iter_has_child(*xChild))
implEmphasize(*xChild, false, true, false);
bChildLoop = m_xTreeView->iter_next_sibling(*xChild);
}
}
if (_bUpdateAncestors)
{
std::unique_ptr<weld::TreeIter> xParent(m_xTreeView->make_iterator(&rEntry)); // remove the mark for all ancestors of the entry if (m_xTreeView->iter_parent(*xParent))
implEmphasize(*xParent, false, false);
}
}
// split the complete name into its components
OUString sCatalog, sSchema, sName;
qualifiedNameComponents( _rxMeta, _rTableName, sCatalog, sSchema, sName, ::dbtools::EComposeRule::InDataManipulation );
// split the complete name into its components
OUString sCatalog, sSchema, sName;
qualifiedNameComponents(xMeta, rName, sCatalog, sSchema, sName,::dbtools::EComposeRule::InDataManipulation);
std::unique_ptr<weld::TreeIter> xParent(getAllObjectsEntry());
std::unique_ptr<weld::TreeIter> xCat;
std::unique_ptr<weld::TreeIter> xSchema; if (!sCatalog.isEmpty())
{
xCat = GetEntryPosByName(sCatalog); if (xCat)
xParent = std::move(xCat);
}
if (!sSchema.isEmpty())
{
xSchema = GetEntryPosByName(sSchema, xParent.get()); if (xSchema)
xParent = std::move(xSchema);
}
void OTableTreeListBox::CheckButtons()
{ if (!m_bShowToggles) return;
auto xEntry(m_xTreeView->make_iterator()); if (!m_xTreeView->get_iter_first(*xEntry)) return;
do
{
implDetermineState(*xEntry);
} while (m_xTreeView->iter_next_sibling(*xEntry));
}
TriState OTableTreeListBox::implDetermineState(const weld::TreeIter& rEntry)
{ if (!m_bShowToggles) return TRISTATE_FALSE;
TriState eState = m_xTreeView->get_toggle(rEntry); if (!m_xTreeView->iter_has_child(rEntry)) // nothing to do in this bottom-up routine if there are no children ... return eState;
// loop through the children and check their states
sal_uInt16 nCheckedChildren = 0;
sal_uInt16 nChildrenOverall = 0;
std::unique_ptr<weld::TreeIter> xChild(m_xTreeView->make_iterator(&rEntry)); bool bChildLoop = m_xTreeView->iter_children(*xChild); while (bChildLoop)
{
TriState eChildState = implDetermineState(*xChild); if (eChildState == TRISTATE_INDET) break; if (eChildState == TRISTATE_TRUE)
++nCheckedChildren;
++nChildrenOverall;
bChildLoop = m_xTreeView->iter_next_sibling(*xChild);
}
if (bChildLoop)
{ // we did not finish the loop because at least one of the children is in tristate
eState = TRISTATE_INDET;
// but this means that we did not finish all the siblings of pChildLoop, // so their checking may be incorrect at the moment // -> correct this while (bChildLoop)
{
implDetermineState(*xChild);
bChildLoop = m_xTreeView->iter_next_sibling(*xChild);
}
} else
{ // none if the children are in tristate if (nCheckedChildren)
{ // we have at least one child checked if (nCheckedChildren != nChildrenOverall)
{ // not all children are checked
eState = TRISTATE_INDET;
} else
{ // all children are checked
eState = TRISTATE_TRUE;
}
} else
{ // no children are checked
eState = TRISTATE_FALSE;
}
}
// finally set the entry to the state we just determined
m_xTreeView->set_toggle(rEntry, eState);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.