xref: /AOO41X/main/sfx2/source/appl/appbas.cxx (revision d119d52d53d0b2180f2ae51341d882123be2af2b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sfx2.hxx"
26 #include <com/sun/star/frame/XDesktop.hpp>
27 #include <com/sun/star/script/XLibraryContainer.hpp>
28 #include <comphelper/processfactory.hxx>
29 #include <com/sun/star/uno/Reference.h>
30 #include <basic/basrdll.hxx>
31 #include <tools/urlobj.hxx>
32 #include <svl/macitem.hxx>
33 #include <basic/sbxfac.hxx>
34 #include <basic/sbx.hxx>
35 #include <vcl/gradient.hxx>
36 #include <svl/rectitem.hxx>
37 #include <svl/intitem.hxx>
38 #include <svl/eitem.hxx>
39 #include <basic/sbmod.hxx>
40 #include <svl/whiter.hxx>
41 #include <basic/sbmeth.hxx>
42 #include <basic/sbstar.hxx>
43 #include <vcl/wrkwin.hxx>
44 #include <vcl/msgbox.hxx>
45 #include <basic/sbuno.hxx>
46 #include <svtools/sfxecode.hxx>
47 #include <svtools/ehdl.hxx>
48 
49 #include <unotools/undoopt.hxx>
50 #include <unotools/pathoptions.hxx>
51 #include <unotools/useroptions.hxx>
52 #include <unotools/bootstrap.hxx>
53 
54 #include <sfx2/appuno.hxx>
55 #include <sfx2/module.hxx>
56 #include "arrdecl.hxx"
57 #include <sfx2/app.hxx>
58 #include "sfxtypes.hxx"
59 #include "sfx2/sfxresid.hxx"
60 #include <sfx2/msg.hxx>
61 #include <sfx2/msgpool.hxx>
62 #include <sfx2/progress.hxx>
63 #include <sfx2/objsh.hxx>
64 #include <sfx2/objitem.hxx>
65 #include <sfx2/viewfrm.hxx>
66 #include <sfx2/viewsh.hxx>
67 #include <sfx2/dispatch.hxx>
68 #include "sfx2/tplpitem.hxx"
69 #include "sfx2/minfitem.hxx"
70 #include "app.hrc"
71 #include <sfx2/evntconf.hxx>
72 #include <sfx2/request.hxx>
73 #include <sfx2/dinfdlg.hxx>
74 #include "appdata.hxx"
75 #include "appbas.hxx"
76 #include "sfx2/sfxhelp.hxx"
77 #include "sfx2/basmgr.hxx"
78 #include "sorgitm.hxx"
79 #include "appbaslib.hxx"
80 #include <basic/basicmanagerrepository.hxx>
81 
82 #define ITEMID_SEARCH SID_SEARCH_ITEM
83 
84 #include <svl/srchitem.hxx>
85 #include <vos/socket.hxx>
86 
87 #define SFX_TYPEMAP
88 #define Selection
89 #include "sfxslots.hxx"
90 
91 using namespace ::com::sun::star;
92 using namespace ::com::sun::star::uno;
93 using namespace ::com::sun::star::frame;
94 using namespace ::com::sun::star::script;
95 
96 using ::basic::BasicManagerRepository;
97 
98 //========================================================================
99 
100 //------------------------------------------------------------------------
lcl_GetVersionString(ResMgr *)101 String lcl_GetVersionString(ResMgr* /*pAppData_ImplResMgr*/)
102 {
103     ::rtl::OUString aDefault;
104     String aVersion( utl::Bootstrap::getBuildIdData( aDefault ));
105 
106     if ( aVersion.Len() == 0 )
107     {
108         DBG_ERROR( "No BUILDID in bootstrap file found" );
109     }
110 
111     aVersion.Erase( 0, aVersion.Search( ':' ) + 1 );
112     aVersion.Erase( aVersion.Search( ')' ) );
113     return aVersion;
114 }
115 
116 //=========================================================================
SaveBasicManager() const117 sal_uInt16 SfxApplication::SaveBasicManager() const
118 {
119     return 0;
120 }
121 
122 //--------------------------------------------------------------------
SaveBasicAndDialogContainer() const123 sal_uInt16 SfxApplication::SaveBasicAndDialogContainer() const
124 {
125     if ( pAppData_Impl->pBasicManager->isValid() )
126         pAppData_Impl->pBasicManager->storeAllLibraries();
127     return 0;
128 }
129 
130 //--------------------------------------------------------------------
131 
RegisterBasicConstants(const char *,const SfxConstant *,sal_uInt16)132 void SfxApplication::RegisterBasicConstants
133 (
134     const char*,        // Prefix vor Konstanten-Namen
135     const SfxConstant*, // Array von <SfxConstant> Instanzen
136     sal_uInt16          // Anahl der Kontanten in pConsts
137 )
138 
139 /*  [Beschreibung]
140 
141     Diese Methode meldet Konstanten beim BASIC an. Sie sollte on-demand
142     (in GetSbxObject() der Applikation) gerufen werden. Das Array mu\s
143     alphabetisch nach den Namen sortiert sein!
144 
145     Durch den Prefix kann Speicher gespart und das Suchen beschleunigt
146     werden. Im StarOffice soll der Prefix "so" verwendet werden.
147 
148 
149     [Beispiel]
150 
151     const SfxConstant __FAR_DATA aConstants[] =
152     {
153         SFX_BOOL_CONSTANT( "False", sal_False ),
154         SFX_BOOL_CONSTANT( "True",  sal_True ),
155     };
156 
157     ...
158     SFX_APP()->RegisterBasicConstants( 0, aConstants, 2 );
159     ...
160 
161 */
162 
163 {
164 //  DBG_ASSERT( pAppData_Impl->pBasicMgr, "no basic available" );
165 
166 //  pAppData_Impl->pBasicMgr->GetLib(0)->Insert(
167 //              new SfxConstants_Impl( pPrefix, pConsts, nCount ) );
168 }
169 
170 //--------------------------------------------------------------------
171 
MakeVariable(StarBASIC * pBas,SbxObject * pObject,const char * pName,sal_uInt32 nSID,SbxDataType eType,SbxClassType eClassType)172 SbxVariable* MakeVariable( StarBASIC *pBas, SbxObject *pObject,
173            const char *pName, sal_uInt32 nSID, SbxDataType eType, SbxClassType eClassType )
174 {
175     SbxVariable *pVar = pBas->Make( String::CreateFromAscii(pName), eClassType, eType ); //SbxCLASS_PROPERTY
176     pVar->SetUserData( nSID );
177     pVar->SetFlag( SBX_DONTSTORE );
178     pObject->StartListening( pVar->GetBroadcaster() );
179     return pVar;
180 }
181 
182 //--------------------------------------------------------------------
183 
GetBasicManager()184 BasicManager* SfxApplication::GetBasicManager()
185 {
186     return BasicManagerRepository::getApplicationBasicManager( true );
187 }
188 
189 //--------------------------------------------------------------------
190 
GetDialogContainer()191 Reference< XLibraryContainer > SfxApplication::GetDialogContainer()
192 {
193     if ( !pAppData_Impl->pBasicManager->isValid() )
194         GetBasicManager();
195     return pAppData_Impl->pBasicManager->getLibraryContainer( SfxBasicManagerHolder::DIALOGS );
196 }
197 
198 //--------------------------------------------------------------------
199 
GetBasicContainer()200 Reference< XLibraryContainer > SfxApplication::GetBasicContainer()
201 {
202     if ( !pAppData_Impl->pBasicManager->isValid() )
203         GetBasicManager();
204     return pAppData_Impl->pBasicManager->getLibraryContainer( SfxBasicManagerHolder::SCRIPTS );
205 }
206 
207 //--------------------------------------------------------------------
208 
GetBasic()209 StarBASIC* SfxApplication::GetBasic()
210 {
211     return GetBasicManager()->GetLib(0);
212 }
213 
214 //-------------------------------------------------------------------------
PropExec_Impl(SfxRequest & rReq)215 void SfxApplication::PropExec_Impl( SfxRequest &rReq )
216 {
217     rReq.GetArgs();
218     sal_uInt16 nSID = rReq.GetSlot();
219     switch ( nSID )
220     {
221         case SID_CREATE_BASICOBJECT:
222         {
223             SFX_REQUEST_ARG(rReq, pItem, SfxStringItem, nSID, sal_False);
224             if ( pItem )
225             {
226                 SbxObject* pObject = SbxBase::CreateObject( pItem->GetValue() );
227                 pObject->AddRef();
228 //(mba)                rReq.SetReturnValue( SfxObjectItem( 0, pObject ) );
229                 rReq.Done();
230             }
231             break;
232         }
233 
234         case SID_DELETE_BASICOBJECT:
235         {
236             SFX_REQUEST_ARG(rReq, pItem, SfxObjectItem, nSID, sal_False);
237             if ( pItem )
238             {
239 //(mba)                SbxObject* pObject = pItem->GetObject();
240 //(mba)                pObject->ReleaseRef();
241             }
242             break;
243         }
244 
245         case SID_ATTR_UNDO_COUNT:
246         {
247             SFX_REQUEST_ARG(rReq, pCountItem, SfxUInt16Item, nSID, sal_False);
248             SvtUndoOptions().SetUndoCount( pCountItem->GetValue() );
249             break;
250         }
251 
252         case SID_WIN_VISIBLE:
253         {
254             break;
255         }
256 
257         case SID_STATUSBARTEXT:
258         {
259             SFX_REQUEST_ARG(rReq, pStringItem, SfxStringItem, nSID, sal_False);
260             String aText = pStringItem->GetValue();
261             if ( aText.Len() )
262                 GetpApp()->ShowStatusText( aText );
263             else
264                 GetpApp()->HideStatusText();
265             break;
266         }
267 
268         case SID_OFFICE_PRIVATE_USE:
269         case SID_OFFICE_COMMERCIAL_USE:
270         {
271             DBG_ASSERT( sal_False, "SfxApplication::PropExec_Impl()\nSID_OFFICE_PRIVATE_USE & SID_OFFICE_COMMERCIAL_USE are obsolete!\n" );
272             break;
273         }
274 
275         case SID_OFFICE_CUSTOMERNUMBER:
276         {
277             SFX_REQUEST_ARG(rReq, pStringItem, SfxStringItem, nSID, sal_False);
278 
279             if ( pStringItem )
280                 SvtUserOptions().SetCustomerNumber( pStringItem->GetValue() );
281             break;
282         }
283     }
284 }
285 
286 //-------------------------------------------------------------------------
PropState_Impl(SfxItemSet & rSet)287 void SfxApplication::PropState_Impl( SfxItemSet &rSet )
288 {
289 //  SfxViewFrame *pFrame = SfxViewFrame::Current();
290     SfxWhichIter aIter(rSet);
291     for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
292     {
293         switch ( nSID )
294         {
295             case SID_PROGNAME:
296                 rSet.Put( SfxStringItem( SID_PROGNAME, GetName() ) );
297                 break;
298 
299             case SID_ACTIVEDOCUMENT:
300                 rSet.Put( SfxObjectItem( SID_ACTIVEDOCUMENT, SfxObjectShell::Current() ) );
301                 break;
302 
303             case SID_APPLICATION:
304                 rSet.Put( SfxObjectItem( SID_APPLICATION, this ) );
305                 break;
306 
307             case SID_PROGFILENAME:
308                 rSet.Put( SfxStringItem( SID_PROGFILENAME, Application::GetAppFileName() ) );
309                 break;
310 
311             case SID_ATTR_UNDO_COUNT:
312                 rSet.Put( SfxUInt16Item( SID_ATTR_UNDO_COUNT, sal::static_int_cast< sal_uInt16 >( SvtUndoOptions().GetUndoCount() ) ) );
313                 break;
314 
315             case SID_UPDATE_VERSION:
316                 rSet.Put( SfxUInt32Item( SID_UPDATE_VERSION, SUPD ) );
317                 break;
318 
319             case SID_OFFICE_CUSTOMERNUMBER:
320             {
321                 rSet.Put( SfxStringItem( nSID, SvtUserOptions().GetCustomerNumber() ) );
322                 break;
323             }
324         }
325     }
326 }
327 
328