Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <vcl/svapp.hxx>
30 : :
31 : : #include <idlemgr.hxx>
32 : :
33 : : // =======================================================================
34 : :
35 : 89690 : struct ImplIdleData
36 : : {
37 : : Link maIdleHdl;
38 : : sal_uInt16 mnPriority;
39 : : sal_Bool mbTimeout;
40 : : };
41 : :
42 : : #define IMPL_IDLETIMEOUT 350
43 : :
44 : : // =======================================================================
45 : :
46 : 60 : ImplIdleMgr::ImplIdleMgr()
47 : : {
48 [ + - ][ + - ]: 60 : mpIdleList = new ImplIdleList();
49 : :
50 [ + - ]: 60 : maTimer.SetTimeout( IMPL_IDLETIMEOUT );
51 [ + - ]: 60 : maTimer.SetTimeoutHdl( LINK( this, ImplIdleMgr, TimeoutHdl ) );
52 : 60 : }
53 : :
54 : : // -----------------------------------------------------------------------
55 : :
56 : 60 : ImplIdleMgr::~ImplIdleMgr()
57 : : {
58 : : // Liste loeschen
59 [ + + ]: 716 : for ( size_t i = 0, n = mpIdleList->size(); i < n; ++i ) {
60 : 656 : delete (*mpIdleList)[ i ];
61 : : }
62 : 60 : mpIdleList->clear();
63 [ + - ]: 60 : delete mpIdleList;
64 : 60 : }
65 : :
66 : : // -----------------------------------------------------------------------
67 : :
68 : 89690 : sal_Bool ImplIdleMgr::InsertIdleHdl( const Link& rLink, sal_uInt16 nPriority )
69 : : {
70 : 89690 : size_t nPos = (size_t)-1;
71 : 89690 : size_t n = mpIdleList->size();
72 [ + + ]: 3268806 : for ( size_t i = 0; i < n; ++i ) {
73 : : // we need to check each element to verify that rLink isn't in the array
74 [ + - ][ - + ]: 3179116 : if ( (*mpIdleList)[ i ]->maIdleHdl == rLink ) {
75 : 0 : return sal_False;
76 : : }
77 [ + - ]: 3179116 : if ( nPriority <= (*mpIdleList)[ i ]->mnPriority ) {
78 : 3179116 : nPos = i;
79 : : }
80 : : }
81 : :
82 [ + - ][ + - ]: 89690 : ImplIdleData* pIdleData = new ImplIdleData;
83 : 89690 : pIdleData->maIdleHdl = rLink;
84 : 89690 : pIdleData->mnPriority = nPriority;
85 : 89690 : pIdleData->mbTimeout = sal_False;
86 : :
87 [ + + ]: 89690 : if ( nPos < mpIdleList->size() ) {
88 : 88950 : ImplIdleList::iterator it = mpIdleList->begin();
89 [ + - ]: 88950 : ::std::advance( it, nPos );
90 [ + - ]: 88950 : mpIdleList->insert( it, pIdleData );
91 : : } else {
92 [ + - ]: 740 : mpIdleList->push_back( pIdleData );
93 : : }
94 : :
95 : : // if Timer was not started already then start it now
96 [ + + ]: 89690 : if ( !maTimer.IsActive() )
97 [ + - ]: 740 : maTimer.Start();
98 : :
99 : 89690 : return sal_True;
100 : : }
101 : :
102 : : // -----------------------------------------------------------------------
103 : :
104 : 89034 : void ImplIdleMgr::RemoveIdleHdl( const Link& rLink )
105 : : {
106 [ + - ][ + - ]: 1131871 : for ( ImplIdleList::iterator it = mpIdleList->begin(); it != mpIdleList->end(); ++it ) {
107 [ + - ][ + + ]: 1131871 : if ( (*it)->maIdleHdl == rLink ) {
108 : 89034 : delete *it;
109 [ + - ]: 89034 : mpIdleList->erase( it );
110 : 89034 : break;
111 : : }
112 : : }
113 : :
114 : : // keine Handdler mehr da
115 [ + + ]: 89034 : if ( mpIdleList->empty() )
116 : 693 : maTimer.Stop();
117 : 89034 : }
118 : :
119 : : // -----------------------------------------------------------------------
120 : :
121 : 7254 : IMPL_LINK_NOARG(ImplIdleMgr, TimeoutHdl)
122 : : {
123 [ + + ]: 96288 : for ( size_t i = 0; i < mpIdleList->size(); ++i ) {
124 : 89034 : ImplIdleData* pIdleData = (*mpIdleList)[ i ];
125 [ + - ]: 89034 : if ( !pIdleData->mbTimeout ) {
126 : 89034 : pIdleData->mbTimeout = sal_True;
127 : 89034 : pIdleData->maIdleHdl.Call( GetpApp() );
128 : : // May have been removed in the handler
129 [ + + ]: 3260278 : for ( size_t j = 0; j < mpIdleList->size(); ++j ) {
130 [ - + ]: 3171244 : if ( (*mpIdleList)[ j ] == pIdleData ) {
131 : 0 : pIdleData->mbTimeout = sal_False;
132 : 0 : break;
133 : : }
134 : : }
135 : : }
136 : : }
137 : :
138 : 7254 : return 0;
139 : : }
140 : :
141 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|