From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- sc/source/ui/namedlg/namepast.cxx | 99 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 sc/source/ui/namedlg/namepast.cxx (limited to 'sc/source/ui/namedlg/namepast.cxx') diff --git a/sc/source/ui/namedlg/namepast.cxx b/sc/source/ui/namedlg/namepast.cxx new file mode 100644 index 000000000..37984eb8b --- /dev/null +++ b/sc/source/ui/namedlg/namepast.cxx @@ -0,0 +1,99 @@ +/* -*- 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 . + */ + +#undef SC_DLLIMPLEMENTATION + +#include +#include +#include +#include +#include +#include +#include +#include + +ScNamePasteDlg::ScNamePasteDlg(weld::Window* pParent, ScDocShell* pShell) + : GenericDialogController(pParent, "modules/scalc/ui/insertname.ui", "InsertNameDialog") + , m_xBtnPasteAll(m_xBuilder->weld_button("pasteall")) + , m_xBtnPaste(m_xBuilder->weld_button("paste")) + , m_xBtnClose(m_xBuilder->weld_button("close")) +{ + ScDocument& rDoc = pShell->GetDocument(); + m_aSheetSep = OUString(rDoc.GetSheetSeparator()); + std::map aCopyMap; + rDoc.GetRangeNameMap(aCopyMap); + for (const auto & [ aTemp, pName ] : aCopyMap) + { + m_RangeMap.insert(std::make_pair(aTemp, std::make_unique(*pName))); + } + + ScAddress aPos; + if (ScViewData* pViewData = ScDocShell::GetViewData()) + aPos = ScAddress(pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo()); + + std::unique_ptr xTreeView(m_xBuilder->weld_tree_view("ctrl")); + xTreeView->set_size_request(xTreeView->get_approximate_digit_width() * 75, + xTreeView->get_height_rows(10)); + m_xTable.reset(new ScRangeManagerTable(std::move(xTreeView), m_RangeMap, aPos)); + + m_xBtnPaste->connect_clicked(LINK(this, ScNamePasteDlg, ButtonHdl)); + m_xBtnPasteAll->connect_clicked(LINK(this, ScNamePasteDlg, ButtonHdl)); + m_xBtnClose->connect_clicked(LINK(this, ScNamePasteDlg, ButtonHdl)); + + if (!m_xTable->n_children()) + { + m_xBtnPaste->set_sensitive(false); + m_xBtnPasteAll->set_sensitive(false); + } +} + +ScNamePasteDlg::~ScNamePasteDlg() {} + +IMPL_LINK(ScNamePasteDlg, ButtonHdl, weld::Button&, rButton, void) +{ + if (&rButton == m_xBtnPasteAll.get()) + { + m_xDialog->response(BTN_PASTE_LIST); + } + else if (&rButton == m_xBtnPaste.get()) + { + const OUString aGlobalScope(ScResId(STR_GLOBAL_SCOPE)); + std::vector aSelectedLines = m_xTable->GetSelectedEntries(); + for (const auto& rLine : aSelectedLines) + { + if (rLine.aScope == aGlobalScope) + maSelectedNames.push_back(rLine.aName); + else + { + OUString aSheet(rLine.aScope); + ScCompiler::CheckTabQuotes(aSheet); + maSelectedNames.push_back(aSheet + m_aSheetSep + rLine.aName); + } + } + m_xDialog->response(BTN_PASTE_NAME); + } + else if (&rButton == m_xBtnClose.get()) + { + m_xDialog->response(BTN_PASTE_CLOSE); + } +} + +const std::vector& ScNamePasteDlg::GetSelectedNames() const { return maSelectedNames; } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3