| 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 |
|
| 20 |
#include <DrawViewWrapper.hxx> |
| 21 |
#include <chartview/DrawModelWrapper.hxx> |
| 22 |
|
| 23 |
#include <unotools/lingucfg.hxx> |
| 24 |
#include <unotools/syslocale.hxx> |
| 25 |
#include <unotools/localedatawrapper.hxx> |
| 26 |
#include <editeng/eeitem.hxx> |
| 27 |
#include <editeng/langitem.hxx> |
| 28 |
#include <svl/intitem.hxx> |
| 29 |
#include <svl/itempool.hxx> |
| 30 |
#include <svx/obj3d.hxx> |
| 31 |
#include <svx/svdpagv.hxx> |
| 32 |
#include <svx/svdmodel.hxx> |
| 33 |
#include <svx/svdetc.hxx> |
| 34 |
#include <svx/svdoutl.hxx> |
| 35 |
#include <svx/svxids.hrc> |
| 36 |
#include <editeng/fhgtitem.hxx> |
| 37 |
#include <osl/diagnose.h> |
| 38 |
|
| 39 |
#include <com/sun/star/drawing/XShape.hpp> |
| 40 |
|
| 41 |
#include <sfx2/objsh.hxx> |
| 42 |
#include <sfx2/viewsh.hxx> |
| 43 |
#include <svx/helperhittest3d.hxx> |
| 44 |
#include <officecfg/Office/Calc.hxx> |
| 45 |
|
| 46 |
using namespace ::com::sun::star; |
| 47 |
|
| 48 |
namespace chart |
| 49 |
{ |
| 50 |
|
| 51 |
namespace |
| 52 |
{ |
| 53 |
short lcl_getHitTolerance( OutputDevice const * pOutDev ) |
| 54 |
{ |
| 55 |
const short HITPIX=2; //hit-tolerance in pixel |
| 56 |
short nHitTolerance = 50; |
| 57 |
if(pOutDev) |
| 58 |
nHitTolerance = static_cast<short>(pOutDev->PixelToLogic(Size(HITPIX,0)).Width()); |
| 59 |
return nHitTolerance; |
| 60 |
} |
| 61 |
|
| 62 |
// this code is copied from sfx2/source/doc/objembed.cxx. It is a workaround to |
| 63 |
// get the reference device (e.g. printer) from the parent document |
| 64 |
OutputDevice * lcl_GetParentRefDevice( const uno::Reference< frame::XModel > & xModel ) |
| 65 |
{ |
| 66 |
SfxObjectShell* pParent = SfxObjectShell::GetParentShell(xModel); |
| 67 |
if ( pParent ) |
| 68 |
return pParent->GetDocumentRefDev(); |
| 69 |
return nullptr; |
| 70 |
} |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
DrawViewWrapper::DrawViewWrapper( |
| 75 |
SdrModel& rSdrModel, |
| 76 |
OutputDevice* pOut) |
| 77 |
: E3dView(rSdrModel, pOut) |
| 78 |
,m_pMarkHandleProvider(nullptr) |
| 79 |
,m_apOutliner(SdrMakeOutliner(OutlinerMode::TextObject, rSdrModel)) |
| 80 |
,m_bRestoreMapMode( false ) |
| 81 |
{ |
| 82 |
SetBufferedOutputAllowed(true); |
| 83 |
SetBufferedOverlayAllowed(true); |
| 84 |
|
| 85 |
// #i12587# support for shapes in chart |
| 86 |
SdrOutliner* pOutliner = getOutliner(); |
| 87 |
SfxItemPool* pOutlinerPool = ( pOutliner ? pOutliner->GetEditEnginePool() : nullptr ); |
| 88 |
if ( pOutlinerPool ) |
| 89 |
{ |
| 90 |
SvtLinguConfig aLinguConfig; |
| 91 |
SvtLinguOptions aLinguOptions; |
| 92 |
aLinguConfig.GetOptions( aLinguOptions ); |
| 93 |
pOutlinerPool->SetUserDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage, EE_CHAR_LANGUAGE ) ); |
| 94 |
pOutlinerPool->SetUserDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage_CJK, EE_CHAR_LANGUAGE_CJK ) ); |
| 95 |
pOutlinerPool->SetUserDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage_CTL, EE_CHAR_LANGUAGE_CTL ) ); |
| 96 |
|
| 97 |
// set font height without changing SdrEngineDefaults |
| 98 |
pOutlinerPool->SetUserDefaultItem( SvxFontHeightItem( 423, 100, EE_CHAR_FONTHEIGHT ) ); // 12pt |
| 99 |
} |
| 100 |
|
| 101 |
// #i121463# Use big handles by default |
| 102 |
SetMarkHdlSizePixel(9); |
| 103 |
|
| 104 |
ReInit(); |
| 105 |
} |
| 106 |
|
| 107 |
void DrawViewWrapper::ReInit() |
| 108 |
{ |
| 109 |
OutputDevice* pOutDev = GetFirstOutputDevice(); |
| 110 |
Size aOutputSize(100,100); |
| 111 |
if(pOutDev) |
| 112 |
aOutputSize = pOutDev->GetOutputSize(); |
| 113 |
|
| 114 |
mbPageVisible = false; |
| 115 |
mbPageBorderVisible = false; |
| 116 |
mbBordVisible = false; |
| 117 |
mbGridVisible = false; |
| 118 |
mbHlplVisible = false; |
| 119 |
|
| 120 |
SetNoDragXorPolys(true);//for interactive 3D resize-dragging: paint only a single rectangle (not a simulated 3D object) |
| 121 |
|
| 122 |
//a correct work area is at least necessary for correct values in the position and size dialog |
| 123 |
tools::Rectangle aRect(Point(0,0), aOutputSize); |
| 124 |
SetWorkArea(aRect); |
| 125 |
|
| 126 |
ShowSdrPage(GetModel().GetPage(0)); |
| 127 |
} |
| 128 |
|
| 129 |
DrawViewWrapper::~DrawViewWrapper() |
| 130 |
{ |
| 131 |
maComeBackIdle.Stop();//@todo this should be done in destructor of base class |
| 132 |
UnmarkAllObj();//necessary to avoid a paint call during the destructor hierarchy |
| 133 |
} |
| 134 |
|
| 135 |
SdrPageView* DrawViewWrapper::GetPageView() const |
| 136 |
{ |
| 137 |
SdrPageView* pSdrPageView = GetSdrPageView(); |
| 138 |
return pSdrPageView; |
| 139 |
}; |
| 140 |
|
| 141 |
void DrawViewWrapper::SetMarkHandles(SfxViewShell* pOtherShell) |
| 142 |
{ |
| 143 |
if( m_pMarkHandleProvider && m_pMarkHandleProvider->getMarkHandles( maHdlList ) ) |
| 144 |
return; |
| 145 |
else |
| 146 |
SdrView::SetMarkHandles(pOtherShell); |
| 147 |
} |
| 148 |
|
| 149 |
SdrObject* DrawViewWrapper::getHitObject( const Point& rPnt ) const |
| 150 |
{ |
| 151 |
SdrPageView* pSdrPageView = GetPageView(); |
| 152 |
SdrObject* pRet = SdrView::PickObj(rPnt, lcl_getHitTolerance( GetFirstOutputDevice() ), pSdrPageView, |
| 153 |
SdrSearchOptions::DEEP | SdrSearchOptions::TESTMARKABLE); |
| 154 |
|
| 155 |
if( pRet ) |
| 156 |
{ |
| 157 |
// ignore some special shapes |
| 158 |
OUString aShapeName = pRet->GetName(); |
| 159 |
|
| 160 |
// return right away if it is a field button |
| 161 |
if (aShapeName.startsWith("FieldButton")) |
| 162 |
return pRet; |
| 163 |
|
| 164 |
if( aShapeName.match("PlotAreaIncludingAxes") || aShapeName.match("PlotAreaExcludingAxes") ) |
| 165 |
{ |
| 166 |
pRet->SetMarkProtect( true ); |
| 167 |
return getHitObject( rPnt ); |
| 168 |
} |
| 169 |
|
| 170 |
//3d objects need a special treatment |
| 171 |
//because the simple PickObj method is not accurate in this case for performance reasons |
| 172 |
E3dObject* pE3d = DynCastE3dObject(pRet); |
| 173 |
if( pE3d ) |
| 174 |
{ |
| 175 |
E3dScene* pScene(pE3d->getRootE3dSceneFromE3dObject()); |
| 176 |
|
| 177 |
if(nullptr != pScene) |
| 178 |
{ |
| 179 |
// prepare result vector and call helper |
| 180 |
std::vector< const E3dCompoundObject* > aHitList; |
| 181 |
const basegfx::B2DPoint aHitPoint(rPnt.X(), rPnt.Y()); |
| 182 |
getAllHit3DObjectsSortedFrontToBack(aHitPoint, *pScene, aHitList); |
| 183 |
|
| 184 |
if(!aHitList.empty()) |
| 185 |
{ |
| 186 |
// choose the frontmost hit 3D object of the scene |
| 187 |
pRet = const_cast< E3dCompoundObject* >(aHitList[0]); |
| 188 |
} |
| 189 |
} |
| 190 |
} |
| 191 |
} |
| 192 |
return pRet; |
| 193 |
} |
| 194 |
|
| 195 |
void DrawViewWrapper::MarkObject( SdrObject* pObj ) |
| 196 |
{ |
| 197 |
bool bFrameDragSingles = true;//true == green == surrounding handles |
| 198 |
if(pObj) |
| 199 |
pObj->SetMarkProtect(false); |
| 200 |
if( m_pMarkHandleProvider ) |
| 201 |
bFrameDragSingles = m_pMarkHandleProvider->getFrameDragSingles(); |
| 202 |
|
| 203 |
SetFrameDragSingles(bFrameDragSingles);//decide whether each single object should get handles |
| 204 |
SdrView::MarkObj( pObj, GetPageView() ); |
| 205 |
showMarkHandles(); |
| 206 |
} |
| 207 |
|
| 208 |
void DrawViewWrapper::setMarkHandleProvider( MarkHandleProvider* pMarkHandleProvider ) |
| 209 |
{ |
| 210 |
m_pMarkHandleProvider = pMarkHandleProvider; |
| 211 |
} |
| 212 |
|
| 213 |
void DrawViewWrapper::CompleteRedraw(OutputDevice* pOut, const vcl::Region& rReg, sdr::contact::ViewObjectContactRedirector* /* pRedirector */) |
| 214 |
{ |
| 215 |
Color aFillColor; |
| 216 |
if (const SfxViewShell* pViewShell = SfxViewShell::Current()) |
| 217 |
aFillColor = pViewShell->GetColorConfigColor(svtools::DOCCOLOR); |
| 218 |
else |
| 219 |
{ |
| 220 |
svtools::ColorConfig aColorConfig; |
| 221 |
aFillColor = aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor; |
| 222 |
} |
| 223 |
SetApplicationBackgroundColor(aFillColor); |
| 224 |
|
| 225 |
SdrOutliner& rOutliner = GetModel().GetDrawOutliner(); |
| 226 |
Color aOldBackColor = rOutliner.GetBackgroundColor(); |
| 227 |
rOutliner.SetBackgroundColor(aFillColor); |
| 228 |
|
| 229 |
E3dView::CompleteRedraw( pOut, rReg ); |
| 230 |
|
| 231 |
rOutliner.SetBackgroundColor(aOldBackColor); |
| 232 |
} |
| 233 |
|
| 234 |
SdrObject* DrawViewWrapper::getSelectedObject() const |
| 235 |
{ |
| 236 |
SdrObject* pObj(nullptr); |
| 237 |
const SdrMarkList& rMarkList = GetMarkedObjectList(); |
| 238 |
if(rMarkList.GetMarkCount() == 1) |
| 239 |
{ |
| 240 |
SdrMark* pMark = rMarkList.GetMark(0); |
| 241 |
pObj = pMark->GetMarkedSdrObj(); |
| 242 |
} |
| 243 |
return pObj; |
| 244 |
} |
| 245 |
|
| 246 |
SdrObject* DrawViewWrapper::getTextEditObject() const |
| 247 |
{ |
| 248 |
SdrObject* pObj = getSelectedObject(); |
| 249 |
SdrObject* pTextObj = nullptr; |
| 250 |
if( pObj && pObj->HasTextEdit()) |
| 251 |
pTextObj = pObj; |
| 252 |
return pTextObj; |
| 253 |
} |
| 254 |
|
| 255 |
void DrawViewWrapper::attachParentReferenceDevice( const uno::Reference< frame::XModel > & xChartModel ) |
| 256 |
{ |
| 257 |
OutputDevice * pParentRefDev( lcl_GetParentRefDevice( xChartModel )); |
| 258 |
SdrOutliner * pOutliner( getOutliner()); |
| 259 |
if( pParentRefDev && pOutliner ) |
| 260 |
{ |
| 261 |
pOutliner->SetRefDevice( pParentRefDev ); |
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
SdrOutliner* DrawViewWrapper::getOutliner() const |
| 266 |
{ |
| 267 |
return m_apOutliner.get(); |
| 268 |
} |
| 269 |
|
| 270 |
SfxItemSet DrawViewWrapper::getPositionAndSizeItemSetFromMarkedObject() const |
| 271 |
{ |
| 272 |
SvtSysLocale aSysLocale; |
| 273 |
MeasurementSystem eSys = aSysLocale.GetLocaleData().getMeasurementSystemEnum(); |
| 274 |
sal_uInt16 nAttrMetric; |
| 275 |
if( eSys == MeasurementSystem::Metric ) |
| 276 |
nAttrMetric = officecfg::Office::Calc::Layout::Other::MeasureUnit::Metric::get(); |
| 277 |
else |
| 278 |
nAttrMetric = officecfg::Office::Calc::Layout::Other::MeasureUnit::NonMetric::get(); |
| 279 |
|
| 280 |
SfxItemSet aFullSet( |
| 281 |
GetModel().GetItemPool(), |
| 282 |
svl::Items< |
| 283 |
SDRATTR_CORNER_RADIUS, SDRATTR_CORNER_RADIUS, |
| 284 |
SID_ATTR_TRANSFORM_POS_X, SID_ATTR_TRANSFORM_ANGLE, |
| 285 |
SID_ATTR_TRANSFORM_PROTECT_POS, SID_ATTR_TRANSFORM_AUTOHEIGHT, |
| 286 |
SID_ATTR_METRIC, SID_ATTR_METRIC>); |
| 287 |
SfxItemSet aGeoSet( E3dView::GetGeoAttrFromMarked() ); |
| 288 |
aFullSet.Put( aGeoSet ); |
| 289 |
aFullSet.Put( SfxUInt16Item(SID_ATTR_METRIC, nAttrMetric) ); |
| 290 |
return aFullSet; |
| 291 |
} |
| 292 |
|
| 293 |
SdrObject* DrawViewWrapper::getNamedSdrObject( const OUString& rName ) const |
| 294 |
{ |
| 295 |
if(rName.isEmpty()) |
| 296 |
return nullptr; |
| 297 |
SdrPageView* pSdrPageView = GetPageView(); |
| 298 |
if( pSdrPageView ) |
| 299 |
{ |
| 300 |
return DrawModelWrapper::getNamedSdrObject( rName, pSdrPageView->GetObjList() ); |
| 301 |
} |
| 302 |
return nullptr; |
| 303 |
} |
| 304 |
|
| 305 |
bool DrawViewWrapper::IsObjectHit( SdrObject const * pObj, const Point& rPnt ) |
| 306 |
{ |
| 307 |
if(pObj) |
| 308 |
{ |
| 309 |
tools::Rectangle aRect(pObj->GetCurrentBoundRect()); |
| 310 |
return aRect.Contains(rPnt); |
| 311 |
} |
| 312 |
return false; |
| 313 |
} |
| 314 |
|
| 315 |
void DrawViewWrapper::Notify(SfxBroadcaster& rBC, const SfxHint& rHint) |
| 316 |
{ |
| 317 |
//prevent wrong reselection of objects |
| 318 |
SdrModel& rSdrModel = GetModel(); |
| 319 |
if (rSdrModel.isLocked()) |
| 320 |
return; |
| 321 |
|
| 322 |
const SdrHint* pSdrHint = ( rHint.GetId() == SfxHintId::ThisIsAnSdrHint ? static_cast<const SdrHint*>(&rHint) : nullptr ); |
| 323 |
|
| 324 |
//#i76053# do nothing when only changes on the hidden draw page were made ( e.g. when the symbols for the dialogs are created ) |
| 325 |
SdrPageView* pSdrPageView = GetPageView(); |
| 326 |
if( pSdrHint && pSdrPageView ) |
| 327 |
{ |
| 328 |
if( pSdrPageView->GetPage() != pSdrHint->GetPage() ) |
| 329 |
return; |
| 330 |
} |
| 331 |
|
| 332 |
E3dView::Notify(rBC, rHint); |
| 333 |
|
| 334 |
if( pSdrHint == nullptr ) |
| 335 |
return; |
| 336 |
|
| 337 |
SdrHintKind eKind = pSdrHint->GetKind(); |
| 338 |
if( eKind == SdrHintKind::BeginEdit ) |
| 339 |
{ |
| 340 |
// #i79965# remember map mode |
| 341 |
OSL_ASSERT( ! m_bRestoreMapMode ); |
| 342 |
OutputDevice* pOutDev = GetFirstOutputDevice(); |
| 343 |
if( pOutDev ) |
| 344 |
{ |
| 345 |
m_aMapModeToRestore = pOutDev->GetMapMode(); |
| 346 |
m_bRestoreMapMode = true; |
| 347 |
} |
| 348 |
} |
| 349 |
else if( eKind == SdrHintKind::EndEdit ) |
| 350 |
{ |
| 351 |
// #i79965# scroll back view when ending text edit |
| 352 |
OSL_ASSERT( m_bRestoreMapMode ); |
| 353 |
if( m_bRestoreMapMode ) |
| 354 |
{ |
| 355 |
OutputDevice* pOutDev = GetFirstOutputDevice(); |
| 356 |
if( pOutDev ) |
| 357 |
{ |
| 358 |
pOutDev->SetMapMode( m_aMapModeToRestore ); |
| 359 |
m_bRestoreMapMode = false; |
| 360 |
} |
| 361 |
} |
| 362 |
} |
| 363 |
} |
| 364 |
|
| 365 |
SdrObject* DrawViewWrapper::getSdrObject( const uno::Reference< |
| 366 |
drawing::XShape >& xShape ) |
| 367 |
{ |
| 368 |
SdrObject* pRet = nullptr; |
| 369 |
uno::Reference< lang::XTypeProvider > xTypeProvider( xShape, uno::UNO_QUERY ); |
| 370 |
if(xTypeProvider.is()) |
| 371 |
{ |
| 372 |
pRet = SdrObject::getSdrObjectFromXShape(xShape); |
| 373 |
} |
| 374 |
return pRet; |
| 375 |
} |
| 376 |
|
| 377 |
} //namespace chart |
| 378 |
|
| 379 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |