Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / drawfunc / fupoor.cxx
blobf6d3cd10e9366f0dbeaaa398a52641bdc19c985a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <editeng/outliner.hxx>
22 #include <svx/svditer.hxx>
23 #include <svx/svdobj.hxx>
24 #include <svx/svdpagv.hxx>
26 #include "fupoor.hxx"
27 #include "tabvwsh.hxx"
28 #include "drawview.hxx"
29 #include "detfunc.hxx"
30 #include "document.hxx"
31 #include <vcl/svapp.hxx>
32 #include <svx/sdrhittesthelper.hxx>
34 FuPoor::FuPoor(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
35 SdrModel* pDoc, SfxRequest& rReq) :
36 pView(pViewP),
37 pViewShell(pViewSh),
38 pWindow(pWin),
39 pDrDoc(pDoc),
40 aSfxRequest(rReq),
41 pDialog(NULL),
42 bIsInDragMode(false),
43 // remember MouseButton state
44 mnCode(0)
46 aScrollTimer.SetTimeoutHdl( LINK(this, FuPoor, ScrollHdl) );
47 aScrollTimer.SetTimeout(SELENG_AUTOREPEAT_INTERVAL);
49 aDragTimer.SetTimeoutHdl( LINK(this, FuPoor, DragTimerHdl) );
50 aDragTimer.SetTimeout(SELENG_DRAGDROP_TIMEOUT);
53 FuPoor::~FuPoor()
55 aDragTimer.Stop();
56 aScrollTimer.Stop();
58 delete pDialog;
61 void FuPoor::Activate()
63 if (pDialog)
65 pDialog->Show();
69 void FuPoor::Deactivate()
71 aDragTimer.Stop();
72 aScrollTimer.Stop();
74 if (pDialog)
76 pDialog->Hide();
80 /*************************************************************************
82 |* Scrollen bei Erreichen des Fensterrandes; wird von
83 |* MouseMove aufgerufen
85 \************************************************************************/
87 void FuPoor::ForceScroll(const Point& aPixPos)
89 aScrollTimer.Stop();
91 Size aSize = pWindow->GetSizePixel();
92 SCsCOL dx = 0;
93 SCsROW dy = 0;
95 if ( aPixPos.X() <= 0 ) dx = -1;
96 if ( aPixPos.X() >= aSize.Width() ) dx = 1;
97 if ( aPixPos.Y() <= 0 ) dy = -1;
98 if ( aPixPos.Y() >= aSize.Height() ) dy = 1;
100 ScViewData* pViewData = pViewShell->GetViewData();
101 if ( pViewData->GetDocument()->IsNegativePage( pViewData->GetTabNo() ) )
102 dx = -dx;
104 ScSplitPos eWhich = pViewData->GetActivePart();
105 if ( dx > 0 && pViewData->GetHSplitMode() == SC_SPLIT_FIX && WhichH(eWhich) == SC_SPLIT_LEFT )
107 pViewShell->ActivatePart( ( eWhich == SC_SPLIT_TOPLEFT ) ?
108 SC_SPLIT_TOPRIGHT : SC_SPLIT_BOTTOMRIGHT );
109 dx = 0;
111 if ( dy > 0 && pViewData->GetVSplitMode() == SC_SPLIT_FIX && WhichV(eWhich) == SC_SPLIT_TOP )
113 pViewShell->ActivatePart( ( eWhich == SC_SPLIT_TOPLEFT ) ?
114 SC_SPLIT_BOTTOMLEFT : SC_SPLIT_BOTTOMRIGHT );
115 dy = 0;
118 if ( dx != 0 || dy != 0 )
120 pViewShell->ScrollLines(2*dx, 4*dy);
121 aScrollTimer.Start();
125 /*************************************************************************
127 |* Timer-Handler fuer Fensterscrolling
129 \************************************************************************/
131 IMPL_LINK_NOARG_INLINE_START(FuPoor, ScrollHdl)
133 Point aPosPixel = pWindow->GetPointerPosPixel();
135 // use remembered MouseButton state to create correct
136 // MouseEvents for this artifical MouseMove.
137 MouseMove(MouseEvent(aPosPixel, 1, 0, GetMouseButtonCode()));
139 return 0;
141 IMPL_LINK_INLINE_END( FuPoor, ScrollHdl, Timer *, pTimer )
143 // moved from inline to *.cxx
144 sal_Bool FuPoor::MouseButtonUp(const MouseEvent& rMEvt)
146 // remember button state for creation of own MouseEvents
147 SetMouseButtonCode(rMEvt.GetButtons());
149 return false;
152 // moved from inline to *.cxx
153 sal_Bool FuPoor::MouseButtonDown(const MouseEvent& rMEvt)
155 // remember button state for creation of own MouseEvents
156 SetMouseButtonCode(rMEvt.GetButtons());
158 return false;
161 /*************************************************************************
163 |* String in Applikations-Statuszeile ausgeben
165 \************************************************************************/
167 // WriteStatus gibt's nicht mehr
169 /*************************************************************************
171 |* Tastaturereignisse bearbeiten
173 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
174 |* FALSE.
176 \************************************************************************/
178 sal_Bool FuPoor::KeyInput(const KeyEvent& /* rKEvt */)
180 sal_Bool bReturn = false;
182 return(bReturn);
185 sal_uInt8 FuPoor::Command(const CommandEvent& rCEvt)
187 if ( COMMAND_STARTDRAG == rCEvt.GetCommand() )
189 //!!! sollte Joe eigentlich machen:
190 // nur, wenn im Outliner was selektiert ist, darf
191 // Command sal_True zurueckliefern:
193 OutlinerView* pOutView = pView->GetTextEditOutlinerView();
195 if ( pOutView )
196 return pOutView->HasSelection() ? pView->Command(rCEvt,pWindow) : SC_CMD_NONE;
197 else
198 return pView->Command(rCEvt,pWindow);
200 else
201 return pView->Command(rCEvt,pWindow);
204 void FuPoor::DoCut()
206 if (pView)
208 //! pView->DoCut(pWindow);
212 /*************************************************************************
214 |* Copy object to clipboard
216 \************************************************************************/
218 void FuPoor::DoCopy()
220 if (pView)
222 //! pView->DoCopy(pWindow);
226 void FuPoor::DoPaste()
228 if (pView)
230 //! pView->DoPaste(pWindow);
234 /*************************************************************************
236 |* Timer-Handler fuer Drag&Drop
238 \************************************************************************/
240 IMPL_LINK_NOARG(FuPoor, DragTimerHdl)
242 // ExecuteDrag (und das damit verbundene Reschedule) direkt aus dem Timer
243 // aufzurufen, bringt die VCL-Timer-Verwaltung durcheinander, wenn dabei
244 // (z.B. im Drop) wieder ein Timer gestartet wird (z.B. ComeBack-Timer der
245 // DrawView fuer Solid Handles / ModelHasChanged) - der neue Timer laeuft
246 // dann um die Dauer des Drag&Drop zu spaet ab.
247 // Darum Drag&Drop aus eigenem Event:
249 Application::PostUserEvent( LINK( this, FuPoor, DragHdl ) );
250 return 0;
253 IMPL_LINK_NOARG(FuPoor, DragHdl)
255 SdrHdl* pHdl = pView->PickHandle(aMDPos);
257 if ( pHdl==NULL && pView->IsMarkedHit(aMDPos) )
259 pWindow->ReleaseMouse();
260 bIsInDragMode = sal_True;
262 // pView->BeginDrag(pWindow, aMDPos);
263 pViewShell->GetScDrawView()->BeginDrag(pWindow, aMDPos);
265 return 0;
268 // Detektiv-Linie
270 sal_Bool FuPoor::IsDetectiveHit( const Point& rLogicPos )
272 SdrPageView* pPV = pView->GetSdrPageView();
273 if (!pPV)
274 return false;
276 sal_Bool bFound = false;
277 SdrObjListIter aIter( *pPV->GetObjList(), IM_FLAT );
278 SdrObject* pObject = aIter.Next();
279 while (pObject && !bFound)
281 if (ScDetectiveFunc::IsNonAlienArrow( pObject ))
283 sal_uInt16 nHitLog = (sal_uInt16) pWindow->PixelToLogic(
284 Size(pView->GetHitTolerancePixel(),0)).Width();
285 if(SdrObjectPrimitiveHit(*pObject, rLogicPos, nHitLog, *pPV, 0, false))
287 bFound = sal_True;
291 pObject = aIter.Next();
293 return bFound;
296 void FuPoor::StopDragTimer()
298 if (aDragTimer.IsActive() )
299 aDragTimer.Stop();
302 /*************************************************************************
304 |* Create default drawing objects via keyboard
306 \************************************************************************/
308 SdrObject* FuPoor::CreateDefaultObject(const sal_uInt16 /* nID */, const Rectangle& /* rRectangle */)
310 // empty base implementation
311 return 0L;
314 void FuPoor::ImpForceQuadratic(Rectangle& rRect)
316 if(rRect.GetWidth() > rRect.GetHeight())
318 rRect = Rectangle(
319 Point(rRect.Left() + ((rRect.GetWidth() - rRect.GetHeight()) / 2), rRect.Top()),
320 Size(rRect.GetHeight(), rRect.GetHeight()));
322 else
324 rRect = Rectangle(
325 Point(rRect.Left(), rRect.Top() + ((rRect.GetHeight() - rRect.GetWidth()) / 2)),
326 Size(rRect.GetWidth(), rRect.GetWidth()));
330 // #i33136#
331 bool FuPoor::doConstructOrthogonal() const
333 return false;
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */