xref: /trunk/main/reportdesign/source/ui/report/dlgedfunc.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #include "precompiled_reportdesign.hxx"
28 #include <vcl/scrbar.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/seleng.hxx>
31 #include <com/sun/star/linguistic2/XSpellChecker1.hpp>
32 #include <com/sun/star/embed/EmbedStates.hpp>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 
35 #include <svx/svdview.hxx>
36 #include <svx/svdpagv.hxx>
37 #include <editeng/outlobj.hxx>
38 #include <editeng/unolingu.hxx>
39 #include <svx/svdetc.hxx>
40 #include <editeng/editstat.hxx>
41 #include <svx/svdoutl.hxx>
42 #include <svx/svddrgmt.hxx>
43 #include <svx/svdoashp.hxx>
44 #include <svx/svxids.hrc>
45 #include <svx/svditer.hxx>
46 
47 #include <toolkit/helper/vclunohelper.hxx>
48 
49 #include "dlgedfunc.hxx"
50 #include "ReportSection.hxx"
51 #include "DesignView.hxx"
52 #include "ReportController.hxx"
53 #include "SectionView.hxx"
54 #include "ViewsWindow.hxx"
55 #include "ReportWindow.hxx"
56 #include "RptObject.hxx"
57 #include "ScrollHelper.hxx"
58 
59 #include "ReportRuler.hxx"
60 #include "UITools.hxx"
61 
62 #include <uistrings.hrc>
63 #include "UndoEnv.hxx"
64 #include <RptModel.hxx>
65 #include <tools/diagnose_ex.h>
66 
67 #define DEFAUL_MOVE_SIZE    100
68 namespace rptui
69 {
70 using namespace ::com::sun::star;
71 //----------------------------------------------------------------------------
72 
73 //----------------------------------------------------------------------------
74 
75 IMPL_LINK( DlgEdFunc, ScrollTimeout, Timer *,  )
76 {
77     ForceScroll( m_pParent->PixelToLogic( m_pParent->GetPointerPosPixel() ) );
78     return 0;
79 }
80 
81 //----------------------------------------------------------------------------
82 
83 void DlgEdFunc::ForceScroll( const Point& rPos )
84 {
85     aScrollTimer.Stop();
86 
87     OReportWindow* pReportWindow = m_pParent->getSectionWindow()->getViewsWindow()->getView();
88     OScrollWindowHelper* pScrollWindow = pReportWindow->getScrollWindow();
89 
90     Size aOut = pReportWindow->GetOutputSizePixel();
91     Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
92     aStartWidth *= m_pParent->GetMapMode().GetScaleX();
93 
94     aOut.Width() -= (long)aStartWidth;
95     aOut.Height() = m_pParent->GetOutputSizePixel().Height();
96 
97     Point aPos = pScrollWindow->getThumbPos();
98     aPos.X() *= 0.5;
99     aPos.Y() *= 0.5;
100     Rectangle aOutRect( aPos, aOut );
101     aOutRect = m_pParent->PixelToLogic( aOutRect );
102     //Rectangle aWorkArea = m_pParent->getView()->GetWorkArea();
103     Point aGcc3WorkaroundTemporary;
104     Rectangle aWorkArea(aGcc3WorkaroundTemporary,pScrollWindow->getTotalSize());
105     aWorkArea.Right() -= (long)aStartWidth;
106     aWorkArea = pScrollWindow->PixelToLogic( aWorkArea );
107     if( !aOutRect.IsInside( rPos ) && aWorkArea.IsInside( rPos ) )
108     {
109         ScrollBar* pHScroll = pScrollWindow->GetHScroll();
110         ScrollBar* pVScroll = pScrollWindow->GetVScroll();
111         ScrollType eH = SCROLL_LINEDOWN,eV = SCROLL_LINEDOWN;
112         if( rPos.X() < aOutRect.Left() )
113             eH = SCROLL_LINEUP;
114         else if( rPos.X() <= aOutRect.Right() )
115             eH = SCROLL_DONTKNOW;
116 
117         if( rPos.Y() < aOutRect.Top() )
118             eV = SCROLL_LINEUP;
119         else if( rPos.Y() <= aOutRect.Bottom() )
120             eV = SCROLL_DONTKNOW;
121 
122         pHScroll->DoScrollAction(eH);
123         pVScroll->DoScrollAction(eV);
124     }
125 
126     aScrollTimer.Start();
127 }
128 
129 //----------------------------------------------------------------------------
130 
131 DlgEdFunc::DlgEdFunc( OReportSection* _pParent )
132 :m_pParent(_pParent),
133  m_rView(_pParent->getSectionView()),
134  m_xOverlappingObj(NULL),
135  m_pOverlappingObj(NULL),
136  m_bSelectionMode(false),
137  m_bUiActive(false),
138  m_bShowPropertyBrowser(false)
139 {
140     // m_pParent = _pParent;
141     aScrollTimer.SetTimeoutHdl( LINK( this, DlgEdFunc, ScrollTimeout ) );
142     m_rView.SetActualWin( m_pParent);
143     aScrollTimer.SetTimeout( SELENG_AUTOREPEAT_INTERVAL );
144 }
145 
146 //----------------------------------------------------------------------------
147 void DlgEdFunc::setOverlappedControlColor(sal_Int32 _nColor)
148 {
149     m_nOverlappedControlColor = _nColor;
150 }
151 // -----------------------------------------------------------------------------
152 sal_Int32 lcl_setColorOfObject(uno::Reference< uno::XInterface > _xObj, long _nColorTRGB)
153 {
154     sal_Int32 nBackColor = 0;
155     try
156     {
157         uno::Reference<report::XReportComponent> xComponent(_xObj, uno::UNO_QUERY_THROW);
158         // NOT NEED if UNO_QUERY_THROW:
159         // if (xComponent.is())
160         // {
161         uno::Reference< beans::XPropertySet > xProp(xComponent, uno::UNO_QUERY_THROW);
162         // if (xProp.is())
163         // {
164         // ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlBackground"))
165         // is PROPERTY_CONTROLBACKGROUND
166         uno::Any aAny = xProp->getPropertyValue(PROPERTY_CONTROLBACKGROUND);
167         if (aAny.hasValue())
168         {
169             aAny >>= nBackColor;
170             // try to set background color at the ReportComponent
171             uno::Any aBlackColorAny = uno::makeAny(_nColorTRGB);
172             xProp->setPropertyValue(PROPERTY_CONTROLBACKGROUND, aBlackColorAny);
173         }
174         // aCopies.push_back(xComponent->createClone());
175     }
176     catch(uno::Exception&)
177     {
178         // bit my shiny metal as!
179         // OSL_ENSURE(0,"Can't copy report elements!");
180     }
181     return nBackColor;
182 }
183 // -----------------------------------------------------------------------------
184 DlgEdFunc::~DlgEdFunc()
185 {
186     unColorizeOverlappedObj();
187     aScrollTimer.Stop();
188 }
189 
190 //----------------------------------------------------------------------------
191 
192 sal_Bool DlgEdFunc::MouseButtonDown( const MouseEvent& rMEvt )
193 {
194     m_aMDPos = m_pParent->PixelToLogic( rMEvt.GetPosPixel() );
195     m_pParent->GrabFocus();
196     sal_Bool bHandled = sal_False;
197     if ( rMEvt.IsLeft() )
198     {
199         if ( rMEvt.GetClicks() > 1 )
200         {
201             // show property browser
202             if ( m_pParent->GetMode() != RPTUI_READONLY )
203             {
204                 uno::Sequence<beans::PropertyValue> aArgs(1);
205                 aArgs[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowProperties"));
206                 aArgs[0].Value <<= sal_True;
207                 m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->getController().executeUnChecked(SID_SHOW_PROPERTYBROWSER,aArgs);
208                 m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->UpdatePropertyBrowserDelayed(m_rView);
209                 // TODO character in shapes
210                 //    SdrViewEvent aVEvt;
211                 // m_rView.PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
212                 //    if ( aVEvt.pRootObj && aVEvt.pRootObj->ISA(SdrTextObj) )
213                 //        SetInEditMode(static_cast<SdrTextObj *>(aVEvt.pRootObj),rMEvt, sal_False);
214                 bHandled = sal_True;
215             }
216         }
217         else
218         {
219             SdrHdl* pHdl = m_rView.PickHandle(m_aMDPos);
220             //m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(m_pView);
221 
222             // if selected object was hit, drag object
223             if ( pHdl!=NULL || m_rView.IsMarkedHit(m_aMDPos) )
224             {
225                 bHandled = sal_True;
226                 m_pParent->CaptureMouse();
227                 m_pParent->getSectionWindow()->getViewsWindow()->BegDragObj(m_aMDPos, pHdl,&m_rView);
228             }
229         }
230     }
231     else if ( rMEvt.IsRight() && !rMEvt.IsLeft() && rMEvt.GetClicks() == 1 ) // mark object when context menu was selected
232     {
233         SdrPageView* pPV = m_rView.GetSdrPageView();
234         SdrViewEvent aVEvt;
235         if ( m_rView.PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt) != SDRHIT_MARKEDOBJECT && !rMEvt.IsShift() )
236             m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(NULL);
237         if ( aVEvt.pRootObj )
238             m_rView.MarkObj(aVEvt.pRootObj, pPV);
239         else
240             m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(NULL);
241 
242         bHandled = sal_True;
243     }
244     else if( !rMEvt.IsLeft() )
245         bHandled = sal_True;
246     if ( !bHandled )
247         m_pParent->CaptureMouse();
248     return bHandled;
249 }
250 
251 //----------------------------------------------------------------------------
252 
253 sal_Bool DlgEdFunc::MouseButtonUp( const MouseEvent& /*rMEvt*/ )
254 {
255     sal_Bool bHandled = sal_False;
256     m_pParent->getSectionWindow()->getViewsWindow()->stopScrollTimer();
257     return bHandled;
258 }
259 // -----------------------------------------------------------------------------
260 void DlgEdFunc::checkTwoCklicks(const MouseEvent& rMEvt)
261 {
262     deactivateOle();
263 
264     const sal_uInt16 nClicks = rMEvt.GetClicks();
265     if ( nClicks == 2 && rMEvt.IsLeft() )
266     {
267         if ( m_rView.AreObjectsMarked() )
268         {
269             const SdrMarkList& rMarkList = m_rView.GetMarkedObjectList();
270             if (rMarkList.GetMarkCount() == 1)
271             {
272                 const SdrMark* pMark = rMarkList.GetMark(0);
273                 SdrObject* pObj = pMark->GetMarkedSdrObj();
274                 activateOle(pObj);
275             } // if (rMarkList.GetMarkCount() == 1)
276         } // if ( pView->AreObjectsMarked() )
277     }
278 }
279 // -----------------------------------------------------------------------------
280 void DlgEdFunc::stopScrollTimer()
281 {
282     unColorizeOverlappedObj();
283     aScrollTimer.Stop();
284     if ( m_pParent->IsMouseCaptured() )
285         m_pParent->ReleaseMouse();
286 }
287 //----------------------------------------------------------------------------
288 
289 sal_Bool DlgEdFunc::MouseMove( const MouseEvent& /*rMEvt*/ )
290 {
291     return sal_False;
292 }
293 //------------------------------------------------------------------------------
294 sal_Bool DlgEdFunc::handleKeyEvent(const KeyEvent& _rEvent)
295 {
296     sal_Bool bReturn = sal_False;
297 
298     if ( !m_bUiActive )
299     {
300         const KeyCode& rCode = _rEvent.GetKeyCode();
301         sal_uInt16 nCode = rCode.GetCode();
302 
303         switch ( nCode )
304         {
305             case KEY_ESCAPE:
306             {
307                 if ( m_pParent->getSectionWindow()->getViewsWindow()->IsAction() )
308                 {
309                     m_pParent->getSectionWindow()->getViewsWindow()->BrkAction();
310                     bReturn = sal_True;
311                 }
312                 else if ( m_rView.IsTextEdit() )
313                 {
314                     m_rView.SdrEndTextEdit();
315                     bReturn = sal_True;
316                 }
317                 else if ( m_rView.AreObjectsMarked() )
318                 {
319                     const SdrHdlList& rHdlList = m_rView.GetHdlList();
320                     SdrHdl* pHdl = rHdlList.GetFocusHdl();
321                     if ( pHdl )
322                         ((SdrHdlList&)rHdlList).ResetFocusHdl();
323                     else
324                         m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(NULL);
325                         //m_rView.UnmarkAll();
326 
327                     deactivateOle(true);
328                     bReturn = sal_False;
329                 }
330                 else
331                 {
332                     deactivateOle(true);
333                 }
334             }
335             break;
336             case KEY_TAB:
337             {
338                 if ( !rCode.IsMod1() && !rCode.IsMod2() )
339                 {
340                     // mark next object
341                     if ( !m_rView.MarkNextObj( !rCode.IsShift() ) )
342                     {
343                         // if no next object, mark first/last
344                         m_rView.UnmarkAllObj();
345                         m_rView.MarkNextObj( !rCode.IsShift() );
346                     }
347 
348                     if ( m_rView.AreObjectsMarked() )
349                         m_rView.MakeVisible( m_rView.GetAllMarkedRect(), *m_pParent);
350 
351                     bReturn = sal_True;
352                 }
353                 else if ( rCode.IsMod1() && rCode.IsMod2())
354                 {
355                     // selected handle
356                     const SdrHdlList& rHdlList = m_rView.GetHdlList();
357                     ((SdrHdlList&)rHdlList).TravelFocusHdl( !rCode.IsShift() );
358 
359                     // guarantee visibility of focused handle
360                     SdrHdl* pHdl = rHdlList.GetFocusHdl();
361                     if ( pHdl )
362                     {
363                         Point aHdlPosition( pHdl->GetPos() );
364                         Rectangle aVisRect( aHdlPosition - Point( DEFAUL_MOVE_SIZE, DEFAUL_MOVE_SIZE ), Size( 200, 200 ) );
365                         m_rView.MakeVisible( aVisRect, *m_pParent);
366                     }
367 
368                     bReturn = sal_True;
369                 }
370             }
371             break;
372             case KEY_UP:
373             case KEY_DOWN:
374             case KEY_LEFT:
375             case KEY_RIGHT:
376             {
377                 m_pParent->getSectionWindow()->getViewsWindow()->handleKey(rCode);
378                 bReturn = sal_True;
379             }
380             break;
381             case KEY_RETURN:
382                 if ( !rCode.IsMod1() )
383                 {
384                     const SdrMarkList& rMarkList = m_rView.GetMarkedObjectList();
385                     if ( rMarkList.GetMarkCount() == 1 )
386                     {
387                         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
388                         activateOle(pObj);
389                     }
390                 }
391                 break;
392             case KEY_DELETE:
393                 if ( !rCode.IsMod1() && !rCode.IsMod2() )
394                 {
395                     bReturn = sal_True;
396                     break;
397                 } // if ( !rCode.IsMod1() && !rCode.IsMod2() )
398                 // run through
399             default:
400             {
401                 bReturn = m_rView.KeyInput(_rEvent, m_pParent);
402             }
403             break;
404         }
405     }
406 
407     if ( bReturn && m_pParent->IsMouseCaptured() )
408         m_pParent->ReleaseMouse();
409 
410     return bReturn;
411 }
412 // -----------------------------------------------------------------------------
413 void DlgEdFunc::activateOle(SdrObject* _pObj)
414 {
415     if ( _pObj )
416     {
417         const sal_uInt16 nSdrObjKind = _pObj->GetObjIdentifier();
418         //
419         //  OLE: activate
420         //
421         if (nSdrObjKind == OBJ_OLE2)
422         {
423             bool bIsInplaceOle = false;
424             if (!bIsInplaceOle)
425             {
426                 SdrOle2Obj* pOleObj = dynamic_cast<SdrOle2Obj*>(_pObj);
427                 if ( pOleObj->GetObjRef().is() )
428                 {
429                     if (m_rView.IsTextEdit())
430                     {
431                         m_rView.SdrEndTextEdit();
432                     }
433 
434                     pOleObj->AddOwnLightClient();
435                     pOleObj->SetWindow(VCLUnoHelper::GetInterface(m_pParent));
436                     try
437                     {
438                         pOleObj->GetObjRef()->changeState( embed::EmbedStates::UI_ACTIVE );
439                         m_bUiActive = true;
440                         OReportController& rController = m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->getController();
441                         m_bShowPropertyBrowser = rController.isCommandChecked(SID_SHOW_PROPERTYBROWSER);
442                         if ( m_bShowPropertyBrowser )
443                             rController.executeChecked(SID_SHOW_PROPERTYBROWSER,uno::Sequence< beans::PropertyValue >());
444                     }
445                     catch( uno::Exception& )
446                     {
447                         DBG_UNHANDLED_EXCEPTION();
448                     }
449                 }
450             }
451         } // if (nSdrObjKind == OBJ_OLE2)
452     } // if ( _pObj )
453 }
454 // -----------------------------------------------------------------------------
455 void DlgEdFunc::deactivateOle(bool _bSelect)
456 {
457     OLEObjCache& rObjCache = GetSdrGlobalData().GetOLEObjCache();
458     OReportController& rController = m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->getController();
459     const sal_uLong nCount = rObjCache.Count();
460     for(sal_uLong i = 0 ; i< nCount;++i)
461     {
462         SdrOle2Obj* pObj = reinterpret_cast<SdrOle2Obj*>(rObjCache.GetObject(i));
463         if ( m_pParent->getPage() == pObj->GetPage() )
464         {
465             uno::Reference< embed::XEmbeddedObject > xObj = pObj->GetObjRef();
466             if ( xObj.is() && xObj->getCurrentState() == embed::EmbedStates::UI_ACTIVE )
467             {
468                 xObj->changeState( embed::EmbedStates::RUNNING );
469                 m_bUiActive = false;
470                 if ( m_bShowPropertyBrowser )
471                 {
472                     rController.executeChecked(SID_SHOW_PROPERTYBROWSER,uno::Sequence< beans::PropertyValue >());
473                 }
474 
475                 if ( _bSelect )
476                 {
477                     SdrPageView* pPV = m_rView.GetSdrPageView();
478                     m_rView.MarkObj(pObj, pPV);
479                 }
480             } // if ( xObj.is() && xObj->getCurrentState() == embed::EmbedStates::UI_ACTIVE )
481         }
482     } // for(sal_uLong i = 0 ; i< nCount;++i)
483 }
484 // -----------------------------------------------------------------------------
485 void DlgEdFunc::colorizeOverlappedObject(SdrObject* _pOverlappedObj)
486 {
487     OObjectBase* pObj = dynamic_cast<OObjectBase*>(_pOverlappedObj);
488     if ( pObj )
489     {
490         uno::Reference<report::XReportComponent> xComponent = pObj->getReportComponent();
491         if (xComponent.is() && xComponent != m_xOverlappingObj)
492         {
493             OReportModel* pRptModel = static_cast<OReportModel*>(_pOverlappedObj->GetModel());
494             if ( pRptModel )
495             {
496                 OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
497 
498                 // uncolorize an old object, if there is one
499                 unColorizeOverlappedObj();
500 
501                 m_nOldColor = lcl_setColorOfObject(xComponent, m_nOverlappedControlColor);
502                 m_xOverlappingObj = xComponent;
503                 m_pOverlappingObj = _pOverlappedObj;
504             }
505         }
506     }
507 }
508 // -----------------------------------------------------------------------------
509 void DlgEdFunc::unColorizeOverlappedObj()
510 {
511     // uncolorize an old object, if there is one
512     if (m_xOverlappingObj.is())
513     {
514         OReportModel* pRptModel = static_cast<OReportModel*>(m_pOverlappingObj->GetModel());
515         if ( pRptModel )
516         {
517             OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
518 
519             lcl_setColorOfObject(m_xOverlappingObj, m_nOldColor);
520             m_xOverlappingObj = NULL;
521             m_pOverlappingObj = NULL;
522         }
523     }
524 }
525 // -----------------------------------------------------------------------------
526 bool DlgEdFunc::isOverlapping(const MouseEvent& rMEvt)
527 {
528     bool bOverlapping = false;
529     SdrViewEvent aVEvt;
530     bOverlapping = m_rView.PickAnything(rMEvt, SDRMOUSEBUTTONUP, aVEvt) != SDRHIT_NONE;
531     if (bOverlapping && aVEvt.pObj)
532     {
533         colorizeOverlappedObject(aVEvt.pObj);
534     }
535     else
536     {
537         unColorizeOverlappedObj();
538     }
539 
540     return bOverlapping;
541 }
542 // -----------------------------------------------------------------------------
543 void DlgEdFunc::checkMovementAllowed(const MouseEvent& rMEvt)
544 {
545     if ( m_pParent->getSectionWindow()->getViewsWindow()->IsDragObj() )
546     {
547         if ( isRectangleHit(rMEvt) )
548         {
549             // there is an other component under use, break action
550             m_pParent->getSectionWindow()->getViewsWindow()->BrkAction();
551         }
552         // object was dragged
553         Point aPnt( m_pParent->PixelToLogic( rMEvt.GetPosPixel() ) );
554         if (m_bSelectionMode)
555         {
556             m_pParent->getSectionWindow()->getViewsWindow()->EndAction();
557         }
558         else
559         {
560             bool bControlKeyPressed = rMEvt.IsMod1();
561             // Don't allow points smaller 0
562             if (bControlKeyPressed && (aPnt.Y() < 0))
563             {
564                 aPnt.Y() = 0;
565             }
566             if (m_rView.IsDragResize())
567             {
568                 // we resize the object don't resize to above sections
569                 if ( aPnt.Y() < 0 )
570                 {
571                     aPnt.Y() = 0;
572                 }
573             }
574             m_pParent->getSectionWindow()->getViewsWindow()->EndDragObj( bControlKeyPressed, &m_rView, aPnt );
575         }
576         m_pParent->getSectionWindow()->getViewsWindow()->ForceMarkedToAnotherPage();
577         m_pParent->Invalidate(INVALIDATE_CHILDREN);
578     }
579     else
580         m_pParent->getSectionWindow()->getViewsWindow()->EndAction();
581 }
582 // -----------------------------------------------------------------------------
583 bool DlgEdFunc::isOnlyCustomShapeMarked()
584 {
585     bool bReturn = true;
586     const SdrMarkList& rMarkList = m_rView.GetMarkedObjectList();
587     for (sal_uInt32 i =  0; i < rMarkList.GetMarkCount();++i )
588     {
589         SdrMark* pMark = rMarkList.GetMark(i);
590         // bCheck = dynamic_cast<OUnoObject*>(pMark->GetMarkedSdrObj()) != NULL;
591         SdrObject* pObj = pMark->GetMarkedSdrObj();
592         if (pObj->GetObjIdentifier() != OBJ_CUSTOMSHAPE)
593         {
594             // we found an object in the marked objects, which is not a custom shape.
595             bReturn = false;
596             break;
597         }
598     }
599     return bReturn;
600 }
601 // -----------------------------------------------------------------------------
602 bool DlgEdFunc::isRectangleHit(const MouseEvent& rMEvt)
603 {
604     if (isOnlyCustomShapeMarked())
605     {
606         return false;
607     }
608 
609     SdrViewEvent aVEvt;
610     const SdrHitKind eHit = m_rView.PickAnything(rMEvt, SDRMOUSEMOVE, aVEvt);
611     bool bIsSetPoint = (eHit == SDRHIT_UNMARKEDOBJECT);
612     if ( !bIsSetPoint )
613     {
614         // no drag rect, we have to check every single select rect
615         //const Rectangle& rRect = m_rView.GetDragStat().GetActionRect();
616         const SdrDragStat& rDragStat = m_rView.GetDragStat();
617         if (rDragStat.GetDragMethod() != NULL)
618         {
619             SdrObjListIter aIter(*m_pParent->getPage(),IM_DEEPNOGROUPS);
620             SdrObject* pObjIter = NULL;
621             // loop through all marked objects and check if there new rect overlapps an old one.
622             while( (pObjIter = aIter.Next()) != NULL && !bIsSetPoint)
623             {
624                 if ( m_rView.IsObjMarked(pObjIter)
625                      && (dynamic_cast<OUnoObject*>(pObjIter) != NULL || dynamic_cast<OOle2Obj*>(pObjIter) != NULL) )
626                 {
627                     Rectangle aNewRect = pObjIter->GetLastBoundRect();
628                     long nDx = rDragStat.IsHorFixed() ? 0 : rDragStat.GetDX();
629                     long nDy = rDragStat.IsVerFixed() ? 0 : rDragStat.GetDY();
630                     if ( (nDx + aNewRect.Left()) < 0 )
631                         nDx = -aNewRect.Left();
632                     if ( (nDy + aNewRect.Top()) < 0 )
633                         nDy = -aNewRect.Top();
634 
635                     if ( rDragStat.GetDragMethod()->getMoveOnly() )
636                         aNewRect.Move(nDx,nDy);
637                     else
638                         ::ResizeRect(aNewRect,rDragStat.GetRef1(),rDragStat.GetXFact(),rDragStat.GetYFact());
639 
640 
641                     SdrObject* pObjOverlapped = isOver(aNewRect,*m_pParent->getPage(),m_rView,false,pObjIter, ISOVER_IGNORE_CUSTOMSHAPES);
642                     bIsSetPoint = pObjOverlapped ? true : false;
643                     if (pObjOverlapped && !m_bSelectionMode)
644                     {
645                         colorizeOverlappedObject(pObjOverlapped);
646                     }
647                 }
648             }
649         }
650     }
651     else if ( aVEvt.pObj && (aVEvt.pObj->GetObjIdentifier() != OBJ_CUSTOMSHAPE) && !m_bSelectionMode)
652     {
653         colorizeOverlappedObject(aVEvt.pObj);
654     }
655     else
656         bIsSetPoint = false;
657     return bIsSetPoint;
658 }
659 // -----------------------------------------------------------------------------
660 bool DlgEdFunc::setMovementPointer(const MouseEvent& rMEvt)
661 {
662     bool bIsSetPoint = isRectangleHit(rMEvt);
663     if ( bIsSetPoint )
664         m_pParent->SetPointer( Pointer(POINTER_NOTALLOWED));
665     else
666     {
667         bool bCtrlKey = rMEvt.IsMod1();
668         (void)bCtrlKey;
669         if (bCtrlKey)
670         {
671             m_pParent->SetPointer( Pointer(POINTER_MOVEDATALINK ));
672             bIsSetPoint = true;
673         }
674     }
675     return bIsSetPoint;
676 }
677 //----------------------------------------------------------------------------
678 
679 DlgEdFuncInsert::DlgEdFuncInsert( OReportSection* _pParent ) :
680     DlgEdFunc( _pParent )
681 {
682     m_rView.SetCreateMode( sal_True );
683 }
684 
685 //----------------------------------------------------------------------------
686 
687 DlgEdFuncInsert::~DlgEdFuncInsert()
688 {
689     m_rView.SetEditMode( sal_True );
690 }
691 
692 //----------------------------------------------------------------------------
693 
694 sal_Bool DlgEdFuncInsert::MouseButtonDown( const MouseEvent& rMEvt )
695 {
696     if ( DlgEdFunc::MouseButtonDown(rMEvt) )
697         return sal_True;
698 
699     SdrViewEvent aVEvt;
700     sal_Int16 nId = m_rView.GetCurrentObjIdentifier();
701 
702     const SdrHitKind eHit = m_rView.PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
703 
704 // eHit == SDRHIT_UNMARKEDOBJECT under the mouse cursor is a unmarked object
705 
706     if (eHit == SDRHIT_UNMARKEDOBJECT &&
707         nId != OBJ_CUSTOMSHAPE)
708     {
709         // there is an object under the mouse cursor, but not a customshape
710         // rtl::OUString suWasN = m_rView.getInsertObjString();
711         // rtl::OUString suWasN2 = m_pParent->getSectionWindow()->getViewsWindow()->GetInsertObjString();
712 
713         m_pParent->getSectionWindow()->getViewsWindow()->BrkAction();
714         return sal_False;
715     }
716 
717     if( eHit != SDRHIT_UNMARKEDOBJECT || nId == OBJ_CUSTOMSHAPE)
718     {
719         // if no action, create object
720         if ( !m_pParent->getSectionWindow()->getViewsWindow()->IsAction() )
721         {
722             deactivateOle(true);
723             if ( m_pParent->getSectionWindow()->getViewsWindow()->HasSelection() )
724                 m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(&m_rView);
725             m_rView.BegCreateObj(m_aMDPos);
726             m_pParent->getSectionWindow()->getViewsWindow()->createDefault();
727         }
728     }
729     else
730     {
731         if( !rMEvt.IsShift() )
732         {
733             // shift key pressed?
734             m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(NULL);
735         }
736         m_pParent->getSectionWindow()->getViewsWindow()->BegMarkObj( m_aMDPos,&m_rView );
737     }
738 
739     return sal_True;
740 }
741 
742 //----------------------------------------------------------------------------
743 sal_Bool DlgEdFuncInsert::MouseButtonUp( const MouseEvent& rMEvt )
744 {
745     if ( DlgEdFunc::MouseButtonUp( rMEvt ) )
746         return sal_True;
747 
748     const Point aPos( m_pParent->PixelToLogic( rMEvt.GetPosPixel() ) );
749     const sal_uInt16 nHitLog = sal_uInt16 ( m_pParent->PixelToLogic(Size(3,0)).Width() );
750 
751     sal_Bool bReturn = sal_True;
752     // object creation active?
753     if ( m_rView.IsCreateObj() )
754     {
755         if ( isOver(m_rView.GetCreateObj(),*m_pParent->getPage(),m_rView) )
756         {
757             m_pParent->getSectionWindow()->getViewsWindow()->BrkAction();
758             // BrkAction disables the create mode
759             m_rView.SetCreateMode( sal_True );
760             return sal_True;
761         }
762 
763         m_rView.EndCreateObj(SDRCREATE_FORCEEND);
764 
765         if ( !m_rView.AreObjectsMarked() )
766         {
767             m_rView.MarkObj(aPos, nHitLog);
768         }
769 
770         bReturn = m_rView.AreObjectsMarked();
771         if ( bReturn )
772         {
773             OReportController& rController = m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->getController();
774             const SdrMarkList& rMarkList = m_rView.GetMarkedObjectList();
775             for (sal_uInt32 i =  0; i < rMarkList.GetMarkCount();++i )
776             {
777                 SdrMark* pMark = rMarkList.GetMark(i);
778                 // bCheck = dynamic_cast<OUnoObject*>(pMark->GetMarkedSdrObj()) != NULL;
779                 OOle2Obj* pObj = dynamic_cast<OOle2Obj*>(pMark->GetMarkedSdrObj());
780                 if ( pObj && !pObj->IsEmpty() )
781                 {
782                     pObj->initializeChart(rController.getModel());
783                 }
784             }
785         }
786     }
787     else
788         checkMovementAllowed(rMEvt);
789 
790     if ( !m_rView.AreObjectsMarked() &&
791          Abs(m_aMDPos.X() - aPos.X()) < nHitLog &&
792          Abs(m_aMDPos.Y() - aPos.Y()) < nHitLog &&
793          !rMEvt.IsShift() && !rMEvt.IsMod2() )
794     {
795         SdrPageView* pPV = m_rView.GetSdrPageView();
796         SdrViewEvent aVEvt;
797         m_rView.PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
798         m_rView.MarkObj(aVEvt.pRootObj, pPV);
799     } // ift() && !rMEvt.IsMod2() )
800     checkTwoCklicks(rMEvt);
801     m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->UpdatePropertyBrowserDelayed(m_rView);
802     return bReturn;
803 }
804 
805 //----------------------------------------------------------------------------
806 
807 sal_Bool DlgEdFuncInsert::MouseMove( const MouseEvent& rMEvt )
808 {
809     if ( DlgEdFunc::MouseMove(rMEvt ) )
810         return sal_True;
811     Point   aPos( m_pParent->PixelToLogic( rMEvt.GetPosPixel() ) );
812 
813     if ( m_rView.IsCreateObj() )
814     {
815         m_rView.SetOrtho(SdrObjCustomShape::doConstructOrthogonal(m_rView.getReportSection()->getSectionWindow()->getViewsWindow()->getShapeType()) ? !rMEvt.IsShift() : rMEvt.IsShift());
816         m_rView.SetAngleSnapEnabled(rMEvt.IsShift());
817     }
818 
819     bool bIsSetPoint = false;
820     if ( m_rView.IsAction() )
821     {
822         if ( m_rView.IsDragResize() )
823         {
824             // we resize the object don't resize to above sections
825             if ( aPos.Y() < 0 )
826             {
827                 aPos.Y() = 0;
828             }
829         }
830         bIsSetPoint = setMovementPointer(rMEvt);
831         ForceScroll(aPos);
832         m_pParent->getSectionWindow()->getViewsWindow()->MovAction(aPos,&m_rView, m_rView.GetDragMethod() == NULL, false);
833     }
834 
835     //if ( isOver(m_rView.GetCreateObj(),*m_pParent->getPage(),*m_pView) )
836     //    m_pParent->SetPointer( Pointer(POINTER_NOTALLOWED));
837     //else
838     if ( !bIsSetPoint )
839         m_pParent->SetPointer( m_rView.GetPreferedPointer( aPos, m_pParent) );
840 
841     return sal_True;
842 }
843 
844 //----------------------------------------------------------------------------
845 
846 DlgEdFuncSelect::DlgEdFuncSelect( OReportSection* _pParent ) :
847     DlgEdFunc( _pParent )
848 {
849 }
850 
851 //----------------------------------------------------------------------------
852 
853 DlgEdFuncSelect::~DlgEdFuncSelect()
854 {
855 }
856 
857 //----------------------------------------------------------------------------
858 
859 sal_Bool DlgEdFuncSelect::MouseButtonDown( const MouseEvent& rMEvt )
860 {
861     m_bSelectionMode = false;
862     if ( DlgEdFunc::MouseButtonDown(rMEvt) )
863         return sal_True;
864 
865     SdrViewEvent aVEvt;
866     const SdrHitKind eHit = m_rView.PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
867     if( eHit == SDRHIT_UNMARKEDOBJECT )
868     {
869         // if not multi selection, unmark all
870         if ( !rMEvt.IsShift() )
871             m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(NULL);
872 
873         if ( m_rView.MarkObj(m_aMDPos) && rMEvt.IsLeft() )
874         {
875             // drag object
876             m_pParent->getSectionWindow()->getViewsWindow()->BegDragObj(m_aMDPos, m_rView.PickHandle(m_aMDPos), &m_rView);
877         }
878         else
879         {
880             // select object
881             m_pParent->getSectionWindow()->getViewsWindow()->BegMarkObj(m_aMDPos,&m_rView);
882         }
883     }
884     else
885     {
886         if( !rMEvt.IsShift() )
887             m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(NULL);
888             //m_rView.UnmarkAll();
889 
890         if ( rMEvt.GetClicks() == 1 )
891         {
892             m_bSelectionMode = true;
893             m_pParent->getSectionWindow()->getViewsWindow()->BegMarkObj( m_aMDPos ,&m_rView);
894         }
895         else
896         {
897             m_rView.SdrBeginTextEdit( aVEvt.pRootObj,m_rView.GetSdrPageView(),m_pParent,sal_False );
898         }
899     }
900 
901     return sal_True;
902 }
903 
904 //----------------------------------------------------------------------------
905 
906 sal_Bool DlgEdFuncSelect::MouseButtonUp( const MouseEvent& rMEvt )
907 {
908     if ( DlgEdFunc::MouseButtonUp( rMEvt ) )
909         return sal_True;
910 
911     // get view from parent
912     const Point aPnt( m_pParent->PixelToLogic( rMEvt.GetPosPixel() ) );
913 
914     if ( rMEvt.IsLeft() )                     // left mousebutton pressed
915         checkMovementAllowed(rMEvt);
916 
917     m_pParent->getSectionWindow()->getViewsWindow()->EndAction();
918     checkTwoCklicks(rMEvt);
919 
920     m_pParent->SetPointer( m_rView.GetPreferedPointer( aPnt, m_pParent) );
921 
922     if ( !m_bUiActive )
923         m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->UpdatePropertyBrowserDelayed(m_rView);
924     m_bSelectionMode = false;
925     return sal_True;
926 }
927 
928 //----------------------------------------------------------------------------
929 
930 sal_Bool DlgEdFuncSelect::MouseMove( const MouseEvent& rMEvt )
931 {
932     if ( DlgEdFunc::MouseMove(rMEvt ) )
933         return sal_True;
934 
935     Point aPnt( m_pParent->PixelToLogic( rMEvt.GetPosPixel() ) );
936     bool bIsSetPoint = false;
937 
938     if ( m_rView.IsAction() ) // Drag Mode
939     {
940         bIsSetPoint = setMovementPointer(rMEvt);
941         ForceScroll(aPnt);
942         if (m_rView.GetDragMethod()==NULL)
943         {
944             // create a selection
945             m_pParent->getSectionWindow()->getViewsWindow()->MovAction(aPnt, &m_rView, true, false);
946         }
947         else
948         {
949             if ( m_rView.IsDragResize() )
950             {
951                 // we resize the object don't resize to above sections
952                 if ( aPnt.Y() < 0 )
953                 {
954                     aPnt.Y() = 0;
955                 }
956                 // grow section if it is under the current section
957 //                else
958 //                {
959 //                    const Size& aSectionSize = m_rView->GetSizePixel();
960 //                    if ( aPnt.Y() > aSectionSize.Height() )
961 //                    {
962 //                        aPnt.Y() = aSectionSize.Height();
963 //                    }
964 //                }
965             }
966             // drag or resize an object
967             bool bControlKey = rMEvt.IsMod1();
968             m_pParent->getSectionWindow()->getViewsWindow()->MovAction(aPnt, &m_rView, false, bControlKey);
969         }
970     }
971 
972     if ( !bIsSetPoint )
973     {
974         m_pParent->SetPointer( m_rView.GetPreferedPointer( aPnt, m_pParent) );
975 
976         // restore color
977         unColorizeOverlappedObj();
978     }
979 
980     return sal_True;
981 }
982 // -----------------------------------------------------------------------------
983 //void DlgEdFuncSelect::SetInEditMode(SdrTextObj* _pTextObj,const MouseEvent& rMEvt, sal_Bool bQuickDrag)
984 //{
985 //
986 //  SdrPageView* pPV = m_rView.GetSdrPageView();
987 //  if( _pTextObj && _pTextObj->GetPage() == pPV->GetPage() )
988 //  {
989 //      m_rView.SetCurrentObj(OBJ_TEXT);
990 //      m_rView.SetEditMode(SDREDITMODE_EDIT);
991 //
992 //      sal_Bool bEmptyOutliner = sal_False;
993 //
994 //      if (!_pTextObj->GetOutlinerParaObject() && m_rView.GetTextEditOutliner())
995 //      {
996 //          ::SdrOutliner* pOutl = m_rView.GetTextEditOutliner();
997 //          sal_uLong nParaAnz = pOutl->GetParagraphCount();
998 //          Paragraph* p1stPara = pOutl->GetParagraph( 0 );
999 //
1000 //          if (nParaAnz==1 && p1stPara)
1001 //          {
1002 //              // Bei nur einem Pararaph
1003 //              if (pOutl->GetText(p1stPara).Len() == 0)
1004 //              {
1005 //                  bEmptyOutliner = sal_True;
1006 //              }
1007 //          }
1008 //      }
1009 //
1010 //      if (_pTextObj != m_rView.GetTextEditObject() || bEmptyOutliner)
1011 //      {
1012 //          sal_uInt32 nInv = _pTextObj->GetObjInventor();
1013 //          sal_uInt16 nSdrObjKind = _pTextObj->GetObjIdentifier();
1014 //
1015 //          if (nInv == SdrInventor && _pTextObj->HasTextEdit() &&
1016 //              (nSdrObjKind == OBJ_TEXT ||
1017 //              nSdrObjKind == OBJ_TITLETEXT ||
1018 //              nSdrObjKind == OBJ_OUTLINETEXT ||
1019 //              (_pTextObj->ISA(SdrTextObj) && !_pTextObj->IsEmptyPresObj())))
1020 //          {
1021 //              // Neuen Outliner machen (gehoert der SdrObjEditView)
1022 //                SdrModel* pModel = _pTextObj->GetModel();
1023 //                SdrOutliner* pOutl = SdrMakeOutliner( OUTLINERMODE_OUTLINEOBJECT, pModel );
1024 //              pOutl->SetMinDepth(0);
1025 //              pOutl->SetStyleSheetPool((SfxStyleSheetPool*) pModel->GetStyleSheetPool());
1026 //              //pOutl->SetCalcFieldValueHdl(LINK(SD_MOD(), SdModule, CalcFieldValueHdl));
1027 //              sal_uLong nCntrl = pOutl->GetControlWord();
1028 //              nCntrl |= EE_CNTRL_ALLOWBIGOBJS;
1029 //              nCntrl |= EE_CNTRL_URLSFXEXECUTE;
1030 //              nCntrl |= EE_CNTRL_MARKFIELDS;
1031 //              nCntrl |= EE_CNTRL_AUTOCORRECT;
1032 //
1033 //              nCntrl &= ~EE_CNTRL_ULSPACESUMMATION;
1034 //              //if ( pModel->IsSummationOfParagraphs() )
1035 //              //    nCntrl |= EE_CNTRL_ULSPACESUMMATION;
1036 //
1037 //              //SetSpellOptions( nCntrl );
1038 //
1039 //              pOutl->SetControlWord(nCntrl);
1040 //
1041 //                uno::Reference< linguistic2::XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() );
1042 //              if ( xSpellChecker.is() )
1043 //                  pOutl->SetSpeller( xSpellChecker );
1044 //
1045 //                uno::Reference< linguistic2::XHyphenator > xHyphenator( LinguMgr::GetHyphenator() );
1046 //              if( xHyphenator.is() )
1047 //                  pOutl->SetHyphenator( xHyphenator );
1048 //
1049 //              pOutl->SetDefaultLanguage( Application::GetSettings().GetLanguage() );
1050 //
1051 //              // in einem Gliederungstext darf nicht auf die 0-te
1052 //              // Ebene ausgerueckt werden
1053 //              if (_pTextObj->GetObjInventor() == SdrInventor &&
1054 //                  _pTextObj->GetObjIdentifier() == OBJ_OUTLINETEXT)
1055 //              {
1056 //                  pOutl->SetMinDepth(1);
1057 //              }
1058 //
1059 //              if (bEmptyOutliner)
1060 //              {
1061 //                  m_rView.SdrEndTextEdit(sal_True);
1062 //              }
1063 //
1064 //              if( _pTextObj )
1065 //              {
1066 //                  OutlinerParaObject* pOPO = _pTextObj->GetOutlinerParaObject();
1067 //                  if( ( pOPO && pOPO->IsVertical() ) /*||
1068 //                      nSlotId == SID_ATTR_CHAR_VERTICAL ||
1069 //                      nSlotId == SID_TEXT_FITTOSIZE_VERTICAL */)
1070 //                      pOutl->SetVertical( sal_True );
1071 //
1072 //
1073 //                  if (m_rView.SdrBeginTextEdit(_pTextObj, pPV, pParent, sal_True, pOutl) && _pTextObj->GetObjInventor() == SdrInventor)
1074 //                  {
1075 //                      //bFirstObjCreated = sal_True;
1076 //                      //DeleteDefaultText();
1077 //
1078 //                      OutlinerView* pOLV = m_rView.GetTextEditOutlinerView();
1079 //
1080 //                      nSdrObjKind = _pTextObj->GetObjIdentifier();
1081 //
1082 //                      SdrViewEvent aVEvt;
1083 //                      SdrHitKind eHit = m_rView.PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
1084 //
1085 //                      if (eHit == SDRHIT_TEXTEDIT)
1086 //                      {
1087 //                          // Text getroffen
1088 //                          if (nSdrObjKind == OBJ_TEXT ||
1089 //                              nSdrObjKind == OBJ_TITLETEXT ||
1090 //                              nSdrObjKind == OBJ_OUTLINETEXT ||
1091 //                              //nSlotId == SID_TEXTEDIT ||
1092 //                              !bQuickDrag)
1093 //                          {
1094 //                              pOLV->MouseButtonDown(rMEvt);
1095 //                              pOLV->MouseMove(rMEvt);
1096 //                              pOLV->MouseButtonUp(rMEvt);
1097 //                          }
1098 //
1099 //                          if ( bQuickDrag && _pTextObj->GetOutlinerParaObject())
1100 //                          {
1101 //                              pOLV->MouseButtonDown(rMEvt);
1102 //                          }
1103 //                      }
1104 //                      else
1105 //                      {
1106 //                          // #98198# Move cursor to end of text
1107 //                          ESelection aNewSelection(EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND, EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND);
1108 //                          pOLV->SetSelection(aNewSelection);
1109 //                      }
1110 //                  }
1111 //                  else
1112 //                  {
1113 //                      //RestoreDefaultText();
1114 //                  }
1115 //              }
1116 //          }
1117 //      }
1118 //  }
1119 //  else
1120 //      _pTextObj = NULL;
1121 //}
1122 
1123 
1124 //----------------------------------------------------------------------------
1125 }
1126