LCOV - code coverage report
Current view: top level - uui/source - iahndl-errorhandler.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 99 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          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 <osl/mutex.hxx>
      21             : #include <vcl/svapp.hxx>
      22             : #include <vcl/msgbox.hxx>
      23             : 
      24             : #include <com/sun/star/task/XInteractionAbort.hpp>
      25             : #include <com/sun/star/task/XInteractionApprove.hpp>
      26             : #include <com/sun/star/task/XInteractionDisapprove.hpp>
      27             : #include <com/sun/star/task/XInteractionRetry.hpp>
      28             : 
      29             : #include <tools/errinf.hxx>
      30             : #include <svtools/svtools.hrc>
      31             : 
      32             : #include "ids.hrc"
      33             : #include "getcontinuations.hxx"
      34             : 
      35             : #include "iahndl.hxx"
      36             : #include <boost/scoped_ptr.hpp>
      37             : 
      38             : using namespace com::sun::star;
      39             : 
      40             : namespace {
      41             : 
      42             : sal_uInt16
      43           0 : executeErrorDialog(
      44             :     vcl::Window * pParent,
      45             :     task::InteractionClassification eClassification,
      46             :     OUString const & rContext,
      47             :     OUString const & rMessage,
      48             :     WinBits nButtonMask)
      49             : {
      50           0 :     SolarMutexGuard aGuard;
      51             : 
      52           0 :     OUStringBuffer aText(rContext);
      53           0 :     if (!rContext.isEmpty() && !rMessage.isEmpty())
      54           0 :         aText.appendAscii(":\n");
      55             :             //TODO! must be internationalized
      56           0 :     aText.append(rMessage);
      57             : 
      58           0 :     VclPtr< MessBox > xBox;
      59             :     try
      60             :     {
      61           0 :         switch (eClassification)
      62             :         {
      63             :         case task::InteractionClassification_ERROR:
      64             :             xBox.reset(VclPtr<ErrorBox>::Create(pParent,
      65             :                                     nButtonMask,
      66           0 :                                     aText.makeStringAndClear()));
      67           0 :             break;
      68             : 
      69             :         case task::InteractionClassification_WARNING:
      70             :             xBox.reset(VclPtr<WarningBox>::Create(pParent,
      71             :                                       nButtonMask,
      72           0 :                                       aText.makeStringAndClear()));
      73           0 :             break;
      74             : 
      75             :         case task::InteractionClassification_INFO:
      76             : #           define WB_DEF_BUTTONS (WB_DEF_OK | WB_DEF_CANCEL | WB_DEF_RETRY)
      77             :             //(want to ignore any default button settings)...
      78           0 :             if ((nButtonMask & WB_DEF_BUTTONS) == WB_DEF_OK)
      79             :                 xBox.reset(VclPtr<InfoBox>::Create(pParent,
      80           0 :                                        aText.makeStringAndClear()));
      81             :             else
      82             :                 xBox.reset(VclPtr<ErrorBox>::Create(pParent,
      83             :                                         nButtonMask,
      84           0 :                                         aText.makeStringAndClear()));
      85           0 :             break;
      86             : 
      87             :         case task::InteractionClassification_QUERY:
      88             :             xBox.reset(VclPtr<QueryBox>::Create(pParent,
      89             :                                     nButtonMask,
      90           0 :                                     aText.makeStringAndClear()));
      91           0 :             break;
      92             : 
      93             :         default:
      94             :             OSL_ASSERT(false);
      95           0 :             break;
      96             :         }
      97             :     }
      98           0 :     catch (std::bad_alloc const &)
      99             :     {
     100           0 :         throw uno::RuntimeException("out of memory");
     101             :     }
     102             : 
     103           0 :     sal_uInt16 aResult = xBox->Execute();
     104             : 
     105           0 :     xBox.disposeAndClear();
     106             : 
     107           0 :     switch( aResult )
     108             :     {
     109             :     case RET_OK:
     110           0 :         aResult = ERRCODE_BUTTON_OK;
     111           0 :         break;
     112             :     case RET_CANCEL:
     113           0 :         aResult = ERRCODE_BUTTON_CANCEL;
     114           0 :         break;
     115             :     case RET_YES:
     116           0 :         aResult = ERRCODE_BUTTON_YES;
     117           0 :         break;
     118             :     case RET_NO:
     119           0 :         aResult = ERRCODE_BUTTON_NO;
     120           0 :         break;
     121             :     case RET_RETRY:
     122           0 :         aResult = ERRCODE_BUTTON_RETRY;
     123           0 :         break;
     124             :     }
     125             : 
     126           0 :     return aResult;
     127             : }
     128             : 
     129             : }
     130             : 
     131             : void
     132           0 : UUIInteractionHelper::handleErrorHandlerRequest(
     133             :     task::InteractionClassification eClassification,
     134             :     ErrCode nErrorCode,
     135             :     std::vector< OUString > const & rArguments,
     136             :     uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
     137             :         rContinuations,
     138             :     bool bObtainErrorStringOnly,
     139             :     bool & bHasErrorString,
     140             :     OUString & rErrorString)
     141             : {
     142           0 :     if (bObtainErrorStringOnly)
     143             :     {
     144           0 :         bHasErrorString = isInformationalErrorMessageRequest(rContinuations);
     145           0 :         if (!bHasErrorString)
     146           0 :             return;
     147             :     }
     148             : 
     149           0 :     OUString aMessage;
     150             :     {
     151             :         enum Source { SOURCE_DEFAULT, SOURCE_CNT, SOURCE_SVX, SOURCE_UUI };
     152             :         static char const * const aManager[4] = { "ofa", "cnt", "svx", "uui" };
     153             :         static sal_uInt16 const aId[4]
     154             :             = { RID_ERRHDL,
     155             :                 RID_CHAOS_START + 12,
     156             :                 // cf. chaos/source/inc/cntrids.hrc, where
     157             :                 // #define RID_CHAOS_ERRHDL (RID_CHAOS_START + 12)
     158             :                 RID_SVX_START + 350, // RID_SVXERRCODE
     159             :                 RID_UUI_ERRHDL };
     160           0 :         ErrCode nErrorId = nErrorCode & ~ERRCODE_WARNING_MASK;
     161             :         Source eSource = nErrorId < ERRCODE_AREA_LIB1 ?
     162             :             SOURCE_DEFAULT :
     163             :             nErrorId >= ERRCODE_AREA_CHAOS
     164           0 :             && nErrorId < ERRCODE_AREA_CHAOS_END ?
     165             :             SOURCE_CNT :
     166             :             nErrorId >= ERRCODE_AREA_SVX
     167           0 :             && nErrorId <= ERRCODE_AREA_SVX_END ?
     168             :             SOURCE_SVX :
     169           0 :             SOURCE_UUI;
     170             : 
     171           0 :         SolarMutexGuard aGuard;
     172           0 :         boost::scoped_ptr< ResMgr > xManager;
     173           0 :         xManager.reset(ResMgr::CreateResMgr(aManager[eSource]));
     174           0 :         if (!xManager.get())
     175           0 :             return;
     176           0 :         ResId aResId(aId[eSource], *xManager.get());
     177           0 :         if (!ErrorResource(aResId).getString(nErrorCode, aMessage))
     178           0 :             return;
     179             :     }
     180             : 
     181           0 :     aMessage = replaceMessageWithArguments( aMessage, rArguments );
     182             : 
     183           0 :     if (bObtainErrorStringOnly)
     184             :     {
     185           0 :         rErrorString = aMessage;
     186           0 :         return;
     187             :     }
     188             :     else
     189             :     {
     190             :         //TODO! It can happen that the buttons calculated below do not match
     191             :         // the error text from the resource (e.g., some text that is not a
     192             :         // question, but YES and NO buttons).  Some error texts have
     193             :         // ExtraData that specifies a set of buttons, but that data is not
     194             :         // really useful, because a single error text may well make sense
     195             :         // both with only an OK button and with RETRY and CANCEL buttons.
     196             : 
     197           0 :         uno::Reference< task::XInteractionApprove > xApprove;
     198           0 :         uno::Reference< task::XInteractionDisapprove > xDisapprove;
     199           0 :         uno::Reference< task::XInteractionRetry > xRetry;
     200           0 :         uno::Reference< task::XInteractionAbort > xAbort;
     201             :         getContinuations(
     202           0 :             rContinuations, &xApprove, &xDisapprove, &xRetry, &xAbort);
     203             : 
     204             :         // The following mapping uses the bit mask
     205             :         //     Approve = 8,
     206             :         //     Disapprove = 4,
     207             :         //     Retry = 2,
     208             :         //     Abort = 1
     209             : 
     210             :         // The mapping has five properties on which the code to select the
     211             :         // correct continuation relies:
     212             :         // 1  The OK button is mapped to Approve if that is available,
     213             :         //    otherwise to Abort if that is available, otherwise to none.
     214             :         // 2  The CANCEL button is always mapped to Abort.
     215             :         // 3  The RETRY button is always mapped to Retry.
     216             :         // 4  The NO button is always mapped to Disapprove.
     217             :         // 5  The YES button is always mapped to Approve.
     218             : 
     219             :         // Because the WinBits button combinations are quite restricted, not
     220             :         // every request can be served here.
     221             : 
     222             :         // Finally, it seems to be better to leave default button
     223             :         // determination to VCL (the favouring of CANCEL as default button
     224             :         // seems to not always be what the user wants)...
     225             :         WinBits const aButtonMask[16]
     226             :             = { 0,
     227             :                 WB_OK /*| WB_DEF_OK*/, // Abort
     228             :                 0,
     229             :                 WB_RETRY_CANCEL /*| WB_DEF_CANCEL*/, // Retry, Abort
     230             :                 0,
     231             :                 0,
     232             :                 0,
     233             :                 0,
     234             :                 WB_OK /*| WB_DEF_OK*/, // Approve
     235             :                 WB_OK_CANCEL /*| WB_DEF_CANCEL*/, // Approve, Abort
     236             :                 0,
     237             :                 0,
     238             :                 WB_YES_NO /*| WB_DEF_NO*/, // Approve, Disapprove
     239             :                 WB_YES_NO_CANCEL /*| WB_DEF_CANCEL*/,
     240             :                 // Approve, Disapprove, Abort
     241             :                 0,
     242           0 :                 0 };
     243             : 
     244           0 :         WinBits nButtonMask = aButtonMask[(xApprove.is() ? 8 : 0)
     245           0 :                                           | (xDisapprove.is() ? 4 : 0)
     246           0 :                                           | (xRetry.is() ? 2 : 0)
     247           0 :                                           | (xAbort.is() ? 1 : 0)];
     248           0 :         if (nButtonMask == 0)
     249           0 :             return;
     250             : 
     251             :         //TODO! remove this backwards compatibility?
     252           0 :         OUString aContext(getContextProperty());
     253           0 :         if (aContext.isEmpty() && nErrorCode != 0)
     254             :         {
     255           0 :             SolarMutexGuard aGuard;
     256           0 :             ErrorContext * pContext = ErrorContext::GetContext();
     257           0 :             if (pContext)
     258             :             {
     259           0 :                 OUString aContextString;
     260           0 :                 if (pContext->GetString(nErrorCode, aContextString))
     261           0 :                     aContext = aContextString;
     262           0 :             }
     263             :         }
     264             : 
     265             :         sal_uInt16 nResult = executeErrorDialog(
     266           0 :             getParentProperty(), eClassification, aContext, aMessage, nButtonMask );
     267             : 
     268           0 :         switch (nResult)
     269             :         {
     270             :         case ERRCODE_BUTTON_OK:
     271             :             OSL_ENSURE(xApprove.is() || xAbort.is(), "unexpected situation");
     272           0 :             if (xApprove.is())
     273           0 :                 xApprove->select();
     274           0 :             else if (xAbort.is())
     275           0 :                 xAbort->select();
     276           0 :             break;
     277             : 
     278             :         case ERRCODE_BUTTON_CANCEL:
     279             :             OSL_ENSURE(xAbort.is(), "unexpected situation");
     280           0 :             if (xAbort.is())
     281           0 :                 xAbort->select();
     282           0 :             break;
     283             : 
     284             :         case ERRCODE_BUTTON_RETRY:
     285             :             OSL_ENSURE(xRetry.is(), "unexpected situation");
     286           0 :             if (xRetry.is())
     287           0 :                 xRetry->select();
     288           0 :             break;
     289             : 
     290             :         case ERRCODE_BUTTON_NO:
     291             :             OSL_ENSURE(xDisapprove.is(), "unexpected situation");
     292           0 :             if (xDisapprove.is())
     293           0 :                 xDisapprove->select();
     294           0 :             break;
     295             : 
     296             :         case ERRCODE_BUTTON_YES:
     297             :             OSL_ENSURE(xApprove.is(), "unexpected situation");
     298           0 :             if (xApprove.is())
     299           0 :                 xApprove->select();
     300           0 :             break;
     301           0 :         }
     302             : 
     303           0 :     }
     304             : }
     305             : 
     306             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11