Changeset 2752 for trunk/synergy/lib/platform/CPMClipboard.cpp
- Timestamp:
- Jul 29, 2006, 6:43:07 AM (19 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/synergy/lib/platform/CPMClipboard.cpp
r2751 r2752 2 2 * synergy -- mouse and keyboard sharing utility 3 3 * Copyright (C) 2002 Chris Schoeneman 4 * Copyright (C) 2006 Knut St. Osmundsen 4 5 * 5 6 * This package is free software; you can redistribute it and/or … … 13 14 */ 14 15 15 #include "C MSWindowsClipboard.h"16 #include "C MSWindowsClipboardTextConverter.h"17 #include "C MSWindowsClipboardUTF16Converter.h"18 #include "C MSWindowsClipboardBitmapConverter.h"19 #include "C MSWindowsClipboardHTMLConverter.h"16 #include "CPMClipboard.h" 17 #include "CPMClipboardTextConverter.h" 18 #include "CPMClipboardBitmapConverter.h" 19 #include "CPMClipboardHTMLConverter.h" 20 #include "CPMUtil.h" 20 21 #include "CLog.h" 21 #include "CArchMiscWindows.h"22 22 23 23 // 24 // C MSWindowsClipboard24 // CPMClipboard 25 25 // 26 26 27 UINT CMSWindowsClipboard::s_ownershipFormat = 0;28 29 C MSWindowsClipboard::CMSWindowsClipboard(HWND window) :27 ATOM CPMClipboard::s_ownershipFormat = 0; 28 29 CPMClipboard::CPMClipboard(HWND window) : 30 30 m_window(window), 31 31 m_time(0) 32 32 { 33 33 // add converters, most desired first 34 m_converters.push_back(new CMSWindowsClipboardUTF16Converter); 35 if (CArchMiscWindows::isWindows95Family()) { 36 // windows nt family converts to/from unicode automatically. 37 // let it do so to avoid text encoding issues. 38 m_converters.push_back(new CMSWindowsClipboardTextConverter); 39 } 40 m_converters.push_back(new CMSWindowsClipboardBitmapConverter); 41 m_converters.push_back(new CMSWindowsClipboardHTMLConverter); 42 } 43 44 CMSWindowsClipboard::~CMSWindowsClipboard() 34 m_converters.push_back(new CPMClipboardTextConverter); 35 m_converters.push_back(new CPMClipboardBitmapConverter); 36 m_converters.push_back(new CPMClipboardHTMLConverter); 37 } 38 39 CPMClipboard::~CPMClipboard() 45 40 { 46 41 clearConverters(); … … 48 43 49 44 bool 50 C MSWindowsClipboard::emptyUnowned()45 CPMClipboard::emptyUnowned() 51 46 { 52 47 LOG((CLOG_DEBUG "empty clipboard")); 53 48 54 49 // empty the clipboard (and take ownership) 55 if (! EmptyClipboard()) {50 if (!WinEmptyClipbrd(CPMUtil::getHAB())) { 56 51 LOG((CLOG_DEBUG "failed to grab clipboard")); 57 52 return false; … … 62 57 63 58 bool 64 C MSWindowsClipboard::empty()59 CPMClipboard::empty() 65 60 { 66 61 if (!emptyUnowned()) { … … 69 64 70 65 // mark clipboard as being owned by synergy 71 HGLOBAL data = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, 1); 72 SetClipboardData(getOwnershipFormat(), data); 73 74 return true; 66 PVOID pv = NULL; 67 APIRET rc = DosAllocSharedMem(&pv, NULL, 1, PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_GETTABLE | OBJ_GIVEABLE); 68 if (rc) { 69 assert(rc); 70 return false; 71 } 72 return !!WinSetClipbrdData(CPMUtil::getHAB(), (ULONG)pv, getOwnershipFormat(), CFI_POINTER); 75 73 } 76 74 77 75 void 78 C MSWindowsClipboard::add(EFormat format, const CString& data)76 CPMClipboard::add(EFormat format, const CString& data) 79 77 { 80 78 LOG((CLOG_DEBUG "add %d bytes to clipboard format: %d", data.size(), format)); … … 82 80 // convert data to win32 form 83 81 for (ConverterList::const_iterator index = m_converters.begin(); 84 index != m_converters.end(); ++index) { 85 IMSWindowsClipboardConverter* converter = *index; 82 index != m_converters.end(); 83 ++index) { 84 IPMClipboardConverter* converter = *index; 86 85 87 86 // skip converters for other formats 88 87 if (converter->getFormat() == format) { 89 HANDLE win32Data = converter->fromIClipboard(data);90 if ( win32Data != NULL) {91 U INT win32Format = converter->getWin32Format();92 if (SetClipboardData(win32Format, win32Data) == NULL) { 93 // free converted data if we couldn't put it on94 // the clipboard95 GlobalFree(win32Data);88 ULONG ulPMData = converter->fromIClipboard(data); 89 if (ulPMData != NULL) { 90 ULONG ulPMFormat = converter->getPMFormat(); 91 ULONG ulPMFormatInfo = converter->getPMFormatInfo(); 92 if (!WinSetClipbrdData(CPMUtil::getHAB(), ulPMData, ulPMFormat, ulPMFormatInfo)) { 93 // free converted data if we couldn't put it on the clipboard 94 converter->freePMData(ulPMData); 96 95 } 97 96 } … … 101 100 102 101 bool 103 C MSWindowsClipboard::open(Time time) const102 CPMClipboard::open(Time time) const 104 103 { 105 104 LOG((CLOG_DEBUG "open clipboard")); 106 105 107 if (! OpenClipboard(m_window)) {106 if (!WinOpenClipbrd(m_window)) { 108 107 LOG((CLOG_WARN "failed to open clipboard")); 109 108 return false; … … 116 115 117 116 void 118 C MSWindowsClipboard::close() const117 CPMClipboard::close() const 119 118 { 120 119 LOG((CLOG_DEBUG "close clipboard")); 121 CloseClipboard();120 WinCloseClipbrd(CPMUtil::getHAB()); 122 121 } 123 122 124 123 IClipboard::Time 125 C MSWindowsClipboard::getTime() const124 CPMClipboard::getTime() const 126 125 { 127 126 return m_time; … … 129 128 130 129 bool 131 C MSWindowsClipboard::has(EFormat format) const130 CPMClipboard::has(EFormat format) const 132 131 { 133 132 for (ConverterList::const_iterator index = m_converters.begin(); 134 index != m_converters.end(); ++index) { 135 IMSWindowsClipboardConverter* converter = *index; 133 index != m_converters.end(); 134 ++index) { 135 IPMClipboardConverter* converter = *index; 136 136 if (converter->getFormat() == format) { 137 if (IsClipboardFormatAvailable(converter->getWin32Format())) { 137 ULONG fFmtInfo; 138 if (WinQueryClipbrdFmtInfo(CPMUtil::getHAB(), getOwnershipFormat(), &fFmtInfo)) { 138 139 return true; 139 140 } … … 144 145 145 146 CString 146 C MSWindowsClipboard::get(EFormat format) const147 CPMClipboard::get(EFormat format) const 147 148 { 148 149 // find the converter for the first clipboard format we can handle 149 I MSWindowsClipboardConverter* converter = NULL;150 U INT win32Format = EnumClipboardFormats(0);151 while (converter == NULL && win32Format != 0) {150 IPMClipboardConverter* converter = NULL; 151 ULONG pmFormat = WinEnumClipbrdFmts(CPMUtil::getHAB(), 0); 152 while (converter == NULL && pmFormat != 0) { 152 153 for (ConverterList::const_iterator index = m_converters.begin(); 153 index != m_converters.end(); ++index) { 154 index != m_converters.end(); 155 ++index) { 154 156 converter = *index; 155 if (converter->get Win32Format() == win32Format &&156 converter->getFormat() 157 if (converter->getPMFormat() == pmFormat && 158 converter->getFormat() == format) { 157 159 break; 158 160 } 159 161 converter = NULL; 160 162 } 161 win32Format = EnumClipboardFormats(win32Format);163 pmFormat = WinEnumClipbrdFmts(CPMUtil::getHAB(), pmFormat); 162 164 } 163 165 … … 168 170 169 171 // get a handle to the clipboard data 170 HANDLE win32Data = GetClipboardData(converter->getWin32Format());171 if ( win32Data == NULL) {172 ULONG ulData = WinQueryClipbrdData(CPMUtil::getHAB(), converter->getPMFormat()); 173 if (ulData == 0) { 172 174 return CString(); 173 175 } 174 176 175 177 // convert 176 return converter->toIClipboard( win32Data);178 return converter->toIClipboard(ulData); 177 179 } 178 180 179 181 void 180 C MSWindowsClipboard::clearConverters()182 CPMClipboard::clearConverters() 181 183 { 182 184 for (ConverterList::iterator index = m_converters.begin(); 183 index != m_converters.end(); ++index) { 185 index != m_converters.end(); 186 ++index) { 184 187 delete *index; 185 188 } … … 188 191 189 192 bool 190 CMSWindowsClipboard::isOwnedBySynergy() 193 CPMClipboard::isOwnedBySynergy() 194 { 195 ULONG fFmtInfo; 196 return (!!WinQueryClipbrdFmtInfo(CPMUtil::getHAB(), getOwnershipFormat(), &fFmtInfo)); 197 } 198 199 ATOM 200 CPMClipboard::getOwnershipFormat() 191 201 { 192 202 // create ownership format if we haven't yet 193 203 if (s_ownershipFormat == 0) { 194 s_ownershipFormat = RegisterClipboardFormat(TEXT("SynergyOwnership")); 195 } 196 return (IsClipboardFormatAvailable(getOwnershipFormat()) != 0); 197 } 198 199 UINT 200 CMSWindowsClipboard::getOwnershipFormat() 201 { 202 // create ownership format if we haven't yet 203 if (s_ownershipFormat == 0) { 204 s_ownershipFormat = RegisterClipboardFormat(TEXT("SynergyOwnership")); 204 ATOM hAtom = WinAddAtom(WinQuerySystemAtomTable(), (PCSZ)"SynergyOwnership"); 205 if (hAtom == 0) 206 hAtom = WinFindAtom(WinQuerySystemAtomTable(), (PCSZ)"SynergyOwnership"); 207 assert(hAtom != 0); 208 s_ownershipFormat = hAtom; 205 209 } 206 210
Note:
See TracChangeset
for help on using the changeset viewer.