1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include <vcl/svapp.hxx>
22 #include <idlemgr.hxx>
27 sal_uInt16 mnPriority
;
31 #define IMPL_IDLETIMEOUT 350
33 ImplIdleMgr::ImplIdleMgr():
34 mbInDestruction(false)
36 mpIdleList
= new ImplIdleList();
38 maTimer
.SetTimeout( IMPL_IDLETIMEOUT
);
39 maTimer
.SetTimeoutHdl( LINK( this, ImplIdleMgr
, TimeoutHdl
) );
42 ImplIdleMgr::~ImplIdleMgr()
44 mbInDestruction
= true;
46 for ( size_t i
= 0, n
= mpIdleList
->size(); i
< n
; ++i
) {
47 ImplIdleData
* pIdleData
= (*mpIdleList
)[ i
];
48 pIdleData
->maIdleHdl
.Call( GetpApp() );
55 bool ImplIdleMgr::InsertIdleHdl( const Link
<>& rLink
, sal_uInt16 nPriority
)
57 size_t nPos
= (size_t)-1;
58 size_t n
= mpIdleList
->size();
59 for ( size_t i
= 0; i
< n
; ++i
) {
60 // we need to check each element to verify that rLink isn't in the array
61 if ( (*mpIdleList
)[ i
]->maIdleHdl
== rLink
) {
64 if ( nPriority
<= (*mpIdleList
)[ i
]->mnPriority
) {
69 ImplIdleData
* pIdleData
= new ImplIdleData
;
70 pIdleData
->maIdleHdl
= rLink
;
71 pIdleData
->mnPriority
= nPriority
;
72 pIdleData
->mbTimeout
= false;
74 if ( nPos
< mpIdleList
->size() ) {
75 ImplIdleList::iterator it
= mpIdleList
->begin();
76 ::std::advance( it
, nPos
);
77 mpIdleList
->insert( it
, pIdleData
);
79 mpIdleList
->push_back( pIdleData
);
82 // if Timer was not started already then start it now
83 if ( !maTimer
.IsActive() )
89 void ImplIdleMgr::RemoveIdleHdl( const Link
<>& rLink
)
94 for ( ImplIdleList::iterator it
= mpIdleList
->begin(); it
!= mpIdleList
->end(); ++it
) {
95 if ( (*it
)->maIdleHdl
== rLink
) {
97 mpIdleList
->erase( it
);
102 // there are no more handlers...
103 if ( mpIdleList
->empty() )
107 IMPL_LINK_NOARG_TYPED(ImplIdleMgr
, TimeoutHdl
, Timer
*, void)
109 for ( size_t i
= 0; i
< mpIdleList
->size(); ++i
) {
110 ImplIdleData
* pIdleData
= (*mpIdleList
)[ i
];
111 if ( !pIdleData
->mbTimeout
) {
112 pIdleData
->mbTimeout
= true;
113 pIdleData
->maIdleHdl
.Call( GetpApp() );
114 // May have been removed in the handler
115 for ( size_t j
= 0; j
< mpIdleList
->size(); ++j
) {
116 if ( (*mpIdleList
)[ j
] == pIdleData
) {
117 pIdleData
->mbTimeout
= false;
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */