Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / dialogs / searchresults.cxx
blob3b27a2a91ea56cf76f36b98fd16f8cbf95a77453
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/.
8 */
10 #include "searchresults.hxx"
12 #include <svtools/simptabl.hxx>
13 #include <svtools/treelistentry.hxx>
14 #include "dociter.hxx"
15 #include "document.hxx"
16 #include "rangeutl.hxx"
17 #include "tabvwsh.hxx"
19 SearchResults::SearchResults(ScDocument *pDoc) :
20 ModelessDialog(NULL, "SearchResultsDialog", "modules/scalc/ui/searchresults.ui")
21 , mpDoc(pDoc)
23 SvSimpleTableContainer *pContainer = get<SvSimpleTableContainer>("results");
24 Size aControlSize(150, 120);
25 aControlSize = pContainer->LogicToPixel(aControlSize, MAP_APPFONT);
26 pContainer->set_width_request(aControlSize.Width());
27 pContainer->set_height_request(aControlSize.Height());
29 mpList = new SvSimpleTable(*pContainer);
30 long nTabs[] = {3, 0, 40, 60};
31 mpList->SetTabs(&nTabs[0]);
32 mpList->InsertHeaderEntry("Sheet\tCell\tContent");
33 mpList->SetSelectHdl( LINK(this, SearchResults, ListSelectHdl) );
36 SearchResults::~SearchResults()
38 delete mpList;
41 void SearchResults::Show(const ScRangeList &rMatchedRanges)
43 mpList->Clear();
44 mpList->SetUpdateMode(false);
45 for (size_t i = 0, n = rMatchedRanges.size(); i < n; ++i)
47 ScCellIterator aIter(mpDoc, *rMatchedRanges[i]);
48 for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
50 ScAddress aAddress = aIter.GetPos();
51 OUString sAddress;
52 ScRangeStringConverter::GetStringFromAddress(sAddress, aAddress,
53 mpDoc, formula::FormulaGrammar::CONV_OOO);
54 mpList->InsertEntry(sAddress.replace('.', '\t') + "\t" + mpDoc->GetString(aAddress));
57 mpList->SetUpdateMode(true);
58 ModelessDialog::Show();
61 IMPL_LINK_NOARG( SearchResults, ListSelectHdl )
63 SvTreeListEntry *pEntry = mpList->FirstSelected();
64 ScAddress aAddress;
65 sal_Int32 nOffset = 0;
66 OUString sAddress = mpList->GetEntryText(pEntry).replaceFirst("\t", ".");
67 ScRangeStringConverter::GetAddressFromString(aAddress, sAddress,
68 mpDoc, formula::FormulaGrammar::CONV_OOO, nOffset, '\t');
69 ScTabViewShell* pScViewShell = ScTabViewShell::GetActiveViewShell();
70 pScViewShell->SetTabNo(aAddress.Tab());
71 pScViewShell->SetCursor(aAddress.Col(), aAddress.Row());
72 pScViewShell->AlignToCursor(aAddress.Col(), aAddress.Row(), SC_FOLLOW_JUMP);
73 return 0;
76 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */