Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / appl / appbas.cxx
blob0018663e83e8d93c20bdba1797eba86d099f447a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <com/sun/star/frame/XDesktop.hpp>
30 #include <com/sun/star/script/XLibraryContainer.hpp>
31 #include <com/sun/star/uno/Reference.h>
32 #include <basic/basrdll.hxx>
33 #include <officecfg/Office/Common.hxx>
34 #include <svl/macitem.hxx>
35 #include <basic/sbxfac.hxx>
36 #include <basic/sbx.hxx>
37 #include <vcl/gradient.hxx>
38 #include <svl/rectitem.hxx>
39 #include <svl/intitem.hxx>
40 #include <svl/eitem.hxx>
41 #include <basic/sbmod.hxx>
42 #include <svl/whiter.hxx>
43 #include <basic/sbmeth.hxx>
44 #include <basic/sbstar.hxx>
45 #include <vcl/wrkwin.hxx>
46 #include <vcl/msgbox.hxx>
47 #include <basic/sbuno.hxx>
48 #include <svtools/sfxecode.hxx>
49 #include <svtools/ehdl.hxx>
51 #include <unotools/pathoptions.hxx>
52 #include <unotools/useroptions.hxx>
53 #include <unotools/bootstrap.hxx>
55 #include <sfx2/appuno.hxx>
56 #include <sfx2/module.hxx>
57 #include "arrdecl.hxx"
58 #include <sfx2/app.hxx>
59 #include "sfxtypes.hxx"
60 #include "sfx2/sfxresid.hxx"
61 #include <sfx2/msg.hxx>
62 #include <sfx2/msgpool.hxx>
63 #include <sfx2/progress.hxx>
64 #include <sfx2/objsh.hxx>
65 #include <sfx2/objitem.hxx>
66 #include <sfx2/viewfrm.hxx>
67 #include <sfx2/viewsh.hxx>
68 #include <sfx2/dispatch.hxx>
69 #include "sfx2/tplpitem.hxx"
70 #include "sfx2/minfitem.hxx"
71 #include "app.hrc"
72 #include <sfx2/evntconf.hxx>
73 #include <sfx2/request.hxx>
74 #include <sfx2/dinfdlg.hxx>
75 #include "appdata.hxx"
76 #include "appbas.hxx"
77 #include "sfx2/sfxhelp.hxx"
78 #include "sfx2/basmgr.hxx"
79 #include "sorgitm.hxx"
80 #include "appbaslib.hxx"
81 #include <basic/basicmanagerrepository.hxx>
83 #define ITEMID_SEARCH SID_SEARCH_ITEM
85 #include <svl/srchitem.hxx>
86 #include <osl/socket.hxx>
88 #if defined(LIBO_MERGELIBS) || defined(IOS)
89 /* Avoid clash with the ones from svx/source/form/typemap.cxx */
90 #define aSfxBoolItem_Impl sfx2_source_appl_appbas_aSfxBoolItem_Impl
91 #ifdef IOS
92 #define aSfxInt16Item_Impl sfx2_source_appl_appbas_aSfxInt16Item_Impl
93 #endif
94 #define aSfxStringItem_Impl sfx2_source_appl_appbas_aSfxStringItem_Impl
95 #define aSfxUInt16Item_Impl sfx2_source_appl_appbas_aSfxUInt16Item_Impl
96 #define aSfxUInt32Item_Impl sfx2_source_appl_appbas_aSfxUInt32Item_Impl
97 #define aSfxVoidItem_Impl sfx2_source_appl_appbas_aSfxVoidtem_Impl
98 #endif
100 #define SFX_TYPEMAP
101 #define Selection
102 #include "sfxslots.hxx"
104 #if defined(LIBO_MERGELIBS) || defined(IOS)
105 #undef aSfxBoolItem_Impl
106 #ifdef IOS
107 #undef aSfxInt16Item_Impl
108 #endif
109 #undef aSfxStringItem_Impl
110 #undef aSfxUInt16Item_Impl
111 #undef aSfxUInt32Item_Impl
112 #undef aSfxVoidItem_Impl
113 #endif
115 using namespace ::com::sun::star;
116 using namespace ::com::sun::star::uno;
117 using namespace ::com::sun::star::frame;
118 using namespace ::com::sun::star::script;
120 using ::basic::BasicManagerRepository;
122 //=========================================================================
123 sal_uInt16 SfxApplication::SaveBasicManager() const
125 return 0;
128 //--------------------------------------------------------------------
129 sal_uInt16 SfxApplication::SaveBasicAndDialogContainer() const
131 if ( pAppData_Impl->pBasicManager->isValid() )
132 pAppData_Impl->pBasicManager->storeAllLibraries();
133 return 0;
136 //--------------------------------------------------------------------
138 SbxVariable* MakeVariable( StarBASIC *pBas, SbxObject *pObject,
139 const char *pName, sal_uInt32 nSID, SbxDataType eType, SbxClassType eClassType )
141 #ifdef DISABLE_SCRIPTING
142 (void) pBas;
143 (void) pObject;
144 (void) pName;
145 (void) nSID;
146 (void) eType;
147 (void) eClassType;
148 return 0;
149 #else
150 SbxVariable *pVar = pBas->Make( String::CreateFromAscii(pName), eClassType, eType ); //SbxCLASS_PROPERTY
151 pVar->SetUserData( nSID );
152 pVar->SetFlag( SBX_DONTSTORE );
153 pObject->StartListening( pVar->GetBroadcaster() );
154 return pVar;
155 #endif
158 //--------------------------------------------------------------------
160 BasicManager* SfxApplication::GetBasicManager()
162 #ifdef DISABLE_SCRIPTING
163 return 0;
164 #else
165 return BasicManagerRepository::getApplicationBasicManager( true );
166 #endif
169 //--------------------------------------------------------------------
171 Reference< XLibraryContainer > SfxApplication::GetDialogContainer()
173 #ifdef DISABLE_SCRIPTING
174 Reference< XLibraryContainer > dummy;
175 return dummy;
176 #else
177 if ( !pAppData_Impl->pBasicManager->isValid() )
178 GetBasicManager();
179 return pAppData_Impl->pBasicManager->getLibraryContainer( SfxBasicManagerHolder::DIALOGS );
180 #endif
183 //--------------------------------------------------------------------
185 Reference< XLibraryContainer > SfxApplication::GetBasicContainer()
187 #ifdef DISABLE_SCRIPTING
188 Reference< XLibraryContainer > dummy;
189 return dummy;
190 #else
191 if ( !pAppData_Impl->pBasicManager->isValid() )
192 GetBasicManager();
193 return pAppData_Impl->pBasicManager->getLibraryContainer( SfxBasicManagerHolder::SCRIPTS );
194 #endif
197 //--------------------------------------------------------------------
199 StarBASIC* SfxApplication::GetBasic()
201 #ifdef DISABLE_SCRIPTING
202 return 0;
203 #else
204 return GetBasicManager()->GetLib(0);
205 #endif
208 //-------------------------------------------------------------------------
209 void SfxApplication::PropExec_Impl( SfxRequest &rReq )
211 #ifdef DISABLE_SCRIPTING
212 (void) rReq;
213 #else
214 rReq.GetArgs();
215 sal_uInt16 nSID = rReq.GetSlot();
216 switch ( nSID )
218 case SID_CREATE_BASICOBJECT:
220 SFX_REQUEST_ARG(rReq, pItem, SfxStringItem, nSID, sal_False);
221 if ( pItem )
223 SbxObject* pObject = SbxBase::CreateObject( pItem->GetValue() );
224 pObject->AddRef();
225 rReq.Done();
227 break;
230 case SID_DELETE_BASICOBJECT:
232 break;
235 case SID_ATTR_UNDO_COUNT:
237 SFX_REQUEST_ARG(rReq, pCountItem, SfxUInt16Item, nSID, sal_False);
238 boost::shared_ptr< comphelper::ConfigurationChanges > batch(
239 comphelper::ConfigurationChanges::create());
240 officecfg::Office::Common::Undo::Steps::set(
241 pCountItem->GetValue(), batch);
242 batch->commit();
243 break;
246 case SID_WIN_VISIBLE:
248 break;
251 case SID_STATUSBARTEXT:
253 SFX_REQUEST_ARG(rReq, pStringItem, SfxStringItem, nSID, sal_False);
254 String aText = pStringItem->GetValue();
255 if ( aText.Len() )
256 GetpApp()->ShowStatusText( aText );
257 else
258 GetpApp()->HideStatusText();
259 break;
262 case SID_OFFICE_PRIVATE_USE:
263 case SID_OFFICE_COMMERCIAL_USE:
265 DBG_ASSERT( sal_False, "SfxApplication::PropExec_Impl()\nSID_OFFICE_PRIVATE_USE & SID_OFFICE_COMMERCIAL_USE are obsolete!\n" );
266 break;
269 case SID_OFFICE_CUSTOMERNUMBER:
271 SFX_REQUEST_ARG(rReq, pStringItem, SfxStringItem, nSID, sal_False);
273 if ( pStringItem )
274 SvtUserOptions().SetCustomerNumber( pStringItem->GetValue() );
275 break;
278 #endif
281 //-------------------------------------------------------------------------
282 void SfxApplication::PropState_Impl( SfxItemSet &rSet )
284 #ifdef DISABLE_SCRIPTING
285 (void) rSet;
286 #else
287 SfxWhichIter aIter(rSet);
288 for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
290 switch ( nSID )
292 case SID_PROGNAME:
293 rSet.Put( SfxStringItem( SID_PROGNAME, GetName() ) );
294 break;
296 case SID_ACTIVEDOCUMENT:
297 rSet.Put( SfxObjectItem( SID_ACTIVEDOCUMENT, SfxObjectShell::Current() ) );
298 break;
300 case SID_APPLICATION:
301 rSet.Put( SfxObjectItem( SID_APPLICATION, this ) );
302 break;
304 case SID_PROGFILENAME:
305 rSet.Put( SfxStringItem( SID_PROGFILENAME, Application::GetAppFileName() ) );
306 break;
308 case SID_ATTR_UNDO_COUNT:
309 rSet.Put(
310 SfxUInt16Item(
311 SID_ATTR_UNDO_COUNT,
312 officecfg::Office::Common::Undo::Steps::get()));
313 break;
315 case SID_UPDATE_VERSION:
316 rSet.Put( SfxUInt32Item( SID_UPDATE_VERSION, SUPD ) );
317 break;
319 case SID_OFFICE_CUSTOMERNUMBER:
321 rSet.Put( SfxStringItem( nSID, SvtUserOptions().GetCustomerNumber() ) );
322 break;
326 #endif
329 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */