Ignore:
Timestamp:
Apr 11, 2003, 4:22:06 PM (22 years ago)
Author:
sandervl
Message:

KSO: Implemented WM_COPYDATA

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/oslibmsgtranslate.cpp

    r9950 r10012  
    1 /* $Id: oslibmsgtranslate.cpp,v 1.107 2003-03-28 11:49:01 sandervl Exp $ */
     1/* $Id: oslibmsgtranslate.cpp,v 1.108 2003-04-11 14:22:06 sandervl Exp $ */
    22/*
    33 * Window message translation functions for OS/2
     
    5252//PF Correction is different for different mouse drivers. For now no correction
    5353//is ok because lots of Odin controls rely on minimum delta. However in future
    54 //we will possibly detect mouse driver and use correction if speed will be 
     54//we will possibly detect mouse driver and use correction if speed will be
    5555//too high or too low.
    56  
     56
    5757//******************************************************************************
    5858//******************************************************************************
     
    9090           ret = pmScan;
    9191  }
    92  
     92
    9393  KeyTranslatePMScanToWinVKey(ret, FALSE, (PBYTE)&winKey, NULL, NULL);
    9494  return winKey;
     
    127127}
    128128//******************************************************************************
     129
     130
     131/**
     132 * Inter process/thread packet cleanup.
     133 * See OSLibPackMessage() for details on the packing.
     134 *
     135 * @param   pTeb        Pointer to the thread environment block for the current thread.
     136 * @param   pPacket     Pointer to the packet in question.
     137 * @param   pWinMsg     Pointer to the window message corresponding to the packet.
     138 */
     139inline void OSLibCleanupPacket(TEB *pTeb, POSTMSG_PACKET *pPacket, MSG *pWinMsg)
     140{
     141    switch (pWinMsg->message)
     142    {
     143        /*
     144         * Place this in the TEB freeing any previous WM_COPYDATA packet.
     145         * Note! Nested WM_COPYDATA isn't working.
     146         */
     147        case WINWM_COPYDATA:
     148        {
     149            dprintf(("OSLibCleanupPacket: WM_COPYDATA: old %#p  new %#p", pTeb->o.odin.pWM_COPYDATA, pPacket));
     150            if (pTeb->o.odin.pWM_COPYDATA)
     151                _sfree(pTeb->o.odin.pWM_COPYDATA);
     152            pTeb->o.odin.pWM_COPYDATA = pPacket;
     153            break;
     154        }
     155
     156        /*
     157         * Default packing - free the shared memory here.
     158         */
     159        default:
     160            _sfree(pPacket);
     161            break;
     162    }
     163}
     164
    129165//******************************************************************************
    130166BOOL OS2ToWinMsgTranslate(void *pTeb, QMSG *os2Msg, MSG *winMsg, BOOL isUnicode, BOOL fMsgRemoved)
     
    167203            winMsg->wParam  = packet->wParam;
    168204            winMsg->lParam  = packet->lParam;
    169             if(fMsgRemoved == MSG_REMOVE) free(packet); //free the shared memory here
     205            if (fMsgRemoved == MSG_REMOVE)
     206                OSLibCleanupPacket(teb, packet, winMsg);
    170207            if(win32wnd) RELEASE_WNDOBJ(win32wnd);
    171208            return TRUE;
     
    407444            (winMsg->message == WINWM_NCMBUTTONDOWN))
    408445        {
    409             if(fGenerateDoubleClick && doubleClickMsg.message == winMsg->message && 
     446            if(fGenerateDoubleClick && doubleClickMsg.message == winMsg->message &&
    410447               winMsg->time - doubleClickMsg.time < GetDoubleClickTime() &&
    411448               (abs(winMsg->pt.x - doubleClickMsg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK_W)/2) &&
    412                (abs(winMsg->pt.y - doubleClickMsg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK_W)/2)) 
     449               (abs(winMsg->pt.y - doubleClickMsg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK_W)/2))
    413450            {
    414451                 dprintf(("single -> double click"));
     
    440477            }
    441478            else msg = winMsg->message;
    442            
     479
    443480            if(msg == WINWM_LBUTTONDBLCLK) {
    444481                msg = WINWM_LBUTTONDOWN;
     
    589626            //FALSE -> keyboard operation = user pressed Alt-F4 -> close app
    590627            //TRUE  -> user clicked on close button -> close window
    591             if(SHORT2FROMMP(os2Msg->mp2) == FALSE) 
     628            if(SHORT2FROMMP(os2Msg->mp2) == FALSE)
    592629            {
    593630                HWND hwnd = win32wnd->GetTopParent();
     
    655692      // NO BREAK! FALLTHRU CASE!
    656693    }
    657      
     694
    658695    case WM_CHAR_SPECIAL:
    659696    {
     
    665702      // NO BREAK! FALLTHRU CASE!
    666703    }
    667      
     704
    668705    case WM_CHAR:
    669706    {
     
    674711      ULONG  flags = SHORT1FROMMP(os2Msg->mp1);
    675712      BOOL   keyWasPressed;
    676       BOOL   numPressed = (BOOL)(WinGetKeyState(HWND_DESKTOP,VK_NUMLOCK) & 1);       
     713      BOOL   numPressed = (BOOL)(WinGetKeyState(HWND_DESKTOP,VK_NUMLOCK) & 1);
    677714      char   c;
    678715      USHORT usPMScanCode = CHAR4FROMMP(os2Msg->mp1);
     
    693730
    694731        KeyTranslatePMScanToWinVKey(usPMScanCode,
    695                                     FALSE, 
     732                                    FALSE,
    696733                                    &bWinVKey,
    697734                                    &wWinScan,
     
    700737        winMsg->lParam  = repeatCount & 0x0FFFF;                 // bit 0-15, repeatcount
    701738        winMsg->lParam |= (wWinScan & 0x1FF) << 16;  // bit 16-23, scancode + bit 15 extended
    702      
     739
    703740        // Set the extended bit when appropriate
    704741        if (fWinExtended)
    705742            winMsg->lParam = winMsg->lParam | WIN_KEY_EXTENDED;
    706743
    707         //PF When we press shift we enable non-numeric functions of Numpad
     744        //PF When we press shift we enable non-numeric functions of Numpad
    708745        if ((!numPressed || (flags & KC_SHIFT)) && (scanCode >= PMSCAN_PAD7) && (scanCode <= PMSCAN_PADPERIOD))
    709746             winMsg->wParam = ConvertNumPadKey(scanCode);
     
    728765            winMsg->lParam = 0x01460001;
    729766        }
    730      
     767
    731768        if (!(flags & KC_ALT))
    732769        {
     
    745782              // held ALT-key when current key is released
    746783              // generates additional flag 0x2000000
    747               // Note: PM seems to do this differently, 
     784              // Note: PM seems to do this differently,
    748785              // KC_ALT is already reset
    749786            }
     
    756793            winMsg->lParam |= 1 << 31;                              // bit 31, transition state, always 1 for WM_KEYUP
    757794          }
    758           else 
     795          else
    759796          { // send WM_KEYDOWN message
    760797            winMsg->message = WINWM_KEYDOWN;
     
    762799            if (keyWasPressed)
    763800              winMsg->lParam |= WIN_KEY_PREVSTATE;                  // bit 30, previous state, 1 means key was pressed
    764              
     801
    765802            //Shift-Enter and possibly others need to have special handling
    766803            if (flags & KC_SHIFT)
    767804            {
    768805                if(fMsgRemoved && !(teb->o.odin.fTranslated))
    769                 {                   
     806                {
    770807                  dprintf(("PM: KC_SHIFT: %x",winMsg->wParam));
    771808                  if (winMsg->wParam == VK_RETURN_W)
     
    773810                    MSG extramsg;
    774811                    memcpy(&extramsg, winMsg, sizeof(MSG));
    775    
     812
    776813                    //After SetFocus(0), all keystrokes are converted in WM_SYS*
    777814                    extramsg.message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR : WINWM_CHAR;
     
    791828                    MSG extramsg;
    792829                    memcpy(&extramsg, winMsg, sizeof(MSG));
    793    
     830
    794831                    //After SetFocus(0), all keystrokes are converted in WM_SYS*
    795832                    extramsg.message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR : WINWM_CHAR;
     
    802839          // if right alt is down, then we need to set the alt down bit too
    803840          // except for the fake Ctrl WM_CHAR sent for AltGr emulation
    804           if (os2Msg->msg != WM_CHAR_SPECIAL_ALTGRCONTROL && 
    805               (WinGetKeyState(HWND_DESKTOP, VK_ALTGRAF) & 0x8000)) 
     841          if (os2Msg->msg != WM_CHAR_SPECIAL_ALTGRCONTROL &&
     842              (WinGetKeyState(HWND_DESKTOP, VK_ALTGRAF) & 0x8000))
    806843          {
    807               winMsg->lParam |= WIN_KEY_ALTHELD;           
     844              winMsg->lParam |= WIN_KEY_ALTHELD;
    808845          }
    809846        }
    810         else 
     847        else
    811848        {
    812849          //
     
    817854             //@@PF Note that without pmkbdhook there will not be correct message for Alt-Enter
    818855              winMsg->message = WINWM_SYSKEYUP;
    819               winMsg->lParam |= WIN_KEY_PREVSTATE;           
     856              winMsg->lParam |= WIN_KEY_PREVSTATE;
    820857              // No ALTHELD for Alt itself ;)
    821               winMsg->lParam |= WIN_KEY_ALTHELD;           
    822               winMsg->lParam |= 1 << 31;                              // bit 31, transition state, always 1 for WM_KEYUP
     858              winMsg->lParam |= WIN_KEY_ALTHELD;
     859              winMsg->lParam |= 1 << 31;                              // bit 31, transition state, always 1 for WM_KEYUP
    823860          }
    824           else 
     861          else
    825862          {
    826863            // send WM_SYSKEYDOWN message
     
    838875        // AltGr needs special handling
    839876        //
    840         // AltGr -> WM_KEYDOWN (VK_CONTROL), WM_KEYDOWN (VK_MENU) 
     877        // AltGr -> WM_KEYDOWN (VK_CONTROL), WM_KEYDOWN (VK_MENU)
    841878        //          WM_SYSKEYUP (VK_CONTROL)
    842879        //          WM_KEYUP (VK_MENU)
    843880        //
    844         // Ctrl+AltGr -> WM_KEYDOWN (VK_CONTROL), WM_KEYUP (VK_CONTROL) 
    845         //               WM_KEYDOWN (VK_MENU) 
     881        // Ctrl+AltGr -> WM_KEYDOWN (VK_CONTROL), WM_KEYUP (VK_CONTROL)
     882        //               WM_KEYDOWN (VK_MENU)
    846883        //               WM_KEYUP (VK_MENU)
    847         //               WM_KEYUP (VK_CONTROL) 
     884        //               WM_KEYUP (VK_CONTROL)
    848885        //
    849         // AltGr+Ctrl -> WM_KEYDOWN (VK_CONTROL), WM_KEYDOWN (VK_MENU) 
    850         //               WM_KEYDOWN (VK_CONTROL) 
    851         //               WM_SYSKEYUP (VK_CONTROL) 
    852         //               WM_SYSKEYUP (VK_CONTROL) 
     886        // AltGr+Ctrl -> WM_KEYDOWN (VK_CONTROL), WM_KEYDOWN (VK_MENU)
     887        //               WM_KEYDOWN (VK_CONTROL)
     888        //               WM_SYSKEYUP (VK_CONTROL)
     889        //               WM_SYSKEYUP (VK_CONTROL)
    853890        //               WM_KEYUP (VK_MENU)
    854891        //
     
    861898        //               endif
    862899        //               Send WM_KEYDOWN (VK_MENU)
    863         // 
    864         if(winMsg->wParam == VK_MENU_W && (winMsg->lParam & WIN_KEY_EXTENDED)) 
     900        //
     901        if(winMsg->wParam == VK_MENU_W && (winMsg->lParam & WIN_KEY_EXTENDED))
    865902        {//AltGr
    866             if(GetKeyState(VK_CONTROL_W) & 0x8000) 
     903            if(GetKeyState(VK_CONTROL_W) & 0x8000)
    867904            {//Ctrl key pressed, send WM_KEYUP
    868            
     905
    869906            }
    870907        }
     
    876913                winMsg->message = WINWM_SYSKEYDOWN;
    877914            }
    878             else 
     915            else
    879916            if(winMsg->message == WINWM_KEYUP) {
    880917                winMsg->message = WINWM_SYSKEYUP;
     
    9711008        if (os2Msg->msg == WM_VSCROLL)
    9721009        {
    973             POINT CursorPoint;
     1010            POINT CursorPoint;
    9741011            winMsg->message = WINWM_MOUSEWHEEL;
    9751012            if (OSLibWinQueryPointerPos(&CursorPoint))
    9761013               mapScreenPoint((OSLIBPOINT*)&CursorPoint);
    977  
     1014
    9781015            if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEDOWN)
    979                 winMsg->wParam  = MAKELONG(GetMouseKeyState(), -WHEEL_DELTA/OS2_WHEEL_CORRECTION); 
     1016                winMsg->wParam  = MAKELONG(GetMouseKeyState(), -WHEEL_DELTA/OS2_WHEEL_CORRECTION);
    9801017            else
    9811018            if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEUP)
    982                 winMsg->wParam  = MAKELONG(GetMouseKeyState(), WHEEL_DELTA/OS2_WHEEL_CORRECTION); 
     1019                winMsg->wParam  = MAKELONG(GetMouseKeyState(), WHEEL_DELTA/OS2_WHEEL_CORRECTION);
    9831020            else
    984                 winMsg->wParam  = MAKELONG(GetMouseKeyState(), 0); 
    985 
    986             winMsg->lParam  = MAKELONG(CursorPoint.x, CursorPoint.y); 
    987 
    988             dprintf(("WM_MOUSEWHEEL message delta %d at (%d,%d)",HIWORD(winMsg->wParam),CursorPoint.x, CursorPoint.y)); 
     1021                winMsg->wParam  = MAKELONG(GetMouseKeyState(), 0);
     1022
     1023            winMsg->lParam  = MAKELONG(CursorPoint.x, CursorPoint.y);
     1024
     1025            dprintf(("WM_MOUSEWHEEL message delta %d at (%d,%d)",HIWORD(winMsg->wParam),CursorPoint.x, CursorPoint.y));
    9891026            if (fMsgRemoved == MSG_REMOVE)
    9901027            {
    991                     MSLLHOOKSTRUCT hook;
    992 
    993                     hook.pt.x       = os2Msg->ptl.x & 0xFFFF;
    994                     hook.pt.y       = mapScreenY(os2Msg->ptl.y);
    995                     if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEDOWN)
    996                         hook.mouseData   = MAKELONG(GetMouseKeyState(), -WHEEL_DELTA/OS2_WHEEL_CORRECTION); 
    997                     else
    998                     if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEUP)
    999                         hook.mouseData   = MAKELONG(GetMouseKeyState(), WHEEL_DELTA/OS2_WHEEL_CORRECTION); 
    1000                     else goto dummymessage; // IBM driver produces other messages as well sometimes
    1001 
    1002                     hook.flags       = LLMHF_INJECTED;
    1003                     hook.time        = winMsg->time;
    1004                     hook.dwExtraInfo = 0;
    1005                     if(HOOK_CallHooksW( WH_MOUSE_LL, HC_ACTION, WINWM_MOUSEWHEEL, (LPARAM)&hook))
    1006                         goto dummymessage; //hook swallowed message
    1007            }
     1028                    MSLLHOOKSTRUCT hook;
     1029
     1030                    hook.pt.x       = os2Msg->ptl.x & 0xFFFF;
     1031                    hook.pt.y       = mapScreenY(os2Msg->ptl.y);
     1032                    if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEDOWN)
     1033                        hook.mouseData   = MAKELONG(GetMouseKeyState(), -WHEEL_DELTA/OS2_WHEEL_CORRECTION);
     1034                    else
     1035                    if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEUP)
     1036                        hook.mouseData   = MAKELONG(GetMouseKeyState(), WHEEL_DELTA/OS2_WHEEL_CORRECTION);
     1037                    else goto dummymessage; // IBM driver produces other messages as well sometimes
     1038
     1039                    hook.flags       = LLMHF_INJECTED;
     1040                    hook.time        = winMsg->time;
     1041                    hook.dwExtraInfo = 0;
     1042                    if(HOOK_CallHooksW( WH_MOUSE_LL, HC_ACTION, WINWM_MOUSEWHEEL, (LPARAM)&hook))
     1043                        goto dummymessage; //hook swallowed message
     1044           }
    10081045           break;
    1009         } 
     1046        }
    10101047        goto dummymessage; //eat this message
    10111048        break;
     
    10541091  TEB *teb;
    10551092  MSG extramsg;
    1056   BOOL   numPressed = (BOOL)(WinGetKeyState(HWND_DESKTOP,VK_NUMLOCK) & 1);       
     1093  BOOL   numPressed = (BOOL)(WinGetKeyState(HWND_DESKTOP,VK_NUMLOCK) & 1);
    10571094  teb = GetThreadTEB();
    10581095  if(!teb)
     
    10611098  UCHAR ucPMScanCode = CHAR4FROMMP(teb->o.odin.os2msg.mp1);
    10621099  ULONG fl = SHORT1FROMMP(teb->o.odin.os2msg.mp1);
    1063    
    1064  
     1100
     1101
    10651102    //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
    10661103    //      the newly generated WM_CHAR message.
    10671104    if(!teb->o.odin.fTranslated &&
    1068        teb->o.odin.os2msg.msg == WM_CHAR && 
     1105       teb->o.odin.os2msg.msg == WM_CHAR &&
    10691106       !((SHORT1FROMMP(teb->o.odin.os2msg.mp1) & KC_KEYUP) == KC_KEYUP))
    10701107    {
     
    10831120        break;
    10841121      }
    1085      
     1122
    10861123      // PF With NumLock off do not generate any WM_CHAR messages at all
    10871124      // PADMINUS,PADPLUS fall in range of PAD7..PADPERIOD but they should generate WM_CHAR
     
    10891126      if (!numPressed && (ucPMScanCode != PMSCAN_PADMINUS) && (ucPMScanCode != PMSCAN_PADPLUS) &&
    10901127         (ucPMScanCode >= PMSCAN_PAD7) && (ucPMScanCode <= PMSCAN_PADPERIOD))
    1091         return FALSE; 
    1092 
    1093       if(!(fl & KC_CHAR) && msg->message < WINWM_SYSKEYDOWN) 
     1128        return FALSE;
     1129
     1130      if(!(fl & KC_CHAR) && msg->message < WINWM_SYSKEYDOWN)
    10941131      {
    10951132        return FALSE;
     
    11031140        if(msg->wParam)
    11041141        {
    1105           if ((msg->wParam >= VK_NUMPAD0_W) && 
     1142          if ((msg->wParam >= VK_NUMPAD0_W) &&
    11061143              (msg->wParam <= VK_NUMPAD9_W))
    11071144            extramsg.wParam = msg->wParam - 0x30;
     
    11141151                extramsg.wParam = msg->wParam;
    11151152        }
    1116         else   
     1153        else
    11171154          extramsg.wParam = SHORT2FROMMP(teb->o.odin.os2msg.mp2);
    11181155      }
     
    11201157
    11211158      //After SetFocus(0), all keystrokes are converted in WM_SYS*
    1122       if(msg->message >= WINWM_SYSKEYDOWN || fIgnoreKeystrokes) 
     1159      if(msg->message >= WINWM_SYSKEYDOWN || fIgnoreKeystrokes)
    11231160        extramsg.message = WINWM_SYSCHAR;
    1124       else   
     1161      else
    11251162        extramsg.message = WINWM_CHAR;
    11261163
Note: See TracChangeset for help on using the changeset viewer.