merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / notify / cancel.cxx
blob013e30a96cac66bcf7530b62b57975d2dedb7778
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cancel.cxx,v $
10 * $Revision: 1.9 $
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 #define _SFX_CANCEL_CXX
34 #include <svtools/cancel.hxx>
36 #include <vos/mutex.hxx>
37 #include <tools/debug.hxx>
39 #include <svtools/smplhint.hxx>
40 #include <svtools/cnclhint.hxx>
41 #include <rtl/instance.hxx>
43 namespace { struct lclMutex : public rtl::Static< ::vos::OMutex, lclMutex >{}; }
45 //=========================================================================
47 SfxCancelManager::SfxCancelManager( SfxCancelManager *pParent )
48 : _pParent( pParent )
52 //-------------------------------------------------------------------------
54 SfxCancelManager::~SfxCancelManager()
56 DBG_ASSERT( _pParent || !_aJobs.Count(), "deleting SfxCancelManager in use" );
57 for ( USHORT n = _aJobs.Count(); n--; )
58 _aJobs.GetObject(n)->SetManager( _pParent );
61 //-------------------------------------------------------------------------
63 BOOL SfxCancelManager::CanCancel() const
65 /* [Beschreibung]
67 Liefert TRUE wenn an diesem CancelManager oder an einem Parent
68 ein Job l"auft.
72 ::vos::OGuard aGuard( lclMutex::get() );
73 return _aJobs.Count() > 0 || ( _pParent && _pParent->CanCancel() );
76 //-------------------------------------------------------------------------
78 void SfxCancelManager::Cancel( BOOL bDeep )
80 /* [Beschreibung]
82 Diese Methode markiert alle angemeldeten <SfxCancellable>-Instanzen
83 als suspendiert.
87 ::vos::OGuard aGuard( lclMutex::get() );
88 SfxCancelManagerWeak xWeak( this );
89 for ( USHORT n = _aJobs.Count(); n-- && xWeak.Is(); )
90 if ( n < _aJobs.Count() )
91 _aJobs.GetObject(n)->Cancel();
92 if ( xWeak.Is() && _pParent )
93 _pParent->Cancel( bDeep );
96 //-------------------------------------------------------------------------
98 void SfxCancelManager::InsertCancellable( SfxCancellable *pJob )
100 /* [Beschreibung]
102 Diese interne Methode tr"agt 'pJob' in die Liste der unterbrechbaren
103 Jobs ein und Broadcastet dies. Jeder <SfxCancellable> darf nur
104 maximal einmal angemeldet sein, dies geschiet in seinem Ctor.
108 #ifdef GPF_ON_EMPTY_TITLE
109 if ( !pJob->GetTitle() )
111 DBG_ERROR( "SfxCancellable: empty titles not allowed (Vermummungsverbot)" )
112 *(int*)0 = 0;
114 #endif
116 ::vos::OClearableGuard aGuard( lclMutex::get() );
117 _aJobs.C40_INSERT( SfxCancellable, pJob, _aJobs.Count() );
119 aGuard.clear();
120 Broadcast( SfxSimpleHint( SFX_HINT_CANCELLABLE ) );
123 //-------------------------------------------------------------------------
126 void SfxCancelManager::RemoveCancellable( SfxCancellable *pJob )
128 /* [Beschreibung]
130 Diese interne Methode tr"agt 'pJob' aus die Liste der unterbrechbaren
131 Jobs aus und Broadcastet dies. Dieser Aufruf mu\s paarig nach einem
132 <InsertCancellable> erfolgen und wird im Dtor des <SfxCancellable>
133 ausgel"ost.
137 ::vos::OClearableGuard aGuard( lclMutex::get() );
138 const SfxCancellable *pTmp = pJob;
139 USHORT nPos = _aJobs.GetPos( pTmp );
140 if ( nPos != 0xFFFF )
142 _aJobs.Remove( nPos , 1 );
143 aGuard.clear();
144 Broadcast( SfxSimpleHint( SFX_HINT_CANCELLABLE ) );
145 Broadcast( SfxCancelHint( pJob, SFXCANCELHINT_REMOVED ) );
149 //-------------------------------------------------------------------------
151 SfxCancellable::~SfxCancellable()
153 SfxCancelManager* pMgr = _pMgr;
154 if ( pMgr )
155 pMgr->RemoveCancellable( this );
158 //-------------------------------------------------------------------------
160 void SfxCancellable::Cancel()
162 /* [Description]
164 This virtual function is called when the user hits the cancel-button.
165 If you overload it, you can stop your activities. Please always call
166 'SfxCancellable::Cancel()'.
170 #ifdef GFP_ON_NO_CANCEL
171 if ( _bCancelled < 5 )
172 ++_bCancelled;
173 else
175 delete this;
177 #else
178 _bCancelled = TRUE;
179 #endif
182 //-------------------------------------------------------------------------
184 void SfxCancellable::SetManager( SfxCancelManager *pMgr )
186 SfxCancelManager* pTmp = _pMgr;
187 if ( pTmp )
188 pTmp->RemoveCancellable( this );
189 _pMgr = pMgr;
190 if ( pMgr )
191 pMgr->InsertCancellable( this );
194 //-------------------------------------------------------------------------
196 TYPEINIT1(SfxCancelHint, SfxHint);
198 SfxCancelHint::SfxCancelHint( SfxCancellable* pJob, USHORT _nAction )
200 pCancellable = pJob;
201 nAction = _nAction;