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 <config_features.h>
21 
22 #include <sal/config.h>
23 
24 #include <cassert>
25 
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 <basic/sbstar.hxx>
32 
33 #include <sfx2/frame.hxx>
34 #include <sfx2/dinfdlg.hxx>
35 #include <sfx2/app.hxx>
36 #include <sfx2/msg.hxx>
37 #include <sfx2/request.hxx>
38 #include <sfx2/sfxsids.hrc>
39 #include <appdata.hxx>
40 #include <basic/basmgr.hxx>
41 #include <unotools/configmgr.hxx>
42 #include <sorgitm.hxx>
43 #include <appbaslib.hxx>
44 #include <basic/basicmanagerrepository.hxx>
45 
46 #define SFX_TYPEMAP
47 #include <sfxslots.hxx>
48 
49 using namespace ::com::sun::star;
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::script;
52 
53 using ::basic::BasicManagerRepository;
54 
55 
SaveBasicAndDialogContainer() const56 void SfxApplication::SaveBasicAndDialogContainer() const
57 {
58     if ( pImpl->pBasicManager->isValid() )
59         pImpl->pBasicManager->storeAllLibraries();
60 }
61 
GetBasicManager()62 BasicManager* SfxApplication::GetBasicManager()
63 {
64 #if !HAVE_FEATURE_SCRIPTING
65     return nullptr;
66 #else
67     if (utl::ConfigManager::IsFuzzing())
68         return nullptr;
69     return BasicManagerRepository::getApplicationBasicManager();
70 #endif
71 }
72 
GetDialogContainer()73 XLibraryContainer * SfxApplication::GetDialogContainer()
74 {
75 #if !HAVE_FEATURE_SCRIPTING
76     return nullptr;
77 #else
78     if (utl::ConfigManager::IsFuzzing())
79         return nullptr;
80     if ( !pImpl->pBasicManager->isValid() )
81         GetBasicManager();
82     return pImpl->pBasicManager->getLibraryContainer( SfxBasicManagerHolder::DIALOGS );
83 #endif
84 }
85 
86 
GetBasicContainer()87 XLibraryContainer * SfxApplication::GetBasicContainer()
88 {
89 #if !HAVE_FEATURE_SCRIPTING
90     return nullptr;
91 #else
92     if (utl::ConfigManager::IsFuzzing())
93         return nullptr;
94     if ( !pImpl->pBasicManager->isValid() )
95         GetBasicManager();
96     return pImpl->pBasicManager->getLibraryContainer( SfxBasicManagerHolder::SCRIPTS );
97 #endif
98 }
99 
GetBasic()100 StarBASIC* SfxApplication::GetBasic()
101 {
102 #if !HAVE_FEATURE_SCRIPTING
103     return nullptr;
104 #else
105     if (utl::ConfigManager::IsFuzzing())
106         return nullptr;
107     return GetBasicManager()->GetLib(0);
108 #endif
109 }
110 
PropExec_Impl(SfxRequest const & rReq)111 void SfxApplication::PropExec_Impl( SfxRequest const &rReq )
112 {
113     sal_uInt16 nSID = rReq.GetSlot();
114     switch ( nSID )
115     {
116         case SID_ATTR_UNDO_COUNT:
117         {
118             if (const SfxUInt16Item* pCountItem = rReq.GetArg<SfxUInt16Item>(nSID))
119             {
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();
125             }
126             break;
127         }
128 
129         default:
130             assert(false);
131     }
132 }
133 
PropState_Impl(SfxItemSet & rSet)134 void SfxApplication::PropState_Impl( SfxItemSet &rSet )
135 {
136     SfxWhichIter aIter(rSet);
137     for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
138     {
139         switch ( nSID )
140         {
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;
147 
148             default:
149                 assert(false);
150         }
151     }
152 }
153 
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
155