1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: appbas.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
33 #include <com/sun/star/frame/XDesktop.hpp>
34 #include <com/sun/star/script/XLibraryContainer.hpp>
35 #include <comphelper/processfactory.hxx>
36 #include <com/sun/star/uno/Reference.h>
37 #include <basic/basrdll.hxx>
38 #include <tools/urlobj.hxx>
39 #include <svtools/macitem.hxx>
40 #include <basic/sbxfac.hxx>
41 #include <basic/sbx.hxx>
42 #include <vcl/gradient.hxx>
43 #include <svtools/rectitem.hxx>
44 #include <svtools/intitem.hxx>
45 #include <svtools/eitem.hxx>
46 #include <basic/sbmod.hxx>
47 #include <svtools/whiter.hxx>
48 #include <basic/sbmeth.hxx>
49 #include <basic/sbstar.hxx>
50 #include <vcl/wrkwin.hxx>
51 #include <vcl/msgbox.hxx>
52 #include <basic/sbuno.hxx>
53 #include <svtools/sfxecode.hxx>
54 #include <svtools/ehdl.hxx>
56 #include <svtools/undoopt.hxx>
57 #include <svtools/pathoptions.hxx>
58 #include <svtools/useroptions.hxx>
59 #include <unotools/bootstrap.hxx>
61 #include <sfx2/appuno.hxx>
62 #include <sfx2/module.hxx>
63 #include "arrdecl.hxx"
64 #include <sfx2/app.hxx>
65 #include "sfxtypes.hxx"
66 #include "sfxresid.hxx"
67 #include <sfx2/msg.hxx>
68 #include <sfx2/msgpool.hxx>
69 #include <sfx2/progress.hxx>
70 #include <sfx2/objsh.hxx>
71 #include <sfx2/objitem.hxx>
72 #include <sfx2/viewfrm.hxx>
73 #include <sfx2/viewsh.hxx>
74 #include <sfx2/dispatch.hxx>
75 #include "tplpitem.hxx"
76 #include "minfitem.hxx"
78 #include <sfx2/evntconf.hxx>
79 #include <sfx2/macrconf.hxx>
80 #include <sfx2/request.hxx>
81 #include <sfx2/dinfdlg.hxx>
82 #include "appdata.hxx"
84 #include "sfxhelp.hxx"
86 #include "sorgitm.hxx"
87 #include "appbaslib.hxx"
88 #include <basic/basicmanagerrepository.hxx>
90 #define ITEMID_SEARCH SID_SEARCH_ITEM
92 #include <sfx2/srchitem.hxx>
93 #include <vos/socket.hxx>
97 #include "sfxslots.hxx"
99 using namespace ::com::sun::star
;
100 using namespace ::com::sun::star::uno
;
101 using namespace ::com::sun::star::frame
;
102 using namespace ::com::sun::star::script
;
104 using ::basic::BasicManagerRepository
;
106 // #ifndef STR_VERSION_ID
107 // #define STR_VERSION_ID 1
109 // #ifndef STR_VERSION_TYPE
110 // #define STR_VERSION_TYPE 1
113 //=========================================================================
115 const SfxConstant __FAR_DATA aConstants[] =
117 SFX_USHORT_CONSTANT( "AlignBottom", ALIGN_BOTTOM ),
118 SFX_USHORT_CONSTANT( "AlignTop", ALIGN_TOP ),
119 SFX_USHORT_CONSTANT( "CharSetANSI", CHARSET_ANSI ),
120 SFX_USHORT_CONSTANT( "CharSetDontKnow", CHARSET_DONTKNOW ),
121 SFX_USHORT_CONSTANT( "CharSetIBMPC437", CHARSET_IBMPC_437 ),
122 SFX_USHORT_CONSTANT( "CharSetIBMPC850", CHARSET_IBMPC_850 ),
123 SFX_USHORT_CONSTANT( "CharSetIBMPC860", CHARSET_IBMPC_860 ),
124 SFX_USHORT_CONSTANT( "CharSetIBMPC861", CHARSET_IBMPC_861 ),
125 SFX_USHORT_CONSTANT( "CharSetIBMPC863", CHARSET_IBMPC_863 ),
126 SFX_USHORT_CONSTANT( "CharSetIBMPC865", CHARSET_IBMPC_865 ),
127 SFX_USHORT_CONSTANT( "CharSetIBMPC", CHARSET_IBMPC ),
128 SFX_USHORT_CONSTANT( "CharSetMac", CHARSET_MAC ),
129 SFX_USHORT_CONSTANT( "CharSetSymbol", CHARSET_SYMBOL ),
130 SFX_USHORT_CONSTANT( "CharSetSystem", RTL_TEXTENCODING_UTF8 ),
131 SFX_USHORT_CONSTANT( "FamilyDecorative", FAMILY_DECORATIVE ),
132 SFX_USHORT_CONSTANT( "FamilyDontknow", FAMILY_DONTKNOW ),
133 SFX_USHORT_CONSTANT( "FamilyModern", FAMILY_MODERN ),
134 SFX_USHORT_CONSTANT( "FamilyRoman", FAMILY_ROMAN ),
135 SFX_USHORT_CONSTANT( "FamilyScript", FAMILY_SCRIPT ),
136 SFX_USHORT_CONSTANT( "FamilySwiss", FAMILY_SWISS ),
137 SFX_USHORT_CONSTANT( "FamilySystem", FAMILY_SYSTEM ),
138 SFX_USHORT_CONSTANT( "GradientAxial", GRADIENT_AXIAL ),
139 SFX_USHORT_CONSTANT( "GradientElliptical", GRADIENT_ELLIPTICAL ),
140 SFX_USHORT_CONSTANT( "GradientLinear", GRADIENT_LINEAR ),
141 SFX_USHORT_CONSTANT( "GradientRadial", GRADIENT_RADIAL ),
142 SFX_USHORT_CONSTANT( "GradientRect", GRADIENT_RECT ),
143 SFX_USHORT_CONSTANT( "GradientSquare", GRADIENT_SQUARE ),
144 SFX_USHORT_CONSTANT( "ItalicNone", ITALIC_NONE ),
145 SFX_USHORT_CONSTANT( "ItalicOblique", ITALIC_OBLIQUE ),
146 SFX_USHORT_CONSTANT( "StrikeThroughDouble", STRIKEOUT_DOUBLE ),
147 SFX_USHORT_CONSTANT( "StrikeThroughNone", STRIKEOUT_NONE ),
148 SFX_USHORT_CONSTANT( "StrikeThroughSingle", STRIKEOUT_SINGLE ),
149 SFX_USHORT_CONSTANT( "UnderlineDotted", UNDERLINE_DOTTED ),
150 SFX_USHORT_CONSTANT( "UnderlineDouble", UNDERLINE_DOUBLE ),
151 SFX_USHORT_CONSTANT( "UnderlineNone", UNDERLINE_NONE ),
152 SFX_USHORT_CONSTANT( "UnderlineSingle", UNDERLINE_SINGLE ),
153 SFX_USHORT_CONSTANT( "UnitFoot", FUNIT_FOOT ),
154 SFX_USHORT_CONSTANT( "UnitInch", FUNIT_INCH ),
155 SFX_USHORT_CONSTANT( "UnitMile", FUNIT_MILE ),
156 SFX_USHORT_CONSTANT( "UnitPercent", FUNIT_PERCENT ),
157 SFX_USHORT_CONSTANT( "UnitPoint", FUNIT_POINT ),
158 SFX_USHORT_CONSTANT( "UnitTwip", FUNIT_TWIP ),
159 SFX_USHORT_CONSTANT( "Unit_cm", FUNIT_CM ),
160 SFX_USHORT_CONSTANT( "Unit_m", FUNIT_M ),
161 SFX_USHORT_CONSTANT( "Unit_mm", FUNIT_MM ),
162 SFX_USHORT_CONSTANT( "WeightBlack", WEIGHT_BLACK ),
163 SFX_USHORT_CONSTANT( "WeightBold", WEIGHT_BOLD ),
164 SFX_USHORT_CONSTANT( "WeightDontKnow", WEIGHT_DONTKNOW ),
165 SFX_USHORT_CONSTANT( "WeightLight", WEIGHT_LIGHT ),
166 SFX_USHORT_CONSTANT( "WeightMedium", WEIGHT_MEDIUM ),
167 SFX_USHORT_CONSTANT( "WeightNormal", WEIGHT_NORMAL ),
168 SFX_USHORT_CONSTANT( "WeightSemibold", WEIGHT_SEMIBOLD ),
169 SFX_USHORT_CONSTANT( "WeightSemilight", WEIGHT_SEMILIGHT ),
170 SFX_USHORT_CONSTANT( "WeightThin", WEIGHT_THIN ),
171 SFX_USHORT_CONSTANT( "WeightUltrabold", WEIGHT_ULTRABOLD ),
172 SFX_USHORT_CONSTANT( "WeightUltralight", WEIGHT_ULTRALIGHT )
175 //========================================================================
177 //------------------------------------------------------------------------
178 String
lcl_GetVersionString(ResMgr
* /*pAppData_ImplResMgr*/)
180 ::rtl::OUString aDefault
;
181 String
aVersion( utl::Bootstrap::getBuildIdData( aDefault
));
183 if ( aVersion
.Len() == 0 )
185 DBG_ERROR( "No BUILDID in bootstrap file found" );
188 aVersion
.Erase( 0, aVersion
.Search( ':' ) + 1 );
189 aVersion
.Erase( aVersion
.Search( ')' ) );
193 //=========================================================================
194 sal_uInt16
SfxApplication::SaveBasicManager() const
199 //--------------------------------------------------------------------
200 sal_uInt16
SfxApplication::SaveBasicAndDialogContainer() const
202 if ( pAppData_Impl
->pBasicManager
->isValid() )
203 pAppData_Impl
->pBasicManager
->storeAllLibraries();
207 //--------------------------------------------------------------------
209 void SfxApplication::RegisterBasicConstants
211 const char*, // Prefix vor Konstanten-Namen
212 const SfxConstant
*, // Array von <SfxConstant> Instanzen
213 sal_uInt16
// Anahl der Kontanten in pConsts
218 Diese Methode meldet Konstanten beim BASIC an. Sie sollte on-demand
219 (in GetSbxObject() der Applikation) gerufen werden. Das Array mu\s
220 alphabetisch nach den Namen sortiert sein!
222 Durch den Prefix kann Speicher gespart und das Suchen beschleunigt
223 werden. Im StarOffice soll der Prefix "so" verwendet werden.
228 const SfxConstant __FAR_DATA aConstants[] =
230 SFX_BOOL_CONSTANT( "False", sal_False ),
231 SFX_BOOL_CONSTANT( "True", sal_True ),
235 SFX_APP()->RegisterBasicConstants( 0, aConstants, 2 );
241 // DBG_ASSERT( pAppData_Impl->pBasicMgr, "no basic available" );
243 // pAppData_Impl->pBasicMgr->GetLib(0)->Insert(
244 // new SfxConstants_Impl( pPrefix, pConsts, nCount ) );
247 //--------------------------------------------------------------------
249 SbxVariable
* MakeVariable( StarBASIC
*pBas
, SbxObject
*pObject
,
250 const char *pName
, sal_uInt32 nSID
, SbxDataType eType
, SbxClassType eClassType
)
252 SbxVariable
*pVar
= pBas
->Make( String::CreateFromAscii(pName
), eClassType
, eType
); //SbxCLASS_PROPERTY
253 pVar
->SetUserData( nSID
);
254 pVar
->SetFlag( SBX_DONTSTORE
);
255 pObject
->StartListening( pVar
->GetBroadcaster() );
259 //--------------------------------------------------------------------
261 BasicManager
* SfxApplication::GetBasicManager()
263 // DBG_ASSERT( pAppData_Impl->nBasicCallLevel != 0,
264 // "unnecessary call to GetBasicManager() - inefficient!" );
265 if ( pAppData_Impl
->nBasicCallLevel
== 0 )
269 return BasicManagerRepository::getApplicationBasicManager( true );
272 //--------------------------------------------------------------------
274 Reference
< XLibraryContainer
> SfxApplication::GetDialogContainer()
276 if ( !pAppData_Impl
->pBasicManager
->isValid() )
278 return pAppData_Impl
->pBasicManager
->getLibraryContainer( SfxBasicManagerHolder::DIALOGS
);
281 //--------------------------------------------------------------------
283 Reference
< XLibraryContainer
> SfxApplication::GetBasicContainer()
285 if ( !pAppData_Impl
->pBasicManager
->isValid() )
287 return pAppData_Impl
->pBasicManager
->getLibraryContainer( SfxBasicManagerHolder::SCRIPTS
);
290 //--------------------------------------------------------------------
292 StarBASIC
* SfxApplication::GetBasic()
294 return GetBasicManager()->GetLib(0);
297 //--------------------------------------------------------------------
299 FASTBOOL
SfxApplication::IsInBasicCall() const
301 return 0 != pAppData_Impl
->nBasicCallLevel
;
304 //--------------------------------------------------------------------
306 void SfxApplication::EnterBasicCall()
308 if ( 1 == ++pAppData_Impl
->nBasicCallLevel
)
310 DBG_TRACE( "SfxShellObject: BASIC-on-demand" );
312 // das kann l"anger dauern, da Progress nicht geht, wenigstens Sanduhr
313 //(mba)/task SfxWaitCursor aWait;
315 // zuerst das BASIC laden
318 // als erstes SfxShellObject das SbxObject der SfxApplication erzeugen
319 SbxObject *pSbx = GetSbxObject();
320 DBG_ASSERT( pSbx, "SfxShellObject: can't create SbxObject for SfxApplication" );
322 // die SbxObjects aller Module erzeugen
323 SfxModuleArr_Impl& rArr = GetModules_Impl();
324 for ( sal_uInt16 n = 0; n < rArr.Count(); ++n )
326 SfxModule *pMod = rArr.GetObject(n);
327 if ( pMod->IsLoaded() )
329 pSbx = pMod->GetSbxObject();
330 DBG_ASSERT( pSbx, "SfxModule: can't create SbxObject" );
334 // die SbxObjects aller Tasks erzeugen
335 for ( SfxTask *pTask = SfxTask::GetFirst(); pTask; pTask = SfxTask::GetNext( *pTask ) )
336 pTask->GetSbxObject();
338 // die SbxObjects aller SfxObjectShells erzeugen (ggf. Frame-los!)
339 for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst( NULL, sal_False );
341 pObjSh = SfxObjectShell::GetNext(*pObjSh, NULL, sal_False) )
343 // kein IP-Object oder wenn doch dann initialisiert?
344 SvStorageRef aStorage;
345 if ( !pObjSh->IsHandsOff() )
346 aStorage = pObjSh->GetStorage();
347 if ( !pObjSh->GetInPlaceObject() || aStorage.Is() )
349 DBG( DbgOutf( "SfxShellObject: BASIC-on-demand for %s",
350 pObjSh->SfxShell::GetName().GetBuffer() ) );
351 pSbx = pObjSh->GetSbxObject();
352 DBG_ASSERT( pSbx, "SfxShellObject: can't create SbxObject" );
356 // die SbxObjects der SfxShells auf den Stacks der Frames erzeugen
357 for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst(0,0,sal_False);
359 pFrame = SfxViewFrame::GetNext(*pFrame,0,0,sal_False) )
361 // den Dispatcher des Frames rausholen
362 SfxDispatcher *pDispat = pFrame->GetDispatcher();
365 // "uber alle SfxShells auf dem Stack des Dispatchers iterieren
366 // Frame selbst wird ausgespart, da er indirekt angezogen wird,
367 // sofern er ein Dokument enth"alt.
368 for ( sal_uInt16 nStackIdx = pDispat->GetShellLevel(*pFrame);
372 DBG( DbgOutf( "SfxShellObject: BASIC-on-demand for level %u", nStackIdx-1 ); )
373 pSbx = pDispat->GetShell(nStackIdx - 1)->GetSbxObject();
374 DBG_ASSERT( pSbx, "SfxShellObject: can't create SbxObject" );
377 if ( !pFrame->GetObjectShell() )
379 DBG( DbgOutf( "SfxShellObject: BASIC-on-demand for empty frame" ); )
380 pSbx = pFrame->GetSbxObject();
381 DBG_ASSERT( pSbx, "SfxShellObject: can't create SbxObject" );
385 // Factories anmelden
386 // SbxBase::AddFactory( new SfxSbxObjectFactory_Impl );
390 //--------------------------------------------------------------------
392 void SfxApplication::LeaveBasicCall()
394 --pAppData_Impl
->nBasicCallLevel
;
397 //-------------------------------------------------------------------------
398 void SfxApplication::PropExec_Impl( SfxRequest
&rReq
)
401 sal_uInt16 nSID
= rReq
.GetSlot();
404 case SID_CREATE_BASICOBJECT
:
406 SFX_REQUEST_ARG(rReq
, pItem
, SfxStringItem
, nSID
, sal_False
);
409 SbxObject
* pObject
= SbxBase::CreateObject( pItem
->GetValue() );
411 //(mba) rReq.SetReturnValue( SfxObjectItem( 0, pObject ) );
417 case SID_DELETE_BASICOBJECT
:
419 SFX_REQUEST_ARG(rReq
, pItem
, SfxObjectItem
, nSID
, sal_False
);
422 //(mba) SbxObject* pObject = pItem->GetObject();
423 //(mba) pObject->ReleaseRef();
428 case SID_WIN_POSSIZE
:
433 case SID_INTERACTIVEMODE
:
438 case SID_ATTR_UNDO_COUNT
:
440 SFX_REQUEST_ARG(rReq
, pCountItem
, SfxUInt16Item
, nSID
, sal_False
);
441 SvtUndoOptions().SetUndoCount( pCountItem
->GetValue() );
445 case SID_WIN_VISIBLE
:
450 case SID_STATUSBARTEXT
:
452 SFX_REQUEST_ARG(rReq
, pStringItem
, SfxStringItem
, nSID
, sal_False
);
453 String aText
= pStringItem
->GetValue();
455 GetpApp()->ShowStatusText( aText
);
457 GetpApp()->HideStatusText();
462 PlayMacro_Impl( rReq
, GetBasic() );
465 case SID_OFFICE_PRIVATE_USE
:
466 case SID_OFFICE_COMMERCIAL_USE
:
468 DBG_ASSERT( sal_False
, "SfxApplication::PropExec_Impl()\nSID_OFFICE_PRIVATE_USE & SID_OFFICE_COMMERCIAL_USE are obsolete!\n" );
472 case SID_OFFICE_CUSTOMERNUMBER
:
474 SFX_REQUEST_ARG(rReq
, pStringItem
, SfxStringItem
, nSID
, sal_False
);
477 SvtUserOptions().SetCustomerNumber( pStringItem
->GetValue() );
483 //-------------------------------------------------------------------------
484 void SfxApplication::PropState_Impl( SfxItemSet
&rSet
)
486 // SfxViewFrame *pFrame = SfxViewFrame::Current();
487 SfxWhichIter
aIter(rSet
);
488 for ( sal_uInt16 nSID
= aIter
.FirstWhich(); nSID
; nSID
= aIter
.NextWhich() )
493 rSet
.Put( SfxStringItem( SID_PROGNAME
, GetName() ) );
496 case SID_ACTIVEDOCUMENT
:
497 rSet
.Put( SfxObjectItem( SID_ACTIVEDOCUMENT
, SfxObjectShell::Current() ) );
500 case SID_APPLICATION
:
501 rSet
.Put( SfxObjectItem( SID_APPLICATION
, this ) );
504 case SID_PROGFILENAME
:
505 rSet
.Put( SfxStringItem( SID_PROGFILENAME
, Application::GetAppFileName() ) );
508 case SID_ATTR_UNDO_COUNT
:
509 rSet
.Put( SfxUInt16Item( SID_ATTR_UNDO_COUNT
, sal::static_int_cast
< UINT16
>( SvtUndoOptions().GetUndoCount() ) ) );
512 case SID_UPDATE_VERSION
:
513 rSet
.Put( SfxUInt32Item( SID_UPDATE_VERSION
, SUPD
) );
516 case SID_BUILD_VERSION
:
518 String aVersion
= lcl_GetVersionString(pAppData_Impl
->pLabelResMgr
);
519 rSet
.Put( SfxUInt32Item( SID_BUILD_VERSION
, (sal_uInt32
) aVersion
.ToInt32() ) );
523 case SID_OFFICE_PRIVATE_USE
:
524 case SID_OFFICE_COMMERCIAL_USE
:
526 DBG_ASSERT( sal_False
, "SfxApplication::PropState_Impl()\nSID_OFFICE_PRIVATE_USE & SID_OFFICE_COMMERCIAL_USE are obsolete!\n" );
530 case SID_OFFICE_CUSTOMERNUMBER
:
532 rSet
.Put( SfxStringItem( nSID
, SvtUserOptions().GetCustomerNumber() ) );
539 //--------------------------------------------------------------------
540 void SfxApplication::MacroExec_Impl( SfxRequest
& rReq
)
543 if ( SfxMacroConfig::IsMacroSlot( rReq
.GetSlot() ) )
545 // SlotId referenzieren, damit nicht im Execute der Slot abgeschossen
547 GetMacroConfig()->RegisterSlotId(rReq
.GetSlot());
548 SFX_REQUEST_ARG(rReq
, pArgs
, SfxStringItem
,
549 rReq
.GetSlot(), sal_False
);
551 if( pArgs
) aArgs
= pArgs
->GetValue();
552 if ( GetMacroConfig()->ExecuteMacro(rReq
.GetSlot(), aArgs
) )
554 GetMacroConfig()->ReleaseSlotId(rReq
.GetSlot());
558 //--------------------------------------------------------------------
559 void SfxApplication::MacroState_Impl( SfxItemSet
& )
564 //-------------------------------------------------------------------------
566 void SfxApplication::PlayMacro_Impl( SfxRequest
&rReq
, StarBASIC
*pBasic
)
569 sal_Bool bOK
= sal_False
;
571 // Makro und asynch-Flag
572 SFX_REQUEST_ARG(rReq
,pMacro
,SfxStringItem
,SID_STATEMENT
,sal_False
);
573 SFX_REQUEST_ARG(rReq
,pAsynch
,SfxBoolItem
,SID_ASYNCHRON
,sal_False
);
575 if ( pAsynch
&& pAsynch
->GetValue() )
577 // asynchron ausf"uhren
578 GetDispatcher_Impl()->Execute( SID_PLAYMACRO
, SFX_CALLMODE_ASYNCHRON
, pMacro
, 0L );
583 // Statement aufbereiten
584 DBG_ASSERT( pBasic
, "no BASIC found" ) ;
585 String
aStatement( '[' );
586 aStatement
+= pMacro
->GetValue();
589 // P"aventiv den Request abschlie\sen, da er ggf. zerst"ort wird
593 // Statement ausf"uhren
594 pBasic
->Execute( aStatement
);
595 bOK
= 0 == SbxBase::GetError();
596 SbxBase::ResetError();
600 rReq
.SetReturnValue(SfxBoolItem(0,bOK
));