update dev300-m58
[ooovba.git] / dtrans / source / inc / MtaOleClipb.hxx
blobc5bb2471b5e174ba7256072bf982a173716b0f95
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MtaOleClipb.hxx,v $
10 * $Revision: 1.9 $
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>
37 #if defined _MSC_VER
38 #pragma warning(push,1)
39 #endif
40 #include <objidl.h>
41 #if defined _MSC_VER
42 #pragma warning(pop)
43 #endif
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
56 public:
57 typedef void ( WINAPI *LPFNC_CLIPVIEWER_CALLBACK_t )( void );
59 public:
60 CMtaOleClipboard( );
61 ~CMtaOleClipboard( );
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
70 // a clipboard viewer
71 // returns true on success else false; use GetLastError( ) in
72 // false case
73 sal_Bool registerClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback );
75 private:
76 unsigned int run( );
78 // create a hidden windows which serves as an request
79 // target; so we guarantee synchronization
80 void createMtaOleReqWnd( );
82 // message support
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;
107 private:
108 HANDLE m_hOleThread;
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;
129 // not allowed
130 private:
131 CMtaOleClipboard( const CMtaOleClipboard& );
132 CMtaOleClipboard& operator=( const CMtaOleClipboard& );
134 friend LRESULT CALLBACK mtaOleReqWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
137 #endif