diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-08-07 12:45:14 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-08-08 14:57:56 +0200 |
commit | f0f1d1fb2f3b059e2a0979c61613b661b938a152 (patch) | |
tree | bd25d4db203b38b743fc80293c43cb87d0b4f7bf | |
parent | 2f2246d22e2a8ccbc1dc3e6f5243734a61edf270 (diff) |
merge dbaui::OMarkableTreeListBox with dbaui::OTableTreeListBox
Change-Id: I5cde5c453493e5287faa770eede2e42b21075477
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100330
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | compilerplugins/clang/mergeclasses.results | 1 | ||||
-rw-r--r-- | dbaccess/Library_dbu.mk | 1 | ||||
-rw-r--r-- | dbaccess/source/ui/control/marktree.cxx | 206 | ||||
-rw-r--r-- | dbaccess/source/ui/control/tabletree.cxx | 169 | ||||
-rw-r--r-- | dbaccess/source/ui/inc/marktree.hxx | 63 | ||||
-rw-r--r-- | dbaccess/source/ui/inc/tabletree.hxx | 18 | ||||
-rw-r--r-- | solenv/clang-format/excludelist | 2 |
7 files changed, 178 insertions, 282 deletions
diff --git a/compilerplugins/clang/mergeclasses.results b/compilerplugins/clang/mergeclasses.results index a01e70500c14..594a37cb76df 100644 --- a/compilerplugins/clang/mergeclasses.results +++ b/compilerplugins/clang/mergeclasses.results @@ -261,7 +261,6 @@ merge dbahsql::CreateStmtParser with dbahsql::FbCreateStmtParser merge dbaui::IController with dbaui::OGenericUnoController merge dbaui::IEntryFilter with dbaui::(anonymous namespace)::FilterByEntryDataId merge dbaui::IUpdateHelper with dbaui::OParameterUpdateHelper -merge dbaui::OMarkableTreeListBox with dbaui::OTableTreeListBox merge dbaui::OSQLNameEntry with dbaui::OPropColumnEditCtrl merge dbaui::OSplitterView with dbaui::OApplicationDetailView merge dbaui::OTableRowView with dbaui::OTableEditorCtrl diff --git a/dbaccess/Library_dbu.mk b/dbaccess/Library_dbu.mk index b751b49e0f9e..67e852518bae 100644 --- a/dbaccess/Library_dbu.mk +++ b/dbaccess/Library_dbu.mk @@ -102,7 +102,6 @@ $(eval $(call gb_Library_add_exception_objects,dbu,\ dbaccess/source/ui/control/FieldControls \ dbaccess/source/ui/control/FieldDescControl \ dbaccess/source/ui/control/listviewitems \ - dbaccess/source/ui/control/marktree \ dbaccess/source/ui/control/opendoccontrols \ dbaccess/source/ui/control/RelationControl \ dbaccess/source/ui/control/ScrollHelper \ diff --git a/dbaccess/source/ui/control/marktree.cxx b/dbaccess/source/ui/control/marktree.cxx deleted file mode 100644 index 9bf664fa6e87..000000000000 --- a/dbaccess/source/ui/control/marktree.cxx +++ /dev/null @@ -1,206 +0,0 @@ -/* -*- 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 . - */ - -#include <marktree.hxx> -#include <vcl/treelistentry.hxx> -#include <vcl/svapp.hxx> -#include <vcl/settings.hxx> -#include <vcl/event.hxx> - -namespace dbaui -{ - using namespace ::com::sun::star::uno; - using namespace ::com::sun::star::lang; - - -OMarkableTreeListBox::OMarkableTreeListBox( vcl::Window* pParent, WinBits nWinStyle ) - : DBTreeListBox(pParent, nWinStyle) -{ - - InitButtonData(); -} - -OMarkableTreeListBox::~OMarkableTreeListBox() -{ - disposeOnce(); -} - -void OMarkableTreeListBox::dispose() -{ - m_pCheckButton.reset(); - DBTreeListBox::dispose(); -} - -void OMarkableTreeListBox::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& _rRect) -{ - if (!IsEnabled()) - { - vcl::Font aOldFont = rRenderContext.GetFont(); - vcl::Font aNewFont(aOldFont); - - StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings(); - aNewFont.SetColor(aSystemStyle.GetDisableColor()); - - rRenderContext.SetFont(aNewFont); - DBTreeListBox::Paint(rRenderContext, _rRect); - rRenderContext.SetFont(aOldFont); - } - else - DBTreeListBox::Paint(rRenderContext, _rRect); -} - -void OMarkableTreeListBox::InitButtonData() -{ - m_pCheckButton.reset( new SvLBoxButtonData( this ) ); - EnableCheckButton( m_pCheckButton.get() ); -} - -void OMarkableTreeListBox::KeyInput( const KeyEvent& rKEvt ) -{ - // only if there are spaces - if (rKEvt.GetKeyCode().GetCode() == KEY_SPACE && !rKEvt.GetKeyCode().IsShift() && !rKEvt.GetKeyCode().IsMod1()) - { - SvTreeListEntry* pCurrentHandlerEntry = GetHdlEntry(); - if(pCurrentHandlerEntry) - { - SvButtonState eState = GetCheckButtonState( pCurrentHandlerEntry); - if(eState == SvButtonState::Checked) - SetCheckButtonState( pCurrentHandlerEntry, SvButtonState::Unchecked); - else - SetCheckButtonState( pCurrentHandlerEntry, SvButtonState::Checked); - - CheckButtonHdl(); - } - else - DBTreeListBox::KeyInput(rKEvt); - } - else - DBTreeListBox::KeyInput(rKEvt); -} - -SvButtonState OMarkableTreeListBox::implDetermineState(SvTreeListEntry* _pEntry) -{ - SvButtonState eState = GetCheckButtonState(_pEntry); - if (!GetModel()->HasChildren(_pEntry)) - // 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; - - SvTreeListEntry* pChildLoop = GetModel()->FirstChild(_pEntry); - while (pChildLoop) - { - SvButtonState eChildState = implDetermineState(pChildLoop); - if (SvButtonState::Tristate == eChildState) - break; - - if (SvButtonState::Checked == eChildState) - ++nCheckedChildren; - ++nChildrenOverall; - - pChildLoop = pChildLoop->NextSibling(); - } - - if (pChildLoop) - { - // we did not finish the loop because at least one of the children is in tristate - eState = SvButtonState::Tristate; - - // 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 (pChildLoop) - { - implDetermineState(pChildLoop); - pChildLoop = pChildLoop->NextSibling(); - } - } - 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 = SvButtonState::Tristate; - else - // all children are checked - eState = SvButtonState::Checked; - else - // no children are checked - eState = SvButtonState::Unchecked; - - // finally set the entry to the state we just determined - SetCheckButtonState(_pEntry, eState); - - return eState; -} - -void OMarkableTreeListBox::CheckButtons() -{ - SvTreeListEntry* pEntry = GetModel()->First(); - while (pEntry) - { - implDetermineState(pEntry); - pEntry = pEntry->NextSibling(); - } -} - -void OMarkableTreeListBox::CheckButtonHdl() -{ - checkedButton_noBroadcast(GetHdlEntry()); -} - -void OMarkableTreeListBox::checkedButton_noBroadcast(SvTreeListEntry* _pEntry) -{ - SvButtonState eState = GetCheckButtonState( _pEntry); - if (GetModel()->HasChildren(_pEntry)) // if it has children, check those too - { - SvTreeListEntry* pChildEntry = GetModel()->Next(_pEntry); - SvTreeListEntry* pSiblingEntry = _pEntry->NextSibling(); - while(pChildEntry && pChildEntry != pSiblingEntry) - { - SetCheckButtonState(pChildEntry, eState); - pChildEntry = GetModel()->Next(pChildEntry); - } - } - - SvTreeListEntry* pEntry = IsSelected(_pEntry) ? FirstSelected() : nullptr; - while(pEntry) - { - SetCheckButtonState(pEntry,eState); - if(GetModel()->HasChildren(pEntry)) // if it has children, check those too - { - SvTreeListEntry* pChildEntry = GetModel()->Next(pEntry); - SvTreeListEntry* pSiblingEntry = pEntry->NextSibling(); - while(pChildEntry && pChildEntry != pSiblingEntry) - { - SetCheckButtonState(pChildEntry,eState); - pChildEntry = GetModel()->Next(pChildEntry); - } - } - pEntry = NextSelected(pEntry); - } - CheckButtons(); -} - -} // namespace - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/ui/control/tabletree.cxx b/dbaccess/source/ui/control/tabletree.cxx index 2ec45c9b756a..414cacbc8afe 100644 --- a/dbaccess/source/ui/control/tabletree.cxx +++ b/dbaccess/source/ui/control/tabletree.cxx @@ -33,6 +33,9 @@ #include <tools/diagnose_ex.h> #include <osl/diagnose.h> #include <connectivity/dbmetadata.hxx> +#include <vcl/event.hxx> +#include <vcl/settings.hxx> +#include <vcl/svapp.hxx> #include <vcl/treelistentry.hxx> #include <algorithm> @@ -57,12 +60,26 @@ namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::Database // OTableTreeListBox OTableTreeListBox::OTableTreeListBox(vcl::Window* pParent, WinBits nWinStyle) - :OMarkableTreeListBox(pParent, nWinStyle) - ,m_xImageProvider( new ImageProvider ) + : DBTreeListBox(pParent, nWinStyle) + , m_xImageProvider( new ImageProvider ) { + InitButtonData(); + implSetDefaultImages(); } +void OTableTreeListBox::InitButtonData() +{ + m_pCheckButton.reset( new SvLBoxButtonData( this ) ); + EnableCheckButton( m_pCheckButton.get() ); +} + +void OTableTreeListBox::dispose() +{ + m_pCheckButton.reset(); + DBTreeListBox::dispose(); +} + TableTreeListBox::TableTreeListBox(std::unique_ptr<weld::TreeView> xTreeView) : m_xImageProvider(new ImageProvider) , m_bVirtualRoot(false) @@ -475,15 +492,155 @@ std::unique_ptr<weld::TreeIter> TableTreeListBox::getAllObjectsEntry() const void OTableTreeListBox::checkedButton_noBroadcast(SvTreeListEntry* _pEntry) { - OMarkableTreeListBox::checkedButton_noBroadcast(_pEntry); + SvButtonState eState = GetCheckButtonState( _pEntry); + if (GetModel()->HasChildren(_pEntry)) // if it has children, check those too + { + SvTreeListEntry* pChildEntry = GetModel()->Next(_pEntry); + SvTreeListEntry* pSiblingEntry = _pEntry->NextSibling(); + while(pChildEntry && pChildEntry != pSiblingEntry) + { + SetCheckButtonState(pChildEntry, eState); + pChildEntry = GetModel()->Next(pChildEntry); + } + } + + SvTreeListEntry* pEntry = IsSelected(_pEntry) ? FirstSelected() : nullptr; + while(pEntry) + { + SetCheckButtonState(pEntry,eState); + if(GetModel()->HasChildren(pEntry)) // if it has children, check those too + { + SvTreeListEntry* pChildEntry = GetModel()->Next(pEntry); + SvTreeListEntry* pSiblingEntry = pEntry->NextSibling(); + while(pChildEntry && pChildEntry != pSiblingEntry) + { + SetCheckButtonState(pChildEntry,eState); + pChildEntry = GetModel()->Next(pChildEntry); + } + } + pEntry = NextSelected(pEntry); + } + 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(_pEntry, SvButtonState::Checked == eState); +} +SvButtonState OTableTreeListBox::implDetermineState(SvTreeListEntry* _pEntry) +{ SvButtonState eState = GetCheckButtonState(_pEntry); - OSL_ENSURE(SvButtonState::Tristate != eState, "OTableTreeListBox::CheckButtonHdl: user action which lead to TRISTATE?"); - implEmphasize(_pEntry, SvButtonState::Checked == eState); + if (!GetModel()->HasChildren(_pEntry)) + // 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; + + SvTreeListEntry* pChildLoop = GetModel()->FirstChild(_pEntry); + while (pChildLoop) + { + SvButtonState eChildState = implDetermineState(pChildLoop); + if (SvButtonState::Tristate == eChildState) + break; + + if (SvButtonState::Checked == eChildState) + ++nCheckedChildren; + ++nChildrenOverall; + + pChildLoop = pChildLoop->NextSibling(); + } + + if (pChildLoop) + { + // we did not finish the loop because at least one of the children is in tristate + eState = SvButtonState::Tristate; + + // 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 (pChildLoop) + { + implDetermineState(pChildLoop); + pChildLoop = pChildLoop->NextSibling(); + } + } + 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 = SvButtonState::Tristate; + else + // all children are checked + eState = SvButtonState::Checked; + else + // no children are checked + eState = SvButtonState::Unchecked; + + // finally set the entry to the state we just determined + SetCheckButtonState(_pEntry, eState); + + return eState; +} + +void OTableTreeListBox::CheckButtons() +{ + SvTreeListEntry* pEntry = GetModel()->First(); + while (pEntry) + { + implDetermineState(pEntry); + pEntry = pEntry->NextSibling(); + } +} + +void OTableTreeListBox::CheckButtonHdl() +{ + checkedButton_noBroadcast(GetHdlEntry()); +} + +void OTableTreeListBox::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& _rRect) +{ + if (!IsEnabled()) + { + vcl::Font aOldFont = rRenderContext.GetFont(); + vcl::Font aNewFont(aOldFont); + + StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings(); + aNewFont.SetColor(aSystemStyle.GetDisableColor()); + + rRenderContext.SetFont(aNewFont); + DBTreeListBox::Paint(rRenderContext, _rRect); + rRenderContext.SetFont(aOldFont); + } + else + DBTreeListBox::Paint(rRenderContext, _rRect); +} + +void OTableTreeListBox::KeyInput( const KeyEvent& rKEvt ) +{ + // only if there are spaces + if (rKEvt.GetKeyCode().GetCode() == KEY_SPACE && !rKEvt.GetKeyCode().IsShift() && !rKEvt.GetKeyCode().IsMod1()) + { + SvTreeListEntry* pCurrentHandlerEntry = GetHdlEntry(); + if(pCurrentHandlerEntry) + { + SvButtonState eState = GetCheckButtonState( pCurrentHandlerEntry); + if(eState == SvButtonState::Checked) + SetCheckButtonState( pCurrentHandlerEntry, SvButtonState::Unchecked); + else + SetCheckButtonState( pCurrentHandlerEntry, SvButtonState::Checked); + + CheckButtonHdl(); + } + else + DBTreeListBox::KeyInput(rKEvt); + } + else + DBTreeListBox::KeyInput(rKEvt); } void TableTreeListBox::checkedButton_noBroadcast(const weld::TreeIter& rEntry) @@ -600,7 +757,7 @@ void TableTreeListBox::implEmphasize(const weld::TreeIter& rEntry, bool _bChecke void OTableTreeListBox::InitEntry(SvTreeListEntry* _pEntry, const OUString& _rString, const Image& _rCollapsedBitmap, const Image& _rExpandedBitmap) { - OMarkableTreeListBox::InitEntry(_pEntry, _rString, _rCollapsedBitmap, _rExpandedBitmap); + DBTreeListBox::InitEntry(_pEntry, _rString, _rCollapsedBitmap, _rExpandedBitmap); // replace the text item with our own one SvLBoxItem* pTextItem = _pEntry->GetFirstItem(SvLBoxItemType::String); diff --git a/dbaccess/source/ui/inc/marktree.hxx b/dbaccess/source/ui/inc/marktree.hxx deleted file mode 100644 index 5eeece39d7ae..000000000000 --- a/dbaccess/source/ui/inc/marktree.hxx +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- 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 . - */ - -#ifndef INCLUDED_DBACCESS_SOURCE_UI_INC_MARKTREE_HXX -#define INCLUDED_DBACCESS_SOURCE_UI_INC_MARKTREE_HXX - -#include "dbtreelistbox.hxx" - -#include <vcl/svlbitm.hxx> - -namespace dbaui -{ - -// OMarkableTreeListBox -/** a tree list box where all entries can be marked (with a checkbox) and - unmarked. In addition, inner nodes know a third state which applies - if some, but not all of their descendants are marked. -*/ -class OMarkableTreeListBox : public DBTreeListBox -{ - std::unique_ptr<SvLBoxButtonData> m_pCheckButton; - -public: - OMarkableTreeListBox( vcl::Window* pParent, WinBits nWinStyle ); - virtual ~OMarkableTreeListBox() override; - virtual void dispose() override; - - virtual void KeyInput( const KeyEvent& rKEvt ) override; - virtual void CheckButtonHdl() override; - void CheckButtons(); // make the button states consistent (bottom-up) - -protected: - virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& _rRect) override; - virtual void checkedButton_noBroadcast(SvTreeListEntry* _pEntry); - - SvButtonState implDetermineState(SvTreeListEntry* _pEntry); - // determines the check state of the given entry, by analyzing the states of all descendants - -private: - void InitButtonData(); -}; - -} // namespace dbaui - -#endif // INCLUDED_DBACCESS_SOURCE_UI_INC_MARKTREE_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/ui/inc/tabletree.hxx b/dbaccess/source/ui/inc/tabletree.hxx index 30b3f742f591..179fce227f75 100644 --- a/dbaccess/source/ui/inc/tabletree.hxx +++ b/dbaccess/source/ui/inc/tabletree.hxx @@ -21,7 +21,7 @@ #define INCLUDED_DBACCESS_SOURCE_UI_INC_TABLETREE_HXX #include "imageprovider.hxx" -#include "marktree.hxx" +#include "dbtreelistbox.hxx" #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> #include <com/sun/star/sdbc/XConnection.hpp> @@ -33,8 +33,9 @@ namespace dbaui { // OTableTreeListBox -class OTableTreeListBox final : public OMarkableTreeListBox +class OTableTreeListBox final : public DBTreeListBox { + std::unique_ptr<SvLBoxButtonData> m_pCheckButton; css::uno::Reference< css::sdbc::XConnection > m_xConnection; // the connection we're working for, set in implOnNewConnection, called by UpdateTableList std::unique_ptr< ImageProvider > @@ -42,6 +43,7 @@ class OTableTreeListBox final : public OMarkableTreeListBox public: OTableTreeListBox(vcl::Window* pParent, WinBits nWinStyle); + virtual void dispose() override; typedef std::pair< OUString, bool > TTableViewName; typedef std::vector< TTableViewName > TNames; @@ -101,7 +103,8 @@ public: private: virtual void InitEntry(SvTreeListEntry* _pEntry, const OUString& _rString, const Image& _rCollapsedBitmap, const Image& _rExpandedBitmap) override; - virtual void checkedButton_noBroadcast(SvTreeListEntry* _pEntry) override; + virtual void CheckButtonHdl() override; + void checkedButton_noBroadcast(SvTreeListEntry* _pEntry); void implEmphasize(SvTreeListEntry* _pEntry, bool _bChecked, bool _bUpdateDescendants = true, bool _bUpdateAncestors = true); @@ -132,6 +135,15 @@ private: const TNames& _rTables ); + void InitButtonData(); + + SvButtonState implDetermineState(SvTreeListEntry* _pEntry); + // determines the check state of the given entry, by analyzing the states of all descendants + + void CheckButtons(); // make the button states consistent (bottom-up) + + virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& _rRect) override; + virtual void KeyInput( const KeyEvent& rKEvt ) override; }; class TableTreeListBox diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist index bdd8173d6106..bc5c41dd8535 100644 --- a/solenv/clang-format/excludelist +++ b/solenv/clang-format/excludelist @@ -3136,7 +3136,6 @@ dbaccess/source/ui/control/charsetlistbox.cxx dbaccess/source/ui/control/curledit.cxx dbaccess/source/ui/control/dbtreelistbox.cxx dbaccess/source/ui/control/listviewitems.cxx -dbaccess/source/ui/control/marktree.cxx dbaccess/source/ui/control/opendoccontrols.cxx dbaccess/source/ui/control/sqledit.cxx dbaccess/source/ui/control/tabletree.cxx @@ -3299,7 +3298,6 @@ dbaccess/source/ui/inc/indexes.hxx dbaccess/source/ui/inc/indexfieldscontrol.hxx dbaccess/source/ui/inc/linkeddocuments.hxx dbaccess/source/ui/inc/listviewitems.hxx -dbaccess/source/ui/inc/marktree.hxx dbaccess/source/ui/inc/objectnamecheck.hxx dbaccess/source/ui/inc/opendoccontrols.hxx dbaccess/source/ui/inc/paramdialog.hxx |