xref: /aoo42x/main/vcl/source/app/idlemgr.cxx (revision 9f62ea84)
1*9f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9f62ea84SAndrew Rist  * distributed with this work for additional information
6*9f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
9*9f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9f62ea84SAndrew Rist  *
11*9f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9f62ea84SAndrew Rist  *
13*9f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9f62ea84SAndrew Rist  * software distributed under the License is distributed on an
15*9f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9f62ea84SAndrew Rist  * specific language governing permissions and limitations
18*9f62ea84SAndrew Rist  * under the License.
19*9f62ea84SAndrew Rist  *
20*9f62ea84SAndrew Rist  *************************************************************/
21*9f62ea84SAndrew Rist 
22*9f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <tools/list.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <vcl/svapp.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <idlemgr.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir // =======================================================================
34cdf0e10cSrcweir 
35cdf0e10cSrcweir struct ImplIdleData
36cdf0e10cSrcweir {
37cdf0e10cSrcweir     Link        maIdleHdl;
38cdf0e10cSrcweir     sal_uInt16      mnPriority;
39cdf0e10cSrcweir     sal_Bool        mbTimeout;
40cdf0e10cSrcweir };
41cdf0e10cSrcweir 
DECLARE_LIST(ImplIdleList,ImplIdleData *)42cdf0e10cSrcweir DECLARE_LIST( ImplIdleList, ImplIdleData* )
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #define IMPL_IDLETIMEOUT         350
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // =======================================================================
47cdf0e10cSrcweir 
48cdf0e10cSrcweir ImplIdleMgr::ImplIdleMgr()
49cdf0e10cSrcweir {
50cdf0e10cSrcweir     mpIdleList  = new ImplIdleList( 8, 8, 8 );
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     maTimer.SetTimeout( IMPL_IDLETIMEOUT );
53cdf0e10cSrcweir     maTimer.SetTimeoutHdl( LINK( this, ImplIdleMgr, TimeoutHdl ) );
54cdf0e10cSrcweir }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir // -----------------------------------------------------------------------
57cdf0e10cSrcweir 
~ImplIdleMgr()58cdf0e10cSrcweir ImplIdleMgr::~ImplIdleMgr()
59cdf0e10cSrcweir {
60cdf0e10cSrcweir     // Liste loeschen
61cdf0e10cSrcweir     ImplIdleData* pIdleData = mpIdleList->First();
62cdf0e10cSrcweir     while ( pIdleData )
63cdf0e10cSrcweir     {
64cdf0e10cSrcweir         delete pIdleData;
65cdf0e10cSrcweir         pIdleData = mpIdleList->Next();
66cdf0e10cSrcweir     }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     delete mpIdleList;
69cdf0e10cSrcweir }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir // -----------------------------------------------------------------------
72cdf0e10cSrcweir 
InsertIdleHdl(const Link & rLink,sal_uInt16 nPriority)73cdf0e10cSrcweir sal_Bool ImplIdleMgr::InsertIdleHdl( const Link& rLink, sal_uInt16 nPriority )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     sal_uLong           nPos = LIST_APPEND;
76cdf0e10cSrcweir     ImplIdleData*   pIdleData = mpIdleList->First();
77cdf0e10cSrcweir     while ( pIdleData )
78cdf0e10cSrcweir     {
79cdf0e10cSrcweir         // Wenn Link schon existiert, dann gebe sal_False zurueck
80cdf0e10cSrcweir         if ( pIdleData->maIdleHdl == rLink )
81cdf0e10cSrcweir             return sal_False;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         // Nach Prioritaet sortieren
84cdf0e10cSrcweir         if ( nPriority <= pIdleData->mnPriority )
85cdf0e10cSrcweir             nPos = mpIdleList->GetCurPos();
86cdf0e10cSrcweir 
87cdf0e10cSrcweir         // Schleife nicht beenden, da noch
88cdf0e10cSrcweir         // geprueft werden muss, ob sich der Link
89cdf0e10cSrcweir         // schon in der Liste befindet
90cdf0e10cSrcweir 
91cdf0e10cSrcweir         pIdleData = mpIdleList->Next();
92cdf0e10cSrcweir     }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     pIdleData               = new ImplIdleData;
95cdf0e10cSrcweir     pIdleData->maIdleHdl    = rLink;
96cdf0e10cSrcweir     pIdleData->mnPriority   = nPriority;
97cdf0e10cSrcweir     pIdleData->mbTimeout    = sal_False;
98cdf0e10cSrcweir     mpIdleList->Insert( pIdleData, nPos );
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     // Wenn Timer noch nicht gestartet ist, dann starten
101cdf0e10cSrcweir     if ( !maTimer.IsActive() )
102cdf0e10cSrcweir         maTimer.Start();
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     return sal_True;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir // -----------------------------------------------------------------------
108cdf0e10cSrcweir 
RemoveIdleHdl(const Link & rLink)109cdf0e10cSrcweir void ImplIdleMgr::RemoveIdleHdl( const Link& rLink )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     ImplIdleData* pIdleData = mpIdleList->First();
112cdf0e10cSrcweir     while ( pIdleData )
113cdf0e10cSrcweir     {
114cdf0e10cSrcweir         if ( pIdleData->maIdleHdl == rLink )
115cdf0e10cSrcweir         {
116cdf0e10cSrcweir             mpIdleList->Remove();
117cdf0e10cSrcweir             delete pIdleData;
118cdf0e10cSrcweir             break;
119cdf0e10cSrcweir         }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         pIdleData = mpIdleList->Next();
122cdf0e10cSrcweir     }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     // keine Handdler mehr da
125cdf0e10cSrcweir     if ( !mpIdleList->Count() )
126cdf0e10cSrcweir         maTimer.Stop();
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir // -----------------------------------------------------------------------
130cdf0e10cSrcweir 
IMPL_LINK(ImplIdleMgr,TimeoutHdl,Timer *,EMPTYARG)131cdf0e10cSrcweir IMPL_LINK( ImplIdleMgr, TimeoutHdl, Timer*, EMPTYARG )
132cdf0e10cSrcweir {
133cdf0e10cSrcweir     ImplIdleData* pIdleData = mpIdleList->First();
134cdf0e10cSrcweir     while ( pIdleData )
135cdf0e10cSrcweir     {
136cdf0e10cSrcweir         if ( !pIdleData->mbTimeout )
137cdf0e10cSrcweir         {
138cdf0e10cSrcweir             pIdleData->mbTimeout = sal_True;
139cdf0e10cSrcweir             pIdleData->maIdleHdl.Call( GetpApp() );
140cdf0e10cSrcweir             // Kann im Handler entfernt worden sein
141cdf0e10cSrcweir             if ( mpIdleList->GetPos( pIdleData ) != LIST_ENTRY_NOTFOUND )
142cdf0e10cSrcweir                 pIdleData->mbTimeout = sal_False;
143cdf0e10cSrcweir         }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         pIdleData = mpIdleList->Next();
146cdf0e10cSrcweir     }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     return 0;
149cdf0e10cSrcweir }
150