1*95a18594SAndre Fischer /**************************************************************
2*95a18594SAndre Fischer  *
3*95a18594SAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
4*95a18594SAndre Fischer  * or more contributor license agreements.  See the NOTICE file
5*95a18594SAndre Fischer  * distributed with this work for additional information
6*95a18594SAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
7*95a18594SAndre Fischer  * to you under the Apache License, Version 2.0 (the
8*95a18594SAndre Fischer  * "License"); you may not use this file except in compliance
9*95a18594SAndre Fischer  * with the License.  You may obtain a copy of the License at
10*95a18594SAndre Fischer  *
11*95a18594SAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
12*95a18594SAndre Fischer  *
13*95a18594SAndre Fischer  * Unless required by applicable law or agreed to in writing,
14*95a18594SAndre Fischer  * software distributed under the License is distributed on an
15*95a18594SAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*95a18594SAndre Fischer  * KIND, either express or implied.  See the License for the
17*95a18594SAndre Fischer  * specific language governing permissions and limitations
18*95a18594SAndre Fischer  * under the License.
19*95a18594SAndre Fischer  *
20*95a18594SAndre Fischer  *************************************************************/
21*95a18594SAndre Fischer 
22*95a18594SAndre Fischer #include "precompiled_sfx2.hxx"
23*95a18594SAndre Fischer 
24*95a18594SAndre Fischer #include "AsynchronousCall.hxx"
25*95a18594SAndre Fischer 
26*95a18594SAndre Fischer #include <vcl/svapp.hxx>
27*95a18594SAndre Fischer 
28*95a18594SAndre Fischer 
29*95a18594SAndre Fischer namespace sfx2 { namespace sidebar {
30*95a18594SAndre Fischer 
31*95a18594SAndre Fischer AsynchronousCall::AsynchronousCall (const Action& rAction)
32*95a18594SAndre Fischer     : maAction(rAction),
33*95a18594SAndre Fischer       mnCallId(0)
34*95a18594SAndre Fischer {
35*95a18594SAndre Fischer }
36*95a18594SAndre Fischer 
37*95a18594SAndre Fischer 
38*95a18594SAndre Fischer 
39*95a18594SAndre Fischer 
40*95a18594SAndre Fischer AsynchronousCall::~AsynchronousCall (void)
41*95a18594SAndre Fischer {
42*95a18594SAndre Fischer     CancelRequest();
43*95a18594SAndre Fischer }
44*95a18594SAndre Fischer 
45*95a18594SAndre Fischer 
46*95a18594SAndre Fischer 
47*95a18594SAndre Fischer 
48*95a18594SAndre Fischer void AsynchronousCall::RequestCall (const Action& rAction)
49*95a18594SAndre Fischer {
50*95a18594SAndre Fischer     CancelRequest();
51*95a18594SAndre Fischer     maAction = rAction;
52*95a18594SAndre Fischer     RequestCall();
53*95a18594SAndre Fischer }
54*95a18594SAndre Fischer 
55*95a18594SAndre Fischer 
56*95a18594SAndre Fischer 
57*95a18594SAndre Fischer 
58*95a18594SAndre Fischer void AsynchronousCall::RequestCall (void)
59*95a18594SAndre Fischer {
60*95a18594SAndre Fischer     if (mnCallId == 0)
61*95a18594SAndre Fischer     {
62*95a18594SAndre Fischer         Link aLink (LINK(this, AsynchronousCall, HandleUserCall));
63*95a18594SAndre Fischer         mnCallId = Application::PostUserEvent(aLink);
64*95a18594SAndre Fischer     }
65*95a18594SAndre Fischer }
66*95a18594SAndre Fischer 
67*95a18594SAndre Fischer 
68*95a18594SAndre Fischer 
69*95a18594SAndre Fischer 
70*95a18594SAndre Fischer void AsynchronousCall::CancelRequest (void)
71*95a18594SAndre Fischer {
72*95a18594SAndre Fischer     if (mnCallId != 0)
73*95a18594SAndre Fischer     {
74*95a18594SAndre Fischer         Application::RemoveUserEvent(mnCallId);
75*95a18594SAndre Fischer         mnCallId = -1;
76*95a18594SAndre Fischer     }
77*95a18594SAndre Fischer }
78*95a18594SAndre Fischer 
79*95a18594SAndre Fischer 
80*95a18594SAndre Fischer 
81*95a18594SAndre Fischer 
82*95a18594SAndre Fischer IMPL_LINK(AsynchronousCall, HandleUserCall, void*, EMPTYARG )
83*95a18594SAndre Fischer {
84*95a18594SAndre Fischer     mnCallId = 0;
85*95a18594SAndre Fischer     if (maAction)
86*95a18594SAndre Fischer         maAction();
87*95a18594SAndre Fischer 
88*95a18594SAndre Fischer     return sal_True;
89*95a18594SAndre Fischer }
90*95a18594SAndre Fischer 
91*95a18594SAndre Fischer 
92*95a18594SAndre Fischer } } // end of namespace sfx2::sidebar
93*95a18594SAndre Fischer 
94