Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / vcl / generic / app / gendisp.cxx
blobf6d1e2e8c75985dafa7911cabb9a0ccb7250def9
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 using ::rtl::OUString;
26 SalGenericDisplay::SalGenericDisplay()
28 m_pCapture = NULL;
29 m_aEventGuard = osl_createMutex();
32 SalGenericDisplay::~SalGenericDisplay()
34 if (m_aEventGuard)
35 osl_destroyMutex( m_aEventGuard );
36 m_aEventGuard = NULL;
39 void SalGenericDisplay::registerFrame( SalFrame* pFrame )
41 m_aFrames.push_front( pFrame );
44 void SalGenericDisplay::deregisterFrame( SalFrame* pFrame )
46 if( osl_acquireMutex( m_aEventGuard ) )
48 std::list< SalUserEvent >::iterator it = m_aUserEvents.begin();
49 while ( it != m_aUserEvents.end() )
51 if( it->m_pFrame == pFrame )
52 it = m_aUserEvents.erase( it );
53 else
54 ++it;
56 osl_releaseMutex( m_aEventGuard );
58 else
59 OSL_FAIL( "SalGenericDisplay::deregisterFrame !acquireMutex\n" );
61 m_aFrames.remove( pFrame );
64 void SalGenericDisplay::emitDisplayChanged()
66 if( !m_aFrames.empty() )
67 m_aFrames.front()->CallCallback( SALEVENT_DISPLAYCHANGED, 0 );
70 bool SalGenericDisplay::DispatchInternalEvent()
72 void* pData = NULL;
73 SalFrame* pFrame = NULL;
74 sal_uInt16 nEvent = 0;
76 if( osl_acquireMutex( m_aEventGuard ) )
78 if( m_aUserEvents.begin() != m_aUserEvents.end() )
80 pFrame = m_aUserEvents.front().m_pFrame;
81 pData = m_aUserEvents.front().m_pData;
82 nEvent = m_aUserEvents.front().m_nEvent;
84 m_aUserEvents.pop_front();
86 osl_releaseMutex( m_aEventGuard );
88 else
89 OSL_FAIL( "SalGenericDisplay::Yield !acquireMutex\n" );
91 if( pFrame )
92 pFrame->CallCallback( nEvent, pData );
94 return pFrame != NULL;
97 void SalGenericDisplay::SendInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent )
99 if( osl_acquireMutex( m_aEventGuard ) )
101 m_aUserEvents.push_back( SalUserEvent( pFrame, pData, nEvent ) );
103 PostUserEvent(); // wakeup the concrete mainloop
105 osl_releaseMutex( m_aEventGuard );
107 else
108 OSL_FAIL( "SalGenericDisplay::SendInternalEvent !acquireMutex\n" );
111 void SalGenericDisplay::CancelInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent )
113 if( osl_acquireMutex( m_aEventGuard ) )
115 if( ! m_aUserEvents.empty() )
117 std::list< SalUserEvent >::iterator it, next;
118 next = m_aUserEvents.begin();
121 it = next++;
122 if( it->m_pFrame == pFrame &&
123 it->m_pData == pData &&
124 it->m_nEvent == nEvent )
126 m_aUserEvents.erase( it );
128 } while( next != m_aUserEvents.end() );
131 osl_releaseMutex( m_aEventGuard );
133 else
134 OSL_FAIL( "SalGenericDisplay::CancelInternalEvent !acquireMutex\n" );
137 bool SalGenericDisplay::HasUserEvents() const
139 bool bRet = false;
140 if( osl_acquireMutex( m_aEventGuard ) )
142 if( m_aUserEvents.begin() != m_aUserEvents.end() )
143 bRet = true;
144 osl_releaseMutex( m_aEventGuard );
146 return bRet;
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */