CWS-TOOLING: integrate CWS os150
[LibreOffice.git] / sd / source / ui / inc / tools / AsynchronousCall.hxx
blobe123afaa06fee4721c04114e9cc6c364a4350110
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef SD_ASYNCHRONOUS_CALL_HXX
29 #define SD_ASYNCHRONOUS_CALL_HXX
31 #include <vcl/timer.hxx>
32 #include <memory>
33 #include <boost/function.hpp>
35 namespace sd { namespace tools {
38 /** Store a function object and execute it asynchronous.
40 The features of this class are:
41 a) It provides a wrapper around a VCL Timer so that generic function
42 objects can be used.
43 b) When more than one function objects are posted to be executed later
44 then the pending ones are erased and only the last one will actually be
45 executed.
47 Use this class like this:
48 aInstanceOfAsynchronousCall.Post(
49 ::boost::bind(
50 ::std::mem_fun(&DrawViewShell::SwitchPage),
51 pDrawViewShell,
52 11));
54 class AsynchronousCall
56 public:
57 /** Create a new asynchronous call. Each object of this class processes
58 one (semantical) type of call.
60 AsynchronousCall (void);
62 ~AsynchronousCall (void);
64 /** Post a function object that is to be executed asynchronously. When
65 this method is called while the current function object has not bee
66 executed then the later is destroyed and only the given function
67 object will be executed.
68 @param rFunction
69 The function object that may be called asynchronously in the
70 near future.
71 @param nTimeoutInMilliseconds
72 The timeout in milliseconds until the function object is
73 executed.
75 typedef ::boost::function0<void> AsynchronousFunction;
76 void Post (
77 const AsynchronousFunction& rFunction,
78 sal_uInt32 nTimeoutInMilliseconds=10);
80 private:
81 Timer maTimer;
82 /** The function object that will be executed when the TimerCallback
83 function is called the next time. This pointer may be NULL.
85 ::std::auto_ptr<AsynchronousFunction> mpFunction;
86 DECL_LINK(TimerCallback,Timer*);
90 } } // end of namespace ::sd::tools
92 #endif