/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. *
*/
namespace
{ void getAnchorPos(SwPosition& rPos)
{ // get the top most anchor position of the position if (SwFrameFormat* pFlyFormat = rPos.GetNode().GetFlyFormat())
{
SwNode* pAnchorNode;
SwFrameFormat* pTmp = pFlyFormat; while (pTmp && (pAnchorNode = pTmp->GetAnchor().GetAnchorNode())
&& (pTmp = pAnchorNode->GetFlyFormat()))
{
pFlyFormat = pTmp;
} if (const SwPosition* pPos = pFlyFormat->GetAnchor().GetContentAnchor())
rPos = *pPos;
}
}
}
// tdf#162580 related: When upgrading from Find toolbar search to advanced Find and Replace // search dialog, inherit (pre-fill) search field's term from current value of find bar's // focused search entry
IMPL_LINK(QuickFindPanel, FindAndReplaceToolbarClickedHandler, const OUString&, rCommand, void)
{ if (!SwView::GetSearchDialog())
{
SvxSearchItem* pSearchItem = SwView::GetSearchItem(); if (!pSearchItem)
{
pSearchItem = new SvxSearchItem(SID_SEARCH_ITEM);
SwView::SetSearchItem(pSearchItem);
}
pSearchItem->SetSearchString(m_xSearchFindEntry->get_text());
}
m_xFindAndReplaceToolbarDispatch->Select(rCommand);
}
OUString aEntry(rId); if (!bPageEntry)
{ int nIndex = m_xSearchFindsList->find_id(rId);
aEntry = m_xSearchFindsList->get_text(nIndex);
}
// To not have top and bottom clipping when the sidebar width is made smaller by the user // calculate the text rectangle using the minimum width the rectangle can become. int x, y, width, height;
m_xSearchFindsList->get_extents_relative_to(*m_xContainer, x, y, width, height);
if (!bPageEntry)
{
aRect.AdjustTop(+3);
aRect.AdjustBottom(-3);
}
// adjust for scrollbar when not using gtk if (m_pWrtShell->GetWin()->GetSystemData()->toolkit != SystemEnvData::Toolkit::Gtk)
{
tools::Long nScrollBarThickness
= Application::GetSettings().GetStyleSettings().GetScrollBarSize();
aRect.AdjustRight(-nScrollBarThickness);
}
if (!bPageEntry)
{
aRect.AdjustRight(-3);
rRenderContext.DrawRect(aRect, 6, 6);
// tdf#163100 Need more FIND details // Set the found times label to show "Match X of N matches found." auto nSearchFindFoundTimes = m_vPaMs.size();
OUString sText = SwResId(STR_SEARCH_KEY_FOUND_XOFN, nSearchFindFoundTimes);
sText = sText.replaceFirst("%1", OUString::number(sId.toUInt32() + 1));
sText = sText.replaceFirst("%2", OUString::number(nSearchFindFoundTimes));
m_xSearchFindFoundTimesLabel->set_label(sText);
// tdf#160538 sort finds in frames and footnotes in the order they occur in the document const SwNodeOffset nEndOfInsertsIndex
= m_pWrtShell->GetNodes().GetEndOfInserts().GetIndex(); const SwNodeOffset nEndOfExtrasIndex = m_pWrtShell->GetNodes().GetEndOfExtras().GetIndex();
std::stable_sort(m_vPaMs.begin(), m_vPaMs.end(),
[&nEndOfInsertsIndex, &nEndOfExtrasIndex, this](const std::unique_ptr<SwPaM>& a, const std::unique_ptr<SwPaM>& b) {
SwPosition aPos(*a->Start());
SwPosition bPos(*b->Start()); // use page number for footnotes and endnotes if (aPos.GetNodeIndex() >= nEndOfInsertsIndex
&& bPos.GetNodeIndex() < nEndOfInsertsIndex) return b->GetPageNum() >= a->GetPageNum(); // use anchor position for finds that are located in flys if (nEndOfExtrasIndex >= aPos.GetNodeIndex())
getAnchorPos(aPos); if (nEndOfExtrasIndex >= bPos.GetNodeIndex())
getAnchorPos(bPos); if (aPos == bPos)
{ // probably in same or nested fly frame // sort using layout position
SwRect aCharRect, bCharRect; if (SwContentFrame* pFrame
= a->GetMarkContentNode()->GetTextNode()->getLayoutFrame(
m_pWrtShell->GetLayout()))
{
pFrame->GetCharRect(aCharRect, *a->GetMark());
} if (SwContentFrame* pFrame
= b->GetMarkContentNode()->GetTextNode()->getLayoutFrame(
m_pWrtShell->GetLayout()))
{
pFrame->GetCharRect(bCharRect, *b->GetMark());
} return aCharRect.Top() < bCharRect.Top();
} return aPos < bPos;
});
// fill list for (sal_uInt16 nPage = 0, i = 0; std::unique_ptr<SwPaM> & xPaM : m_vPaMs)
{
SwPosition* pMarkPosition = xPaM->GetMark();
SwPosition* pPointPosition = xPaM->GetPoint();
auto nMarkIndex = pMarkPosition->GetContentIndex(); auto nPointIndex = pPointPosition->GetContentIndex();
// determine the text node text subview start index for the list entry text auto nStartIndex = nMarkIndex - CharactersBeforeAndAfter; if (nStartIndex < 0)
{
nStartIndex = 0;
} else
{ // tdf#160539 format search finds results also to word boundaries
sal_Unicode ch; do
{
ch = sNodeText[nStartIndex];
} while (++nStartIndex < nMarkIndex && ch != ' ' && ch != '\t'); if (nStartIndex < nMarkIndex)
{ // move past neighboring space and tab characters
ch = sNodeText[nStartIndex]; while (nStartIndex < nMarkIndex && (ch == ' ' || ch == '\t'))
ch = sNodeText[++nStartIndex];
} if (nStartIndex == nMarkIndex) // no white space found
nStartIndex = nMarkIndex - CharactersBeforeAndAfter;
}
// determine the text node text subview end index for the list entry text auto nEndIndex = nPointIndex + CharactersBeforeAndAfter; if (nEndIndex >= sNodeText.getLength())
{
nEndIndex = sNodeText.getLength() - 1;
} else
{ // tdf#160539 format search finds results also to word boundaries
sal_Unicode ch; do
{
ch = sNodeText[nEndIndex];
} while (--nEndIndex > nPointIndex && ch != ' ' && ch != '\t'); if (nEndIndex > nPointIndex)
{ // move past neighboring space and tab characters
ch = sNodeText[nEndIndex]; while (nEndIndex > nPointIndex && (ch == ' ' || ch == '\t'))
ch = sNodeText[--nEndIndex];
} if (nEndIndex == nPointIndex) // no white space found
{
nEndIndex = nPointIndex + CharactersBeforeAndAfter; if (nEndIndex >= sNodeText.getLength())
nEndIndex = sNodeText.getLength() - 1;
}
}
// Any finds? auto nSearchFindFoundTimes = m_vPaMs.size();
// set the search term entry background
m_xSearchFindEntry->set_message_type(nSearchFindFoundTimes ? weld::EntryMessageType::Normal
: weld::EntryMessageType::Error); // make the search finds list focusable or not
m_xSearchFindsList->set_sensitive(bool(nSearchFindFoundTimes));
// set the search term found label number of times found
OUString sText(SwResId(STR_SEARCH_KEY_FOUND_TIMES, nSearchFindFoundTimes));
sText = sText.replaceFirst("%1", OUString::number(nSearchFindFoundTimes));
m_xSearchFindFoundTimesLabel->set_label(sText);
}
} // end of namespace ::sw::sidebar /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.