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 
29  : GenericDialogController(pParent, "modules/scalc/ui/insertname.ui", "InsertNameDialog")
30  , m_xBtnPasteAll(m_xBuilder->weld_button("pasteall"))
31  , m_xBtnPaste(m_xBuilder->weld_button("paste"))
32  , m_xBtnClose(m_xBuilder->weld_button("close"))
33 {
34  ScDocument& rDoc = pShell->GetDocument();
35  std::map<OUString, ScRangeName*> aCopyMap;
36  rDoc.GetRangeNameMap(aCopyMap);
37  for (const auto& [aTemp, pName] : aCopyMap)
38  {
39  m_RangeMap.insert(std::make_pair(aTemp, std::make_unique<ScRangeName>(*pName)));
40  }
41 
42  ScViewData* pViewData = ScDocShell::GetViewData();
43  ScAddress aPos(pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo());
44 
45  std::unique_ptr<weld::TreeView> xTreeView(m_xBuilder->weld_tree_view("ctrl"));
46  xTreeView->set_size_request(xTreeView->get_approximate_digit_width() * 75,
47  xTreeView->get_height_rows(10));
48  m_xTable.reset(new ScRangeManagerTable(std::move(xTreeView), m_RangeMap, aPos));
49 
50  m_xBtnPaste->connect_clicked( LINK( this, ScNamePasteDlg, ButtonHdl) );
51  m_xBtnPasteAll->connect_clicked( LINK( this, ScNamePasteDlg, ButtonHdl));
52  m_xBtnClose->connect_clicked( LINK( this, ScNamePasteDlg, ButtonHdl));
53 
54  if (!m_xTable->n_children())
55  {
56  m_xBtnPaste->set_sensitive(false);
57  m_xBtnPasteAll->set_sensitive(false);
58  }
59 }
60 
62 {
63 }
64 
65 IMPL_LINK(ScNamePasteDlg, ButtonHdl, weld::Button&, rButton, void)
66 {
67  if (&rButton == m_xBtnPasteAll.get())
68  {
69  m_xDialog->response(BTN_PASTE_LIST);
70  }
71  else if (&rButton == m_xBtnPaste.get())
72  {
73  std::vector<ScRangeNameLine> aSelectedLines = m_xTable->GetSelectedEntries();
74  for (const auto& rLine : aSelectedLines)
75  {
76  maSelectedNames.push_back(rLine.aName);
77  }
78  m_xDialog->response(BTN_PASTE_NAME);
79  }
80  else if (&rButton == m_xBtnClose.get())
81  {
82  m_xDialog->response(BTN_PASTE_CLOSE);
83  }
84 }
85 
86 const std::vector<OUString>& ScNamePasteDlg::GetSelectedNames() const
87 {
88  return maSelectedNames;
89 }
90 
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
IMPL_LINK(ScNamePasteDlg, ButtonHdl, weld::Button &, rButton, void)
Definition: namepast.cxx:65
virtual ~ScNamePasteDlg() override
Definition: namepast.cxx:61
std::unique_ptr< weld::Builder > m_xBuilder
SCROW GetCurY() const
Definition: viewdata.hxx:402
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
std::unique_ptr< weld::Button > m_xBtnPaste
Definition: namepast.hxx:38
sal_uInt16 char * pName
Definition: callform.cxx:58
std::unique_ptr< ScRangeManagerTable > m_xTable
Definition: namepast.hxx:40
SC_DLLPUBLIC void GetRangeNameMap(std::map< OUString, ScRangeName * > &rRangeName)
Definition: documen3.cxx:146
ScNamePasteDlg(weld::Window *pParent, ScDocShell *pShell)
Definition: namepast.cxx:28
static ScViewData * GetViewData()
Definition: docsh4.cxx:2540
std::unique_ptr< weld::Button > m_xBtnClose
Definition: namepast.hxx:39
#define BTN_PASTE_CLOSE
Definition: scui_def.hxx:64
std::unique_ptr< weld::Button > m_xBtnPasteAll
Definition: namepast.hxx:37
std::map< OUString, std::unique_ptr< ScRangeName > > m_RangeMap
Definition: namepast.hxx:43
Reference< XExecutableDialog > m_xDialog
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
#define BTN_PASTE_LIST
Definition: scui_def.hxx:63
std::vector< OUString > maSelectedNames
Definition: namepast.hxx:42
const std::vector< OUString > & GetSelectedNames() const
Definition: namepast.cxx:86
SCCOL GetCurX() const
Definition: viewdata.hxx:401
#define BTN_PASTE_NAME
Definition: scui_def.hxx:62