Changeset 2752


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).

Location:
trunk/synergy
Files:
18 added
5 edited
26 copied

Legend:

Unmodified
Added
Removed
  • trunk/synergy/cmd/synergyc/CPMClientTaskBarReceiver.cpp

    r2751 r2752  
    22 * synergy -- mouse and keyboard sharing utility
    33 * Copyright (C) 2004 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 "COSXClientTaskBarReceiver.h"
     16#include "CPMClientTaskBarReceiver.h"
    1617#include "CArch.h"
    1718
    1819//
    19 // COSXClientTaskBarReceiver
     20// CPMClientTaskBarReceiver
    2021//
    2122
    22 COSXClientTaskBarReceiver::COSXClientTaskBarReceiver(
     23CPMClientTaskBarReceiver::CPMClientTaskBarReceiver(
    2324                                const CBufferedLogOutputter*)
    2425{
     
    2728}
    2829
    29 COSXClientTaskBarReceiver::~COSXClientTaskBarReceiver()
     30CPMClientTaskBarReceiver::~CPMClientTaskBarReceiver()
    3031{
    3132        ARCH->removeReceiver(this);
     
    3334
    3435void
    35 COSXClientTaskBarReceiver::showStatus()
     36CPMClientTaskBarReceiver::showStatus()
    3637{
    3738        // do nothing
     
    3940
    4041void
    41 COSXClientTaskBarReceiver::runMenu(int, int)
     42CPMClientTaskBarReceiver::runMenu(int, int)
    4243{
    4344        // do nothing
     
    4546
    4647void
    47 COSXClientTaskBarReceiver::primaryAction()
     48CPMClientTaskBarReceiver::primaryAction()
    4849{
    4950        // do nothing
     
    5152
    5253const IArchTaskBarReceiver::Icon
    53 COSXClientTaskBarReceiver::getIcon() const
     54CPMClientTaskBarReceiver::getIcon() const
    5455{
    5556        return NULL;
    5657}
     58
  • trunk/synergy/cmd/synergyc/CPMClientTaskBarReceiver.h

    r2751 r2752  
    22 * synergy -- mouse and keyboard sharing utility
    33 * Copyright (C) 2004 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 #ifndef COSXCLIENTTASKBARRECEIVER_H
    16 #define COSXCLIENTTASKBARRECEIVER_H
     16#ifndef CPMCLIENTTASKBARRECEIVER_H
     17#define CPMCLIENTTASKBARRECEIVER_H
    1718
    1819#include "CClientTaskBarReceiver.h"
     
    2021class CBufferedLogOutputter;
    2122
    22 //! Implementation of CClientTaskBarReceiver for OS X
    23 class COSXClientTaskBarReceiver : public CClientTaskBarReceiver {
     23//! Implementation of CClientTaskBarReceiver for PM
     24class CPMClientTaskBarReceiver : public CClientTaskBarReceiver {
    2425public:
    25         COSXClientTaskBarReceiver(const CBufferedLogOutputter*);
    26         virtual ~COSXClientTaskBarReceiver();
     26        CPMClientTaskBarReceiver(const CBufferedLogOutputter*);
     27        virtual ~CPMClientTaskBarReceiver();
    2728
    2829        // IArchTaskBarReceiver overrides
     
    3435
    3536#endif
     37
  • trunk/synergy/cmd/synergyc/synergyc.cpp

    r2749 r2752  
    4949#include "COSXScreen.h"
    5050#include "COSXClientTaskBarReceiver.h"
     51#elif WINAPI_PM
     52#include "CPMScreen.h"
     53#include "CPMClientTaskBarReceiver.h"
    5154#endif
    5255
     
    110113#elif WINAPI_CARBON
    111114        return new CScreen(new COSXScreen(false));
     115#elif WINAPI_PM
     116        return new CScreen(new CPMScreen(false));
    112117#endif
    113118}
     
    124129#elif WINAPI_CARBON
    125130        return new COSXClientTaskBarReceiver(logBuffer);
     131#elif WINAPI_PM
     132        return new CPMClientTaskBarReceiver(logBuffer);
    126133#endif
    127134}
  • trunk/synergy/cmd/synergys/CPMServerTaskBarReceiver.cpp

    r2751 r2752  
    22 * synergy -- mouse and keyboard sharing utility
    33 * Copyright (C) 2004 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 "COSXServerTaskBarReceiver.h"
     16#include "CPMServerTaskBarReceiver.h"
    1617#include "CArch.h"
    1718
    1819//
    19 // COSXServerTaskBarReceiver
     20// CPMServerTaskBarReceiver
    2021//
    2122
    22 COSXServerTaskBarReceiver::COSXServerTaskBarReceiver(
     23CPMServerTaskBarReceiver::CPMServerTaskBarReceiver(
    2324                                const CBufferedLogOutputter*)
    2425{
     
    2728}
    2829
    29 COSXServerTaskBarReceiver::~COSXServerTaskBarReceiver()
     30CPMServerTaskBarReceiver::~CPMServerTaskBarReceiver()
    3031{
    3132        ARCH->removeReceiver(this);
     
    3334
    3435void
    35 COSXServerTaskBarReceiver::showStatus()
     36CPMServerTaskBarReceiver::showStatus()
    3637{
    3738        // do nothing
     
    3940
    4041void
    41 COSXServerTaskBarReceiver::runMenu(int, int)
     42CPMServerTaskBarReceiver::runMenu(int, int)
    4243{
    4344        // do nothing
     
    4546
    4647void
    47 COSXServerTaskBarReceiver::primaryAction()
     48CPMServerTaskBarReceiver::primaryAction()
    4849{
    4950        // do nothing
     
    5152
    5253const IArchTaskBarReceiver::Icon
    53 COSXServerTaskBarReceiver::getIcon() const
     54CPMServerTaskBarReceiver::getIcon() const
    5455{
    5556        return NULL;
  • trunk/synergy/cmd/synergys/CPMServerTaskBarReceiver.h

    r2751 r2752  
    22 * synergy -- mouse and keyboard sharing utility
    33 * Copyright (C) 2004 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 #ifndef COSXSERVERTASKBARRECEIVER_H
    16 #define COSXSERVERTASKBARRECEIVER_H
     16#ifndef CPMSERVERTASKBARRECEIVER_H
     17#define CPMSERVERTASKBARRECEIVER_H
    1718
    1819#include "CServerTaskBarReceiver.h"
     
    2021class CBufferedLogOutputter;
    2122
    22 //! Implementation of CServerTaskBarReceiver for OS X
    23 class COSXServerTaskBarReceiver : public CServerTaskBarReceiver {
     23//! Implementation of CServerTaskBarReceiver for PM
     24class CPMServerTaskBarReceiver : public CServerTaskBarReceiver {
    2425public:
    25         COSXServerTaskBarReceiver(const CBufferedLogOutputter*);
    26         virtual ~COSXServerTaskBarReceiver();
     26        CPMServerTaskBarReceiver(const CBufferedLogOutputter*);
     27        virtual ~CPMServerTaskBarReceiver();
    2728
    2829        // IArchTaskBarReceiver overrides
  • trunk/synergy/cmd/synergys/synergys.cpp

    r2749 r2752  
    5252#include "COSXScreen.h"
    5353#include "COSXServerTaskBarReceiver.h"
     54#elif WINAPI_PM
     55#include "CPMScreen.h"
     56#include "CPMServerTaskBarReceiver.h"
    5457#endif
    5558
     
    127130#elif WINAPI_CARBON
    128131        return new CScreen(new COSXScreen(true));
     132#elif WINAPI_PM
     133        return new CScreen(new CPMScreen(true));
    129134#endif
    130135}
     
    141146#elif WINAPI_CARBON
    142147        return new COSXServerTaskBarReceiver(logBuffer);
     148#elif WINAPI_PM
     149        return new CPMServerTaskBarReceiver(logBuffer);
    143150#endif
    144151}
  • trunk/synergy/lib/arch/CArch.cpp

    r2749 r2752  
    4444#elif SYSAPI_UNIX
    4545#       include "CArchConsoleUnix.h"
    46 #       include "CArchDaemonUnix.h"
     46#   ifdef __OS2__
     47#               include "CArchDaemonNone.h"
     48#       else
     49#               include "CArchDaemonUnix.h"
     50#       endif
    4751#       include "CArchFileUnix.h"
    4852#       include "CArchLogUnix.h"
     
    5458#       include "CArchStringUnix.h"
    5559#       include "CArchSystemUnix.h"
    56 #       include "CArchTaskBarXWindows.h"
     60#   ifdef __OS2__ /// @todo isn't this really WINAPI?
     61#               include "CArchTaskBarOS2.h"
     62#       else
     63#               include "CArchTaskBarXWindows.h"
     64#       endif
    5765#       include "CArchTimeUnix.h"
    5866#endif
  • trunk/synergy/lib/arch/CArchMultithreadPosix.h

    r2749 r2752  
    1515#ifndef CARCHMULTITHREADPOSIX_H
    1616#define CARCHMULTITHREADPOSIX_H
     17
     18#ifdef __OS2__
     19
     20#include "CArchMultithreadOS2.h"
     21
     22#else /* !__OS2__ */
    1723
    1824#include "IArchMultithread.h"
     
    111117};
    112118
     119#endif /* !__OS2__ */
    113120#endif
  • trunk/synergy/lib/common/common.h

    r2749 r2752  
    8585#               define X_DISPLAY_MISSING 1
    8686#       endif
     87
     88#       if defined(__OS2__)
     89#               define SYSAPI_UNIX 1
     90#               define WINAPI_PM 1
     91
     92#               define HAVE_CXX_BOOL 1
     93#               define HAVE_CXX_CASTS 1
     94#               define HAVE_CXX_EXCEPTIONS 1
     95#               define HAVE_CXX_MUTABLE 1
     96#               define HAVE_CXX_STDLIB 1
     97//#             define HAVE_GETPWUID_R 1
     98#               define HAVE_GMTIME_R 1
     99#               define HAVE_INET_ATON 1
     100#               define HAVE_INTTYPES_H 1
     101#               define HAVE_ISTREAM 1
     102#               define HAVE_MEMORY_H 1
     103#               define HAVE_NANOSLEEP 1
     104#               define HAVE_OSTREAM 1
     105#               define HAVE_POSIX_SIGWAIT 1
     106// we don't have pthreads, but we use the same header to reduce changes.
     107#               define HAVE_PTHREAD 1
     108//#             define HAVE_PTHREAD_SIGNAL 1
     109#               include <sys/types.h>
     110#               include <sys/socket.h>
     111//#             if defined(_SOCKLEN_T)
     112//#                     define HAVE_SOCKLEN_T 1
     113//#             endif
     114#               define HAVE_SSTREAM 1
     115#               define HAVE_STDINT_H 1
     116#               define HAVE_STDLIB_H 1
     117#               define HAVE_STRINGS_H 1
     118#               define HAVE_STRING_H 1
     119#               define HAVE_SYS_SELECT_H 1
     120#               define HAVE_SYS_SOCKET_H 1
     121#               define HAVE_SYS_STAT_H 1
     122#               define HAVE_SYS_TIME_H 1
     123#               define HAVE_SYS_TYPES_H 1
     124#               define HAVE_SYS_UTSNAME_H 1
     125#               define HAVE_UNISTD_H 1
     126#               define HAVE_VSNPRINTF 1
     127#               define HAVE_WCHAR_H 1
     128#               define HAVE_LOCALE_H 1
     129
     130#               define SELECT_TYPE_ARG1 int
     131#               define SELECT_TYPE_ARG234 (fd_set *)
     132#               define SELECT_TYPE_ARG5 (struct timeval *)
     133#               define SIZEOF_CHAR 1
     134#               define SIZEOF_INT 4
     135#               define SIZEOF_LONG 4
     136#               define SIZEOF_SHORT 2
     137#               define STDC_HEADERS 1
     138#               define TIME_WITH_SYS_TIME 1
     139#               define X_DISPLAY_MISSING 1
     140#       endif /* __OS2__ */
    87141#endif
    88142
  • 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
  • trunk/synergy/lib/platform/CPMClipboard.h

    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 #ifndef CMSWINDOWSCLIPBOARD_H
    16 #define CMSWINDOWSCLIPBOARD_H
     16#ifndef CPMCLIPBOARD_H
     17#define CPMCLIPBOARD_H
    1718
    1819#include "IClipboard.h"
    1920#include "stdvector.h"
    20 #define WIN32_LEAN_AND_MEAN
    21 #include <windows.h>
     21#define INCL_ERRORS
     22#define INCL_BASE
     23#define INCL_PM
     24#include <os2.h>
    2225
    23 class IMSWindowsClipboardConverter;
     26class IPMClipboardConverter;
    2427
    2528//! Microsoft windows clipboard implementation
    26 class CMSWindowsClipboard : public IClipboard {
     29class CPMClipboard : public IClipboard {
    2730public:
    28         CMSWindowsClipboard(HWND window);
    29         virtual ~CMSWindowsClipboard();
     31        CPMClipboard(HWND window);
     32        virtual ~CPMClipboard();
    3033
    3134        //! Empty clipboard without ownership
     
    5962        void                            clearConverters();
    6063
    61         UINT                            convertFormatToWin32(EFormat) const;
    62         HANDLE                          convertTextToWin32(const CString& data) const;
    63         CString                         convertTextFromWin32(HANDLE) const;
     64        ULONG                           convertFormatToPM(EFormat) const;
     65        ULONG                           convertTextToPM(const CString& data) const;
     66        CString                         convertTextFromPM(ULONG) const;
    6467
    65         static UINT                     getOwnershipFormat();
     68        static ATOM                     getOwnershipFormat();
    6669
    6770private:
    68         typedef std::vector<IMSWindowsClipboardConverter*> ConverterList;
     71        typedef std::vector<IPMClipboardConverter*> ConverterList;
    6972
    7073        HWND                            m_window;
    7174        mutable Time            m_time;
    7275        ConverterList           m_converters;
    73         static UINT                     s_ownershipFormat;
     76        static ATOM                     s_ownershipFormat;
    7477};
    7578
     
    7982converters.
    8083*/
    81 class IMSWindowsClipboardConverter : public IInterface {
     84class IPMClipboardConverter : public IInterface {
    8285public:
    8386        // accessors
     
    8790                                                getFormat() const = 0;
    8891
    89         // return the atom representing the win32 clipboard format that
     92        // return the atom representing the PM clipboard format that
    9093        // this object converts from/to
    91         virtual UINT            getWin32Format() const = 0;
     94        virtual ULONG           getPMFormat() const = 0;
    9295
    93         // convert from the IClipboard format to the win32 clipboard format.
     96        // return the format info flags for the PM clipboard format
     97        // this object converts from/to
     98        virtual ULONG           getPMFormatInfo() const = 0;
     99
     100        // convert from the IClipboard format to the PM clipboard format.
    94101        // 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;
     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
     106        // free PM clipboard data (failure case).
     107        virtual void            freePMData(ULONG) const = 0;
    98108
    99109        // convert from the win32 clipboard format to the IClipboard format
    100110        // (i.e., the reverse of fromIClipboard()).
    101         virtual CString         toIClipboard(HANDLE data) const = 0;
     111        virtual CString         toIClipboard(ULONG data) const = 0;
    102112};
    103113
  • trunk/synergy/lib/platform/CPMClipboardAnyTextConverter.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 "CMSWindowsClipboardAnyTextConverter.h"
     16#include "CPMClipboardAnyTextConverter.h"
    1617
    1718//
    18 // CMSWindowsClipboardAnyTextConverter
     19// CPMClipboardAnyTextConverter
    1920//
    2021
    21 CMSWindowsClipboardAnyTextConverter::CMSWindowsClipboardAnyTextConverter()
     22CPMClipboardAnyTextConverter::CPMClipboardAnyTextConverter()
    2223{
    2324        // do nothing
    2425}
    2526
    26 CMSWindowsClipboardAnyTextConverter::~CMSWindowsClipboardAnyTextConverter()
     27CPMClipboardAnyTextConverter::~CPMClipboardAnyTextConverter()
    2728{
    2829        // do nothing
     
    3031
    3132IClipboard::EFormat
    32 CMSWindowsClipboardAnyTextConverter::getFormat() const
     33CPMClipboardAnyTextConverter::getFormat() const
    3334{
    3435        return IClipboard::kText;
    3536}
     37ULONG
     38CPMClipboardAnyTextConverter::getPMFormatInfo() const
     39{
     40    return CFI_POINTER;
     41}
    3642
    37 HANDLE
    38 CMSWindowsClipboardAnyTextConverter::fromIClipboard(const CString& data) const
     43ULONG
     44CPMClipboardAnyTextConverter::fromIClipboard(const CString& data) const
    3945{
    4046        // convert linefeeds and then convert to desired encoding
    41         CString text = doFromIClipboard(convertLinefeedToWin32(data));
    42         UInt32 size = text.size();
     47        CString text = doFromIClipboard(convertLinefeedToPM(data));
     48        UInt32 cb = text.size();
    4349
    4450        // copy to memory handle
    45         HGLOBAL gData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, size);
    46         if (gData != NULL) {
    47                 // get a pointer to the allocated memory
    48                 char* dst = (char*)GlobalLock(gData);
    49                 if (dst != NULL) {
    50                         memcpy(dst, text.data(), size);
    51                         GlobalUnlock(gData);
    52                 }
    53                 else {
    54                         GlobalFree(gData);
    55                         gData = NULL;
    56                 }
    57         }
     51    PVOID pv = NULL;
     52    APIRET rc = DosAllocSharedMem(&pv, NULL, cb, PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_GETTABLE | OBJ_GIVEABLE);
     53    if (rc == NO_ERROR) {
     54        return (ULONG)memcpy(pv, text.data(), cb);
     55    }
     56    return 0;
     57}
    5858
    59         return gData;
     59void
     60CPMClipboardAnyTextConverter::freePMData(ULONG ulPMData) const
     61{
     62    DosFreeMem((PVOID)ulPMData);
    6063}
    6164
    6265CString
    63 CMSWindowsClipboardAnyTextConverter::toIClipboard(HANDLE data) const
     66CPMClipboardAnyTextConverter::toIClipboard(ULONG data) const
    6467{
    65         // get datator
    66         const char* src = (const char*)GlobalLock(data);
    67         UInt32 srcSize = (UInt32)GlobalSize(data);
    68         if (src == NULL || srcSize <= 1) {
    69                 return CString();
    70         }
    71 
    7268        // convert text
    73         CString text = doToIClipboard(CString(src, srcSize));
    74 
    75         // release handle
    76         GlobalUnlock(data);
     69    const char *psz = (const char *)data;
     70        CString text = doToIClipboard(CString(psz));
    7771
    7872        // convert newlines
     
    8175
    8276CString
    83 CMSWindowsClipboardAnyTextConverter::convertLinefeedToWin32(
    84                                 const CString& src) const
     77CPMClipboardAnyTextConverter::convertLinefeedToPM(const CString& src) const
    8578{
    8679        // note -- we assume src is a valid UTF-8 string
     
    115108
    116109CString
    117 CMSWindowsClipboardAnyTextConverter::convertLinefeedToUnix(
    118                                 const CString& src) const
     110CPMClipboardAnyTextConverter::convertLinefeedToUnix(const CString& src) const
    119111{
    120112        // count newlines in string
  • trunk/synergy/lib/platform/CPMClipboardAnyTextConverter.h

    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 #ifndef CMSWINDOWSCLIPBOARDANYTEXTCONVERTER_H
    16 #define CMSWINDOWSCLIPBOARDANYTEXTCONVERTER_H
     16#ifndef CPMCLIPBOARDANYTEXTCONVERTER_H
     17#define CPMCLIPBOARDANYTEXTCONVERTER_H
    1718
    18 #include "CMSWindowsClipboard.h"
     19#include "CPMClipboard.h"
    1920
    2021//! Convert to/from some text encoding
    21 class CMSWindowsClipboardAnyTextConverter :
    22                                 public IMSWindowsClipboardConverter {
     22class CPMClipboardAnyTextConverter :
     23                                public IPMClipboardConverter {
    2324public:
    24         CMSWindowsClipboardAnyTextConverter();
    25         virtual ~CMSWindowsClipboardAnyTextConverter();
     25        CPMClipboardAnyTextConverter();
     26        virtual ~CPMClipboardAnyTextConverter();
    2627
    27         // IMSWindowsClipboardConverter overrides
     28        // IPMClipboardConverter overrides
    2829        virtual IClipboard::EFormat
    2930                                                getFormat() const;
    30         virtual UINT            getWin32Format() const = 0;
    31         virtual HANDLE          fromIClipboard(const CString&) const;
    32         virtual CString         toIClipboard(HANDLE) const;
     31        virtual ULONG           getPMFormat() const = 0;
     32        virtual ULONG           getPMFormatInfo() const;
     33        virtual ULONG           fromIClipboard(const CString&) const;
     34        virtual void            freePMData(ULONG) const;
     35        virtual CString         toIClipboard(ULONG) const;
    3336
    3437protected:
     
    5053
    5154private:
    52         CString                         convertLinefeedToWin32(const CString&) const;
     55        CString                         convertLinefeedToPM(const CString&) const;
    5356        CString                         convertLinefeedToUnix(const CString&) const;
    5457};
  • trunk/synergy/lib/platform/CPMClipboardBitmapConverter.cpp

    r2751 r2752  
    22 * synergy -- mouse and keyboard sharing utility
    33 * Copyright (C) 2004 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 "CMSWindowsClipboardBitmapConverter.h"
     16#include "CPMClipboardBitmapConverter.h"
    1617#include "CLog.h"
    1718
    1819//
    19 // CMSWindowsClipboardBitmapConverter
     20// CPMClipboardBitmapConverter
    2021//
    2122
    22 CMSWindowsClipboardBitmapConverter::CMSWindowsClipboardBitmapConverter()
     23CPMClipboardBitmapConverter::CPMClipboardBitmapConverter()
    2324{
    2425        // do nothing
    2526}
    2627
    27 CMSWindowsClipboardBitmapConverter::~CMSWindowsClipboardBitmapConverter()
     28CPMClipboardBitmapConverter::~CPMClipboardBitmapConverter()
    2829{
    2930        // do nothing
     
    3132
    3233IClipboard::EFormat
    33 CMSWindowsClipboardBitmapConverter::getFormat() const
     34CPMClipboardBitmapConverter::getFormat() const
    3435{
    3536        return IClipboard::kBitmap;
    3637}
    3738
    38 UINT
    39 CMSWindowsClipboardBitmapConverter::getWin32Format() const
     39ULONG
     40CPMClipboardBitmapConverter::getPMFormat() const
    4041{
    41         return CF_DIB;
     42        return CF_BITMAP;
    4243}
    4344
    44 HANDLE
    45 CMSWindowsClipboardBitmapConverter::fromIClipboard(const CString& data) const
     45ULONG
     46CPMClipboardBitmapConverter::getPMFormatInfo() const
    4647{
    47         // copy to memory handle
    48         HGLOBAL gData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, data.size());
    49         if (gData != NULL) {
    50                 // get a pointer to the allocated memory
    51                 char* dst = (char*)GlobalLock(gData);
    52                 if (dst != NULL) {
    53                         memcpy(dst, data.data(), data.size());
    54                         GlobalUnlock(gData);
    55                 }
    56                 else {
    57                         GlobalFree(gData);
    58                         gData = NULL;
    59                 }
    60         }
     48        return CFI_HANDLE;
     49}
    6150
    62         return gData;
     51ULONG
     52CPMClipboardBitmapConverter::fromIClipboard(const CString& data) const
     53{
     54    /*
     55     * We're getting a windows DIB, create a PM bitmap from that.
     56     */
     57    /** @todo implement me */
     58    return 0;
    6359}
    6460
    6561CString
    66 CMSWindowsClipboardBitmapConverter::toIClipboard(HANDLE data) const
     62CPMClipboardBitmapConverter::toIClipboard(ULONG data) const
    6763{
     64#if 1
     65    /** @todo implement me */
     66    return CString();
     67#else
     68    HBITMAP hbmp = (HBITMAP)data;
     69
     70    BITMAPINFOHEADER2 BmpHdr;
     71
     72    ULONG        cbFix;
     73    ULONG        cx;
     74    ULONG        cy;
     75    USHORT cPlanes;
     76    USHORT cBitCount;
     77    ULONG        ulCompression;
     78    ULONG        cbImage;
     79    ULONG        cxResolution;
     80    ULONG        cyResolution;
     81    ULONG        cclrUsed;
     82    ULONG        cclrImportant;
     83    USHORT usUnits;
     84    USHORT usReserved;
     85    USHORT usRecording;
     86    USHORT usRendering;
     87    ULONG        cSize1;
     88    ULONG        cSize2;
     89    ULONG        ulColorEncoding;
     90    ULONG        ulIdentifier;
     91
     92    if (GpiQueryBitmapInfoHeader(hbmp, &BmpHdr)) {
     93        LOG((CLOG_INFO "bitmap: %dx%d %d", bmpData.biWidth, bitmap->bmiHeader.biHeight, (int)bitmap->bmiHeader.biBitCount));
     94        if (    BmpHdr.cPlanes == 1
     95            &&  (BmpHdr.cBitsCount == 32 || BmpHdr.cBitsCount == 24 /*???*/)
     96            &&   BmpHdr.ulCompression == ) {
     97            // already in canonical form
     98            char *abImage = new char[BmpHdr.cbImage];
     99            /* fun stuff starts here. */
     100            //if (GipQueryBitmapBits() {
     101            }
     102            CString image(abImage, srcSize);
     103            delete abImage;
     104            return image;
     105        }
     106       
     107    }
     108    return CString();
     109
    68110        // get datator
    69111        const char* src = (const char*)GlobalLock(data);
     
    113155                        (bitmap->bmiHeader.biBitCount == 16 ||
    114156                        bitmap->bmiHeader.biBitCount == 32)) {
    115                         srcBits += 3 * sizeof(DWORD);
     157                        srcBits += 3 * sizeof(ULONG);
    116158                }
    117159        }
     
    144186
    145187        return image;
     188#endif
    146189}
     190
  • trunk/synergy/lib/platform/CPMClipboardBitmapConverter.h

    r2751 r2752  
    22 * synergy -- mouse and keyboard sharing utility
    33 * Copyright (C) 2004 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 #ifndef CMSWINDOWSCLIPBOARDBITMAPCONVERTER_H
    16 #define CMSWINDOWSCLIPBOARDBITMAPCONVERTER_H
     16#ifndef CPMCLIPBOARDBITMAPCONVERTER_H
     17#define CPMCLIPBOARDBITMAPCONVERTER_H
    1718
    18 #include "CMSWindowsClipboard.h"
     19#include "CPMClipboard.h"
    1920
    2021//! Convert to/from some text encoding
    21 class CMSWindowsClipboardBitmapConverter :
    22                                 public IMSWindowsClipboardConverter {
     22class CPMClipboardBitmapConverter :
     23                                public IPMClipboardConverter {
    2324public:
    24         CMSWindowsClipboardBitmapConverter();
    25         virtual ~CMSWindowsClipboardBitmapConverter();
     25        CPMClipboardBitmapConverter();
     26        virtual ~CPMClipboardBitmapConverter();
    2627
    27         // IMSWindowsClipboardConverter overrides
     28        // IPMClipboardConverter overrides
    2829        virtual IClipboard::EFormat
    2930                                                getFormat() const;
    30         virtual UINT            getWin32Format() const;
    31         virtual HANDLE          fromIClipboard(const CString&) const;
    32         virtual CString         toIClipboard(HANDLE) const;
     31        virtual ULONG           getPMFormat() const;
     32        virtual ULONG           getPMFormatInfo() const;
     33        virtual ULONG           fromIClipboard(const CString&) const;
     34        virtual void            freePMData(ULONG) const;
     35        virtual CString         toIClipboard(ULONG) const;
    3336};
    3437
  • trunk/synergy/lib/platform/CPMClipboardHTMLConverter.cpp

    r2751 r2752  
    22 * synergy -- mouse and keyboard sharing utility
    33 * Copyright (C) 2004 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 "CMSWindowsClipboardHTMLConverter.h"
     16#include "CPMClipboardHTMLConverter.h"
    1617#include "CStringUtil.h"
    1718
    1819//
    19 // CMSWindowsClipboardHTMLConverter
     20// CPMClipboardHTMLConverter
    2021//
    2122
    22 CMSWindowsClipboardHTMLConverter::CMSWindowsClipboardHTMLConverter()
     23CPMClipboardHTMLConverter::CPMClipboardHTMLConverter()
    2324{
    24         m_format = RegisterClipboardFormat("HTML Format");
     25        m_format = WinAddAtom(WinQuerySystemAtomTable(), (PCSZ)"HTML Format");
     26    if (!m_format) {
     27        m_format = WinFindAtom(WinQuerySystemAtomTable(), (PCSZ)"HTML Format");
     28        assert(m_format);
     29    }
    2530}
    2631
    27 CMSWindowsClipboardHTMLConverter::~CMSWindowsClipboardHTMLConverter()
     32CPMClipboardHTMLConverter::~CPMClipboardHTMLConverter()
    2833{
    2934        // do nothing
     
    3136
    3237IClipboard::EFormat
    33 CMSWindowsClipboardHTMLConverter::getFormat() const
     38CPMClipboardHTMLConverter::getFormat() const
    3439{
    3540        return IClipboard::kHTML;
    3641}
    3742
    38 UINT
    39 CMSWindowsClipboardHTMLConverter::getWin32Format() const
     43ULONG
     44CPMClipboardHTMLConverter::getPMFormat() const
    4045{
    4146        return m_format;
     
    4348
    4449CString
    45 CMSWindowsClipboardHTMLConverter::doFromIClipboard(const CString& data) const
     50CPMClipboardHTMLConverter::doFromIClipboard(const CString& data) const
    4651{
    4752        // prepare to CF_HTML format prefix and suffix
     
    6469
    6570CString
    66 CMSWindowsClipboardHTMLConverter::doToIClipboard(const CString& data) const
     71CPMClipboardHTMLConverter::doToIClipboard(const CString& data) const
    6772{
    6873        // get fragment start/end args
     
    8590
    8691CString
    87 CMSWindowsClipboardHTMLConverter::findArg(
     92CPMClipboardHTMLConverter::findArg(
    8893                                const CString& data, const CString& name) const
    8994{
  • trunk/synergy/lib/platform/CPMClipboardHTMLConverter.h

    r2751 r2752  
    22 * synergy -- mouse and keyboard sharing utility
    33 * Copyright (C) 2004 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 #ifndef CMSWINDOWSCLIPBOARDHTMLCONVERTER_H
    16 #define CMSWINDOWSCLIPBOARDHTMLCONVERTER_H
     16#ifndef CPMCLIPBOARDHTMLCONVERTER_H
     17#define CPMCLIPBOARDHTMLCONVERTER_H
    1718
    18 #include "CMSWindowsClipboardAnyTextConverter.h"
     19#include "CPMClipboardAnyTextConverter.h"
    1920
    2021//! Convert to/from HTML encoding
    21 class CMSWindowsClipboardHTMLConverter :
    22                                 public CMSWindowsClipboardAnyTextConverter {
     22class CPMClipboardHTMLConverter :
     23                                public CPMClipboardAnyTextConverter {
    2324public:
    24         CMSWindowsClipboardHTMLConverter();
    25         virtual ~CMSWindowsClipboardHTMLConverter();
     25        CPMClipboardHTMLConverter();
     26        virtual ~CPMClipboardHTMLConverter();
    2627
    27         // IMSWindowsClipboardConverter overrides
    28         virtual IClipboard::EFormat
    29                                                 getFormat() const;
    30         virtual UINT            getWin32Format() const;
     28        // IPMClipboardConverter overrides
     29        virtual IClipboard::EFormat getFormat() const;
     30        virtual ULONG           getPMFormat() const;
    3131
    3232protected:
    33         // CMSWindowsClipboardAnyTextConverter overrides
     33        // CPMClipboardAnyTextConverter overrides
    3434        virtual CString         doFromIClipboard(const CString&) const;
    3535        virtual CString         doToIClipboard(const CString&) const;
     
    3939
    4040private:
    41         UINT                            m_format;
     41        ATOM                            m_format;
    4242};
    4343
  • trunk/synergy/lib/platform/CPMClipboardTextConverter.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 "CMSWindowsClipboardTextConverter.h"
     16#include "CPMClipboardTextConverter.h"
    1617#include "CUnicode.h"
    1718
    1819//
    19 // CMSWindowsClipboardTextConverter
     20// CPMClipboardTextConverter
    2021//
    2122
    22 CMSWindowsClipboardTextConverter::CMSWindowsClipboardTextConverter()
     23CPMClipboardTextConverter::CPMClipboardTextConverter()
    2324{
    2425        // do nothing
    2526}
    2627
    27 CMSWindowsClipboardTextConverter::~CMSWindowsClipboardTextConverter()
     28CPMClipboardTextConverter::~CPMClipboardTextConverter()
    2829{
    2930        // do nothing
    3031}
    3132
    32 UINT
    33 CMSWindowsClipboardTextConverter::getWin32Format() const
     33ULONG
     34CPMClipboardTextConverter::getPMFormat() const
    3435{
    3536        return CF_TEXT;
     
    3738
    3839CString
    39 CMSWindowsClipboardTextConverter::doFromIClipboard(const CString& data) const
     40CPMClipboardTextConverter::doFromIClipboard(const CString& data) const
    4041{
    4142        // convert and add nul terminator
     
    4445
    4546CString
    46 CMSWindowsClipboardTextConverter::doToIClipboard(const CString& data) const
     47CPMClipboardTextConverter::doToIClipboard(const CString& data) const
    4748{
    4849        // convert and truncate at first nul terminator
  • trunk/synergy/lib/platform/CPMClipboardTextConverter.h

    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 #ifndef CMSWINDOWSCLIPBOARDTEXTCONVERTER_H
    16 #define CMSWINDOWSCLIPBOARDTEXTCONVERTER_H
     16#ifndef CPMCLIPBOARDTEXTCONVERTER_H
     17#define CPMCLIPBOARDTEXTCONVERTER_H
    1718
    18 #include "CMSWindowsClipboardAnyTextConverter.h"
     19#include "CPMClipboardAnyTextConverter.h"
    1920
    2021//! Convert to/from locale text encoding
    21 class CMSWindowsClipboardTextConverter :
    22                                 public CMSWindowsClipboardAnyTextConverter {
     22class CPMClipboardTextConverter :
     23                                public CPMClipboardAnyTextConverter {
    2324public:
    24         CMSWindowsClipboardTextConverter();
    25         virtual ~CMSWindowsClipboardTextConverter();
     25        CPMClipboardTextConverter();
     26        virtual ~CPMClipboardTextConverter();
    2627
    27         // IMSWindowsClipboardConverter overrides
    28         virtual UINT            getWin32Format() const;
     28        // IPMClipboardConverter overrides
     29        virtual ULONG           getPMFormat() const;
    2930
    3031protected:
    31         // CMSWindowsClipboardAnyTextConverter overrides
     32        // CPMClipboardAnyTextConverter overrides
    3233        virtual CString         doFromIClipboard(const CString&) const;
    3334        virtual CString         doToIClipboard(const CString&) const;
  • trunk/synergy/lib/platform/CPMEventQueueBuffer.cpp

    r2751 r2752  
    22 * synergy -- mouse and keyboard sharing utility
    33 * Copyright (C) 2004 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 "CMSWindowsEventQueueBuffer.h"
     16#include "CPMEventQueueBuffer.h"
    1617#include "CThread.h"
    1718#include "IEventQueue.h"
    18 #include "CArchMiscWindows.h"
    1919
    2020//
     
    2626
    2727//
    28 // CMSWindowsEventQueueBuffer
     28// CPMEventQueueBuffer
    2929//
    3030
    31 CMSWindowsEventQueueBuffer::CMSWindowsEventQueueBuffer()
     31CPMEventQueueBuffer::CPMEventQueueBuffer()
    3232{
    33         // remember thread.  we'll be posting messages to it.
    34         m_thread     = GetCurrentThreadId();
     33        // remember the queue (/ thread / hab).  we'll be posting messages to it.
     34    m_hab = WinInitialize(0);
     35    m_hmq = WinCreateMsgQueue(m_hab, 0);
     36    assert(m_hmq != NULLHANDLE);
    3537
    3638        // create a message type for custom events
    37         m_userEvent  = RegisterWindowMessage("SYNERGY_USER_EVENT");
     39        m_userEvent  = WM_USER + 42 + 42 + 42;
    3840
    3941        // get message type for daemon quit
    40         m_daemonQuit = CArchMiscWindows::getDaemonQuitMessage();
     42        m_daemonQuit = WM_USER + 666;
    4143
    42         // make sure this thread has a message queue
    43         MSG dummy;
    44         PeekMessage(&dummy, NULL, WM_USER, WM_USER, PM_NOREMOVE);
     44    // create the event semaphore we'll be waiting on when waiting for messages.
     45    m_hev = NULLHANDLE;
     46    APIRET rc = DosCreateEventSem(NULL, &m_hev, 0, FALSE);
     47    assert(rc == NO_ERROR);
    4548}
    4649
    47 CMSWindowsEventQueueBuffer::~CMSWindowsEventQueueBuffer()
     50CPMEventQueueBuffer::~CPMEventQueueBuffer()
    4851{
    4952        // do nothing
     53    DosCloseEventSem(m_hev);
     54    WinDestroyMsgQueue(m_hmq);
     55    WinTerminate(m_hab);
    5056}
    5157
    5258void
    53 CMSWindowsEventQueueBuffer::waitForEvent(double timeout)
     59CPMEventQueueBuffer::waitForEvent(double timeout)
    5460{
    55         // check if messages are available first.  if we don't do this then
    56         // MsgWaitForMultipleObjects() will block even if the queue isn't
    57         // empty if the messages in the queue were there before the last
    58         // call to GetMessage()/PeekMessage().
    59         if (HIWORD(GetQueueStatus(QS_ALLINPUT)) != 0) {
    60                 return;
    61         }
    62 
    63         // convert timeout
    64         DWORD t;
    65         if (timeout < 0.0) {
    66                 t = INFINITE;
    67         }
    68         else {
    69                 t = (DWORD)(1000.0 * timeout);
    70         }
    71 
    72         // wait for a message.  we cannot be interrupted by thread
    73         // cancellation but that's okay because we're run in the main
    74         // thread and we never cancel that thread.
    75         HANDLE dummy[1];
    76         MsgWaitForMultipleObjects(0, dummy, FALSE, t, QS_ALLINPUT);
     61        // check if messages are available first.
     62    ULONG fStatus = WinQueryQueueStatus(HWND_DESKTOP);
     63    if (!fStatus) {
     64        // convert timeout and wait.
     65        ULONG ulPMTimeout = timeout < 0.0
     66                          ? SEM_INDEFINITE_WAIT
     67                          : (ULONG)(1000.0 * timeout);
     68        WinWaitEventSem(m_hev, ulPMTimeout);
     69    }
    7770}
    7871
    7972IEventQueueBuffer::Type
    80 CMSWindowsEventQueueBuffer::getEvent(CEvent& event, UInt32& dataID)
     73CPMEventQueueBuffer::getEvent(CEvent& event, UInt32& dataID)
    8174{
    82         // peek at messages first.  waiting for QS_ALLINPUT will return
    83         // if a message has been sent to our window but GetMessage will
    84         // dispatch that message behind our backs and block.  PeekMessage
    85         // will also dispatch behind our backs but won't block.
    86         if (!PeekMessage(&m_event, NULL, 0, 0, PM_NOREMOVE) &&
    87                 !PeekMessage(&m_event, (HWND)-1, 0, 0, PM_NOREMOVE)) {
     75        // peek at messages first.
     76    QMSG qmsg;
     77    if (!WinPeekMsg(m_hab, &qmsg, NULLHANDLE, 0, 0, PM_NOREMOVE)) {
    8878                return kNone;
    89         }
     79    }
    9080
    91         // BOOL.  yeah, right.
    92         BOOL result = GetMessage(&m_event, NULL, 0, 0);
    93         if (result == -1) {
    94                 return kNone;
    95         }
    96         else if (result == 0) {
     81    // get the message
     82    if (    !WinGetMsg(m_hab, &m_event, NULLHANDLE, 0, 0)
     83        ||  (m_event.msg == m_daemonQuit && m_daemonQuit != 0)) {
    9784                event = CEvent(CEvent::kQuit);
    9885                return kSystem;
    9986        }
    100         else if (m_daemonQuit != 0 && m_event.message == m_daemonQuit) {
    101                 event = CEvent(CEvent::kQuit);
    102                 return kSystem;
    103         }
    104         else if (m_event.message == m_userEvent) {
    105                 dataID = static_cast<UInt32>(m_event.wParam);
     87       
     88    if (m_event.msg == m_userEvent) {
     89                dataID = (UInt32)(uintptr_t)m_event.mp1;
    10690                return kUser;
    10791        }
    108         else {
    109                 event = CEvent(CEvent::kSystem,
    110                                                         IEventQueue::getSystemTarget(), &m_event);
    111                 return kSystem;
    112         }
     92   
     93    event = CEvent(CEvent::kSystem, IEventQueue::getSystemTarget(), &m_event);
     94    return kSystem;
    11395}
    11496
    11597bool
    116 CMSWindowsEventQueueBuffer::addEvent(UInt32 dataID)
     98CPMEventQueueBuffer::addEvent(UInt32 dataID)
    11799{
    118         return (PostThreadMessage(m_thread, m_userEvent,
    119                                                         static_cast<WPARAM>(dataID), 0) != 0);
     100    return WinPostQueueMsg(m_hmq, m_userEvent, (MPARAM)dataID, 0) != FALSE;
    120101}
    121102
    122103bool
    123 CMSWindowsEventQueueBuffer::isEmpty() const
     104CPMEventQueueBuffer::isEmpty() const
    124105{
    125         return (HIWORD(GetQueueStatus(QS_ALLINPUT)) == 0);
     106    ULONG fStatus = WinQueryQueueStatus(HWND_DESKTOP);
     107        return fStatus != 0;
    126108}
    127109
    128110CEventQueueTimer*
    129 CMSWindowsEventQueueBuffer::newTimer(double, bool) const
     111CPMEventQueueBuffer::newTimer(double, bool) const
    130112{
    131113        return new CEventQueueTimer;
     
    133115
    134116void
    135 CMSWindowsEventQueueBuffer::deleteTimer(CEventQueueTimer* timer) const
     117CPMEventQueueBuffer::deleteTimer(CEventQueueTimer* timer) const
    136118{
    137119        delete timer;
    138120}
     121
  • trunk/synergy/lib/platform/CPMEventQueueBuffer.h

    r2751 r2752  
    22 * synergy -- mouse and keyboard sharing utility
    33 * Copyright (C) 2004 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 #ifndef CMSWINDOWSEVENTQUEUEBUFFER_H
    16 #define CMSWINDOWSEVENTQUEUEBUFFER_H
     16#ifndef CPMEVENTQUEUEBUFFER_H
     17#define CPMEVENTQUEUEBUFFER_H
    1718
    1819#include "IEventQueueBuffer.h"
    19 #define WIN32_LEAN_AND_MEAN
    20 #include <windows.h>
     20#define INCL_ERRORS
     21#define INCL_BASE
     22#define INCL_PM
     23#include <os2.h>
    2124
    22 //! Event queue buffer for Win32
    23 class CMSWindowsEventQueueBuffer : public IEventQueueBuffer {
     25//! Event queue buffer for PM
     26class CPMEventQueueBuffer : public IEventQueueBuffer {
    2427public:
    25         CMSWindowsEventQueueBuffer();
    26         virtual ~CMSWindowsEventQueueBuffer();
     28        CPMEventQueueBuffer();
     29        virtual ~CPMEventQueueBuffer();
    2730
    2831        // IEventQueueBuffer overrides
     
    3639
    3740private:
    38         DWORD                           m_thread;
    39         UINT                            m_userEvent;
    40         MSG                                     m_event;
    41         UINT                            m_daemonQuit;
     41        HAB                                 m_hab;
     42        HMQ                                 m_hmq;
     43    HEV                 m_hev;
     44        ULONG                           m_userEvent;
     45        QMSG                            m_event;
     46        ULONG                           m_daemonQuit;
    4247};
    4348
  • trunk/synergy/lib/platform/CPMKeyState.cpp

    r2751 r2752  
    22 * synergy -- mouse and keyboard sharing utility
    33 * Copyright (C) 2003 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 "CMSWindowsKeyState.h"
    16 #include "CMSWindowsDesks.h"
     16#include "CPMKeyState.h"
    1717#include "CThread.h"
    1818#include "CFunctionJob.h"
     
    2121#include "IEventQueue.h"
    2222#include "TMethodEventJob.h"
    23 #include "CArchMiscWindows.h"
    24 
    25 // extended mouse buttons
    26 #if !defined(VK_XBUTTON1)
    27 #define VK_XBUTTON1                             0x05
    28 #define VK_XBUTTON2                             0x06
    29 #endif
    3023
    3124//
    32 // CMSWindowsKeyState
     25// CPMKeyState
    3326//
    3427
    3528// map virtual keys to synergy key enumeration
    36 const KeyID                             CMSWindowsKeyState::s_virtualKey[] =
    37 {
    38         /* 0x000 */ { kKeyNone },               // reserved
    39         /* 0x001 */ { kKeyNone },               // VK_LBUTTON
    40         /* 0x002 */ { kKeyNone },               // VK_RBUTTON
    41         /* 0x003 */ { kKeyNone },               // VK_CANCEL
    42         /* 0x004 */ { kKeyNone },               // VK_MBUTTON
    43         /* 0x005 */ { kKeyNone },               // VK_XBUTTON1
    44         /* 0x006 */ { kKeyNone },               // VK_XBUTTON2
    45         /* 0x007 */ { kKeyNone },               // undefined
    46         /* 0x008 */ { kKeyBackSpace },  // VK_BACK
    47         /* 0x009 */ { kKeyTab },                // VK_TAB
    48         /* 0x00a */ { kKeyNone },               // undefined
    49         /* 0x00b */ { kKeyNone },               // undefined
    50         /* 0x00c */ { kKeyClear },              // VK_CLEAR
    51         /* 0x00d */ { kKeyReturn },             // VK_RETURN
    52         /* 0x00e */ { kKeyNone },               // undefined
    53         /* 0x00f */ { kKeyNone },               // undefined
    54         /* 0x010 */ { kKeyShift_L },    // VK_SHIFT
    55         /* 0x011 */ { kKeyControl_L },  // VK_CONTROL
    56         /* 0x012 */ { kKeyAlt_L },              // VK_MENU
    57         /* 0x013 */ { kKeyPause },              // VK_PAUSE
    58         /* 0x014 */ { kKeyCapsLock },   // VK_CAPITAL
    59         /* 0x015 */ { kKeyNone },               // VK_KANA                     
    60         /* 0x016 */ { kKeyNone },               // VK_HANGUL           
    61         /* 0x017 */ { kKeyNone },               // VK_JUNJA                     
    62         /* 0x018 */ { kKeyNone },               // VK_FINAL                     
    63         /* 0x019 */ { kKeyZenkaku },    // VK_KANJI                     
    64         /* 0x01a */ { kKeyNone },               // undefined
    65         /* 0x01b */ { kKeyEscape },             // VK_ESCAPE
    66         /* 0x01c */ { kKeyHenkan },             // VK_CONVERT           
    67         /* 0x01d */ { kKeyNone },               // VK_NONCONVERT       
    68         /* 0x01e */ { kKeyNone },               // VK_ACCEPT           
    69         /* 0x01f */ { kKeyNone },               // VK_MODECHANGE       
    70         /* 0x020 */ { kKeyNone },               // VK_SPACE
    71         /* 0x021 */ { kKeyKP_PageUp },  // VK_PRIOR
    72         /* 0x022 */ { kKeyKP_PageDown },// VK_NEXT
    73         /* 0x023 */ { kKeyKP_End },             // VK_END
    74         /* 0x024 */ { kKeyKP_Home },    // VK_HOME
    75         /* 0x025 */ { kKeyKP_Left },    // VK_LEFT
    76         /* 0x026 */ { kKeyKP_Up },              // VK_UP
    77         /* 0x027 */ { kKeyKP_Right },   // VK_RIGHT
    78         /* 0x028 */ { kKeyKP_Down },    // VK_DOWN
    79         /* 0x029 */ { kKeySelect },             // VK_SELECT
    80         /* 0x02a */ { kKeyNone },               // VK_PRINT
    81         /* 0x02b */ { kKeyExecute },    // VK_EXECUTE
    82         /* 0x02c */ { kKeyPrint },              // VK_SNAPSHOT
    83         /* 0x02d */ { kKeyKP_Insert },  // VK_INSERT
    84         /* 0x02e */ { kKeyKP_Delete },  // VK_DELETE
    85         /* 0x02f */ { kKeyHelp },               // VK_HELP
    86         /* 0x030 */ { kKeyNone },               // VK_0
    87         /* 0x031 */ { kKeyNone },               // VK_1
    88         /* 0x032 */ { kKeyNone },               // VK_2
    89         /* 0x033 */ { kKeyNone },               // VK_3
    90         /* 0x034 */ { kKeyNone },               // VK_4
    91         /* 0x035 */ { kKeyNone },               // VK_5
    92         /* 0x036 */ { kKeyNone },               // VK_6
    93         /* 0x037 */ { kKeyNone },               // VK_7
    94         /* 0x038 */ { kKeyNone },               // VK_8
    95         /* 0x039 */ { kKeyNone },               // VK_9
    96         /* 0x03a */ { kKeyNone },               // undefined
    97         /* 0x03b */ { kKeyNone },               // undefined
    98         /* 0x03c */ { kKeyNone },               // undefined
    99         /* 0x03d */ { kKeyNone },               // undefined
    100         /* 0x03e */ { kKeyNone },               // undefined
    101         /* 0x03f */ { kKeyNone },               // undefined
    102         /* 0x040 */ { kKeyNone },               // undefined
    103         /* 0x041 */ { kKeyNone },               // VK_A
    104         /* 0x042 */ { kKeyNone },               // VK_B
    105         /* 0x043 */ { kKeyNone },               // VK_C
    106         /* 0x044 */ { kKeyNone },               // VK_D
    107         /* 0x045 */ { kKeyNone },               // VK_E
    108         /* 0x046 */ { kKeyNone },               // VK_F
    109         /* 0x047 */ { kKeyNone },               // VK_G
    110         /* 0x048 */ { kKeyNone },               // VK_H
    111         /* 0x049 */ { kKeyNone },               // VK_I
    112         /* 0x04a */ { kKeyNone },               // VK_J
    113         /* 0x04b */ { kKeyNone },               // VK_K
    114         /* 0x04c */ { kKeyNone },               // VK_L
    115         /* 0x04d */ { kKeyNone },               // VK_M
    116         /* 0x04e */ { kKeyNone },               // VK_N
    117         /* 0x04f */ { kKeyNone },               // VK_O
    118         /* 0x050 */ { kKeyNone },               // VK_P
    119         /* 0x051 */ { kKeyNone },               // VK_Q
    120         /* 0x052 */ { kKeyNone },               // VK_R
    121         /* 0x053 */ { kKeyNone },               // VK_S
    122         /* 0x054 */ { kKeyNone },               // VK_T
    123         /* 0x055 */ { kKeyNone },               // VK_U
    124         /* 0x056 */ { kKeyNone },               // VK_V
    125         /* 0x057 */ { kKeyNone },               // VK_W
    126         /* 0x058 */ { kKeyNone },               // VK_X
    127         /* 0x059 */ { kKeyNone },               // VK_Y
    128         /* 0x05a */ { kKeyNone },               // VK_Z
    129         /* 0x05b */ { kKeySuper_L },    // VK_LWIN
    130         /* 0x05c */ { kKeySuper_R },    // VK_RWIN
    131         /* 0x05d */ { kKeyMenu },               // VK_APPS
    132         /* 0x05e */ { kKeyNone },               // undefined
    133         /* 0x05f */ { kKeySleep },              // VK_SLEEP
    134         /* 0x060 */ { kKeyKP_0 },               // VK_NUMPAD0
    135         /* 0x061 */ { kKeyKP_1 },               // VK_NUMPAD1
    136         /* 0x062 */ { kKeyKP_2 },               // VK_NUMPAD2
    137         /* 0x063 */ { kKeyKP_3 },               // VK_NUMPAD3
    138         /* 0x064 */ { kKeyKP_4 },               // VK_NUMPAD4
    139         /* 0x065 */ { kKeyKP_5 },               // VK_NUMPAD5
    140         /* 0x066 */ { kKeyKP_6 },               // VK_NUMPAD6
    141         /* 0x067 */ { kKeyKP_7 },               // VK_NUMPAD7
    142         /* 0x068 */ { kKeyKP_8 },               // VK_NUMPAD8
    143         /* 0x069 */ { kKeyKP_9 },               // VK_NUMPAD9
    144         /* 0x06a */ { kKeyKP_Multiply },// VK_MULTIPLY
    145         /* 0x06b */ { kKeyKP_Add },             // VK_ADD
    146         /* 0x06c */ { kKeyKP_Separator },// VK_SEPARATOR
    147         /* 0x06d */ { kKeyKP_Subtract },// VK_SUBTRACT
    148         /* 0x06e */ { kKeyKP_Decimal }, // VK_DECIMAL
    149         /* 0x06f */ { kKeyNone },               // VK_DIVIDE
    150         /* 0x070 */ { kKeyF1 },                 // VK_F1
    151         /* 0x071 */ { kKeyF2 },                 // VK_F2
    152         /* 0x072 */ { kKeyF3 },                 // VK_F3
    153         /* 0x073 */ { kKeyF4 },                 // VK_F4
    154         /* 0x074 */ { kKeyF5 },                 // VK_F5
    155         /* 0x075 */ { kKeyF6 },                 // VK_F6
    156         /* 0x076 */ { kKeyF7 },                 // VK_F7
    157         /* 0x077 */ { kKeyF8 },                 // VK_F8
    158         /* 0x078 */ { kKeyF9 },                 // VK_F9
    159         /* 0x079 */ { kKeyF10 },                // VK_F10
    160         /* 0x07a */ { kKeyF11 },                // VK_F11
    161         /* 0x07b */ { kKeyF12 },                // VK_F12
    162         /* 0x07c */ { kKeyF13 },                // VK_F13
    163         /* 0x07d */ { kKeyF14 },                // VK_F14
    164         /* 0x07e */ { kKeyF15 },                // VK_F15
    165         /* 0x07f */ { kKeyF16 },                // VK_F16
    166         /* 0x080 */ { kKeyF17 },                // VK_F17
    167         /* 0x081 */ { kKeyF18 },                // VK_F18
    168         /* 0x082 */ { kKeyF19 },                // VK_F19
    169         /* 0x083 */ { kKeyF20 },                // VK_F20
    170         /* 0x084 */ { kKeyF21 },                // VK_F21
    171         /* 0x085 */ { kKeyF22 },                // VK_F22
    172         /* 0x086 */ { kKeyF23 },                // VK_F23
    173         /* 0x087 */ { kKeyF24 },                // VK_F24
    174         /* 0x088 */ { kKeyNone },               // unassigned
    175         /* 0x089 */ { kKeyNone },               // unassigned
    176         /* 0x08a */ { kKeyNone },               // unassigned
    177         /* 0x08b */ { kKeyNone },               // unassigned
    178         /* 0x08c */ { kKeyNone },               // unassigned
    179         /* 0x08d */ { kKeyNone },               // unassigned
    180         /* 0x08e */ { kKeyNone },               // unassigned
    181         /* 0x08f */ { kKeyNone },               // unassigned
    182         /* 0x090 */ { kKeyNumLock },    // VK_NUMLOCK
    183         /* 0x091 */ { kKeyScrollLock }, // VK_SCROLL
    184         /* 0x092 */ { kKeyNone },               // unassigned
    185         /* 0x093 */ { kKeyNone },               // unassigned
    186         /* 0x094 */ { kKeyNone },               // unassigned
    187         /* 0x095 */ { kKeyNone },               // unassigned
    188         /* 0x096 */ { kKeyNone },               // unassigned
    189         /* 0x097 */ { kKeyNone },               // unassigned
    190         /* 0x098 */ { kKeyNone },               // unassigned
    191         /* 0x099 */ { kKeyNone },               // unassigned
    192         /* 0x09a */ { kKeyNone },               // unassigned
    193         /* 0x09b */ { kKeyNone },               // unassigned
    194         /* 0x09c */ { kKeyNone },               // unassigned
    195         /* 0x09d */ { kKeyNone },               // unassigned
    196         /* 0x09e */ { kKeyNone },               // unassigned
    197         /* 0x09f */ { kKeyNone },               // unassigned
    198         /* 0x0a0 */ { kKeyShift_L },    // VK_LSHIFT
    199         /* 0x0a1 */ { kKeyShift_R },    // VK_RSHIFT
    200         /* 0x0a2 */ { kKeyControl_L },  // VK_LCONTROL
    201         /* 0x0a3 */ { kKeyControl_R },  // VK_RCONTROL
    202         /* 0x0a4 */ { kKeyAlt_L },              // VK_LMENU
    203         /* 0x0a5 */ { kKeyAlt_R },              // VK_RMENU
    204         /* 0x0a6 */ { kKeyNone },               // VK_BROWSER_BACK
    205         /* 0x0a7 */ { kKeyNone },               // VK_BROWSER_FORWARD
    206         /* 0x0a8 */ { kKeyNone },               // VK_BROWSER_REFRESH
    207         /* 0x0a9 */ { kKeyNone },               // VK_BROWSER_STOP
    208         /* 0x0aa */ { kKeyNone },               // VK_BROWSER_SEARCH
    209         /* 0x0ab */ { kKeyNone },               // VK_BROWSER_FAVORITES
    210         /* 0x0ac */ { kKeyNone },               // VK_BROWSER_HOME
    211         /* 0x0ad */ { kKeyNone },               // VK_VOLUME_MUTE
    212         /* 0x0ae */ { kKeyNone },               // VK_VOLUME_DOWN
    213         /* 0x0af */ { kKeyNone },               // VK_VOLUME_UP
    214         /* 0x0b0 */ { kKeyNone },               // VK_MEDIA_NEXT_TRACK
    215         /* 0x0b1 */ { kKeyNone },               // VK_MEDIA_PREV_TRACK
    216         /* 0x0b2 */ { kKeyNone },               // VK_MEDIA_STOP
    217         /* 0x0b3 */ { kKeyNone },               // VK_MEDIA_PLAY_PAUSE
    218         /* 0x0b4 */ { kKeyNone },               // VK_LAUNCH_MAIL
    219         /* 0x0b5 */ { kKeyNone },               // VK_LAUNCH_MEDIA_SELECT
    220         /* 0x0b6 */ { kKeyNone },               // VK_LAUNCH_APP1
    221         /* 0x0b7 */ { kKeyNone },               // VK_LAUNCH_APP2
    222         /* 0x0b8 */ { kKeyNone },               // unassigned
    223         /* 0x0b9 */ { kKeyNone },               // unassigned
    224         /* 0x0ba */ { kKeyNone },               // OEM specific
    225         /* 0x0bb */ { kKeyNone },               // OEM specific
    226         /* 0x0bc */ { kKeyNone },               // OEM specific
    227         /* 0x0bd */ { kKeyNone },               // OEM specific
    228         /* 0x0be */ { kKeyNone },               // OEM specific
    229         /* 0x0bf */ { kKeyNone },               // OEM specific
    230         /* 0x0c0 */ { kKeyNone },               // OEM specific
    231         /* 0x0c1 */ { kKeyNone },               // unassigned
    232         /* 0x0c2 */ { kKeyNone },               // unassigned
    233         /* 0x0c3 */ { kKeyNone },               // unassigned
    234         /* 0x0c4 */ { kKeyNone },               // unassigned
    235         /* 0x0c5 */ { kKeyNone },               // unassigned
    236         /* 0x0c6 */ { kKeyNone },               // unassigned
    237         /* 0x0c7 */ { kKeyNone },               // unassigned
    238         /* 0x0c8 */ { kKeyNone },               // unassigned
    239         /* 0x0c9 */ { kKeyNone },               // unassigned
    240         /* 0x0ca */ { kKeyNone },               // unassigned
    241         /* 0x0cb */ { kKeyNone },               // unassigned
    242         /* 0x0cc */ { kKeyNone },               // unassigned
    243         /* 0x0cd */ { kKeyNone },               // unassigned
    244         /* 0x0ce */ { kKeyNone },               // unassigned
    245         /* 0x0cf */ { kKeyNone },               // unassigned
    246         /* 0x0d0 */ { kKeyNone },               // unassigned
    247         /* 0x0d1 */ { kKeyNone },               // unassigned
    248         /* 0x0d2 */ { kKeyNone },               // unassigned
    249         /* 0x0d3 */ { kKeyNone },               // unassigned
    250         /* 0x0d4 */ { kKeyNone },               // unassigned
    251         /* 0x0d5 */ { kKeyNone },               // unassigned
    252         /* 0x0d6 */ { kKeyNone },               // unassigned
    253         /* 0x0d7 */ { kKeyNone },               // unassigned
    254         /* 0x0d8 */ { kKeyNone },               // unassigned
    255         /* 0x0d9 */ { kKeyNone },               // unassigned
    256         /* 0x0da */ { kKeyNone },               // unassigned
    257         /* 0x0db */ { kKeyNone },               // OEM specific
    258         /* 0x0dc */ { kKeyNone },               // OEM specific
    259         /* 0x0dd */ { kKeyNone },               // OEM specific
    260         /* 0x0de */ { kKeyNone },               // OEM specific
    261         /* 0x0df */ { kKeyNone },               // OEM specific
    262         /* 0x0e0 */ { kKeyNone },               // OEM specific
    263         /* 0x0e1 */ { kKeyNone },               // OEM specific
    264         /* 0x0e2 */ { kKeyNone },               // OEM specific
    265         /* 0x0e3 */ { kKeyNone },               // OEM specific
    266         /* 0x0e4 */ { kKeyNone },               // OEM specific
    267         /* 0x0e5 */ { kKeyNone },               // unassigned
    268         /* 0x0e6 */ { kKeyNone },               // OEM specific
    269         /* 0x0e7 */ { kKeyNone },               // unassigned
    270         /* 0x0e8 */ { kKeyNone },               // unassigned
    271         /* 0x0e9 */ { kKeyNone },               // OEM specific
    272         /* 0x0ea */ { kKeyNone },               // OEM specific
    273         /* 0x0eb */ { kKeyNone },               // OEM specific
    274         /* 0x0ec */ { kKeyNone },               // OEM specific
    275         /* 0x0ed */ { kKeyNone },               // OEM specific
    276         /* 0x0ee */ { kKeyNone },               // OEM specific
    277         /* 0x0ef */ { kKeyNone },               // OEM specific
    278         /* 0x0f0 */ { kKeyNone },               // OEM specific
    279         /* 0x0f1 */ { kKeyNone },               // OEM specific
    280         /* 0x0f2 */ { kKeyNone },               // OEM specific
    281         /* 0x0f3 */ { kKeyNone },               // OEM specific
    282         /* 0x0f4 */ { kKeyNone },               // OEM specific
    283         /* 0x0f5 */ { kKeyNone },               // OEM specific
    284         /* 0x0f6 */ { kKeyNone },               // VK_ATTN                     
    285         /* 0x0f7 */ { kKeyNone },               // VK_CRSEL                     
    286         /* 0x0f8 */ { kKeyNone },               // VK_EXSEL                     
    287         /* 0x0f9 */ { kKeyNone },               // VK_EREOF                     
    288         /* 0x0fa */ { kKeyNone },               // VK_PLAY                     
    289         /* 0x0fb */ { kKeyNone },               // VK_ZOOM                     
    290         /* 0x0fc */ { kKeyNone },               // reserved
    291         /* 0x0fd */ { kKeyNone },               // VK_PA1                       
    292         /* 0x0fe */ { kKeyNone },               // VK_OEM_CLEAR         
    293         /* 0x0ff */ { kKeyNone },               // reserved
    294 
    295         /* 0x100 */ { kKeyNone },               // reserved
    296         /* 0x101 */ { kKeyNone },               // VK_LBUTTON
    297         /* 0x102 */ { kKeyNone },               // VK_RBUTTON
    298         /* 0x103 */ { kKeyBreak },              // VK_CANCEL
    299         /* 0x104 */ { kKeyNone },               // VK_MBUTTON
    300         /* 0x105 */ { kKeyNone },               // VK_XBUTTON1
    301         /* 0x106 */ { kKeyNone },               // VK_XBUTTON2
    302         /* 0x107 */ { kKeyNone },               // undefined
    303         /* 0x108 */ { kKeyNone },               // VK_BACK
    304         /* 0x109 */ { kKeyNone },               // VK_TAB
    305         /* 0x10a */ { kKeyNone },               // undefined
    306         /* 0x10b */ { kKeyNone },               // undefined
    307         /* 0x10c */ { kKeyClear },              // VK_CLEAR
    308         /* 0x10d */ { kKeyKP_Enter },   // VK_RETURN
    309         /* 0x10e */ { kKeyNone },               // undefined
    310         /* 0x10f */ { kKeyNone },               // undefined
    311         /* 0x110 */ { kKeyShift_R },    // VK_SHIFT
    312         /* 0x111 */ { kKeyControl_R },  // VK_CONTROL
    313         /* 0x112 */ { kKeyAlt_R },              // VK_MENU
    314         /* 0x113 */ { kKeyNone },               // VK_PAUSE
    315         /* 0x114 */ { kKeyNone },               // VK_CAPITAL
    316         /* 0x115 */ { kKeyNone },               // VK_KANA                     
    317         /* 0x116 */ { kKeyNone },               // VK_HANGUL           
    318         /* 0x117 */ { kKeyNone },               // VK_JUNJA                     
    319         /* 0x118 */ { kKeyNone },               // VK_FINAL                     
    320         /* 0x119 */ { kKeyNone },               // VK_KANJI                     
    321         /* 0x11a */ { kKeyNone },               // undefined
    322         /* 0x11b */ { kKeyNone },               // VK_ESCAPE
    323         /* 0x11c */ { kKeyNone },               // VK_CONVERT           
    324         /* 0x11d */ { kKeyNone },               // VK_NONCONVERT       
    325         /* 0x11e */ { kKeyNone },               // VK_ACCEPT           
    326         /* 0x11f */ { kKeyNone },               // VK_MODECHANGE       
    327         /* 0x120 */ { kKeyNone },               // VK_SPACE
    328         /* 0x121 */ { kKeyPageUp },             // VK_PRIOR
    329         /* 0x122 */ { kKeyPageDown },   // VK_NEXT
    330         /* 0x123 */ { kKeyEnd },                // VK_END
    331         /* 0x124 */ { kKeyHome },               // VK_HOME
    332         /* 0x125 */ { kKeyLeft },               // VK_LEFT
    333         /* 0x126 */ { kKeyUp },                 // VK_UP
    334         /* 0x127 */ { kKeyRight },              // VK_RIGHT
    335         /* 0x128 */ { kKeyDown },               // VK_DOWN
    336         /* 0x129 */ { kKeySelect },             // VK_SELECT
    337         /* 0x12a */ { kKeyNone },               // VK_PRINT
    338         /* 0x12b */ { kKeyExecute },    // VK_EXECUTE
    339         /* 0x12c */ { kKeyPrint },              // VK_SNAPSHOT
    340         /* 0x12d */ { kKeyInsert },             // VK_INSERT
    341         /* 0x12e */ { kKeyDelete },             // VK_DELETE
    342         /* 0x12f */ { kKeyHelp },               // VK_HELP
    343         /* 0x130 */ { kKeyNone },               // VK_0
    344         /* 0x131 */ { kKeyNone },               // VK_1
    345         /* 0x132 */ { kKeyNone },               // VK_2
    346         /* 0x133 */ { kKeyNone },               // VK_3
    347         /* 0x134 */ { kKeyNone },               // VK_4
    348         /* 0x135 */ { kKeyNone },               // VK_5
    349         /* 0x136 */ { kKeyNone },               // VK_6
    350         /* 0x137 */ { kKeyNone },               // VK_7
    351         /* 0x138 */ { kKeyNone },               // VK_8
    352         /* 0x139 */ { kKeyNone },               // VK_9
    353         /* 0x13a */ { kKeyNone },               // undefined
    354         /* 0x13b */ { kKeyNone },               // undefined
    355         /* 0x13c */ { kKeyNone },               // undefined
    356         /* 0x13d */ { kKeyNone },               // undefined
    357         /* 0x13e */ { kKeyNone },               // undefined
    358         /* 0x13f */ { kKeyNone },               // undefined
    359         /* 0x140 */ { kKeyNone },               // undefined
    360         /* 0x141 */ { kKeyNone },               // VK_A
    361         /* 0x142 */ { kKeyNone },               // VK_B
    362         /* 0x143 */ { kKeyNone },               // VK_C
    363         /* 0x144 */ { kKeyNone },               // VK_D
    364         /* 0x145 */ { kKeyNone },               // VK_E
    365         /* 0x146 */ { kKeyNone },               // VK_F
    366         /* 0x147 */ { kKeyNone },               // VK_G
    367         /* 0x148 */ { kKeyNone },               // VK_H
    368         /* 0x149 */ { kKeyNone },               // VK_I
    369         /* 0x14a */ { kKeyNone },               // VK_J
    370         /* 0x14b */ { kKeyNone },               // VK_K
    371         /* 0x14c */ { kKeyNone },               // VK_L
    372         /* 0x14d */ { kKeyNone },               // VK_M
    373         /* 0x14e */ { kKeyNone },               // VK_N
    374         /* 0x14f */ { kKeyNone },               // VK_O
    375         /* 0x150 */ { kKeyNone },               // VK_P
    376         /* 0x151 */ { kKeyNone },               // VK_Q
    377         /* 0x152 */ { kKeyNone },               // VK_R
    378         /* 0x153 */ { kKeyNone },               // VK_S
    379         /* 0x154 */ { kKeyNone },               // VK_T
    380         /* 0x155 */ { kKeyNone },               // VK_U
    381         /* 0x156 */ { kKeyNone },               // VK_V
    382         /* 0x157 */ { kKeyNone },               // VK_W
    383         /* 0x158 */ { kKeyNone },               // VK_X
    384         /* 0x159 */ { kKeyNone },               // VK_Y
    385         /* 0x15a */ { kKeyNone },               // VK_Z
    386         /* 0x15b */ { kKeySuper_L },    // VK_LWIN
    387         /* 0x15c */ { kKeySuper_R },    // VK_RWIN
    388         /* 0x15d */ { kKeyMenu },               // VK_APPS
    389         /* 0x15e */ { kKeyNone },               // undefined
    390         /* 0x15f */ { kKeyNone },               // VK_SLEEP
    391         /* 0x160 */ { kKeyNone },               // VK_NUMPAD0
    392         /* 0x161 */ { kKeyNone },               // VK_NUMPAD1
    393         /* 0x162 */ { kKeyNone },               // VK_NUMPAD2
    394         /* 0x163 */ { kKeyNone },               // VK_NUMPAD3
    395         /* 0x164 */ { kKeyNone },               // VK_NUMPAD4
    396         /* 0x165 */ { kKeyNone },               // VK_NUMPAD5
    397         /* 0x166 */ { kKeyNone },               // VK_NUMPAD6
    398         /* 0x167 */ { kKeyNone },               // VK_NUMPAD7
    399         /* 0x168 */ { kKeyNone },               // VK_NUMPAD8
    400         /* 0x169 */ { kKeyNone },               // VK_NUMPAD9
    401         /* 0x16a */ { kKeyNone },               // VK_MULTIPLY
    402         /* 0x16b */ { kKeyNone },               // VK_ADD
    403         /* 0x16c */ { kKeyKP_Separator },// VK_SEPARATOR
    404         /* 0x16d */ { kKeyNone },               // VK_SUBTRACT
    405         /* 0x16e */ { kKeyNone },               // VK_DECIMAL
    406         /* 0x16f */ { kKeyKP_Divide },  // VK_DIVIDE
    407         /* 0x170 */ { kKeyNone },               // VK_F1
    408         /* 0x171 */ { kKeyNone },               // VK_F2
    409         /* 0x172 */ { kKeyNone },               // VK_F3
    410         /* 0x173 */ { kKeyNone },               // VK_F4
    411         /* 0x174 */ { kKeyNone },               // VK_F5
    412         /* 0x175 */ { kKeyNone },               // VK_F6
    413         /* 0x176 */ { kKeyNone },               // VK_F7
    414         /* 0x177 */ { kKeyNone },               // VK_F8
    415         /* 0x178 */ { kKeyNone },               // VK_F9
    416         /* 0x179 */ { kKeyNone },               // VK_F10
    417         /* 0x17a */ { kKeyNone },               // VK_F11
    418         /* 0x17b */ { kKeyNone },               // VK_F12
    419         /* 0x17c */ { kKeyF13 },                // VK_F13
    420         /* 0x17d */ { kKeyF14 },                // VK_F14
    421         /* 0x17e */ { kKeyF15 },                // VK_F15
    422         /* 0x17f */ { kKeyF16 },                // VK_F16
    423         /* 0x180 */ { kKeyF17 },                // VK_F17
    424         /* 0x181 */ { kKeyF18 },                // VK_F18
    425         /* 0x182 */ { kKeyF19 },                // VK_F19
    426         /* 0x183 */ { kKeyF20 },                // VK_F20
    427         /* 0x184 */ { kKeyF21 },                // VK_F21
    428         /* 0x185 */ { kKeyF22 },                // VK_F22
    429         /* 0x186 */ { kKeyF23 },                // VK_F23
    430         /* 0x187 */ { kKeyF24 },                // VK_F24
    431         /* 0x188 */ { kKeyNone },               // unassigned
    432         /* 0x189 */ { kKeyNone },               // unassigned
    433         /* 0x18a */ { kKeyNone },               // unassigned
    434         /* 0x18b */ { kKeyNone },               // unassigned
    435         /* 0x18c */ { kKeyNone },               // unassigned
    436         /* 0x18d */ { kKeyNone },               // unassigned
    437         /* 0x18e */ { kKeyNone },               // unassigned
    438         /* 0x18f */ { kKeyNone },               // unassigned
    439         /* 0x190 */ { kKeyNumLock },    // VK_NUMLOCK
    440         /* 0x191 */ { kKeyNone },               // VK_SCROLL
    441         /* 0x192 */ { kKeyNone },               // unassigned
    442         /* 0x193 */ { kKeyNone },               // unassigned
    443         /* 0x194 */ { kKeyNone },               // unassigned
    444         /* 0x195 */ { kKeyNone },               // unassigned
    445         /* 0x196 */ { kKeyNone },               // unassigned
    446         /* 0x197 */ { kKeyNone },               // unassigned
    447         /* 0x198 */ { kKeyNone },               // unassigned
    448         /* 0x199 */ { kKeyNone },               // unassigned
    449         /* 0x19a */ { kKeyNone },               // unassigned
    450         /* 0x19b */ { kKeyNone },               // unassigned
    451         /* 0x19c */ { kKeyNone },               // unassigned
    452         /* 0x19d */ { kKeyNone },               // unassigned
    453         /* 0x19e */ { kKeyNone },               // unassigned
    454         /* 0x19f */ { kKeyNone },               // unassigned
    455         /* 0x1a0 */ { kKeyShift_L },    // VK_LSHIFT
    456         /* 0x1a1 */ { kKeyShift_R },    // VK_RSHIFT
    457         /* 0x1a2 */ { kKeyControl_L },  // VK_LCONTROL
    458         /* 0x1a3 */ { kKeyControl_R },  // VK_RCONTROL
    459         /* 0x1a4 */ { kKeyAlt_L },              // VK_LMENU
    460         /* 0x1a5 */ { kKeyAlt_R },              // VK_RMENU
    461         /* 0x1a6 */ { kKeyWWWBack },    // VK_BROWSER_BACK
    462         /* 0x1a7 */ { kKeyWWWForward }, // VK_BROWSER_FORWARD
    463         /* 0x1a8 */ { kKeyWWWRefresh }, // VK_BROWSER_REFRESH
    464         /* 0x1a9 */ { kKeyWWWStop },    // VK_BROWSER_STOP
    465         /* 0x1aa */ { kKeyWWWSearch },  // VK_BROWSER_SEARCH
    466         /* 0x1ab */ { kKeyWWWFavorites },// VK_BROWSER_FAVORITES
    467         /* 0x1ac */ { kKeyWWWHome },    // VK_BROWSER_HOME
    468         /* 0x1ad */ { kKeyAudioMute },  // VK_VOLUME_MUTE
    469         /* 0x1ae */ { kKeyAudioDown },  // VK_VOLUME_DOWN
    470         /* 0x1af */ { kKeyAudioUp },    // VK_VOLUME_UP
    471         /* 0x1b0 */ { kKeyAudioNext },  // VK_MEDIA_NEXT_TRACK
    472         /* 0x1b1 */ { kKeyAudioPrev },  // VK_MEDIA_PREV_TRACK
    473         /* 0x1b2 */ { kKeyAudioStop },  // VK_MEDIA_STOP
    474         /* 0x1b3 */ { kKeyAudioPlay },  // VK_MEDIA_PLAY_PAUSE
    475         /* 0x1b4 */ { kKeyAppMail },    // VK_LAUNCH_MAIL
    476         /* 0x1b5 */ { kKeyAppMedia },   // VK_LAUNCH_MEDIA_SELECT
    477         /* 0x1b6 */ { kKeyAppUser1 },   // VK_LAUNCH_APP1
    478         /* 0x1b7 */ { kKeyAppUser2 },   // VK_LAUNCH_APP2
    479         /* 0x1b8 */ { kKeyNone },               // unassigned
    480         /* 0x1b9 */ { kKeyNone },               // unassigned
    481         /* 0x1ba */ { kKeyNone },               // OEM specific
    482         /* 0x1bb */ { kKeyNone },               // OEM specific
    483         /* 0x1bc */ { kKeyNone },               // OEM specific
    484         /* 0x1bd */ { kKeyNone },               // OEM specific
    485         /* 0x1be */ { kKeyNone },               // OEM specific
    486         /* 0x1bf */ { kKeyNone },               // OEM specific
    487         /* 0x1c0 */ { kKeyNone },               // OEM specific
    488         /* 0x1c1 */ { kKeyNone },               // unassigned
    489         /* 0x1c2 */ { kKeyNone },               // unassigned
    490         /* 0x1c3 */ { kKeyNone },               // unassigned
    491         /* 0x1c4 */ { kKeyNone },               // unassigned
    492         /* 0x1c5 */ { kKeyNone },               // unassigned
    493         /* 0x1c6 */ { kKeyNone },               // unassigned
    494         /* 0x1c7 */ { kKeyNone },               // unassigned
    495         /* 0x1c8 */ { kKeyNone },               // unassigned
    496         /* 0x1c9 */ { kKeyNone },               // unassigned
    497         /* 0x1ca */ { kKeyNone },               // unassigned
    498         /* 0x1cb */ { kKeyNone },               // unassigned
    499         /* 0x1cc */ { kKeyNone },               // unassigned
    500         /* 0x1cd */ { kKeyNone },               // unassigned
    501         /* 0x1ce */ { kKeyNone },               // unassigned
    502         /* 0x1cf */ { kKeyNone },               // unassigned
    503         /* 0x1d0 */ { kKeyNone },               // unassigned
    504         /* 0x1d1 */ { kKeyNone },               // unassigned
    505         /* 0x1d2 */ { kKeyNone },               // unassigned
    506         /* 0x1d3 */ { kKeyNone },               // unassigned
    507         /* 0x1d4 */ { kKeyNone },               // unassigned
    508         /* 0x1d5 */ { kKeyNone },               // unassigned
    509         /* 0x1d6 */ { kKeyNone },               // unassigned
    510         /* 0x1d7 */ { kKeyNone },               // unassigned
    511         /* 0x1d8 */ { kKeyNone },               // unassigned
    512         /* 0x1d9 */ { kKeyNone },               // unassigned
    513         /* 0x1da */ { kKeyNone },               // unassigned
    514         /* 0x1db */ { kKeyNone },               // OEM specific
    515         /* 0x1dc */ { kKeyNone },               // OEM specific
    516         /* 0x1dd */ { kKeyNone },               // OEM specific
    517         /* 0x1de */ { kKeyNone },               // OEM specific
    518         /* 0x1df */ { kKeyNone },               // OEM specific
    519         /* 0x1e0 */ { kKeyNone },               // OEM specific
    520         /* 0x1e1 */ { kKeyNone },               // OEM specific
    521         /* 0x1e2 */ { kKeyNone },               // OEM specific
    522         /* 0x1e3 */ { kKeyNone },               // OEM specific
    523         /* 0x1e4 */ { kKeyNone },               // OEM specific
    524         /* 0x1e5 */ { kKeyNone },               // unassigned
    525         /* 0x1e6 */ { kKeyNone },               // OEM specific
    526         /* 0x1e7 */ { kKeyNone },               // unassigned
    527         /* 0x1e8 */ { kKeyNone },               // unassigned
    528         /* 0x1e9 */ { kKeyNone },               // OEM specific
    529         /* 0x1ea */ { kKeyNone },               // OEM specific
    530         /* 0x1eb */ { kKeyNone },               // OEM specific
    531         /* 0x1ec */ { kKeyNone },               // OEM specific
    532         /* 0x1ed */ { kKeyNone },               // OEM specific
    533         /* 0x1ee */ { kKeyNone },               // OEM specific
    534         /* 0x1ef */ { kKeyNone },               // OEM specific
    535         /* 0x1f0 */ { kKeyNone },               // OEM specific
    536         /* 0x1f1 */ { kKeyNone },               // OEM specific
    537         /* 0x1f2 */ { kKeyNone },               // OEM specific
    538         /* 0x1f3 */ { kKeyNone },               // OEM specific
    539         /* 0x1f4 */ { kKeyNone },               // OEM specific
    540         /* 0x1f5 */ { kKeyNone },               // OEM specific
    541         /* 0x1f6 */ { kKeyNone },               // VK_ATTN                     
    542         /* 0x1f7 */ { kKeyNone },               // VK_CRSEL                     
    543         /* 0x1f8 */ { kKeyNone },               // VK_EXSEL                     
    544         /* 0x1f9 */ { kKeyNone },               // VK_EREOF                     
    545         /* 0x1fa */ { kKeyNone },               // VK_PLAY                     
    546         /* 0x1fb */ { kKeyNone },               // VK_ZOOM                     
    547         /* 0x1fc */ { kKeyNone },               // reserved
    548         /* 0x1fd */ { kKeyNone },               // VK_PA1                       
    549         /* 0x1fe */ { kKeyNone },               // VK_OEM_CLEAR         
    550         /* 0x1ff */ { kKeyNone }                // reserved
     29const KeyID                             CPMKeyState::s_virtualKey[0x42] =
     30{
     31        /* 0x000 */ kKeyNone,           // reserved
     32        /* 0x001 */ kKeyNone,           // VK_BUTTON1              VK_BUTTON1          0x0001         
     33        /* 0x002 */ kKeyNone,           // VK_BUTTON2              VK_BUTTON2          0x0002         
     34        /* 0x003 */ kKeyNone,           // VK_BUTTON3              VK_BUTTON3          0x0003         
     35        /* 0x004 */ kKeyBreak,          // VK_BREAK                VK_BREAK            0x0004         
     36        /* 0x005 */ kKeyBackSpace,      // VK_BACKSPACE
     37        /* 0x006 */ kKeyTab,            // VK_TAB
     38        /* 0x007 */ kKeyLeftTab,        // VK_BACKTAB -- ???
     39        /* 0x008 */ kKeyReturn,         // VK_NEWLINE
     40        /* 0x009 */ kKeyShift_L,        // VK_SHIFT
     41        /* 0x00a */ kKeyControl_L,      // VK_CTRL             0x000a         
     42        /* 0x00b */ kKeyAlt_L,          // VK_ALT              0x000b         
     43        /* 0x00c */ kKeyAltGr,          // VK_ALTGRAF          0x000c         
     44        /* 0x00d */ kKeyPause,          // VK_PAUSE            0x000d         
     45        /* 0x00e */ kKeyCapsLock,       // VK_CAPSLOCK         0x000e         
     46        /* 0x00f */ kKeyEscape,         // VK_ESC              0x000f         
     47        /* 0x010 */ kKeyNone,           // VK_SPACE            0x0010         
     48        /* 0x011 */ kKeyPageUp,         // VK_PAGEUP           0x0011         
     49        /* 0x012 */ kKeyPageDown,       // VK_PAGEDOWN         0x0012         
     50        /* 0x013 */ kKeyEnd,            // VK_END              0x0013         
     51        /* 0x014 */ kKeyHome,           // VK_HOME             0x0014         
     52        /* 0x015 */ kKeyLeft,           // VK_LEFT             0x0015         
     53        /* 0x016 */ kKeyUp,                     // VK_UP               0x0016         
     54        /* 0x017 */ kKeyRight,          // VK_RIGHT            0x0017         
     55        /* 0x018 */ kKeyDown,           // VK_DOWN             0x0018         
     56        /* 0x019 */ kKeyNone,           // VK_PRINTSCRN            0x0019     
     57        /* 0x01a */ kKeyInsert,         // VK_INSERT           0x001a         
     58        /* 0x01b */ kKeyDelete,         // VK_DELETE           0x001b         
     59        /* 0x01c */ kKeyScrollLock,     // VK_SCRLLOCK         0x001c         
     60        /* 0x01d */ kKeyNumLock,        // VK_NUMLOCK          0x001d         
     61        /* 0x01e */ kKeyKP_Enter,       // VK_ENTER            0x001e         
     62        /* 0x01f */ kKeySysReq,         // VK_SYSRQ            0x001f         
     63        /* 0x020 */ kKeyF1,                     // VK_F1               0x0020         
     64        /* 0x021 */ kKeyF2,                     // VK_F2               0x0021         
     65        /* 0x022 */ kKeyF3,                     // VK_F3               0x0022         
     66        /* 0x023 */ kKeyF4,                     // VK_F4               0x0023         
     67        /* 0x024 */ kKeyF5,                     // VK_F5               0x0024         
     68        /* 0x025 */ kKeyF6,                     // VK_F6               0x0025         
     69        /* 0x026 */ kKeyF7,                     // VK_F7               0x0026         
     70        /* 0x027 */ kKeyF8,                     // VK_F8               0x0027         
     71        /* 0x028 */ kKeyF9,                     // VK_F9               0x0028         
     72        /* 0x029 */ kKeyF10,            // VK_F10              0x0029         
     73        /* 0x02a */ kKeyF11,            // VK_F11              0x002a         
     74        /* 0x02b */ kKeyF12,            // VK_F12              0x002b         
     75        /* 0x02c */ kKeyF13,            // VK_F13              0x002c         
     76        /* 0x02d */ kKeyF14,            // VK_F14              0x002d         
     77        /* 0x02e */ kKeyF15,            // VK_F15              0x002e         
     78        /* 0x02f */ kKeyF16,            // VK_F16              0x002f         
     79        /* 0x030 */ kKeyF17,            // VK_F17              0x0030         
     80        /* 0x031 */ kKeyF18,            // VK_F18              0x0031         
     81        /* 0x032 */ kKeyF19,            // VK_F19              0x0032         
     82        /* 0x033 */ kKeyF20,            // VK_F20              0x0033         
     83        /* 0x034 */ kKeyF21,            // VK_F21              0x0034         
     84        /* 0x035 */ kKeyF22,            // VK_F22              0x0035         
     85        /* 0x036 */ kKeyF23,            // VK_F23              0x0036         
     86        /* 0x037 */ kKeyF24,            // VK_F24              0x0037         
     87        /* 0x038 */ kKeyNone,           // VK_ENDDRAG          0x0038         
     88        /* 0x039 */ kKeyClear,          // VK_CLEAR            0x0039         
     89        /* 0x03a */ kKeyNone,           // VK_EREOF            0x003a         
     90        /* 0x03b */ kKeyNone,           // VK_PA1              0x003b         
     91        /* 0x03c */ kKeyNone,           // VK_ATTN             0x003c         
     92        /* 0x03d */ kKeyNone,           // VK_CRSEL            0x003d         
     93        /* 0x03e */ kKeyNone,           // VK_EXSEL            0x003e         
     94        /* 0x03f */ kKeyNone,           // VK_COPY             0x003f         
     95        /* 0x040 */ kKeyNone,           // VK_BLK1             0x0040         
     96        /* 0x041 */ kKeyNone            // VK_BLK2             0x0041         
    55197};
    55298
    55399struct CWin32Modifiers {
    554100public:
    555         UINT                            m_vk;
     101        ULONG                           m_vk;
    556102        KeyModifierMask         m_mask;
    557103};
     
    560106{
    561107        { VK_SHIFT,    KeyModifierShift   },
    562         { VK_LSHIFT,   KeyModifierShift   },
    563         { VK_RSHIFT,   KeyModifierShift   },
    564         { VK_CONTROL,  KeyModifierControl },
    565         { VK_LCONTROL, KeyModifierControl },
    566         { VK_RCONTROL, KeyModifierControl },
    567         { VK_MENU,     KeyModifierAlt     },
    568         { VK_LMENU,    KeyModifierAlt     },
    569         { VK_RMENU,    KeyModifierAlt     },
    570         { VK_LWIN,     KeyModifierSuper   },
    571         { VK_RWIN,     KeyModifierSuper   }
     108        { VK_CTRL,     KeyModifierControl },
     109        { VK_ALT,      KeyModifierAlt     },
     110        { VK_ALTGRAF,  KeyModifierAltGr     },
    572111};
    573112
    574 CMSWindowsKeyState::CMSWindowsKeyState(CMSWindowsDesks* desks,
    575                                 void* eventTarget) :
    576         m_is95Family(CArchMiscWindows::isWindows95Family()),
     113CPMKeyState::CPMKeyState(void* eventTarget) :
    577114        m_eventTarget(eventTarget),
    578         m_desks(desks),
    579         m_keyLayout(GetKeyboardLayout(0)),
    580115        m_fixTimer(NULL),
    581116        m_lastDown(0),
     
    584119        m_originalSavedModifiers(0)
    585120{
    586         // look up symbol that's available on winNT family but not win95
    587         HMODULE userModule = GetModuleHandle("user32.dll");
    588         m_ToUnicodeEx = (ToUnicodeEx_t)GetProcAddress(userModule, "ToUnicodeEx");
    589 }
    590 
    591 CMSWindowsKeyState::~CMSWindowsKeyState()
     121
     122}
     123
     124CPMKeyState::~CPMKeyState()
    592125{
    593126        disable();
     
    595128
    596129void
    597 CMSWindowsKeyState::disable()
     130CPMKeyState::disable()
    598131{
    599132        if (m_fixTimer != NULL) {
     
    606139
    607140KeyButton
    608 CMSWindowsKeyState::virtualKeyToButton(UINT virtualKey) const
     141CPMKeyState::virtualKeyToButton(ULONG virtualKey) const
    609142{
    610143        return m_virtualKeyToButton[virtualKey & 0xffu];
    611144}
    612145
    613 void
    614 CMSWindowsKeyState::setKeyLayout(HKL keyLayout)
    615 {
    616         m_keyLayout = keyLayout;
    617 }
    618 
    619146bool
    620 CMSWindowsKeyState::testAutoRepeat(bool press, bool isRepeat, KeyButton button)
     147CPMKeyState::testAutoRepeat(bool press, bool isRepeat, KeyButton button)
    621148{
    622149        if (!isRepeat) {
     
    633160
    634161void
    635 CMSWindowsKeyState::saveModifiers()
     162CPMKeyState::saveModifiers()
    636163{
    637164        m_savedModifiers         = getActiveModifiers();
     
    640167
    641168void
    642 CMSWindowsKeyState::useSavedModifiers(bool enable)
     169CPMKeyState::useSavedModifiers(bool enable)
    643170{
    644171        if (enable != m_useSavedModifiers) {
     
    654181
    655182KeyID
    656 CMSWindowsKeyState::mapKeyFromEvent(WPARAM charAndVirtKey,
    657                                 LPARAM info, KeyModifierMask* maskOut) const
    658 {
    659         static const KeyModifierMask s_controlAlt =
    660                 KeyModifierControl | KeyModifierAlt;
     183CPMKeyState::mapKeyFromEvent(MPARAM charAndVirtKey, MPARAM info, KeyModifierMask* maskOut) const
     184{
     185        static const KeyModifierMask s_controlAlt = KeyModifierControl | KeyModifierAlt;
    661186
    662187        // extract character, virtual key, and if we didn't use AltGr
     
    708233
    709234bool
    710 CMSWindowsKeyState::didGroupsChange() const
     235CPMKeyState::didGroupsChange() const
    711236{
    712237        GroupList groups;
     
    715240
    716241UINT
    717 CMSWindowsKeyState::mapKeyToVirtualKey(KeyID key) const
     242CPMKeyState::mapKeyToVirtualKey(KeyID key) const
    718243{
    719244        if (key == kKeyNone) {
     
    730255
    731256void
    732 CMSWindowsKeyState::onKey(KeyButton button, bool down, KeyModifierMask newState)
     257CPMKeyState::onKey(KeyButton button, bool down, KeyModifierMask newState)
    733258{
    734259        // handle win32 brokenness and forward to superclass
     
    739264
    740265void
    741 CMSWindowsKeyState::sendKeyEvent(void* target,
     266CPMKeyState::sendKeyEvent(void* target,
    742267                                                        bool press, bool isAutoRepeat,
    743268                                                        KeyID key, KeyModifierMask mask,
     
    765290
    766291void
    767 CMSWindowsKeyState::fakeKeyDown(KeyID id, KeyModifierMask mask,
     292CPMKeyState::fakeKeyDown(KeyID id, KeyModifierMask mask,
    768293                                KeyButton button)
    769294{
     
    772297
    773298void
    774 CMSWindowsKeyState::fakeKeyRepeat(KeyID id, KeyModifierMask mask,
     299CPMKeyState::fakeKeyRepeat(KeyID id, KeyModifierMask mask,
    775300                                SInt32 count, KeyButton button)
    776301{
     
    779304
    780305bool
    781 CMSWindowsKeyState::fakeCtrlAltDel()
    782 {
    783         if (!m_is95Family) {
    784                 // to fake ctrl+alt+del on the NT family we broadcast a suitable
    785                 // hotkey to all windows on the winlogon desktop.  however, the
    786                 // current thread must be on that desktop to do the broadcast
    787                 // and we can't switch just any thread because some own windows
    788                 // or hooks.  so start a new thread to do the real work.
    789                 CThread cad(new CFunctionJob(&CMSWindowsKeyState::ctrlAltDelThread));
    790                 cad.wait();
    791         }
    792         else {
    793                 // simulate ctrl+alt+del
    794                 fakeKeyDown(kKeyDelete, KeyModifierControl | KeyModifierAlt,
    795                                                         virtualKeyToButton(VK_DELETE));
    796         }
    797         return true;
    798 }
    799 
    800 void
    801 CMSWindowsKeyState::ctrlAltDelThread(void*)
    802 {
    803         // get the Winlogon desktop at whatever privilege we can
    804         HDESK desk = OpenDesktop("Winlogon", 0, FALSE, MAXIMUM_ALLOWED);
    805         if (desk != NULL) {
    806                 if (SetThreadDesktop(desk)) {
    807                         PostMessage(HWND_BROADCAST, WM_HOTKEY, 0,
    808                                                 MAKELPARAM(MOD_CONTROL | MOD_ALT, VK_DELETE));
    809                 }
    810                 else {
    811                         LOG((CLOG_DEBUG "can't switch to Winlogon desk: %d", GetLastError()));
    812                 }
    813                 CloseDesktop(desk);
    814         }
    815         else {
    816                 LOG((CLOG_DEBUG "can't open Winlogon desk: %d", GetLastError()));
    817         }
     306CPMKeyState::fakeCtrlAltDel()
     307{
     308    fakeKeyDown(kKeyDelete, KeyModifierControl | KeyModifierAlt, virtualKeyToButton(VK_DELETE));
    818309}
    819310
    820311KeyModifierMask
    821 CMSWindowsKeyState::pollActiveModifiers() const
     312CPMKeyState::pollActiveModifiers() const
    822313{
    823314        KeyModifierMask state = 0;
     
    832323
    833324        // we can get toggle modifiers from the system
    834         if ((GetKeyState(VK_CAPITAL) & 0x01) != 0) {
     325        if (WinGetKeyState(HWND_DESKTOP, VK_CAPITAL) & 1) {
    835326                state |= KeyModifierCapsLock;
    836327        }
    837         if ((GetKeyState(VK_NUMLOCK) & 0x01) != 0) {
     328        if (WinGetKeyState(HWND_DESKTOP, VK_NUMLOCK) & 1) {
    838329                state |= KeyModifierNumLock;
    839330        }
    840         if ((GetKeyState(VK_SCROLL) & 0x01) != 0) {
     331        if (WinGetKeyState(HWND_DESKTOP, VK_SCROLL) & 1) {
    841332                state |= KeyModifierScrollLock;
    842333        }
     
    846337
    847338SInt32
    848 CMSWindowsKeyState::pollActiveGroup() const
     339CPMKeyState::pollActiveGroup() const
    849340{
    850341        // determine the thread that'll receive this event
    851342        HWND  targetWindow = GetForegroundWindow();
    852         DWORD targetThread = GetWindowThreadProcessId(targetWindow, NULL);
     343        ULONG targetThread = GetWindowThreadProcessId(targetWindow, NULL);
    853344
    854345        // get keyboard layout for the thread
     
    866357
    867358void
    868 CMSWindowsKeyState::pollPressedKeys(KeyButtonSet& pressedKeys) const
     359CPMKeyState::pollPressedKeys(KeyButtonSet& pressedKeys) const
    869360{
    870361        BYTE keyState[256];
     
    878369
    879370void
    880 CMSWindowsKeyState::getKeyMap(CKeyMap& keyMap)
     371CPMKeyState::getKeyMap(CKeyMap& keyMap)
    881372{
    882373        // update keyboard groups
     
    1185676
    1186677void
    1187 CMSWindowsKeyState::fakeKey(const Keystroke& keystroke)
     678CPMKeyState::fakeKey(const Keystroke& keystroke)
    1188679{
    1189680        switch (keystroke.m_type) {
     
    1241732
    1242733KeyModifierMask&
    1243 CMSWindowsKeyState::getActiveModifiersRValue()
     734CPMKeyState::getActiveModifiersRValue()
    1244735{
    1245736        if (m_useSavedModifiers) {
     
    1252743
    1253744bool
    1254 CMSWindowsKeyState::getGroups(GroupList& groups) const
     745CPMKeyState::getGroups(GroupList& groups) const
    1255746{
    1256747        // get keyboard layouts
     
    1275766
    1276767void
    1277 CMSWindowsKeyState::setWindowGroup(SInt32 group)
     768CPMKeyState::setWindowGroup(SInt32 group)
    1278769{
    1279770        HWND targetWindow = GetForegroundWindow();
     
    1294785
    1295786void
    1296 CMSWindowsKeyState::fixKeys()
     787CPMKeyState::fixKeys()
    1297788{
    1298789        // fake key releases for the windows keys if we think they're
     
    1347838                m_fixTimer = EVENTQUEUE->newTimer(0.1, NULL);
    1348839                EVENTQUEUE->adoptHandler(CEvent::kTimer, m_fixTimer,
    1349                                                         new TMethodEventJob<CMSWindowsKeyState>(
    1350                                                                 this, &CMSWindowsKeyState::handleFixKeys));
     840                                                        new TMethodEventJob<CPMKeyState>(
     841                                                                this, &CPMKeyState::handleFixKeys));
    1351842        }
    1352843        else if (!fix && m_fixTimer != NULL) {
     
    1359850
    1360851void
    1361 CMSWindowsKeyState::handleFixKeys(const CEvent&, void*)
     852CPMKeyState::handleFixKeys(const CEvent&, void*)
    1362853{
    1363854        fixKeys();
     
    1365856
    1366857KeyID
    1367 CMSWindowsKeyState::getKeyID(UINT virtualKey, KeyButton button)
     858CPMKeyState::getKeyID(UINT virtualKey, KeyButton button)
    1368859{
    1369860        if ((button & 0x100u) != 0) {
     
    1374865
    1375866KeyID
    1376 CMSWindowsKeyState::getIDForKey(CKeyMap::KeyItem& item,
     867CPMKeyState::getIDForKey(CKeyMap::KeyItem& item,
    1377868                                KeyButton button, UINT virtualKey,
    1378869                                PBYTE keyState, HKL hkl) const
     
    1412903
    1413904void
    1414 CMSWindowsKeyState::addKeyEntry(CKeyMap& keyMap, CKeyMap::KeyItem& item)
     905CPMKeyState::addKeyEntry(CKeyMap& keyMap, CKeyMap::KeyItem& item)
    1415906{
    1416907        keyMap.addKeyEntry(item);
  • trunk/synergy/lib/platform/CPMKeyState.h

    r2751 r2752  
    22 * synergy -- mouse and keyboard sharing utility
    33 * Copyright (C) 2003 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 #ifndef CMSWINDOWSKEYSTATE_H
    16 #define CMSWINDOWSKEYSTATE_H
     16#ifndef CPMKEYSTATE_H
     17#define CPMKEYSTATE_H
    1718
    1819#include "CKeyState.h"
    1920#include "CString.h"
    2021#include "stdvector.h"
    21 #define WIN32_LEAN_AND_MEAN
    22 #include <windows.h>
     22#define INCL_ERRORS
     23#define INCL_BASE
     24#define INCL_PM
     25#include <os2.h>
    2326
    2427class CEvent;
    2528class CEventQueueTimer;
    26 class CMSWindowsDesks;
    2729
    2830//! Microsoft Windows key mapper
     
    3032This class maps KeyIDs to keystrokes.
    3133*/
    32 class CMSWindowsKeyState : public CKeyState {
     34class CPMKeyState : public CKeyState {
    3335public:
    34         CMSWindowsKeyState(CMSWindowsDesks* desks, void* eventTarget);
    35         virtual ~CMSWindowsKeyState();
     36        CPMKeyState(void* eventTarget);
     37        virtual ~CPMKeyState();
    3638
    3739        //! @name manipulators
     
    4446        */
    4547        void                            disable();
    46 
    47         //! Set the active keyboard layout
    48         /*!
    49         Uses \p keyLayout when querying the keyboard.
    50         */
    51         void                            setKeyLayout(HKL keyLayout);
    5248
    5349        //! Test and set autorepeat state
     
    8783        Returns the button for the \p virtualKey.
    8884        */
    89         KeyButton                       virtualKeyToButton(UINT virtualKey) const;
     85        KeyButton                       virtualKeyToButton(ULONG virtualKey) const;
    9086
    9187        //! Map key event to a key
     
    9490        to a modifier mask.
    9591        */
    96         KeyID                           mapKeyFromEvent(WPARAM charAndVirtKey,
    97                                                         LPARAM info, KeyModifierMask* maskOut) const;
     92        KeyID                           mapKeyFromEvent(MPARAM charAndVirtKey, MPARAM info, KeyModifierMask* maskOut) const;
    9893
    9994        //! Check if keyboard groups have changed
     
    109104        key.
    110105        */
    111         UINT                            mapKeyToVirtualKey(KeyID key) const;
     106        ULONG                           mapKeyToVirtualKey(KeyID key) const;
    112107
    113108        //! Map virtual key and button to KeyID
     
    117112        no such key.
    118113        */
    119         static KeyID            getKeyID(UINT virtualKey, KeyButton button);
     114        static KeyID            getKeyID(ULONG virtualKey, KeyButton button);
    120115
    121116        //@}
     
    148143
    149144private:
    150         typedef std::vector<HKL> GroupList;
    151 
    152         // send ctrl+alt+del hotkey event on NT family
    153         static void                     ctrlAltDelThread(void*);
    154 
    155         bool                            getGroups(GroupList&) const;
    156         void                            setWindowGroup(SInt32 group);
    157 
    158145        void                            fixKeys();
    159146        void                            handleFixKeys(const CEvent&, void*);
    160147
    161148        KeyID                           getIDForKey(CKeyMap::KeyItem& item,
    162                                                         KeyButton button, UINT virtualKey,
    163                                                         PBYTE keyState, HKL hkl) const;
     149                                                        KeyButton button, ULONG virtualKey,
     150                                                        PBYTE keyState) const;
    164151
    165152        void                            addKeyEntry(CKeyMap& keyMap, CKeyMap::KeyItem& item);
     
    167154private:
    168155        // not implemented
    169         CMSWindowsKeyState(const CMSWindowsKeyState&);
    170         CMSWindowsKeyState& operator=(const CMSWindowsKeyState&);
     156        CPMKeyState(const CPMKeyState&);
     157        CPMKeyState& operator=(const CPMKeyState&);
    171158
    172159private:
    173         typedef std::map<HKL, SInt32> GroupMap;
    174         typedef std::map<KeyID, UINT> KeyToVKMap;
     160        typedef std::map<KeyID, ULONG> KeyToVKMap;
    175161
    176         bool                            m_is95Family;
    177162        void*                           m_eventTarget;
    178         CMSWindowsDesks*        m_desks;
    179         HKL                                     m_keyLayout;
    180         UINT                            m_buttonToVK[512];
    181         UINT                            m_buttonToNumpadVK[512];
     163        ULONG                           m_buttonToVK[512];
     164        ULONG                           m_buttonToNumpadVK[512];
    182165        KeyButton                       m_virtualKeyToButton[256];
    183166        KeyToVKMap                      m_keyToVKMap;
     
    185168        // the timer used to check for fixing key state
    186169        CEventQueueTimer*       m_fixTimer;
    187 
    188         // the groups (keyboard layouts)
    189         GroupList                       m_groups;
    190         GroupMap                        m_groupMap;
    191170
    192171        // the last button that we generated a key down event for.  this
     
    201180        KeyModifierMask         m_originalSavedModifiers;
    202181
    203         // pointer to ToUnicodeEx.  on win95 family this will be NULL.
    204         typedef int (WINAPI *ToUnicodeEx_t)(UINT wVirtKey,
    205                                                                                 UINT wScanCode,
    206                                                                                 PBYTE lpKeyState,
    207                                                                                 LPWSTR pwszBuff,
    208                                                                                 int cchBuff,
    209                                                                                 UINT wFlags,
    210                                                                                 HKL dwhkl);
    211         ToUnicodeEx_t           m_ToUnicodeEx;
    212 
    213         static const KeyID      s_virtualKey[];
     182        static const KeyID      s_virtualKey[0x42];
    214183};
    215184
  • trunk/synergy/lib/platform/CPMScreen.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 "CMSWindowsScreen.h"
    16 #include "CMSWindowsClipboard.h"
    17 #include "CMSWindowsDesks.h"
    18 #include "CMSWindowsEventQueueBuffer.h"
    19 #include "CMSWindowsKeyState.h"
    20 #include "CMSWindowsScreenSaver.h"
     16#include "CPMScreen.h"
     17#include "CPMClipboard.h"
     18#include "CPMEventQueueBuffer.h"
     19#include "CPMKeyState.h"
     20#include "CPMScreenSaver.h"
    2121#include "CClipboard.h"
    2222#include "CKeyMap.h"
     
    3232#include "TMethodJob.h"
    3333#include "CArch.h"
    34 #include "CArchMiscWindows.h"
     34#include "CPMUtil.h"
    3535#include <string.h>
    36 #include <pbt.h>
    3736
    3837//
    39 // add backwards compatible multihead support (and suppress bogus warning).
    40 // this isn't supported on MinGW yet AFAICT.
     38// CPMScreen
    4139//
    42 #if defined(_MSC_VER)
    43 #pragma warning(push)
    44 #pragma warning(disable: 4706) // assignment within conditional
    45 #define COMPILE_MULTIMON_STUBS
    46 #include <multimon.h>
    47 #pragma warning(pop)
    48 #endif
    49 
    50 // X button stuff
    51 #if !defined(WM_XBUTTONDOWN)
    52 #define WM_XBUTTONDOWN          0x020B
    53 #define WM_XBUTTONUP            0x020C
    54 #define WM_XBUTTONDBLCLK        0x020D
    55 #define WM_NCXBUTTONDOWN        0x00AB
    56 #define WM_NCXBUTTONUP          0x00AC
    57 #define WM_NCXBUTTONDBLCLK      0x00AD
    58 #define MOUSEEVENTF_XDOWN       0x0080
    59 #define MOUSEEVENTF_XUP         0x0100
    60 #define XBUTTON1                        0x0001
    61 #define XBUTTON2                        0x0002
    62 #endif
    63 #if !defined(VK_XBUTTON1)
    64 #define VK_XBUTTON1                     0x05
    65 #define VK_XBUTTON2                     0x06
    66 #endif
    67 
    68 // WM_POWERBROADCAST stuff
    69 #if !defined(PBT_APMRESUMEAUTOMATIC)
    70 #define PBT_APMRESUMEAUTOMATIC  0x0012
    71 #endif
    72 
    73 //
    74 // CMSWindowsScreen
    75 //
    76 
    77 HINSTANCE                               CMSWindowsScreen::s_instance = NULL;
    78 CMSWindowsScreen*               CMSWindowsScreen::s_screen   = NULL;
    79 
    80 CMSWindowsScreen::CMSWindowsScreen(bool isPrimary) :
     40
     41CPMScreen*              CPMScreen::s_screen   = NULL;
     42
     43CPMScreen::CPMScreen(bool isPrimary) :
    8144        m_isPrimary(isPrimary),
    82         m_is95Family(CArchMiscWindows::isWindows95Family()),
    8345        m_isOnScreen(m_isPrimary),
    8446        m_class(0),
    8547        m_x(0), m_y(0),
    86         m_w(0), m_h(0),
     48        m_cx(0), m_cy(0),
    8749        m_xCenter(0), m_yCenter(0),
    8850        m_multimon(false),
     
    9254        m_markReceived(0),
    9355        m_fixTimer(NULL),
    94         m_keyLayout(NULL),
    9556        m_screensaver(NULL),
    9657        m_screensaverNotify(false),
    9758        m_screensaverActive(false),
    98         m_window(NULL),
    99         m_nextClipboardWindow(NULL),
     59        m_window(NULLHANDLE),
     60        m_nextClipboardWindow(NULLHANDLE),
    10061        m_ownClipboard(false),
    101         m_desks(NULL),
    102         m_hookLibrary(NULL),
     62        m_hmodHook(NULLHANDLE),
    10363        m_init(NULL),
    10464        m_cleanup(NULL),
     
    10767        m_setMode(NULL),
    10868        m_keyState(NULL),
    109         m_hasMouse(GetSystemMetrics(SM_MOUSEPRESENT) != 0),
     69        m_hasMouse(WinQuerySysValue(HWND_DESKTOP, SV_MOUSEPRESENT) != FALSE),
    11070        m_showingMouse(false)
    11171{
    112         assert(s_instance != NULL);
    113         assert(s_screen   == NULL);
     72        assert(s_screen == NULL);
    11473
    11574        s_screen = this;
    11675        try {
    11776                if (m_isPrimary) {
    118                         m_hookLibrary = openHookLibrary("synrgyhk");
    119                 }
    120                 m_screensaver = new CMSWindowsScreenSaver();
    121                 m_desks       = new CMSWindowsDesks(m_isPrimary,
    122                                                         m_hookLibrary, m_screensaver,
    123                                                         new TMethodJob<CMSWindowsScreen>(this,
    124                                                                 &CMSWindowsScreen::updateKeysCB));
    125                 m_keyState    = new CMSWindowsKeyState(m_desks, getEventTarget());
     77                        m_hmodHook = openHookLibrary("synrgyhk");
     78                }
     79                m_screensaver = new CPMScreenSaver();
     80                m_keyState    = new CPMKeyState(getEventTarget());
    12681                updateScreenShape();
    12782                m_class       = createWindowClass();
    12883                m_window      = createWindow(m_class, "Synergy");
    12984                forceShowCursor();
    130                 LOG((CLOG_DEBUG "screen shape: %d,%d %dx%d %s", m_x, m_y, m_w, m_h, m_multimon ? "(multi-monitor)" : ""));
     85                LOG((CLOG_DEBUG "screen shape: %d,%d %dx%d %s", m_x, m_y, m_cx, m_cy, m_multimon ? "(multi-monitor)" : ""));
    13186                LOG((CLOG_DEBUG "window is 0x%08x", m_window));
    13287        }
    13388        catch (...) {
    13489                delete m_keyState;
    135                 delete m_desks;
    13690                delete m_screensaver;
    13791                destroyWindow(m_window);
    13892                destroyClass(m_class);
    139                 closeHookLibrary(m_hookLibrary);
     93                closeHookLibrary(m_hmodHook);
    14094                s_screen = NULL;
    14195                throw;
     
    14498        // install event handlers
    14599        EVENTQUEUE->adoptHandler(CEvent::kSystem, IEventQueue::getSystemTarget(),
    146                                                         new TMethodEventJob<CMSWindowsScreen>(this,
    147                                                                 &CMSWindowsScreen::handleSystemEvent));
     100                                                        new TMethodEventJob<CPMScreen>(this,
     101                                                                &CPMScreen::handleSystemEvent));
    148102
    149103        // install the platform event queue
    150         EVENTQUEUE->adoptBuffer(new CMSWindowsEventQueueBuffer);
    151 }
    152 
    153 CMSWindowsScreen::~CMSWindowsScreen()
     104        EVENTQUEUE->adoptBuffer(new CPMEventQueueBuffer);
     105}
     106
     107CPMScreen::~CPMScreen()
    154108{
    155109        assert(s_screen != NULL);
     
    159113        EVENTQUEUE->removeHandler(CEvent::kSystem, IEventQueue::getSystemTarget());
    160114        delete m_keyState;
    161         delete m_desks;
    162115        delete m_screensaver;
    163116        destroyWindow(m_window);
    164117        destroyClass(m_class);
    165         closeHookLibrary(m_hookLibrary);
     118        closeHookLibrary(m_hmodHook);
    166119        s_screen = NULL;
    167120}
    168121
    169122void
    170 CMSWindowsScreen::init(HINSTANCE instance)
    171 {
    172         assert(s_instance == NULL);
    173         assert(instance   != NULL);
    174 
    175         s_instance = instance;
    176 }
    177 
    178 HINSTANCE
    179 CMSWindowsScreen::getInstance()
    180 {
    181         return s_instance;
    182 }
    183 
    184 void
    185 CMSWindowsScreen::enable()
     123CPMScreen::enable()
    186124{
    187125        assert(m_isOnScreen == m_isPrimary);
     
    190128        m_fixTimer = EVENTQUEUE->newTimer(1.0, NULL);
    191129        EVENTQUEUE->adoptHandler(CEvent::kTimer, m_fixTimer,
    192                                                         new TMethodEventJob<CMSWindowsScreen>(this,
    193                                                                 &CMSWindowsScreen::handleFixes));
     130                                                         new TMethodEventJob<CPMScreen>(this, &CPMScreen::handleFixes));
    194131
    195132        // install our clipboard snooper
    196         m_nextClipboardWindow = SetClipboardViewer(m_window);
    197 
     133    HAB hab = CPMUtil::getHAB();
     134        m_nextClipboardWindow = WinQueryClipbrdViewer(hab);
     135    WinSetClipbrdViewer(hab, m_window);
     136
     137/// @todo start here!
    198138        // track the active desk and (re)install the hooks
    199139        m_desks->enable();
     
    201141        if (m_isPrimary) {
    202142                // set jump zones
    203                 m_setZone(m_x, m_y, m_w, m_h, getJumpZoneSize());
     143                m_setZone(m_x, m_y, m_cx, m_cy, getJumpZoneSize());
    204144
    205145                // watch jump zones
    206146                m_setMode(kHOOK_WATCH_JUMP_ZONE);
    207147        }
    208         else {
    209                 // prevent the system from entering power saving modes.  if
    210                 // it did we'd be forced to disconnect from the server and
    211                 // the server would not be able to wake us up.
    212                 CArchMiscWindows::addBusyState(CArchMiscWindows::kSYSTEM);
    213         }
    214 }
    215 
    216 void
    217 CMSWindowsScreen::disable()
     148}
     149
     150void
     151CPMScreen::disable()
    218152{
    219153        // stop tracking the active desk
     
    223157                // disable hooks
    224158                m_setMode(kHOOK_DISABLE);
    225 
    226                 // enable special key sequences on win95 family
    227                 enableSpecialKeys(true);
    228         }
    229         else {
    230                 // allow the system to enter power saving mode
    231                 CArchMiscWindows::removeBusyState(CArchMiscWindows::kSYSTEM |
    232                                                         CArchMiscWindows::kDISPLAY);
    233159        }
    234160
     
    237163
    238164        // stop snooping the clipboard
    239         ChangeClipboardChain(m_window, m_nextClipboardWindow);
     165        WinSetClipbrdViewer(m_window, m_nextClipboardWindow);
    240166        m_nextClipboardWindow = NULL;
    241167
     
    252178
    253179void
    254 CMSWindowsScreen::enter()
     180CPMScreen::enter()
    255181{
    256182        m_desks->enter();
    257183        if (m_isPrimary) {
    258                 // enable special key sequences on win95 family
    259                 enableSpecialKeys(true);
    260 
    261184                // watch jump zones
    262185                m_setMode(kHOOK_WATCH_JUMP_ZONE);
     
    272195
    273196bool
    274 CMSWindowsScreen::leave()
    275 {
    276         // get keyboard layout of foreground window.  we'll use this
    277         // keyboard layout for translating keys sent to clients.
    278         HWND window  = GetForegroundWindow();
    279         DWORD thread = GetWindowThreadProcessId(window, NULL);
    280         m_keyLayout  = GetKeyboardLayout(thread);
    281 
    282         // tell the key mapper about the keyboard layout
    283         m_keyState->setKeyLayout(m_keyLayout);
    284 
    285         // tell desk that we're leaving and tell it the keyboard layout
    286         m_desks->leave(m_keyLayout);
    287 
     197CPMScreen::leave()
     198{
    288199        if (m_isPrimary) {
    289200                // warp to center
    290201                warpCursor(m_xCenter, m_yCenter);
    291202
    292                 // disable special key sequences on win95 family
    293                 enableSpecialKeys(false);
    294 
    295203                // all messages prior to now are invalid
    296204                nextMark();
     
    312220
    313221bool
    314 CMSWindowsScreen::setClipboard(ClipboardID, const IClipboard* src)
    315 {
    316         CMSWindowsClipboard dst(m_window);
     222CPMScreen::setClipboard(ClipboardID, const IClipboard* src)
     223{
     224        CPMClipboard dst(m_window);
    317225        if (src != NULL) {
    318226                // save clipboard data
    319227                return CClipboard::copy(&dst, src);
    320228        }
    321         else {
    322                 // assert clipboard ownership
    323                 if (!dst.open(0)) {
    324                         return false;
    325                 }
    326                 dst.empty();
    327                 dst.close();
    328                 return true;
    329         }
    330 }
    331 
    332 void
    333 CMSWindowsScreen::checkClipboards()
    334 {
    335         // if we think we own the clipboard but we don't then somebody
    336         // grabbed the clipboard on this screen without us knowing.
    337         // tell the server that this screen grabbed the clipboard.
    338         //
    339         // this works around bugs in the clipboard viewer chain.
    340         // sometimes NT will simply never send WM_DRAWCLIPBOARD
    341         // messages for no apparent reason and rebooting fixes the
    342         // problem.  since we don't want a broken clipboard until the
    343         // next reboot we do this double check.  clipboard ownership
    344         // won't be reflected on other screens until we leave but at
    345         // least the clipboard itself will work.
    346         if (m_ownClipboard && !CMSWindowsClipboard::isOwnedBySynergy()) {
     229    // assert clipboard ownership
     230    if (!dst.open(0)) {
     231        return false;
     232    }
     233    dst.empty();
     234    dst.close();
     235    return true;
     236}
     237
     238void
     239CPMScreen::checkClipboards()
     240{
     241    // be careful, even if we don't have the NT bugs.
     242        if (m_ownClipboard && !CPMClipboard::isOwnedBySynergy()) {
    347243                LOG((CLOG_DEBUG "clipboard changed: lost ownership and no notification received"));
    348244                m_ownClipboard = false;
     
    353249
    354250void
    355 CMSWindowsScreen::openScreensaver(bool notify)
    356 {
    357         assert(m_screensaver != NULL);
    358 
     251CPMScreen::openScreensaver(bool notify)
     252{
    359253        m_screensaverNotify = notify;
    360         if (m_screensaverNotify) {
    361                 m_desks->installScreensaverHooks(true);
    362         }
    363         else {
     254        if (!m_screensaverNotify) {
    364255                m_screensaver->disable();
    365256        }
     
    367258
    368259void
    369 CMSWindowsScreen::closeScreensaver()
    370 {
    371         if (m_screensaver != NULL) {
    372                 if (m_screensaverNotify) {
    373                         m_desks->installScreensaverHooks(false);
    374                 }
    375                 else {
    376                         m_screensaver->enable();
    377                 }
    378         }
    379         m_screensaverNotify = false;
    380 }
    381 
    382 void
    383 CMSWindowsScreen::screensaver(bool activate)
    384 {
    385         assert(m_screensaver != NULL);
    386 
    387         if (activate) {
    388                 m_screensaver->activate();
    389         }
    390         else {
    391                 m_screensaver->deactivate();
    392         }
    393 }
    394 
    395 void
    396 CMSWindowsScreen::resetOptions()
    397 {
    398         m_desks->resetOptions();
    399 }
    400 
    401 void
    402 CMSWindowsScreen::setOptions(const COptionsList& options)
    403 {
    404         m_desks->setOptions(options);
    405 }
    406 
    407 void
    408 CMSWindowsScreen::setSequenceNumber(UInt32 seqNum)
     260CPMScreen::closeScreensaver()
     261{
     262        if (!m_screensaverNotify) {
     263                m_screensaver->enable();
     264        }
     265}
     266
     267void
     268CPMScreen::screensaver(bool activate)
     269{
     270    if (activate) {
     271        m_screensaver->activate();
     272    }
     273    else {
     274        m_screensaver->deactivate();
     275    }
     276}
     277
     278void
     279CPMScreen::resetOptions()
     280{
     281//example    m_xtestIsXineramaUnaware = true;
     282}
     283
     284void
     285CPMScreen::setOptions(const COptionsList& options)
     286{
     287    for (UInt32 i = 0, n = options.size(); i < n; i += 2) {
     288//example        if (options[i] == kOptionXTestXineramaUnaware) {
     289//example            m_xtestIsXineramaUnaware = (options[i + 1] != 0);
     290//example            LOG((CLOG_DEBUG1 "XTest is Xinerama unaware %s", m_xtestIsXineramaUnaware ? "true" : "false"));
     291//example        }
     292    }
     293}
     294
     295void
     296CPMScreen::setSequenceNumber(UInt32 seqNum)
    409297{
    410298        m_sequenceNumber = seqNum;
     
    412300
    413301bool
    414 CMSWindowsScreen::isPrimary() const
     302CPMScreen::isPrimary() const
    415303{
    416304        return m_isPrimary;
     
    418306
    419307void*
    420 CMSWindowsScreen::getEventTarget() const
    421 {
    422         return const_cast<CMSWindowsScreen*>(this);
    423 }
    424 
    425 bool
    426 CMSWindowsScreen::getClipboard(ClipboardID, IClipboard* dst) const
    427 {
    428         CMSWindowsClipboard src(m_window);
    429         CClipboard::copy(dst, &src);
    430         return true;
    431 }
    432 
    433 void
    434 CMSWindowsScreen::getShape(SInt32& x, SInt32& y, SInt32& w, SInt32& h) const
     308CPMScreen::getEventTarget() const
     309{
     310        return const_cast<CPMScreen*>(this);
     311}
     312
     313bool
     314CPMScreen::getClipboard(ClipboardID, IClipboard* dst) const
     315{
     316        CPMClipboard src(m_window);
     317        return CClipboard::copy(dst, &src);
     318}
     319
     320void
     321CPMScreen::getShape(SInt32& x, SInt32& y, SInt32& cx, SInt32& cy) const
    435322{
    436323        assert(m_class != 0);
     
    438325        x = m_x;
    439326        y = m_y;
    440         w = m_w;
    441         h = m_h;
    442 }
    443 
    444 void
    445 CMSWindowsScreen::getCursorPos(SInt32& x, SInt32& y) const
    446 {
    447         m_desks->getCursorPos(x, y);
    448 }
    449 
    450 void
    451 CMSWindowsScreen::reconfigure(UInt32 activeSides)
    452 {
    453         assert(m_isPrimary);
    454 
    455         LOG((CLOG_DEBUG "active sides: %x", activeSides));
    456         m_setSides(activeSides);
    457 }
    458 
    459 void
    460 CMSWindowsScreen::warpCursor(SInt32 x, SInt32 y)
     327        cx= m_cx;
     328        cy = m_cy;
     329}
     330
     331void
     332CPMScreen::getCursorPos(SInt32& x, SInt32& y) const
     333{
     334    CURSORINFO Info;
     335    if (WinQueryCursorInfo(HWND_DESKTOP, &Info)) {
     336        x = Info.x;
     337        y = m_cy - Info.y;
     338    } else {
     339        x = 0;
     340        y = 0;
     341    }
     342}
     343
     344void
     345CPMScreen::reconfigure(UInt32 activeSides)
     346{
     347    // do nothing.
     348}
     349
     350void
     351CPMScreen::warpCursor(SInt32 x, SInt32 y)
    461352{
    462353        // warp mouse
     
    464355
    465356        // remove all input events before and including warp
    466         MSG msg;
    467         while (PeekMessage(&msg, NULL, SYNERGY_MSG_INPUT_FIRST,
    468                                                                 SYNERGY_MSG_INPUT_LAST, PM_REMOVE)) {
     357        QMSG qmsg;
     358        while (WinPeekMsg(m_hab, &qmsg, NULLHANDLE, SYNERGY_MSG_INPUT_FIRST, SYNERGY_MSG_INPUT_LAST, PM_REMOVE)) {
    469359                // do nothing
    470360        }
     
    476366
    477367UInt32
    478 CMSWindowsScreen::registerHotKey(KeyID key, KeyModifierMask mask)
     368CPMScreen::registerHotKey(KeyID key, KeyModifierMask mask)
    479369{
    480370        // only allow certain modifiers
     
    490380        }
    491381
     382#if 1
     383    LOG((CLOG_WARN "not implemented id=%04x mask=%04x", key, mask));
     384    return 0;
     385#else
    492386        // convert to win32
    493387        UINT modifiers = 0;
     
    545439        LOG((CLOG_DEBUG "registered hotkey %s (id=%04x mask=%04x) as id=%d", CKeyMap::formatKey(key, mask).c_str(), key, mask, id));
    546440        return id;
    547 }
    548 
    549 void
    550 CMSWindowsScreen::unregisterHotKey(UInt32 id)
     441#endif
     442}
     443
     444void
     445CPMScreen::unregisterHotKey(UInt32 id)
    551446{
    552447        // look up hotkey
     
    558453        // unregister with OS
    559454        bool err;
     455#if 1
     456    err = true;
     457#else
    560458        if (i->second.getVirtualKey() != 0) {
    561459                err = !UnregisterHotKey(NULL, id);
    562         }
    563         else {
     460        } else {
    564461                err = false;
    565462        }
     463#endif
    566464        if (err) {
    567465                LOG((CLOG_WARN "failed to unregister hotkey id=%d", id));
     
    578476
    579477void
    580 CMSWindowsScreen::fakeInputBegin()
     478CPMScreen::fakeInputBegin()
    581479{
    582480        assert(m_isPrimary);
     
    589487
    590488void
    591 CMSWindowsScreen::fakeInputEnd()
     489CPMScreen::fakeInputEnd()
    592490{
    593491        assert(m_isPrimary);
     
    600498
    601499SInt32
    602 CMSWindowsScreen::getJumpZoneSize() const
     500CPMScreen::getJumpZoneSize() const
    603501{
    604502        return 1;
     
    606504
    607505bool
    608 CMSWindowsScreen::isAnyMouseButtonDown() const
     506CPMScreen::isAnyMouseButtonDown() const
    609507{
    610508        static const char* buttonToName[] = {
     
    628526
    629527void
    630 CMSWindowsScreen::getCursorCenter(SInt32& x, SInt32& y) const
     528CPMScreen::getCursorCenter(SInt32& x, SInt32& y) const
    631529{
    632530        x = m_xCenter;
     
    635533
    636534void
    637 CMSWindowsScreen::fakeMouseButton(ButtonID id, bool press) const
     535CPMScreen::fakeMouseButton(ButtonID id, bool press) const
    638536{
    639537        m_desks->fakeMouseButton(id, press);
     
    641539
    642540void
    643 CMSWindowsScreen::fakeMouseMove(SInt32 x, SInt32 y) const
     541CPMScreen::fakeMouseMove(SInt32 x, SInt32 y) const
    644542{
    645543        m_desks->fakeMouseMove(x, y);
     
    647545
    648546void
    649 CMSWindowsScreen::fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const
     547CPMScreen::fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const
    650548{
    651549        m_desks->fakeMouseRelativeMove(dx, dy);
     
    653551
    654552void
    655 CMSWindowsScreen::fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const
     553CPMScreen::fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const
    656554{
    657555        m_desks->fakeMouseWheel(xDelta, yDelta);
     
    659557
    660558void
    661 CMSWindowsScreen::updateKeys()
     559CPMScreen::updateKeys()
    662560{
    663561        m_desks->updateKeys();
     
    665563
    666564void
    667 CMSWindowsScreen::fakeKeyDown(KeyID id, KeyModifierMask mask,
     565CPMScreen::fakeKeyDown(KeyID id, KeyModifierMask mask,
    668566                                KeyButton button)
    669567{
     
    673571
    674572void
    675 CMSWindowsScreen::fakeKeyRepeat(KeyID id, KeyModifierMask mask,
     573CPMScreen::fakeKeyRepeat(KeyID id, KeyModifierMask mask,
    676574                                SInt32 count, KeyButton button)
    677575{
     
    681579
    682580void
    683 CMSWindowsScreen::fakeKeyUp(KeyButton button)
     581CPMScreen::fakeKeyUp(KeyButton button)
    684582{
    685583        CPlatformScreen::fakeKeyUp(button);
     
    688586
    689587void
    690 CMSWindowsScreen::fakeAllKeysUp()
     588CPMScreen::fakeAllKeysUp()
    691589{
    692590        CPlatformScreen::fakeAllKeysUp();
     
    695593
    696594HINSTANCE
    697 CMSWindowsScreen::openHookLibrary(const char* name)
     595CPMScreen::openHookLibrary(const char* name)
    698596{
    699597        // load the hook library
     
    729627
    730628void
    731 CMSWindowsScreen::closeHookLibrary(HINSTANCE hookLibrary) const
     629CPMScreen::closeHookLibrary(HINSTANCE hookLibrary) const
    732630{
    733631        if (hookLibrary != NULL) {
     
    737635}
    738636
    739 HCURSOR
    740 CMSWindowsScreen::createBlankCursor() const
    741 {
    742         // create a transparent cursor
    743         int cw = GetSystemMetrics(SM_CXCURSOR);
    744         int ch = GetSystemMetrics(SM_CYCURSOR);
    745         UInt8* cursorAND = new UInt8[ch * ((cw + 31) >> 2)];
    746         UInt8* cursorXOR = new UInt8[ch * ((cw + 31) >> 2)];
    747         memset(cursorAND, 0xff, ch * ((cw + 31) >> 2));
    748         memset(cursorXOR, 0x00, ch * ((cw + 31) >> 2));
    749         HCURSOR c = CreateCursor(s_instance, 0, 0, cw, ch, cursorAND, cursorXOR);
    750         delete[] cursorXOR;
    751         delete[] cursorAND;
    752         return c;
    753 }
    754 
    755 void
    756 CMSWindowsScreen::destroyCursor(HCURSOR cursor) const
    757 {
    758         if (cursor != NULL) {
    759                 DestroyCursor(cursor);
    760         }
    761 }
    762 
    763637ATOM
    764 CMSWindowsScreen::createWindowClass() const
     638CPMScreen::createWindowClass() const
    765639{
    766640        WNDCLASSEX classInfo;
    767641        classInfo.cbSize        = sizeof(classInfo);
    768642        classInfo.style         = CS_DBLCLKS | CS_NOCLOSE;
    769         classInfo.lpfnWndProc   = &CMSWindowsScreen::wndProc;
     643        classInfo.lpfnWndProc   = &CPMScreen::wndProc;
    770644        classInfo.cbClsExtra    = 0;
    771645        classInfo.cbWndExtra    = 0;
     
    781655
    782656void
    783 CMSWindowsScreen::destroyClass(ATOM windowClass) const
     657CPMScreen::destroyClass(ATOM windowClass) const
    784658{
    785659        if (windowClass != 0) {
     
    789663
    790664HWND
    791 CMSWindowsScreen::createWindow(ATOM windowClass, const char* name) const
     665CPMScreen::createWindow(ATOM windowClass, const char* name) const
    792666{
    793667        HWND window = CreateWindowEx(WS_EX_TOPMOST |
     
    809683
    810684void
    811 CMSWindowsScreen::destroyWindow(HWND hwnd) const
     685CPMScreen::destroyWindow(HWND hwnd) const
    812686{
    813687        if (hwnd != NULL) {
     
    817691
    818692void
    819 CMSWindowsScreen::sendEvent(CEvent::Type type, void* data)
     693CPMScreen::sendEvent(CEvent::Type type, void* data)
    820694{
    821695        EVENTQUEUE->addEvent(CEvent(type, getEventTarget(), data));
     
    823697
    824698void
    825 CMSWindowsScreen::sendClipboardEvent(CEvent::Type type, ClipboardID id)
     699CPMScreen::sendClipboardEvent(CEvent::Type type, ClipboardID id)
    826700{
    827701        CClipboardInfo* info   = (CClipboardInfo*)malloc(sizeof(CClipboardInfo));
     
    832706
    833707void
    834 CMSWindowsScreen::handleSystemEvent(const CEvent& event, void*)
     708CPMScreen::handleSystemEvent(const CEvent& event, void*)
    835709{
    836710        MSG* msg = reinterpret_cast<MSG*>(event.getData());
     
    848722
    849723void
    850 CMSWindowsScreen::updateButtons()
     724CPMScreen::updateButtons()
    851725{
    852726        int numButtons               = GetSystemMetrics(SM_CMOUSEBUTTONS);
     
    862736
    863737IKeyState*
    864 CMSWindowsScreen::getKeyState() const
     738CPMScreen::getKeyState() const
    865739{
    866740        return m_keyState;
     
    868742
    869743bool
    870 CMSWindowsScreen::onPreDispatch(HWND hwnd,
     744CPMScreen::onPreDispatch(HWND hwnd,
    871745                                UINT message, WPARAM wParam, LPARAM lParam)
    872746{
     
    889763
    890764bool
    891 CMSWindowsScreen::onPreDispatchPrimary(HWND,
     765CPMScreen::onPreDispatchPrimary(HWND,
    892766                                UINT message, WPARAM wParam, LPARAM lParam)
    893767{
     
    946820
    947821bool
    948 CMSWindowsScreen::onEvent(HWND, UINT msg,
     822CPMScreen::onEvent(HWND, UINT msg,
    949823                                WPARAM wParam, LPARAM lParam, LRESULT* result)
    950824{
     
    1006880                *result = TRUE;
    1007881                return true;
    1008 
    1009         case WM_DEVICECHANGE:
    1010                 forceShowCursor();
    1011                 break;
    1012 
    1013         case WM_SETTINGCHANGE:
    1014                 if (wParam == SPI_SETMOUSEKEYS) {
    1015                         forceShowCursor();
    1016                 }
    1017                 break;
    1018882        }
    1019883
     
    1022886
    1023887bool
    1024 CMSWindowsScreen::onMark(UInt32 mark)
     888CPMScreen::onMark(UInt32 mark)
    1025889{
    1026890        m_markReceived = mark;
     
    1029893
    1030894bool
    1031 CMSWindowsScreen::onKey(WPARAM wParam, LPARAM lParam)
     895CPMScreen::onKey(WPARAM wParam, LPARAM lParam)
    1032896{
    1033897        static const KeyModifierMask s_ctrlAlt =
     
    11721036
    11731037bool
    1174 CMSWindowsScreen::onHotKey(WPARAM wParam, LPARAM lParam)
     1038CPMScreen::onHotKey(WPARAM wParam, LPARAM lParam)
    11751039{
    11761040        // get the key info
     
    12191083
    12201084bool
    1221 CMSWindowsScreen::onMouseButton(WPARAM wParam, LPARAM lParam)
     1085CPMScreen::onMouseButton(WPARAM wParam, LPARAM lParam)
    12221086{
    12231087        // get which button
    1224         bool pressed    = mapPressFromEvent(wParam, lParam);
    1225         ButtonID button = mapButtonFromEvent(wParam, lParam);
     1088        bool pressed    = mapPressFromEvent((ULONG)wParam, lParam);
     1089        ButtonID button = mapButtonFromEvent((ULONG)wParam, lParam);
    12261090
    12271091        // keep our shadow key state up to date
     
    12581122
    12591123bool
    1260 CMSWindowsScreen::onMouseMove(SInt32 mx, SInt32 my)
     1124CPMScreen::onMouseMove(SInt32 mx, SInt32 my)
    12611125{
    12621126        // compute motion delta (relative to the last known
     
    12921156                static SInt32 bogusZoneSize = 10;
    12931157                if (-x + bogusZoneSize > m_xCenter - m_x ||
    1294                          x + bogusZoneSize > m_x + m_w - m_xCenter ||
     1158                         x + bogusZoneSize > m_x + m_cx - m_xCenter ||
    12951159                        -y + bogusZoneSize > m_yCenter - m_y ||
    1296                          y + bogusZoneSize > m_y + m_h - m_yCenter) {
     1160                         y + bogusZoneSize > m_y + m_cy - m_yCenter) {
    12971161                        LOG((CLOG_DEBUG "dropped bogus motion %+d,%+d", x, y));
    12981162                }
     
    13071171
    13081172bool
    1309 CMSWindowsScreen::onMouseWheel(SInt32 xDelta, SInt32 yDelta)
     1173CPMScreen::onMouseWheel(SInt32 xDelta, SInt32 yDelta)
    13101174{
    13111175        // ignore message if posted prior to last mark change
     
    13181182
    13191183bool
    1320 CMSWindowsScreen::onScreensaver(bool activated)
     1184CPMScreen::onScreensaver(bool activated)
    13211185{
    13221186        // ignore this message if there are any other screen saver
     
    13581222
    13591223bool
    1360 CMSWindowsScreen::onDisplayChange()
     1224CPMScreen::onDisplayChange()
    13611225{
    13621226        // screen resolution may have changed.  save old shape.
    1363         SInt32 xOld = m_x, yOld = m_y, wOld = m_w, hOld = m_h;
     1227        SInt32 xOld = m_x, yOld = m_y, wOld = m_cx, hOld = m_cy;
    13641228
    13651229        // update shape
     
    13671231
    13681232        // do nothing if resolution hasn't changed
    1369         if (xOld != m_x || yOld != m_y || wOld != m_w || hOld != m_h) {
     1233        if (xOld != m_x || yOld != m_y || wOld != m_cx || hOld != m_cy) {
    13701234                if (m_isPrimary) {
    13711235                        // warp mouse to center if off screen
     
    13761240                        // tell hook about resize if on screen
    13771241                        else {
    1378                                 m_setZone(m_x, m_y, m_w, m_h, getJumpZoneSize());
     1242                                m_setZone(m_x, m_y, m_cx, m_cy, getJumpZoneSize());
    13791243                        }
    13801244                }
     
    13831247                sendEvent(getShapeChangedEvent());
    13841248
    1385                 LOG((CLOG_DEBUG "screen shape: %d,%d %dx%d %s", m_x, m_y, m_w, m_h, m_multimon ? "(multi-monitor)" : ""));
     1249                LOG((CLOG_DEBUG "screen shape: %d,%d %dx%d %s", m_x, m_y, m_cx, m_cy, m_multimon ? "(multi-monitor)" : ""));
    13861250        }
    13871251
     
    13901254
    13911255bool
    1392 CMSWindowsScreen::onClipboardChange()
     1256CPMScreen::onClipboardChange()
    13931257{
    13941258        // now notify client that somebody changed the clipboard (unless
    13951259        // we're the owner).
    1396         if (!CMSWindowsClipboard::isOwnedBySynergy()) {
     1260        if (!CPMClipboard::isOwnedBySynergy()) {
    13971261                if (m_ownClipboard) {
    13981262                        LOG((CLOG_DEBUG "clipboard changed: lost ownership"));
     
    14111275
    14121276void
    1413 CMSWindowsScreen::warpCursorNoFlush(SInt32 x, SInt32 y)
     1277CPMScreen::warpCursorNoFlush(SInt32 x, SInt32 y)
    14141278{
    14151279        // send an event that we can recognize before the mouse warp
    1416         PostThreadMessage(GetCurrentThreadId(), SYNERGY_MSG_PRE_WARP, x, y);
     1280    WinPostQueueMsg(m_hmq, SYNERGY_MSG_PRE_WARP, (MPARAM)x, (MPARAM)y);
    14171281
    14181282        // warp mouse.  hopefully this inserts a mouse motion event
    14191283        // between the previous message and the following message.
    1420         SetCursorPos(x, y);
     1284    WinSetPointerPos(HWND_DESKTOP, x, y);
    14211285
    14221286        // yield the CPU.  there's a race condition when warping:
     
    14391303
    14401304        // send an event that we can recognize after the mouse warp
    1441         PostThreadMessage(GetCurrentThreadId(), SYNERGY_MSG_POST_WARP, 0, 0);
    1442 }
    1443 
    1444 void
    1445 CMSWindowsScreen::nextMark()
     1305    WinPostQueueMsg(m_hmq, SYNERGY_MSG_POST_WARP, 0, 0);
     1306}
     1307
     1308void
     1309CPMScreen::nextMark()
    14461310{
    14471311        // next mark
     
    14491313
    14501314        // mark point in message queue where the mark was changed
    1451         PostThreadMessage(GetCurrentThreadId(), SYNERGY_MSG_MARK, m_mark, 0);
    1452 }
    1453 
    1454 bool
    1455 CMSWindowsScreen::ignore() const
     1315    WinPostQueueMsg(m_hmq, SYNERGY_MSG_MARK, (MPARAM)m_mark, 0);
     1316}
     1317
     1318bool
     1319CPMScreen::ignore() const
    14561320{
    14571321        return (m_mark != m_markReceived);
     
    14591323
    14601324void
    1461 CMSWindowsScreen::updateScreenShape()
     1325CPMScreen::updateScreenShape()
    14621326{
    14631327        // get shape
    1464         m_x = GetSystemMetrics(SM_XVIRTUALSCREEN);
    1465         m_y = GetSystemMetrics(SM_YVIRTUALSCREEN);
    1466         m_w = GetSystemMetrics(SM_CXVIRTUALSCREEN);
    1467         m_h = GetSystemMetrics(SM_CYVIRTUALSCREEN);
     1328        m_x = 0;
     1329        m_y = 0;
     1330        m_cx = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
     1331        m_cy = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
    14681332
    14691333        // get center for cursor
    1470         m_xCenter = GetSystemMetrics(SM_CXSCREEN) >> 1;
    1471         m_yCenter = GetSystemMetrics(SM_CYSCREEN) >> 1;
     1334        m_xCenter = m_cx / 2;
     1335        m_yCenter = m_cy / 2;
    14721336
    14731337        // check for multiple monitors
    1474         m_multimon = (m_w != GetSystemMetrics(SM_CXSCREEN) ||
    1475                                   m_h != GetSystemMetrics(SM_CYSCREEN));
    1476 
    1477         // tell the desks
    1478         m_desks->setShape(m_x, m_y, m_w, m_h, m_xCenter, m_yCenter, m_multimon);
    1479 }
    1480 
    1481 void
    1482 CMSWindowsScreen::handleFixes(const CEvent&, void*)
    1483 {
    1484         // fix clipboard chain
    1485         fixClipboardViewer();
    1486 
     1338        m_multimon = false;
     1339}
     1340
     1341void
     1342CPMScreen::handleFixes(const CEvent&, void*)
     1343{
    14871344        // update keys if keyboard layouts have changed
    14881345        if (m_keyState->didGroupsChange()) {
     
    14911348}
    14921349
    1493 void
    1494 CMSWindowsScreen::fixClipboardViewer()
    1495 {
    1496         // XXX -- disable this code for now.  somehow it can cause an infinite
    1497         // recursion in the WM_DRAWCLIPBOARD handler.  either we're sending
    1498         // the message to our own window or some window farther down the chain
    1499         // forwards the message to our window or a window farther up the chain.
    1500         // i'm not sure how that could happen.  the m_nextClipboardWindow = NULL
    1501         // was not in the code that infinite loops and may fix the bug but i
    1502         // doubt it.
    1503         return;
    1504         ChangeClipboardChain(m_window, m_nextClipboardWindow);
    1505         m_nextClipboardWindow = NULL;
    1506         m_nextClipboardWindow = SetClipboardViewer(m_window);
    1507 }
    1508 
    1509 void
    1510 CMSWindowsScreen::enableSpecialKeys(bool enable) const
    1511 {
    1512         // enable/disable ctrl+alt+del, alt+tab, etc on win95 family.
    1513         // since the win95 family doesn't support low-level hooks, we
    1514         // use this undocumented feature to suppress normal handling
    1515         // of certain key combinations.
    1516         if (m_is95Family) {
    1517                 DWORD dummy = 0;
    1518                 SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,
    1519                                                         enable ? FALSE : TRUE, &dummy, 0);
    1520         }
    1521 }
    1522 
    15231350ButtonID
    1524 CMSWindowsScreen::mapButtonFromEvent(WPARAM msg, LPARAM button) const
    1525 {
     1351CPMScreen::mapButtonFromEvent(ULONG msg, MPARAM button) const
     1352{
     1353    /** @todo query which is left and which is right. */
     1354
    15261355        switch (msg) {
    1527         case WM_LBUTTONDOWN:
    1528         case WM_LBUTTONDBLCLK:
    1529         case WM_LBUTTONUP:
    1530         case WM_NCLBUTTONDOWN:
    1531         case WM_NCLBUTTONDBLCLK:
    1532         case WM_NCLBUTTONUP:
    1533                 return kButtonLeft;
    1534 
    1535         case WM_MBUTTONDOWN:
    1536         case WM_MBUTTONDBLCLK:
    1537         case WM_MBUTTONUP:
    1538         case WM_NCMBUTTONDOWN:
    1539         case WM_NCMBUTTONDBLCLK:
    1540         case WM_NCMBUTTONUP:
    1541                 return kButtonMiddle;
    1542 
    1543         case WM_RBUTTONDOWN:
    1544         case WM_RBUTTONDBLCLK:
    1545         case WM_RBUTTONUP:
    1546         case WM_NCRBUTTONDOWN:
    1547         case WM_NCRBUTTONDBLCLK:
    1548         case WM_NCRBUTTONUP:
    1549                 return kButtonRight;
    1550 
    1551         case WM_XBUTTONDOWN:
    1552         case WM_XBUTTONDBLCLK:
    1553         case WM_XBUTTONUP:
    1554         case WM_NCXBUTTONDOWN:
    1555         case WM_NCXBUTTONDBLCLK:
    1556         case WM_NCXBUTTONUP:
    1557                 switch (button) {
    1558                 case XBUTTON1:
    1559                         if (GetSystemMetrics(SM_CMOUSEBUTTONS) >= 4) {
    1560                                 return kButtonExtra0 + 0;
    1561                         }
    1562                         break;
    1563 
    1564                 case XBUTTON2:
    1565                         if (GetSystemMetrics(SM_CMOUSEBUTTONS) >= 5) {
    1566                                 return kButtonExtra0 + 1;
    1567                         }
    1568                         break;
    1569                 }
    1570                 return kButtonNone;
    1571 
    1572         default:
    1573                 return kButtonNone;
    1574         }
    1575 }
    1576 
    1577 bool
    1578 CMSWindowsScreen::mapPressFromEvent(WPARAM msg, LPARAM) const
     1356        case WM_BUTTON1DOWN:
     1357        case WM_BUTTON1UP:
     1358        case WM_BUTTON1DBLCLK:
     1359        case WM_BUTTON1CLICK: //??
     1360                    return kButtonLeft;
     1361
     1362        case WM_BUTTON2DOWN:
     1363        case WM_BUTTON2UP:
     1364        case WM_BUTTON2DBLCLK:
     1365        case WM_BUTTON2CLICK: //??
     1366            return kButtonLeft;
     1367
     1368        case WM_BUTTON3DOWN:
     1369        case WM_BUTTON3UP:
     1370        case WM_BUTTON3DBLCLK:
     1371        case WM_BUTTON3CLICK: //??
     1372            return kButtonMiddle;
     1373        default:
     1374                return kButtonNone;
     1375        }
     1376}
     1377
     1378bool
     1379CPMScreen::mapPressFromEvent(ULONG msg, LPARAM) const
    15791380{
    15801381        switch (msg) {
    1581         case WM_LBUTTONDOWN:
    1582         case WM_MBUTTONDOWN:
    1583         case WM_RBUTTONDOWN:
    1584         case WM_XBUTTONDOWN:
    1585         case WM_LBUTTONDBLCLK:
    1586         case WM_MBUTTONDBLCLK:
    1587         case WM_RBUTTONDBLCLK:
    1588         case WM_XBUTTONDBLCLK:
    1589         case WM_NCLBUTTONDOWN:
    1590         case WM_NCMBUTTONDOWN:
    1591         case WM_NCRBUTTONDOWN:
    1592         case WM_NCXBUTTONDOWN:
    1593         case WM_NCLBUTTONDBLCLK:
    1594         case WM_NCMBUTTONDBLCLK:
    1595         case WM_NCRBUTTONDBLCLK:
    1596         case WM_NCXBUTTONDBLCLK:
    1597                 return true;
    1598 
    1599         case WM_LBUTTONUP:
    1600         case WM_MBUTTONUP:
    1601         case WM_RBUTTONUP:
    1602         case WM_XBUTTONUP:
    1603         case WM_NCLBUTTONUP:
    1604         case WM_NCMBUTTONUP:
    1605         case WM_NCRBUTTONUP:
    1606         case WM_NCXBUTTONUP:
    1607                 return false;
    1608 
    1609         default:
    1610                 return false;
    1611         }
    1612 }
    1613 
    1614 void
    1615 CMSWindowsScreen::updateKeysCB(void*)
     1382        case WM_BUTTON1DOWN:
     1383        case WM_BUTTON1CLICK: //??
     1384        case WM_BUTTON1DBLCLK:
     1385        case WM_BUTTON2DOWN:
     1386        case WM_BUTTON2DBLCLK:
     1387        case WM_BUTTON2CLICK: //??
     1388        case WM_BUTTON3DOWN:
     1389        case WM_BUTTON3DBLCLK:
     1390        case WM_BUTTON3CLICK: //??
     1391            return true;
     1392        case WM_BUTTON1UP:
     1393        case WM_BUTTON2UP:
     1394        case WM_BUTTON3UP:
     1395            return false;
     1396        default:
     1397            return false;
     1398        }
     1399}
     1400
     1401void
     1402CPMScreen::updateKeysCB(void*)
    16161403{
    16171404        // record which keys we think are down
     
    16461433
    16471434void
    1648 CMSWindowsScreen::forceShowCursor()
    1649 {
    1650         // check for mouse
    1651         m_hasMouse = (GetSystemMetrics(SM_MOUSEPRESENT) != 0);
     1435CPMScreen::forceShowCursor()
     1436{
     1437        // check for mouse - probably not required.
     1438        m_hasMouse = WinQuerySysValue(HWND_DESKTOP, SV_MOUSEPRESENT) != FALSE;
    16521439
    16531440        // decide if we should show the mouse
     
    16561443        // show/hide the mouse
    16571444        if (showMouse != m_showingMouse) {
    1658                 if (showMouse) {
    1659                         m_oldMouseKeys.cbSize = sizeof(m_oldMouseKeys);
    1660                         m_gotOldMouseKeys =
    1661                                 (SystemParametersInfo(SPI_GETMOUSEKEYS,
    1662                                                         m_oldMouseKeys.cbSize,  &m_oldMouseKeys, 0) != 0);
    1663                         if (m_gotOldMouseKeys) {
    1664                                 m_mouseKeys    = m_oldMouseKeys;
    1665                                 m_showingMouse = true;
    1666                                 updateForceShowCursor();
    1667                         }
    1668                 }
    1669                 else {
    1670                         if (m_gotOldMouseKeys) {
    1671                                 SystemParametersInfo(SPI_SETMOUSEKEYS,
    1672                                                         m_oldMouseKeys.cbSize,
    1673                                                         &m_oldMouseKeys, SPIF_SENDCHANGE);
    1674                                 m_showingMouse = false;
    1675                         }
    1676                 }
    1677         }
    1678 }
    1679 
    1680 void
    1681 CMSWindowsScreen::updateForceShowCursor()
    1682 {
    1683         DWORD oldFlags = m_mouseKeys.dwFlags;
    1684 
    1685         // turn on MouseKeys
    1686         m_mouseKeys.dwFlags = MKF_AVAILABLE | MKF_MOUSEKEYSON;
    1687 
    1688         // make sure MouseKeys is active in whatever state the NumLock is
    1689         // not currently in.
    1690         if ((m_keyState->getActiveModifiers() & KeyModifierNumLock) != 0) {
    1691                 m_mouseKeys.dwFlags |= MKF_REPLACENUMBERS;
    1692         }
    1693 
    1694         // update MouseKeys
    1695         if (oldFlags != m_mouseKeys.dwFlags) {
    1696                 SystemParametersInfo(SPI_SETMOUSEKEYS,
    1697                                                         m_mouseKeys.cbSize, &m_mouseKeys, SPIF_SENDCHANGE);
    1698         }
    1699 }
    1700 
    1701 LRESULT CALLBACK
    1702 CMSWindowsScreen::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
     1445        WinShowPointer(HWND_DESKTOP, showMouse);
     1446        m_showingMouse = WinQuerySysValue(HWND_DESKTOP, SV_POINTERLEVEL) != 0;
     1447        }
     1448}
     1449
     1450void
     1451CPMScreen::updateForceShowCursor()
     1452{
     1453    //???
     1454}
     1455
     1456HRESULT EXPENTRY
     1457CPMScreen::wndProc(HWND hwnd, UINT msg, MPARAM mp1, MPARAM mp2)
    17031458{
    17041459        assert(s_screen != NULL);
    17051460
    1706         LRESULT result = 0;
    1707         if (!s_screen->onEvent(hwnd, msg, wParam, lParam, &result)) {
    1708                 result = DefWindowProc(hwnd, msg, wParam, lParam);
    1709         }
    1710 
    1711         return result;
     1461        HRESULT mr = 0;
     1462        if (!s_screen->onEvent(hwnd, msg, mp1, mp2, &result)) {
     1463                mr = WinDefWindowProc(hwnd, msg, mp1, mp2);
     1464        }
     1465
     1466        return mr;
    17121467}
    17131468
    17141469
    17151470//
    1716 // CMSWindowsScreen::CHotKeyItem
     1471// CPMScreen::CHotKeyItem
    17171472//
    17181473
    1719 CMSWindowsScreen::CHotKeyItem::CHotKeyItem(UINT keycode, UINT mask) :
     1474CPMScreen::CHotKeyItem::CHotKeyItem(UINT keycode, UINT mask) :
    17201475        m_keycode(keycode),
    17211476        m_mask(mask)
     
    17251480
    17261481UINT
    1727 CMSWindowsScreen::CHotKeyItem::getVirtualKey() const
     1482CPMScreen::CHotKeyItem::getVirtualKey() const
    17281483{
    17291484        return m_keycode;
     
    17311486
    17321487bool
    1733 CMSWindowsScreen::CHotKeyItem::operator<(const CHotKeyItem& x) const
     1488CPMScreen::CHotKeyItem::operator<(const CHotKeyItem& x) const
    17341489{
    17351490        return (m_keycode < x.m_keycode ||
  • trunk/synergy/lib/platform/CPMScreen.h

    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 #ifndef CMSWINDOWSSCREEN_H
    16 #define CMSWINDOWSSCREEN_H
     16#ifndef CPMSCREEN_H
     17#define CPMSCREEN_H
    1718
    1819#include "CPlatformScreen.h"
    19 #include "CSynergyHook.h"
     20#include "CPMSynergyHook.h"
    2021#include "CCondVar.h"
    2122#include "CMutex.h"
    2223#include "CString.h"
    23 #define WIN32_LEAN_AND_MEAN
    24 #include <windows.h>
     24#define INCL_ERRORS
     25#define INCL_BASE
     26#define INCL_PM
     27#include <os2.h>
     28
    2529
    2630class CEventQueueTimer;
    27 class CMSWindowsDesks;
    28 class CMSWindowsKeyState;
    29 class CMSWindowsScreenSaver;
     31class CPMDesks;
     32class CPMKeyState;
     33class CPMScreenSaver;
    3034class CThread;
    3135
    32 //! Implementation of IPlatformScreen for Microsoft Windows
    33 class CMSWindowsScreen : public CPlatformScreen {
     36//! Implementation of IPlatformScreen for PM
     37class CPMScreen : public CPlatformScreen {
    3438public:
    35         CMSWindowsScreen(bool isPrimary);
    36         virtual ~CMSWindowsScreen();
    37 
    38         //! @name manipulators
    39         //@{
    40 
    41         //! Initialize
    42         /*!
    43         Saves the application's HINSTANCE.  This \b must be called by
    44         WinMain with the HINSTANCE it was passed.
    45         */
    46         static void                     init(HINSTANCE);
    47 
    48         //@}
    49         //! @name accessors
    50         //@{
    51 
    52         //! Get instance
    53         /*!
    54         Returns the application instance handle passed to init().
    55         */
    56         static HINSTANCE        getInstance();
    57 
    58         //@}
     39        CPMScreen(bool isPrimary);
     40        virtual ~CPMScreen();
    5941
    6042        // IScreen overrides
    6143        virtual void*           getEventTarget() const;
    6244        virtual bool            getClipboard(ClipboardID id, IClipboard*) const;
    63         virtual void            getShape(SInt32& x, SInt32& y,
    64                                                         SInt32& width, SInt32& height) const;
     45        virtual void            getShape(SInt32& x, SInt32& y, SInt32& cx, SInt32& cy) const;
    6546        virtual void            getCursorPos(SInt32& x, SInt32& y) const;
    6647
     
    11596private:
    11697        // initialization and shutdown operations
    117         HINSTANCE                       openHookLibrary(const char* name);
    118         void                            closeHookLibrary(HINSTANCE hookLibrary) const;
    119         HCURSOR                         createBlankCursor() const;
    120         void                            destroyCursor(HCURSOR cursor) const;
     98        HMODULE                         openHookLibrary(const char* name);
     99        void                            closeHookLibrary(HMODULE hookLibrary) const;
    121100        ATOM                            createWindowClass() const;
    122101        ATOM                            createDeskWindowClass(bool isPrimary) const;
     
    131110        // handle message before it gets dispatched.  returns true iff
    132111        // the message should not be dispatched.
    133         bool                            onPreDispatch(HWND, UINT, WPARAM, LPARAM);
     112        bool                            onPreDispatch(HWND, ULONG, MPARAM, MPARAM);
    134113
    135114        // handle message before it gets dispatched.  returns true iff
    136115        // the message should not be dispatched.
    137         bool                            onPreDispatchPrimary(HWND, UINT, WPARAM, LPARAM);
     116        bool                            onPreDispatchPrimary(HWND, ULONG, MPARAM, MPARAM);
    138117
    139118        // handle message.  returns true iff handled and optionally sets
    140119        // \c *result (which defaults to 0).
    141         bool                            onEvent(HWND, UINT, WPARAM, LPARAM, LRESULT* result);
     120        bool                            onEvent(HWND, ULONG, MPARAM, MPARAM, MRESULT*);
    142121
    143122        // message handlers
    144123        bool                            onMark(UInt32 mark);
    145         bool                            onKey(WPARAM, LPARAM);
    146         bool                            onHotKey(WPARAM, LPARAM);
    147         bool                            onMouseButton(WPARAM, LPARAM);
     124        bool                            onKey(MPARAM, MPARAM);
     125        bool                            onHotKey(MPARAM, MPARAM);
     126        bool                            onMouseButton(MPARAM, MPARAM);
    148127        bool                            onMouseMove(SInt32 x, SInt32 y);
    149128        bool                            onMouseWheel(SInt32 xDelta, SInt32 yDelta);
     
    167146        void                            handleFixes(const CEvent&, void*);
    168147
    169         // fix the clipboard viewer chain
    170         void                            fixClipboardViewer();
    171 
    172148        // enable/disable special key combinations so we can catch/pass them
    173149        void                            enableSpecialKeys(bool) const;
    174150
    175151        // map a button event to a button ID
    176         ButtonID                        mapButtonFromEvent(WPARAM msg, LPARAM button) const;
     152        ButtonID                        mapButtonFromEvent(ULONG msg, MPARAM button) const;
    177153
    178154        // map a button event to a press (true) or release (false)
    179         bool                            mapPressFromEvent(WPARAM msg, LPARAM button) const;
     155        bool                            mapPressFromEvent(ULONG msg, MPARAM button) const;
    180156
    181157        // job to update the key state
     
    193169
    194170        // our window proc
    195         static LRESULT CALLBACK wndProc(HWND, UINT, WPARAM, LPARAM);
     171        static MRESULT EXPENTRY wndProc(HWND, ULONG, MPARAM, MPARAM);
    196172
    197173private:
    198174        struct CHotKeyItem {
    199175        public:
    200                 CHotKeyItem(UINT vk, UINT modifiers);
    201 
    202                 UINT                    getVirtualKey() const;
     176                CHotKeyItem(ULONG vk, ULONG modifiers);
     177
     178                ULONG                   getVirtualKey() const;
    203179
    204180                bool                    operator<(const CHotKeyItem&) const;
    205181
    206182        private:
    207                 UINT                    m_keycode;
    208                 UINT                    m_mask;
     183                ULONG                   m_keycode;
     184                ULONG                   m_mask;
    209185        };
    210186        typedef std::map<UInt32, CHotKeyItem> HotKeyMap;
     
    212188        typedef std::map<CHotKeyItem, UInt32> HotKeyToIDMap;
    213189
    214         static HINSTANCE        s_instance;
    215 
    216190        // true if screen is being used as a primary screen, false otherwise
    217191        bool                            m_isPrimary;
    218 
    219         // true if windows 95/98/me
    220         bool                            m_is95Family;
    221 
    222         // true if mouse has entered the screen
    223192        bool                            m_isOnScreen;
    224193
     
    228197        // screen shape stuff
    229198        SInt32                          m_x, m_y;
    230         SInt32                          m_w, m_h;
     199        SInt32                          m_cx, m_cy;
    231200        SInt32                          m_xCenter, m_yCenter;
    232201
     
    245214
    246215        // the main loop's thread id
    247         DWORD                           m_threadID;
     216        int                                     m_threadID;
    248217
    249218        // timer for periodically checking stuff that requires polling
    250219        CEventQueueTimer*       m_fixTimer;
    251220
    252         // the keyboard layout to use when off primary screen
    253         HKL                                     m_keyLayout;
    254 
    255221        // screen saver stuff
    256         CMSWindowsScreenSaver*  m_screensaver;
     222        CPMScreenSaver* m_screensaver;
    257223        bool                                    m_screensaverNotify;
    258224        bool                                    m_screensaverActive;
     
    264230        bool                            m_ownClipboard;
    265231
    266         // one desk per desktop and a cond var to communicate with it
    267         CMSWindowsDesks*        m_desks;
    268 
    269232        // hook library stuff
    270         HINSTANCE                       m_hookLibrary;
     233        HMODULE                         m_hmodHook;
    271234        InitFunc                        m_init;
    272235        CleanupFunc                     m_cleanup;
     
    276239
    277240        // keyboard stuff
    278         CMSWindowsKeyState*     m_keyState;
     241        CPMKeyState*            m_keyState;
    279242
    280243        // hot key stuff
     
    286249        bool                            m_buttons[1 + kButtonExtra0 + 1];
    287250
    288         // the system shows the mouse cursor when an internal display count
    289         // is >= 0.  this count is maintained per application but there's
    290         // apparently a system wide count added to the application's count.
    291         // this system count is 0 if there's a mouse attached to the system
    292         // and -1 otherwise.  the MouseKeys accessibility feature can modify
    293         // this system count by making the system appear to have a mouse.
    294         //
    295         // m_hasMouse is true iff there's a mouse attached to the system or
    296         // MouseKeys is simulating one.  we track this so we can force the
    297         // cursor to be displayed when the user has entered this screen.
    298         // m_showingMouse is true when we're doing that.
    299251        bool                            m_hasMouse;
    300252        bool                            m_showingMouse;
    301         bool                            m_gotOldMouseKeys;
    302         MOUSEKEYS                       m_mouseKeys;
    303         MOUSEKEYS                       m_oldMouseKeys;
    304 
    305         static CMSWindowsScreen*        s_screen;
     253
     254        static CPMScreen*       s_screen;
    306255};
    307256
  • trunk/synergy/lib/platform/CPMScreenSaver.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 "CMSWindowsScreenSaver.h"
    16 #include "CMSWindowsScreen.h"
    17 #include "CThread.h"
    18 #include "CLog.h"
    19 #include "TMethodJob.h"
    20 #include "CArch.h"
    21 #include "CArchMiscWindows.h"
    22 #include <malloc.h>
    23 #include <tchar.h>
    24 
    25 #if !defined(SPI_GETSCREENSAVERRUNNING)
    26 #define SPI_GETSCREENSAVERRUNNING 114
    27 #endif
    28 
    29 static const TCHAR* g_isSecureNT = "ScreenSaverIsSecure";
    30 static const TCHAR* g_isSecure9x = "ScreenSaveUsePassword";
    31 static const TCHAR* const g_pathScreenSaverIsSecure[] = {
    32         "Control Panel",
    33         "Desktop",
    34         NULL
    35 };
     16#include "CPMScreenSaver.h"
    3617
    3718//
    38 // CMSWindowsScreenSaver
     19// CPMScreenSaver
    3920//
    4021
    41 CMSWindowsScreenSaver::CMSWindowsScreenSaver() :
    42         m_wasSecure(false),
    43         m_wasSecureAnInt(false),
    44         m_process(NULL),
    45         m_watch(NULL),
    46         m_threadID(0),
    47         m_active(false)
     22CPMScreenSaver::CPMScreenSaver()
    4823{
    49         // detect OS
    50         m_is95Family = false;
    51         m_is95       = false;
    52         m_isNT       = false;
    53         OSVERSIONINFO info;
    54         info.dwOSVersionInfoSize = sizeof(info);
    55         if (GetVersionEx(&info)) {
    56                 m_is95Family = (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS);
    57                 if (info.dwPlatformId   == VER_PLATFORM_WIN32_NT &&
    58                         info.dwMajorVersion <= 4) {
    59                         m_isNT = true;
    60                 }
    61                 else if (info.dwPlatformId  == VER_PLATFORM_WIN32_WINDOWS &&
    62                                 info.dwMajorVersion == 4 &&
    63                                 info.dwMinorVersion == 0) {
    64                         m_is95 = true;
    65                 }
    66         }
    67 
    68         // check if screen saver is enabled
    69         SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, &m_wasEnabled, 0);
    7024}
    7125
    72 CMSWindowsScreenSaver::~CMSWindowsScreenSaver()
     26CPMScreenSaver::~CPMScreenSaver()
    7327{
    74         unwatchProcess();
     28}
     29
     30void
     31CPMScreenSaver::enable()
     32{
     33}
     34
     35void
     36CPMScreenSaver::disable()
     37{
     38}
     39
     40void
     41CPMScreenSaver::activate()
     42{
     43}
     44
     45void
     46CPMScreenSaver::deactivate()
     47{
    7548}
    7649
    7750bool
    78 CMSWindowsScreenSaver::checkStarted(UINT msg, WPARAM wParam, LPARAM lParam)
     51CPMScreenSaver::isActive() const
    7952{
    80         // if already started then say it didn't just start
    81         if (m_active) {
    82                 return false;
    83         }
    84 
    85         // screen saver may have started.  look for it and get
    86         // the process.  if we can't find it then assume it
    87         // didn't really start.  we wait a moment before
    88         // looking to give the screen saver a chance to start.
    89         // this shouldn't be a problem since we only get here
    90         // if the screen saver wants to kick in, meaning that
    91         // the system is idle or the user deliberately started
    92         // the screen saver.
    93         Sleep(250);
    94 
    95         // set parameters common to all screen saver handling
    96         m_threadID = GetCurrentThreadId();
    97         m_msg      = msg;
    98         m_wParam   = wParam;
    99         m_lParam   = lParam;
    100 
    101         // we handle the screen saver differently for the windows
    102         // 95 and nt families.
    103         if (m_is95Family) {
    104                 // on windows 95 we wait for the screen saver process
    105                 // to terminate.  get the process.
    106                 DWORD processID = findScreenSaver();
    107                 HANDLE process = OpenProcess(SYNCHRONIZE, FALSE, processID);
    108                 if (process == NULL) {
    109                         // didn't start
    110                         LOG((CLOG_DEBUG2 "can't open screen saver process"));
    111                         return false;
    112                 }
    113 
    114                 // watch for the process to exit
    115                 watchProcess(process);
    116         }
    117         else {
    118                 // on the windows nt family we wait for the desktop to
    119                 // change until it's neither the Screen-Saver desktop
    120                 // nor a desktop we can't open (the login desktop).
    121                 // since windows will send the request-to-start-screen-
    122                 // saver message even when the screen saver is disabled
    123                 // we first check that the screen saver is indeed active
    124                 // before watching for it to stop.
    125                 if (!isActive()) {
    126                         LOG((CLOG_DEBUG2 "can't open screen saver desktop"));
    127                         return false;
    128                 }
    129 
    130                 watchDesktop();
    131         }
    132 
    133         return true;
     53    return false;
    13454}
    13555
    136 void
    137 CMSWindowsScreenSaver::enable()
    138 {
    139         SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, m_wasEnabled, 0, 0);
    140 
    141         // restore password protection
    142         if (m_wasSecure) {
    143                 setSecure(true, m_wasSecureAnInt);
    144         }
    145 
    146         // restore display power down
    147         CArchMiscWindows::removeBusyState(CArchMiscWindows::kDISPLAY);
    148 }
    149 
    150 void
    151 CMSWindowsScreenSaver::disable()
    152 {
    153         SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, &m_wasEnabled, 0);
    154         SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE, 0, 0);
    155 
    156         // disable password protected screensaver
    157         m_wasSecure = isSecure(&m_wasSecureAnInt);
    158         if (m_wasSecure) {
    159                 setSecure(false, m_wasSecureAnInt);
    160         }
    161 
    162         // disable display power down
    163         CArchMiscWindows::addBusyState(CArchMiscWindows::kDISPLAY);
    164 }
    165 
    166 void
    167 CMSWindowsScreenSaver::activate()
    168 {
    169         // don't activate if already active
    170         if (!isActive()) {
    171                 // activate
    172                 HWND hwnd = GetForegroundWindow();
    173                 if (hwnd != NULL) {
    174                         PostMessage(hwnd, WM_SYSCOMMAND, SC_SCREENSAVE, 0);
    175                 }
    176                 else {
    177                         // no foreground window.  pretend we got the event instead.
    178                         DefWindowProc(NULL, WM_SYSCOMMAND, SC_SCREENSAVE, 0);
    179                 }
    180 
    181                 // restore power save when screen saver activates
    182                 CArchMiscWindows::removeBusyState(CArchMiscWindows::kDISPLAY);
    183         }
    184 }
    185 
    186 void
    187 CMSWindowsScreenSaver::deactivate()
    188 {
    189         bool killed = false;
    190         if (!m_is95Family) {
    191                 // NT runs screen saver in another desktop
    192                 HDESK desktop = OpenDesktop("Screen-saver", 0, FALSE,
    193                                                                 DESKTOP_READOBJECTS | DESKTOP_WRITEOBJECTS);
    194                 if (desktop != NULL) {
    195                         EnumDesktopWindows(desktop,
    196                                                                 &CMSWindowsScreenSaver::killScreenSaverFunc,
    197                                                                 reinterpret_cast<LPARAM>(&killed));
    198                         CloseDesktop(desktop);
    199                 }
    200         }
    201 
    202         // if above failed or wasn't tried, try the windows 95 way
    203         if (!killed) {
    204                 // find screen saver window and close it
    205                 HWND hwnd = FindWindow("WindowsScreenSaverClass", NULL);
    206                 if (hwnd == NULL) {
    207                         // win2k may use a different class
    208                         hwnd = FindWindow("Default Screen Saver", NULL);
    209                 }
    210                 if (hwnd != NULL) {
    211                         PostMessage(hwnd, WM_CLOSE, 0, 0);
    212                 }
    213         }
    214 
    215         // force timer to restart
    216         SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, &m_wasEnabled, 0);
    217         SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,
    218                                                                 !m_wasEnabled, 0, SPIF_SENDWININICHANGE);
    219         SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,
    220                                                                  m_wasEnabled, 0, SPIF_SENDWININICHANGE);
    221 
    222         // disable display power down
    223         CArchMiscWindows::removeBusyState(CArchMiscWindows::kDISPLAY);
    224 }
    225 
    226 bool
    227 CMSWindowsScreenSaver::isActive() const
    228 {
    229         if (m_is95) {
    230                 return (FindWindow("WindowsScreenSaverClass", NULL) != NULL);
    231         }
    232         else if (m_isNT) {
    233                 // screen saver runs on a separate desktop
    234                 HDESK desktop = OpenDesktop("Screen-saver", 0, FALSE, MAXIMUM_ALLOWED);
    235                 if (desktop == NULL && GetLastError() != ERROR_ACCESS_DENIED) {
    236                         // desktop doesn't exist so screen saver is not running
    237                         return false;
    238                 }
    239 
    240                 // desktop exists.  this should indicate that the screen saver
    241                 // is running but an OS bug can cause a valid handle to be
    242                 // returned even if the screen saver isn't running (Q230117).
    243                 // we'll try to enumerate the windows on the desktop and, if
    244                 // there are any, we assume the screen saver is running.  (note
    245                 // that if we don't have permission to enumerate then we'll
    246                 // assume that the screen saver is not running.)  that'd be
    247                 // easy enough except there's another OS bug (Q198590) that can
    248                 // cause EnumDesktopWindows() to enumerate the windows of
    249                 // another desktop if the requested desktop has no windows.  to
    250                 // work around that we have to verify that the enumerated
    251                 // windows are, in fact, on the expected desktop.
    252                 CFindScreenSaverInfo info;
    253                 info.m_desktop = desktop;
    254                 info.m_window  = NULL;
    255                 EnumDesktopWindows(desktop,
    256                                                                 &CMSWindowsScreenSaver::findScreenSaverFunc,
    257                                                                 reinterpret_cast<LPARAM>(&info));
    258 
    259                 // done with desktop
    260                 CloseDesktop(desktop);
    261 
    262                 // screen saver is running if a window was found
    263                 return (info.m_window != NULL);
    264         }
    265         else {
    266                 BOOL running;
    267                 SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &running, 0);
    268                 return (running != FALSE);
    269         }
    270 }
    271 
    272 BOOL CALLBACK
    273 CMSWindowsScreenSaver::findScreenSaverFunc(HWND hwnd, LPARAM arg)
    274 {
    275         CFindScreenSaverInfo* info = reinterpret_cast<CFindScreenSaverInfo*>(arg);
    276 
    277         if (info->m_desktop != NULL) {
    278                 DWORD threadID = GetWindowThreadProcessId(hwnd, NULL);
    279                 HDESK desktop  = GetThreadDesktop(threadID);
    280                 if (desktop != NULL && desktop != info->m_desktop) {
    281                         // stop enumerating -- wrong desktop
    282                         return FALSE;
    283                 }
    284         }
    285 
    286         // found a window
    287         info->m_window = hwnd;
    288 
    289         // don't need to enumerate further
    290         return FALSE;
    291 }
    292 
    293 BOOL CALLBACK
    294 CMSWindowsScreenSaver::killScreenSaverFunc(HWND hwnd, LPARAM arg)
    295 {
    296         if (IsWindowVisible(hwnd)) {
    297                 HINSTANCE instance = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE);
    298                 if (instance != CMSWindowsScreen::getInstance()) {
    299                         PostMessage(hwnd, WM_CLOSE, 0, 0);
    300                         *reinterpret_cast<bool*>(arg) = true;
    301                 }
    302         }
    303         return TRUE;
    304 }
    305 
    306 DWORD
    307 CMSWindowsScreenSaver::findScreenSaver()
    308 {
    309         // try windows 95 way
    310         HWND hwnd = FindWindow("WindowsScreenSaverClass", NULL);
    311 
    312         // get process ID of process that owns the window, if found
    313         if (hwnd != NULL) {
    314                 DWORD processID;
    315                 GetWindowThreadProcessId(hwnd, &processID);
    316                 return processID;
    317         }
    318 
    319         // not found
    320         return 0;
    321 }
    322 
    323 void
    324 CMSWindowsScreenSaver::watchDesktop()
    325 {
    326         // stop watching previous process/desktop
    327         unwatchProcess();
    328 
    329         // watch desktop in another thread
    330         LOG((CLOG_DEBUG "watching screen saver desktop"));
    331         m_active = true;
    332         m_watch  = new CThread(new TMethodJob<CMSWindowsScreenSaver>(this,
    333                                                                 &CMSWindowsScreenSaver::watchDesktopThread));
    334 }
    335 
    336 void
    337 CMSWindowsScreenSaver::watchProcess(HANDLE process)
    338 {
    339         // stop watching previous process/desktop
    340         unwatchProcess();
    341 
    342         // watch new process in another thread
    343         if (process != NULL) {
    344                 LOG((CLOG_DEBUG "watching screen saver process"));
    345                 m_process = process;
    346                 m_active  = true;
    347                 m_watch   = new CThread(new TMethodJob<CMSWindowsScreenSaver>(this,
    348                                                                 &CMSWindowsScreenSaver::watchProcessThread));
    349         }
    350 }
    351 
    352 void
    353 CMSWindowsScreenSaver::unwatchProcess()
    354 {
    355         if (m_watch != NULL) {
    356                 LOG((CLOG_DEBUG "stopped watching screen saver process/desktop"));
    357                 m_watch->cancel();
    358                 m_watch->wait();
    359                 delete m_watch;
    360                 m_watch  = NULL;
    361                 m_active = false;
    362         }
    363         if (m_process != NULL) {
    364                 CloseHandle(m_process);
    365                 m_process = NULL;
    366         }
    367 }
    368 
    369 void
    370 CMSWindowsScreenSaver::watchDesktopThread(void*)
    371 {
    372         DWORD reserved = 0;
    373         TCHAR* name    = NULL;
    374 
    375         for (;;) {
    376                 // wait a bit
    377                 ARCH->sleep(0.2);
    378 
    379                 if (m_isNT) {
    380                         // get current desktop
    381                         HDESK desk = OpenInputDesktop(0, FALSE, GENERIC_READ);
    382                         if (desk == NULL) {
    383                                 // can't open desktop so keep waiting
    384                                 continue;
    385                         }
    386 
    387                         // get current desktop name length
    388                         DWORD size;
    389                         GetUserObjectInformation(desk, UOI_NAME, NULL, 0, &size);
    390 
    391                         // allocate more space for the name, if necessary
    392                         if (size > reserved) {
    393                                 reserved = size;
    394                                 name     = (TCHAR*)alloca(reserved + sizeof(TCHAR));
    395                         }
    396 
    397                         // get current desktop name
    398                         GetUserObjectInformation(desk, UOI_NAME, name, size, &size);
    399                         CloseDesktop(desk);
    400 
    401                         // compare name to screen saver desktop name
    402                         if (_tcsicmp(name, TEXT("Screen-saver")) == 0) {
    403                                 // still the screen saver desktop so keep waiting
    404                                 continue;
    405                         }
    406                 }
    407                 else {
    408                         // 2000/XP have a sane way to detect a runnin screensaver.
    409                         BOOL running;
    410                         SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &running, 0);
    411                         if (running) {
    412                                 continue;
    413                         }
    414                 }
    415 
    416                 // send screen saver deactivation message
    417                 m_active = false;
    418                 PostThreadMessage(m_threadID, m_msg, m_wParam, m_lParam);
    419                 return;
    420         }
    421 }
    422 
    423 void
    424 CMSWindowsScreenSaver::watchProcessThread(void*)
    425 {
    426         for (;;) {
    427                 CThread::testCancel();
    428                 if (WaitForSingleObject(m_process, 50) == WAIT_OBJECT_0) {
    429                         // process terminated
    430                         LOG((CLOG_DEBUG "screen saver died"));
    431 
    432                         // send screen saver deactivation message
    433                         m_active = false;
    434                         PostThreadMessage(m_threadID, m_msg, m_wParam, m_lParam);
    435                         return;
    436                 }
    437         }
    438 }
    439 
    440 void
    441 CMSWindowsScreenSaver::setSecure(bool secure, bool saveSecureAsInt)
    442 {
    443         HKEY hkey =
    444                 CArchMiscWindows::addKey(HKEY_CURRENT_USER, g_pathScreenSaverIsSecure);
    445         if (hkey == NULL) {
    446                 return;
    447         }
    448 
    449         const TCHAR* isSecure = m_is95Family ? g_isSecure9x : g_isSecureNT;
    450         if (saveSecureAsInt) {
    451                 CArchMiscWindows::setValue(hkey, isSecure, secure ? 1 : 0);
    452         }
    453         else {
    454                 CArchMiscWindows::setValue(hkey, isSecure, secure ? "1" : "0");
    455         }
    456 
    457         CArchMiscWindows::closeKey(hkey);
    458 }
    459 
    460 bool
    461 CMSWindowsScreenSaver::isSecure(bool* wasSecureFlagAnInt) const
    462 {
    463         // get the password protection setting key
    464         HKEY hkey =
    465                 CArchMiscWindows::openKey(HKEY_CURRENT_USER, g_pathScreenSaverIsSecure);
    466         if (hkey == NULL) {
    467                 return false;
    468         }
    469 
    470         // get the value.  the value may be an int or a string, depending
    471         // on the version of windows.
    472         bool result;
    473         const TCHAR* isSecure = m_is95Family ? g_isSecure9x : g_isSecureNT;
    474         switch (CArchMiscWindows::typeOfValue(hkey, isSecure)) {
    475         default:
    476                 result = false;
    477                 break;
    478 
    479         case CArchMiscWindows::kUINT: {
    480                 DWORD value =
    481                         CArchMiscWindows::readValueInt(hkey, isSecure);
    482                 *wasSecureFlagAnInt = true;
    483                 result = (value != 0);
    484                 break;
    485         }
    486 
    487         case CArchMiscWindows::kSTRING: {
    488                 std::string value =
    489                         CArchMiscWindows::readValueString(hkey, isSecure);
    490                 *wasSecureFlagAnInt = false;
    491                 result = (value != "0");
    492                 break;
    493         }
    494         }
    495 
    496         CArchMiscWindows::closeKey(hkey);
    497         return result;
    498 }
  • trunk/synergy/lib/platform/CPMScreenSaver.h

    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 #ifndef CMSWINDOWSSCREENSAVER_H
    16 #define CMSWINDOWSSCREENSAVER_H
     16#ifndef CPMSCREENSAVER_H
     17#define CPMSCREENSAVER_H
    1718
    1819#include "IScreenSaver.h"
    1920#include "CString.h"
    20 #define WIN32_LEAN_AND_MEAN
    21 #include <windows.h>
     21#define INCL_ERRORS
     22#define INCL_BASE
     23#define INCL_PM
     24#include <os2.h>
    2225
    2326class CThread;
    2427
    25 //! Microsoft windows screen saver implementation
    26 class CMSWindowsScreenSaver : public IScreenSaver {
     28//! PM screen saver implementation (stub)
     29class CPMScreenSaver : public IScreenSaver {
    2730public:
    28         CMSWindowsScreenSaver();
    29         virtual ~CMSWindowsScreenSaver();
    30 
    31         //! @name manipulators
    32         //@{
    33 
    34         //! Check if screen saver started
    35         /*!
    36         Check if the screen saver really started.  Returns false if it
    37         hasn't, true otherwise.  When the screen saver stops, \c msg will
    38         be posted to the current thread's message queue with the given
    39         parameters.
    40         */
    41         bool                            checkStarted(UINT msg, WPARAM, LPARAM);
    42 
    43         //@}
     31        CPMScreenSaver();
     32        virtual ~CPMScreenSaver();
    4433
    4534        // IScreenSaver overrides
     
    5140
    5241private:
    53         class CFindScreenSaverInfo {
    54         public:
    55                 HDESK                   m_desktop;
    56                 HWND                    m_window;
    57         };
    58 
    59         static BOOL CALLBACK    findScreenSaverFunc(HWND hwnd, LPARAM lParam);
    60         static BOOL CALLBACK    killScreenSaverFunc(HWND hwnd, LPARAM lParam);
    61 
    62         DWORD                           findScreenSaver();
    63         void                            watchDesktop();
    64         void                            watchProcess(HANDLE process);
    65         void                            unwatchProcess();
    66         void                            watchDesktopThread(void*);
    67         void                            watchProcessThread(void*);
    68 
    69         void                            setSecure(bool secure, bool saveSecureAsInt);
    70         bool                            isSecure(bool* wasSecureAnInt) const;
    71 
    72 private:
    73         bool                            m_is95Family;
    74         bool                            m_is95;
    75         bool                            m_isNT;
    76         BOOL                            m_wasEnabled;
    77         bool                            m_wasSecure;
    78         bool                            m_wasSecureAnInt;
    79 
    80         HANDLE                          m_process;
    81         CThread*                        m_watch;
    82         DWORD                           m_threadID;
    83         UINT                            m_msg;
    84         WPARAM                          m_wParam;
    85         LPARAM                          m_lParam;
    86 
    87         // checkActive state.  true if the screen saver is being watched
    88         // for deactivation (and is therefore active).
    89         bool                            m_active;
    9042};
    9143
  • trunk/synergy/lib/platform/CPMSynergyHook.h

    r2751 r2752  
    1717
    1818#include "BasicTypes.h"
    19 #define WIN32_LEAN_AND_MEAN
    20 #include <windows.h>
     19#define INCL_BASE
     20#define INCL_ERRORS
     21#define INCL_PM
     22#include <os2.h>
    2123
    2224#if defined(SYNRGYHK_EXPORTS)
    23 #define CSYNERGYHOOK_API __declspec(dllexport)
     25# define CSYNERGYHOOK_API __declspec(dllexport)
    2426#else
    25 #define CSYNERGYHOOK_API __declspec(dllimport)
     27# define CSYNERGYHOOK_API __declspec(dllimport)
    2628#endif
    2729
    28 #define SYNERGY_MSG_MARK                        WM_APP + 0x0011 // mark id; <unused>
    29 #define SYNERGY_MSG_KEY                         WM_APP + 0x0012 // vk code; key data
    30 #define SYNERGY_MSG_MOUSE_BUTTON        WM_APP + 0x0013 // button msg; <unused>
    31 #define SYNERGY_MSG_MOUSE_WHEEL         WM_APP + 0x0014 // delta; <unused>
    32 #define SYNERGY_MSG_MOUSE_MOVE          WM_APP + 0x0015 // x; y
    33 #define SYNERGY_MSG_POST_WARP           WM_APP + 0x0016 // <unused>; <unused>
    34 #define SYNERGY_MSG_PRE_WARP            WM_APP + 0x0017 // x; y
    35 #define SYNERGY_MSG_SCREEN_SAVER        WM_APP + 0x0018 // activated; <unused>
    36 #define SYNERGY_MSG_DEBUG                       WM_APP + 0x0019 // data, data
     30#define SYNERGY_MSG_MARK                        WM_USER + 0x0011        // mark id; <unused>
     31#define SYNERGY_MSG_KEY                         WM_USER + 0x0012        // vk code; key data
     32#define SYNERGY_MSG_MOUSE_BUTTON        WM_USER + 0x0013        // button msg; <unused>
     33#define SYNERGY_MSG_MOUSE_WHEEL         WM_USER + 0x0014        // delta; <unused>
     34#define SYNERGY_MSG_MOUSE_MOVE          WM_USER + 0x0015        // x; y
     35#define SYNERGY_MSG_POST_WARP           WM_USER + 0x0016        // <unused>; <unused>
     36#define SYNERGY_MSG_PRE_WARP            WM_USER + 0x0017        // x; y
     37#define SYNERGY_MSG_SCREEN_SAVER        WM_USER + 0x0018        // activated; <unused>
     38#define SYNERGY_MSG_DEBUG                       WM_USER + 0x0019        // data, data
    3739#define SYNERGY_MSG_INPUT_FIRST         SYNERGY_MSG_KEY
    3840#define SYNERGY_MSG_INPUT_LAST          SYNERGY_MSG_PRE_WARP
     
    5658};
    5759
    58 typedef int                             (*InitFunc)(DWORD targetQueueThreadID);
     60typedef int                             (*InitFunc)(HMQ hmq, int tid, int pid);
    5961typedef int                             (*CleanupFunc)(void);
    6062typedef EHookResult             (*InstallFunc)(void);
     
    6668typedef void                    (*SetModeFunc)(int);
    6769
    68 CSYNERGYHOOK_API int    init(DWORD);
     70CSYNERGYHOOK_API int    init(HMQ hmq, int tid, int pid);
    6971CSYNERGYHOOK_API int    cleanup(void);
    7072CSYNERGYHOOK_API EHookResult    install(void);
     
    7375CSYNERGYHOOK_API int    uninstallScreenSaver(void);
    7476CSYNERGYHOOK_API void   setSides(UInt32 sides);
    75 CSYNERGYHOOK_API void   setZone(SInt32 x, SInt32 y, SInt32 w, SInt32 h,
    76                                                         SInt32 jumpZoneSize);
     77CSYNERGYHOOK_API void   setZone(SInt32 x, SInt32 y, SInt32 cx, SInt32 cy, SInt32 jumpZoneSize);
    7778CSYNERGYHOOK_API void   setMode(EHookMode mode);
    7879
  • trunk/synergy/lib/platform/CPMUtil.cpp

    r2751 r2752  
    22 * synergy -- mouse and keyboard sharing utility
    33 * Copyright (C) 2004 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 "CMSWindowsUtil.h"
     16#include "CPMUtil.h"
    1617#include "CStringUtil.h"
    1718#include <stdio.h>
    1819
    1920//
    20 // CMSWindowsUtil
     21// CPMUtil
    2122//
    2223
    2324CString
    24 CMSWindowsUtil::getString(HINSTANCE instance, DWORD id)
     25CPMUtil::getString(HMODULE hmod, ULONG id)
    2526{
    26         char buffer[1024];
    27         int size = static_cast<int>(sizeof(buffer) / sizeof(buffer[0]));
    28         char* msg = buffer;
     27        char szBuf[1024];
    2928
    3029        // load string
    31         int n = LoadString(instance, id, msg, size);
    32         msg[n] = '\0';
    33         if (n < size) {
    34                 return msg;
     30        LONG cch = WinLoadString(WinQueryAnchorBlock(HWND_DESKTOP), hmod, id, sizeof(szBuf), (PSZ)szBuf);
     31        if(cch < 0) {
     32                szBuf[cch] = '\0';
     33                char *psz = szBuf;
     34                return psz;
    3535        }
    36 
    37         // not enough buffer space.  keep trying larger buffers until
    38         // we get the whole string.
    39         msg = NULL;
    40         do {
    41                 size <<= 1;
    42                 delete[] msg;
    43                 char* msg = new char[size];
    44                 n = LoadString(instance, id, msg, size);
    45         } while (n == size);
    46         msg[n] = '\0';
    47 
    48         CString result(msg);
    49         delete[] msg;
    50         return result;
     36        return "";
    5137}
    5238
    5339CString
    54 CMSWindowsUtil::getErrorString(HINSTANCE hinstance, DWORD error, DWORD id)
     40CPMUtil::getErrorString(HMODULE hmod, ULONG error, ULONG id)
    5541{
     42#if 1
     43        char szMsg[80];
     44        snprintf(szMsg, sizeof(szMsg), "sys error %#lx (%d)\n", error, error);
     45        char *pszMsg = szMsg;
     46        return CString(pszMsg);
     47
     48#else
    5649        char* buffer;
    5750        if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
     
    7366                return result;
    7467        }
     68#endif
    7569}
     70
     71HAB CPMUtil::getHAB(void)
     72{
     73    return WinQueryAnchorBlock(HWND_DESKTOP);
     74}
     75
  • trunk/synergy/lib/platform/CPMUtil.h

    r2751 r2752  
    22 * synergy -- mouse and keyboard sharing utility
    33 * Copyright (C) 2004 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 #ifndef CMSWINDOWSUTIL_H
    16 #define CMSWINDOWSUTIL_H
     16#ifndef CPMUTIL_H
     17#define CPMUTIL_H
    1718
    1819#include "CString.h"
    19 #define WINDOWS_LEAN_AND_MEAN
    20 #include <windows.h>
     20#define INCL_BASE
     21#define INCL_ERRORS
     22#define INCL_PM
     23#include <os2.h>
    2124
    22 class CMSWindowsUtil {
     25class CPMUtil {
    2326public:
    2427        //! Get message string
     
    2629        Gets a string for \p id from the string table of \p instance.
    2730        */
    28         static CString          getString(HINSTANCE instance, DWORD id);
     31        static CString          getString(HMODULE hmod, ULONG id);
    2932
    3033        //! Get error string
     
    3336        found return the string for \p id, replacing ${1} with \p error.
    3437        */
    35         static CString          getErrorString(HINSTANCE, DWORD error, DWORD id);
     38        static CString          getErrorString(HMODULE hmod, ULONG error, ULONG id);
     39   
     40    static HAB          getHAB(void);
     41
    3642};
    3743
Note: See TracChangeset for help on using the changeset viewer.