LibreOffice Module sc (master) 1
namepast.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#undef SC_DLLIMPLEMENTATION
21
22#include <namepast.hxx>
23#include <docsh.hxx>
24#include <rangenam.hxx>
25#include <viewdata.hxx>
26#include <scui_def.hxx>
27#include <globstr.hrc>
28#include <scresid.hxx>
29#include <compiler.hxx>
30
32 : GenericDialogController(pParent, "modules/scalc/ui/insertname.ui", "InsertNameDialog")
33 , m_xBtnPasteAll(m_xBuilder->weld_button("pasteall"))
34 , m_xBtnPaste(m_xBuilder->weld_button("paste"))
35 , m_xBtnClose(m_xBuilder->weld_button("close"))
36{
37 ScDocument& rDoc = pShell->GetDocument();
38 m_aSheetSep = OUString(rDoc.GetSheetSeparator());
39 std::map<OUString, ScRangeName*> aCopyMap;
40 rDoc.GetRangeNameMap(aCopyMap);
41 for (const auto & [ aTemp, pName ] : aCopyMap)
42 {
43 m_RangeMap.insert(std::make_pair(aTemp, *pName));
44 }
45
46 ScAddress aPos;
47 if (ScViewData* pViewData = ScDocShell::GetViewData())
48 aPos = ScAddress(pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo());
49
50 std::unique_ptr<weld::TreeView> xTreeView(m_xBuilder->weld_tree_view("ctrl"));
51 xTreeView->set_size_request(xTreeView->get_approximate_digit_width() * 75,
52 xTreeView->get_height_rows(10));
53 m_xTable.reset(new ScRangeManagerTable(std::move(xTreeView), m_RangeMap, aPos));
54
55 m_xBtnPaste->connect_clicked(LINK(this, ScNamePasteDlg, ButtonHdl));
56 m_xBtnPasteAll->connect_clicked(LINK(this, ScNamePasteDlg, ButtonHdl));
57 m_xBtnClose->connect_clicked(LINK(this, ScNamePasteDlg, ButtonHdl));
58
59 if (!m_xTable->n_children())
60 {
61 m_xBtnPaste->set_sensitive(false);
62 m_xBtnPasteAll->set_sensitive(false);
63 }
64}
65
67
68IMPL_LINK(ScNamePasteDlg, ButtonHdl, weld::Button&, rButton, void)
69{
70 if (&rButton == m_xBtnPasteAll.get())
71 {
72 m_xDialog->response(BTN_PASTE_LIST);
73 }
74 else if (&rButton == m_xBtnPaste.get())
75 {
76 const OUString aGlobalScope(ScResId(STR_GLOBAL_SCOPE));
77 std::vector<ScRangeNameLine> aSelectedLines = m_xTable->GetSelectedEntries();
78 for (const auto& rLine : aSelectedLines)
79 {
80 if (rLine.aScope == aGlobalScope)
81 maSelectedNames.push_back(rLine.aName);
82 else
83 {
84 OUString aSheet(rLine.aScope);
86 maSelectedNames.push_back(aSheet + m_aSheetSep + rLine.aName);
87 }
88 }
89 m_xDialog->response(BTN_PASTE_NAME);
90 }
91 else if (&rButton == m_xBtnClose.get())
92 {
93 m_xDialog->response(BTN_PASTE_CLOSE);
94 }
95}
96
97const std::vector<OUString>& ScNamePasteDlg::GetSelectedNames() const { return maSelectedNames; }
98
99/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const char * pName
Reference< XExecutableDialog > m_xDialog
static void CheckTabQuotes(OUString &aTabName, const formula::FormulaGrammar::AddressConvention eConv=formula::FormulaGrammar::CONV_OOO)
all
Definition: compiler.cxx:1954
const ScDocument & GetDocument() const
Definition: docsh.hxx:219
static ScViewData * GetViewData()
Definition: docsh4.cxx:2607
SC_DLLPUBLIC void GetRangeNameMap(std::map< OUString, ScRangeName * > &rRangeName)
Definition: documen3.cxx:149
SC_DLLPUBLIC sal_Unicode GetSheetSeparator() const
Obtain the sheet separator corresponding to the document's grammar.
Definition: documen4.cxx:1351
OUString m_aSheetSep
Definition: namepast.hxx:43
std::unique_ptr< weld::Button > m_xBtnClose
Definition: namepast.hxx:38
std::map< OUString, ScRangeName > m_RangeMap
Definition: namepast.hxx:42
ScNamePasteDlg(weld::Window *pParent, ScDocShell *pShell)
Definition: namepast.cxx:31
std::unique_ptr< weld::Button > m_xBtnPaste
Definition: namepast.hxx:37
std::unique_ptr< ScRangeManagerTable > m_xTable
Definition: namepast.hxx:39
std::vector< OUString > maSelectedNames
Definition: namepast.hxx:41
const std::vector< OUString > & GetSelectedNames() const
Definition: namepast.cxx:97
std::unique_ptr< weld::Button > m_xBtnPasteAll
Definition: namepast.hxx:36
virtual ~ScNamePasteDlg() override
Definition: namepast.cxx:66
std::unique_ptr< weld::Builder > m_xBuilder
IMPL_LINK(ScNamePasteDlg, ButtonHdl, weld::Button &, rButton, void)
Definition: namepast.cxx:68
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
#define BTN_PASTE_CLOSE
Definition: scui_def.hxx:63
#define BTN_PASTE_NAME
Definition: scui_def.hxx:61
#define BTN_PASTE_LIST
Definition: scui_def.hxx:62