diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2011-12-06 20:27:29 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2011-12-06 20:28:56 +0100 |
commit | 2a9c1d1a75b7d4e79dfbc6be3dada1a1e959e58e (patch) | |
tree | a1f99c2b4ab4806bc117d8552fbd2e8472bf4e90 | |
parent | f547b2c4788439380c3202407c251153be0c5b8e (diff) |
Make dialogs fail with an exception in headless tests.
-rw-r--r-- | desktop/source/app/appinit.cxx | 2 | ||||
-rw-r--r-- | framework/source/services/frame.cxx | 9 | ||||
-rw-r--r-- | test/source/bootstrapfixture.cxx | 3 | ||||
-rw-r--r-- | vcl/inc/svdata.hxx | 3 | ||||
-rw-r--r-- | vcl/inc/vcl/svapp.hxx | 29 | ||||
-rw-r--r-- | vcl/source/app/svapp.cxx | 33 | ||||
-rw-r--r-- | vcl/source/window/dialog.cxx | 26 | ||||
-rw-r--r-- | vcl/unx/generic/desktopdetect/desktopdetector.cxx | 16 |
8 files changed, 85 insertions, 36 deletions
diff --git a/desktop/source/app/appinit.cxx b/desktop/source/app/appinit.cxx index 31c0cf91b65f..89641857c82d 100644 --- a/desktop/source/app/appinit.cxx +++ b/desktop/source/app/appinit.cxx @@ -237,7 +237,7 @@ void Desktop::RegisterServices( Reference< XMultiServiceFactory >& xSMgr ) // Headless mode for FAT Office bHeadlessMode = rCmdLine.IsHeadless(); if ( bHeadlessMode ) - Application::EnableHeadlessMode(); + Application::EnableHeadlessMode(false); if ( conDcp.getLength() > 0 ) { diff --git a/framework/source/services/frame.cxx b/framework/source/services/frame.cxx index a24404ffab1a..90d47d43d4c4 100644 --- a/framework/source/services/frame.cxx +++ b/framework/source/services/frame.cxx @@ -1887,10 +1887,9 @@ void SAL_CALL Frame::dispose() throw( css::uno::RuntimeException ) // (a) Do it after stopWindowListening(). May that force some active/deactive // notifications which we doesn't need here realy. // (b) Don't forget to save the old value of IsDialogCancelEnabled() to - // restore it afterwards. We cannot call EnableDialogCancel( sal_False ) - // as we would kill the headless mode! - sal_Bool bCancelDialogs( Application::IsDialogCancelEnabled() ); - Application::EnableDialogCancel( sal_True ); + // restore it afterwards (to not kill headless mode). + Application::DialogCancelMode old = Application::GetDialogCancelMode(); + Application::SetDialogCancelMode( Application::DIALOG_CANCEL_SILENT ); // We should be alone for ever and further dispose calls are rejected by lines before ... // I hope it :-) @@ -1969,7 +1968,7 @@ void SAL_CALL Frame::dispose() throw( css::uno::RuntimeException ) // Don't forget it restore old value - // otherwhise no dialogs can be shown anymore in other frames. - Application::EnableDialogCancel( bCancelDialogs ); + Application::SetDialogCancelMode( old ); } /*-****************************************************************************************************//** diff --git a/test/source/bootstrapfixture.cxx b/test/source/bootstrapfixture.cxx index c059d3a0df60..284dbf7f3210 100644 --- a/test/source/bootstrapfixture.cxx +++ b/test/source/bootstrapfixture.cxx @@ -96,6 +96,9 @@ void test::BootstrapFixture::setUp() aLocalOptions.SetUILocaleConfigString( aLangISO ); InitVCL(m_xSFactory); + if (Application::IsHeadlessModeRequested()) { + Application::EnableHeadlessMode(true); + } if( m_bAssertOnDialog ) ErrorHandler::RegisterDisplay( aBasicErrorFunc ); diff --git a/vcl/inc/svdata.hxx b/vcl/inc/svdata.hxx index 6cb48900c386..82a5aae7980f 100644 --- a/vcl/inc/svdata.hxx +++ b/vcl/inc/svdata.hxx @@ -42,6 +42,7 @@ #include "vcl/vclevent.hxx" #include "vcl/sv.h" +#include "vcl/svapp.hxx" #include "vcl/dllapi.h" #include "unotools/options.hxx" @@ -167,9 +168,9 @@ struct ImplSVAppData sal_Bool mbInAppExecute; // is Application::Execute() on stack sal_Bool mbAppQuit; // is Application::Quit() called sal_Bool mbSettingsInit; // sal_True: Settings are initialized - sal_Bool mbDialogCancel; // sal_True: Alle Dialog::Execute()-Aufrufe werden mit return sal_False sofort beendet sal_Bool mbNoYield; // Application::Yield will not wait for events if the queue is empty // essentially that makes it the same as Application::Reschedule + Application::DialogCancelMode meDialogCancel; // sal_True: Alle Dialog::Execute()-Aufrufe werden mit return sal_False sofort beendet long mnDefaultLayoutBorder; // default value in pixel for layout distances used // in window arrangers diff --git a/vcl/inc/vcl/svapp.hxx b/vcl/inc/vcl/svapp.hxx index 0350ee5f3c63..cfd46eddac6a 100644 --- a/vcl/inc/vcl/svapp.hxx +++ b/vcl/inc/vcl/svapp.hxx @@ -29,6 +29,10 @@ #ifndef _SV_SVAPP_HXX #define _SV_SVAPP_HXX +#include <sal/config.h> + +#include <stdexcept> + #include <osl/thread.hxx> #include <osl/mutex.hxx> #include <tools/string.hxx> @@ -140,6 +144,23 @@ public: class VCL_DLLPUBLIC Application { public: + enum DialogCancelMode { + DIALOG_CANCEL_OFF, ///< do not automatically cancel dialogs + DIALOG_CANCEL_SILENT, ///< silently cancel any dialogs + DIALOG_CANCEL_FATAL + ///< cancel any dialogs by throwing a DialogCancelledException + }; + + class VCL_DLLPUBLIC DialogCancelledException: + virtual public std::runtime_error + { + public: + explicit DialogCancelledException(char const * what_arg): + runtime_error(what_arg) {} + + virtual ~DialogCancelledException() throw (); + }; + Application(); virtual ~Application(); @@ -302,7 +323,8 @@ public: static void SetDefDialogParent( Window* pWindow ); static Window* GetDefDialogParent(); - static void EnableDialogCancel( sal_Bool bDialogCancel = sal_True ); + static DialogCancelMode GetDialogCancelMode(); + static void SetDialogCancelMode( DialogCancelMode mode ); static sal_Bool IsDialogCancelEnabled(); static void SetSystemWindowMode( sal_uInt16 nMode ); @@ -320,9 +342,12 @@ public: static void SetFilterHdl( const Link& rLink ); static const Link& GetFilterHdl(); - static void EnableHeadlessMode( sal_Bool bEnable = sal_True ); + static void EnableHeadlessMode( bool dialogsAreFatal ); static sal_Bool IsHeadlessModeEnabled(); + static bool IsHeadlessModeRequested(); + ///< check command line arguments for --headless + static void ShowNativeErrorBox(const String& sTitle , const String& sMessage); diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx index 6c70e10d45ec..44a08442ecc1 100644 --- a/vcl/source/app/svapp.cxx +++ b/vcl/source/app/svapp.cxx @@ -37,7 +37,7 @@ #include "rtl/tencinfo.h" #include "rtl/instance.hxx" - +#include "rtl/process.h" #include "tools/tools.h" #include "tools/debug.hxx" @@ -1539,16 +1539,21 @@ Window* Application::GetDefDialogParent() // ----------------------------------------------------------------------- -void Application::EnableDialogCancel( sal_Bool bDialogCancel ) +Application::DialogCancelMode Application::GetDialogCancelMode() +{ + return ImplGetSVData()->maAppData.meDialogCancel; +} + +void Application::SetDialogCancelMode( DialogCancelMode mode ) { - ImplGetSVData()->maAppData.mbDialogCancel = bDialogCancel; + ImplGetSVData()->maAppData.meDialogCancel = mode; } // ----------------------------------------------------------------------- sal_Bool Application::IsDialogCancelEnabled() { - return ImplGetSVData()->maAppData.mbDialogCancel; + return ImplGetSVData()->maAppData.meDialogCancel != DIALOG_CANCEL_OFF; } // ----------------------------------------------------------------------- @@ -1765,9 +1770,10 @@ const LocaleDataWrapper& Application::GetAppLocaleDataWrapper() // ----------------------------------------------------------------------- -void Application::EnableHeadlessMode( sal_Bool bEnable ) +void Application::EnableHeadlessMode( bool dialogsAreFatal ) { - EnableDialogCancel( bEnable ); + SetDialogCancelMode( + dialogsAreFatal ? DIALOG_CANCEL_FATAL : DIALOG_CANCEL_SILENT ); } // ----------------------------------------------------------------------- @@ -1777,6 +1783,19 @@ sal_Bool Application::IsHeadlessModeEnabled() return IsDialogCancelEnabled(); } +bool Application::IsHeadlessModeRequested() +{ + sal_uInt32 n = rtl_getAppCommandArgCount(); + for (sal_uInt32 i = 0; i < n; ++i) { + rtl::OUString arg; + rtl_getAppCommandArg(i, &arg.pData); + if (arg.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("--headless"))) { + return true; + } + } + return false; +} + // ----------------------------------------------------------------------- void Application::ShowNativeErrorBox(const String& sTitle , @@ -1902,4 +1921,6 @@ Application::createFolderPicker( const Reference< uno::XComponentContext >& xSM return pSVData->mpDefInst->createFolderPicker( xSM ); } +Application::DialogCancelledException::~DialogCancelledException() throw () {} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx index 751ef29d047e..7fed9bb85172 100644 --- a/vcl/source/window/dialog.cxx +++ b/vcl/source/window/dialog.cxx @@ -34,6 +34,7 @@ #include <brdwin.hxx> #include <rtl/strbuf.hxx> +#include <sal/log.hxx> #include <vcl/svapp.hxx> #include <vcl/event.hxx> @@ -53,8 +54,6 @@ // ======================================================================= -#ifdef DBG_UTIL - static rtl::OString ImplGetDialogText( Dialog* pDialog ) { rtl::OStringBuffer aErrorStr(rtl::OUStringToOString( @@ -72,8 +71,6 @@ static rtl::OString ImplGetDialogText( Dialog* pDialog ) return aErrorStr.makeStringAndClear(); } -#endif - // ======================================================================= static sal_Bool ImplIsMnemonicCtrl( Window* pWindow ) @@ -610,15 +607,22 @@ sal_Bool Dialog::ImplStartExecuteModal() return sal_False; } - if ( Application::IsDialogCancelEnabled() ) + switch ( Application::GetDialogCancelMode() ) { -#ifdef DBG_UTIL - rtl::OStringBuffer aErrorStr; - aErrorStr.append(RTL_CONSTASCII_STRINGPARAM("Dialog::StartExecuteModal() is called in a none UI application: ")); - aErrorStr.append(ImplGetDialogText(this)); - OSL_FAIL(aErrorStr.getStr()); -#endif + case Application::DIALOG_CANCEL_OFF: + break; + case Application::DIALOG_CANCEL_SILENT: + SAL_INFO( + "vcl", + "Dialog \"" << ImplGetDialogText(this).getStr() + << "\"cancelled in silent mode"); return sal_False; + default: + assert(false); // this cannot happen + // fall through + case Application::DIALOG_CANCEL_FATAL: + throw Application::DialogCancelledException( + ImplGetDialogText(this).getStr()); } #ifdef DBG_UTIL diff --git a/vcl/unx/generic/desktopdetect/desktopdetector.cxx b/vcl/unx/generic/desktopdetect/desktopdetector.cxx index 601ccafedd26..1e4636ee69a8 100644 --- a/vcl/unx/generic/desktopdetect/desktopdetector.cxx +++ b/vcl/unx/generic/desktopdetect/desktopdetector.cxx @@ -33,10 +33,11 @@ #include <X11/Xatom.h> #include <tools/postx.h> +#include "rtl/process.h" #include "rtl/ustrbuf.hxx" #include "osl/module.h" -#include "osl/process.h" #include "osl/thread.h" +#include "vcl/svapp.hxx" #include "vclpluginapi.h" @@ -251,22 +252,17 @@ DESKTOP_DETECTOR_PUBLIC DesktopType get_desktop_environment() const char* pUsePlugin = getenv( "SAL_USE_VCLPLUGIN" ); - if (pUsePlugin && (strcmp(pUsePlugin, "svp") == 0)) + if ((pUsePlugin && (strcmp(pUsePlugin, "svp") == 0)) + || Application::IsHeadlessModeRequested()) pDisplayStr = NULL; else { - int nParams = osl_getCommandArgCount(); + int nParams = rtl_getAppCommandArgCount(); OUString aParam; OString aBParm; for( int i = 0; i < nParams; i++ ) { - osl_getCommandArg( i, &aParam.pData ); - if( aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-headless" ) ) || - aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "--headless" ) ) ) - { - pDisplayStr = NULL; - break; - } + rtl_getAppCommandArg( i, &aParam.pData ); if( i < nParams-1 && (aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-display" ) ) || aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "--display" ) )) ) { osl_getCommandArg( i+1, &aParam.pData ); |