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