Kaydet (Commit) 2a9c1d1a authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Make dialogs fail with an exception in headless tests.

üst f547b2c4
......@@ -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 )
{
......
......@@ -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 );
}
/*-****************************************************************************************************//**
......
......@@ -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 );
......
......@@ -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
......
......@@ -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);
......
......@@ -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: */
......@@ -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
......
......@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment