LibreOffice Module sd (master) 1
viewoverlaymanager.cxx
Go to the documentation of this file.
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 <sal/config.h>
21
22#include <sfx2/viewfrm.hxx>
23#include <sfx2/bindings.hxx>
24#include <sfx2/dispatch.hxx>
25
26#include <vcl/help.hxx>
27#include <vcl/lazydelete.hxx>
28#include <vcl/ptrstyle.hxx>
29#include <vcl/svapp.hxx>
30
31#include <svx/sdrpagewindow.hxx>
35#include <svx/svxids.hrc>
36#include <svx/svdpagv.hxx>
37
39
40
41#include <DrawDocShell.hxx>
42#include <strings.hrc>
43#include <bitmaps.hlst>
44#include <sdresid.hxx>
45#include <EventMultiplexer.hxx>
46#include <View.hxx>
47#include <ViewShellBase.hxx>
48#include <ViewShell.hxx>
49#include <sdpage.hxx>
50#include <smarttag.hxx>
51
52using namespace ::com::sun::star::uno;
53
54namespace sd {
55
56namespace {
57
58class ImageButtonHdl;
59
60}
61
62const sal_uInt16 gButtonSlots[] = { SID_INSERT_TABLE, SID_INSERT_DIAGRAM, SID_INSERT_GRAPHIC, SID_INSERT_AVMEDIA };
63const TranslateId gButtonToolTips[] = { STR_INSERT_TABLE, STR_INSERT_CHART, STR_INSERT_PICTURE, STR_INSERT_MOVIE };
64
65constexpr rtl::OUStringConstExpr aSmallPlaceHolders[] =
66{
67 BMP_PLACEHOLDER_TABLE_SMALL,
68 BMP_PLACEHOLDER_CHART_SMALL,
69 BMP_PLACEHOLDER_IMAGE_SMALL,
70 BMP_PLACEHOLDER_MOVIE_SMALL,
71 BMP_PLACEHOLDER_TABLE_SMALL_HOVER,
72 BMP_PLACEHOLDER_CHART_SMALL_HOVER,
73 BMP_PLACEHOLDER_IMAGE_SMALL_HOVER,
74 BMP_PLACEHOLDER_MOVIE_SMALL_HOVER
75};
76
77constexpr rtl::OUStringConstExpr aBigPlaceHolders[] =
78{
79 BMP_PLACEHOLDER_TABLE_LARGE,
80 BMP_PLACEHOLDER_CHART_LARGE,
81 BMP_PLACEHOLDER_IMAGE_LARGE,
82 BMP_PLACEHOLDER_MOVIE_LARGE,
83 BMP_PLACEHOLDER_TABLE_LARGE_HOVER,
84 BMP_PLACEHOLDER_CHART_LARGE_HOVER,
85 BMP_PLACEHOLDER_IMAGE_LARGE_HOVER,
86 BMP_PLACEHOLDER_MOVIE_LARGE_HOVER
87};
88
89static BitmapEx* getButtonImage( int index, bool large )
90{
93
95
96 if( !gSmallButtonImages[0].get() )
97 {
98 for (size_t i = 0; i < SAL_N_ELEMENTS(aSmallPlaceHolders); i++ )
99 {
100 gSmallButtonImages[i].set(OUString(aSmallPlaceHolders[i]));
101 gLargeButtonImages[i].set(OUString(aBigPlaceHolders[i]));
102 }
103 }
104
105 if( large )
106 {
107 return gLargeButtonImages[index].get();
108 }
109 else
110 {
111 return gSmallButtonImages[index].get();
112 }
113}
114
115const sal_uInt32 SMART_TAG_HDL_NUM = SAL_MAX_UINT32;
116
117namespace {
118
119class ChangePlaceholderTag : public SmartTag
120{
121 friend class ImageButtonHdl;
122public:
123 ChangePlaceholderTag( ::sd::View& rView, SdrObject& rPlaceholderObj );
124
126 virtual bool MouseButtonDown( const MouseEvent&, SmartHdl& ) override;
127
129 virtual bool KeyInput( const KeyEvent& rKEvt ) override;
130
131 BitmapEx createOverlayImage( int nHighlight );
132
133protected:
134 virtual void addCustomHandles( SdrHdlList& rHandlerList ) override;
135
136private:
138};
139
140class ImageButtonHdl : public SmartHdl
141{
142public:
143 ImageButtonHdl( const SmartTagReference& xTag, /* sal_uInt16 nSID, const Image& rImage, const Image& rImageMO, */ const Point& rPnt );
144 virtual ~ImageButtonHdl() override;
145 virtual void CreateB2dIAObject() override;
146 virtual bool IsFocusHdl() const override;
147 virtual PointerStyle GetPointer() const override;
148
149 virtual void onMouseEnter(const MouseEvent& rMEvt) override;
150 virtual void onHelpRequest() override;
151 virtual void onMouseLeave() override;
152
153 int getHighlightId() const { return mnHighlightId; }
154
155 void ShowTip();
156 static void HideTip();
157
158private:
159 rtl::Reference< ChangePlaceholderTag > mxChangePlaceholderTag;
160
161 int mnHighlightId;
162 Size maImageSize;
163};
164
165}
166
167ImageButtonHdl::ImageButtonHdl( const SmartTagReference& xTag /*, sal_uInt16 nSID, const Image& rImage, const Image& rImageMO*/, const Point& rPnt )
168: SmartHdl( xTag, rPnt, SdrHdlKind::SmartTag )
169, mxChangePlaceholderTag( dynamic_cast< ChangePlaceholderTag* >( xTag.get() ) )
170, mnHighlightId( -1 )
171, maImageSize( 42, 42 )
172{
173}
174
175ImageButtonHdl::~ImageButtonHdl()
176{
177 HideTip();
178}
179
180void ImageButtonHdl::HideTip()
181{
183}
184
185void ImageButtonHdl::ShowTip()
186{
187 if (!pHdlList || !pHdlList->GetView() || mnHighlightId == -1)
188 return;
189
190 OutputDevice* pDev = pHdlList->GetView()->GetFirstOutputDevice();
191 if( pDev == nullptr )
193
194 OUString aHelpText(SdResId(gButtonToolTips[mnHighlightId]));
195 Point aHelpPos(pDev->LogicToPixel(GetPos()));
196 if (mnHighlightId == 1)
197 aHelpPos.Move(maImageSize.Width(), 0);
198 else if (mnHighlightId == 2)
199 aHelpPos.Move(0, maImageSize.Height());
200 else if (mnHighlightId == 3)
201 aHelpPos.Move(maImageSize.Width(), maImageSize.Height());
202 ::tools::Rectangle aLogicPix(aHelpPos, maImageSize);
203 vcl::Window* pWindow = pHdlList->GetView()->GetFirstOutputDevice()->GetOwnerWindow();
204 ::tools::Rectangle aScreenRect(pWindow->OutputToScreenPixel(aLogicPix.TopLeft()),
205 pWindow->OutputToScreenPixel(aLogicPix.BottomRight()));
206 Help::ShowQuickHelp(pWindow, aScreenRect, aHelpText);
207}
208
209void ImageButtonHdl::onHelpRequest()
210{
211 ShowTip();
212}
213
214void ImageButtonHdl::onMouseEnter(const MouseEvent& rMEvt)
215{
216 if( !(pHdlList && pHdlList->GetView()))
217 return;
218
219 int nHighlightId = 0;
220 OutputDevice* pDev = pHdlList->GetView()->GetFirstOutputDevice();
221 if( pDev == nullptr )
223
224 Point aMDPos( rMEvt.GetPosPixel() );
225 aMDPos -= pDev->LogicToPixel( GetPos() );
226
227 nHighlightId += aMDPos.X() > maImageSize.Width() ? 1 : 0;
228 nHighlightId += aMDPos.Y() > maImageSize.Height() ? 2 : 0;
229
230 if( mnHighlightId != nHighlightId )
231 {
232 HideTip();
233
234 mnHighlightId = nHighlightId;
235
236 ShowTip();
237
238 Touch();
239 }
240}
241
242void ImageButtonHdl::onMouseLeave()
243{
244 mnHighlightId = -1;
245 HideTip();
246 Touch();
247}
248
249void ImageButtonHdl::CreateB2dIAObject()
250{
251 // first throw away old one
252 GetRidOfIAObject();
253
254 const Point aTagPos( GetPos() );
255 basegfx::B2DPoint aPosition( aTagPos.X(), aTagPos.Y() );
256
257 BitmapEx aBitmapEx( mxChangePlaceholderTag->createOverlayImage( mnHighlightId ) ); // maImageMO.GetBitmapEx() : maImage.GetBitmapEx() );
258 maImageSize = aBitmapEx.GetSizePixel();
259 maImageSize.setWidth( maImageSize.Width() >> 1 );
260 maImageSize.setHeight( maImageSize.Height() >> 1 );
261
262 if(!pHdlList)
263 return;
264
265 SdrMarkView* pView = pHdlList->GetView();
266
267 if(!pView || pView->areMarkHandlesHidden())
268 return;
269
270 SdrPageView* pPageView = pView->GetSdrPageView();
271
272 if(!pPageView)
273 return;
274
275 for(sal_uInt32 b = 0; b < pPageView->PageWindowCount(); b++)
276 {
277 const SdrPageWindow& rPageWindow = *pPageView->GetPageWindow(b);
278
279 SdrPaintWindow& rPaintWindow = rPageWindow.GetPaintWindow();
281 if(rPaintWindow.OutputToWindow() && xManager.is() )
282 {
283 std::unique_ptr<sdr::overlay::OverlayObject> pOverlayObject(
284 new sdr::overlay::OverlayBitmapEx( aPosition, aBitmapEx, 0, 0 ));
285
286 // OVERLAYMANAGER
287 insertNewlyCreatedOverlayObjectForSdrHdl(
288 std::move(pOverlayObject),
289 rPageWindow.GetObjectContact(),
290 *xManager);
291 }
292 }
293}
294
295bool ImageButtonHdl::IsFocusHdl() const
296{
297 return false;
298}
299
300PointerStyle ImageButtonHdl::GetPointer() const
301{
302 return PointerStyle::Arrow;
303}
304
305ChangePlaceholderTag::ChangePlaceholderTag( ::sd::View& rView, SdrObject& rPlaceholderObj )
306: SmartTag( rView )
307, mxPlaceholderObj( &rPlaceholderObj )
308{
309}
310
312bool ChangePlaceholderTag::MouseButtonDown( const MouseEvent& /*rMEvt*/, SmartHdl& rHdl )
313{
314 int nHighlightId = static_cast< ImageButtonHdl& >(rHdl).getHighlightId();
315 if( nHighlightId >= 0 )
316 {
317 sal_uInt16 nSID = gButtonSlots[nHighlightId];
318
319 if( auto pPlaceholder = mxPlaceholderObj.get() )
320 {
321 // mark placeholder if it is not currently marked (or if also others are marked)
322 if( !mrView.IsObjMarked( pPlaceholder.get() ) || (mrView.GetMarkedObjectList().GetMarkCount() != 1) )
323 {
324 SdrPageView* pPV = mrView.GetSdrPageView();
325 mrView.UnmarkAllObj(pPV );
326 mrView.MarkObj(pPlaceholder.get(), pPV);
327 }
328 }
329
330 mrView.GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( nSID, SfxCallMode::ASYNCHRON);
331 }
332 return false;
333}
334
336bool ChangePlaceholderTag::KeyInput( const KeyEvent& rKEvt )
337{
338 sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
339 switch( nCode )
340 {
341 case KEY_DOWN:
342 case KEY_UP:
343 case KEY_LEFT:
344 case KEY_RIGHT:
345 case KEY_ESCAPE:
346 case KEY_TAB:
347 case KEY_RETURN:
348 case KEY_SPACE:
349 default:
350 return false;
351 }
352}
353
354BitmapEx ChangePlaceholderTag::createOverlayImage( int nHighlight )
355{
356 BitmapEx aRet;
357 if( auto pPlaceholder = mxPlaceholderObj.get() )
358 {
359 SmartTagReference xThis( this );
360 const ::tools::Rectangle& rSnapRect = pPlaceholder->GetSnapRect();
361
362 OutputDevice* pDev = mrView.GetFirstOutputDevice();
363 if( pDev == nullptr )
365
366 Size aShapeSizePix = pDev->LogicToPixel(rSnapRect.GetSize());
367 ::tools::Long nShapeSizePix = std::min(aShapeSizePix.Width(),aShapeSizePix.Height());
368
369 bool bLarge = nShapeSizePix > 250;
370
371 Size aSize( getButtonImage( 0, bLarge )->GetSizePixel() );
372
373 aRet.Scale(Size(aSize.Width() << 1, aSize.Height() << 1));
374
375 const ::tools::Rectangle aRectSrc( Point( 0, 0 ), aSize );
376
377 aRet = *(getButtonImage((nHighlight == 0) ? 4 : 0, bLarge));
378 aRet.Expand( aSize.Width(), aSize.Height(), true );
379
380 aRet.CopyPixel( ::tools::Rectangle( Point( aSize.Width(), 0 ), aSize ), aRectSrc, getButtonImage((nHighlight == 1) ? 5 : 1, bLarge) );
381 aRet.CopyPixel( ::tools::Rectangle( Point( 0, aSize.Height() ), aSize ), aRectSrc, getButtonImage((nHighlight == 2) ? 6 : 2, bLarge) );
382 aRet.CopyPixel( ::tools::Rectangle( Point( aSize.Width(), aSize.Height() ), aSize ), aRectSrc, getButtonImage((nHighlight == 3) ? 7 : 3, bLarge) );
383 }
384
385 return aRet;
386}
387
388void ChangePlaceholderTag::addCustomHandles( SdrHdlList& rHandlerList )
389{
390 rtl::Reference<SdrObject> pPlaceholder = mxPlaceholderObj.get();
391 if( !pPlaceholder )
392 return;
393
394 SmartTagReference xThis( this );
395 const ::tools::Rectangle& rSnapRect = pPlaceholder->GetSnapRect();
396 const Point aPoint;
397
398 OutputDevice* pDev = mrView.GetFirstOutputDevice();
399 if( pDev == nullptr )
401
402 Size aShapeSizePix = pDev->LogicToPixel(rSnapRect.GetSize());
403 ::tools::Long nShapeSizePix = std::min(aShapeSizePix.Width(),aShapeSizePix.Height());
404 if( 50 > nShapeSizePix )
405 return;
406
407 bool bLarge = nShapeSizePix > 250;
408
409 Size aButtonSize( pDev->PixelToLogic( getButtonImage(0, bLarge )->GetSizePixel()) );
410
411 const int nColumns = 2;
412 const int nRows = 2;
413
414 ::tools::Long all_width = nColumns * aButtonSize.Width();
415 ::tools::Long all_height = nRows * aButtonSize.Height();
416
417 Point aPos( rSnapRect.Center() );
418 aPos.AdjustX( -(all_width >> 1) );
419 aPos.AdjustY( -(all_height >> 1) );
420
421 std::unique_ptr<ImageButtonHdl> pHdl(new ImageButtonHdl( xThis, aPoint ));
422 pHdl->SetObjHdlNum( SMART_TAG_HDL_NUM );
423 pHdl->SetPageView( mrView.GetSdrPageView() );
424
425 pHdl->SetPos( aPos );
426
427 rHandlerList.AddHdl( std::move(pHdl) );
428}
429
430ViewOverlayManager::ViewOverlayManager( ViewShellBase& rViewShellBase )
431: mrBase( rViewShellBase )
432, mnUpdateTagsEvent( nullptr )
433{
434 Link<tools::EventMultiplexerEvent&,void> aLink( LINK(this,ViewOverlayManager,EventMultiplexerListener) );
435 mrBase.GetEventMultiplexer()->AddEventListener(aLink);
436
438}
439
441{
442 Link<tools::EventMultiplexerEvent&,void> aLink( LINK(this,ViewOverlayManager,EventMultiplexerListener) );
443 mrBase.GetEventMultiplexer()->RemoveEventListener( aLink );
444
446 {
448 mnUpdateTagsEvent = nullptr;
449 }
450
451 DisposeTags();
452}
453
455{
456 if (rHint.GetId() == SfxHintId::DocChanged)
457 {
458 UpdateTags();
459 }
460}
461
463{
464 if( !maTagVector.empty() )
465 {
466 UpdateTags();
467 }
468}
469
471{
472 if( !mnUpdateTagsEvent )
474}
475
476IMPL_LINK_NOARG(ViewOverlayManager, UpdateTagsHdl, void*, void)
477{
478 mnUpdateTagsEvent = nullptr;
479 bool bChanges = DisposeTags();
480 bChanges |= CreateTags();
481
482 if( bChanges && mrBase.GetDrawView() )
483 static_cast< ::sd::View* >( mrBase.GetDrawView() )->updateHandles();
484}
485
487{
488 bool bChanges = false;
489
490 std::shared_ptr<ViewShell> aMainShell = mrBase.GetMainViewShell();
491
492 SdPage* pPage = aMainShell ? aMainShell->getCurrentPage() : nullptr;
493
494 if( pPage && !pPage->IsMasterPage() && (pPage->GetPageKind() == PageKind::Standard) )
495 {
496 const std::list< SdrObject* >& rShapes = pPage->GetPresentationShapeList().getList();
497
498 for( SdrObject* pShape : rShapes )
499 {
500 if( pShape->IsEmptyPresObj() && (pShape->GetObjIdentifier() == SdrObjKind::OutlineText) && (mrBase.GetDrawView()->GetTextEditObject() != pShape) )
501 {
502 rtl::Reference< SmartTag > xTag( new ChangePlaceholderTag( *mrBase.GetMainViewShell()->GetView(), *pShape ) );
503 maTagVector.push_back(xTag);
504 bChanges = true;
505 }
506 }
507 }
508
509 return bChanges;
510}
511
513{
514 if( !maTagVector.empty() )
515 {
516 ViewTagVector vec;
517 vec.swap( maTagVector );
518
519 for (auto& rxViewTag : vec)
520 rxViewTag->Dispose();
521 return true;
522 }
523
524 return false;
525}
526
527IMPL_LINK(ViewOverlayManager,EventMultiplexerListener,
528 tools::EventMultiplexerEvent&, rEvent, void)
529{
530 switch (rEvent.meEventId)
531 {
537 UpdateTags();
538 break;
539 default: break;
540 }
541}
542
543}
544
545/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ BeginTextEdit
Text editing in one of the shapes in the MainViewShell has started.
@ ViewAdded
A new ViewShell is being displayed in one of the panes.
@ EndTextEdit
Text editing in one of the shapes in the MainViewShell has ended.
@ MainViewAdded
A new ViewShell has been made the MainViewShell.
@ CurrentPageChanged
The current page has changed.
SlideSorterView & mrView
static OutputDevice * GetDefaultDevice()
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static void RemoveUserEvent(ImplSVEvent *nUserEvent)
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
void Expand(sal_Int32 nDX, sal_Int32 nDY, bool bExpandTransparent=false)
bool CopyPixel(const tools::Rectangle &rRectDst, const tools::Rectangle &rRectSrc, const BitmapEx *pBmpExSrc)
static void HideBalloonAndQuickHelp()
static void ShowQuickHelp(vcl::Window *pParent, const tools::Rectangle &rScreenRect, const OUString &rHelpText, QuickHelpFlags nStyle=QuickHelpFlags::NONE)
const vcl::KeyCode & GetKeyCode() const
const Point & GetPosPixel() const
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
constexpr tools::Long X() const
PageKind GetPageKind() const
Definition: sdpage.hxx:205
sd::ShapeList & GetPresentationShapeList()
Definition: sdpage.hxx:166
void AddHdl(std::unique_ptr< SdrHdl > pHdl)
bool areMarkHandlesHidden() const
SdrTextObj * GetTextEditObject() const
sal_uInt32 PageWindowCount() const
SdrPageWindow * GetPageWindow(sal_uInt32 nIndex) const
rtl::Reference< sdr::overlay::OverlayManager > const & GetOverlayManager() const
SdrPaintWindow & GetPaintWindow() const
const sdr::contact::ObjectContact & GetObjectContact() const
bool IsMasterPage() const
SdrPageView * GetSdrPageView() const
bool OutputToWindow() const
SfxHintId GetId() const
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
constexpr tools::Long Height() const
constexpr tools::Long Width() const
const std::list< SdrObject * > & getList() const
Definition: shapelist.hxx:60
virtual ~ViewOverlayManager() override
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
SfxViewShell descendant that the stacked Draw/Impress shells are based on.
std::shared_ptr< ViewShell > GetMainViewShell() const
Return the main view shell stacked on the called ViewShellBase object.
std::shared_ptr< tools::EventMultiplexer > const & GetEventMultiplexer() const
Return an event multiplexer.
DrawDocShell * GetDocShell() const
virtual SdrView * GetDrawView() const override
std::optional< T > set(Args &&... args)
sal_uInt16 GetCode() const
Point OutputToScreenPixel(const Point &rPos) const
constexpr sal_uInt16 KEY_RETURN
constexpr sal_uInt16 KEY_ESCAPE
constexpr sal_uInt16 KEY_LEFT
constexpr sal_uInt16 KEY_TAB
constexpr sal_uInt16 KEY_UP
constexpr sal_uInt16 KEY_RIGHT
constexpr sal_uInt16 KEY_DOWN
constexpr sal_uInt16 KEY_SPACE
#define SAL_N_ELEMENTS(arr)
int i
index
IMPL_LINK_NOARG(MainSequence, onTimerHdl, Timer *, void)
static BitmapEx * getButtonImage(int index, bool large)
const TranslateId gButtonToolTips[]
const sal_uInt16 gButtonSlots[]
constexpr rtl::OUStringConstExpr aBigPlaceHolders[]
rtl::Reference< SmartTag > SmartTagReference
Definition: smarttag.hxx:87
std::vector< rtl::Reference< SmartTag > > ViewTagVector
IMPL_LINK(SdCharHeightPropertyBox, implMenuSelectHdl, const OUString &, rIdent, void)
constexpr rtl::OUStringConstExpr aSmallPlaceHolders[]
const sal_uInt32 SMART_TAG_HDL_NUM
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
long Long
PointerStyle
@ MouseButtonDown
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
SdrHdlKind
#define SAL_MAX_UINT32