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 : #include <hintids.hxx>
21 :
22 :
23 : #include <svx/svdview.hxx>
24 : #include <editeng/outliner.hxx>
25 : #include <svx/svdobj.hxx>
26 : #include <sot/exchange.hxx>
27 : #include <sot/formats.hxx>
28 : #include <sfx2/bindings.hxx>
29 :
30 : #include <sfx2/viewfrm.hxx>
31 : #include <fmturl.hxx>
32 : #include <frmfmt.hxx>
33 : #include <wrtsh.hxx>
34 : #include <edtwin.hxx>
35 : #include <view.hxx>
36 : #include <viewopt.hxx>
37 : #include <swdtflvr.hxx>
38 : #include <swmodule.hxx>
39 : #include <docsh.hxx>
40 : #include <wdocsh.hxx>
41 : #include <swundo.hxx>
42 :
43 : using namespace ::com::sun::star;
44 :
45 : // no include "dbgoutsw.hxx" here!!!!!!
46 :
47 : extern sal_Bool bNoInterrupt;
48 : extern sal_Bool bFrmDrag;
49 : extern sal_Bool bDDTimerStarted;
50 :
51 : sal_Bool bExecuteDrag = sal_False;
52 :
53 0 : void SwEditWin::StartDDTimer()
54 : {
55 0 : aTimer.SetTimeoutHdl(LINK(this, SwEditWin, DDHandler));
56 0 : aTimer.SetTimeout(480);
57 0 : aTimer.Start();
58 0 : bDDTimerStarted = sal_True;
59 0 : }
60 :
61 :
62 0 : void SwEditWin::StopDDTimer(SwWrtShell *pSh, const Point &rPt)
63 : {
64 0 : aTimer.Stop();
65 0 : bDDTimerStarted = sal_False;
66 0 : if(!pSh->IsSelFrmMode())
67 0 : pSh->SetCursor(&rPt, false);
68 0 : aTimer.SetTimeoutHdl(LINK(this,SwEditWin, TimerHandler));
69 0 : }
70 :
71 0 : void SwEditWin::StartDrag( sal_Int8 /*nAction*/, const Point& rPosPixel )
72 : {
73 0 : SwWrtShell &rSh = rView.GetWrtShell();
74 0 : if( rSh.GetDrawView() )
75 : {
76 0 : CommandEvent aDragEvent( rPosPixel, COMMAND_STARTDRAG, sal_True );
77 0 : if( rSh.GetDrawView()->Command( aDragEvent, this ) )
78 : {
79 0 : rView.GetViewFrame()->GetBindings().InvalidateAll(sal_False);
80 0 : return; // Event von der SdrView ausgewertet
81 : }
82 : }
83 :
84 0 : if ( !pApplyTempl && !rSh.IsDrawCreate() && !IsDrawAction())
85 : {
86 0 : sal_Bool bStart = sal_False, bDelSelect = sal_False;
87 0 : SdrObject *pObj = NULL;
88 0 : Point aDocPos( PixelToLogic( rPosPixel ) );
89 0 : if ( !rSh.IsInSelect() && rSh.ChgCurrPam( aDocPos, sal_True, sal_True))
90 : //We are not selecting and aren't at a selection
91 0 : bStart = sal_True;
92 0 : else if ( !bFrmDrag && rSh.IsSelFrmMode() &&
93 0 : rSh.IsInsideSelectedObj( aDocPos ) )
94 : {
95 : //We are not dragging internally and are not at an
96 : //object (frame, draw object)
97 :
98 0 : bStart = sal_True;
99 : }
100 0 : else if( !bFrmDrag && rView.GetDocShell()->IsReadOnly() &&
101 0 : OBJCNT_NONE != rSh.GetObjCntType( aDocPos, pObj ))
102 : {
103 0 : rSh.LockPaint();
104 0 : if( rSh.SelectObj( aDocPos, 0, pObj ))
105 0 : bStart = bDelSelect = sal_True;
106 : else
107 0 : rSh.UnlockPaint();
108 : }
109 : else
110 : {
111 0 : SwContentAtPos aSwContentAtPos( SwContentAtPos::SW_INETATTR );
112 : bStart = rSh.GetContentAtPos( aDocPos,
113 : aSwContentAtPos,
114 0 : sal_False );
115 : }
116 :
117 0 : if ( bStart && !bIsInDrag )
118 : {
119 0 : bMBPressed = sal_False;
120 0 : ReleaseMouse();
121 0 : bFrmDrag = sal_False;
122 0 : bExecuteDrag = sal_True;
123 0 : SwEditWin::nDDStartPosY = aDocPos.Y();
124 0 : SwEditWin::nDDStartPosX = aDocPos.X();
125 0 : aMovePos = aDocPos;
126 0 : StartExecuteDrag();
127 0 : if( bDelSelect )
128 : {
129 0 : rSh.UnSelectFrm();
130 0 : rSh.UnlockPaint();
131 : }
132 : }
133 : }
134 : }
135 :
136 0 : void SwEditWin::StartExecuteDrag()
137 : {
138 0 : if( !bExecuteDrag || bIsInDrag )
139 0 : return;
140 :
141 0 : bIsInDrag = sal_True;
142 :
143 0 : SwTransferable* pTransfer = new SwTransferable( rView.GetWrtShell() );
144 : uno::Reference<
145 0 : datatransfer::XTransferable > xRef( pTransfer );
146 :
147 0 : pTransfer->StartDrag( this, aMovePos );
148 : }
149 :
150 0 : void SwEditWin::DragFinished()
151 : {
152 0 : DropCleanup();
153 0 : aTimer.SetTimeoutHdl( LINK(this,SwEditWin, TimerHandler) );
154 0 : bIsInDrag = sal_False;
155 0 : }
156 :
157 :
158 0 : void SwEditWin::DropCleanup()
159 : {
160 0 : SwWrtShell &rSh = rView.GetWrtShell();
161 :
162 : // reset statuses
163 0 : bNoInterrupt = sal_False;
164 0 : if ( bOldIdleSet )
165 : {
166 0 : ((SwViewOption*)rSh.GetViewOptions())->SetIdle( bOldIdle );
167 0 : bOldIdleSet = sal_False;
168 : }
169 0 : if ( pUserMarker )
170 0 : CleanupDropUserMarker();
171 : else
172 0 : rSh.UnSetVisCrsr();
173 :
174 0 : }
175 :
176 0 : void SwEditWin::CleanupDropUserMarker()
177 : {
178 0 : if ( pUserMarker )
179 : {
180 0 : delete pUserMarker;
181 0 : pUserMarker = 0;
182 0 : pUserMarkerObj = 0;
183 : }
184 0 : }
185 :
186 :
187 : //exhibition hack (MA,MBA)
188 0 : void SwView::SelectShellForDrop()
189 : {
190 0 : if ( !GetCurShell() )
191 0 : SelectShell();
192 0 : }
193 :
194 0 : sal_Int8 SwEditWin::ExecuteDrop( const ExecuteDropEvent& rEvt )
195 : {
196 0 : GetView().SelectShellForDrop();
197 0 : DropCleanup();
198 0 : sal_Int8 nRet = DND_ACTION_NONE;
199 :
200 : //A Drop to an open OutlinerView doesn't concern us (also see QueryDrop)
201 0 : SwWrtShell &rSh = rView.GetWrtShell();
202 0 : const Point aDocPt( PixelToLogic( rEvt.maPosPixel ));
203 0 : SdrObject *pObj = 0;
204 : OutlinerView* pOLV;
205 0 : rSh.GetObjCntType( aDocPt, pObj );
206 :
207 0 : if( pObj && 0 != ( pOLV = rSh.GetDrawView()->GetTextEditOutlinerView() ))
208 : {
209 0 : Rectangle aRect( pOLV->GetOutputArea() );
210 0 : aRect.Union( pObj->GetLogicRect() );
211 0 : const Point aPos = pOLV->GetWindow()->PixelToLogic(rEvt.maPosPixel);
212 0 : if ( aRect.IsInside(aPos) )
213 : {
214 0 : rSh.StartAllAction();
215 0 : rSh.EndAllAction();
216 0 : return nRet;
217 : }
218 : }
219 :
220 :
221 : // There's a special treatment for file lists with a single
222 : // element, that depends on the actual content of the
223 : // Transferable to be accessible. Since the transferable
224 : // may only be accessed after the drop has been accepted
225 : // (according to KA due to Java D&D), we'll have to
226 : // reevaluate the drop action once more _with_ the
227 : // Transferable.
228 : sal_uInt16 nEventAction;
229 : sal_Int8 nUserOpt = rEvt.mbDefault ? EXCHG_IN_ACTION_DEFAULT
230 0 : : rEvt.mnAction;
231 : m_nDropAction = SotExchange::GetExchangeAction(
232 0 : GetDataFlavorExVector(),
233 : m_nDropDestination,
234 : rEvt.mnAction,
235 : nUserOpt, m_nDropFormat, nEventAction, 0,
236 0 : &rEvt.maDropEvent.Transferable );
237 :
238 :
239 0 : TransferableDataHelper aData( rEvt.maDropEvent.Transferable );
240 0 : nRet = rEvt.mnAction;
241 0 : if( !SwTransferable::PasteData( aData, rSh, m_nDropAction, m_nDropFormat,
242 0 : m_nDropDestination, sal_False, rEvt.mbDefault, &aDocPt, nRet))
243 0 : nRet = DND_ACTION_NONE;
244 0 : else if ( SW_MOD()->pDragDrop )
245 : //Don't clean up anymore at internal D&D!
246 0 : SW_MOD()->pDragDrop->SetCleanUp( sal_False );
247 :
248 0 : return nRet;
249 : }
250 :
251 :
252 0 : sal_uInt16 SwEditWin::GetDropDestination( const Point& rPixPnt, SdrObject ** ppObj )
253 : {
254 0 : SwWrtShell &rSh = rView.GetWrtShell();
255 0 : const Point aDocPt( PixelToLogic( rPixPnt ) );
256 0 : if( rSh.ChgCurrPam( aDocPt ) || rSh.IsOverReadOnlyPos( aDocPt ) )
257 0 : return 0;
258 :
259 0 : SdrObject *pObj = NULL;
260 0 : const ObjCntType eType = rSh.GetObjCntType( aDocPt, pObj );
261 :
262 : //Drop to OutlinerView (TextEdit in Drawing) should decide it on its own!
263 0 : if( pObj )
264 : {
265 0 : OutlinerView* pOLV = rSh.GetDrawView()->GetTextEditOutlinerView();
266 0 : if ( pOLV )
267 : {
268 0 : Rectangle aRect( pOLV->GetOutputArea() );
269 0 : aRect.Union( pObj->GetLogicRect() );
270 0 : const Point aPos = pOLV->GetWindow()->PixelToLogic( rPixPnt );
271 0 : if( aRect.IsInside( aPos ) )
272 0 : return 0;
273 : }
274 : }
275 :
276 : //What do we want to drop on now?
277 0 : sal_uInt16 nDropDestination = 0;
278 :
279 : //Did anything else arrive from the DrawingEngine?
280 0 : if( OBJCNT_NONE != eType )
281 : {
282 0 : switch ( eType )
283 : {
284 : case OBJCNT_GRF:
285 : {
286 : sal_Bool bLink,
287 0 : bIMap = 0 != rSh.GetFmtFromObj( aDocPt )->GetURL().GetMap();
288 0 : String aDummy;
289 0 : rSh.GetGrfAtPos( aDocPt, aDummy, bLink );
290 0 : if ( bLink && bIMap )
291 0 : nDropDestination = EXCHG_DEST_DOC_LNKD_GRAPH_W_IMAP;
292 0 : else if ( bLink )
293 0 : nDropDestination = EXCHG_DEST_DOC_LNKD_GRAPHOBJ;
294 0 : else if ( bIMap )
295 0 : nDropDestination = EXCHG_DEST_DOC_GRAPH_W_IMAP;
296 : else
297 0 : nDropDestination = EXCHG_DEST_DOC_GRAPHOBJ;
298 : }
299 0 : break;
300 : case OBJCNT_FLY:
301 0 : if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) )
302 0 : nDropDestination = EXCHG_DEST_DOC_TEXTFRAME_WEB;
303 : else
304 0 : nDropDestination = EXCHG_DEST_DOC_TEXTFRAME;
305 0 : break;
306 0 : case OBJCNT_OLE: nDropDestination = EXCHG_DEST_DOC_OLEOBJ; break;
307 : case OBJCNT_CONTROL: /* no Action avail */
308 0 : case OBJCNT_SIMPLE: nDropDestination = EXCHG_DEST_DOC_DRAWOBJ; break;
309 0 : case OBJCNT_URLBUTTON: nDropDestination = EXCHG_DEST_DOC_URLBUTTON; break;
310 0 : case OBJCNT_GROUPOBJ: nDropDestination = EXCHG_DEST_DOC_GROUPOBJ; break;
311 :
312 : default: OSL_ENSURE( !this, "new ObjectType?" );
313 : }
314 : }
315 0 : if ( !nDropDestination )
316 : {
317 0 : if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) )
318 0 : nDropDestination = EXCHG_DEST_SWDOC_FREE_AREA_WEB;
319 : else
320 0 : nDropDestination = EXCHG_DEST_SWDOC_FREE_AREA;
321 : }
322 0 : if( ppObj )
323 0 : *ppObj = pObj;
324 0 : return nDropDestination;
325 : }
326 :
327 0 : sal_Int8 SwEditWin::AcceptDrop( const AcceptDropEvent& rEvt )
328 : {
329 0 : if( rEvt.mbLeaving )
330 : {
331 0 : DropCleanup();
332 0 : return rEvt.mnAction;
333 : }
334 :
335 0 : if( rView.GetDocShell()->IsReadOnly() )
336 0 : return DND_ACTION_NONE;
337 :
338 0 : SwWrtShell &rSh = rView.GetWrtShell();
339 :
340 0 : Point aPixPt( rEvt.maPosPixel );
341 :
342 : // If the cursor is near the inner boundary
343 : // we attempt to scroll towards the desired direction.
344 0 : Point aPoint;
345 0 : Rectangle aWin(aPoint,GetOutputSizePixel());
346 0 : const int nMargin = 10;
347 0 : aWin.Left() += nMargin;
348 0 : aWin.Top() += nMargin;
349 0 : aWin.Right() -= nMargin;
350 0 : aWin.Bottom() -= nMargin;
351 0 : if(!aWin.IsInside(aPixPt)) {
352 : static sal_uLong last_tick = 0;
353 0 : sal_uLong current_tick = Time::GetSystemTicks();
354 0 : if((current_tick-last_tick) > 500) {
355 0 : last_tick = current_tick;
356 0 : if(!bOldIdleSet) {
357 0 : bOldIdle = rSh.GetViewOptions()->IsIdle();
358 0 : ((SwViewOption *)rSh.GetViewOptions())->SetIdle(sal_False);
359 0 : bOldIdleSet = sal_True;
360 : }
361 0 : CleanupDropUserMarker();
362 0 : if(aPixPt.X() > aWin.Right()) aPixPt.X() += nMargin;
363 0 : if(aPixPt.X() < aWin.Left()) aPixPt.X() -= nMargin;
364 0 : if(aPixPt.Y() > aWin.Bottom()) aPixPt.Y() += nMargin;
365 0 : if(aPixPt.Y() < aWin.Top()) aPixPt.Y() -= nMargin;
366 0 : Point aDocPt(PixelToLogic(aPixPt));
367 0 : SwRect rect(aDocPt,Size(1,1));
368 0 : rSh.MakeVisible(rect);
369 : }
370 : }
371 :
372 0 : if(bOldIdleSet) {
373 0 : ((SwViewOption *)rSh.GetViewOptions())->SetIdle( bOldIdle );
374 0 : bOldIdleSet = sal_False;
375 : }
376 :
377 0 : SdrObject *pObj = NULL;
378 0 : m_nDropDestination = GetDropDestination( aPixPt, &pObj );
379 0 : if( !m_nDropDestination )
380 0 : return DND_ACTION_NONE;
381 :
382 : sal_uInt16 nEventAction;
383 : sal_Int8 nUserOpt = rEvt.mbDefault ? EXCHG_IN_ACTION_DEFAULT
384 0 : : rEvt.mnAction;
385 :
386 : m_nDropAction = SotExchange::GetExchangeAction(
387 0 : GetDataFlavorExVector(),
388 : m_nDropDestination,
389 : rEvt.mnAction,
390 0 : nUserOpt, m_nDropFormat, nEventAction );
391 :
392 0 : if( EXCHG_INOUT_ACTION_NONE != m_nDropAction )
393 : {
394 0 : const Point aDocPt( PixelToLogic( aPixPt ) );
395 :
396 : //With the default action we still want to have a say.
397 0 : SwModule *pMod = SW_MOD();
398 0 : if( pMod->pDragDrop )
399 : {
400 0 : sal_Bool bCleanup = sal_False;
401 : //Drawing objects in Headers/Footers are not allowed
402 :
403 0 : SwWrtShell *pSrcSh = pMod->pDragDrop->GetShell();
404 0 : if( (pSrcSh->GetSelFrmType() == FRMTYPE_DRAWOBJ) &&
405 0 : pSrcSh->IsSelContainsControl() &&
406 0 : (rSh.GetFrmType( &aDocPt, sal_False ) & (FRMTYPE_HEADER|FRMTYPE_FOOTER)) )
407 : {
408 0 : bCleanup = sal_True;
409 : }
410 : // don't more position protected objects!
411 0 : else if( DND_ACTION_MOVE == rEvt.mnAction &&
412 0 : pSrcSh->IsSelObjProtected( FLYPROTECT_POS ) )
413 : {
414 0 : bCleanup = sal_True;
415 : }
416 0 : else if( rEvt.mbDefault )
417 : {
418 : // internal Drag&Drop: within same Doc a Move
419 : // otherwise a Copy - Task 54974
420 0 : nEventAction = pSrcSh->GetDoc() == rSh.GetDoc()
421 : ? DND_ACTION_MOVE
422 0 : : DND_ACTION_COPY;
423 : }
424 0 : if ( bCleanup )
425 : {
426 0 : CleanupDropUserMarker();
427 0 : rSh.UnSetVisCrsr();
428 0 : return DND_ACTION_NONE;
429 : }
430 : }
431 : else
432 : {
433 : //D&D from outside of SW should be a Copy per default.
434 0 : if( EXCHG_IN_ACTION_DEFAULT == nEventAction &&
435 : DND_ACTION_MOVE == rEvt.mnAction )
436 0 : nEventAction = DND_ACTION_COPY;
437 :
438 0 : if( (SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE == m_nDropFormat &&
439 : EXCHG_IN_ACTION_LINK == m_nDropAction) ||
440 : SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE == m_nDropFormat )
441 : {
442 0 : SdrMarkView* pMView = PTR_CAST( SdrMarkView, rSh.GetDrawView() );
443 0 : if( pMView && !pMView->IsDesignMode() )
444 0 : return DND_ACTION_NONE;
445 : }
446 : }
447 :
448 0 : if ( EXCHG_IN_ACTION_DEFAULT != nEventAction )
449 0 : nUserOpt = (sal_Int8)nEventAction;
450 :
451 : // show DropCursor or UserMarker ?
452 0 : if( EXCHG_DEST_SWDOC_FREE_AREA_WEB == m_nDropDestination ||
453 : EXCHG_DEST_SWDOC_FREE_AREA == m_nDropDestination )
454 : {
455 0 : CleanupDropUserMarker();
456 0 : SwContentAtPos aCont( SwContentAtPos::SW_CONTENT_CHECK );
457 0 : if(rSh.GetContentAtPos(aDocPt, aCont))
458 0 : rSh.SwCrsrShell::SetVisCrsr( aDocPt );
459 : }
460 : else
461 : {
462 0 : rSh.UnSetVisCrsr();
463 :
464 0 : if ( pUserMarkerObj != pObj )
465 : {
466 0 : CleanupDropUserMarker();
467 0 : pUserMarkerObj = pObj;
468 :
469 0 : if(pUserMarkerObj)
470 : {
471 0 : pUserMarker = new SdrDropMarkerOverlay( *rSh.GetDrawView(), *pUserMarkerObj );
472 : }
473 : }
474 : }
475 0 : return nUserOpt;
476 : }
477 :
478 0 : CleanupDropUserMarker();
479 0 : rSh.UnSetVisCrsr();
480 0 : return DND_ACTION_NONE;
481 : }
482 :
483 :
484 0 : IMPL_LINK_NOARG(SwEditWin, DDHandler)
485 : {
486 0 : bDDTimerStarted = sal_False;
487 0 : aTimer.Stop();
488 0 : aTimer.SetTimeout(240);
489 0 : bMBPressed = sal_False;
490 0 : ReleaseMouse();
491 0 : bFrmDrag = sal_False;
492 :
493 0 : if ( rView.GetViewFrame() )
494 : {
495 0 : bExecuteDrag = sal_True;
496 0 : StartExecuteDrag();
497 : }
498 0 : return 0;
499 : }
500 :
501 :
502 :
503 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|