xref: /trunk/main/sc/source/ui/drawfunc/fupoor.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 #include <editeng/outliner.hxx>
32 #include <svx/svditer.hxx>
33 #include <svx/svdobj.hxx>
34 #include <svx/svdpagv.hxx>
35 
36 #include "fupoor.hxx"
37 #include "tabvwsh.hxx"
38 #include "drawview.hxx"
39 #include "detfunc.hxx"
40 #include "document.hxx"
41 #include <vcl/svapp.hxx>
42 #include <svx/sdrhittesthelper.hxx>
43 
44 /*************************************************************************
45 |*
46 |* Konstruktor
47 |*
48 \************************************************************************/
49 
50 FuPoor::FuPoor(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
51                SdrModel* pDoc, SfxRequest& rReq) :
52     pView(pViewP),
53     pViewShell(pViewSh),
54     pWindow(pWin),
55     pDrDoc(pDoc),
56     aSfxRequest(rReq),
57     pDialog(NULL),
58     bIsInDragMode(sal_False),
59     // #95491# remember MouseButton state
60     mnCode(0)
61 {
62     aScrollTimer.SetTimeoutHdl( LINK(this, FuPoor, ScrollHdl) );
63     aScrollTimer.SetTimeout(SELENG_AUTOREPEAT_INTERVAL);
64 
65     aDragTimer.SetTimeoutHdl( LINK(this, FuPoor, DragTimerHdl) );
66     aDragTimer.SetTimeout(SELENG_DRAGDROP_TIMEOUT);
67 }
68 
69 /*************************************************************************
70 |*
71 |* Destruktor
72 |*
73 \************************************************************************/
74 
75 FuPoor::~FuPoor()
76 {
77     aDragTimer.Stop();
78     aScrollTimer.Stop();
79 
80     if (pDialog)
81         delete pDialog;
82 }
83 
84 /*************************************************************************
85 |*
86 |* Function aktivieren
87 |*
88 \************************************************************************/
89 
90 void FuPoor::Activate()
91 {
92     if (pDialog)
93     {
94         pDialog->Show();
95     }
96 }
97 
98 /*************************************************************************
99 |*
100 |* Function deaktivieren
101 |*
102 \************************************************************************/
103 
104 void FuPoor::Deactivate()
105 {
106     aDragTimer.Stop();
107     aScrollTimer.Stop();
108 
109     if (pDialog)
110     {
111         pDialog->Hide();
112     }
113 }
114 
115 /*************************************************************************
116 |*
117 |* Scrollen bei Erreichen des Fensterrandes; wird von
118 |* MouseMove aufgerufen
119 |*
120 \************************************************************************/
121 
122 void FuPoor::ForceScroll(const Point& aPixPos)
123 {
124     aScrollTimer.Stop();
125 
126     Size aSize = pWindow->GetSizePixel();
127     SCsCOL dx = 0;
128     SCsROW dy = 0;
129 
130     if ( aPixPos.X() <= 0              ) dx = -1;
131     if ( aPixPos.X() >= aSize.Width()  ) dx =  1;
132     if ( aPixPos.Y() <= 0              ) dy = -1;
133     if ( aPixPos.Y() >= aSize.Height() ) dy =  1;
134 
135     ScViewData* pViewData = pViewShell->GetViewData();
136     if ( pViewData->GetDocument()->IsNegativePage( pViewData->GetTabNo() ) )
137         dx = -dx;
138 
139     ScSplitPos eWhich = pViewData->GetActivePart();
140     if ( dx > 0 && pViewData->GetHSplitMode() == SC_SPLIT_FIX && WhichH(eWhich) == SC_SPLIT_LEFT )
141     {
142         pViewShell->ActivatePart( ( eWhich == SC_SPLIT_TOPLEFT ) ?
143                         SC_SPLIT_TOPRIGHT : SC_SPLIT_BOTTOMRIGHT );
144         dx = 0;
145     }
146     if ( dy > 0 && pViewData->GetVSplitMode() == SC_SPLIT_FIX && WhichV(eWhich) == SC_SPLIT_TOP )
147     {
148         pViewShell->ActivatePart( ( eWhich == SC_SPLIT_TOPLEFT ) ?
149                         SC_SPLIT_BOTTOMLEFT : SC_SPLIT_BOTTOMRIGHT );
150         dy = 0;
151     }
152 
153     if ( dx != 0 || dy != 0 )
154     {
155         ScrollStart();                          // Scrollaktion in abgeleiteter Klasse
156         pViewShell->ScrollLines(2*dx, 4*dy);
157         ScrollEnd();
158         aScrollTimer.Start();
159     }
160 }
161 
162 /*************************************************************************
163 |*
164 |* Timer-Handler fuer Fensterscrolling
165 |*
166 \************************************************************************/
167 
168 IMPL_LINK_INLINE_START( FuPoor, ScrollHdl, Timer *, EMPTYARG )
169 {
170     Point aPosPixel = pWindow->GetPointerPosPixel();
171 
172     // #95491# use remembered MouseButton state to create correct
173     // MouseEvents for this artifical MouseMove.
174     MouseMove(MouseEvent(aPosPixel, 1, 0, GetMouseButtonCode()));
175 
176     return 0;
177 }
178 IMPL_LINK_INLINE_END( FuPoor, ScrollHdl, Timer *, pTimer )
179 
180 // #95491# moved from inline to *.cxx
181 sal_Bool FuPoor::MouseButtonUp(const MouseEvent& rMEvt)
182 {
183     // #95491# remember button state for creation of own MouseEvents
184     SetMouseButtonCode(rMEvt.GetButtons());
185 
186     return sal_False;
187 }
188 
189 // #95491# moved from inline to *.cxx
190 sal_Bool FuPoor::MouseButtonDown(const MouseEvent& rMEvt)
191 {
192     // #95491# remember button state for creation of own MouseEvents
193     SetMouseButtonCode(rMEvt.GetButtons());
194 
195     return sal_False;
196 }
197 
198 /*************************************************************************
199 |*
200 |* String in Applikations-Statuszeile ausgeben
201 |*
202 \************************************************************************/
203 
204 //  WriteStatus gibt's nicht mehr
205 
206 /*************************************************************************
207 |*
208 |* Tastaturereignisse bearbeiten
209 |*
210 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
211 |* FALSE.
212 |*
213 \************************************************************************/
214 
215 sal_Bool FuPoor::KeyInput(const KeyEvent& /* rKEvt */)
216 {
217     sal_Bool bReturn = sal_False;
218 
219     return(bReturn);
220 }
221 
222 sal_uInt8 FuPoor::Command(const CommandEvent& rCEvt)
223 {
224     if ( COMMAND_STARTDRAG == rCEvt.GetCommand() )
225     {
226         //!!! sollte Joe eigentlich machen:
227         // nur, wenn im Outliner was selektiert ist, darf
228         // Command sal_True zurueckliefern:
229 
230         OutlinerView* pOutView = pView->GetTextEditOutlinerView();
231 
232         if ( pOutView )
233             return pOutView->HasSelection() ? pView->Command(rCEvt,pWindow) : SC_CMD_NONE;
234         else
235             return pView->Command(rCEvt,pWindow);
236     }
237     else
238         return pView->Command(rCEvt,pWindow);
239 }
240 
241 /*************************************************************************
242 |*
243 |* Cut object to clipboard
244 |*
245 \************************************************************************/
246 
247 void FuPoor::DoCut()
248 {
249     if (pView)
250     {
251 //!     pView->DoCut(pWindow);
252     }
253 }
254 
255 /*************************************************************************
256 |*
257 |* Copy object to clipboard
258 |*
259 \************************************************************************/
260 
261 void FuPoor::DoCopy()
262 {
263     if (pView)
264     {
265 //!     pView->DoCopy(pWindow);
266     }
267 }
268 
269 /*************************************************************************
270 |*
271 |* Paste object from clipboard
272 |*
273 \************************************************************************/
274 
275 void FuPoor::DoPaste()
276 {
277     if (pView)
278     {
279 //!     pView->DoPaste(pWindow);
280     }
281 }
282 
283 /*************************************************************************
284 |*
285 |* Timer-Handler fuer Drag&Drop
286 |*
287 \************************************************************************/
288 
289 IMPL_LINK( FuPoor, DragTimerHdl, Timer *, EMPTYARG )
290 {
291     //  ExecuteDrag (und das damit verbundene Reschedule) direkt aus dem Timer
292     //  aufzurufen, bringt die VCL-Timer-Verwaltung durcheinander, wenn dabei
293     //  (z.B. im Drop) wieder ein Timer gestartet wird (z.B. ComeBack-Timer der
294     //  DrawView fuer Solid Handles / ModelHasChanged) - der neue Timer laeuft
295     //  dann um die Dauer des Drag&Drop zu spaet ab.
296     //  Darum Drag&Drop aus eigenem Event:
297 
298     Application::PostUserEvent( LINK( this, FuPoor, DragHdl ) );
299     return 0;
300 }
301 
302 IMPL_LINK( FuPoor, DragHdl, void *, EMPTYARG )
303 {
304     SdrHdl* pHdl = pView->PickHandle(aMDPos);
305 
306     if ( pHdl==NULL && pView->IsMarkedHit(aMDPos) )
307     {
308         pWindow->ReleaseMouse();
309         bIsInDragMode = sal_True;
310 
311 //      pView->BeginDrag(pWindow, aMDPos);
312         pViewShell->GetScDrawView()->BeginDrag(pWindow, aMDPos);
313     }
314     return 0;
315 }
316 
317 //  Detektiv-Linie
318 
319 sal_Bool FuPoor::IsDetectiveHit( const Point& rLogicPos )
320 {
321     SdrPageView* pPV = pView->GetSdrPageView();
322     if (!pPV)
323         return sal_False;
324 
325     sal_Bool bFound = sal_False;
326     SdrObjListIter aIter( *pPV->GetObjList(), IM_FLAT );
327     SdrObject* pObject = aIter.Next();
328     while (pObject && !bFound)
329     {
330         if (ScDetectiveFunc::IsNonAlienArrow( pObject ))
331         {
332             sal_uInt16 nHitLog = (sal_uInt16) pWindow->PixelToLogic(
333                                 Size(pView->GetHitTolerancePixel(),0)).Width();
334             if(SdrObjectPrimitiveHit(*pObject, rLogicPos, nHitLog, *pPV, 0, false))
335             {
336                 bFound = sal_True;
337             }
338         }
339 
340         pObject = aIter.Next();
341     }
342     return bFound;
343 }
344 
345 void FuPoor::StopDragTimer()
346 {
347     if (aDragTimer.IsActive() )
348         aDragTimer.Stop();
349 }
350 
351 /*************************************************************************
352 |*
353 |* #98185# Create default drawing objects via keyboard
354 |*
355 \************************************************************************/
356 
357 SdrObject* FuPoor::CreateDefaultObject(const sal_uInt16 /* nID */, const Rectangle& /* rRectangle */)
358 {
359     // empty base implementation
360     return 0L;
361 }
362 
363 void FuPoor::ImpForceQuadratic(Rectangle& rRect)
364 {
365     if(rRect.GetWidth() > rRect.GetHeight())
366     {
367         rRect = Rectangle(
368             Point(rRect.Left() + ((rRect.GetWidth() - rRect.GetHeight()) / 2), rRect.Top()),
369             Size(rRect.GetHeight(), rRect.GetHeight()));
370     }
371     else
372     {
373         rRect = Rectangle(
374             Point(rRect.Left(), rRect.Top() + ((rRect.GetHeight() - rRect.GetWidth()) / 2)),
375             Size(rRect.GetWidth(), rRect.GetWidth()));
376     }
377 }
378 
379 // #i33136#
380 bool FuPoor::doConstructOrthogonal() const
381 {
382     return false;
383 }
384 
385 // eof
386