summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Francis <dennis.francis@collabora.com>2020-05-25 17:55:19 +0530
committerDennis Francis <dennis.francis@collabora.com>2020-05-26 22:08:55 +0530
commit11f4a63732602db6c8feb03b5252b3d99fa331ea (patch)
tree5aa700c9253783686c68d91e3b99d924e71e291f
parente7546301e8569847b9236bd859792079e97e0c50 (diff)
lokit: scPrintTwipsMsgs: LOK_CALLBACK_*SELECTION*
Allow print twips coordinates in the below messages: LOK_CALLBACK_CELL_SELECTION_AREA LOK_CALLBACK_TEXT_SELECTION LOK_CALLBACK_TEXT_VIEW_SELECTION Change-Id: I267a636bbeab434b305a45abe3e21cb5afc4c1e9
-rw-r--r--sc/source/ui/inc/gridwin.hxx3
-rw-r--r--sc/source/ui/view/gridwin.cxx74
-rw-r--r--sc/source/ui/view/gridwin4.cxx34
3 files changed, 87 insertions, 24 deletions
diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx
index 5f0844a1547f..96fb7e632775 100644
--- a/sc/source/ui/inc/gridwin.hxx
+++ b/sc/source/ui/inc/gridwin.hxx
@@ -298,8 +298,11 @@ class SAL_DLLPUBLIC_RTTI ScGridWindow : public vcl::Window, public DropTargetHel
void SelectForContextMenu( const Point& rPosPixel, SCCOL nCellX, SCROW nCellY );
void GetSelectionRects( ::std::vector< tools::Rectangle >& rPixelRects ) const;
+ void GetSelectionRectsPrintTwips(::std::vector< tools::Rectangle >& rRects) const;
void GetPixelRectsFor( const ScMarkData &rMarkData,
::std::vector< tools::Rectangle >& rPixelRects ) const;
+ void GetRectsAnyFor(const ScMarkData &rMarkData,
+ ::std::vector< tools::Rectangle >& rRects, bool bInPrintTwips) const;
void UpdateKitSelection(const std::vector<tools::Rectangle>& rRectangles,
std::vector<tools::Rectangle>* pLogicRects = nullptr);
bool NeedLOKCursorInvalidation(const tools::Rectangle& rCursorRect,
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 405dd5e7de1a..7947045b3854 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -5990,13 +5990,24 @@ void ScGridWindow::UpdateKitSelection(const std::vector<tools::Rectangle>& rRect
if (!comphelper::LibreOfficeKit::isActive())
return;
+ // If this is true, rRectangles should already in print twips.
+ // If false, rRectangles are in pixels.
+ bool bInPrintTwips = comphelper::LibreOfficeKit::isCompatFlagSet(
+ comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs);
+
tools::Rectangle aBoundingBox;
- std::vector<tools::Rectangle> aLogicRects;
+ std::vector<tools::Rectangle> aConvertedRects;
- aLogicRects = convertPixelToLogical(pViewData, rRectangles, aBoundingBox);
+ if (bInPrintTwips)
+ std::for_each(rRectangles.begin(), rRectangles.end(),
+ [&aBoundingBox](const tools::Rectangle& rRect) { aBoundingBox.Union(rRect); });
+ else
+ aConvertedRects = convertPixelToLogical(pViewData, rRectangles, aBoundingBox);
+
+ const std::vector<tools::Rectangle>& rLogicRects = bInPrintTwips ? rRectangles : aConvertedRects;
if (pLogicRects)
{
- *pLogicRects = aLogicRects;
+ *pLogicRects = rLogicRects;
return;
}
@@ -6004,8 +6015,16 @@ void ScGridWindow::UpdateKitSelection(const std::vector<tools::Rectangle>& rRect
OString sBoundingBoxString = "EMPTY";
if (!aBoundingBox.IsEmpty())
sBoundingBoxString = aBoundingBox.toString();
+ OString aRectListString = rectanglesToString(rLogicRects);
pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CELL_SELECTION_AREA, sBoundingBoxString.getStr());
- pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, rectanglesToString(aLogicRects).getStr());
+ pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, aRectListString.getStr());
+
+ if (bInPrintTwips)
+ {
+ SfxLokHelper::notifyOtherViews(pViewShell, LOK_CALLBACK_TEXT_VIEW_SELECTION,
+ "selection", aRectListString);
+ return;
+ }
for (SfxViewShell* it = SfxViewShell::GetFirst(); it;
it = SfxViewShell::GetNext(*it))
@@ -6037,6 +6056,8 @@ void ScGridWindow::UpdateKitSelection(const std::vector<tools::Rectangle>& rRect
void ScGridWindow::updateOtherKitSelections() const
{
ScTabViewShell* pViewShell = pViewData->GetViewShell();
+ bool bInPrintTwips = comphelper::LibreOfficeKit::isCompatFlagSet(
+ comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs);
for (SfxViewShell* it = SfxViewShell::GetFirst(); it;
it = SfxViewShell::GetNext(*it))
@@ -6048,10 +6069,19 @@ void ScGridWindow::updateOtherKitSelections() const
// Fetch pixels & convert for each view separately.
tools::Rectangle aBoundingBox;
- std::vector<tools::Rectangle> aPixelRects;
- GetPixelRectsFor(pOther->GetViewData().GetMarkData() /* theirs */, aPixelRects);
- auto aOtherLogicRects = convertPixelToLogical(&pViewShell->GetViewData(), aPixelRects, aBoundingBox);
- OString aRectsString = rectanglesToString(aOtherLogicRects);
+ std::vector<tools::Rectangle> aRects;
+ OString aRectsString;
+ GetRectsAnyFor(pOther->GetViewData().GetMarkData() /* theirs */, aRects, bInPrintTwips);
+ if (bInPrintTwips)
+ {
+ std::for_each(aRects.begin(), aRects.end(),
+ [&aBoundingBox](const tools::Rectangle& rRect) { aBoundingBox.Union(rRect); });
+ aRectsString = rectanglesToString(aRects);
+ }
+ else
+ aRectsString = rectanglesToString(
+ convertPixelToLogical(&pViewShell->GetViewData(), aRects, aBoundingBox));
+
if (it == pViewShell)
{
OString sBoundingBoxString = "EMPTY";
@@ -6063,7 +6093,7 @@ void ScGridWindow::updateOtherKitSelections() const
}
else
SfxLokHelper::notifyOtherView(it, pViewShell, LOK_CALLBACK_TEXT_VIEW_SELECTION,
- "selection", aRectsString.getStr());
+ "selection", aRectsString);
}
}
@@ -6261,9 +6291,14 @@ void ScGridWindow::UpdateCursorOverlay()
void ScGridWindow::GetCellSelection(std::vector<tools::Rectangle>& rLogicRects)
{
- std::vector<tools::Rectangle> aPixelRects;
- GetSelectionRects(aPixelRects);
- UpdateKitSelection(aPixelRects, &rLogicRects);
+ std::vector<tools::Rectangle> aRects;
+ if (comphelper::LibreOfficeKit::isActive() &&
+ comphelper::LibreOfficeKit::isCompatFlagSet(
+ comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs))
+ GetSelectionRectsPrintTwips(aRects);
+ else
+ GetSelectionRects(aRects);
+ UpdateKitSelection(aRects, &rLogicRects);
}
void ScGridWindow::DeleteSelectionOverlay()
@@ -6279,17 +6314,22 @@ void ScGridWindow::UpdateSelectionOverlay()
SetMapMode( aDrawMode );
DeleteSelectionOverlay();
- std::vector<tools::Rectangle> aPixelRects;
- GetSelectionRects( aPixelRects );
+ std::vector<tools::Rectangle> aRects;
+ if (comphelper::LibreOfficeKit::isActive() &&
+ comphelper::LibreOfficeKit::isCompatFlagSet(
+ comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs))
+ GetSelectionRectsPrintTwips(aRects);
+ else
+ GetSelectionRects(aRects);
- if (!aPixelRects.empty() && pViewData->IsActive())
+ if (!aRects.empty() && pViewData->IsActive())
{
// #i70788# get the OverlayManager safely
rtl::Reference<sdr::overlay::OverlayManager> xOverlayManager = getOverlayManager();
if (comphelper::LibreOfficeKit::isActive())
{
// notify the LibreOfficeKit too
- UpdateKitSelection(aPixelRects);
+ UpdateKitSelection(aRects);
}
else if (xOverlayManager.is())
{
@@ -6299,7 +6339,7 @@ void ScGridWindow::UpdateSelectionOverlay()
SCTAB nTab = pViewData->GetTabNo();
bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
- for(const tools::Rectangle & rRA : aPixelRects)
+ for(const tools::Rectangle & rRA : aRects)
{
if (bLayoutRTL)
{
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 8c60a5c9efc3..7cb3975db80b 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -1903,10 +1903,22 @@ void ScGridWindow::GetSelectionRects( ::std::vector< tools::Rectangle >& rPixelR
GetPixelRectsFor( pViewData->GetMarkData(), rPixelRects );
}
+void ScGridWindow::GetSelectionRectsPrintTwips(::std::vector< tools::Rectangle >& rRects) const
+{
+ GetRectsAnyFor(pViewData->GetMarkData(), rRects, true);
+}
+
/// convert rMarkData into pixel rectangles for this view
void ScGridWindow::GetPixelRectsFor( const ScMarkData &rMarkData,
::std::vector< tools::Rectangle >& rPixelRects ) const
{
+ GetRectsAnyFor(rMarkData, rPixelRects, false);
+}
+
+void ScGridWindow::GetRectsAnyFor(const ScMarkData &rMarkData,
+ ::std::vector< tools::Rectangle >& rRects,
+ bool bInPrintTwips) const
+{
ScMarkData aMultiMark( rMarkData );
aMultiMark.SetMarking( false );
aMultiMark.MarkToMulti();
@@ -1978,9 +1990,10 @@ void ScGridWindow::GetPixelRectsFor( const ScMarkData &rMarkData,
double nPPTX = pViewData->GetPPTX();
double nPPTY = pViewData->GetPPTY();
- ScInvertMerger aInvert( &rPixelRects );
+ ScInvertMerger aInvert( &rRects );
- Point aScrPos = pViewData->GetScrPos( nX1, nY1, eWhich );
+ Point aScrPos = bInPrintTwips ? pViewData->GetPrintTwipsPos(nX1, nY1) :
+ pViewData->GetScrPos(nX1, nY1, eWhich);
long nScrY = aScrPos.Y();
bool bWasHidden = false;
for (SCROW nY=nY1; nY<=nY2; nY++)
@@ -2018,11 +2031,16 @@ void ScGridWindow::GetPixelRectsFor( const ScMarkData &rMarkData,
nLoopEndX = nX1;
}
- long nEndY = nScrY + ScViewData::ToPixel( nHeightTwips, nPPTY ) - 1;
+ const long nHeight = bInPrintTwips ?
+ nHeightTwips : ScViewData::ToPixel(nHeightTwips, nPPTY);
+ long nEndY = nScrY + nHeight - 1;
long nScrX = aScrPos.X();
for (SCCOL nX=nX1; nX<=nLoopEndX; nX++)
{
- long nWidth = ScViewData::ToPixel( pDoc->GetColWidth( nX,nTab ), nPPTX );
+ long nWidth = pDoc->GetColWidth(nX, nTab);
+ if (!bInPrintTwips)
+ nWidth = ScViewData::ToPixel(nWidth, nPPTX);
+
if ( nWidth > 0 )
{
long nEndX = nScrX + ( nWidth - 1 ) * nLayoutSign;
@@ -2060,9 +2078,11 @@ void ScGridWindow::GetPixelRectsFor( const ScMarkData &rMarkData,
const ScMergeAttr* pMerge = &pPattern->GetItem(ATTR_MERGE);
if (pMerge->GetColMerge() > 0 || pMerge->GetRowMerge() > 0)
{
- Point aEndPos = pViewData->GetScrPos(
- nThisX + pMerge->GetColMerge(),
- nThisY + pMerge->GetRowMerge(), eWhich );
+ const SCCOL nEndColMerge = nThisX + pMerge->GetColMerge();
+ const SCROW nEndRowMerge = nThisY + pMerge->GetRowMerge();
+ Point aEndPos = bInPrintTwips ?
+ pViewData->GetPrintTwipsPos(nEndColMerge, nEndRowMerge) :
+ pViewData->GetScrPos(nEndColMerge, nEndRowMerge, eWhich);
if ( aEndPos.X() * nLayoutSign > nScrX * nLayoutSign && aEndPos.Y() > nScrY )
{
aInvert.AddRect( tools::Rectangle( nScrX,nScrY,