cid#1636693 COPY_INSTEAD_OF_MOVE
[LibreOffice.git] / sfx2 / source / appl / appbas.cxx
blob8929ccf908cf1bea01dbeca8170f5976ac4d4553
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 <config_features.h>
22 #include <sal/config.h>
24 #include <cassert>
26 #include <com/sun/star/script/XLibraryContainer.hpp>
27 #include <officecfg/Office/Common.hxx>
28 #include <svl/intitem.hxx>
29 #include <svl/eitem.hxx>
30 #include <svl/whiter.hxx>
31 #include <svl/voiditem.hxx>
32 #include <basic/sbstar.hxx>
34 #include <sfx2/frame.hxx>
35 #include <sfx2/dinfdlg.hxx>
36 #include <sfx2/app.hxx>
37 #include <sfx2/msg.hxx>
38 #include <sfx2/request.hxx>
39 #include <sfx2/sfxsids.hrc>
40 #include <appdata.hxx>
41 #include <basic/basmgr.hxx>
42 #include <unotools/configmgr.hxx>
43 #include <sorgitm.hxx>
44 #include <appbaslib.hxx>
45 #include <basic/basicmanagerrepository.hxx>
47 #define SFX_TYPEMAP
48 #include <sfxslots.hxx>
50 using namespace ::com::sun::star;
51 using namespace ::com::sun::star::script;
53 using ::basic::BasicManagerRepository;
56 void SfxApplication::SaveBasicAndDialogContainer() const
58 if ( pImpl->pBasicManager->isValid() )
59 pImpl->pBasicManager->storeAllLibraries();
62 BasicManager* SfxApplication::GetBasicManager()
64 #if !HAVE_FEATURE_SCRIPTING
65 return nullptr;
66 #else
67 if (comphelper::IsFuzzing())
68 return nullptr;
69 return BasicManagerRepository::getApplicationBasicManager();
70 #endif
73 XLibraryContainer * SfxApplication::GetDialogContainer()
75 #if !HAVE_FEATURE_SCRIPTING
76 return nullptr;
77 #else
78 if (comphelper::IsFuzzing())
79 return nullptr;
80 if ( !pImpl->pBasicManager->isValid() )
81 GetBasicManager();
82 return pImpl->pBasicManager->getLibraryContainer( SfxBasicManagerHolder::DIALOGS );
83 #endif
87 XLibraryContainer * SfxApplication::GetBasicContainer()
89 #if !HAVE_FEATURE_SCRIPTING
90 return nullptr;
91 #else
92 if (comphelper::IsFuzzing())
93 return nullptr;
94 if ( !pImpl->pBasicManager->isValid() )
95 GetBasicManager();
96 return pImpl->pBasicManager->getLibraryContainer( SfxBasicManagerHolder::SCRIPTS );
97 #endif
100 StarBASIC* SfxApplication::GetBasic()
102 #if !HAVE_FEATURE_SCRIPTING
103 return nullptr;
104 #else
105 if (comphelper::IsFuzzing())
106 return nullptr;
107 return GetBasicManager()->GetLib(0);
108 #endif
111 void SfxApplication::PropExec_Impl( SfxRequest const &rReq )
113 sal_uInt16 nSID = rReq.GetSlot();
114 switch ( nSID )
116 case SID_ATTR_UNDO_COUNT:
118 if (const SfxUInt16Item* pCountItem = rReq.GetArg<SfxUInt16Item>(nSID))
120 std::shared_ptr< comphelper::ConfigurationChanges > batch(
121 comphelper::ConfigurationChanges::create());
122 officecfg::Office::Common::Undo::Steps::set(
123 pCountItem->GetValue(), batch);
124 batch->commit();
126 break;
129 default:
130 assert(false);
134 void SfxApplication::PropState_Impl( SfxItemSet &rSet )
136 SfxWhichIter aIter(rSet);
137 for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
139 switch ( nSID )
141 case SID_ATTR_UNDO_COUNT:
142 rSet.Put(
143 SfxUInt16Item(
144 SID_ATTR_UNDO_COUNT,
145 officecfg::Office::Common::Undo::Steps::get()));
146 break;
148 default:
149 assert(false);
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */