Ignore:
Timestamp:
Aug 20, 2006, 8:15:41 AM (19 years ago)
Author:
bird
Message:

I hate tabs.

File:
1 edited

Legend:

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

    r2752 r2770  
    33 * Copyright (C) 2002 Chris Schoeneman
    44 * Copyright (C) 2006 Knut St. Osmundsen
    5  * 
     5 *
    66 * This package is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU General Public License
    88 * found in the file COPYING that should have accompanied this file.
    9  * 
     9 *
    1010 * This package is distributed in the hope that it will be useful,
    1111 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     
    2525//
    2626
    27 ATOM                                    CPMClipboard::s_ownershipFormat = 0;
     27ATOM                    CPMClipboard::s_ownershipFormat = 0;
    2828
    2929CPMClipboard::CPMClipboard(HWND window) :
    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);
     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);
    3737}
    3838
    3939CPMClipboard::~CPMClipboard()
    4040{
    41         clearConverters();
     41    clearConverters();
    4242}
    4343
     
    4545CPMClipboard::emptyUnowned()
    4646{
    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;
     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;
    5656}
    5757
     
    5959CPMClipboard::empty()
    6060{
    61         if (!emptyUnowned()) {
    62                 return false;
    63         }
    64 
    65         // mark clipboard as being owned by synergy
     61    if (!emptyUnowned()) {
     62        return false;
     63    }
     64
     65    // mark clipboard as being owned by synergy
    6666    PVOID pv = NULL;
    6767    APIRET rc = DosAllocSharedMem(&pv, NULL, 1, PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_GETTABLE | OBJ_GIVEABLE);
     
    7070        return false;
    7171    }
    72         return !!WinSetClipbrdData(CPMUtil::getHAB(), (ULONG)pv, getOwnershipFormat(), CFI_POINTER);
     72    return !!WinSetClipbrdData(CPMUtil::getHAB(), (ULONG)pv, getOwnershipFormat(), CFI_POINTER);
    7373}
    7474
     
    7676CPMClipboard::add(EFormat format, const CString& data)
    7777{
    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();
     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();
    9191                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
     92                if (!WinSetClipbrdData(CPMUtil::getHAB(), ulPMData, ulPMFormat, ulPMFormatInfo)) {
     93                    // free converted data if we couldn't put it on the clipboard
    9494                    converter->freePMData(ulPMData);
    95                                 }
    96                         }
    97                 }
    98         }
     95                }
     96            }
     97        }
     98    }
    9999}
    100100
     
    102102CPMClipboard::open(Time time) const
    103103{
    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;
     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;
    114114}
    115115
     
    117117CPMClipboard::close() const
    118118{
    119         LOG((CLOG_DEBUG "close clipboard"));
    120         WinCloseClipbrd(CPMUtil::getHAB());
     119    LOG((CLOG_DEBUG "close clipboard"));
     120    WinCloseClipbrd(CPMUtil::getHAB());
    121121}
    122122
     
    124124CPMClipboard::getTime() const
    125125{
    126         return m_time;
     126    return m_time;
    127127}
    128128
     
    130130CPMClipboard::has(EFormat format) const
    131131{
    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) {
     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) {
    137137            ULONG fFmtInfo;
    138                         if (WinQueryClipbrdFmtInfo(CPMUtil::getHAB(), getOwnershipFormat(), &fFmtInfo)) {
    139                                 return true;
    140                         }
    141                 }
    142         }
    143         return false;
     138            if (WinQueryClipbrdFmtInfo(CPMUtil::getHAB(), getOwnershipFormat(), &fFmtInfo)) {
     139                return true;
     140            }
     141        }
     142    }
     143    return false;
    144144}
    145145
     
    147147CPMClipboard::get(EFormat format) const
    148148{
    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();
     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();
    155155             ++index) {
    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);
     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);
    179179}
    180180
     
    182182CPMClipboard::clearConverters()
    183183{
    184         for (ConverterList::iterator index = m_converters.begin();
    185                 index != m_converters.end();
    186                 ++index) {
    187                 delete *index;
    188         }
    189         m_converters.clear();
     184    for (ConverterList::iterator index = m_converters.begin();
     185        index != m_converters.end();
     186        ++index) {
     187        delete *index;
     188    }
     189    m_converters.clear();
    190190}
    191191
     
    194194{
    195195    ULONG fFmtInfo;
    196         return (!!WinQueryClipbrdFmtInfo(CPMUtil::getHAB(), getOwnershipFormat(), &fFmtInfo));
     196    return (!!WinQueryClipbrdFmtInfo(CPMUtil::getHAB(), getOwnershipFormat(), &fFmtInfo));
    197197}
    198198
     
    200200CPMClipboard::getOwnershipFormat()
    201201{
    202         // create ownership format if we haven't yet
    203         if (s_ownershipFormat == 0) {
     202    // create ownership format if we haven't yet
     203    if (s_ownershipFormat == 0) {
    204204        ATOM hAtom = WinAddAtom(WinQuerySystemAtomTable(), (PCSZ)"SynergyOwnership");
    205205        if (hAtom == 0)
     
    207207        assert(hAtom != 0);
    208208        s_ownershipFormat = hAtom;
    209         }
    210 
    211         // return the format
    212         return s_ownershipFormat;
    213 }
     209    }
     210
     211    // return the format
     212    return s_ownershipFormat;
     213}
Note: See TracChangeset for help on using the changeset viewer.