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 .
22 #include <sal/types.h>
23 #include <osl/mutex.hxx>
27 // the Mta-Ole clipboard class is for internal use only!
28 // only one instance of this class should be created, the
29 // user has to ensure this!
30 // the class is not thread-safe because it will be used
31 // only from within the clipboard service and the methods
32 // of the clipboard service are already synchronized
34 class CMtaOleClipboard
37 typedef void ( WINAPI
*LPFNC_CLIPVIEWER_CALLBACK_t
)( void );
43 // clipboard functions
44 HRESULT
setClipboard( IDataObject
* pIDataObject
);
45 HRESULT
getClipboard( IDataObject
** ppIDataObject
);
46 HRESULT
flushClipboard( );
48 // register/unregister a clipboard viewer; there can only
49 // be one at a time; parameter NULL means unregister
51 // returns true on success else false; use GetLastError( ) in
53 bool registerClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback
);
58 // create a hidden window which serves as a request target; so we
59 // guarantee synchronization
60 void createMtaOleReqWnd( );
63 bool postMessage( UINT msg
, WPARAM wParam
= 0, LPARAM lParam
= 0 );
64 LRESULT
sendMessage( UINT msg
, WPARAM wParam
= 0, LPARAM lParam
= 0 );
66 // message handler functions; remember these functions are called
67 // from a different thread context!
69 static HRESULT
onSetClipboard( IDataObject
* pIDataObject
);
70 static HRESULT
onGetClipboard( LPSTREAM
* ppStream
);
71 static HRESULT
onFlushClipboard( );
72 bool onRegisterClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback
);
74 // win32 clipboard listener support
75 LRESULT
onClipboardUpdate();
77 static LRESULT CALLBACK
mtaOleReqWndProc( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
78 static unsigned int WINAPI
oleThreadProc( LPVOID pParam
);
80 static unsigned int WINAPI
clipboardChangedNotifierThreadProc( LPVOID pParam
);
82 bool WaitForThreadReady( ) const;
86 unsigned m_uOleThreadId
;
87 HANDLE m_hEvtThrdReady
;
88 HWND m_hwndMtaOleReqWnd
;
89 HANDLE m_hEvtWndDisposed
;
90 ATOM m_MtaOleReqWndClassAtom
;
91 LPFNC_CLIPVIEWER_CALLBACK_t m_pfncClipViewerCallback
;
92 bool m_bInRegisterClipViewer
;
94 bool m_bRunClipboardNotifierThread
;
95 HANDLE m_hClipboardChangedNotifierThread
;
96 HANDLE m_hClipboardChangedNotifierEvents
[2];
97 HANDLE
& m_hClipboardChangedEvent
;
98 HANDLE
& m_hTerminateClipboardChangedNotifierEvent
;
99 osl::Mutex m_ClipboardChangedEventCountMutex
;
100 sal_Int32 m_ClipboardChangedEventCount
;
102 osl::Mutex m_pfncClipViewerCallbackMutex
;
104 static CMtaOleClipboard
* s_theMtaOleClipboardInst
;
108 CMtaOleClipboard( const CMtaOleClipboard
& );
109 CMtaOleClipboard
& operator=( const CMtaOleClipboard
& );
111 friend LRESULT CALLBACK
mtaOleReqWndProc( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */