summaryrefslogtreecommitdiff
path: root/sc/source/ui/view
diff options
context:
space:
mode:
authorGrigory A. Mozhaev <zcrendel@gmail.com>2023-02-27 16:03:39 +0300
committerHeiko Tietze <heiko.tietze@documentfoundation.org>2023-03-08 10:51:42 +0000
commit3fcf9f864f9d12fdb0ade4741127c81cec74378a (patch)
treef61b2806640b59e333082053e845c6723486f398 /sc/source/ui/view
parente624e07cc54c408bb86bd2e52cfed3c7ec59fb4a (diff)
tdf#97551 Added marker and hint for formula to Calc
Added option "Formula indicator and hint" to LibreOffice Calc > View section (near to "Comment indicator"). This option turned off by default to avoid interfere existing UX. Indicator displays in the bottom-left corner as blue triangle marker if cells contains formula (correctly reacts on cells merging and different sizing). Hint displays when user hover cursor over the cell that contains the formula (uses already built-in mechanics for help tooltip). More details about request and discussion of the feature in Bugzilla. Change-Id: I8f3e368d4fdad362b819b4ce2fd6b0c32b5c1c0f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147914 Tested-by: Jenkins Tested-by: Heiko Tietze <heiko.tietze@documentfoundation.org> Reviewed-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
Diffstat (limited to 'sc/source/ui/view')
-rw-r--r--sc/source/ui/view/gridwin4.cxx3
-rw-r--r--sc/source/ui/view/gridwin5.cxx25
-rw-r--r--sc/source/ui/view/output.cxx72
-rw-r--r--sc/source/ui/view/viewdata.cxx4
4 files changed, 104 insertions, 0 deletions
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index c30052237646..d3d21f049e55 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -927,6 +927,9 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, const ScTableInfo& rTableI
if ( rOpts.GetOption( VOPT_NOTES ) )
aOutputData.DrawNoteMarks(*pContentDev);
+ if ( rOpts.GetOption( VOPT_FORMULAS_MARKS ) )
+ aOutputData.DrawFormulaMarks(*pContentDev);
+
if ( !bLogicText )
aOutputData.DrawStrings(); // in pixel MapMode
diff --git a/sc/source/ui/view/gridwin5.cxx b/sc/source/ui/view/gridwin5.cxx
index ff26f2e5709f..22ee3726b124 100644
--- a/sc/source/ui/view/gridwin5.cxx
+++ b/sc/source/ui/view/gridwin5.cxx
@@ -204,6 +204,8 @@ bool ScGridWindow::ShowNoteMarker( SCCOL nPosX, SCROW nPosY, bool bKeyboard )
void ScGridWindow::RequestHelp(const HelpEvent& rHEvt)
{
bool bDone = false;
+ OUString aFormulaText;
+ tools::Rectangle aFormulaPixRect;
bool bHelpEnabled = bool(rHEvt.GetMode() & ( HelpEventMode::BALLOON | HelpEventMode::QUICK ));
SdrView* pDrView = mrViewData.GetScDrawView();
bool bDrawTextEdit = false;
@@ -215,6 +217,9 @@ void ScGridWindow::RequestHelp(const HelpEvent& rHEvt)
Point aPosPixel = ScreenToOutputPixel( rHEvt.GetMousePosPixel() );
SCCOL nPosX;
SCROW nPosY;
+ ScDocument& rDoc = mrViewData.GetDocument();
+ SCTAB nTab = mrViewData.GetTabNo();
+ const ScViewOptions& rOpts = mrViewData.GetOptions();
mrViewData.GetPosFromPixel( aPosPixel.X(), aPosPixel.Y(), eWhich, nPosX, nPosY );
if ( ShowNoteMarker( nPosX, nPosY, false ) )
@@ -222,6 +227,15 @@ void ScGridWindow::RequestHelp(const HelpEvent& rHEvt)
Window::RequestHelp( rHEvt ); // turn off old Tip/Balloon
bDone = true;
}
+
+ if ( rOpts.GetOption( VOPT_FORMULAS_MARKS ) )
+ {
+ aFormulaText = rDoc.GetFormula( nPosX, nPosY, nTab );
+ if ( !aFormulaText.isEmpty() ) {
+ const ScPatternAttr* pPattern = rDoc.GetPattern( nPosX, nPosY, nTab );
+ aFormulaPixRect = mrViewData.GetEditArea( eWhich, nPosX, nPosY, this, pPattern, true );
+ }
+ }
}
if (!bDone && mpNoteMarker)
@@ -236,6 +250,17 @@ void ScGridWindow::RequestHelp(const HelpEvent& rHEvt)
}
}
+ if ( !aFormulaText.isEmpty() )
+ {
+ tools::Rectangle aScreenRect(OutputToScreenPixel(aFormulaPixRect.TopLeft()),
+ OutputToScreenPixel(aFormulaPixRect.BottomRight()));
+ if ( rHEvt.GetMode() & HelpEventMode::BALLOON )
+ Help::ShowBalloon(this, rHEvt.GetMousePosPixel(), aScreenRect, aFormulaText);
+ else if ( rHEvt.GetMode() & HelpEventMode::QUICK )
+ Help::ShowQuickHelp(this, aScreenRect, aFormulaText);
+ bDone = true;
+ }
+
// Image-Map / Text-URL
if ( bHelpEnabled && !bDone && !nButtonDown ) // only without pressed button
diff --git a/sc/source/ui/view/output.cxx b/sc/source/ui/view/output.cxx
index 9b7ba7ea66ed..14227020e70f 100644
--- a/sc/source/ui/view/output.cxx
+++ b/sc/source/ui/view/output.cxx
@@ -2454,6 +2454,78 @@ void ScOutputData::DrawNoteMarks(vcl::RenderContext& rRenderContext)
}
}
+void ScOutputData::DrawFormulaMarks(vcl::RenderContext& rRenderContext)
+{
+ bool bFirst = true;
+
+ tools::Long nInitPosX = nScrX;
+ if ( bLayoutRTL )
+ nInitPosX += nMirrorW - 1; // always in pixels
+ tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;
+
+ tools::Long nPosY = nScrY;
+ for (SCSIZE nArrY=1; nArrY+1<nArrCount; nArrY++)
+ {
+ RowInfo* pThisRowInfo = &pRowInfo[nArrY];
+ if ( pThisRowInfo->bChanged )
+ {
+ tools::Long nPosX = nInitPosX;
+ for (SCCOL nX=nX1; nX<=nX2; nX++)
+ {
+ ScCellInfo* pInfo = &pThisRowInfo->cellInfo(nX);
+ if (!mpDoc->ColHidden(nX, nTab) && !mpDoc->GetFormula(nX, pRowInfo[nArrY].nRowNo, nTab).isEmpty()
+ && (!pInfo->bHOverlapped && !pInfo->bVOverlapped))
+ {
+ if (bFirst)
+ {
+ rRenderContext.SetLineColor(COL_WHITE);
+
+ const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
+ if ( mbUseStyleColor && rStyleSettings.GetHighContrastMode() )
+ rRenderContext.SetFillColor( SC_MOD()->GetColorConfig().GetColorValue(svtools::FONTCOLOR).nColor );
+ else
+ rRenderContext.SetFillColor(COL_LIGHTBLUE);
+
+ bFirst = false;
+ }
+
+ tools::Long nMarkX = nPosX;
+ tools::Long nMarkY = nPosY + pThisRowInfo->nHeight - 2;
+ if ( pInfo->bMerged )
+ {
+ for (SCSIZE nNextY=nArrY+1; nNextY+1<nArrCount; nNextY++)
+ {
+ bool bVOver;
+ if (pRowInfo[nNextY + 1].nRowNo == (pRowInfo[nNextY].nRowNo + 1)) {
+ bVOver = pRowInfo[nNextY].cellInfo(nX).bVOverlapped;
+ } else {
+ bVOver = mpDoc->GetAttr(nX,nNextY,nTab,ATTR_MERGE_FLAG)->IsVerOverlapped();
+ }
+ if (!bVOver) break;
+ nMarkY += pRowInfo[nNextY].nHeight;
+ }
+ }
+ // DPI/ZOOM 100/100 => 10, 100/50 => 7, 100/150 => 13
+ // DPI/ZOOM 150/100 => 13, 150/50 => 8.5, 150/150 => 17.5
+ const double nSize( rRenderContext.GetDPIScaleFactor() * aZoomX * 6 + 4);
+ Point aPoints[3];
+ aPoints[0] = Point(nMarkX, nMarkY);
+ aPoints[0].setX( bLayoutRTL ? aPoints[0].X() - nSize : aPoints[0].X() + nSize );
+ aPoints[1] = Point(nMarkX, nMarkY);
+ aPoints[2] = Point(nMarkX, nMarkY - nSize);
+ tools::Polygon aPoly(3, aPoints);
+
+ if ( bLayoutRTL ? ( nMarkX >= 0 ) : ( nMarkX < nScrX+nScrW ) )
+ rRenderContext.DrawPolygon(aPoly);
+ }
+
+ nPosX += pRowInfo[0].basicCellInfo(nX).nWidth * nLayoutSign;
+ }
+ }
+ nPosY += pThisRowInfo->nHeight;
+ }
+}
+
void ScOutputData::AddPDFNotes()
{
vcl::PDFExtOutDevData* pPDFData = dynamic_cast< vcl::PDFExtOutDevData* >( mpDev->GetExtOutDevData() );
diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx
index 61d62a8cccd8..e236256ce35d 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -3757,6 +3757,8 @@ void ScViewData::WriteUserDataSequence(uno::Sequence <beans::PropertyValue>& rSe
pSettings[SC_SHOWZERO].Value <<= maOptions.GetOption(VOPT_NULLVALS);
pSettings[SC_SHOWNOTES].Name = SC_UNO_SHOWNOTES;
pSettings[SC_SHOWNOTES].Value <<= maOptions.GetOption(VOPT_NOTES);
+ pSettings[SC_SHOWFORMULASMARKS].Name = SC_UNO_SHOWFORMULASMARKS;
+ pSettings[SC_SHOWFORMULASMARKS].Value <<= maOptions.GetOption(VOPT_FORMULAS_MARKS);
pSettings[SC_SHOWGRID].Name = SC_UNO_SHOWGRID;
pSettings[SC_SHOWGRID].Value <<= maOptions.GetOption(VOPT_GRID);
pSettings[SC_GRIDCOLOR].Name = SC_UNO_GRIDCOLOR;
@@ -3901,6 +3903,8 @@ void ScViewData::ReadUserDataSequence(const uno::Sequence <beans::PropertyValue>
maOptions.SetOption(VOPT_NULLVALS, ScUnoHelpFunctions::GetBoolFromAny(rSetting.Value));
else if ( sName == SC_UNO_SHOWNOTES )
maOptions.SetOption(VOPT_NOTES, ScUnoHelpFunctions::GetBoolFromAny(rSetting.Value));
+ else if ( sName == SC_UNO_SHOWFORMULASMARKS )
+ maOptions.SetOption(VOPT_FORMULAS_MARKS, ScUnoHelpFunctions::GetBoolFromAny(rSetting.Value));
else if ( sName == SC_UNO_SHOWGRID )
maOptions.SetOption(VOPT_GRID, ScUnoHelpFunctions::GetBoolFromAny(rSetting.Value));
else if ( sName == SC_UNO_GRIDCOLOR )