Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "vcl/svapp.hxx"
21 :
22 : #include "xconnection.hxx"
23 : #include "svdata.hxx"
24 : #include "salinst.hxx"
25 :
26 : using namespace osl;
27 : using namespace vcl;
28 : using namespace com::sun::star::uno;
29 : using namespace com::sun::star::awt;
30 :
31 164 : DisplayConnection::DisplayConnection()
32 : {
33 : SalInstance::ConnectionIdentifierType eType;
34 : int nBytes;
35 164 : void* pBytes = ImplGetSVData()->mpDefInst->GetConnectionIdentifier( eType, nBytes );
36 164 : switch( eType )
37 : {
38 : case SalInstance::AsciiCString:
39 164 : m_aAny <<= OUString::createFromAscii( (sal_Char*)pBytes );
40 164 : break;
41 : case SalInstance::Blob:
42 0 : m_aAny <<= Sequence< sal_Int8 >( (sal_Int8*)pBytes, nBytes );
43 0 : break;
44 : }
45 164 : }
46 :
47 320 : DisplayConnection::~DisplayConnection()
48 320 : {}
49 :
50 164 : void DisplayConnection::start()
51 : {
52 : DBG_TESTSOLARMUTEX();
53 164 : ImplSVData* pSVData = ImplGetSVData();
54 164 : pSVData->mpDefInst->SetEventCallback( this );
55 164 : }
56 :
57 58 : void DisplayConnection::terminate()
58 : {
59 : DBG_TESTSOLARMUTEX();
60 58 : ImplSVData* pSVData = ImplGetSVData();
61 :
62 58 : if( pSVData )
63 : {
64 58 : pSVData->mpDefInst->SetEventCallback( NULL );
65 : }
66 :
67 58 : SolarMutexReleaser aRel;
68 :
69 116 : MutexGuard aGuard( m_aMutex );
70 116 : Any aEvent;
71 116 : std::list< css::uno::Reference< XEventHandler > > aLocalList( m_aHandlers );
72 58 : for( ::std::list< css::uno::Reference< XEventHandler > >::const_iterator it = aLocalList.begin(); it != aLocalList.end(); ++it )
73 58 : (*it)->handleEvent( aEvent );
74 58 : }
75 :
76 0 : void SAL_CALL DisplayConnection::addEventHandler( const Any& /*window*/, const css::uno::Reference< XEventHandler >& handler, sal_Int32 /*eventMask*/ ) throw(std::exception)
77 : {
78 0 : MutexGuard aGuard( m_aMutex );
79 :
80 0 : m_aHandlers.push_back( handler );
81 0 : }
82 :
83 0 : void SAL_CALL DisplayConnection::removeEventHandler( const Any& /*window*/, const css::uno::Reference< XEventHandler >& handler ) throw(std::exception)
84 : {
85 0 : MutexGuard aGuard( m_aMutex );
86 :
87 0 : m_aHandlers.remove( handler );
88 0 : }
89 :
90 0 : void SAL_CALL DisplayConnection::addErrorHandler( const css::uno::Reference< XEventHandler >& handler ) throw(std::exception)
91 : {
92 0 : MutexGuard aGuard( m_aMutex );
93 :
94 0 : m_aErrorHandlers.push_back( handler );
95 0 : }
96 :
97 0 : void SAL_CALL DisplayConnection::removeErrorHandler( const css::uno::Reference< XEventHandler >& handler ) throw(std::exception)
98 : {
99 0 : MutexGuard aGuard( m_aMutex );
100 :
101 0 : m_aErrorHandlers.remove( handler );
102 0 : }
103 :
104 0 : Any SAL_CALL DisplayConnection::getIdentifier() throw(std::exception)
105 : {
106 0 : return m_aAny;
107 : }
108 :
109 0 : bool DisplayConnection::dispatchEvent( void* pData, int nBytes )
110 : {
111 0 : SolarMutexReleaser aRel;
112 :
113 0 : Sequence< sal_Int8 > aSeq( (sal_Int8*)pData, nBytes );
114 0 : Any aEvent;
115 0 : aEvent <<= aSeq;
116 0 : ::std::list< css::uno::Reference< XEventHandler > > handlers;
117 : {
118 0 : MutexGuard aGuard( m_aMutex );
119 0 : handlers = m_aHandlers;
120 : }
121 0 : for( ::std::list< css::uno::Reference< XEventHandler > >::const_iterator it = handlers.begin(); it != handlers.end(); ++it )
122 0 : if( (*it)->handleEvent( aEvent ) )
123 0 : return true;
124 0 : return false;
125 : }
126 :
127 0 : bool DisplayConnection::dispatchErrorEvent( void* pData, int nBytes )
128 : {
129 0 : SolarMutexReleaser aRel;
130 :
131 0 : Sequence< sal_Int8 > aSeq( (sal_Int8*)pData, nBytes );
132 0 : Any aEvent;
133 0 : aEvent <<= aSeq;
134 0 : ::std::list< css::uno::Reference< XEventHandler > > handlers;
135 : {
136 0 : MutexGuard aGuard( m_aMutex );
137 0 : handlers = m_aErrorHandlers;
138 : }
139 0 : for( ::std::list< css::uno::Reference< XEventHandler > >::const_iterator it = handlers.begin(); it != handlers.end(); ++it )
140 0 : if( (*it)->handleEvent( aEvent ) )
141 0 : return true;
142 :
143 0 : return false;
144 1233 : }
145 :
146 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|