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
47 ScAddress aPos(pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo());
48
49 std::unique_ptr<weld::TreeView> xTreeView(m_xBuilder->weld_tree_view("ctrl"));
50 xTreeView->set_size_request(xTreeView->get_approximate_digit_width() * 75,
51 xTreeView->get_height_rows(10));
52 m_xTable.reset(new ScRangeManagerTable(std::move(xTreeView), m_RangeMap, aPos));
53
54 m_xBtnPaste->connect_clicked(LINK(this, ScNamePasteDlg, ButtonHdl));
55 m_xBtnPasteAll->connect_clicked(LINK(this, ScNamePasteDlg, ButtonHdl));
56 m_xBtnClose->connect_clicked(LINK(this, ScNamePasteDlg, ButtonHdl));
57
58 if (!m_xTable->n_children())
59 {
60 m_xBtnPaste->set_sensitive(false);
61 m_xBtnPasteAll->set_sensitive(false);
62 }
63}
64
66
67IMPL_LINK(ScNamePasteDlg, ButtonHdl, weld::Button&, rButton, void)
68{
69 if (&rButton == m_xBtnPasteAll.get())
70 {
71 m_xDialog->response(BTN_PASTE_LIST);
72 }
73 else if (&rButton == m_xBtnPaste.get())
74 {
75 const OUString aGlobalScope(ScResId(STR_GLOBAL_SCOPE));
76 std::vector<ScRangeNameLine> aSelectedLines = m_xTable->GetSelectedEntries();
77 for (const auto& rLine : aSelectedLines)
78 {
79 if (rLine.aScope == aGlobalScope)
80 maSelectedNames.push_back(rLine.aName);
81 else
82 {
83 OUString aSheet(rLine.aScope);
85 maSelectedNames.push_back(aSheet + m_aSheetSep + rLine.aName);
86 }
87 }
88 m_xDialog->response(BTN_PASTE_NAME);
89 }
90 else if (&rButton == m_xBtnClose.get())
91 {
92 m_xDialog->response(BTN_PASTE_CLOSE);
93 }
94}
95
96const std::vector<OUString>& ScNamePasteDlg::GetSelectedNames() const { return maSelectedNames; }
97
98/* 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:1949
const ScDocument & GetDocument() const
Definition: docsh.hxx:220
static ScViewData * GetViewData()
Definition: docsh4.cxx:2592
SC_DLLPUBLIC void GetRangeNameMap(std::map< OUString, ScRangeName * > &rRangeName)
Definition: documen3.cxx:152
SC_DLLPUBLIC sal_Unicode GetSheetSeparator() const
Obtain the sheet separator corresponding to the document's grammar.
Definition: documen4.cxx:1359
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:96
std::unique_ptr< weld::Button > m_xBtnPasteAll
Definition: namepast.hxx:36
virtual ~ScNamePasteDlg() override
Definition: namepast.cxx:65
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
SCROW GetCurY() const
Definition: viewdata.hxx:402
SCCOL GetCurX() const
Definition: viewdata.hxx:401
std::unique_ptr< weld::Builder > m_xBuilder
IMPL_LINK(ScNamePasteDlg, ButtonHdl, weld::Button &, rButton, void)
Definition: namepast.cxx:67
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