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 bool bNoInterrupt;
48 : extern bool bFrmDrag;
49 : extern bool bDDTimerStarted;
50 :
51 : bool bExecuteDrag = false;
52 :
53 0 : void SwEditWin::StartDDTimer()
54 : {
55 0 : m_aTimer.SetTimeoutHdl(LINK(this, SwEditWin, DDHandler));
56 0 : m_aTimer.SetTimeout(480);
57 0 : m_aTimer.Start();
58 0 : bDDTimerStarted = true;
59 0 : }
60 :
61 :
62 0 : void SwEditWin::StopDDTimer(SwWrtShell *pSh, const Point &rPt)
63 : {
64 0 : m_aTimer.Stop();
65 0 : bDDTimerStarted = false;
66 0 : if(!pSh->IsSelFrmMode())
67 0 : pSh->SetCursor(&rPt, false);
68 0 : m_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 = m_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 : m_rView.GetViewFrame()->GetBindings().InvalidateAll(sal_False);
80 0 : return; // Event evaluated by SdrView
81 : }
82 : }
83 :
84 0 : if ( !m_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 && m_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 && !m_bIsInDrag )
118 : {
119 0 : m_bMBPressed = sal_False;
120 0 : ReleaseMouse();
121 0 : bFrmDrag = false;
122 0 : bExecuteDrag = true;
123 0 : SwEditWin::m_nDDStartPosY = aDocPos.Y();
124 0 : SwEditWin::m_nDDStartPosX = aDocPos.X();
125 0 : m_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 || m_bIsInDrag )
139 0 : return;
140 :
141 0 : m_bIsInDrag = sal_True;
142 :
143 0 : SwTransferable* pTransfer = new SwTransferable( m_rView.GetWrtShell() );
144 : uno::Reference<
145 0 : datatransfer::XTransferable > xRef( pTransfer );
146 :
147 0 : pTransfer->StartDrag( this, m_aMovePos );
148 : }
149 :
150 0 : void SwEditWin::DragFinished()
151 : {
152 0 : DropCleanup();
153 0 : m_aTimer.SetTimeoutHdl( LINK(this,SwEditWin, TimerHandler) );
154 0 : m_bIsInDrag = sal_False;
155 0 : }
156 :
157 :
158 0 : void SwEditWin::DropCleanup()
159 : {
160 0 : SwWrtShell &rSh = m_rView.GetWrtShell();
161 :
162 : // reset statuses
163 0 : bNoInterrupt = false;
164 0 : if ( m_bOldIdleSet )
165 : {
166 0 : ((SwViewOption*)rSh.GetViewOptions())->SetIdle( m_bOldIdle );
167 0 : m_bOldIdleSet = sal_False;
168 : }
169 0 : if ( m_pUserMarker )
170 0 : CleanupDropUserMarker();
171 : else
172 0 : rSh.UnSetVisCrsr();
173 :
174 0 : }
175 :
176 0 : void SwEditWin::CleanupDropUserMarker()
177 : {
178 0 : if ( m_pUserMarker )
179 : {
180 0 : delete m_pUserMarker;
181 0 : m_pUserMarker = 0;
182 0 : m_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 = m_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 : // There's a special treatment for file lists with a single
221 : // element, that depends on the actual content of the
222 : // Transferable to be accessible. Since the transferable
223 : // may only be accessed after the drop has been accepted
224 : // (according to KA due to Java D&D), we'll have to
225 : // reevaluate the drop action once more _with_ the
226 : // Transferable.
227 : sal_uInt16 nEventAction;
228 : sal_Int8 nUserOpt = rEvt.mbDefault ? EXCHG_IN_ACTION_DEFAULT
229 0 : : rEvt.mnAction;
230 : m_nDropAction = SotExchange::GetExchangeAction(
231 0 : GetDataFlavorExVector(),
232 : m_nDropDestination,
233 : rEvt.mnAction,
234 : nUserOpt, m_nDropFormat, nEventAction, 0,
235 0 : &rEvt.maDropEvent.Transferable );
236 :
237 :
238 0 : TransferableDataHelper aData( rEvt.maDropEvent.Transferable );
239 0 : nRet = rEvt.mnAction;
240 0 : if( !SwTransferable::PasteData( aData, rSh, m_nDropAction, m_nDropFormat,
241 0 : m_nDropDestination, sal_False, rEvt.mbDefault, &aDocPt, nRet))
242 0 : nRet = DND_ACTION_NONE;
243 0 : else if ( SW_MOD()->pDragDrop )
244 : //Don't clean up anymore at internal D&D!
245 0 : SW_MOD()->pDragDrop->SetCleanUp( sal_False );
246 :
247 0 : return nRet;
248 : }
249 :
250 :
251 0 : sal_uInt16 SwEditWin::GetDropDestination( const Point& rPixPnt, SdrObject ** ppObj )
252 : {
253 0 : SwWrtShell &rSh = m_rView.GetWrtShell();
254 0 : const Point aDocPt( PixelToLogic( rPixPnt ) );
255 0 : if( rSh.ChgCurrPam( aDocPt ) || rSh.IsOverReadOnlyPos( aDocPt ) )
256 0 : return 0;
257 :
258 0 : SdrObject *pObj = NULL;
259 0 : const ObjCntType eType = rSh.GetObjCntType( aDocPt, pObj );
260 :
261 : //Drop to OutlinerView (TextEdit in Drawing) should decide it on its own!
262 0 : if( pObj )
263 : {
264 0 : OutlinerView* pOLV = rSh.GetDrawView()->GetTextEditOutlinerView();
265 0 : if ( pOLV )
266 : {
267 0 : Rectangle aRect( pOLV->GetOutputArea() );
268 0 : aRect.Union( pObj->GetLogicRect() );
269 0 : const Point aPos = pOLV->GetWindow()->PixelToLogic( rPixPnt );
270 0 : if( aRect.IsInside( aPos ) )
271 0 : return 0;
272 : }
273 : }
274 :
275 : //What do we want to drop on now?
276 0 : sal_uInt16 nDropDestination = 0;
277 :
278 : //Did anything else arrive from the DrawingEngine?
279 0 : if( OBJCNT_NONE != eType )
280 : {
281 0 : switch ( eType )
282 : {
283 : case OBJCNT_GRF:
284 : {
285 : sal_Bool bLink,
286 0 : bIMap = 0 != rSh.GetFmtFromObj( aDocPt )->GetURL().GetMap();
287 0 : String aDummy;
288 0 : rSh.GetGrfAtPos( aDocPt, aDummy, bLink );
289 0 : if ( bLink && bIMap )
290 0 : nDropDestination = EXCHG_DEST_DOC_LNKD_GRAPH_W_IMAP;
291 0 : else if ( bLink )
292 0 : nDropDestination = EXCHG_DEST_DOC_LNKD_GRAPHOBJ;
293 0 : else if ( bIMap )
294 0 : nDropDestination = EXCHG_DEST_DOC_GRAPH_W_IMAP;
295 : else
296 0 : nDropDestination = EXCHG_DEST_DOC_GRAPHOBJ;
297 : }
298 0 : break;
299 : case OBJCNT_FLY:
300 0 : if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) )
301 0 : nDropDestination = EXCHG_DEST_DOC_TEXTFRAME_WEB;
302 : else
303 0 : nDropDestination = EXCHG_DEST_DOC_TEXTFRAME;
304 0 : break;
305 0 : case OBJCNT_OLE: nDropDestination = EXCHG_DEST_DOC_OLEOBJ; break;
306 : case OBJCNT_CONTROL: /* no Action avail */
307 0 : case OBJCNT_SIMPLE: nDropDestination = EXCHG_DEST_DOC_DRAWOBJ; break;
308 0 : case OBJCNT_URLBUTTON: nDropDestination = EXCHG_DEST_DOC_URLBUTTON; break;
309 0 : case OBJCNT_GROUPOBJ: nDropDestination = EXCHG_DEST_DOC_GROUPOBJ; break;
310 :
311 : default: OSL_ENSURE( !this, "new ObjectType?" );
312 : }
313 : }
314 0 : if ( !nDropDestination )
315 : {
316 0 : if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) )
317 0 : nDropDestination = EXCHG_DEST_SWDOC_FREE_AREA_WEB;
318 : else
319 0 : nDropDestination = EXCHG_DEST_SWDOC_FREE_AREA;
320 : }
321 0 : if( ppObj )
322 0 : *ppObj = pObj;
323 0 : return nDropDestination;
324 : }
325 :
326 0 : sal_Int8 SwEditWin::AcceptDrop( const AcceptDropEvent& rEvt )
327 : {
328 0 : if( rEvt.mbLeaving )
329 : {
330 0 : DropCleanup();
331 0 : return rEvt.mnAction;
332 : }
333 :
334 0 : if( m_rView.GetDocShell()->IsReadOnly() )
335 0 : return DND_ACTION_NONE;
336 :
337 0 : SwWrtShell &rSh = m_rView.GetWrtShell();
338 :
339 0 : Point aPixPt( rEvt.maPosPixel );
340 :
341 : // If the cursor is near the inner boundary
342 : // we attempt to scroll towards the desired direction.
343 0 : Point aPoint;
344 0 : Rectangle aWin(aPoint,GetOutputSizePixel());
345 0 : const int nMargin = 10;
346 0 : aWin.Left() += nMargin;
347 0 : aWin.Top() += nMargin;
348 0 : aWin.Right() -= nMargin;
349 0 : aWin.Bottom() -= nMargin;
350 0 : if(!aWin.IsInside(aPixPt)) {
351 : static sal_uLong last_tick = 0;
352 0 : sal_uLong current_tick = Time::GetSystemTicks();
353 0 : if((current_tick-last_tick) > 500) {
354 0 : last_tick = current_tick;
355 0 : if(!m_bOldIdleSet) {
356 0 : m_bOldIdle = rSh.GetViewOptions()->IsIdle();
357 0 : ((SwViewOption *)rSh.GetViewOptions())->SetIdle(sal_False);
358 0 : m_bOldIdleSet = sal_True;
359 : }
360 0 : CleanupDropUserMarker();
361 0 : if(aPixPt.X() > aWin.Right()) aPixPt.X() += nMargin;
362 0 : if(aPixPt.X() < aWin.Left()) aPixPt.X() -= nMargin;
363 0 : if(aPixPt.Y() > aWin.Bottom()) aPixPt.Y() += nMargin;
364 0 : if(aPixPt.Y() < aWin.Top()) aPixPt.Y() -= nMargin;
365 0 : Point aDocPt(PixelToLogic(aPixPt));
366 0 : SwRect rect(aDocPt,Size(1,1));
367 0 : rSh.MakeVisible(rect);
368 : }
369 : }
370 :
371 0 : if(m_bOldIdleSet) {
372 0 : ((SwViewOption *)rSh.GetViewOptions())->SetIdle( m_bOldIdle );
373 0 : m_bOldIdleSet = sal_False;
374 : }
375 :
376 0 : SdrObject *pObj = NULL;
377 0 : m_nDropDestination = GetDropDestination( aPixPt, &pObj );
378 0 : if( !m_nDropDestination )
379 0 : return DND_ACTION_NONE;
380 :
381 : sal_uInt16 nEventAction;
382 : sal_Int8 nUserOpt = rEvt.mbDefault ? EXCHG_IN_ACTION_DEFAULT
383 0 : : rEvt.mnAction;
384 :
385 : m_nDropAction = SotExchange::GetExchangeAction(
386 0 : GetDataFlavorExVector(),
387 : m_nDropDestination,
388 : rEvt.mnAction,
389 0 : nUserOpt, m_nDropFormat, nEventAction );
390 :
391 0 : if( EXCHG_INOUT_ACTION_NONE != m_nDropAction )
392 : {
393 0 : const Point aDocPt( PixelToLogic( aPixPt ) );
394 :
395 : //With the default action we still want to have a say.
396 0 : SwModule *pMod = SW_MOD();
397 0 : if( pMod->pDragDrop )
398 : {
399 0 : sal_Bool bCleanup = sal_False;
400 : //Drawing objects in Headers/Footers are not allowed
401 :
402 0 : SwWrtShell *pSrcSh = pMod->pDragDrop->GetShell();
403 0 : if( (pSrcSh->GetSelFrmType() == FRMTYPE_DRAWOBJ) &&
404 0 : pSrcSh->IsSelContainsControl() &&
405 0 : (rSh.GetFrmType( &aDocPt, sal_False ) & (FRMTYPE_HEADER|FRMTYPE_FOOTER)) )
406 : {
407 0 : bCleanup = sal_True;
408 : }
409 : // don't more position protected objects!
410 0 : else if( DND_ACTION_MOVE == rEvt.mnAction &&
411 0 : pSrcSh->IsSelObjProtected( FLYPROTECT_POS ) )
412 : {
413 0 : bCleanup = sal_True;
414 : }
415 0 : else if( rEvt.mbDefault )
416 : {
417 : // internal Drag&Drop: within same Doc a Move
418 : // otherwise a Copy - Task 54974
419 0 : nEventAction = pSrcSh->GetDoc() == rSh.GetDoc()
420 : ? DND_ACTION_MOVE
421 0 : : DND_ACTION_COPY;
422 : }
423 0 : if ( bCleanup )
424 : {
425 0 : CleanupDropUserMarker();
426 0 : rSh.UnSetVisCrsr();
427 0 : return DND_ACTION_NONE;
428 : }
429 : }
430 : else
431 : {
432 : //D&D from outside of SW should be a Copy per default.
433 0 : if( EXCHG_IN_ACTION_DEFAULT == nEventAction &&
434 0 : DND_ACTION_MOVE == rEvt.mnAction )
435 0 : nEventAction = DND_ACTION_COPY;
436 :
437 0 : if( (SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE == m_nDropFormat &&
438 0 : EXCHG_IN_ACTION_LINK == m_nDropAction) ||
439 0 : SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE == m_nDropFormat )
440 : {
441 0 : SdrMarkView* pMView = PTR_CAST( SdrMarkView, rSh.GetDrawView() );
442 0 : if( pMView && !pMView->IsDesignMode() )
443 0 : return DND_ACTION_NONE;
444 : }
445 : }
446 :
447 0 : if ( EXCHG_IN_ACTION_DEFAULT != nEventAction )
448 0 : nUserOpt = (sal_Int8)nEventAction;
449 :
450 : // show DropCursor or UserMarker ?
451 0 : if( EXCHG_DEST_SWDOC_FREE_AREA_WEB == m_nDropDestination ||
452 0 : EXCHG_DEST_SWDOC_FREE_AREA == m_nDropDestination )
453 : {
454 0 : CleanupDropUserMarker();
455 0 : SwContentAtPos aCont( SwContentAtPos::SW_CONTENT_CHECK );
456 0 : if(rSh.GetContentAtPos(aDocPt, aCont))
457 0 : rSh.SwCrsrShell::SetVisCrsr( aDocPt );
458 : }
459 : else
460 : {
461 0 : rSh.UnSetVisCrsr();
462 :
463 0 : if ( m_pUserMarkerObj != pObj )
464 : {
465 0 : CleanupDropUserMarker();
466 0 : m_pUserMarkerObj = pObj;
467 :
468 0 : if(m_pUserMarkerObj)
469 : {
470 0 : m_pUserMarker = new SdrDropMarkerOverlay( *rSh.GetDrawView(), *m_pUserMarkerObj );
471 : }
472 : }
473 : }
474 0 : return nUserOpt;
475 : }
476 :
477 0 : CleanupDropUserMarker();
478 0 : rSh.UnSetVisCrsr();
479 0 : return DND_ACTION_NONE;
480 : }
481 :
482 :
483 0 : IMPL_LINK_NOARG(SwEditWin, DDHandler)
484 : {
485 0 : bDDTimerStarted = false;
486 0 : m_aTimer.Stop();
487 0 : m_aTimer.SetTimeout(240);
488 0 : m_bMBPressed = sal_False;
489 0 : ReleaseMouse();
490 0 : bFrmDrag = false;
491 :
492 0 : if ( m_rView.GetViewFrame() )
493 : {
494 0 : bExecuteDrag = true;
495 0 : StartExecuteDrag();
496 : }
497 0 : return 0;
498 99 : }
499 :
500 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|