1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include "searchresults.hxx"
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"
21 #include "scresid.hxx"
25 SearchResultsDlg::SearchResultsDlg( SfxBindings
* _pBindings
, vcl::Window
* pParent
, sal_uInt16
/* nId */ ) :
26 ModelessDialog(pParent
, "SearchResultsDialog", "modules/scalc/ui/searchresults.ui"),
27 mpBindings(_pBindings
), mpDoc(NULL
)
29 SvSimpleTableContainer
*pContainer
= get
<SvSimpleTableContainer
>("results");
30 Size
aControlSize(150, 120);
31 aControlSize
= pContainer
->LogicToPixel(aControlSize
, MAP_APPFONT
);
32 pContainer
->set_width_request(aControlSize
.Width());
33 pContainer
->set_height_request(aControlSize
.Height());
35 mpList
= VclPtr
<SvSimpleTable
>::Create(*pContainer
);
36 long nTabs
[] = {3, 0, 40, 60};
37 mpList
->SetTabs(&nTabs
[0]);
38 mpList
->InsertHeaderEntry(SC_RESSTR(STR_SHEET
) + "\t" + SC_RESSTR(STR_CELL
) + "\t" + SC_RESSTR(STR_CONTENT
));
39 mpList
->SetSelectHdl( LINK(this, SearchResultsDlg
, ListSelectHdl
) );
42 SearchResultsDlg::~SearchResultsDlg()
47 void SearchResultsDlg::dispose()
49 mpList
.disposeAndClear();
50 ModelessDialog::dispose();
53 void SearchResultsDlg::FillResults( ScDocument
* pDoc
, const ScRangeList
&rMatchedRanges
)
56 mpList
->SetUpdateMode(false);
57 std::vector
<OUString
> aTabNames
= pDoc
->GetAllTableNames();
58 SCTAB nTabCount
= aTabNames
.size();
59 for (size_t i
= 0, n
= rMatchedRanges
.size(); i
< n
; ++i
)
61 ScCellIterator
aIter(pDoc
, *rMatchedRanges
[i
]);
62 for (bool bHas
= aIter
.first(); bHas
; bHas
= aIter
.next())
64 ScAddress aPos
= aIter
.GetPos();
65 if (aPos
.Tab() >= nTabCount
)
66 // Out-of-bound sheet index.
69 OUString aPosStr
= aPos
.Format(SCA_ABS
, NULL
, pDoc
->GetAddressConvention());
70 mpList
->InsertEntry(aTabNames
[aPos
.Tab()] + "\t" + aPosStr
+ "\t" + pDoc
->GetString(aPos
));
73 mpList
->SetUpdateMode(true);
78 bool SearchResultsDlg::Close()
82 // Remove this dialog from the view frame after the dialog gets
83 // dismissed, else it would keep popping up endlessly!
84 SfxDispatcher
* pDispacher
= mpBindings
->GetDispatcher();
85 SfxBoolItem
aItem(SID_SEARCH_RESULTS_DIALOG
, false);
88 SID_SEARCH_RESULTS_DIALOG
, SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
, &aItem
, 0L);
91 return ModelessDialog::Close();
94 IMPL_LINK_NOARG( SearchResultsDlg
, ListSelectHdl
)
99 SvTreeListEntry
*pEntry
= mpList
->FirstSelected();
100 OUString aTabStr
= SvTabListBox::GetEntryText(pEntry
, 0);
101 OUString aPosStr
= SvTabListBox::GetEntryText(pEntry
, 1);
104 if (!mpDoc
->GetTable(aTabStr
, nTab
))
105 // No sheet with specified name.
109 sal_uInt16 nRes
= aPos
.Parse(aPosStr
, mpDoc
, mpDoc
->GetAddressConvention());
110 if (!(nRes
& SCA_VALID
))
111 // Invalid address string.
115 ScTabViewShell
* pScViewShell
= ScTabViewShell::GetActiveViewShell();
116 pScViewShell
->SetTabNo(nTab
);
117 pScViewShell
->SetCursor(aPos
.Col(), aPos
.Row());
118 pScViewShell
->AlignToCursor(aPos
.Col(), aPos
.Row(), SC_FOLLOW_JUMP
);
123 SearchResultsDlgWrapper::SearchResultsDlgWrapper(
124 vcl::Window
* _pParent
, sal_uInt16 nId
, SfxBindings
* pBindings
, SfxChildWinInfo
* /*pInfo*/ ) :
125 SfxChildWindow(_pParent
, nId
)
127 pWindow
= VclPtr
<SearchResultsDlg
>::Create(pBindings
, _pParent
, nId
);
130 SearchResultsDlgWrapper::~SearchResultsDlgWrapper() {}
132 SfxChildWinInfo
SearchResultsDlgWrapper::GetInfo() const
134 SfxChildWinInfo aInfo
= SfxChildWindow::GetInfo();
135 aInfo
.bVisible
= false;
139 SFX_IMPL_CHILDWINDOW_WITHID(SearchResultsDlgWrapper
, SID_SEARCH_RESULTS_DIALOG
);
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */