update emoji autocorrect entries from po-files
[LibreOffice.git] / svtools / source / control / asynclink.cxx
blobd9d5652502ad1c72b037244c40e3c0eefe9d0862
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <svtools/asynclink.hxx>
22 #include <osl/mutex.hxx>
23 #include <tools/debug.hxx>
24 #include <vcl/timer.hxx>
25 #include <vcl/idle.hxx>
26 #include <vcl/svapp.hxx>
29 namespace svtools {
31 void AsynchronLink::CreateMutex()
33 if( !_pMutex ) _pMutex = new osl::Mutex;
36 void AsynchronLink::Call( void* pObj, bool
37 #ifdef DBG_UTIL
38 bAllowDoubles
39 #endif
40 , bool bUseTimer )
42 #ifdef DBG_UTIL
43 if ( bUseTimer || !_bInCall )
44 DBG_WARNING( "Recursives Call. Eher ueber Timer. TLX Fragen" );
45 #endif
46 if( _aLink.IsSet() )
48 _pArg = pObj;
49 DBG_ASSERT( bAllowDoubles ||
50 ( !_nEventId && ( !_pIdle || !_pIdle->IsActive() ) ),
51 "Schon ein Call unterwegs" );
52 ClearPendingCall();
53 if( bUseTimer )
55 if( !_pIdle )
57 _pIdle = new Idle;
58 _pIdle->SetPriority( SchedulerPriority::HIGHEST );
59 _pIdle->SetIdleHdl( LINK(
60 this, AsynchronLink, HandleCall_Idle) );
62 _pIdle->Start();
64 else
66 if( _pMutex ) _pMutex->acquire();
67 _nEventId = Application::PostUserEvent( LINK( this, AsynchronLink, HandleCall_PostUserEvent), 0 );
68 if( _pMutex ) _pMutex->release();
73 AsynchronLink::~AsynchronLink()
75 if( _nEventId )
77 Application::RemoveUserEvent( _nEventId );
79 delete _pIdle;
80 if( _pDeleted ) *_pDeleted = true;
81 delete _pMutex;
84 IMPL_LINK_NOARG_TYPED( AsynchronLink, HandleCall_Idle, Idle*, void )
86 if( _pMutex ) _pMutex->acquire();
87 _nEventId = 0;
88 if( _pMutex ) _pMutex->release();
89 Call_Impl( _pArg );
92 IMPL_LINK_NOARG( AsynchronLink, HandleCall_PostUserEvent )
94 HandleCall_Idle(nullptr);
95 return 0;
98 void AsynchronLink::ClearPendingCall()
100 if( _pMutex ) _pMutex->acquire();
101 if( _nEventId )
103 Application::RemoveUserEvent( _nEventId );
104 _nEventId = 0;
106 if( _pMutex ) _pMutex->release();
107 if( _pIdle ) _pIdle->Stop();
110 void AsynchronLink::Call_Impl( void* pArg )
112 _bInCall = true;
113 bool bDeleted = false;
114 _pDeleted = &bDeleted;
115 _aLink.Call( pArg );
116 if( !bDeleted )
118 _bInCall = false;
119 _pDeleted = 0;
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */