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