1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: idlemgr.cxx,v $
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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
33 #include <tools/list.hxx>
34 #include <vcl/idlemgr.hxx>
35 #include <vcl/svapp.hxx>
37 // =======================================================================
46 DECLARE_LIST( ImplIdleList
, ImplIdleData
* )
48 #define IMPL_IDLETIMEOUT 350
50 // =======================================================================
52 ImplIdleMgr::ImplIdleMgr()
54 mpIdleList
= new ImplIdleList( 8, 8, 8 );
56 maTimer
.SetTimeout( IMPL_IDLETIMEOUT
);
57 maTimer
.SetTimeoutHdl( LINK( this, ImplIdleMgr
, TimeoutHdl
) );
60 // -----------------------------------------------------------------------
62 ImplIdleMgr::~ImplIdleMgr()
65 ImplIdleData
* pIdleData
= mpIdleList
->First();
69 pIdleData
= mpIdleList
->Next();
75 // -----------------------------------------------------------------------
77 BOOL
ImplIdleMgr::InsertIdleHdl( const Link
& rLink
, USHORT nPriority
)
79 ULONG nPos
= LIST_APPEND
;
80 ImplIdleData
* pIdleData
= mpIdleList
->First();
83 // Wenn Link schon existiert, dann gebe FALSE zurueck
84 if ( pIdleData
->maIdleHdl
== rLink
)
87 // Nach Prioritaet sortieren
88 if ( nPriority
<= pIdleData
->mnPriority
)
89 nPos
= mpIdleList
->GetCurPos();
91 // Schleife nicht beenden, da noch
92 // geprueft werden muss, ob sich der Link
93 // schon in der Liste befindet
95 pIdleData
= mpIdleList
->Next();
98 pIdleData
= new ImplIdleData
;
99 pIdleData
->maIdleHdl
= rLink
;
100 pIdleData
->mnPriority
= nPriority
;
101 pIdleData
->mbTimeout
= FALSE
;
102 mpIdleList
->Insert( pIdleData
, nPos
);
104 // Wenn Timer noch nicht gestartet ist, dann starten
105 if ( !maTimer
.IsActive() )
111 // -----------------------------------------------------------------------
113 void ImplIdleMgr::RemoveIdleHdl( const Link
& rLink
)
115 ImplIdleData
* pIdleData
= mpIdleList
->First();
118 if ( pIdleData
->maIdleHdl
== rLink
)
120 mpIdleList
->Remove();
125 pIdleData
= mpIdleList
->Next();
128 // keine Handdler mehr da
129 if ( !mpIdleList
->Count() )
133 // -----------------------------------------------------------------------
135 IMPL_LINK( ImplIdleMgr
, TimeoutHdl
, Timer
*, EMPTYARG
)
137 ImplIdleData
* pIdleData
= mpIdleList
->First();
140 if ( !pIdleData
->mbTimeout
)
142 pIdleData
->mbTimeout
= TRUE
;
143 pIdleData
->maIdleHdl
.Call( GetpApp() );
144 // Kann im Handler entfernt worden sein
145 if ( mpIdleList
->GetPos( pIdleData
) != LIST_ENTRY_NOTFOUND
)
146 pIdleData
->mbTimeout
= FALSE
;
149 pIdleData
= mpIdleList
->Next();