LCOV - code coverage report
Current view: top level - vcl/source/app - svdata.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 18 117 15.4 %
Date: 2014-04-14 Functions: 3 14 21.4 %
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 <string.h>
      21             : #include <boost/ptr_container/ptr_vector.hpp>
      22             : 
      23             : #include <comphelper/processfactory.hxx>
      24             : #include <comphelper/string.hxx>
      25             : #include <osl/mutex.hxx>
      26             : #include <rtl/process.h>
      27             : #include <tools/debug.hxx>
      28             : #include <tools/resary.hxx>
      29             : #include <tools/gen.hxx>
      30             : #include <cppuhelper/implbase1.hxx>
      31             : #include <uno/current_context.hxx>
      32             : 
      33             : #include "vcl/configsettings.hxx"
      34             : #include "vcl/svapp.hxx"
      35             : #include "vcl/settings.hxx"
      36             : #include "vcl/wrkwin.hxx"
      37             : #include "vcl/msgbox.hxx"
      38             : #include "vcl/button.hxx"
      39             : #include "vcl/dockwin.hxx"
      40             : #include "salinst.hxx"
      41             : #include "salframe.hxx"
      42             : #include "svdata.hxx"
      43             : #include "window.h"
      44             : #include "salimestatus.hxx"
      45             : #include "salsys.hxx"
      46             : #include "svids.hrc"
      47             : 
      48             : #include "com/sun/star/accessibility/MSAAService.hpp"
      49             : 
      50             : #include "officecfg/Office/Common.hxx"
      51             : 
      52             : #include <stdio.h>
      53             : 
      54             : using namespace com::sun::star::uno;
      55             : using namespace com::sun::star::lang;
      56             : using namespace com::sun::star::awt;
      57             : 
      58             : namespace
      59             : {
      60             :     struct private_aImplSVData :
      61             :         public rtl::Static<ImplSVData, private_aImplSVData> {};
      62             : }
      63             : 
      64             : // static SV-Data
      65             : ImplSVData* pImplSVData = NULL;
      66             : 
      67           0 : SalSystem* ImplGetSalSystem()
      68             : {
      69           0 :     ImplSVData* pSVData = ImplGetSVData();
      70           0 :     if( ! pSVData->mpSalSystem )
      71           0 :         pSVData->mpSalSystem = pSVData->mpDefInst->CreateSalSystem();
      72           0 :     return pSVData->mpSalSystem;
      73             : }
      74             : 
      75           1 : void ImplInitSVData()
      76             : {
      77           1 :     pImplSVData = &private_aImplSVData::get();
      78             : 
      79             :     // init global instance data
      80           1 :     memset( pImplSVData, 0, sizeof( ImplSVData ) );
      81           1 :     pImplSVData->maHelpData.mbAutoHelpId = true;
      82           1 :     pImplSVData->maNWFData.maMenuBarHighlightTextColor = Color( COL_TRANSPARENT );
      83             : 
      84             :     // mark default layout border as unitialized
      85           1 :     pImplSVData->maAppData.mnDefaultLayoutBorder = -1;
      86           1 : }
      87             : 
      88           1 : void ImplDeInitSVData()
      89             : {
      90           1 :     ImplSVData* pSVData = ImplGetSVData();
      91             : 
      92             :     // delete global instance data
      93           1 :     if( pSVData->mpSettingsConfigItem )
      94           0 :         delete pSVData->mpSettingsConfigItem;
      95             : 
      96           1 :     if( pSVData->mpDockingManager )
      97           0 :         delete pSVData->mpDockingManager;
      98             : 
      99           1 :     if( pSVData->maCtrlData.mpFieldUnitStrings )
     100           0 :         delete pSVData->maCtrlData.mpFieldUnitStrings, pSVData->maCtrlData.mpFieldUnitStrings = NULL;
     101           1 :     if( pSVData->maCtrlData.mpCleanUnitStrings )
     102           0 :         delete pSVData->maCtrlData.mpCleanUnitStrings, pSVData->maCtrlData.mpCleanUnitStrings = NULL;
     103           1 :     if( pSVData->mpPaperNames )
     104           0 :         delete pSVData->mpPaperNames, pSVData->mpPaperNames = NULL;
     105           1 : }
     106             : 
     107           1 : void ImplDestroySVData()
     108             : {
     109           1 :     pImplSVData = NULL;
     110           1 : }
     111             : 
     112           0 : Window* ImplGetDefaultWindow()
     113             : {
     114           0 :     ImplSVData* pSVData = ImplGetSVData();
     115           0 :     if ( pSVData->maWinData.mpAppWin )
     116           0 :         return pSVData->maWinData.mpAppWin;
     117             : 
     118             :     // First test if we already have a default window.
     119             :     // Don't only place a single if..else inside solar mutex lockframe
     120             :     // because then we might have to wait for the solar mutex what is not necessary
     121             :     // if we already have a default window.
     122             : 
     123           0 :     if ( !pSVData->mpDefaultWin )
     124             :     {
     125           0 :         Application::GetSolarMutex().acquire();
     126             : 
     127             :         // Test again because the thread who released the solar mutex could have called
     128             :         // the same method
     129             : 
     130           0 :         if ( !pSVData->mpDefaultWin && !pSVData->mbDeInit )
     131             :         {
     132             :             DBG_WARNING( "ImplGetDefaultWindow(): No AppWindow" );
     133           0 :             pSVData->mpDefaultWin = new WorkWindow( 0, WB_DEFAULTWIN );
     134           0 :             pSVData->mpDefaultWin->SetText( OUString( "VCL ImplGetDefaultWindow"  ) );
     135             :         }
     136           0 :         Application::GetSolarMutex().release();
     137             :     }
     138             : 
     139           0 :     return pSVData->mpDefaultWin;
     140             : }
     141             : 
     142           0 : ResMgr* ImplGetResMgr()
     143             : {
     144           0 :     ImplSVData* pSVData = ImplGetSVData();
     145           0 :     if ( !pSVData->mpResMgr )
     146             :     {
     147           0 :         LanguageTag aLocale( Application::GetSettings().GetUILanguageTag());
     148           0 :         pSVData->mpResMgr = ResMgr::SearchCreateResMgr( "vcl", aLocale );
     149             : 
     150             :         static bool bMessageOnce = false;
     151           0 :         if( !pSVData->mpResMgr && ! bMessageOnce )
     152             :         {
     153           0 :             bMessageOnce = true;
     154             :             const char* pMsg =
     155             :                 "Missing vcl resource. This indicates that files vital to localization are missing. "
     156           0 :                 "You might have a corrupt installation.";
     157           0 :             fprintf( stderr, "%s\n", pMsg );
     158           0 :             ErrorBox aBox( NULL, WB_OK | WB_DEF_OK, OUString( pMsg, strlen( pMsg ), RTL_TEXTENCODING_ASCII_US ) );
     159           0 :             aBox.Execute();
     160           0 :         }
     161             :     }
     162           0 :     return pSVData->mpResMgr;
     163             : }
     164             : 
     165           0 : ResId VclResId( sal_Int32 nId )
     166             : {
     167           0 :     ResMgr* pMgr = ImplGetResMgr();
     168           0 :     if( ! pMgr )
     169           0 :         throw std::bad_alloc();
     170             : 
     171           0 :     return ResId( nId, *pMgr );
     172             : }
     173             : 
     174           0 : FieldUnitStringList* ImplGetFieldUnits()
     175             : {
     176           0 :     ImplSVData* pSVData = ImplGetSVData();
     177           0 :     if( ! pSVData->maCtrlData.mpFieldUnitStrings )
     178             :     {
     179           0 :         ResMgr* pResMgr = ImplGetResMgr();
     180           0 :         if( pResMgr )
     181             :         {
     182           0 :             ResStringArray aUnits( ResId (SV_FUNIT_STRINGS, *pResMgr) );
     183           0 :             sal_uInt32 nUnits = aUnits.Count();
     184           0 :             pSVData->maCtrlData.mpFieldUnitStrings = new FieldUnitStringList();
     185           0 :             pSVData->maCtrlData.mpFieldUnitStrings->reserve( nUnits );
     186           0 :             for( sal_uInt32 i = 0; i < nUnits; i++ )
     187             :             {
     188           0 :                 std::pair< OUString, FieldUnit > aElement( aUnits.GetString(i), static_cast<FieldUnit>(aUnits.GetValue(i)) );
     189           0 :                 pSVData->maCtrlData.mpFieldUnitStrings->push_back( aElement );
     190           0 :             }
     191             :         }
     192             :     }
     193           0 :     return pSVData->maCtrlData.mpFieldUnitStrings;
     194             : }
     195             : 
     196           0 : FieldUnitStringList* ImplGetCleanedFieldUnits()
     197             : {
     198           0 :     ImplSVData* pSVData = ImplGetSVData();
     199           0 :     if( ! pSVData->maCtrlData.mpCleanUnitStrings )
     200             :     {
     201           0 :         FieldUnitStringList* pUnits = ImplGetFieldUnits();
     202           0 :         if( pUnits )
     203             :         {
     204           0 :             size_t nUnits = pUnits->size();
     205           0 :             pSVData->maCtrlData.mpCleanUnitStrings = new FieldUnitStringList();
     206           0 :             pSVData->maCtrlData.mpCleanUnitStrings->reserve( nUnits );
     207           0 :             for( size_t i = 0; i < nUnits; ++i )
     208             :             {
     209           0 :                 OUString aUnit( (*pUnits)[i].first );
     210           0 :                 aUnit = comphelper::string::remove(aUnit, ' ');
     211           0 :                 aUnit = aUnit.toAsciiLowerCase();
     212           0 :                 std::pair< OUString, FieldUnit > aElement( aUnit, (*pUnits)[i].second );
     213           0 :                 pSVData->maCtrlData.mpCleanUnitStrings->push_back( aElement );
     214           0 :             }
     215             :         }
     216             :     }
     217           0 :     return pSVData->maCtrlData.mpCleanUnitStrings;
     218             : }
     219             : 
     220           0 : DockingManager* ImplGetDockingManager()
     221             : {
     222           0 :     ImplSVData* pSVData = ImplGetSVData();
     223           0 :     if ( !pSVData->mpDockingManager )
     224           0 :         pSVData->mpDockingManager = new DockingManager();
     225             : 
     226           0 :     return pSVData->mpDockingManager;
     227             : }
     228             : 
     229           0 : BlendFrameCache* ImplGetBlendFrameCache()
     230             : {
     231           0 :     ImplSVData* pSVData = ImplGetSVData();
     232           0 :     if ( !pSVData->mpBlendFrameCache)
     233           0 :         pSVData->mpBlendFrameCache= new BlendFrameCache();
     234             : 
     235           0 :     return pSVData->mpBlendFrameCache;
     236             : }
     237             : 
     238             : #ifdef _WIN32
     239             : bool HasAtHook();
     240             : #endif
     241             : 
     242           0 : bool ImplInitAccessBridge()
     243             : {
     244           0 :     ImplSVData* pSVData = ImplGetSVData();
     245           0 :     if( ! pSVData->mxAccessBridge.is() )
     246             :     {
     247           0 :         css::uno::Reference< XComponentContext > xContext(comphelper::getProcessComponentContext());
     248             : 
     249             : #ifdef _WIN32
     250             :         if (!HasAtHook() && !getenv("SAL_FORCE_IACCESSIBLE2"))
     251             :         {
     252             :             SAL_INFO("vcl", "Apparently no running AT -> "
     253             :                      "not enabling IAccessible2 integration");
     254             :         }
     255             :         else
     256             :         {
     257             :             try {
     258             :                  pSVData->mxAccessBridge
     259             :                      = css::accessibility::MSAAService::create(xContext);
     260             :                  SAL_INFO("vcl", "got IAccessible2 bridge");
     261             :                  return true;
     262             :              } catch (css::uno::DeploymentException & e) {
     263             :                  SAL_WARN(
     264             :                     "vcl",
     265             :                     "got no IAccessible2 bridge" << e.Message);
     266             :                  return false;
     267             :              }
     268             :         }
     269             : #endif
     270             :     }
     271             : 
     272           0 :     return true;
     273             : }
     274             : 
     275           0 : Window* ImplFindWindow( const SalFrame* pFrame, ::Point& rSalFramePos )
     276             : {
     277           0 :     ImplSVData* pSVData = ImplGetSVData();
     278           0 :     Window*     pFrameWindow = pSVData->maWinData.mpFirstFrame;
     279           0 :     while ( pFrameWindow )
     280             :     {
     281           0 :         if ( pFrameWindow->ImplGetFrame() == pFrame )
     282             :         {
     283           0 :             Window* pWindow = pFrameWindow->ImplFindWindow( rSalFramePos );
     284           0 :             if ( !pWindow )
     285           0 :                 pWindow = pFrameWindow->ImplGetWindow();
     286           0 :             rSalFramePos = pWindow->ImplFrameToOutput( rSalFramePos );
     287           0 :             return pWindow;
     288             :         }
     289           0 :         pFrameWindow = pFrameWindow->ImplGetFrameData()->mpNextFrame;
     290             :     }
     291             : 
     292           0 :     return NULL;
     293             : }
     294             : 
     295           0 : void LocaleConfigurationListener::ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32 nHint )
     296             : {
     297           0 :     AllSettings::LocaleSettingsChanged( nHint );
     298           0 : }
     299             : 
     300             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10