Changeset 2770 for trunk/synergy/lib/platform
- Timestamp:
- Aug 20, 2006, 8:15:41 AM (19 years ago)
- Location:
- trunk/synergy/lib/platform
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/synergy/lib/platform/CPMClipboard.cpp
r2752 r2770 3 3 * Copyright (C) 2002 Chris Schoeneman 4 4 * Copyright (C) 2006 Knut St. Osmundsen 5 * 5 * 6 6 * This package is free software; you can redistribute it and/or 7 7 * modify it under the terms of the GNU General Public License 8 8 * found in the file COPYING that should have accompanied this file. 9 * 9 * 10 10 * This package is distributed in the hope that it will be useful, 11 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of … … 25 25 // 26 26 27 ATOM 27 ATOM CPMClipboard::s_ownershipFormat = 0; 28 28 29 29 CPMClipboard::CPMClipboard(HWND window) : 30 31 32 { 33 34 35 36 30 m_window(window), 31 m_time(0) 32 { 33 // add converters, most desired first 34 m_converters.push_back(new CPMClipboardTextConverter); 35 m_converters.push_back(new CPMClipboardBitmapConverter); 36 m_converters.push_back(new CPMClipboardHTMLConverter); 37 37 } 38 38 39 39 CPMClipboard::~CPMClipboard() 40 40 { 41 41 clearConverters(); 42 42 } 43 43 … … 45 45 CPMClipboard::emptyUnowned() 46 46 { 47 48 49 50 51 52 53 54 55 47 LOG((CLOG_DEBUG "empty clipboard")); 48 49 // empty the clipboard (and take ownership) 50 if (!WinEmptyClipbrd(CPMUtil::getHAB())) { 51 LOG((CLOG_DEBUG "failed to grab clipboard")); 52 return false; 53 } 54 55 return true; 56 56 } 57 57 … … 59 59 CPMClipboard::empty() 60 60 { 61 62 63 64 65 61 if (!emptyUnowned()) { 62 return false; 63 } 64 65 // mark clipboard as being owned by synergy 66 66 PVOID pv = NULL; 67 67 APIRET rc = DosAllocSharedMem(&pv, NULL, 1, PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_GETTABLE | OBJ_GIVEABLE); … … 70 70 return false; 71 71 } 72 72 return !!WinSetClipbrdData(CPMUtil::getHAB(), (ULONG)pv, getOwnershipFormat(), CFI_POINTER); 73 73 } 74 74 … … 76 76 CPMClipboard::add(EFormat format, const CString& data) 77 77 { 78 79 80 81 82 83 84 85 86 87 88 89 90 78 LOG((CLOG_DEBUG "add %d bytes to clipboard format: %d", data.size(), format)); 79 80 // convert data to win32 form 81 for (ConverterList::const_iterator index = m_converters.begin(); 82 index != m_converters.end(); 83 ++index) { 84 IPMClipboardConverter* converter = *index; 85 86 // skip converters for other formats 87 if (converter->getFormat() == format) { 88 ULONG ulPMData = converter->fromIClipboard(data); 89 if (ulPMData != NULL) { 90 ULONG ulPMFormat = converter->getPMFormat(); 91 91 ULONG ulPMFormatInfo = converter->getPMFormatInfo(); 92 93 92 if (!WinSetClipbrdData(CPMUtil::getHAB(), ulPMData, ulPMFormat, ulPMFormatInfo)) { 93 // free converted data if we couldn't put it on the clipboard 94 94 converter->freePMData(ulPMData); 95 96 97 98 95 } 96 } 97 } 98 } 99 99 } 100 100 … … 102 102 CPMClipboard::open(Time time) const 103 103 { 104 105 106 107 108 109 110 111 112 113 104 LOG((CLOG_DEBUG "open clipboard")); 105 106 if (!WinOpenClipbrd(m_window)) { 107 LOG((CLOG_WARN "failed to open clipboard")); 108 return false; 109 } 110 111 m_time = time; 112 113 return true; 114 114 } 115 115 … … 117 117 CPMClipboard::close() const 118 118 { 119 120 119 LOG((CLOG_DEBUG "close clipboard")); 120 WinCloseClipbrd(CPMUtil::getHAB()); 121 121 } 122 122 … … 124 124 CPMClipboard::getTime() const 125 125 { 126 126 return m_time; 127 127 } 128 128 … … 130 130 CPMClipboard::has(EFormat format) const 131 131 { 132 133 134 135 136 132 for (ConverterList::const_iterator index = m_converters.begin(); 133 index != m_converters.end(); 134 ++index) { 135 IPMClipboardConverter* converter = *index; 136 if (converter->getFormat() == format) { 137 137 ULONG fFmtInfo; 138 139 140 141 142 143 138 if (WinQueryClipbrdFmtInfo(CPMUtil::getHAB(), getOwnershipFormat(), &fFmtInfo)) { 139 return true; 140 } 141 } 142 } 143 return false; 144 144 } 145 145 … … 147 147 CPMClipboard::get(EFormat format) const 148 148 { 149 150 151 152 153 154 index != m_converters.end(); 149 // find the converter for the first clipboard format we can handle 150 IPMClipboardConverter* converter = NULL; 151 ULONG pmFormat = WinEnumClipbrdFmts(CPMUtil::getHAB(), 0); 152 while (converter == NULL && pmFormat != 0) { 153 for (ConverterList::const_iterator index = m_converters.begin(); 154 index != m_converters.end(); 155 155 ++index) { 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 156 converter = *index; 157 if (converter->getPMFormat() == pmFormat && 158 converter->getFormat() == format) { 159 break; 160 } 161 converter = NULL; 162 } 163 pmFormat = WinEnumClipbrdFmts(CPMUtil::getHAB(), pmFormat); 164 } 165 166 // if no converter then we don't recognize any formats 167 if (converter == NULL) { 168 return CString(); 169 } 170 171 // get a handle to the clipboard data 172 ULONG ulData = WinQueryClipbrdData(CPMUtil::getHAB(), converter->getPMFormat()); 173 if (ulData == 0) { 174 return CString(); 175 } 176 177 // convert 178 return converter->toIClipboard(ulData); 179 179 } 180 180 … … 182 182 CPMClipboard::clearConverters() 183 183 { 184 185 186 187 188 189 184 for (ConverterList::iterator index = m_converters.begin(); 185 index != m_converters.end(); 186 ++index) { 187 delete *index; 188 } 189 m_converters.clear(); 190 190 } 191 191 … … 194 194 { 195 195 ULONG fFmtInfo; 196 196 return (!!WinQueryClipbrdFmtInfo(CPMUtil::getHAB(), getOwnershipFormat(), &fFmtInfo)); 197 197 } 198 198 … … 200 200 CPMClipboard::getOwnershipFormat() 201 201 { 202 203 202 // create ownership format if we haven't yet 203 if (s_ownershipFormat == 0) { 204 204 ATOM hAtom = WinAddAtom(WinQuerySystemAtomTable(), (PCSZ)"SynergyOwnership"); 205 205 if (hAtom == 0) … … 207 207 assert(hAtom != 0); 208 208 s_ownershipFormat = hAtom; 209 210 211 212 213 } 209 } 210 211 // return the format 212 return s_ownershipFormat; 213 } -
trunk/synergy/lib/platform/CPMClipboard.h
r2752 r2770 3 3 * Copyright (C) 2002 Chris Schoeneman 4 4 * Copyright (C) 2006 Knut St. Osmundsen 5 * 5 * 6 6 * This package is free software; you can redistribute it and/or 7 7 * modify it under the terms of the GNU General Public License 8 8 * found in the file COPYING that should have accompanied this file. 9 * 9 * 10 10 * This package is distributed in the hope that it will be useful, 11 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of … … 29 29 class CPMClipboard : public IClipboard { 30 30 public: 31 32 31 CPMClipboard(HWND window); 32 virtual ~CPMClipboard(); 33 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 boolemptyUnowned();34 //! Empty clipboard without ownership 35 /*! 36 Take ownership of the clipboard and clear all data from it. 37 This must be called between a successful open() and close(). 38 Return false if the clipboard ownership could not be taken; 39 the clipboard should not be emptied in this case. Unlike 40 empty(), isOwnedBySynergy() will return false when emptied 41 this way. This is useful when synergy wants to put data on 42 clipboard but pretend (to itself) that some other app did it. 43 When using empty(), synergy assumes the data came from the 44 server and doesn't need to be sent back. emptyUnowned() 45 makes synergy send the data to the server. 46 */ 47 bool emptyUnowned(); 48 48 49 50 static boolisOwnedBySynergy();49 //! Test if clipboard is owned by synergy 50 static bool isOwnedBySynergy(); 51 51 52 53 virtual boolempty();54 virtual voidadd(EFormat, const CString& data);55 virtual boolopen(Time) const;56 virtual voidclose() const;57 virtual TimegetTime() const;58 virtual boolhas(EFormat) const;59 virtual CStringget(EFormat) const;52 // IClipboard overrides 53 virtual bool empty(); 54 virtual void add(EFormat, const CString& data); 55 virtual bool open(Time) const; 56 virtual void close() const; 57 virtual Time getTime() const; 58 virtual bool has(EFormat) const; 59 virtual CString get(EFormat) const; 60 60 61 61 private: 62 voidclearConverters();62 void clearConverters(); 63 63 64 ULONGconvertFormatToPM(EFormat) const;65 ULONGconvertTextToPM(const CString& data) const;66 CStringconvertTextFromPM(ULONG) const;64 ULONG convertFormatToPM(EFormat) const; 65 ULONG convertTextToPM(const CString& data) const; 66 CString convertTextFromPM(ULONG) const; 67 67 68 static ATOMgetOwnershipFormat();68 static ATOM getOwnershipFormat(); 69 69 70 70 private: 71 71 typedef std::vector<IPMClipboardConverter*> ConverterList; 72 72 73 HWNDm_window;74 mutable Timem_time;75 ConverterListm_converters;76 static ATOMs_ownershipFormat;73 HWND m_window; 74 mutable Time m_time; 75 ConverterList m_converters; 76 static ATOM s_ownershipFormat; 77 77 }; 78 78 … … 84 84 class IPMClipboardConverter : public IInterface { 85 85 public: 86 86 // accessors 87 87 88 89 90 88 // return the clipboard format this object converts from/to 89 virtual IClipboard::EFormat 90 getFormat() const = 0; 91 91 92 93 94 virtual ULONGgetPMFormat() const = 0;92 // return the atom representing the PM clipboard format that 93 // this object converts from/to 94 virtual ULONG getPMFormat() const = 0; 95 95 96 // return the format info flags for the PM clipboard format 97 98 virtual ULONGgetPMFormatInfo() const = 0;96 // return the format info flags for the PM clipboard format 97 // this object converts from/to 98 virtual ULONG getPMFormatInfo() const = 0; 99 99 100 101 102 103 104 virtual ULONGfromIClipboard(const CString&) const = 0;100 // convert from the IClipboard format to the PM clipboard format. 101 // the input data must be in the IClipboard format returned by 102 // getFormat(). the return data will be in the PM clipboard 103 // format returned by getPMFormat(). 104 virtual ULONG fromIClipboard(const CString&) const = 0; 105 105 106 107 virtual voidfreePMData(ULONG) const = 0;106 // free PM clipboard data (failure case). 107 virtual void freePMData(ULONG) const = 0; 108 108 109 110 111 virtual CStringtoIClipboard(ULONG data) const = 0;109 // convert from the win32 clipboard format to the IClipboard format 110 // (i.e., the reverse of fromIClipboard()). 111 virtual CString toIClipboard(ULONG data) const = 0; 112 112 }; 113 113
Note:
See TracChangeset
for help on using the changeset viewer.