Get the style color and number just once
[LibreOffice.git] / reportdesign / source / ui / report / dlgedfunc.cxx
blobb22f6f652eee3aae8f066ba49ea67d2b42a5aca9
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 .
19 #include <vcl/seleng.hxx>
20 #include <vcl/ptrstyle.hxx>
21 #include <com/sun/star/embed/EmbedStates.hpp>
22 #include <com/sun/star/embed/XEmbeddedObject.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <svx/svdview.hxx>
26 #include <svx/svdpagv.hxx>
27 #include <svx/svdetc.hxx>
28 #include <svx/svddrgmt.hxx>
29 #include <svx/svdoashp.hxx>
30 #include <svx/svxids.hrc>
31 #include <svx/svditer.hxx>
33 #include <toolkit/helper/vclunohelper.hxx>
35 #include <dlgedfunc.hxx>
36 #include <ReportSection.hxx>
37 #include <DesignView.hxx>
38 #include <ReportController.hxx>
39 #include <SectionView.hxx>
40 #include <ViewsWindow.hxx>
41 #include <ReportWindow.hxx>
42 #include <RptObject.hxx>
43 #include <ScrollHelper.hxx>
44 #include <UITools.hxx>
46 #include <strings.hxx>
47 #include <UndoEnv.hxx>
48 #include <RptModel.hxx>
49 #include <comphelper/propertysequence.hxx>
50 #include <comphelper/diagnose_ex.hxx>
52 #define DEFAUL_MOVE_SIZE 100
53 namespace rptui
55 using namespace ::com::sun::star;
58 IMPL_LINK_NOARG( DlgEdFunc, ScrollTimeout, Timer *, void )
60 ForceScroll( m_pParent->PixelToLogic( m_pParent->GetPointerPosPixel() ) );
64 void DlgEdFunc::ForceScroll( const Point& rPos )
66 aScrollTimer.Stop();
68 OReportWindow* pReportWindow = m_pParent->getSectionWindow()->getViewsWindow()->getView();
69 OScrollWindowHelper* pScrollWindow = pReportWindow->getScrollWindow();
71 Size aOut = pReportWindow->GetOutputSizePixel();
72 Fraction aStartWidth(tools::Long(REPORT_STARTMARKER_WIDTH));
73 aStartWidth *= m_pParent->GetMapMode().GetScaleX();
75 aOut.AdjustWidth( -static_cast<tools::Long>(aStartWidth) );
76 aOut.setHeight( m_pParent->GetOutputSizePixel().Height() );
78 Point aPos = pScrollWindow->getThumbPos();
79 aPos.setX( aPos.X() * 0.5 );
80 aPos.setY( aPos.Y() * 0.5 );
81 tools::Rectangle aOutRect( aPos, aOut );
82 aOutRect = m_pParent->PixelToLogic( aOutRect );
83 tools::Rectangle aWorkArea(Point(), pScrollWindow->getTotalSize());
84 aWorkArea.AdjustRight( -static_cast<tools::Long>(aStartWidth) );
85 aWorkArea = pScrollWindow->PixelToLogic( aWorkArea );
86 if( !aOutRect.Contains( rPos ) && aWorkArea.Contains( rPos ) )
88 ScrollAdaptor& rHScroll = pScrollWindow->GetHScroll();
89 ScrollAdaptor& rVScroll = pScrollWindow->GetVScroll();
90 ScrollType eH = ScrollType::LineDown,eV = ScrollType::LineDown;
91 if( rPos.X() < aOutRect.Left() )
92 eH = ScrollType::LineUp;
93 else if( rPos.X() <= aOutRect.Right() )
94 eH = ScrollType::DontKnow;
96 if( rPos.Y() < aOutRect.Top() )
97 eV = ScrollType::LineUp;
98 else if( rPos.Y() <= aOutRect.Bottom() )
99 eV = ScrollType::DontKnow;
101 if (eH != ScrollType::DontKnow)
103 auto nCurrentPos = rHScroll.GetThumbPos();
104 auto nLineSize = rHScroll.GetLineSize();
105 assert(eH == ScrollType::LineUp || eH == ScrollType::LineDown);
106 rHScroll.DoScroll(eH == ScrollType::LineUp ? (nCurrentPos - nLineSize) : (nCurrentPos + nLineSize));
109 if (eV != ScrollType::DontKnow)
111 auto nCurrentPos = rVScroll.GetThumbPos();
112 auto nLineSize = rVScroll.GetLineSize();
113 assert(eV == ScrollType::LineUp || eV == ScrollType::LineDown);
114 rVScroll.DoScroll(eV == ScrollType::LineUp ? (nCurrentPos - nLineSize) : (nCurrentPos + nLineSize));
118 aScrollTimer.Start();
121 DlgEdFunc::DlgEdFunc( OReportSection* _pParent )
122 : m_pParent(_pParent)
123 , m_rView(_pParent->getSectionView())
124 , aScrollTimer("reportdesign DlgEdFunc aScrollTimer")
125 , m_pOverlappingObj(nullptr)
126 , m_nOverlappedControlColor(0)
127 , m_nOldColor(0)
128 , m_bSelectionMode(false)
129 , m_bUiActive(false)
130 , m_bShowPropertyBrowser(false)
132 aScrollTimer.SetInvokeHandler( LINK( this, DlgEdFunc, ScrollTimeout ) );
133 m_rView.SetActualWin( m_pParent->GetOutDev() );
134 aScrollTimer.SetTimeout( SELENG_AUTOREPEAT_INTERVAL );
137 void DlgEdFunc::setOverlappedControlColor(Color _nColor)
139 m_nOverlappedControlColor = _nColor;
142 static Color lcl_setColorOfObject(const uno::Reference< uno::XInterface >& _xObj, Color _nColorTRGB)
144 Color nBackColor;
147 uno::Reference<report::XReportComponent> xComponent(_xObj, uno::UNO_QUERY_THROW);
148 uno::Reference< beans::XPropertySet > xProp(xComponent, uno::UNO_QUERY_THROW);
149 uno::Any aAny = xProp->getPropertyValue(PROPERTY_CONTROLBACKGROUND);
150 if (aAny.hasValue())
152 aAny >>= nBackColor;
153 // try to set background color at the ReportComponent
154 uno::Any aBlackColorAny(_nColorTRGB);
155 xProp->setPropertyValue(PROPERTY_CONTROLBACKGROUND, aBlackColorAny);
158 catch(uno::Exception&)
161 return nBackColor;
164 DlgEdFunc::~DlgEdFunc()
166 unColorizeOverlappedObj();
167 aScrollTimer.Stop();
171 bool DlgEdFunc::MouseButtonDown( const MouseEvent& rMEvt )
173 m_aMDPos = m_pParent->PixelToLogic( rMEvt.GetPosPixel() );
174 m_pParent->GrabFocus();
175 bool bHandled = false;
176 if ( rMEvt.IsLeft() )
178 if ( rMEvt.GetClicks() > 1 )
180 // show property browser
181 uno::Sequence<beans::PropertyValue> aArgs( comphelper::InitPropertySequence({
182 { "ShowProperties", uno::Any(true) }
183 }));
184 m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->getController().executeUnChecked(SID_SHOW_PROPERTYBROWSER,aArgs);
185 m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->UpdatePropertyBrowserDelayed(m_rView);
186 // TODO character in shapes
187 // SdrViewEvent aVEvt;
188 // m_rView.PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
189 // if ( aVEvt.mpRootObj && aVEvt.pRootObj->ISA(SdrTextObj) )
190 // SetInEditMode(static_cast<SdrTextObj *>(aVEvt.mpRootObj),rMEvt, sal_False);
191 bHandled = true;
193 else
195 SdrHdl* pHdl = m_rView.PickHandle(m_aMDPos);
197 // if selected object was hit, drag object
198 if ( pHdl!=nullptr || m_rView.IsMarkedHit(m_aMDPos) )
200 bHandled = true;
201 m_pParent->CaptureMouse();
202 m_pParent->getSectionWindow()->getViewsWindow()->BegDragObj(m_aMDPos, pHdl,&m_rView);
206 else if ( rMEvt.IsRight() && !rMEvt.IsLeft() && rMEvt.GetClicks() == 1 ) // mark object when context menu was selected
208 SdrPageView* pPV = m_rView.GetSdrPageView();
209 SdrViewEvent aVEvt;
210 if ( m_rView.PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt) != SdrHitKind::MarkedObject && !rMEvt.IsShift() )
211 m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(nullptr);
212 if ( aVEvt.mpRootObj )
213 m_rView.MarkObj(aVEvt.mpRootObj, pPV);
214 else
215 m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(nullptr);
217 bHandled = true;
219 else if( !rMEvt.IsLeft() )
220 bHandled = true;
221 if ( !bHandled )
222 m_pParent->CaptureMouse();
223 return bHandled;
227 bool DlgEdFunc::MouseButtonUp( const MouseEvent& /*rMEvt*/ )
229 m_pParent->getSectionWindow()->getViewsWindow()->stopScrollTimer();
230 return false;
233 void DlgEdFunc::checkTwoClicks(const MouseEvent& rMEvt)
235 deactivateOle();
237 const sal_uInt16 nClicks = rMEvt.GetClicks();
238 if ( !(nClicks == 2 && rMEvt.IsLeft()) )
239 return;
241 if ( m_rView.GetMarkedObjectList().GetMarkCount() != 0 )
243 const SdrMarkList& rMarkList = m_rView.GetMarkedObjectList();
244 if (rMarkList.GetMarkCount() == 1)
246 const SdrMark* pMark = rMarkList.GetMark(0);
247 SdrObject* pObj = pMark->GetMarkedSdrObj();
248 activateOle(pObj);
253 void DlgEdFunc::stopScrollTimer()
255 unColorizeOverlappedObj();
256 aScrollTimer.Stop();
257 if ( m_pParent->IsMouseCaptured() )
258 m_pParent->ReleaseMouse();
262 bool DlgEdFunc::MouseMove( const MouseEvent& /*rMEvt*/ )
264 return false;
267 bool DlgEdFunc::handleKeyEvent(const KeyEvent& _rEvent)
269 bool bReturn = false;
271 if ( !m_bUiActive )
273 const vcl::KeyCode& rCode = _rEvent.GetKeyCode();
274 sal_uInt16 nCode = rCode.GetCode();
276 switch ( nCode )
278 case KEY_ESCAPE:
280 if ( m_pParent->getSectionWindow()->getViewsWindow()->IsAction() )
282 m_pParent->getSectionWindow()->getViewsWindow()->BrkAction();
283 bReturn = true;
285 else if ( m_rView.IsTextEdit() )
287 m_rView.SdrEndTextEdit();
288 bReturn = true;
290 else if ( m_rView.GetMarkedObjectList().GetMarkCount() != 0 )
292 const SdrHdlList& rHdlList = m_rView.GetHdlList();
293 SdrHdl* pHdl = rHdlList.GetFocusHdl();
294 if ( pHdl )
295 const_cast<SdrHdlList&>(rHdlList).ResetFocusHdl();
296 else
297 m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(nullptr);
299 deactivateOle(true);
300 bReturn = false;
302 else
304 deactivateOle(true);
307 break;
308 case KEY_TAB:
310 if ( !rCode.IsMod1() && !rCode.IsMod2() )
312 // mark next object
313 if ( !m_rView.MarkNextObj( !rCode.IsShift() ) )
315 // if no next object, mark first/last
316 m_rView.UnmarkAllObj();
317 m_rView.MarkNextObj( !rCode.IsShift() );
320 if ( m_rView.GetMarkedObjectList().GetMarkCount() != 0 )
321 m_rView.MakeVisible( m_rView.GetAllMarkedRect(), *m_pParent);
323 bReturn = true;
325 else if ( rCode.IsMod1() && rCode.IsMod2())
327 // selected handle
328 const SdrHdlList& rHdlList = m_rView.GetHdlList();
329 const_cast<SdrHdlList&>(rHdlList).TravelFocusHdl( !rCode.IsShift() );
331 // guarantee visibility of focused handle
332 SdrHdl* pHdl = rHdlList.GetFocusHdl();
333 if ( pHdl )
335 Point aHdlPosition( pHdl->GetPos() );
336 tools::Rectangle aVisRect( aHdlPosition - Point( DEFAUL_MOVE_SIZE, DEFAUL_MOVE_SIZE ), Size( 200, 200 ) );
337 m_rView.MakeVisible( aVisRect, *m_pParent);
340 bReturn = true;
343 break;
344 case KEY_UP:
345 case KEY_DOWN:
346 case KEY_LEFT:
347 case KEY_RIGHT:
349 m_pParent->getSectionWindow()->getViewsWindow()->handleKey(rCode);
350 bReturn = true;
352 break;
353 case KEY_RETURN:
354 if ( !rCode.IsMod1() )
356 const SdrMarkList& rMarkList = m_rView.GetMarkedObjectList();
357 if ( rMarkList.GetMarkCount() == 1 )
359 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
360 activateOle(pObj);
363 break;
364 case KEY_DELETE:
365 if ( !rCode.IsMod1() && !rCode.IsMod2() )
367 bReturn = true;
368 break;
370 [[fallthrough]];
371 default:
373 bReturn = m_rView.KeyInput(_rEvent, m_pParent);
375 break;
379 if ( bReturn && m_pParent->IsMouseCaptured() )
380 m_pParent->ReleaseMouse();
382 return bReturn;
385 void DlgEdFunc::activateOle(SdrObject* _pObj)
387 if ( !_pObj )
388 return;
390 const SdrObjKind nSdrObjKind = _pObj->GetObjIdentifier();
392 // OLE: activate
394 if (nSdrObjKind != SdrObjKind::OLE2)
395 return;
397 SdrOle2Obj* pOleObj = dynamic_cast<SdrOle2Obj*>(_pObj);
398 if (!(pOleObj && pOleObj->GetObjRef().is()))
399 return;
401 if (m_rView.IsTextEdit())
403 m_rView.SdrEndTextEdit();
406 pOleObj->AddOwnLightClient();
407 pOleObj->SetWindow(VCLUnoHelper::GetInterface(m_pParent));
410 pOleObj->GetObjRef()->changeState( embed::EmbedStates::UI_ACTIVE );
411 m_bUiActive = true;
412 OReportController& rController = m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->getController();
413 m_bShowPropertyBrowser = rController.isCommandChecked(SID_SHOW_PROPERTYBROWSER);
414 if ( m_bShowPropertyBrowser )
415 rController.executeChecked(SID_SHOW_PROPERTYBROWSER,uno::Sequence< beans::PropertyValue >());
417 catch( uno::Exception& )
419 DBG_UNHANDLED_EXCEPTION("reportdesign");
423 void DlgEdFunc::deactivateOle(bool _bSelect)
425 OLEObjCache& rObjCache = GetSdrGlobalData().GetOLEObjCache();
426 OReportController& rController = m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->getController();
427 const size_t nCount = rObjCache.size();
428 for(size_t i = 0 ; i < nCount;++i)
430 SdrOle2Obj* pObj = rObjCache[i];
431 if ( m_pParent->getPage() == pObj->getSdrPageFromSdrObject() )
433 uno::Reference< embed::XEmbeddedObject > xObj = pObj->GetObjRef();
434 if ( xObj.is() && xObj->getCurrentState() == embed::EmbedStates::UI_ACTIVE )
436 xObj->changeState( embed::EmbedStates::RUNNING );
437 m_bUiActive = false;
438 if ( m_bShowPropertyBrowser )
440 rController.executeChecked(SID_SHOW_PROPERTYBROWSER,uno::Sequence< beans::PropertyValue >());
443 if ( _bSelect )
445 SdrPageView* pPV = m_rView.GetSdrPageView();
446 m_rView.MarkObj(pObj, pPV);
453 void DlgEdFunc::colorizeOverlappedObject(SdrObject* _pOverlappedObj)
455 OObjectBase* pObj = dynamic_cast<OObjectBase*>(_pOverlappedObj);
456 if ( !pObj )
457 return;
459 const uno::Reference<report::XReportComponent>& xComponent = pObj->getReportComponent();
460 if (xComponent.is() && xComponent != m_xOverlappingObj)
462 OReportModel& rRptModel(static_cast< OReportModel& >(_pOverlappedObj->getSdrModelFromSdrObject()));
463 OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
465 // uncolorize an old object, if there is one
466 unColorizeOverlappedObj();
468 m_nOldColor = lcl_setColorOfObject(xComponent, m_nOverlappedControlColor);
469 m_xOverlappingObj = xComponent;
470 m_pOverlappingObj = _pOverlappedObj;
474 void DlgEdFunc::unColorizeOverlappedObj()
476 // uncolorize an old object, if there is one
477 if (m_xOverlappingObj.is())
479 OReportModel& rRptModel(static_cast< OReportModel& >(m_pOverlappingObj->getSdrModelFromSdrObject()));
480 OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
482 lcl_setColorOfObject(m_xOverlappingObj, m_nOldColor);
483 m_xOverlappingObj = nullptr;
484 m_pOverlappingObj = nullptr;
488 bool DlgEdFunc::isOverlapping(const MouseEvent& rMEvt)
490 SdrViewEvent aVEvt;
491 bool bOverlapping = m_rView.PickAnything(rMEvt, SdrMouseEventKind::BUTTONUP, aVEvt) != SdrHitKind::NONE;
492 if (bOverlapping && aVEvt.mpObj)
494 colorizeOverlappedObject(aVEvt.mpObj);
496 else
498 unColorizeOverlappedObj();
501 return bOverlapping;
504 void DlgEdFunc::checkMovementAllowed(const MouseEvent& rMEvt)
506 if ( m_pParent->getSectionWindow()->getViewsWindow()->IsDragObj() )
508 if ( isRectangleHit(rMEvt) )
510 // there is another component under use, break action
511 m_pParent->getSectionWindow()->getViewsWindow()->BrkAction();
513 // object was dragged
514 Point aPnt( m_pParent->PixelToLogic( rMEvt.GetPosPixel() ) );
515 if (m_bSelectionMode)
517 m_pParent->getSectionWindow()->getViewsWindow()->EndAction();
519 else
521 bool bControlKeyPressed = rMEvt.IsMod1();
522 // Don't allow points smaller 0
523 if (bControlKeyPressed && (aPnt.Y() < 0))
525 aPnt.setY( 0 );
527 if (m_rView.IsDragResize())
529 // we resize the object don't resize to above sections
530 if ( aPnt.Y() < 0 )
532 aPnt.setY( 0 );
535 m_pParent->getSectionWindow()->getViewsWindow()->EndDragObj( bControlKeyPressed, &m_rView, aPnt );
537 m_pParent->getSectionWindow()->getViewsWindow()->ForceMarkedToAnotherPage();
538 m_pParent->Invalidate(InvalidateFlags::Children);
540 else
541 m_pParent->getSectionWindow()->getViewsWindow()->EndAction();
544 bool DlgEdFunc::isOnlyCustomShapeMarked() const
546 bool bReturn = true;
547 const SdrMarkList& rMarkList = m_rView.GetMarkedObjectList();
548 for (size_t i = 0; i < rMarkList.GetMarkCount(); ++i )
550 SdrMark* pMark = rMarkList.GetMark(i);
551 SdrObject* pObj = pMark->GetMarkedSdrObj();
552 if (pObj->GetObjIdentifier() != SdrObjKind::CustomShape)
554 // we found an object in the marked objects, which is not a custom shape.
555 bReturn = false;
556 break;
559 return bReturn;
562 bool DlgEdFunc::isRectangleHit(const MouseEvent& rMEvt)
564 if (isOnlyCustomShapeMarked())
566 return false;
569 SdrViewEvent aVEvt;
570 const SdrHitKind eHit = m_rView.PickAnything(rMEvt, SdrMouseEventKind::MOVE, aVEvt);
571 bool bIsSetPoint = (eHit == SdrHitKind::UnmarkedObject);
572 if ( !bIsSetPoint )
574 // no drag rect, we have to check every single select rect
575 const SdrDragStat& rDragStat = m_rView.GetDragStat();
576 if (rDragStat.GetDragMethod() != nullptr)
578 SdrObjListIter aIter(m_pParent->getPage(),SdrIterMode::DeepNoGroups);
579 // loop through all marked objects and check if there new rect overlapps an old one.
580 for (;;)
582 SdrObject* pObjIter = aIter.Next();
583 if( !pObjIter || bIsSetPoint)
584 break;
585 if ( m_rView.IsObjMarked(pObjIter)
586 && (dynamic_cast<OUnoObject*>(pObjIter) != nullptr || dynamic_cast<OOle2Obj*>(pObjIter) != nullptr) )
588 tools::Rectangle aNewRect = pObjIter->GetLastBoundRect();
589 tools::Long nDx = rDragStat.IsHorFixed() ? 0 : rDragStat.GetDX();
590 tools::Long nDy = rDragStat.IsVerFixed() ? 0 : rDragStat.GetDY();
591 if ( (nDx + aNewRect.Left()) < 0 )
592 nDx = -aNewRect.Left();
593 if ( (nDy + aNewRect.Top()) < 0 )
594 nDy = -aNewRect.Top();
596 if ( rDragStat.GetDragMethod()->getMoveOnly() )
597 aNewRect.Move(nDx,nDy);
598 else
599 ::ResizeRect(aNewRect,rDragStat.GetRef1(),rDragStat.GetXFact(),rDragStat.GetYFact());
602 SdrObject* pObjOverlapped = isOver(aNewRect,*m_pParent->getPage(),m_rView,false,pObjIter, ISOVER_IGNORE_CUSTOMSHAPES);
603 bIsSetPoint = pObjOverlapped != nullptr;
604 if (pObjOverlapped && !m_bSelectionMode)
606 colorizeOverlappedObject(pObjOverlapped);
612 else if (aVEvt.mpObj && (aVEvt.mpObj->GetObjIdentifier() != SdrObjKind::CustomShape) && !m_bSelectionMode)
614 colorizeOverlappedObject(aVEvt.mpObj);
616 else
617 bIsSetPoint = false;
618 return bIsSetPoint;
621 bool DlgEdFunc::setMovementPointer(const MouseEvent& rMEvt)
623 bool bIsSetPoint = isRectangleHit(rMEvt);
624 if ( bIsSetPoint )
625 m_pParent->SetPointer( PointerStyle::NotAllowed );
626 else
628 bool bCtrlKey = rMEvt.IsMod1();
629 if (bCtrlKey)
631 m_pParent->SetPointer( PointerStyle::MoveDataLink );
632 bIsSetPoint = true;
635 return bIsSetPoint;
639 DlgEdFuncInsert::DlgEdFuncInsert( OReportSection* _pParent ) :
640 DlgEdFunc( _pParent )
642 m_rView.SetCreateMode();
646 DlgEdFuncInsert::~DlgEdFuncInsert()
648 m_rView.SetEditMode();
652 bool DlgEdFuncInsert::MouseButtonDown( const MouseEvent& rMEvt )
654 if ( DlgEdFunc::MouseButtonDown(rMEvt) )
655 return true;
657 SdrViewEvent aVEvt;
658 SdrObjKind nId = m_rView.GetCurrentObjIdentifier();
660 const SdrHitKind eHit = m_rView.PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
662 if (eHit == SdrHitKind::UnmarkedObject && nId != SdrObjKind::CustomShape)
664 // there is an object under the mouse cursor, but not a customshape
665 m_pParent->getSectionWindow()->getViewsWindow()->BrkAction();
666 return false;
669 // if no action, create object
670 if (!m_pParent->getSectionWindow()->getViewsWindow()->IsAction())
672 deactivateOle(true);
673 if ( m_pParent->getSectionWindow()->getViewsWindow()->HasSelection() )
674 m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(&m_rView);
675 m_rView.BegCreateObj(m_aMDPos);
676 m_pParent->getSectionWindow()->getViewsWindow()->createDefault();
679 return true;
683 bool DlgEdFuncInsert::MouseButtonUp( const MouseEvent& rMEvt )
685 if ( DlgEdFunc::MouseButtonUp( rMEvt ) )
686 return true;
688 const Point aPos( m_pParent->PixelToLogic( rMEvt.GetPosPixel() ) );
689 const sal_uInt16 nHitLog = sal_uInt16 ( m_pParent->PixelToLogic(Size(3,0)).Width() );
691 bool bReturn = true;
692 // object creation active?
693 if ( m_rView.IsCreateObj() )
695 if ( isOver(m_rView.GetCreateObj(),*m_pParent->getPage(),m_rView) )
697 m_pParent->getSectionWindow()->getViewsWindow()->BrkAction();
698 // BrkAction disables the create mode
699 m_rView.SetCreateMode();
700 return true;
703 m_rView.EndCreateObj(SdrCreateCmd::ForceEnd);
705 if ( m_rView.GetMarkedObjectList().GetMarkCount() == 0 )
707 m_rView.MarkObj(aPos, nHitLog);
710 bReturn = m_rView.GetMarkedObjectList().GetMarkCount() != 0;
711 if ( bReturn )
713 OReportController& rController = m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->getController();
714 const SdrMarkList& rMarkList = m_rView.GetMarkedObjectList();
715 for (size_t i = 0; i < rMarkList.GetMarkCount(); ++i )
717 SdrMark* pMark = rMarkList.GetMark(i);
718 OOle2Obj* pObj = dynamic_cast<OOle2Obj*>(pMark->GetMarkedSdrObj());
719 if ( pObj && !pObj->IsEmpty() )
721 pObj->initializeChart(rController.getModel());
726 else
727 checkMovementAllowed(rMEvt);
729 if ( m_rView.GetMarkedObjectList().GetMarkCount() == 0 &&
730 std::abs(m_aMDPos.X() - aPos.X()) < nHitLog &&
731 std::abs(m_aMDPos.Y() - aPos.Y()) < nHitLog &&
732 !rMEvt.IsShift() && !rMEvt.IsMod2() )
734 SdrPageView* pPV = m_rView.GetSdrPageView();
735 SdrViewEvent aVEvt;
736 m_rView.PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
737 m_rView.MarkObj(aVEvt.mpRootObj, pPV);
739 checkTwoClicks(rMEvt);
740 m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->UpdatePropertyBrowserDelayed(m_rView);
741 return bReturn;
745 bool DlgEdFuncInsert::MouseMove( const MouseEvent& rMEvt )
747 if ( DlgEdFunc::MouseMove(rMEvt ) )
748 return true;
749 Point aPos( m_pParent->PixelToLogic( rMEvt.GetPosPixel() ) );
751 if ( m_rView.IsCreateObj() )
753 m_rView.SetOrtho(SdrObjCustomShape::doConstructOrthogonal(m_rView.getReportSection()->getSectionWindow()->getViewsWindow()->getShapeType()) ? !rMEvt.IsShift() : rMEvt.IsShift());
754 m_rView.SetAngleSnapEnabled(rMEvt.IsShift());
757 bool bIsSetPoint = false;
758 if ( m_rView.IsAction() )
760 if ( m_rView.IsDragResize() )
762 // we resize the object don't resize to above sections
763 if ( aPos.Y() < 0 )
765 aPos.setY( 0 );
768 bIsSetPoint = setMovementPointer(rMEvt);
769 ForceScroll(aPos);
770 m_pParent->getSectionWindow()->getViewsWindow()->MovAction(aPos,&m_rView, false);
773 if ( !bIsSetPoint )
774 m_pParent->SetPointer( m_rView.GetPreferredPointer( aPos, m_pParent->GetOutDev()) );
776 return true;
780 DlgEdFuncSelect::DlgEdFuncSelect( OReportSection* _pParent ) :
781 DlgEdFunc( _pParent )
786 DlgEdFuncSelect::~DlgEdFuncSelect()
791 bool DlgEdFuncSelect::MouseButtonDown( const MouseEvent& rMEvt )
793 m_bSelectionMode = false;
794 if ( DlgEdFunc::MouseButtonDown(rMEvt) )
795 return true;
797 SdrViewEvent aVEvt;
798 const SdrHitKind eHit = m_rView.PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
799 if( eHit == SdrHitKind::UnmarkedObject )
801 // if not multi selection, unmark all
802 if ( !rMEvt.IsShift() )
803 m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(nullptr);
805 if ( m_rView.MarkObj(m_aMDPos) && rMEvt.IsLeft() )
807 // drag object
808 m_pParent->getSectionWindow()->getViewsWindow()->BegDragObj(m_aMDPos, m_rView.PickHandle(m_aMDPos), &m_rView);
810 else
812 // select object
813 m_pParent->getSectionWindow()->getViewsWindow()->BegMarkObj(m_aMDPos,&m_rView);
816 else
818 if( !rMEvt.IsShift() )
819 m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(nullptr);
821 if ( rMEvt.GetClicks() == 1 )
823 m_bSelectionMode = true;
824 m_pParent->getSectionWindow()->getViewsWindow()->BegMarkObj( m_aMDPos ,&m_rView);
826 else
828 m_rView.SdrBeginTextEdit( aVEvt.mpRootObj,m_rView.GetSdrPageView(),m_pParent );
832 return true;
836 bool DlgEdFuncSelect::MouseButtonUp( const MouseEvent& rMEvt )
838 if ( DlgEdFunc::MouseButtonUp( rMEvt ) )
839 return true;
841 // get view from parent
842 const Point aPnt( m_pParent->PixelToLogic( rMEvt.GetPosPixel() ) );
844 if ( rMEvt.IsLeft() ) // left mousebutton pressed
845 checkMovementAllowed(rMEvt);
847 m_pParent->getSectionWindow()->getViewsWindow()->EndAction();
848 checkTwoClicks(rMEvt);
850 m_pParent->SetPointer( m_rView.GetPreferredPointer( aPnt, m_pParent->GetOutDev() ) );
852 if ( !m_bUiActive )
853 m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->UpdatePropertyBrowserDelayed(m_rView);
854 m_bSelectionMode = false;
855 return true;
859 bool DlgEdFuncSelect::MouseMove( const MouseEvent& rMEvt )
861 if ( DlgEdFunc::MouseMove(rMEvt ) )
862 return true;
864 Point aPnt( m_pParent->PixelToLogic( rMEvt.GetPosPixel() ) );
865 bool bIsSetPoint = false;
867 if ( m_rView.IsAction() ) // Drag Mode
869 bIsSetPoint = setMovementPointer(rMEvt);
870 ForceScroll(aPnt);
871 if (m_rView.GetDragMethod()==nullptr)
873 // create a selection
874 m_pParent->getSectionWindow()->getViewsWindow()->MovAction(aPnt, &m_rView, false);
876 else
878 if ( m_rView.IsDragResize() )
880 // we resize the object don't resize to above sections
881 if ( aPnt.Y() < 0 )
883 aPnt.setY( 0 );
886 // drag or resize an object
887 bool bControlKey = rMEvt.IsMod1();
888 m_pParent->getSectionWindow()->getViewsWindow()->MovAction(aPnt, &m_rView, bControlKey);
892 if ( !bIsSetPoint )
894 m_pParent->SetPointer( m_rView.GetPreferredPointer( aPnt, m_pParent->GetOutDev() ) );
896 // restore color
897 unColorizeOverlappedObj();
900 return true;
906 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */