LibreOffice Module sc (master)  1
gridwin5.cxx
Go to the documentation of this file.
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  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <editeng/flditem.hxx>
21 
22 #include <svx/fmpage.hxx>
23 #include <svx/svdobj.hxx>
24 #include <svx/svdpagv.hxx>
25 #include <svx/ImageMapInfo.hxx>
26 #include <vcl/imapobj.hxx>
27 #include <vcl/help.hxx>
28 #include <tools/urlobj.hxx>
29 #include <sfx2/sfxhelp.hxx>
30 
31 #include <AccessibleDocument.hxx>
32 #include <com/sun/star/accessibility/XAccessible.hpp>
33 
34 #include <gridwin.hxx>
35 #include <viewdata.hxx>
36 #include <drawview.hxx>
37 #include <drwlayer.hxx>
38 #include <document.hxx>
39 #include <notemark.hxx>
40 #include <chgtrack.hxx>
41 #include <chgviset.hxx>
42 #include <dbfunc.hxx>
43 #include <postit.hxx>
44 #include <global.hxx>
45 
46 bool ScGridWindow::ShowNoteMarker( SCCOL nPosX, SCROW nPosY, bool bKeyboard )
47 {
48  bool bDone = false;
49 
51  SCTAB nTab = mrViewData.GetTabNo();
52  ScAddress aCellPos( nPosX, nPosY, nTab );
53 
54  OUString aTrackText;
55  bool bLeftEdge = false;
56 
57  // change tracking
58 
59  ScChangeTrack* pTrack = rDoc.GetChangeTrack();
60  ScChangeViewSettings* pSettings = rDoc.GetChangeViewSettings();
61  if ( pTrack && pTrack->GetFirst() && pSettings && pSettings->ShowChanges())
62  {
63  const ScChangeAction* pFound = nullptr;
64  const ScChangeAction* pFoundContent = nullptr;
65  const ScChangeAction* pFoundMove = nullptr;
66  const ScChangeAction* pAction = pTrack->GetFirst();
67  while (pAction)
68  {
69  if ( pAction->IsVisible() &&
70  ScViewUtil::IsActionShown( *pAction, *pSettings, rDoc ) )
71  {
72  ScChangeActionType eType = pAction->GetType();
73  const ScBigRange& rBig = pAction->GetBigRange();
74  if ( rBig.aStart.Tab() == nTab )
75  {
76  ScRange aRange = rBig.MakeRange( rDoc );
77 
78  if ( eType == SC_CAT_DELETE_ROWS )
79  aRange.aEnd.SetRow( aRange.aStart.Row() );
80  else if ( eType == SC_CAT_DELETE_COLS )
81  aRange.aEnd.SetCol( aRange.aStart.Col() );
82 
83  if ( aRange.Contains( aCellPos ) )
84  {
85  pFound = pAction; // the last one wins
86  switch ( eType )
87  {
88  case SC_CAT_CONTENT :
89  pFoundContent = pAction;
90  break;
91  case SC_CAT_MOVE :
92  pFoundMove = pAction;
93  break;
94  default:
95  {
96  // added to avoid warnings
97  }
98  }
99  }
100  }
101  if ( eType == SC_CAT_MOVE )
102  {
103  ScRange aRange =
104  static_cast<const ScChangeActionMove*>(pAction)->
105  GetFromRange().MakeRange( rDoc );
106  if ( aRange.Contains( aCellPos ) )
107  {
108  pFound = pAction;
109  }
110  }
111  }
112  pAction = pAction->GetNext();
113  }
114 
115  if ( pFound )
116  {
117  if ( pFoundContent && pFound->GetType() != SC_CAT_CONTENT )
118  pFound = pFoundContent; // content wins
119  if ( pFoundMove && pFound->GetType() != SC_CAT_MOVE &&
120  pFoundMove->GetActionNumber() >
121  pFound->GetActionNumber() )
122  pFound = pFoundMove; // move wins
123 
124  // for deleted columns: Arrow on the left side of the cell
125  if ( pFound->GetType() == SC_CAT_DELETE_COLS )
126  bLeftEdge = true;
127 
128  DateTime aDT = pFound->GetDateTime();
129  aTrackText = pFound->GetUser()
130  + ", "
132  + " "
134  + ":\n";
135  OUString aComStr=pFound->GetComment();
136  if(!aComStr.isEmpty())
137  {
138  aTrackText += aComStr + "\n( ";
139  }
140  OUString aTmp = pFound->GetDescription(rDoc);
141  aTrackText += aTmp;
142  if(!aComStr.isEmpty())
143  {
144  aTrackText += ")";
145  }
146  }
147  }
148 
149  // Note, only if it is not already displayed on the Drawing Layer:
150  const ScPostIt* pNote = rDoc.GetNote( aCellPos );
151  if ( (!aTrackText.isEmpty()) || (pNote && !pNote->IsCaptionShown()) )
152  {
153  bool bNew = true;
154  bool bFast = false;
155  if (mpNoteMarker) // A note already shown
156  {
157  if (mpNoteMarker->GetDocPos() == aCellPos)
158  bNew = false; // then stop
159  else
160  bFast = true; // otherwise, at once
161 
162  // marker which was shown for ctrl-F1 isn't removed by mouse events
163  if (mpNoteMarker->IsByKeyboard() && !bKeyboard)
164  bNew = false;
165  }
166  if (bNew)
167  {
168  if (bKeyboard)
169  bFast = true; // keyboard also shows the marker immediately
170 
171  mpNoteMarker.reset();
172 
173  bool bHSplit = mrViewData.GetHSplitMode() != SC_SPLIT_NONE;
174  bool bVSplit = mrViewData.GetVSplitMode() != SC_SPLIT_NONE;
175 
177  vcl::Window* pRight = bHSplit ? mrViewData.GetView()->GetWindowByPos( bVSplit ? SC_SPLIT_TOPRIGHT : SC_SPLIT_BOTTOMRIGHT ) : nullptr;
178  vcl::Window* pBottom = bVSplit ? mrViewData.GetView()->GetWindowByPos( SC_SPLIT_BOTTOMLEFT ) : nullptr;
179  vcl::Window* pDiagonal = (bHSplit && bVSplit) ? mrViewData.GetView()->GetWindowByPos( SC_SPLIT_BOTTOMRIGHT ) : nullptr;
180  OSL_ENSURE( pLeft, "ScGridWindow::ShowNoteMarker - missing top-left grid window" );
181 
182  /* If caption is shown from right or bottom windows, adjust
183  mapmode to include size of top-left window. */
184  MapMode aMapMode = GetDrawMapMode( true );
185  Size aLeftSize = pLeft->PixelToLogic( pLeft->GetOutputSizePixel(), aMapMode );
186  Point aOrigin = aMapMode.GetOrigin();
187  if( (this == pRight) || (this == pDiagonal) )
188  aOrigin.AdjustX(aLeftSize.Width() );
189  if( (this == pBottom) || (this == pDiagonal) )
190  aOrigin.AdjustY(aLeftSize.Height() );
191  aMapMode.SetOrigin( aOrigin );
192 
193  mpNoteMarker.reset(new ScNoteMarker(pLeft, pRight, pBottom, pDiagonal,
194  &rDoc, aCellPos, aTrackText,
195  aMapMode, bLeftEdge, bFast, bKeyboard));
196  }
197 
198  bDone = true; // something is shown (old or new)
199  }
200 
201  return bDone;
202 }
203 
205 {
206  bool bDone = false;
207  bool bHelpEnabled = bool(rHEvt.GetMode() & ( HelpEventMode::BALLOON | HelpEventMode::QUICK ));
208  SdrView* pDrView = mrViewData.GetScDrawView();
209  bool bDrawTextEdit = false;
210  if (pDrView)
211  bDrawTextEdit = pDrView->IsTextEdit();
212  // notes or change tracking
213  if ( bHelpEnabled && !bDrawTextEdit )
214  {
215  Point aPosPixel = ScreenToOutputPixel( rHEvt.GetMousePosPixel() );
216  SCCOL nPosX;
217  SCROW nPosY;
218  mrViewData.GetPosFromPixel( aPosPixel.X(), aPosPixel.Y(), eWhich, nPosX, nPosY );
219 
220  if ( ShowNoteMarker( nPosX, nPosY, false ) )
221  {
222  Window::RequestHelp( rHEvt ); // turn off old Tip/Balloon
223  bDone = true;
224  }
225  }
226 
227  if (!bDone && mpNoteMarker)
228  {
229  if (mpNoteMarker->IsByKeyboard())
230  {
231  // marker which was shown for ctrl-F1 isn't removed by mouse events
232  }
233  else
234  {
235  mpNoteMarker.reset();
236  }
237  }
238 
239  // Image-Map / Text-URL
240 
241  if ( bHelpEnabled && !bDone && !nButtonDown ) // only without pressed button
242  {
243  OUString aHelpText;
244  tools::Rectangle aPixRect;
245  Point aPosPixel = ScreenToOutputPixel( rHEvt.GetMousePosPixel() );
246 
247  if ( pDrView ) // URL / Image-Map
248  {
249  SdrViewEvent aVEvt;
250  MouseEvent aMEvt( aPosPixel, 1, MouseEventModifiers::NONE, MOUSE_LEFT );
251  SdrHitKind eHit = pDrView->PickAnything( aMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt );
252 
253  if ( eHit != SdrHitKind::NONE && aVEvt.mpObj != nullptr )
254  {
255  // URL for IMapObject below Pointer is help text
256  if (SvxIMapInfo::GetIMapInfo(aVEvt.mpObj))
257  {
258  Point aLogicPos = PixelToLogic( aPosPixel );
260  aVEvt.mpObj, aLogicPos, GetOutDev() );
261 
262  if ( pIMapObj )
263  {
264  // For image maps show the description, if available
265  aHelpText = pIMapObj->GetAltText();
266  if (aHelpText.isEmpty())
267  aHelpText = SfxHelp::GetURLHelpText(pIMapObj->GetURL());
268  aPixRect = LogicToPixel(aVEvt.mpObj->GetLogicRect());
269  }
270  }
271  // URL in shape text or at shape itself (URL in text overrides object URL)
272  if ( aHelpText.isEmpty() )
273  {
274  if( aVEvt.meEvent == SdrEventKind::ExecuteUrl )
275  {
276  aHelpText = SfxHelp::GetURLHelpText(aVEvt.mpURLField->GetURL());
277  aPixRect = LogicToPixel(aVEvt.mpObj->GetLogicRect());
278  }
279  else
280  {
281  SdrPageView* pPV = nullptr;
282  Point aMDPos = PixelToLogic( aPosPixel );
283  SdrObject* pObj = pDrView->PickObj(aMDPos, pDrView->getHitTolLog(), pPV, SdrSearchOptions::ALSOONMASTER);
284  if (pObj)
285  {
286  if ( pObj->IsGroupObject() )
287  {
288  SdrObject* pHit = pDrView->PickObj(aMDPos, pDrView->getHitTolLog(), pPV, SdrSearchOptions::DEEP);
289  if (pHit)
290  pObj = pHit;
291  }
292  // Fragments pointing into the current document need no tooltip
293  // describing the ctrl-click functionality.
294  if ( !pObj->getHyperlink().isEmpty() && !pObj->getHyperlink().startsWith("#") )
295  {
296  aPixRect = LogicToPixel(aVEvt.mpObj->GetLogicRect());
297  aHelpText = SfxHelp::GetURLHelpText(pObj->getHyperlink());
298  }
299  }
300  }
301  }
302  }
303  }
304 
305  if ( aHelpText.isEmpty() ) // Text-URL
306  {
307  OUString aUrl;
308  if ( GetEditUrl( aPosPixel, nullptr, &aUrl ) )
309  {
310  aHelpText = SfxHelp::GetURLHelpText(
312 
314  SCCOL nPosX;
315  SCROW nPosY;
316  SCTAB nTab = mrViewData.GetTabNo();
317  mrViewData.GetPosFromPixel( aPosPixel.X(), aPosPixel.Y(), eWhich, nPosX, nPosY );
318  const ScPatternAttr* pPattern = rDoc.GetPattern( nPosX, nPosY, nTab );
319 
320  // bForceToTop = sal_False, use the cell's real position
321  aPixRect = mrViewData.GetEditArea( eWhich, nPosX, nPosY, this, pPattern, false );
322  }
323  }
324 
325  if ( !aHelpText.isEmpty() )
326  {
327  tools::Rectangle aScreenRect(OutputToScreenPixel(aPixRect.TopLeft()),
328  OutputToScreenPixel(aPixRect.BottomRight()));
329 
330  if ( rHEvt.GetMode() & HelpEventMode::BALLOON )
331  Help::ShowBalloon(this,rHEvt.GetMousePosPixel(), aScreenRect, aHelpText);
332  else if ( rHEvt.GetMode() & HelpEventMode::QUICK )
333  Help::ShowQuickHelp(this,aScreenRect, aHelpText);
334 
335  bDone = true;
336  }
337  }
338 
339  // basic controls
340 
341  if ( pDrView && bHelpEnabled && !bDone )
342  {
343  SdrPageView* pPV = pDrView->GetSdrPageView();
344  OSL_ENSURE( pPV, "SdrPageView* is NULL" );
345  if (pPV)
346  bDone = FmFormPage::RequestHelp( this, pDrView, rHEvt );
347  }
348 
349  // If QuickHelp for AutoFill is shown, do not allow it to be removed
350 
353  bDone = true;
354 
355  if (!bDone)
356  Window::RequestHelp( rHEvt );
357 }
358 
360 {
361  return pSdrView &&
362  pSdrView->GetModel() == mrViewData.GetDocument().GetDrawLayer();
363 }
364 
366 {
367  mpNoteMarker.reset();
368 }
369 
370 css::uno::Reference< css::accessibility::XAccessible >
372 {
373  css::uno::Reference< css::accessibility::XAccessible > xAcc= GetAccessible(false);
374  if (xAcc.is())
375  {
376  return xAcc;
377  }
378 
379  rtl::Reference<ScAccessibleDocument> pAccessibleDocument =
382  pAccessibleDocument->PreInit();
383 
384  xAcc = pAccessibleDocument;
385  SetAccessible(xAcc);
386 
387  pAccessibleDocument->Init();
388 
389  return xAcc;
390 }
391 
392 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< ScNoteMarker, o3tl::default_delete< ScNoteMarker > > mpNoteMarker
Definition: gridwin.hxx:156
bool IsMyModel(const SdrEditView *pSdrView)
Definition: gridwin5.cxx:359
ScAddress aStart
Definition: address.hxx:497
ScRefType GetRefType() const
Definition: viewdata.hxx:531
ScChangeActionType GetType() const
Definition: chgtrack.hxx:317
static bool IsActionShown(const ScChangeAction &rAction, const ScChangeViewSettings &rSettings, ScDocument &rDocument)
Definition: viewutil.cxx:135
MapMode GetDrawMapMode(bool bForce=false)
MapMode for the drawinglayer objects.
Definition: gridwin3.cxx:252
SCROW Row() const
Definition: address.hxx:274
ScChangeAction * GetNext() const
Definition: chgtrack.hxx:322
vcl::Window * GetAccessibleParentWindow() const
ScViewData & mrViewData
Definition: gridwin.hxx:151
ScChangeActionType
Definition: chgtrack.hxx:62
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
ScAddress aEnd
Definition: address.hxx:498
const OUString & getHyperlink() const
#define SC_GM_TABDOWN
Definition: gridwin.hxx:62
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
const SvxURLField * mpURLField
SdrHitKind PickAnything(const MouseEvent &rMEvt, SdrMouseEventKind nMouseDownOrMoveOrUp, SdrViewEvent &rVEvt) const
static OUString decode(std::u16string_view rText, DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
virtual OUString GetDescription(ScDocument &rDoc, bool bSplitRange=false, bool bWarning=true) const
Definition: chgtrack.cxx:419
sal_Int64 Tab() const
Definition: bigrange.hxx:46
void HideNoteMarker()
Definition: gridwin5.cxx:365
HelpEventMode GetMode() const
bool GetEditUrl(const Point &rPos, OUString *pName=nullptr, OUString *pUrl=nullptr, OUString *pTarget=nullptr)
Definition: gridwin.cxx:5659
constexpr tools::Long Width() const
static SC_DLLPUBLIC const LocaleDataWrapper & getLocaleData()
Definition: global.cxx:1015
SC_DLLPUBLIC ScPostIt * GetNote(const ScAddress &rPos)
Definition: document.cxx:6716
bool ShowChanges() const
Definition: chgviset.hxx:77
sal_uInt16 nButtonDown
Definition: gridwin.hxx:167
css::uno::Reference< css::accessibility::XAccessible > GetAccessible(bool bCreate=true)
Additional class containing cell annotation data.
Definition: postit.hxx:160
static IMapObject * GetHitIMapObject(const SdrObject *pObj, const Point &rWinPoint, const OutputDevice *pCmpWnd=nullptr)
ScChangeAction * GetFirst() const
Definition: chgtrack.hxx:953
void SetRow(SCROW nRowP)
Definition: address.hxx:287
void SetAccessible(const css::uno::Reference< css::accessibility::XAccessible > &)
ScSplitMode GetHSplitMode() const
Definition: viewdata.hxx:416
SC_DLLPUBLIC const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:4799
void SetCol(SCCOL nColP)
Definition: address.hxx:291
ScDrawView * GetScDrawView()
Definition: viewdata.cxx:3163
ScChangeTrack * GetChangeTrack() const
Definition: document.hxx:2485
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override
Definition: gridwin5.cxx:371
#define MOUSE_LEFT
const Point & GetMousePosPixel() const
DocumentType eType
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:357
SdrHitKind
SdrObject * PickObj(const Point &rPnt, short nTol, SdrPageView *&rpPV, SdrSearchOptions nOptions, SdrObject **ppRootObj, bool *pbHitPassDirect=nullptr) const
sal_uInt8 nMouseStatus
Definition: gridwin.hxx:168
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1081
vcl::Window * GetWindowByPos(ScSplitPos ePos) const
Definition: tabview.hxx:371
Point LogicToPixel(const Point &rLogicPt) const
tools::Rectangle GetEditArea(ScSplitPos eWhich, SCCOL nPosX, SCROW nPosY, vcl::Window *pWin, const ScPatternAttr *pPattern, bool bForceToTop, bool bInPrintTwips=false)
Definition: viewdata.cxx:1509
const OUString & GetAltText() const
void GetPosFromPixel(tools::Long nClickX, tools::Long nClickY, ScSplitPos eWhich, SCCOL &rPosX, SCROW &rPosY, bool bTestMerge=true, bool bRepair=false, SCTAB nForTab=-1)
Definition: viewdata.cxx:2774
sal_Int16 SCCOL
Definition: types.hxx:21
static bool IsQuickHelpEnabled()
const OUString & GetComment() const
Definition: chgtrack.hxx:350
void SetOrigin(const Point &rOrigin)
bool IsGroupObject() const
ScBigRange & GetBigRange()
Definition: chgtrack.hxx:231
Point PixelToLogic(const Point &rDevicePt) const
static bool RequestHelp(vcl::Window *pWin, SdrView const *pView, const HelpEvent &rEvt)
Point ScreenToOutputPixel(const Point &rPos) const
static void ShowQuickHelp(vcl::Window *pParent, const tools::Rectangle &rScreenRect, const OUString &rHelpText, QuickHelpFlags nStyle=QuickHelpFlags::NONE)
virtual void RequestHelp(const HelpEvent &rEvt) override
Definition: gridwin5.cxx:204
ScSplitPos eWhich
Definition: gridwin.hxx:152
SCCOL Col() const
Definition: address.hxx:279
ScDBFunc * GetView() const
Definition: viewdata.cxx:863
constexpr Point TopLeft() const
const OUString & GetURL() const
sal_uLong GetActionNumber() const
Definition: chgtrack.hxx:319
OUString getDate(const Date &rDate) const
sal_Int32 SCROW
Definition: types.hxx:17
ScBigAddress aStart
Definition: bigrange.hxx:108
virtual bool IsTextEdit() const final override
constexpr tools::Long Height() const
bool ShowNoteMarker(SCCOL nPosX, SCROW nPosY, bool bKeyboard)
Definition: gridwin5.cxx:46
SdrObject * mpObj
bool IsVisible() const
Definition: chgtrack.cxx:141
::OutputDevice const * GetOutDev() const
ScChangeViewSettings * GetChangeViewSettings() const
Definition: document.hxx:2236
bool Contains(const ScAddress &) const
is Address& fully in Range?
Definition: address.hxx:718
const Point & GetOrigin() const
SdrPageView * GetSdrPageView() const
const OUString & GetUser() const
Definition: chgtrack.hxx:349
Size GetOutputSizePixel() const
constexpr Point BottomRight() const
ScRange MakeRange(const ScDocument &rDoc) const
Definition: bigrange.hxx:134
virtual const tools::Rectangle & GetLogicRect() const
Point OutputToScreenPixel(const Point &rPos) const
SdrEventKind meEvent
OUString getTime(const tools::Time &rTime, bool bSec=true, bool b100Sec=false) const
static OUString GetURLHelpText(std::u16string_view)
sal_uInt16 getHitTolLog() const
SdrModel * GetModel() const
const OUString & GetURL() const
SC_DLLPUBLIC DateTime GetDateTime() const
Definition: chgtrack.cxx:405
ScSplitMode GetVSplitMode() const
Definition: viewdata.hxx:417
sal_Int16 SCTAB
Definition: types.hxx:22
static void ShowBalloon(vcl::Window *pParent, const Point &rScreenPos, const tools::Rectangle &, const OUString &rHelpText)
bool IsCaptionShown() const
Returns true, if the caption object is visible.
Definition: postit.hxx:255
static SvxIMapInfo * GetIMapInfo(const SdrObject *pObject)