bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / svdraw / svdview.cxx
blobea1c73700395cab6f264525b7fb4130579893be9
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 .
20 #include <editeng/eeitem.hxx>
22 #include "svx/svdstr.hrc" // names taken from the resource
23 #include "svx/svdglob.hxx" // StringCache
24 #include <svx/svdpagv.hxx>
25 #include <svx/svdmrkv.hxx>
26 #include <svx/svdedxv.hxx>
27 #include <svx/svdobj.hxx>
28 #include <svx/svdopath.hxx> // for GetContext
29 #include <svx/svdograf.hxx> // for GetContext
30 #include <svx/svdomedia.hxx> // for GetContext
31 #include <svx/svdetc.hxx> // for SdrEngineDefaults
33 #ifdef DBG_UTIL
34 #include <svdibrow.hxx>
35 #endif
37 #include "svx/svdoutl.hxx"
38 #include "svx/svdview.hxx"
39 #include "editeng/editview.hxx" // for GetField
40 #include "editeng/flditem.hxx" // for URLField
41 #include "svx/obj3d.hxx"
42 #include "svx/svddrgmt.hxx"
43 #include "svx/svdotable.hxx"
44 #include <tools/tenccvt.hxx>
45 #include <svx/sdr/overlay/overlaypolypolygon.hxx>
46 #include <svx/sdr/overlay/overlaymanager.hxx>
47 #include <svx/sdrpaintwindow.hxx>
48 #include <svx/sdrpagewindow.hxx>
49 #include <svx/sdrhittesthelper.hxx>
51 ////////////////////////////////////////////////////////////////////////////////////////////////////
53 SdrViewEvent::SdrViewEvent()
54 : pHdl(NULL),
55 pObj(NULL),
56 pRootObj(NULL),
57 pPV(NULL),
58 pURLField(NULL),
59 eHit(SDRHIT_NONE),
60 eEvent(SDREVENT_NONE),
61 eHdlKind(HDL_MOVE),
62 eEndCreateCmd(SDRCREATE_NEXTPOINT),
63 nMouseClicks(0),
64 nMouseMode(0),
65 nMouseCode(0),
66 nHlplIdx(0),
67 nGlueId(0),
68 bMouseDown(sal_False),
69 bMouseUp(sal_False),
70 bDoubleHdlSize(sal_False),
71 bIsAction(sal_False),
72 bIsTextEdit(sal_False),
73 bTextEditHit(sal_False),
74 bAddMark(sal_False),
75 bUnmark(sal_False),
76 bPrevNextMark(sal_False),
77 bMarkPrev(sal_False),
78 bInsPointNewObj(sal_False),
79 bDragWithCopy(sal_False),
80 bCaptureMouse(sal_False),
81 bReleaseMouse(sal_False)
85 SdrViewEvent::~SdrViewEvent()
89 ////////////////////////////////////////////////////////////////////////////////////////////////////
90 // helper class for all D&D overlays
92 void SdrDropMarkerOverlay::ImplCreateOverlays(const SdrView& rView, const basegfx::B2DPolyPolygon& rPolyPolygon)
94 for(sal_uInt32 a(0L); a < rView.PaintWindowCount(); a++)
96 SdrPaintWindow* pCandidate = rView.GetPaintWindow(a);
97 rtl::Reference< ::sdr::overlay::OverlayManager > xTargetOverlay = pCandidate->GetOverlayManager();
99 if (xTargetOverlay.is())
101 ::sdr::overlay::OverlayPolyPolygonStriped* pNew = new ::sdr::overlay::OverlayPolyPolygonStriped(
102 rPolyPolygon);
103 xTargetOverlay->add(*pNew);
104 maObjects.append(*pNew);
109 SdrDropMarkerOverlay::SdrDropMarkerOverlay(const SdrView& rView, const SdrObject& rObject)
111 ImplCreateOverlays(rView, rObject.TakeXorPoly());
114 SdrDropMarkerOverlay::SdrDropMarkerOverlay(const SdrView& rView, const Rectangle& rRectangle)
116 basegfx::B2DPolygon aB2DPolygon;
117 aB2DPolygon.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top()));
118 aB2DPolygon.append(basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
119 aB2DPolygon.append(basegfx::B2DPoint(rRectangle.Right(), rRectangle.Bottom()));
120 aB2DPolygon.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
121 aB2DPolygon.setClosed(true);
123 basegfx::B2DPolyPolygon aB2DPolyPolygon;
124 aB2DPolyPolygon.append(aB2DPolygon);
126 ImplCreateOverlays(rView, aB2DPolyPolygon);
129 SdrDropMarkerOverlay::SdrDropMarkerOverlay(const SdrView& rView, const Point& rStart, const Point& rEnd)
131 basegfx::B2DPolygon aB2DPolygon;
132 aB2DPolygon.append(basegfx::B2DPoint(rStart.X(), rStart.Y()));
133 aB2DPolygon.append(basegfx::B2DPoint(rEnd.X(), rEnd.Y()));
134 aB2DPolygon.setClosed(true);
136 basegfx::B2DPolyPolygon aB2DPolyPolygon;
137 aB2DPolyPolygon.append(aB2DPolygon);
139 ImplCreateOverlays(rView, aB2DPolyPolygon);
142 SdrDropMarkerOverlay::~SdrDropMarkerOverlay()
144 // The OverlayObjects are cleared using the destructor of OverlayObjectList.
145 // That destructor calls clear() at the list which removes all objects from the
146 // OverlayManager and deletes them.
150 TYPEINIT1(SdrView,SdrCreateView);
152 SdrView::SdrView(SdrModel* pModel1, OutputDevice* pOut)
153 : SdrCreateView(pModel1,pOut),
154 bNoExtendedMouseDispatcher(sal_False),
155 bNoExtendedKeyDispatcher(sal_False),
156 bNoExtendedCommandDispatcher(sal_False),
157 mbMasterPagePaintCaching(sal_False)
159 bTextEditOnObjectsWithoutTextIfTextTool=sal_False;
161 maAccessibilityOptions.AddListener(this);
163 onAccessibilityOptionsChanged();
166 SdrView::~SdrView()
168 maAccessibilityOptions.RemoveListener(this);
171 sal_Bool SdrView::KeyInput(const KeyEvent& rKEvt, Window* pWin)
173 SetActualWin(pWin);
174 sal_Bool bRet=SdrCreateView::KeyInput(rKEvt,pWin);
175 if (!bRet && !IsExtendedKeyInputDispatcherEnabled()) {
176 bRet=sal_True;
177 switch (rKEvt.GetKeyCode().GetFullFunction()) {
178 case KEYFUNC_CUT : Cut(); break;
179 case KEYFUNC_COPY : Yank(); break;
180 case KEYFUNC_PASTE : Paste(pWin); break;
181 case KEYFUNC_DELETE: DeleteMarked(); break;
182 case KEYFUNC_UNDO: pMod->Undo(); break;
183 case KEYFUNC_REDO: pMod->Redo(); break;
184 case KEYFUNC_REPEAT: pMod->Repeat(*this); break;
185 default: {
186 switch (rKEvt.GetKeyCode().GetFullCode()) {
187 case KEY_ESCAPE: {
188 if (IsTextEdit()) SdrEndTextEdit();
189 if (IsAction()) BrkAction();
190 if (pWin!=NULL) pWin->ReleaseMouse();
191 } break;
192 case KEY_DELETE: DeleteMarked(); break;
193 case KEY_CUT: case KEY_DELETE+KEY_SHIFT: Cut(); break;
194 case KEY_COPY: case KEY_INSERT+KEY_MOD1: Yank(); break;
195 case KEY_PASTE: case KEY_INSERT+KEY_SHIFT: Paste(pWin); break;
196 case KEY_UNDO: case KEY_BACKSPACE+KEY_MOD2: pMod->Undo(); break;
197 case KEY_BACKSPACE+KEY_MOD2+KEY_SHIFT: pMod->Redo(); break;
198 case KEY_REPEAT: case KEY_BACKSPACE+KEY_MOD2+KEY_MOD1: pMod->Repeat(*this); break;
199 case KEY_MOD1+KEY_A: MarkAll(); break;
200 default: bRet=sal_False;
201 } // switch
203 } // switch
204 if (bRet && pWin!=NULL) {
205 pWin->SetPointer(GetPreferedPointer(
206 pWin->PixelToLogic(pWin->ScreenToOutputPixel( pWin->GetPointerPosPixel() ) ),
207 pWin,
208 rKEvt.GetKeyCode().GetModifier()));
211 return bRet;
214 sal_Bool SdrView::MouseButtonDown(const MouseEvent& rMEvt, Window* pWin)
216 SetActualWin(pWin);
217 if (rMEvt.IsLeft()) aDragStat.SetMouseDown(sal_True);
218 sal_Bool bRet=SdrCreateView::MouseButtonDown(rMEvt,pWin);
219 if (!bRet && !IsExtendedMouseEventDispatcherEnabled()) {
220 SdrViewEvent aVEvt;
221 PickAnything(rMEvt,SDRMOUSEBUTTONDOWN,aVEvt);
222 bRet=DoMouseEvent(aVEvt);
224 return bRet;
227 sal_Bool SdrView::MouseButtonUp(const MouseEvent& rMEvt, Window* pWin)
229 SetActualWin(pWin);
230 if (rMEvt.IsLeft()) aDragStat.SetMouseDown(sal_False);
231 sal_Bool bAction=IsAction();
232 sal_Bool bRet=!bAction && SdrCreateView::MouseButtonUp(rMEvt,pWin);
233 if (!bRet && !IsExtendedMouseEventDispatcherEnabled()) {
234 SdrViewEvent aVEvt;
235 PickAnything(rMEvt,SDRMOUSEBUTTONUP,aVEvt);
236 bRet=DoMouseEvent(aVEvt);
238 return bRet;
241 sal_Bool SdrView::MouseMove(const MouseEvent& rMEvt, Window* pWin)
243 SetActualWin(pWin);
244 aDragStat.SetMouseDown(rMEvt.IsLeft());
245 sal_Bool bRet=SdrCreateView::MouseMove(rMEvt,pWin);
246 if (!IsExtendedMouseEventDispatcherEnabled() && !IsTextEditInSelectionMode()) {
247 SdrViewEvent aVEvt;
248 PickAnything(rMEvt,SDRMOUSEMOVE,aVEvt);
249 if (DoMouseEvent(aVEvt)) bRet=sal_True;
252 return bRet;
255 sal_Bool SdrView::Command(const CommandEvent& rCEvt, Window* pWin)
257 SetActualWin(pWin);
258 sal_Bool bRet=SdrCreateView::Command(rCEvt,pWin);
259 return bRet;
262 sal_Bool SdrView::GetAttributes(SfxItemSet& rTargetSet, sal_Bool bOnlyHardAttr) const
264 return SdrCreateView::GetAttributes(rTargetSet, bOnlyHardAttr);
267 SfxStyleSheet* SdrView::GetStyleSheet() const
269 return SdrCreateView::GetStyleSheet();
272 SdrHitKind SdrView::PickAnything(const MouseEvent& rMEvt, sal_uInt16 nEventKind, SdrViewEvent& rVEvt) const
274 rVEvt.bMouseDown=nEventKind==SDRMOUSEBUTTONDOWN;
275 rVEvt.bMouseUp=nEventKind==SDRMOUSEBUTTONUP;
276 rVEvt.nMouseClicks=rMEvt.GetClicks();
277 rVEvt.nMouseMode=rMEvt.GetMode();
278 rVEvt.nMouseCode=rMEvt.GetButtons() | rMEvt.GetModifier();
279 const OutputDevice* pOut=pActualOutDev;
280 if (pOut==NULL)
282 pOut = GetFirstOutputDevice();
284 Point aPnt(rMEvt.GetPosPixel());
285 if (pOut!=NULL) aPnt=pOut->PixelToLogic(aPnt);
286 rVEvt.aLogicPos=aPnt;
287 return PickAnything(aPnt,rVEvt);
290 // Dragging with the Mouse (Move)
291 // Example when creating a rectangle: MouseDown has to happen without a ModKey,
292 // else we usually force a selection (see below).
293 // When pressing Shift, Ctrl and Alt at the same time while doing a MouseMove,
294 // a centered, not snapped square is created.
295 // The dual allocation of Ortho and Shift won't usually create a problem, as the
296 // two functions are in most cases mutually exclusive. Only shearing (the kind
297 // that happens when contorting, not when rotating) can use both functions at
298 // the same time. To get around this, the user can use e. g. help lines.
299 #define MODKEY_NoSnap bCtrl /* temporarily disable snapping */
300 #define MODKEY_Ortho bShift /* ortho */
301 #define MODKEY_Center bAlt /* create/resize centeredly */
302 #define MODKEY_AngleSnap bShift
303 #define MODKEY_CopyDrag bCtrl /* drag and copy */
305 // click somewhere (MouseDown)
306 #define MODKEY_PolyPoly bAlt /* new Poly at InsPt and at Create */
307 #define MODKEY_MultiMark bShift /* MarkObj without doing UnmarkAll first */
308 #define MODKEY_Unmark bAlt /* deselect with a dragged frame */
309 #define MODKEY_ForceMark bCtrl /* force dragging a frame, even if there's an object at cursor position */
310 #define MODKEY_DeepMark bAlt /* MarkNextObj */
311 #define MODKEY_DeepBackw bShift /* MarkNextObj but backwards */
313 SdrHitKind SdrView::PickAnything(const Point& rLogicPos, SdrViewEvent& rVEvt) const
315 const OutputDevice* pOut=pActualOutDev;
316 if (pOut==NULL)
318 pOut = GetFirstOutputDevice();
321 // #i73628# Use a non-changeable copy of he logic position
322 const Point aLocalLogicPosition(rLogicPos);
324 sal_Bool bEditMode=IsEditMode();
325 bool bPointMode=bEditMode && HasMarkablePoints();
326 sal_Bool bGluePointMode=IsGluePointEditMode();
327 bool bInsPolyPt=bPointMode && IsInsObjPointMode() && IsInsObjPointPossible();
328 bool bInsGluePt=bGluePointMode && IsInsGluePointMode() && IsInsGluePointPossible();
329 sal_Bool bIsTextEdit=IsTextEdit();
330 sal_Bool bTextEditHit=IsTextEditHit(aLocalLogicPosition,0/*nHitTolLog*/);
331 sal_Bool bTextEditSel=IsTextEditInSelectionMode();
332 sal_Bool bShift=(rVEvt.nMouseCode & KEY_SHIFT) !=0;
333 sal_Bool bCtrl=(rVEvt.nMouseCode & KEY_MOD1) !=0;
334 sal_Bool bAlt=(rVEvt.nMouseCode & KEY_MOD2) !=0;
335 SdrHitKind eHit=SDRHIT_NONE;
336 SdrHdl* pHdl=pOut!=NULL && !bTextEditSel ? PickHandle(aLocalLogicPosition) : NULL;
337 SdrPageView* pPV=NULL;
338 SdrObject* pObj=NULL;
339 SdrObject* pHitObj=NULL;
340 sal_uInt16 nHitPassNum=0;
341 sal_uInt16 nHlplIdx=0;
342 sal_uInt16 nGlueId=0;
343 if (bTextEditHit || bTextEditSel)
345 eHit=SDRHIT_TEXTEDIT;
346 bTextEditHit=sal_True;
348 else if (pHdl!=NULL)
350 eHit=SDRHIT_HANDLE; // handle is hit: highest priority
352 else if (bEditMode && IsHlplVisible() && IsHlplFront() && pOut!=NULL && PickHelpLine(aLocalLogicPosition,nHitTolLog,*pOut,nHlplIdx,pPV))
354 eHit=SDRHIT_HELPLINE; // help line in the foreground hit: can be moved now
356 else if (bGluePointMode && PickGluePoint(aLocalLogicPosition,pObj,nGlueId,pPV))
358 eHit=SDRHIT_GLUEPOINT; // deselected glue point hit
360 else if (PickObj(aLocalLogicPosition,nHitTolLog,pHitObj,pPV,SDRSEARCH_DEEP|SDRSEARCH_MARKED,&pObj,NULL,&nHitPassNum))
362 eHit=SDRHIT_MARKEDOBJECT;
363 ::sdr::table::SdrTableObj* pTableObj = dynamic_cast< ::sdr::table::SdrTableObj* >( pObj );
364 if( pTableObj )
366 sal_Int32 nX = 0, nY = 0;
367 switch( pTableObj->CheckTableHit( aLocalLogicPosition, nX, nY, 0 ) )
369 case sdr::table::SDRTABLEHIT_CELL:
370 eHit = SDRHIT_CELL;
371 break;
372 case sdr::table::SDRTABLEHIT_CELLTEXTAREA:
373 eHit = SDRHIT_TEXTEDITOBJ;
374 break;
375 default:
376 break;
380 else if (PickObj(aLocalLogicPosition,nHitTolLog,pHitObj,pPV,SDRSEARCH_DEEP|SDRSEARCH_ALSOONMASTER|SDRSEARCH_WHOLEPAGE,&pObj,NULL,&nHitPassNum))
382 // MasterPages and WholePage for Macro and URL
383 eHit=SDRHIT_UNMARKEDOBJECT;
384 ::sdr::table::SdrTableObj* pTableObj = dynamic_cast< ::sdr::table::SdrTableObj* >( pObj );
385 if( pTableObj )
387 sal_Int32 nX = 0, nY = 0;
388 switch( pTableObj->CheckTableHit( aLocalLogicPosition, nX, nY, 0 ) )
390 case sdr::table::SDRTABLEHIT_CELL:
391 eHit = SDRHIT_CELL;
392 break;
393 case sdr::table::SDRTABLEHIT_CELLTEXTAREA:
394 eHit = SDRHIT_TEXTEDITOBJ;
395 break;
396 default:
397 break;
401 else if (bEditMode && IsHlplVisible() && !IsHlplFront() && pOut!=NULL && PickHelpLine(aLocalLogicPosition,nHitTolLog,*pOut,nHlplIdx,pPV))
403 eHit=SDRHIT_HELPLINE; // help line in foreground hit: can be moved now
405 if (IsMacroMode() && eHit==SDRHIT_UNMARKEDOBJECT)
407 bool bRoot=pObj->HasMacro();
408 sal_Bool bDeep=pObj!=pHitObj && pHitObj->HasMacro();
409 sal_Bool bMid=sal_False; // Have we hit upon a grouped group with a macro?
410 SdrObject* pMidObj=NULL;
411 if (pObj!=pHitObj)
413 SdrObject* pObjTmp=NULL;
414 pObjTmp=pHitObj->GetUpGroup();
415 if (pObjTmp==pObj) pObjTmp=NULL;
416 while (pObjTmp!=NULL)
418 if (pObjTmp->HasMacro())
420 bMid=sal_True;
421 pMidObj=pObjTmp;
423 pObjTmp=pObjTmp->GetUpGroup();
424 if (pObjTmp==pObj) pObjTmp=NULL;
428 if (bDeep || bMid || bRoot)
430 SdrObjMacroHitRec aHitRec;
431 aHitRec.aPos=aLocalLogicPosition;
432 aHitRec.aDownPos=aLocalLogicPosition;
433 aHitRec.nTol=nHitTolLog;
434 aHitRec.pVisiLayer=&pPV->GetVisibleLayers();
435 aHitRec.pPageView=pPV;
436 if (bDeep) bDeep=pHitObj->IsMacroHit(aHitRec);
437 if (bMid ) bMid =pMidObj->IsMacroHit(aHitRec);
438 if (bRoot) bRoot=pObj->IsMacroHit(aHitRec);
439 if (bRoot || bMid || bDeep)
441 // Priorities: 1. Root, 2. Mid, 3. Deep
442 rVEvt.pRootObj=pObj;
443 if (!bRoot) pObj=pMidObj;
444 if (!bRoot && !bMid) pObj=pHitObj;
445 eHit=SDRHIT_MACRO;
449 // check for URL field
450 if (IsMacroMode() && eHit==SDRHIT_UNMARKEDOBJECT)
452 SdrTextObj* pTextObj=PTR_CAST(SdrTextObj,pHitObj);
453 if (pTextObj!=NULL && pTextObj->HasText())
455 bool bTEHit(pPV &&
456 SdrObjectPrimitiveHit(*pTextObj, aLocalLogicPosition, 0, *pPV, &pPV->GetVisibleLayers(), true));
458 if (bTEHit)
460 Rectangle aTextRect;
461 Rectangle aAnchor;
462 SdrOutliner* pOutliner = &pTextObj->ImpGetDrawOutliner();
463 if( pTextObj->GetModel() )
464 pOutliner = &pTextObj->GetModel()->GetHitTestOutliner();
466 pTextObj->TakeTextRect( *pOutliner, aTextRect, sal_False, &aAnchor, sal_False );
468 // #i73628# Use a text-relative position for hit test in hit test outliner
469 Point aTemporaryTextRelativePosition(aLocalLogicPosition - aTextRect.TopLeft());
471 // account for FitToSize
472 bool bFitToSize(pTextObj->IsFitToSize());
473 if (bFitToSize) {
474 Fraction aX(aTextRect.GetWidth()-1,aAnchor.GetWidth()-1);
475 Fraction aY(aTextRect.GetHeight()-1,aAnchor.GetHeight()-1);
476 ResizePoint(aTemporaryTextRelativePosition,Point(),aX,aY);
478 // account for rotation
479 const GeoStat& rGeo=pTextObj->GetGeoStat();
480 if (rGeo.nDrehWink!=0) RotatePoint(aTemporaryTextRelativePosition,Point(),-rGeo.nSin,rGeo.nCos); // -sin for Unrotate
481 // we currently don't account for ticker text
482 if(pActualOutDev && pActualOutDev->GetOutDevType() == OUTDEV_WINDOW)
484 OutlinerView aOLV(pOutliner, (Window*)pActualOutDev);
485 const EditView& aEV=aOLV.GetEditView();
486 const SvxFieldItem* pItem=aEV.GetField(aTemporaryTextRelativePosition);
487 if (pItem!=NULL) {
488 const SvxFieldData* pFld=pItem->GetField();
489 const SvxURLField* pURL=PTR_CAST(SvxURLField,pFld);
490 if (pURL!=NULL) {
491 eHit=SDRHIT_URLFIELD;
492 rVEvt.pURLField=pURL;
500 if (nHitPassNum==SDRSEARCHPASS_DIRECT &&
501 (eHit==SDRHIT_MARKEDOBJECT || eHit==SDRHIT_UNMARKEDOBJECT) &&
502 (IsTextTool() || (IsEditMode() && IsQuickTextEditMode())) && pHitObj->HasTextEdit())
504 // Around the TextEditArea there's a border to select without going into text edit mode.
505 Rectangle aBoundRect(pHitObj->GetCurrentBoundRect());
507 // Force to SnapRect when Fontwork
508 if(pHitObj->ISA(SdrTextObj) && ((SdrTextObj*)pHitObj)->IsFontwork())
510 aBoundRect = pHitObj->GetSnapRect();
513 sal_Int32 nTolerance(nHitTolLog);
514 sal_Bool bBoundRectHit(sal_False);
516 if(pOut)
518 nTolerance = pOut->PixelToLogic(Size(2, 0)).Width();
521 if( (aLocalLogicPosition.X() >= aBoundRect.Left() - nTolerance && aLocalLogicPosition.X() <= aBoundRect.Left() + nTolerance)
522 || (aLocalLogicPosition.X() >= aBoundRect.Right() - nTolerance && aLocalLogicPosition.X() <= aBoundRect.Right() + nTolerance)
523 || (aLocalLogicPosition.Y() >= aBoundRect.Top() - nTolerance && aLocalLogicPosition.Y() <= aBoundRect.Top() + nTolerance)
524 || (aLocalLogicPosition.Y() >= aBoundRect.Bottom() - nTolerance && aLocalLogicPosition.Y() <= aBoundRect.Bottom() + nTolerance))
526 bBoundRectHit = sal_True;
529 if(!bBoundRectHit)
531 bool bTEHit(pPV &&
532 SdrObjectPrimitiveHit(*pHitObj, aLocalLogicPosition, 0, *pPV, &pPV->GetVisibleLayers(), true));
534 // TextEdit attached to an object in a locked layer
535 if (pPV->GetLockedLayers().IsSet(pHitObj->GetLayer()))
537 bTEHit=sal_False;
540 if (bTEHit)
542 rVEvt.pRootObj=pObj;
543 pObj=pHitObj;
544 eHit=SDRHIT_TEXTEDITOBJ;
548 if (nHitPassNum!=SDRSEARCHPASS_DIRECT && eHit==SDRHIT_UNMARKEDOBJECT) {
549 eHit=SDRHIT_NONE;
550 pObj=NULL;
551 pPV=NULL;
553 sal_Bool bMouseLeft=(rVEvt.nMouseCode&MOUSE_LEFT)!=0;
554 sal_Bool bMouseRight=(rVEvt.nMouseCode&MOUSE_RIGHT)!=0;
555 sal_Bool bMouseDown=rVEvt.bMouseDown;
556 sal_Bool bMouseUp=rVEvt.bMouseUp;
557 SdrEventKind eEvent=SDREVENT_NONE;
558 sal_Bool bIsAction=IsAction();
560 if (bIsAction)
562 if (bMouseDown)
564 if (bMouseRight) eEvent=SDREVENT_BCKACTION;
566 else if (bMouseUp)
568 if (bMouseLeft)
570 eEvent=SDREVENT_ENDACTION;
571 if (IsDragObj())
573 eEvent=SDREVENT_ENDDRAG;
574 rVEvt.bDragWithCopy=MODKEY_CopyDrag;
576 else if (IsCreateObj() || IsInsObjPoint())
578 eEvent=IsCreateObj() ? SDREVENT_ENDCREATE : SDREVENT_ENDINSOBJPOINT;
579 rVEvt.eEndCreateCmd=SDRCREATE_NEXTPOINT;
580 if (MODKEY_PolyPoly) rVEvt.eEndCreateCmd=SDRCREATE_NEXTOBJECT;
581 if (rVEvt.nMouseClicks>1) rVEvt.eEndCreateCmd=SDRCREATE_FORCEEND;
583 else if (IsMarking())
585 eEvent=SDREVENT_ENDMARK;
586 if (!aDragStat.IsMinMoved())
588 eEvent=SDREVENT_BRKMARK;
589 rVEvt.bAddMark=MODKEY_MultiMark;
594 else
596 eEvent=SDREVENT_MOVACTION;
599 else if (eHit==SDRHIT_TEXTEDIT)
601 eEvent=SDREVENT_TEXTEDIT;
603 else if (bMouseDown && bMouseLeft)
605 if (rVEvt.nMouseClicks==2 && rVEvt.nMouseCode==MOUSE_LEFT && pObj!=NULL && pHitObj!=NULL && pHitObj->HasTextEdit() && eHit==SDRHIT_MARKEDOBJECT)
607 rVEvt.pRootObj=pObj;
608 pObj=pHitObj;
609 eEvent=SDREVENT_BEGTEXTEDIT;
611 else if (MODKEY_ForceMark && eHit!=SDRHIT_URLFIELD)
613 eEvent=SDREVENT_BEGMARK; // AddMark,Unmark */
615 else if (eHit==SDRHIT_HELPLINE)
617 eEvent=SDREVENT_BEGDRAGHELPLINE; // nothing, actually
619 else if (eHit==SDRHIT_GLUEPOINT)
621 eEvent=SDREVENT_MARKGLUEPOINT; // AddMark+Drag
622 rVEvt.bAddMark=MODKEY_MultiMark || MODKEY_DeepMark; // if not hit with Deep
624 else if (eHit==SDRHIT_HANDLE)
626 eEvent=SDREVENT_BEGDRAGOBJ; // Mark+Drag,AddMark+Drag,DeepMark+Drag,Unmark
627 sal_Bool bGlue=pHdl->GetKind()==HDL_GLUE;
628 sal_Bool bPoly=!bGlue && IsPointMarkable(*pHdl);
629 sal_Bool bMarked=bGlue || (bPoly && pHdl->IsSelected());
630 if (bGlue || bPoly)
632 eEvent=bGlue ? SDREVENT_MARKGLUEPOINT : SDREVENT_MARKPOINT;
633 if (MODKEY_DeepMark)
635 rVEvt.bAddMark=sal_True;
636 rVEvt.bPrevNextMark=sal_True;
637 rVEvt.bMarkPrev=MODKEY_DeepBackw;
639 else if (MODKEY_MultiMark)
641 rVEvt.bAddMark=sal_True;
642 rVEvt.bUnmark=bMarked; // Toggle
643 if (bGlue)
645 pObj=pHdl->GetObj();
646 nGlueId=(sal_uInt16)pHdl->GetObjHdlNum();
649 else if (bMarked)
651 eEvent=SDREVENT_BEGDRAGOBJ; // don't change MarkState, only change Drag
655 else if (bInsPolyPt && (MODKEY_PolyPoly || (!MODKEY_MultiMark && !MODKEY_DeepMark)))
657 eEvent=SDREVENT_BEGINSOBJPOINT;
658 rVEvt.bInsPointNewObj=MODKEY_PolyPoly;
660 else if (bInsGluePt && !MODKEY_MultiMark && !MODKEY_DeepMark)
662 eEvent=SDREVENT_BEGINSGLUEPOINT;
664 else if (eHit==SDRHIT_TEXTEDITOBJ)
666 eEvent=SDREVENT_BEGTEXTEDIT; // AddMark+Drag,DeepMark+Drag,Unmark
667 if (MODKEY_MultiMark || MODKEY_DeepMark)
668 { // if not hit with Deep
669 eEvent=SDREVENT_MARKOBJ;
672 else if (eHit==SDRHIT_MACRO)
674 eEvent=SDREVENT_BEGMACROOBJ; // AddMark+Drag
675 if (MODKEY_MultiMark || MODKEY_DeepMark)
676 { // if not hit with Deep
677 eEvent=SDREVENT_MARKOBJ;
680 else if (eHit==SDRHIT_URLFIELD)
682 eEvent=SDREVENT_EXECUTEURL; // AddMark+Drag
683 if (MODKEY_MultiMark || MODKEY_DeepMark)
684 { // if not hit with Deep
685 eEvent=SDREVENT_MARKOBJ;
688 else if (eHit==SDRHIT_MARKEDOBJECT)
690 eEvent=SDREVENT_BEGDRAGOBJ; // DeepMark+Drag,Unmark
692 if (MODKEY_MultiMark || MODKEY_DeepMark)
693 { // if not hit with Deep
694 eEvent=SDREVENT_MARKOBJ;
697 else if (IsCreateMode())
699 eEvent=SDREVENT_BEGCREATEOBJ; // nothing, actually
701 else if (eHit==SDRHIT_UNMARKEDOBJECT)
703 eEvent=SDREVENT_MARKOBJ; // AddMark+Drag
705 else
707 eEvent=SDREVENT_BEGMARK;
710 if (eEvent==SDREVENT_MARKOBJ)
712 rVEvt.bAddMark=MODKEY_MultiMark || MODKEY_DeepMark; // if not hit with Deep
713 rVEvt.bPrevNextMark=MODKEY_DeepMark;
714 rVEvt.bMarkPrev=MODKEY_DeepMark && MODKEY_DeepBackw;
716 if (eEvent==SDREVENT_BEGMARK)
718 rVEvt.bAddMark=MODKEY_MultiMark;
719 rVEvt.bUnmark=MODKEY_Unmark;
722 rVEvt.bIsAction=bIsAction;
723 rVEvt.bIsTextEdit=bIsTextEdit;
724 rVEvt.bTextEditHit=bTextEditHit;
725 rVEvt.aLogicPos=aLocalLogicPosition;
726 rVEvt.pHdl=pHdl;
727 rVEvt.pObj=pObj;
728 if(rVEvt.pRootObj==NULL)
729 rVEvt.pRootObj=pObj;
730 rVEvt.pPV=pPV;
731 rVEvt.nHlplIdx=nHlplIdx;
732 rVEvt.nGlueId=nGlueId;
733 rVEvt.eHit=eHit;
734 rVEvt.eEvent=eEvent;
735 rVEvt.bCaptureMouse=bMouseLeft && bMouseDown && eEvent!=SDREVENT_NONE;
736 rVEvt.bReleaseMouse=bMouseLeft && bMouseUp;
737 #ifdef DGB_UTIL
738 if (rVEvt.pRootObj!=NULL) {
739 if (rVEvt.pRootObj->GetObjList()!=rVEvt.pPV->GetObjList()) {
740 OSL_FAIL("SdrView::PickAnything(): pRootObj->GetObjList()!=pPV->GetObjList() !");
743 #endif
744 return eHit;
747 sal_Bool SdrView::DoMouseEvent(const SdrViewEvent& rVEvt)
749 sal_Bool bRet=sal_False;
750 SdrHitKind eHit=rVEvt.eHit;
751 Point aLogicPos(rVEvt.aLogicPos);
753 sal_Bool bShift=(rVEvt.nMouseCode & KEY_SHIFT) !=0;
754 sal_Bool bCtrl=(rVEvt.nMouseCode & KEY_MOD1) !=0;
755 sal_Bool bAlt=(rVEvt.nMouseCode & KEY_MOD2) !=0;
756 sal_Bool bMouseLeft=(rVEvt.nMouseCode&MOUSE_LEFT)!=0;
757 sal_Bool bMouseDown=rVEvt.bMouseDown;
758 sal_Bool bMouseUp=rVEvt.bMouseUp;
759 if (bMouseDown) {
760 if (bMouseLeft) aDragStat.SetMouseDown(sal_True);
761 } else if (bMouseUp) {
762 if (bMouseLeft) aDragStat.SetMouseDown(sal_False);
763 } else { // else, MouseMove
764 aDragStat.SetMouseDown(bMouseLeft);
767 #ifdef MODKEY_NoSnap
768 SetSnapEnabled(!MODKEY_NoSnap);
769 #endif
770 #ifdef MODKEY_Ortho
771 SetOrtho(MODKEY_Ortho!=IsOrthoDesired());
772 #endif
773 #ifdef MODKEY_AngleSnap
774 SetAngleSnapEnabled(MODKEY_AngleSnap);
775 #endif
776 #ifdef MODKEY_CopyDrag
777 SetDragWithCopy(MODKEY_CopyDrag);
778 #endif
779 #ifdef MODKEY_Center
780 SetCreate1stPointAsCenter(MODKEY_Center);
781 SetResizeAtCenter(MODKEY_Center);
782 SetCrookAtCenter(MODKEY_Center);
783 #endif
784 if (bMouseLeft && bMouseDown && rVEvt.bIsTextEdit && (eHit==SDRHIT_UNMARKEDOBJECT || eHit==SDRHIT_NONE)) {
785 SdrEndTextEdit(); // User has clicked beneath object, exit edit mode.
786 // pHdl is invalid, then, that shouldn't matter, though, as we expect
787 // pHdl==NULL (because of eHit).
789 switch (rVEvt.eEvent) {
790 case SDREVENT_NONE: bRet=sal_False; break;
791 case SDREVENT_TEXTEDIT: bRet=sal_False; break; // Events handled by the OutlinerView are not taken into account here.
792 case SDREVENT_MOVACTION: MovAction(aLogicPos); bRet=sal_True; break;
793 case SDREVENT_ENDACTION: EndAction(); bRet=sal_True; break;
794 case SDREVENT_BCKACTION: BckAction(); bRet=sal_True; break;
795 case SDREVENT_BRKACTION: BrkAction(); bRet=sal_True; break;
796 case SDREVENT_ENDMARK : EndAction(); bRet=sal_True; break;
797 case SDREVENT_BRKMARK : {
798 BrkAction();
799 if (!MarkObj(aLogicPos,nHitTolLog,rVEvt.bAddMark)) {
800 // No object hit. Do the following:
801 // 1. deselect any selected glue points
802 // 2. deselect any selected polygon points
803 // 3. deselect any selected objects
804 if (!rVEvt.bAddMark) UnmarkAll();
806 bRet=sal_True;
807 } break;
808 case SDREVENT_ENDCREATE: { // if necessary, MarkObj
809 SdrCreateCmd eCmd=SDRCREATE_NEXTPOINT;
810 if (MODKEY_PolyPoly) eCmd=SDRCREATE_NEXTOBJECT;
811 if (rVEvt.nMouseClicks>1) eCmd=SDRCREATE_FORCEEND;
812 if (!EndCreateObj(eCmd)) { // Don't evaluate event for Create? -> Select
813 if (eHit==SDRHIT_UNMARKEDOBJECT || eHit==SDRHIT_TEXTEDIT) {
814 MarkObj(rVEvt.pRootObj,rVEvt.pPV);
815 if (eHit==SDRHIT_TEXTEDIT)
817 bool bRet2(pActualOutDev && OUTDEV_WINDOW == pActualOutDev->GetOutDevType() &&
818 SdrBeginTextEdit(rVEvt.pObj, rVEvt.pPV, (Window*)pActualOutDev, sal_False, (SdrOutliner*)0L));
820 if(bRet2)
822 MouseEvent aMEvt(pActualOutDev->LogicToPixel(aLogicPos),
823 1,rVEvt.nMouseMode,rVEvt.nMouseCode,rVEvt.nMouseCode);
825 OutlinerView* pOLV=GetTextEditOutlinerView();
826 if (pOLV!=NULL) {
827 pOLV->MouseButtonDown(aMEvt); // event for the Outliner, but without double-click
828 pOLV->MouseButtonUp(aMEvt); // event for the Outliner, but without double-click
832 bRet=sal_True; // object is selected and (if necessary) TextEdit is started
833 } else bRet=sal_False; // canceled Create, nothing else
834 } else bRet=sal_True; // return sal_True for EndCreate
835 } break;
836 case SDREVENT_ENDDRAG: {
837 bRet=EndDragObj(IsDragWithCopy());
838 ForceMarkedObjToAnotherPage(); // TODO: Undo+bracing missing!
839 } break;
840 case SDREVENT_MARKOBJ: { // + (if applicable) BegDrag
841 if (!rVEvt.bAddMark) UnmarkAllObj();
842 sal_Bool bUnmark=rVEvt.bUnmark;
843 if (rVEvt.bPrevNextMark) {
844 bRet=MarkNextObj(aLogicPos,nHitTolLog,rVEvt.bMarkPrev);
845 } else {
846 SortMarkedObjects();
847 sal_uIntPtr nAnz0=GetMarkedObjectCount();
848 bRet=MarkObj(aLogicPos,nHitTolLog,rVEvt.bAddMark);
849 SortMarkedObjects();
850 sal_uIntPtr nAnz1=GetMarkedObjectCount();
851 bUnmark=nAnz1<nAnz0;
853 if (!bUnmark) {
854 BegDragObj(aLogicPos,NULL,(SdrHdl*)NULL,nMinMovLog);
855 bRet=sal_True;
857 } break;
858 case SDREVENT_MARKPOINT: { // + (if applicable) BegDrag
859 if (!rVEvt.bAddMark) UnmarkAllPoints();
860 if (rVEvt.bPrevNextMark) {
861 bRet=MarkNextPoint(aLogicPos,rVEvt.bMarkPrev);
862 } else {
863 bRet=MarkPoint(*rVEvt.pHdl,rVEvt.bUnmark);
865 if (!rVEvt.bUnmark && !rVEvt.bPrevNextMark) {
866 BegDragObj(aLogicPos,NULL,rVEvt.pHdl,nMinMovLog);
867 bRet=sal_True;
869 } break;
870 case SDREVENT_MARKGLUEPOINT: { // + (if applicable) BegDrag
871 if (!rVEvt.bAddMark) UnmarkAllGluePoints();
872 if (rVEvt.bPrevNextMark) {
873 bRet=MarkNextGluePoint(aLogicPos,rVEvt.bMarkPrev);
874 } else {
875 bRet=MarkGluePoint(rVEvt.pObj,rVEvt.nGlueId,rVEvt.pPV,rVEvt.bUnmark);
877 if (!rVEvt.bUnmark && !rVEvt.bPrevNextMark) {
878 SdrHdl* pHdl=GetGluePointHdl(rVEvt.pObj,rVEvt.nGlueId);
879 BegDragObj(aLogicPos,NULL,pHdl,nMinMovLog);
880 bRet=sal_True;
882 } break;
883 case SDREVENT_BEGMARK: bRet=BegMark(aLogicPos,rVEvt.bAddMark,rVEvt.bUnmark); break;
884 case SDREVENT_BEGINSOBJPOINT: bRet = BegInsObjPoint(aLogicPos, MODKEY_PolyPoly); break;
885 case SDREVENT_ENDINSOBJPOINT: {
886 SdrCreateCmd eCmd=SDRCREATE_NEXTPOINT;
887 if (MODKEY_PolyPoly) eCmd=SDRCREATE_NEXTOBJECT;
888 if (rVEvt.nMouseClicks>1) eCmd=SDRCREATE_FORCEEND;
889 EndInsObjPoint(eCmd);
890 bRet=sal_True;
891 } break;
892 case SDREVENT_BEGINSGLUEPOINT: bRet=BegInsGluePoint(aLogicPos); break;
893 case SDREVENT_BEGDRAGHELPLINE: bRet=BegDragHelpLine(rVEvt.nHlplIdx,rVEvt.pPV); break;
894 case SDREVENT_BEGDRAGOBJ: bRet=BegDragObj(aLogicPos,NULL,rVEvt.pHdl,nMinMovLog); break;
895 case SDREVENT_BEGCREATEOBJ: {
896 if (nAktInvent==SdrInventor && nAktIdent==OBJ_CAPTION) {
897 long nHgt=SdrEngineDefaults::GetFontHeight();
898 bRet=BegCreateCaptionObj(aLogicPos,Size(5*nHgt,2*nHgt));
899 } else bRet=BegCreateObj(aLogicPos);
900 } break;
901 case SDREVENT_BEGMACROOBJ: bRet=BegMacroObj(aLogicPos,nHitTolLog,rVEvt.pObj,rVEvt.pPV,(Window*)pActualOutDev); break;
902 case SDREVENT_BEGTEXTEDIT: {
903 if (!IsObjMarked(rVEvt.pObj)) {
904 UnmarkAllObj();
905 MarkObj(rVEvt.pRootObj,rVEvt.pPV);
908 bRet = pActualOutDev && OUTDEV_WINDOW == pActualOutDev->GetOutDevType()&&
909 SdrBeginTextEdit(rVEvt.pObj, rVEvt.pPV, (Window*)pActualOutDev, sal_False, (SdrOutliner*)0L);
911 if(bRet)
913 MouseEvent aMEvt(pActualOutDev->LogicToPixel(aLogicPos),
914 1,rVEvt.nMouseMode,rVEvt.nMouseCode,rVEvt.nMouseCode);
915 OutlinerView* pOLV=GetTextEditOutlinerView();
916 if (pOLV!=NULL) pOLV->MouseButtonDown(aMEvt); // event for the Outliner, but without double-click
918 } break;
919 default: break;
920 } // switch
921 if (bRet && pActualOutDev!=NULL && pActualOutDev->GetOutDevType()==OUTDEV_WINDOW) {
922 Window* pWin=(Window*)pActualOutDev;
923 // left mouse button pressed?
924 bool bLeftDown=(rVEvt.nMouseCode&MOUSE_LEFT)!=0 && rVEvt.bMouseDown;
925 // left mouse button released?
926 bool bLeftUp=(rVEvt.nMouseCode&MOUSE_LEFT)!=0 && rVEvt.bMouseUp;
927 // left mouse button pressed or held?
928 sal_Bool bLeftDown1=(rVEvt.nMouseCode&MOUSE_LEFT)!=0 && !rVEvt.bMouseUp;
929 pWin->SetPointer(GetPreferedPointer(rVEvt.aLogicPos,pWin,
930 rVEvt.nMouseCode & (KEY_SHIFT|KEY_MOD1|KEY_MOD2),bLeftDown1));
931 sal_Bool bAction=IsAction();
932 if (bLeftDown && bAction) pWin->CaptureMouse();
933 else if (bLeftUp || (rVEvt.bIsAction && !bAction)) pWin->ReleaseMouse();
935 return bRet;
937 #include <editeng/outlobj.hxx>
939 Pointer SdrView::GetPreferedPointer(const Point& rMousePos, const OutputDevice* pOut, sal_uInt16 nModifier, sal_Bool bLeftDown) const
941 // Actions
942 if (IsCreateObj())
944 return pAktCreate->GetCreatePointer();
946 if (mpCurrentSdrDragMethod)
948 if ((IsDraggingPoints() || IsDraggingGluePoints()) && IsMouseHideWhileDraggingPoints())
949 return Pointer(POINTER_NULL);
951 return mpCurrentSdrDragMethod->GetSdrDragPointer();
953 if (IsMarkObj() || IsMarkPoints() || IsMarkGluePoints() || IsSetPageOrg()) return Pointer(POINTER_ARROW);
954 if (IsDragHelpLine()) return GetDraggedHelpLinePointer();
955 if (IsMacroObj()) {
956 SdrObjMacroHitRec aHitRec;
957 aHitRec.aPos=pOut->LogicToPixel(rMousePos);
958 aHitRec.aDownPos=aMacroDownPos;
959 aHitRec.nTol=nMacroTol;
960 aHitRec.pVisiLayer=&pMacroPV->GetVisibleLayers();
961 aHitRec.pPageView=pMacroPV;
962 aHitRec.pOut=pMacroWin;
963 aHitRec.bDown=bMacroDown;
964 return pMacroObj->GetMacroPointer(aHitRec);
967 // TextEdit, ObjEdit, Macro
968 if (IsTextEdit() && (IsTextEditInSelectionMode() || IsTextEditHit(rMousePos,0/*nTol*/)))
970 if(!pOut || IsTextEditInSelectionMode())
972 if(pTextEditOutliner->IsVertical())
973 return Pointer(POINTER_TEXT_VERTICAL);
974 else
975 return Pointer(POINTER_TEXT);
977 // Outliner should return something here...
978 Point aPos(pOut->LogicToPixel(rMousePos));
979 Pointer aPointer(pTextEditOutlinerView->GetPointer(aPos));
980 if (aPointer==POINTER_ARROW)
982 if(pTextEditOutliner->IsVertical())
983 aPointer = POINTER_TEXT_VERTICAL;
984 else
985 aPointer = POINTER_TEXT;
987 return aPointer;
990 SdrViewEvent aVEvt;
991 aVEvt.nMouseCode=(nModifier&(KEY_SHIFT|KEY_MOD1|KEY_MOD2))|MOUSE_LEFT; // to see what would happen on MouseLeftDown
992 aVEvt.bMouseDown=!bLeftDown; // What if ..?
993 aVEvt.bMouseUp=bLeftDown; // What if ..?
994 if (pOut!=NULL)
995 ((SdrView*)this)->SetActualWin(pOut);
996 SdrHitKind eHit=PickAnything(rMousePos,aVEvt);
997 SdrEventKind eEvent=aVEvt.eEvent;
998 switch (eEvent)
1000 case SDREVENT_BEGCREATEOBJ:
1001 return aAktCreatePointer;
1002 case SDREVENT_MARKOBJ:
1003 case SDREVENT_BEGMARK:
1004 return Pointer(POINTER_ARROW);
1005 case SDREVENT_MARKPOINT:
1006 case SDREVENT_MARKGLUEPOINT:
1007 return Pointer(POINTER_MOVEPOINT);
1008 case SDREVENT_BEGINSOBJPOINT:
1009 case SDREVENT_BEGINSGLUEPOINT:
1010 return Pointer(POINTER_CROSS);
1011 case SDREVENT_EXECUTEURL:
1012 return Pointer(POINTER_REFHAND);
1013 case SDREVENT_BEGMACROOBJ:
1015 SdrObjMacroHitRec aHitRec;
1016 aHitRec.aPos=aVEvt.aLogicPos;
1017 aHitRec.aDownPos=aHitRec.aPos;
1018 aHitRec.nTol=nHitTolLog;
1019 aHitRec.pVisiLayer=&aVEvt.pPV->GetVisibleLayers();
1020 aHitRec.pPageView=aVEvt.pPV;
1021 aHitRec.pOut=(OutputDevice*)pOut;
1022 return aVEvt.pObj->GetMacroPointer(aHitRec);
1024 default: break;
1025 } // switch
1027 switch(eHit)
1029 case SDRHIT_CELL:
1030 return Pointer(POINTER_ARROW);
1031 case SDRHIT_HELPLINE :
1032 return aVEvt.pPV->GetHelpLines()[aVEvt.nHlplIdx].GetPointer();
1033 case SDRHIT_GLUEPOINT:
1034 return Pointer(POINTER_MOVEPOINT);
1035 case SDRHIT_TEXTEDIT :
1036 case SDRHIT_TEXTEDITOBJ:
1038 SdrTextObj* pText = dynamic_cast< SdrTextObj* >( aVEvt.pObj );
1039 if(pText && pText->HasText())
1041 OutlinerParaObject* pParaObj = pText->GetOutlinerParaObject();
1042 if(pParaObj && pParaObj->IsVertical())
1043 return Pointer(POINTER_TEXT_VERTICAL);
1045 return Pointer(POINTER_TEXT);
1047 default: break;
1050 bool bMarkHit=eHit==SDRHIT_MARKEDOBJECT;
1051 SdrHdl* pHdl=aVEvt.pHdl;
1052 // now check the pointers for dragging
1053 if (pHdl!=NULL || bMarkHit) {
1054 SdrHdlKind eHdl= pHdl!=NULL ? pHdl->GetKind() : HDL_MOVE;
1055 bool bCorner=pHdl!=NULL && pHdl->IsCornerHdl();
1056 bool bVertex=pHdl!=NULL && pHdl->IsVertexHdl();
1057 bool bMov=eHdl==HDL_MOVE;
1058 if (bMov && (eDragMode==SDRDRAG_MOVE || eDragMode==SDRDRAG_RESIZE || bMarkedHitMovesAlways)) {
1059 if (!IsMoveAllowed()) return Pointer(POINTER_ARROW); // because double click or drag & drop is possible
1060 return Pointer(POINTER_MOVE);
1062 switch (eDragMode) {
1063 case SDRDRAG_ROTATE: {
1064 if ((bCorner || bMov) && !IsRotateAllowed(sal_True))
1065 return Pointer(POINTER_NOTALLOWED);
1067 // are 3D objects selected?
1068 bool b3DObjSelected = false;
1069 for (sal_uInt32 a=0; !b3DObjSelected && a<GetMarkedObjectCount(); a++) {
1070 SdrObject* pObj = GetMarkedObjectByIndex(a);
1071 if(pObj && pObj->ISA(E3dObject))
1072 b3DObjSelected = true;
1074 // If we have a 3D object, go on despite !IsShearAllowed,
1075 // because then we have a rotation instead of a shear.
1076 if (bVertex && !IsShearAllowed() && !b3DObjSelected)
1077 return Pointer(POINTER_NOTALLOWED);
1078 if (bMov)
1079 return Pointer(POINTER_ROTATE);
1080 } break;
1081 case SDRDRAG_SHEAR: case SDRDRAG_DISTORT: {
1082 if (bCorner) {
1083 if (!IsDistortAllowed(sal_True) && !IsDistortAllowed(sal_False)) return Pointer(POINTER_NOTALLOWED);
1084 else return Pointer(POINTER_REFHAND);
1086 if (bVertex && !IsShearAllowed()) return Pointer(POINTER_NOTALLOWED);
1087 if (bMov) {
1088 if (!IsMoveAllowed()) return Pointer(POINTER_ARROW); // because double click or drag & drop is possible
1089 return Pointer(POINTER_MOVE);
1091 } break;
1092 case SDRDRAG_MIRROR: {
1093 if (bCorner || bVertex || bMov) {
1094 SdrHdl* pH1=aHdl.GetHdl(HDL_REF1);
1095 SdrHdl* pH2=aHdl.GetHdl(HDL_REF2);
1096 bool b90=false;
1097 bool b45=false;
1098 Point aDif;
1099 if (pH1!=NULL && pH2!=NULL) {
1100 aDif=pH2->GetPos()-pH1->GetPos();
1101 b90=(aDif.X()==0) || aDif.Y()==0;
1102 b45=b90 || (std::abs(aDif.X())==std::abs(aDif.Y()));
1104 bool bNo=false;
1105 if (!IsMirrorAllowed(sal_True,sal_True)) bNo=true; // any mirroring is forbidden
1106 if (!IsMirrorAllowed(sal_False,sal_False) && !b45) bNo=true; // mirroring freely is forbidden
1107 if (!IsMirrorAllowed(sal_True,sal_False) && !b90) bNo=true; // mirroring horizontally/vertically is allowed
1108 if (bNo) return Pointer(POINTER_NOTALLOWED);
1109 if (b90) {
1110 return Pointer(POINTER_MIRROR);
1112 return Pointer(POINTER_MIRROR);
1114 } break;
1116 case SDRDRAG_TRANSPARENCE:
1118 if(!IsTransparenceAllowed())
1119 return Pointer(POINTER_NOTALLOWED);
1121 return Pointer(POINTER_REFHAND);
1124 case SDRDRAG_GRADIENT:
1126 if(!IsGradientAllowed())
1127 return Pointer(POINTER_NOTALLOWED);
1129 return Pointer(POINTER_REFHAND);
1132 case SDRDRAG_CROOK: {
1133 if (bCorner || bVertex || bMov) {
1134 if (!IsCrookAllowed(sal_True) && !IsCrookAllowed(sal_False)) return Pointer(POINTER_NOTALLOWED);
1135 return Pointer(POINTER_CROOK);
1139 case SDRDRAG_CROP:
1141 return Pointer(POINTER_CROP);
1144 default: {
1145 if ((bCorner || bVertex) && !IsResizeAllowed(sal_True)) return Pointer(POINTER_NOTALLOWED);
1148 if (pHdl!=NULL) return pHdl->GetPointer();
1149 if (bMov) {
1150 if (!IsMoveAllowed()) return Pointer(POINTER_ARROW); // because double click or drag & drop is possible
1151 return Pointer(POINTER_MOVE);
1154 if (eEditMode==SDREDITMODE_CREATE) return aAktCreatePointer;
1155 return Pointer(POINTER_ARROW);
1158 #define STR_NOTHING "nothing"
1159 XubString SdrView::GetStatusText()
1161 XubString aStr;
1162 XubString aName;
1164 aStr.AppendAscii(STR_NOTHING);
1166 if (pAktCreate!=NULL)
1168 aStr=pAktCreate->getSpecialDragComment(aDragStat);
1170 if(!aStr.Len())
1172 pAktCreate->TakeObjNameSingul(aName);
1173 aStr = ImpGetResStr(STR_ViewCreateObj);
1176 else if (mpCurrentSdrDragMethod)
1178 if (bInsPolyPoint || IsInsertGluePoint())
1180 aStr=aInsPointUndoStr;
1182 else
1184 if (aDragStat.IsMinMoved())
1186 OSL_TRACE("SdrView::GetStatusText(%lx) %lx", this, mpCurrentSdrDragMethod);
1187 mpCurrentSdrDragMethod->TakeSdrDragComment(aStr);
1191 else if(IsMarkObj())
1193 if(AreObjectsMarked())
1195 aStr = ImpGetResStr(STR_ViewMarkMoreObjs);
1197 else
1199 aStr = ImpGetResStr(STR_ViewMarkObjs);
1202 else if(IsMarkPoints())
1204 if(HasMarkedPoints())
1206 aStr = ImpGetResStr(STR_ViewMarkMorePoints);
1208 else
1210 aStr = ImpGetResStr(STR_ViewMarkPoints);
1212 } else if (IsMarkGluePoints())
1214 if(HasMarkedGluePoints())
1216 aStr = ImpGetResStr(STR_ViewMarkMoreGluePoints);
1218 else
1220 aStr = ImpGetResStr(STR_ViewMarkGluePoints);
1223 else if (IsTextEdit() && pTextEditOutlinerView!=NULL) {
1224 aStr=ImpGetResStr(STR_ViewTextEdit); // "TextEdit - Row y, Column x";
1225 ESelection aSel(pTextEditOutlinerView->GetSelection());
1226 long nPar=aSel.nEndPara,nLin=0,nCol=aSel.nEndPos;
1227 if (aSel.nEndPara>0) {
1228 for (sal_Int32 nParaNum=0; nParaNum<aSel.nEndPara; nParaNum++) {
1229 nLin+=pTextEditOutliner->GetLineCount(nParaNum);
1232 // A little imperfection:
1233 // At the end of a line of any multi-line paragraph, we display the
1234 // position of the next line of the same paragraph, if there is one.
1235 sal_uInt16 nParaLine=0;
1236 sal_uIntPtr nParaLineAnz=pTextEditOutliner->GetLineCount(aSel.nEndPara);
1237 bool bBrk=false;
1238 while (!bBrk) {
1239 sal_uInt16 nLen=pTextEditOutliner->GetLineLen(aSel.nEndPara,nParaLine);
1240 sal_Bool bLastLine=(nParaLine==nParaLineAnz-1);
1241 if (nCol>nLen || (!bLastLine && nCol==nLen)) {
1242 nCol-=nLen;
1243 nLin++;
1244 nParaLine++;
1245 } else bBrk=true;
1246 if (nLen==0) bBrk=true; // to be sure
1249 aStr.SearchAndReplaceAscii("%1", OUString::valueOf(nPar + 1));
1250 aStr.SearchAndReplaceAscii("%2", OUString::valueOf(nLin + 1));
1251 aStr.SearchAndReplaceAscii("%3", OUString::valueOf(nCol + 1));
1253 #ifdef DBG_UTIL
1254 aStr += OUString( ", Level " );
1255 aStr += OUString::valueOf( sal_Int32( pTextEditOutliner->GetDepth( aSel.nEndPara )) );
1256 #endif
1259 if(aStr.EqualsAscii(STR_NOTHING))
1261 if (AreObjectsMarked()) {
1262 ImpTakeDescriptionStr(STR_ViewMarked,aStr);
1263 if (IsGluePointEditMode()) {
1264 if (HasMarkedGluePoints()) {
1265 ImpTakeDescriptionStr(STR_ViewMarked,aStr,0,IMPSDR_GLUEPOINTSDESCRIPTION);
1267 } else {
1268 if (HasMarkedPoints()) {
1269 ImpTakeDescriptionStr(STR_ViewMarked,aStr,0,IMPSDR_POINTSDESCRIPTION);
1272 } else {
1273 aStr.Erase();
1276 else if(aName.Len())
1278 aStr.SearchAndReplaceAscii("%1", aName);
1281 if(aStr.Len())
1283 // capitalize first letter
1284 OUString aTmpStr(aStr.Copy(0, 1));
1285 aStr.Replace(0, 1, aTmpStr.toAsciiUpperCase());
1287 return aStr;
1290 SdrViewContext SdrView::GetContext() const
1292 if( IsGluePointEditMode() )
1293 return SDRCONTEXT_GLUEPOINTEDIT;
1295 const sal_uIntPtr nMarkAnz = GetMarkedObjectCount();
1297 if( HasMarkablePoints() && !IsFrameHandles() )
1299 bool bPath=true;
1300 for( sal_uIntPtr nMarkNum = 0; nMarkNum < nMarkAnz && bPath; nMarkNum++ )
1301 if (!GetMarkedObjectByIndex(nMarkNum)->ISA(SdrPathObj))
1302 bPath=false;
1304 if( bPath )
1305 return SDRCONTEXT_POINTEDIT;
1308 if( GetMarkedObjectCount() )
1310 bool bGraf = true, bMedia = true, bTable = true;
1312 for( sal_uIntPtr nMarkNum = 0; nMarkNum < nMarkAnz && ( bGraf || bMedia ); nMarkNum++ )
1314 const SdrObject* pMarkObj = GetMarkedObjectByIndex( nMarkNum );
1315 DBG_ASSERT( pMarkObj, "SdrView::GetContext(), null pointer in mark list!" );
1317 if( !pMarkObj )
1318 continue;
1320 if( !pMarkObj->ISA( SdrGrafObj ) )
1321 bGraf = false;
1323 if( !pMarkObj->ISA( SdrMediaObj ) )
1324 bMedia = false;
1326 if( !pMarkObj->ISA( ::sdr::table::SdrTableObj ) )
1327 bTable = false;
1330 if( bGraf )
1331 return SDRCONTEXT_GRAPHIC;
1332 else if( bMedia )
1333 return SDRCONTEXT_MEDIA;
1334 else if( bTable )
1335 return SDRCONTEXT_TABLE;
1338 return SDRCONTEXT_STANDARD;
1341 void SdrView::MarkAll()
1343 if (IsTextEdit()) {
1344 GetTextEditOutlinerView()->SetSelection(ESelection(0,0,EE_PARA_ALL,EE_TEXTPOS_ALL));
1345 #ifdef DBG_UTIL
1346 if (pItemBrowser!=NULL) pItemBrowser->SetDirty();
1347 #endif
1348 } else if (IsGluePointEditMode()) MarkAllGluePoints();
1349 else if (HasMarkablePoints()) MarkAllPoints();
1350 else MarkAllObj();
1353 void SdrView::UnmarkAll()
1355 if (IsTextEdit()) {
1356 ESelection eSel=GetTextEditOutlinerView()->GetSelection();
1357 eSel.nStartPara=eSel.nEndPara;
1358 eSel.nStartPos=eSel.nEndPos;
1359 GetTextEditOutlinerView()->SetSelection(eSel);
1360 #ifdef DBG_UTIL
1361 if (pItemBrowser!=NULL) pItemBrowser->SetDirty();
1362 #endif
1363 } else if (HasMarkedGluePoints()) UnmarkAllGluePoints();
1364 else if (HasMarkedPoints()) UnmarkAllPoints(); // Marked, not Markable!
1365 else UnmarkAllObj();
1368 const Rectangle& SdrView::GetMarkedRect() const
1370 if (IsGluePointEditMode() && HasMarkedGluePoints()) {
1371 return GetMarkedGluePointsRect();
1373 if (HasMarkedPoints()) {
1374 return GetMarkedPointsRect();
1376 return GetMarkedObjRect();
1379 void SdrView::DeleteMarked()
1381 if (IsTextEdit())
1383 SdrObjEditView::KeyInput(KeyEvent(0,KeyCode(KEYFUNC_DELETE)),pTextEditWin);
1385 else
1387 if( mxSelectionController.is() && mxSelectionController->DeleteMarked() )
1389 // action already performed by current selection controller, do nothing
1391 else if (IsGluePointEditMode() && HasMarkedGluePoints())
1393 DeleteMarkedGluePoints();
1395 else if (GetContext()==SDRCONTEXT_POINTEDIT && HasMarkedPoints())
1397 DeleteMarkedPoints();
1399 else
1401 DeleteMarkedObj();
1406 sal_Bool SdrView::BegMark(const Point& rPnt, sal_Bool bAddMark, sal_Bool bUnmark)
1408 if (bUnmark) bAddMark=sal_True;
1409 if (IsGluePointEditMode()) {
1410 if (!bAddMark) UnmarkAllGluePoints();
1411 return BegMarkGluePoints(rPnt,bUnmark);
1412 } else if (HasMarkablePoints()) {
1413 if (!bAddMark) UnmarkAllPoints();
1414 return BegMarkPoints(rPnt,bUnmark);
1415 } else {
1416 if (!bAddMark) UnmarkAllObj();
1417 return BegMarkObj(rPnt,bUnmark);
1421 void SdrView::ConfigurationChanged( ::utl::ConfigurationBroadcaster*p, sal_uInt32 nHint)
1423 onAccessibilityOptionsChanged();
1424 SdrCreateView::ConfigurationChanged(p, nHint);
1427 SvtAccessibilityOptions& SdrView::getAccessibilityOptions()
1429 return maAccessibilityOptions;
1432 /** method is called whenever the global SvtAccessibilityOptions is changed */
1433 void SdrView::onAccessibilityOptionsChanged()
1437 void SdrView::SetMasterPagePaintCaching(sal_Bool bOn)
1439 if(mbMasterPagePaintCaching != bOn)
1441 mbMasterPagePaintCaching = bOn;
1443 // reset at all SdrPageWindows
1444 SdrPageView* pPageView = GetSdrPageView();
1446 if(pPageView)
1448 for(sal_uInt32 b(0L); b < pPageView->PageWindowCount(); b++)
1450 SdrPageWindow* pPageWindow = pPageView->GetPageWindow(b);
1451 DBG_ASSERT(pPageWindow, "SdrView::SetMasterPagePaintCaching: Corrupt SdrPageWindow list (!)");
1453 // force deletion of ObjectContact, so at re-display all VOCs
1454 // will be re-created with updated flag setting
1455 pPageWindow->ResetObjectContact();
1458 // force redraw of this view
1459 pPageView->InvalidateAllWin();
1465 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */