merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / ribbar / drawbase.cxx
bloba9fe374f73b57052a2c72b40123c221b2e71bff4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: drawbase.cxx,v $
10 * $Revision: 1.20 $
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>
42 #include <frmfmt.hxx>
43 #include "cmdid.h"
44 #include "basesh.hxx"
45 #include "view.hxx"
46 #include "wrtsh.hxx"
47 #include "drawbase.hxx"
48 #include "edtwin.hxx"
49 #include "caption.hxx"
50 #include "swundo.hxx"
51 #include "undobj.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 /*************************************************************************
63 |* Konstruktor
65 \************************************************************************/
68 SwDrawBase::SwDrawBase(SwWrtShell* pSwWrtShell, SwEditWin* pWindow, SwView* pSwView) :
69 m_pView(pSwView),
70 m_pSh(pSwWrtShell),
71 m_pWin(pWindow),
72 m_nSlotId(USHRT_MAX),
73 m_bCreateObj(TRUE),
74 m_bInsForm(FALSE)
76 if ( !m_pSh->HasDrawView() )
77 m_pSh->MakeDrawView();
80 /*************************************************************************
82 |* Destruktor
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();
105 // #i33136#
106 // pSdrView->SetOrtho(rMEvt.IsShift());
107 pSdrView->SetOrtho(doConstructOrthogonal() ? !rMEvt.IsShift() : rMEvt.IsShift());
108 pSdrView->SetAngleSnapEnabled(rMEvt.IsShift());
110 if (rMEvt.IsMod2())
112 pSdrView->SetCreate1stPointAsCenter(TRUE);
113 pSdrView->SetResizeAtCenter(TRUE);
115 else
117 pSdrView->SetCreate1stPointAsCenter(FALSE);
118 pSdrView->SetResizeAtCenter(FALSE);
121 SdrViewEvent aVEvt;
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()))
129 bNoInterrupt = TRUE;
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);
136 SetDrawPointer();
138 if ( bReturn )
139 m_pWin->SetDrawAction(TRUE);
141 else if (!pSdrView->IsAction())
143 /**********************************************************************
144 * BEZIER-EDITOR
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 /******************************************************************
153 * Handle draggen
154 ******************************************************************/
155 bNoInterrupt = TRUE;
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 ******************************************************************/
164 bNoInterrupt = TRUE;
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 /******************************************************************
182 * Objekt verschieben
183 ******************************************************************/
184 return FALSE;
186 else if (eHit == SDRHIT_HANDLE)
188 /******************************************************************
189 * Klebepunkt selektieren
190 ******************************************************************/
191 if (pSdrView->HasMarkablePoints() && (!pSdrView->IsPointMarked(*aVEvt.pHdl) || rMEvt.IsShift()))
193 SdrHdl* pHdl = NULL;
195 if (!rMEvt.IsShift())
197 pSdrView->UnmarkAllPoints();
198 pHdl = pSdrView->PickHandle(m_aStartPos);
200 else
202 if (pSdrView->IsPointMarked(*aVEvt.pHdl))
204 bReturn = pSdrView->UnmarkPoint(*aVEvt.pHdl);
205 pHdl = NULL;
207 else
209 pHdl = pSdrView->PickHandle(m_aStartPos);
213 if (pHdl)
215 bNoInterrupt = TRUE;
216 pSdrView->MarkPoint(*pHdl);
217 // bReturn = pSdrView->BegDragObj(m_aStartPos, (OutputDevice*) NULL, pHdl);
218 // m_pWin->SetDrawAction(TRUE);
222 else
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
234 return FALSE;
237 bNoInterrupt = TRUE;
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
250 if( bUnlockView )
251 m_pSh->LockView( FALSE );
253 else
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);
263 SetDrawPointer();
267 return bReturn;
270 /*************************************************************************
272 |* MouseMove-event
274 \************************************************************************/
277 BOOL SwDrawBase::MouseMove(const MouseEvent& rMEvt)
279 SdrView *pSdrView = m_pSh->GetDrawView();
280 Point aPnt(m_pWin->PixelToLogic(rMEvt.GetPosPixel()));
281 BOOL bRet = FALSE;
283 if (IsCreateObj() && !m_pWin->IsDrawSelMode() && pSdrView->IsCreateObj())
285 // #i33136#
286 // pSdrView->SetOrtho(rMEvt.IsShift());
287 pSdrView->SetOrtho(doConstructOrthogonal() ? !rMEvt.IsShift() : rMEvt.IsShift());
288 pSdrView->SetAngleSnapEnabled(rMEvt.IsShift());
290 m_pSh->MoveCreate(aPnt);
291 bRet = TRUE;
293 else if (pSdrView->IsAction() || pSdrView->IsInsObjPoint() || pSdrView->IsMarkPoints())
295 m_pSh->MoveMark(aPnt);
296 bRet = TRUE;
299 return (bRet);
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();
329 else
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()));
350 aReq.Done();
352 bAutoCap = TRUE;
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());
358 aSet.Put(aCol);
359 // Vorlagen-AutoUpdate
360 SwFrmFmt* pFmt = m_pSh->GetCurFrmFmt();
361 if(pFmt && pFmt->IsAutoUpdateFmt())
362 m_pSh->AutoUpdateFrame(pFmt, aSet);
363 else
364 m_pSh->SetFlyFrmAttr( aSet );
367 if (m_pWin->GetSdrDrawMode() == OBJ_NONE)
368 m_pSh->EndUndo(UNDO_INSERT);
371 bReturn = TRUE;
373 EnterSelectMode(rMEvt);
375 else
377 SdrView *pSdrView = m_pSh->GetDrawView();
379 if (!pSdrView->HasMarkablePoints())
381 /**********************************************************************
382 * KEIN BEZIER_EDITOR
383 **********************************************************************/
384 if ((m_pSh->GetDrawView()->IsMarkObj() || m_pSh->GetDrawView()->IsMarkPoints())
385 && rMEvt.IsLeft())
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();
405 m_pView->NoRotate();
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 );
414 else
416 m_pView->LeaveDrawCreate();
417 if (m_pSh->IsSelFrmMode())
418 m_pSh->LeaveSelFrmMode();
420 m_pView->NoRotate();
422 bReturn = TRUE;
426 else
428 /**********************************************************************
429 * BEZIER_EDITOR
430 **********************************************************************/
431 if ( pSdrView->IsAction() )
433 if ( pSdrView->IsInsObjPoint() )
434 bReturn = pSdrView->EndInsObjPoint(SDRCREATE_FORCEEND);
435 else if (pSdrView->IsMarkPoints() )
436 bReturn = pSdrView->EndMarkPoints();
437 else
439 pSdrView->EndAction();
440 bReturn = TRUE;
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));
448 else if (!bReturn)
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();
465 m_pView->NoRotate();
467 bCheckShell = TRUE; // ggf BezierShell anwerfen
471 SetDrawPointer();
473 if (!m_pSh->IsObjSelected() && !m_pWin->IsDrawAction())
475 m_pView->LeaveDrawCreate();
476 if (m_pSh->IsSelFrmMode())
477 m_pSh->LeaveSelFrmMode();
479 m_pView->NoRotate();
480 bReturn = TRUE;
485 if (bCheckShell)
486 m_pView->AttrChangedNotify( m_pSh ); // ggf BezierShell anwerfen
488 //!!!!!!!!!! Achtung Suizid !!!!!!!!!!! Sollte alles mal erneuert werden
489 if ( bAutoCap )
490 m_pView->AutoCaption(FRAME_CAP); //Kann derzeit nur FRAME sein, sonst auf
491 //enums umstellen
492 return (bReturn);
495 /*************************************************************************
497 |* Function aktivieren
499 \************************************************************************/
502 void SwDrawBase::Activate(const USHORT nSlot)
504 SetSlotId(nSlot);
505 SdrView *pSdrView = m_pSh->GetDrawView();
507 pSdrView->SetCurrentObj( static_cast< UINT16 >(m_pWin->GetSdrDrawMode()) );
508 pSdrView->SetEditMode(FALSE);
510 SetDrawPointer();
511 m_pSh->NoEdit();
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())
536 // m_pSh->Edit();
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
548 |* FALSE.
550 \************************************************************************/
553 BOOL SwDrawBase::KeyInput(const KeyEvent& rKEvt)
555 BOOL bReturn = FALSE;
556 USHORT nCode = rKEvt.GetKeyCode().GetCode();
558 switch (nCode)
560 case KEY_ESCAPE:
562 if (m_pWin->IsDrawAction())
564 BreakCreate();
565 m_pView->LeaveDrawCreate();
568 bReturn = TRUE;
570 break;
572 case KEY_DELETE:
574 m_pSh->DelSelectedObj();
575 bReturn = TRUE;
577 break;
579 case KEY_UP:
580 case KEY_DOWN:
581 case KEY_LEFT:
582 case KEY_RIGHT:
584 SdrView *pSdrView = m_pSh->GetDrawView();
586 if (!pSdrView->IsTextEdit())
588 long nX = 0;
589 long nY = 0;
591 if (nCode == KEY_UP)
593 // Scroll nach oben
594 nX = 0;
595 nY =-1;
597 else if (nCode == KEY_DOWN)
599 // Scroll nach unten
600 nX = 0;
601 nY = 1;
603 else if (nCode == KEY_LEFT)
605 // Scroll nach links
606 nX =-1;
607 nY = 0;
609 else if (nCode == KEY_RIGHT)
611 // Scroll nach rechts
612 nX = 1;
613 nY = 0;
616 if (pSdrView->AreObjectsMarked() && rKEvt.GetKeyCode().IsMod2())
618 // Objekte verschieben
619 nX *= 100;
620 nY *= 100;
621 pSdrView->MoveAllMarked(Size(nX, nY));
624 bReturn = TRUE;
627 break;
630 return (bReturn);
634 /*************************************************************************
636 |* Tastaturereignisse bearbeiten
638 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert TRUE, andernfalls
639 |* FALSE.
641 \************************************************************************/
644 void SwDrawBase::BreakCreate()
646 m_pSh->BreakCreate();
647 m_pWin->SetDrawAction(FALSE);
648 m_pWin->ReleaseMouse();
650 Deactivate();
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);
695 else
697 m_pView->LeaveDrawCreate();
698 if (m_pSh->IsSelFrmMode())
699 m_pSh->LeaveSelFrmMode();
701 m_pView->NoRotate();
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();
730 return aStartPos;
733 // #i33136#
734 bool SwDrawBase::doConstructOrthogonal() const
736 return false;
739 // eof