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 = VclPtr<SvSimpleTable>::Create(*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 : disposeOnce();
45 0 : }
46 :
47 0 : void SearchResultsDlg::dispose()
48 : {
49 0 : mpList.disposeAndClear();
50 0 : ModelessDialog::dispose();
51 0 : }
52 :
53 0 : void SearchResultsDlg::FillResults( ScDocument* pDoc, const ScRangeList &rMatchedRanges )
54 : {
55 0 : mpList->Clear();
56 0 : mpList->SetUpdateMode(false);
57 0 : std::vector<OUString> aTabNames = pDoc->GetAllTableNames();
58 0 : SCTAB nTabCount = aTabNames.size();
59 0 : for (size_t i = 0, n = rMatchedRanges.size(); i < n; ++i)
60 : {
61 0 : ScCellIterator aIter(pDoc, *rMatchedRanges[i]);
62 0 : for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
63 : {
64 0 : ScAddress aPos = aIter.GetPos();
65 0 : if (aPos.Tab() >= nTabCount)
66 : // Out-of-bound sheet index.
67 0 : continue;
68 :
69 0 : OUString aPosStr = aPos.Format(SCA_ABS, NULL, pDoc->GetAddressConvention());
70 0 : mpList->InsertEntry(aTabNames[aPos.Tab()] + "\t" + aPosStr + "\t" + pDoc->GetString(aPos));
71 0 : }
72 0 : }
73 0 : mpList->SetUpdateMode(true);
74 :
75 0 : mpDoc = pDoc;
76 0 : }
77 :
78 0 : bool SearchResultsDlg::Close()
79 : {
80 0 : if (mpBindings)
81 : {
82 : // Remove this dialog from the view frame after the dialog gets
83 : // dismissed, else it would keep popping up endlessly!
84 0 : SfxDispatcher* pDispacher = mpBindings ->GetDispatcher();
85 0 : SfxBoolItem aItem(SID_SEARCH_RESULTS_DIALOG, false);
86 0 : if (pDispacher)
87 : pDispacher->Execute(
88 0 : SID_SEARCH_RESULTS_DIALOG, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD, &aItem, 0L);
89 : }
90 :
91 0 : return ModelessDialog::Close();
92 : }
93 :
94 0 : IMPL_LINK_NOARG( SearchResultsDlg, ListSelectHdl )
95 : {
96 0 : if (!mpDoc)
97 0 : return 0;
98 :
99 0 : SvTreeListEntry *pEntry = mpList->FirstSelected();
100 0 : OUString aTabStr = SvTabListBox::GetEntryText(pEntry, 0);
101 0 : OUString aPosStr = SvTabListBox::GetEntryText(pEntry, 1);
102 :
103 0 : SCTAB nTab = -1;
104 0 : if (!mpDoc->GetTable(aTabStr, nTab))
105 : // No sheet with specified name.
106 0 : return 0;
107 :
108 0 : ScAddress aPos;
109 0 : sal_uInt16 nRes = aPos.Parse(aPosStr, mpDoc, mpDoc->GetAddressConvention());
110 0 : if (!(nRes & SCA_VALID))
111 : // Invalid address string.
112 0 : return 0;
113 :
114 : // Jump to the cell.
115 0 : ScTabViewShell* pScViewShell = ScTabViewShell::GetActiveViewShell();
116 0 : pScViewShell->SetTabNo(nTab);
117 0 : pScViewShell->SetCursor(aPos.Col(), aPos.Row());
118 0 : pScViewShell->AlignToCursor(aPos.Col(), aPos.Row(), SC_FOLLOW_JUMP);
119 :
120 0 : return 0;
121 : }
122 :
123 0 : SearchResultsDlgWrapper::SearchResultsDlgWrapper(
124 : vcl::Window* _pParent, sal_uInt16 nId, SfxBindings* pBindings, SfxChildWinInfo* /*pInfo*/ ) :
125 0 : SfxChildWindow(_pParent, nId)
126 : {
127 0 : pWindow = VclPtr<SearchResultsDlg>::Create(pBindings, _pParent, nId);
128 0 : }
129 :
130 0 : SearchResultsDlgWrapper::~SearchResultsDlgWrapper() {}
131 :
132 0 : SfxChildWinInfo SearchResultsDlgWrapper::GetInfo() const
133 : {
134 0 : SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();
135 0 : aInfo.bVisible = false;
136 0 : return aInfo;
137 : }
138 :
139 104 : SFX_IMPL_CHILDWINDOW_WITHID(SearchResultsDlgWrapper, SID_SEARCH_RESULTS_DIALOG);
140 :
141 156 : }
142 :
143 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|