xref: /aoo42x/main/dtrans/source/inc/MtaOleClipb.hxx (revision 07a3d7f1)
1fbcf0fe9SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3fbcf0fe9SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4fbcf0fe9SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5fbcf0fe9SAndrew Rist  * distributed with this work for additional information
6fbcf0fe9SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7fbcf0fe9SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8fbcf0fe9SAndrew Rist  * "License"); you may not use this file except in compliance
9fbcf0fe9SAndrew Rist  * with the License.  You may obtain a copy of the License at
10fbcf0fe9SAndrew Rist  *
11fbcf0fe9SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12fbcf0fe9SAndrew Rist  *
13fbcf0fe9SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14fbcf0fe9SAndrew Rist  * software distributed under the License is distributed on an
15fbcf0fe9SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16fbcf0fe9SAndrew Rist  * KIND, either express or implied.  See the License for the
17fbcf0fe9SAndrew Rist  * specific language governing permissions and limitations
18fbcf0fe9SAndrew Rist  * under the License.
19fbcf0fe9SAndrew Rist  *
20fbcf0fe9SAndrew Rist  *************************************************************/
21fbcf0fe9SAndrew Rist 
22fbcf0fe9SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _MTAOLECLIPB_HXX_
25cdf0e10cSrcweir #define _MTAOLECLIPB_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <sal/types.h>
28cdf0e10cSrcweir #include <osl/mutex.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #if defined _MSC_VER
31cdf0e10cSrcweir #pragma warning(push,1)
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #include <objidl.h>
34cdf0e10cSrcweir #if defined _MSC_VER
35cdf0e10cSrcweir #pragma warning(pop)
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //--------------------------------------------------------
39cdf0e10cSrcweir // the Mta-Ole clipboard class is for internal use only!
40cdf0e10cSrcweir // only one instance of this class should be created, the
41cdf0e10cSrcweir // user has to ensure this!
42cdf0e10cSrcweir // the class is not thread-safe because it will be used
43cdf0e10cSrcweir // only from within the clipboard service and the methods
44cdf0e10cSrcweir // of the clipboard service are already synchronized
45cdf0e10cSrcweir //--------------------------------------------------------
46cdf0e10cSrcweir 
47cdf0e10cSrcweir class CMtaOleClipboard
48cdf0e10cSrcweir {
49cdf0e10cSrcweir public:
50cdf0e10cSrcweir 	typedef void ( WINAPI *LPFNC_CLIPVIEWER_CALLBACK_t )( void );
51cdf0e10cSrcweir 
52cdf0e10cSrcweir public:
53cdf0e10cSrcweir 	CMtaOleClipboard( );
54cdf0e10cSrcweir 	~CMtaOleClipboard( );
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 	// clipboard functions
57cdf0e10cSrcweir 	HRESULT setClipboard( IDataObject* pIDataObject );
58cdf0e10cSrcweir 	HRESULT getClipboard( IDataObject** ppIDataObject );
59cdf0e10cSrcweir 	HRESULT flushClipboard( );
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 	// register/unregister a clipboard viewer; there can only
62cdf0e10cSrcweir 	// be one at a time; parameter NULL means unregister
63cdf0e10cSrcweir 	// a clipboard viewer
64cdf0e10cSrcweir 	// returns true on success else false; use GetLastError( ) in
65cdf0e10cSrcweir 	// false case
66cdf0e10cSrcweir 	sal_Bool registerClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir private:
69cdf0e10cSrcweir 	unsigned int run( );
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	// create a hidden windows which serves as an request
72cdf0e10cSrcweir 	// target; so we guarantee synchronization
73cdf0e10cSrcweir 	void createMtaOleReqWnd( );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	// message support
76cdf0e10cSrcweir 	sal_Bool postMessage( UINT msg, WPARAM wParam = 0, LPARAM lParam = 0 );
77cdf0e10cSrcweir 	LRESULT  sendMessage( UINT msg, WPARAM wParam = 0, LPARAM lParam = 0 );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	//---------------------------------------------------------------
80*07a3d7f1SPedro Giffuni 	// message handler functions; remember these functions are called
81cdf0e10cSrcweir 	// from a different thread context!
82cdf0e10cSrcweir 	//---------------------------------------------------------------
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	LRESULT  onSetClipboard( IDataObject* pIDataObject );
85cdf0e10cSrcweir 	LRESULT  onGetClipboard( LPSTREAM* ppStream );
86cdf0e10cSrcweir 	LRESULT  onFlushClipboard( );
87cdf0e10cSrcweir 	sal_Bool onRegisterClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	// win32 clipboard-viewer support
90cdf0e10cSrcweir 	LRESULT onChangeCBChain( HWND hWndRemove, HWND hWndNext );
91cdf0e10cSrcweir 	LRESULT onDrawClipboard( );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	static LRESULT CALLBACK mtaOleReqWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
94cdf0e10cSrcweir 	static unsigned int WINAPI oleThreadProc( LPVOID pParam );
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     static unsigned int WINAPI clipboardChangedNotifierThreadProc( LPVOID pParam );
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	sal_Bool WaitForThreadReady( ) const;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir private:
101cdf0e10cSrcweir 	HANDLE						m_hOleThread;
102cdf0e10cSrcweir 	unsigned					m_uOleThreadId;
103cdf0e10cSrcweir 	HANDLE						m_hEvtThrdReady;
104cdf0e10cSrcweir 	HWND						m_hwndMtaOleReqWnd;
105cdf0e10cSrcweir 	ATOM						m_MtaOleReqWndClassAtom;
106cdf0e10cSrcweir 	HWND						m_hwndNextClipViewer;
107cdf0e10cSrcweir 	LPFNC_CLIPVIEWER_CALLBACK_t	m_pfncClipViewerCallback;
108cdf0e10cSrcweir 	sal_Bool					m_bInRegisterClipViewer;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     sal_Bool                    m_bRunClipboardNotifierThread;
111cdf0e10cSrcweir     HANDLE                      m_hClipboardChangedNotifierThread;
112cdf0e10cSrcweir     HANDLE                      m_hClipboardChangedNotifierEvents[2];
113cdf0e10cSrcweir     HANDLE&                     m_hClipboardChangedEvent;
114cdf0e10cSrcweir     HANDLE&                     m_hTerminateClipboardChangedNotifierEvent;
115cdf0e10cSrcweir     osl::Mutex                  m_ClipboardChangedEventCountMutex;
116cdf0e10cSrcweir     sal_Int32                   m_ClipboardChangedEventCount;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     osl::Mutex                  m_pfncClipViewerCallbackMutex;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	static CMtaOleClipboard*    s_theMtaOleClipboardInst;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir // not allowed
123cdf0e10cSrcweir private:
124cdf0e10cSrcweir 	CMtaOleClipboard( const CMtaOleClipboard& );
125cdf0e10cSrcweir 	CMtaOleClipboard& operator=( const CMtaOleClipboard& );
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	friend LRESULT CALLBACK mtaOleReqWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
128cdf0e10cSrcweir };
129cdf0e10cSrcweir 
130cdf0e10cSrcweir #endif
131