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 <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"
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
47 class SvtHelpOptions_Impl
: public utl::ConfigItem
49 sal_Bool bExtendedHelp
;
51 sal_Bool bWelcomeScreen
;
54 OUString sHelpStyleSheet
;
56 DECLARE_STL_USTRINGACCESS_MAP( sal_Int32
, MapString2Int
);
57 MapString2Int aURLIgnoreCounters
;
58 ::osl::Mutex aIgnoreCounterSafety
;
60 Sequence
< OUString
> GetPropertyNames();
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
[] =
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
] );
105 ::osl::Mutex
& SvtHelpOptions_Impl::getInitMutex()
107 static ::osl::Mutex
*pMutex
= 0;
111 ::osl::MutexGuard
guard( ::osl::Mutex::getGlobalMutex() );
114 static ::osl::Mutex mutex
;
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();
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
)
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" );
160 if ( pValues
[nProp
].hasValue() )
162 sal_Bool bTmp
= sal_Bool();
164 sal_Int32 nTmpInt
= 0;
165 if ( pValues
[nProp
] >>= bTmp
)
167 switch ( lcl_MapPropertyName(rPropertyNames
[nProp
], aInternalPropertyNames
) )
170 bExtendedHelp
= bTmp
;
176 SAL_WARN( "svtools.config", "Wrong Member!" );
180 else if ( pValues
[nProp
] >>= aTmpStr
)
192 sHelpStyleSheet
= aTmpStr
;
195 SAL_WARN( "svtools.config", "Wrong Member!" );
199 else if ( pValues
[nProp
] >>= nTmpInt
)
201 SAL_WARN( "svtools.config", "Wrong Member!" );
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
++ )
228 pValues
[nProp
] <<= bExtendedHelp
;
232 pValues
[nProp
] <<= bHelpTips
;
236 pValues
[nProp
] <<= OUString(aLocale
);
240 pValues
[nProp
] <<= OUString(aSystem
);
243 pValues
[nProp
] <<= OUString(sHelpStyleSheet
);
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() );
266 pOptions
= new SvtHelpOptions_Impl
;
268 svtools::ItemHolder2::holdConfigItem(E_HELPOPTIONS
);
273 // -----------------------------------------------------------------------
275 SvtHelpOptions::~SvtHelpOptions()
277 // Global access, must be guarded (multithreading)
278 ::osl::MutexGuard
aGuard( SvtHelpOptions_Impl::getInitMutex() );
281 if ( pOptions
->IsModified() )
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: */