1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: undoopt.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #ifdef SVL_DLLIMPLEMENTATION
34 #undef SVL_DLLIMPLEMENTATION
36 #define SVT_DLLIMPLEMENTATION
38 #include <svtools/undoopt.hxx>
39 #include "rtl/instance.hxx"
40 #include <unotools/configmgr.hxx>
41 #include <unotools/configitem.hxx>
42 #include <tools/debug.hxx>
43 #include <com/sun/star/uno/Any.hxx>
44 #include <com/sun/star/uno/Sequence.hxx>
45 #include <vos/mutex.hxx>
46 #include <svtools/smplhint.hxx>
47 #include <vcl/svapp.hxx>
48 #include <osl/mutex.hxx>
49 #include <rtl/logfile.hxx>
50 #include "itemholder2.hxx"
54 using namespace com::sun::star::uno
;
56 static SvtUndoOptions_Impl
* pOptions
= NULL
;
57 static sal_Int32 nRefCount
= 0;
61 class SvtUndoOptions_Impl
: public utl::ConfigItem
, public SfxBroadcaster
64 Sequence
< rtl::OUString
> m_aPropertyNames
;
67 SvtUndoOptions_Impl();
69 virtual void Notify( const com::sun::star::uno::Sequence
< rtl::OUString
>& aPropertyNames
);
70 virtual void Commit();
73 void SetUndoCount( sal_Int32 n
) { nUndoCount
= n
; SetModified(); }
74 sal_Int32
GetUndoCount() const { return nUndoCount
; }
77 // -----------------------------------------------------------------------
79 SvtUndoOptions_Impl::SvtUndoOptions_Impl()
80 : ConfigItem( OUString::createFromAscii("Office.Common/Undo") )
86 void SvtUndoOptions_Impl::Commit()
88 Sequence
< Any
> aValues( m_aPropertyNames
.getLength() );
89 Any
* pValues
= aValues
.getArray();
90 for ( int nProp
= 0; nProp
< m_aPropertyNames
.getLength(); nProp
++ )
95 pValues
[nProp
] <<= nUndoCount
;
98 DBG_ERRORFILE( "invalid index to save a path" );
102 PutProperties( m_aPropertyNames
, aValues
);
104 Broadcast(SfxSimpleHint(SFX_HINT_UNDO_OPTIONS_CHANGED
));
107 // -----------------------------------------------------------------------
108 void SvtUndoOptions_Impl::Load()
110 if(!m_aPropertyNames
.getLength())
112 static const char* aPropNames
[] =
117 const int nCount
= sizeof( aPropNames
) / sizeof( const char* );
118 m_aPropertyNames
.realloc(nCount
);
119 OUString
* pNames
= m_aPropertyNames
.getArray();
120 for ( int i
= 0; i
< nCount
; i
++ )
121 pNames
[i
] = OUString::createFromAscii( aPropNames
[i
] );
122 EnableNotification( m_aPropertyNames
);
125 Sequence
< Any
> aValues
= GetProperties( m_aPropertyNames
);
126 const Any
* pValues
= aValues
.getConstArray();
127 DBG_ASSERT( aValues
.getLength() == m_aPropertyNames
.getLength(), "GetProperties failed" );
128 if ( aValues
.getLength() == m_aPropertyNames
.getLength() )
130 for ( int nProp
= 0; nProp
< m_aPropertyNames
.getLength(); nProp
++ )
132 DBG_ASSERT( pValues
[nProp
].hasValue(), "property value missing" );
133 if ( pValues
[nProp
].hasValue() )
140 if ( pValues
[nProp
] >>= nTemp
)
144 DBG_ERROR( "Wrong Type!" );
150 DBG_ERROR( "Wrong Type!" );
157 // -----------------------------------------------------------------------
158 void SvtUndoOptions_Impl::Notify( const Sequence
<rtl::OUString
>& )
162 Broadcast(SfxSimpleHint(SFX_HINT_UNDO_OPTIONS_CHANGED
));
165 // -----------------------------------------------------------------------
168 class LocalSingleton
: public rtl::Static
< osl::Mutex
, LocalSingleton
>
173 // -----------------------------------------------------------------------
174 SvtUndoOptions::SvtUndoOptions()
176 // Global access, must be guarded (multithreading)
177 ::osl::MutexGuard
aGuard( LocalSingleton::get() );
180 RTL_LOGFILE_CONTEXT(aLog
, "svtools ( ??? ) ::SvtUndoOptions_Impl::ctor()");
181 pOptions
= new SvtUndoOptions_Impl
;
183 ItemHolder2::holdConfigItem(E_UNDOOPTIONS
);
187 StartListening(*pImp
);
190 // -----------------------------------------------------------------------
192 SvtUndoOptions::~SvtUndoOptions()
194 // Global access, must be guarded (multithreading)
195 ::osl::MutexGuard
aGuard( LocalSingleton::get() );
199 if ( pOptions
->IsModified() )
205 void SvtUndoOptions::SetUndoCount( sal_Int32 n
)
207 pImp
->SetUndoCount( n
);
210 sal_Int32
SvtUndoOptions::GetUndoCount() const
212 return pImp
->GetUndoCount();
215 void SvtUndoOptions::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
217 vos::OGuard
aVclGuard( Application::GetSolarMutex() );