1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <boost/ptr_container/ptr_vector.hpp>
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>
33 #include "vcl/configsettings.hxx"
34 #include "vcl/svapp.hxx"
35 #include "vcl/settings.hxx"
36 #include "vcl/wrkwin.hxx"
37 #include "vcl/layout.hxx"
38 #include "vcl/button.hxx"
39 #include "vcl/dockwin.hxx"
40 #include "vcl/print.hxx"
41 #include "vcl/virdev.hxx"
42 #include "salinst.hxx"
43 #include "salframe.hxx"
47 #include "salimestatus.hxx"
50 #include "helpwin.hxx"
51 #include "../window/scrwnd.hxx"
53 #include "com/sun/star/accessibility/MSAAService.hpp"
55 #include "officecfg/Office/Common.hxx"
57 #include "vcl/opengl/OpenGLContext.hxx"
61 using namespace com::sun::star::uno
;
62 using namespace com::sun::star::lang
;
63 using namespace com::sun::star::awt
;
67 struct private_aImplSVData
:
68 public rtl::Static
<ImplSVData
, private_aImplSVData
> {};
71 ImplSVData
* ImplGetSVData() {
72 return &private_aImplSVData::get();
75 SalSystem
* ImplGetSalSystem()
77 ImplSVData
* pSVData
= ImplGetSVData();
78 if( ! pSVData
->mpSalSystem
)
79 pSVData
->mpSalSystem
= pSVData
->mpDefInst
->CreateSalSystem();
80 return pSVData
->mpSalSystem
;
83 ImplSVData::ImplSVData()
85 // init global instance data
86 memset( this, 0, sizeof( ImplSVData
) );
87 maHelpData
.mbAutoHelpId
= true;
88 maNWFData
.maMenuBarHighlightTextColor
= Color( COL_TRANSPARENT
);
91 ImplSVGDIData::~ImplSVGDIData()
93 // FIXME: deliberately leak any remaining OutputDevice
94 // until we have their pGraphics reference counted, doing
95 // any disposes so late in shutdown is rather unsafe.
96 memset( this, 0, sizeof( ImplSVGDIData
) );
99 void ImplDeInitSVData()
101 ImplSVData
* pSVData
= ImplGetSVData();
103 // delete global instance data
104 if( pSVData
->mpSettingsConfigItem
)
105 delete pSVData
->mpSettingsConfigItem
;
107 if( pSVData
->mpDockingManager
)
108 delete pSVData
->mpDockingManager
;
110 if( pSVData
->maCtrlData
.mpFieldUnitStrings
)
111 delete pSVData
->maCtrlData
.mpFieldUnitStrings
, pSVData
->maCtrlData
.mpFieldUnitStrings
= NULL
;
112 if( pSVData
->maCtrlData
.mpCleanUnitStrings
)
113 delete pSVData
->maCtrlData
.mpCleanUnitStrings
, pSVData
->maCtrlData
.mpCleanUnitStrings
= NULL
;
114 if( pSVData
->mpPaperNames
)
115 delete pSVData
->mpPaperNames
, pSVData
->mpPaperNames
= NULL
;
118 vcl::Window
* ImplGetDefaultWindow()
120 ImplSVData
* pSVData
= ImplGetSVData();
121 if ( pSVData
->maWinData
.mpAppWin
)
122 return pSVData
->maWinData
.mpAppWin
;
124 // First test if we already have a default window.
125 // Don't only place a single if..else inside solar mutex lockframe
126 // because then we might have to wait for the solar mutex what is not necessary
127 // if we already have a default window.
129 if ( !pSVData
->mpDefaultWin
)
131 Application::GetSolarMutex().acquire();
133 // Test again because the thread who released the solar mutex could have called
136 if ( !pSVData
->mpDefaultWin
&& !pSVData
->mbDeInit
)
138 DBG_WARNING( "ImplGetDefaultWindow(): No AppWindow" );
139 pSVData
->mpDefaultWin
= VclPtr
<WorkWindow
>::Create( nullptr, WB_DEFAULTWIN
);
140 pSVData
->mpDefaultWin
->SetText( OUString( "VCL ImplGetDefaultWindow" ) );
142 // Add a reference to the default context so it never gets deleted
143 rtl::Reference
<OpenGLContext
> pContext
= pSVData
->mpDefaultWin
->GetGraphics()->GetOpenGLContext();
147 Application::GetSolarMutex().release();
150 return pSVData
->mpDefaultWin
;
153 ResMgr
* ImplGetResMgr()
155 ImplSVData
* pSVData
= ImplGetSVData();
156 if ( !pSVData
->mpResMgr
)
158 LanguageTag
aLocale( Application::GetSettings().GetUILanguageTag());
159 pSVData
->mpResMgr
= ResMgr::SearchCreateResMgr( "vcl", aLocale
);
161 static bool bMessageOnce
= false;
162 if( !pSVData
->mpResMgr
&& ! bMessageOnce
)
166 "Missing vcl resource. This indicates that files vital to localization are missing. "
167 "You might have a corrupt installation.";
168 fprintf( stderr
, "%s\n", pMsg
);
169 ScopedVclPtrInstance
< MessageDialog
> aBox( nullptr, OUString(pMsg
, strlen(pMsg
), RTL_TEXTENCODING_ASCII_US
) );
173 return pSVData
->mpResMgr
;
176 ResId
VclResId( sal_Int32 nId
)
178 ResMgr
* pMgr
= ImplGetResMgr();
180 throw std::bad_alloc();
182 return ResId( nId
, *pMgr
);
185 FieldUnitStringList
* ImplGetFieldUnits()
187 ImplSVData
* pSVData
= ImplGetSVData();
188 if( ! pSVData
->maCtrlData
.mpFieldUnitStrings
)
190 ResMgr
* pResMgr
= ImplGetResMgr();
193 ResStringArray
aUnits( ResId (SV_FUNIT_STRINGS
, *pResMgr
) );
194 sal_uInt32 nUnits
= aUnits
.Count();
195 pSVData
->maCtrlData
.mpFieldUnitStrings
= new FieldUnitStringList();
196 pSVData
->maCtrlData
.mpFieldUnitStrings
->reserve( nUnits
);
197 for( sal_uInt32 i
= 0; i
< nUnits
; i
++ )
199 std::pair
< OUString
, FieldUnit
> aElement( aUnits
.GetString(i
), static_cast<FieldUnit
>(aUnits
.GetValue(i
)) );
200 pSVData
->maCtrlData
.mpFieldUnitStrings
->push_back( aElement
);
204 return pSVData
->maCtrlData
.mpFieldUnitStrings
;
207 FieldUnitStringList
* ImplGetCleanedFieldUnits()
209 ImplSVData
* pSVData
= ImplGetSVData();
210 if( ! pSVData
->maCtrlData
.mpCleanUnitStrings
)
212 FieldUnitStringList
* pUnits
= ImplGetFieldUnits();
215 size_t nUnits
= pUnits
->size();
216 pSVData
->maCtrlData
.mpCleanUnitStrings
= new FieldUnitStringList();
217 pSVData
->maCtrlData
.mpCleanUnitStrings
->reserve( nUnits
);
218 for( size_t i
= 0; i
< nUnits
; ++i
)
220 OUString
aUnit( (*pUnits
)[i
].first
);
221 aUnit
= comphelper::string::remove(aUnit
, ' ');
222 aUnit
= aUnit
.toAsciiLowerCase();
223 std::pair
< OUString
, FieldUnit
> aElement( aUnit
, (*pUnits
)[i
].second
);
224 pSVData
->maCtrlData
.mpCleanUnitStrings
->push_back( aElement
);
228 return pSVData
->maCtrlData
.mpCleanUnitStrings
;
231 DockingManager
* ImplGetDockingManager()
233 ImplSVData
* pSVData
= ImplGetSVData();
234 if ( !pSVData
->mpDockingManager
)
235 pSVData
->mpDockingManager
= new DockingManager();
237 return pSVData
->mpDockingManager
;
240 BlendFrameCache
* ImplGetBlendFrameCache()
242 ImplSVData
* pSVData
= ImplGetSVData();
243 if ( !pSVData
->mpBlendFrameCache
)
244 pSVData
->mpBlendFrameCache
= new BlendFrameCache();
246 return pSVData
->mpBlendFrameCache
;
253 bool ImplInitAccessBridge()
255 ImplSVData
* pSVData
= ImplGetSVData();
256 if( ! pSVData
->mxAccessBridge
.is() )
258 css::uno::Reference
< XComponentContext
> xContext(comphelper::getProcessComponentContext());
261 if (!HasAtHook() && !getenv("SAL_FORCE_IACCESSIBLE2"))
263 SAL_INFO("vcl", "Apparently no running AT -> "
264 "not enabling IAccessible2 integration");
269 pSVData
->mxAccessBridge
270 = css::accessibility::MSAAService::create(xContext
);
271 SAL_INFO("vcl", "got IAccessible2 bridge");
273 } catch (css::uno::DeploymentException
& e
) {
276 "got no IAccessible2 bridge" << e
.Message
);
286 vcl::Window
* ImplFindWindow( const SalFrame
* pFrame
, ::Point
& rSalFramePos
)
288 ImplSVData
* pSVData
= ImplGetSVData();
289 vcl::Window
* pFrameWindow
= pSVData
->maWinData
.mpFirstFrame
;
290 while ( pFrameWindow
)
292 if ( pFrameWindow
->ImplGetFrame() == pFrame
)
294 vcl::Window
* pWindow
= pFrameWindow
->ImplFindWindow( rSalFramePos
);
296 pWindow
= pFrameWindow
->ImplGetWindow();
297 rSalFramePos
= pWindow
->ImplFrameToOutput( rSalFramePos
);
300 pFrameWindow
= pFrameWindow
->ImplGetFrameData()->mpNextFrame
;
306 void LocaleConfigurationListener::ConfigurationChanged( utl::ConfigurationBroadcaster
*, sal_uInt32 nHint
)
308 AllSettings::LocaleSettingsChanged( nHint
);
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */