1 | /*
|
---|
2 | * synergy -- mouse and keyboard sharing utility
|
---|
3 | * Copyright (C) 2002 Chris Schoeneman
|
---|
4 | *
|
---|
5 | * This package is free software; you can redistribute it and/or
|
---|
6 | * modify it under the terms of the GNU General Public License
|
---|
7 | * found in the file COPYING that should have accompanied this file.
|
---|
8 | *
|
---|
9 | * This package is distributed in the hope that it will be useful,
|
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | * GNU General Public License for more details.
|
---|
13 | */
|
---|
14 |
|
---|
15 | #ifndef CMSWINDOWSCLIPBOARD_H
|
---|
16 | #define CMSWINDOWSCLIPBOARD_H
|
---|
17 |
|
---|
18 | #include "IClipboard.h"
|
---|
19 | #include "stdvector.h"
|
---|
20 | #define WIN32_LEAN_AND_MEAN
|
---|
21 | #include <windows.h>
|
---|
22 |
|
---|
23 | class IMSWindowsClipboardConverter;
|
---|
24 |
|
---|
25 | //! Microsoft windows clipboard implementation
|
---|
26 | class CMSWindowsClipboard : public IClipboard {
|
---|
27 | public:
|
---|
28 | CMSWindowsClipboard(HWND window);
|
---|
29 | virtual ~CMSWindowsClipboard();
|
---|
30 |
|
---|
31 | //! Empty clipboard without ownership
|
---|
32 | /*!
|
---|
33 | Take ownership of the clipboard and clear all data from it.
|
---|
34 | This must be called between a successful open() and close().
|
---|
35 | Return false if the clipboard ownership could not be taken;
|
---|
36 | the clipboard should not be emptied in this case. Unlike
|
---|
37 | empty(), isOwnedBySynergy() will return false when emptied
|
---|
38 | this way. This is useful when synergy wants to put data on
|
---|
39 | clipboard but pretend (to itself) that some other app did it.
|
---|
40 | When using empty(), synergy assumes the data came from the
|
---|
41 | server and doesn't need to be sent back. emptyUnowned()
|
---|
42 | makes synergy send the data to the server.
|
---|
43 | */
|
---|
44 | bool emptyUnowned();
|
---|
45 |
|
---|
46 | //! Test if clipboard is owned by synergy
|
---|
47 | static bool isOwnedBySynergy();
|
---|
48 |
|
---|
49 | // IClipboard overrides
|
---|
50 | virtual bool empty();
|
---|
51 | virtual void add(EFormat, const CString& data);
|
---|
52 | virtual bool open(Time) const;
|
---|
53 | virtual void close() const;
|
---|
54 | virtual Time getTime() const;
|
---|
55 | virtual bool has(EFormat) const;
|
---|
56 | virtual CString get(EFormat) const;
|
---|
57 |
|
---|
58 | private:
|
---|
59 | void clearConverters();
|
---|
60 |
|
---|
61 | UINT convertFormatToWin32(EFormat) const;
|
---|
62 | HANDLE convertTextToWin32(const CString& data) const;
|
---|
63 | CString convertTextFromWin32(HANDLE) const;
|
---|
64 |
|
---|
65 | static UINT getOwnershipFormat();
|
---|
66 |
|
---|
67 | private:
|
---|
68 | typedef std::vector<IMSWindowsClipboardConverter*> ConverterList;
|
---|
69 |
|
---|
70 | HWND m_window;
|
---|
71 | mutable Time m_time;
|
---|
72 | ConverterList m_converters;
|
---|
73 | static UINT s_ownershipFormat;
|
---|
74 | };
|
---|
75 |
|
---|
76 | //! Clipboard format converter interface
|
---|
77 | /*!
|
---|
78 | This interface defines the methods common to all win32 clipboard format
|
---|
79 | converters.
|
---|
80 | */
|
---|
81 | class IMSWindowsClipboardConverter : public IInterface {
|
---|
82 | public:
|
---|
83 | // accessors
|
---|
84 |
|
---|
85 | // return the clipboard format this object converts from/to
|
---|
86 | virtual IClipboard::EFormat
|
---|
87 | getFormat() const = 0;
|
---|
88 |
|
---|
89 | // return the atom representing the win32 clipboard format that
|
---|
90 | // this object converts from/to
|
---|
91 | virtual UINT getWin32Format() const = 0;
|
---|
92 |
|
---|
93 | // convert from the IClipboard format to the win32 clipboard format.
|
---|
94 | // the input data must be in the IClipboard format returned by
|
---|
95 | // getFormat(). the return data will be in the win32 clipboard
|
---|
96 | // format returned by getWin32Format(), allocated by GlobalAlloc().
|
---|
97 | virtual HANDLE fromIClipboard(const CString&) const = 0;
|
---|
98 |
|
---|
99 | // convert from the win32 clipboard format to the IClipboard format
|
---|
100 | // (i.e., the reverse of fromIClipboard()).
|
---|
101 | virtual CString toIClipboard(HANDLE data) const = 0;
|
---|
102 | };
|
---|
103 |
|
---|
104 | #endif
|
---|