Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #include <vcl/scrbar.hxx>
20 : #include <vcl/svapp.hxx>
21 : #include <vcl/seleng.hxx>
22 : #include <com/sun/star/linguistic2/XSpellChecker1.hpp>
23 : #include <com/sun/star/embed/EmbedStates.hpp>
24 : #include <com/sun/star/embed/XEmbeddedObject.hpp>
25 : #include <com/sun/star/beans/XPropertySet.hpp>
26 :
27 : #include <svx/svdview.hxx>
28 : #include <svx/svdpagv.hxx>
29 : #include <editeng/outlobj.hxx>
30 : #include <editeng/unolingu.hxx>
31 : #include <svx/svdetc.hxx>
32 : #include <editeng/editstat.hxx>
33 : #include <svx/svdoutl.hxx>
34 : #include <svx/svddrgmt.hxx>
35 : #include <svx/svdoashp.hxx>
36 : #include <svx/svxids.hrc>
37 : #include <svx/svditer.hxx>
38 :
39 : #include <toolkit/helper/vclunohelper.hxx>
40 :
41 : #include "dlgedfunc.hxx"
42 : #include "ReportSection.hxx"
43 : #include "DesignView.hxx"
44 : #include "ReportController.hxx"
45 : #include "SectionView.hxx"
46 : #include "ViewsWindow.hxx"
47 : #include "ReportWindow.hxx"
48 : #include "RptObject.hxx"
49 : #include "ScrollHelper.hxx"
50 :
51 : #include "ReportRuler.hxx"
52 : #include "UITools.hxx"
53 :
54 : #include <uistrings.hrc>
55 : #include "UndoEnv.hxx"
56 : #include <RptModel.hxx>
57 : #include <tools/diagnose_ex.h>
58 :
59 : #define DEFAUL_MOVE_SIZE 100
60 : namespace rptui
61 : {
62 : using namespace ::com::sun::star;
63 : //----------------------------------------------------------------------------
64 :
65 : //----------------------------------------------------------------------------
66 :
67 0 : IMPL_LINK( DlgEdFunc, ScrollTimeout, Timer *, )
68 : {
69 0 : ForceScroll( m_pParent->PixelToLogic( m_pParent->GetPointerPosPixel() ) );
70 0 : return 0;
71 : }
72 :
73 : //----------------------------------------------------------------------------
74 :
75 0 : void DlgEdFunc::ForceScroll( const Point& rPos )
76 : {
77 0 : aScrollTimer.Stop();
78 :
79 0 : OReportWindow* pReportWindow = m_pParent->getSectionWindow()->getViewsWindow()->getView();
80 0 : OScrollWindowHelper* pScrollWindow = pReportWindow->getScrollWindow();
81 :
82 0 : Size aOut = pReportWindow->GetOutputSizePixel();
83 0 : Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
84 0 : aStartWidth *= m_pParent->GetMapMode().GetScaleX();
85 :
86 0 : aOut.Width() -= (long)aStartWidth;
87 0 : aOut.Height() = m_pParent->GetOutputSizePixel().Height();
88 :
89 0 : Point aPos = pScrollWindow->getThumbPos();
90 0 : aPos.X() *= 0.5;
91 0 : aPos.Y() *= 0.5;
92 0 : Rectangle aOutRect( aPos, aOut );
93 0 : aOutRect = m_pParent->PixelToLogic( aOutRect );
94 0 : Point aGcc3WorkaroundTemporary;
95 0 : Rectangle aWorkArea(aGcc3WorkaroundTemporary,pScrollWindow->getTotalSize());
96 0 : aWorkArea.Right() -= (long)aStartWidth;
97 0 : aWorkArea = pScrollWindow->PixelToLogic( aWorkArea );
98 0 : if( !aOutRect.IsInside( rPos ) && aWorkArea.IsInside( rPos ) )
99 : {
100 0 : ScrollBar* pHScroll = pScrollWindow->GetHScroll();
101 0 : ScrollBar* pVScroll = pScrollWindow->GetVScroll();
102 0 : ScrollType eH = SCROLL_LINEDOWN,eV = SCROLL_LINEDOWN;
103 0 : if( rPos.X() < aOutRect.Left() )
104 0 : eH = SCROLL_LINEUP;
105 0 : else if( rPos.X() <= aOutRect.Right() )
106 0 : eH = SCROLL_DONTKNOW;
107 :
108 0 : if( rPos.Y() < aOutRect.Top() )
109 0 : eV = SCROLL_LINEUP;
110 0 : else if( rPos.Y() <= aOutRect.Bottom() )
111 0 : eV = SCROLL_DONTKNOW;
112 :
113 0 : pHScroll->DoScrollAction(eH);
114 0 : pVScroll->DoScrollAction(eV);
115 : }
116 :
117 0 : aScrollTimer.Start();
118 0 : }
119 :
120 : //----------------------------------------------------------------------------
121 :
122 0 : DlgEdFunc::DlgEdFunc( OReportSection* _pParent )
123 : :m_pParent(_pParent),
124 0 : m_rView(_pParent->getSectionView()),
125 : m_xOverlappingObj(NULL),
126 : m_pOverlappingObj(NULL),
127 : m_bSelectionMode(false),
128 : m_bUiActive(false),
129 0 : m_bShowPropertyBrowser(false)
130 : {
131 0 : aScrollTimer.SetTimeoutHdl( LINK( this, DlgEdFunc, ScrollTimeout ) );
132 0 : m_rView.SetActualWin( m_pParent);
133 0 : aScrollTimer.SetTimeout( SELENG_AUTOREPEAT_INTERVAL );
134 0 : }
135 :
136 : //----------------------------------------------------------------------------
137 0 : void DlgEdFunc::setOverlappedControlColor(sal_Int32 _nColor)
138 : {
139 0 : m_nOverlappedControlColor = _nColor;
140 0 : }
141 : // -----------------------------------------------------------------------------
142 0 : sal_Int32 lcl_setColorOfObject(uno::Reference< uno::XInterface > _xObj, long _nColorTRGB)
143 : {
144 0 : sal_Int32 nBackColor = 0;
145 : try
146 : {
147 0 : uno::Reference<report::XReportComponent> xComponent(_xObj, uno::UNO_QUERY_THROW);
148 0 : uno::Reference< beans::XPropertySet > xProp(xComponent, uno::UNO_QUERY_THROW);
149 0 : uno::Any aAny = xProp->getPropertyValue(PROPERTY_CONTROLBACKGROUND);
150 0 : if (aAny.hasValue())
151 : {
152 0 : aAny >>= nBackColor;
153 : // try to set background color at the ReportComponent
154 0 : uno::Any aBlackColorAny = uno::makeAny(_nColorTRGB);
155 0 : xProp->setPropertyValue(PROPERTY_CONTROLBACKGROUND, aBlackColorAny);
156 0 : }
157 : }
158 0 : catch(uno::Exception&)
159 : {
160 : }
161 0 : return nBackColor;
162 : }
163 : // -----------------------------------------------------------------------------
164 0 : DlgEdFunc::~DlgEdFunc()
165 : {
166 0 : unColorizeOverlappedObj();
167 0 : aScrollTimer.Stop();
168 0 : }
169 :
170 : //----------------------------------------------------------------------------
171 :
172 0 : sal_Bool DlgEdFunc::MouseButtonDown( const MouseEvent& rMEvt )
173 : {
174 0 : m_aMDPos = m_pParent->PixelToLogic( rMEvt.GetPosPixel() );
175 0 : m_pParent->GrabFocus();
176 0 : sal_Bool bHandled = sal_False;
177 0 : if ( rMEvt.IsLeft() )
178 : {
179 0 : if ( rMEvt.GetClicks() > 1 )
180 : {
181 : // show property browser
182 0 : if ( m_pParent->GetMode() != RPTUI_READONLY )
183 : {
184 0 : uno::Sequence<beans::PropertyValue> aArgs(1);
185 0 : aArgs[0].Name = OUString("ShowProperties");
186 0 : aArgs[0].Value <<= sal_True;
187 0 : m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->getController().executeUnChecked(SID_SHOW_PROPERTYBROWSER,aArgs);
188 0 : m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->UpdatePropertyBrowserDelayed(m_rView);
189 : // TODO character in shapes
190 : // SdrViewEvent aVEvt;
191 : // m_rView.PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
192 : // if ( aVEvt.pRootObj && aVEvt.pRootObj->ISA(SdrTextObj) )
193 : // SetInEditMode(static_cast<SdrTextObj *>(aVEvt.pRootObj),rMEvt, sal_False);
194 0 : bHandled = sal_True;
195 : }
196 : }
197 : else
198 : {
199 0 : SdrHdl* pHdl = m_rView.PickHandle(m_aMDPos);
200 :
201 : // if selected object was hit, drag object
202 0 : if ( pHdl!=NULL || m_rView.IsMarkedHit(m_aMDPos) )
203 : {
204 0 : bHandled = sal_True;
205 0 : m_pParent->CaptureMouse();
206 0 : m_pParent->getSectionWindow()->getViewsWindow()->BegDragObj(m_aMDPos, pHdl,&m_rView);
207 : }
208 : }
209 : }
210 0 : else if ( rMEvt.IsRight() && !rMEvt.IsLeft() && rMEvt.GetClicks() == 1 ) // mark object when context menu was selected
211 : {
212 0 : SdrPageView* pPV = m_rView.GetSdrPageView();
213 0 : SdrViewEvent aVEvt;
214 0 : if ( m_rView.PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt) != SDRHIT_MARKEDOBJECT && !rMEvt.IsShift() )
215 0 : m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(NULL);
216 0 : if ( aVEvt.pRootObj )
217 0 : m_rView.MarkObj(aVEvt.pRootObj, pPV);
218 : else
219 0 : m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(NULL);
220 :
221 0 : bHandled = sal_True;
222 : }
223 0 : else if( !rMEvt.IsLeft() )
224 0 : bHandled = sal_True;
225 0 : if ( !bHandled )
226 0 : m_pParent->CaptureMouse();
227 0 : return bHandled;
228 : }
229 :
230 : //----------------------------------------------------------------------------
231 :
232 0 : sal_Bool DlgEdFunc::MouseButtonUp( const MouseEvent& /*rMEvt*/ )
233 : {
234 0 : sal_Bool bHandled = sal_False;
235 0 : m_pParent->getSectionWindow()->getViewsWindow()->stopScrollTimer();
236 0 : return bHandled;
237 : }
238 : // -----------------------------------------------------------------------------
239 0 : void DlgEdFunc::checkTwoCklicks(const MouseEvent& rMEvt)
240 : {
241 0 : deactivateOle();
242 :
243 0 : const sal_uInt16 nClicks = rMEvt.GetClicks();
244 0 : if ( nClicks == 2 && rMEvt.IsLeft() )
245 : {
246 0 : if ( m_rView.AreObjectsMarked() )
247 : {
248 0 : const SdrMarkList& rMarkList = m_rView.GetMarkedObjectList();
249 0 : if (rMarkList.GetMarkCount() == 1)
250 : {
251 0 : const SdrMark* pMark = rMarkList.GetMark(0);
252 0 : SdrObject* pObj = pMark->GetMarkedSdrObj();
253 0 : activateOle(pObj);
254 : }
255 : }
256 : }
257 0 : }
258 : // -----------------------------------------------------------------------------
259 0 : void DlgEdFunc::stopScrollTimer()
260 : {
261 0 : unColorizeOverlappedObj();
262 0 : aScrollTimer.Stop();
263 0 : if ( m_pParent->IsMouseCaptured() )
264 0 : m_pParent->ReleaseMouse();
265 0 : }
266 : //----------------------------------------------------------------------------
267 :
268 0 : sal_Bool DlgEdFunc::MouseMove( const MouseEvent& /*rMEvt*/ )
269 : {
270 0 : return sal_False;
271 : }
272 : //------------------------------------------------------------------------------
273 0 : sal_Bool DlgEdFunc::handleKeyEvent(const KeyEvent& _rEvent)
274 : {
275 0 : sal_Bool bReturn = sal_False;
276 :
277 0 : if ( !m_bUiActive )
278 : {
279 0 : const KeyCode& rCode = _rEvent.GetKeyCode();
280 0 : sal_uInt16 nCode = rCode.GetCode();
281 :
282 0 : switch ( nCode )
283 : {
284 : case KEY_ESCAPE:
285 : {
286 0 : if ( m_pParent->getSectionWindow()->getViewsWindow()->IsAction() )
287 : {
288 0 : m_pParent->getSectionWindow()->getViewsWindow()->BrkAction();
289 0 : bReturn = sal_True;
290 : }
291 0 : else if ( m_rView.IsTextEdit() )
292 : {
293 0 : m_rView.SdrEndTextEdit();
294 0 : bReturn = sal_True;
295 : }
296 0 : else if ( m_rView.AreObjectsMarked() )
297 : {
298 0 : const SdrHdlList& rHdlList = m_rView.GetHdlList();
299 0 : SdrHdl* pHdl = rHdlList.GetFocusHdl();
300 0 : if ( pHdl )
301 0 : ((SdrHdlList&)rHdlList).ResetFocusHdl();
302 : else
303 0 : m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(NULL);
304 :
305 0 : deactivateOle(true);
306 0 : bReturn = sal_False;
307 : }
308 : else
309 : {
310 0 : deactivateOle(true);
311 : }
312 : }
313 0 : break;
314 : case KEY_TAB:
315 : {
316 0 : if ( !rCode.IsMod1() && !rCode.IsMod2() )
317 : {
318 : // mark next object
319 0 : if ( !m_rView.MarkNextObj( !rCode.IsShift() ) )
320 : {
321 : // if no next object, mark first/last
322 0 : m_rView.UnmarkAllObj();
323 0 : m_rView.MarkNextObj( !rCode.IsShift() );
324 : }
325 :
326 0 : if ( m_rView.AreObjectsMarked() )
327 0 : m_rView.MakeVisible( m_rView.GetAllMarkedRect(), *m_pParent);
328 :
329 0 : bReturn = sal_True;
330 : }
331 0 : else if ( rCode.IsMod1() && rCode.IsMod2())
332 : {
333 : // selected handle
334 0 : const SdrHdlList& rHdlList = m_rView.GetHdlList();
335 0 : ((SdrHdlList&)rHdlList).TravelFocusHdl( !rCode.IsShift() );
336 :
337 : // guarantee visibility of focused handle
338 0 : SdrHdl* pHdl = rHdlList.GetFocusHdl();
339 0 : if ( pHdl )
340 : {
341 0 : Point aHdlPosition( pHdl->GetPos() );
342 0 : Rectangle aVisRect( aHdlPosition - Point( DEFAUL_MOVE_SIZE, DEFAUL_MOVE_SIZE ), Size( 200, 200 ) );
343 0 : m_rView.MakeVisible( aVisRect, *m_pParent);
344 : }
345 :
346 0 : bReturn = sal_True;
347 : }
348 : }
349 0 : break;
350 : case KEY_UP:
351 : case KEY_DOWN:
352 : case KEY_LEFT:
353 : case KEY_RIGHT:
354 : {
355 0 : m_pParent->getSectionWindow()->getViewsWindow()->handleKey(rCode);
356 0 : bReturn = sal_True;
357 : }
358 0 : break;
359 : case KEY_RETURN:
360 0 : if ( !rCode.IsMod1() )
361 : {
362 0 : const SdrMarkList& rMarkList = m_rView.GetMarkedObjectList();
363 0 : if ( rMarkList.GetMarkCount() == 1 )
364 : {
365 0 : SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
366 0 : activateOle(pObj);
367 : }
368 : }
369 0 : break;
370 : case KEY_DELETE:
371 0 : if ( !rCode.IsMod1() && !rCode.IsMod2() )
372 : {
373 0 : bReturn = sal_True;
374 0 : break;
375 : }
376 : // run through
377 : default:
378 : {
379 0 : bReturn = m_rView.KeyInput(_rEvent, m_pParent);
380 : }
381 0 : break;
382 : }
383 : }
384 :
385 0 : if ( bReturn && m_pParent->IsMouseCaptured() )
386 0 : m_pParent->ReleaseMouse();
387 :
388 0 : return bReturn;
389 : }
390 : // -----------------------------------------------------------------------------
391 0 : void DlgEdFunc::activateOle(SdrObject* _pObj)
392 : {
393 0 : if ( _pObj )
394 : {
395 0 : const sal_uInt16 nSdrObjKind = _pObj->GetObjIdentifier();
396 : //
397 : // OLE: activate
398 : //
399 0 : if (nSdrObjKind == OBJ_OLE2)
400 : {
401 0 : bool bIsInplaceOle = false;
402 0 : if (!bIsInplaceOle)
403 : {
404 0 : SdrOle2Obj* pOleObj = dynamic_cast<SdrOle2Obj*>(_pObj);
405 0 : if ( pOleObj->GetObjRef().is() )
406 : {
407 0 : if (m_rView.IsTextEdit())
408 : {
409 0 : m_rView.SdrEndTextEdit();
410 : }
411 :
412 0 : pOleObj->AddOwnLightClient();
413 0 : pOleObj->SetWindow(VCLUnoHelper::GetInterface(m_pParent));
414 : try
415 : {
416 0 : pOleObj->GetObjRef()->changeState( embed::EmbedStates::UI_ACTIVE );
417 0 : m_bUiActive = true;
418 0 : OReportController& rController = m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->getController();
419 0 : m_bShowPropertyBrowser = rController.isCommandChecked(SID_SHOW_PROPERTYBROWSER);
420 0 : if ( m_bShowPropertyBrowser )
421 0 : rController.executeChecked(SID_SHOW_PROPERTYBROWSER,uno::Sequence< beans::PropertyValue >());
422 : }
423 0 : catch( uno::Exception& )
424 : {
425 : DBG_UNHANDLED_EXCEPTION();
426 : }
427 : }
428 : }
429 : }
430 : }
431 0 : }
432 : // -----------------------------------------------------------------------------
433 0 : void DlgEdFunc::deactivateOle(bool _bSelect)
434 : {
435 0 : OLEObjCache& rObjCache = GetSdrGlobalData().GetOLEObjCache();
436 0 : OReportController& rController = m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->getController();
437 0 : const sal_uLong nCount = rObjCache.size();
438 0 : for(sal_uLong i = 0 ; i< nCount;++i)
439 : {
440 0 : SdrOle2Obj* pObj = rObjCache[i];
441 0 : if ( m_pParent->getPage() == pObj->GetPage() )
442 : {
443 0 : uno::Reference< embed::XEmbeddedObject > xObj = pObj->GetObjRef();
444 0 : if ( xObj.is() && xObj->getCurrentState() == embed::EmbedStates::UI_ACTIVE )
445 : {
446 0 : xObj->changeState( embed::EmbedStates::RUNNING );
447 0 : m_bUiActive = false;
448 0 : if ( m_bShowPropertyBrowser )
449 : {
450 0 : rController.executeChecked(SID_SHOW_PROPERTYBROWSER,uno::Sequence< beans::PropertyValue >());
451 : }
452 :
453 0 : if ( _bSelect )
454 : {
455 0 : SdrPageView* pPV = m_rView.GetSdrPageView();
456 0 : m_rView.MarkObj(pObj, pPV);
457 : }
458 0 : }
459 : }
460 : }
461 0 : }
462 : // -----------------------------------------------------------------------------
463 0 : void DlgEdFunc::colorizeOverlappedObject(SdrObject* _pOverlappedObj)
464 : {
465 0 : OObjectBase* pObj = dynamic_cast<OObjectBase*>(_pOverlappedObj);
466 0 : if ( pObj )
467 : {
468 0 : uno::Reference<report::XReportComponent> xComponent = pObj->getReportComponent();
469 0 : if (xComponent.is() && xComponent != m_xOverlappingObj)
470 : {
471 0 : OReportModel* pRptModel = static_cast<OReportModel*>(_pOverlappedObj->GetModel());
472 0 : if ( pRptModel )
473 : {
474 0 : OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
475 :
476 : // uncolorize an old object, if there is one
477 0 : unColorizeOverlappedObj();
478 :
479 0 : m_nOldColor = lcl_setColorOfObject(xComponent, m_nOverlappedControlColor);
480 0 : m_xOverlappingObj = xComponent;
481 0 : m_pOverlappingObj = _pOverlappedObj;
482 : }
483 0 : }
484 : }
485 0 : }
486 : // -----------------------------------------------------------------------------
487 0 : void DlgEdFunc::unColorizeOverlappedObj()
488 : {
489 : // uncolorize an old object, if there is one
490 0 : if (m_xOverlappingObj.is())
491 : {
492 0 : OReportModel* pRptModel = static_cast<OReportModel*>(m_pOverlappingObj->GetModel());
493 0 : if ( pRptModel )
494 : {
495 0 : OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
496 :
497 0 : lcl_setColorOfObject(m_xOverlappingObj, m_nOldColor);
498 0 : m_xOverlappingObj = NULL;
499 0 : m_pOverlappingObj = NULL;
500 : }
501 : }
502 0 : }
503 : // -----------------------------------------------------------------------------
504 0 : bool DlgEdFunc::isOverlapping(const MouseEvent& rMEvt)
505 : {
506 0 : bool bOverlapping = false;
507 0 : SdrViewEvent aVEvt;
508 0 : bOverlapping = m_rView.PickAnything(rMEvt, SDRMOUSEBUTTONUP, aVEvt) != SDRHIT_NONE;
509 0 : if (bOverlapping && aVEvt.pObj)
510 : {
511 0 : colorizeOverlappedObject(aVEvt.pObj);
512 : }
513 : else
514 : {
515 0 : unColorizeOverlappedObj();
516 : }
517 :
518 0 : return bOverlapping;
519 : }
520 : // -----------------------------------------------------------------------------
521 0 : void DlgEdFunc::checkMovementAllowed(const MouseEvent& rMEvt)
522 : {
523 0 : if ( m_pParent->getSectionWindow()->getViewsWindow()->IsDragObj() )
524 : {
525 0 : if ( isRectangleHit(rMEvt) )
526 : {
527 : // there is an other component under use, break action
528 0 : m_pParent->getSectionWindow()->getViewsWindow()->BrkAction();
529 : }
530 : // object was dragged
531 0 : Point aPnt( m_pParent->PixelToLogic( rMEvt.GetPosPixel() ) );
532 0 : if (m_bSelectionMode)
533 : {
534 0 : m_pParent->getSectionWindow()->getViewsWindow()->EndAction();
535 : }
536 : else
537 : {
538 0 : bool bControlKeyPressed = rMEvt.IsMod1();
539 : // Don't allow points smaller 0
540 0 : if (bControlKeyPressed && (aPnt.Y() < 0))
541 : {
542 0 : aPnt.Y() = 0;
543 : }
544 0 : if (m_rView.IsDragResize())
545 : {
546 : // we resize the object don't resize to above sections
547 0 : if ( aPnt.Y() < 0 )
548 : {
549 0 : aPnt.Y() = 0;
550 : }
551 : }
552 0 : m_pParent->getSectionWindow()->getViewsWindow()->EndDragObj( bControlKeyPressed, &m_rView, aPnt );
553 : }
554 0 : m_pParent->getSectionWindow()->getViewsWindow()->ForceMarkedToAnotherPage();
555 0 : m_pParent->Invalidate(INVALIDATE_CHILDREN);
556 : }
557 : else
558 0 : m_pParent->getSectionWindow()->getViewsWindow()->EndAction();
559 0 : }
560 : // -----------------------------------------------------------------------------
561 0 : bool DlgEdFunc::isOnlyCustomShapeMarked()
562 : {
563 0 : bool bReturn = true;
564 0 : const SdrMarkList& rMarkList = m_rView.GetMarkedObjectList();
565 0 : for (sal_uInt32 i = 0; i < rMarkList.GetMarkCount();++i )
566 : {
567 0 : SdrMark* pMark = rMarkList.GetMark(i);
568 0 : SdrObject* pObj = pMark->GetMarkedSdrObj();
569 0 : if (pObj->GetObjIdentifier() != OBJ_CUSTOMSHAPE)
570 : {
571 : // we found an object in the marked objects, which is not a custom shape.
572 0 : bReturn = false;
573 0 : break;
574 : }
575 : }
576 0 : return bReturn;
577 : }
578 : // -----------------------------------------------------------------------------
579 0 : bool DlgEdFunc::isRectangleHit(const MouseEvent& rMEvt)
580 : {
581 0 : if (isOnlyCustomShapeMarked())
582 : {
583 0 : return false;
584 : }
585 :
586 0 : SdrViewEvent aVEvt;
587 0 : const SdrHitKind eHit = m_rView.PickAnything(rMEvt, SDRMOUSEMOVE, aVEvt);
588 0 : bool bIsSetPoint = (eHit == SDRHIT_UNMARKEDOBJECT);
589 0 : if ( !bIsSetPoint )
590 : {
591 : // no drag rect, we have to check every single select rect
592 0 : const SdrDragStat& rDragStat = m_rView.GetDragStat();
593 0 : if (rDragStat.GetDragMethod() != NULL)
594 : {
595 0 : SdrObjListIter aIter(*m_pParent->getPage(),IM_DEEPNOGROUPS);
596 0 : SdrObject* pObjIter = NULL;
597 : // loop through all marked objects and check if there new rect overlapps an old one.
598 0 : while( (pObjIter = aIter.Next()) != NULL && !bIsSetPoint)
599 : {
600 0 : if ( m_rView.IsObjMarked(pObjIter)
601 0 : && (dynamic_cast<OUnoObject*>(pObjIter) != NULL || dynamic_cast<OOle2Obj*>(pObjIter) != NULL) )
602 : {
603 0 : Rectangle aNewRect = pObjIter->GetLastBoundRect();
604 0 : long nDx = rDragStat.IsHorFixed() ? 0 : rDragStat.GetDX();
605 0 : long nDy = rDragStat.IsVerFixed() ? 0 : rDragStat.GetDY();
606 0 : if ( (nDx + aNewRect.Left()) < 0 )
607 0 : nDx = -aNewRect.Left();
608 0 : if ( (nDy + aNewRect.Top()) < 0 )
609 0 : nDy = -aNewRect.Top();
610 :
611 0 : if ( rDragStat.GetDragMethod()->getMoveOnly() )
612 0 : aNewRect.Move(nDx,nDy);
613 : else
614 0 : ::ResizeRect(aNewRect,rDragStat.GetRef1(),rDragStat.GetXFact(),rDragStat.GetYFact());
615 :
616 :
617 0 : SdrObject* pObjOverlapped = isOver(aNewRect,*m_pParent->getPage(),m_rView,false,pObjIter, ISOVER_IGNORE_CUSTOMSHAPES);
618 0 : bIsSetPoint = pObjOverlapped ? true : false;
619 0 : if (pObjOverlapped && !m_bSelectionMode)
620 : {
621 0 : colorizeOverlappedObject(pObjOverlapped);
622 : }
623 : }
624 0 : }
625 : }
626 : }
627 0 : else if ( aVEvt.pObj && (aVEvt.pObj->GetObjIdentifier() != OBJ_CUSTOMSHAPE) && !m_bSelectionMode)
628 : {
629 0 : colorizeOverlappedObject(aVEvt.pObj);
630 : }
631 : else
632 0 : bIsSetPoint = false;
633 0 : return bIsSetPoint;
634 : }
635 : // -----------------------------------------------------------------------------
636 0 : bool DlgEdFunc::setMovementPointer(const MouseEvent& rMEvt)
637 : {
638 0 : bool bIsSetPoint = isRectangleHit(rMEvt);
639 0 : if ( bIsSetPoint )
640 0 : m_pParent->SetPointer( Pointer(POINTER_NOTALLOWED));
641 : else
642 : {
643 0 : bool bCtrlKey = rMEvt.IsMod1();
644 : (void)bCtrlKey;
645 0 : if (bCtrlKey)
646 : {
647 0 : m_pParent->SetPointer( Pointer(POINTER_MOVEDATALINK ));
648 0 : bIsSetPoint = true;
649 : }
650 : }
651 0 : return bIsSetPoint;
652 : }
653 : //----------------------------------------------------------------------------
654 :
655 0 : DlgEdFuncInsert::DlgEdFuncInsert( OReportSection* _pParent ) :
656 0 : DlgEdFunc( _pParent )
657 : {
658 0 : m_rView.SetCreateMode( sal_True );
659 0 : }
660 :
661 : //----------------------------------------------------------------------------
662 :
663 0 : DlgEdFuncInsert::~DlgEdFuncInsert()
664 : {
665 0 : m_rView.SetEditMode( sal_True );
666 0 : }
667 :
668 : //----------------------------------------------------------------------------
669 :
670 0 : sal_Bool DlgEdFuncInsert::MouseButtonDown( const MouseEvent& rMEvt )
671 : {
672 0 : if ( DlgEdFunc::MouseButtonDown(rMEvt) )
673 0 : return sal_True;
674 :
675 0 : SdrViewEvent aVEvt;
676 0 : sal_Int16 nId = m_rView.GetCurrentObjIdentifier();
677 :
678 0 : const SdrHitKind eHit = m_rView.PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
679 :
680 0 : if (eHit == SDRHIT_UNMARKEDOBJECT &&
681 : nId != OBJ_CUSTOMSHAPE)
682 : {
683 : // there is an object under the mouse cursor, but not a customshape
684 0 : m_pParent->getSectionWindow()->getViewsWindow()->BrkAction();
685 0 : return sal_False;
686 : }
687 :
688 0 : if( eHit != SDRHIT_UNMARKEDOBJECT || nId == OBJ_CUSTOMSHAPE)
689 : {
690 : // if no action, create object
691 0 : if ( !m_pParent->getSectionWindow()->getViewsWindow()->IsAction() )
692 : {
693 0 : deactivateOle(true);
694 0 : if ( m_pParent->getSectionWindow()->getViewsWindow()->HasSelection() )
695 0 : m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(&m_rView);
696 0 : m_rView.BegCreateObj(m_aMDPos);
697 0 : m_pParent->getSectionWindow()->getViewsWindow()->createDefault();
698 : }
699 : }
700 : else
701 : {
702 0 : if( !rMEvt.IsShift() )
703 : {
704 : // shift key pressed?
705 0 : m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(NULL);
706 : }
707 0 : m_pParent->getSectionWindow()->getViewsWindow()->BegMarkObj( m_aMDPos,&m_rView );
708 : }
709 :
710 0 : return sal_True;
711 : }
712 :
713 : //----------------------------------------------------------------------------
714 0 : sal_Bool DlgEdFuncInsert::MouseButtonUp( const MouseEvent& rMEvt )
715 : {
716 0 : if ( DlgEdFunc::MouseButtonUp( rMEvt ) )
717 0 : return sal_True;
718 :
719 0 : const Point aPos( m_pParent->PixelToLogic( rMEvt.GetPosPixel() ) );
720 0 : const sal_uInt16 nHitLog = sal_uInt16 ( m_pParent->PixelToLogic(Size(3,0)).Width() );
721 :
722 0 : sal_Bool bReturn = sal_True;
723 : // object creation active?
724 0 : if ( m_rView.IsCreateObj() )
725 : {
726 0 : if ( isOver(m_rView.GetCreateObj(),*m_pParent->getPage(),m_rView) )
727 : {
728 0 : m_pParent->getSectionWindow()->getViewsWindow()->BrkAction();
729 : // BrkAction disables the create mode
730 0 : m_rView.SetCreateMode( sal_True );
731 0 : return sal_True;
732 : }
733 :
734 0 : m_rView.EndCreateObj(SDRCREATE_FORCEEND);
735 :
736 0 : if ( !m_rView.AreObjectsMarked() )
737 : {
738 0 : m_rView.MarkObj(aPos, nHitLog);
739 : }
740 :
741 0 : bReturn = m_rView.AreObjectsMarked();
742 0 : if ( bReturn )
743 : {
744 0 : OReportController& rController = m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->getController();
745 0 : const SdrMarkList& rMarkList = m_rView.GetMarkedObjectList();
746 0 : for (sal_uInt32 i = 0; i < rMarkList.GetMarkCount();++i )
747 : {
748 0 : SdrMark* pMark = rMarkList.GetMark(i);
749 0 : OOle2Obj* pObj = dynamic_cast<OOle2Obj*>(pMark->GetMarkedSdrObj());
750 0 : if ( pObj && !pObj->IsEmpty() )
751 : {
752 0 : pObj->initializeChart(rController.getModel());
753 : }
754 : }
755 : }
756 : }
757 : else
758 0 : checkMovementAllowed(rMEvt);
759 :
760 0 : if ( !m_rView.AreObjectsMarked() &&
761 0 : std::abs(m_aMDPos.X() - aPos.X()) < nHitLog &&
762 0 : std::abs(m_aMDPos.Y() - aPos.Y()) < nHitLog &&
763 0 : !rMEvt.IsShift() && !rMEvt.IsMod2() )
764 : {
765 0 : SdrPageView* pPV = m_rView.GetSdrPageView();
766 0 : SdrViewEvent aVEvt;
767 0 : m_rView.PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
768 0 : m_rView.MarkObj(aVEvt.pRootObj, pPV);
769 : }
770 0 : checkTwoCklicks(rMEvt);
771 0 : m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->UpdatePropertyBrowserDelayed(m_rView);
772 0 : return bReturn;
773 : }
774 :
775 : //----------------------------------------------------------------------------
776 :
777 0 : sal_Bool DlgEdFuncInsert::MouseMove( const MouseEvent& rMEvt )
778 : {
779 0 : if ( DlgEdFunc::MouseMove(rMEvt ) )
780 0 : return sal_True;
781 0 : Point aPos( m_pParent->PixelToLogic( rMEvt.GetPosPixel() ) );
782 :
783 0 : if ( m_rView.IsCreateObj() )
784 : {
785 0 : m_rView.SetOrtho(SdrObjCustomShape::doConstructOrthogonal(m_rView.getReportSection()->getSectionWindow()->getViewsWindow()->getShapeType()) ? !rMEvt.IsShift() : rMEvt.IsShift());
786 0 : m_rView.SetAngleSnapEnabled(rMEvt.IsShift());
787 : }
788 :
789 0 : bool bIsSetPoint = false;
790 0 : if ( m_rView.IsAction() )
791 : {
792 0 : if ( m_rView.IsDragResize() )
793 : {
794 : // we resize the object don't resize to above sections
795 0 : if ( aPos.Y() < 0 )
796 : {
797 0 : aPos.Y() = 0;
798 : }
799 : }
800 0 : bIsSetPoint = setMovementPointer(rMEvt);
801 0 : ForceScroll(aPos);
802 0 : m_pParent->getSectionWindow()->getViewsWindow()->MovAction(aPos,&m_rView, m_rView.GetDragMethod() == NULL, false);
803 : }
804 :
805 0 : if ( !bIsSetPoint )
806 0 : m_pParent->SetPointer( m_rView.GetPreferedPointer( aPos, m_pParent) );
807 :
808 0 : return sal_True;
809 : }
810 :
811 : //----------------------------------------------------------------------------
812 :
813 0 : DlgEdFuncSelect::DlgEdFuncSelect( OReportSection* _pParent ) :
814 0 : DlgEdFunc( _pParent )
815 : {
816 0 : }
817 :
818 : //----------------------------------------------------------------------------
819 :
820 0 : DlgEdFuncSelect::~DlgEdFuncSelect()
821 : {
822 0 : }
823 :
824 : //----------------------------------------------------------------------------
825 :
826 0 : sal_Bool DlgEdFuncSelect::MouseButtonDown( const MouseEvent& rMEvt )
827 : {
828 0 : m_bSelectionMode = false;
829 0 : if ( DlgEdFunc::MouseButtonDown(rMEvt) )
830 0 : return sal_True;
831 :
832 0 : SdrViewEvent aVEvt;
833 0 : const SdrHitKind eHit = m_rView.PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
834 0 : if( eHit == SDRHIT_UNMARKEDOBJECT )
835 : {
836 : // if not multi selection, unmark all
837 0 : if ( !rMEvt.IsShift() )
838 0 : m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(NULL);
839 :
840 0 : if ( m_rView.MarkObj(m_aMDPos) && rMEvt.IsLeft() )
841 : {
842 : // drag object
843 0 : m_pParent->getSectionWindow()->getViewsWindow()->BegDragObj(m_aMDPos, m_rView.PickHandle(m_aMDPos), &m_rView);
844 : }
845 : else
846 : {
847 : // select object
848 0 : m_pParent->getSectionWindow()->getViewsWindow()->BegMarkObj(m_aMDPos,&m_rView);
849 : }
850 : }
851 : else
852 : {
853 0 : if( !rMEvt.IsShift() )
854 0 : m_pParent->getSectionWindow()->getViewsWindow()->unmarkAllObjects(NULL);
855 :
856 0 : if ( rMEvt.GetClicks() == 1 )
857 : {
858 0 : m_bSelectionMode = true;
859 0 : m_pParent->getSectionWindow()->getViewsWindow()->BegMarkObj( m_aMDPos ,&m_rView);
860 : }
861 : else
862 : {
863 0 : m_rView.SdrBeginTextEdit( aVEvt.pRootObj,m_rView.GetSdrPageView(),m_pParent,sal_False );
864 : }
865 : }
866 :
867 0 : return sal_True;
868 : }
869 :
870 : //----------------------------------------------------------------------------
871 :
872 0 : sal_Bool DlgEdFuncSelect::MouseButtonUp( const MouseEvent& rMEvt )
873 : {
874 0 : if ( DlgEdFunc::MouseButtonUp( rMEvt ) )
875 0 : return sal_True;
876 :
877 : // get view from parent
878 0 : const Point aPnt( m_pParent->PixelToLogic( rMEvt.GetPosPixel() ) );
879 :
880 0 : if ( rMEvt.IsLeft() ) // left mousebutton pressed
881 0 : checkMovementAllowed(rMEvt);
882 :
883 0 : m_pParent->getSectionWindow()->getViewsWindow()->EndAction();
884 0 : checkTwoCklicks(rMEvt);
885 :
886 0 : m_pParent->SetPointer( m_rView.GetPreferedPointer( aPnt, m_pParent) );
887 :
888 0 : if ( !m_bUiActive )
889 0 : m_pParent->getSectionWindow()->getViewsWindow()->getView()->getReportView()->UpdatePropertyBrowserDelayed(m_rView);
890 0 : m_bSelectionMode = false;
891 0 : return sal_True;
892 : }
893 :
894 : //----------------------------------------------------------------------------
895 :
896 0 : sal_Bool DlgEdFuncSelect::MouseMove( const MouseEvent& rMEvt )
897 : {
898 0 : if ( DlgEdFunc::MouseMove(rMEvt ) )
899 0 : return sal_True;
900 :
901 0 : Point aPnt( m_pParent->PixelToLogic( rMEvt.GetPosPixel() ) );
902 0 : bool bIsSetPoint = false;
903 :
904 0 : if ( m_rView.IsAction() ) // Drag Mode
905 : {
906 0 : bIsSetPoint = setMovementPointer(rMEvt);
907 0 : ForceScroll(aPnt);
908 0 : if (m_rView.GetDragMethod()==NULL)
909 : {
910 : // create a selection
911 0 : m_pParent->getSectionWindow()->getViewsWindow()->MovAction(aPnt, &m_rView, true, false);
912 : }
913 : else
914 : {
915 0 : if ( m_rView.IsDragResize() )
916 : {
917 : // we resize the object don't resize to above sections
918 0 : if ( aPnt.Y() < 0 )
919 : {
920 0 : aPnt.Y() = 0;
921 : }
922 : }
923 : // drag or resize an object
924 0 : bool bControlKey = rMEvt.IsMod1();
925 0 : m_pParent->getSectionWindow()->getViewsWindow()->MovAction(aPnt, &m_rView, false, bControlKey);
926 : }
927 : }
928 :
929 0 : if ( !bIsSetPoint )
930 : {
931 0 : m_pParent->SetPointer( m_rView.GetPreferedPointer( aPnt, m_pParent) );
932 :
933 : // restore color
934 0 : unColorizeOverlappedObj();
935 : }
936 :
937 0 : return sal_True;
938 : }
939 :
940 : //----------------------------------------------------------------------------
941 0 : }
942 :
943 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|