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

Generated by: LCOV version 1.10