Line data Source code
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 <com/sun/star/uno/Reference.hxx>
21 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
22 : #include <com/sun/star/lang/IllegalArgumentException.hpp>
23 : #include <com/sun/star/frame/DispatchResultEvent.hpp>
24 : #include <com/sun/star/frame/DispatchResultState.hpp>
25 : #include <com/sun/star/task/XJobExecutor.hpp>
26 : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
27 : #include <com/sun/star/frame/DispatchHelper.hpp>
28 : #include <com/sun/star/frame/XDesktop.hpp>
29 : #include <com/sun/star/frame/XFramesSupplier.hpp>
30 : #include <com/sun/star/util/XCloseable.hpp>
31 : #include <com/sun/star/util/CloseVetoException.hpp>
32 : #include <com/sun/star/frame/XLayoutManager.hpp>
33 : #include <com/sun/star/document/XEmbeddedScripts.hpp>
34 : #include <com/sun/star/embed/XStorage.hpp>
35 : #include <com/sun/star/embed/ElementModes.hpp>
36 : #include <com/sun/star/system/SystemShellExecute.hpp>
37 : #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
38 : #include <com/sun/star/system/SystemShellExecuteException.hpp>
39 : #include <com/sun/star/sdbc/DriverManager.hpp>
40 : #include <org/freedesktop/PackageKit/SyncDbusSessionHelper.hpp>
41 :
42 : #include <com/sun/star/frame/XComponentLoader.hpp>
43 :
44 : #include <comphelper/processfactory.hxx>
45 : #include <comphelper/storagehelper.hxx>
46 : #include "comphelper/configurationhelper.hxx"
47 :
48 : #include <svtools/addresstemplate.hxx>
49 : #include <svtools/miscopt.hxx>
50 : #include <svtools/restartdialog.hxx>
51 : #include <svl/visitem.hxx>
52 : #include <unotools/intlwrapper.hxx>
53 :
54 : #include <unotools/configmgr.hxx>
55 : #include <tools/diagnose_ex.h>
56 : #include <vcl/msgbox.hxx>
57 : #include <svl/intitem.hxx>
58 : #include <svl/eitem.hxx>
59 : #include <svl/stritem.hxx>
60 : #include <basic/sbstar.hxx>
61 : #include <basic/basmgr.hxx>
62 : #include <basic/basrdll.hxx>
63 : #include <svtools/sfxecode.hxx>
64 : #include <svtools/ehdl.hxx>
65 : #include <vcl/help.hxx>
66 : #include <vcl/stdtext.hxx>
67 : #include <rtl/ustrbuf.hxx>
68 : #include <osl/file.hxx>
69 :
70 : #include <unotools/pathoptions.hxx>
71 : #include <unotools/moduleoptions.hxx>
72 : #include <svtools/helpopt.hxx>
73 : #include <svtools/miscopt.hxx>
74 : #include <toolkit/helper/vclunohelper.hxx>
75 : #include <tools/shl.hxx>
76 : #include <unotools/bootstrap.hxx>
77 : #include <rtl/bootstrap.hxx>
78 : #include <cppuhelper/exc_hlp.hxx>
79 :
80 : #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
81 : #include <com/sun/star/frame/ModuleManager.hpp>
82 : #include <com/sun/star/beans/XPropertySet.hpp>
83 :
84 : #include "frmload.hxx"
85 : #include "referers.hxx"
86 : #include <sfx2/app.hxx>
87 : #include <sfx2/request.hxx>
88 : #include <sfx2/dispatch.hxx>
89 : #include <sfx2/bindings.hxx>
90 : #include <sfx2/msg.hxx>
91 : #include <sfx2/objface.hxx>
92 : #include <sfx2/objitem.hxx>
93 : #include <sfx2/objsh.hxx>
94 : #include <sfx2/hintpost.hxx>
95 : #include <sfx2/viewsh.hxx>
96 : #include <sfx2/docfac.hxx>
97 : #include <sfx2/docfile.hxx>
98 : #include <sfx2/docfilt.hxx>
99 : #include "docvor.hxx"
100 : #include <sfx2/new.hxx>
101 : #include <sfx2/templdlg.hxx>
102 : #include "sfxtypes.hxx"
103 : #include <sfx2/tabdlg.hxx>
104 : #include "arrdecl.hxx"
105 : #include "fltfnc.hxx"
106 : #include <sfx2/sfx.hrc>
107 : #include "app.hrc"
108 : #include <sfx2/passwd.hxx>
109 : #include "sfx2/sfxresid.hxx"
110 : #include <sfx2/childwin.hxx>
111 : #include "appdata.hxx"
112 : #include "sfx2/minfitem.hxx"
113 : #include <sfx2/event.hxx>
114 : #include <sfx2/module.hxx>
115 : #include <sfx2/viewfrm.hxx>
116 : #include "sfxpicklist.hxx"
117 : #include "imestatuswindow.hxx"
118 : #include <sfx2/sfxdlg.hxx>
119 : #include <sfx2/dialogs.hrc>
120 : #include "sorgitm.hxx"
121 : #include "sfx2/sfxhelp.hxx"
122 : #include <sfx2/zoomitem.hxx>
123 : #include "templatedlg.hxx"
124 :
125 : using namespace ::com::sun::star;
126 : using namespace ::com::sun::star::beans;
127 : using namespace ::com::sun::star::uno;
128 : using namespace ::com::sun::star::frame;
129 : using namespace ::com::sun::star::container;
130 : using namespace ::com::sun::star::util;
131 : using namespace ::com::sun::star::script;
132 : using namespace ::com::sun::star::system;
133 : using namespace ::com::sun::star::lang;
134 : using namespace ::com::sun::star::document;
135 :
136 : namespace
137 : {
138 : // lp#527938, debian#602953, fdo#33266, i#105408
139 0 : static bool lcl_isBaseAvailable()
140 : {
141 : try
142 : {
143 : // if we get com::sun::star::sdbc::DriverManager, libsdbc2 is there
144 : // and the bibliography is assumed to work
145 0 : return com::sun::star::sdbc::DriverManager::create(comphelper::getProcessComponentContext()).is();
146 : }
147 0 : catch (Exception & e)
148 : {
149 : SAL_INFO(
150 : "sfx2.appl",
151 : "assuming Base to be missing; caught " << e.Message);
152 0 : return false;
153 : }
154 : }
155 0 : static void lcl_tryLoadBibliography()
156 : {
157 : // lp#527938, debian#602953, fdo#33266, i#105408
158 : // make sure we actually can instanciate services from base first
159 0 : if(!lcl_isBaseAvailable())
160 : {
161 : try
162 : {
163 : using namespace org::freedesktop::PackageKit;
164 : using namespace svtools;
165 0 : Reference< XSyncDbusSessionHelper > xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext()));
166 0 : Sequence< ::rtl::OUString > vPackages(1);
167 0 : vPackages[0] = "libreoffice-base";
168 0 : ::rtl::OUString sInteraction;
169 0 : xSyncDbusSessionHelper->InstallPackageNames(0, vPackages, sInteraction);
170 : // Ill be back (hopefully)!
171 0 : SolarMutexGuard aGuard;
172 0 : executeRestartDialog(comphelper::getProcessComponentContext(), NULL, RESTART_REASON_BIBLIOGRAPHY_INSTALL);
173 : }
174 0 : catch (Exception & e)
175 : {
176 : SAL_INFO(
177 : "sfx2.appl",
178 : "trying to install LibreOffice Base, caught " << e.Message);
179 : }
180 0 : return;
181 : }
182 0 : SfxStringItem aURL(SID_FILE_NAME, rtl::OUString(".component:Bibliography/View1"));
183 0 : SfxStringItem aRef(SID_REFERER, rtl::OUString("private:user"));
184 0 : SfxStringItem aTarget(SID_TARGETNAME, rtl::OUString("_blank"));
185 0 : SfxViewFrame::Current()->GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, &aURL, &aRef, &aTarget, 0L);
186 : }
187 : }
188 : /// Find the correct location of the document (LICENSE.odt, etc.), and return
189 : /// it in rURL if found.
190 0 : static sal_Bool checkURL( const char *pName, const char *pExt, rtl::OUString &rURL )
191 : {
192 : using namespace osl;
193 0 : DirectoryItem aDirItem;
194 :
195 0 : rURL = rtl::OUString( "$BRAND_BASE_DIR/" );
196 0 : rURL += rtl::OUString::createFromAscii( pName );
197 0 : rURL += rtl::OUString::createFromAscii( pExt );
198 0 : rtl::Bootstrap::expandMacros( rURL );
199 :
200 0 : if (!rURL.isEmpty())
201 0 : return DirectoryItem::get( rURL, aDirItem ) == DirectoryItem::E_None;
202 : else
203 0 : return sal_False;
204 : }
205 :
206 : /// Displays CREDITS or LICENSE in any of the available version
207 0 : static void showDocument( const char* pBaseName )
208 : {
209 : try {
210 0 : Reference < XComponentLoader > xLoader( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString("com.sun.star.frame.Desktop") ), UNO_QUERY );
211 0 : Sequence < com::sun::star::beans::PropertyValue > args(2);
212 0 : args[0].Name = ::rtl::OUString("ViewOnly");
213 0 : args[0].Value <<= sal_True;
214 0 : args[1].Name = ::rtl::OUString("ReadOnly");
215 0 : args[1].Value <<= sal_True;
216 :
217 0 : rtl::OUString aURL;
218 0 : if ( checkURL ( pBaseName, ".odt", aURL ) ||
219 0 : checkURL ( pBaseName, ".html", aURL ) ||
220 0 : checkURL ( pBaseName, "", aURL ) ) {
221 0 : xLoader->loadComponentFromURL( aURL, ::rtl::OUString("_blank"), 0, args );
222 0 : }
223 0 : } catch (const ::com::sun::star::uno::Exception &) {
224 : }
225 0 : }
226 :
227 : namespace
228 : {
229 0 : class LicenseDialog : public ModalDialog
230 : {
231 : private:
232 : FixedText aText;
233 : OKButton aShow;
234 : CancelButton aClose;
235 :
236 : DECL_LINK(CancelHdl, void *);
237 : DECL_LINK(ShowHdl, void *);
238 : public:
239 : LicenseDialog(Window *pParent=NULL);
240 : };
241 :
242 0 : LicenseDialog::LicenseDialog(Window *pParent)
243 : : ModalDialog(pParent, SfxResId(DLG_HELP_LICENSING))
244 : , aText( this )
245 : , aShow( this, SfxResId( PB_LICENSING_SHOW ) )
246 0 : , aClose( this, SfxResId( PB_LICENSING_CLOSE ) )
247 : {
248 0 : aClose.SetClickHdl( LINK( this, LicenseDialog, CancelHdl ) );
249 0 : aShow.SetClickHdl( LINK( this, LicenseDialog, ShowHdl ) );
250 :
251 0 : String aLicensing;
252 0 : for ( int i = STR_LICENSING_INFORMATION_1; i <= STR_LICENSING_INFORMATION_5; ++i )
253 : {
254 0 : if ( i != STR_LICENSING_INFORMATION_1 )
255 0 : aLicensing += String( RTL_CONSTASCII_USTRINGPARAM( "\n\n" ) );
256 0 : aLicensing += SfxResId( i ).toString();
257 : }
258 :
259 0 : aText.SetText( aLicensing );
260 :
261 : // positions and sizes are computed to always fit the language
262 0 : Size aTextSize( aText.GetOptimalSize( WINDOWSIZE_PREFERRED ) );
263 0 : Size aShowSize( aShow.GetOptimalSize( WINDOWSIZE_PREFERRED ) );
264 0 : Size aCloseSize( aClose.GetOptimalSize( WINDOWSIZE_PREFERRED ) );
265 :
266 0 : long nDelimX = 12;
267 0 : long nDelimY = 12;
268 0 : long nWidth = aTextSize.Width() + 2*nDelimX;
269 0 : long nButtonY = aTextSize.Height() + 2*nDelimY;
270 0 : Size aButtonSize( std::max( aShowSize.Width(), aCloseSize.Width() ) + nDelimX,
271 0 : std::max( aShowSize.Height(), aCloseSize.Height() ) );
272 :
273 0 : SetSizePixel( Size( nWidth, aTextSize.Height() + 3*nDelimY + aButtonSize.Height() ) );
274 0 : aText.SetPosSizePixel( Point( nDelimX, nDelimY ), aTextSize );
275 0 : aShow.SetPosSizePixel( Point( ( nWidth - nDelimX ) / 2 - aButtonSize.Width(), nButtonY ), aButtonSize );
276 0 : aClose.SetPosSizePixel( Point( aShow.GetPosPixel().X() + aButtonSize.Width() + nDelimX, nButtonY ), aButtonSize );
277 :
278 0 : aText.Show();
279 :
280 0 : FreeResource();
281 0 : }
282 :
283 0 : IMPL_LINK_NOARG(LicenseDialog, CancelHdl)
284 : {
285 0 : Close();
286 0 : return 0;
287 : }
288 :
289 0 : IMPL_LINK_NOARG(LicenseDialog, ShowHdl)
290 : {
291 0 : EndDialog(RET_OK);
292 0 : showDocument("LICENSE");
293 0 : return 0;
294 : }
295 :
296 : }
297 :
298 :
299 0 : void SfxApplication::MiscExec_Impl( SfxRequest& rReq )
300 : {
301 0 : bool bDone = false;
302 0 : switch ( rReq.GetSlot() )
303 : {
304 : case SID_SETOPTIONS:
305 : {
306 0 : if( rReq.GetArgs() )
307 0 : SetOptions_Impl( *rReq.GetArgs() );
308 0 : break;
309 : }
310 :
311 : case SID_QUITAPP:
312 : case SID_EXITANDRETURN:
313 : case SID_LOGOUT:
314 : {
315 : // protect against reentrant calls
316 0 : if ( pAppData_Impl->bInQuit )
317 : return;
318 :
319 0 : if ( rReq.GetSlot() == SID_LOGOUT )
320 : {
321 0 : for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
322 : pObjSh; pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
323 : {
324 0 : if ( !pObjSh->IsModified() )
325 0 : continue;
326 :
327 0 : SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pObjSh );
328 0 : if ( !pFrame || !pFrame->GetWindow().IsReallyVisible() )
329 0 : continue;
330 :
331 0 : if ( pObjSh->PrepareClose(2) )
332 0 : pObjSh->SetModified( sal_False );
333 : else
334 : return;
335 : }
336 :
337 0 : SfxStringItem aNameItem( SID_FILE_NAME, rtl::OUString("vnd.sun.star.cmd:logout") );
338 0 : SfxStringItem aReferer( SID_REFERER, DEFINE_CONST_UNICODE( "private/user" ) );
339 0 : pAppData_Impl->pAppDispat->Execute( SID_OPENDOC, SFX_CALLMODE_SLOT, &aNameItem, &aReferer, 0L );
340 0 : return;
341 : }
342 :
343 : // aus verschachtelten Requests nach 100ms nochmal probieren
344 0 : if( Application::GetDispatchLevel() > 1 )
345 : {
346 : /* Dont save the request for closing the application and try it later
347 : again. This is an UI bound functionality ... and the user will try it again
348 : if the dialog is closed. But we shouldnt close the application automaticly
349 : if this dialog is closed by the user ...
350 : So we ignore this request now and wait for a new user decision.
351 : */
352 : OSL_TRACE( "QueryExit => sal_False (DispatchLevel == %u)", Application::GetDispatchLevel() );
353 : return;
354 : }
355 :
356 : // block reentrant calls
357 0 : pAppData_Impl->bInQuit = sal_True;
358 0 : Reference < XDesktop > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
359 :
360 0 : rReq.ForgetAllArgs();
361 :
362 : // if terminate() failed, pAppData_Impl->bInQuit will now be sal_False, allowing further calls of SID_QUITAPP
363 0 : sal_Bool bTerminated = xDesktop->terminate();
364 0 : if (!bTerminated)
365 : // if terminate() was successful, SfxApplication is now dead!
366 0 : pAppData_Impl->bInQuit = sal_False;
367 :
368 : // Set return value, terminate if possible
369 0 : rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bTerminated ) );
370 0 : return;
371 : }
372 :
373 : case SID_CONFIG:
374 : case SID_TOOLBOXOPTIONS:
375 : case SID_CONFIGSTATUSBAR:
376 : case SID_CONFIGMENU:
377 : case SID_CONFIGACCEL:
378 : case SID_CONFIGEVENT:
379 : {
380 : SfxAbstractDialogFactory* pFact =
381 0 : SfxAbstractDialogFactory::Create();
382 :
383 0 : if ( pFact )
384 : {
385 0 : SFX_REQUEST_ARG(rReq, pStringItem,
386 : SfxStringItem, SID_CONFIG, sal_False);
387 :
388 : SfxItemSet aSet(
389 0 : GetPool(), SID_CONFIG, SID_CONFIG );
390 :
391 0 : if ( pStringItem )
392 : {
393 : aSet.Put( SfxStringItem(
394 0 : SID_CONFIG, pStringItem->GetValue() ) );
395 : }
396 :
397 0 : Reference< XFrame > xFrame;
398 0 : const SfxItemSet* pIntSet = rReq.GetInternalArgs_Impl();
399 0 : SFX_ITEMSET_ARG( pIntSet, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False );
400 0 : if ( pFrameItem )
401 0 : xFrame = pFrameItem->GetFrame();
402 :
403 : SfxAbstractTabDialog* pDlg = pFact->CreateTabDialog(
404 : RID_SVXDLG_CUSTOMIZE,
405 0 : NULL, &aSet, xFrame );
406 :
407 0 : if ( pDlg )
408 : {
409 0 : const short nRet = pDlg->Execute();
410 :
411 0 : if ( nRet )
412 0 : bDone = true;
413 :
414 0 : delete pDlg;
415 0 : }
416 : }
417 0 : break;
418 : }
419 :
420 : case SID_CLOSEDOCS:
421 : case SID_CLOSEWINS:
422 : {
423 :
424 0 : Reference < XFramesSupplier > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
425 0 : Reference< XIndexAccess > xTasks( xDesktop->getFrames(), UNO_QUERY );
426 0 : if ( !xTasks.is() )
427 : break;
428 :
429 0 : sal_Int32 n=0;
430 0 : do
431 : {
432 0 : if ( xTasks->getCount() <= n )
433 : break;
434 :
435 0 : Any aAny = xTasks->getByIndex(n);
436 0 : Reference < XCloseable > xTask;
437 0 : aAny >>= xTask;
438 : try
439 : {
440 0 : xTask->close(sal_True);
441 0 : n++;
442 : }
443 0 : catch( CloseVetoException& )
444 : {
445 0 : }
446 : }
447 : while( sal_True );
448 :
449 0 : sal_Bool bOk = ( n == 0);
450 0 : rReq.SetReturnValue( SfxBoolItem( 0, bOk ) );
451 0 : bDone = true;
452 0 : break;
453 : }
454 :
455 : case SID_SAVEDOCS:
456 : {
457 0 : sal_Bool bOK = sal_True;
458 0 : for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
459 : pObjSh;
460 : pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
461 : {
462 0 : SfxRequest aReq( SID_SAVEDOC, 0, pObjSh->GetPool() );
463 0 : if ( pObjSh->IsModified() )
464 : {
465 0 : pObjSh->ExecuteSlot( aReq );
466 0 : SfxBoolItem *pItem = PTR_CAST( SfxBoolItem, aReq.GetReturnValue() );
467 0 : if ( !pItem || !pItem->GetValue() )
468 0 : bOK = sal_False;
469 : }
470 0 : }
471 :
472 0 : rReq.SetReturnValue( SfxBoolItem( 0, bOK ) );
473 0 : rReq.Done();
474 0 : break;
475 : }
476 :
477 : case SID_SEND_FEEDBACK:
478 : {
479 0 : ::rtl::OUString module = SfxHelp::GetCurrentModuleIdentifier();
480 0 : ::rtl::OUString sURL("http://hub.libreoffice.org/send-feedback/?version=" + utl::ConfigManager::getAboutBoxProductVersion() +
481 0 : "&locale=" + utl::ConfigManager::getLocale() + "&module=" + module.copy(module.lastIndexOf(".") + 1 ) );
482 : try
483 : {
484 : uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShellExecute(
485 0 : com::sun::star::system::SystemShellExecute::create(::comphelper::getProcessComponentContext()) );
486 0 : xSystemShellExecute->execute( sURL, ::rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
487 : }
488 0 : catch ( uno::Exception& )
489 : {
490 : }
491 0 : break;
492 : }
493 :
494 : case SID_SHOW_LICENSE:
495 : {
496 0 : LicenseDialog aDialog;
497 0 : aDialog.Execute();
498 0 : break;
499 : }
500 :
501 : case SID_SHOW_CREDITS:
502 : {
503 0 : showDocument( "CREDITS" );
504 0 : break;
505 : }
506 :
507 : // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
508 : case SID_HELPINDEX:
509 : {
510 0 : Help* pHelp = Application::GetHelp();
511 0 : if ( pHelp )
512 : {
513 0 : pHelp->Start( rtl::OUString(".uno:HelpIndex"), NULL ); // show start page
514 0 : bDone = true;
515 : }
516 0 : break;
517 : }
518 :
519 : // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
520 : case SID_HELPTIPS:
521 : {
522 : // Evaluate Parameter
523 0 : SFX_REQUEST_ARG(rReq, pOnItem, SfxBoolItem, SID_HELPTIPS, sal_False);
524 : bool bOn = pOnItem
525 0 : ? ((SfxBoolItem*)pOnItem)->GetValue()
526 0 : : !Help::IsQuickHelpEnabled();
527 :
528 0 : if ( bOn )
529 0 : Help::EnableQuickHelp();
530 : else
531 0 : Help::DisableQuickHelp();
532 0 : SvtHelpOptions().SetHelpTips( bOn );
533 0 : Invalidate(SID_HELPTIPS);
534 0 : bDone = true;
535 :
536 : // Record if possible
537 0 : if ( !rReq.IsAPI() )
538 0 : rReq.AppendItem( SfxBoolItem( SID_HELPTIPS, bOn) );
539 0 : break;
540 : }
541 : // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
542 : case SID_EXTENDEDHELP:
543 : {
544 0 : Help::StartExtHelp();
545 0 : break;
546 : }
547 : case SID_HELPBALLOONS:
548 : {
549 : // Evaluate Parameter
550 0 : SFX_REQUEST_ARG(rReq, pOnItem, SfxBoolItem, SID_HELPBALLOONS, sal_False);
551 : bool bOn = pOnItem
552 0 : ? ((SfxBoolItem*)pOnItem)->GetValue()
553 0 : : !Help::IsBalloonHelpEnabled();
554 :
555 0 : if ( bOn )
556 0 : Help::EnableBalloonHelp();
557 : else
558 0 : Help::DisableBalloonHelp();
559 0 : SvtHelpOptions().SetExtendedHelp( bOn );
560 0 : Invalidate(SID_HELPBALLOONS);
561 0 : bDone = true;
562 :
563 : // Record if possible
564 0 : if ( !rReq.IsAPI() )
565 0 : rReq.AppendItem( SfxBoolItem( SID_HELPBALLOONS, bOn) );
566 0 : break;
567 : }
568 :
569 : // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
570 : case SID_HELP_PI:
571 : {
572 0 : SvtHelpOptions aHelpOpt;
573 0 : SFX_REQUEST_ARG(rReq, pOnItem, SfxBoolItem, SID_HELP_PI, sal_False);
574 : sal_Bool bOn = pOnItem
575 0 : ? ((SfxBoolItem*)pOnItem)->GetValue()
576 0 : : !aHelpOpt.IsHelpAgentAutoStartMode();
577 0 : aHelpOpt.SetHelpAgentAutoStartMode( bOn );
578 0 : Invalidate(SID_HELP_PI);
579 0 : bDone = true;
580 0 : break;
581 : }
582 :
583 : // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
584 : case SID_ABOUT:
585 : {
586 0 : SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
587 0 : if ( pFact )
588 : {
589 0 : VclAbstractDialog* pDlg = pFact->CreateVclDialog( 0, RID_DEFAULTABOUT );
590 0 : pDlg->Execute();
591 0 : delete pDlg;
592 0 : bDone = true;
593 : }
594 0 : break;
595 : }
596 :
597 : case SID_TEMPLATE_MANAGER:
598 : {
599 0 : SfxTemplateManagerDlg dlg;
600 0 : dlg.Execute();
601 0 : bDone = true;
602 0 : break;
603 : }
604 :
605 : // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
606 : case SID_ORGANIZER:
607 : {
608 : SfxTemplateOrganizeDlg *pDlg =
609 0 : new SfxTemplateOrganizeDlg(NULL);
610 0 : pDlg->Execute();
611 0 : delete pDlg;
612 0 : bDone = true;
613 0 : break;
614 : }
615 :
616 : case SID_TEMPLATE_ADDRESSBOKSOURCE:
617 : {
618 0 : svt::AddressBookSourceDialog aDialog(GetTopWindow(), ::comphelper::getProcessServiceFactory());
619 0 : aDialog.Execute();
620 0 : bDone = true;
621 0 : break;
622 : }
623 :
624 : #ifndef DISABLE_SCRIPTING
625 : case SID_BASICSTOP:
626 0 : StarBASIC::Stop();
627 0 : break;
628 :
629 : case SID_BASICBREAK :
630 0 : BASIC_DLL()->BasicBreak();
631 0 : break;
632 : #endif
633 :
634 : case SID_CRASH :
635 : {
636 : // Provoke a crash:
637 0 : char * crash = 0;
638 0 : *crash = 0;
639 0 : break;
640 : }
641 :
642 : case SID_SHOW_IME_STATUS_WINDOW:
643 0 : if (pAppData_Impl->m_xImeStatusWindow->canToggle())
644 : {
645 : SfxBoolItem const * pItem = static_cast< SfxBoolItem const * >(
646 : rReq.GetArg(SID_SHOW_IME_STATUS_WINDOW, false,
647 0 : TYPE(SfxBoolItem)));
648 : bool bShow = pItem == 0
649 0 : ? !pAppData_Impl->m_xImeStatusWindow->isShowing()
650 0 : : ( pItem->GetValue() == sal_True );
651 0 : pAppData_Impl->m_xImeStatusWindow->show(bShow);
652 0 : if (pItem == 0)
653 : rReq.AppendItem(SfxBoolItem(SID_SHOW_IME_STATUS_WINDOW,
654 0 : bShow));
655 : }
656 0 : bDone = true;
657 0 : break;
658 :
659 : case SID_ZOOM_50_PERCENT:
660 : case SID_ZOOM_75_PERCENT:
661 : case SID_ZOOM_100_PERCENT:
662 : case SID_ZOOM_150_PERCENT:
663 : case SID_ZOOM_200_PERCENT:
664 : case SID_ZOOM_OPTIMAL:
665 : case SID_ZOOM_ENTIRE_PAGE:
666 : case SID_ZOOM_PAGE_WIDTH:
667 : {
668 : // make sure aZoom is initialized with a proper value if SetType
669 : // doesn't work
670 0 : SvxZoomItem aZoom( SVX_ZOOM_PERCENT, 100 );
671 :
672 0 : switch (rReq.GetSlot())
673 : {
674 : case SID_ZOOM_50_PERCENT:
675 0 : aZoom.SetValue(50);
676 0 : break;
677 : case SID_ZOOM_75_PERCENT:
678 0 : aZoom.SetValue(75);
679 0 : break;
680 : case SID_ZOOM_100_PERCENT:
681 0 : aZoom.SetValue(100);
682 0 : break;
683 : case SID_ZOOM_150_PERCENT:
684 0 : aZoom.SetValue(150);
685 0 : break;
686 : case SID_ZOOM_200_PERCENT:
687 0 : aZoom.SetValue(200);
688 0 : break;
689 : case SID_ZOOM_OPTIMAL:
690 0 : aZoom.SetType( SVX_ZOOM_OPTIMAL );
691 0 : break;
692 : case SID_ZOOM_ENTIRE_PAGE:
693 0 : aZoom.SetType( SVX_ZOOM_WHOLEPAGE );
694 0 : break;
695 : case SID_ZOOM_PAGE_WIDTH:
696 0 : aZoom.SetType( SVX_ZOOM_PAGEWIDTH );
697 0 : break;
698 : }
699 :
700 0 : SfxViewFrame::Current()->GetDispatcher()->Execute(SID_ATTR_ZOOM, SFX_CALLMODE_ASYNCHRON, &aZoom, 0L);
701 :
702 0 : break;
703 : }
704 : case SID_AVAILABLE_TOOLBARS:
705 : {
706 : SfxStringItem const * pToolbarName = static_cast< SfxStringItem const *>(
707 0 : rReq.GetArg(SID_AVAILABLE_TOOLBARS, false, TYPE(SfxStringItem)));
708 :
709 0 : if ( pToolbarName )
710 : {
711 0 : com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame;
712 0 : Reference < XFramesSupplier > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance(
713 0 : DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
714 0 : xFrame = xDesktop->getActiveFrame();
715 :
716 0 : Reference< com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
717 0 : Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
718 0 : if ( xPropSet.is() )
719 : {
720 : try
721 : {
722 0 : Any aValue = xPropSet->getPropertyValue( rtl::OUString( "LayoutManager" ));
723 0 : aValue >>= xLayoutManager;
724 : }
725 0 : catch ( const ::com::sun::star::uno::RuntimeException& )
726 : {
727 0 : throw;
728 : }
729 0 : catch ( ::com::sun::star::uno::Exception& )
730 : {
731 : }
732 : }
733 :
734 0 : if ( xLayoutManager.is() )
735 : {
736 0 : rtl::OUString aToolbarResName( "private:resource/toolbar/" );
737 0 : rtl::OUStringBuffer aBuf( aToolbarResName );
738 0 : aBuf.append( pToolbarName->GetValue() );
739 :
740 : // Evaluate Parameter
741 0 : rtl::OUString aToolbarName( aBuf.makeStringAndClear() );
742 0 : sal_Bool bShow( !xLayoutManager->isElementVisible( aToolbarName ));
743 :
744 0 : if ( bShow )
745 : {
746 0 : xLayoutManager->createElement( aToolbarName );
747 0 : xLayoutManager->showElement( aToolbarName );
748 : }
749 : else
750 0 : xLayoutManager->hideElement( aToolbarName );
751 0 : }
752 : }
753 :
754 0 : bDone = true;
755 0 : break;
756 : }
757 :
758 : default:
759 0 : break;
760 : }
761 :
762 0 : if ( bDone )
763 0 : rReq.Done();
764 : }
765 :
766 : //--------------------------------------------------------------------
767 :
768 7 : void SfxApplication::MiscState_Impl(SfxItemSet &rSet)
769 : {
770 7 : const sal_uInt16 *pRanges = rSet.GetRanges();
771 : DBG_ASSERT(pRanges && *pRanges, "Set without range");
772 21 : while ( *pRanges )
773 : {
774 14 : for(sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich)
775 : {
776 7 : switch(nWhich)
777 : {
778 : case SID_TEMPLATE_ADDRESSBOKSOURCE:
779 0 : if ( !SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE) )
780 0 : rSet.Put(SfxVisibilityItem(nWhich, sal_False));
781 0 : break;
782 : case SID_EXITANDRETURN:
783 : case SID_QUITAPP:
784 : {
785 0 : if ( pAppData_Impl->nDocModalMode )
786 0 : rSet.DisableItem(nWhich);
787 : else
788 0 : rSet.Put(SfxStringItem(nWhich, SfxResId(STR_QUITAPP).toString()));
789 0 : break;
790 : }
791 :
792 : case SID_CONFIG:
793 : case SID_TOOLBOXOPTIONS:
794 : case SID_CONFIGSTATUSBAR:
795 : case SID_CONFIGMENU:
796 : case SID_CONFIGACCEL:
797 : case SID_CONFIGEVENT:
798 : {
799 0 : if( SvtMiscOptions().DisableUICustomization() )
800 0 : rSet.DisableItem(nWhich);
801 0 : break;
802 : }
803 :
804 : #ifndef DISABLE_SCRIPTING
805 : case SID_BASICSTOP:
806 0 : if ( !StarBASIC::IsRunning() )
807 0 : rSet.DisableItem(nWhich);
808 0 : break;
809 : #endif
810 :
811 : case SID_HELPTIPS:
812 : {
813 0 : rSet.Put( SfxBoolItem( SID_HELPTIPS, Help::IsQuickHelpEnabled() ) );
814 : }
815 0 : break;
816 : case SID_HELPBALLOONS:
817 : {
818 0 : rSet.Put( SfxBoolItem( SID_HELPBALLOONS, Help::IsBalloonHelpEnabled() ) );
819 : }
820 0 : break;
821 : case SID_HELP_PI:
822 : {
823 0 : rSet.Put( SfxBoolItem( SID_HELP_PI, SvtHelpOptions().IsHelpAgentAutoStartMode() ) );
824 : }
825 0 : break;
826 :
827 : case SID_EXTENDEDHELP:
828 : {
829 : }
830 7 : break;
831 :
832 : case SID_CLOSEDOCS:
833 : case SID_CLOSEWINS:
834 : {
835 0 : Reference < XFramesSupplier > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
836 0 : Reference< XIndexAccess > xTasks( xDesktop->getFrames(), UNO_QUERY );
837 0 : if ( !xTasks.is() || !xTasks->getCount() )
838 0 : rSet.DisableItem(nWhich);
839 0 : break;
840 : }
841 :
842 : case SID_SAVEDOCS:
843 : {
844 0 : sal_Bool bModified = sal_False;
845 0 : for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
846 : pObjSh;
847 : pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
848 : {
849 0 : if ( pObjSh->IsModified() )
850 : {
851 0 : bModified = sal_True;
852 0 : break;
853 : }
854 : }
855 :
856 0 : if ( !bModified )
857 0 : rSet.DisableItem( nWhich );
858 0 : break;
859 : }
860 :
861 : case SID_SHOW_IME_STATUS_WINDOW:
862 0 : if (pAppData_Impl->m_xImeStatusWindow->canToggle())
863 : rSet.Put(SfxBoolItem(
864 : SID_SHOW_IME_STATUS_WINDOW,
865 : pAppData_Impl->m_xImeStatusWindow->
866 0 : isShowing()));
867 : else
868 0 : rSet.DisableItem(SID_SHOW_IME_STATUS_WINDOW);
869 0 : break;
870 :
871 : case SID_TEMPLATE_MANAGER:
872 : {
873 0 : SvtMiscOptions aMiscOptions;
874 0 : if ( !aMiscOptions.IsExperimentalMode() )
875 : {
876 0 : rSet.DisableItem( nWhich );
877 0 : rSet.Put( SfxVisibilityItem( nWhich, sal_False ) );
878 0 : }
879 : }
880 0 : break;
881 :
882 : default:
883 0 : break;
884 : }
885 : }
886 :
887 7 : ++pRanges;
888 : }
889 7 : }
890 :
891 : #ifndef DISABLE_SCRIPTING
892 :
893 : #ifndef DISABLE_DYNLOADING
894 :
895 : typedef rtl_uString* (SAL_CALL *basicide_choose_macro)(XModel*, sal_Bool, rtl_uString*);
896 : typedef void (SAL_CALL *basicide_macro_organizer)( sal_Int16 );
897 :
898 0 : extern "C" { static void SAL_CALL thisModule() {} }
899 :
900 : #else
901 :
902 : extern "C" rtl_uString* basicide_choose_macro(XModel*, sal_Bool, rtl_uString*);
903 : extern "C" void basicide_macro_organizer( sal_Int16 );
904 :
905 : #endif
906 :
907 0 : ::rtl::OUString ChooseMacro( const Reference< XModel >& rxLimitToDocument, sal_Bool bChooseOnly, const ::rtl::OUString& rMacroDesc = ::rtl::OUString() )
908 : {
909 : #ifndef DISABLE_DYNLOADING
910 : // get basctl dllname
911 0 : static ::rtl::OUString aLibName( SVLIBRARY( "basctl" ) );
912 :
913 : // load module
914 : oslModule handleMod = osl_loadModuleRelative(
915 0 : &thisModule, aLibName.pData, 0 );
916 :
917 : // get symbol
918 0 : ::rtl::OUString aSymbol( "basicide_choose_macro" );
919 0 : basicide_choose_macro pSymbol = (basicide_choose_macro) osl_getFunctionSymbol( handleMod, aSymbol.pData );
920 : #else
921 : #define pSymbol basicide_choose_macro
922 : #endif
923 :
924 : // call basicide_choose_macro in basctl
925 0 : rtl_uString* pScriptURL = pSymbol( rxLimitToDocument.get(), bChooseOnly, rMacroDesc.pData );
926 0 : ::rtl::OUString aScriptURL( pScriptURL );
927 0 : rtl_uString_release( pScriptURL );
928 0 : return aScriptURL;
929 :
930 : #ifdef DISABLE_DYNLOADING
931 : #undef pSymbol
932 : #endif
933 : }
934 :
935 0 : void MacroOrganizer( sal_Int16 nTabId )
936 : {
937 : #ifndef DISABLE_DYNLOADING
938 : // get basctl dllname
939 0 : static ::rtl::OUString aLibName( SVLIBRARY( "basctl" ) );
940 :
941 : // load module
942 : oslModule handleMod = osl_loadModuleRelative(
943 0 : &thisModule, aLibName.pData, 0 );
944 :
945 : // get symbol
946 0 : ::rtl::OUString aSymbol( "basicide_macro_organizer" );
947 0 : basicide_macro_organizer pSymbol = (basicide_macro_organizer) osl_getFunctionSymbol( handleMod, aSymbol.pData );
948 : // call basicide_macro_organizer in basctl
949 0 : pSymbol( nTabId );
950 : #else
951 : basicide_macro_organizer( nTabId );
952 : #endif
953 :
954 0 : }
955 :
956 : #endif
957 :
958 :
959 : #define RID_ERRBOX_MODULENOTINSTALLED (RID_OFA_START + 72)
960 :
961 3358 : ResMgr* SfxApplication::GetOffResManager_Impl()
962 : {
963 3358 : if ( !pAppData_Impl->pOfaResMgr )
964 72 : pAppData_Impl->pOfaResMgr = CreateResManager( "ofa");
965 3358 : return pAppData_Impl->pOfaResMgr;
966 : }
967 :
968 : namespace
969 : {
970 : #ifndef DISABLE_SCRIPTING
971 0 : Window* lcl_getDialogParent( const Reference< XFrame >& _rxFrame, Window* _pFallback )
972 : {
973 0 : if ( !_rxFrame.is() )
974 0 : return _pFallback;
975 :
976 : try
977 : {
978 0 : Reference< awt::XWindow > xContainerWindow( _rxFrame->getContainerWindow(), UNO_SET_THROW );
979 0 : Window* pWindow = VCLUnoHelper::GetWindow( xContainerWindow );
980 : OSL_ENSURE( pWindow, "lcl_getDialogParent: cool, somebody implemented a VCL-less toolkit!" );
981 :
982 0 : if ( pWindow )
983 0 : return pWindow->GetSystemWindow();
984 : }
985 0 : catch( const Exception& )
986 : {
987 : DBG_UNHANDLED_EXCEPTION();
988 : }
989 0 : return _pFallback;
990 : }
991 :
992 0 : const ::rtl::OUString& lcl_getBasicIDEServiceName()
993 : {
994 0 : static const ::rtl::OUString s_sBasicName( "com.sun.star.script.BasicIDE" );
995 0 : return s_sBasicName;
996 : }
997 :
998 0 : SfxViewFrame* lcl_getBasicIDEViewFrame( SfxObjectShell* i_pBasicIDE )
999 : {
1000 0 : SfxViewFrame* pView = SfxViewFrame::GetFirst( i_pBasicIDE );
1001 0 : while ( pView )
1002 : {
1003 0 : if ( pView->GetObjectShell()->GetFactory().GetDocumentServiceName() == lcl_getBasicIDEServiceName() )
1004 0 : break;
1005 0 : pView = SfxViewFrame::GetNext( *pView, i_pBasicIDE );
1006 : }
1007 0 : return pView;
1008 : }
1009 0 : Reference< XFrame > lcl_findStartModuleFrame( const ::comphelper::ComponentContext& i_rContext )
1010 : {
1011 : try
1012 : {
1013 0 : Reference < XFramesSupplier > xSupplier( i_rContext.createComponent( "com.sun.star.frame.Desktop" ), UNO_QUERY_THROW );
1014 0 : Reference < XIndexAccess > xContainer( xSupplier->getFrames(), UNO_QUERY_THROW );
1015 :
1016 0 : Reference< XModuleManager2 > xCheck( ModuleManager::create(i_rContext.getUNOContext()) );
1017 :
1018 0 : sal_Int32 nCount = xContainer->getCount();
1019 0 : for ( sal_Int32 i=0; i<nCount; ++i )
1020 : {
1021 : try
1022 : {
1023 0 : Reference < XFrame > xFrame( xContainer->getByIndex(i), UNO_QUERY_THROW );
1024 0 : ::rtl::OUString sModule = xCheck->identify( xFrame );
1025 0 : if ( sModule == "com.sun.star.frame.StartModule" )
1026 0 : return xFrame;
1027 : }
1028 0 : catch( const UnknownModuleException& )
1029 : {
1030 : // silence
1031 : }
1032 0 : catch(const Exception&)
1033 : {
1034 : // re-throw, caught below
1035 0 : throw;
1036 : }
1037 0 : }
1038 : }
1039 0 : catch( const Exception& )
1040 : {
1041 : DBG_UNHANDLED_EXCEPTION();
1042 : }
1043 0 : return NULL;
1044 : }
1045 : #endif // !DISABLE_SCRIPTING
1046 : }
1047 :
1048 0 : static ::rtl::OUString getConfigurationStringValue(
1049 : const ::rtl::OUString& rPackage,
1050 : const ::rtl::OUString& rRelPath,
1051 : const ::rtl::OUString& rKey,
1052 : const ::rtl::OUString& rDefaultValue )
1053 : {
1054 0 : ::rtl::OUString aDefVal( rDefaultValue );
1055 :
1056 : try
1057 : {
1058 : ::comphelper::ConfigurationHelper::readDirectKey(
1059 : comphelper::getProcessComponentContext(),
1060 : rPackage,
1061 : rRelPath,
1062 : rKey,
1063 0 : ::comphelper::ConfigurationHelper::E_READONLY) >>= aDefVal;
1064 : }
1065 0 : catch(const com::sun::star::uno::RuntimeException&)
1066 0 : { throw; }
1067 0 : catch(const com::sun::star::uno::Exception&)
1068 : {}
1069 :
1070 0 : return aDefVal;
1071 : }
1072 :
1073 0 : void SfxApplication::OfaExec_Impl( SfxRequest& rReq )
1074 : {
1075 0 : switch ( rReq.GetSlot() )
1076 : {
1077 : case SID_OPTIONS_TREEDIALOG:
1078 : {
1079 0 : String sPageURL;
1080 0 : SFX_REQUEST_ARG( rReq, pURLItem, SfxStringItem, SID_OPTIONS_PAGEURL, sal_False );
1081 0 : if ( pURLItem )
1082 0 : sPageURL = pURLItem->GetValue();
1083 0 : const SfxItemSet* pArgs = rReq.GetInternalArgs_Impl();
1084 0 : const SfxPoolItem* pItem = NULL;
1085 0 : Reference < XFrame > xFrame;
1086 0 : if ( pArgs && pArgs->GetItemState( SID_FILLFRAME, sal_False, &pItem ) == SFX_ITEM_SET )
1087 : {
1088 : OSL_ENSURE( pItem->ISA( SfxUnoFrameItem ), "SfxApplication::OfaExec_Impl: XFrames are to be transported via SfxUnoFrameItem by now!" );
1089 0 : xFrame = static_cast< const SfxUnoFrameItem*>( pItem )->GetFrame();
1090 : }
1091 0 : SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1092 0 : if ( pFact )
1093 : {
1094 : VclAbstractDialog* pDlg =
1095 0 : pFact->CreateFrameDialog( NULL, xFrame, rReq.GetSlot(), sPageURL );
1096 0 : short nRet = pDlg->Execute();
1097 0 : delete pDlg;
1098 0 : SfxViewFrame* pView = SfxViewFrame::GetFirst();
1099 0 : while ( pView )
1100 : {
1101 0 : if (nRet == RET_OK)
1102 : {
1103 0 : SfxObjectShell* pObjSh = pView->GetObjectShell();
1104 0 : if (pObjSh)
1105 0 : pObjSh->SetConfigOptionsChecked(false);
1106 : }
1107 0 : pView->GetBindings().InvalidateAll(sal_False);
1108 0 : pView = SfxViewFrame::GetNext( *pView );
1109 : }
1110 : }
1111 0 : break;
1112 : }
1113 :
1114 : case SID_MORE_DICTIONARIES:
1115 : {
1116 : try
1117 : {
1118 : uno::Reference< lang::XMultiServiceFactory > xSMGR =
1119 0 : ::comphelper::getProcessServiceFactory();
1120 : uno::Reference< uno::XComponentContext > xContext =
1121 0 : ::comphelper::getProcessComponentContext();
1122 : uno::Reference< css::system::XSystemShellExecute > xSystemShell(
1123 0 : css::system::SystemShellExecute::create(xContext) );
1124 :
1125 : // read repository URL from configuration
1126 : ::rtl::OUString sTemplRepoURL =
1127 : getConfigurationStringValue(
1128 : ::rtl::OUString("org.openoffice.Office.Common"),
1129 : ::rtl::OUString("Dictionaries"),
1130 : ::rtl::OUString("RepositoryURL"),
1131 0 : ::rtl::OUString());
1132 :
1133 0 : if ( xSystemShell.is() && !sTemplRepoURL.isEmpty() )
1134 : {
1135 0 : ::rtl::OUStringBuffer aURLBuf( sTemplRepoURL );
1136 0 : aURLBuf.appendAscii(RTL_CONSTASCII_STRINGPARAM("?lang="));
1137 :
1138 : // read locale from configuration
1139 : ::rtl::OUString sLocale = getConfigurationStringValue(
1140 : ::rtl::OUString("org.openoffice.Setup"),
1141 : ::rtl::OUString("L10N"),
1142 : ::rtl::OUString("ooLocale"),
1143 0 : ::rtl::OUString("en-US"));
1144 :
1145 0 : aURLBuf.append( sLocale );
1146 0 : xSystemShell->execute(
1147 : aURLBuf.makeStringAndClear(),
1148 : ::rtl::OUString(),
1149 0 : css::system::SystemShellExecuteFlags::URIS_ONLY );
1150 0 : }
1151 : }
1152 0 : catch( const ::com::sun::star::uno::Exception& )
1153 : {
1154 : SAL_WARN( "sfx2.appl", "SfxApplication::OfaExec_Impl(SID_MORE_DICTIONARIES): caught an exception!" );
1155 : }
1156 0 : break;
1157 : }
1158 : #ifndef DISABLE_SCRIPTING
1159 : case SID_BASICIDE_APPEAR:
1160 : {
1161 0 : SfxViewFrame* pView = lcl_getBasicIDEViewFrame( NULL );
1162 0 : if ( !pView )
1163 : {
1164 0 : SfxObjectShell* pBasicIDE = SfxObjectShell::CreateObject( lcl_getBasicIDEServiceName() );
1165 0 : pBasicIDE->DoInitNew( 0 );
1166 0 : pBasicIDE->SetModified( sal_False );
1167 : try
1168 : {
1169 : // load the Basic IDE via direct access to the SFX frame loader. A generic loadComponentFromURL
1170 : // (which could be done via SfxViewFrame::LoadDocumentIntoFrame) is not feasible here, since the Basic IDE
1171 : // does not really play nice with the framework's concept. For instance, it is a "singleton document",
1172 : // which conflicts, at the latest, with the framework's concept of loading into _blank frames.
1173 : // So, since we know that our frame loader can handle it, we skip the generic framework loader
1174 : // mechanism, and the type detection (which doesn't know about the Basic IDE).
1175 0 : ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
1176 : Reference< XSynchronousFrameLoader > xLoader( aContext.createComponent(
1177 0 : SfxFrameLoader_Impl::impl_getStaticImplementationName() ), UNO_QUERY_THROW );
1178 0 : ::comphelper::NamedValueCollection aLoadArgs;
1179 0 : aLoadArgs.put( "Model", pBasicIDE->GetModel() );
1180 0 : aLoadArgs.put( "URL", ::rtl::OUString( "private:factory/sbasic" ) );
1181 :
1182 0 : Reference< XFrame > xTargetFrame( lcl_findStartModuleFrame( aContext ) );
1183 0 : if ( !xTargetFrame.is() )
1184 0 : xTargetFrame = SfxFrame::CreateBlankFrame();
1185 0 : ENSURE_OR_THROW( xTargetFrame.is(), "could not obtain a frameto load the Basic IDE into!" );
1186 :
1187 0 : xLoader->load( aLoadArgs.getPropertyValues(), xTargetFrame );
1188 : }
1189 0 : catch( const Exception& )
1190 : {
1191 : DBG_UNHANDLED_EXCEPTION();
1192 : }
1193 :
1194 0 : pView = lcl_getBasicIDEViewFrame( pBasicIDE );
1195 0 : if ( pView )
1196 0 : pView->SetName( String( RTL_CONSTASCII_USTRINGPARAM( "BASIC:1" ) ) );
1197 : }
1198 :
1199 0 : if ( pView )
1200 0 : pView->GetFrame().Appear();
1201 :
1202 0 : const SfxItemSet* pArgs = rReq.GetArgs();
1203 0 : if ( pArgs && pView )
1204 : {
1205 0 : SfxViewShell* pViewShell = pView->GetViewShell();
1206 0 : SfxObjectShell* pObjShell = pView->GetObjectShell();
1207 0 : if ( pViewShell && pObjShell )
1208 : {
1209 0 : SfxRequest aReq( SID_BASICIDE_SHOWWINDOW, SFX_CALLMODE_SYNCHRON, pObjShell->GetPool() );
1210 0 : aReq.SetArgs( *pArgs );
1211 0 : pViewShell->ExecuteSlot( aReq );
1212 : }
1213 : }
1214 :
1215 0 : rReq.Done();
1216 : }
1217 0 : break;
1218 :
1219 : case SID_BASICCHOOSER:
1220 : {
1221 0 : const SfxItemSet* pArgs = rReq.GetArgs();
1222 : const SfxPoolItem* pItem;
1223 0 : sal_Bool bChooseOnly = sal_False;
1224 0 : Reference< XModel > xLimitToModel;
1225 0 : if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_RECORDMACRO, sal_False, &pItem) )
1226 : {
1227 0 : sal_Bool bRecord = ((SfxBoolItem*)pItem)->GetValue();
1228 0 : if ( bRecord )
1229 : {
1230 : // !Hack
1231 0 : bChooseOnly = sal_False;
1232 0 : SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
1233 : OSL_ENSURE( pCurrentShell, "macro recording outside an SFX document?" );
1234 0 : if ( pCurrentShell )
1235 0 : xLimitToModel = pCurrentShell->GetModel();
1236 : }
1237 : }
1238 :
1239 0 : rReq.SetReturnValue( SfxStringItem( rReq.GetSlot(), ChooseMacro( xLimitToModel, bChooseOnly ) ) );
1240 0 : rReq.Done();
1241 : }
1242 0 : break;
1243 :
1244 : case SID_MACROORGANIZER:
1245 : {
1246 : OSL_TRACE("handling SID_MACROORGANIZER");
1247 0 : const SfxItemSet* pArgs = rReq.GetArgs();
1248 : const SfxPoolItem* pItem;
1249 0 : sal_Int16 nTabId = 0;
1250 0 : if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_MACROORGANIZER, sal_False, &pItem) )
1251 : {
1252 0 : nTabId = ((SfxUInt16Item*)pItem)->GetValue();
1253 : }
1254 :
1255 0 : SfxApplication::MacroOrganizer( nTabId );
1256 0 : rReq.Done();
1257 : }
1258 0 : break;
1259 :
1260 : case SID_RUNMACRO:
1261 : {
1262 0 : SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1263 : OSL_TRACE("SfxApplication::OfaExec_Impl: case ScriptOrg");
1264 :
1265 0 : Reference< XFrame > xFrame;
1266 0 : const SfxItemSet* pIntSet = rReq.GetInternalArgs_Impl();
1267 0 : SFX_ITEMSET_ARG( pIntSet, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False );
1268 0 : if ( pFrameItem )
1269 0 : xFrame = pFrameItem->GetFrame();
1270 :
1271 0 : if ( !xFrame.is() )
1272 : {
1273 0 : const SfxViewFrame* pViewFrame = SfxViewFrame::Current();
1274 0 : if ( pViewFrame )
1275 0 : xFrame = pViewFrame->GetFrame().GetFrameInterface();
1276 : }
1277 :
1278 : do // artificial loop for flow control
1279 : {
1280 : AbstractScriptSelectorDialog* pDlg = pFact->CreateScriptSelectorDialog(
1281 0 : lcl_getDialogParent( xFrame, GetTopWindow() ), sal_False, xFrame );
1282 : OSL_ENSURE( pDlg, "SfxApplication::OfaExec_Impl( SID_RUNMACRO ): no dialog!" );
1283 0 : if ( !pDlg )
1284 : break;
1285 0 : pDlg->SetRunLabel();
1286 :
1287 0 : short nDialogResult = pDlg->Execute();
1288 0 : if ( !nDialogResult )
1289 : {
1290 0 : delete pDlg;
1291 : break;
1292 : }
1293 :
1294 0 : Sequence< Any > args;
1295 0 : Sequence< sal_Int16 > outIndex;
1296 0 : Sequence< Any > outArgs;
1297 0 : Any ret;
1298 :
1299 0 : Reference< XInterface > xScriptContext;
1300 :
1301 0 : Reference< XController > xController;
1302 0 : if ( xFrame.is() )
1303 0 : xController = xFrame->getController();
1304 0 : if ( xController.is() )
1305 0 : xScriptContext = xController->getModel();
1306 0 : if ( !xScriptContext.is() )
1307 0 : xScriptContext = xController;
1308 :
1309 0 : SfxObjectShell::CallXScript( xScriptContext, pDlg->GetScriptURL(), args, ret, outIndex, outArgs );
1310 0 : delete pDlg;
1311 : }
1312 : while ( false );
1313 0 : rReq.Done();
1314 : }
1315 0 : break;
1316 :
1317 : case SID_SCRIPTORGANIZER:
1318 : {
1319 0 : SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1320 : OSL_TRACE("SfxApplication::OfaExec_Impl: case ScriptOrg");
1321 0 : const SfxItemSet* pArgs = rReq.GetArgs();
1322 : const SfxPoolItem* pItem;
1323 0 : String aLanguage;
1324 0 : if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_SCRIPTORGANIZER, sal_False, &pItem) )
1325 : {
1326 0 : aLanguage = ((SfxScriptOrganizerItem*)pItem)->getLanguage();
1327 : }
1328 :
1329 0 : ::rtl::OUString aLang( aLanguage );
1330 : OSL_TRACE("SfxApplication::OfaExec_Impl: about to create dialog for: %s", ::rtl::OUStringToOString( aLang , RTL_TEXTENCODING_ASCII_US ).pData->buffer);
1331 : // not sure about the Window*
1332 0 : VclAbstractDialog* pDlg = pFact->CreateSvxScriptOrgDialog( GetTopWindow(), aLanguage );
1333 0 : if( pDlg )
1334 : {
1335 0 : pDlg->Execute();
1336 0 : delete pDlg;
1337 : }
1338 : else
1339 : {
1340 : OSL_TRACE("no dialog!!!");
1341 : }
1342 0 : rReq.Done();
1343 : }
1344 0 : break;
1345 : #endif // !DISABLE_SCRIPTING
1346 :
1347 : case SID_OFFICE_CHECK_PLZ:
1348 : {
1349 0 : sal_Bool bRet = sal_False;
1350 0 : SFX_REQUEST_ARG(rReq, pStringItem, SfxStringItem, rReq.GetSlot(), sal_False);
1351 :
1352 0 : if ( pStringItem )
1353 : {
1354 0 : String aPLZ = pStringItem->GetValue();
1355 0 : bRet = sal_True /*!!!SfxIniManager::CheckPLZ( aPLZ )*/;
1356 : }
1357 : #ifndef DISABLE_SCRIPTING
1358 : else
1359 0 : SbxBase::SetError( SbxERR_WRONG_ARGS );
1360 : #endif
1361 0 : rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bRet ) );
1362 : }
1363 0 : break;
1364 :
1365 : case SID_AUTO_CORRECT_DLG:
1366 : {
1367 0 : SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1368 0 : if ( pFact )
1369 : {
1370 0 : SfxItemSet aSet(GetPool(), SID_AUTO_CORRECT_DLG, SID_AUTO_CORRECT_DLG);
1371 0 : const SfxPoolItem* pItem=NULL;
1372 0 : const SfxItemSet* pSet = rReq.GetArgs();
1373 0 : SfxItemPool* pSetPool = pSet ? pSet->GetPool() : NULL;
1374 0 : if ( pSet && pSet->GetItemState( pSetPool->GetWhich( SID_AUTO_CORRECT_DLG ), sal_False, &pItem ) == SFX_ITEM_SET )
1375 0 : aSet.Put( *pItem );
1376 :
1377 0 : SfxAbstractTabDialog* pDlg = pFact->CreateTabDialog( RID_OFA_AUTOCORR_DLG, NULL, &aSet, NULL );
1378 0 : pDlg->Execute();
1379 0 : delete pDlg;
1380 : }
1381 :
1382 0 : break;
1383 : }
1384 :
1385 : case SID_SD_AUTOPILOT :
1386 : case SID_NEWSD :
1387 : {
1388 0 : SvtModuleOptions aModuleOpt;
1389 0 : if ( !aModuleOpt.IsImpress() )
1390 : {
1391 0 : ErrorBox( 0, ResId( RID_ERRBOX_MODULENOTINSTALLED, *GetOffResManager_Impl() )).Execute();
1392 0 : return;
1393 : }
1394 :
1395 0 : Reference< com::sun::star::lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
1396 0 : Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
1397 : Reference< com::sun::star::frame::XDispatchProvider > xProv(
1398 0 : xORB->createInstance( ::rtl::OUString("com.sun.star.drawing.ModuleDispatcher")), UNO_QUERY );
1399 :
1400 0 : if ( xProv.is() )
1401 : {
1402 0 : ::rtl::OUString aCmd = ::rtl::OUString::createFromAscii( GetInterface()->GetSlot( rReq.GetSlot() )->GetUnoName() );
1403 0 : Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) );
1404 0 : Sequence < com::sun::star::beans::PropertyValue > aSeq;
1405 0 : if ( rReq.GetArgs() )
1406 0 : TransformItems( rReq.GetSlot(), *rReq.GetArgs(), aSeq );
1407 0 : Any aResult = xHelper->executeDispatch( xProv, aCmd, ::rtl::OUString(), 0, aSeq );
1408 0 : ::com::sun::star::frame::DispatchResultEvent aEvent;
1409 : sal_Bool bSuccess = (
1410 0 : (aResult >>= aEvent) &&
1411 : (aEvent.State == ::com::sun::star::frame::DispatchResultState::SUCCESS)
1412 0 : );
1413 0 : rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bSuccess ) );
1414 0 : }
1415 : }
1416 0 : break;
1417 :
1418 : case FN_LABEL :
1419 : case FN_BUSINESS_CARD :
1420 : case FN_XFORMS_INIT :
1421 : {
1422 0 : Reference< com::sun::star::lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
1423 0 : Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
1424 : Reference< com::sun::star::frame::XDispatchProvider > xProv(
1425 0 : xORB->createInstance( ::rtl::OUString("com.sun.star.text.ModuleDispatcher")), UNO_QUERY );
1426 :
1427 0 : if ( xProv.is() )
1428 : {
1429 0 : ::rtl::OUString aCmd = ::rtl::OUString::createFromAscii( GetInterface()->GetSlot( rReq.GetSlot() )->GetUnoName() );
1430 0 : Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) );
1431 0 : Sequence < com::sun::star::beans::PropertyValue > aSeq;
1432 0 : if ( rReq.GetArgs() )
1433 0 : TransformItems( rReq.GetSlot(), *rReq.GetArgs(), aSeq );
1434 0 : Any aResult = xHelper->executeDispatch( xProv, aCmd, ::rtl::OUString(), 0, aSeq );
1435 0 : ::com::sun::star::frame::DispatchResultEvent aEvent;
1436 : sal_Bool bSuccess = (
1437 0 : (aResult >>= aEvent) &&
1438 : (aEvent.State == ::com::sun::star::frame::DispatchResultState::SUCCESS)
1439 0 : );
1440 0 : rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bSuccess ) );
1441 0 : }
1442 : }
1443 0 : break;
1444 :
1445 : case SID_ADDRESS_DATA_SOURCE:
1446 : {
1447 0 : ::rtl::OUString sDialogServiceName( "com.sun.star.ui.dialogs.AddressBookSourcePilot" );
1448 : try
1449 : {
1450 0 : Reference< com::sun::star::lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
1451 0 : Reference< com::sun::star::ui::dialogs::XExecutableDialog > xDialog;
1452 0 : if (xORB.is())
1453 0 : xDialog = Reference< com::sun::star::ui::dialogs::XExecutableDialog >(xORB->createInstance(sDialogServiceName), UNO_QUERY);
1454 0 : if (xDialog.is())
1455 0 : xDialog->execute();
1456 : else
1457 0 : ShowServiceNotAvailableError(NULL, sDialogServiceName, sal_True);
1458 : }
1459 0 : catch(::com::sun::star::uno::Exception&)
1460 : {
1461 0 : }
1462 : }
1463 0 : break;
1464 :
1465 : case SID_COMP_BIBLIOGRAPHY:
1466 0 : lcl_tryLoadBibliography();
1467 0 : break;
1468 : }
1469 : }
1470 :
1471 0 : void SfxApplication::OfaState_Impl(SfxItemSet &rSet)
1472 : {
1473 0 : SvtModuleOptions aModuleOpt;
1474 :
1475 0 : if( !aModuleOpt.IsWriter())
1476 : {
1477 0 : rSet.DisableItem( FN_LABEL );
1478 0 : rSet.DisableItem( FN_BUSINESS_CARD );
1479 0 : rSet.DisableItem( FN_XFORMS_INIT );
1480 : }
1481 :
1482 0 : if ( !aModuleOpt.IsImpress() )
1483 0 : rSet.DisableItem( SID_SD_AUTOPILOT );
1484 234 : }
1485 :
1486 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|