LibreOffice Module dtrans (master)  1
MtaOleClipb.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_DTRANS_SOURCE_WIN32_CLIPB_MTAOLECLIPB_HXX
21 #define INCLUDED_DTRANS_SOURCE_WIN32_CLIPB_MTAOLECLIPB_HXX
22 
23 #include <sal/types.h>
24 #include <osl/mutex.hxx>
25 
26 #include <objidl.h>
27 
28 // the Mta-Ole clipboard class is for internal use only!
29 // only one instance of this class should be created, the
30 // user has to ensure this!
31 // the class is not thread-safe because it will be used
32 // only from within the clipboard service and the methods
33 // of the clipboard service are already synchronized
34 
36 {
37 public:
38  typedef void ( WINAPI *LPFNC_CLIPVIEWER_CALLBACK_t )( void );
39 
40 public:
43 
44  // clipboard functions
45  HRESULT setClipboard( IDataObject* pIDataObject );
46  HRESULT getClipboard( IDataObject** ppIDataObject );
47  HRESULT flushClipboard( );
48 
49  // register/unregister a clipboard viewer; there can only
50  // be one at a time; parameter NULL means unregister
51  // a clipboard viewer
52  // returns true on success else false; use GetLastError( ) in
53  // false case
54  bool registerClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback );
55 
56 private:
57  unsigned int run( );
58 
59  // create a hidden window which serves as a request target; so we
60  // guarantee synchronization
61  void createMtaOleReqWnd( );
62 
63  // message support
64  bool postMessage( UINT msg, WPARAM wParam = 0, LPARAM lParam = 0 );
65  LRESULT sendMessage( UINT msg, WPARAM wParam = 0, LPARAM lParam = 0 );
66 
67  // message handler functions; remember these functions are called
68  // from a different thread context!
69 
70  static HRESULT onSetClipboard( IDataObject* pIDataObject );
71  static HRESULT onGetClipboard( LPSTREAM* ppStream );
72  static HRESULT onFlushClipboard( );
73  bool onRegisterClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback );
74 
75  // win32 clipboard listener support
76  LRESULT onClipboardUpdate();
77 
78  static LRESULT CALLBACK mtaOleReqWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
79  static unsigned int WINAPI oleThreadProc( LPVOID pParam );
80 
81  static unsigned int WINAPI clipboardChangedNotifierThreadProc( LPVOID pParam );
82 
83  bool WaitForThreadReady( ) const;
84 
85 private:
86  HANDLE m_hOleThread;
87  unsigned m_uOleThreadId;
92  LPFNC_CLIPVIEWER_CALLBACK_t m_pfncClipViewerCallback;
94 
102 
104 
106 
107 // not allowed
108 private:
111 
112  friend LRESULT CALLBACK mtaOleReqWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
113 };
114 
115 #endif
116 
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static LRESULT CALLBACK mtaOleReqWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
HANDLE & m_hTerminateClipboardChangedNotifierEvent
Definition: MtaOleClipb.hxx:99
HANDLE & m_hClipboardChangedEvent
Definition: MtaOleClipb.hxx:98
LRESULT sendMessage(UINT msg, WPARAM wParam=0, LPARAM lParam=0)
void createMtaOleReqWnd()
bool m_bRunClipboardNotifierThread
Definition: MtaOleClipb.hxx:95
static CMtaOleClipboard * s_theMtaOleClipboardInst
static HRESULT onSetClipboard(IDataObject *pIDataObject)
HANDLE m_hEvtWndDisposed
Definition: MtaOleClipb.hxx:90
static unsigned int WINAPI clipboardChangedNotifierThreadProc(LPVOID pParam)
sal_Int32 m_ClipboardChangedEventCount
bool registerClipViewer(LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback)
bool onRegisterClipViewer(LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback)
bool WaitForThreadReady() const
HANDLE m_hClipboardChangedNotifierThread
Definition: MtaOleClipb.hxx:96
LRESULT onClipboardUpdate()
HRESULT flushClipboard()
LPFNC_CLIPVIEWER_CALLBACK_t m_pfncClipViewerCallback
Definition: MtaOleClipb.hxx:92
typedef void(WINAPI *LPFNC_CLIPVIEWER_CALLBACK_t)(void)
static HRESULT onFlushClipboard()
unsigned int run()
HANDLE m_hClipboardChangedNotifierEvents[2]
Definition: MtaOleClipb.hxx:97
static HRESULT onGetClipboard(LPSTREAM *ppStream)
CMtaOleClipboard & operator=(const CMtaOleClipboard &)
bool m_bInRegisterClipViewer
Definition: MtaOleClipb.hxx:93
osl::Mutex m_ClipboardChangedEventCountMutex
unsigned m_uOleThreadId
Definition: MtaOleClipb.hxx:87
ATOM m_MtaOleReqWndClassAtom
Definition: MtaOleClipb.hxx:91
static unsigned int WINAPI oleThreadProc(LPVOID pParam)
osl::Mutex m_pfncClipViewerCallbackMutex
HRESULT setClipboard(IDataObject *pIDataObject)
HRESULT getClipboard(IDataObject **ppIDataObject)
#define CALLBACK
HANDLE m_hEvtThrdReady
Definition: MtaOleClipb.hxx:88
bool postMessage(UINT msg, WPARAM wParam=0, LPARAM lParam=0)