Ignore:
Timestamp:
Jul 29, 2006, 6:43:07 AM (19 years ago)
Author:
bird
Message:

Two classes (CPMScreen and CPMKeyState) + the hook dll left (and debugging of course).

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/synergy/lib/platform/CPMClipboard.cpp

    r2751 r2752  
    22 * synergy -- mouse and keyboard sharing utility
    33 * Copyright (C) 2002 Chris Schoeneman
     4 * Copyright (C) 2006 Knut St. Osmundsen
    45 *
    56 * This package is free software; you can redistribute it and/or
     
    1314 */
    1415
    15 #include "CMSWindowsClipboard.h"
    16 #include "CMSWindowsClipboardTextConverter.h"
    17 #include "CMSWindowsClipboardUTF16Converter.h"
    18 #include "CMSWindowsClipboardBitmapConverter.h"
    19 #include "CMSWindowsClipboardHTMLConverter.h"
     16#include "CPMClipboard.h"
     17#include "CPMClipboardTextConverter.h"
     18#include "CPMClipboardBitmapConverter.h"
     19#include "CPMClipboardHTMLConverter.h"
     20#include "CPMUtil.h"
    2021#include "CLog.h"
    21 #include "CArchMiscWindows.h"
    2222
    2323//
    24 // CMSWindowsClipboard
     24// CPMClipboard
    2525//
    2626
    27 UINT                                    CMSWindowsClipboard::s_ownershipFormat = 0;
    28 
    29 CMSWindowsClipboard::CMSWindowsClipboard(HWND window) :
     27ATOM                                    CPMClipboard::s_ownershipFormat = 0;
     28
     29CPMClipboard::CPMClipboard(HWND window) :
    3030        m_window(window),
    3131        m_time(0)
    3232{
    3333        // 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
     39CPMClipboard::~CPMClipboard()
    4540{
    4641        clearConverters();
     
    4843
    4944bool
    50 CMSWindowsClipboard::emptyUnowned()
     45CPMClipboard::emptyUnowned()
    5146{
    5247        LOG((CLOG_DEBUG "empty clipboard"));
    5348
    5449        // empty the clipboard (and take ownership)
    55         if (!EmptyClipboard()) {
     50        if (!WinEmptyClipbrd(CPMUtil::getHAB())) {
    5651                LOG((CLOG_DEBUG "failed to grab clipboard"));
    5752                return false;
     
    6257
    6358bool
    64 CMSWindowsClipboard::empty()
     59CPMClipboard::empty()
    6560{
    6661        if (!emptyUnowned()) {
     
    6964
    7065        // 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);
    7573}
    7674
    7775void
    78 CMSWindowsClipboard::add(EFormat format, const CString& data)
     76CPMClipboard::add(EFormat format, const CString& data)
    7977{
    8078        LOG((CLOG_DEBUG "add %d bytes to clipboard format: %d", data.size(), format));
     
    8280        // convert data to win32 form
    8381        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;
    8685
    8786                // skip converters for other formats
    8887                if (converter->getFormat() == format) {
    89                         HANDLE win32Data = converter->fromIClipboard(data);
    90                         if (win32Data != NULL) {
    91                                 UINT win32Format = converter->getWin32Format();
    92                                 if (SetClipboardData(win32Format, win32Data) == NULL) {
    93                                         // free converted data if we couldn't put it on
    94                                         // the clipboard
    95                                         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);
    9695                                }
    9796                        }
     
    101100
    102101bool
    103 CMSWindowsClipboard::open(Time time) const
     102CPMClipboard::open(Time time) const
    104103{
    105104        LOG((CLOG_DEBUG "open clipboard"));
    106105
    107         if (!OpenClipboard(m_window)) {
     106        if (!WinOpenClipbrd(m_window)) {
    108107                LOG((CLOG_WARN "failed to open clipboard"));
    109108                return false;
     
    116115
    117116void
    118 CMSWindowsClipboard::close() const
     117CPMClipboard::close() const
    119118{
    120119        LOG((CLOG_DEBUG "close clipboard"));
    121         CloseClipboard();
     120        WinCloseClipbrd(CPMUtil::getHAB());
    122121}
    123122
    124123IClipboard::Time
    125 CMSWindowsClipboard::getTime() const
     124CPMClipboard::getTime() const
    126125{
    127126        return m_time;
     
    129128
    130129bool
    131 CMSWindowsClipboard::has(EFormat format) const
     130CPMClipboard::has(EFormat format) const
    132131{
    133132        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;
    136136                if (converter->getFormat() == format) {
    137                         if (IsClipboardFormatAvailable(converter->getWin32Format())) {
     137            ULONG fFmtInfo;
     138                        if (WinQueryClipbrdFmtInfo(CPMUtil::getHAB(), getOwnershipFormat(), &fFmtInfo)) {
    138139                                return true;
    139140                        }
     
    144145
    145146CString
    146 CMSWindowsClipboard::get(EFormat format) const
     147CPMClipboard::get(EFormat format) const
    147148{
    148149        // find the converter for the first clipboard format we can handle
    149         IMSWindowsClipboardConverter* converter = NULL;
    150         UINT 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) {
    152153                for (ConverterList::const_iterator index = m_converters.begin();
    153                                                                 index != m_converters.end(); ++index) {
     154                         index != m_converters.end();
     155             ++index) {
    154156                        converter = *index;
    155                         if (converter->getWin32Format() == win32Format &&
    156                                 converter->getFormat()      == format) {
     157                        if (converter->getPMFormat() == pmFormat &&
     158                                converter->getFormat()   == format) {
    157159                                break;
    158160                        }
    159161                        converter = NULL;
    160162                }
    161                 win32Format = EnumClipboardFormats(win32Format);
     163                pmFormat = WinEnumClipbrdFmts(CPMUtil::getHAB(), pmFormat);
    162164        }
    163165
     
    168170
    169171        // 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) {
    172174                return CString();
    173175        }
    174176
    175177        // convert
    176         return converter->toIClipboard(win32Data);
     178        return converter->toIClipboard(ulData);
    177179}
    178180
    179181void
    180 CMSWindowsClipboard::clearConverters()
     182CPMClipboard::clearConverters()
    181183{
    182184        for (ConverterList::iterator index = m_converters.begin();
    183                                                                 index != m_converters.end(); ++index) {
     185                 index != m_converters.end();
     186                 ++index) {
    184187                delete *index;
    185188        }
     
    188191
    189192bool
    190 CMSWindowsClipboard::isOwnedBySynergy()
     193CPMClipboard::isOwnedBySynergy()
     194{
     195    ULONG fFmtInfo;
     196        return (!!WinQueryClipbrdFmtInfo(CPMUtil::getHAB(), getOwnershipFormat(), &fFmtInfo));
     197}
     198
     199ATOM
     200CPMClipboard::getOwnershipFormat()
    191201{
    192202        // create ownership format if we haven't yet
    193203        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;
    205209        }
    206210
Note: See TracChangeset for help on using the changeset viewer.