Line data Source code
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 :
10 : #include "searchresults.hxx"
11 :
12 : #include <svtools/simptabl.hxx>
13 : #include <svtools/treelistentry.hxx>
14 : #include <sfx2/bindings.hxx>
15 : #include <sfx2/dispatch.hxx>
16 : #include "dociter.hxx"
17 : #include "document.hxx"
18 : #include "rangeutl.hxx"
19 : #include "tabvwsh.hxx"
20 : #include <sc.hrc>
21 : #include "scresid.hxx"
22 :
23 : namespace sc {
24 :
25 0 : SearchResultsDlg::SearchResultsDlg( SfxBindings* _pBindings, vcl::Window* pParent, sal_uInt16 /* nId */ ) :
26 : ModelessDialog(pParent, "SearchResultsDialog", "modules/scalc/ui/searchresults.ui"),
27 0 : mpBindings(_pBindings), mpDoc(NULL)
28 : {
29 0 : SvSimpleTableContainer *pContainer = get<SvSimpleTableContainer>("results");
30 0 : Size aControlSize(150, 120);
31 0 : aControlSize = pContainer->LogicToPixel(aControlSize, MAP_APPFONT);
32 0 : pContainer->set_width_request(aControlSize.Width());
33 0 : pContainer->set_height_request(aControlSize.Height());
34 :
35 0 : mpList = new SvSimpleTable(*pContainer);
36 0 : long nTabs[] = {3, 0, 40, 60};
37 0 : mpList->SetTabs(&nTabs[0]);
38 0 : mpList->InsertHeaderEntry(SC_RESSTR(STR_SHEET) + "\t" + SC_RESSTR(STR_CELL) + "\t" + SC_RESSTR(STR_CONTENT));
39 0 : mpList->SetSelectHdl( LINK(this, SearchResultsDlg, ListSelectHdl) );
40 0 : }
41 :
42 0 : SearchResultsDlg::~SearchResultsDlg()
43 : {
44 0 : delete mpList;
45 0 : }
46 :
47 0 : void SearchResultsDlg::FillResults( ScDocument* pDoc, const ScRangeList &rMatchedRanges )
48 : {
49 0 : mpList->Clear();
50 0 : mpList->SetUpdateMode(false);
51 0 : std::vector<OUString> aTabNames = pDoc->GetAllTableNames();
52 0 : SCTAB nTabCount = aTabNames.size();
53 0 : for (size_t i = 0, n = rMatchedRanges.size(); i < n; ++i)
54 : {
55 0 : ScCellIterator aIter(pDoc, *rMatchedRanges[i]);
56 0 : for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
57 : {
58 0 : ScAddress aPos = aIter.GetPos();
59 0 : if (aPos.Tab() >= nTabCount)
60 : // Out-of-bound sheet index.
61 0 : continue;
62 :
63 0 : OUString aPosStr = aPos.Format(SCA_ABS, NULL, pDoc->GetAddressConvention());
64 0 : mpList->InsertEntry(aTabNames[aPos.Tab()] + "\t" + aPosStr + "\t" + pDoc->GetString(aPos));
65 0 : }
66 0 : }
67 0 : mpList->SetUpdateMode(true);
68 :
69 0 : mpDoc = pDoc;
70 0 : }
71 :
72 0 : bool SearchResultsDlg::Close()
73 : {
74 0 : if (mpBindings)
75 : {
76 : // Remove this dialog from the view frame after the dialog gets
77 : // dismissed, else it would keep popping up endlessly!
78 0 : SfxDispatcher* pDispacher = mpBindings ->GetDispatcher();
79 0 : SfxBoolItem aItem(SID_SEARCH_RESULTS_DIALOG, false);
80 0 : if (pDispacher)
81 : pDispacher->Execute(
82 0 : SID_SEARCH_RESULTS_DIALOG, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD, &aItem, 0L);
83 : }
84 :
85 0 : return ModelessDialog::Close();
86 : }
87 :
88 0 : IMPL_LINK_NOARG( SearchResultsDlg, ListSelectHdl )
89 : {
90 0 : if (!mpDoc)
91 0 : return 0;
92 :
93 0 : SvTreeListEntry *pEntry = mpList->FirstSelected();
94 0 : OUString aTabStr = mpList->GetEntryText(pEntry, 0);
95 0 : OUString aPosStr = mpList->GetEntryText(pEntry, 1);
96 :
97 0 : SCTAB nTab = -1;
98 0 : if (!mpDoc->GetTable(aTabStr, nTab))
99 : // No sheet with specified name.
100 0 : return 0;
101 :
102 0 : ScAddress aPos;
103 0 : sal_uInt16 nRes = aPos.Parse(aPosStr, mpDoc, mpDoc->GetAddressConvention());
104 0 : if (!(nRes & SCA_VALID))
105 : // Invalid address string.
106 0 : return 0;
107 :
108 : // Jump to the cell.
109 0 : ScTabViewShell* pScViewShell = ScTabViewShell::GetActiveViewShell();
110 0 : pScViewShell->SetTabNo(nTab);
111 0 : pScViewShell->SetCursor(aPos.Col(), aPos.Row());
112 0 : pScViewShell->AlignToCursor(aPos.Col(), aPos.Row(), SC_FOLLOW_JUMP);
113 :
114 0 : return 0;
115 : }
116 :
117 0 : SearchResultsDlgWrapper::SearchResultsDlgWrapper(
118 : vcl::Window* _pParent, sal_uInt16 nId, SfxBindings* pBindings, SfxChildWinInfo* /*pInfo*/ ) :
119 0 : SfxChildWindow(_pParent, nId)
120 : {
121 0 : pWindow = new SearchResultsDlg(pBindings, _pParent, nId);
122 0 : }
123 :
124 0 : SearchResultsDlgWrapper::~SearchResultsDlgWrapper() {}
125 :
126 0 : SfxChildWinInfo SearchResultsDlgWrapper::GetInfo() const
127 : {
128 0 : SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();
129 0 : aInfo.bVisible = false;
130 0 : return aInfo;
131 : }
132 :
133 152 : SFX_IMPL_CHILDWINDOW_WITHID(SearchResultsDlgWrapper, SID_SEARCH_RESULTS_DIALOG);
134 :
135 228 : }
136 :
137 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|