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, std::make_unique<ScRangeName>(*pName)));
44  }
45 
46  ScViewData* pViewData = ScDocShell::GetViewData();
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 
67 IMPL_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 
96 const std::vector<OUString>& ScNamePasteDlg::GetSelectedNames() const { return maSelectedNames; }
97 
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
IMPL_LINK(ScNamePasteDlg, ButtonHdl, weld::Button &, rButton, void)
Definition: namepast.cxx:67
virtual ~ScNamePasteDlg() override
Definition: namepast.cxx:65
std::unique_ptr< weld::Builder > m_xBuilder
SCROW GetCurY() const
Definition: viewdata.hxx:401
SC_DLLPUBLIC sal_Unicode GetSheetSeparator() const
Obtain the sheet separator corresponding to the document's grammar.
Definition: documen4.cxx:1349
SCTAB GetTabNo() const
Definition: viewdata.hxx:394
OUString m_aSheetSep
Definition: namepast.hxx:43
std::unique_ptr< weld::Button > m_xBtnPaste
Definition: namepast.hxx:37
sal_uInt16 char * pName
Definition: callform.cxx:57
std::unique_ptr< ScRangeManagerTable > m_xTable
Definition: namepast.hxx:39
SC_DLLPUBLIC void GetRangeNameMap(std::map< OUString, ScRangeName * > &rRangeName)
Definition: documen3.cxx:145
ScNamePasteDlg(weld::Window *pParent, ScDocShell *pShell)
Definition: namepast.cxx:31
OUString ScResId(const char *pId)
Definition: scdll.cxx:89
static ScViewData * GetViewData()
Definition: docsh4.cxx:2549
std::unique_ptr< weld::Button > m_xBtnClose
Definition: namepast.hxx:38
#define BTN_PASTE_CLOSE
Definition: scui_def.hxx:63
std::unique_ptr< weld::Button > m_xBtnPasteAll
Definition: namepast.hxx:36
std::map< OUString, std::unique_ptr< ScRangeName > > m_RangeMap
Definition: namepast.hxx:42
Reference< XExecutableDialog > m_xDialog
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
#define BTN_PASTE_LIST
Definition: scui_def.hxx:62
std::vector< OUString > maSelectedNames
Definition: namepast.hxx:41
const std::vector< OUString > & GetSelectedNames() const
Definition: namepast.cxx:96
static void CheckTabQuotes(OUString &aTabName, const formula::FormulaGrammar::AddressConvention eConv=formula::FormulaGrammar::CONV_OOO)
all
Definition: compiler.cxx:1929
SCCOL GetCurX() const
Definition: viewdata.hxx:400
#define BTN_PASTE_NAME
Definition: scui_def.hxx:61