1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MtaOleClipb.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _MTAOLECLIPB_HXX_
32 #define _MTAOLECLIPB_HXX_
34 #include <sal/types.h>
35 #include <osl/mutex.hxx>
38 #pragma warning(push,1)
45 //--------------------------------------------------------
46 // the Mta-Ole clipboard class is for internal use only!
47 // only one instance of this class should be created, the
48 // user has to ensure this!
49 // the class is not thread-safe because it will be used
50 // only from within the clipboard service and the methods
51 // of the clipboard service are already synchronized
52 //--------------------------------------------------------
54 class CMtaOleClipboard
57 typedef void ( WINAPI
*LPFNC_CLIPVIEWER_CALLBACK_t
)( void );
63 // clipboard functions
64 HRESULT
setClipboard( IDataObject
* pIDataObject
);
65 HRESULT
getClipboard( IDataObject
** ppIDataObject
);
66 HRESULT
flushClipboard( );
68 // register/unregister a clipboard viewer; there can only
69 // be one at a time; parameter NULL means unregister
71 // returns true on success else false; use GetLastError( ) in
73 sal_Bool
registerClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback
);
78 // create a hidden windows which serves as an request
79 // target; so we guarantee synchronization
80 void createMtaOleReqWnd( );
83 sal_Bool
postMessage( UINT msg
, WPARAM wParam
= 0, LPARAM lParam
= 0 );
84 LRESULT
sendMessage( UINT msg
, WPARAM wParam
= 0, LPARAM lParam
= 0 );
86 //---------------------------------------------------------------
87 // message handler functions; remeber these functions are called
88 // from a different thread context!
89 //---------------------------------------------------------------
91 LRESULT
onSetClipboard( IDataObject
* pIDataObject
);
92 LRESULT
onGetClipboard( LPSTREAM
* ppStream
);
93 LRESULT
onFlushClipboard( );
94 sal_Bool
onRegisterClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback
);
96 // win32 clipboard-viewer support
97 LRESULT
onChangeCBChain( HWND hWndRemove
, HWND hWndNext
);
98 LRESULT
onDrawClipboard( );
100 static LRESULT CALLBACK
mtaOleReqWndProc( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
101 static unsigned int WINAPI
oleThreadProc( LPVOID pParam
);
103 static unsigned int WINAPI
clipboardChangedNotifierThreadProc( LPVOID pParam
);
105 sal_Bool
WaitForThreadReady( ) const;
109 unsigned m_uOleThreadId
;
110 HANDLE m_hEvtThrdReady
;
111 HWND m_hwndMtaOleReqWnd
;
112 ATOM m_MtaOleReqWndClassAtom
;
113 HWND m_hwndNextClipViewer
;
114 LPFNC_CLIPVIEWER_CALLBACK_t m_pfncClipViewerCallback
;
115 sal_Bool m_bInRegisterClipViewer
;
117 sal_Bool m_bRunClipboardNotifierThread
;
118 HANDLE m_hClipboardChangedNotifierThread
;
119 HANDLE m_hClipboardChangedNotifierEvents
[2];
120 HANDLE
& m_hClipboardChangedEvent
;
121 HANDLE
& m_hTerminateClipboardChangedNotifierEvent
;
122 osl::Mutex m_ClipboardChangedEventCountMutex
;
123 sal_Int32 m_ClipboardChangedEventCount
;
125 osl::Mutex m_pfncClipViewerCallbackMutex
;
127 static CMtaOleClipboard
* s_theMtaOleClipboardInst
;
131 CMtaOleClipboard( const CMtaOleClipboard
& );
132 CMtaOleClipboard
& operator=( const CMtaOleClipboard
& );
134 friend LRESULT CALLBACK
mtaOleReqWndProc( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);