fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / svtools / source / config / helpopt.cxx
blobf19ecd3b3b8dff450ab63df65f525f0ac96d22fd
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 .
20 #include <sal/config.h>
22 #include <map>
24 #include <svtools/helpopt.hxx>
25 #include <unotools/configmgr.hxx>
26 #include <unotools/configitem.hxx>
27 #include <tools/debug.hxx>
28 #include <com/sun/star/uno/Any.hxx>
29 #include <com/sun/star/uno/Sequence.hxx>
30 #include <vcl/help.hxx>
31 #include <osl/mutex.hxx>
33 #include "itemholder2.hxx"
35 using namespace utl;
36 using namespace com::sun::star::uno;
37 using namespace com::sun::star;
40 static SvtHelpOptions_Impl* pOptions = NULL;
41 static sal_Int32 nRefCount = 0;
43 #define EXTENDEDHELP 0
44 #define HELPTIPS 1
45 #define LOCALE 2
46 #define SYSTEM 3
47 #define STYLESHEET 4
49 class SvtHelpOptions_Impl : public utl::ConfigItem
51 bool bExtendedHelp;
52 bool bHelpTips;
53 bool bWelcomeScreen;
54 OUString aLocale;
55 OUString aSystem;
56 OUString sHelpStyleSheet;
58 typedef std::map <OUString, sal_Int32> MapString2Int;
59 MapString2Int aURLIgnoreCounters;
61 static Sequence< OUString > GetPropertyNames();
63 virtual void ImplCommit() SAL_OVERRIDE;
65 public:
66 SvtHelpOptions_Impl();
68 virtual void Notify( const com::sun::star::uno::Sequence< OUString >& aPropertyNames ) SAL_OVERRIDE;
69 void Load( const ::com::sun::star::uno::Sequence< OUString>& aPropertyNames);
71 void SetExtendedHelp( bool b ) { bExtendedHelp= b; SetModified(); }
72 bool IsExtendedHelp() const { return bExtendedHelp; }
73 void SetHelpTips( bool b ) { bHelpTips = b; SetModified(); }
74 bool IsHelpTips() const { return bHelpTips; }
76 void SetWelcomeScreen( bool b ) { bWelcomeScreen = b; SetModified(); }
77 bool IsWelcomeScreen() const { return bWelcomeScreen; }
78 OUString GetSystem() const { return aSystem; }
80 const OUString& GetHelpStyleSheet()const{return sHelpStyleSheet;}
81 void SetHelpStyleSheet(const OUString& rStyleSheet){sHelpStyleSheet = rStyleSheet; SetModified();}
83 static ::osl::Mutex & getInitMutex();
86 Sequence< OUString > SvtHelpOptions_Impl::GetPropertyNames()
88 static const char* aPropNames[] =
90 "ExtendedTip",
91 "Tip",
92 "Locale",
93 "System",
94 "HelpStyleSheet"
97 const int nCount = sizeof( aPropNames ) / sizeof( const char* );
98 Sequence< OUString > aNames( nCount );
99 OUString* pNames = aNames.getArray();
100 for ( int i = 0; i < nCount; i++ )
101 pNames[i] = OUString::createFromAscii( aPropNames[i] );
103 return aNames;
106 ::osl::Mutex & SvtHelpOptions_Impl::getInitMutex()
108 static ::osl::Mutex *pMutex = 0;
110 if( ! pMutex )
112 ::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() );
113 if( ! pMutex )
115 static ::osl::Mutex mutex;
116 pMutex = &mutex;
119 return *pMutex;
125 SvtHelpOptions_Impl::SvtHelpOptions_Impl()
126 : ConfigItem( OUString( "Office.Common/Help" ) )
127 , bExtendedHelp( false )
128 , bHelpTips( true )
129 , bWelcomeScreen( false )
131 Sequence< OUString > aNames = GetPropertyNames();
132 Load( aNames );
133 EnableNotification( aNames );
137 static int lcl_MapPropertyName( const OUString& rCompare,
138 const uno::Sequence< OUString>& aInternalPropertyNames)
140 for(int nProp = 0; nProp < aInternalPropertyNames.getLength(); ++nProp)
142 if( aInternalPropertyNames[nProp] == rCompare )
143 return nProp;
145 return -1;
148 void SvtHelpOptions_Impl::Load(const uno::Sequence< OUString>& rPropertyNames)
150 const uno::Sequence< OUString> aInternalPropertyNames( GetPropertyNames());
151 Sequence< Any > aValues = GetProperties( rPropertyNames );
152 const Any* pValues = aValues.getConstArray();
153 DBG_ASSERT( aValues.getLength() == rPropertyNames.getLength(), "GetProperties failed" );
154 if ( aValues.getLength() == rPropertyNames.getLength() )
156 for ( int nProp = 0; nProp < rPropertyNames.getLength(); nProp++ )
158 #if OSL_DEBUG_LEVEL > 1
159 DBG_ASSERT( pValues[nProp].hasValue(), "property value missing" );
160 #endif
161 if ( pValues[nProp].hasValue() )
163 bool bTmp;
164 OUString aTmpStr;
165 sal_Int32 nTmpInt = 0;
166 if ( pValues[nProp] >>= bTmp )
168 switch ( lcl_MapPropertyName(rPropertyNames[nProp], aInternalPropertyNames) )
170 case EXTENDEDHELP :
171 bExtendedHelp = bTmp;
172 break;
173 case HELPTIPS :
174 bHelpTips = bTmp;
175 break;
176 default:
177 SAL_WARN( "svtools.config", "Wrong Member!" );
178 break;
181 else if ( pValues[nProp] >>= aTmpStr )
183 switch ( nProp )
185 case LOCALE:
186 aLocale = aTmpStr;
187 break;
189 case SYSTEM:
190 aSystem = aTmpStr;
191 break;
192 case STYLESHEET :
193 sHelpStyleSheet = aTmpStr;
194 break;
195 default:
196 SAL_WARN( "svtools.config", "Wrong Member!" );
197 break;
200 else if ( pValues[nProp] >>= nTmpInt )
202 SAL_WARN( "svtools.config", "Wrong Member!" );
204 else
206 SAL_WARN( "svtools.config", "Wrong Type!" );
210 if ( IsHelpTips() != Help::IsQuickHelpEnabled() )
211 IsHelpTips() ? Help::EnableQuickHelp() : Help::DisableQuickHelp();
212 if ( IsExtendedHelp() != Help::IsBalloonHelpEnabled() )
213 IsExtendedHelp() ? Help::EnableBalloonHelp() : Help::DisableBalloonHelp();
219 void SvtHelpOptions_Impl::ImplCommit()
221 Sequence< OUString > aNames = GetPropertyNames();
222 Sequence< Any > aValues( aNames.getLength() );
223 Any* pValues = aValues.getArray();
224 for ( int nProp = 0; nProp < aNames.getLength(); nProp++ )
226 switch ( nProp )
228 case EXTENDEDHELP :
229 pValues[nProp] <<= bExtendedHelp;
230 break;
232 case HELPTIPS :
233 pValues[nProp] <<= bHelpTips;
234 break;
236 case LOCALE:
237 pValues[nProp] <<= OUString(aLocale);
238 break;
240 case SYSTEM:
241 pValues[nProp] <<= OUString(aSystem);
242 break;
243 case STYLESHEET :
244 pValues[nProp] <<= OUString(sHelpStyleSheet);
245 break;
250 PutProperties( aNames, aValues );
255 void SvtHelpOptions_Impl::Notify( const Sequence<OUString>& aPropertyNames )
257 Load( aPropertyNames );
260 SvtHelpOptions::SvtHelpOptions()
262 // Global access, must be guarded (multithreading)
263 ::osl::MutexGuard aGuard( SvtHelpOptions_Impl::getInitMutex() );
264 ++nRefCount;
265 if ( !pOptions )
267 pOptions = new SvtHelpOptions_Impl;
269 svtools::ItemHolder2::holdConfigItem(E_HELPOPTIONS);
271 pImp = pOptions;
276 SvtHelpOptions::~SvtHelpOptions()
278 // Global access, must be guarded (multithreading)
279 ::osl::MutexGuard aGuard( SvtHelpOptions_Impl::getInitMutex() );
280 if ( !--nRefCount )
282 if ( pOptions->IsModified() )
283 pOptions->Commit();
284 DELETEZ( pOptions );
288 void SvtHelpOptions::SetExtendedHelp( bool b )
290 pImp->SetExtendedHelp( b );
293 bool SvtHelpOptions::IsExtendedHelp() const
295 return pImp->IsExtendedHelp();
298 void SvtHelpOptions::SetHelpTips( bool b )
300 pImp->SetHelpTips( b );
303 bool SvtHelpOptions::IsHelpTips() const
305 return pImp->IsHelpTips();
310 void SvtHelpOptions::SetWelcomeScreen( bool b )
312 pImp->SetWelcomeScreen( b );
315 bool SvtHelpOptions::IsWelcomeScreen() const
317 return pImp->IsWelcomeScreen();
320 OUString SvtHelpOptions::GetSystem() const
322 return pImp->GetSystem();
325 const OUString& SvtHelpOptions::GetHelpStyleSheet()const
327 return pImp->GetHelpStyleSheet();
330 void SvtHelpOptions::SetHelpStyleSheet(const OUString& rStyleSheet)
332 pImp->SetHelpStyleSheet(rStyleSheet);
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */