2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-07-11 09:51:50 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2014-11-14 22:52:35 +01:00
|
|
|
#include <osl/diagnose.h>
|
2017-04-21 21:04:34 +10:00
|
|
|
#include <rtl/strbuf.hxx>
|
|
|
|
|
|
|
|
#include <vcl/errinf.hxx>
|
2015-03-09 14:29:30 +02:00
|
|
|
#include <vcl/window.hxx>
|
2017-04-21 21:04:34 +10:00
|
|
|
|
2016-04-22 14:30:48 +02:00
|
|
|
#include <vector>
|
2017-04-21 21:04:34 +10:00
|
|
|
#include <limits.h>
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
class ErrorHandler;
|
2017-04-23 22:01:46 +10:00
|
|
|
class TheErrorRegistry: public rtl::Static<ErrorRegistry, TheErrorRegistry> {};
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2017-04-24 02:13:30 +10:00
|
|
|
class ErrorStringFactory
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2017-04-24 02:13:30 +10:00
|
|
|
public:
|
|
|
|
static bool CreateString(const ErrorInfo*, OUString&);
|
|
|
|
};
|
2015-07-06 22:49:48 +02:00
|
|
|
|
2017-04-24 02:13:30 +10:00
|
|
|
bool ErrorStringFactory::CreateString(const ErrorInfo* pInfo, OUString& rStr)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2017-04-24 02:13:30 +10:00
|
|
|
for(const ErrorHandler *pHdlr : TheErrorRegistry::get().errorHandlers)
|
|
|
|
{
|
|
|
|
if(pHdlr->CreateString(pInfo, rStr))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2017-04-14 07:48:03 +10:00
|
|
|
ErrorRegistry::ErrorRegistry()
|
2016-04-22 14:30:48 +02:00
|
|
|
: pDsp(nullptr)
|
2014-03-10 12:45:00 +00:00
|
|
|
, bIsWindowDsp(false)
|
2017-04-18 12:58:50 +10:00
|
|
|
, nNextError(0)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2017-04-14 07:55:15 +10:00
|
|
|
for(DynamicErrorInfo*& rp : ppDynErrInfo)
|
2016-05-12 10:05:54 +02:00
|
|
|
rp = nullptr;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2017-04-23 22:01:46 +10:00
|
|
|
void ErrorRegistry::RegisterDisplay(BasicDisplayErrorFunc *aDsp)
|
|
|
|
{
|
|
|
|
ErrorRegistry &rData = TheErrorRegistry::get();
|
|
|
|
rData.bIsWindowDsp = false;
|
|
|
|
rData.pDsp = reinterpret_cast< DisplayFnPtr >(aDsp);
|
|
|
|
}
|
|
|
|
|
2017-04-24 02:13:30 +10:00
|
|
|
void ErrorRegistry::RegisterDisplay(WindowDisplayErrorFunc *aDsp)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2017-04-24 02:13:30 +10:00
|
|
|
ErrorRegistry &rData = TheErrorRegistry::get();
|
|
|
|
rData.bIsWindowDsp = true;
|
|
|
|
rData.pDsp = reinterpret_cast< DisplayFnPtr >(aDsp);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2012-10-04 17:13:24 +02:00
|
|
|
static void aDspFunc(const OUString &rErr, const OUString &rAction)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2017-06-23 11:47:53 +02:00
|
|
|
SAL_WARN("vcl", "Action: " << rAction << " Error: " << rErr);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ErrorHandler::ErrorHandler()
|
|
|
|
{
|
2017-04-14 07:48:03 +10:00
|
|
|
ErrorRegistry &rData = TheErrorRegistry::get();
|
2016-04-25 09:59:16 +02:00
|
|
|
rData.errorHandlers.insert(rData.errorHandlers.begin(), this);
|
2017-04-21 20:55:26 +10:00
|
|
|
|
2016-04-25 09:59:16 +02:00
|
|
|
if(!rData.pDsp)
|
2017-04-23 22:01:46 +10:00
|
|
|
ErrorRegistry::RegisterDisplay(&aDspFunc);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ErrorHandler::~ErrorHandler()
|
|
|
|
{
|
2017-04-14 07:48:03 +10:00
|
|
|
auto &rErrorHandlers = TheErrorRegistry::get().errorHandlers;
|
2017-04-21 20:55:26 +10:00
|
|
|
rErrorHandlers.erase( ::std::remove(rErrorHandlers.begin(), rErrorHandlers.end(), this),
|
|
|
|
rErrorHandlers.end());
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2017-02-09 08:52:13 +02:00
|
|
|
bool ErrorHandler::GetErrorString(ErrCode nErrCodeId, OUString& rErrStr)
|
vcl: refactor ErrorHandler functions
Current, HandleError_Impl is called on by GetErrorString, and
HandleError_Impl also creates the error string. However, when
you look at what each function does, HandleError_Impl has been
imbued with some extraneous parameters:
1. bJustCreateString, and
2. rError
bJustCreateString is unnecessary, in fact it just mutates
HandleError to create the string, which is not really the core
purpose of this function. In fact, the string should be created
when we get the string from the error ID (GetErrorString), and
in fact the error handler function should call on GetErrorString
and not the other way around!
This has the happy side effect of vastly simplifying this code,
and allows each of the functions only do the thing they are
meant to do, and we no longer need these extraneous parameters
which just cause problems for code readibility. On to of this,
by simplifying the HandleError_Impl function, we just move the
code into the public HandleError function because these
parameters aren't necessary any more.
Change-Id: I4a727b5bbc6d3cdb0519f49b48dc52f8a8976629
Reviewed-on: https://gerrit.libreoffice.org/36849
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
2017-04-22 05:58:04 +10:00
|
|
|
{
|
|
|
|
OUString aErr;
|
|
|
|
|
|
|
|
if(!nErrCodeId || nErrCodeId == ERRCODE_ABORT)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ErrorInfo *pInfo = ErrorInfo::GetErrorInfo(nErrCodeId);
|
|
|
|
|
2017-04-23 19:39:43 +10:00
|
|
|
if (ErrorStringFactory::CreateString(pInfo,aErr))
|
vcl: refactor ErrorHandler functions
Current, HandleError_Impl is called on by GetErrorString, and
HandleError_Impl also creates the error string. However, when
you look at what each function does, HandleError_Impl has been
imbued with some extraneous parameters:
1. bJustCreateString, and
2. rError
bJustCreateString is unnecessary, in fact it just mutates
HandleError to create the string, which is not really the core
purpose of this function. In fact, the string should be created
when we get the string from the error ID (GetErrorString), and
in fact the error handler function should call on GetErrorString
and not the other way around!
This has the happy side effect of vastly simplifying this code,
and allows each of the functions only do the thing they are
meant to do, and we no longer need these extraneous parameters
which just cause problems for code readibility. On to of this,
by simplifying the HandleError_Impl function, we just move the
code into the public HandleError function because these
parameters aren't necessary any more.
Change-Id: I4a727b5bbc6d3cdb0519f49b48dc52f8a8976629
Reviewed-on: https://gerrit.libreoffice.org/36849
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
2017-04-22 05:58:04 +10:00
|
|
|
{
|
|
|
|
rErrStr = aErr;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete pInfo;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-09 08:52:13 +02:00
|
|
|
DialogMask ErrorHandler::HandleError(ErrCode nErrCodeId, DialogMask nFlags)
|
2012-08-11 23:01:00 +00:00
|
|
|
{
|
2017-04-30 15:47:54 +01:00
|
|
|
if (nErrCodeId == ERRCODE_NONE || nErrCodeId == ERRCODE_ABORT)
|
2017-04-17 09:37:31 +10:00
|
|
|
return DialogMask::NONE;
|
2017-04-21 20:55:26 +10:00
|
|
|
|
|
|
|
ErrorRegistry &rData = TheErrorRegistry::get();
|
2016-04-22 14:30:48 +02:00
|
|
|
vcl::Window *pParent = nullptr;
|
2017-04-21 20:55:26 +10:00
|
|
|
ErrorInfo *pInfo = ErrorInfo::GetErrorInfo(nErrCodeId);
|
vcl: refactor ErrorHandler functions
Current, HandleError_Impl is called on by GetErrorString, and
HandleError_Impl also creates the error string. However, when
you look at what each function does, HandleError_Impl has been
imbued with some extraneous parameters:
1. bJustCreateString, and
2. rError
bJustCreateString is unnecessary, in fact it just mutates
HandleError to create the string, which is not really the core
purpose of this function. In fact, the string should be created
when we get the string from the error ID (GetErrorString), and
in fact the error handler function should call on GetErrorString
and not the other way around!
This has the happy side effect of vastly simplifying this code,
and allows each of the functions only do the thing they are
meant to do, and we no longer need these extraneous parameters
which just cause problems for code readibility. On to of this,
by simplifying the HandleError_Impl function, we just move the
code into the public HandleError function because these
parameters aren't necessary any more.
Change-Id: I4a727b5bbc6d3cdb0519f49b48dc52f8a8976629
Reviewed-on: https://gerrit.libreoffice.org/36849
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
2017-04-22 05:58:04 +10:00
|
|
|
OUString aAction;
|
|
|
|
|
2016-04-25 09:59:16 +02:00
|
|
|
if (!rData.contexts.empty())
|
2016-04-22 14:30:48 +02:00
|
|
|
{
|
2016-04-25 09:59:16 +02:00
|
|
|
rData.contexts.front()->GetString(pInfo->GetErrorCode(), aAction);
|
2017-04-24 02:20:42 +10:00
|
|
|
|
2016-04-25 09:59:16 +02:00
|
|
|
for(ErrorContext *pCtx : rData.contexts)
|
2017-04-18 12:58:50 +10:00
|
|
|
{
|
2016-04-22 14:30:48 +02:00
|
|
|
if(pCtx->GetParent())
|
|
|
|
{
|
|
|
|
pParent=pCtx->GetParent();
|
|
|
|
break;
|
|
|
|
}
|
2017-04-18 12:58:50 +10:00
|
|
|
}
|
2016-04-22 14:30:48 +02:00
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2017-02-09 08:52:13 +02:00
|
|
|
bool bWarning = nErrCodeId.IsWarning();
|
2017-04-17 09:37:31 +10:00
|
|
|
DialogMask nErrFlags = DialogMask::ButtonDefaultsOk | DialogMask::ButtonsOk;
|
2005-11-11 11:15:49 +00:00
|
|
|
if (bWarning)
|
2017-04-17 09:37:31 +10:00
|
|
|
nErrFlags |= DialogMask::MessageWarning;
|
2005-11-11 11:15:49 +00:00
|
|
|
else
|
2017-04-17 09:37:31 +10:00
|
|
|
nErrFlags |= DialogMask::MessageError;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2017-04-21 20:55:26 +10:00
|
|
|
DynamicErrorInfo* pDynPtr = dynamic_cast<DynamicErrorInfo*>(pInfo);
|
2000-09-18 16:07:07 +00:00
|
|
|
if(pDynPtr)
|
|
|
|
{
|
2017-04-17 09:37:31 +10:00
|
|
|
DialogMask nDynFlags = pDynPtr->GetDialogMask();
|
|
|
|
if( nDynFlags != DialogMask::NONE )
|
2000-09-18 16:07:07 +00:00
|
|
|
nErrFlags = nDynFlags;
|
|
|
|
}
|
|
|
|
|
vcl: refactor ErrorHandler functions
Current, HandleError_Impl is called on by GetErrorString, and
HandleError_Impl also creates the error string. However, when
you look at what each function does, HandleError_Impl has been
imbued with some extraneous parameters:
1. bJustCreateString, and
2. rError
bJustCreateString is unnecessary, in fact it just mutates
HandleError to create the string, which is not really the core
purpose of this function. In fact, the string should be created
when we get the string from the error ID (GetErrorString), and
in fact the error handler function should call on GetErrorString
and not the other way around!
This has the happy side effect of vastly simplifying this code,
and allows each of the functions only do the thing they are
meant to do, and we no longer need these extraneous parameters
which just cause problems for code readibility. On to of this,
by simplifying the HandleError_Impl function, we just move the
code into the public HandleError function because these
parameters aren't necessary any more.
Change-Id: I4a727b5bbc6d3cdb0519f49b48dc52f8a8976629
Reviewed-on: https://gerrit.libreoffice.org/36849
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
2017-04-22 05:58:04 +10:00
|
|
|
OUString aErr;
|
2017-08-24 17:14:45 +02:00
|
|
|
if (ErrorStringFactory::CreateString(pInfo, aErr))
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
vcl: refactor ErrorHandler functions
Current, HandleError_Impl is called on by GetErrorString, and
HandleError_Impl also creates the error string. However, when
you look at what each function does, HandleError_Impl has been
imbued with some extraneous parameters:
1. bJustCreateString, and
2. rError
bJustCreateString is unnecessary, in fact it just mutates
HandleError to create the string, which is not really the core
purpose of this function. In fact, the string should be created
when we get the string from the error ID (GetErrorString), and
in fact the error handler function should call on GetErrorString
and not the other way around!
This has the happy side effect of vastly simplifying this code,
and allows each of the functions only do the thing they are
meant to do, and we no longer need these extraneous parameters
which just cause problems for code readibility. On to of this,
by simplifying the HandleError_Impl function, we just move the
code into the public HandleError function because these
parameters aren't necessary any more.
Change-Id: I4a727b5bbc6d3cdb0519f49b48dc52f8a8976629
Reviewed-on: https://gerrit.libreoffice.org/36849
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
2017-04-22 05:58:04 +10:00
|
|
|
if(!rData.pDsp)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2017-06-23 11:47:53 +02:00
|
|
|
SAL_WARN( "vcl", "Action: " << aAction << "Error: " << aErr);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else
|
2006-12-13 14:07:03 +00:00
|
|
|
{
|
vcl: refactor ErrorHandler functions
Current, HandleError_Impl is called on by GetErrorString, and
HandleError_Impl also creates the error string. However, when
you look at what each function does, HandleError_Impl has been
imbued with some extraneous parameters:
1. bJustCreateString, and
2. rError
bJustCreateString is unnecessary, in fact it just mutates
HandleError to create the string, which is not really the core
purpose of this function. In fact, the string should be created
when we get the string from the error ID (GetErrorString), and
in fact the error handler function should call on GetErrorString
and not the other way around!
This has the happy side effect of vastly simplifying this code,
and allows each of the functions only do the thing they are
meant to do, and we no longer need these extraneous parameters
which just cause problems for code readibility. On to of this,
by simplifying the HandleError_Impl function, we just move the
code into the public HandleError function because these
parameters aren't necessary any more.
Change-Id: I4a727b5bbc6d3cdb0519f49b48dc52f8a8976629
Reviewed-on: https://gerrit.libreoffice.org/36849
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
2017-04-22 05:58:04 +10:00
|
|
|
delete pInfo;
|
|
|
|
|
|
|
|
if(!rData.bIsWindowDsp)
|
2011-11-16 21:20:20 +00:00
|
|
|
{
|
vcl: refactor ErrorHandler functions
Current, HandleError_Impl is called on by GetErrorString, and
HandleError_Impl also creates the error string. However, when
you look at what each function does, HandleError_Impl has been
imbued with some extraneous parameters:
1. bJustCreateString, and
2. rError
bJustCreateString is unnecessary, in fact it just mutates
HandleError to create the string, which is not really the core
purpose of this function. In fact, the string should be created
when we get the string from the error ID (GetErrorString), and
in fact the error handler function should call on GetErrorString
and not the other way around!
This has the happy side effect of vastly simplifying this code,
and allows each of the functions only do the thing they are
meant to do, and we no longer need these extraneous parameters
which just cause problems for code readibility. On to of this,
by simplifying the HandleError_Impl function, we just move the
code into the public HandleError function because these
parameters aren't necessary any more.
Change-Id: I4a727b5bbc6d3cdb0519f49b48dc52f8a8976629
Reviewed-on: https://gerrit.libreoffice.org/36849
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
2017-04-22 05:58:04 +10:00
|
|
|
(*reinterpret_cast<BasicDisplayErrorFunc*>(rData.pDsp))(aErr,aAction);
|
|
|
|
return DialogMask::NONE;
|
2011-11-16 21:20:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
vcl: refactor ErrorHandler functions
Current, HandleError_Impl is called on by GetErrorString, and
HandleError_Impl also creates the error string. However, when
you look at what each function does, HandleError_Impl has been
imbued with some extraneous parameters:
1. bJustCreateString, and
2. rError
bJustCreateString is unnecessary, in fact it just mutates
HandleError to create the string, which is not really the core
purpose of this function. In fact, the string should be created
when we get the string from the error ID (GetErrorString), and
in fact the error handler function should call on GetErrorString
and not the other way around!
This has the happy side effect of vastly simplifying this code,
and allows each of the functions only do the thing they are
meant to do, and we no longer need these extraneous parameters
which just cause problems for code readibility. On to of this,
by simplifying the HandleError_Impl function, we just move the
code into the public HandleError function because these
parameters aren't necessary any more.
Change-Id: I4a727b5bbc6d3cdb0519f49b48dc52f8a8976629
Reviewed-on: https://gerrit.libreoffice.org/36849
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
2017-04-22 05:58:04 +10:00
|
|
|
if (nFlags != DialogMask::MAX)
|
|
|
|
nErrFlags = nFlags;
|
2017-04-24 02:27:09 +10:00
|
|
|
|
vcl: refactor ErrorHandler functions
Current, HandleError_Impl is called on by GetErrorString, and
HandleError_Impl also creates the error string. However, when
you look at what each function does, HandleError_Impl has been
imbued with some extraneous parameters:
1. bJustCreateString, and
2. rError
bJustCreateString is unnecessary, in fact it just mutates
HandleError to create the string, which is not really the core
purpose of this function. In fact, the string should be created
when we get the string from the error ID (GetErrorString), and
in fact the error handler function should call on GetErrorString
and not the other way around!
This has the happy side effect of vastly simplifying this code,
and allows each of the functions only do the thing they are
meant to do, and we no longer need these extraneous parameters
which just cause problems for code readibility. On to of this,
by simplifying the HandleError_Impl function, we just move the
code into the public HandleError function because these
parameters aren't necessary any more.
Change-Id: I4a727b5bbc6d3cdb0519f49b48dc52f8a8976629
Reviewed-on: https://gerrit.libreoffice.org/36849
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
2017-04-22 05:58:04 +10:00
|
|
|
return (*reinterpret_cast<WindowDisplayErrorFunc*>(rData.pDsp))(
|
|
|
|
pParent, nErrFlags, aErr, aAction);
|
2011-11-16 21:20:20 +00:00
|
|
|
}
|
2006-12-13 14:07:03 +00:00
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2017-04-21 20:55:26 +10:00
|
|
|
|
2017-08-12 17:10:19 +02:00
|
|
|
SAL_WARN( "vcl", "Error not handled " << pInfo->GetErrorCode());
|
2017-04-23 18:53:58 +10:00
|
|
|
// Error 1 (ERRCODE_ABORT) is classified as a General Error in sfx
|
|
|
|
if (pInfo->GetErrorCode() != ERRCODE_ABORT)
|
|
|
|
HandleError(ERRCODE_ABORT);
|
2011-11-16 21:20:20 +00:00
|
|
|
else
|
2017-04-23 18:53:58 +10:00
|
|
|
OSL_FAIL("ERRCODE_ABORT not handled");
|
2017-04-21 20:55:26 +10:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
delete pInfo;
|
2017-04-17 09:37:31 +10:00
|
|
|
return DialogMask::NONE;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2017-04-24 02:25:11 +10:00
|
|
|
struct ImplErrorContext
|
2017-04-24 02:13:30 +10:00
|
|
|
{
|
|
|
|
vcl::Window *pWin; // FIXME: should be VclPtr for strong lifecycle
|
|
|
|
};
|
|
|
|
|
|
|
|
ErrorContext::ErrorContext(vcl::Window *pWinP)
|
2017-04-24 02:25:11 +10:00
|
|
|
: pImpl( new ImplErrorContext )
|
2017-04-24 02:13:30 +10:00
|
|
|
{
|
|
|
|
pImpl->pWin = pWinP;
|
|
|
|
TheErrorRegistry::get().contexts.insert(TheErrorRegistry::get().contexts.begin(), this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorContext::~ErrorContext()
|
|
|
|
{
|
|
|
|
auto &rContexts = TheErrorRegistry::get().contexts;
|
|
|
|
rContexts.erase( ::std::remove(rContexts.begin(), rContexts.end(), this), rContexts.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorContext *ErrorContext::GetContext()
|
|
|
|
{
|
|
|
|
return TheErrorRegistry::get().contexts.empty() ? nullptr : TheErrorRegistry::get().contexts.front();
|
|
|
|
}
|
|
|
|
|
|
|
|
vcl::Window* ErrorContext::GetParent()
|
|
|
|
{
|
|
|
|
return pImpl ? pImpl->pWin : nullptr;
|
|
|
|
}
|
|
|
|
|
2017-04-24 02:25:11 +10:00
|
|
|
class ImplDynamicErrorInfo
|
2017-04-24 02:13:30 +10:00
|
|
|
{
|
|
|
|
friend class DynamicErrorInfo;
|
|
|
|
friend class ErrorInfo;
|
|
|
|
|
|
|
|
private:
|
2017-06-23 09:13:26 +01:00
|
|
|
explicit ImplDynamicErrorInfo(DialogMask nInMask)
|
|
|
|
: nMask(nInMask)
|
|
|
|
{
|
|
|
|
}
|
2017-04-24 02:13:30 +10:00
|
|
|
void RegisterError(DynamicErrorInfo *);
|
|
|
|
static void UnRegisterError(DynamicErrorInfo const *);
|
2017-02-09 08:52:13 +02:00
|
|
|
static ErrorInfo* GetDynamicErrorInfo(ErrCode nId);
|
2017-04-24 02:13:30 +10:00
|
|
|
|
|
|
|
ErrCode nErrId;
|
|
|
|
DialogMask nMask;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-04-24 02:25:11 +10:00
|
|
|
void ImplDynamicErrorInfo::RegisterError(DynamicErrorInfo *pDynErrInfo)
|
2017-04-24 02:13:30 +10:00
|
|
|
{
|
|
|
|
// Register dynamic identifier
|
|
|
|
ErrorRegistry& rData = TheErrorRegistry::get();
|
2017-02-09 08:52:13 +02:00
|
|
|
nErrId = ErrCode(((sal_uInt32(rData.nNextError) + 1) << ERRCODE_DYNAMIC_SHIFT) +
|
|
|
|
sal_uInt32(pDynErrInfo->GetErrorCode()));
|
2017-04-24 02:13:30 +10:00
|
|
|
|
|
|
|
if(rData.ppDynErrInfo[rData.nNextError])
|
|
|
|
delete rData.ppDynErrInfo[rData.nNextError];
|
|
|
|
|
|
|
|
rData.ppDynErrInfo[rData.nNextError] = pDynErrInfo;
|
|
|
|
|
|
|
|
if(++rData.nNextError>=ERRCODE_DYNAMIC_COUNT)
|
|
|
|
rData.nNextError=0;
|
|
|
|
}
|
|
|
|
|
2017-04-24 02:25:11 +10:00
|
|
|
void ImplDynamicErrorInfo::UnRegisterError(DynamicErrorInfo const *pDynErrInfo)
|
2017-04-24 02:13:30 +10:00
|
|
|
{
|
|
|
|
DynamicErrorInfo **ppDynErrInfo = TheErrorRegistry::get().ppDynErrInfo;
|
2017-02-09 08:52:13 +02:00
|
|
|
sal_uInt32 nIdx = ErrCode(*pDynErrInfo).GetDynamic() - 1;
|
2017-04-24 02:13:30 +10:00
|
|
|
DBG_ASSERT(ppDynErrInfo[nIdx] == pDynErrInfo, "ErrHdl: Error not found");
|
|
|
|
|
|
|
|
if(ppDynErrInfo[nIdx]==pDynErrInfo)
|
|
|
|
ppDynErrInfo[nIdx]=nullptr;
|
|
|
|
}
|
|
|
|
|
2017-02-09 08:52:13 +02:00
|
|
|
ErrorInfo* ImplDynamicErrorInfo::GetDynamicErrorInfo(ErrCode nId)
|
2017-04-24 02:13:30 +10:00
|
|
|
{
|
2017-02-09 08:52:13 +02:00
|
|
|
sal_uInt32 nIdx = nId.GetDynamic() - 1;
|
2017-04-24 02:13:30 +10:00
|
|
|
DynamicErrorInfo* pDynErrInfo = TheErrorRegistry::get().ppDynErrInfo[nIdx];
|
|
|
|
|
2017-02-09 08:52:13 +02:00
|
|
|
if(pDynErrInfo && ErrCode(*pDynErrInfo)==nId)
|
2017-04-24 02:13:30 +10:00
|
|
|
return pDynErrInfo;
|
|
|
|
else
|
2017-02-09 08:52:13 +02:00
|
|
|
return new ErrorInfo(nId.StripDynamic());
|
2017-04-24 02:13:30 +10:00
|
|
|
}
|
|
|
|
|
2017-02-09 08:52:13 +02:00
|
|
|
ErrorInfo *ErrorInfo::GetErrorInfo(ErrCode nId)
|
2017-04-24 02:13:30 +10:00
|
|
|
{
|
2017-02-09 08:52:13 +02:00
|
|
|
if(nId.IsDynamic())
|
2017-04-24 02:25:11 +10:00
|
|
|
return ImplDynamicErrorInfo::GetDynamicErrorInfo(nId);
|
2017-04-24 02:13:30 +10:00
|
|
|
else
|
|
|
|
return new ErrorInfo(nId);
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorInfo::~ErrorInfo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-02-09 08:52:13 +02:00
|
|
|
DynamicErrorInfo::DynamicErrorInfo(ErrCode nArgUserId, DialogMask nMask)
|
2017-04-24 02:13:30 +10:00
|
|
|
: ErrorInfo(nArgUserId),
|
2017-06-23 09:13:26 +01:00
|
|
|
pImpl(new ImplDynamicErrorInfo(nMask))
|
2017-04-24 02:13:30 +10:00
|
|
|
{
|
|
|
|
pImpl->RegisterError(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
DynamicErrorInfo::~DynamicErrorInfo()
|
|
|
|
{
|
2017-04-24 02:25:11 +10:00
|
|
|
ImplDynamicErrorInfo::UnRegisterError(this);
|
2017-04-24 02:13:30 +10:00
|
|
|
}
|
|
|
|
|
2017-02-09 08:52:13 +02:00
|
|
|
DynamicErrorInfo::operator ErrCode() const
|
2017-04-24 02:13:30 +10:00
|
|
|
{
|
|
|
|
return pImpl->nErrId;
|
|
|
|
}
|
|
|
|
|
|
|
|
DialogMask DynamicErrorInfo::GetDialogMask() const
|
|
|
|
{
|
|
|
|
return pImpl->nMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringErrorInfo::StringErrorInfo(
|
2017-02-09 08:52:13 +02:00
|
|
|
ErrCode nArgUserId, const OUString& aStringP, DialogMask nMask)
|
2017-04-27 08:41:19 +02:00
|
|
|
: DynamicErrorInfo(nArgUserId, nMask), aString(aStringP)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-10-14 08:27:31 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|