Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / generic / app / gendisp.cxx
blob1275465c4fb197166f024c4dbbcbf1ec7a607fd9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
24 SalGenericDisplay::SalGenericDisplay()
26 m_pCapture = NULL;
27 m_aEventGuard = osl_createMutex();
30 SalGenericDisplay::~SalGenericDisplay()
32 if (m_aEventGuard)
33 osl_destroyMutex( m_aEventGuard );
34 m_aEventGuard = NULL;
37 void SalGenericDisplay::registerFrame( SalFrame* pFrame )
39 m_aFrames.push_front( pFrame );
42 void SalGenericDisplay::deregisterFrame( SalFrame* pFrame )
44 if( osl_acquireMutex( m_aEventGuard ) )
46 std::list< SalUserEvent >::iterator it = m_aUserEvents.begin();
47 while ( it != m_aUserEvents.end() )
49 if( it->m_pFrame == pFrame )
50 it = m_aUserEvents.erase( it );
51 else
52 ++it;
54 osl_releaseMutex( m_aEventGuard );
56 else
57 OSL_FAIL( "SalGenericDisplay::deregisterFrame !acquireMutex\n" );
59 m_aFrames.remove( pFrame );
62 void SalGenericDisplay::emitDisplayChanged()
64 if( !m_aFrames.empty() )
65 m_aFrames.front()->CallCallback( SALEVENT_DISPLAYCHANGED, 0 );
68 bool SalGenericDisplay::DispatchInternalEvent()
70 void* pData = NULL;
71 SalFrame* pFrame = NULL;
72 sal_uInt16 nEvent = 0;
74 if( osl_acquireMutex( m_aEventGuard ) )
76 if( m_aUserEvents.begin() != m_aUserEvents.end() )
78 pFrame = m_aUserEvents.front().m_pFrame;
79 pData = m_aUserEvents.front().m_pData;
80 nEvent = m_aUserEvents.front().m_nEvent;
82 m_aUserEvents.pop_front();
84 osl_releaseMutex( m_aEventGuard );
86 else
87 OSL_FAIL( "SalGenericDisplay::Yield !acquireMutex\n" );
89 if( pFrame )
90 pFrame->CallCallback( nEvent, pData );
92 return pFrame != NULL;
95 void SalGenericDisplay::SendInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent )
97 if( osl_acquireMutex( m_aEventGuard ) )
99 m_aUserEvents.push_back( SalUserEvent( pFrame, pData, nEvent ) );
101 PostUserEvent(); // wakeup the concrete mainloop
103 osl_releaseMutex( m_aEventGuard );
105 else
106 OSL_FAIL( "SalGenericDisplay::SendInternalEvent !acquireMutex\n" );
109 void SalGenericDisplay::CancelInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent )
111 if( osl_acquireMutex( m_aEventGuard ) )
113 if( ! m_aUserEvents.empty() )
115 std::list< SalUserEvent >::iterator it = m_aUserEvents.begin();
116 while (it != m_aUserEvents.end())
118 if( it->m_pFrame == pFrame &&
119 it->m_pData == pData &&
120 it->m_nEvent == nEvent )
122 it = m_aUserEvents.erase( it );
124 else
125 ++it;
129 osl_releaseMutex( m_aEventGuard );
131 else
132 OSL_FAIL( "SalGenericDisplay::CancelInternalEvent !acquireMutex\n" );
135 bool SalGenericDisplay::HasUserEvents() const
137 bool bRet = false;
138 if( osl_acquireMutex( m_aEventGuard ) )
140 if( m_aUserEvents.begin() != m_aUserEvents.end() )
141 bRet = true;
142 osl_releaseMutex( m_aEventGuard );
144 return bRet;
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */