Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / dtrans / source / win32 / clipb / MtaOleClipb.hxx
blobbf71ac26e8f843d718ccd11a267bf816c8dd9846
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 #ifndef INCLUDED_DTRANS_SOURCE_WIN32_CLIPB_MTAOLECLIPB_HXX
21 #define INCLUDED_DTRANS_SOURCE_WIN32_CLIPB_MTAOLECLIPB_HXX
23 #include <sal/types.h>
24 #include <osl/mutex.hxx>
26 #include <objidl.h>
28 // the Mta-Ole clipboard class is for internal use only!
29 // only one instance of this class should be created, the
30 // user has to ensure this!
31 // the class is not thread-safe because it will be used
32 // only from within the clipboard service and the methods
33 // of the clipboard service are already synchronized
35 class CMtaOleClipboard
37 public:
38 typedef void ( WINAPI *LPFNC_CLIPVIEWER_CALLBACK_t )( void );
40 public:
41 CMtaOleClipboard( );
42 ~CMtaOleClipboard( );
44 // clipboard functions
45 HRESULT setClipboard( IDataObject* pIDataObject );
46 HRESULT getClipboard( IDataObject** ppIDataObject );
47 HRESULT flushClipboard( );
49 // register/unregister a clipboard viewer; there can only
50 // be one at a time; parameter NULL means unregister
51 // a clipboard viewer
52 // returns true on success else false; use GetLastError( ) in
53 // false case
54 bool registerClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback );
56 private:
57 unsigned int run( );
59 // create a hidden window which serves as a request target; so we
60 // guarantee synchronization
61 void createMtaOleReqWnd( );
63 // message support
64 bool postMessage( UINT msg, WPARAM wParam = 0, LPARAM lParam = 0 );
65 LRESULT sendMessage( UINT msg, WPARAM wParam = 0, LPARAM lParam = 0 );
67 // message handler functions; remember these functions are called
68 // from a different thread context!
70 static HRESULT onSetClipboard( IDataObject* pIDataObject );
71 static HRESULT onGetClipboard( LPSTREAM* ppStream );
72 static HRESULT onFlushClipboard( );
73 bool onRegisterClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback );
75 // win32 clipboard listener support
76 LRESULT onClipboardUpdate();
78 static LRESULT CALLBACK mtaOleReqWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
79 static unsigned int WINAPI oleThreadProc( LPVOID pParam );
81 static unsigned int WINAPI clipboardChangedNotifierThreadProc( LPVOID pParam );
83 bool WaitForThreadReady( ) const;
85 private:
86 HANDLE m_hOleThread;
87 unsigned m_uOleThreadId;
88 HANDLE m_hEvtThrdReady;
89 HWND m_hwndMtaOleReqWnd;
90 HANDLE m_hEvtWndDisposed;
91 ATOM m_MtaOleReqWndClassAtom;
92 LPFNC_CLIPVIEWER_CALLBACK_t m_pfncClipViewerCallback;
93 bool m_bInRegisterClipViewer;
95 bool m_bRunClipboardNotifierThread;
96 HANDLE m_hClipboardChangedNotifierThread;
97 HANDLE m_hClipboardChangedNotifierEvents[2];
98 HANDLE& m_hClipboardChangedEvent;
99 HANDLE& m_hTerminateClipboardChangedNotifierEvent;
100 osl::Mutex m_ClipboardChangedEventCountMutex;
101 sal_Int32 m_ClipboardChangedEventCount;
103 osl::Mutex m_pfncClipViewerCallbackMutex;
105 static CMtaOleClipboard* s_theMtaOleClipboardInst;
107 // not allowed
108 private:
109 CMtaOleClipboard( const CMtaOleClipboard& );
110 CMtaOleClipboard& operator=( const CMtaOleClipboard& );
112 friend LRESULT CALLBACK mtaOleReqWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
115 #endif
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */