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