diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /cui/source/dialogs/showcols.cxx | |
parent | Initial commit. (diff) | |
download | libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'cui/source/dialogs/showcols.cxx')
-rw-r--r-- | cui/source/dialogs/showcols.cxx | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/cui/source/dialogs/showcols.cxx b/cui/source/dialogs/showcols.cxx new file mode 100644 index 000000000..895ed485e --- /dev/null +++ b/cui/source/dialogs/showcols.cxx @@ -0,0 +1,107 @@ +/* -*- 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 <showcols.hxx> + +#include <osl/diagnose.h> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <comphelper/types.hxx> +#include <tools/debug.hxx> + +#define CUIFM_PROP_HIDDEN "Hidden" +#define CUIFM_PROP_LABEL "Label" + +FmShowColsDialog::FmShowColsDialog(weld::Window* pParent) + : GenericDialogController(pParent, "cui/ui/showcoldialog.ui", "ShowColDialog") + , m_xList(m_xBuilder->weld_tree_view("treeview")) + , m_xOK(m_xBuilder->weld_button("ok")) +{ + m_xList->set_size_request(m_xList->get_approximate_digit_width() * 40, m_xList->get_height_rows(8)); + m_xList->set_selection_mode(SelectionMode::Multiple); + m_xOK->connect_clicked(LINK(this, FmShowColsDialog, OnClickedOk)); +} + +FmShowColsDialog::~FmShowColsDialog() +{ +} + +IMPL_LINK_NOARG(FmShowColsDialog, OnClickedOk, weld::Button&, void) +{ + DBG_ASSERT(m_xColumns.is(), "FmShowColsDialog::OnClickedOk : you should call SetColumns before executing the dialog !"); + if (m_xColumns.is()) + { + css::uno::Reference< css::beans::XPropertySet > xCol; + auto nSelectedRows = m_xList->get_selected_rows(); + for (auto i : nSelectedRows) + { + m_xColumns->getByIndex(m_xList->get_id(i).toInt32()) >>= xCol; + if (xCol.is()) + { + try + { + xCol->setPropertyValue(CUIFM_PROP_HIDDEN, css::uno::Any(false)); + } + catch(...) + { + OSL_FAIL("FmShowColsDialog::OnClickedOk Exception occurred!"); + } + } + } + } + + m_xDialog->response(RET_OK); +} + +void FmShowColsDialog::SetColumns(const css::uno::Reference< css::container::XIndexContainer>& xCols) +{ + DBG_ASSERT(xCols.is(), "FmShowColsDialog::SetColumns : invalid columns !"); + if (!xCols.is()) + return; + m_xColumns = xCols.get(); + + m_xList->clear(); + + css::uno::Reference< css::beans::XPropertySet> xCurCol; + OUString sCurName; + for (sal_Int32 i=0; i<xCols->getCount(); ++i) + { + sCurName.clear(); + xCurCol.set(xCols->getByIndex(i), css::uno::UNO_QUERY); + bool bIsHidden = false; + try + { + css::uno::Any aHidden = xCurCol->getPropertyValue(CUIFM_PROP_HIDDEN); + bIsHidden = ::comphelper::getBOOL(aHidden); + + OUString sName; + xCurCol->getPropertyValue(CUIFM_PROP_LABEL) >>= sName; + sCurName = sName; + } + catch(...) + { + OSL_FAIL("FmShowColsDialog::SetColumns Exception occurred!"); + } + + // if the col is hidden, put it into the list + if (bIsHidden) + m_xList->append(OUString::number(i), sCurName); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |