xref: /core/sfx2/source/appl/appbas.cxx (revision 663fd3d6)
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 #include <config_options.h>
22 
23 #include <sal/config.h>
24 
25 #include <cassert>
26 
27 #include <com/sun/star/script/XLibraryContainer.hpp>
28 #include <basic/basrdll.hxx>
29 #include <officecfg/Office/Common.hxx>
30 #include <svl/macitem.hxx>
31 #include <basic/sbxfac.hxx>
32 #include <basic/sbx.hxx>
33 #include <vcl/gradient.hxx>
34 #include <svl/rectitem.hxx>
35 #include <svl/intitem.hxx>
36 #include <svl/eitem.hxx>
37 #include <basic/sbmod.hxx>
38 #include <svl/whiter.hxx>
39 #include <basic/sbmeth.hxx>
40 #include <basic/sbstar.hxx>
41 #include <vcl/wrkwin.hxx>
42 #include <basic/sbuno.hxx>
43 #include <svtools/sfxecode.hxx>
44 #include <svtools/ehdl.hxx>
45 
46 #include <sfx2/dinfdlg.hxx>
47 #include <sfx2/module.hxx>
48 #include <arrdecl.hxx>
49 #include <sfx2/app.hxx>
50 #include <sfxtypes.hxx>
51 #include <sfx2/msg.hxx>
52 #include <sfx2/msgpool.hxx>
53 #include <sfx2/progress.hxx>
54 #include <sfx2/objsh.hxx>
55 #include <sfx2/objitem.hxx>
56 #include <sfx2/viewfrm.hxx>
57 #include <sfx2/viewsh.hxx>
58 #include <sfx2/dispatch.hxx>
59 #include <sfx2/tplpitem.hxx>
60 #include <sfx2/minfitem.hxx>
61 #include <sfx2/evntconf.hxx>
62 #include <sfx2/request.hxx>
63 #include <appdata.hxx>
64 #include <sfx2/sfxhelp.hxx>
65 #include <basic/basmgr.hxx>
66 #include <unotools/configmgr.hxx>
67 #include <sorgitm.hxx>
68 #include <appbaslib.hxx>
69 #include <basic/basicmanagerrepository.hxx>
70 
71 #include <svl/srchitem.hxx>
72 #include <osl/socket.hxx>
73 
74 #define SFX_TYPEMAP
75 #include <sfxslots.hxx>
76 
77 using namespace ::com::sun::star;
78 using namespace ::com::sun::star::uno;
79 using namespace ::com::sun::star::script;
80 
81 using ::basic::BasicManagerRepository;
82 
83 
84 void SfxApplication::SaveBasicAndDialogContainer() const
85 {
86     if ( pImpl->pBasicManager->isValid() )
87         pImpl->pBasicManager->storeAllLibraries();
88 }
89 
90 BasicManager* SfxApplication::GetBasicManager()
91 {
92 #if !HAVE_FEATURE_SCRIPTING
93     return 0;
94 #else
95     if (utl::ConfigManager::IsFuzzing())
96         return nullptr;
97     return BasicManagerRepository::getApplicationBasicManager();
98 #endif
99 }
100 
101 XLibraryContainer * SfxApplication::GetDialogContainer()
102 {
103 #if !HAVE_FEATURE_SCRIPTING
104     return NULL;
105 #else
106     if (utl::ConfigManager::IsFuzzing())
107         return nullptr;
108     if ( !pImpl->pBasicManager->isValid() )
109         GetBasicManager();
110     return pImpl->pBasicManager->getLibraryContainer( SfxBasicManagerHolder::DIALOGS );
111 #endif
112 }
113 
114 
115 XLibraryContainer * SfxApplication::GetBasicContainer()
116 {
117 #if !HAVE_FEATURE_SCRIPTING
118     return NULL;
119 #else
120     if (utl::ConfigManager::IsFuzzing())
121         return nullptr;
122     if ( !pImpl->pBasicManager->isValid() )
123         GetBasicManager();
124     return pImpl->pBasicManager->getLibraryContainer( SfxBasicManagerHolder::SCRIPTS );
125 #endif
126 }
127 
128 StarBASIC* SfxApplication::GetBasic()
129 {
130 #if !HAVE_FEATURE_SCRIPTING
131     return 0;
132 #else
133     if (utl::ConfigManager::IsFuzzing())
134         return nullptr;
135     return GetBasicManager()->GetLib(0);
136 #endif
137 }
138 
139 void SfxApplication::PropExec_Impl( SfxRequest const &rReq )
140 {
141     sal_uInt16 nSID = rReq.GetSlot();
142     switch ( nSID )
143     {
144         case SID_ATTR_UNDO_COUNT:
145         {
146             if (const SfxUInt16Item* pCountItem = rReq.GetArg<SfxUInt16Item>(nSID))
147             {
148                 std::shared_ptr< comphelper::ConfigurationChanges > batch(
149                     comphelper::ConfigurationChanges::create());
150                 officecfg::Office::Common::Undo::Steps::set(
151                     pCountItem->GetValue(), batch);
152                 batch->commit();
153             }
154             break;
155         }
156 
157         default:
158             assert(false);
159     }
160 }
161 
162 void SfxApplication::PropState_Impl( SfxItemSet &rSet )
163 {
164     SfxWhichIter aIter(rSet);
165     for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
166     {
167         switch ( nSID )
168         {
169             case SID_ATTR_UNDO_COUNT:
170                 rSet.Put(
171                     SfxUInt16Item(
172                         SID_ATTR_UNDO_COUNT,
173                         officecfg::Office::Common::Undo::Steps::get()));
174                 break;
175 
176             default:
177                 assert(false);
178         }
179     }
180 }
181 
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
183