1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: drawbase.cxx,v $
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_sw.hxx"
33 #include <hintids.hxx>
34 #include <tools/list.hxx>
35 #include <svx/svdview.hxx>
36 #include <svx/svdobj.hxx>
37 #include <svtools/ptitem.hxx>
38 #include <svx/sizeitem.hxx>
39 #include <sfx2/request.hxx>
40 #include <sfx2/bindings.hxx>
41 #include <fmtclds.hxx>
47 #include "drawbase.hxx"
49 #include "caption.hxx"
52 #include "comcore.hrc"
54 using namespace ::com::sun::star
;
56 extern BOOL bNoInterrupt
; // in mainwn.cxx
58 #define MINMOVE ((USHORT)m_pSh->GetOut()->PixelToLogic(Size(m_pSh->GetDrawView()->GetMarkHdlSizePixel()/2,0)).Width())
61 /*************************************************************************
65 \************************************************************************/
68 SwDrawBase::SwDrawBase(SwWrtShell
* pSwWrtShell
, SwEditWin
* pWindow
, SwView
* pSwView
) :
76 if ( !m_pSh
->HasDrawView() )
77 m_pSh
->MakeDrawView();
80 /*************************************************************************
84 \************************************************************************/
86 __EXPORT
SwDrawBase::~SwDrawBase()
88 if (m_pView
->GetWrtShellPtr()) // Im view-Dtor koennte die wrtsh bereits geloescht worden sein...
89 m_pSh
->GetDrawView()->SetEditMode(TRUE
);
92 /*************************************************************************
94 |* MouseButtonDown-event
96 \************************************************************************/
99 BOOL
SwDrawBase::MouseButtonDown(const MouseEvent
& rMEvt
)
101 BOOL bReturn
= FALSE
;
103 SdrView
*pSdrView
= m_pSh
->GetDrawView();
106 // pSdrView->SetOrtho(rMEvt.IsShift());
107 pSdrView
->SetOrtho(doConstructOrthogonal() ? !rMEvt
.IsShift() : rMEvt
.IsShift());
108 pSdrView
->SetAngleSnapEnabled(rMEvt
.IsShift());
112 pSdrView
->SetCreate1stPointAsCenter(TRUE
);
113 pSdrView
->SetResizeAtCenter(TRUE
);
117 pSdrView
->SetCreate1stPointAsCenter(FALSE
);
118 pSdrView
->SetResizeAtCenter(FALSE
);
122 SdrHitKind eHit
= pSdrView
->PickAnything(rMEvt
, SDRMOUSEBUTTONDOWN
, aVEvt
);
124 // Nur neues Objekt, wenn nicht im Basismode (bzw reinem Selektionsmode)
125 if (rMEvt
.IsLeft() && !m_pWin
->IsDrawAction())
127 if (IsCreateObj() && (eHit
== SDRHIT_UNMARKEDOBJECT
|| eHit
== SDRHIT_NONE
|| m_pSh
->IsDrawCreate()))
130 m_pWin
->CaptureMouse();
132 m_aStartPos
= m_pWin
->PixelToLogic(rMEvt
.GetPosPixel());
134 bReturn
= m_pSh
->BeginCreate( static_cast< UINT16
>(m_pWin
->GetSdrDrawMode()), m_aStartPos
);
139 m_pWin
->SetDrawAction(TRUE
);
141 else if (!pSdrView
->IsAction())
143 /**********************************************************************
145 **********************************************************************/
146 m_pWin
->CaptureMouse();
147 m_aStartPos
= m_pWin
->PixelToLogic(rMEvt
.GetPosPixel());
148 UINT16 nEditMode
= m_pWin
->GetBezierMode();
150 if (eHit
== SDRHIT_HANDLE
&& aVEvt
.pHdl
->GetKind() == HDL_BWGT
)
152 /******************************************************************
154 ******************************************************************/
156 bReturn
= pSdrView
->BegDragObj(m_aStartPos
, (OutputDevice
*) NULL
, aVEvt
.pHdl
);
157 m_pWin
->SetDrawAction(TRUE
);
159 else if (eHit
== SDRHIT_MARKEDOBJECT
&& nEditMode
== SID_BEZIER_INSERT
)
161 /******************************************************************
162 * Klebepunkt einfuegen
163 ******************************************************************/
165 bReturn
= pSdrView
->BegInsObjPoint(m_aStartPos
, rMEvt
.IsMod1());
166 m_pWin
->SetDrawAction(TRUE
);
168 else if (eHit
== SDRHIT_MARKEDOBJECT
&& rMEvt
.IsMod1())
170 /******************************************************************
171 * Klebepunkt selektieren
172 ******************************************************************/
173 if (!rMEvt
.IsShift())
174 pSdrView
->UnmarkAllPoints();
176 bReturn
= pSdrView
->BegMarkPoints(m_aStartPos
);
177 m_pWin
->SetDrawAction(TRUE
);
179 else if (eHit
== SDRHIT_MARKEDOBJECT
&& !rMEvt
.IsShift() && !rMEvt
.IsMod2())
181 /******************************************************************
183 ******************************************************************/
186 else if (eHit
== SDRHIT_HANDLE
)
188 /******************************************************************
189 * Klebepunkt selektieren
190 ******************************************************************/
191 if (pSdrView
->HasMarkablePoints() && (!pSdrView
->IsPointMarked(*aVEvt
.pHdl
) || rMEvt
.IsShift()))
195 if (!rMEvt
.IsShift())
197 pSdrView
->UnmarkAllPoints();
198 pHdl
= pSdrView
->PickHandle(m_aStartPos
);
202 if (pSdrView
->IsPointMarked(*aVEvt
.pHdl
))
204 bReturn
= pSdrView
->UnmarkPoint(*aVEvt
.pHdl
);
209 pHdl
= pSdrView
->PickHandle(m_aStartPos
);
216 pSdrView
->MarkPoint(*pHdl
);
217 // bReturn = pSdrView->BegDragObj(m_aStartPos, (OutputDevice*) NULL, pHdl);
218 // m_pWin->SetDrawAction(TRUE);
224 /******************************************************************
225 * Objekt selektieren oder draggen
226 ******************************************************************/
227 if (m_pSh
->IsObjSelectable(m_aStartPos
) && eHit
== SDRHIT_UNMARKEDOBJECT
)
229 if (pSdrView
->HasMarkablePoints())
230 pSdrView
->UnmarkAllPoints();
232 bNoInterrupt
= FALSE
;
233 // Drag im edtwin verwenden
239 if (m_pSh
->IsObjSelected())
241 if (!rMEvt
.IsShift())
243 if (!pSdrView
->HasMarkablePoints())
245 //JP 10.10.2001: Bug 89619 - don't scroll the
246 // cursor into the visible area
247 BOOL bUnlockView
= !m_pSh
->IsViewLocked();
248 m_pSh
->LockView( TRUE
); //lock visible section
249 m_pSh
->SelectObj(Point(LONG_MAX
, LONG_MAX
)); // Alles deselektieren
251 m_pSh
->LockView( FALSE
);
254 pSdrView
->UnmarkAllPoints();
257 if (!m_pSh
->IsSelFrmMode())
258 m_pSh
->EnterSelFrmMode(NULL
);
260 if( 0 != (bReturn
= m_pSh
->BeginMark(m_aStartPos
)) )
261 m_pWin
->SetDrawAction(TRUE
);
270 /*************************************************************************
274 \************************************************************************/
277 BOOL
SwDrawBase::MouseMove(const MouseEvent
& rMEvt
)
279 SdrView
*pSdrView
= m_pSh
->GetDrawView();
280 Point
aPnt(m_pWin
->PixelToLogic(rMEvt
.GetPosPixel()));
283 if (IsCreateObj() && !m_pWin
->IsDrawSelMode() && pSdrView
->IsCreateObj())
286 // pSdrView->SetOrtho(rMEvt.IsShift());
287 pSdrView
->SetOrtho(doConstructOrthogonal() ? !rMEvt
.IsShift() : rMEvt
.IsShift());
288 pSdrView
->SetAngleSnapEnabled(rMEvt
.IsShift());
290 m_pSh
->MoveCreate(aPnt
);
293 else if (pSdrView
->IsAction() || pSdrView
->IsInsObjPoint() || pSdrView
->IsMarkPoints())
295 m_pSh
->MoveMark(aPnt
);
302 /*************************************************************************
304 |* MouseButtonUp-event
306 \************************************************************************/
309 BOOL
SwDrawBase::MouseButtonUp(const MouseEvent
& rMEvt
)
311 BOOL bReturn
= FALSE
;
312 BOOL bCheckShell
= FALSE
;
313 BOOL bAutoCap
= FALSE
;
315 Point
aPnt(m_pWin
->PixelToLogic(rMEvt
.GetPosPixel()));
317 if (IsCreateObj() && m_pSh
->IsDrawCreate() && !m_pWin
->IsDrawSelMode())
319 const SdrObjKind nDrawMode
= m_pWin
->GetSdrDrawMode();
320 //objects with multiple point may end at the start position
321 BOOL bMultiPoint
= OBJ_PLIN
== nDrawMode
||
322 OBJ_PATHLINE
== nDrawMode
||
323 OBJ_FREELINE
== nDrawMode
;
324 if(rMEvt
.IsRight() || (aPnt
== m_aStartPos
&& !bMultiPoint
))
326 m_pSh
->BreakCreate();
327 m_pView
->LeaveDrawCreate();
331 if (OBJ_NONE
== nDrawMode
)
333 SwRewriter aRewriter
;
335 aRewriter
.AddRule(UNDO_ARG1
, SW_RES(STR_FRAME
));
336 m_pSh
->StartUndo(UNDO_INSERT
, &aRewriter
);
339 m_pSh
->EndCreate(SDRCREATE_FORCEEND
);
340 if (OBJ_NONE
== nDrawMode
) // Textrahmen eingefuegt
342 uno::Reference
< frame::XDispatchRecorder
> xRecorder
=
343 m_pSh
->GetView().GetViewFrame()->GetBindings().GetRecorder();
344 if ( xRecorder
.is() )
346 SfxRequest
aReq(m_pSh
->GetView().GetViewFrame(),FN_INSERT_FRAME
);
347 aReq
.AppendItem(SfxUInt16Item( FN_INSERT_FRAME
, (USHORT
)FLY_AT_CNTNT
));
348 aReq
.AppendItem(SfxPointItem( FN_PARAM_1
, m_pSh
->GetAnchorObjDiff()));
349 aReq
.AppendItem(SvxSizeItem( FN_PARAM_2
, m_pSh
->GetObjSize()));
353 if(m_pWin
->GetFrmColCount() > 1)
355 SfxItemSet
aSet(m_pView
->GetPool(),RES_COL
,RES_COL
);
356 SwFmtCol
aCol((const SwFmtCol
&)aSet
.Get(RES_COL
));
357 aCol
.Init(m_pWin
->GetFrmColCount(), aCol
.GetGutterWidth(), aCol
.GetWishWidth());
359 // Vorlagen-AutoUpdate
360 SwFrmFmt
* pFmt
= m_pSh
->GetCurFrmFmt();
361 if(pFmt
&& pFmt
->IsAutoUpdateFmt())
362 m_pSh
->AutoUpdateFrame(pFmt
, aSet
);
364 m_pSh
->SetFlyFrmAttr( aSet
);
367 if (m_pWin
->GetSdrDrawMode() == OBJ_NONE
)
368 m_pSh
->EndUndo(UNDO_INSERT
);
373 EnterSelectMode(rMEvt
);
377 SdrView
*pSdrView
= m_pSh
->GetDrawView();
379 if (!pSdrView
->HasMarkablePoints())
381 /**********************************************************************
383 **********************************************************************/
384 if ((m_pSh
->GetDrawView()->IsMarkObj() || m_pSh
->GetDrawView()->IsMarkPoints())
387 bReturn
= m_pSh
->EndMark();
389 m_pWin
->SetDrawAction(FALSE
);
391 if (aPnt
== m_aStartPos
&& m_pSh
->IsObjSelectable(aPnt
))
393 m_pSh
->SelectObj(aPnt
, ( rMEvt
.IsShift() &&
394 m_pSh
->IsSelFrmMode()) ? SW_ADD_SELECT
: 0);
396 if (!m_pSh
->IsObjSelected())
398 m_pView
->LeaveDrawCreate(); // In Selektionsmode wechseln
400 m_pSh
->GetView().GetViewFrame()->GetBindings().Invalidate(SID_INSERT_DRAW
);
402 if (m_pSh
->IsSelFrmMode())
403 m_pSh
->LeaveSelFrmMode();
407 bCheckShell
= TRUE
; // ggf BezierShell anwerfen
409 else if (!m_pSh
->IsObjSelected() && !m_pWin
->IsDrawAction())
411 if (m_pSh
->IsObjSelectable(aPnt
))
412 m_pSh
->SelectObj(aPnt
, ( rMEvt
.IsShift() &&
413 m_pSh
->IsSelFrmMode() ) ? SW_ADD_SELECT
: 0 );
416 m_pView
->LeaveDrawCreate();
417 if (m_pSh
->IsSelFrmMode())
418 m_pSh
->LeaveSelFrmMode();
428 /**********************************************************************
430 **********************************************************************/
431 if ( pSdrView
->IsAction() )
433 if ( pSdrView
->IsInsObjPoint() )
434 bReturn
= pSdrView
->EndInsObjPoint(SDRCREATE_FORCEEND
);
435 else if (pSdrView
->IsMarkPoints() )
436 bReturn
= pSdrView
->EndMarkPoints();
439 pSdrView
->EndAction();
442 m_pWin
->SetDrawAction(FALSE
);
444 if (aPnt
== m_aStartPos
)
446 if (!m_pSh
->IsObjSelectable(aPnt
))
447 m_pSh
->SelectObj(Point(LONG_MAX
, LONG_MAX
));
450 if (!rMEvt
.IsShift())
451 pSdrView
->UnmarkAllPoints();
452 m_pSh
->SelectObj(aPnt
, (rMEvt
.IsShift() &&
453 m_pSh
->IsSelFrmMode()) ? SW_ADD_SELECT
:0);
456 if (!m_pSh
->IsObjSelected())
458 m_pView
->LeaveDrawCreate(); // In Selektionsmode wechseln
460 m_pSh
->GetView().GetViewFrame()->GetBindings().Invalidate(SID_INSERT_DRAW
);
462 if (m_pSh
->IsSelFrmMode())
463 m_pSh
->LeaveSelFrmMode();
467 bCheckShell
= TRUE
; // ggf BezierShell anwerfen
473 if (!m_pSh
->IsObjSelected() && !m_pWin
->IsDrawAction())
475 m_pView
->LeaveDrawCreate();
476 if (m_pSh
->IsSelFrmMode())
477 m_pSh
->LeaveSelFrmMode();
486 m_pView
->AttrChangedNotify( m_pSh
); // ggf BezierShell anwerfen
488 //!!!!!!!!!! Achtung Suizid !!!!!!!!!!! Sollte alles mal erneuert werden
490 m_pView
->AutoCaption(FRAME_CAP
); //Kann derzeit nur FRAME sein, sonst auf
495 /*************************************************************************
497 |* Function aktivieren
499 \************************************************************************/
502 void SwDrawBase::Activate(const USHORT nSlot
)
505 SdrView
*pSdrView
= m_pSh
->GetDrawView();
507 pSdrView
->SetCurrentObj( static_cast< UINT16
>(m_pWin
->GetSdrDrawMode()) );
508 pSdrView
->SetEditMode(FALSE
);
514 /*************************************************************************
516 |* Function deaktivieren
518 \************************************************************************/
521 void __EXPORT
SwDrawBase::Deactivate()
523 SdrView
*pSdrView
= m_pSh
->GetDrawView();
524 pSdrView
->SetOrtho(FALSE
);
525 pSdrView
->SetAngleSnapEnabled(FALSE
);
527 if (m_pWin
->IsDrawAction() && m_pSh
->IsDrawCreate())
528 m_pSh
->BreakCreate();
530 m_pWin
->SetDrawAction(FALSE
);
532 m_pWin
->ReleaseMouse();
533 bNoInterrupt
= FALSE
;
535 // if(!m_pSh->IsObjSelected())
538 if(m_pWin
->GetApplyTemplate())
539 m_pWin
->SetApplyTemplate(SwApplyTemplate());
540 m_pSh
->GetView().GetViewFrame()->GetBindings().Invalidate(SID_INSERT_DRAW
);
543 /*************************************************************************
545 |* Tastaturereignisse bearbeiten
547 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert TRUE, andernfalls
550 \************************************************************************/
553 BOOL
SwDrawBase::KeyInput(const KeyEvent
& rKEvt
)
555 BOOL bReturn
= FALSE
;
556 USHORT nCode
= rKEvt
.GetKeyCode().GetCode();
562 if (m_pWin
->IsDrawAction())
565 m_pView
->LeaveDrawCreate();
574 m_pSh
->DelSelectedObj();
584 SdrView
*pSdrView
= m_pSh
->GetDrawView();
586 if (!pSdrView
->IsTextEdit())
597 else if (nCode
== KEY_DOWN
)
603 else if (nCode
== KEY_LEFT
)
609 else if (nCode
== KEY_RIGHT
)
611 // Scroll nach rechts
616 if (pSdrView
->AreObjectsMarked() && rKEvt
.GetKeyCode().IsMod2())
618 // Objekte verschieben
621 pSdrView
->MoveAllMarked(Size(nX
, nY
));
634 /*************************************************************************
636 |* Tastaturereignisse bearbeiten
638 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert TRUE, andernfalls
641 \************************************************************************/
644 void SwDrawBase::BreakCreate()
646 m_pSh
->BreakCreate();
647 m_pWin
->SetDrawAction(FALSE
);
648 m_pWin
->ReleaseMouse();
651 // m_pView->LeaveDrawCreate();
654 /*************************************************************************
656 |* Mauspointer umschalten
658 \************************************************************************/
661 void SwDrawBase::SetDrawPointer()
663 SdrView
*pSdrView
= m_pSh
->GetDrawView();
664 Point
aPnt(m_pWin
->OutputToScreenPixel(m_pWin
->GetPointerPosPixel()));
665 aPnt
= m_pWin
->PixelToLogic(m_pWin
->ScreenToOutputPixel(aPnt
));
666 const Pointer aPointTyp
= pSdrView
->GetPreferedPointer(aPnt
, m_pSh
->GetOut());
667 const Pointer
aDrawPt(aPointTyp
);
668 m_pWin
->SetPointer(aDrawPt
);
671 /*************************************************************************
673 |* Ggf in Selektionsmode wechseln
675 \************************************************************************/
677 void SwDrawBase::EnterSelectMode(const MouseEvent
& rMEvt
)
679 m_pWin
->SetDrawAction(FALSE
);
681 if (!m_pSh
->IsObjSelected() && !m_pWin
->IsDrawAction())
683 Point
aPnt(m_pWin
->PixelToLogic(rMEvt
.GetPosPixel()));
685 if (m_pSh
->IsObjSelectable(aPnt
))
687 m_pSh
->SelectObj(aPnt
);
688 if (rMEvt
.GetModifier() == KEY_SHIFT
|| !m_pSh
->IsObjSelected())
690 m_pView
->LeaveDrawCreate(); // In Selektionsmode wechseln
692 m_pSh
->GetView().GetViewFrame()->GetBindings().Invalidate(SID_INSERT_DRAW
);
697 m_pView
->LeaveDrawCreate();
698 if (m_pSh
->IsSelFrmMode())
699 m_pSh
->LeaveSelFrmMode();
704 /* -----------------------------03.04.2002 10:52------------------------------
706 ---------------------------------------------------------------------------*/
707 void SwDrawBase::CreateDefaultObject()
709 Point aStartPos
= GetDefaultCenterPos();
710 Point
aEndPos(aStartPos
);
711 aStartPos
.X() -= 8 * MM50
;
712 aStartPos
.Y() -= 4 * MM50
;
713 aEndPos
.X() += 8 * MM50
;
714 aEndPos
.Y() += 4 * MM50
;
715 Rectangle
aRect(aStartPos
, aEndPos
);
716 m_pSh
->CreateDefaultShape( static_cast< UINT16
>(m_pWin
->GetSdrDrawMode()), aRect
, m_nSlotId
);
718 /* -----------------25.10.2002 14:14-----------------
720 * --------------------------------------------------*/
721 Point
SwDrawBase::GetDefaultCenterPos()
723 Size
aDocSz(m_pSh
->GetDocSize());
724 const SwRect
& rVisArea
= m_pSh
->VisArea();
725 Point aStartPos
= rVisArea
.Center();
726 if(rVisArea
.Width() > aDocSz
.Width())
727 aStartPos
.X() = aDocSz
.Width() / 2 + rVisArea
.Left();
728 if(rVisArea
.Height() > aDocSz
.Height())
729 aStartPos
.Y() = aDocSz
.Height() / 2 + rVisArea
.Top();
734 bool SwDrawBase::doConstructOrthogonal() const