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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_SOURCE_UI_INC_GRIDWIN_HXX
21 #define INCLUDED_SC_SOURCE_UI_INC_GRIDWIN_HXX
23 #include <vcl/transfer.hxx>
24 #include "viewutil.hxx"
25 #include "viewdata.hxx"
26 #include "cbutton.hxx"
27 #include "checklistmenu.hxx"
28 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
29 #include <o3tl/deleter.hxx>
35 struct MisspellRanges
;
39 struct SpellCheckContext
;
42 namespace sdr
{ namespace overlay
{ class OverlayManager
; } }
47 class ScDPFieldButton
;
49 class ScFilterListBox
;
56 struct SpellCallbackInfo
;
58 // mouse status (nMouseStatus)
61 #define SC_GM_TABDOWN 1
62 #define SC_GM_DBLDOWN 2
63 #define SC_GM_FILTER 3
64 #define SC_GM_IGNORE 4
65 #define SC_GM_WATERUNDO 5
66 #define SC_GM_URLDOWN 6
71 #define SC_PD_RANGE_L 1
72 #define SC_PD_RANGE_R 2
73 #define SC_PD_RANGE_T 4
74 #define SC_PD_RANGE_B 8
75 #define SC_PD_RANGE_TL (SC_PD_RANGE_T|SC_PD_RANGE_L)
76 #define SC_PD_RANGE_TR (SC_PD_RANGE_T|SC_PD_RANGE_R)
77 #define SC_PD_RANGE_BL (SC_PD_RANGE_B|SC_PD_RANGE_L)
78 #define SC_PD_RANGE_BR (SC_PD_RANGE_B|SC_PD_RANGE_R)
79 #define SC_PD_BREAK_H 16
80 #define SC_PD_BREAK_V 32
83 namespace sdr
{ namespace overlay
{ class OverlayObjectList
; }}
85 class SAL_DLLPUBLIC_RTTI ScGridWindow
: public vcl::Window
, public DropTargetHelper
, public DragSourceHelper
87 // ScFilterListBox is always used for selection list
88 friend class ScFilterListBox
;
99 std::unique_ptr
<sdr::overlay::OverlayObjectList
> mpOOCursors
;
100 std::unique_ptr
<sdr::overlay::OverlayObjectList
> mpOOSelection
;
101 std::unique_ptr
<sdr::overlay::OverlayObjectList
> mpOOSelectionBorder
;
102 std::unique_ptr
<sdr::overlay::OverlayObjectList
> mpOOAutoFill
;
103 std::unique_ptr
<sdr::overlay::OverlayObjectList
> mpOODragRect
;
104 std::unique_ptr
<sdr::overlay::OverlayObjectList
> mpOOHeader
;
105 std::unique_ptr
<sdr::overlay::OverlayObjectList
> mpOOShrink
;
107 boost::optional
<tools::Rectangle
> mpAutoFillRect
;
109 /// LibreOfficeKit needs a persistent FmFormView for tiled rendering,
110 /// otherwise the invalidations from drawinglayer do not work.
111 std::unique_ptr
<FmFormView
> mpLOKDrawView
;
113 struct MouseEventState
;
116 * Stores current visible column and row ranges, used to avoid expensive
117 * operations on objects that are outside visible area.
126 VisibleRange(const ScDocument
*);
128 bool isInside(SCCOL nCol
, SCROW nRow
) const;
129 bool set(SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
132 VisibleRange maVisibleRange
;
134 std::unique_ptr
<sc::SpellCheckContext
> mpSpellCheckCxt
;
136 ScViewData
* pViewData
;
137 ScSplitPos
const eWhich
;
141 std::unique_ptr
<ScNoteMarker
, o3tl::default_delete
<ScNoteMarker
>> mpNoteMarker
;
143 VclPtr
<ScFilterListBox
> mpFilterBox
;
144 VclPtr
<FloatingWindow
> mpFilterFloat
;
145 VclPtr
<ScCheckListMenuWindow
> mpAutoFilterPopup
;
146 VclPtr
<ScCheckListMenuWindow
> mpDPFieldPopup
;
147 std::unique_ptr
<ScDPFieldButton
> mpFilterButton
;
149 ScCheckListMenuWindow::ResultType aSaveAutoFilterResult
;
151 sal_uInt16 nCursorHideCount
;
153 sal_uInt16 nButtonDown
;
154 sal_uInt8 nMouseStatus
;
155 enum class ScNestedButtonState
{ NONE
, Down
, Up
};
156 ScNestedButtonState nNestedButtonState
; // track nested button up/down calls
159 ScDPObject
* pDragDPObj
; //! name?
165 sal_uInt16 nPagebreakMouse
; // Page break mode, Drag
166 SCCOLROW nPagebreakBreak
;
167 SCCOLROW nPagebreakPrev
;
168 ScRange aPagebreakSource
;
169 ScRange aPagebreakDrag
;
171 SvtScriptType nPageScript
;
177 InsCellCmd meDragInsertMode
;
179 ScDDComboBoxButton aComboButton
;
183 sal_uInt16 nPaintCount
;
184 tools::Rectangle aRepaintPixel
;
186 ScAddress aAutoMarkPos
;
187 ScAddress aListValPos
;
189 tools::Rectangle aInvertRect
;
191 RfCorner aRFSelectedCorned
;
193 bool bEEMouse
:1; // Edit Engine has mouse
194 bool bDPMouse
:1; // DataPilot D&D (new Pivot table)
195 bool bRFMouse
:1; // RangeFinder drag
197 bool bPagebreakDrawn
:1;
200 bool bNeedsRepaint
:1;
201 bool bAutoMarkVisible
:1;
202 bool bListValButton
:1;
204 DECL_LINK( PopupModeEndHdl
, FloatingWindow
*, void );
205 DECL_LINK( PopupSpellingHdl
, SpellCallbackInfo
&, void );
207 bool TestMouse( const MouseEvent
& rMEvt
, bool bAction
);
209 bool DoPageFieldSelection( SCCOL nCol
, SCROW nRow
);
210 bool DoAutoFilterButton( SCCOL nCol
, SCROW nRow
, const MouseEvent
& rMEvt
);
211 void DoPushPivotButton( SCCOL nCol
, SCROW nRow
, const MouseEvent
& rMEvt
, bool bButton
, bool bPopup
);
213 void DPMouseMove( const MouseEvent
& rMEvt
);
214 void DPMouseButtonUp( const MouseEvent
& rMEvt
);
215 void DPTestMouse( const MouseEvent
& rMEvt
, bool bMove
);
218 * Check if the mouse click is on a field popup button.
220 * @return true if the field popup menu has been launched and no further
221 * mouse event handling is necessary, false otherwise.
223 bool DPTestFieldPopupArrow(const MouseEvent
& rMEvt
, const ScAddress
& rPos
, const ScAddress
& rDimPos
, ScDPObject
* pDPObj
);
225 void DPLaunchFieldPopupMenu(const Point
& rScrPos
, const Size
& rScrSize
, const ScAddress
& rPos
, ScDPObject
* pDPObj
);
227 void RFMouseMove( const MouseEvent
& rMEvt
, bool bUp
);
229 void PagebreakMove( const MouseEvent
& rMEvt
, bool bUp
);
231 void UpdateDragRect( bool bShowRange
, const tools::Rectangle
& rPosRect
);
233 bool IsAutoFilterActive( SCCOL nCol
, SCROW nRow
, SCTAB nTab
);
234 void FilterSelect( sal_uLong nSel
);
236 void ExecDataSelect( SCCOL nCol
, SCROW nRow
, const OUString
& rStr
);
238 bool HasScenarioButton( const Point
& rPosPixel
, ScRange
& rScenRange
);
240 void DropScroll( const Point
& rMousePos
);
242 sal_Int8
AcceptPrivateDrop( const AcceptDropEvent
& rEvt
);
243 sal_Int8
ExecutePrivateDrop( const ExecuteDropEvent
& rEvt
);
244 sal_Int8
DropTransferObj( ScTransferObj
* pTransObj
, SCCOL nDestPosX
, SCROW nDestPosY
,
245 const Point
& rLogicPos
, sal_Int8 nDndAction
);
247 void HandleMouseButtonDown( const MouseEvent
& rMEvt
, MouseEventState
& rState
);
249 bool DrawMouseButtonDown(const MouseEvent
& rMEvt
);
250 bool DrawMouseButtonUp(const MouseEvent
& rMEvt
);
251 bool DrawMouseMove(const MouseEvent
& rMEvt
);
252 bool DrawKeyInput(const KeyEvent
& rKEvt
);
253 bool DrawCommand(const CommandEvent
& rCEvt
);
254 bool DrawHasMarkedObj();
255 void DrawEndAction();
256 void DrawMarkDropObj( SdrObject
* pObj
);
257 bool IsMyModel(const SdrEditView
* pSdrView
);
259 void DrawRedraw( ScOutputData
& rOutputData
, SdrLayerID nLayer
);
260 void DrawSdrGrid( const tools::Rectangle
& rDrawingRect
, OutputDevice
* pContentDev
);
261 void DrawAfterScroll();
262 tools::Rectangle
GetListValButtonRect( const ScAddress
& rButtonPos
);
264 void DrawPagePreview( SCCOL nX1
, SCROW nY1
, SCCOL nX2
, SCROW nY2
, vcl::RenderContext
& rRenderContext
);
266 bool GetEditUrl( const Point
& rPos
,
267 OUString
* pName
=nullptr, OUString
* pUrl
=nullptr, OUString
* pTarget
=nullptr );
269 bool IsSpellErrorAtPos( const Point
& rPos
, SCCOL nCol1
, SCROW nRow
);
271 bool HitRangeFinder( const Point
& rMouse
, RfCorner
& rCorner
, sal_uInt16
* pIndex
,
272 SCCOL
* pAddX
, SCROW
* pAddY
);
274 sal_uInt16
HitPageBreak( const Point
& rMouse
, ScRange
* pSource
,
275 SCCOLROW
* pBreak
, SCCOLROW
* pPrev
);
277 /** The cell may be covered by text that overflows from a previous cell.
279 @return if true, the given cell is covered by (overflowing) text and
280 rTextStartPosX returns the column where the text that overflows
283 bool IsCellCoveredByText(SCCOL nPosX
, SCROW nPosY
, SCTAB nTab
, SCCOL
&rTextStartPosX
);
285 void PasteSelection( const Point
& rPosPixel
);
287 void SelectForContextMenu( const Point
& rPosPixel
, SCCOL nCellX
, SCROW nCellY
);
289 void GetSelectionRects( ::std::vector
< tools::Rectangle
>& rPixelRects
);
293 virtual void PrePaint(vcl::RenderContext
& rRenderContext
) override
;
294 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
295 virtual void GetFocus() override
;
296 virtual void LoseFocus() override
;
298 virtual void RequestHelp( const HelpEvent
& rEvt
) override
;
300 virtual sal_Int8
AcceptDrop( const AcceptDropEvent
& rEvt
) override
;
301 virtual sal_Int8
ExecuteDrop( const ExecuteDropEvent
& rEvt
) override
;
302 virtual void StartDrag( sal_Int8 nAction
, const Point
& rPosPixel
) override
;
305 enum class AutoFilterMode
{ Normal
, Top10
, Custom
, Empty
, NonEmpty
, SortAscending
, SortDescending
};
307 ScGridWindow( vcl::Window
* pParent
, ScViewData
* pData
, ScSplitPos eWhichPos
);
308 virtual ~ScGridWindow() override
;
309 virtual void dispose() override
;
311 virtual void KeyInput(const KeyEvent
& rKEvt
) override
;
312 // #i70788# flush and get overlay
313 rtl::Reference
<sdr::overlay::OverlayManager
> getOverlayManager() const;
314 void flushOverlayManager();
316 virtual void Command( const CommandEvent
& rCEvt
) override
;
317 virtual void DataChanged( const DataChangedEvent
& rDCEvt
) override
;
319 virtual void MouseButtonDown( const MouseEvent
& rMEvt
) override
;
320 virtual void MouseButtonUp( const MouseEvent
& rMEvt
) override
;
321 virtual void MouseMove( const MouseEvent
& rMEvt
) override
;
322 virtual bool PreNotify( NotifyEvent
& rNEvt
) override
;
323 virtual void Tracking( const TrackingEvent
& rTEvt
) override
;
325 void PaintTile( VirtualDevice
& rDevice
,
326 int nOutputWidth
, int nOutputHeight
,
327 int nTilePosX
, int nTilePosY
,
328 long nTileWidth
, long nTileHeight
);
330 /// @see Window::LogicInvalidate().
331 void LogicInvalidate(const tools::Rectangle
* pRectangle
) override
;
333 /// Update the cell selection according to what handles have been dragged.
334 /// @see vcl::ITiledRenderable::setTextSelection() for the values of nType.
335 /// Coordinates are in pixels.
336 void SetCellSelectionPixel(int nType
, int nPixelX
, int nPixelY
);
337 /// Get the cell selection, coordinates are in logic units.
338 void GetCellSelection(std::vector
<tools::Rectangle
>& rLogicRects
);
340 virtual css::uno::Reference
< css::accessibility::XAccessible
> CreateAccessible() override
;
344 const Point
& GetMousePosPixel() const { return aCurMousePos
; }
345 void UpdateStatusPosSize();
349 using Window::SetPointer
;
351 void MoveMouseStatus( ScGridWindow
&rDestWin
);
353 void ScrollPixel( long nDifX
, long nDifY
);
354 void UpdateEditViewPos();
356 void UpdateFormulas(SCCOL nX1
= -1, SCROW nY1
= -1, SCCOL nX2
= -1, SCROW nY2
= -1);
358 void LaunchDataSelectMenu( SCCOL nCol
, SCROW nRow
);
359 void DoScenarioMenu( const ScRange
& rScenRange
);
361 void LaunchAutoFilterMenu(SCCOL nCol
, SCROW nRow
);
362 void RefreshAutoFilterButton(const ScAddress
& rPos
);
363 void UpdateAutoFilterFromMenu(AutoFilterMode eMode
);
365 void LaunchPageFieldMenu( SCCOL nCol
, SCROW nRow
);
366 void LaunchDPFieldMenu( SCCOL nCol
, SCROW nRow
);
368 css::sheet::DataPilotFieldOrientation
GetDPFieldOrientation( SCCOL nCol
, SCROW nRow
) const;
370 void DPLaunchFieldPopupMenu(const Point
& rScrPos
, const Size
& rScrSize
,
371 long nDimIndex
, ScDPObject
* pDPObj
);
373 void DrawButtons(SCCOL nX1
, SCCOL nX2
, const ScTableInfo
& rTabInfo
, OutputDevice
* pContentDev
);
376 void Draw( SCCOL nX1
, SCROW nY1
, SCCOL nX2
, SCROW nY2
,
377 ScUpdateMode eMode
);
379 /// Draw content of the gridwindow; shared between the desktop and the tiled rendering.
380 void DrawContent(OutputDevice
&rDevice
, const ScTableInfo
& rTableInfo
, ScOutputData
& aOutputData
, bool bLogicText
);
382 void CreateAnchorHandle(SdrHdlList
& rHdl
, const ScAddress
& rAddress
);
386 void UpdateAutoFillMark(bool bMarked
, const ScRange
& rMarkRange
);
388 void UpdateListValPos( bool bVisible
, const ScAddress
& rPos
);
390 bool ShowNoteMarker( SCCOL nPosX
, SCROW nPosY
, bool bKeyboard
);
391 void HideNoteMarker();
393 /// MapMode for the drawinglayer objects.
394 MapMode
GetDrawMapMode( bool bForce
= false );
397 void UpdateInputContext();
399 bool NeedsRepaint() { return bNeedsRepaint
; }
401 void DoInvertRect( const tools::Rectangle
& rPixel
);
403 void CheckNeedsRepaint();
405 void UpdateDPFromFieldPopupMenu();
406 bool UpdateVisibleRange();
408 void CursorChanged();
409 void DrawLayerCreated();
410 bool ContinueOnlineSpelling();
411 void EnableAutoSpell( bool bEnable
);
412 void ResetAutoSpell();
413 void SetAutoSpellData( SCCOL nPosX
, SCROW nPosY
, const std::vector
<editeng::MisspellRanges
>* pRanges
);
414 const std::vector
<editeng::MisspellRanges
>* GetAutoSpellData( SCCOL nPosX
, SCROW nPosY
);
415 bool InsideVisibleRange( SCCOL nPosX
, SCROW nPosY
);
417 void DeleteCopySourceOverlay();
418 void UpdateCopySourceOverlay();
419 void DeleteCursorOverlay();
420 void UpdateCursorOverlay();
421 void DeleteSelectionOverlay();
422 void UpdateSelectionOverlay();
423 void DeleteAutoFillOverlay();
424 void UpdateAutoFillOverlay();
425 void DeleteDragRectOverlay();
426 void UpdateDragRectOverlay();
427 void DeleteHeaderOverlay();
428 void UpdateHeaderOverlay();
429 void DeleteShrinkOverlay();
430 void UpdateShrinkOverlay();
431 void UpdateAllOverlays();
433 /// @see ScModelObj::getCellCursor().
434 OString
getCellCursor(const Fraction
& rZoomX
,
435 const Fraction
& rZoomY
) const;
436 OString
getCellCursor(int nOutputWidth
,
440 void updateLibreOfficeKitCellCursor(const SfxViewShell
* pOtherShell
) const;
442 /// Same as MouseButtonDown(), but coordinates are in logic unit.
443 virtual void LogicMouseButtonDown(const MouseEvent
& rMouseEvent
) override
;
444 /// Same as MouseButtonUp(), but coordinates are in logic unit.
445 virtual void LogicMouseButtonUp(const MouseEvent
& rMouseEvent
) override
;
446 /// Same as MouseMove(), but coordinates are in logic unit.
447 virtual void LogicMouseMove(const MouseEvent
& rMouseEvent
) override
;
449 ScViewData
* getViewData();
450 virtual FactoryFunction
GetUITestFactory() const override
;
452 void updateLOKValListButton(bool bVisible
, const ScAddress
& rPos
) const;
455 void ImpCreateOverlayObjects();
456 void ImpDestroyOverlayObjects();
461 void dumpCellProperties();
462 void dumpColumnInformationPixel();
463 void dumpColumnInformationHmm();
464 void dumpGraphicInformation();
465 void dumpColumnCellStorage();
472 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */