xref: /AOO41X/main/sc/source/ui/inc/gridwin.hxx (revision 4d7c9de063a797b8b4f3d45e3561e82ad1f8ef1f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_GRIDWIN_HXX
25 #define SC_GRIDWIN_HXX
26 
27 #include <tools/string.hxx>
28 #include <svtools/transfer.hxx>
29 #include "viewutil.hxx"
30 #include "viewdata.hxx"
31 #include "cbutton.hxx"
32 #include <svx/sdr/overlay/overlayobject.hxx>
33 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
34 #include <basegfx/matrix/b2dhommatrix.hxx>
35 
36 #include <vector>
37 #include <memory>
38 #include <boost/shared_ptr.hpp>
39 
40 // ---------------------------------------------------------------------------
41 
42 struct ScTableInfo;
43 class ScViewSelectionEngine;
44 class ScDPObject;
45 class ScDPFieldPopupWindow;
46 class ScDPFieldButton;
47 class ScOutputData;
48 class ScFilterListBox;
49 class AutoFilterPopup;
50 class SdrObject;
51 class SdrEditView;
52 class ScNoteMarker;
53 class FloatingWindow;
54 class SdrHdlList;
55 class ScTransferObj;
56 struct SpellCallbackInfo;
57 
58         //  Maus-Status (nMouseStatus)
59 
60 #define SC_GM_NONE          0
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
67 
68         //  Page-Drag-Modus
69 
70 #define SC_PD_NONE          0
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
81 
82 
83 class ScHideTextCursor
84 {
85 private:
86     ScViewData* pViewData;
87     ScSplitPos  eWhich;
88 
89 public:
90             ScHideTextCursor( ScViewData* pData, ScSplitPos eW );
91             ~ScHideTextCursor();
92 };
93 
94 // ---------------------------------------------------------------------------
95 // predefines
96 namespace sdr { namespace overlay { class OverlayObjectList; }}
97 
98 class ScGridWindow : public Window, public DropTargetHelper, public DragSourceHelper
99 {
100     //  ScFilterListBox wird immer fuer Auswahlliste benutzt
101     friend class ScFilterListBox;
102 
103 private:
104     // #114409#
105     ::sdr::overlay::OverlayObjectList*              mpOOCursors;
106     ::sdr::overlay::OverlayObjectList*              mpOOSelection;
107     ::sdr::overlay::OverlayObjectList*              mpOOAutoFill;
108     ::sdr::overlay::OverlayObjectList*              mpOODragRect;
109     ::sdr::overlay::OverlayObjectList*              mpOOHeader;
110     ::sdr::overlay::OverlayObjectList*              mpOOShrink;
111 
112     ::boost::shared_ptr<Rectangle> mpAutoFillRect;
113 
114     /**
115      * Stores current visible column and row ranges, used to avoid expensive
116      * operations on objects that are outside visible area.
117      */
118     struct VisibleRange
119     {
120         SCCOL mnCol1;
121         SCCOL mnCol2;
122         SCROW mnRow1;
123         SCROW mnRow2;
124 
125         VisibleRange();
126 
127         bool isInside(SCCOL nCol, SCROW nRow) const;
128     };
129     VisibleRange maVisibleRange;
130 
131 private:
132     ScViewData*             pViewData;
133     ScSplitPos              eWhich;
134     ScHSplitPos             eHWhich;
135     ScVSplitPos             eVWhich;
136 
137     ScNoteMarker*           pNoteMarker;
138 
139     ScFilterListBox*        pFilterBox;
140     FloatingWindow*         pFilterFloat;
141     ::std::auto_ptr<ScDPFieldPopupWindow> mpDPFieldPopup;
142     ::std::auto_ptr<ScDPFieldButton>      mpFilterButton;
143 
144     sal_uInt16                  nCursorHideCount;
145 
146     sal_Bool                    bMarking;
147 
148     sal_uInt16                  nButtonDown;
149     sal_Bool                    bEEMouse;               // Edit-Engine hat Maus
150     sal_uInt8                   nMouseStatus;
151     sal_uInt8                    nNestedButtonState;     // track nested button up/down calls
152 
153     sal_Bool                    bDPMouse;               // DataPilot-D&D (neue Pivottabellen)
154     long                    nDPField;
155     ScDPObject*             pDragDPObj; //! name?
156 
157     sal_Bool                    bRFMouse;               // RangeFinder-Drag
158     sal_Bool                    bRFSize;
159     sal_uInt16                  nRFIndex;
160     SCsCOL                  nRFAddX;
161     SCsROW                  nRFAddY;
162 
163     sal_uInt16                  nPagebreakMouse;        // Pagebreak-Modus Drag
164     SCCOLROW                nPagebreakBreak;
165     SCCOLROW                nPagebreakPrev;
166     ScRange                 aPagebreakSource;
167     ScRange                 aPagebreakDrag;
168     sal_Bool                    bPagebreakDrawn;
169 
170     sal_uInt8                   nPageScript;
171 
172     long                    nLastClickX;
173     long                    nLastClickY;
174 
175     sal_Bool                    bDragRect;
176     SCCOL                   nDragStartX;
177     SCROW                   nDragStartY;
178     SCCOL                   nDragEndX;
179     SCROW                   nDragEndY;
180     InsCellCmd              meDragInsertMode;
181 
182     sal_uInt16                  nCurrentPointer;
183 
184     sal_Bool                    bIsInScroll;
185     sal_Bool                    bIsInPaint;
186 
187     ScDDComboBoxButton      aComboButton;
188 
189     Point                   aCurMousePos;
190 
191     sal_uInt16                  nPaintCount;
192     Rectangle               aRepaintPixel;
193     sal_Bool                    bNeedsRepaint;
194 
195     sal_Bool                    bAutoMarkVisible;
196     ScAddress               aAutoMarkPos;
197 
198     sal_Bool                    bListValButton;
199     ScAddress               aListValPos;
200 
201     Rectangle               aInvertRect;
202 
203     DECL_LINK( PopupModeEndHdl, FloatingWindow* );
204     DECL_LINK( PopupSpellingHdl, SpellCallbackInfo* );
205 
206     sal_Bool            TestMouse( const MouseEvent& rMEvt, sal_Bool bAction );
207 
208     sal_Bool            DoPageFieldSelection( SCCOL nCol, SCROW nRow );
209     bool            DoAutoFilterButton( SCCOL nCol, SCROW nRow, const MouseEvent& rMEvt );
210     void            DoPushButton( SCCOL nCol, SCROW nRow, const MouseEvent& rMEvt );
211 
212     void            DPMouseMove( const MouseEvent& rMEvt );
213     void            DPMouseButtonUp( const MouseEvent& rMEvt );
214     void            DPTestMouse( const MouseEvent& rMEvt, sal_Bool bMove );
215 
216     /**
217      * Check if the mouse click is on a field popup button.
218      *
219      * @return bool true if the field popup menu has been launched and no
220      *         further mouse event handling is necessary, false otherwise.
221      */
222     bool            DPTestFieldPopupArrow(const MouseEvent& rMEvt, const ScAddress& rPos, ScDPObject* pDPObj);
223     void            DPLaunchFieldPopupMenu(
224         const Point& rScrPos, const Size& rScrSize, const ScAddress& rPos, ScDPObject* pDPObj);
225 
226     void            RFMouseMove( const MouseEvent& rMEvt, sal_Bool bUp );
227 
228     void            PagebreakMove( const MouseEvent& rMEvt, sal_Bool bUp );
229 
230     void            UpdateDragRect( sal_Bool bShowRange, const Rectangle& rPosRect );
231 
232     sal_Bool            IsAutoFilterActive( SCCOL nCol, SCROW nRow, SCTAB nTab );
233     void            ExecFilter( sal_uLong nSel, SCCOL nCol, SCROW nRow,
234                                 const String& aValue, bool bCheckForDates );
235     void            FilterSelect( sal_uLong nSel );
236 
237     void            ExecDataSelect( SCCOL nCol, SCROW nRow, const String& rStr );
238 
239     void            ExecPageFieldSelect( SCCOL nCol, SCROW nRow, sal_Bool bHasSelection, const String& rStr );
240 
241     sal_Bool            HasScenarioButton( const Point& rPosPixel, ScRange& rScenRange );
242     sal_Bool            HasScenarioRange( sal_uInt16 nCol, sal_Int32 nRow, ScRange& rScenRange );
243     sal_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 );
251 
252     sal_Bool            DrawMouseButtonDown(const MouseEvent& rMEvt);
253     sal_Bool            DrawMouseButtonUp(const MouseEvent& rMEvt);
254     sal_Bool            DrawMouseMove(const MouseEvent& rMEvt);
255     sal_Bool            DrawKeyInput(const KeyEvent& rKEvt);
256     sal_Bool            DrawCommand(const CommandEvent& rCEvt);
257     sal_Bool            DrawHasMarkedObj();
258     void            DrawEndAction();
259     void            DrawMarkDropObj( SdrObject* pObj );
260     SdrObject*      GetEditObject();
261     sal_Bool            IsMyModel(SdrEditView* pSdrView);
262     //void          DrawStartTimer();
263 
264     void            DrawRedraw( ScOutputData& rOutputData, ScUpdateMode eMode, sal_uLong nLayer );
265     void            DrawSdrGrid( const Rectangle& rDrawingRect, OutputDevice* pContentDev );
266     //sal_Bool          DrawBeforeScroll();
267     void            DrawAfterScroll(/*sal_Bool bVal*/);
268     //void          DrawMarks();
269     //sal_Bool          NeedDrawMarks();
270     void            DrawComboButton( const Point&   rCellPos,
271                                      long           nCellSizeX,
272                                      long           nCellSizeY,
273                                      sal_Bool           bArrowState,
274                                      sal_Bool           bBtnIn  = sal_False );
275     Rectangle       GetListValButtonRect( const ScAddress& rButtonPos );
276 
277     void            DrawPagePreview( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2, OutputDevice* pContentDev );
278 
279     sal_Bool            GetEditUrl( const Point& rPos,
280                                 String* pName=0, String* pUrl=0, String* pTarget=0 );
281     sal_Bool            GetEditUrlOrError( sal_Bool bSpellErr, const Point& rPos,
282                                 String* pName=0, String* pUrl=0, String* pTarget=0 );
283 
284     sal_Bool            HitRangeFinder( const Point& rMouse, sal_Bool& rCorner, sal_uInt16* pIndex = NULL,
285                                         SCsCOL* pAddX = NULL, SCsROW* pAddY = NULL );
286 
287     sal_uInt16          HitPageBreak( const Point& rMouse, ScRange* pSource = NULL,
288                                     SCCOLROW* pBreak = NULL, SCCOLROW* pPrev = NULL );
289 
290     void            PasteSelection( const Point& rPosPixel );
291 
292     void            SelectForContextMenu( const Point& rPosPixel, SCsCOL nCellX, SCsROW nCellY );
293 
294     void            GetSelectionRects( ::std::vector< Rectangle >& rPixelRects );
295 
296 protected:
297     using Window::Resize;
298     virtual void    Resize( const Size& rSize );
299     virtual void    PrePaint();
300     virtual void    Paint( const Rectangle& rRect );
301     virtual void    KeyInput(const KeyEvent& rKEvt);
302     virtual void    GetFocus();
303     virtual void    LoseFocus();
304 
305     virtual void    RequestHelp( const HelpEvent& rEvt );
306     virtual void    Command( const CommandEvent& rCEvt );
307 
308     virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt );
309     virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt );
310     virtual void    StartDrag( sal_Int8 nAction, const Point& rPosPixel );
311 
312 public:
313     ScGridWindow( Window* pParent, ScViewData* pData, ScSplitPos eWhichPos );
314     ~ScGridWindow();
315 
316     // #i70788# flush and get overlay
317     ::sdr::overlay::OverlayManager* getOverlayManager();
318     void flushOverlayManager();
319 
320     virtual void    DataChanged( const DataChangedEvent& rDCEvt );
321 
322     virtual void    MouseButtonDown( const MouseEvent& rMEvt );
323     virtual void    MouseButtonUp( const MouseEvent& rMEvt );
324     virtual void    MouseMove( const MouseEvent& rMEvt );
325     virtual long    PreNotify( NotifyEvent& rNEvt );
326     virtual void    Tracking( const TrackingEvent& rTEvt );
327 
328     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible();
329 
330     void            FakeButtonUp();
331 
332     Point           GetMousePosPixel() const;
333     void            UpdateStatusPosSize();
334 
335     void            ClickExtern();
336 
337     void            SetPointer( const Pointer& rPointer );
338 
339     void            MoveMouseStatus( ScGridWindow &rDestWin );
340 
341     void            ScrollPixel( long nDifX, long nDifY );
342     void            UpdateEditViewPos();
343 
344     void            UpdateFormulas();
345 
346     void            DoAutoFilterMenue( SCCOL nCol, SCROW nRow, sal_Bool bDataSelect );
347     void            DoScenarioMenue( const ScRange& rScenRange );
348 
349     void            LaunchPageFieldMenu( SCCOL nCol, SCROW nRow );
350     void            LaunchDPFieldMenu( SCCOL nCol, SCROW nRow );
351 
352     ::com::sun::star::sheet::DataPilotFieldOrientation GetDPFieldOrientation( SCCOL nCol, SCROW nRow ) const;
353 
354     void            DrawButtons( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
355                                     ScTableInfo& rTabInfo, OutputDevice* pContentDev );
356 
357     using Window::Draw;
358     void            Draw( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
359                         ScUpdateMode eMode = SC_UPDATE_ALL );
360 
361     void            InvertSimple( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
362                                     sal_Bool bTestMerge = sal_False, sal_Bool bRepeat = sal_False );
363 
364 //UNUSED2008-05  void           DrawDragRect( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2 );
365 
366     void            CreateAnchorHandle(SdrHdlList& rHdl, const ScAddress& rAddress);
367 
368     void            HideCursor();
369     void            ShowCursor();
370     void            DrawCursor();
371     void            DrawAutoFillMark();
372     void            UpdateAutoFillMark(sal_Bool bMarked, const ScRange& rMarkRange);
373 
374     void            UpdateListValPos( sal_Bool bVisible, const ScAddress& rPos );
375 
376     sal_Bool            ShowNoteMarker( SCsCOL nPosX, SCsROW nPosY, sal_Bool bKeyboard );
377     void            HideNoteMarker();
378 
379     MapMode         GetDrawMapMode( sal_Bool bForce = sal_False );
380 
381     void            ContinueDrag();
382 
383     void            StopMarking();
384     void            UpdateInputContext();
385 
CheckInverted()386     void            CheckInverted()     { if (nPaintCount) bNeedsRepaint = sal_True; }
387 
388     void            DoInvertRect( const Rectangle& rPixel );
389 
390     void            CheckNeedsRepaint();
391     virtual void SwitchView();
392 
393     void            UpdateDPFromFieldPopupMenu();
394 
395     void            UpdateVisibleRange();
396 
397     // #114409#
398     void CursorChanged();
399     void DrawLayerCreated();
400 
401     void            DeleteCursorOverlay();
402     void            UpdateCursorOverlay();
403     void            DeleteSelectionOverlay();
404     void            UpdateSelectionOverlay();
405     void            DeleteAutoFillOverlay();
406     void            UpdateAutoFillOverlay();
407     void            DeleteDragRectOverlay();
408     void            UpdateDragRectOverlay();
409     void            DeleteHeaderOverlay();
410     void            UpdateHeaderOverlay();
411     void            DeleteShrinkOverlay();
412     void            UpdateShrinkOverlay();
413     void            UpdateAllOverlays();
414 
415 protected:
416     // #114409#
417     void ImpCreateOverlayObjects();
418     void ImpDestroyOverlayObjects();
419 
420 };
421 
422 
423 
424 #endif
425 
426