Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / ui / namedlg / namepast.cxx
blobf53d761ed87e6a47fbf5871653977803926d9846
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #undef SC_DLLIMPLEMENTATION
22 #include "namepast.hxx"
23 #include "scresid.hxx"
24 #include "docsh.hxx"
25 #include "miscdlgs.hrc"
26 #include "rangenam.hxx"
27 #include "viewdata.hxx"
29 #include <o3tl/make_unique.hxx>
31 ScNamePasteDlg::ScNamePasteDlg( vcl::Window * pParent, ScDocShell* pShell, bool )
32 : ModalDialog( pParent, "InsertNameDialog", "modules/scalc/ui/insertname.ui" )
34 get(m_pBtnPasteAll, "pasteall");
35 get(m_pBtnPaste, "paste");
36 get(m_pBtnClose, "close");
38 ScDocument& rDoc = pShell->GetDocument();
39 std::map<OUString, ScRangeName*> aCopyMap;
40 rDoc.GetRangeNameMap(aCopyMap);
41 std::map<OUString, ScRangeName*>::iterator itr = aCopyMap.begin(), itrEnd = aCopyMap.end();
42 for (; itr != itrEnd; ++itr)
44 OUString aTemp(itr->first);
45 m_RangeMap.insert(std::make_pair(aTemp, o3tl::make_unique<ScRangeName>(*itr->second)));
48 ScViewData* pViewData = ScDocShell::GetViewData();
49 ScAddress aPos(pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo());
50 SvSimpleTableContainer *pContainer = get<SvSimpleTableContainer>("ctrl");
51 Size aControlSize(210, 0);
52 aControlSize = LogicToPixel(aControlSize, MAP_APPFONT);
53 pContainer->set_width_request(aControlSize.Width());
54 pContainer->set_height_request(10 * GetTextHeight());
55 mpTable = VclPtr<ScRangeManagerTable>::Create(*pContainer, m_RangeMap, aPos);
57 m_pBtnPaste->SetClickHdl( LINK( this, ScNamePasteDlg, ButtonHdl) );
58 m_pBtnPasteAll->SetClickHdl( LINK( this, ScNamePasteDlg, ButtonHdl));
59 m_pBtnClose->SetClickHdl( LINK( this, ScNamePasteDlg, ButtonHdl));
61 if (!mpTable->GetEntryCount())
63 m_pBtnPaste->Disable();
64 m_pBtnPasteAll->Disable();
68 ScNamePasteDlg::~ScNamePasteDlg()
70 disposeOnce();
73 void ScNamePasteDlg::dispose()
75 mpTable.disposeAndClear();
76 m_pBtnPasteAll.clear();
77 m_pBtnPaste.clear();
78 m_pBtnClose.clear();
79 ModalDialog::dispose();
82 IMPL_LINK_TYPED( ScNamePasteDlg, ButtonHdl, Button *, pButton, void )
84 if( pButton == m_pBtnPasteAll )
86 EndDialog( BTN_PASTE_LIST );
88 else if( pButton == m_pBtnPaste )
90 std::vector<ScRangeNameLine> aSelectedLines = mpTable->GetSelectedEntries();
91 for (std::vector<ScRangeNameLine>::const_iterator itr = aSelectedLines.begin();
92 itr != aSelectedLines.end(); ++itr)
94 maSelectedNames.push_back(itr->aName);
96 EndDialog( BTN_PASTE_NAME );
98 else if( pButton == m_pBtnClose )
100 EndDialog( BTN_PASTE_CLOSE );
104 const std::vector<OUString>& ScNamePasteDlg::GetSelectedNames() const
106 return maSelectedNames;
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */