Line data Source code
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 : #ifndef INCLUDED_SC_SOURCE_UI_INC_GRIDWIN_HXX
21 : #define INCLUDED_SC_SOURCE_UI_INC_GRIDWIN_HXX
22 :
23 : #include <svtools/transfer.hxx>
24 : #include "viewutil.hxx"
25 : #include "viewdata.hxx"
26 : #include "cbutton.hxx"
27 : #include <svx/sdr/overlay/overlayobject.hxx>
28 : #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
29 : #include <basegfx/matrix/b2dhommatrix.hxx>
30 :
31 : #include <boost/ptr_container/ptr_map.hpp>
32 : #include <boost/ptr_container/ptr_vector.hpp>
33 : #include <vector>
34 :
35 : namespace editeng {
36 : struct MisspellRanges;
37 : }
38 :
39 : namespace sc {
40 : struct SpellCheckContext;
41 : }
42 :
43 : struct ScTableInfo;
44 : class ScDPObject;
45 : class ScCheckListMenuWindow;
46 : class ScDPFieldButton;
47 : class ScOutputData;
48 : class ScFilterListBox;
49 : class SdrObject;
50 : class SdrEditView;
51 : class ScNoteMarker;
52 : class FloatingWindow;
53 : class SdrHdlList;
54 : class ScTransferObj;
55 : struct SpellCallbackInfo;
56 :
57 : // Maus-Status (nMouseStatus)
58 :
59 : #define SC_GM_NONE 0
60 : #define SC_GM_TABDOWN 1
61 : #define SC_GM_DBLDOWN 2
62 : #define SC_GM_FILTER 3
63 : #define SC_GM_IGNORE 4
64 : #define SC_GM_WATERUNDO 5
65 : #define SC_GM_URLDOWN 6
66 :
67 : // Page-Drag-Modus
68 :
69 : #define SC_PD_NONE 0
70 : #define SC_PD_RANGE_L 1
71 : #define SC_PD_RANGE_R 2
72 : #define SC_PD_RANGE_T 4
73 : #define SC_PD_RANGE_B 8
74 : #define SC_PD_RANGE_TL (SC_PD_RANGE_T|SC_PD_RANGE_L)
75 : #define SC_PD_RANGE_TR (SC_PD_RANGE_T|SC_PD_RANGE_R)
76 : #define SC_PD_RANGE_BL (SC_PD_RANGE_B|SC_PD_RANGE_L)
77 : #define SC_PD_RANGE_BR (SC_PD_RANGE_B|SC_PD_RANGE_R)
78 : #define SC_PD_BREAK_H 16
79 : #define SC_PD_BREAK_V 32
80 :
81 : // predefines
82 : namespace sdr { namespace overlay { class OverlayObjectList; }}
83 :
84 : class ScGridWindow : public vcl::Window, public DropTargetHelper, public DragSourceHelper
85 : {
86 : // ScFilterListBox is always used for selection list
87 : friend class ScFilterListBox;
88 :
89 : enum RfCorner
90 : {
91 : NONE,
92 : LEFT_UP,
93 : RIGHT_UP,
94 : LEFT_DOWN,
95 : RIGHT_DOWN
96 : };
97 :
98 : // #114409#
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;
106 :
107 : std::unique_ptr<Rectangle> mpAutoFillRect;
108 :
109 : struct MouseEventState;
110 :
111 : /**
112 : * Stores current visible column and row ranges, used to avoid expensive
113 : * operations on objects that are outside visible area.
114 : */
115 : struct VisibleRange
116 : {
117 : SCCOL mnCol1;
118 : SCCOL mnCol2;
119 : SCROW mnRow1;
120 : SCROW mnRow2;
121 :
122 : VisibleRange();
123 :
124 : bool isInside(SCCOL nCol, SCROW nRow) const;
125 : bool set(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
126 : };
127 :
128 : VisibleRange maVisibleRange;
129 :
130 : std::unique_ptr<sc::SpellCheckContext> mpSpellCheckCxt;
131 :
132 : ScViewData* pViewData;
133 : ScSplitPos eWhich;
134 : ScHSplitPos eHWhich;
135 : ScVSplitPos eVWhich;
136 :
137 : std::unique_ptr<ScNoteMarker> mpNoteMarker;
138 :
139 : VclPtr<ScFilterListBox> mpFilterBox;
140 : VclPtr<FloatingWindow> mpFilterFloat;
141 : VclPtr<ScCheckListMenuWindow> mpAutoFilterPopup;
142 : VclPtr<ScCheckListMenuWindow> mpDPFieldPopup;
143 : std::unique_ptr<ScDPFieldButton> mpFilterButton;
144 :
145 : sal_uInt16 nCursorHideCount;
146 :
147 : sal_uInt16 nButtonDown;
148 : sal_uInt8 nMouseStatus;
149 : sal_uInt8 nNestedButtonState; // track nested button up/down calls
150 :
151 : long nDPField;
152 : ScDPObject* pDragDPObj; //! name?
153 :
154 : sal_uInt16 nRFIndex;
155 : SCsCOL nRFAddX;
156 : SCsROW nRFAddY;
157 :
158 : sal_uInt16 nPagebreakMouse; // Page break mode, Drag
159 : SCCOLROW nPagebreakBreak;
160 : SCCOLROW nPagebreakPrev;
161 : ScRange aPagebreakSource;
162 : ScRange aPagebreakDrag;
163 :
164 : SvtScriptType nPageScript;
165 :
166 : long nLastClickX;
167 : long nLastClickY;
168 :
169 : SCCOL nDragStartX;
170 : SCROW nDragStartY;
171 : SCCOL nDragEndX;
172 : SCROW nDragEndY;
173 : InsCellCmd meDragInsertMode;
174 :
175 : sal_uInt16 nCurrentPointer;
176 :
177 : ScDDComboBoxButton aComboButton;
178 :
179 : Point aCurMousePos;
180 :
181 : sal_uInt16 nPaintCount;
182 : Rectangle aRepaintPixel;
183 :
184 : ScAddress aAutoMarkPos;
185 : ScAddress aListValPos;
186 :
187 : Rectangle aInvertRect;
188 :
189 : RfCorner aRFSelectedCorned;
190 :
191 : bool bEEMouse:1; // Edit Engine has mouse
192 : bool bDPMouse:1; // DataPilot D&D (new Pivot table)
193 : bool bRFMouse:1; // RangeFinder drag
194 : bool bRFSize:1;
195 : bool bPagebreakDrawn:1;
196 : bool bDragRect:1;
197 : bool bIsInScroll:1;
198 : bool bIsInPaint:1;
199 : bool bNeedsRepaint:1;
200 : bool bAutoMarkVisible:1;
201 : bool bListValButton:1;
202 :
203 : DECL_LINK( PopupModeEndHdl, void* );
204 : DECL_LINK( PopupSpellingHdl, SpellCallbackInfo* );
205 :
206 : bool TestMouse( const MouseEvent& rMEvt, bool bAction );
207 :
208 : bool DoPageFieldSelection( SCCOL nCol, SCROW nRow );
209 : bool DoAutoFilterButton( SCCOL nCol, SCROW nRow, const MouseEvent& rMEvt );
210 : void DoPushPivotButton( SCCOL nCol, SCROW nRow, const MouseEvent& rMEvt, bool bButton, bool bPopup );
211 :
212 : void DPMouseMove( const MouseEvent& rMEvt );
213 : void DPMouseButtonUp( const MouseEvent& rMEvt );
214 : void DPTestMouse( const MouseEvent& rMEvt, bool bMove );
215 :
216 : /**
217 : * Check if the mouse click is on a field popup button.
218 : *
219 : * @return true if the field popup menu has been launched and no further
220 : * mouse event handling is necessary, false otherwise.
221 : */
222 : bool DPTestFieldPopupArrow(const MouseEvent& rMEvt, const ScAddress& rPos, const ScAddress& rDimPos, ScDPObject* pDPObj);
223 : void DPLaunchFieldPopupMenu(
224 : const Point& rScrPos, const Size& rScrSize, const ScAddress& rPos, ScDPObject* pDPObj);
225 :
226 : void RFMouseMove( const MouseEvent& rMEvt, bool bUp );
227 :
228 : void PagebreakMove( const MouseEvent& rMEvt, bool bUp );
229 :
230 : void UpdateDragRect( bool bShowRange, const Rectangle& rPosRect );
231 :
232 : bool IsAutoFilterActive( SCCOL nCol, SCROW nRow, SCTAB nTab );
233 : void ExecFilter( sal_uLong nSel, SCCOL nCol, SCROW nRow,
234 : const OUString& aValue, bool bCheckForDates );
235 : void FilterSelect( sal_uLong nSel );
236 :
237 : void ExecDataSelect( SCCOL nCol, SCROW nRow, const OUString& rStr );
238 :
239 : void ExecPageFieldSelect( SCCOL nCol, SCROW nRow, bool bHasSelection, const OUString& rStr );
240 :
241 : bool HasScenarioButton( const Point& rPosPixel, ScRange& rScenRange );
242 :
243 : bool DropScroll( const Point& rMousePos );
244 :
245 : sal_Int8 AcceptPrivateDrop( const AcceptDropEvent& rEvt );
246 : sal_Int8 ExecutePrivateDrop( const ExecuteDropEvent& rEvt );
247 : sal_Int8 DropTransferObj( ScTransferObj* pTransObj, SCCOL nDestPosX, SCROW nDestPosY,
248 : const Point& rLogicPos, sal_Int8 nDndAction );
249 :
250 : void HandleMouseButtonDown( const MouseEvent& rMEvt, MouseEventState& rState );
251 :
252 : bool DrawMouseButtonDown(const MouseEvent& rMEvt);
253 : bool DrawMouseButtonUp(const MouseEvent& rMEvt);
254 : bool DrawMouseMove(const MouseEvent& rMEvt);
255 : bool DrawKeyInput(const KeyEvent& rKEvt);
256 : bool DrawCommand(const CommandEvent& rCEvt);
257 : bool DrawHasMarkedObj();
258 : void DrawEndAction();
259 : void DrawMarkDropObj( SdrObject* pObj );
260 : SdrObject* GetEditObject();
261 : bool IsMyModel(SdrEditView* pSdrView);
262 :
263 : void DrawRedraw( ScOutputData& rOutputData, ScUpdateMode eMode, sal_uLong nLayer );
264 : void DrawSdrGrid( const Rectangle& rDrawingRect, OutputDevice* pContentDev );
265 : void DrawAfterScroll();
266 : Rectangle GetListValButtonRect( const ScAddress& rButtonPos );
267 :
268 : void DrawPagePreview( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2, OutputDevice* pContentDev );
269 :
270 : bool GetEditUrl( const Point& rPos,
271 : OUString* pName=0, OUString* pUrl=0, OUString* pTarget=0 );
272 :
273 : bool IsSpellErrorAtPos( const Point& rPos, SCCOL nCol1, SCROW nRow );
274 :
275 : bool HitRangeFinder( const Point& rMouse, RfCorner& rCorner, sal_uInt16* pIndex = NULL,
276 : SCsCOL* pAddX = NULL, SCsROW* pAddY = NULL );
277 :
278 : sal_uInt16 HitPageBreak( const Point& rMouse, ScRange* pSource = NULL,
279 : SCCOLROW* pBreak = NULL, SCCOLROW* pPrev = NULL );
280 :
281 : /** The cell may be covered by text that overflows from a previous cell.
282 :
283 : @return if true, the given cell is covered by (overflowing) text and
284 : rTextStartPosX returns the column where the text that overflows
285 : starts.
286 : */
287 : bool IsCellCoveredByText(SCsCOL nPosX, SCsROW nPosY, SCTAB nTab, SCsCOL &rTextStartPosX);
288 :
289 : void PasteSelection( const Point& rPosPixel );
290 :
291 : void SelectForContextMenu( const Point& rPosPixel, SCsCOL nCellX, SCsROW nCellY );
292 :
293 : void GetSelectionRects( ::std::vector< Rectangle >& rPixelRects );
294 :
295 : protected:
296 : virtual void PrePaint(vcl::RenderContext& rRenderContext) SAL_OVERRIDE;
297 : virtual void Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) SAL_OVERRIDE;
298 : virtual void GetFocus() SAL_OVERRIDE;
299 : virtual void LoseFocus() SAL_OVERRIDE;
300 :
301 : virtual void RequestHelp( const HelpEvent& rEvt ) SAL_OVERRIDE;
302 : virtual void Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
303 :
304 : virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) SAL_OVERRIDE;
305 : virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) SAL_OVERRIDE;
306 : virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel ) SAL_OVERRIDE;
307 :
308 : public:
309 : enum AutoFilterMode { Normal, Top10, Custom, Empty, NonEmpty, SortAscending, SortDescending };
310 :
311 : ScGridWindow( vcl::Window* pParent, ScViewData* pData, ScSplitPos eWhichPos );
312 : virtual ~ScGridWindow();
313 : virtual void dispose() SAL_OVERRIDE;
314 :
315 : virtual void KeyInput(const KeyEvent& rKEvt) SAL_OVERRIDE;
316 : // #i70788# flush and get overlay
317 : rtl::Reference<sdr::overlay::OverlayManager> getOverlayManager();
318 : void flushOverlayManager();
319 :
320 : virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
321 :
322 : virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
323 : virtual void MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
324 : virtual void MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
325 : virtual bool PreNotify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
326 : virtual void Tracking( const TrackingEvent& rTEvt ) SAL_OVERRIDE;
327 :
328 : void PaintTile( VirtualDevice& rDevice,
329 : int nOutputWidth, int nOutputHeight,
330 : int nTilePosX, int nTilePosY,
331 : long nTileWidth, long nTileHeight );
332 :
333 : /// @see OutputDevice::LogicInvalidate().
334 : void LogicInvalidate(const Rectangle* pRectangle) SAL_OVERRIDE;
335 :
336 : /// Update the cell selection according to what handles have been dragged.
337 : /// @see vcl::ITiledRenderable::setTextSelection() for the values of nType.
338 : /// Coordinates are in pixels.
339 : void SetCellSelectionPixel(int nType, int nPixelX, int nPixelY);
340 :
341 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible() SAL_OVERRIDE;
342 :
343 : void FakeButtonUp();
344 :
345 0 : Point GetMousePosPixel() const { return aCurMousePos; }
346 : void UpdateStatusPosSize();
347 :
348 : void ClickExtern();
349 :
350 : void SetPointer( const Pointer& rPointer );
351 :
352 : void MoveMouseStatus( ScGridWindow &rDestWin );
353 :
354 : void ScrollPixel( long nDifX, long nDifY );
355 : void UpdateEditViewPos();
356 :
357 : void UpdateFormulas();
358 :
359 : void LaunchDataSelectMenu( SCCOL nCol, SCROW nRow, bool bDataSelect );
360 : void DoScenarioMenu( const ScRange& rScenRange );
361 :
362 : void LaunchAutoFilterMenu(SCCOL nCol, SCROW nRow);
363 : void RefreshAutoFilterButton(const ScAddress& rPos);
364 : void UpdateAutoFilterFromMenu(AutoFilterMode eMode);
365 :
366 : void LaunchPageFieldMenu( SCCOL nCol, SCROW nRow );
367 : void LaunchDPFieldMenu( SCCOL nCol, SCROW nRow );
368 :
369 : ::com::sun::star::sheet::DataPilotFieldOrientation GetDPFieldOrientation( SCCOL nCol, SCROW nRow ) const;
370 :
371 : void DrawButtons(SCCOL nX1, SCCOL nX2, const ScTableInfo& rTabInfo, OutputDevice* pContentDev);
372 :
373 : using Window::Draw;
374 : void Draw( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
375 : ScUpdateMode eMode = SC_UPDATE_ALL );
376 :
377 : /// Draw content of the gridwindow; shared between the desktop and the tiled rendering.
378 : void DrawContent(OutputDevice &rDevice, const ScTableInfo& rTableInfo, ScOutputData& aOutputData, bool bLogicText, ScUpdateMode eMode);
379 :
380 : void CreateAnchorHandle(SdrHdlList& rHdl, const ScAddress& rAddress);
381 :
382 : void HideCursor();
383 : void ShowCursor();
384 : void UpdateAutoFillMark(bool bMarked, const ScRange& rMarkRange);
385 :
386 : void UpdateListValPos( bool bVisible, const ScAddress& rPos );
387 :
388 : bool ShowNoteMarker( SCsCOL nPosX, SCsROW nPosY, bool bKeyboard );
389 : void HideNoteMarker();
390 :
391 : /// MapMode for the drawinglayer objects.
392 : MapMode GetDrawMapMode( bool bForce = false );
393 :
394 : void ContinueDrag();
395 :
396 : void StopMarking();
397 : void UpdateInputContext();
398 :
399 0 : bool NeedsRepaint() { return bNeedsRepaint; }
400 :
401 : void DoInvertRect( const Rectangle& rPixel );
402 :
403 : void CheckNeedsRepaint();
404 :
405 : void UpdateDPFromFieldPopupMenu();
406 : bool UpdateVisibleRange();
407 :
408 : // #114409#
409 : void CursorChanged();
410 : void DrawLayerCreated();
411 : bool ContinueOnlineSpelling();
412 : void EnableAutoSpell( bool bEnable );
413 : void ResetAutoSpell();
414 : void SetAutoSpellData( SCCOL nPosX, SCROW nPosY, const std::vector<editeng::MisspellRanges>* pRanges );
415 : const std::vector<editeng::MisspellRanges>* GetAutoSpellData( SCCOL nPosX, SCROW nPosY );
416 : bool InsideVisibleRange( SCCOL nPosX, SCROW nPosY );
417 :
418 : void DeleteCopySourceOverlay();
419 : void UpdateCopySourceOverlay();
420 : void DeleteCursorOverlay();
421 : void UpdateCursorOverlay();
422 : void DeleteSelectionOverlay();
423 : void UpdateSelectionOverlay();
424 : void DeleteAutoFillOverlay();
425 : void UpdateAutoFillOverlay();
426 : void DeleteDragRectOverlay();
427 : void UpdateDragRectOverlay();
428 : void DeleteHeaderOverlay();
429 : void UpdateHeaderOverlay();
430 : void DeleteShrinkOverlay();
431 : void UpdateShrinkOverlay();
432 : void UpdateAllOverlays();
433 :
434 : protected:
435 : // #114409#
436 : void ImpCreateOverlayObjects();
437 : void ImpDestroyOverlayObjects();
438 :
439 : private:
440 :
441 : #ifdef DBG_UTIL
442 : void dumpColumnInformationPixel();
443 : void dumpColumnInformationHmm();
444 : void dumpGraphicInformation();
445 : #endif
446 :
447 : };
448 :
449 : #endif
450 :
451 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|