sync master with lastest vba changes
[ooovba.git] / binfilter / inc / bf_svtools / cancel.hxx
blob592fcf9e37e0ab23c4c007ef3b4d9c60d1700281
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.hxx,v $
10 * $Revision: 1.3 $
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>
35 #endif
37 #ifndef _REF_HXX //autogen
38 #include <tools/ref.hxx>
39 #endif
41 #ifndef _SFXBRDCST_HXX
42 #include <bf_svtools/brdcst.hxx>
43 #endif
45 #ifndef _SFXSMPLHINT_HXX
46 #include <bf_svtools/smplhint.hxx>
47 #endif
49 namespace binfilter {
51 class SfxCancellable;
53 #ifdef _SFX_CANCEL_CXX
55 #ifndef _SVARRAY_HXX
56 #include <bf_svtools/svarray.hxx>
57 #endif
59 SV_DECL_PTRARR( SfxCancellables_Impl, SfxCancellable*, 0, 4 )
61 #else
63 typedef SvPtrarr SfxCancellables_Impl;
65 #endif
67 //-------------------------------------------------------------------------
69 class SfxCancelManager: public SfxBroadcaster
70 , public SvWeakBase
72 /* [Beschreibung]
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
78 gebroadcastet.
80 SfxCancelManager k"onnen hierarchisch angeordnet werden, so k"onnen
81 z.B. Dokument-lokale Prozesse getrennt gecancelt werden.
83 [Beispiel]
85 SfxCancelManager *pMgr = new SfxCancelManager;
86 StartListening( pMgr );
87 pMailSystem->SetCancelManager( pMgr )
91 SfxCancelManager* _pParent;
92 SfxCancellables_Impl _aJobs;
94 public:
95 SfxCancelManager( SfxCancelManager *pParent = 0 );
96 ~SfxCancelManager();
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 //-------------------------------------------------------------------------
113 class SfxCancellable
115 /* [Beschreibung]
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'
120 setzen kann.
122 Die im Ctor "ubergebene <SfxCancelManger>-Instanz mu\s die Instanz
123 dieser Klasse "uberleben!
125 [Beispiel]
128 SfxCancellable aCancel( pCancelMgr );
129 while ( !aCancel && GetData() )
130 Reschedule();
136 SfxCancelManager* _pMgr;
137 BOOL _bCancelled;
138 String _aTitle;
140 public:
141 SfxCancellable( SfxCancelManager *pMgr,
142 const String &rTitle )
143 : _pMgr( pMgr ),
144 _bCancelled( FALSE ),
145 _aTitle( rTitle )
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; }
161 #endif