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 <salframe.hxx>
21 #include <generic/gendisp.hxx>
22 #include <generic/geninst.h>
25 SalGenericDisplay::SalGenericDisplay()
28 m_aEventGuard
= osl_createMutex();
31 SalGenericDisplay::~SalGenericDisplay()
34 osl_destroyMutex( m_aEventGuard
);
38 void SalGenericDisplay::registerFrame( SalFrame
* pFrame
)
40 m_aFrames
.push_front( pFrame
);
43 void SalGenericDisplay::deregisterFrame( SalFrame
* pFrame
)
45 if( osl_acquireMutex( m_aEventGuard
) )
47 std::list
< SalUserEvent
>::iterator it
= m_aUserEvents
.begin();
48 while ( it
!= m_aUserEvents
.end() )
50 if( it
->m_pFrame
== pFrame
)
51 it
= m_aUserEvents
.erase( it
);
55 osl_releaseMutex( m_aEventGuard
);
58 OSL_FAIL( "SalGenericDisplay::deregisterFrame !acquireMutex\n" );
60 m_aFrames
.remove( pFrame
);
63 void SalGenericDisplay::emitDisplayChanged()
65 if( !m_aFrames
.empty() )
66 m_aFrames
.front()->CallCallback( SALEVENT_DISPLAYCHANGED
, 0 );
69 bool SalGenericDisplay::DispatchInternalEvent()
72 SalFrame
* pFrame
= NULL
;
73 sal_uInt16 nEvent
= 0;
75 if( osl_acquireMutex( m_aEventGuard
) )
77 if( m_aUserEvents
.begin() != m_aUserEvents
.end() )
79 pFrame
= m_aUserEvents
.front().m_pFrame
;
80 pData
= m_aUserEvents
.front().m_pData
;
81 nEvent
= m_aUserEvents
.front().m_nEvent
;
83 m_aUserEvents
.pop_front();
85 osl_releaseMutex( m_aEventGuard
);
88 OSL_FAIL( "SalGenericDisplay::Yield !acquireMutex\n" );
91 pFrame
->CallCallback( nEvent
, pData
);
93 return pFrame
!= NULL
;
96 void SalGenericDisplay::SendInternalEvent( SalFrame
* pFrame
, void* pData
, sal_uInt16 nEvent
)
98 if( osl_acquireMutex( m_aEventGuard
) )
100 m_aUserEvents
.push_back( SalUserEvent( pFrame
, pData
, nEvent
) );
102 PostUserEvent(); // wakeup the concrete mainloop
104 osl_releaseMutex( m_aEventGuard
);
107 OSL_FAIL( "SalGenericDisplay::SendInternalEvent !acquireMutex\n" );
110 void SalGenericDisplay::CancelInternalEvent( SalFrame
* pFrame
, void* pData
, sal_uInt16 nEvent
)
112 if( osl_acquireMutex( m_aEventGuard
) )
114 if( ! m_aUserEvents
.empty() )
116 std::list
< SalUserEvent
>::iterator it
, next
;
117 next
= m_aUserEvents
.begin();
121 if( it
->m_pFrame
== pFrame
&&
122 it
->m_pData
== pData
&&
123 it
->m_nEvent
== nEvent
)
125 m_aUserEvents
.erase( it
);
127 } while( next
!= m_aUserEvents
.end() );
130 osl_releaseMutex( m_aEventGuard
);
133 OSL_FAIL( "SalGenericDisplay::CancelInternalEvent !acquireMutex\n" );
136 bool SalGenericDisplay::HasUserEvents() const
139 if( osl_acquireMutex( m_aEventGuard
) )
141 if( m_aUserEvents
.begin() != m_aUserEvents
.end() )
143 osl_releaseMutex( m_aEventGuard
);
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */