xref: /trunk/main/dtrans/source/inc/MtaOleClipb.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _MTAOLECLIPB_HXX_
29 #define _MTAOLECLIPB_HXX_
30 
31 #include <sal/types.h>
32 #include <osl/mutex.hxx>
33 
34 #if defined _MSC_VER
35 #pragma warning(push,1)
36 #endif
37 #include <objidl.h>
38 #if defined _MSC_VER
39 #pragma warning(pop)
40 #endif
41 
42 //--------------------------------------------------------
43 // the Mta-Ole clipboard class is for internal use only!
44 // only one instance of this class should be created, the
45 // user has to ensure this!
46 // the class is not thread-safe because it will be used
47 // only from within the clipboard service and the methods
48 // of the clipboard service are already synchronized
49 //--------------------------------------------------------
50 
51 class CMtaOleClipboard
52 {
53 public:
54 	typedef void ( WINAPI *LPFNC_CLIPVIEWER_CALLBACK_t )( void );
55 
56 public:
57 	CMtaOleClipboard( );
58 	~CMtaOleClipboard( );
59 
60 	// clipboard functions
61 	HRESULT setClipboard( IDataObject* pIDataObject );
62 	HRESULT getClipboard( IDataObject** ppIDataObject );
63 	HRESULT flushClipboard( );
64 
65 	// register/unregister a clipboard viewer; there can only
66 	// be one at a time; parameter NULL means unregister
67 	// a clipboard viewer
68 	// returns true on success else false; use GetLastError( ) in
69 	// false case
70 	sal_Bool registerClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback );
71 
72 private:
73 	unsigned int run( );
74 
75 	// create a hidden windows which serves as an request
76 	// target; so we guarantee synchronization
77 	void createMtaOleReqWnd( );
78 
79 	// message support
80 	sal_Bool postMessage( UINT msg, WPARAM wParam = 0, LPARAM lParam = 0 );
81 	LRESULT  sendMessage( UINT msg, WPARAM wParam = 0, LPARAM lParam = 0 );
82 
83 	//---------------------------------------------------------------
84 	// message handler functions; remeber these functions are called
85 	// from a different thread context!
86 	//---------------------------------------------------------------
87 
88 	LRESULT  onSetClipboard( IDataObject* pIDataObject );
89 	LRESULT  onGetClipboard( LPSTREAM* ppStream );
90 	LRESULT  onFlushClipboard( );
91 	sal_Bool onRegisterClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback );
92 
93 	// win32 clipboard-viewer support
94 	LRESULT onChangeCBChain( HWND hWndRemove, HWND hWndNext );
95 	LRESULT onDrawClipboard( );
96 
97 	static LRESULT CALLBACK mtaOleReqWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
98 	static unsigned int WINAPI oleThreadProc( LPVOID pParam );
99 
100     static unsigned int WINAPI clipboardChangedNotifierThreadProc( LPVOID pParam );
101 
102 	sal_Bool WaitForThreadReady( ) const;
103 
104 private:
105 	HANDLE						m_hOleThread;
106 	unsigned					m_uOleThreadId;
107 	HANDLE						m_hEvtThrdReady;
108 	HWND						m_hwndMtaOleReqWnd;
109 	ATOM						m_MtaOleReqWndClassAtom;
110 	HWND						m_hwndNextClipViewer;
111 	LPFNC_CLIPVIEWER_CALLBACK_t	m_pfncClipViewerCallback;
112 	sal_Bool					m_bInRegisterClipViewer;
113 
114     sal_Bool                    m_bRunClipboardNotifierThread;
115     HANDLE                      m_hClipboardChangedNotifierThread;
116     HANDLE                      m_hClipboardChangedNotifierEvents[2];
117     HANDLE&                     m_hClipboardChangedEvent;
118     HANDLE&                     m_hTerminateClipboardChangedNotifierEvent;
119     osl::Mutex                  m_ClipboardChangedEventCountMutex;
120     sal_Int32                   m_ClipboardChangedEventCount;
121 
122     osl::Mutex                  m_pfncClipViewerCallbackMutex;
123 
124 	static CMtaOleClipboard*    s_theMtaOleClipboardInst;
125 
126 // not allowed
127 private:
128 	CMtaOleClipboard( const CMtaOleClipboard& );
129 	CMtaOleClipboard& operator=( const CMtaOleClipboard& );
130 
131 	friend LRESULT CALLBACK mtaOleReqWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
132 };
133 
134 #endif
135