GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svtools / source / config / helpopt.cxx
blobd9f0d3d8db0e4307472a876785f8fd9857becfc5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <svtools/helpopt.hxx>
22 #include <unotools/configmgr.hxx>
23 #include <unotools/configitem.hxx>
24 #include <tools/debug.hxx>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/uno/Sequence.hxx>
27 #include <vcl/help.hxx>
28 #include <osl/mutex.hxx>
29 #include <comphelper/stl_types.hxx>
31 #include "itemholder2.hxx"
33 using namespace utl;
34 using namespace com::sun::star::uno;
35 using namespace com::sun::star;
38 static SvtHelpOptions_Impl* pOptions = NULL;
39 static sal_Int32 nRefCount = 0;
41 #define EXTENDEDHELP 0
42 #define HELPTIPS 1
43 #define LOCALE 2
44 #define SYSTEM 3
45 #define STYLESHEET 4
47 class SvtHelpOptions_Impl : public utl::ConfigItem
49 sal_Bool bExtendedHelp;
50 sal_Bool bHelpTips;
51 sal_Bool bWelcomeScreen;
52 OUString aLocale;
53 OUString aSystem;
54 OUString sHelpStyleSheet;
56 DECLARE_STL_USTRINGACCESS_MAP( sal_Int32, MapString2Int );
57 MapString2Int aURLIgnoreCounters;
58 ::osl::Mutex aIgnoreCounterSafety;
60 Sequence< OUString > GetPropertyNames();
62 public:
63 SvtHelpOptions_Impl();
65 virtual void Notify( const com::sun::star::uno::Sequence< OUString >& aPropertyNames );
66 void Load( const ::com::sun::star::uno::Sequence< OUString>& aPropertyNames);
67 virtual void Commit();
69 void SetExtendedHelp( sal_Bool b ) { bExtendedHelp= b; SetModified(); }
70 sal_Bool IsExtendedHelp() const { return bExtendedHelp; }
71 void SetHelpTips( sal_Bool b ) { bHelpTips = b; SetModified(); }
72 sal_Bool IsHelpTips() const { return bHelpTips; }
74 void SetWelcomeScreen( sal_Bool b ) { bWelcomeScreen = b; SetModified(); }
75 sal_Bool IsWelcomeScreen() const { return bWelcomeScreen; }
76 OUString GetLocale() const { return aLocale; }
77 OUString GetSystem() const { return aSystem; }
79 const OUString& GetHelpStyleSheet()const{return sHelpStyleSheet;}
80 void SetHelpStyleSheet(const OUString& rStyleSheet){sHelpStyleSheet = rStyleSheet; SetModified();}
82 static ::osl::Mutex & getInitMutex();
85 Sequence< OUString > SvtHelpOptions_Impl::GetPropertyNames()
87 static const char* aPropNames[] =
89 "ExtendedTip",
90 "Tip",
91 "Locale",
92 "System",
93 "HelpStyleSheet"
96 const int nCount = sizeof( aPropNames ) / sizeof( const char* );
97 Sequence< OUString > aNames( nCount );
98 OUString* pNames = aNames.getArray();
99 for ( int i = 0; i < nCount; i++ )
100 pNames[i] = OUString::createFromAscii( aPropNames[i] );
102 return aNames;
105 ::osl::Mutex & SvtHelpOptions_Impl::getInitMutex()
107 static ::osl::Mutex *pMutex = 0;
109 if( ! pMutex )
111 ::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() );
112 if( ! pMutex )
114 static ::osl::Mutex mutex;
115 pMutex = &mutex;
118 return *pMutex;
122 // -----------------------------------------------------------------------
124 SvtHelpOptions_Impl::SvtHelpOptions_Impl()
125 : ConfigItem( OUString( "Office.Common/Help" ) )
126 , bExtendedHelp( sal_False )
127 , bHelpTips( sal_True )
128 , bWelcomeScreen( sal_False )
130 Sequence< OUString > aNames = GetPropertyNames();
131 Load( aNames );
132 EnableNotification( aNames );
135 // -----------------------------------------------------------------------
136 static int lcl_MapPropertyName( const OUString rCompare,
137 const uno::Sequence< OUString>& aInternalPropertyNames)
139 for(int nProp = 0; nProp < aInternalPropertyNames.getLength(); ++nProp)
141 if( aInternalPropertyNames[nProp] == rCompare )
142 return nProp;
144 return -1;
147 void SvtHelpOptions_Impl::Load(const uno::Sequence< OUString>& rPropertyNames)
149 const uno::Sequence< OUString> aInternalPropertyNames( GetPropertyNames());
150 Sequence< Any > aValues = GetProperties( rPropertyNames );
151 const Any* pValues = aValues.getConstArray();
152 DBG_ASSERT( aValues.getLength() == rPropertyNames.getLength(), "GetProperties failed" );
153 if ( aValues.getLength() == rPropertyNames.getLength() )
155 for ( int nProp = 0; nProp < rPropertyNames.getLength(); nProp++ )
157 #if OSL_DEBUG_LEVEL > 1
158 DBG_ASSERT( pValues[nProp].hasValue(), "property value missing" );
159 #endif
160 if ( pValues[nProp].hasValue() )
162 sal_Bool bTmp = sal_Bool();
163 OUString aTmpStr;
164 sal_Int32 nTmpInt = 0;
165 if ( pValues[nProp] >>= bTmp )
167 switch ( lcl_MapPropertyName(rPropertyNames[nProp], aInternalPropertyNames) )
169 case EXTENDEDHELP :
170 bExtendedHelp = bTmp;
171 break;
172 case HELPTIPS :
173 bHelpTips = bTmp;
174 break;
175 default:
176 SAL_WARN( "svtools.config", "Wrong Member!" );
177 break;
180 else if ( pValues[nProp] >>= aTmpStr )
182 switch ( nProp )
184 case LOCALE:
185 aLocale = aTmpStr;
186 break;
188 case SYSTEM:
189 aSystem = aTmpStr;
190 break;
191 case STYLESHEET :
192 sHelpStyleSheet = aTmpStr;
193 break;
194 default:
195 SAL_WARN( "svtools.config", "Wrong Member!" );
196 break;
199 else if ( pValues[nProp] >>= nTmpInt )
201 SAL_WARN( "svtools.config", "Wrong Member!" );
203 else
205 SAL_WARN( "svtools.config", "Wrong Type!" );
209 if ( IsHelpTips() != Help::IsQuickHelpEnabled() )
210 IsHelpTips() ? Help::EnableQuickHelp() : Help::DisableQuickHelp();
211 if ( IsExtendedHelp() != Help::IsBalloonHelpEnabled() )
212 IsExtendedHelp() ? Help::EnableBalloonHelp() : Help::DisableBalloonHelp();
216 // -----------------------------------------------------------------------
218 void SvtHelpOptions_Impl::Commit()
220 Sequence< OUString > aNames = GetPropertyNames();
221 Sequence< Any > aValues( aNames.getLength() );
222 Any* pValues = aValues.getArray();
223 for ( int nProp = 0; nProp < aNames.getLength(); nProp++ )
225 switch ( nProp )
227 case EXTENDEDHELP :
228 pValues[nProp] <<= bExtendedHelp;
229 break;
231 case HELPTIPS :
232 pValues[nProp] <<= bHelpTips;
233 break;
235 case LOCALE:
236 pValues[nProp] <<= OUString(aLocale);
237 break;
239 case SYSTEM:
240 pValues[nProp] <<= OUString(aSystem);
241 break;
242 case STYLESHEET :
243 pValues[nProp] <<= OUString(sHelpStyleSheet);
244 break;
249 PutProperties( aNames, aValues );
252 // -----------------------------------------------------------------------
254 void SvtHelpOptions_Impl::Notify( const Sequence<OUString>& aPropertyNames )
256 Load( aPropertyNames );
259 SvtHelpOptions::SvtHelpOptions()
261 // Global access, must be guarded (multithreading)
262 ::osl::MutexGuard aGuard( SvtHelpOptions_Impl::getInitMutex() );
263 ++nRefCount;
264 if ( !pOptions )
266 pOptions = new SvtHelpOptions_Impl;
268 svtools::ItemHolder2::holdConfigItem(E_HELPOPTIONS);
270 pImp = pOptions;
273 // -----------------------------------------------------------------------
275 SvtHelpOptions::~SvtHelpOptions()
277 // Global access, must be guarded (multithreading)
278 ::osl::MutexGuard aGuard( SvtHelpOptions_Impl::getInitMutex() );
279 if ( !--nRefCount )
281 if ( pOptions->IsModified() )
282 pOptions->Commit();
283 DELETEZ( pOptions );
287 void SvtHelpOptions::SetExtendedHelp( sal_Bool b )
289 pImp->SetExtendedHelp( b );
292 sal_Bool SvtHelpOptions::IsExtendedHelp() const
294 return pImp->IsExtendedHelp();
297 void SvtHelpOptions::SetHelpTips( sal_Bool b )
299 pImp->SetHelpTips( b );
302 sal_Bool SvtHelpOptions::IsHelpTips() const
304 return pImp->IsHelpTips();
307 // -----------------------------------------------------------------------
309 void SvtHelpOptions::SetWelcomeScreen( sal_Bool b )
311 pImp->SetWelcomeScreen( b );
314 sal_Bool SvtHelpOptions::IsWelcomeScreen() const
316 return pImp->IsWelcomeScreen();
319 OUString SvtHelpOptions::GetSystem() const
321 return pImp->GetSystem();
324 const OUString& SvtHelpOptions::GetHelpStyleSheet()const
326 return pImp->GetHelpStyleSheet();
329 void SvtHelpOptions::SetHelpStyleSheet(const OUString& rStyleSheet)
331 pImp->SetHelpStyleSheet(rStyleSheet);
334 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */