LCOV - code coverage report
Current view: top level - libreoffice/vcl/generic/app - gensys.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 96 2.1 %
Date: 2012-12-27 Functions: 1 8 12.5 %
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 <generic/gensys.h>
      21             : 
      22             : #include <vcl/msgbox.hxx>
      23             : #include <vcl/button.hxx>
      24             : 
      25             : #include <svdata.hxx>
      26             : 
      27             : #include <rtl/ustrbuf.hxx>
      28             : #include <rtl/strbuf.hxx>
      29             : #include <rtl/bootstrap.hxx>
      30             : #include <osl/process.h>
      31             : #include <osl/thread.h>
      32             : 
      33             : #include "vcl/unohelp.hxx"
      34             : #include <com/sun/star/beans/PropertyValue.hpp>
      35             : #include <com/sun/star/container/XNameAccess.hpp>
      36             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      37             : 
      38             : using namespace com::sun::star;
      39             : 
      40             : namespace {
      41             : 
      42           0 : OUString GetNativeMessageBoxButtonText( int nButtonId, bool bUseResources )
      43             : {
      44           0 :     OUString aText;
      45           0 :     if( bUseResources )
      46             :     {
      47           0 :         aText = Button::GetStandardText( nButtonId );
      48             :     }
      49           0 :     if( aText.isEmpty() )
      50             :     {
      51           0 :         switch( nButtonId )
      52             :         {
      53             :         case BUTTON_OK:
      54           0 :             aText = "OK";
      55           0 :             break;
      56             :         case BUTTON_CANCEL:
      57           0 :             aText = "Cancel";
      58           0 :             break;
      59             :         case BUTTON_ABORT:
      60           0 :             aText = "Abort";
      61           0 :             break;
      62             :         case BUTTON_RETRY:
      63           0 :             aText = "Retry";
      64           0 :             break;
      65             :         case BUTTON_IGNORE:
      66           0 :             aText = "Ignore";
      67           0 :             break;
      68             :         case BUTTON_YES:
      69           0 :             aText = "Yes";
      70           0 :             break;
      71             :         case BUTTON_NO:
      72           0 :             aText = "No";
      73           0 :             break;
      74             :         }
      75             :     }
      76           0 :     return aText;
      77             : }
      78             : 
      79             : }
      80             : 
      81           3 : SalGenericSystem::SalGenericSystem()
      82             : {
      83           3 : }
      84             : 
      85           0 : SalGenericSystem::~SalGenericSystem()
      86             : {
      87           0 : }
      88             : 
      89           0 : int SalGenericSystem::ShowNativeMessageBox( const rtl::OUString& rTitle, const rtl::OUString& rMessage,
      90             :                                             int nButtonCombination, int nDefaultButton,
      91             :                                             bool bUseResources )
      92             : {
      93           0 :     int nDefButton = 0;
      94           0 :     std::list< rtl::OUString > aButtons;
      95           0 :     int nButtonIds[5], nBut = 0;
      96             : 
      97           0 :     ImplHideSplash();
      98             : 
      99           0 :     if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK ||
     100             :         nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL )
     101             :     {
     102           0 :         aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_OK, bUseResources ) );
     103           0 :         nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK;
     104             :     }
     105           0 :     if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL ||
     106             :         nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO )
     107             :     {
     108           0 :         aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_YES, bUseResources ) );
     109           0 :         nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_YES;
     110           0 :         aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_NO, bUseResources ) );
     111           0 :         nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO;
     112           0 :         if( nDefaultButton == SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO )
     113           0 :             nDefButton = 1;
     114             :     }
     115           0 :     if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL ||
     116             :         nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL ||
     117             :         nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL )
     118             :     {
     119           0 :         if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL )
     120             :         {
     121           0 :             aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_RETRY, bUseResources ) );
     122           0 :             nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY;
     123             :         }
     124           0 :         aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_CANCEL, bUseResources ) );
     125           0 :         nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL;
     126           0 :         if( nDefaultButton == SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL )
     127           0 :             nDefButton = aButtons.size()-1;
     128             :     }
     129           0 :     if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_ABORT_RETRY_IGNORE )
     130             :     {
     131           0 :         aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_ABORT, bUseResources ) );
     132           0 :         nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_ABORT;
     133           0 :         aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_RETRY, bUseResources ) );
     134           0 :         nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY;
     135           0 :         aButtons.push_back( GetNativeMessageBoxButtonText( BUTTON_IGNORE, bUseResources ) );
     136           0 :         nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_IGNORE;
     137           0 :         switch( nDefaultButton )
     138             :         {
     139           0 :             case SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY: nDefButton = 1;break;
     140           0 :             case SALSYSTEM_SHOWNATIVEMSGBOX_BTN_IGNORE: nDefButton = 2;break;
     141             :         }
     142             :     }
     143             : 
     144           0 :     int nResult = ShowNativeDialog( rTitle, rMessage, aButtons, nDefButton );
     145             : 
     146           0 :     return nResult != -1 ? nButtonIds[ nResult ] : 0;
     147             : }
     148             : 
     149             : // ------------------------------------------------------------------------
     150             : //           Helpers primarily for X Windowing derivatives
     151             : // ------------------------------------------------------------------------
     152             : 
     153           0 : const char* SalGenericSystem::getFrameResName()
     154             : {
     155             :     /*  according to ICCCM:
     156             :      *  first search command line for -name parameter
     157             :      *  then try RESOURCE_NAME environment variable
     158             :      *  then use argv[0] stripped by directories
     159             :      */
     160           0 :     static rtl::OStringBuffer aResName;
     161           0 :     if( !aResName.getLength() )
     162             :     {
     163           0 :         int nArgs = osl_getCommandArgCount();
     164           0 :         for( int n = 0; n < nArgs-1; n++ )
     165             :         {
     166           0 :             rtl::OUString aArg;
     167           0 :             if( ! osl_getCommandArg( n, &aArg.pData ) &&
     168           0 :                 aArg.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("-name")) &&
     169           0 :                 ! osl_getCommandArg( n+1, &aArg.pData ) )
     170             :             {
     171           0 :                 aResName.append( rtl::OUStringToOString( aArg, osl_getThreadTextEncoding() ) );
     172             :                 break;
     173             :             }
     174           0 :         }
     175           0 :         if( !aResName.getLength() )
     176             :         {
     177           0 :             const char* pEnv = getenv( "RESOURCE_NAME" );
     178           0 :             if( pEnv && *pEnv )
     179           0 :                 aResName.append( pEnv );
     180             :         }
     181           0 :         if( !aResName.getLength() )
     182           0 :             aResName.append( "VCLSalFrame" );
     183             :     }
     184           0 :     return aResName.getStr();
     185             : }
     186             : 
     187           0 : const char* SalGenericSystem::getFrameClassName()
     188             : {
     189           0 :     static rtl::OStringBuffer aClassName;
     190           0 :     if( !aClassName.getLength() )
     191             :     {
     192           0 :         rtl::OUString aIni, aProduct;
     193           0 :         rtl::Bootstrap::get( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BRAND_BASE_DIR" ) ), aIni );
     194           0 :         aIni += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/program/" SAL_CONFIGFILE( "bootstrap" ) ) );
     195           0 :         rtl::Bootstrap aBootstrap( aIni );
     196           0 :         aBootstrap.getFrom( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ProductKey" ) ), aProduct );
     197             : 
     198           0 :         if( !aProduct.isEmpty() )
     199           0 :             aClassName.append( rtl::OUStringToOString( aProduct, osl_getThreadTextEncoding() ) );
     200             :         else
     201           0 :             aClassName.append( "VCLSalFrame" );
     202             :     }
     203           0 :     return aClassName.getStr();
     204             : }
     205             : 
     206           0 : rtl::OString SalGenericSystem::getFrameResName( SalExtStyle nStyle )
     207             : {
     208           0 :     rtl::OStringBuffer aBuf( 64 );
     209           0 :     aBuf.append( getFrameResName() );
     210           0 :     if( (nStyle & SAL_FRAME_EXT_STYLE_DOCUMENT) )
     211           0 :         aBuf.append( ".DocumentWindow" );
     212             : 
     213           0 :     return aBuf.makeStringAndClear();
     214             : }
     215             : 
     216             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10