Update ooo320-m1
[ooovba.git] / sc / source / ui / drawfunc / fupoor.cxx
blobd181385fabdaf8724909ef7187bca0bf4a98758d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fupoor.cxx,v $
10 * $Revision: 1.13.128.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include <svx/outliner.hxx>
35 #include <svx/svditer.hxx>
36 #include <svx/svdobj.hxx>
37 #include <svx/svdpagv.hxx>
39 #include "fupoor.hxx"
40 #include "tabvwsh.hxx"
41 #include "drawview.hxx"
42 #include "detfunc.hxx"
43 #include "document.hxx"
44 #include <vcl/svapp.hxx>
45 #include <svx/sdrhittesthelper.hxx>
47 /*************************************************************************
49 |* Konstruktor
51 \************************************************************************/
53 FuPoor::FuPoor(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
54 SdrModel* pDoc, SfxRequest& rReq) :
55 pView(pViewP),
56 pViewShell(pViewSh),
57 pWindow(pWin),
58 pDrDoc(pDoc),
59 aSfxRequest(rReq),
60 pDialog(NULL),
61 bIsInDragMode(FALSE),
62 // #95491# remember MouseButton state
63 mnCode(0)
65 aScrollTimer.SetTimeoutHdl( LINK(this, FuPoor, ScrollHdl) );
66 aScrollTimer.SetTimeout(SELENG_AUTOREPEAT_INTERVAL);
68 aDragTimer.SetTimeoutHdl( LINK(this, FuPoor, DragTimerHdl) );
69 aDragTimer.SetTimeout(SELENG_DRAGDROP_TIMEOUT);
72 /*************************************************************************
74 |* Destruktor
76 \************************************************************************/
78 FuPoor::~FuPoor()
80 aDragTimer.Stop();
81 aScrollTimer.Stop();
83 if (pDialog)
84 delete pDialog;
87 /*************************************************************************
89 |* Function aktivieren
91 \************************************************************************/
93 void FuPoor::Activate()
95 if (pDialog)
97 pDialog->Show();
101 /*************************************************************************
103 |* Function deaktivieren
105 \************************************************************************/
107 void FuPoor::Deactivate()
109 aDragTimer.Stop();
110 aScrollTimer.Stop();
112 if (pDialog)
114 pDialog->Hide();
118 /*************************************************************************
120 |* Scrollen bei Erreichen des Fensterrandes; wird von
121 |* MouseMove aufgerufen
123 \************************************************************************/
125 void FuPoor::ForceScroll(const Point& aPixPos)
127 aScrollTimer.Stop();
129 Size aSize = pWindow->GetSizePixel();
130 SCsCOL dx = 0;
131 SCsROW dy = 0;
133 if ( aPixPos.X() <= 0 ) dx = -1;
134 if ( aPixPos.X() >= aSize.Width() ) dx = 1;
135 if ( aPixPos.Y() <= 0 ) dy = -1;
136 if ( aPixPos.Y() >= aSize.Height() ) dy = 1;
138 ScViewData* pViewData = pViewShell->GetViewData();
139 if ( pViewData->GetDocument()->IsNegativePage( pViewData->GetTabNo() ) )
140 dx = -dx;
142 ScSplitPos eWhich = pViewData->GetActivePart();
143 if ( dx > 0 && pViewData->GetHSplitMode() == SC_SPLIT_FIX && WhichH(eWhich) == SC_SPLIT_LEFT )
145 pViewShell->ActivatePart( ( eWhich == SC_SPLIT_TOPLEFT ) ?
146 SC_SPLIT_TOPRIGHT : SC_SPLIT_BOTTOMRIGHT );
147 dx = 0;
149 if ( dy > 0 && pViewData->GetVSplitMode() == SC_SPLIT_FIX && WhichV(eWhich) == SC_SPLIT_TOP )
151 pViewShell->ActivatePart( ( eWhich == SC_SPLIT_TOPLEFT ) ?
152 SC_SPLIT_BOTTOMLEFT : SC_SPLIT_BOTTOMRIGHT );
153 dy = 0;
156 if ( dx != 0 || dy != 0 )
158 ScrollStart(); // Scrollaktion in abgeleiteter Klasse
159 pViewShell->ScrollLines(2*dx, 4*dy);
160 ScrollEnd();
161 aScrollTimer.Start();
165 /*************************************************************************
167 |* Timer-Handler fuer Fensterscrolling
169 \************************************************************************/
171 IMPL_LINK_INLINE_START( FuPoor, ScrollHdl, Timer *, EMPTYARG )
173 Point aPosPixel = pWindow->GetPointerPosPixel();
175 // #95491# use remembered MouseButton state to create correct
176 // MouseEvents for this artifical MouseMove.
177 MouseMove(MouseEvent(aPosPixel, 1, 0, GetMouseButtonCode()));
179 return 0;
181 IMPL_LINK_INLINE_END( FuPoor, ScrollHdl, Timer *, pTimer )
183 // #95491# moved from inline to *.cxx
184 BOOL FuPoor::MouseButtonUp(const MouseEvent& rMEvt)
186 // #95491# remember button state for creation of own MouseEvents
187 SetMouseButtonCode(rMEvt.GetButtons());
189 return FALSE;
192 // #95491# moved from inline to *.cxx
193 BOOL FuPoor::MouseButtonDown(const MouseEvent& rMEvt)
195 // #95491# remember button state for creation of own MouseEvents
196 SetMouseButtonCode(rMEvt.GetButtons());
198 return FALSE;
201 /*************************************************************************
203 |* String in Applikations-Statuszeile ausgeben
205 \************************************************************************/
207 // WriteStatus gibt's nicht mehr
209 /*************************************************************************
211 |* Tastaturereignisse bearbeiten
213 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert TRUE, andernfalls
214 |* FALSE.
216 \************************************************************************/
218 BOOL FuPoor::KeyInput(const KeyEvent& /* rKEvt */)
220 BOOL bReturn = FALSE;
222 return(bReturn);
225 BYTE FuPoor::Command(const CommandEvent& rCEvt)
227 if ( COMMAND_STARTDRAG == rCEvt.GetCommand() )
229 //!!! sollte Joe eigentlich machen:
230 // nur, wenn im Outliner was selektiert ist, darf
231 // Command TRUE zurueckliefern:
233 OutlinerView* pOutView = pView->GetTextEditOutlinerView();
235 if ( pOutView )
236 return pOutView->HasSelection() ? pView->Command(rCEvt,pWindow) : SC_CMD_NONE;
237 else
238 return pView->Command(rCEvt,pWindow);
240 else
241 return pView->Command(rCEvt,pWindow);
244 /*************************************************************************
246 |* Cut object to clipboard
248 \************************************************************************/
250 void FuPoor::DoCut()
252 if (pView)
254 //! pView->DoCut(pWindow);
258 /*************************************************************************
260 |* Copy object to clipboard
262 \************************************************************************/
264 void FuPoor::DoCopy()
266 if (pView)
268 //! pView->DoCopy(pWindow);
272 /*************************************************************************
274 |* Paste object from clipboard
276 \************************************************************************/
278 void FuPoor::DoPaste()
280 if (pView)
282 //! pView->DoPaste(pWindow);
286 /*************************************************************************
288 |* Timer-Handler fuer Drag&Drop
290 \************************************************************************/
292 IMPL_LINK( FuPoor, DragTimerHdl, Timer *, EMPTYARG )
294 // ExecuteDrag (und das damit verbundene Reschedule) direkt aus dem Timer
295 // aufzurufen, bringt die VCL-Timer-Verwaltung durcheinander, wenn dabei
296 // (z.B. im Drop) wieder ein Timer gestartet wird (z.B. ComeBack-Timer der
297 // DrawView fuer Solid Handles / ModelHasChanged) - der neue Timer laeuft
298 // dann um die Dauer des Drag&Drop zu spaet ab.
299 // Darum Drag&Drop aus eigenem Event:
301 Application::PostUserEvent( LINK( this, FuPoor, DragHdl ) );
302 return 0;
305 IMPL_LINK( FuPoor, DragHdl, void *, EMPTYARG )
307 SdrHdl* pHdl = pView->PickHandle(aMDPos);
309 if ( pHdl==NULL && pView->IsMarkedHit(aMDPos) )
311 pWindow->ReleaseMouse();
312 bIsInDragMode = TRUE;
314 // pView->BeginDrag(pWindow, aMDPos);
315 pViewShell->GetScDrawView()->BeginDrag(pWindow, aMDPos);
317 return 0;
320 // Detektiv-Linie
322 BOOL FuPoor::IsDetectiveHit( const Point& rLogicPos )
324 SdrPageView* pPV = pView->GetSdrPageView();
325 if (!pPV)
326 return FALSE;
328 BOOL bFound = FALSE;
329 SdrObjListIter aIter( *pPV->GetObjList(), IM_FLAT );
330 SdrObject* pObject = aIter.Next();
331 while (pObject && !bFound)
333 if (ScDetectiveFunc::IsNonAlienArrow( pObject ))
335 USHORT nHitLog = (USHORT) pWindow->PixelToLogic(
336 Size(pView->GetHitTolerancePixel(),0)).Width();
337 if(SdrObjectPrimitiveHit(*pObject, rLogicPos, nHitLog, *pPV, 0, false))
339 bFound = TRUE;
343 pObject = aIter.Next();
345 return bFound;
348 void FuPoor::StopDragTimer()
350 if (aDragTimer.IsActive() )
351 aDragTimer.Stop();
354 /*************************************************************************
356 |* #98185# Create default drawing objects via keyboard
358 \************************************************************************/
360 SdrObject* FuPoor::CreateDefaultObject(const sal_uInt16 /* nID */, const Rectangle& /* rRectangle */)
362 // empty base implementation
363 return 0L;
366 void FuPoor::ImpForceQuadratic(Rectangle& rRect)
368 if(rRect.GetWidth() > rRect.GetHeight())
370 rRect = Rectangle(
371 Point(rRect.Left() + ((rRect.GetWidth() - rRect.GetHeight()) / 2), rRect.Top()),
372 Size(rRect.GetHeight(), rRect.GetHeight()));
374 else
376 rRect = Rectangle(
377 Point(rRect.Left(), rRect.Top() + ((rRect.GetHeight() - rRect.GetWidth()) / 2)),
378 Size(rRect.GetWidth(), rRect.GetWidth()));
382 // #i33136#
383 bool FuPoor::doConstructOrthogonal() const
385 return false;
388 // eof