cid#1607171 Data race condition
[LibreOffice.git] / sd / source / ui / view / GraphicObjectBar.cxx
blobcabd82753878258bdb4f71f5fd0d9e12103fcbaa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <GraphicObjectBar.hxx>
22 #include <sfx2/shell.hxx>
23 #include <svx/svxids.hrc>
24 #include <sfx2/request.hxx>
25 #include <svx/svdograf.hxx>
26 #include <svx/grfflt.hxx>
27 #include <svx/grafctrl.hxx>
29 #include <sfx2/objface.hxx>
31 #include <strings.hrc>
32 #include <DrawDocShell.hxx>
33 #include <ViewShell.hxx>
34 #include <sdresid.hxx>
36 using namespace sd;
37 #define ShellClass_GraphicObjectBar
38 #include <sdslots.hxx>
40 namespace sd {
43 SFX_IMPL_INTERFACE(GraphicObjectBar, SfxShell)
45 void GraphicObjectBar::InitInterface_Impl()
50 GraphicObjectBar::GraphicObjectBar (
51 const ViewShell* pSdViewShell,
52 ::sd::View* pSdView )
53 : SfxShell (pSdViewShell->GetViewShell()),
54 mpView ( pSdView )
56 DrawDocShell* pDocShell = pSdViewShell->GetDocSh();
58 SetPool( &pDocShell->GetPool() );
59 SetUndoManager( pDocShell->GetUndoManager() );
60 SetRepeatTarget( mpView );
61 SetName( u"Graphic objectbar"_ustr);
64 GraphicObjectBar::~GraphicObjectBar()
66 SetRepeatTarget( nullptr );
69 void GraphicObjectBar::GetAttrState( SfxItemSet& rSet )
71 if( mpView )
72 SvxGrafAttrHelper::GetGrafAttrState( rSet, *mpView );
75 void GraphicObjectBar::Execute( SfxRequest& rReq )
77 if( mpView )
79 SvxGrafAttrHelper::ExecuteGrafAttr( rReq, *mpView );
80 Invalidate();
84 void GraphicObjectBar::GetFilterState( SfxItemSet& rSet )
86 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
87 bool bEnable = false;
89 if( rMarkList.GetMarkCount() == 1 )
91 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
93 if( auto pGrafObj = dynamic_cast< SdrGrafObj *>( pObj ) )
94 if( pGrafObj->GetGraphicType() == GraphicType::Bitmap )
95 bEnable = true;
98 if( !bEnable )
99 SvxGraphicFilter::DisableGraphicFilterSlots( rSet );
102 void GraphicObjectBar::ExecuteFilter( SfxRequest const & rReq )
104 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
106 if( rMarkList.GetMarkCount() == 1 )
108 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
110 if( auto pGrafObj = dynamic_cast< SdrGrafObj *>( pObj ) )
111 if( pGrafObj->GetGraphicType() == GraphicType::Bitmap )
113 SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, pGrafObj->GetGraphicObject(),
114 [this, pObj] (GraphicObject aFilterObj) -> void
116 if (SdrPageView* pPageView = mpView->GetSdrPageView())
118 rtl::Reference<SdrGrafObj> pFilteredObj = SdrObject::Clone(static_cast<SdrGrafObj&>(*pObj), pObj->getSdrModelFromSdrObject());
119 OUString aStr = mpView->GetMarkedObjectList().GetMarkDescription() +
120 " " + SdResId(STR_UNDO_GRAFFILTER);
121 mpView->BegUndo( aStr );
122 pFilteredObj->SetGraphicObject( aFilterObj );
123 ::sd::View* const pView = mpView;
124 pView->ReplaceObjectAtView( pObj, *pPageView, pFilteredObj.get() );
125 pView->EndUndo();
128 return;
131 Invalidate();
134 } // end of namespace sd
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */