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: cancel.hxx,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 ************************************************************************/
30 #ifndef _SFXCANCEL_HXX
31 #define _SFXCANCEL_HXX
33 #ifndef _STRING_HXX //autogen
34 #include <tools/string.hxx>
37 #ifndef _REF_HXX //autogen
38 #include <tools/ref.hxx>
41 #ifndef _SFXBRDCST_HXX
42 #include <bf_svtools/brdcst.hxx>
45 #ifndef _SFXSMPLHINT_HXX
46 #include <bf_svtools/smplhint.hxx>
53 #ifdef _SFX_CANCEL_CXX
56 #include <bf_svtools/svarray.hxx>
59 SV_DECL_PTRARR( SfxCancellables_Impl
, SfxCancellable
*, 0, 4 )
63 typedef SvPtrarr SfxCancellables_Impl
;
67 //-------------------------------------------------------------------------
69 class SfxCancelManager
: public SfxBroadcaster
74 An Instanzen dieser Klasse k"onnen nebenl"aufige Prozesse angemeldet
75 werden, um vom Benutzer abbrechbar zu sein. Werden abbrechbare
76 Prozesse (Instanzen von <SfxCancellable>) an- oder abgemeldet, wird
77 dies durch einen <SfxSimpleHint> mit dem Flag SFX_HINT_CANCELLABLE
80 SfxCancelManager k"onnen hierarchisch angeordnet werden, so k"onnen
81 z.B. Dokument-lokale Prozesse getrennt gecancelt werden.
85 SfxCancelManager *pMgr = new SfxCancelManager;
86 StartListening( pMgr );
87 pMailSystem->SetCancelManager( pMgr )
91 SfxCancelManager
* _pParent
;
92 SfxCancellables_Impl _aJobs
;
95 SfxCancelManager( SfxCancelManager
*pParent
= 0 );
98 BOOL
CanCancel() const;
99 void Cancel( BOOL bDeep
);
100 SfxCancelManager
* GetParent() const { return _pParent
; }
102 void InsertCancellable( SfxCancellable
*pJob
);
103 void RemoveCancellable( SfxCancellable
*pJob
);
104 USHORT
GetCancellableCount() const
105 { return _aJobs
.Count(); }
106 SfxCancellable
* GetCancellable( USHORT nPos
) const
107 { return (SfxCancellable
*) _aJobs
[nPos
]; }
110 SV_DECL_WEAK( SfxCancelManager
)
111 //-------------------------------------------------------------------------
117 Instanzen dieser Klasse werden immer an einem Cancel-Manager angemeldet,
118 der dadurch dem Benutzer signalisieren kann, ob abbrechbare Prozesse
119 vorhanden sind und der die SfxCancellable-Instanzen auf 'abgebrochen'
122 Die im Ctor "ubergebene <SfxCancelManger>-Instanz mu\s die Instanz
123 dieser Klasse "uberleben!
128 SfxCancellable aCancel( pCancelMgr );
129 while ( !aCancel && GetData() )
136 SfxCancelManager
* _pMgr
;
141 SfxCancellable( SfxCancelManager
*pMgr
,
142 const String
&rTitle
)
144 _bCancelled( FALSE
),
146 { pMgr
->InsertCancellable( this ); }
148 virtual ~SfxCancellable();
150 void SetManager( SfxCancelManager
*pMgr
);
151 SfxCancelManager
* GetManager() const { return _pMgr
; }
153 virtual void Cancel();
154 BOOL
IsCancelled() const { return _bCancelled
; }
155 operator BOOL() const { return _bCancelled
; }
156 const String
& GetTitle() const { return _aTitle
; }